@statelyai/flow 0.0.1 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +481 -10
- package/dist/esm/index.d.ts +1285 -0
- package/dist/esm/index.js +2534 -0
- package/package.json +46 -13
- package/.vscode/launch.json +0 -34
- package/LICENSE +0 -21
- package/src/createFlow.test.ts +0 -204
- package/src/index.ts +0 -62
|
@@ -0,0 +1,1285 @@
|
|
|
1
|
+
import * as _xstate_store0 from "@xstate/store";
|
|
2
|
+
import { Graph, GraphEdge, GraphNode, GraphPort, PortDirection, Positioned as EntityRect, VisualEdge, VisualEdge as VisualEdge$1, VisualGraph, VisualGraphConfig, VisualNode, VisualNode as VisualNode$1, VisualPort, VisualPort as VisualPort$1 } from "@statelyai/graph";
|
|
3
|
+
|
|
4
|
+
//#region src/types.d.ts
|
|
5
|
+
type Point = {
|
|
6
|
+
x: number;
|
|
7
|
+
y: number;
|
|
8
|
+
};
|
|
9
|
+
type Size = {
|
|
10
|
+
width: number;
|
|
11
|
+
height: number;
|
|
12
|
+
};
|
|
13
|
+
type Rect = Point & Size;
|
|
14
|
+
type Viewport = {
|
|
15
|
+
/** Pan offset x (canvas → screen translation) */
|
|
16
|
+
x: number;
|
|
17
|
+
/** Pan offset y */
|
|
18
|
+
y: number;
|
|
19
|
+
/** Scale factor (1 = 100%) */
|
|
20
|
+
zoom: number;
|
|
21
|
+
};
|
|
22
|
+
type Side = 'top' | 'bottom' | 'left' | 'right';
|
|
23
|
+
/** Port on a node — positioned by renderer, measured via observer */
|
|
24
|
+
type FlowPort<TPortData = unknown> = VisualPort$1<TPortData> & {
|
|
25
|
+
side: Side;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Flow node attributes — drag offset, ports, style overrides, behavior flags.
|
|
29
|
+
* Visual position = { x + dx, y + dy }
|
|
30
|
+
*/
|
|
31
|
+
type FlowNodeAttributes = {
|
|
32
|
+
dx?: number;
|
|
33
|
+
dy?: number;
|
|
34
|
+
style?: StyleOverrides;
|
|
35
|
+
ports?: FlowPort[];
|
|
36
|
+
hidden?: boolean;
|
|
37
|
+
selectable?: boolean;
|
|
38
|
+
draggable?: boolean;
|
|
39
|
+
connectable?: boolean;
|
|
40
|
+
deletable?: boolean;
|
|
41
|
+
resizable?: boolean;
|
|
42
|
+
};
|
|
43
|
+
/** Flow edge label — positioned like a node, lives on edge */
|
|
44
|
+
type FlowEdgeLabel<TData = unknown> = {
|
|
45
|
+
x: number;
|
|
46
|
+
y: number;
|
|
47
|
+
dx?: number;
|
|
48
|
+
dy?: number;
|
|
49
|
+
width: number;
|
|
50
|
+
height: number;
|
|
51
|
+
style?: StyleOverrides;
|
|
52
|
+
data: TData;
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* Label anchor: determines base position of edge label before dx/dy offset.
|
|
56
|
+
* - number (0..1): interpolation along source→target centers (0.5 = midpoint)
|
|
57
|
+
* - 'fixed': uses label's own x/y, ignores node positions
|
|
58
|
+
* - function: custom anchor returning center point given source/target bounds
|
|
59
|
+
*/
|
|
60
|
+
type LabelAnchor = number | 'fixed' | ((sourceBounds: Rect, targetBounds: Rect) => Point);
|
|
61
|
+
/** Edge marker type */
|
|
62
|
+
type MarkerType = 'arrow' | 'arrow-closed' | 'circle' | 'none' | (string & {});
|
|
63
|
+
/** Edge visual style — read by renderer */
|
|
64
|
+
type FlowEdgeStyle = {
|
|
65
|
+
markerStart?: MarkerType;
|
|
66
|
+
markerEnd?: MarkerType;
|
|
67
|
+
strokeDasharray?: string;
|
|
68
|
+
strokeWidth?: number;
|
|
69
|
+
stroke?: string;
|
|
70
|
+
};
|
|
71
|
+
/** Flow edge attributes — label, ports, style, behavior flags */
|
|
72
|
+
type FlowEdgeAttributes<TLabelData = unknown> = {
|
|
73
|
+
dx?: number;
|
|
74
|
+
dy?: number;
|
|
75
|
+
label?: FlowEdgeLabel<TLabelData> | null;
|
|
76
|
+
labelAnchor?: LabelAnchor;
|
|
77
|
+
sourcePort?: string | null;
|
|
78
|
+
targetPort?: string | null;
|
|
79
|
+
kind?: string;
|
|
80
|
+
style?: FlowEdgeStyle;
|
|
81
|
+
hidden?: boolean;
|
|
82
|
+
selectable?: boolean;
|
|
83
|
+
draggable?: boolean;
|
|
84
|
+
connectable?: boolean;
|
|
85
|
+
reconnectable?: boolean;
|
|
86
|
+
deletable?: boolean;
|
|
87
|
+
};
|
|
88
|
+
/** A flow node: VisualNode + flow attributes */
|
|
89
|
+
type FlowNode<TData = any> = VisualNode$1<TData> & FlowNodeAttributes;
|
|
90
|
+
/** A flow edge: VisualEdge + flow attributes */
|
|
91
|
+
type FlowEdge<TEdgeData = any, TLabelData = any> = Omit<VisualEdge$1<TEdgeData>, 'label'> & FlowEdgeAttributes<TLabelData>;
|
|
92
|
+
/** A flow graph: VisualGraph with FlowNode/FlowEdge */
|
|
93
|
+
type FlowGraph<TNodeData = any, TEdgeData = any> = Omit<VisualGraphConfig<TNodeData, TEdgeData>, 'nodes' | 'edges'> & {
|
|
94
|
+
nodes: FlowNode<TNodeData>[];
|
|
95
|
+
edges: FlowEdge<TEdgeData>[];
|
|
96
|
+
};
|
|
97
|
+
/** Direction of the graph layout */
|
|
98
|
+
type EdgeDirection = 'up' | 'down' | 'left' | 'right';
|
|
99
|
+
type StyleOverrides = {
|
|
100
|
+
/** User-set dimension overrides (from manual resize) */
|
|
101
|
+
customWidth?: number;
|
|
102
|
+
customHeight?: number;
|
|
103
|
+
};
|
|
104
|
+
type InteractionMode = 'default' | 'pan' | 'connect' | 'select';
|
|
105
|
+
type SelectionMode = 'partial' | 'full';
|
|
106
|
+
type CanvasState = 'idle' | 'panning' | 'dragging' | 'connecting' | 'resizing' | 'selecting' | 'editing';
|
|
107
|
+
type ConnectionState = {
|
|
108
|
+
sourceId: string;
|
|
109
|
+
sourcePort: string | null;
|
|
110
|
+
/** null while dragging over empty space */
|
|
111
|
+
targetId: string | null;
|
|
112
|
+
targetPort: string | null;
|
|
113
|
+
/** Canvas position where the gesture began */
|
|
114
|
+
startPosition: Point;
|
|
115
|
+
/** Current pointer in canvas coords */
|
|
116
|
+
pointerPosition: Point;
|
|
117
|
+
/** Thresholded activation state for drag-based connections */
|
|
118
|
+
active: boolean;
|
|
119
|
+
/** canConnect result for current target */
|
|
120
|
+
isValid: boolean;
|
|
121
|
+
};
|
|
122
|
+
type ResizeHandle = 'top' | 'bottom' | 'left' | 'right' | 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right';
|
|
123
|
+
type AutoLayoutState = {
|
|
124
|
+
status: 'idle' | 'pending' | 'running';
|
|
125
|
+
algorithm: string | null;
|
|
126
|
+
};
|
|
127
|
+
type EntityVisualState = {
|
|
128
|
+
selected: boolean;
|
|
129
|
+
focused: boolean;
|
|
130
|
+
hovered: boolean;
|
|
131
|
+
highlighted: boolean;
|
|
132
|
+
connectionValid: boolean;
|
|
133
|
+
connectionInvalid: boolean;
|
|
134
|
+
disabled: boolean;
|
|
135
|
+
dragging: boolean;
|
|
136
|
+
resizing: boolean;
|
|
137
|
+
editing: boolean;
|
|
138
|
+
};
|
|
139
|
+
type Direction = 'top' | 'bottom' | 'left' | 'right';
|
|
140
|
+
type PathData = {
|
|
141
|
+
points: Point[];
|
|
142
|
+
sourceDirection: Direction;
|
|
143
|
+
targetDirection: Direction;
|
|
144
|
+
};
|
|
145
|
+
/** Edge path result from engine — may contain two segments if edge has a label */
|
|
146
|
+
type EdgePathData = {
|
|
147
|
+
segments: PathData[];
|
|
148
|
+
labelBounds: Rect | null;
|
|
149
|
+
};
|
|
150
|
+
type ShapeHandler = {
|
|
151
|
+
hitTest: (point: Point, bounds: Rect) => boolean;
|
|
152
|
+
edgeAnchor: (bounds: Rect, direction: Direction) => Point;
|
|
153
|
+
};
|
|
154
|
+
type EntityColorSet = {
|
|
155
|
+
fill: string;
|
|
156
|
+
stroke: string;
|
|
157
|
+
text: string;
|
|
158
|
+
};
|
|
159
|
+
type EdgeStyleConfig = {
|
|
160
|
+
dashArray?: number[];
|
|
161
|
+
width: number;
|
|
162
|
+
};
|
|
163
|
+
type FlowTheme = {
|
|
164
|
+
colors: {
|
|
165
|
+
entity: Record<string, EntityColorSet>;
|
|
166
|
+
selection: string;
|
|
167
|
+
connection: string;
|
|
168
|
+
connectionValid: string;
|
|
169
|
+
connectionInvalid: string;
|
|
170
|
+
highlight: string;
|
|
171
|
+
focus: string;
|
|
172
|
+
canvas: string;
|
|
173
|
+
grid: string;
|
|
174
|
+
};
|
|
175
|
+
edgeStyles: Record<string, EdgeStyleConfig>;
|
|
176
|
+
spacing: {
|
|
177
|
+
gridSize: number;
|
|
178
|
+
snapSize: number;
|
|
179
|
+
portSize: number;
|
|
180
|
+
selectionPadding: number;
|
|
181
|
+
};
|
|
182
|
+
};
|
|
183
|
+
/** A behavior predicate: function or `false` to disable globally */
|
|
184
|
+
type BehaviorPredicate<TEntity = unknown, TState = unknown> = ((entity: TEntity, flowState: TState) => boolean) | false;
|
|
185
|
+
type FlowConfig<TEntity = unknown, TState = unknown> = {
|
|
186
|
+
selectable: BehaviorPredicate<TEntity, TState>;
|
|
187
|
+
draggable: BehaviorPredicate<TEntity, TState>;
|
|
188
|
+
connectable: BehaviorPredicate<TEntity, TState>;
|
|
189
|
+
reconnectable: BehaviorPredicate<TEntity, TState>;
|
|
190
|
+
deletable: BehaviorPredicate<TEntity, TState>;
|
|
191
|
+
resizable: BehaviorPredicate<TEntity, TState>;
|
|
192
|
+
visible: BehaviorPredicate<TEntity, TState>;
|
|
193
|
+
};
|
|
194
|
+
type ViewportAnimationOptions = {
|
|
195
|
+
duration?: number;
|
|
196
|
+
easing?: (t: number) => number;
|
|
197
|
+
};
|
|
198
|
+
type FitViewOptions = ViewportAnimationOptions & {
|
|
199
|
+
padding?: number;
|
|
200
|
+
minZoom?: number;
|
|
201
|
+
maxZoom?: number;
|
|
202
|
+
nodes?: Array<string | {
|
|
203
|
+
id: string;
|
|
204
|
+
}>;
|
|
205
|
+
};
|
|
206
|
+
//#endregion
|
|
207
|
+
//#region src/store/index.d.ts
|
|
208
|
+
type FlowStoreContext = {
|
|
209
|
+
graph: FlowGraph;
|
|
210
|
+
parentNodeId: string | null;
|
|
211
|
+
depth: number | null;
|
|
212
|
+
viewport: Viewport;
|
|
213
|
+
viewportSize: Size;
|
|
214
|
+
viewportStack: Viewport[];
|
|
215
|
+
minZoom: number;
|
|
216
|
+
maxZoom: number;
|
|
217
|
+
translateExtent: [Point, Point] | null;
|
|
218
|
+
nodeExtent: [Point, Point] | null;
|
|
219
|
+
selection: Set<string>;
|
|
220
|
+
selectionBox: [Point, Point] | null;
|
|
221
|
+
highlights: Set<string>;
|
|
222
|
+
focusedEntityId: string | null;
|
|
223
|
+
canvasState: CanvasState;
|
|
224
|
+
draggedEntityId: string | null;
|
|
225
|
+
dragThreshold: number;
|
|
226
|
+
autoPanOnDrag: boolean;
|
|
227
|
+
autoPanThreshold: number;
|
|
228
|
+
autoPanSpeed: number;
|
|
229
|
+
connection: ConnectionState | null;
|
|
230
|
+
connectOnClick: boolean;
|
|
231
|
+
connectionClickStartHandle: {
|
|
232
|
+
nodeId: string;
|
|
233
|
+
port: string | null;
|
|
234
|
+
} | null;
|
|
235
|
+
panOrigin: Point | null;
|
|
236
|
+
panViewportOrigin: Viewport | null;
|
|
237
|
+
resizingEntityId: string | null;
|
|
238
|
+
resizeHandle: ResizeHandle | null;
|
|
239
|
+
/** Two opposite corners during resize: [anchor, moving]. Derived bounds = min/max of these. */
|
|
240
|
+
resizeCorners: [Point, Point] | null;
|
|
241
|
+
interactionMode: InteractionMode;
|
|
242
|
+
selectionMode: SelectionMode;
|
|
243
|
+
snapToGrid: boolean;
|
|
244
|
+
snapGrid: [number, number];
|
|
245
|
+
enableSnapLines: boolean;
|
|
246
|
+
snapThreshold: number;
|
|
247
|
+
enableSpacingGuides: boolean;
|
|
248
|
+
autoLayout: AutoLayoutState;
|
|
249
|
+
};
|
|
250
|
+
type FlowStoreOptions = {
|
|
251
|
+
minZoom?: number;
|
|
252
|
+
maxZoom?: number;
|
|
253
|
+
translateExtent?: [Point, Point] | null;
|
|
254
|
+
nodeExtent?: [Point, Point] | null;
|
|
255
|
+
dragThreshold?: number;
|
|
256
|
+
autoPanOnDrag?: boolean;
|
|
257
|
+
autoPanThreshold?: number;
|
|
258
|
+
autoPanSpeed?: number;
|
|
259
|
+
snapToGrid?: boolean;
|
|
260
|
+
snapGrid?: [number, number];
|
|
261
|
+
enableSnapLines?: boolean;
|
|
262
|
+
snapThreshold?: number;
|
|
263
|
+
enableSpacingGuides?: boolean;
|
|
264
|
+
connectOnClick?: boolean;
|
|
265
|
+
connectionDragThreshold?: number;
|
|
266
|
+
selectionMode?: SelectionMode;
|
|
267
|
+
historyLimit?: number;
|
|
268
|
+
beforeDelete?: (payload: {
|
|
269
|
+
graph: FlowGraph;
|
|
270
|
+
reason: 'deleteNode' | 'deleteEdge' | 'deleteSelected';
|
|
271
|
+
nodes: FlowNode[];
|
|
272
|
+
edges: FlowEdge[];
|
|
273
|
+
}) => false | {
|
|
274
|
+
nodes?: FlowNode[];
|
|
275
|
+
edges?: FlowEdge[];
|
|
276
|
+
} | void;
|
|
277
|
+
/**
|
|
278
|
+
* Controls what happens to edges when a node is deleted.
|
|
279
|
+
* - 'cascade' (default): delete all edges connected to the node
|
|
280
|
+
* - 'retarget': edges connected to deleted node become self-loops on the other endpoint
|
|
281
|
+
* - function: custom logic — receives graph + node ids to delete, returns { nodes, edges } to keep
|
|
282
|
+
*/
|
|
283
|
+
onDeleteNodes?: 'cascade' | 'retarget' | ((graph: FlowGraph, nodeIds: Set<string>) => {
|
|
284
|
+
nodes: FlowNode[];
|
|
285
|
+
edges: FlowEdge[];
|
|
286
|
+
});
|
|
287
|
+
};
|
|
288
|
+
type LayoutRequestedEvent = {
|
|
289
|
+
algorithm: string;
|
|
290
|
+
graph: FlowGraph;
|
|
291
|
+
};
|
|
292
|
+
type ConnectEndTarget = {
|
|
293
|
+
kind: 'node';
|
|
294
|
+
nodeId: string;
|
|
295
|
+
port: string | null;
|
|
296
|
+
} | {
|
|
297
|
+
kind: 'edge';
|
|
298
|
+
edgeId: string;
|
|
299
|
+
} | {
|
|
300
|
+
kind: 'canvas';
|
|
301
|
+
position: Point;
|
|
302
|
+
} | {
|
|
303
|
+
kind: 'none';
|
|
304
|
+
};
|
|
305
|
+
type ConnectionEndedEvent = {
|
|
306
|
+
source: {
|
|
307
|
+
nodeId: string;
|
|
308
|
+
port: string | null;
|
|
309
|
+
};
|
|
310
|
+
target: ConnectEndTarget;
|
|
311
|
+
connection: ConnectionState;
|
|
312
|
+
};
|
|
313
|
+
type TransactionMetadata = {
|
|
314
|
+
transactionId?: string;
|
|
315
|
+
};
|
|
316
|
+
declare function createFlowStore(initialGraph?: FlowGraph, options?: FlowStoreOptions): _xstate_store0.Store<FlowStoreContext, {
|
|
317
|
+
createNode: {
|
|
318
|
+
node: FlowNode;
|
|
319
|
+
} & TransactionMetadata;
|
|
320
|
+
deleteNode: {
|
|
321
|
+
id: string;
|
|
322
|
+
} & TransactionMetadata;
|
|
323
|
+
updateNodeData: {
|
|
324
|
+
id: string;
|
|
325
|
+
data: Record<string, unknown>;
|
|
326
|
+
} & TransactionMetadata;
|
|
327
|
+
createEdge: {
|
|
328
|
+
edge: FlowEdge;
|
|
329
|
+
} & TransactionMetadata;
|
|
330
|
+
deleteEdge: {
|
|
331
|
+
id: string;
|
|
332
|
+
} & TransactionMetadata;
|
|
333
|
+
updateEdgeData: {
|
|
334
|
+
id: string;
|
|
335
|
+
data: Record<string, unknown>;
|
|
336
|
+
} & TransactionMetadata;
|
|
337
|
+
deleteSelected: unknown;
|
|
338
|
+
setGraph: {
|
|
339
|
+
graph: FlowGraph;
|
|
340
|
+
};
|
|
341
|
+
reset: unknown;
|
|
342
|
+
reparentNode: {
|
|
343
|
+
id: string;
|
|
344
|
+
parentId: string | null;
|
|
345
|
+
} & TransactionMetadata;
|
|
346
|
+
dragStart: {
|
|
347
|
+
id: string;
|
|
348
|
+
};
|
|
349
|
+
dragMove: {
|
|
350
|
+
dx: number;
|
|
351
|
+
dy: number;
|
|
352
|
+
};
|
|
353
|
+
dragEnd: unknown;
|
|
354
|
+
commitDrag: unknown;
|
|
355
|
+
select: {
|
|
356
|
+
ids: string[];
|
|
357
|
+
mode?: "single" | "multi";
|
|
358
|
+
};
|
|
359
|
+
selectAll: unknown;
|
|
360
|
+
clearSelection: unknown;
|
|
361
|
+
selectionBoxStart: {
|
|
362
|
+
point: Point;
|
|
363
|
+
mode?: "single" | "multi";
|
|
364
|
+
};
|
|
365
|
+
selectionBoxMove: {
|
|
366
|
+
point: Point;
|
|
367
|
+
};
|
|
368
|
+
selectionBoxEnd: unknown;
|
|
369
|
+
focus: {
|
|
370
|
+
entityId: string;
|
|
371
|
+
};
|
|
372
|
+
clearFocus: unknown;
|
|
373
|
+
updateParentNodeId: {
|
|
374
|
+
parentNodeId: string | null;
|
|
375
|
+
};
|
|
376
|
+
setViewport: Viewport;
|
|
377
|
+
panBy: Point;
|
|
378
|
+
zoomTo: {
|
|
379
|
+
zoom: number;
|
|
380
|
+
center: Point;
|
|
381
|
+
};
|
|
382
|
+
setMinZoom: {
|
|
383
|
+
minZoom: number;
|
|
384
|
+
};
|
|
385
|
+
setMaxZoom: {
|
|
386
|
+
maxZoom: number;
|
|
387
|
+
};
|
|
388
|
+
setDragThreshold: {
|
|
389
|
+
dragThreshold: number;
|
|
390
|
+
};
|
|
391
|
+
setAutoPanOptions: {
|
|
392
|
+
autoPanOnDrag?: boolean;
|
|
393
|
+
autoPanThreshold?: number;
|
|
394
|
+
autoPanSpeed?: number;
|
|
395
|
+
};
|
|
396
|
+
setTranslateExtent: {
|
|
397
|
+
extent: [Point, Point] | null;
|
|
398
|
+
};
|
|
399
|
+
setNodeExtent: {
|
|
400
|
+
extent: [Point, Point] | null;
|
|
401
|
+
};
|
|
402
|
+
updateViewportSize: Size;
|
|
403
|
+
fitView: FitViewOptions | undefined;
|
|
404
|
+
pushViewport: unknown;
|
|
405
|
+
popViewport: unknown;
|
|
406
|
+
panStart: Point;
|
|
407
|
+
pan: Point;
|
|
408
|
+
panEnd: unknown;
|
|
409
|
+
setCanvasState: {
|
|
410
|
+
state: CanvasState;
|
|
411
|
+
};
|
|
412
|
+
connectionStart: {
|
|
413
|
+
sourceId: string;
|
|
414
|
+
sourcePort: string | null;
|
|
415
|
+
position: Point;
|
|
416
|
+
};
|
|
417
|
+
connectionMove: {
|
|
418
|
+
position: Point;
|
|
419
|
+
targetId?: string | null;
|
|
420
|
+
targetPort?: string | null;
|
|
421
|
+
isValid?: boolean;
|
|
422
|
+
};
|
|
423
|
+
connectionEnd: {
|
|
424
|
+
target?: ConnectEndTarget;
|
|
425
|
+
} | undefined;
|
|
426
|
+
cancelConnection: unknown;
|
|
427
|
+
setConnectionClickStartHandle: {
|
|
428
|
+
nodeId: string;
|
|
429
|
+
port: string | null;
|
|
430
|
+
} | null;
|
|
431
|
+
resizeStart: {
|
|
432
|
+
id: string;
|
|
433
|
+
handle: ResizeHandle;
|
|
434
|
+
};
|
|
435
|
+
resizeMove: Point;
|
|
436
|
+
resizeEnd: unknown;
|
|
437
|
+
resizeCancel: unknown;
|
|
438
|
+
reconnectEdge: {
|
|
439
|
+
edgeId: string;
|
|
440
|
+
newSourceId?: string;
|
|
441
|
+
newTargetId?: string;
|
|
442
|
+
newSourcePort?: string;
|
|
443
|
+
newTargetPort?: string;
|
|
444
|
+
} & TransactionMetadata;
|
|
445
|
+
reportPortMeasurements: {
|
|
446
|
+
measurements: Array<{
|
|
447
|
+
nodeId: string;
|
|
448
|
+
portName: string;
|
|
449
|
+
x: number;
|
|
450
|
+
y: number;
|
|
451
|
+
width: number;
|
|
452
|
+
height: number;
|
|
453
|
+
}>;
|
|
454
|
+
};
|
|
455
|
+
setInteractionMode: {
|
|
456
|
+
mode: InteractionMode;
|
|
457
|
+
};
|
|
458
|
+
setSnapToGrid: {
|
|
459
|
+
enabled: boolean;
|
|
460
|
+
grid?: [number, number];
|
|
461
|
+
};
|
|
462
|
+
setSnapLines: {
|
|
463
|
+
enabled: boolean;
|
|
464
|
+
threshold?: number;
|
|
465
|
+
spacing?: boolean;
|
|
466
|
+
};
|
|
467
|
+
moveNodes: {
|
|
468
|
+
direction: Point;
|
|
469
|
+
factor?: number;
|
|
470
|
+
};
|
|
471
|
+
requestLayout: {
|
|
472
|
+
algorithm?: string;
|
|
473
|
+
};
|
|
474
|
+
applyLayoutResult: {
|
|
475
|
+
positions: Map<string, {
|
|
476
|
+
x: number;
|
|
477
|
+
y: number;
|
|
478
|
+
}>;
|
|
479
|
+
edgeLabelPositions?: Map<string, {
|
|
480
|
+
x: number;
|
|
481
|
+
y: number;
|
|
482
|
+
}>;
|
|
483
|
+
} & TransactionMetadata;
|
|
484
|
+
reportMeasurements: {
|
|
485
|
+
measurements: Map<string, {
|
|
486
|
+
width: number;
|
|
487
|
+
height: number;
|
|
488
|
+
}>;
|
|
489
|
+
};
|
|
490
|
+
bakeLabelPositions: {
|
|
491
|
+
positions: Map<string, Point>;
|
|
492
|
+
} & TransactionMetadata;
|
|
493
|
+
} & {
|
|
494
|
+
undo: null;
|
|
495
|
+
redo: null;
|
|
496
|
+
}, _xstate_store0.ExtractEvents<{
|
|
497
|
+
layoutRequested: LayoutRequestedEvent;
|
|
498
|
+
connectionEnded: ConnectionEndedEvent;
|
|
499
|
+
}>>;
|
|
500
|
+
type FlowStore = ReturnType<typeof createFlowStore>;
|
|
501
|
+
//#endregion
|
|
502
|
+
//#region src/routing/index.d.ts
|
|
503
|
+
type EdgeRouterContext = {
|
|
504
|
+
sourceBounds: Rect;
|
|
505
|
+
targetBounds: Rect;
|
|
506
|
+
sourceDirection: Direction;
|
|
507
|
+
targetDirection: Direction;
|
|
508
|
+
sourcePoint?: Point;
|
|
509
|
+
targetPoint?: Point;
|
|
510
|
+
/** All node bounds for obstacle avoidance */
|
|
511
|
+
obstacles: Rect[];
|
|
512
|
+
};
|
|
513
|
+
type EdgeRouter = (edge: {
|
|
514
|
+
sourceId: string;
|
|
515
|
+
targetId: string;
|
|
516
|
+
}, context: EdgeRouterContext) => PathData;
|
|
517
|
+
declare const straightRouter: EdgeRouter;
|
|
518
|
+
declare const stepRouter: EdgeRouter;
|
|
519
|
+
declare const bezierRouter: EdgeRouter;
|
|
520
|
+
/**
|
|
521
|
+
* Determine the best side of `from` to connect toward `to`,
|
|
522
|
+
* based on relative center positions.
|
|
523
|
+
*/
|
|
524
|
+
declare function bestDirection(from: Rect, to: Rect): Direction;
|
|
525
|
+
/**
|
|
526
|
+
* Convert PathData points to an SVG path `d` attribute.
|
|
527
|
+
* Handles 2 points (line), 3 points (quadratic), 4 points (cubic bezier).
|
|
528
|
+
*/
|
|
529
|
+
declare function pathToSVG(path: PathData): string;
|
|
530
|
+
//#endregion
|
|
531
|
+
//#region src/snap.d.ts
|
|
532
|
+
interface SnapLine {
|
|
533
|
+
axis: 'x' | 'y';
|
|
534
|
+
value: number;
|
|
535
|
+
}
|
|
536
|
+
interface SpacingGuide {
|
|
537
|
+
axis: 'x' | 'y';
|
|
538
|
+
/** Position on the perpendicular axis (y for 'x' axis, x for 'y') */
|
|
539
|
+
position: number;
|
|
540
|
+
/** The gap distance being matched */
|
|
541
|
+
spacing: number;
|
|
542
|
+
/** Segments showing where spacing applies */
|
|
543
|
+
ranges: Array<{
|
|
544
|
+
start: number;
|
|
545
|
+
end: number;
|
|
546
|
+
}>;
|
|
547
|
+
}
|
|
548
|
+
interface SnapResult {
|
|
549
|
+
snapLines: SnapLine[];
|
|
550
|
+
/** Adjusted rect position (size unchanged) */
|
|
551
|
+
snapRect: Rect;
|
|
552
|
+
spacingGuides?: SpacingGuide[];
|
|
553
|
+
}
|
|
554
|
+
interface SnapOptions {
|
|
555
|
+
/** Distance threshold in canvas pixels (default 5) */
|
|
556
|
+
threshold?: number;
|
|
557
|
+
/** Enable equal-spacing guides (default false) */
|
|
558
|
+
enableSpacing?: boolean;
|
|
559
|
+
}
|
|
560
|
+
/**
|
|
561
|
+
* Compute snap lines for a dragged rect against other rects.
|
|
562
|
+
*
|
|
563
|
+
* Checks alignment of left/right/center-x and top/bottom/center-y
|
|
564
|
+
* against all target rects. Optionally checks equal spacing between elements.
|
|
565
|
+
*
|
|
566
|
+
* Returns null if no snap is within threshold.
|
|
567
|
+
*/
|
|
568
|
+
declare function getSnapLines(rect: Rect, otherRects: Rect[], {
|
|
569
|
+
threshold,
|
|
570
|
+
enableSpacing
|
|
571
|
+
}?: SnapOptions): SnapResult | null;
|
|
572
|
+
//#endregion
|
|
573
|
+
//#region src/engine.d.ts
|
|
574
|
+
type ProposedConnection = {
|
|
575
|
+
sourceId: string;
|
|
576
|
+
targetId: string;
|
|
577
|
+
sourcePort?: string | null;
|
|
578
|
+
targetPort?: string | null;
|
|
579
|
+
};
|
|
580
|
+
type FlowEngineOptions = {
|
|
581
|
+
/** Default edge router (default: bezierRouter) */
|
|
582
|
+
edgeRouter?: EdgeRouter;
|
|
583
|
+
/** Default label anchor (default: 0.5 = midpoint) */
|
|
584
|
+
labelAnchor?: LabelAnchor;
|
|
585
|
+
/** Connection validation hook */
|
|
586
|
+
canConnect?: (proposed: ProposedConnection) => boolean;
|
|
587
|
+
/** Global behavior config */
|
|
588
|
+
config?: Partial<FlowConfig>;
|
|
589
|
+
/** Custom visibility function */
|
|
590
|
+
isVisible?: (entity: FlowNode | FlowEdge, viewport: Viewport) => boolean;
|
|
591
|
+
};
|
|
592
|
+
type RenderableEntitiesOptions = {
|
|
593
|
+
cull?: 'none' | 'viewport';
|
|
594
|
+
overscan?: number;
|
|
595
|
+
};
|
|
596
|
+
declare function createFlowEngine(store: FlowStore, options?: FlowEngineOptions): {
|
|
597
|
+
store: _xstate_store0.Store<FlowStoreContext, {
|
|
598
|
+
createNode: {
|
|
599
|
+
node: FlowNode;
|
|
600
|
+
} & {
|
|
601
|
+
transactionId?: string;
|
|
602
|
+
};
|
|
603
|
+
deleteNode: {
|
|
604
|
+
id: string;
|
|
605
|
+
} & {
|
|
606
|
+
transactionId?: string;
|
|
607
|
+
};
|
|
608
|
+
updateNodeData: {
|
|
609
|
+
id: string;
|
|
610
|
+
data: Record<string, unknown>;
|
|
611
|
+
} & {
|
|
612
|
+
transactionId?: string;
|
|
613
|
+
};
|
|
614
|
+
createEdge: {
|
|
615
|
+
edge: FlowEdge;
|
|
616
|
+
} & {
|
|
617
|
+
transactionId?: string;
|
|
618
|
+
};
|
|
619
|
+
deleteEdge: {
|
|
620
|
+
id: string;
|
|
621
|
+
} & {
|
|
622
|
+
transactionId?: string;
|
|
623
|
+
};
|
|
624
|
+
updateEdgeData: {
|
|
625
|
+
id: string;
|
|
626
|
+
data: Record<string, unknown>;
|
|
627
|
+
} & {
|
|
628
|
+
transactionId?: string;
|
|
629
|
+
};
|
|
630
|
+
deleteSelected: unknown;
|
|
631
|
+
setGraph: {
|
|
632
|
+
graph: FlowGraph;
|
|
633
|
+
};
|
|
634
|
+
reset: unknown;
|
|
635
|
+
reparentNode: {
|
|
636
|
+
id: string;
|
|
637
|
+
parentId: string | null;
|
|
638
|
+
} & {
|
|
639
|
+
transactionId?: string;
|
|
640
|
+
};
|
|
641
|
+
dragStart: {
|
|
642
|
+
id: string;
|
|
643
|
+
};
|
|
644
|
+
dragMove: {
|
|
645
|
+
dx: number;
|
|
646
|
+
dy: number;
|
|
647
|
+
};
|
|
648
|
+
dragEnd: unknown;
|
|
649
|
+
commitDrag: unknown;
|
|
650
|
+
select: {
|
|
651
|
+
ids: string[];
|
|
652
|
+
mode?: "single" | "multi";
|
|
653
|
+
};
|
|
654
|
+
selectAll: unknown;
|
|
655
|
+
clearSelection: unknown;
|
|
656
|
+
selectionBoxStart: {
|
|
657
|
+
point: Point;
|
|
658
|
+
mode?: "single" | "multi";
|
|
659
|
+
};
|
|
660
|
+
selectionBoxMove: {
|
|
661
|
+
point: Point;
|
|
662
|
+
};
|
|
663
|
+
selectionBoxEnd: unknown;
|
|
664
|
+
focus: {
|
|
665
|
+
entityId: string;
|
|
666
|
+
};
|
|
667
|
+
clearFocus: unknown;
|
|
668
|
+
updateParentNodeId: {
|
|
669
|
+
parentNodeId: string | null;
|
|
670
|
+
};
|
|
671
|
+
setViewport: Viewport;
|
|
672
|
+
panBy: Point;
|
|
673
|
+
zoomTo: {
|
|
674
|
+
zoom: number;
|
|
675
|
+
center: Point;
|
|
676
|
+
};
|
|
677
|
+
setMinZoom: {
|
|
678
|
+
minZoom: number;
|
|
679
|
+
};
|
|
680
|
+
setMaxZoom: {
|
|
681
|
+
maxZoom: number;
|
|
682
|
+
};
|
|
683
|
+
setDragThreshold: {
|
|
684
|
+
dragThreshold: number;
|
|
685
|
+
};
|
|
686
|
+
setAutoPanOptions: {
|
|
687
|
+
autoPanOnDrag?: boolean;
|
|
688
|
+
autoPanThreshold?: number;
|
|
689
|
+
autoPanSpeed?: number;
|
|
690
|
+
};
|
|
691
|
+
setTranslateExtent: {
|
|
692
|
+
extent: [Point, Point] | null;
|
|
693
|
+
};
|
|
694
|
+
setNodeExtent: {
|
|
695
|
+
extent: [Point, Point] | null;
|
|
696
|
+
};
|
|
697
|
+
updateViewportSize: Size;
|
|
698
|
+
fitView: FitViewOptions | undefined;
|
|
699
|
+
pushViewport: unknown;
|
|
700
|
+
popViewport: unknown;
|
|
701
|
+
panStart: Point;
|
|
702
|
+
pan: Point;
|
|
703
|
+
panEnd: unknown;
|
|
704
|
+
setCanvasState: {
|
|
705
|
+
state: CanvasState;
|
|
706
|
+
};
|
|
707
|
+
connectionStart: {
|
|
708
|
+
sourceId: string;
|
|
709
|
+
sourcePort: string | null;
|
|
710
|
+
position: Point;
|
|
711
|
+
};
|
|
712
|
+
connectionMove: {
|
|
713
|
+
position: Point;
|
|
714
|
+
targetId?: string | null;
|
|
715
|
+
targetPort?: string | null;
|
|
716
|
+
isValid?: boolean;
|
|
717
|
+
};
|
|
718
|
+
connectionEnd: {
|
|
719
|
+
target?: ConnectEndTarget;
|
|
720
|
+
} | undefined;
|
|
721
|
+
cancelConnection: unknown;
|
|
722
|
+
setConnectionClickStartHandle: {
|
|
723
|
+
nodeId: string;
|
|
724
|
+
port: string | null;
|
|
725
|
+
} | null;
|
|
726
|
+
resizeStart: {
|
|
727
|
+
id: string;
|
|
728
|
+
handle: ResizeHandle;
|
|
729
|
+
};
|
|
730
|
+
resizeMove: Point;
|
|
731
|
+
resizeEnd: unknown;
|
|
732
|
+
resizeCancel: unknown;
|
|
733
|
+
reconnectEdge: {
|
|
734
|
+
edgeId: string;
|
|
735
|
+
newSourceId?: string;
|
|
736
|
+
newTargetId?: string;
|
|
737
|
+
newSourcePort?: string;
|
|
738
|
+
newTargetPort?: string;
|
|
739
|
+
} & {
|
|
740
|
+
transactionId?: string;
|
|
741
|
+
};
|
|
742
|
+
reportPortMeasurements: {
|
|
743
|
+
measurements: Array<{
|
|
744
|
+
nodeId: string;
|
|
745
|
+
portName: string;
|
|
746
|
+
x: number;
|
|
747
|
+
y: number;
|
|
748
|
+
width: number;
|
|
749
|
+
height: number;
|
|
750
|
+
}>;
|
|
751
|
+
};
|
|
752
|
+
setInteractionMode: {
|
|
753
|
+
mode: InteractionMode;
|
|
754
|
+
};
|
|
755
|
+
setSnapToGrid: {
|
|
756
|
+
enabled: boolean;
|
|
757
|
+
grid?: [number, number];
|
|
758
|
+
};
|
|
759
|
+
setSnapLines: {
|
|
760
|
+
enabled: boolean;
|
|
761
|
+
threshold?: number;
|
|
762
|
+
spacing?: boolean;
|
|
763
|
+
};
|
|
764
|
+
moveNodes: {
|
|
765
|
+
direction: Point;
|
|
766
|
+
factor?: number;
|
|
767
|
+
};
|
|
768
|
+
requestLayout: {
|
|
769
|
+
algorithm?: string;
|
|
770
|
+
};
|
|
771
|
+
applyLayoutResult: {
|
|
772
|
+
positions: Map<string, {
|
|
773
|
+
x: number;
|
|
774
|
+
y: number;
|
|
775
|
+
}>;
|
|
776
|
+
edgeLabelPositions?: Map<string, {
|
|
777
|
+
x: number;
|
|
778
|
+
y: number;
|
|
779
|
+
}>;
|
|
780
|
+
} & {
|
|
781
|
+
transactionId?: string;
|
|
782
|
+
};
|
|
783
|
+
reportMeasurements: {
|
|
784
|
+
measurements: Map<string, {
|
|
785
|
+
width: number;
|
|
786
|
+
height: number;
|
|
787
|
+
}>;
|
|
788
|
+
};
|
|
789
|
+
bakeLabelPositions: {
|
|
790
|
+
positions: Map<string, Point>;
|
|
791
|
+
} & {
|
|
792
|
+
transactionId?: string;
|
|
793
|
+
};
|
|
794
|
+
} & {
|
|
795
|
+
undo: null;
|
|
796
|
+
redo: null;
|
|
797
|
+
}, _xstate_store0.ExtractEvents<{
|
|
798
|
+
layoutRequested: LayoutRequestedEvent;
|
|
799
|
+
connectionEnded: ConnectionEndedEvent;
|
|
800
|
+
}>>;
|
|
801
|
+
trigger: {
|
|
802
|
+
createNode: (eventPayload: Omit<{
|
|
803
|
+
node: FlowNode;
|
|
804
|
+
} & {
|
|
805
|
+
transactionId?: string;
|
|
806
|
+
}, "type">) => void;
|
|
807
|
+
deleteNode: (eventPayload: Omit<{
|
|
808
|
+
id: string;
|
|
809
|
+
} & {
|
|
810
|
+
transactionId?: string;
|
|
811
|
+
}, "type">) => void;
|
|
812
|
+
updateNodeData: (eventPayload: Omit<{
|
|
813
|
+
id: string;
|
|
814
|
+
data: Record<string, unknown>;
|
|
815
|
+
} & {
|
|
816
|
+
transactionId?: string;
|
|
817
|
+
}, "type">) => void;
|
|
818
|
+
createEdge: (eventPayload: Omit<{
|
|
819
|
+
edge: FlowEdge;
|
|
820
|
+
} & {
|
|
821
|
+
transactionId?: string;
|
|
822
|
+
}, "type">) => void;
|
|
823
|
+
deleteEdge: (eventPayload: Omit<{
|
|
824
|
+
id: string;
|
|
825
|
+
} & {
|
|
826
|
+
transactionId?: string;
|
|
827
|
+
}, "type">) => void;
|
|
828
|
+
updateEdgeData: (eventPayload: Omit<{
|
|
829
|
+
id: string;
|
|
830
|
+
data: Record<string, unknown>;
|
|
831
|
+
} & {
|
|
832
|
+
transactionId?: string;
|
|
833
|
+
}, "type">) => void;
|
|
834
|
+
deleteSelected: () => void;
|
|
835
|
+
setGraph: (eventPayload: Omit<{
|
|
836
|
+
graph: FlowGraph;
|
|
837
|
+
}, "type">) => void;
|
|
838
|
+
reset: () => void;
|
|
839
|
+
reparentNode: (eventPayload: Omit<{
|
|
840
|
+
id: string;
|
|
841
|
+
parentId: string | null;
|
|
842
|
+
} & {
|
|
843
|
+
transactionId?: string;
|
|
844
|
+
}, "type">) => void;
|
|
845
|
+
dragStart: (eventPayload: Omit<{
|
|
846
|
+
id: string;
|
|
847
|
+
}, "type">) => void;
|
|
848
|
+
dragMove: (eventPayload: Omit<{
|
|
849
|
+
dx: number;
|
|
850
|
+
dy: number;
|
|
851
|
+
}, "type">) => void;
|
|
852
|
+
dragEnd: () => void;
|
|
853
|
+
commitDrag: () => void;
|
|
854
|
+
select: (eventPayload: Omit<{
|
|
855
|
+
ids: string[];
|
|
856
|
+
mode?: "single" | "multi";
|
|
857
|
+
}, "type">) => void;
|
|
858
|
+
selectAll: () => void;
|
|
859
|
+
clearSelection: () => void;
|
|
860
|
+
selectionBoxStart: (eventPayload: Omit<{
|
|
861
|
+
point: Point;
|
|
862
|
+
mode?: "single" | "multi";
|
|
863
|
+
}, "type">) => void;
|
|
864
|
+
selectionBoxMove: (eventPayload: Omit<{
|
|
865
|
+
point: Point;
|
|
866
|
+
}, "type">) => void;
|
|
867
|
+
selectionBoxEnd: () => void;
|
|
868
|
+
focus: (eventPayload: Omit<{
|
|
869
|
+
entityId: string;
|
|
870
|
+
}, "type">) => void;
|
|
871
|
+
clearFocus: () => void;
|
|
872
|
+
updateParentNodeId: (eventPayload: Omit<{
|
|
873
|
+
parentNodeId: string | null;
|
|
874
|
+
}, "type">) => void;
|
|
875
|
+
setViewport: (eventPayload: Omit<Viewport, "type">) => void;
|
|
876
|
+
panBy: (eventPayload: Omit<Point, "type">) => void;
|
|
877
|
+
zoomTo: (eventPayload: Omit<{
|
|
878
|
+
zoom: number;
|
|
879
|
+
center: Point;
|
|
880
|
+
}, "type">) => void;
|
|
881
|
+
setMinZoom: (eventPayload: Omit<{
|
|
882
|
+
minZoom: number;
|
|
883
|
+
}, "type">) => void;
|
|
884
|
+
setMaxZoom: (eventPayload: Omit<{
|
|
885
|
+
maxZoom: number;
|
|
886
|
+
}, "type">) => void;
|
|
887
|
+
setDragThreshold: (eventPayload: Omit<{
|
|
888
|
+
dragThreshold: number;
|
|
889
|
+
}, "type">) => void;
|
|
890
|
+
setAutoPanOptions: (eventPayload: Omit<{
|
|
891
|
+
autoPanOnDrag?: boolean;
|
|
892
|
+
autoPanThreshold?: number;
|
|
893
|
+
autoPanSpeed?: number;
|
|
894
|
+
}, "type">) => void;
|
|
895
|
+
setTranslateExtent: (eventPayload: Omit<{
|
|
896
|
+
extent: [Point, Point] | null;
|
|
897
|
+
}, "type">) => void;
|
|
898
|
+
setNodeExtent: (eventPayload: Omit<{
|
|
899
|
+
extent: [Point, Point] | null;
|
|
900
|
+
}, "type">) => void;
|
|
901
|
+
updateViewportSize: (eventPayload: Omit<Size, "type">) => void;
|
|
902
|
+
fitView: (eventPayload: Omit<undefined, "type"> | Omit<FitViewOptions, "type">) => void;
|
|
903
|
+
pushViewport: () => void;
|
|
904
|
+
popViewport: () => void;
|
|
905
|
+
panStart: (eventPayload: Omit<Point, "type">) => void;
|
|
906
|
+
pan: (eventPayload: Omit<Point, "type">) => void;
|
|
907
|
+
panEnd: () => void;
|
|
908
|
+
setCanvasState: (eventPayload: Omit<{
|
|
909
|
+
state: CanvasState;
|
|
910
|
+
}, "type">) => void;
|
|
911
|
+
connectionStart: (eventPayload: Omit<{
|
|
912
|
+
sourceId: string;
|
|
913
|
+
sourcePort: string | null;
|
|
914
|
+
position: Point;
|
|
915
|
+
}, "type">) => void;
|
|
916
|
+
connectionMove: (eventPayload: Omit<{
|
|
917
|
+
position: Point;
|
|
918
|
+
targetId?: string | null;
|
|
919
|
+
targetPort?: string | null;
|
|
920
|
+
isValid?: boolean;
|
|
921
|
+
}, "type">) => void;
|
|
922
|
+
connectionEnd: (eventPayload: Omit<undefined, "type"> | Omit<{
|
|
923
|
+
target?: ConnectEndTarget;
|
|
924
|
+
}, "type">) => void;
|
|
925
|
+
cancelConnection: () => void;
|
|
926
|
+
setConnectionClickStartHandle: (eventPayload: Omit<null, "type"> | Omit<{
|
|
927
|
+
nodeId: string;
|
|
928
|
+
port: string | null;
|
|
929
|
+
}, "type">) => void;
|
|
930
|
+
resizeStart: (eventPayload: Omit<{
|
|
931
|
+
id: string;
|
|
932
|
+
handle: ResizeHandle;
|
|
933
|
+
}, "type">) => void;
|
|
934
|
+
resizeMove: (eventPayload: Omit<Point, "type">) => void;
|
|
935
|
+
resizeEnd: () => void;
|
|
936
|
+
resizeCancel: () => void;
|
|
937
|
+
reconnectEdge: (eventPayload: Omit<{
|
|
938
|
+
edgeId: string;
|
|
939
|
+
newSourceId?: string;
|
|
940
|
+
newTargetId?: string;
|
|
941
|
+
newSourcePort?: string;
|
|
942
|
+
newTargetPort?: string;
|
|
943
|
+
} & {
|
|
944
|
+
transactionId?: string;
|
|
945
|
+
}, "type">) => void;
|
|
946
|
+
reportPortMeasurements: (eventPayload: Omit<{
|
|
947
|
+
measurements: Array<{
|
|
948
|
+
nodeId: string;
|
|
949
|
+
portName: string;
|
|
950
|
+
x: number;
|
|
951
|
+
y: number;
|
|
952
|
+
width: number;
|
|
953
|
+
height: number;
|
|
954
|
+
}>;
|
|
955
|
+
}, "type">) => void;
|
|
956
|
+
setInteractionMode: (eventPayload: Omit<{
|
|
957
|
+
mode: InteractionMode;
|
|
958
|
+
}, "type">) => void;
|
|
959
|
+
setSnapToGrid: (eventPayload: Omit<{
|
|
960
|
+
enabled: boolean;
|
|
961
|
+
grid?: [number, number];
|
|
962
|
+
}, "type">) => void;
|
|
963
|
+
setSnapLines: (eventPayload: Omit<{
|
|
964
|
+
enabled: boolean;
|
|
965
|
+
threshold?: number;
|
|
966
|
+
spacing?: boolean;
|
|
967
|
+
}, "type">) => void;
|
|
968
|
+
moveNodes: (eventPayload: Omit<{
|
|
969
|
+
direction: Point;
|
|
970
|
+
factor?: number;
|
|
971
|
+
}, "type">) => void;
|
|
972
|
+
requestLayout: (eventPayload: Omit<{
|
|
973
|
+
algorithm?: string;
|
|
974
|
+
}, "type">) => void;
|
|
975
|
+
applyLayoutResult: (eventPayload: Omit<{
|
|
976
|
+
positions: Map<string, {
|
|
977
|
+
x: number;
|
|
978
|
+
y: number;
|
|
979
|
+
}>;
|
|
980
|
+
edgeLabelPositions?: Map<string, {
|
|
981
|
+
x: number;
|
|
982
|
+
y: number;
|
|
983
|
+
}>;
|
|
984
|
+
} & {
|
|
985
|
+
transactionId?: string;
|
|
986
|
+
}, "type">) => void;
|
|
987
|
+
reportMeasurements: (eventPayload: Omit<{
|
|
988
|
+
measurements: Map<string, {
|
|
989
|
+
width: number;
|
|
990
|
+
height: number;
|
|
991
|
+
}>;
|
|
992
|
+
}, "type">) => void;
|
|
993
|
+
bakeLabelPositions: (eventPayload: Omit<{
|
|
994
|
+
positions: Map<string, Point>;
|
|
995
|
+
} & {
|
|
996
|
+
transactionId?: string;
|
|
997
|
+
}, "type">) => void;
|
|
998
|
+
undo: () => void;
|
|
999
|
+
redo: () => void;
|
|
1000
|
+
};
|
|
1001
|
+
getContext: () => FlowStoreContext;
|
|
1002
|
+
getNode: (id: string) => FlowNode | undefined;
|
|
1003
|
+
getEdge: (id: string) => FlowEdge | undefined;
|
|
1004
|
+
getEntity: (id: string) => FlowNode | FlowEdge | undefined;
|
|
1005
|
+
screenToCanvas: (screenPoint: Point) => Point;
|
|
1006
|
+
canvasToScreen: (canvasPoint: Point) => Point;
|
|
1007
|
+
entityAtPoint: (canvasPoint: Point) => FlowNode | FlowEdge | null;
|
|
1008
|
+
entityIdAtPoint: (canvasPoint: Point) => string | null;
|
|
1009
|
+
getEdgePath: (edgeId: string) => PathData | null;
|
|
1010
|
+
getAllEdgePaths: () => Map<string, EdgePathData>;
|
|
1011
|
+
resolvedPosition: (nodeOrId: FlowNode | string) => Point;
|
|
1012
|
+
resolvedBounds: (nodeOrId: FlowNode | string) => Rect;
|
|
1013
|
+
getGraphBounds: () => Rect;
|
|
1014
|
+
getSelectionBounds: () => Rect | null;
|
|
1015
|
+
entitiesInRect: (rect: Rect) => string[];
|
|
1016
|
+
getPortPosition: (nodeId: string, portName: string) => Point | null;
|
|
1017
|
+
getPortPositions: (nodeId: string) => Map<string, Point>;
|
|
1018
|
+
getEdgeEndpoints: (edgeId: string) => {
|
|
1019
|
+
source: Point;
|
|
1020
|
+
target: Point;
|
|
1021
|
+
} | null;
|
|
1022
|
+
validateConnection: (proposed: ProposedConnection) => boolean;
|
|
1023
|
+
resolveEntityConfig: (entityOrId: FlowNode | FlowEdge | string) => {
|
|
1024
|
+
hidden: boolean;
|
|
1025
|
+
selectable: boolean;
|
|
1026
|
+
draggable: boolean;
|
|
1027
|
+
connectable: boolean;
|
|
1028
|
+
reconnectable: boolean;
|
|
1029
|
+
deletable: boolean;
|
|
1030
|
+
resizable: boolean;
|
|
1031
|
+
};
|
|
1032
|
+
getVisibleEntities: () => {
|
|
1033
|
+
nodes: FlowNode[];
|
|
1034
|
+
edges: FlowEdge[];
|
|
1035
|
+
};
|
|
1036
|
+
getRenderableEntities: (options?: RenderableEntitiesOptions) => {
|
|
1037
|
+
nodes: FlowNode[];
|
|
1038
|
+
edges: FlowEdge[];
|
|
1039
|
+
};
|
|
1040
|
+
getIntersectingNodes: (nodeId: string) => FlowNode[];
|
|
1041
|
+
getAriaLabel: (entityId: string) => string;
|
|
1042
|
+
/** Compute snap result during drag. Returns null if not dragging or snap lines disabled.
|
|
1043
|
+
* Only activates after actual movement (dx/dy != 0) to avoid showing on click. */
|
|
1044
|
+
getSnapResult: () => SnapResult | null;
|
|
1045
|
+
/** Get in-progress resize bounds, or null if not resizing */
|
|
1046
|
+
getResizeBounds: () => Rect | null;
|
|
1047
|
+
subscribe: (listener: (ctx: FlowStoreContext) => void) => () => void;
|
|
1048
|
+
};
|
|
1049
|
+
type FlowEngine = ReturnType<typeof createFlowEngine>;
|
|
1050
|
+
//#endregion
|
|
1051
|
+
//#region src/createFlow.d.ts
|
|
1052
|
+
type LayoutAlgorithm<TNodeData = any, TEdgeData = any> = (graph: FlowGraph<TNodeData, TEdgeData>) => Promise<Map<string, {
|
|
1053
|
+
x: number;
|
|
1054
|
+
y: number;
|
|
1055
|
+
}>>;
|
|
1056
|
+
interface CreateFlowOptions<TNodeData = any, TEdgeData = any> {
|
|
1057
|
+
/** Initial graph owned by the controller. */
|
|
1058
|
+
graph?: FlowGraph<TNodeData, TEdgeData>;
|
|
1059
|
+
/** Layout algorithm used by `flow.runLayout()`. */
|
|
1060
|
+
layout?: LayoutAlgorithm<TNodeData, TEdgeData> | null;
|
|
1061
|
+
/** Store creation options. */
|
|
1062
|
+
store?: FlowStoreOptions;
|
|
1063
|
+
/** Engine creation options. */
|
|
1064
|
+
engine?: FlowEngineOptions;
|
|
1065
|
+
/** Optional listener for completed connection gestures. */
|
|
1066
|
+
onConnectionEnd?: (event: ConnectionEndedEvent) => void;
|
|
1067
|
+
}
|
|
1068
|
+
interface FlowController {
|
|
1069
|
+
store: FlowStore;
|
|
1070
|
+
engine: FlowEngine;
|
|
1071
|
+
trigger: FlowStore['trigger'];
|
|
1072
|
+
destroy: () => void;
|
|
1073
|
+
getContext: () => FlowStoreContext;
|
|
1074
|
+
subscribe: (listener: (context: FlowStoreContext) => void) => () => void;
|
|
1075
|
+
getNode: (id: string) => FlowNode | undefined;
|
|
1076
|
+
getEdge: (id: string) => FlowEdge | undefined;
|
|
1077
|
+
getEntity: (id: string) => FlowNode | FlowEdge | undefined;
|
|
1078
|
+
screenToCanvas: (point: Point) => Point;
|
|
1079
|
+
canvasToScreen: (point: Point) => Point;
|
|
1080
|
+
getAllEdgePaths: () => Map<string, EdgePathData>;
|
|
1081
|
+
getGraphBounds: () => Rect;
|
|
1082
|
+
getSelectionBounds: () => Rect | null;
|
|
1083
|
+
getRenderableEntities: (options?: RenderableEntitiesOptions) => {
|
|
1084
|
+
nodes: FlowNode[];
|
|
1085
|
+
edges: FlowEdge[];
|
|
1086
|
+
};
|
|
1087
|
+
runLayout: (layout?: LayoutAlgorithm) => Promise<void>;
|
|
1088
|
+
}
|
|
1089
|
+
declare function createFlow<TNodeData = any, TEdgeData = any>(options?: CreateFlowOptions<TNodeData, TEdgeData>): FlowController;
|
|
1090
|
+
//#endregion
|
|
1091
|
+
//#region src/spatial.d.ts
|
|
1092
|
+
/** Resolved visual position: layout position + drag offset */
|
|
1093
|
+
declare function resolvedPosition(node: FlowNode): Point;
|
|
1094
|
+
/** Resolved visual bounds: layout position + drag offset + dimensions.
|
|
1095
|
+
* Uses style.customWidth/customHeight when set (from resize), otherwise inherent width/height. */
|
|
1096
|
+
declare function resolvedBounds(node: FlowNode): Rect;
|
|
1097
|
+
/** Resolved bounds with visual snap — for rendering during drag.
|
|
1098
|
+
* Applies grid snap and/or entity snap offset. */
|
|
1099
|
+
declare function snappedBounds(node: FlowNode, grid: [number, number] | null, /** Optional snap offset from entity snap lines (snapRect.x - selectionRect.x) */
|
|
1100
|
+
snapOffset?: Point | null): Rect;
|
|
1101
|
+
/** Compute bounding rect of all nodes + edge labels (resolved positions) */
|
|
1102
|
+
declare function getGraphBounds(nodes: FlowNode[], edges?: FlowEdge[]): Rect;
|
|
1103
|
+
/** AABB intersection test */
|
|
1104
|
+
declare function rectsIntersect(a: Rect, b: Rect): boolean;
|
|
1105
|
+
/** Snap a value to the nearest grid increment */
|
|
1106
|
+
declare function snapToGrid(value: number, gridSize: number): number;
|
|
1107
|
+
/** Snap a point to grid */
|
|
1108
|
+
declare function snapPointToGrid(point: Point, gridSize: number): Point;
|
|
1109
|
+
/** Normalize a box (two points) into a Rect with positive width/height */
|
|
1110
|
+
declare function boxToRect(p1: Point, p2: Point): Rect;
|
|
1111
|
+
/** Get bounding rect of specific entities by id */
|
|
1112
|
+
declare function getSelectionBounds(nodes: FlowNode[], edges: FlowEdge[], selection: Set<string>): Rect | null;
|
|
1113
|
+
/** Determine select mode from a pointer/keyboard event */
|
|
1114
|
+
declare function selectMode(e: {
|
|
1115
|
+
shiftKey?: boolean;
|
|
1116
|
+
metaKey?: boolean;
|
|
1117
|
+
ctrlKey?: boolean;
|
|
1118
|
+
}): 'single' | 'multi';
|
|
1119
|
+
/** Does rect `a` fully contain rect `b`? */
|
|
1120
|
+
declare function rectContains(a: Rect, b: Rect): boolean;
|
|
1121
|
+
/**
|
|
1122
|
+
* Convert a wheel event into a logarithmic zoom exponent.
|
|
1123
|
+
* Accounts for deltaMode (pixels/lines/pages) and trackpad pinch (ctrlKey on macOS).
|
|
1124
|
+
* Use as: `newZoom = currentZoom * Math.pow(2, wheelZoomDelta(e))`
|
|
1125
|
+
*/
|
|
1126
|
+
declare function wheelZoomDelta(e: {
|
|
1127
|
+
deltaY: number;
|
|
1128
|
+
deltaMode: number;
|
|
1129
|
+
ctrlKey: boolean;
|
|
1130
|
+
}): number;
|
|
1131
|
+
/**
|
|
1132
|
+
* Normalize wheel deltas for panning across browsers.
|
|
1133
|
+
* Firefox fires deltaMode=1 (lines) with small values; Chrome fires deltaMode=0 (pixels) with large values.
|
|
1134
|
+
*/
|
|
1135
|
+
declare function normalizeWheelPan(e: {
|
|
1136
|
+
deltaX: number;
|
|
1137
|
+
deltaY: number;
|
|
1138
|
+
deltaMode: number;
|
|
1139
|
+
}): {
|
|
1140
|
+
x: number;
|
|
1141
|
+
y: number;
|
|
1142
|
+
};
|
|
1143
|
+
/**
|
|
1144
|
+
* Detect whether a wheel event is a trackpad pinch-to-zoom gesture.
|
|
1145
|
+
* Browsers send wheel events with ctrlKey=true for trackpad pinch.
|
|
1146
|
+
*/
|
|
1147
|
+
declare function isTrackpadPinch(e: {
|
|
1148
|
+
ctrlKey: boolean;
|
|
1149
|
+
metaKey: boolean;
|
|
1150
|
+
}): boolean;
|
|
1151
|
+
type WheelInteraction = 'zoom' | 'pan' | 'block' | 'ignore';
|
|
1152
|
+
type WheelInteractionOptions = {
|
|
1153
|
+
/**
|
|
1154
|
+
* Whether ordinary wheel gestures pan the canvas.
|
|
1155
|
+
*/
|
|
1156
|
+
panOnScroll?: boolean;
|
|
1157
|
+
/**
|
|
1158
|
+
* Whether browser pinch gestures zoom the canvas.
|
|
1159
|
+
*
|
|
1160
|
+
* Even when disabled, pinch wheels should still be blocked while the pointer is
|
|
1161
|
+
* over the canvas so the browser page does not zoom behind the app.
|
|
1162
|
+
*/
|
|
1163
|
+
zoomOnPinch?: boolean;
|
|
1164
|
+
/**
|
|
1165
|
+
* Whether a floating layer such as a context menu, popover, or dialog is open.
|
|
1166
|
+
*/
|
|
1167
|
+
floatingLayerOpen?: boolean;
|
|
1168
|
+
};
|
|
1169
|
+
/**
|
|
1170
|
+
* Decide how a wheel event should be handled by a flow canvas.
|
|
1171
|
+
*
|
|
1172
|
+
* This mirrors the important React Flow / d3-zoom behavior: browser pinch
|
|
1173
|
+
* gestures are always consumed over the canvas. Otherwise the whole page can
|
|
1174
|
+
* zoom even though the user is interacting with the diagram.
|
|
1175
|
+
*/
|
|
1176
|
+
declare function wheelInteraction(e: {
|
|
1177
|
+
ctrlKey: boolean;
|
|
1178
|
+
metaKey: boolean;
|
|
1179
|
+
}, options?: WheelInteractionOptions): WheelInteraction;
|
|
1180
|
+
/**
|
|
1181
|
+
* Constrain viewport so content can't be panned entirely off-screen.
|
|
1182
|
+
* When zoomed out (content smaller than view), centers the content.
|
|
1183
|
+
* Matches d3-zoom's defaultConstrain behavior.
|
|
1184
|
+
*/
|
|
1185
|
+
declare function constrainViewport(viewport: Viewport, viewportSize: {
|
|
1186
|
+
width: number;
|
|
1187
|
+
height: number;
|
|
1188
|
+
}, translateExtent: [Point, Point]): Viewport;
|
|
1189
|
+
/**
|
|
1190
|
+
* Compute auto-pan velocity when dragging near the viewport edge.
|
|
1191
|
+
* Returns screen-space delta to apply per frame. Returns {0,0} if cursor isn't near an edge.
|
|
1192
|
+
*/
|
|
1193
|
+
declare function calcAutoPan(mousePosition: Point, containerBounds: {
|
|
1194
|
+
width: number;
|
|
1195
|
+
height: number;
|
|
1196
|
+
}, edgeWidth?: number, speed?: number): Point;
|
|
1197
|
+
type AnchorSpec = {
|
|
1198
|
+
x: number | string;
|
|
1199
|
+
y: number | string;
|
|
1200
|
+
offsetX?: number;
|
|
1201
|
+
offsetY?: number;
|
|
1202
|
+
};
|
|
1203
|
+
type AnchorTransform = {
|
|
1204
|
+
x: number;
|
|
1205
|
+
y: number;
|
|
1206
|
+
scale: number;
|
|
1207
|
+
};
|
|
1208
|
+
/**
|
|
1209
|
+
* Compute anchor transform for positioning overlays relative to a rect.
|
|
1210
|
+
* Returns canvas-space position + inverse zoom scale.
|
|
1211
|
+
*
|
|
1212
|
+
* Offsets are in screen pixels — divided by zoom so they stay constant.
|
|
1213
|
+
*
|
|
1214
|
+
* Usage (SVG): `transform="translate(${t.x}, ${t.y}) scale(${t.scale})"`
|
|
1215
|
+
* Usage (CSS): `transform: translate(${t.x}px, ${t.y}px) scale(${t.scale})`
|
|
1216
|
+
*/
|
|
1217
|
+
declare function getAnchorTransform(bounds: Rect, viewport: Viewport, anchor: AnchorSpec): AnchorTransform;
|
|
1218
|
+
//#endregion
|
|
1219
|
+
//#region src/viewport/index.d.ts
|
|
1220
|
+
/** Create a default viewport (origin, no zoom) */
|
|
1221
|
+
declare function createViewport(x?: number, y?: number, zoom?: number): Viewport;
|
|
1222
|
+
/**
|
|
1223
|
+
* Convert viewport to SVG transform string.
|
|
1224
|
+
* Use on the root <g> wrapping all entities.
|
|
1225
|
+
*
|
|
1226
|
+
* @example
|
|
1227
|
+
* <g transform={toSVGTransform(viewport)}>...</g>
|
|
1228
|
+
*/
|
|
1229
|
+
declare function toSVGTransform(viewport: Viewport): string;
|
|
1230
|
+
/**
|
|
1231
|
+
* Convert viewport + container size to an SVG viewBox string.
|
|
1232
|
+
*
|
|
1233
|
+
* @example
|
|
1234
|
+
* <svg viewBox={toViewBox(viewport, { width: 800, height: 600 })}>...</svg>
|
|
1235
|
+
*/
|
|
1236
|
+
declare function toViewBox(viewport: Viewport, size: Size): string;
|
|
1237
|
+
/** Convert a screen-space point to canvas-space */
|
|
1238
|
+
declare function screenToCanvas(point: Point, viewport: Viewport): Point;
|
|
1239
|
+
/** Convert a canvas-space point to screen-space */
|
|
1240
|
+
declare function canvasToScreen(point: Point, viewport: Viewport): Point;
|
|
1241
|
+
/** Get the canvas-space bounding rect of what's visible on screen */
|
|
1242
|
+
declare function getVisibleBounds(viewport: Viewport, size: Size): Rect;
|
|
1243
|
+
/**
|
|
1244
|
+
* Compute a viewport that fits the given bounds into the given screen size.
|
|
1245
|
+
*/
|
|
1246
|
+
declare function viewportForBounds(bounds: Rect, size: Size, options?: FitViewOptions): Viewport;
|
|
1247
|
+
/** Pan viewport by a delta */
|
|
1248
|
+
declare function panBy(viewport: Viewport, delta: Point): Viewport;
|
|
1249
|
+
/** Zoom to a specific level, keeping a screen-space point fixed */
|
|
1250
|
+
declare function zoomTo(viewport: Viewport, zoom: number, center: Point): Viewport;
|
|
1251
|
+
/** Clamp zoom to min/max bounds */
|
|
1252
|
+
declare function clampZoom(zoom: number, minZoom: number, maxZoom: number): number;
|
|
1253
|
+
//#endregion
|
|
1254
|
+
//#region src/shapes/index.d.ts
|
|
1255
|
+
declare function registerShape(name: string, handler: ShapeHandler): void;
|
|
1256
|
+
declare function getShape(name: string): ShapeHandler | undefined;
|
|
1257
|
+
declare function getShapeOrDefault(name: string): ShapeHandler;
|
|
1258
|
+
//#endregion
|
|
1259
|
+
//#region src/config.d.ts
|
|
1260
|
+
/** Default config: everything enabled */
|
|
1261
|
+
declare const defaultConfig: FlowConfig;
|
|
1262
|
+
/** Readonly preset: can select and view, cannot modify */
|
|
1263
|
+
declare const readonlyConfig: Partial<FlowConfig>;
|
|
1264
|
+
/**
|
|
1265
|
+
* Resolve a behavior predicate.
|
|
1266
|
+
* If `false`, returns false. If function, calls it. If undefined, returns default.
|
|
1267
|
+
*/
|
|
1268
|
+
declare function resolveBehavior<TEntity, TState>(predicate: ((entity: TEntity, state: TState) => boolean) | false | undefined, entity: TEntity, state: TState, defaultValue?: boolean): boolean;
|
|
1269
|
+
//#endregion
|
|
1270
|
+
//#region src/factories.d.ts
|
|
1271
|
+
declare function createNode<TData = any>(opts: Partial<FlowNode<TData>> & {
|
|
1272
|
+
id: string;
|
|
1273
|
+
}): FlowNode<TData>;
|
|
1274
|
+
declare function createEdge<TEdgeData = any, TLabelData = any>(opts: Omit<Partial<FlowEdge<TEdgeData, TLabelData>>, 'label'> & Pick<FlowEdge<TEdgeData, TLabelData>, 'id' | 'sourceId' | 'targetId'> & {
|
|
1275
|
+
label?: Partial<FlowEdgeLabel<TLabelData>> & {
|
|
1276
|
+
width: number;
|
|
1277
|
+
height: number;
|
|
1278
|
+
};
|
|
1279
|
+
}): FlowEdge<TEdgeData, TLabelData>;
|
|
1280
|
+
declare function createGraph<TNodeData = any, TEdgeData = any>(opts: Partial<FlowGraph<TNodeData, TEdgeData>> & {
|
|
1281
|
+
nodes: FlowNode<TNodeData>[];
|
|
1282
|
+
edges: FlowEdge<TEdgeData>[];
|
|
1283
|
+
}): FlowGraph<TNodeData, TEdgeData>;
|
|
1284
|
+
//#endregion
|
|
1285
|
+
export { type AnchorSpec, type AnchorTransform, type AutoLayoutState, type BehaviorPredicate, type CanvasState, type ConnectEndTarget, type ConnectionEndedEvent, type ConnectionState, type CreateFlowOptions, type Direction, type EdgeDirection, type EdgePathData, type EdgeRouter, type EdgeRouterContext, type EdgeStyleConfig, type EntityColorSet, type EntityRect, type EntityVisualState, type FitViewOptions, type FlowConfig, type FlowController, type FlowEdge, type FlowEdgeAttributes, type FlowEdgeLabel, type FlowEdgeStyle, type FlowEngine, type FlowEngineOptions, type FlowGraph, type FlowNode, type FlowNodeAttributes, type FlowPort, type FlowStore, type FlowStoreContext, type FlowStoreOptions, type FlowTheme, type Graph, type GraphEdge, type GraphNode, type GraphPort, type InteractionMode, type LabelAnchor, type LayoutAlgorithm, type MarkerType, type PathData, type Point, type PortDirection, type ProposedConnection, type Rect, type RenderableEntitiesOptions, type ResizeHandle, type SelectionMode, type ShapeHandler, type Side, type Size, type SnapLine, type SnapOptions, type SnapResult, type SpacingGuide, type StyleOverrides, type Viewport, type ViewportAnimationOptions, type VisualEdge, type VisualGraph, type VisualNode, type VisualPort, type WheelInteraction, type WheelInteractionOptions, bestDirection, bezierRouter, boxToRect, calcAutoPan, canvasToScreen, clampZoom, constrainViewport, createEdge, createFlow, createFlowEngine, createFlowStore, createGraph, createNode, createViewport, defaultConfig, getAnchorTransform, getGraphBounds, getSelectionBounds, getShape, getShapeOrDefault, getSnapLines, getVisibleBounds, isTrackpadPinch, normalizeWheelPan, panBy, pathToSVG, readonlyConfig, rectContains, rectsIntersect, registerShape, resolveBehavior, resolvedBounds, resolvedPosition, screenToCanvas, selectMode, snapPointToGrid, snapToGrid, snappedBounds, stepRouter, straightRouter, toSVGTransform, toViewBox, viewportForBounds, wheelInteraction, wheelZoomDelta, zoomTo };
|