@statelyai/flow 0.6.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 CHANGED
@@ -27,11 +27,37 @@ const flow = createFlow({
27
27
  graph: {
28
28
  direction: 'down',
29
29
  nodes: [
30
- { type: 'node', id: 'a', x: 0, y: 0, width: 200, height: 80, data: { label: 'Start' } },
31
- { type: 'node', id: 'b', x: 0, y: 150, width: 200, height: 80, data: { label: 'End' } },
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
- { type: 'edge', id: 'e1', sourceId: 'a', targetId: 'b', x: 0, y: 0, width: 0, height: 0, data: {} },
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
  });
@@ -73,7 +99,7 @@ await flow.layout.run(
73
99
  elkLayout({
74
100
  nodeSpacing: 80,
75
101
  rankSpacing: 120,
76
- }),
102
+ })
77
103
  );
78
104
  ```
79
105
 
@@ -157,10 +183,7 @@ visibility with visual projections/highlights. The default scope is
157
183
  `{ parentId: null, depth: null }`, preserving the full visible graph.
158
184
 
159
185
  ```ts
160
- flow.view.setScope(
161
- { parentId: 'compound', depth: 1 },
162
- { selection: 'prune' },
163
- );
186
+ flow.view.setScope({ parentId: 'compound', depth: 1 }, { selection: 'prune' });
164
187
 
165
188
  const { nodes, edges, boundaryEndpoints } = flow.view.getEntities();
166
189
  ```
@@ -189,19 +212,44 @@ then target that frame. The default remains the full, current viewport.
189
212
  ```ts
190
213
  flow.viewport.setFitFrame({ x: 320, y: 0, width: 880, height: 800 });
191
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
+
192
226
  flow.viewport.fit();
193
227
  flow.viewport.fitBounds(bounds);
194
228
  flow.viewport.centerOn({ x: 100, y: 50 });
195
229
  flow.viewport.zoomTo(1.5);
196
230
 
197
231
  flow.viewport.setFitFrame(null); // reset to the full viewport
232
+ unregister();
198
233
  ```
199
234
 
200
235
  Frames require finite `x`/`y` and positive finite dimensions. A `frame` on
201
236
  `fit()`, `fitBounds()`, or `centerOn()` overrides the registered frame for that
202
- call. `fit()` still composes with the current structural view and its `nodes`
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`
203
239
  subset. Animation resolves the same frame-aware target before it begins.
204
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
+
205
253
  Every viewport mutation (`set`, `panBy`, `zoomTo`, `zoomBy`, `fit`,
206
254
  `fitBounds`, and `centerOn`) returns `ViewportAnimationControls` with `cancel()`
207
255
  and a `done` promise. `done` resolves on completion or cancellation. Immediate
@@ -237,7 +285,15 @@ const graph = {
237
285
  width: 160,
238
286
  height: 60,
239
287
  ports: [
240
- { name: 'out', side: 'right', direction: 'out', x: 150, y: 25, width: 10, height: 10 },
288
+ {
289
+ name: 'out',
290
+ side: 'right',
291
+ direction: 'out',
292
+ x: 150,
293
+ y: 25,
294
+ width: 10,
295
+ height: 10,
296
+ },
241
297
  ],
242
298
  data: {},
243
299
  },
@@ -324,140 +380,140 @@ events.
324
380
 
325
381
  ### Graph mutations
326
382
 
