Skip to content

Commit 8f31397

Browse files
committed
refactor(core): align node type(s) with xyflow system
Signed-off-by: braks <78412429+bcakmakoglu@users.noreply.github.com>
1 parent d465d1b commit 8f31397

File tree

1 file changed

+12
-95
lines changed

1 file changed

+12
-95
lines changed

packages/core/src/types/node.ts

Lines changed: 12 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import type { Component, VNode } from 'vue'
2+
import type { InternalNodeBase, NodeBase } from '@xyflow/system'
23
import type { ClassFunc, Dimensions, ElementData, Position, StyleFunc, Styles, XYPosition, XYZPosition } from './flow'
3-
import type { NodeComponent } from './components'
44
import type { HandleConnectable, HandleElement, ValidConnectionFunc } from './handle'
5-
import type { CustomEvent, NodeEventsHandler, NodeEventsOn } from './hooks'
5+
import type { NodeEventsHandler, NodeEventsOn } from './hooks'
66

77
/** Defined as [[x-from, y-from], [x-to, y-to]] */
88
export type CoordinateExtent = [extentFrom: [fromX: number, fromY: number], extentTo: [toX: number, toY: number]]
@@ -23,99 +23,25 @@ export interface NodeHandleBounds {
2323
target?: HandleElement[]
2424
}
2525

26-
/** @deprecated will be removed in next major release */
27-
export type WidthFunc = (node: GraphNode) => number | string | void
28-
29-
/** @deprecated will be removed in next major release */
30-
export type HeightFunc = (node: GraphNode) => number | string | void
31-
32-
export interface Node<Data = ElementData, CustomEvents extends Record<string, CustomEvent> = any, Type extends string = string> {
33-
/** Unique node id */
34-
id: string
35-
/**
36-
* @deprecated - will be removed in next major release and replaced with `{ data: { label: string | VNode | Component } }`
37-
* A node label
38-
*/
39-
label?: string | VNode | Component
40-
/** initial node position x, y */
41-
position: XYPosition
42-
/** node type, can be a default type or a custom type */
43-
type?: Type
44-
/** handle position */
45-
targetPosition?: Position
46-
/** handle position */
47-
sourcePosition?: Position
48-
/** Disable/enable dragging node */
49-
draggable?: boolean
50-
/** Disable/enable selecting node */
51-
selectable?: boolean
52-
/** Disable/enable connecting node */
53-
connectable?: HandleConnectable
54-
/** Disable/enable focusing node (a11y) */
55-
focusable?: boolean
56-
/** Disable/enable deleting node */
57-
deletable?: boolean
58-
/** element selector as drag handle for node (can only be dragged from the dragHandle el) */
59-
dragHandle?: string
60-
/**
61-
* @deprecated will be removed in next major release
62-
* called when used as target for new connection
63-
*/
64-
isValidTargetPos?: ValidConnectionFunc
65-
/**
66-
* @deprecated will be removed in next major release
67-
* called when used as source for new connection
68-
*/
69-
isValidSourcePos?: ValidConnectionFunc
26+
export interface Node<NodeData extends Record<string, unknown> = Record<string, unknown>, NodeType extends string = string>
27+
extends NodeBase<NodeData, NodeType> {
7028
/** define node extent, i.e. area in which node can be moved */
71-
extent?: CoordinateExtent | CoordinateExtentRange | 'parent'
29+
// extent?: CoordinateExtent | CoordinateExtentRange | 'parent'
7230
/** expands parent area to fit child node */
7331
expandParent?: boolean
7432
/**
7533
* todo: rename to `parentId` in next major release
7634
* define node as a child node by setting a parent node id
7735
*/
7836
parentNode?: string
79-
/**
80-
* Fixed width of node, applied as style
81-
* You can pass a number which will be used in pixel values (width: 300 -> width: 300px)
82-
* or pass a string with units (width: `10rem` -> width: 10rem)
83-
*/
84-
width?: number | string | WidthFunc
85-
/**
86-
* Fixed height of node, applied as style
87-
* You can pass a number which will be used in pixel values (height: 300 -> height: 300px)
88-
* or pass a string with units (height: `10rem` -> height: 10rem)
89-
*/
90-
height?: number | string | HeightFunc
91-
9237
/** Additional class names, can be a string or a callback returning a string (receives current flow element) */
93-
class?: string | string[] | Record<string, any> | ClassFunc<GraphNode<Data, CustomEvents>>
38+
class?: string | string[] | Record<string, any> | ClassFunc<GraphNode<NodeData, NodeType>>
9439
/** Additional styles, can be an object or a callback returning an object (receives current flow element) */
95-
style?: Styles | StyleFunc<GraphNode<Data, CustomEvents>>
96-
/** Is node hidden */
97-
hidden?: boolean
98-
/**
99-
* @deprecated - will be removed in the next major release
100-
* overwrites current node type
101-
*/
102-
template?: NodeComponent
103-
/** Additional data that is passed to your custom components */
104-
data?: Data
105-
/**
106-
* @deprecated - will be removed in the next major release
107-
* contextual and custom events that are passed to your custom components
108-
*/
109-
events?: Partial<NodeEventsHandler<CustomEvents>>
110-
zIndex?: number
111-
ariaLabel?: string
40+
style?: Styles | StyleFunc<GraphNode<NodeData, NodeType>>
11241
}
11342

114-
export interface GraphNode<
115-
Data = ElementData,
116-
CustomEvents extends Record<string, CustomEvent> = any,
117-
Type extends string = string,
118-
> extends Node<Data, CustomEvents, Type> {
43+
export interface GraphNode<NodeData extends Record<string, unknown> = Record<string, unknown>, NodeType extends string = string>
44+
extends InternalNodeBase<Node<NodeData, NodeType>> {
11945
/** absolute position in relation to parent elements + z-index */
12046
computedPosition: XYZPosition
12147
handleBounds: NodeHandleBounds
@@ -125,10 +51,10 @@ export interface GraphNode<
12551
selected: boolean
12652
resizing: boolean
12753
dragging: boolean
128-
data: Data
54+
data: NodeData
12955
/** @deprecated will be removed in the next major version */
130-
events: Partial<NodeEventsHandler<CustomEvents>>
131-
type: Type
56+
events: Partial<NodeEventsHandler>
57+
type: NodeType
13258
}
13359

13460
/** these props are passed to node components */
@@ -196,12 +122,3 @@ export interface NodeProps<Data = ElementData, CustomEvents = object, Type exten
196122
*/
197123
events: NodeEventsOn<CustomEvents>
198124
}
199-
200-
/**
201-
* Transform a Node type to a GraphNode type
202-
*/
203-
export type ToGraphNode<T extends Node> = GraphNode<
204-
T extends Node<infer Data> ? Data : never,
205-
T extends Node<any, infer Events> ? Events : never,
206-
T extends Node<any, any, infer Type> ? Type : never
207-
>

0 commit comments

Comments
 (0)