1
1
import type { Component , VNode } from 'vue'
2
- import type { ClassFunc , Dimensions , ElementData , Position , StyleFunc , Styles , XYPosition , XYZPosition } from './flow '
3
- import type { NodeComponent } from './components '
2
+ import type { NodeBase } from '@xyflow/system '
3
+ import type { Dimensions , Position , Styles , XYPosition , XYZPosition } from './flow '
4
4
import type { HandleConnectable , HandleElement , ValidConnectionFunc } from './handle'
5
- import type { CustomEvent , NodeEventsHandler , NodeEventsOn } from './hooks'
5
+ import type { NodeEventsOn } from './hooks'
6
+
7
+ export type ElementData = Record < string , unknown >
6
8
7
9
/** Defined as [[x-from, y-from], [x-to, y-to]] */
8
10
export type CoordinateExtent = [ extentFrom : [ fromX : number , fromY : number ] , extentTo : [ toX : number , toY : number ] ]
@@ -29,93 +31,23 @@ export type WidthFunc = (node: GraphNode) => number | string | void
29
31
/** @deprecated will be removed in next major release */
30
32
export type HeightFunc = ( node : GraphNode ) => number | string | void
31
33
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
34
+ /**
35
+ * The node data structure that gets used for the nodes prop.
36
+ * @public
37
+ */
38
+ export interface Node < NodeData extends Record < string , unknown > = Record < string , unknown > , NodeType extends string = string >
39
+ extends Omit < NodeBase < NodeData , NodeType > , 'connectable' | 'extent' | 'origin' > {
52
40
/** Disable/enable connecting node */
53
41
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
70
42
/** define node extent, i.e. area in which node can be moved */
71
43
extent ?: CoordinateExtent | CoordinateExtentRange | 'parent'
72
- /** expands parent area to fit child node */
73
- expandParent ?: boolean
74
- /**
75
- * todo: rename to `parentId` in next major release
76
- * define node as a child node by setting a parent node id
77
- */
78
- 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
-
92
44
/** 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 > >
45
+ class ?: string | string [ ] | Record < string , any >
94
46
/** 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
47
+ style ?: Styles
112
48
}
113
49
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 > {
50
+ export interface GraphNode < Data extends ElementData = ElementData , Type extends string = string > extends Node < Data , Type > {
119
51
/** absolute position in relation to parent elements + z-index */
120
52
computedPosition : XYZPosition
121
53
handleBounds : NodeHandleBounds
@@ -125,10 +57,6 @@ export interface GraphNode<
125
57
selected : boolean
126
58
resizing : boolean
127
59
dragging : boolean
128
- data : Data
129
- /** @deprecated will be removed in the next major version */
130
- events : Partial < NodeEventsHandler < CustomEvents > >
131
- type : Type
132
60
}
133
61
134
62
/** these props are passed to node components */
@@ -196,12 +124,3 @@ export interface NodeProps<Data = ElementData, CustomEvents = object, Type exten
196
124
*/
197
125
events : NodeEventsOn < CustomEvents >
198
126
}
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