327
- | Event | Payload | Description |
328
- |---|---|---|
329
- | `createNode` | `{ node: FlowNode }` | Add a node |
330
- | `deleteNode` | `{ id }` | Remove node + cascade edges |
331
- | `updateNode` | `{ id, patch? }` or `{ id, updater? }` | Patch/replace a node without changing id/type/parent |
332
- | `updateNodeData` | `{ id, data }` | Merge into node.data |
333
- | `createEdge` | `{ edge: FlowEdge }` | Add an edge |
334
- | `deleteEdge` | `{ id }` | Remove an edge |
335
- | `deleteEntities` | `{ nodeIds?, edgeIds? }` | Low-level synchronous deletion of a known entity set |
336
- | `updateEdge` | `{ id, patch? }` or `{ id, updater? }` | Patch/replace an edge without changing id/type/endpoints/ports |
337
- | `updateEdgeData` | `{ id, data }` | Merge into edge.data |
338
- | `deleteSelected` | — | Remove all selected nodes + edges |
339
- | `setGraph` | `{ graph: FlowGraph }` | Replace entire graph, reset interaction state |
340
- | `replaceGraph` | `{ graph, retention?, history?, origin?, transactionId? }` | Replace through the external synchronization policy used by `flow.replaceGraph()` |
341
- | `reset` | — | Reset store to initial state (preserves viewport size) |
342
- | `reparentNode` | `{ id, parentId }` | Move node to new parent |
343
- | `collapseNode` | `{ id }` | Hide descendants and derive folded boundary edges |
344
- | `expandNode` | `{ id }` | Show descendants again |
345
- | `reconnectEdge` | `{ edgeId, newSourceId?, newTargetId?, newSourcePort?, newTargetPort? }` | Rewire edge endpoints |
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 |
346
402
 
347
403
  ### Drag lifecycle
348
404
 
349
- | Event | Payload | Description |
350
- |---|---|---|
351
- | `dragStart` | `{ id }` | Begin dragging the selected entity |
352
- | `dragMove` | `{ dx, dy }` | Apply in-progress drag delta |
353
- | `dragEnd` | — | End drag gesture |
354
- | `commitDrag` | — | Bake `dx/dy` into committed positions |
355
- | `moveNodes` | `{ direction: Point, factor? }` | Move selected nodes by arrow key |
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 |
356
412
 
357
413
  ### Selection & focus
358
414
 
359
- | Event | Payload | Description |
360
- |---|---|---|
361
- | `select` | `{ ids, mode: 'single' \| 'multi' }` | Select entities (multi toggles) |
362
- | `selectAll` | — | Select all nodes and edges |
363
- | `clearSelection` | — | Deselect everything |
364
- | `focus` | `{ entityId }` | Set keyboard/a11y focus |
365
- | `clearFocus` | — | Clear focus |
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 |
366
422
 
367
423
  ### Box selection
368
424
 
369
- | Event | Payload | Description |
370
- |---|---|---|
371
- | `selectionBoxStart` | `{ point, mode? }` | Begin box-select gesture |
372
- | `selectionBoxMove` | `{ point }` | Update box-select corner |
373
- | `selectionBoxEnd` | — | Finalize: select intersecting entities |
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 |
374
430
 
375
431
  ### Viewport
376
432
 
377
- | Event | Payload | Description |
378
- |---|---|---|
379
- | `setViewport` | `{ x, y, zoom }` | Set viewport directly |
380
- | `setFitFrame` | `{ frame: { x, y, width, height } \| null }` | Set or reset the persistent screen-space fit frame |
381
- | `panBy` | `{ x, y }` | Pan by offset |
382
- | `panStart` | `{ x, y }` | Begin pan gesture (screen coords) |
383
- | `pan` | `{ x, y }` | Continue pan gesture (screen coords) |
384
- | `panEnd` | — | End pan gesture |
385
- | `zoomTo` | `{ zoom, center }` | Zoom to level around center point |
386
- | `setMinZoom` | `{ minZoom }` | Set minimum zoom level |
387
- | `setMaxZoom` | `{ maxZoom }` | Set maximum zoom level |
388
- | `updateViewportSize` | `{ width, height }` | Report container size |
389
- | `fitView` | `{ padding?, minZoom?, maxZoom?, nodes?, frame? }` | Fit all (or specific) nodes into a target frame |
390
- | `pushViewport` / `popViewport` | — | Viewport stack for drill-in/out |
391
- | `setTranslateExtent` | `{ extent: [Point, Point] \| null }` | Set pan boundary |
392
- | `setNodeExtent` | `{ extent: [Point, Point] \| null }` | Set node drag boundary |
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 |
393
449
 
