@statelyai/flow 0.13.3 → 0.13.4

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
@@ -802,7 +802,7 @@ await animation.done;
802
802
 
803
803
  <!-- edge routers from src/routing/index.ts -->
804
804
 
805
- 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'`: Flow records the edge and graph fields a router reads, the bounds it looks up, and whether it reads obstacles, and skips routing when none of them and no call's geometry changed. Edits a router never reads, such as node `data`, then do not reroute.
805
+ 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'`: Flow records the edge and graph fields a router reads, the bounds it looks up, and whether it reads obstacles, and skips routing when none of them and no call's geometry changed. Edits a router never reads, such as node `data`, then do not reroute. Replay only spans graph changes: a change to other routing state, such as measurements, appearances, or selection, reroutes. Set `'snapshot'` when a router reads state outside its context, such as `flow.getNode()` or measurements through a closure. Flow then never replays its results and reroutes on every graph or routing state change.
806
806
 
807
807
  Router obstacles exclude the source, target, and their ancestor groups, so an
808
808
  edge crossing a hierarchy boundary can pass through its endpoint container.
@@ -710,7 +710,7 @@ type ProposedConnection = {
710
710
  targetPort?: string | null;
711
711
  };
712
712
  type FlowConnectionMode = 'strict' | 'loose';
