@statelyai/flow 0.9.1 → 0.11.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 +63 -25
- package/dist/esm/index.d.ts +36 -11
- package/dist/esm/index.js +95 -63
- package/dist/esm/layout/elk.js +3 -0
- package/dist/esm/layout/index.d.ts +2 -1
- package/dist/esm/layout/index.js +2 -1
- package/dist/esm/layout/stately.d.ts +8 -0
- package/dist/esm/layout/stately.js +425 -0
- package/package.json +12 -1
package/README.md
CHANGED
|
@@ -83,31 +83,61 @@ const selectedBounds = flow.getSelectionBounds();
|
|
|
83
83
|
Install only the engine you use:
|
|
84
84
|
|
|
85
85
|
```bash
|
|
86
|
-
npm install @statelyai/flow
|
|
86
|
+
npm install @statelyai/flow @statelyai/layout
|
|
87
87
|
```
|
|
88
88
|
|
|
89
|
-
|
|
90
|
-
|
|
89
|
+
`@statelyai/layout` is the first-class engine: both packages operate on
|
|
90
|
+
`@statelyai/graph`, so the adapter preserves graph-native nodes, ports, labels,
|
|
91
|
+
and complete edge routes. Layout engines are optional peer dependencies; use
|
|
92
|
+
`elkjs` or `@dagrejs/dagre` only for their compatibility adapters.
|
|
91
93
|
|
|
92
94
|
```ts
|
|
93
95
|
import { createFlow } from '@statelyai/flow';
|
|
94
|
-
import {
|
|
96
|
+
import { statelyLayout } from '@statelyai/flow/layout';
|
|
97
|
+
|
|
98
|
+
const flow = createFlow({
|
|
99
|
+
graph,
|
|
100
|
+
layout: statelyLayout({
|
|
101
|
+
direction: 'right',
|
|
102
|
+
spacing: { node: 80, layer: 120 },
|
|
103
|
+
}),
|
|
104
|
+
});
|
|
95
105
|
|
|
96
|
-
|
|
106
|
+
await flow.layout.run();
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
<!-- adapter contracts from src/layout/stately.ts src/layout/elk.ts src/layout/dagre.ts and src/layout/shared.ts -->
|
|
110
|
+
|
|
111
|
+
`statelyLayout()` uses `@statelyai/layout`'s native layered algorithm. It
|
|
112
|
+
supports flat and compound graphs, ports, labels, cycles, four directions,
|
|
113
|
+
constraints, advanced layered settings, and replaceable layout phases. Flow
|
|
114
|
+
resolves measured node bounds before the run, converts parent-relative compound
|
|
115
|
+
geometry back to its absolute coordinate model, and applies complete routed
|
|
116
|
+
`points` as authoritative graph geometry. Factory and run scopes induce a
|
|
117
|
+
smaller graph before layout; fixed and pinned entities stay in the input but are
|
|
118
|
+
omitted from returned geometry.
|
|
97
119
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
);
|
|
120
|
+
```ts
|
|
121
|
+
await flow.layout.run(statelyLayout({ scope: { ids: candidateIds } }), {
|
|
122
|
+
scope: { parentId: 'group', depth: 1 },
|
|
123
|
+
fixedEntityIds: new Set(['pinned-node']),
|
|
124
|
+
source: 'editor',
|
|
125
|
+
});
|
|
104
126
|
```
|
|
105
127
|
|
|
106
|
-
|
|
128
|
+
The ELK adapter remains available for migration and comparison:
|
|
129
|
+
|
|
130
|
+
```ts
|
|
131
|
+
import { elkLayout } from '@statelyai/flow/layout/elk';
|
|
132
|
+
|
|
133
|
+
await flow.layout.run(elkLayout({ nodeSpacing: 80, rankSpacing: 120 }));
|
|
134
|
+
```
|
|
107
135
|
|
|
108
136
|
`elkLayout()` supports compound nodes, ports, edge labels, graph direction,
|
|
109
137
|
per-group child direction, measured bounds via `getBounds`, and scoped
|
|
110
|
-
incremental layout with `scope: { ids }`.
|
|
138
|
+
incremental layout with `scope: { ids }`. If an explicit group direction needs a
|
|
139
|
+
local repair pass, it retains `elk.layered.cycleBreaking.strategy`: direct `node`
|
|
140
|
+
options take precedence over `node.layoutOptions`, then `graph` options.
|
|
111
141
|
Results include computed node sizes and bounds, label bounds, routed interior
|
|
112
142
|
waypoints, source metadata, and diagnostics. Hierarchical ELK runs repair
|
|
113
143
|
invalid nested label positions by choosing the nearest node-free position, keep
|
|
@@ -123,14 +153,6 @@ child ranks without changing the root direction. Scoped passes send only
|
|
|
123
153
|
the induced graph to ELK; fixed and pinned entities remain in the input but are
|
|
124
154
|
omitted from returned geometry.
|
|
125
155
|
|
|
126
|
-
```ts
|
|
127
|
-
await flow.layout.run(elkLayout({ scope: { ids: candidateIds } }), {
|
|
128
|
-
scope: { parentId: 'group', depth: 1 },
|
|
129
|
-
fixedEntityIds: new Set(['pinned-node']),
|
|
130
|
-
source: 'editor',
|
|
131
|
-
});
|
|
132
|
-
```
|
|
133
|
-
|
|
134
156
|
`dagreLayout()` flattens hierarchy and rejects scoped layout. It returns node
|
|
135
157
|
sizes, node bounds, and edge-label bounds without fabricating unsupported route
|
|
136
158
|
waypoints.
|
|
@@ -148,7 +170,7 @@ The canonical data model is `VisualGraph` from `@statelyai/graph`. Flow extends
|
|
|
148
170
|
<!-- flow entity types from src/types.ts -->
|
|
149
171
|
|
|
150
172
|
- **`FlowNode`** — `VisualNode` + `{ kind, dx, dy, style, ports, autoSize, autoSizeAnchor, selectionBounds, resize, hidden, selectable, draggable, connectable, deletable, resizable }` for application-defined rendering kinds, drag offsets, DOM-owned sizing, anchor policy, optional marquee hit geometry, style overrides, resize constraints, and per-entity behavior. Keep the structural `type` equal to `"node"`; use `kind` for variants such as `state` or `annotation`.
|
|
151
|
-
- **`FlowEdge`** — `VisualEdge` + `{ label, waypoints, svgPath, sourcePort, targetPort, kind, style, labelAnchor }` for edge labels, editable router via-points, exact SVG geometry, port binding, and edge styling. Canonical `VisualEdge.points` plus `routing` are an authoritative precomputed route and bypass Flow routers; an optional `svgPath` controls exact SVG paint while points remain authoritative for interaction geometry. Reconnects, node geometry updates, committed drags, and layout application clear stale precomputed routes; layout
|
|
173
|
+
- **`FlowEdge`** — `VisualEdge` + `{ label, waypoints, svgPath, sourcePort, targetPort, kind, style, labelAnchor }` for edge labels, editable router via-points, exact SVG geometry, port binding, and edge styling. Canonical `VisualEdge.points` plus `routing` are an authoritative precomputed route and bypass Flow routers; an optional `svgPath` controls exact SVG paint while points remain authoritative for interaction geometry. Reconnects, node geometry updates, committed drags, and layout application clear stale precomputed routes; layout results may provide either interior router waypoints or a complete authoritative route. `label.autoSize` makes rendered DOM own transient label dimensions without overwriting authored fallback `width`/`height`; inherited edge `x/y/width/height` are reserved, while positioned edge content belongs on `label`.
|
|
152
174
|
- **`FlowGraph`** — `VisualGraph` with `FlowNode[]` and `FlowEdge[]`
|
|
153
175
|
- **`FlowEntityRef`** — descriptor for a node, edge, port, or block resolved by id. `FlowAddressable` is a deprecated alias.
|
|
154
176
|
|
|
@@ -162,7 +184,9 @@ measurements remain derived session state: they emit no graph commit, create no
|
|
|
162
184
|
undo entry, and do not overwrite authored dimensions. Auto-size label
|
|
163
185
|
measurements drive routing, graph/selection bounds, hit testing, snapping,
|
|
164
186
|
culling, and toolbar anchors; surviving measurements remain stable across
|
|
165
|
-
`replaceGraph()` calls.
|
|
187
|
+
`replaceGraph()` calls. Current graph geometry always supplies entity and label
|
|
188
|
+
positions, so stale DOM measurements cannot move bounds or toolbar anchors back
|
|
189
|
+
to a pre-drag location.
|
|
166
190
|
|
|
167
191
|
## Graph projections
|
|
168
192
|
|
|
@@ -245,6 +269,15 @@ flow.viewport.setFitFrame(null); // reset to the full viewport
|
|
|
245
269
|
unregister();
|
|
246
270
|
```
|
|
247
271
|
|
|
272
|
+
Set a default animation for all viewport commands through Flow settings. An
|
|
273
|
+
animation mode passed to an individual command overrides the default mode:
|
|
274
|
+
|
|
275
|
+
```ts
|
|
276
|
+
const flow = createFlow({
|
|
277
|
+
store: { viewportAnimation: { lerp: 0.15 } },
|
|
278
|
+
});
|
|
279
|
+
```
|
|
280
|
+
|
|
248
281
|
Frames require finite `x`/`y` and positive finite dimensions. A `frame` on
|
|
249
282
|
`fit()`, `fitBounds()`, or `centerOn()` overrides the registered frame for that
|
|
250
283
|
call. `preserveCenter` shifts the viewport by the fit-frame center delta, so
|
|
@@ -615,7 +648,7 @@ await animation.done;
|
|
|
615
648
|
|
|
616
649
|
<!-- edge routers from src/routing/index.ts -->
|
|
617
650
|
|
|
618
|
-
Four built-in routers. All return `PathData` (points + source/target direction). A custom router may also return `svgPath` to preserve rounded or otherwise custom SVG geometry; `points` remain required for bounds and endpoint handles, and exported `pathToSVG` safely prefers a finite override containing only SVG path commands and numeric parameters. Canonical graph `edge.points` are different from `waypoints`: they are a complete authoritative endpoint-to-endpoint route, interpreted by `edge.routing` (`polyline`, `orthogonal`, or chained `splines`) and never sent through a Flow router or split around a label. An optional edge `svgPath` preserves exact SVG paint while the authoritative points drive endpoints, bounds, hit testing, culling, transient DOM updates, and export. Core endpoint-geometry mutations invalidate precomputed route fields; layout
|
|
651
|
+
Four built-in routers. All return `PathData` (points + source/target direction). A custom router may also return `svgPath` to preserve rounded or otherwise custom SVG geometry; `points` remain required for bounds and endpoint handles, and exported `pathToSVG` safely prefers a finite override containing only SVG path commands and numeric parameters. Canonical graph `edge.points` are different from `waypoints`: they are a complete authoritative endpoint-to-endpoint route, interpreted by `edge.routing` (`polyline`, `orthogonal`, or chained `splines`) and never sent through a Flow router or split around a label. An optional edge `svgPath` preserves exact SVG paint while the authoritative points drive endpoints, bounds, hit testing, culling, transient DOM updates, and export. Core endpoint-geometry mutations invalidate precomputed route fields; layout results may atomically replace them with either interior router waypoints or complete `points` plus `routing`. Edge `waypoints` remain ordered interior router inputs passed through `EdgeRouterContext`; built-in routers honor them. Custom `EdgeRouter`s receive the full typed edge plus the exact canonical or projection `graph` currently being routed and a detached, read-only `getEntityBounds(id)` lookup for live node/edge-label geometry. The lookup never routes another edge. Use `configureBezierRouter(options)`, `configureStepRouter(options)`, and `configureAvoidRouter(options)` for customized built-in router variants. `avoidRouter` is opt-in and routes orthogonal polylines around sibling node obstacles. Set `engine.edgeRouterDependencies: 'endpoints'` only when a custom router does not inspect unrelated graph entities, bounds, or obstacles; Flow can then retain unaffected routes after local geometry changes. The safe default is `'graph'`.
|
|
619
652
|
|
|
620
653
|
Router obstacles exclude the source, target, and their ancestor groups, so an
|
|
621
654
|
edge crossing a hierarchy boundary can pass through its endpoint container.
|
|
@@ -754,6 +787,11 @@ const store = createFlowStore(graph, {
|
|
|
754
787
|
});
|
|
755
788
|
```
|
|
756
789
|
|
|
790
|
+
Auto-pan is pointer-driven: while a drag, connection, or resize gesture is
|
|
791
|
+
active, the pointer staying within `autoPanThreshold` of an edge keeps producing
|
|
792
|
+
a per-frame pan delta, including when entity bounds are clamped or lag behind
|
|
793
|
+
the gesture.
|
|
794
|
+
|
|
757
795
|
<!-- box-selection behavior from src/store/index.ts -->
|
|
758
796
|
|
|
759
797
|
Box selection tests node bounds and rendered edge-label bounds only. Crossing
|
|
@@ -857,7 +895,7 @@ store.trigger.dragEnd();
|
|
|
857
895
|
store.trigger.zoomTo({ zoom: 1.5, center: { x: 400, y: 300 } });
|
|
858
896
|
|
|
859
897
|
// Engine is purely derived:
|
|
860
|
-
const bounds = engine.getBounds('a'); //
|
|
898
|
+
const bounds = engine.getBounds('a'); // current model position + measured size
|
|
861
899
|
const paths = engine.getAllEdgePaths(); // computed from graph state
|
|
862
900
|
const canvas = engine.screenToCanvas({ x, y }); // from current viewport
|
|
863
901
|
```
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -1888,18 +1888,17 @@ declare function defaultModesForContext(context: FlowStoreContext, keymap?: Part
|
|
|
1888
1888
|
declare function profileModesForContext(profile: FlowProfile): (context: FlowStoreContext) => FlowInputMode[];
|
|
1889
1889
|
declare function profilePoliciesForContext(profile: FlowProfile): (context: FlowStoreContext) => FlowPolicies;
|
|
1890
1890
|
/**
|
|
1891
|
-
* Per-frame auto-pan step while a drag
|
|
1892
|
-
* container edge. Returns the `calcAutoPan` screen-space
|
|
1893
|
-
* `panBy`), or null when auto-pan should not run. Adapters
|
|
1894
|
-
* frame ticker while a gesture session is active and re-send
|
|
1895
|
-
* pointer afterwards so the dragged entity follows the panned
|
|
1891
|
+
* Per-frame, pointer-driven auto-pan step while a drag, connection, or resize
|
|
1892
|
+
* gesture is near the container edge. Returns the `calcAutoPan` screen-space
|
|
1893
|
+
* delta (negate it for `panBy`), or null when auto-pan should not run. Adapters
|
|
1894
|
+
* call this from a frame ticker while a gesture session is active and re-send
|
|
1895
|
+
* the stationary pointer afterwards so the dragged entity follows the panned
|
|
1896
|
+
* canvas.
|
|
1896
1897
|
*/
|
|
1897
1898
|
declare function getAutoPanDelta(context: FlowStoreContext, screenPoint: Point,
|
|
1898
1899
|
/**
|
|
1899
|
-
*
|
|
1900
|
-
*
|
|
1901
|
-
* actually reaches that viewport edge. Prevents pointless scrolling when a
|
|
1902
|
-
* clamped child is pinned mid-canvas while the pointer overshoots.
|
|
1900
|
+
* Retained for source compatibility. Auto-pan is intentionally driven by the
|
|
1901
|
+
* pointer position, not by resolved entity bounds.
|
|
1903
1902
|
*/
|
|
1904
1903
|
engine?: FlowEngine): Point | null;
|
|
1905
1904
|
//#endregion
|
|
@@ -2075,6 +2074,8 @@ type FlowStoreContext = {
|
|
|
2075
2074
|
} | null;
|
|
2076
2075
|
panOrigin: Point | null;
|
|
2077
2076
|
panViewportOrigin: Viewport | null;
|
|
2077
|
+
/** Default animation applied to viewport commands unless overridden per call. */
|
|
2078
|
+
viewportAnimation: ViewportAnimationOptions | null;
|
|
2078
2079
|
resizingEntityId: string | null;
|
|
2079
2080
|
resizeHandle: ResizeHandle | null;
|
|
2080
2081
|
/** Two opposite corners during resize: [anchor, moving]. Derived bounds = min/max of these. */
|
|
@@ -2136,6 +2137,8 @@ type FlowStoreOptions = {
|
|
|
2136
2137
|
autoPanOnDrag?: boolean;
|
|
2137
2138
|
autoPanThreshold?: number;
|
|
2138
2139
|
autoPanSpeed?: number;
|
|
2140
|
+
/** Default animation applied to viewport commands unless overridden per call. */
|
|
2141
|
+
viewportAnimation?: ViewportAnimationOptions | null;
|
|
2139
2142
|
snapToGrid?: boolean;
|
|
2140
2143
|
snapGrid?: [number, number];
|
|
2141
2144
|
enableSnapLines?: boolean;
|
|
@@ -2163,7 +2166,7 @@ type FlowStoreOptions = {
|
|
|
2163
2166
|
edges: FlowEdge[];
|
|
2164
2167
|
});
|
|
2165
2168
|
};
|
|
2166
|
-
type FlowRuntimeSettings = Pick<FlowStoreOptions, 'dragThreshold' | 'constrainNodeMovement' | 'autoPanOnDrag' | 'autoPanThreshold' | 'autoPanSpeed' | 'enableSnapLines' | 'snapThreshold' | 'enableSpacingGuides' | 'boxSelectionTest' | 'labelAnchor'>;
|
|
2169
|
+
type FlowRuntimeSettings = Pick<FlowStoreOptions, 'dragThreshold' | 'constrainNodeMovement' | 'autoPanOnDrag' | 'autoPanThreshold' | 'autoPanSpeed' | 'viewportAnimation' | 'enableSnapLines' | 'snapThreshold' | 'enableSpacingGuides' | 'boxSelectionTest' | 'labelAnchor'>;
|
|
2167
2170
|
type LayoutRequestedEvent = {
|
|
2168
2171
|
algorithm: string;
|
|
2169
2172
|
graph: FlowGraph;
|
|
@@ -2822,9 +2825,14 @@ type LayoutDiagnostic = {
|
|
|
2822
2825
|
severity?: 'info' | 'warning' | 'error';
|
|
2823
2826
|
code?: string;
|
|
2824
2827
|
entityId?: string;
|
|
2828
|
+
entityIds?: readonly string[];
|
|
2829
|
+
phase?: string;
|
|
2825
2830
|
};
|
|
2826
2831
|
type LayoutEdgeRoute = {
|
|
2827
2832
|
waypoints: readonly Point[];
|
|
2833
|
+
} | {
|
|
2834
|
+
points: readonly Point[];
|
|
2835
|
+
routing?: EdgeRouting;
|
|
2828
2836
|
};
|
|
2829
2837
|
type LayoutResult = {
|
|
2830
2838
|
positions: ReadonlyMap<string, Point>;
|
|
@@ -3428,6 +3436,23 @@ type MinimapProjection = {
|
|
|
3428
3436
|
toCanvas(point: Point): Point;
|
|
3429
3437
|
rectToMinimap(rect: Rect): Rect;
|
|
3430
3438
|
};
|
|
3439
|
+
type MinimapViewportCenterOptions = {
|
|
3440
|
+
/** Pointer position in canvas space. */
|
|
3441
|
+
point: Point;
|
|
3442
|
+
/** Pointer offset from the lens center, captured at pointer-down. */
|
|
3443
|
+
grabOffset?: Point;
|
|
3444
|
+
/** Graph bounds that minimap-driven navigation may move around. */
|
|
3445
|
+
contentBounds: Rect;
|
|
3446
|
+
/** Current visible canvas bounds; only its size is used. */
|
|
3447
|
+
viewportBounds: Rect;
|
|
3448
|
+
};
|
|
3449
|
+
/**
|
|
3450
|
+
* Resolve a minimap pointer to a bounded viewport center.
|
|
3451
|
+
*
|
|
3452
|
+
* This constraint applies only to minimap navigation. Each axis lets the lens
|
|
3453
|
+
* move fully past the graph, stopping when its nearest edge reaches the graph.
|
|
3454
|
+
*/
|
|
3455
|
+
declare function getMinimapViewportCenter(options: MinimapViewportCenterOptions): Point;
|
|
3431
3456
|
declare function getMinimapProjection(options: MinimapProjectionOptions): MinimapProjection;
|
|
3432
3457
|
//#endregion
|
|
3433
3458
|
//#region src/graph-index.d.ts
|
|
@@ -3480,4 +3505,4 @@ declare const readonlyConfig: Partial<FlowConfig>;
|
|
|
3480
3505
|
*/
|
|
3481
3506
|
declare function resolveBehavior<TEntity, TState>(predicate: ((entity: TEntity, state: TState) => boolean) | false | undefined, entity: TEntity, state: TState, defaultValue?: boolean): boolean;
|
|
3482
3507
|
//#endregion
|
|
3483
|
-
export { type ActiveGraphProjection, type AnchorSpec, type AnchorTransform, type AnimateViewportOptions, type AutoLayoutState, type AvoidRouterOptions, type BehaviorPredicate, type BezierRouterOptions, type BoxSelectModeOptions, type BoxSelectionTest, CONNECTION_PREVIEW_EDGE_ID, CONNECTION_PREVIEW_NODE_ID, type CanvasState, type ComposedGraphProjectionAttrs, type ConnectEndTarget, type ConnectModeOptions, type ConnectionCandidate, type ConnectionCandidateOptions, type ConnectionCandidateSource, type ConnectionEndedEvent, type ConnectionPreviewData, type ConnectionPreviewGraphOptions, type ConnectionState, type ConnectionValidationContext, type ConnectionValidationResult, type CreateEdgeInput, type CreateFlowOptions, type CreateNodeInput, type Direction, type EdgeAdjacencyIndex, type EdgeDirection, type EdgePathData, type EdgePathOptions, type EdgeRouter, type EdgeRouterContext, type EdgeRouterGraph, type EdgeRouting, type EdgeSourceBoundsContext, type EntityRect, type EntityVisualState, type FitViewExclusion, type FitViewExclusionSide, type FitViewOptions, type FlowAbortSignal, type FlowAddressable, type FlowAutoSizeAnchor, type FlowCapabilityCommand, type FlowCapabilityResult, type FlowChangeSet, type FlowColorMode, type FlowCommand, type FlowCommitEvent, type FlowConfig, type FlowConfiguration, type FlowConfigureOptions, type FlowConnectMovedEvent, type FlowConnectStartedEvent, type FlowConnection, type FlowConnectionMode, type FlowConnectionOptions, type FlowConnectionsApi, type FlowContent, type FlowContentApi, type FlowContentInsertResult, type FlowController, type FlowCreateIdContext, type FlowDataSchema, type FlowDataSchemas, type FlowDataVersions, type FlowDragEndedEvent, type FlowDragMovedEvent, type FlowDragStartedEvent, type FlowEdge, type FlowEdgeAttributes, type FlowEdgeLabel, type FlowEdgePatch, type FlowEdgeStyle, type FlowEdgeUpdater, type FlowEdgesApi, type FlowEngine, type FlowEngineOptions, type FlowEntitiesDeletedEvent, type FlowEntityChangeNotifier, type FlowEntityChangeNotifierOptions, type FlowEntityGestureEvent, type FlowEntityRef, type FlowEntityUpdate, type FlowErrorEvent, type FlowEventObject, type FlowGestureModifiers, type FlowGraph, type FlowGraphChangedEvent, type FlowGraphHistoryPolicy, type FlowGraphRetentionPolicy, FlowGraphValidationError, type FlowHighlightEntry, type FlowHighlights, type FlowHighlightsApi, type FlowHistoryApi, type FlowInputEffects, type FlowInputEvent, type FlowInputMode, type FlowInputModeContext, type FlowInputModifiers, type FlowInputProfile, type FlowInputReaction, type FlowInputRuntime, type FlowInputRuntimeOptions, type FlowInputSessionHandlers, type FlowInputTarget, type FlowKeyBinding, type FlowKeyInputEvent, type FlowKeymap, type FlowLayoutApi, type FlowModeDefinition, type FlowNode, type FlowNodeAttributes, type FlowNodePatch, type FlowNodeUpdater, type FlowNodesApi, type FlowOrigin, type FlowPaneGestureEvent, type FlowPatch, type FlowPinchInputEvent, type FlowPointerInputEvent, type FlowPolicies, type FlowPort, type FlowProfile, type FlowProjectionListener, type FlowProjectionsApi, type FlowReplaceGraphOptions, type FlowResizeEndedEvent, type FlowResizeStartedEvent, type FlowResolvers, type FlowResult, type FlowRules, type FlowRuntimeSettings, type FlowSelectionAlignment, type FlowSelectionApi, type FlowSelectionChangedEvent, type FlowSelectionDistribution, type FlowSelectionDuplicateResult, type FlowSerialized, type FlowSessionResult, type FlowSettings, type FlowStore, type FlowStoreContext, type FlowStoreOptions, type FlowTransactionDraft, type FlowTransactionOptions, type FlowTransition, type FlowTransitions, type FlowTriggerCommand, type FlowTriggerName, type FlowUpdateEdgeEvent, type FlowUpdateNodeEvent, type FlowValidationIssue, type FlowViewApi, type FlowViewBoundaryEndpoints, type FlowViewChangedEvent, type FlowViewEndpoint, type FlowViewEntities, type FlowViewScope, type FlowViewSelectionPolicy, type FlowViewportApi, type FlowViewportChangedEvent, type FlowWheelInputEvent, type Graph, type GraphDecoration, type GraphEdge, type GraphEdgeAttrs, type GraphNode, type GraphNodeAttrs, type GraphPort, type GraphProjection, type GraphProjectionMapper, type GroupContentSide, type GroupGeometry, type GroupInsets, type GroupLayout, type InteractionMode, type LabelAnchor, type LayoutAlgorithm, type LayoutAnimationControls, type LayoutAnimationOptions, type LayoutApplyOptions, type LayoutDiagnostic, type LayoutEdgeRoute, type LayoutPositions, type LayoutRequestedEvent, type LayoutResult, type LayoutRunOptions, type LayoutRunResult, type MarkerType, type MinimapProjection, type MinimapProjectionOptions, type PathData, type Point, type PortDirection, type ProposedConnection, type ReconnectModeOptions, type Rect, type RenderableEntitiesOptions, type ReparentDecision, type ReparentDropContext, type ReparentOptions, type ResizeConstraints, type ResizeHandle, type ResolvedFitViewExclusion, type SelectionMode, type ShapeHandler, type Side, type Size, type SnapLine, type SnapOptions, type SnapResult, type SpacingGuide, type StandardSchemaV1Like, type StepRouterOptions, type StyleOverrides, type ToolbarPlacement, type ToolbarPlacementInput, type Viewport, type ViewportAnimationCancelFrame, type ViewportAnimationControls, type ViewportAnimationFrame, type ViewportAnimationOptions, type VisualEdge, type VisualGraph, type VisualNode, type VisualPort, type WheelInteraction, type WheelInteractionOptions, animateViewport, applyFlowPatches, areNodesMeasured, avoidRouter, bestDirection, bezierRouter, boxSelectMode, boxToRect, calcAutoPan, canvasToScreen, clampZoom, cloneJsonSafe, composeGraphProjectionAttrs, configureAvoidRouter, configureBezierRouter, configureStepRouter, connectMode, constrainViewport, createConnectionPreviewGraph, createEdge, createEntityChangeNotifier, createFlow, createFlowChangeSet, createFlowEngine, createFlowInputRuntime, createFlowStore, createGraph, createNode, createPort, createViewport, defaultConfig, defaultFlowProfile, defaultInputModes, defaultInputModesForKeymap, defaultKeymap, defaultModesForContext, defineFlowProfile, deriveFlowView, deriveGroupGeometry, entityPressMode, extractFlowContent, fitFrameAroundExclusions, fixedGroupGeometry, fromJSON, getAnchorTransform, getAutoPanDelta, getConnectedEdges, getEdgeOwner, getGraphBounds, getIncomers, getMinimapProjection, getNeighbors, getOutgoers, getProjectedEdgeAttrs, getProjectedNodeAttrs, getSelectionBounds, getShape, getShapeOrDefault, getSnapLines, getToolbarPlacement, getVisibleBounds, hoverMode, indexChildren, indexEdgeAdjacency, indexEdges, indexNodes, insertFlowContent, isDerivedGroup, isGroup, isTrackpadPinch, keyboardMode, keyboardNavMode, markerToSVG, matchesKeyBinding, mergeGraphEdgeAttrs, mergeGraphNodeAttrs, nodeDepths, normalizeWheelPan, panBy, panMode, panePressMode, parseFlowSerialized, pathToSVG, pinchMode, portPressMode, preventDefault, profileModesForContext, profilePoliciesForContext, readonlyConfig, readonlyInputModes, readonlyInputModesForKeymap, reconnectMode, rectContains, rectsIntersect, registerShape, resolveBehavior, resolveGroupPadding, resolveKeymap, resolvedBounds, resolvedEdgeLabelBounds, resolvedEdgeLabelSize, resolvedPosition, resolvedSelectionBounds, screenToCanvas, selectMode, serializeFlowGraph, snapPointToGrid, snapToGrid, snappedBounds, sortActiveGraphProjections, stepRouter, straightRouter, toSVGTransform, toViewBox, trigger, unionRect, validateAndCloneGraph, validateFitFrame, validateViewport, viewportCenteredOn, viewportForBounds, visualBounds, visualPosition, wheelInteraction, wheelMode, wheelZoomDelta, zoomTo };
|
|
3508
|
+
export { type ActiveGraphProjection, type AnchorSpec, type AnchorTransform, type AnimateViewportOptions, type AutoLayoutState, type AvoidRouterOptions, type BehaviorPredicate, type BezierRouterOptions, type BoxSelectModeOptions, type BoxSelectionTest, CONNECTION_PREVIEW_EDGE_ID, CONNECTION_PREVIEW_NODE_ID, type CanvasState, type ComposedGraphProjectionAttrs, type ConnectEndTarget, type ConnectModeOptions, type ConnectionCandidate, type ConnectionCandidateOptions, type ConnectionCandidateSource, type ConnectionEndedEvent, type ConnectionPreviewData, type ConnectionPreviewGraphOptions, type ConnectionState, type ConnectionValidationContext, type ConnectionValidationResult, type CreateEdgeInput, type CreateFlowOptions, type CreateNodeInput, type Direction, type EdgeAdjacencyIndex, type EdgeDirection, type EdgePathData, type EdgePathOptions, type EdgeRouter, type EdgeRouterContext, type EdgeRouterGraph, type EdgeRouting, type EdgeSourceBoundsContext, type EntityRect, type EntityVisualState, type FitViewExclusion, type FitViewExclusionSide, type FitViewOptions, type FlowAbortSignal, type FlowAddressable, type FlowAutoSizeAnchor, type FlowCapabilityCommand, type FlowCapabilityResult, type FlowChangeSet, type FlowColorMode, type FlowCommand, type FlowCommitEvent, type FlowConfig, type FlowConfiguration, type FlowConfigureOptions, type FlowConnectMovedEvent, type FlowConnectStartedEvent, type FlowConnection, type FlowConnectionMode, type FlowConnectionOptions, type FlowConnectionsApi, type FlowContent, type FlowContentApi, type FlowContentInsertResult, type FlowController, type FlowCreateIdContext, type FlowDataSchema, type FlowDataSchemas, type FlowDataVersions, type FlowDragEndedEvent, type FlowDragMovedEvent, type FlowDragStartedEvent, type FlowEdge, type FlowEdgeAttributes, type FlowEdgeLabel, type FlowEdgePatch, type FlowEdgeStyle, type FlowEdgeUpdater, type FlowEdgesApi, type FlowEngine, type FlowEngineOptions, type FlowEntitiesDeletedEvent, type FlowEntityChangeNotifier, type FlowEntityChangeNotifierOptions, type FlowEntityGestureEvent, type FlowEntityRef, type FlowEntityUpdate, type FlowErrorEvent, type FlowEventObject, type FlowGestureModifiers, type FlowGraph, type FlowGraphChangedEvent, type FlowGraphHistoryPolicy, type FlowGraphRetentionPolicy, FlowGraphValidationError, type FlowHighlightEntry, type FlowHighlights, type FlowHighlightsApi, type FlowHistoryApi, type FlowInputEffects, type FlowInputEvent, type FlowInputMode, type FlowInputModeContext, type FlowInputModifiers, type FlowInputProfile, type FlowInputReaction, type FlowInputRuntime, type FlowInputRuntimeOptions, type FlowInputSessionHandlers, type FlowInputTarget, type FlowKeyBinding, type FlowKeyInputEvent, type FlowKeymap, type FlowLayoutApi, type FlowModeDefinition, type FlowNode, type FlowNodeAttributes, type FlowNodePatch, type FlowNodeUpdater, type FlowNodesApi, type FlowOrigin, type FlowPaneGestureEvent, type FlowPatch, type FlowPinchInputEvent, type FlowPointerInputEvent, type FlowPolicies, type FlowPort, type FlowProfile, type FlowProjectionListener, type FlowProjectionsApi, type FlowReplaceGraphOptions, type FlowResizeEndedEvent, type FlowResizeStartedEvent, type FlowResolvers, type FlowResult, type FlowRules, type FlowRuntimeSettings, type FlowSelectionAlignment, type FlowSelectionApi, type FlowSelectionChangedEvent, type FlowSelectionDistribution, type FlowSelectionDuplicateResult, type FlowSerialized, type FlowSessionResult, type FlowSettings, type FlowStore, type FlowStoreContext, type FlowStoreOptions, type FlowTransactionDraft, type FlowTransactionOptions, type FlowTransition, type FlowTransitions, type FlowTriggerCommand, type FlowTriggerName, type FlowUpdateEdgeEvent, type FlowUpdateNodeEvent, type FlowValidationIssue, type FlowViewApi, type FlowViewBoundaryEndpoints, type FlowViewChangedEvent, type FlowViewEndpoint, type FlowViewEntities, type FlowViewScope, type FlowViewSelectionPolicy, type FlowViewportApi, type FlowViewportChangedEvent, type FlowWheelInputEvent, type Graph, type GraphDecoration, type GraphEdge, type GraphEdgeAttrs, type GraphNode, type GraphNodeAttrs, type GraphPort, type GraphProjection, type GraphProjectionMapper, type GroupContentSide, type GroupGeometry, type GroupInsets, type GroupLayout, type InteractionMode, type LabelAnchor, type LayoutAlgorithm, type LayoutAnimationControls, type LayoutAnimationOptions, type LayoutApplyOptions, type LayoutDiagnostic, type LayoutEdgeRoute, type LayoutPositions, type LayoutRequestedEvent, type LayoutResult, type LayoutRunOptions, type LayoutRunResult, type MarkerType, type MinimapProjection, type MinimapProjectionOptions, type MinimapViewportCenterOptions, type PathData, type Point, type PortDirection, type ProposedConnection, type ReconnectModeOptions, type Rect, type RenderableEntitiesOptions, type ReparentDecision, type ReparentDropContext, type ReparentOptions, type ResizeConstraints, type ResizeHandle, type ResolvedFitViewExclusion, type SelectionMode, type ShapeHandler, type Side, type Size, type SnapLine, type SnapOptions, type SnapResult, type SpacingGuide, type StandardSchemaV1Like, type StepRouterOptions, type StyleOverrides, type ToolbarPlacement, type ToolbarPlacementInput, type Viewport, type ViewportAnimationCancelFrame, type ViewportAnimationControls, type ViewportAnimationFrame, type ViewportAnimationOptions, type VisualEdge, type VisualGraph, type VisualNode, type VisualPort, type WheelInteraction, type WheelInteractionOptions, animateViewport, applyFlowPatches, areNodesMeasured, avoidRouter, bestDirection, bezierRouter, boxSelectMode, boxToRect, calcAutoPan, canvasToScreen, clampZoom, cloneJsonSafe, composeGraphProjectionAttrs, configureAvoidRouter, configureBezierRouter, configureStepRouter, connectMode, constrainViewport, createConnectionPreviewGraph, createEdge, createEntityChangeNotifier, createFlow, createFlowChangeSet, createFlowEngine, createFlowInputRuntime, createFlowStore, createGraph, createNode, createPort, createViewport, defaultConfig, defaultFlowProfile, defaultInputModes, defaultInputModesForKeymap, defaultKeymap, defaultModesForContext, defineFlowProfile, deriveFlowView, deriveGroupGeometry, entityPressMode, extractFlowContent, fitFrameAroundExclusions, fixedGroupGeometry, fromJSON, getAnchorTransform, getAutoPanDelta, getConnectedEdges, getEdgeOwner, getGraphBounds, getIncomers, getMinimapProjection, getMinimapViewportCenter, getNeighbors, getOutgoers, getProjectedEdgeAttrs, getProjectedNodeAttrs, getSelectionBounds, getShape, getShapeOrDefault, getSnapLines, getToolbarPlacement, getVisibleBounds, hoverMode, indexChildren, indexEdgeAdjacency, indexEdges, indexNodes, insertFlowContent, isDerivedGroup, isGroup, isTrackpadPinch, keyboardMode, keyboardNavMode, markerToSVG, matchesKeyBinding, mergeGraphEdgeAttrs, mergeGraphNodeAttrs, nodeDepths, normalizeWheelPan, panBy, panMode, panePressMode, parseFlowSerialized, pathToSVG, pinchMode, portPressMode, preventDefault, profileModesForContext, profilePoliciesForContext, readonlyConfig, readonlyInputModes, readonlyInputModesForKeymap, reconnectMode, rectContains, rectsIntersect, registerShape, resolveBehavior, resolveGroupPadding, resolveKeymap, resolvedBounds, resolvedEdgeLabelBounds, resolvedEdgeLabelSize, resolvedPosition, resolvedSelectionBounds, screenToCanvas, selectMode, serializeFlowGraph, snapPointToGrid, snapToGrid, snappedBounds, sortActiveGraphProjections, stepRouter, straightRouter, toSVGTransform, toViewBox, trigger, unionRect, validateAndCloneGraph, validateFitFrame, validateViewport, viewportCenteredOn, viewportForBounds, visualBounds, visualPosition, wheelInteraction, wheelMode, wheelZoomDelta, zoomTo };
|
package/dist/esm/index.js
CHANGED
|
@@ -807,14 +807,19 @@ function constrainViewport(viewport, viewportSize, translateExtent) {
|
|
|
807
807
|
* Returns screen-space delta to apply per frame. Returns {0,0} if cursor isn't near an edge.
|
|
808
808
|
*/
|
|
809
809
|
function calcAutoPan(mousePosition, containerBounds, edgeWidth = 25, speed = 10) {
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
810
|
+
if (edgeWidth <= 0 || speed <= 0) return {
|
|
811
|
+
x: 0,
|
|
812
|
+
y: 0
|
|
813
|
+
};
|
|
814
|
+
const clamp01 = (value) => Math.min(1, Math.max(0, value));
|
|
815
|
+
const getAxisDelta = (position, size) => {
|
|
816
|
+
if (position < edgeWidth) return -speed * clamp01(1 - position / edgeWidth);
|
|
817
|
+
if (position > size - edgeWidth) return speed * clamp01(1 - (size - position) / edgeWidth);
|
|
818
|
+
return 0;
|
|
819
|
+
};
|
|
815
820
|
return {
|
|
816
|
-
x:
|
|
817
|
-
y:
|
|
821
|
+
x: getAxisDelta(mousePosition.x, containerBounds.width),
|
|
822
|
+
y: getAxisDelta(mousePosition.y, containerBounds.height)
|
|
818
823
|
};
|
|
819
824
|
}
|
|
820
825
|
/**
|
|
@@ -3261,6 +3266,7 @@ function createFlowStore(initialGraph = {
|
|
|
3261
3266
|
connectionClickStartHandle: null,
|
|
3262
3267
|
panOrigin: null,
|
|
3263
3268
|
panViewportOrigin: null,
|
|
3269
|
+
viewportAnimation: options.viewportAnimation ?? null,
|
|
3264
3270
|
resizingEntityId: null,
|
|
3265
3271
|
resizeHandle: null,
|
|
3266
3272
|
resizeCorners: null,
|
|
@@ -4157,6 +4163,7 @@ function createFlowStore(initialGraph = {
|
|
|
4157
4163
|
if (event.autoPanOnDrag !== void 0) draft.autoPanOnDrag = event.autoPanOnDrag;
|
|
4158
4164
|
if (event.autoPanThreshold !== void 0) draft.autoPanThreshold = Math.max(0, event.autoPanThreshold);
|
|
4159
4165
|
if (event.autoPanSpeed !== void 0) draft.autoPanSpeed = Math.max(0, event.autoPanSpeed);
|
|
4166
|
+
if (event.viewportAnimation !== void 0) draft.viewportAnimation = event.viewportAnimation;
|
|
4160
4167
|
if (event.enableSnapLines !== void 0) draft.enableSnapLines = event.enableSnapLines;
|
|
4161
4168
|
if (event.snapThreshold !== void 0) draft.snapThreshold = Math.max(0, event.snapThreshold);
|
|
4162
4169
|
if (event.enableSpacingGuides !== void 0) draft.enableSpacingGuides = event.enableSpacingGuides;
|
|
@@ -4176,6 +4183,7 @@ function createFlowStore(initialGraph = {
|
|
|
4176
4183
|
if (event.autoPanOnDrag !== void 0) draft.autoPanOnDrag = event.autoPanOnDrag;
|
|
4177
4184
|
if (event.autoPanThreshold !== void 0) draft.autoPanThreshold = Math.max(0, event.autoPanThreshold);
|
|
4178
4185
|
if (event.autoPanSpeed !== void 0) draft.autoPanSpeed = Math.max(0, event.autoPanSpeed);
|
|
4186
|
+
if (event.viewportAnimation !== void 0) draft.viewportAnimation = event.viewportAnimation;
|
|
4179
4187
|
if (event.snapToGrid !== void 0) draft.snapToGrid = event.snapToGrid;
|
|
4180
4188
|
if (event.snapGrid !== void 0) draft.snapGrid = event.snapGrid;
|
|
4181
4189
|
if (event.enableSnapLines !== void 0) draft.enableSnapLines = event.enableSnapLines;
|
|
@@ -4704,8 +4712,9 @@ function createFlowStore(initialGraph = {
|
|
|
4704
4712
|
const candidate = draft.graph.nodes[portTarget.nodeIndex];
|
|
4705
4713
|
const port = candidate.ports?.[portTarget.portIndex];
|
|
4706
4714
|
if (!port) continue;
|
|
4707
|
-
|
|
4708
|
-
port.
|
|
4715
|
+
const origin = snappedBounds(candidate, draft.snapToGrid ? draft.snapGrid : null);
|
|
4716
|
+
port.x = measurement.rect.x - origin.x;
|
|
4717
|
+
port.y = measurement.rect.y - origin.y;
|
|
4709
4718
|
port.width = measurement.rect.width;
|
|
4710
4719
|
port.height = measurement.rect.height;
|
|
4711
4720
|
}
|
|
@@ -5659,7 +5668,6 @@ function createFlowEngine(store, initialOptions = {}) {
|
|
|
5659
5668
|
const edge = getEdge(edgeId);
|
|
5660
5669
|
if (!edge?.label) return null;
|
|
5661
5670
|
const measured = c.measurements.get(edgeId);
|
|
5662
|
-
if (measured && !edge.label.autoSize) return measured;
|
|
5663
5671
|
return resolveEdgeLabelBounds(edge, indexNodes(c.graph.nodes), measured);
|
|
5664
5672
|
}
|
|
5665
5673
|
function getBounds(id) {
|
|
@@ -7411,6 +7419,12 @@ function insertFlowContent(graph, content, options) {
|
|
|
7411
7419
|
}
|
|
7412
7420
|
//#endregion
|
|
7413
7421
|
//#region src/createFlow.ts
|
|
7422
|
+
function hasAuthoritativeLayoutPoints(route) {
|
|
7423
|
+
return !Array.isArray(route) && "points" in route;
|
|
7424
|
+
}
|
|
7425
|
+
function layoutWaypoints(route) {
|
|
7426
|
+
return Array.isArray(route) ? route : route.waypoints;
|
|
7427
|
+
}
|
|
7414
7428
|
function immutableConfiguration(configuration) {
|
|
7415
7429
|
const seen = /* @__PURE__ */ new WeakMap();
|
|
7416
7430
|
const clone = (value) => {
|
|
@@ -7573,10 +7587,19 @@ function createFlow(options = {}) {
|
|
|
7573
7587
|
...value.nodeBounds ? { nodeBounds: rects(value.nodeBounds) } : {},
|
|
7574
7588
|
...value.edgeLabelPositions ? { edgeLabelPositions: points(value.edgeLabelPositions) } : {},
|
|
7575
7589
|
...value.edgeLabelBounds ? { edgeLabelBounds: rects(value.edgeLabelBounds) } : {},
|
|
7576
|
-
...value.edgeRoutes ? { edgeRoutes: new Map([...value.edgeRoutes].map(([id, route]) =>
|
|
7577
|
-
|
|
7578
|
-
|
|
7579
|
-
|
|
7590
|
+
...value.edgeRoutes ? { edgeRoutes: new Map([...value.edgeRoutes].map(([id, route]) => {
|
|
7591
|
+
if (hasAuthoritativeLayoutPoints(route)) return [id, {
|
|
7592
|
+
points: route.points.map((point) => ({
|
|
7593
|
+
x: point.x,
|
|
7594
|
+
y: point.y
|
|
7595
|
+
})),
|
|
7596
|
+
...route.routing ? { routing: route.routing } : {}
|
|
7597
|
+
}];
|
|
7598
|
+
return [id, { waypoints: layoutWaypoints(route).map((point) => ({
|
|
7599
|
+
x: point.x,
|
|
7600
|
+
y: point.y
|
|
7601
|
+
})) }];
|
|
7602
|
+
})) } : {},
|
|
7580
7603
|
...value.diagnostics ? { diagnostics: value.diagnostics.map((entry) => ({ ...entry })) } : {},
|
|
7581
7604
|
...value.quality ? { quality: cloneJsonSafe(value.quality, "$.layout.quality") } : {},
|
|
7582
7605
|
...value.metadata ? { metadata: cloneJsonSafe(value.metadata, "$.layout.metadata") } : {},
|
|
@@ -7832,7 +7855,7 @@ function createFlow(options = {}) {
|
|
|
7832
7855
|
finiteSize(rect, path);
|
|
7833
7856
|
});
|
|
7834
7857
|
validateMap("edgeRoutes", result.edgeRoutes, edgeIds, (route, path) => {
|
|
7835
|
-
(
|
|
7858
|
+
(hasAuthoritativeLayoutPoints(route) ? route.points : layoutWaypoints(route)).forEach((point, index) => finitePoint(point, `${path}.points[${index}]`));
|
|
7836
7859
|
});
|
|
7837
7860
|
for (const [field, ids] of [
|
|
7838
7861
|
["fixedEntityIds", applyOptions.fixedEntityIds],
|
|
@@ -7920,7 +7943,11 @@ function createFlow(options = {}) {
|
|
|
7920
7943
|
delete edge.label.dx;
|
|
7921
7944
|
delete edge.label.dy;
|
|
7922
7945
|
}
|
|
7923
|
-
if (route)
|
|
7946
|
+
if (route) if (hasAuthoritativeLayoutPoints(route)) {
|
|
7947
|
+
edge.points = route.points.map((point) => ({ ...point }));
|
|
7948
|
+
edge.routing = route.routing ?? "polyline";
|
|
7949
|
+
delete edge.waypoints;
|
|
7950
|
+
} else edge.waypoints = layoutWaypoints(route).map((point) => ({ ...point }));
|
|
7924
7951
|
}
|
|
7925
7952
|
const initialOffsets = /* @__PURE__ */ new Map();
|
|
7926
7953
|
if (animate) {
|
|
@@ -8082,7 +8109,23 @@ function createFlow(options = {}) {
|
|
|
8082
8109
|
return resolvedViewportControls();
|
|
8083
8110
|
}
|
|
8084
8111
|
cancelViewportAnimation();
|
|
8085
|
-
|
|
8112
|
+
const resolvedAnimationOptions = {
|
|
8113
|
+
...store.getSnapshot().context.viewportAnimation ?? {},
|
|
8114
|
+
...animationOptions,
|
|
8115
|
+
...animationOptions?.duration !== void 0 ? {
|
|
8116
|
+
lerp: void 0,
|
|
8117
|
+
spring: void 0
|
|
8118
|
+
} : animationOptions?.lerp !== void 0 ? {
|
|
8119
|
+
duration: void 0,
|
|
8120
|
+
easing: void 0,
|
|
8121
|
+
spring: void 0
|
|
8122
|
+
} : animationOptions?.spring !== void 0 ? {
|
|
8123
|
+
duration: void 0,
|
|
8124
|
+
easing: void 0,
|
|
8125
|
+
lerp: void 0
|
|
8126
|
+
} : {}
|
|
8127
|
+
};
|
|
8128
|
+
if ((resolvedAnimationOptions.duration ?? 0) <= 0 && !resolvedAnimationOptions.spring && resolvedAnimationOptions.lerp === void 0) {
|
|
8086
8129
|
store.trigger.setViewport(target);
|
|
8087
8130
|
return resolvedViewportControls();
|
|
8088
8131
|
}
|
|
@@ -8092,7 +8135,7 @@ function createFlow(options = {}) {
|
|
|
8092
8135
|
...store.trigger,
|
|
8093
8136
|
setViewport: writeViewport
|
|
8094
8137
|
}
|
|
8095
|
-
}, target,
|
|
8138
|
+
}, target, resolvedAnimationOptions);
|
|
8096
8139
|
activeViewportAnimation = animation;
|
|
8097
8140
|
animation.done.then(() => {
|
|
8098
8141
|
if (activeViewportAnimation === animation) activeViewportAnimation = null;
|
|
@@ -9130,7 +9173,7 @@ function fromJSON(data, options = {}) {
|
|
|
9130
9173
|
graph: parsed.graph
|
|
9131
9174
|
});
|
|
9132
9175
|
flow.internals.store.trigger.setCollapsedNodes({ ids: parsed.collapsedNodeIds ?? [] });
|
|
9133
|
-
flow.
|
|
9176
|
+
flow.internals.store.trigger.setViewport(parsed.viewport);
|
|
9134
9177
|
return flow;
|
|
9135
9178
|
}
|
|
9136
9179
|
//#endregion
|
|
@@ -9205,6 +9248,32 @@ function getToolbarPlacement(input) {
|
|
|
9205
9248
|
}
|
|
9206
9249
|
//#endregion
|
|
9207
9250
|
//#region src/minimap.ts
|
|
9251
|
+
/**
|
|
9252
|
+
* Resolve a minimap pointer to a bounded viewport center.
|
|
9253
|
+
*
|
|
9254
|
+
* This constraint applies only to minimap navigation. Each axis lets the lens
|
|
9255
|
+
* move fully past the graph, stopping when its nearest edge reaches the graph.
|
|
9256
|
+
*/
|
|
9257
|
+
function getMinimapViewportCenter(options) {
|
|
9258
|
+
const grabOffset = options.grabOffset ?? {
|
|
9259
|
+
x: 0,
|
|
9260
|
+
y: 0
|
|
9261
|
+
};
|
|
9262
|
+
const target = {
|
|
9263
|
+
x: options.point.x - grabOffset.x,
|
|
9264
|
+
y: options.point.y - grabOffset.y
|
|
9265
|
+
};
|
|
9266
|
+
const halfWidth = Math.max(0, options.viewportBounds.width) / 2;
|
|
9267
|
+
const halfHeight = Math.max(0, options.viewportBounds.height) / 2;
|
|
9268
|
+
const minX = options.contentBounds.x - halfWidth;
|
|
9269
|
+
const maxX = options.contentBounds.x + options.contentBounds.width + halfWidth;
|
|
9270
|
+
const minY = options.contentBounds.y - halfHeight;
|
|
9271
|
+
const maxY = options.contentBounds.y + options.contentBounds.height + halfHeight;
|
|
9272
|
+
return {
|
|
9273
|
+
x: Math.min(Math.max(target.x, minX), maxX),
|
|
9274
|
+
y: Math.min(Math.max(target.y, minY), maxY)
|
|
9275
|
+
};
|
|
9276
|
+
}
|
|
9208
9277
|
function getMinimapProjection(options) {
|
|
9209
9278
|
const padding = options.padding ?? .1;
|
|
9210
9279
|
const content = options.contentBounds;
|
|
@@ -10583,11 +10652,12 @@ function profilePoliciesForContext(profile) {
|
|
|
10583
10652
|
};
|
|
10584
10653
|
}
|
|
10585
10654
|
/**
|
|
10586
|
-
* Per-frame auto-pan step while a drag
|
|
10587
|
-
* container edge. Returns the `calcAutoPan` screen-space
|
|
10588
|
-
* `panBy`), or null when auto-pan should not run. Adapters
|
|
10589
|
-
* frame ticker while a gesture session is active and re-send
|
|
10590
|
-
* pointer afterwards so the dragged entity follows the panned
|
|
10655
|
+
* Per-frame, pointer-driven auto-pan step while a drag, connection, or resize
|
|
10656
|
+
* gesture is near the container edge. Returns the `calcAutoPan` screen-space
|
|
10657
|
+
* delta (negate it for `panBy`), or null when auto-pan should not run. Adapters
|
|
10658
|
+
* call this from a frame ticker while a gesture session is active and re-send
|
|
10659
|
+
* the stationary pointer afterwards so the dragged entity follows the panned
|
|
10660
|
+
* canvas.
|
|
10591
10661
|
*/
|
|
10592
10662
|
function getAutoPanDelta(context, screenPoint, engine) {
|
|
10593
10663
|
if (!context.autoPanOnDrag) return null;
|
|
@@ -10596,44 +10666,6 @@ function getAutoPanDelta(context, screenPoint, engine) {
|
|
|
10596
10666
|
if (size.width === 0 || size.height === 0) return null;
|
|
10597
10667
|
const delta = calcAutoPan(screenPoint, size, context.autoPanThreshold, context.autoPanSpeed);
|
|
10598
10668
|
if (delta.x === 0 && delta.y === 0) return null;
|
|
10599
|
-
const toScreen = (b) => {
|
|
10600
|
-
const x0 = b.x * context.viewport.zoom + context.viewport.x;
|
|
10601
|
-
const y0 = b.y * context.viewport.zoom + context.viewport.y;
|
|
10602
|
-
return {
|
|
10603
|
-
x0,
|
|
10604
|
-
y0,
|
|
10605
|
-
x1: x0 + b.width * context.viewport.zoom,
|
|
10606
|
-
y1: y0 + b.height * context.viewport.zoom
|
|
10607
|
-
};
|
|
10608
|
-
};
|
|
10609
|
-
const gateByBounds = (union) => {
|
|
10610
|
-
const edge = context.autoPanThreshold;
|
|
10611
|
-
if (delta.x < 0 && union.x0 > edge) delta.x = 0;
|
|
10612
|
-
if (delta.x > 0 && union.x1 < size.width - edge) delta.x = 0;
|
|
10613
|
-
if (delta.y < 0 && union.y0 > edge) delta.y = 0;
|
|
10614
|
-
if (delta.y > 0 && union.y1 < size.height - edge) delta.y = 0;
|
|
10615
|
-
if (delta.x === 0 && delta.y === 0) return null;
|
|
10616
|
-
return delta;
|
|
10617
|
-
};
|
|
10618
|
-
if (engine && context.canvasState === "dragging") {
|
|
10619
|
-
let union = null;
|
|
10620
|
-
for (const selectedId of context.selection) {
|
|
10621
|
-
const node = engine.getNode(selectedId);
|
|
10622
|
-
if (!node || node.draggable === false) continue;
|
|
10623
|
-
const s = toScreen(engine.resolvedBounds(selectedId));
|
|
10624
|
-
union = union ? {
|
|
10625
|
-
x0: Math.min(union.x0, s.x0),
|
|
10626
|
-
y0: Math.min(union.y0, s.y0),
|
|
10627
|
-
x1: Math.max(union.x1, s.x1),
|
|
10628
|
-
y1: Math.max(union.y1, s.y1)
|
|
10629
|
-
} : s;
|
|
10630
|
-
}
|
|
10631
|
-
if (union) return gateByBounds(union);
|
|
10632
|
-
}
|
|
10633
|
-
if (engine && context.canvasState === "resizing") {
|
|
10634
|
-
const rect = engine.getResizeBounds();
|
|
10635
|
-
if (rect) return gateByBounds(toScreen(rect));
|
|
10636
|
-
}
|
|
10637
10669
|
return delta;
|
|
10638
10670
|
}
|
|
10639
10671
|
//#endregion
|
|
@@ -10864,4 +10896,4 @@ function createEntityChangeNotifier(store, options = {}) {
|
|
|
10864
10896
|
};
|
|
10865
10897
|
}
|
|
10866
10898
|
//#endregion
|
|
10867
|
-
export { CONNECTION_PREVIEW_EDGE_ID, CONNECTION_PREVIEW_NODE_ID, FlowGraphValidationError, animateViewport, applyFlowPatches, areNodesMeasured, avoidRouter, bestDirection, bezierRouter, boxSelectMode, boxToRect, calcAutoPan, canvasToScreen, clampZoom, cloneJsonSafe, composeGraphProjectionAttrs, configureAvoidRouter, configureBezierRouter, configureStepRouter, connectMode, constrainViewport, createConnectionPreviewGraph, createEdge, createEntityChangeNotifier, createFlow, createFlowChangeSet, createFlowEngine, createFlowInputRuntime, createFlowStore, createGraph, createNode, createPort, createViewport, defaultConfig, defaultFlowProfile, defaultInputModes, defaultInputModesForKeymap, defaultKeymap, defaultModesForContext, defineFlowProfile, deriveFlowView, deriveGroupGeometry, entityPressMode, extractFlowContent, fitFrameAroundExclusions, fixedGroupGeometry, fromJSON, getAnchorTransform, getAutoPanDelta, getConnectedEdges, getEdgeOwner, getGraphBounds, getIncomers, getMinimapProjection, getNeighbors, getOutgoers, getProjectedEdgeAttrs, getProjectedNodeAttrs, getSelectionBounds, getShape, getShapeOrDefault, getSnapLines, getToolbarPlacement, getVisibleBounds, hoverMode, indexChildren, indexEdgeAdjacency, indexEdges, indexNodes, insertFlowContent, isDerivedGroup, isGroup, isTrackpadPinch, keyboardMode, keyboardNavMode, markerToSVG, matchesKeyBinding, mergeGraphEdgeAttrs, mergeGraphNodeAttrs, nodeDepths, normalizeWheelPan, panBy, panMode, panePressMode, parseFlowSerialized, pathToSVG, pinchMode, portPressMode, preventDefault, profileModesForContext, profilePoliciesForContext, readonlyConfig, readonlyInputModes, readonlyInputModesForKeymap, reconnectMode, rectContains, rectsIntersect, registerShape, resolveBehavior, resolveGroupPadding, resolveKeymap, resolvedBounds, resolvedEdgeLabelBounds, resolvedEdgeLabelSize, resolvedPosition, resolvedSelectionBounds, screenToCanvas, selectMode, serializeFlowGraph, snapPointToGrid, snapToGrid, snappedBounds, sortActiveGraphProjections, stepRouter, straightRouter, toSVGTransform, toViewBox, trigger, unionRect, validateAndCloneGraph, validateFitFrame, validateViewport, viewportCenteredOn, viewportForBounds, visualBounds, visualPosition, wheelInteraction, wheelMode, wheelZoomDelta, zoomTo };
|
|
10899
|
+
export { CONNECTION_PREVIEW_EDGE_ID, CONNECTION_PREVIEW_NODE_ID, FlowGraphValidationError, animateViewport, applyFlowPatches, areNodesMeasured, avoidRouter, bestDirection, bezierRouter, boxSelectMode, boxToRect, calcAutoPan, canvasToScreen, clampZoom, cloneJsonSafe, composeGraphProjectionAttrs, configureAvoidRouter, configureBezierRouter, configureStepRouter, connectMode, constrainViewport, createConnectionPreviewGraph, createEdge, createEntityChangeNotifier, createFlow, createFlowChangeSet, createFlowEngine, createFlowInputRuntime, createFlowStore, createGraph, createNode, createPort, createViewport, defaultConfig, defaultFlowProfile, defaultInputModes, defaultInputModesForKeymap, defaultKeymap, defaultModesForContext, defineFlowProfile, deriveFlowView, deriveGroupGeometry, entityPressMode, extractFlowContent, fitFrameAroundExclusions, fixedGroupGeometry, fromJSON, getAnchorTransform, getAutoPanDelta, getConnectedEdges, getEdgeOwner, getGraphBounds, getIncomers, getMinimapProjection, getMinimapViewportCenter, getNeighbors, getOutgoers, getProjectedEdgeAttrs, getProjectedNodeAttrs, getSelectionBounds, getShape, getShapeOrDefault, getSnapLines, getToolbarPlacement, getVisibleBounds, hoverMode, indexChildren, indexEdgeAdjacency, indexEdges, indexNodes, insertFlowContent, isDerivedGroup, isGroup, isTrackpadPinch, keyboardMode, keyboardNavMode, markerToSVG, matchesKeyBinding, mergeGraphEdgeAttrs, mergeGraphNodeAttrs, nodeDepths, normalizeWheelPan, panBy, panMode, panePressMode, parseFlowSerialized, pathToSVG, pinchMode, portPressMode, preventDefault, profileModesForContext, profilePoliciesForContext, readonlyConfig, readonlyInputModes, readonlyInputModesForKeymap, reconnectMode, rectContains, rectsIntersect, registerShape, resolveBehavior, resolveGroupPadding, resolveKeymap, resolvedBounds, resolvedEdgeLabelBounds, resolvedEdgeLabelSize, resolvedPosition, resolvedSelectionBounds, screenToCanvas, selectMode, serializeFlowGraph, snapPointToGrid, snapToGrid, snappedBounds, sortActiveGraphProjections, stepRouter, straightRouter, toSVGTransform, toViewBox, trigger, unionRect, validateAndCloneGraph, validateFitFrame, validateViewport, viewportCenteredOn, viewportForBounds, visualBounds, visualPosition, wheelInteraction, wheelMode, wheelZoomDelta, zoomTo };
|
package/dist/esm/layout/elk.js
CHANGED
|
@@ -167,6 +167,9 @@ async function restoreExplicitCompoundDirections(elk, graph, positions, nodeSize
|
|
|
167
167
|
"elk.spacing.nodeNode": String(options.nodeSpacing ?? 60)
|
|
168
168
|
};
|
|
169
169
|
applyCompoundLayeredOptions(localLayoutOptions, localEdges, direction, options);
|
|
170
|
+
const nestedNodeOptions = options.node?.layoutOptions;
|
|
171
|
+
const cycleBreakingStrategy = options.node?.["elk.layered.cycleBreaking.strategy"] ?? (nestedNodeOptions && typeof nestedNodeOptions === "object" ? nestedNodeOptions["elk.layered.cycleBreaking.strategy"] : void 0) ?? options.graph?.["elk.layered.cycleBreaking.strategy"];
|
|
172
|
+
if (cycleBreakingStrategy !== void 0) localLayoutOptions["elk.layered.cycleBreaking.strategy"] = String(cycleBreakingStrategy);
|
|
170
173
|
const laidOutChildren = (await elk.layout({
|
|
171
174
|
id: `direction:${group.id}`,
|
|
172
175
|
layoutOptions: localLayoutOptions,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { i as FlowLayoutScope, n as FlowLayoutFactory, r as FlowLayoutOptions, t as FlowLayoutAlgorithm } from "../shared.js";
|
|
2
2
|
import { DagreLayoutOptions, dagreLayout } from "./dagre.js";
|
|
3
3
|
import { ElkLayoutOptions, elkLayout } from "./elk.js";
|
|
4
|
-
|
|
4
|
+
import { StatelyLayoutOptions, statelyLayout } from "./stately.js";
|
|
5
|
+
export { type DagreLayoutOptions, type ElkLayoutOptions, type FlowLayoutAlgorithm, type FlowLayoutFactory, type FlowLayoutOptions, type FlowLayoutScope, type StatelyLayoutOptions, dagreLayout, elkLayout, statelyLayout };
|
package/dist/esm/layout/index.js
CHANGED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { r as FlowLayoutOptions, t as FlowLayoutAlgorithm } from "../shared.js";
|
|
2
|
+
import { LayeredLayoutOptions } from "@statelyai/layout/layered";
|
|
3
|
+
//#region src/layout/stately.d.ts
|
|
4
|
+
type StatelyLayoutOptions<TNodeData = any, TEdgeData = any, TLabelData = any> = Omit<LayeredLayoutOptions, 'measure'> & Pick<FlowLayoutOptions<TNodeData, TEdgeData, TLabelData>, 'getBounds' | 'scope' | 'source' | 'metadata' | '_types'>;
|
|
5
|
+
/** Graph-native layered layout powered by `@statelyai/layout`. */
|
|
6
|
+
declare const statelyLayout: <TNodeData = any, TEdgeData = any, TLabelData = any>(options?: StatelyLayoutOptions<TNodeData, TEdgeData, TLabelData>) => FlowLayoutAlgorithm<TNodeData, TEdgeData, TLabelData>;
|
|
7
|
+
//#endregion
|
|
8
|
+
export { StatelyLayoutOptions, statelyLayout };
|
|
@@ -0,0 +1,425 @@
|
|
|
1
|
+
import { a as mergedLayoutScope, i as layoutRunContext, r as graphForLayoutScope, s as throwIfAborted, t as boundsOf } from "../shared.js";
|
|
2
|
+
import { getLCA } from "@statelyai/graph";
|
|
3
|
+
import { deriveGroupGeometry, fixedGroupGeometry, isGroup, resolveGroupPadding } from "@statelyai/flow";
|
|
4
|
+
import { getLayeredLayout } from "@statelyai/layout/layered";
|
|
5
|
+
import { getLayout } from "@statelyai/layout";
|
|
6
|
+
//#region src/layout/stately.ts
|
|
7
|
+
/** Graph-native layered layout powered by `@statelyai/layout`. */
|
|
8
|
+
const statelyLayout = (options = {}) => {
|
|
9
|
+
return async (graph, runOptions = {}) => {
|
|
10
|
+
throwIfAborted(runOptions);
|
|
11
|
+
const mutableGraph = graph;
|
|
12
|
+
const layoutGraph = graphForLayoutScope(mutableGraph, mergedLayoutScope(mutableGraph, options.scope, runOptions));
|
|
13
|
+
const context = layoutRunContext(mutableGraph, options, runOptions, "stately");
|
|
14
|
+
const native = await getLayout({
|
|
15
|
+
graph: toStatelyGraph(layoutGraph, options.getBounds),
|
|
16
|
+
algorithm: "layered",
|
|
17
|
+
options: nativeOptions(options),
|
|
18
|
+
...runOptions.signal ? { signal: runOptions.signal } : {}
|
|
19
|
+
});
|
|
20
|
+
context.diagnostics.push(...native.diagnostics.map((entry) => ({ ...entry })));
|
|
21
|
+
const output = applyFlowGroupContracts(native.graph, layoutGraph, nativeOptions(options), options.getBounds);
|
|
22
|
+
throwIfAborted(runOptions);
|
|
23
|
+
return fromStatelyGraph(output, layoutGraph, promotedRootOffsets(layoutGraph, mutableGraph, options.getBounds), context.fixedIds, options.getBounds, new Set(layoutGraph.edges.filter((edge) => edge.label).map((edge) => edge.id)), {
|
|
24
|
+
source: context.source,
|
|
25
|
+
metadata: {
|
|
26
|
+
...context.metadata,
|
|
27
|
+
algorithm: "layered"
|
|
28
|
+
},
|
|
29
|
+
diagnostics: context.diagnostics
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
function nativeOptions(options) {
|
|
34
|
+
const { getBounds: _getBounds, scope: _scope, source: _source, metadata: _metadata, _types, ...native } = options;
|
|
35
|
+
return native;
|
|
36
|
+
}
|
|
37
|
+
function promotedRootOffsets(scoped, full, getBounds) {
|
|
38
|
+
if (scoped === full) return /* @__PURE__ */ new Map();
|
|
39
|
+
const scopedById = new Map(scoped.nodes.map((node) => [node.id, node]));
|
|
40
|
+
const fullById = new Map(full.nodes.map((node) => [node.id, node]));
|
|
41
|
+
return new Map(scoped.nodes.flatMap((node) => {
|
|
42
|
+
const original = fullById.get(node.id);
|
|
43
|
+
if (!original?.parentId || scopedById.has(original.parentId)) return [];
|
|
44
|
+
const parent = fullById.get(original.parentId);
|
|
45
|
+
return parent ? [[node.id, boundsOf(parent, getBounds)]] : [];
|
|
46
|
+
}));
|
|
47
|
+
}
|
|
48
|
+
function applyFlowGroupContracts(output, input, options, getBounds) {
|
|
49
|
+
const nodes = output.nodes.map((node) => ({ ...node }));
|
|
50
|
+
const edges = output.edges.map((edge) => ({ ...edge }));
|
|
51
|
+
const nodeById = new Map(nodes.map((node) => [node.id, node]));
|
|
52
|
+
const inputById = new Map(input.nodes.map((node) => [node.id, node]));
|
|
53
|
+
const edgeById = new Map(edges.map((edge) => [edge.id, edge]));
|
|
54
|
+
const depth = (id) => {
|
|
55
|
+
let value = 0;
|
|
56
|
+
let parentId = nodeById.get(id)?.parentId;
|
|
57
|
+
const seen = /* @__PURE__ */ new Set();
|
|
58
|
+
while (parentId && !seen.has(parentId)) {
|
|
59
|
+
seen.add(parentId);
|
|
60
|
+
value++;
|
|
61
|
+
parentId = nodeById.get(parentId)?.parentId;
|
|
62
|
+
}
|
|
63
|
+
return value;
|
|
64
|
+
};
|
|
65
|
+
const layoutSiblings = (parentId, direction, padding = 0) => {
|
|
66
|
+
const siblings = nodes.filter((node) => (node.parentId ?? void 0) === parentId);
|
|
67
|
+
if (siblings.length === 0) return;
|
|
68
|
+
const siblingIds = new Set(siblings.map((node) => node.id));
|
|
69
|
+
const owner = (id) => {
|
|
70
|
+
let node = nodeById.get(id);
|
|
71
|
+
const seen = /* @__PURE__ */ new Set();
|
|
72
|
+
while (node && !seen.has(node.id)) {
|
|
73
|
+
seen.add(node.id);
|
|
74
|
+
if (siblingIds.has(node.id)) return node.id;
|
|
75
|
+
node = node.parentId ? nodeById.get(node.parentId) : void 0;
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
const siblingEdges = edges.flatMap((edge) => {
|
|
79
|
+
const sourceId = owner(edge.sourceId);
|
|
80
|
+
const targetId = owner(edge.targetId);
|
|
81
|
+
if (!sourceId || !targetId || sourceId === targetId) return [];
|
|
82
|
+
if (sourceId === edge.sourceId && targetId === edge.targetId) return [edge];
|
|
83
|
+
return [{
|
|
84
|
+
...edge,
|
|
85
|
+
id: `__flow_layout_proxy__${edge.id}`,
|
|
86
|
+
sourceId,
|
|
87
|
+
targetId,
|
|
88
|
+
x: 0,
|
|
89
|
+
y: 0,
|
|
90
|
+
width: 0,
|
|
91
|
+
height: 0,
|
|
92
|
+
points: void 0
|
|
93
|
+
}];
|
|
94
|
+
});
|
|
95
|
+
const laidOut = getLayeredLayout({
|
|
96
|
+
...output,
|
|
97
|
+
direction,
|
|
98
|
+
nodes: siblings.map((node) => ({
|
|
99
|
+
...node,
|
|
100
|
+
parentId: void 0
|
|
101
|
+
})),
|
|
102
|
+
edges: siblingEdges
|
|
103
|
+
}, {
|
|
104
|
+
...options,
|
|
105
|
+
direction,
|
|
106
|
+
padding
|
|
107
|
+
});
|
|
108
|
+
for (const node of laidOut.nodes) Object.assign(nodeById.get(node.id), node, { parentId });
|
|
109
|
+
for (const edge of laidOut.edges) if (edgeById.has(edge.id)) edgeById.set(edge.id, edge);
|
|
110
|
+
};
|
|
111
|
+
const groups = input.nodes.filter(isGroup).sort((left, right) => depth(right.id) - depth(left.id));
|
|
112
|
+
for (const group of groups) {
|
|
113
|
+
const node = nodeById.get(group.id);
|
|
114
|
+
if (!node) continue;
|
|
115
|
+
const children = nodes.filter((child) => child.parentId === group.id);
|
|
116
|
+
if (children.length === 0) continue;
|
|
117
|
+
layoutSiblings(group.id, group.group.direction ?? input.direction);
|
|
118
|
+
const union = boundsUnion(children);
|
|
119
|
+
const original = boundsOf(inputById.get(group.id), getBounds);
|
|
120
|
+
const contentSize = group.group.type === "fixed" ? group.group.contentSize ?? {
|
|
121
|
+
width: 0,
|
|
122
|
+
height: 0
|
|
123
|
+
} : {
|
|
124
|
+
width: original.width,
|
|
125
|
+
height: original.height
|
|
126
|
+
};
|
|
127
|
+
const normalizedUnion = {
|
|
128
|
+
...union,
|
|
129
|
+
x: 0,
|
|
130
|
+
y: 0
|
|
131
|
+
};
|
|
132
|
+
const geometry = group.group.type === "fixed" ? fixedGroupGeometry({
|
|
133
|
+
x: 0,
|
|
134
|
+
y: 0,
|
|
135
|
+
width: original.width,
|
|
136
|
+
height: original.height
|
|
137
|
+
}, contentSize, group.group) : deriveGroupGeometry(contentSize, normalizedUnion, group.group);
|
|
138
|
+
const derivedPadding = group.group.type === "derived" ? resolveGroupPadding(group.group.padding) : {
|
|
139
|
+
top: 0,
|
|
140
|
+
left: 0
|
|
141
|
+
};
|
|
142
|
+
const target = {
|
|
143
|
+
x: geometry.childArea.x - geometry.bounds.x + derivedPadding.left,
|
|
144
|
+
y: geometry.childArea.y - geometry.bounds.y + derivedPadding.top
|
|
145
|
+
};
|
|
146
|
+
shiftChildrenAndOwnedEdges(children, edgeById, target.x - union.x, target.y - union.y);
|
|
147
|
+
node.width = geometry.bounds.width;
|
|
148
|
+
node.height = geometry.bounds.height;
|
|
149
|
+
}
|
|
150
|
+
layoutSiblings(void 0, options.direction ?? input.direction, options.padding);
|
|
151
|
+
routeCrossBoundaryEdges({
|
|
152
|
+
...output,
|
|
153
|
+
nodes,
|
|
154
|
+
edges: edges.map((edge) => edgeById.get(edge.id) ?? edge)
|
|
155
|
+
}, options.direction ?? input.direction ?? "down");
|
|
156
|
+
return {
|
|
157
|
+
...output,
|
|
158
|
+
nodes,
|
|
159
|
+
edges: edges.map((edge) => edgeById.get(edge.id) ?? edge)
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
function routeCrossBoundaryEdges(graph, direction) {
|
|
163
|
+
const nodes = new Map(graph.nodes.map((node) => [node.id, node]));
|
|
164
|
+
const absolute = (id) => {
|
|
165
|
+
const node = nodes.get(id);
|
|
166
|
+
if (!node) return {
|
|
167
|
+
x: 0,
|
|
168
|
+
y: 0
|
|
169
|
+
};
|
|
170
|
+
const parent = node.parentId ? absolute(node.parentId) : {
|
|
171
|
+
x: 0,
|
|
172
|
+
y: 0
|
|
173
|
+
};
|
|
174
|
+
return {
|
|
175
|
+
x: parent.x + node.x,
|
|
176
|
+
y: parent.y + node.y
|
|
177
|
+
};
|
|
178
|
+
};
|
|
179
|
+
const horizontal = direction === "left" || direction === "right";
|
|
180
|
+
const reverse = direction === "left" || direction === "up";
|
|
181
|
+
for (const edge of graph.edges) {
|
|
182
|
+
const sourceNode = nodes.get(edge.sourceId);
|
|
183
|
+
const targetNode = nodes.get(edge.targetId);
|
|
184
|
+
if (!sourceNode || !targetNode || sourceNode.parentId === targetNode.parentId) continue;
|
|
185
|
+
const source = {
|
|
186
|
+
...absolute(sourceNode.id),
|
|
187
|
+
width: sourceNode.width,
|
|
188
|
+
height: sourceNode.height
|
|
189
|
+
};
|
|
190
|
+
const target = {
|
|
191
|
+
...absolute(targetNode.id),
|
|
192
|
+
width: targetNode.width,
|
|
193
|
+
height: targetNode.height
|
|
194
|
+
};
|
|
195
|
+
const start = horizontal ? {
|
|
196
|
+
x: reverse ? source.x : source.x + source.width,
|
|
197
|
+
y: source.y + source.height / 2
|
|
198
|
+
} : {
|
|
199
|
+
x: source.x + source.width / 2,
|
|
200
|
+
y: reverse ? source.y : source.y + source.height
|
|
201
|
+
};
|
|
202
|
+
const end = horizontal ? {
|
|
203
|
+
x: reverse ? target.x + target.width : target.x,
|
|
204
|
+
y: target.y + target.height / 2
|
|
205
|
+
} : {
|
|
206
|
+
x: target.x + target.width / 2,
|
|
207
|
+
y: reverse ? target.y + target.height : target.y
|
|
208
|
+
};
|
|
209
|
+
const track = horizontal ? {
|
|
210
|
+
x: (start.x + end.x) / 2,
|
|
211
|
+
y: 0
|
|
212
|
+
} : {
|
|
213
|
+
x: 0,
|
|
214
|
+
y: (start.y + end.y) / 2
|
|
215
|
+
};
|
|
216
|
+
const container = getLCA(graph, edge.sourceId, edge.targetId);
|
|
217
|
+
const origin = container ? absolute(container.id) : {
|
|
218
|
+
x: 0,
|
|
219
|
+
y: 0
|
|
220
|
+
};
|
|
221
|
+
edge.points = (horizontal ? [
|
|
222
|
+
start,
|
|
223
|
+
{
|
|
224
|
+
x: track.x,
|
|
225
|
+
y: start.y
|
|
226
|
+
},
|
|
227
|
+
{
|
|
228
|
+
x: track.x,
|
|
229
|
+
y: end.y
|
|
230
|
+
},
|
|
231
|
+
end
|
|
232
|
+
] : [
|
|
233
|
+
start,
|
|
234
|
+
{
|
|
235
|
+
x: start.x,
|
|
236
|
+
y: track.y
|
|
237
|
+
},
|
|
238
|
+
{
|
|
239
|
+
x: end.x,
|
|
240
|
+
y: track.y
|
|
241
|
+
},
|
|
242
|
+
end
|
|
243
|
+
]).map((point) => ({
|
|
244
|
+
x: point.x - origin.x,
|
|
245
|
+
y: point.y - origin.y
|
|
246
|
+
}));
|
|
247
|
+
edge.routing = "orthogonal";
|
|
248
|
+
edge.x = (start.x + end.x) / 2 - origin.x - edge.width / 2;
|
|
249
|
+
edge.y = (start.y + end.y) / 2 - origin.y - edge.height / 2;
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
function boundsUnion(nodes) {
|
|
253
|
+
const left = Math.min(...nodes.map((node) => node.x));
|
|
254
|
+
const top = Math.min(...nodes.map((node) => node.y));
|
|
255
|
+
const right = Math.max(...nodes.map((node) => node.x + node.width));
|
|
256
|
+
const bottom = Math.max(...nodes.map((node) => node.y + node.height));
|
|
257
|
+
return {
|
|
258
|
+
x: left,
|
|
259
|
+
y: top,
|
|
260
|
+
width: right - left,
|
|
261
|
+
height: bottom - top
|
|
262
|
+
};
|
|
263
|
+
}
|
|
264
|
+
function shiftChildrenAndOwnedEdges(children, edges, dx, dy) {
|
|
265
|
+
const ids = new Set(children.map((node) => node.id));
|
|
266
|
+
for (const child of children) {
|
|
267
|
+
child.x += dx;
|
|
268
|
+
child.y += dy;
|
|
269
|
+
}
|
|
270
|
+
for (const edge of edges.values()) {
|
|
271
|
+
if (!ids.has(edge.sourceId) || !ids.has(edge.targetId)) continue;
|
|
272
|
+
edge.x += dx;
|
|
273
|
+
edge.y += dy;
|
|
274
|
+
if (edge.points) edge.points = edge.points.map((point) => ({
|
|
275
|
+
x: point.x + dx,
|
|
276
|
+
y: point.y + dy
|
|
277
|
+
}));
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
function toStatelyGraph(graph, getBounds) {
|
|
281
|
+
const boundsById = new Map(graph.nodes.map((node) => [node.id, boundsOf(node, getBounds)]));
|
|
282
|
+
return {
|
|
283
|
+
...graph,
|
|
284
|
+
id: graph.id ?? "flow",
|
|
285
|
+
mode: graph.mode ?? "directed",
|
|
286
|
+
data: graph.data ?? {},
|
|
287
|
+
direction: graph.direction ?? "down",
|
|
288
|
+
nodes: graph.nodes.map((node) => {
|
|
289
|
+
const bounds = boundsById.get(node.id);
|
|
290
|
+
const parent = node.parentId ? boundsById.get(node.parentId) : void 0;
|
|
291
|
+
return {
|
|
292
|
+
...node,
|
|
293
|
+
...bounds,
|
|
294
|
+
x: bounds.x - (parent?.x ?? 0),
|
|
295
|
+
y: bounds.y - (parent?.y ?? 0)
|
|
296
|
+
};
|
|
297
|
+
}),
|
|
298
|
+
edges: graph.edges.map((edge) => {
|
|
299
|
+
const container = getLCA(graph, edge.sourceId, edge.targetId);
|
|
300
|
+
const origin = container ? boundsById.get(container.id) ?? {
|
|
301
|
+
x: 0,
|
|
302
|
+
y: 0
|
|
303
|
+
} : {
|
|
304
|
+
x: 0,
|
|
305
|
+
y: 0
|
|
306
|
+
};
|
|
307
|
+
return {
|
|
308
|
+
...edge,
|
|
309
|
+
x: (edge.label?.x ?? edge.x ?? 0) - origin.x,
|
|
310
|
+
y: (edge.label?.y ?? edge.y ?? 0) - origin.y,
|
|
311
|
+
width: edge.label?.width ?? edge.width ?? 0,
|
|
312
|
+
height: edge.label?.height ?? edge.height ?? 0,
|
|
313
|
+
...edge.points ? { points: edge.points.map((point) => ({
|
|
314
|
+
x: point.x - origin.x,
|
|
315
|
+
y: point.y - origin.y
|
|
316
|
+
})) } : {}
|
|
317
|
+
};
|
|
318
|
+
})
|
|
319
|
+
};
|
|
320
|
+
}
|
|
321
|
+
function fromStatelyGraph(graph, input, rootOffsets, fixedIds, getBounds, labelEdgeIds, details) {
|
|
322
|
+
const nodesById = new Map(graph.nodes.map((node) => [node.id, node]));
|
|
323
|
+
const inputNodesById = new Map(input.nodes.map((node) => [node.id, node]));
|
|
324
|
+
const absolutePositions = /* @__PURE__ */ new Map();
|
|
325
|
+
const absolutePosition = (id, visiting = /* @__PURE__ */ new Set()) => {
|
|
326
|
+
const cached = absolutePositions.get(id);
|
|
327
|
+
if (cached) return cached;
|
|
328
|
+
const node = nodesById.get(id);
|
|
329
|
+
if (!node || visiting.has(id)) return {
|
|
330
|
+
x: 0,
|
|
331
|
+
y: 0
|
|
332
|
+
};
|
|
333
|
+
if (fixedIds.has(id)) {
|
|
334
|
+
const fixed = inputNodesById.get(id);
|
|
335
|
+
if (fixed) {
|
|
336
|
+
const position = boundsOf(fixed, getBounds);
|
|
337
|
+
absolutePositions.set(id, position);
|
|
338
|
+
return position;
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
visiting.add(id);
|
|
342
|
+
const parent = node.parentId ? absolutePosition(node.parentId, visiting) : rootOffsets.get(node.id) ?? {
|
|
343
|
+
x: 0,
|
|
344
|
+
y: 0
|
|
345
|
+
};
|
|
346
|
+
const position = {
|
|
347
|
+
x: parent.x + node.x,
|
|
348
|
+
y: parent.y + node.y
|
|
349
|
+
};
|
|
350
|
+
absolutePositions.set(id, position);
|
|
351
|
+
return position;
|
|
352
|
+
};
|
|
353
|
+
const rootAncestorId = (id) => {
|
|
354
|
+
let node = nodesById.get(id);
|
|
355
|
+
const seen = /* @__PURE__ */ new Set();
|
|
356
|
+
while (node?.parentId && !seen.has(node.id)) {
|
|
357
|
+
seen.add(node.id);
|
|
358
|
+
node = nodesById.get(node.parentId);
|
|
359
|
+
}
|
|
360
|
+
return node?.id ?? id;
|
|
361
|
+
};
|
|
362
|
+
const rootOffsetOf = (id) => rootOffsets.get(rootAncestorId(id)) ?? {
|
|
363
|
+
x: 0,
|
|
364
|
+
y: 0
|
|
365
|
+
};
|
|
366
|
+
const positions = /* @__PURE__ */ new Map();
|
|
367
|
+
const nodeSizes = /* @__PURE__ */ new Map();
|
|
368
|
+
const nodeBounds = /* @__PURE__ */ new Map();
|
|
369
|
+
for (const node of graph.nodes) {
|
|
370
|
+
if (fixedIds.has(node.id)) continue;
|
|
371
|
+
const position = absolutePosition(node.id);
|
|
372
|
+
const size = {
|
|
373
|
+
width: node.width,
|
|
374
|
+
height: node.height
|
|
375
|
+
};
|
|
376
|
+
positions.set(node.id, position);
|
|
377
|
+
nodeSizes.set(node.id, size);
|
|
378
|
+
nodeBounds.set(node.id, {
|
|
379
|
+
...position,
|
|
380
|
+
...size
|
|
381
|
+
});
|
|
382
|
+
}
|
|
383
|
+
const edgeLabelBounds = /* @__PURE__ */ new Map();
|
|
384
|
+
const edgeRoutes = /* @__PURE__ */ new Map();
|
|
385
|
+
for (const edge of graph.edges) {
|
|
386
|
+
if (fixedIds.has(edge.id)) continue;
|
|
387
|
+
if (fixedIds.has(edge.sourceId) || fixedIds.has(edge.targetId)) continue;
|
|
388
|
+
const container = getLCA(graph, edge.sourceId, edge.targetId);
|
|
389
|
+
const sourceOffset = rootOffsetOf(edge.sourceId);
|
|
390
|
+
const targetOffset = rootOffsetOf(edge.targetId);
|
|
391
|
+
if (!container && (sourceOffset.x !== targetOffset.x || sourceOffset.y !== targetOffset.y)) continue;
|
|
392
|
+
const origin = container ? absolutePosition(container.id) : sourceOffset;
|
|
393
|
+
if (labelEdgeIds.has(edge.id) && Number.isFinite(edge.x) && Number.isFinite(edge.y) && Number.isFinite(edge.width) && Number.isFinite(edge.height)) edgeLabelBounds.set(edge.id, {
|
|
394
|
+
x: origin.x + edge.x,
|
|
395
|
+
y: origin.y + edge.y,
|
|
396
|
+
width: edge.width,
|
|
397
|
+
height: edge.height
|
|
398
|
+
});
|
|
399
|
+
if (edge.points && edge.points.length >= 2) edgeRoutes.set(edge.id, {
|
|
400
|
+
points: edge.points.map((point) => ({
|
|
401
|
+
x: origin.x + point.x,
|
|
402
|
+
y: origin.y + point.y
|
|
403
|
+
})),
|
|
404
|
+
...edge.routing ? { routing: edge.routing } : {}
|
|
405
|
+
});
|
|
406
|
+
}
|
|
407
|
+
return {
|
|
408
|
+
positions,
|
|
409
|
+
nodeSizes,
|
|
410
|
+
nodeBounds,
|
|
411
|
+
...edgeLabelBounds.size > 0 ? {
|
|
412
|
+
edgeLabelBounds,
|
|
413
|
+
edgeLabelPositions: new Map([...edgeLabelBounds].map(([id, bounds]) => [id, {
|
|
414
|
+
x: bounds.x,
|
|
415
|
+
y: bounds.y
|
|
416
|
+
}]))
|
|
417
|
+
} : {},
|
|
418
|
+
...edgeRoutes.size > 0 ? { edgeRoutes } : {},
|
|
419
|
+
...details.diagnostics?.length ? { diagnostics: details.diagnostics } : {},
|
|
420
|
+
source: details.source,
|
|
421
|
+
metadata: details.metadata
|
|
422
|
+
};
|
|
423
|
+
}
|
|
424
|
+
//#endregion
|
|
425
|
+
export { statelyLayout };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@statelyai/flow",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.0",
|
|
4
4
|
"description": "Framework-agnostic flow visualization engine. Builds on @statelyai/graph.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": true,
|
|
@@ -39,6 +39,12 @@
|
|
|
39
39
|
"import": "./dist/esm/layout/elk.js",
|
|
40
40
|
"default": "./dist/esm/layout/elk.js"
|
|
41
41
|
},
|
|
42
|
+
"./layout/stately": {
|
|
43
|
+
"source": "./src/layout/stately.ts",
|
|
44
|
+
"types": "./dist/esm/layout/stately.d.ts",
|
|
45
|
+
"import": "./dist/esm/layout/stately.js",
|
|
46
|
+
"default": "./dist/esm/layout/stately.js"
|
|
47
|
+
},
|
|
42
48
|
"./layout/dagre": {
|
|
43
49
|
"source": "./src/layout/dagre.ts",
|
|
44
50
|
"types": "./dist/esm/layout/dagre.d.ts",
|
|
@@ -53,12 +59,16 @@
|
|
|
53
59
|
"peerDependencies": {
|
|
54
60
|
"@dagrejs/dagre": ">=3.0.0",
|
|
55
61
|
"@statelyai/graph": ">=2.1.0",
|
|
62
|
+
"@statelyai/layout": ">=0.0.5",
|
|
56
63
|
"elkjs": ">=0.11.0"
|
|
57
64
|
},
|
|
58
65
|
"peerDependenciesMeta": {
|
|
59
66
|
"@dagrejs/dagre": {
|
|
60
67
|
"optional": true
|
|
61
68
|
},
|
|
69
|
+
"@statelyai/layout": {
|
|
70
|
+
"optional": true
|
|
71
|
+
},
|
|
62
72
|
"elkjs": {
|
|
63
73
|
"optional": true
|
|
64
74
|
}
|
|
@@ -66,6 +76,7 @@
|
|
|
66
76
|
"devDependencies": {
|
|
67
77
|
"@dagrejs/dagre": "^3.0.0",
|
|
68
78
|
"@statelyai/graph": "^2.1.0",
|
|
79
|
+
"@statelyai/layout": "^0.0.5",
|
|
69
80
|
"@vitest/coverage-v8": "^4.1.0",
|
|
70
81
|
"elkjs": "^0.11.1",
|
|
71
82
|
"tsdown": "^0.22.13",
|