394
450
  ### Connection lifecycle
395
451
 
396
- | Event | Payload | Description |
397
- |---|---|---|
398
- | `connectionStart` | `{ sourceId, sourcePort, position }` | Begin connection gesture |
399
- | `connectionMove` | `{ position, targetId?, targetPort?, isValid?, invalidReason? }` | Update in-progress connection |
400
- | `connectionEnd` | `{ target?: ConnectEndTarget }` | End connection gesture (emits `connectionEnded` with `status`) |
401
- | `cancelConnection` | — | Cancel connection without emitting |
402
- | `setConnectionClickStartHandle` | `{ nodeId, port } \| null` | Set/clear click-to-connect start handle |
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 |
403
459
 
404
460
  ### Resize lifecycle
405
461
 
406
- | Event | Payload | Description |
407
- |---|---|---|
408
- | `resizeStart` | `{ id, handle: ResizeHandle }` | Begin resize gesture |
409
- | `resizeMove` | `{ x, y }` | Update resize position |
410
- | `resizeEnd` | — | Commit resize (bake position + custom dimensions) |
411
- | `resizeCancel` | — | Cancel resize without committing |
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 |
412
468
 
413
469
  ### Layout
414
470
 
415
- | Event | Payload | Description |
416
- |---|---|---|
417
- | `requestLayout` | `{ algorithm? }` | Request auto-layout (blocked during drag) |
418
- | `applyLayoutResult` | `{ positions: Map<id, {x,y}>, edgeLabelPositions? }` | Apply layout positions, reset dx/dy |
419
- | `updateMeasurements` | `{ measurements: Array<{ id, rect: Rect }> }` | Renderer reports measured world-space rects |
420
- | `bakeLabelPositions` | `{ positions: Map<edgeId, Point> }` | Bake computed label positions into edge data |
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 |
421
477
 
422
478
  ### Configuration
423
479
 
424
- | Event | Payload | Description |
425
- |---|---|---|
426
- | `setCanvasState` | `{ state: CanvasState }` | Set low-level canvas gesture state |
427
- | `setMode` | `{ mode: string }` | Set active profile mode |
428
- | `setDragThreshold` | `{ dragThreshold }` | Set pixel threshold before drag starts |
429
- | `setAutoPanOptions` | `{ autoPanOnDrag?, autoPanThreshold?, autoPanSpeed? }` | Configure auto-pan behavior |
430
- | `updateSettings` | `Partial<FlowRuntimeSettings>` | Update runtime store settings in one event |
431
- | `setSnapToGrid` | `{ enabled, grid? }` | Enable/disable grid snapping |
432
- | `setSnapLines` | `{ enabled, threshold?, spacing? }` | Enable/disable Figma-style alignment guides |
433
- | `setColorMode` | `{ colorMode: FlowColorMode }` | Set the preferred UI color mode (`'light'` \| `'dark'` \| `'system'`) |
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'`) |
434
490
 
435
491
  ### Navigation
436
492
 
