@statelyai/flow 0.5.0 → 0.7.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 +264 -131
- package/dist/esm/index.d.ts +58 -21
- package/dist/esm/index.js +214 -183
- package/dist/esm/layout/dagre.d.ts +6 -0
- package/dist/esm/layout/dagre.js +106 -0
- package/dist/esm/layout/elk.d.ts +9 -0
- package/dist/esm/layout/elk.js +237 -0
- package/dist/esm/layout/index.d.ts +4 -0
- package/dist/esm/layout/index.js +3 -0
- package/dist/esm/shared.d.ts +28 -0
- package/dist/esm/shared.js +91 -0
- package/package.json +31 -2
package/README.md
CHANGED
|
@@ -27,11 +27,37 @@ const flow = createFlow({
|
|
|
27
27
|
graph: {
|
|
28
28
|
direction: 'down',
|
|
29
29
|
nodes: [
|
|
30
|
-
{
|
|
31
|
-
|
|
30
|
+
{
|
|
31
|
+
type: 'node',
|
|
32
|
+
id: 'a',
|
|
33
|
+
x: 0,
|
|
34
|
+
y: 0,
|
|
35
|
+
width: 200,
|
|
36
|
+
height: 80,
|
|
37
|
+
data: { label: 'Start' },
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
type: 'node',
|
|
41
|
+
id: 'b',
|
|
42
|
+
x: 0,
|
|
43
|
+
y: 150,
|
|
44
|
+
width: 200,
|
|
45
|
+
height: 80,
|
|
46
|
+
data: { label: 'End' },
|
|
47
|
+
},
|
|
32
48
|
],
|
|
33
49
|
edges: [
|
|
34
|
-
{
|
|
50
|
+
{
|
|
51
|
+
type: 'edge',
|
|
52
|
+
id: 'e1',
|
|
53
|
+
sourceId: 'a',
|
|
54
|
+
targetId: 'b',
|
|
55
|
+
x: 0,
|
|
56
|
+
y: 0,
|
|
57
|
+
width: 0,
|
|
58
|
+
height: 0,
|
|
59
|
+
data: {},
|
|
60
|
+
},
|
|
35
61
|
],
|
|
36
62
|
},
|
|
37
63
|
});
|
|
@@ -52,6 +78,58 @@ const selectedBounds = flow.getSelectionBounds();
|
|
|
52
78
|
`createFlow()` owns the store and engine together. Use `createFlowStore()` and
|
|
53
79
|
`createFlowEngine()` directly when you need lower-level control.
|
|
54
80
|
|
|
81
|
+
## Layout adapters
|
|
82
|
+
|
|
83
|
+
Install only the engine you use:
|
|
84
|
+
|
|
85
|
+
```bash
|
|
86
|
+
npm install @statelyai/flow elkjs
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
Use `@dagrejs/dagre` instead of `elkjs` for dagre. Both are optional peer
|
|
90
|
+
dependencies, so installing Flow alone does not install either engine.
|
|
91
|
+
|
|
92
|
+
```ts
|
|
93
|
+
import { createFlow } from '@statelyai/flow';
|
|
94
|
+
import { elkLayout } from '@statelyai/flow/layout/elk';
|
|
95
|
+
|
|
96
|
+
const flow = createFlow({ graph });
|
|
97
|
+
|
|
98
|
+
await flow.layout.run(
|
|
99
|
+
elkLayout({
|
|
100
|
+
nodeSpacing: 80,
|
|
101
|
+
rankSpacing: 120,
|
|
102
|
+
})
|
|
103
|
+
);
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
<!-- adapter contracts from src/layout/elk.ts src/layout/dagre.ts and src/layout/shared.ts -->
|
|
107
|
+
|
|
108
|
+
`elkLayout()` supports compound nodes, ports, edge labels, direction, measured
|
|
109
|
+
bounds via `getBounds`, and scoped incremental layout with `scope: { ids }`.
|
|
110
|
+
Results include computed node sizes and bounds, actual ELK label bounds, routed
|
|
111
|
+
interior waypoints, source metadata, and diagnostics. Scoped passes send only
|
|
112
|
+
the induced graph to ELK; fixed and pinned entities remain in the input but are
|
|
113
|
+
omitted from returned geometry.
|
|
114
|
+
|
|
115
|
+
```ts
|
|
116
|
+
await flow.layout.run(elkLayout({ scope: { ids: candidateIds } }), {
|
|
117
|
+
scope: { parentId: 'group', depth: 1 },
|
|
118
|
+
fixedEntityIds: new Set(['pinned-node']),
|
|
119
|
+
source: 'editor',
|
|
120
|
+
});
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
`dagreLayout()` flattens hierarchy and rejects scoped layout. It returns node
|
|
124
|
+
sizes, node bounds, and edge-label bounds without fabricating unsupported route
|
|
125
|
+
waypoints.
|
|
126
|
+
|
|
127
|
+
```ts
|
|
128
|
+
import { dagreLayout } from '@statelyai/flow/layout/dagre';
|
|
129
|
+
|
|
130
|
+
await flow.layout.run(dagreLayout());
|
|
131
|
+
```
|
|
132
|
+
|
|
55
133
|
## Data model
|
|
56
134
|
|
|
57
135
|
The canonical data model is `VisualGraph` from `@statelyai/graph`. Flow extends it with:
|
|
@@ -105,10 +183,7 @@ visibility with visual projections/highlights. The default scope is
|
|
|
105
183
|
`{ parentId: null, depth: null }`, preserving the full visible graph.
|
|
106
184
|
|
|
107
185
|
```ts
|
|
108
|
-
flow.view.setScope(
|
|
109
|
-
{ parentId: 'compound', depth: 1 },
|
|
110
|
-
{ selection: 'prune' },
|
|
111
|
-
);
|
|
186
|
+
flow.view.setScope({ parentId: 'compound', depth: 1 }, { selection: 'prune' });
|
|
112
187
|
|
|
113
188
|
const { nodes, edges, boundaryEndpoints } = flow.view.getEntities();
|
|
114
189
|
```
|
|
@@ -137,19 +212,44 @@ then target that frame. The default remains the full, current viewport.
|
|
|
137
212
|
```ts
|
|
138
213
|
flow.viewport.setFitFrame({ x: 320, y: 0, width: 880, height: 800 });
|
|
139
214
|
|
|
215
|
+
// Keep the same world point centered as a docked panel changes the frame.
|
|
216
|
+
flow.viewport.setFitFrame(nextFrame, { preserveCenter: true });
|
|
217
|
+
|
|
218
|
+
// Floating chrome can register live, measured screen-space exclusions. Fit,
|
|
219
|
+
// center, and default zoom pivots use the remaining safe frame.
|
|
220
|
+
const unregister = flow.viewport.registerFitExclusion({
|
|
221
|
+
side: 'left',
|
|
222
|
+
gap: 8,
|
|
223
|
+
getRect: () => measuredPaletteRect,
|
|
224
|
+
});
|
|
225
|
+
|
|
140
226
|
flow.viewport.fit();
|
|
141
227
|
flow.viewport.fitBounds(bounds);
|
|
142
228
|
flow.viewport.centerOn({ x: 100, y: 50 });
|
|
143
229
|
flow.viewport.zoomTo(1.5);
|
|
144
230
|
|
|
145
231
|
flow.viewport.setFitFrame(null); // reset to the full viewport
|
|
232
|
+
unregister();
|
|
146
233
|
```
|
|
147
234
|
|
|
148
235
|
Frames require finite `x`/`y` and positive finite dimensions. A `frame` on
|
|
149
236
|
`fit()`, `fitBounds()`, or `centerOn()` overrides the registered frame for that
|
|
150
|
-
call. `
|
|
237
|
+
call. `preserveCenter` shifts the viewport by the fit-frame center delta, so
|
|
238
|
+
resizing or docking panels keeps the same world point centered. `fit()` still composes with the current structural view and its `nodes`
|
|
151
239
|
subset. Animation resolves the same frame-aware target before it begins.
|
|
152
240
|
|
|
241
|
+
Duration-based viewport animations use focal, log-space zooming. Set `lerp` to
|
|
242
|
+
an exponential smoothing factor in `(0, 1]` for a camera that continuously
|
|
243
|
+
approaches changing active entities. The factor is normalized to a nominal
|
|
244
|
+
60 Hz frame, so it feels consistent across display refresh rates:
|
|
245
|
+
|
|
246
|
+
```ts
|
|
247
|
+
flow.viewport.fit({
|
|
248
|
+
nodes: activeEntityIds.map((id) => ({ id })),
|
|
249
|
+
lerp: 0.15,
|
|
250
|
+
});
|
|
251
|
+
```
|
|
252
|
+
|
|
153
253
|
Every viewport mutation (`set`, `panBy`, `zoomTo`, `zoomBy`, `fit`,
|
|
154
254
|
`fitBounds`, and `centerOn`) returns `ViewportAnimationControls` with `cancel()`
|
|
155
255
|
and a `done` promise. `done` resolves on completion or cancellation. Immediate
|
|
@@ -185,7 +285,15 @@ const graph = {
|
|
|
185
285
|
width: 160,
|
|
186
286
|
height: 60,
|
|
187
287
|
ports: [
|
|
188
|
-
{
|
|
288
|
+
{
|
|
289
|
+
name: 'out',
|
|
290
|
+
side: 'right',
|
|
291
|
+
direction: 'out',
|
|
292
|
+
x: 150,
|
|
293
|
+
y: 25,
|
|
294
|
+
width: 10,
|
|
295
|
+
height: 10,
|
|
296
|
+
},
|
|
189
297
|
],
|
|
190
298
|
data: {},
|
|
191
299
|
},
|
|
@@ -272,140 +380,140 @@ events.
|
|
|
272
380
|
|
|
273
381
|
### Graph mutations
|
|
274
382
|
|
|
275
|
-
| Event
|
|
276
|
-
|
|
277
|
-
| `createNode`
|
|
278
|
-
| `deleteNode`
|
|
279
|
-
| `updateNode`
|
|
280
|
-
| `updateNodeData` | `{ id, data }`
|
|
281
|
-
| `createEdge`
|
|
282
|
-
| `deleteEdge`
|
|
283
|
-
| `deleteEntities` | `{ nodeIds?, edgeIds? }`
|
|
284
|
-
| `updateEdge`
|
|
285
|
-
| `updateEdgeData` | `{ id, data }`
|
|
286
|
-
| `deleteSelected` | —
|
|
287
|
-
| `setGraph`
|
|
288
|
-
| `replaceGraph`
|
|
289
|
-
| `reset`
|
|
290
|
-
| `reparentNode`
|
|
291
|
-
| `collapseNode`
|
|
292
|
-
| `expandNode`
|
|
293
|
-
| `reconnectEdge`
|
|
383
|
+
| Event | Payload | Description |
|
|
384
|
+
| ---------------- | ------------------------------------------------------------------------ | --------------------------------------------------------------------------------- |
|
|
385
|
+
| `createNode` | `{ node: FlowNode }` | Add a node |
|
|
386
|
+
| `deleteNode` | `{ id }` | Remove node + cascade edges |
|
|
387
|
+
| `updateNode` | `{ id, patch? }` or `{ id, updater? }` | Patch/replace a node without changing id/type/parent |
|
|
388
|
+
| `updateNodeData` | `{ id, data }` | Merge into node.data |
|
|
389
|
+
| `createEdge` | `{ edge: FlowEdge }` | Add an edge |
|
|
390
|
+
| `deleteEdge` | `{ id }` | Remove an edge |
|
|
391
|
+
| `deleteEntities` | `{ nodeIds?, edgeIds? }` | Low-level synchronous deletion of a known entity set |
|
|
392
|
+
| `updateEdge` | `{ id, patch? }` or `{ id, updater? }` | Patch/replace an edge without changing id/type/endpoints/ports |
|
|
393
|
+
| `updateEdgeData` | `{ id, data }` | Merge into edge.data |
|
|
394
|
+
| `deleteSelected` | — | Remove all selected nodes + edges |
|
|
395
|
+
| `setGraph` | `{ graph: FlowGraph }` | Replace entire graph, reset interaction state |
|
|
396
|
+
| `replaceGraph` | `{ graph, retention?, history?, origin?, transactionId? }` | Replace through the external synchronization policy used by `flow.replaceGraph()` |
|
|
397
|
+
| `reset` | — | Reset store to initial state (preserves viewport size) |
|
|
398
|
+
| `reparentNode` | `{ id, parentId }` | Move node to new parent |
|
|
399
|
+
| `collapseNode` | `{ id }` | Hide descendants and derive folded boundary edges |
|
|
400
|
+
| `expandNode` | `{ id }` | Show descendants again |
|
|
401
|
+
| `reconnectEdge` | `{ edgeId, newSourceId?, newTargetId?, newSourcePort?, newTargetPort? }` | Rewire edge endpoints |
|
|
294
402
|
|
|
295
403
|
### Drag lifecycle
|
|
296
404
|
|
|
297
|
-
| Event
|
|
298
|
-
|
|
299
|
-
| `dragStart`
|
|
300
|
-
| `dragMove`
|
|
301
|
-
| `dragEnd`
|
|
302
|
-
| `commitDrag` | —
|
|
303
|
-
| `moveNodes`
|
|
405
|
+
| Event | Payload | Description |
|
|
406
|
+
| ------------ | ------------------------------- | ------------------------------------- |
|
|
407
|
+
| `dragStart` | `{ id }` | Begin dragging the selected entity |
|
|
408
|
+
| `dragMove` | `{ dx, dy }` | Apply in-progress drag delta |
|
|
409
|
+
| `dragEnd` | — | End drag gesture |
|
|
410
|
+
| `commitDrag` | — | Bake `dx/dy` into committed positions |
|
|
411
|
+
| `moveNodes` | `{ direction: Point, factor? }` | Move selected nodes by arrow key |
|
|
304
412
|
|
|
305
413
|
### Selection & focus
|
|
306
414
|
|
|
307
|
-
| Event
|
|
308
|
-
|
|
309
|
-
| `select`
|
|
310
|
-
| `selectAll`
|
|
311
|
-
| `clearSelection` | —
|
|
312
|
-
| `focus`
|
|
313
|
-
| `clearFocus`
|
|
415
|
+
| Event | Payload | Description |
|
|
416
|
+
| ---------------- | ------------------------------------ | ------------------------------- |
|
|
417
|
+
| `select` | `{ ids, mode: 'single' \| 'multi' }` | Select entities (multi toggles) |
|
|
418
|
+
| `selectAll` | — | Select all nodes and edges |
|
|
419
|
+
| `clearSelection` | — | Deselect everything |
|
|
420
|
+
| `focus` | `{ entityId }` | Set keyboard/a11y focus |
|
|
421
|
+
| `clearFocus` | — | Clear focus |
|
|
314
422
|
|
|
315
423
|
### Box selection
|
|
316
424
|
|
|
317
|
-
| Event
|
|
318
|
-
|
|
319
|
-
| `selectionBoxStart` | `{ point, mode? }` | Begin box-select gesture
|
|
320
|
-
| `selectionBoxMove`
|
|
321
|
-
| `selectionBoxEnd`
|
|
425
|
+
| Event | Payload | Description |
|
|
426
|
+
| ------------------- | ------------------ | -------------------------------------- |
|
|
427
|
+
| `selectionBoxStart` | `{ point, mode? }` | Begin box-select gesture |
|
|
428
|
+
| `selectionBoxMove` | `{ point }` | Update box-select corner |
|
|
429
|
+
| `selectionBoxEnd` | — | Finalize: select intersecting entities |
|
|
322
430
|
|
|
323
431
|
### Viewport
|
|
324
432
|
|
|
325
|
-
| Event
|
|
326
|
-
|
|
327
|
-
| `setViewport`
|
|
328
|
-
| `setFitFrame`
|
|
329
|
-
| `panBy`
|
|
330
|
-
| `panStart`
|
|
331
|
-
| `pan`
|
|
332
|
-
| `panEnd`
|
|
333
|
-
| `zoomTo`
|
|
334
|
-
| `setMinZoom`
|
|
335
|
-
| `setMaxZoom`
|
|
336
|
-
| `updateViewportSize`
|
|
337
|
-
| `fitView`
|
|
338
|
-
| `pushViewport` / `popViewport` | —
|
|
339
|
-
| `setTranslateExtent`
|
|
340
|
-
| `setNodeExtent`
|
|
433
|
+
| Event | Payload | Description |
|
|
434
|
+
| ------------------------------ | ------------------------------------------------------------- | ------------------------------------------------------------- |
|
|
435
|
+
| `setViewport` | `{ x, y, zoom }` | Set viewport directly |
|
|
436
|
+
| `setFitFrame` | `{ frame: { x, y, width, height } \| null, preserveCenter? }` | Set or reset the persistent screen-space fit frame |
|
|
437
|
+
| `panBy` | `{ x, y }` | Pan by offset |
|
|
438
|
+
| `panStart` | `{ x, y }` | Begin pan gesture (screen coords) |
|
|
439
|
+
| `pan` | `{ x, y }` | Continue pan gesture (screen coords) |
|
|
440
|
+
| `panEnd` | — | End pan gesture |
|
|
441
|
+
| `zoomTo` | `{ zoom, center }` | Zoom to level around center point |
|
|
442
|
+
| `setMinZoom` | `{ minZoom }` | Set minimum zoom level |
|
|
443
|
+
| `setMaxZoom` | `{ maxZoom }` | Set maximum zoom level |
|
|
444
|
+
| `updateViewportSize` | `{ width, height, preserveCenter? }` | Report container size, optionally preserving its world center |
|
|
445
|
+
| `fitView` | `{ padding?, minZoom?, maxZoom?, nodes?, frame? }` | Fit all (or specific) nodes into a target frame |
|
|
446
|
+
| `pushViewport` / `popViewport` | — | Viewport stack for drill-in/out |
|
|
447
|
+
| `setTranslateExtent` | `{ extent: [Point, Point] \| null }` | Set pan boundary |
|
|
448
|
+
| `setNodeExtent` | `{ extent: [Point, Point] \| null }` | Set node drag boundary |
|
|
341
449
|
|
|
342
450
|
### Connection lifecycle
|
|
343
451
|
|
|
344
|
-
| Event
|
|
345
|
-
|
|
346
|
-
| `connectionStart`
|
|
347
|
-
| `connectionMove`
|
|
348
|
-
| `connectionEnd`
|
|
349
|
-
| `cancelConnection`
|
|
350
|
-
| `setConnectionClickStartHandle` | `{ nodeId, port } \| null`
|
|
452
|
+
| Event | Payload | Description |
|
|
453
|
+
| ------------------------------- | ---------------------------------------------------------------- | -------------------------------------------------------------- |
|
|
454
|
+
| `connectionStart` | `{ sourceId, sourcePort, position }` | Begin connection gesture |
|
|
455
|
+
| `connectionMove` | `{ position, targetId?, targetPort?, isValid?, invalidReason? }` | Update in-progress connection |
|
|
456
|
+
| `connectionEnd` | `{ target?: ConnectEndTarget }` | End connection gesture (emits `connectionEnded` with `status`) |
|
|
457
|
+
| `cancelConnection` | — | Cancel connection without emitting |
|
|
458
|
+
| `setConnectionClickStartHandle` | `{ nodeId, port } \| null` | Set/clear click-to-connect start handle |
|
|
351
459
|
|
|
352
460
|
### Resize lifecycle
|
|
353
461
|
|
|
354
|
-
| Event
|
|
355
|
-
|
|
356
|
-
| `resizeStart`
|
|
357
|
-
| `resizeMove`
|
|
358
|
-
| `resizeEnd`
|
|
359
|
-
| `resizeCancel` | —
|
|
462
|
+
| Event | Payload | Description |
|
|
463
|
+
| -------------- | ------------------------------ | ------------------------------------------------- |
|
|
464
|
+
| `resizeStart` | `{ id, handle: ResizeHandle }` | Begin resize gesture |
|
|
465
|
+
| `resizeMove` | `{ x, y }` | Update resize position |
|
|
466
|
+
| `resizeEnd` | — | Commit resize (bake position + custom dimensions) |
|
|
467
|
+
| `resizeCancel` | — | Cancel resize without committing |
|
|
360
468
|
|
|
361
469
|
### Layout
|
|
362
470
|
|
|
363
|
-
| Event
|
|
364
|
-
|
|
365
|
-
| `requestLayout`
|
|
366
|
-
| `applyLayoutResult`
|
|
367
|
-
| `updateMeasurements` | `{ measurements: Array<{ id, rect: Rect }> }`
|
|
368
|
-
| `bakeLabelPositions` | `{ positions: Map<edgeId, Point> }`
|
|
471
|
+
| Event | Payload | Description |
|
|
472
|
+
| -------------------- | ---------------------------------------------------- | -------------------------------------------- |
|
|
473
|
+
| `requestLayout` | `{ algorithm? }` | Request auto-layout (blocked during drag) |
|
|
474
|
+
| `applyLayoutResult` | `{ positions: Map<id, {x,y}>, edgeLabelPositions? }` | Apply layout positions, reset dx/dy |
|
|
475
|
+
| `updateMeasurements` | `{ measurements: Array<{ id, rect: Rect }> }` | Renderer reports measured world-space rects |
|
|
476
|
+
| `bakeLabelPositions` | `{ positions: Map<edgeId, Point> }` | Bake computed label positions into edge data |
|
|
369
477
|
|
|
370
478
|
### Configuration
|
|
371
479
|
|
|
372
|
-
| Event
|
|
373
|
-
|
|
374
|
-
| `setCanvasState`
|
|
375
|
-
| `setMode`
|
|
376
|
-
| `setDragThreshold`
|
|
377
|
-
| `setAutoPanOptions` | `{ autoPanOnDrag?, autoPanThreshold?, autoPanSpeed? }` | Configure auto-pan behavior
|
|
378
|
-
| `updateSettings`
|
|
379
|
-
| `setSnapToGrid`
|
|
380
|
-
| `setSnapLines`
|
|
381
|
-
| `setColorMode`
|
|
480
|
+
| Event | Payload | Description |
|
|
481
|
+
| ------------------- | ------------------------------------------------------ | --------------------------------------------------------------------- |
|
|
482
|
+
| `setCanvasState` | `{ state: CanvasState }` | Set low-level canvas gesture state |
|
|
483
|
+
| `setMode` | `{ mode: string }` | Set active profile mode |
|
|
484
|
+
| `setDragThreshold` | `{ dragThreshold }` | Set pixel threshold before drag starts |
|
|
485
|
+
| `setAutoPanOptions` | `{ autoPanOnDrag?, autoPanThreshold?, autoPanSpeed? }` | Configure auto-pan behavior |
|
|
486
|
+
| `updateSettings` | `Partial<FlowRuntimeSettings>` | Update runtime store settings in one event |
|
|
487
|
+
| `setSnapToGrid` | `{ enabled, grid? }` | Enable/disable grid snapping |
|
|
488
|
+
| `setSnapLines` | `{ enabled, threshold?, spacing? }` | Enable/disable Figma-style alignment guides |
|
|
489
|
+
| `setColorMode` | `{ colorMode: FlowColorMode }` | Set the preferred UI color mode (`'light'` \| `'dark'` \| `'system'`) |
|
|
382
490
|
|
|
383
491
|
### Navigation
|
|
384
492
|
|
|
385
|
-
| Event
|
|
386
|
-
|
|
387
|
-
| `updateParentNodeId` | `{ parentNodeId }`
|
|
388
|
-
| `setViewScope`
|
|
493
|
+
| Event | Payload | Description |
|
|
494
|
+
| -------------------- | ------------------------------------------------------ | ---------------------------------------------------------------- |
|
|
495
|
+
| `updateParentNodeId` | `{ parentNodeId }` | Drill into/out of nested node |
|
|
496
|
+
| `setViewScope` | `{ parentNodeId, depth, selection, visibleEntityIds }` | Low-level structural scope update; prefer `flow.view.setScope()` |
|
|
389
497
|
|
|
390
498
|
### Emitted events
|
|
391
499
|
|
|
392
500
|
Subscribe with `flow.on(type, listener)` or, for the low-level escape hatch, `flow.internals.store.on(type, listener)`.
|
|
393
501
|
|
|
394
|
-
| Event
|
|
395
|
-
|
|
396
|
-
| `graphChanged`
|
|
397
|
-
| `viewportChanged`
|
|
398
|
-
| `selectionChanged`
|
|
399
|
-
| `viewChanged`
|
|
400
|
-
| `entitiesDeleted`
|
|
401
|
-
| `connectionEnded`
|
|
402
|
-
| `dragStarted` / `dragMoved` / `dragEnded`
|
|
403
|
-
| `resizeStarted` / `resizeEnded`
|
|
404
|
-
| `connectStarted` / `connectMoved`
|
|
405
|
-
| `paneClicked` / `paneContextMenu`
|
|
406
|
-
| `entityClicked` / `entityDoubleClicked` / `entityContextMenu` | `FlowEntityGestureEvent` | Entity click, double-click, and context menu gestures
|
|
407
|
-
| `layoutRequested`
|
|
408
|
-
| `error`
|
|
502
|
+
| Event | Payload | Description |
|
|
503
|
+
| ------------------------------------------------------------- | ------------------------ | ------------------------------------------------------------------------------- |
|
|
504
|
+
| `graphChanged` | `{ graph, event }` | Graph changed after a mutation |
|
|
505
|
+
| `viewportChanged` | `{ viewport, event }` | Viewport changed |
|
|
506
|
+
| `selectionChanged` | `{ selection, event }` | Selection changed |
|
|
507
|
+
| `viewChanged` | `{ scope, event }` | Structural parent/depth changed |
|
|
508
|
+
| `entitiesDeleted` | `{ ids, event }` | Entities were deleted |
|
|
509
|
+
| `connectionEnded` | `ConnectionEndedEvent` | Connection gesture ended with `status: 'connected' \| 'cancelled' \| 'invalid'` |
|
|
510
|
+
| `dragStarted` / `dragMoved` / `dragEnded` | `FlowDrag*Event` | Drag gesture milestones; `dragMoved` fires per processed input event |
|
|
511
|
+
| `resizeStarted` / `resizeEnded` | `FlowResize*Event` | Resize gesture milestones |
|
|
512
|
+
| `connectStarted` / `connectMoved` | `FlowConnect*Event` | Connection gesture milestones; `connectMoved` fires per processed input event |
|
|
513
|
+
| `paneClicked` / `paneContextMenu` | `FlowPaneGestureEvent` | Pane click and context menu gestures |
|
|
514
|
+
| `entityClicked` / `entityDoubleClicked` / `entityContextMenu` | `FlowEntityGestureEvent` | Entity click, double-click, and context menu gestures |
|
|
515
|
+
| `layoutRequested` | `LayoutRequestedEvent` | Layout was requested |
|
|
516
|
+
| `error` | `{ error, event? }` | Flow error emitted |
|
|
409
517
|
|
|
410
518
|
## Undo / redo
|
|
411
519
|
|
|
@@ -414,10 +522,7 @@ Subscribe with `flow.on(type, listener)` or, for the low-level escape hatch, `fl
|
|
|
414
522
|
`@statelyai/flow` uses XState Store's `undoRedo()` extension with a whitelist of committed graph mutation events. Interaction-only events such as selection, panning, live drag updates, and connection hover state are intentionally skipped. Undo/redo restores graph and collapse history while preserving current viewport and valid session state. Cancelled drag/resize gestures create no history entry.
|
|
415
523
|
|
|
416
524
|
```ts
|
|
417
|
-
import {
|
|
418
|
-
createFlowStore,
|
|
419
|
-
createNode,
|
|
420
|
-
} from '@statelyai/flow';
|
|
525
|
+
import { createFlowStore, createNode } from '@statelyai/flow';
|
|
421
526
|
|
|
422
527
|
const store = createFlowStore(undefined, {
|
|
423
528
|
historyLimit: 200,
|
|
@@ -487,7 +592,9 @@ const fitted = viewportForBounds(contentRect, containerSize, {
|
|
|
487
592
|
const centered = viewportCenteredOn(canvasPoint, containerSize, 1, frame);
|
|
488
593
|
|
|
489
594
|
// Animation
|
|
490
|
-
const animation = animateViewport(store, fitted, {
|
|
595
|
+
const animation = animateViewport(store, fitted, {
|
|
596
|
+
lerp: 0.15,
|
|
597
|
+
});
|
|
491
598
|
await animation.done;
|
|
492
599
|
```
|
|
493
600
|
|
|
@@ -514,8 +621,8 @@ const statechartRouter: EdgeRouter<StatechartEdgeData> = (edge, context) => {
|
|
|
514
621
|
edge.data.transitionType === 'internal'
|
|
515
622
|
? 32
|
|
516
623
|
: siblingBounds.length
|
|
517
|
-
|
|
518
|
-
|
|
624
|
+
? 64
|
|
625
|
+
: 48;
|
|
519
626
|
return configureStepRouter({ offset })(edge, context);
|
|
520
627
|
};
|
|
521
628
|
```
|
|
@@ -532,8 +639,12 @@ Shape handlers own hit testing and edge anchor calculation. Register custom shap
|
|
|
532
639
|
import { registerShape, getShapeOrDefault } from '@statelyai/flow';
|
|
533
640
|
|
|
534
641
|
registerShape('hexagon', {
|
|
535
|
-
hitTest: (point, bounds) => {
|
|
536
|
-
|
|
642
|
+
hitTest: (point, bounds) => {
|
|
643
|
+
/* point-in-hexagon */
|
|
644
|
+
},
|
|
645
|
+
edgeAnchor: (bounds, direction) => {
|
|
646
|
+
/* anchor point */
|
|
647
|
+
},
|
|
537
648
|
});
|
|
538
649
|
|
|
539
650
|
// Built-in: 'rect', 'rounded', 'ellipse', 'diamond'
|
|
@@ -548,7 +659,12 @@ Figma-style alignment guides for drag operations. Exported:
|
|
|
548
659
|
|
|
549
660
|
```ts
|
|
550
661
|
import { getSnapLines } from '@statelyai/flow';
|
|
551
|
-
import type {
|
|
662
|
+
import type {
|
|
663
|
+
SnapLine,
|
|
664
|
+
SpacingGuide,
|
|
665
|
+
SnapResult,
|
|
666
|
+
SnapOptions,
|
|
667
|
+
} from '@statelyai/flow';
|
|
552
668
|
|
|
553
669
|
const result: SnapResult = getSnapLines(movingRect, otherRects, {
|
|
554
670
|
threshold: 5,
|
|
@@ -568,7 +684,11 @@ Enable via store: `store.trigger.setSnapLines({ enabled: true })`.
|
|
|
568
684
|
Behavior is controlled by predicate functions, not boolean flags:
|
|
569
685
|
|
|
570
686
|
```ts
|
|
571
|
-
import {
|
|
687
|
+
import {
|
|
688
|
+
defaultConfig,
|
|
689
|
+
readonlyConfig,
|
|
690
|
+
resolveBehavior,
|
|
691
|
+
} from '@statelyai/flow';
|
|
572
692
|
|
|
573
693
|
// Everything interactive
|
|
574
694
|
defaultConfig; // { selectable: () => true, draggable: () => true, connectable: () => true, ... }
|
|
@@ -594,9 +714,9 @@ const canDrag = resolveBehavior(config.draggable, someNode, flowState);
|
|
|
594
714
|
const store = createFlowStore(graph, {
|
|
595
715
|
minZoom: 0.1,
|
|
596
716
|
maxZoom: 4,
|
|
597
|
-
translateExtent: null,
|
|
598
|
-
nodeExtent: null,
|
|
599
|
-
dragThreshold: 3,
|
|
717
|
+
translateExtent: null, // [Point, Point] | null — pan boundary
|
|
718
|
+
nodeExtent: null, // [Point, Point] | null — node drag boundary
|
|
719
|
+
dragThreshold: 3, // px before drag starts
|
|
600
720
|
autoPanOnDrag: true,
|
|
601
721
|
autoPanThreshold: 40,
|
|
602
722
|
autoPanSpeed: 15,
|
|
@@ -607,7 +727,7 @@ const store = createFlowStore(graph, {
|
|
|
607
727
|
enableSpacingGuides: false,
|
|
608
728
|
connectOnClick: false,
|
|
609
729
|
labelAnchor: 'fixed',
|
|
610
|
-
boxSelectionTest: null,
|
|
730
|
+
boxSelectionTest: null, // custom node / edge-label bounds predicate
|
|
611
731
|
selectionMode: 'partial', // 'partial' | 'full'
|
|
612
732
|
historyLimit: 100,
|
|
613
733
|
mode: 'interactive',
|
|
@@ -616,6 +736,13 @@ const store = createFlowStore(graph, {
|
|
|
616
736
|
});
|
|
617
737
|
```
|
|
618
738
|
|
|
739
|
+
<!-- box-selection behavior from src/store/index.ts -->
|
|
740
|
+
|
|
741
|
+
Box selection tests node bounds and rendered edge-label bounds only. Crossing
|
|
742
|
+
an edge path does not select it, and edges without labels are not box-selected.
|
|
743
|
+
As a growing box captures entities, selection order records when each entity
|
|
744
|
+
first enters the box.
|
|
745
|
+
|
|
619
746
|
Use `flow.configure(patch)` for partial live updates. Use `flow.configure(current => completeNext)` for explicit full replacement and `flow.getConfiguration()` to capture a baseline. Store, engine, profile, mode, edge defaults, connection creation, and layout configuration share this path. Changing `historyLimit` after creation throws until XState exposes a supported live history-limit API.
|
|
620
747
|
|
|
621
748
|
`FlowProfile.resolvers`, `FlowProfile.policies`, and `FlowProfile.rules` are exported but experimental until the profile API settles.
|
|
@@ -643,11 +770,16 @@ store.trigger.createEdge({
|
|
|
643
770
|
id: 'e1',
|
|
644
771
|
sourceId: 'a',
|
|
645
772
|
targetId: 'b',
|
|
646
|
-
x: 0,
|
|
773
|
+
x: 0,
|
|
774
|
+
y: 0,
|
|
775
|
+
width: 0,
|
|
776
|
+
height: 0,
|
|
647
777
|
data: {},
|
|
648
778
|
label: {
|
|
649
|
-
x: 150,
|
|
650
|
-
|
|
779
|
+
x: 150,
|
|
780
|
+
y: 100,
|
|
781
|
+
width: 80,
|
|
782
|
+
height: 30,
|
|
651
783
|
autoSize: true, // optional: rendered DOM owns live width/height
|
|
652
784
|
data: { text: 'yes' },
|
|
653
785
|
},
|
|
@@ -684,6 +816,7 @@ renderer adapter (React, Vue, …) ← UI: components, DOM/SVG, event binding
|
|
|
684
816
|
**Design principle: the engine is a pure projection over the store.** DOM-specific concerns such as element measurement and container observation are intentionally out of this package. All interaction state (pan, drag, selection, connection) lives in the store and is driven by `store.trigger.*` events. The engine provides computed queries (edge paths, visual bounds, coordinate conversion, hit testing) derived from the current store snapshot.
|
|
685
817
|
|
|
686
818
|
This means:
|
|
819
|
+
|
|
687
820
|
- All state transitions are testable via `store.trigger.*` + snapshot assertions
|
|
688
821
|
- The store is the single source of truth
|
|
689
822
|
- The engine can be reconstructed from any store snapshot
|
|
@@ -701,8 +834,8 @@ store.trigger.dragEnd();
|
|
|
701
834
|
store.trigger.zoomTo({ zoom: 1.5, center: { x: 400, y: 300 } });
|
|
702
835
|
|
|
703
836
|
// Engine is purely derived:
|
|
704
|
-
const bounds = engine.getBounds('a');
|
|
705
|
-
const paths = engine.getAllEdgePaths();
|
|
837
|
+
const bounds = engine.getBounds('a'); // measured or model bounds
|
|
838
|
+
const paths = engine.getAllEdgePaths(); // computed from graph state
|
|
706
839
|
const canvas = engine.screenToCanvas({ x, y }); // from current viewport
|
|
707
840
|
```
|
|
708
841
|
|