713
- type EdgeRouterDependencies = 'graph' | 'endpoints';
713
+ type EdgeRouterDependencies = 'graph' | 'endpoints' | 'snapshot';
714
714
  type FlowConnectionOptions = {
715
715
  /** Magnet radius in canvas pixels. Default 24. */
716
716
  radius?: number;
@@ -754,8 +754,12 @@ type FlowEngineOptions = {
754
754
  * Geometry read by a custom edge router. Defaults to `graph`: Flow records
755
755
  * what the router reads from the edge, the graph, `getEntityBounds`, and
756
756
  * `obstacles` during a routing pass, and reroutes every edge when any of it,
757
- * or any call's geometry, changes. Use `endpoints` only
758
- * when the router depends on the edge and its endpoint/label inputs—not
757
+ * any call's geometry, or any other routing state (measurements,
758
+ * appearances, selection, connection, snapping) changes. Use `snapshot`
759
+ * when the router also reads state those views don't cover, such as
760
+ * `flow.getNode()` or measurements through a closure: Flow then reroutes on
761
+ * every graph or routing state change. Use `endpoints` only
762
+ * when the router depends on the edge and its endpoint/label inputs, not
759
763
  * arbitrary `graph`, `getEntityBounds`, or `obstacles` reads. That contract
760
764
  * lets Flow retain unaffected custom routes by identity.
761
765
  */
package/dist/esm/index.js CHANGED
@@ -6840,6 +6840,17 @@ function createFlowEngine(store, initialOptions = {}) {
6840
6840
  function sameEdgePathsCacheInputs(a, b) {
6841
6841
  return a.appearances === b.appearances && a.canonicalGraph === b.canonicalGraph && a.selection === b.selection && a.collapsedNodeIds === b.collapsedNodeIds && a.connection === b.connection && a.offsetX === b.offsetX && a.offsetY === b.offsetY && a.gridX === b.gridX && a.gridY === b.gridY && a.resizingEntityId === b.resizingEntityId && a.resizeCorners === b.resizeCorners && a.measurements === b.measurements && a.layoutOffsets === b.layoutOffsets;
6842
6842
  }
6843
+ /**
6844
+ * Whether routing state outside the graph is unchanged. Graph updates
6845
+ * replace idle layout offsets with a new empty map, so empty maps match.
6846
+ */
6847
+ function sameRoutingState(a, b) {
6848
+ return sameEdgePathsCacheInputs(a, {
6849
+ ...b,
6850
+ canonicalGraph: a.canonicalGraph,
6851
+ layoutOffsets: a.layoutOffsets.size === 0 && b.layoutOffsets.size === 0 ? a.layoutOffsets : b.layoutOffsets
6852
+ });
6853
+ }
6843
6854
  /** Route all edges. Callers must treat the returned Map as read-only. */
6844
6855
  function getAllEdgePaths(options = {}) {
6845
6856
  const c = ctx();
@@ -6883,13 +6894,15 @@ function createFlowEngine(store, initialOptions = {}) {
6883
6894
  * later pass finds every logged read unchanged and the same calls with the
6884
6895
  * same inputs, it reuses the previous results instead of calling the router,
6885
6896
  * so edits the router never looked at (a node's color, say) skip routing.
6886
- * Any difference reroutes the whole pass, which keeps routers that share
6887
- * work across calls exact.
6897
+ * Replay only bridges graph changes: any other routing state change
6898
+ * (measurements, appearances, selection, ...) reroutes, because a router
6899
+ * may read that state through a closure. Any difference reroutes the whole
6900
+ * pass, which keeps routers that share work across calls exact.
6888
6901
  */
6889
6902
  function computeAllEdgePaths(c, graph, snap = getVisualSnapOffset()) {
6890
6903
  const router = engineOptions.edgeRouter;
6891
- if (!router || engineOptions.edgeRouterDependencies === "endpoints" || graph !== c.graph || routerReadTrackingDisabled) return computeEdgePathsPass(c, graph, snap, "plain");
6892
- const previous = lastRouting?.router === router ? lastRouting : null;
6904
+ if (!router || (engineOptions.edgeRouterDependencies ?? "graph") !== "graph" || graph !== c.graph || routerReadTrackingDisabled) return computeEdgePathsPass(c, graph, snap, "plain");
6905
+ const previous = lastRouting?.router === router && sameRoutingState(lastRouting.inputs, edgePathsCacheInputs(c, snap)) ? lastRouting : null;
6893
6906
  if (previous) try {
6894
6907
  return computeEdgePathsPass(c, graph, snap, previous);
6895
6908
  } catch (error) {
@@ -6903,7 +6916,7 @@ function createFlowEngine(store, initialOptions = {}) {
6903
6916
  return computeEdgePathsPass(c, graph, snap, "plain");
6904
6917
  }
6905
6918
  }
6906
- function createRoute(c, graph, edgeMap, getEntityBounds, mode) {
6919
+ function createRoute(c, graph, edgeMap, getEntityBounds, snap, mode) {
6907
6920
  const router = engineOptions.edgeRouter ?? bezierRouter;
6908
6921
  if (mode === "plain") return {
6909
6922
  route: (edge, _key, values, getObstacles) => router(edge, {
@@ -6949,6 +6962,7 @@ function createFlowEngine(store, initialOptions = {}) {
6949
6962
  finish: () => {
6950
6963
  lastRouting = {
6951
6964
  router,
6965
+ inputs: edgePathsCacheInputs(c, snap),
6952
6966
  log: tracker.log,
6953
6967
  owners,
6954
6968
  calls
@@ -6985,7 +6999,7 @@ function createFlowEngine(store, initialOptions = {}) {
6985
6999
  const paths = /* @__PURE__ */ new Map();
6986
7000
  const nodeMap = indexNodes(graph.nodes);
6987
7001
  const edgeMap = indexEdges(graph.edges);
6988
- const { route, finish: finishRouting } = createRoute(c, graph, edgeMap, createRouterEntityBoundsLookup(graph, snap, nodeMap, edgeMap), mode);
7002
+ const { route, finish: finishRouting } = createRoute(c, graph, edgeMap, createRouterEntityBoundsLookup(graph, snap, nodeMap, edgeMap), snap, mode);
6989
7003
  const computing = /* @__PURE__ */ new Set();
6990
7004
  const trackSourceDependencies = graph === c.graph;
6991
7005
  const nextEdgeSourceDependents = trackSourceDependencies ? /* @__PURE__ */ new Map() : edgeSourceDependents;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@statelyai/flow",
3
- "version": "0.13.3",
3
+ "version": "0.13.4",
4
4
  "description": "Framework-agnostic flow visualization engine. Builds on @statelyai/graph.",
5
5
  "type": "module",
6
6
  "sideEffects": true,