437
- | Event | Payload | Description |
438
- |---|---|---|
439
- | `updateParentNodeId` | `{ parentNodeId }` | Drill into/out of nested node |
440
- | `setViewScope` | `{ parentNodeId, depth, selection, visibleEntityIds }` | Low-level structural scope update; prefer `flow.view.setScope()` |
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()` |
441
497
 
442
498
  ### Emitted events
443
499
 
444
500
  Subscribe with `flow.on(type, listener)` or, for the low-level escape hatch, `flow.internals.store.on(type, listener)`.
445
501
 
446
- | Event | Payload | Description |
447
- |---|---|---|
448
- | `graphChanged` | `{ graph, event }` | Graph changed after a mutation |
449
- | `viewportChanged` | `{ viewport, event }` | Viewport changed |
450
- | `selectionChanged` | `{ selection, event }` | Selection changed |
451
- | `viewChanged` | `{ scope, event }` | Structural parent/depth changed |
452
- | `entitiesDeleted` | `{ ids, event }` | Entities were deleted |
453
- | `connectionEnded` | `ConnectionEndedEvent` | Connection gesture ended with `status: 'connected' \| 'cancelled' \| 'invalid'` |
454
- | `dragStarted` / `dragMoved` / `dragEnded` | `FlowDrag*Event` | Drag gesture milestones; `dragMoved` fires per processed input event |
455
- | `resizeStarted` / `resizeEnded` | `FlowResize*Event` | Resize gesture milestones |
456
- | `connectStarted` / `connectMoved` | `FlowConnect*Event` | Connection gesture milestones; `connectMoved` fires per processed input event |
457
- | `paneClicked` / `paneContextMenu` | `FlowPaneGestureEvent` | Pane click and context menu gestures |
458
- | `entityClicked` / `entityDoubleClicked` / `entityContextMenu` | `FlowEntityGestureEvent` | Entity click, double-click, and context menu gestures |
459
- | `layoutRequested` | `LayoutRequestedEvent` | Layout was requested |
460
- | `error` | `{ error, event? }` | Flow error emitted |
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 |
461
517
 
462
518
  ## Undo / redo
463
519
 
@@ -466,10 +522,7 @@ Subscribe with `flow.on(type, listener)` or, for the low-level escape hatch, `fl
466
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.
467
523
 
468
524
  ```ts
469
- import {
470
- createFlowStore,
471
- createNode,
472
- } from '@statelyai/flow';
525
+ import { createFlowStore, createNode } from '@statelyai/flow';
473
526
 
474
527
  const store = createFlowStore(undefined, {
475
528
  historyLimit: 200,
@@ -539,7 +592,9 @@ const fitted = viewportForBounds(contentRect, containerSize, {
539
592
  const centered = viewportCenteredOn(canvasPoint, containerSize, 1, frame);
540
593
 
541
594
  // Animation
542
- const animation = animateViewport(store, fitted, { duration: 300 });
595
+ const animation = animateViewport(store, fitted, {
596
+ lerp: 0.15,
597
+ });
543
598
  await animation.done;
544
599
  ```
545
600
 
@@ -566,8 +621,8 @@ const statechartRouter: EdgeRouter<StatechartEdgeData> = (edge, context) => {
566
621
  edge.data.transitionType === 'internal'
567
622
  ? 32
568
623
  : siblingBounds.length
569
- ? 64
570
- : 48;
624
+ ? 64
625
+ : 48;
571
626
  return configureStepRouter({ offset })(edge, context);
572
627
  };
573
628
  ```
@@ -584,8 +639,12 @@ Shape handlers own hit testing and edge anchor calculation. Register custom shap
584
639
  import { registerShape, getShapeOrDefault } from '@statelyai/flow';
585
640
 
586
641
  registerShape('hexagon', {
587
- hitTest: (point, bounds) => { /* point-in-hexagon */ },
588
- edgeAnchor: (bounds, direction) => { /* anchor point */ },
642
+ hitTest: (point, bounds) => {
643
+ /* point-in-hexagon */
644
+ },
645
+ edgeAnchor: (bounds, direction) => {
646
+ /* anchor point */
647
+ },
589
648
  });
590
649
 
591
650
  // Built-in: 'rect', 'rounded', 'ellipse', 'diamond'
@@ -600,7 +659,12 @@ Figma-style alignment guides for drag operations. Exported:
600
659
 
601
660
  ```ts
602
661
  import { getSnapLines } from '@statelyai/flow';
603
- import type { SnapLine, SpacingGuide, SnapResult, SnapOptions } from '@statelyai/flow';
662
+ import type {
663
+ SnapLine,
664
+ SpacingGuide,
665
+ SnapResult,
666
+ SnapOptions,
667
+ } from '@statelyai/flow';
604
668
 
605
669
  const result: SnapResult = getSnapLines(movingRect, otherRects, {
606
670
  threshold: 5,
@@ -620,7 +684,11 @@ Enable via store: `store.trigger.setSnapLines({ enabled: true })`.
620
684
  Behavior is controlled by predicate functions, not boolean flags:
621
685
 
622
686
  ```ts
623
- import { defaultConfig, readonlyConfig, resolveBehavior } from '@statelyai/flow';
687
+ import {
688
+ defaultConfig,
689
+ readonlyConfig,
690
+ resolveBehavior,
691
+ } from '@statelyai/flow';
624
692
 
625
693
  // Everything interactive
626
694
  defaultConfig; // { selectable: () => true, draggable: () => true, connectable: () => true, ... }
@@ -646,9 +714,9 @@ const canDrag = resolveBehavior(config.draggable, someNode, flowState);
646
714
  const store = createFlowStore(graph, {
647
715
  minZoom: 0.1,
648
716
  maxZoom: 4,
649
- translateExtent: null, // [Point, Point] | null — pan boundary
650
- nodeExtent: null, // [Point, Point] | null — node drag boundary
651
- dragThreshold: 3, // px before drag starts
717
+ translateExtent: null, // [Point, Point] | null — pan boundary
718
+ nodeExtent: null, // [Point, Point] | null — node drag boundary
719
+ dragThreshold: 3, // px before drag starts
652
720
  autoPanOnDrag: true,
653
721
  autoPanThreshold: 40,
654
722
  autoPanSpeed: 15,
@@ -659,7 +727,7 @@ const store = createFlowStore(graph, {
659
727
  enableSpacingGuides: false,
660
728
  connectOnClick: false,
661
729
  labelAnchor: 'fixed',
662
- boxSelectionTest: null,
730
+ boxSelectionTest: null, // custom node / edge-label bounds predicate
663
731
  selectionMode: 'partial', // 'partial' | 'full'
664
732
  historyLimit: 100,
665
733
  mode: 'interactive',
@@ -668,6 +736,13 @@ const store = createFlowStore(graph, {
668
736
  });
669
737
  ```
670
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
+
671
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.
672
747
 
673
748
  `FlowProfile.resolvers`, `FlowProfile.policies`, and `FlowProfile.rules` are exported but experimental until the profile API settles.
@@ -695,11 +770,16 @@ store.trigger.createEdge({
695
770
  id: 'e1',
696
771
  sourceId: 'a',
697
772
  targetId: 'b',
698
- x: 0, y: 0, width: 0, height: 0,
773
+ x: 0,
774
+ y: 0,
775
+ width: 0,
776
+ height: 0,
699
777
  data: {},
700
778
  label: {
701
- x: 150, y: 100,
702
- width: 80, height: 30,
779
+ x: 150,
780
+ y: 100,
781
+ width: 80,
782
+ height: 30,
703
783
  autoSize: true, // optional: rendered DOM owns live width/height
704
784
  data: { text: 'yes' },
705
785
  },
@@ -736,6 +816,7 @@ renderer adapter (React, Vue, …) ← UI: components, DOM/SVG, event binding
736
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.
737
817
 
738
818
  This means:
819
+
739
820
  - All state transitions are testable via `store.trigger.*` + snapshot assertions
740
821
  - The store is the single source of truth
741
822
  - The engine can be reconstructed from any store snapshot
@@ -753,8 +834,8 @@ store.trigger.dragEnd();
753
834
  store.trigger.zoomTo({ zoom: 1.5, center: { x: 400, y: 300 } });
754
835
 
755
836
  // Engine is purely derived:
756
- const bounds = engine.getBounds('a'); // measured or model bounds
757
- const paths = engine.getAllEdgePaths(); // computed from graph state
837
+ const bounds = engine.getBounds('a'); // measured or model bounds
838
+ const paths = engine.getAllEdgePaths(); // computed from graph state
758
839
  const canvas = engine.screenToCanvas({ x, y }); // from current viewport
759
840
  ```
760
841