@ankhorage/zora 27.2.6 → 27.3.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.
Files changed (43) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/README.md +1 -1
  3. package/dist/features/graph-view/adapters/inbound/web-artifact/GraphView.d.ts +4 -0
  4. package/dist/features/graph-view/adapters/inbound/web-artifact/GraphView.d.ts.map +1 -1
  5. package/dist/features/graph-view/adapters/inbound/web-artifact/GraphView.js +7 -1
  6. package/dist/features/graph-view/adapters/inbound/web-artifact/GraphView.js.map +1 -1
  7. package/dist/features/graph-view/adapters/inbound/web-artifact/createGraphRuntime.d.ts.map +1 -1
  8. package/dist/features/graph-view/adapters/inbound/web-artifact/createGraphRuntime.js +24 -3
  9. package/dist/features/graph-view/adapters/inbound/web-artifact/createGraphRuntime.js.map +1 -1
  10. package/dist/features/graph-view/adapters/inbound/web-artifact/getGraphGeometryKey.d.ts +1 -1
  11. package/dist/features/graph-view/adapters/inbound/web-artifact/getGraphGeometryKey.d.ts.map +1 -1
  12. package/dist/features/graph-view/adapters/inbound/web-artifact/getGraphGeometryKey.js +8 -3
  13. package/dist/features/graph-view/adapters/inbound/web-artifact/getGraphGeometryKey.js.map +1 -1
  14. package/dist/features/graph-view/adapters/inbound/web-artifact/hasGraphLayoutChanged.d.ts +1 -1
  15. package/dist/features/graph-view/adapters/inbound/web-artifact/hasGraphLayoutChanged.d.ts.map +1 -1
  16. package/dist/features/graph-view/adapters/inbound/web-artifact/hasGraphLayoutChanged.js +4 -3
  17. package/dist/features/graph-view/adapters/inbound/web-artifact/hasGraphLayoutChanged.js.map +1 -1
  18. package/dist/features/graph-view/adapters/inbound/web-artifact/placeAddedGraphNodes.d.ts +9 -0
  19. package/dist/features/graph-view/adapters/inbound/web-artifact/placeAddedGraphNodes.d.ts.map +1 -0
  20. package/dist/features/graph-view/adapters/inbound/web-artifact/placeAddedGraphNodes.js +30 -0
  21. package/dist/features/graph-view/adapters/inbound/web-artifact/placeAddedGraphNodes.js.map +1 -0
  22. package/dist/features/graph-view/public.d.ts +1 -1
  23. package/dist/features/graph-view/public.d.ts.map +1 -1
  24. package/dist/features/graph-view/public.js.map +1 -1
  25. package/dist/types/graph-view.d.ts +7 -0
  26. package/dist/types/graph-view.d.ts.map +1 -1
  27. package/dist/types/graph-view.js.map +1 -1
  28. package/dist/types/graphViewRuntime.d.ts +2 -1
  29. package/dist/types/graphViewRuntime.d.ts.map +1 -1
  30. package/dist/types/graphViewRuntime.js.map +1 -1
  31. package/package.json +1 -1
  32. package/src/features/graph-view/adapters/inbound/web-artifact/GraphView.tsx +7 -0
  33. package/src/features/graph-view/adapters/inbound/web-artifact/createGraphRuntime.test.ts +77 -0
  34. package/src/features/graph-view/adapters/inbound/web-artifact/createGraphRuntime.ts +36 -3
  35. package/src/features/graph-view/adapters/inbound/web-artifact/getGraphGeometryKey.ts +16 -12
  36. package/src/features/graph-view/adapters/inbound/web-artifact/hasGraphLayoutChanged.ts +4 -2
  37. package/src/features/graph-view/adapters/inbound/web-artifact/placeAddedGraphNodes.ts +37 -0
  38. package/src/features/graph-view/public.ts +1 -0
  39. package/src/types/graph-view.ts +7 -0
  40. package/src/types/graphViewRuntime.ts +2 -0
  41. package/web-dist/components/graph-view/GraphView.d.ts +5 -1
  42. package/web-dist/components/graph-view/GraphView.js +50 -10
  43. package/web-dist/components/graph-view/GraphView.types-0.d.ts +7 -0
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ## 27.3.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 845a331: Add the GraphView `preserve-positions` topology update policy for stable incremental graph updates.
8
+
3
9
  ## 27.2.6
4
10
 
5
11
  ### Patch Changes
package/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
 
4
4
  # ZORA
5
5
 
6
- ![license: MIT](././paradox/badges/license.svg) ![npm: v27.2.6](././paradox/badges/npm.svg) ![runtime: bun](././paradox/badges/runtime.svg) ![typescript: strict](././paradox/badges/typescript.svg) ![eslint: checked](././paradox/badges/eslint.svg) ![prettier: checked](././paradox/badges/prettier.svg) ![build: checked](././paradox/badges/build.svg) ![tests: checked](././paradox/badges/tests.svg) ![paradox: warnings](././paradox/badges/docs.svg)
6
+ ![license: MIT](././paradox/badges/license.svg) ![npm: v27.3.0](././paradox/badges/npm.svg) ![runtime: bun](././paradox/badges/runtime.svg) ![typescript: strict](././paradox/badges/typescript.svg) ![eslint: checked](././paradox/badges/eslint.svg) ![prettier: checked](././paradox/badges/prettier.svg) ![build: checked](././paradox/badges/build.svg) ![tests: checked](././paradox/badges/tests.svg) ![paradox: warnings](././paradox/badges/docs.svg)
7
7
 
8
8
  Provides opinionated React Native and React Native Web UI components, theme primitives, registries, and reader surfaces built on @ankhorage/surface.
9
9
 
@@ -16,6 +16,10 @@ import type { GraphViewProps } from '../../../../../types/graph-view';
16
16
  * Ordinary zoom never adjusts spacing or relayouts. Explicit optimization preserves layout ordering,
17
17
  * stops once effective fit reaches maxFitLabelSize, keeps labels and unrelated compound boundaries
18
18
  * collision-safe, and permits only a small rendered background-overlap fallback for dense graphs.
19
+ * topologyUpdatePolicy Use `preserve-positions` for controlled incremental topology changes. It
20
+ * retains settled nodes and the user viewport, and initially places new nodes on a deterministic
21
+ * local grid. Use an explicit controller fit or a layout change when a complete rearrangement is
22
+ * intentional.
19
23
  */
20
24
  export declare function GraphView(props: GraphViewProps): React.JSX.Element;
21
25
  export declare namespace GraphView {
@@ -1 +1 @@
1
- {"version":3,"file":"GraphView.d.ts","sourceRoot":"","sources":["../../../../../../src/features/graph-view/adapters/inbound/web-artifact/GraphView.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,KAAK,EAGV,cAAc,EAEf,MAAM,iCAAiC,CAAC;AAQzC;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,cAAc,qBAiC9C;yBAjCe,SAAS"}
1
+ {"version":3,"file":"GraphView.d.ts","sourceRoot":"","sources":["../../../../../../src/features/graph-view/adapters/inbound/web-artifact/GraphView.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,KAAK,EAGV,cAAc,EAEf,MAAM,iCAAiC,CAAC;AAQzC;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,cAAc,qBAiC9C;yBAjCe,SAAS"}
@@ -19,6 +19,10 @@ import { GraphNodeOverlay } from './GraphNodeOverlay';
19
19
  * Ordinary zoom never adjusts spacing or relayouts. Explicit optimization preserves layout ordering,
20
20
  * stops once effective fit reaches maxFitLabelSize, keeps labels and unrelated compound boundaries
21
21
  * collision-safe, and permits only a small rendered background-overlap fallback for dense graphs.
22
+ * topologyUpdatePolicy Use `preserve-positions` for controlled incremental topology changes. It
23
+ * retains settled nodes and the user viewport, and initially places new nodes on a deterministic
24
+ * local grid. Use an explicit controller fit or a layout change when a complete rearrangement is
25
+ * intentional.
22
26
  */
23
27
  export function GraphView(props) {
24
28
  const hostRef = React.useRef(null);
@@ -90,7 +94,7 @@ function useRuntimeLifecycle(containerRef, runtimeRef, callbacksRef) {
90
94
  }
91
95
  /*** Synchronize graph data and layout policy without exposing Cytoscape to React. */
92
96
  function useRuntimeGraphUpdate(runtimeRef, props) {
93
- const { edges, fitPadding, layout, layoutOptions, maxZoom, minReadableLabelSize, maxFitLabelSize, minZoom, zoomMode, sizeNodesToLabels, nodes, renderNode, spacingFactor, styleRules, } = props;
97
+ const { edges, fitPadding, layout, layoutOptions, maxZoom, minReadableLabelSize, maxFitLabelSize, minZoom, zoomMode, sizeNodesToLabels, nodes, renderNode, spacingFactor, styleRules, topologyUpdatePolicy, } = props;
94
98
  React.useEffect(() => {
95
99
  runtimeRef.current?.update({
96
100
  edges,
@@ -107,6 +111,7 @@ function useRuntimeGraphUpdate(runtimeRef, props) {
107
111
  richNodeRendering: renderNode !== undefined,
108
112
  spacingFactor,
109
113
  styleRules,
114
+ topologyUpdatePolicy,
110
115
  });
111
116
  }, [
112
117
  edges,
@@ -124,6 +129,7 @@ function useRuntimeGraphUpdate(runtimeRef, props) {
124
129
  runtimeRef,
125
130
  spacingFactor,
126
131
  styleRules,
132
+ topologyUpdatePolicy,
127
133
  ]);
128
134
  }
129
135
  /*** Synchronize optional controlled selection independently from graph layout. */
@@ -1 +1 @@
1
- {"version":3,"file":"GraphView.js","sourceRoot":"","sources":["../../../../../../src/features/graph-view/adapters/inbound/web-artifact/GraphView.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,OAAO,CAAC;AAQ1B,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,EAAE,kBAAkB,EAAqB,MAAM,sBAAsB,CAAC;AAC7E,OAAO,EAAE,2BAA2B,EAAE,MAAM,+BAA+B,CAAC;AAC5E,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAItD;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,SAAS,CAAC,KAAqB;IAC7C,MAAM,OAAO,GAAG,KAAK,CAAC,MAAM,CAAwB,IAAI,CAAC,CAAC;IAC1D,MAAM,EAAE,YAAY,EAAE,aAAa,EAAE,UAAU,EAAE,GAAG,mBAAmB,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;IAExF,OAAO,CACL,CAAC,GAAG,CACF,GAAG,CAAC,CAAC,OAAO,CAAC,CACb,UAAU,CAAC,CAAC,KAAK,CAAC,SAAS,IAAI,OAAO,CAAC,CACvC,SAAS,CAAC,CAAC,KAAK,CAAC,SAAS,CAAC,CAC3B,IAAI,CAAC,aAAa,CAClB,KAAK,CAAC,CAAC;YACL,MAAM,EAAE,MAAM;YACd,SAAS,EAAE,CAAC;YACZ,QAAQ,EAAE,CAAC;YACX,QAAQ,EAAE,UAAU;YACpB,KAAK,EAAE,MAAM;YACb,GAAG,KAAK,CAAC,K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AAC,OAAO;QACtB,gBAAgB,EAAE,KAAK,CAAC,gBAAgB;QACxC,qBAAqB,EAAE,KAAK,CAAC,qBAAqB;KACnD,CAAC;AACJ,CAAC","sourcesContent":["import type { CytoscapeOptions } from 'cytoscape';\nimport React from 'react';\n\nimport type {\n GraphViewCallbacks,\n GraphViewNode,\n GraphViewProps,\n GraphViewRenderedNode,\n} from '../../../../../types/graph-view';\nimport { GRAPH_VIEW_EVENTS } from '../../../constants/events';\nimport { createGraphRuntime, type GraphRuntime } from './createGraphRuntime';\nimport { createGraphViewDomCallbacks } from './createGraphViewDomCallbacks';\nimport { GraphNodeOverlay } from './GraphNodeOverlay';\n\ntype GraphContainer = NonNullable<CytoscapeOptions['container']>;\n\n/***\n * Render a browser graph while one runtime owns Cytoscape layout, viewport, and disposal.\n * zoomMode Use `fit-relative` to make controller zoom, events and min/max limits relative\n * to the visible-node fit (1 = fit). The default `absolute` keeps engine-space zoom units.\n * sizeNodesToLabels Opt in to renderer-measured plain labels, including bold and Unicode\n * text. Keep padding in styleRules. Compound and rich-node dimensions retain their existing owners.\n * minReadableLabelSize Expand the manual zoom ceiling until plain labels reach this CSS-pixel size.\n * maxFitLabelSize Cap automatic fitting at this plain-label CSS-pixel size, leaving whitespace for tiny graphs.\n * Browser lifecycle events named by public GRAPH_VIEW_EVENTS bubble from the root\n * with `detail.controller`: the same public GraphViewController delivered to React.\n * Browser integrations can call `measureNodes` without accessing the Cytoscape runtime.\n * The standalone browser artifact exposes the same names as `GraphView.events`.\n * onSpacingFactorChange Receive the spacing accepted by explicit fit({ optimizeSpacing: true }).\n * Ordinary zoom never adjusts spacing or relayouts. Explicit optimization preserves layout ordering,\n * stops once effective fit reaches maxFitLabelSize, keeps labels and unrelated compound boundaries\n * collision-safe, and permits only a small rendered background-overlap fallback for dense graphs.\n */\nexport function GraphView(props: GraphViewProps) {\n const hostRef = React.useRef<HTMLDivElement | null>(null);\n const { containerRef, renderedNodes, runtimeRef } = useGraphViewRuntime(props, hostRef);\n\n return (\n <div\n ref={hostRef}\n aria-label={props.ariaLabel ?? 'Graph'}\n className={props.className}\n role=\"application\"\n style={{\n height: '100%',\n minHeight: 0,\n minWidth: 0,\n position: 'relative',\n width: '100%',\n ...props.style,\n }}\n >\n <div ref={containerRef} style={{ height: '100%', width: '100%' }} />\n {props.renderNode ? (\n <GraphNodeOverlay\n nodes={props.nodes}\n renderedNodes={renderedNodes}\n renderNode={props.renderNode}\n onNodeEvent={(id, type, selectionIntent) =>\n runtimeRef.current?.handleOverlayNodeEvent(id, type, selectionIntent)\n }\n onNodeSize={(id, size) => runtimeRef.current?.setNodeSize(id, size)}\n />\n ) : null}\n </div>\n );\n}\n\n/*** Publish the same canonical event registry on the standalone GraphView artifact. */\nGraphView.events = GRAPH_VIEW_EVENTS;\n\n/*** Compose React synchronization around the single imperative graph runtime. */\nfunction useGraphViewRuntime(\n props: GraphViewProps,\n hostRef: React.RefObject<HTMLDivElement | null>,\n) {\n const containerRef = React.useRef<GraphContainer | null>(null);\n const runtimeRef = React.useRef<GraphRuntime | null>(null);\n const callbacksRef = useGraphCallbacksRef(props, hostRef);\n const [renderedNodes, setRenderedNodes] = React.useState<readonly GraphViewRenderedNode[]>([]);\n\n useRuntimeLifecycle(containerRef, runtimeRef, callbacksRef);\n useRuntimeGraphUpdate(runtimeRef, props);\n useRuntimeSelection(runtimeRef, props.selectedNodeIds);\n useRenderedNodeSubscription(runtimeRef, props.renderNode, setRenderedNodes);\n useKnownNodeSizes(runtimeRef, props.nodes, props.getNodeSize);\n\n return { containerRef, renderedNodes, runtimeRef };\n}\n\n/*** Keep the callback ref current without mutating refs during render. */\nfunction useGraphCallbacksRef(\n props: GraphViewProps,\n hostRef: React.RefObject<HTMLDivElement | null>,\n) {\n const callbacksRef = React.useRef<GraphViewCallbacks>(\n createGraphViewDomCallbacks(readCallbacks(props), hostRef),\n );\n const {\n onEdgeEvent,\n onLayoutComplete,\n onNodeEvent,\n onReady,\n onViewportChange,\n onSpacingFactorChange,\n } = props;\n\n React.useEffect(() => {\n callbacksRef.current = createGraphViewDomCallbacks(\n {\n onEdgeEvent,\n onLayoutComplete,\n onNodeEvent,\n onReady,\n onViewportChange,\n onSpacingFactorChange,\n },\n hostRef,\n );\n }, [\n onEdgeEvent,\n onLayoutComplete,\n onNodeEvent,\n onReady,\n onViewportChange,\n onSpacingFactorChange,\n hostRef,\n ]);\n\n return callbacksRef;\n}\n\n/*** Create and dispose the runtime only with the underlying browser container lifetime. */\nfunction useRuntimeLifecycle(\n containerRef: { current: GraphContainer | null },\n runtimeRef: { current: GraphRuntime | null },\n callbacksRef: { current: GraphViewCallbacks },\n) {\n React.useEffect(() => {\n const container = containerRef.current;\n if (container === null) return;\n const runtime = createGraphRuntime(container, callbacksRef);\n runtimeRef.current = runtime;\n return () => {\n runtime.destroy();\n runtimeRef.current = null;\n };\n }, [callbacksRef, containerRef, runtimeRef]);\n}\n\n/*** Synchronize graph data and layout policy without exposing Cytoscape to React. */\nfunction useRuntimeGraphUpdate(\n runtimeRef: { current: GraphRuntime | null },\n props: GraphViewProps,\n) {\n const {\n edges,\n fitPadding,\n layout,\n layoutOptions,\n maxZoom,\n minReadableLabelSize,\n maxFitLabelSize,\n minZoom,\n zoomMode,\n sizeNodesToLabels,\n nodes,\n renderNode,\n spacingFactor,\n styleRules,\n } = props;\n\n React.useEffect(() => {\n runtimeRef.current?.update({\n edges,\n fitPadding,\n layout,\n layoutOptions,\n maxZoom,\n minReadableLabelSize,\n maxFitLabelSize,\n minZoom,\n zoomMode,\n sizeNodesToLabels,\n nodes,\n richNodeRendering: renderNode !== undefined,\n spacingFactor,\n styleRules,\n });\n }, [\n edges,\n fitPadding,\n layout,\n layoutOptions,\n maxZoom,\n minReadableLabelSize,\n maxFitLabelSize,\n minZoom,\n zoomMode,\n sizeNodesToLabels,\n nodes,\n renderNode,\n runtimeRef,\n spacingFactor,\n styleRules,\n ]);\n}\n\n/*** Synchronize optional controlled selection independently from graph layout. */\nfunction useRuntimeSelection(\n runtimeRef: { current: GraphRuntime | null },\n selectedNodeIds: readonly string[] | undefined,\n) {\n React.useEffect(() => {\n runtimeRef.current?.setSelectedNodeIds(selectedNodeIds);\n }, [runtimeRef, selectedNodeIds]);\n}\n\n/*** Subscribe the optional rich-node overlay to rendered runtime positions. */\nfunction useRenderedNodeSubscription(\n runtimeRef: { current: GraphRuntime | null },\n renderNode: GraphViewProps['renderNode'],\n setRenderedNodes: (nodes: readonly GraphViewRenderedNode[]) => void,\n) {\n React.useEffect(() => {\n const runtime = runtimeRef.current;\n if (runtime === null || renderNode === undefined) {\n setRenderedNodes([]);\n return;\n }\n return runtime.subscribeRenderedNodes(setRenderedNodes);\n }, [renderNode, runtimeRef, setRenderedNodes]);\n}\n\n/*** Seed known rich-node dimensions without requiring DOM measurement. */\nfunction useKnownNodeSizes(\n runtimeRef: { current: GraphRuntime | null },\n nodes: readonly GraphViewNode[],\n getNodeSize: GraphViewProps['getNodeSize'],\n) {\n React.useEffect(() => {\n const runtime = runtimeRef.current;\n if (runtime === null || getNodeSize === undefined) return;\n for (const node of nodes) {\n const size = getNodeSize(node);\n if (size) runtime.setNodeSize(node.id, size);\n }\n }, [getNodeSize, nodes, runtimeRef]);\n}\n\n/*** Read callback props for the initial runtime callback-ref value. */\nfunction readCallbacks(props: GraphViewProps): GraphViewCallbacks {\n return {\n onEdgeEvent: props.onEdgeEvent,\n onLayoutComplete: props.onLayoutComplete,\n onNodeEvent: props.onNodeEvent,\n onReady: props.onReady,\n onViewportChange: props.onViewportChange,\n onSpacingFactorChange: props.onSpacingFactorChange,\n };\n}\n"]}
1
+ {"version":3,"file":"GraphView.js","sourceRoot":"","sources":["../../../../../../src/features/graph-view/adapters/inbound/web-artifact/GraphView.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,OAAO,CAAC;AAQ1B,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,EAAE,kBAAkB,EAAqB,MAAM,sBAAsB,CAAC;AAC7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B,CAAC,CAAC,CAAC;AACjD,CAAC;AAED,0EAA0E;AAC1E,SAAS,iBAAiB,CACxB,UAA4C,EAC5C,KAA+B,EAC/B,WAA0C;IAE1C,KAAK,CAAC,SAAS,CAAC,GAAG,EAAE;QACnB,MAAM,OAAO,GAAG,UAAU,CAAC,OAAO,CAAC;QACnC,IAAI,OAAO,KAAK,IAAI,IAAI,WAAW,KAAK,SAAS;YAAE,OAAO;QAC1D,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;YACzB,MAAM,IAAI,GAAG,WAAW,CAAC,IAAI,CAAC,CAAC;YAC/B,IAAI,IAAI;gBAAE,OAAO,CAAC,WAAW,CAAC,IAAI,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC;QAC/C,CAAC;IACH,CAAC,EAAE,CAAC,WAAW,EAAE,KAAK,EAAE,UAAU,CAAC,CAAC,CAAC;AACvC,CAAC;AAED,uEAAuE;AACvE,SAAS,aAAa,CAAC,KAAqB;IAC1C,OAAO;QACL,WAAW,EAAE,KAAK,CAAC,WAAW;QAC9B,gBAAgB,EAAE,KAAK,CAAC,gBAAgB;QACxC,WAAW,EAAE,KAAK,CAAC,WAAW;QAC9B,OAAO,EAAE,KAAK,CAAC,OAAO;QACtB,gBAAgB,EAAE,KAAK,CAAC,gBAAgB;QACxC,qBAAqB,EAAE,KAAK,CAAC,qBAAqB;KACnD,CAAC;AACJ,CAAC","sourcesContent":["import type { CytoscapeOptions } from 'cytoscape';\nimport React from 'react';\n\nimport type {\n GraphViewCallbacks,\n GraphViewNode,\n GraphViewProps,\n GraphViewRenderedNode,\n} from '../../../../../types/graph-view';\nimport { GRAPH_VIEW_EVENTS } from '../../../constants/events';\nimport { createGraphRuntime, type GraphRuntime } from './createGraphRuntime';\nimport { createGraphViewDomCallbacks } from './createGraphViewDomCallbacks';\nimport { GraphNodeOverlay } from './GraphNodeOverlay';\n\ntype GraphContainer = NonNullable<CytoscapeOptions['container']>;\n\n/***\n * Render a browser graph while one runtime owns Cytoscape layout, viewport, and disposal.\n * zoomMode Use `fit-relative` to make controller zoom, events and min/max limits relative\n * to the visible-node fit (1 = fit). The default `absolute` keeps engine-space zoom units.\n * sizeNodesToLabels Opt in to renderer-measured plain labels, including bold and Unicode\n * text. Keep padding in styleRules. Compound and rich-node dimensions retain their existing owners.\n * minReadableLabelSize Expand the manual zoom ceiling until plain labels reach this CSS-pixel size.\n * maxFitLabelSize Cap automatic fitting at this plain-label CSS-pixel size, leaving whitespace for tiny graphs.\n * Browser lifecycle events named by public GRAPH_VIEW_EVENTS bubble from the root\n * with `detail.controller`: the same public GraphViewController delivered to React.\n * Browser integrations can call `measureNodes` without accessing the Cytoscape runtime.\n * The standalone browser artifact exposes the same names as `GraphView.events`.\n * onSpacingFactorChange Receive the spacing accepted by explicit fit({ optimizeSpacing: true }).\n * Ordinary zoom never adjusts spacing or relayouts. Explicit optimization preserves layout ordering,\n * stops once effective fit reaches maxFitLabelSize, keeps labels and unrelated compound boundaries\n * collision-safe, and permits only a small rendered background-overlap fallback for dense graphs.\n * topologyUpdatePolicy Use `preserve-positions` for controlled incremental topology changes. It\n * retains settled nodes and the user viewport, and initially places new nodes on a deterministic\n * local grid. Use an explicit controller fit or a layout change when a complete rearrangement is\n * intentional.\n */\nexport function GraphView(props: GraphViewProps) {\n const hostRef = React.useRef<HTMLDivElement | null>(null);\n const { containerRef, renderedNodes, runtimeRef } = useGraphViewRuntime(props, hostRef);\n\n return (\n <div\n ref={hostRef}\n aria-label={props.ariaLabel ?? 'Graph'}\n className={props.className}\n role=\"application\"\n style={{\n height: '100%',\n minHeight: 0,\n minWidth: 0,\n position: 'relative',\n width: '100%',\n ...props.style,\n }}\n >\n <div ref={containerRef} style={{ height: '100%', width: '100%' }} />\n {props.renderNode ? (\n <GraphNodeOverlay\n nodes={props.nodes}\n renderedNodes={renderedNodes}\n renderNode={props.renderNode}\n onNodeEvent={(id, type, selectionIntent) =>\n runtimeRef.current?.handleOverlayNodeEvent(id, type, selectionIntent)\n }\n onNodeSize={(id, size) => runtimeRef.current?.setNodeSize(id, size)}\n />\n ) : null}\n </div>\n );\n}\n\n/*** Publish the same canonical event registry on the standalone GraphView artifact. */\nGraphView.events = GRAPH_VIEW_EVENTS;\n\n/*** Compose React synchronization around the single imperative graph runtime. */\nfunction useGraphViewRuntime(\n props: GraphViewProps,\n hostRef: React.RefObject<HTMLDivElement | null>,\n) {\n const containerRef = React.useRef<GraphContainer | null>(null);\n const runtimeRef = React.useRef<GraphRuntime | null>(null);\n const callbacksRef = useGraphCallbacksRef(props, hostRef);\n const [renderedNodes, setRenderedNodes] = React.useState<readonly GraphViewRenderedNode[]>([]);\n\n useRuntimeLifecycle(containerRef, runtimeRef, callbacksRef);\n useRuntimeGraphUpdate(runtimeRef, props);\n useRuntimeSelection(runtimeRef, props.selectedNodeIds);\n useRenderedNodeSubscription(runtimeRef, props.renderNode, setRenderedNodes);\n useKnownNodeSizes(runtimeRef, props.nodes, props.getNodeSize);\n\n return { containerRef, renderedNodes, runtimeRef };\n}\n\n/*** Keep the callback ref current without mutating refs during render. */\nfunction useGraphCallbacksRef(\n props: GraphViewProps,\n hostRef: React.RefObject<HTMLDivElement | null>,\n) {\n const callbacksRef = React.useRef<GraphViewCallbacks>(\n createGraphViewDomCallbacks(readCallbacks(props), hostRef),\n );\n const {\n onEdgeEvent,\n onLayoutComplete,\n onNodeEvent,\n onReady,\n onViewportChange,\n onSpacingFactorChange,\n } = props;\n\n React.useEffect(() => {\n callbacksRef.current = createGraphViewDomCallbacks(\n {\n onEdgeEvent,\n onLayoutComplete,\n onNodeEvent,\n onReady,\n onViewportChange,\n onSpacingFactorChange,\n },\n hostRef,\n );\n }, [\n onEdgeEvent,\n onLayoutComplete,\n onNodeEvent,\n onReady,\n onViewportChange,\n onSpacingFactorChange,\n hostRef,\n ]);\n\n return callbacksRef;\n}\n\n/*** Create and dispose the runtime only with the underlying browser container lifetime. */\nfunction useRuntimeLifecycle(\n containerRef: { current: GraphContainer | null },\n runtimeRef: { current: GraphRuntime | null },\n callbacksRef: { current: GraphViewCallbacks },\n) {\n React.useEffect(() => {\n const container = containerRef.current;\n if (container === null) return;\n const runtime = createGraphRuntime(container, callbacksRef);\n runtimeRef.current = runtime;\n return () => {\n runtime.destroy();\n runtimeRef.current = null;\n };\n }, [callbacksRef, containerRef, runtimeRef]);\n}\n\n/*** Synchronize graph data and layout policy without exposing Cytoscape to React. */\nfunction useRuntimeGraphUpdate(\n runtimeRef: { current: GraphRuntime | null },\n props: GraphViewProps,\n) {\n const {\n edges,\n fitPadding,\n layout,\n layoutOptions,\n maxZoom,\n minReadableLabelSize,\n maxFitLabelSize,\n minZoom,\n zoomMode,\n sizeNodesToLabels,\n nodes,\n renderNode,\n spacingFactor,\n styleRules,\n topologyUpdatePolicy,\n } = props;\n\n React.useEffect(() => {\n runtimeRef.current?.update({\n edges,\n fitPadding,\n layout,\n layoutOptions,\n maxZoom,\n minReadableLabelSize,\n maxFitLabelSize,\n minZoom,\n zoomMode,\n sizeNodesToLabels,\n nodes,\n richNodeRendering: renderNode !== undefined,\n spacingFactor,\n styleRules,\n topologyUpdatePolicy,\n });\n }, [\n edges,\n fitPadding,\n layout,\n layoutOptions,\n maxZoom,\n minReadableLabelSize,\n maxFitLabelSize,\n minZoom,\n zoomMode,\n sizeNodesToLabels,\n nodes,\n renderNode,\n runtimeRef,\n spacingFactor,\n styleRules,\n topologyUpdatePolicy,\n ]);\n}\n\n/*** Synchronize optional controlled selection independently from graph layout. */\nfunction useRuntimeSelection(\n runtimeRef: { current: GraphRuntime | null },\n selectedNodeIds: readonly string[] | undefined,\n) {\n React.useEffect(() => {\n runtimeRef.current?.setSelectedNodeIds(selectedNodeIds);\n }, [runtimeRef, selectedNodeIds]);\n}\n\n/*** Subscribe the optional rich-node overlay to rendered runtime positions. */\nfunction useRenderedNodeSubscription(\n runtimeRef: { current: GraphRuntime | null },\n renderNode: GraphViewProps['renderNode'],\n setRenderedNodes: (nodes: readonly GraphViewRenderedNode[]) => void,\n) {\n React.useEffect(() => {\n const runtime = runtimeRef.current;\n if (runtime === null || renderNode === undefined) {\n setRenderedNodes([]);\n return;\n }\n return runtime.subscribeRenderedNodes(setRenderedNodes);\n }, [renderNode, runtimeRef, setRenderedNodes]);\n}\n\n/*** Seed known rich-node dimensions without requiring DOM measurement. */\nfunction useKnownNodeSizes(\n runtimeRef: { current: GraphRuntime | null },\n nodes: readonly GraphViewNode[],\n getNodeSize: GraphViewProps['getNodeSize'],\n) {\n React.useEffect(() => {\n const runtime = runtimeRef.current;\n if (runtime === null || getNodeSize === undefined) return;\n for (const node of nodes) {\n const size = getNodeSize(node);\n if (size) runtime.setNodeSize(node.id, size);\n }\n }, [getNodeSize, nodes, runtimeRef]);\n}\n\n/*** Read callback props for the initial runtime callback-ref value. */\nfunction readCallbacks(props: GraphViewProps): GraphViewCallbacks {\n return {\n onEdgeEvent: props.onEdgeEvent,\n onLayoutComplete: props.onLayoutComplete,\n onNodeEvent: props.onNodeEvent,\n onReady: props.onReady,\n onViewportChange: props.onViewportChange,\n onSpacingFactorChange: props.onSpacingFactorChange,\n };\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"createGraphRuntime.d.ts","sourceRoot":"","sources":["../../../../../../src/features/graph-view/adapters/inbound/web-artifact/createGraphRuntime.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AACpE,OAAkB,EAAa,KAAK,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAExE,OAAO,KAAK,EACV,kBAAkB,EAClB,yBAAyB,EAEzB,qBAAqB,EACrB,aAAa,EAEd,MAAM,iCAAiC,CAAC;AACzC,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,uCAAuC,CAAC;AAiBhF,KAAK,cAAc,GAAG,gBAAgB,CAAC,WAAW,CAAC,CAAC;AACpD,KAAK,oBAAoB,GAAG,CAAC,KAAK,EAAE,SAAS,qBAAqB,EAAE,KAAK,IAAI,CAAC;AAE9E,MAAM,WAAW,YAAY;IAC3B,OAAO,IAAI,IAAI,CAAC;IAChB,sBAAsB,CACpB,EAAE,EAAE,MAAM,EACV,IAAI,EAAE,yBAAyB,EAC/B,eAAe,CAAC,EAAE,eAAe,GAChC,IAAI,CAAC;IACR,WAAW,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,aAAa,GAAG,IAAI,CAAC;IACnD,kBAAkB,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,GAAG,SAAS,GAAG,IAAI,CAAC;IACjE,sBAAsB,CAAC,QAAQ,EAAE,oBAAoB,GAAG,MAAM,IAAI,CAAC;IACnE,MAAM,CAAC,KAAK,EAAE,kBAAkB,GAAG,IAAI,CAAC;CACzC;AA6BD,6FAA6F;AAC7F,wBAAgB,kBAAkB,CAChC,SAAS,EAAE,cAAc,EACzB,YAAY,EAAE;IAAE,OAAO,EAAE,kBAAkB,CAAA;CAAE,GAC5C,YAAY,CAoBd"}
1
+ {"version":3,"file":"createGraphRuntime.d.ts","sourceRoot":"","sources":["../../../../../../src/features/graph-view/adapters/inbound/web-artifact/createGraphRuntime.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AACpE,OAAkB,EAAa,KAAK,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAExE,OAAO,KAAK,EACV,kBAAkB,EAClB,yBAAyB,EAEzB,qBAAqB,EACrB,aAAa,EAEd,MAAM,iCAAiC,CAAC;AACzC,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,uCAAuC,CAAC;AAkBhF,KAAK,cAAc,GAAG,gBAAgB,CAAC,WAAW,CAAC,CAAC;AACpD,KAAK,oBAAoB,GAAG,CAAC,KAAK,EAAE,SAAS,qBAAqB,EAAE,KAAK,IAAI,CAAC;AAE9E,MAAM,WAAW,YAAY;IAC3B,OAAO,IAAI,IAAI,CAAC;IAChB,sBAAsB,CACpB,EAAE,EAAE,MAAM,EACV,IAAI,EAAE,yBAAyB,EAC/B,eAAe,CAAC,EAAE,eAAe,GAChC,IAAI,CAAC;IACR,WAAW,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,aAAa,GAAG,IAAI,CAAC;IACnD,kBAAkB,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,GAAG,SAAS,GAAG,IAAI,CAAC;IACjE,sBAAsB,CAAC,QAAQ,EAAE,oBAAoB,GAAG,MAAM,IAAI,CAAC;IACnE,MAAM,CAAC,KAAK,EAAE,kBAAkB,GAAG,IAAI,CAAC;CACzC;AA6BD,6FAA6F;AAC7F,wBAAgB,kBAAkB,CAChC,SAAS,EAAE,cAAc,EACzB,YAAY,EAAE;IAAE,OAAO,EAAE,kBAAkB,CAAA;CAAE,GAC5C,YAAY,CAoBd"}
@@ -7,6 +7,7 @@ import { createGraphResizeObserver } from './createGraphResizeObserver';
7
7
  import { getGraphGeometryKey } from './getGraphGeometryKey';
8
8
  import { getGraphTopologyKey } from './getGraphTopologyKey';
9
9
  import { hasGraphLayoutChanged } from './hasGraphLayoutChanged';
10
+ import { placeAddedGraphNodes } from './placeAddedGraphNodes';
10
11
  import { readGraphRenderedNodes } from './readGraphRenderedNodes';
11
12
  import { registerGraphLayouts } from './registerGraphLayouts';
12
13
  import { runGraphLayout } from './runGraphLayout';
@@ -103,9 +104,14 @@ function updateRuntime(state, input) {
103
104
  state.latestUpdateRef.current = input;
104
105
  state.fitPaddingRef.current = input.fitPadding ?? 50;
105
106
  state.viewport.configure(input);
107
+ const preservesTopology = shouldPreserveTopology(state, previous, input);
108
+ const retainedNodeIds = getRetainedNodeIds(previous, input, preservesTopology);
109
+ const retainedGeometry = retainedNodeIds === null ? null : getGraphGeometryKey(state.cy, retainedNodeIds);
106
110
  state.cy.batch(() => {
107
111
  if (previous?.nodes !== input.nodes || previous.edges !== input.edges) {
108
112
  syncGraphElements(state.cy, input.nodes, input.edges);
113
+ if (preservesTopology)
114
+ placeAddedGraphNodes(state.cy, previous?.nodes ?? [], input.nodes);
109
115
  }
110
116
  if (previous?.styleRules !== input.styleRules ||
111
117
  previous?.richNodeRendering !== input.richNodeRendering) {
@@ -119,7 +125,10 @@ function updateRuntime(state, input) {
119
125
  const geometry = getGraphGeometryKey(state.cy);
120
126
  // Keep native double-press targets stable for paint-only class changes. A class that changes
121
127
  // measured node dimensions remains a geometry change and must relayout.
122
- const relayout = hasGraphLayoutChanged(previous, input) || geometry !== state.geometryRef.current;
128
+ const geometryChanged = retainedGeometry === null
129
+ ? geometry !== state.geometryRef.current
130
+ : retainedGeometry !== getGraphGeometryKey(state.cy, retainedNodeIds ?? undefined);
131
+ const relayout = hasGraphLayoutChanged(previous, input, preservesTopology) || geometryChanged;
123
132
  state.geometryRef.current = geometry;
124
133
  if (!relayout) {
125
134
  if (previous?.zoomMode !== input.zoomMode ||
@@ -131,8 +140,6 @@ function updateRuntime(state, input) {
131
140
  state.viewport.settle(previous?.zoomMode !== input.zoomMode);
132
141
  }
133
142
  emitRenderedNodes(state);
134
- if (!state.layoutRunningRef.current && !state.pendingInitialFitRef.current)
135
- state.callbacksRef.current.onLayoutComplete?.(state.controller);
136
143
  return;
137
144
  }
138
145
  stopCurrentLayout(state);
@@ -140,6 +147,20 @@ function updateRuntime(state, input) {
140
147
  state.optimizedSpacingRef.current = null;
141
148
  startCurrentLayout(state, input);
142
149
  }
150
+ /*** Preserve only opt-in topology updates after the initial layout and fit have settled. */
151
+ function shouldPreserveTopology(state, previous, input) {
152
+ return (previous !== null &&
153
+ state.readyRef.current &&
154
+ !state.pendingInitialFitRef.current &&
155
+ input.topologyUpdatePolicy === 'preserve-positions');
156
+ }
157
+ /*** Limit stable-update geometry checks to nodes that existed before reconciliation. */
158
+ function getRetainedNodeIds(previous, input, preservesTopology) {
159
+ if (!preservesTopology || previous === null)
160
+ return null;
161
+ const nextNodeIds = new Set(input.nodes.map((node) => node.id));
162
+ return new Set(previous.nodes.map((node) => node.id).filter((id) => nextNodeIds.has(id)));
163
+ }
143
164
  /*** Start a generation-safe layout whose completion is the only normal automatic fit trigger. */
144
165
  function startCurrentLayout(state, input) {
145
166
  state.pendingInitialFitRef.current = false;
@@ -1 +1 @@
1
- {"version":3,"file":"createGraphRuntime.js","sourceRoot":"","sources":["../../../../../../src/features/graph-view/adapters/inbound/web-artifact/createGraphRuntime.ts"],"names":[],"mappings":"AACA,OAAO,SAAS,EAAE,EAAoC,MAAM,WAAW,CAAC;AAWxE,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAChE,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,EAAE,yBAAyB,EAA4B,MAAM,6BAA6B,CAAC;AAClG,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAChE,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAC;AACxE,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AA6CxD,6FAA6F;AAC7F,MAAM,UAAU,kBAAkB,CAChC,SAAyB,EACzB,YAA6C;IAE7C,MAAM,EAAE,GAAG,SAAS,CAAC;QACnB,SAAS;QACT,QAAQ,EAAE,EAAE;QACZ,OAAO,EAAE,IAAI;QACb,OAA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iBAAiB,CAAC,EAAQ;IACjC,OAAO,EAAE,CAAC,KAAK,EAAE,GAAG,CAAC,IAAI,EAAE,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;AAC3C,CAAC;AAED,8EAA8E;AAC9E,SAAS,cAAc,CAAC,KAAwB;IAC9C,KAAK,CAAC,cAAc,EAAE,UAAU,EAAE,CAAC;IACnC,iBAAiB,CAAC,KAAK,CAAC,CAAC;IACzB,KAAK,CAAC,YAAY,EAAE,CAAC;IACrB,KAAK,CAAC,qBAAqB,CAAC,KAAK,EAAE,CAAC;IACpC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,SAAS,EAAE;QAAE,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC;AAChD,CAAC;AAED,oBAAoB,EAAE,CAAC","sourcesContent":["import type { SelectionIntent } from '@ankhorage/utility/selection';\nimport cytoscape, { type Core, type CytoscapeOptions } from 'cytoscape';\n\nimport type {\n GraphViewCallbacks,\n GraphViewElementEventType,\n GraphViewFitOptions,\n GraphViewRenderedNode,\n GraphViewSize,\n GraphViewStyleRule,\n} from '../../../../../types/graph-view';\nimport type { GraphRuntimeUpdate } from '../../../../../types/graphViewRuntime';\nimport { bindGraphEvents } from './bindGraphEvents';\nimport { compactGraphSpacing } from './compactGraphSpacing';\nimport { createGraphController } from './createGraphController';\nimport { createGraphLoopSizer } from './createGraphLoopSizer';\nimport { createGraphResizeObserver, type GraphResizeObserver } from './createGraphResizeObserver';\nimport { getGraphGeometryKey } from './getGraphGeometryKey';\nimport { getGraphTopologyKey } from './getGraphTopologyKey';\nimport { hasGraphLayoutChanged } from './hasGraphLayoutChanged';\nimport { readGraphRenderedNodes } from './readGraphRenderedNodes';\nimport { registerGraphLayouts } from './registerGraphLayouts';\nimport { runGraphLayout } from './runGraphLayout';\nimport { scheduleGraphFrame } from './scheduleGraphFrame';\nimport { shouldFitGraphAfterLayout } from './shouldFitGraphAfterLayout';\nimport { sizeGraphNodesToLabels } from './sizeGraphNodesToLabels';\nimport { syncGraphElements } from './syncGraphElements';\n\ntype GraphContainer = CytoscapeOptions['container'];\ntype RenderedNodeListener = (nodes: readonly GraphViewRenderedNode[]) => void;\n\nexport interface GraphRuntime {\n destroy(): void;\n handleOverlayNodeEvent(\n id: string,\n type: GraphViewElementEventType,\n selectionIntent?: SelectionIntent,\n ): void;\n setNodeSize(id: string, size: GraphViewSize): void;\n setSelectedNodeIds(nodeIds: readonly string[] | undefined): void;\n subscribeRenderedNodes(listener: RenderedNodeListener): () => void;\n update(input: GraphRuntimeUpdate): void;\n}\n\ninterface GraphRuntimeState {\n readonly fitRequestRef: { current: GraphViewFitOptions | null };\n readonly optimizedSpacingRef: { current: number | null };\n readonly callbacksRef: { current: GraphViewCallbacks };\n readonly controller: ReturnType<typeof createGraphController>['controller'];\n readonly viewport: ReturnType<typeof createGraphController>;\n readonly cy: Core;\n readonly fitPaddingRef: { current: number };\n readonly generationRef: { current: number };\n readonly geometryRef: { current: string | null };\n readonly hoveredNodeIds: Set<string>;\n readonly latestUpdateRef: { current: GraphRuntimeUpdate | null };\n readonly layoutRef: { current: ReturnType<typeof runGraphLayout> | null };\n readonly layoutRunningRef: { current: boolean };\n readonly nodeSizes: Map<string, GraphViewSize>;\n readonly labelSizedNodeIds: Set<string>;\n readonly loopSizer: ReturnType<typeof createGraphLoopSizer>;\n readonly pendingInitialFitRef: { current: boolean };\n readonly readyRef: { current: boolean };\n readonly settledLayoutRef: { current: GraphRuntimeUpdate['layout'] | null };\n readonly settledTopologyRef: { current: string | null };\n readonly relayoutScheduledRef: { current: boolean };\n readonly renderedNodeListeners: Set<RenderedNodeListener>;\n readonly resizeObserver: GraphResizeObserver | null;\n readonly unbindEvents: () => void;\n}\n\n/*** Create one Cytoscape runtime that exclusively owns layout, fit, resize, and disposal. */\nexport function createGraphRuntime(\n container: GraphContainer,\n callbacksRef: { current: GraphViewCallbacks },\n): GraphRuntime {\n const cy = cytoscape({\n container,\n elements: [],\n minZoom: 0.05,\n maxZoom: 2,\n selectionType: 'additive',\n userPanningEnabled: true,\n });\n const state = createRuntimeState(cy, container, callbacksRef);\n\n return {\n destroy: () => destroyRuntime(state),\n handleOverlayNodeEvent: (id, type, selectionIntent) =>\n handleOverlayNodeEvent(state, id, type, selectionIntent),\n setNodeSize: (id, size) => setNodeSize(state, id, size),\n setSelectedNodeIds: (nodeIds) => setSelectedNodeIds(state, nodeIds),\n subscribeRenderedNodes: (listener) => subscribeRenderedNodes(state, listener),\n update: (input) => updateRuntime(state, input),\n };\n}\n\n/*** Build the mutable state shared by the single graph-runtime owner. */\nfunction createRuntimeState(\n cy: Core,\n container: GraphContainer,\n callbacksRef: { current: GraphViewCallbacks },\n): GraphRuntimeState {\n const fitPaddingRef = { current: 50 };\n const viewport = createGraphController(cy, fitPaddingRef, (options) =>\n requestOptimizedFit(state, options),\n );\n const { controller } = viewport;\n const layoutRunningRef = { current: false };\n const readyRef = { current: false };\n const renderedNodeListeners = new Set<RenderedNodeListener>();\n const stateBase = {\n fitRequestRef: { current: null as GraphViewFitOptions | null },\n optimizedSpacingRef: { current: null as number | null },\n callbacksRef,\n controller,\n viewport,\n cy,\n fitPaddingRef,\n generationRef: { current: 0 },\n geometryRef: { current: null as string | null },\n hoveredNodeIds: new Set<string>(),\n latestUpdateRef: { current: null as GraphRuntimeUpdate | null },\n layoutRef: { current: null as ReturnType<typeof runGraphLayout> | null },\n layoutRunningRef,\n nodeSizes: new Map<string, GraphViewSize>(),\n labelSizedNodeIds: new Set<string>(),\n loopSizer: createGraphLoopSizer(cy),\n pendingInitialFitRef: { current: false },\n readyRef,\n settledLayoutRef: { current: null as GraphRuntimeUpdate['layout'] | null },\n settledTopologyRef: { current: null as string | null },\n relayoutScheduledRef: { current: false },\n renderedNodeListeners,\n };\n const unbindEvents = bindGraphEvents(cy, callbacksRef, controller, () =>\n emitRenderedNodes(stateBase),\n );\n const resizeObserver = createGraphResizeObserver({\n container,\n cy,\n beginViewportResize: () => viewport.beginResize(),\n settleViewport: (fit) => viewport.settle(fit),\n layoutRunningRef,\n pendingInitialFitRef: stateBase.pendingInitialFitRef,\n onViewportSettled: (completedPendingInitialFit) => {\n emitRenderedNodes(stateBase);\n if (!completedPendingInitialFit || readyRef.current) return;\n readyRef.current = true;\n callbacksRef.current.onReady?.(controller);\n callbacksRef.current.onLayoutComplete?.(controller);\n },\n readyRef,\n });\n\n const state = { ...stateBase, resizeObserver, unbindEvents };\n return state;\n}\n\n/***\n * Reconcile presentation in place and relayout only when graph geometry or layout policy changes.\n * Batch reconciliation and skip layout for presentation-only updates.\n */\nfunction updateRuntime(state: GraphRuntimeState, input: GraphRuntimeUpdate) {\n if (state.cy.destroyed()) return;\n const last = state.latestUpdateRef.current;\n const acceptsSpacing =\n state.optimizedSpacingRef.current !== null &&\n state.optimizedSpacingRef.current === input.spacingFactor;\n const previous = acceptsSpacing && last ? { ...last, spacingFactor: input.spacingFactor } : last;\n if (acceptsSpacing) state.optimizedSpacingRef.current = null;\n state.latestUpdateRef.current = input;\n state.fitPaddingRef.current = input.fitPadding ?? 50;\n state.viewport.configure(input);\n state.cy.batch(() => {\n if (previous?.nodes !== input.nodes || previous.edges !== input.edges) {\n syncGraphElements(state.cy, input.nodes, input.edges);\n }\n if (\n previous?.styleRules !== input.styleRules ||\n previous?.richNodeRendering !== input.richNodeRendering\n ) {\n state.loopSizer.reset();\n applyGraphStyles(state.cy, input.styleRules, input.richNodeRendering);\n }\n });\n sizeGraphNodesToLabels(\n state.cy,\n state.labelSizedNodeIds,\n input.sizeNodesToLabels === true && !input.richNodeRendering,\n );\n applyKnownNodeSizes(state);\n state.loopSizer.update();\n const geometry = getGraphGeometryKey(state.cy);\n // Keep native double-press targets stable for paint-only class changes. A class that changes\n // measured node dimensions remains a geometry change and must relayout.\n const relayout = hasGraphLayoutChanged(previous, input) || geometry !== state.geometryRef.current;\n state.geometryRef.current = geometry;\n if (!relayout) {\n if (\n previous?.zoomMode !== input.zoomMode ||\n previous?.fitPadding !== input.fitPadding ||\n previous?.minZoom !== input.minZoom ||\n previous?.maxZoom !== input.maxZoom ||\n previous?.minReadableLabelSize !== input.minReadableLabelSize ||\n previous?.maxFitLabelSize !== input.maxFitLabelSize\n ) {\n state.viewport.settle(previous?.zoomMode !== input.zoomMode);\n }\n emitRenderedNodes(state);\n if (!state.layoutRunningRef.current && !state.pendingInitialFitRef.current)\n state.callbacksRef.current.onLayoutComplete?.(state.controller);\n return;\n }\n stopCurrentLayout(state);\n state.fitRequestRef.current = null;\n state.optimizedSpacingRef.current = null;\n startCurrentLayout(state, input);\n}\n\n/*** Start a generation-safe layout whose completion is the only normal automatic fit trigger. */\nfunction startCurrentLayout(state: GraphRuntimeState, input: GraphRuntimeUpdate) {\n state.pendingInitialFitRef.current = false;\n const generation = state.generationRef.current + 1;\n state.generationRef.current = generation;\n state.layoutRunningRef.current = true;\n state.cy.resize();\n state.layoutRef.current = runGraphLayout(\n state.cy,\n {\n layout: input.layout ?? 'concentric',\n layoutOptions: input.layoutOptions,\n spacingFactor: input.spacingFactor ?? 1,\n },\n () => completeCurrentLayout(state, generation),\n );\n}\n\n/***\n * Settle only the latest layout generation and fit once from node bounds.\n * Discard stale completions and avoid repeated automatic fits.\n */\nfunction completeCurrentLayout(state: GraphRuntimeState, generation: number) {\n scheduleGraphFrame(() => {\n if (state.cy.destroyed() || generation !== state.generationRef.current) return;\n state.loopSizer.update();\n state.layoutRef.current = null;\n state.cy.resize();\n state.layoutRunningRef.current = false;\n state.resizeObserver?.flushAfterLayout();\n if (!hasUsableViewport(state.cy)) {\n if (!state.readyRef.current) state.pendingInitialFitRef.current = true;\n return;\n }\n state.pendingInitialFitRef.current = false;\n const input = state.latestUpdateRef.current;\n if (input === null) return;\n const topology = getGraphTopologyKey(input.nodes, input.edges);\n const shouldFit = shouldFitGraphAfterLayout(\n state.readyRef.current,\n topology !== state.settledTopologyRef.current,\n input.layout !== state.settledLayoutRef.current,\n );\n state.viewport.settle(shouldFit);\n state.settledLayoutRef.current = input.layout;\n state.settledTopologyRef.current = topology;\n const fitRequest = state.fitRequestRef.current;\n state.fitRequestRef.current = null;\n if (fitRequest) requestOptimizedFit(state, fitRequest);\n emitRenderedNodes(state);\n\n if (!state.readyRef.current) {\n state.readyRef.current = true;\n state.callbacksRef.current.onReady?.(state.controller);\n }\n state.callbacksRef.current.onLayoutComplete?.(state.controller);\n });\n}\n\n/***\n * Handle explicit readable-fit intent in the runtime owner, never from zoom or React effects.\n * Bounded spacing optimization preserves the settled algorithm instead of repeatedly running it.\n */\nfunction requestOptimizedFit(state: GraphRuntimeState, options: GraphViewFitOptions) {\n if (state.cy.destroyed()) return;\n if (state.layoutRunningRef.current) {\n state.fitRequestRef.current = options;\n return;\n }\n const input = state.latestUpdateRef.current;\n if (!input) return;\n const previous = state.optimizedSpacingRef.current ?? input.spacingFactor ?? 1;\n const spacing = compactGraphSpacing(state.cy, previous, {\n fitPadding: options.padding ?? state.fitPaddingRef.current,\n maxFitZoom: state.viewport.getFitZoomLimit(),\n minReadableZoom: state.viewport.getReadableZoomTarget(),\n });\n state.geometryRef.current = getGraphGeometryKey(state.cy);\n state.loopSizer.update();\n state.viewport.settle(false);\n state.controller.fit({ ...options, optimizeSpacing: false });\n if (spacing !== previous) {\n state.optimizedSpacingRef.current = spacing;\n state.callbacksRef.current.onSpacingFactorChange?.(spacing);\n }\n emitRenderedNodes(state);\n}\n\n/*** Stop the current layout and invalidate every stale completion callback. */\nfunction stopCurrentLayout(state: GraphRuntimeState) {\n state.generationRef.current += 1;\n state.layoutRunningRef.current = false;\n state.layoutRef.current?.stop();\n state.layoutRef.current = null;\n}\n\n/*** Apply consumer styles and hide native node paint only when React rich nodes are active. */\nfunction applyGraphStyles(\n cy: Core,\n rules: readonly GraphViewStyleRule[] | undefined,\n richNodeRendering: boolean,\n) {\n const styles = [...(rules ?? [])];\n if (richNodeRendering) {\n styles.push({\n selector: 'node',\n style: {\n 'background-opacity': 0,\n 'border-width': 0,\n label: '',\n 'overlay-opacity': 0,\n },\n });\n }\n if (styles.length > 0) cy.style(styles).update();\n}\n\n/***\n * Synchronize controlled selection without rerunning layout.\n * Selection updates must not trigger graph reconstruction or layout.\n */\nfunction setSelectedNodeIds(state: GraphRuntimeState, nodeIds: readonly string[] | undefined) {\n if (state.cy.destroyed() || nodeIds === undefined) return;\n const selectedIds = new Set(nodeIds);\n state.cy.nodes().forEach((node) => {\n if (selectedIds.has(node.id())) node.select();\n else node.unselect();\n });\n emitRenderedNodes(state);\n}\n\n/***\n * Persist one rich-node size and schedule at most one relayout for changed geometry.\n * Ignore unchanged measurements before scheduling layout work.\n */\nfunction setNodeSize(state: GraphRuntimeState, id: string, size: GraphViewSize) {\n const previous = state.nodeSizes.get(id);\n if (previous?.width === size.width && previous.height === size.height) return;\n state.nodeSizes.set(id, size);\n applyNodeSize(state.cy, id, size);\n scheduleMeasuredNodeRelayout(state);\n}\n\n/*** Apply every known rich-node size after Cytoscape elements are replaced. */\nfunction applyKnownNodeSizes(state: GraphRuntimeState) {\n for (const [id, size] of state.nodeSizes) applyNodeSize(state.cy, id, size);\n}\n\n/*** Apply one measured model-space size as a Cytoscape per-node style bypass. */\nfunction applyNodeSize(cy: Core, id: string, size: GraphViewSize) {\n const node = cy.getElementById(id);\n if (node.empty()) return;\n node.style({ height: size.height, width: size.width });\n}\n\n/***\n * Coalesce DOM measurements into one follow-up layout generation.\n * Keep one scheduled layout per frame instead of one per measured node.\n */\nfunction scheduleMeasuredNodeRelayout(state: GraphRuntimeState) {\n if (state.relayoutScheduledRef.current) return;\n state.relayoutScheduledRef.current = true;\n scheduleGraphFrame(() => {\n state.relayoutScheduledRef.current = false;\n const input = state.latestUpdateRef.current;\n if (input === null || state.cy.destroyed()) return;\n stopCurrentLayout(state);\n startCurrentLayout(state, input);\n });\n}\n\n/*** Subscribe one React overlay to rendered node state without exposing the Cytoscape core. */\nfunction subscribeRenderedNodes(state: GraphRuntimeState, listener: RenderedNodeListener) {\n state.renderedNodeListeners.add(listener);\n listener(readGraphRenderedNodes(state.cy, state.hoveredNodeIds));\n return () => {\n state.renderedNodeListeners.delete(listener);\n };\n}\n\n/***\n * Publish current rendered node positions only to active rich-node subscribers.\n * Skip snapshot preparation when no overlay is subscribed.\n */\nfunction emitRenderedNodes(\n state: Pick<GraphRuntimeState, 'cy' | 'hoveredNodeIds' | 'renderedNodeListeners'>,\n) {\n if (state.renderedNodeListeners.size === 0) return;\n const nodes = readGraphRenderedNodes(state.cy, state.hoveredNodeIds);\n for (const listener of state.renderedNodeListeners) listener(nodes);\n}\n\n/*** Translate one rich-overlay event back into normal graph selection and callbacks. */\nfunction handleOverlayNodeEvent(\n state: GraphRuntimeState,\n id: string,\n type: GraphViewElementEventType,\n selectionIntent?: SelectionIntent,\n) {\n if (type === 'pointer-enter') state.hoveredNodeIds.add(id);\n if (type === 'pointer-leave') state.hoveredNodeIds.delete(id);\n if (type === 'press') state.cy.getElementById(id).select();\n state.callbacksRef.current.onNodeEvent?.({ id, type, selectionIntent });\n emitRenderedNodes(state);\n}\n\n/*** Return whether Cytoscape currently has dimensions suitable for fitting. */\nfunction hasUsableViewport(cy: Core): boolean {\n return cy.width() > 0 && cy.height() > 0;\n}\n\n/*** Dispose all runtime resources in the reverse order they were acquired. */\nfunction destroyRuntime(state: GraphRuntimeState) {\n state.resizeObserver?.disconnect();\n stopCurrentLayout(state);\n state.unbindEvents();\n state.renderedNodeListeners.clear();\n if (!state.cy.destroyed()) state.cy.destroy();\n}\n\nregisterGraphLayouts();\n"]}
1
+ {"version":3,"file":"createGraphRuntime.js","sourceRoot":"","sources":["../../../../../../src/features/graph-view/adapters/inbound/web-artifact/createGraphRuntime.ts"],"names":[],"mappings":"AACA,OAAO,SAAS,EAAE,EAAoC,MAAM,WAAW,CAAC;AAWxE,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAChE,OAAO,E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,KAAK,CAAC,EAAE,CAAC,SAAS,EAAE;QAAE,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC;AAChD,CAAC;AAED,oBAAoB,EAAE,CAAC","sourcesContent":["import type { SelectionIntent } from '@ankhorage/utility/selection';\nimport cytoscape, { type Core, type CytoscapeOptions } from 'cytoscape';\n\nimport type {\n GraphViewCallbacks,\n GraphViewElementEventType,\n GraphViewFitOptions,\n GraphViewRenderedNode,\n GraphViewSize,\n GraphViewStyleRule,\n} from '../../../../../types/graph-view';\nimport type { GraphRuntimeUpdate } from '../../../../../types/graphViewRuntime';\nimport { bindGraphEvents } from './bindGraphEvents';\nimport { compactGraphSpacing } from './compactGraphSpacing';\nimport { createGraphController } from './createGraphController';\nimport { createGraphLoopSizer } from './createGraphLoopSizer';\nimport { createGraphResizeObserver, type GraphResizeObserver } from './createGraphResizeObserver';\nimport { getGraphGeometryKey } from './getGraphGeometryKey';\nimport { getGraphTopologyKey } from './getGraphTopologyKey';\nimport { hasGraphLayoutChanged } from './hasGraphLayoutChanged';\nimport { placeAddedGraphNodes } from './placeAddedGraphNodes';\nimport { readGraphRenderedNodes } from './readGraphRenderedNodes';\nimport { registerGraphLayouts } from './registerGraphLayouts';\nimport { runGraphLayout } from './runGraphLayout';\nimport { scheduleGraphFrame } from './scheduleGraphFrame';\nimport { shouldFitGraphAfterLayout } from './shouldFitGraphAfterLayout';\nimport { sizeGraphNodesToLabels } from './sizeGraphNodesToLabels';\nimport { syncGraphElements } from './syncGraphElements';\n\ntype GraphContainer = CytoscapeOptions['container'];\ntype RenderedNodeListener = (nodes: readonly GraphViewRenderedNode[]) => void;\n\nexport interface GraphRuntime {\n destroy(): void;\n handleOverlayNodeEvent(\n id: string,\n type: GraphViewElementEventType,\n selectionIntent?: SelectionIntent,\n ): void;\n setNodeSize(id: string, size: GraphViewSize): void;\n setSelectedNodeIds(nodeIds: readonly string[] | undefined): void;\n subscribeRenderedNodes(listener: RenderedNodeListener): () => void;\n update(input: GraphRuntimeUpdate): void;\n}\n\ninterface GraphRuntimeState {\n readonly fitRequestRef: { current: GraphViewFitOptions | null };\n readonly optimizedSpacingRef: { current: number | null };\n readonly callbacksRef: { current: GraphViewCallbacks };\n readonly controller: ReturnType<typeof createGraphController>['controller'];\n readonly viewport: ReturnType<typeof createGraphController>;\n readonly cy: Core;\n readonly fitPaddingRef: { current: number };\n readonly generationRef: { current: number };\n readonly geometryRef: { current: string | null };\n readonly hoveredNodeIds: Set<string>;\n readonly latestUpdateRef: { current: GraphRuntimeUpdate | null };\n readonly layoutRef: { current: ReturnType<typeof runGraphLayout> | null };\n readonly layoutRunningRef: { current: boolean };\n readonly nodeSizes: Map<string, GraphViewSize>;\n readonly labelSizedNodeIds: Set<string>;\n readonly loopSizer: ReturnType<typeof createGraphLoopSizer>;\n readonly pendingInitialFitRef: { current: boolean };\n readonly readyRef: { current: boolean };\n readonly settledLayoutRef: { current: GraphRuntimeUpdate['layout'] | null };\n readonly settledTopologyRef: { current: string | null };\n readonly relayoutScheduledRef: { current: boolean };\n readonly renderedNodeListeners: Set<RenderedNodeListener>;\n readonly resizeObserver: GraphResizeObserver | null;\n readonly unbindEvents: () => void;\n}\n\n/*** Create one Cytoscape runtime that exclusively owns layout, fit, resize, and disposal. */\nexport function createGraphRuntime(\n container: GraphContainer,\n callbacksRef: { current: GraphViewCallbacks },\n): GraphRuntime {\n const cy = cytoscape({\n container,\n elements: [],\n minZoom: 0.05,\n maxZoom: 2,\n selectionType: 'additive',\n userPanningEnabled: true,\n });\n const state = createRuntimeState(cy, container, callbacksRef);\n\n return {\n destroy: () => destroyRuntime(state),\n handleOverlayNodeEvent: (id, type, selectionIntent) =>\n handleOverlayNodeEvent(state, id, type, selectionIntent),\n setNodeSize: (id, size) => setNodeSize(state, id, size),\n setSelectedNodeIds: (nodeIds) => setSelectedNodeIds(state, nodeIds),\n subscribeRenderedNodes: (listener) => subscribeRenderedNodes(state, listener),\n update: (input) => updateRuntime(state, input),\n };\n}\n\n/*** Build the mutable state shared by the single graph-runtime owner. */\nfunction createRuntimeState(\n cy: Core,\n container: GraphContainer,\n callbacksRef: { current: GraphViewCallbacks },\n): GraphRuntimeState {\n const fitPaddingRef = { current: 50 };\n const viewport = createGraphController(cy, fitPaddingRef, (options) =>\n requestOptimizedFit(state, options),\n );\n const { controller } = viewport;\n const layoutRunningRef = { current: false };\n const readyRef = { current: false };\n const renderedNodeListeners = new Set<RenderedNodeListener>();\n const stateBase = {\n fitRequestRef: { current: null as GraphViewFitOptions | null },\n optimizedSpacingRef: { current: null as number | null },\n callbacksRef,\n controller,\n viewport,\n cy,\n fitPaddingRef,\n generationRef: { current: 0 },\n geometryRef: { current: null as string | null },\n hoveredNodeIds: new Set<string>(),\n latestUpdateRef: { current: null as GraphRuntimeUpdate | null },\n layoutRef: { current: null as ReturnType<typeof runGraphLayout> | null },\n layoutRunningRef,\n nodeSizes: new Map<string, GraphViewSize>(),\n labelSizedNodeIds: new Set<string>(),\n loopSizer: createGraphLoopSizer(cy),\n pendingInitialFitRef: { current: false },\n readyRef,\n settledLayoutRef: { current: null as GraphRuntimeUpdate['layout'] | null },\n settledTopologyRef: { current: null as string | null },\n relayoutScheduledRef: { current: false },\n renderedNodeListeners,\n };\n const unbindEvents = bindGraphEvents(cy, callbacksRef, controller, () =>\n emitRenderedNodes(stateBase),\n );\n const resizeObserver = createGraphResizeObserver({\n container,\n cy,\n beginViewportResize: () => viewport.beginResize(),\n settleViewport: (fit) => viewport.settle(fit),\n layoutRunningRef,\n pendingInitialFitRef: stateBase.pendingInitialFitRef,\n onViewportSettled: (completedPendingInitialFit) => {\n emitRenderedNodes(stateBase);\n if (!completedPendingInitialFit || readyRef.current) return;\n readyRef.current = true;\n callbacksRef.current.onReady?.(controller);\n callbacksRef.current.onLayoutComplete?.(controller);\n },\n readyRef,\n });\n\n const state = { ...stateBase, resizeObserver, unbindEvents };\n return state;\n}\n\n/***\n * Reconcile presentation in place and relayout only when graph geometry or layout policy changes.\n * Batch reconciliation and skip layout for presentation-only updates.\n */\nfunction updateRuntime(state: GraphRuntimeState, input: GraphRuntimeUpdate) {\n if (state.cy.destroyed()) return;\n const last = state.latestUpdateRef.current;\n const acceptsSpacing =\n state.optimizedSpacingRef.current !== null &&\n state.optimizedSpacingRef.current === input.spacingFactor;\n const previous = acceptsSpacing && last ? { ...last, spacingFactor: input.spacingFactor } : last;\n if (acceptsSpacing) state.optimizedSpacingRef.current = null;\n state.latestUpdateRef.current = input;\n state.fitPaddingRef.current = input.fitPadding ?? 50;\n state.viewport.configure(input);\n const preservesTopology = shouldPreserveTopology(state, previous, input);\n const retainedNodeIds = getRetainedNodeIds(previous, input, preservesTopology);\n const retainedGeometry =\n retainedNodeIds === null ? null : getGraphGeometryKey(state.cy, retainedNodeIds);\n state.cy.batch(() => {\n if (previous?.nodes !== input.nodes || previous.edges !== input.edges) {\n syncGraphElements(state.cy, input.nodes, input.edges);\n if (preservesTopology) placeAddedGraphNodes(state.cy, previous?.nodes ?? [], input.nodes);\n }\n if (\n previous?.styleRules !== input.styleRules ||\n previous?.richNodeRendering !== input.richNodeRendering\n ) {\n state.loopSizer.reset();\n applyGraphStyles(state.cy, input.styleRules, input.richNodeRendering);\n }\n });\n sizeGraphNodesToLabels(\n state.cy,\n state.labelSizedNodeIds,\n input.sizeNodesToLabels === true && !input.richNodeRendering,\n );\n applyKnownNodeSizes(state);\n state.loopSizer.update();\n const geometry = getGraphGeometryKey(state.cy);\n // Keep native double-press targets stable for paint-only class changes. A class that changes\n // measured node dimensions remains a geometry change and must relayout.\n const geometryChanged =\n retainedGeometry === null\n ? geometry !== state.geometryRef.current\n : retainedGeometry !== getGraphGeometryKey(state.cy, retainedNodeIds ?? undefined);\n const relayout = hasGraphLayoutChanged(previous, input, preservesTopology) || geometryChanged;\n state.geometryRef.current = geometry;\n if (!relayout) {\n if (\n previous?.zoomMode !== input.zoomMode ||\n previous?.fitPadding !== input.fitPadding ||\n previous?.minZoom !== input.minZoom ||\n previous?.maxZoom !== input.maxZoom ||\n previous?.minReadableLabelSize !== input.minReadableLabelSize ||\n previous?.maxFitLabelSize !== input.maxFitLabelSize\n ) {\n state.viewport.settle(previous?.zoomMode !== input.zoomMode);\n }\n emitRenderedNodes(state);\n return;\n }\n stopCurrentLayout(state);\n state.fitRequestRef.current = null;\n state.optimizedSpacingRef.current = null;\n startCurrentLayout(state, input);\n}\n\n/*** Preserve only opt-in topology updates after the initial layout and fit have settled. */\nfunction shouldPreserveTopology(\n state: GraphRuntimeState,\n previous: GraphRuntimeUpdate | null,\n input: GraphRuntimeUpdate,\n): boolean {\n return (\n previous !== null &&\n state.readyRef.current &&\n !state.pendingInitialFitRef.current &&\n input.topologyUpdatePolicy === 'preserve-positions'\n );\n}\n\n/*** Limit stable-update geometry checks to nodes that existed before reconciliation. */\nfunction getRetainedNodeIds(\n previous: GraphRuntimeUpdate | null,\n input: GraphRuntimeUpdate,\n preservesTopology: boolean,\n): ReadonlySet<string> | null {\n if (!preservesTopology || previous === null) return null;\n const nextNodeIds = new Set(input.nodes.map((node) => node.id));\n return new Set(previous.nodes.map((node) => node.id).filter((id) => nextNodeIds.has(id)));\n}\n\n/*** Start a generation-safe layout whose completion is the only normal automatic fit trigger. */\nfunction startCurrentLayout(state: GraphRuntimeState, input: GraphRuntimeUpdate) {\n state.pendingInitialFitRef.current = false;\n const generation = state.generationRef.current + 1;\n state.generationRef.current = generation;\n state.layoutRunningRef.current = true;\n state.cy.resize();\n state.layoutRef.current = runGraphLayout(\n state.cy,\n {\n layout: input.layout ?? 'concentric',\n layoutOptions: input.layoutOptions,\n spacingFactor: input.spacingFactor ?? 1,\n },\n () => completeCurrentLayout(state, generation),\n );\n}\n\n/***\n * Settle only the latest layout generation and fit once from node bounds.\n * Discard stale completions and avoid repeated automatic fits.\n */\nfunction completeCurrentLayout(state: GraphRuntimeState, generation: number) {\n scheduleGraphFrame(() => {\n if (state.cy.destroyed() || generation !== state.generationRef.current) return;\n state.loopSizer.update();\n state.layoutRef.current = null;\n state.cy.resize();\n state.layoutRunningRef.current = false;\n state.resizeObserver?.flushAfterLayout();\n if (!hasUsableViewport(state.cy)) {\n if (!state.readyRef.current) state.pendingInitialFitRef.current = true;\n return;\n }\n state.pendingInitialFitRef.current = false;\n const input = state.latestUpdateRef.current;\n if (input === null) return;\n const topology = getGraphTopologyKey(input.nodes, input.edges);\n const shouldFit = shouldFitGraphAfterLayout(\n state.readyRef.current,\n topology !== state.settledTopologyRef.current,\n input.layout !== state.settledLayoutRef.current,\n );\n state.viewport.settle(shouldFit);\n state.settledLayoutRef.current = input.layout;\n state.settledTopologyRef.current = topology;\n const fitRequest = state.fitRequestRef.current;\n state.fitRequestRef.current = null;\n if (fitRequest) requestOptimizedFit(state, fitRequest);\n emitRenderedNodes(state);\n\n if (!state.readyRef.current) {\n state.readyRef.current = true;\n state.callbacksRef.current.onReady?.(state.controller);\n }\n state.callbacksRef.current.onLayoutComplete?.(state.controller);\n });\n}\n\n/***\n * Handle explicit readable-fit intent in the runtime owner, never from zoom or React effects.\n * Bounded spacing optimization preserves the settled algorithm instead of repeatedly running it.\n */\nfunction requestOptimizedFit(state: GraphRuntimeState, options: GraphViewFitOptions) {\n if (state.cy.destroyed()) return;\n if (state.layoutRunningRef.current) {\n state.fitRequestRef.current = options;\n return;\n }\n const input = state.latestUpdateRef.current;\n if (!input) return;\n const previous = state.optimizedSpacingRef.current ?? input.spacingFactor ?? 1;\n const spacing = compactGraphSpacing(state.cy, previous, {\n fitPadding: options.padding ?? state.fitPaddingRef.current,\n maxFitZoom: state.viewport.getFitZoomLimit(),\n minReadableZoom: state.viewport.getReadableZoomTarget(),\n });\n state.geometryRef.current = getGraphGeometryKey(state.cy);\n state.loopSizer.update();\n state.viewport.settle(false);\n state.controller.fit({ ...options, optimizeSpacing: false });\n if (spacing !== previous) {\n state.optimizedSpacingRef.current = spacing;\n state.callbacksRef.current.onSpacingFactorChange?.(spacing);\n }\n emitRenderedNodes(state);\n}\n\n/*** Stop the current layout and invalidate every stale completion callback. */\nfunction stopCurrentLayout(state: GraphRuntimeState) {\n state.generationRef.current += 1;\n state.layoutRunningRef.current = false;\n state.layoutRef.current?.stop();\n state.layoutRef.current = null;\n}\n\n/*** Apply consumer styles and hide native node paint only when React rich nodes are active. */\nfunction applyGraphStyles(\n cy: Core,\n rules: readonly GraphViewStyleRule[] | undefined,\n richNodeRendering: boolean,\n) {\n const styles = [...(rules ?? [])];\n if (richNodeRendering) {\n styles.push({\n selector: 'node',\n style: {\n 'background-opacity': 0,\n 'border-width': 0,\n label: '',\n 'overlay-opacity': 0,\n },\n });\n }\n if (styles.length > 0) cy.style(styles).update();\n}\n\n/***\n * Synchronize controlled selection without rerunning layout.\n * Selection updates must not trigger graph reconstruction or layout.\n */\nfunction setSelectedNodeIds(state: GraphRuntimeState, nodeIds: readonly string[] | undefined) {\n if (state.cy.destroyed() || nodeIds === undefined) return;\n const selectedIds = new Set(nodeIds);\n state.cy.nodes().forEach((node) => {\n if (selectedIds.has(node.id())) node.select();\n else node.unselect();\n });\n emitRenderedNodes(state);\n}\n\n/***\n * Persist one rich-node size and schedule at most one relayout for changed geometry.\n * Ignore unchanged measurements before scheduling layout work.\n */\nfunction setNodeSize(state: GraphRuntimeState, id: string, size: GraphViewSize) {\n const previous = state.nodeSizes.get(id);\n if (previous?.width === size.width && previous.height === size.height) return;\n state.nodeSizes.set(id, size);\n applyNodeSize(state.cy, id, size);\n scheduleMeasuredNodeRelayout(state);\n}\n\n/*** Apply every known rich-node size after Cytoscape elements are replaced. */\nfunction applyKnownNodeSizes(state: GraphRuntimeState) {\n for (const [id, size] of state.nodeSizes) applyNodeSize(state.cy, id, size);\n}\n\n/*** Apply one measured model-space size as a Cytoscape per-node style bypass. */\nfunction applyNodeSize(cy: Core, id: string, size: GraphViewSize) {\n const node = cy.getElementById(id);\n if (node.empty()) return;\n node.style({ height: size.height, width: size.width });\n}\n\n/***\n * Coalesce DOM measurements into one follow-up layout generation.\n * Keep one scheduled layout per frame instead of one per measured node.\n */\nfunction scheduleMeasuredNodeRelayout(state: GraphRuntimeState) {\n if (state.relayoutScheduledRef.current) return;\n state.relayoutScheduledRef.current = true;\n scheduleGraphFrame(() => {\n state.relayoutScheduledRef.current = false;\n const input = state.latestUpdateRef.current;\n if (input === null || state.cy.destroyed()) return;\n stopCurrentLayout(state);\n startCurrentLayout(state, input);\n });\n}\n\n/*** Subscribe one React overlay to rendered node state without exposing the Cytoscape core. */\nfunction subscribeRenderedNodes(state: GraphRuntimeState, listener: RenderedNodeListener) {\n state.renderedNodeListeners.add(listener);\n listener(readGraphRenderedNodes(state.cy, state.hoveredNodeIds));\n return () => {\n state.renderedNodeListeners.delete(listener);\n };\n}\n\n/***\n * Publish current rendered node positions only to active rich-node subscribers.\n * Skip snapshot preparation when no overlay is subscribed.\n */\nfunction emitRenderedNodes(\n state: Pick<GraphRuntimeState, 'cy' | 'hoveredNodeIds' | 'renderedNodeListeners'>,\n) {\n if (state.renderedNodeListeners.size === 0) return;\n const nodes = readGraphRenderedNodes(state.cy, state.hoveredNodeIds);\n for (const listener of state.renderedNodeListeners) listener(nodes);\n}\n\n/*** Translate one rich-overlay event back into normal graph selection and callbacks. */\nfunction handleOverlayNodeEvent(\n state: GraphRuntimeState,\n id: string,\n type: GraphViewElementEventType,\n selectionIntent?: SelectionIntent,\n) {\n if (type === 'pointer-enter') state.hoveredNodeIds.add(id);\n if (type === 'pointer-leave') state.hoveredNodeIds.delete(id);\n if (type === 'press') state.cy.getElementById(id).select();\n state.callbacksRef.current.onNodeEvent?.({ id, type, selectionIntent });\n emitRenderedNodes(state);\n}\n\n/*** Return whether Cytoscape currently has dimensions suitable for fitting. */\nfunction hasUsableViewport(cy: Core): boolean {\n return cy.width() > 0 && cy.height() > 0;\n}\n\n/*** Dispose all runtime resources in the reverse order they were acquired. */\nfunction destroyRuntime(state: GraphRuntimeState) {\n state.resizeObserver?.disconnect();\n stopCurrentLayout(state);\n state.unbindEvents();\n state.renderedNodeListeners.clear();\n if (!state.cy.destroyed()) state.cy.destroy();\n}\n\nregisterGraphLayouts();\n"]}
@@ -6,5 +6,5 @@ import type { Core } from 'cytoscape';
6
6
  * bounds follow child positions, so keying their measured bounds would feed layout output back
7
7
  * into input. Styled geometry tests and runtime interaction tests protect these distinctions.
8
8
  */
9
- export declare function getGraphGeometryKey(cy: Core): string;
9
+ export declare function getGraphGeometryKey(cy: Core, nodeIds?: ReadonlySet<string>): string;
10
10
  //# sourceMappingURL=getGraphGeometryKey.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"getGraphGeometryKey.d.ts","sourceRoot":"","sources":["../../../../../../src/features/graph-view/adapters/inbound/web-artifact/getGraphGeometryKey.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEtC;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,EAAE,EAAE,IAAI,GAAG,MAAM,CAcpD"}
1
+ {"version":3,"file":"getGraphGeometryKey.d.ts","sourceRoot":"","sources":["../../../../../../src/features/graph-view/adapters/inbound/web-artifact/getGraphGeometryKey.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEtC;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,EAAE,EAAE,IAAI,EAAE,OAAO,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC,GAAG,MAAM,CAkBnF"}
@@ -5,8 +5,12 @@
5
5
  * bounds follow child positions, so keying their measured bounds would feed layout output back
6
6
  * into input. Styled geometry tests and runtime interaction tests protect these distinctions.
7
7
  */
8
- export function getGraphGeometryKey(cy) {
9
- return JSON.stringify(cy.nodes().map((node) => {
8
+ export function getGraphGeometryKey(cy, nodeIds) {
9
+ return JSON.stringify(cy
10
+ .nodes()
11
+ .map((node) => {
12
+ if (nodeIds !== undefined && !nodeIds.has(node.id()))
13
+ return null;
10
14
  if (node.isParent())
11
15
  return [node.id()];
12
16
  const labelBounds = node.boundingBox({
@@ -17,6 +21,7 @@ export function getGraphGeometryKey(cy) {
17
21
  includeUnderlays: false,
18
22
  });
19
23
  return [node.id(), node.outerWidth(), node.outerHeight(), labelBounds.w, labelBounds.h];
20
- }));
24
+ })
25
+ .filter((entry) => entry !== null));
21
26
  }
22
27
  //# sourceMappingURL=getGraphGeometryKey.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"getGraphGeometryKey.js","sourceRoot":"","sources":["../../../../../../src/features/graph-view/adapters/inbound/web-artifact/getGraphGeometryKey.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AACH,MAAM,UAAU,mBAAmB,CAAC,EAAQ;IAC1C,OAAO,IAAI,CAAC,SAAS,CACnB,EAAE,CAAC,KAAK,EAAE,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE;QACtB,IAAI,IAAI,CAAC,QAAQ,EAAE;YAAE,OAAO,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC,CAAC;QACxC,MAAM,WAAW,GAAG,IAAI,CAAC,WAAW,CAAC;YACnC,YAAY,EAAE,KAAK;YACnB,aAAa,EAAE,IAAI;YACnB,YAAY,EAAE,KAAK;YACnB,eAAe,EAAE,KAAK;YACtB,gBAAgB,EAAE,KAAK;SACxB,CAAC,CAAC;QACH,OAAO,CAAC,IAAI,CAAC,EAAE,EAAE,EAAE,IAAI,CAAC,UAAU,EAAE,EAAE,IAAI,CAAC,WAAW,EAAE,EAAE,WAAW,CAAC,CAAC,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC;IAC1F,CAAC,CAAC,CACH,CAAC;AACJ,CAAC","sourcesContent":["import type { Core } from 'cytoscape';\n\n/***\n * Identifies layout-relevant leaf dimensions without including positions or paint-only outlines.\n * Cytoscape's layoutDimensions() includes selected-outline rendering even though layouts use only\n * the node body, padding, border, and label bounds. Key those direct inputs instead. Compound\n * bounds follow child positions, so keying their measured bounds would feed layout output back\n * into input. Styled geometry tests and runtime interaction tests protect these distinctions.\n */\nexport function getGraphGeometryKey(cy: Core): string {\n return JSON.stringify(\n cy.nodes().map((node) => {\n if (node.isParent()) return [node.id()];\n const labelBounds = node.boundingBox({\n includeEdges: false,\n includeLabels: true,\n includeNodes: false,\n includeOverlays: false,\n includeUnderlays: false,\n });\n return [node.id(), node.outerWidth(), node.outerHeight(), labelBounds.w, labelBounds.h];\n }),\n );\n}\n"]}
1
+ {"version":3,"file":"getGraphGeometryKey.js","sourceRoot":"","sources":["../../../../../../src/features/graph-view/adapters/inbound/web-artifact/getGraphGeometryKey.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AACH,MAAM,UAAU,mBAAmB,CAAC,EAAQ,EAAE,OAA6B;IACzE,OAAO,IAAI,CAAC,SAAS,CACnB,EAAE;SACC,KAAK,EAAE;SACP,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE;QACZ,IAAI,OAAO,KAAK,SAAS,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC;YAAE,OAAO,IAAI,CAAC;QAClE,IAAI,IAAI,CAAC,QAAQ,EAAE;YAAE,OAAO,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC,CAAC;QACxC,MAAM,WAAW,GAAG,IAAI,CAAC,WAAW,CAAC;YACnC,YAAY,EAAE,KAAK;YACnB,aAAa,EAAE,IAAI;YACnB,YAAY,EAAE,KAAK;YACnB,eAAe,EAAE,KAAK;YACtB,gBAAgB,EAAE,KAAK;SACxB,CAAC,CAAC;QACH,OAAO,CAAC,IAAI,CAAC,EAAE,EAAE,EAAE,IAAI,CAAC,UAAU,EAAE,EAAE,IAAI,CAAC,WAAW,EAAE,EAAE,WAAW,CAAC,CAAC,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC;IAC1F,CAAC,CAAC;SACD,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,KAAK,IAAI,CAAC,CACrC,CAAC;AACJ,CAAC","sourcesContent":["import type { Core } from 'cytoscape';\n\n/***\n * Identifies layout-relevant leaf dimensions without including positions or paint-only outlines.\n * Cytoscape's layoutDimensions() includes selected-outline rendering even though layouts use only\n * the node body, padding, border, and label bounds. Key those direct inputs instead. Compound\n * bounds follow child positions, so keying their measured bounds would feed layout output back\n * into input. Styled geometry tests and runtime interaction tests protect these distinctions.\n */\nexport function getGraphGeometryKey(cy: Core, nodeIds?: ReadonlySet<string>): string {\n return JSON.stringify(\n cy\n .nodes()\n .map((node) => {\n if (nodeIds !== undefined && !nodeIds.has(node.id())) return null;\n if (node.isParent()) return [node.id()];\n const labelBounds = node.boundingBox({\n includeEdges: false,\n includeLabels: true,\n includeNodes: false,\n includeOverlays: false,\n includeUnderlays: false,\n });\n return [node.id(), node.outerWidth(), node.outerHeight(), labelBounds.w, labelBounds.h];\n })\n .filter((entry) => entry !== null),\n );\n}\n"]}
@@ -5,5 +5,5 @@ import type { GraphRuntimeUpdate } from '../../../../../types/graphViewRuntime';
5
5
  * and colors on hover or selection. Keep structural identity separate from presentation and
6
6
  * combine this decision with measured geometry in the single runtime owner, not consumer effects.
7
7
  */
8
- export declare function hasGraphLayoutChanged(previous: GraphRuntimeUpdate | null, input: GraphRuntimeUpdate): boolean;
8
+ export declare function hasGraphLayoutChanged(previous: GraphRuntimeUpdate | null, input: GraphRuntimeUpdate, preservesTopology: boolean): boolean;
9
9
  //# sourceMappingURL=hasGraphLayoutChanged.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"hasGraphLayoutChanged.d.ts","sourceRoot":"","sources":["../../../../../../src/features/graph-view/adapters/inbound/web-artifact/hasGraphLayoutChanged.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,uCAAuC,CAAC;AAGhF;;;;;GAKG;AACH,wBAAgB,qBAAqB,CACnC,QAAQ,EAAE,kBAAkB,GAAG,IAAI,EACnC,KAAK,EAAE,kBAAkB,GACxB,OAAO,CAUT"}
1
+ {"version":3,"file":"hasGraphLayoutChanged.d.ts","sourceRoot":"","sources":["../../../../../../src/features/graph-view/adapters/inbound/web-artifact/hasGraphLayoutChanged.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,uCAAuC,CAAC;AAGhF;;;;;GAKG;AACH,wBAAgB,qBAAqB,CACnC,QAAQ,EAAE,kBAAkB,GAAG,IAAI,EACnC,KAAK,EAAE,kBAAkB,EACzB,iBAAiB,EAAE,OAAO,GACzB,OAAO,CAWT"}
@@ -5,13 +5,14 @@ import { getGraphTopologyKey } from './getGraphTopologyKey';
5
5
  * and colors on hover or selection. Keep structural identity separate from presentation and
6
6
  * combine this decision with measured geometry in the single runtime owner, not consumer effects.
7
7
  */
8
- export function hasGraphLayoutChanged(previous, input) {
8
+ export function hasGraphLayoutChanged(previous, input, preservesTopology) {
9
9
  return (previous === null ||
10
10
  previous.layout !== input.layout ||
11
11
  previous.spacingFactor !== input.spacingFactor ||
12
12
  previous.layoutOptions !== input.layoutOptions ||
13
13
  previous.richNodeRendering !== input.richNodeRendering ||
14
- getGraphTopologyKey(previous.nodes, previous.edges) !==
15
- getGraphTopologyKey(input.nodes, input.edges));
14
+ (!preservesTopology &&
15
+ getGraphTopologyKey(previous.nodes, previous.edges) !==
16
+ getGraphTopologyKey(input.nodes, input.edges)));
16
17
  }
17
18
  //# sourceMappingURL=hasGraphLayoutChanged.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"hasGraphLayoutChanged.js","sourceRoot":"","sources":["../../../../../../src/features/graph-view/adapters/inbound/web-artifact/hasGraphLayoutChanged.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAE5D;;;;;GAKG;AACH,MAAM,UAAU,qBAAqB,CACnC,QAAmC,EACnC,KAAyB;IAEzB,OAAO,CACL,QAAQ,KAAK,IAAI;QACjB,QAAQ,CAAC,MAAM,KAAK,KAAK,CAAC,MAAM;QAChC,QAAQ,CAAC,aAAa,KAAK,KAAK,CAAC,aAAa;QAC9C,QAAQ,CAAC,aAAa,KAAK,KAAK,CAAC,aAAa;QAC9C,QAAQ,CAAC,iBAAiB,KAAK,KAAK,CAAC,iBAAiB;QACtD,mBAAmB,CAAC,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAC,KAAK,CAAC;YACjD,mBAAmB,CAAC,KAAK,CAAC,KAAK,EAAE,KAAK,CAAC,KAAK,CAAC,CAChD,CAAC;AACJ,CAAC","sourcesContent":["import type { GraphRuntimeUpdate } from '../../../../../types/graphViewRuntime';\nimport { getGraphTopologyKey } from './getGraphTopologyKey';\n\n/***\n * Detects topology and explicit layout-policy changes independently of highlight metadata.\n * New node/edge array identities alone are not a layout request: consumers may update classes\n * and colors on hover or selection. Keep structural identity separate from presentation and\n * combine this decision with measured geometry in the single runtime owner, not consumer effects.\n */\nexport function hasGraphLayoutChanged(\n previous: GraphRuntimeUpdate | null,\n input: GraphRuntimeUpdate,\n): boolean {\n return (\n previous === null ||\n previous.layout !== input.layout ||\n previous.spacingFactor !== input.spacingFactor ||\n previous.layoutOptions !== input.layoutOptions ||\n previous.richNodeRendering !== input.richNodeRendering ||\n getGraphTopologyKey(previous.nodes, previous.edges) !==\n getGraphTopologyKey(input.nodes, input.edges)\n );\n}\n"]}
1
+ {"version":3,"file":"hasGraphLayoutChanged.js","sourceRoot":"","sources":["../../../../../../src/features/graph-view/adapters/inbound/web-artifact/hasGraphLayoutChanged.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAE5D;;;;;GAKG;AACH,MAAM,UAAU,qBAAqB,CACnC,QAAmC,EACnC,KAAyB,EACzB,iBAA0B;IAE1B,OAAO,CACL,QAAQ,KAAK,IAAI;QACjB,QAAQ,CAAC,MAAM,KAAK,KAAK,CAAC,MAAM;QAChC,QAAQ,CAAC,aAAa,KAAK,KAAK,CAAC,aAAa;QAC9C,QAAQ,CAAC,aAAa,KAAK,KAAK,CAAC,aAAa;QAC9C,QAAQ,CAAC,iBAAiB,KAAK,KAAK,CAAC,iBAAiB;QACtD,CAAC,CAAC,iBAAiB;YACjB,mBAAmB,CAAC,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAC,KAAK,CAAC;gBACjD,mBAAmB,CAAC,KAAK,CAAC,KAAK,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC,CACnD,CAAC;AACJ,CAAC","sourcesContent":["import type { GraphRuntimeUpdate } from '../../../../../types/graphViewRuntime';\nimport { getGraphTopologyKey } from './getGraphTopologyKey';\n\n/***\n * Detects topology and explicit layout-policy changes independently of highlight metadata.\n * New node/edge array identities alone are not a layout request: consumers may update classes\n * and colors on hover or selection. Keep structural identity separate from presentation and\n * combine this decision with measured geometry in the single runtime owner, not consumer effects.\n */\nexport function hasGraphLayoutChanged(\n previous: GraphRuntimeUpdate | null,\n input: GraphRuntimeUpdate,\n preservesTopology: boolean,\n): boolean {\n return (\n previous === null ||\n previous.layout !== input.layout ||\n previous.spacingFactor !== input.spacingFactor ||\n previous.layoutOptions !== input.layoutOptions ||\n previous.richNodeRendering !== input.richNodeRendering ||\n (!preservesTopology &&\n getGraphTopologyKey(previous.nodes, previous.edges) !==\n getGraphTopologyKey(input.nodes, input.edges))\n );\n}\n"]}
@@ -0,0 +1,9 @@
1
+ import type { Core } from 'cytoscape';
2
+ import type { GraphViewNode } from '../../../../../types/graph-view';
3
+ /***
4
+ * Give stable-topology additions deterministic positions without moving settled nodes.
5
+ * This deliberately is not an incremental layout: callers can request a complete layout by
6
+ * changing the configured algorithm, while ordinary controlled additions keep the user viewport.
7
+ */
8
+ export declare function placeAddedGraphNodes(cy: Core, previousNodes: readonly GraphViewNode[], nodes: readonly GraphViewNode[]): void;
9
+ //# sourceMappingURL=placeAddedGraphNodes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"placeAddedGraphNodes.d.ts","sourceRoot":"","sources":["../../../../../../src/features/graph-view/adapters/inbound/web-artifact/placeAddedGraphNodes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEtC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AAIrE;;;;GAIG;AACH,wBAAgB,oBAAoB,CAClC,EAAE,EAAE,IAAI,EACR,aAAa,EAAE,SAAS,aAAa,EAAE,EACvC,KAAK,EAAE,SAAS,aAAa,EAAE,QAsBhC"}
@@ -0,0 +1,30 @@
1
+ const GRID_GAP = 120;
2
+ /***
3
+ * Give stable-topology additions deterministic positions without moving settled nodes.
4
+ * This deliberately is not an incremental layout: callers can request a complete layout by
5
+ * changing the configured algorithm, while ordinary controlled additions keep the user viewport.
6
+ */
7
+ export function placeAddedGraphNodes(cy, previousNodes, nodes) {
8
+ const previousNodeIds = new Set(previousNodes.map((node) => node.id));
9
+ const addedNodes = nodes
10
+ .filter((node) => !previousNodeIds.has(node.id))
11
+ .sort((left, right) => left.id.localeCompare(right.id));
12
+ if (addedNodes.length === 0)
13
+ return;
14
+ const retainedNodes = cy
15
+ .nodes()
16
+ .filter((node) => previousNodeIds.has(node.id()) && !node.isParent());
17
+ const bounds = retainedNodes.boundingBox({ includeEdges: false, includeLabels: true });
18
+ const origin = retainedNodes.empty() ? { x: 0, y: 0 } : { x: bounds.x2 + GRID_GAP, y: bounds.y1 };
19
+ const columns = Math.ceil(Math.sqrt(addedNodes.length));
20
+ addedNodes.forEach((node, index) => {
21
+ const graphNode = cy.getElementById(node.id);
22
+ if (graphNode.empty() || graphNode.isParent())
23
+ return;
24
+ graphNode.position({
25
+ x: origin.x + (index % columns) * GRID_GAP,
26
+ y: origin.y + Math.floor(index / columns) * GRID_GAP,
27
+ });
28
+ });
29
+ }
30
+ //# sourceMappingURL=placeAddedGraphNodes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"placeAddedGraphNodes.js","sourceRoot":"","sources":["../../../../../../src/features/graph-view/adapters/inbound/web-artifact/placeAddedGraphNodes.ts"],"names":[],"mappings":"AAIA,MAAM,QAAQ,GAAG,GAAG,CAAC;AAErB;;;;GAI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,KAAK,EAAE,EAAE;QACjC,MAAM,SAAS,GAAG,EAAE,CAAC,cAAc,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAC7C,IAAI,SAAS,CAAC,KAAK,EAAE,IAAI,SAAS,CAAC,QAAQ,EAAE;YAAE,OAAO;QACtD,SAAS,CAAC,QAAQ,CAAC;YACjB,CAAC,EAAE,MAAM,CAAC,CAAC,GAAG,CAAC,KAAK,GAAG,OAAO,CAAC,GAAG,QAAQ;YAC1C,CAAC,EAAE,MAAM,CAAC,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,GAAG,OAAO,CAAC,GAAG,QAAQ;SACrD,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import type { Core } from 'cytoscape';\n\nimport type { GraphViewNode } from '../../../../../types/graph-view';\n\nconst GRID_GAP = 120;\n\n/***\n * Give stable-topology additions deterministic positions without moving settled nodes.\n * This deliberately is not an incremental layout: callers can request a complete layout by\n * changing the configured algorithm, while ordinary controlled additions keep the user viewport.\n */\nexport function placeAddedGraphNodes(\n cy: Core,\n previousNodes: readonly GraphViewNode[],\n nodes: readonly GraphViewNode[],\n) {\n const previousNodeIds = new Set(previousNodes.map((node) => node.id));\n const addedNodes = nodes\n .filter((node) => !previousNodeIds.has(node.id))\n .sort((left, right) => left.id.localeCompare(right.id));\n if (addedNodes.length === 0) return;\n\n const retainedNodes = cy\n .nodes()\n .filter((node) => previousNodeIds.has(node.id()) && !node.isParent());\n const bounds = retainedNodes.boundingBox({ includeEdges: false, includeLabels: true });\n const origin = retainedNodes.empty() ? { x: 0, y: 0 } : { x: bounds.x2 + GRID_GAP, y: bounds.y1 };\n const columns = Math.ceil(Math.sqrt(addedNodes.length));\n addedNodes.forEach((node, index) => {\n const graphNode = cy.getElementById(node.id);\n if (graphNode.empty() || graphNode.isParent()) return;\n graphNode.position({\n x: origin.x + (index % columns) * GRID_GAP,\n y: origin.y + Math.floor(index / columns) * GRID_GAP,\n });\n });\n}\n"]}
@@ -1,4 +1,4 @@
1
- export type { GraphViewCallbacks, GraphViewController, GraphViewDomControllerEventDetail, GraphViewEdge, GraphViewElementEvent, GraphViewElementEventType, GraphViewFitOptions, GraphViewLayoutName, GraphViewMeasurement, GraphViewNode, GraphViewNodeMeasurement, GraphViewNodeRenderContext, GraphViewPoint, GraphViewProps, GraphViewRenderedNode, GraphViewSize, GraphViewStyleRule, GraphViewViewport, } from '../../types/graph-view';
1
+ export type { GraphViewCallbacks, GraphViewController, GraphViewDomControllerEventDetail, GraphViewEdge, GraphViewElementEvent, GraphViewElementEventType, GraphViewFitOptions, GraphViewLayoutName, GraphViewMeasurement, GraphViewNode, GraphViewNodeMeasurement, GraphViewNodeRenderContext, GraphViewPoint, GraphViewProps, GraphViewRenderedNode, GraphViewSize, GraphViewStyleRule, GraphViewTopologyUpdatePolicy, GraphViewViewport, } from '../../types/graph-view';
2
2
  export { GraphView } from './adapters/inbound/web-artifact/GraphView';
3
3
  export { GRAPH_VIEW_EVENTS } from './constants/events';
4
4
  //# sourceMappingURL=public.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"public.d.ts","sourceRoot":"","sources":["../../../src/features/graph-view/public.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,kBAAkB,EAClB,mBAAmB,EACnB,iCAAiC,EACjC,aAAa,EACb,qBAAqB,EACrB,yBAAyB,EACzB,mBAAmB,EACnB,mBAAmB,EACnB,oBAAoB,EACpB,aAAa,EACb,wBAAwB,EACxB,0BAA0B,EAC1B,cAAc,EACd,cAAc,EACd,qBAAqB,EACrB,aAAa,EACb,kBAAkB,EAClB,iBAAiB,GAClB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,SAAS,EAAE,MAAM,2CAA2C,CAAC;AACtE,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC"}
1
+ {"version":3,"file":"public.d.ts","sourceRoot":"","sources":["../../../src/features/graph-view/public.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,kBAAkB,EAClB,mBAAmB,EACnB,iCAAiC,EACjC,aAAa,EACb,qBAAqB,EACrB,yBAAyB,EACzB,mBAAmB,EACnB,mBAAmB,EACnB,oBAAoB,EACpB,aAAa,EACb,wBAAwB,EACxB,0BAA0B,EAC1B,cAAc,EACd,cAAc,EACd,qBAAqB,EACrB,aAAa,EACb,kBAAkB,EAClB,6BAA6B,EAC7B,iBAAiB,GAClB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,SAAS,EAAE,MAAM,2CAA2C,CAAC;AACtE,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"public.js","sourceRoot":"","sources":["../../../src/features/graph-view/public.ts"],"names":[],"mappings":"AAoBA,OAAO,EAAE,SAAS,EAAE,MAAM,2CAA2C,CAAC;AACtE,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC","sourcesContent":["export type {\n GraphViewCallbacks,\n GraphViewController,\n GraphViewDomControllerEventDetail,\n GraphViewEdge,\n GraphViewElementEvent,\n GraphViewElementEventType,\n GraphViewFitOptions,\n GraphViewLayoutName,\n GraphViewMeasurement,\n GraphViewNode,\n GraphViewNodeMeasurement,\n GraphViewNodeRenderContext,\n GraphViewPoint,\n GraphViewProps,\n GraphViewRenderedNode,\n GraphViewSize,\n GraphViewStyleRule,\n GraphViewViewport,\n} from '../../types/graph-view';\nexport { GraphView } from './adapters/inbound/web-artifact/GraphView';\nexport { GRAPH_VIEW_EVENTS } from './constants/events';\n"]}
1
+ {"version":3,"file":"public.js","sourceRoot":"","sources":["../../../src/features/graph-view/public.ts"],"names":[],"mappings":"AAqBA,OAAO,EAAE,SAAS,EAAE,MAAM,2CAA2C,CAAC;AACtE,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC","sourcesContent":["export type {\n GraphViewCallbacks,\n GraphViewController,\n GraphViewDomControllerEventDetail,\n GraphViewEdge,\n GraphViewElementEvent,\n GraphViewElementEventType,\n GraphViewFitOptions,\n GraphViewLayoutName,\n GraphViewMeasurement,\n GraphViewNode,\n GraphViewNodeMeasurement,\n GraphViewNodeRenderContext,\n GraphViewPoint,\n GraphViewProps,\n GraphViewRenderedNode,\n GraphViewSize,\n GraphViewStyleRule,\n GraphViewTopologyUpdatePolicy,\n GraphViewViewport,\n} from '../../types/graph-view';\nexport { GraphView } from './adapters/inbound/web-artifact/GraphView';\nexport { GRAPH_VIEW_EVENTS } from './constants/events';\n"]}
@@ -1,6 +1,7 @@
1
1
  import type { SelectionIntent } from '@ankhorage/utility/selection';
2
2
  import type React from 'react';
3
3
  export type GraphViewLayoutName = 'breadthfirst' | 'circle' | 'concentric' | 'elk' | 'grid';
4
+ export type GraphViewTopologyUpdatePolicy = 'preserve-positions';
4
5
  export type GraphViewElementEventType = 'press' | 'double-press' | 'select' | 'unselect' | 'pointer-enter' | 'pointer-leave';
5
6
  export interface GraphViewNode {
6
7
  readonly id: string;
@@ -90,6 +91,12 @@ export interface GraphViewProps {
90
91
  readonly edges: readonly GraphViewEdge[];
91
92
  readonly layout?: GraphViewLayoutName;
92
93
  readonly layoutOptions?: Readonly<Record<string, unknown>>;
94
+ /**
95
+ * Preserve the settled viewport and retained-node positions during controlled topology updates.
96
+ * New nodes receive a deterministic initial position; call controller.fit() or change layout to
97
+ * intentionally fit or relayout the graph. Without this opt-in, topology changes relayout.
98
+ */
99
+ readonly topologyUpdatePolicy?: GraphViewTopologyUpdatePolicy;
93
100
  readonly spacingFactor?: number;
94
101
  readonly styleRules?: readonly GraphViewStyleRule[];
95
102
  readonly selectedNodeIds?: readonly string[];
@@ -1 +1 @@
1
- {"version":3,"file":"graph-view.d.ts","sourceRoot":"","sources":["../../src/types/graph-view.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AACpE,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,MAAM,MAAM,mBAAmB,GAAG,cA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AAC;IAC9D,QAAQ,CAAC,gBAAgB,CAAC,EAAE,CAAC,QAAQ,EAAE,iBAAiB,KAAK,IAAI,CAAC;IAClE,QAAQ,CAAC,qBAAqB,CAAC,EAAE,CAAC,aAAa,EAAE,MAAM,KAAK,IAAI,CAAC;CAClE;AAED,MAAM,MAAM,kBAAkB,GAAG,IAAI,CACnC,cAAc,EACZ,aAAa,GACb,kBAAkB,GAClB,aAAa,GACb,SAAS,GACT,kBAAkB,GAClB,uBAAuB,CAC1B,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"graph-view.js","sourceRoot":"","sources":["../../src/types/graph-view.ts"],"names":[],"mappings":"","sourcesContent":["import type { SelectionIntent } from '@ankhorage/utility/selection';\nimport type React from 'react';\n\nexport type GraphViewLayoutName = 'breadthfirst' | 'circle' | 'concentric' | 'elk' | 'grid';\nexport type GraphViewElementEventType =\n 'press' | 'double-press' | 'select' | 'unselect' | 'pointer-enter' | 'pointer-leave';\n\nexport interface GraphViewNode {\n readonly id: string;\n readonly label?: string;\n readonly parentId?: string;\n readonly classes?: string;\n readonly data?: Readonly<Record<string, unknown>>;\n}\n\nexport interface GraphViewEdge {\n readonly id?: string;\n readonly source: string;\n readonly target: string;\n readonly classes?: string;\n readonly data?: Readonly<Record<string, unknown>>;\n}\n\nexport interface GraphViewStyleRule {\n readonly selector: string;\n readonly style: Readonly<Record<string, unknown>>;\n}\n\nexport interface GraphViewPoint {\n readonly x: number;\n readonly y: number;\n}\n\nexport interface GraphViewSize {\n readonly width: number;\n readonly height: number;\n}\n\nexport interface GraphViewNodeRenderContext {\n readonly hovered: boolean;\n readonly node: GraphViewNode;\n readonly selected: boolean;\n readonly zoom: number;\n}\n\nexport interface GraphViewRenderedNode {\n readonly hovered: boolean;\n readonly id: string;\n readonly position: GraphViewPoint;\n readonly selected: boolean;\n readonly zoom: number;\n}\n\nexport interface GraphViewNodeMeasurement {\n readonly id: string;\n readonly position: GraphViewPoint;\n readonly size: GraphViewSize;\n}\n\nexport interface GraphViewMeasurement {\n readonly nodes: readonly GraphViewNodeMeasurement[];\n readonly viewport: GraphViewSize;\n}\n\nexport interface GraphViewViewport {\n readonly zoom: number;\n readonly pan: GraphViewPoint;\n}\n\nexport interface GraphViewFitOptions {\n /**\n * Optimize effective rendered fit without rerunning the layout algorithm; whole-graph fits only.\n * Stops at the configured fit-size target and keeps semantic labels collision-safe.\n */\n readonly optimizeSpacing?: boolean;\n readonly nodeIds?: readonly string[];\n readonly padding?: number;\n}\n\nexport interface GraphViewElementEvent {\n readonly id: string;\n readonly type: GraphViewElementEventType;\n readonly selectionIntent?: SelectionIntent;\n}\n\nexport interface GraphViewController {\n fit(options?: GraphViewFitOptions): void;\n /** Measure rendered node geometry without exposing the backing graph engine. */\n measureNodes?(nodeIds: readonly string[]): GraphViewMeasurement | null;\n getViewport(): GraphViewViewport;\n getZoomRange(): { readonly min: number; readonly max: number };\n setPan(pan: GraphViewPoint): void;\n setZoom(zoom: number): void;\n zoomBy(factor: number): void;\n}\n\n/*** The browser lifecycle events carry only the existing public graph controller. */\nexport interface GraphViewDomControllerEventDetail {\n readonly controller: GraphViewController;\n}\n\nexport interface GraphViewProps {\n readonly nodes: readonly GraphViewNode[];\n readonly edges: readonly GraphViewEdge[];\n readonly layout?: GraphViewLayoutName;\n readonly layoutOptions?: Readonly<Record<string, unknown>>;\n readonly spacingFactor?: number;\n readonly styleRules?: readonly GraphViewStyleRule[];\n readonly selectedNodeIds?: readonly string[];\n readonly renderNode?: (context: GraphViewNodeRenderContext) => React.ReactNode;\n readonly getNodeSize?: (node: GraphViewNode) => GraphViewSize | undefined;\n readonly fitPadding?: number;\n readonly minZoom?: number;\n readonly maxZoom?: number;\n readonly minReadableLabelSize?: number;\n readonly maxFitLabelSize?: number;\n /** Zoom values and bounds use the full-node fit as 1 when fit-relative is selected. */\n readonly zoomMode?: 'absolute' | 'fit-relative';\n /** Measure plain labels before layout instead of estimating width from character count. */\n readonly sizeNodesToLabels?: boolean;\n readonly className?: string;\n readonly style?: React.CSSProperties;\n readonly ariaLabel?: string;\n readonly onReady?: (controller: GraphViewController) => void;\n readonly onLayoutComplete?: (controller: GraphViewController) => void;\n readonly onNodeEvent?: (event: GraphViewElementEvent) => void;\n readonly onEdgeEvent?: (event: GraphViewElementEvent) => void;\n readonly onViewportChange?: (viewport: GraphViewViewport) => void;\n readonly onSpacingFactorChange?: (spacingFactor: number) => void;\n}\n\nexport type GraphViewCallbacks = Pick<\n GraphViewProps,\n | 'onEdgeEvent'\n | 'onLayoutComplete'\n | 'onNodeEvent'\n | 'onReady'\n | 'onViewportChange'\n | 'onSpacingFactorChange'\n>;\n"]}
1
+ {"version":3,"file":"graph-view.js","sourceRoot":"","sources":["../../src/types/graph-view.ts"],"names":[],"mappings":"","sourcesContent":["import type { SelectionIntent } from '@ankhorage/utility/selection';\nimport type React from 'react';\n\nexport type GraphViewLayoutName = 'breadthfirst' | 'circle' | 'concentric' | 'elk' | 'grid';\nexport type GraphViewTopologyUpdatePolicy = 'preserve-positions';\nexport type GraphViewElementEventType =\n 'press' | 'double-press' | 'select' | 'unselect' | 'pointer-enter' | 'pointer-leave';\n\nexport interface GraphViewNode {\n readonly id: string;\n readonly label?: string;\n readonly parentId?: string;\n readonly classes?: string;\n readonly data?: Readonly<Record<string, unknown>>;\n}\n\nexport interface GraphViewEdge {\n readonly id?: string;\n readonly source: string;\n readonly target: string;\n readonly classes?: string;\n readonly data?: Readonly<Record<string, unknown>>;\n}\n\nexport interface GraphViewStyleRule {\n readonly selector: string;\n readonly style: Readonly<Record<string, unknown>>;\n}\n\nexport interface GraphViewPoint {\n readonly x: number;\n readonly y: number;\n}\n\nexport interface GraphViewSize {\n readonly width: number;\n readonly height: number;\n}\n\nexport interface GraphViewNodeRenderContext {\n readonly hovered: boolean;\n readonly node: GraphViewNode;\n readonly selected: boolean;\n readonly zoom: number;\n}\n\nexport interface GraphViewRenderedNode {\n readonly hovered: boolean;\n readonly id: string;\n readonly position: GraphViewPoint;\n readonly selected: boolean;\n readonly zoom: number;\n}\n\nexport interface GraphViewNodeMeasurement {\n readonly id: string;\n readonly position: GraphViewPoint;\n readonly size: GraphViewSize;\n}\n\nexport interface GraphViewMeasurement {\n readonly nodes: readonly GraphViewNodeMeasurement[];\n readonly viewport: GraphViewSize;\n}\n\nexport interface GraphViewViewport {\n readonly zoom: number;\n readonly pan: GraphViewPoint;\n}\n\nexport interface GraphViewFitOptions {\n /**\n * Optimize effective rendered fit without rerunning the layout algorithm; whole-graph fits only.\n * Stops at the configured fit-size target and keeps semantic labels collision-safe.\n */\n readonly optimizeSpacing?: boolean;\n readonly nodeIds?: readonly string[];\n readonly padding?: number;\n}\n\nexport interface GraphViewElementEvent {\n readonly id: string;\n readonly type: GraphViewElementEventType;\n readonly selectionIntent?: SelectionIntent;\n}\n\nexport interface GraphViewController {\n fit(options?: GraphViewFitOptions): void;\n /** Measure rendered node geometry without exposing the backing graph engine. */\n measureNodes?(nodeIds: readonly string[]): GraphViewMeasurement | null;\n getViewport(): GraphViewViewport;\n getZoomRange(): { readonly min: number; readonly max: number };\n setPan(pan: GraphViewPoint): void;\n setZoom(zoom: number): void;\n zoomBy(factor: number): void;\n}\n\n/*** The browser lifecycle events carry only the existing public graph controller. */\nexport interface GraphViewDomControllerEventDetail {\n readonly controller: GraphViewController;\n}\n\nexport interface GraphViewProps {\n readonly nodes: readonly GraphViewNode[];\n readonly edges: readonly GraphViewEdge[];\n readonly layout?: GraphViewLayoutName;\n readonly layoutOptions?: Readonly<Record<string, unknown>>;\n /**\n * Preserve the settled viewport and retained-node positions during controlled topology updates.\n * New nodes receive a deterministic initial position; call controller.fit() or change layout to\n * intentionally fit or relayout the graph. Without this opt-in, topology changes relayout.\n */\n readonly topologyUpdatePolicy?: GraphViewTopologyUpdatePolicy;\n readonly spacingFactor?: number;\n readonly styleRules?: readonly GraphViewStyleRule[];\n readonly selectedNodeIds?: readonly string[];\n readonly renderNode?: (context: GraphViewNodeRenderContext) => React.ReactNode;\n readonly getNodeSize?: (node: GraphViewNode) => GraphViewSize | undefined;\n readonly fitPadding?: number;\n readonly minZoom?: number;\n readonly maxZoom?: number;\n readonly minReadableLabelSize?: number;\n readonly maxFitLabelSize?: number;\n /** Zoom values and bounds use the full-node fit as 1 when fit-relative is selected. */\n readonly zoomMode?: 'absolute' | 'fit-relative';\n /** Measure plain labels before layout instead of estimating width from character count. */\n readonly sizeNodesToLabels?: boolean;\n readonly className?: string;\n readonly style?: React.CSSProperties;\n readonly ariaLabel?: string;\n readonly onReady?: (controller: GraphViewController) => void;\n readonly onLayoutComplete?: (controller: GraphViewController) => void;\n readonly onNodeEvent?: (event: GraphViewElementEvent) => void;\n readonly onEdgeEvent?: (event: GraphViewElementEvent) => void;\n readonly onViewportChange?: (viewport: GraphViewViewport) => void;\n readonly onSpacingFactorChange?: (spacingFactor: number) => void;\n}\n\nexport type GraphViewCallbacks = Pick<\n GraphViewProps,\n | 'onEdgeEvent'\n | 'onLayoutComplete'\n | 'onNodeEvent'\n | 'onReady'\n | 'onViewportChange'\n | 'onSpacingFactorChange'\n>;\n"]}
@@ -1,4 +1,4 @@
1
- import type { GraphViewEdge, GraphViewLayoutName, GraphViewNode, GraphViewStyleRule } from './graph-view';
1
+ import type { GraphViewEdge, GraphViewLayoutName, GraphViewNode, GraphViewStyleRule, GraphViewTopologyUpdatePolicy } from './graph-view';
2
2
  export interface GraphRuntimeUpdate {
3
3
  readonly edges: readonly GraphViewEdge[];
4
4
  readonly fitPadding?: number;
@@ -14,5 +14,6 @@ export interface GraphRuntimeUpdate {
14
14
  readonly richNodeRendering: boolean;
15
15
  readonly spacingFactor?: number;
16
16
  readonly styleRules?: readonly GraphViewStyleRule[];
17
+ readonly topologyUpdatePolicy?: GraphViewTopologyUpdatePolicy;
17
18
  }
18
19
  //# sourceMappingURL=graphViewRuntime.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"graphViewRuntime.d.ts","sourceRoot":"","sources":["../../src/types/graphViewRuntime.ts"],"names":[],"mappings":"AAAA,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C;IAC7B,QAAQ,CAAC,MAAM,CAAC,EAAE,mBAAmB,CAAC;IACtC,QAAQ,CAAC,aAAa,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IAC3D,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,oBAAoB,CAAC,EAAE,MAAM,CAAC;IACvC,QAAQ,CAAC,eAAe,CAAC,EAAE,MAAM,CAAC;IAClC,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,QAAQ,CAAC,EAAE,UAAU,GAAG,cAAc,CAAC;IAChD,QAAQ,CAAC,iBAAiB,CAAC,EAAE,OAAO,CAAC;IACrC,QAAQ,CAAC,KAAK,EAAE,SAAS,aAAa,EAAE,CAAC;IACzC,QAAQ,CAAC,iBAAiB,EAAE,OAAO,CAAC;IACpC,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,CAAC;IAChC,QAAQ,CAAC,UAAU,CAAC,EAAE,SAAS,kBAAkB,EAAE,CAAC;IACpD,QAAQ,CAAC,oBAAoB,CAAC,EAAE,6BAA6B,CAAC;CAC/D"}
@@ -1 +1 @@
1
- {"version":3,"file":"graphViewRuntime.js","sourceRoot":"","sources":["../../src/types/graphViewRuntime.ts"],"names":[],"mappings":"","sourcesContent":["import type {\n GraphViewEdge,\n GraphViewLayoutName,\n GraphViewNode,\n GraphViewStyleRule,\n} from './graph-view';\n\nexport interface GraphRuntimeUpdate {\n readonly edges: readonly GraphViewEdge[];\n readonly fitPadding?: number;\n readonly layout?: GraphViewLayoutName;\n readonly layoutOptions?: Readonly<Record<string, unknown>>;\n readonly maxZoom?: number;\n readonly minReadableLabelSize?: number;\n readonly maxFitLabelSize?: number;\n readonly minZoom?: number;\n readonly zoomMode?: 'absolute' | 'fit-relative';\n readonly sizeNodesToLabels?: boolean;\n readonly nodes: readonly GraphViewNode[];\n readonly richNodeRendering: boolean;\n readonly spacingFactor?: number;\n readonly styleRules?: readonly GraphViewStyleRule[];\n}\n"]}
1
+ {"version":3,"file":"graphViewRuntime.js","sourceRoot":"","sources":["../../src/types/graphViewRuntime.ts"],"names":[],"mappings":"","sourcesContent":["import type {\n GraphViewEdge,\n GraphViewLayoutName,\n GraphViewNode,\n GraphViewStyleRule,\n GraphViewTopologyUpdatePolicy,\n} from './graph-view';\n\nexport interface GraphRuntimeUpdate {\n readonly edges: readonly GraphViewEdge[];\n readonly fitPadding?: number;\n readonly layout?: GraphViewLayoutName;\n readonly layoutOptions?: Readonly<Record<string, unknown>>;\n readonly maxZoom?: number;\n readonly minReadableLabelSize?: number;\n readonly maxFitLabelSize?: number;\n readonly minZoom?: number;\n readonly zoomMode?: 'absolute' | 'fit-relative';\n readonly sizeNodesToLabels?: boolean;\n readonly nodes: readonly GraphViewNode[];\n readonly richNodeRendering: boolean;\n readonly spacingFactor?: number;\n readonly styleRules?: readonly GraphViewStyleRule[];\n readonly topologyUpdatePolicy?: GraphViewTopologyUpdatePolicy;\n}\n"]}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ankhorage/zora",
3
3
  "type": "module",
4
- "version": "27.2.6",
4
+ "version": "27.3.0",
5
5
  "description": "Opinionated React Native and React Native Web UI kit built on @ankhorage/surface.",
6
6
  "homepage": "https://github.com/ankhorage/zora#readme",
7
7
  "bugs": {
@@ -30,6 +30,10 @@ type GraphContainer = NonNullable<CytoscapeOptions['container']>;
30
30
  * Ordinary zoom never adjusts spacing or relayouts. Explicit optimization preserves layout ordering,
31
31
  * stops once effective fit reaches maxFitLabelSize, keeps labels and unrelated compound boundaries
32
32
  * collision-safe, and permits only a small rendered background-overlap fallback for dense graphs.
33
+ * topologyUpdatePolicy Use `preserve-positions` for controlled incremental topology changes. It
34
+ * retains settled nodes and the user viewport, and initially places new nodes on a deterministic
35
+ * local grid. Use an explicit controller fit or a layout change when a complete rearrangement is
36
+ * intentional.
33
37
  */
34
38
  export function GraphView(props: GraphViewProps) {
35
39
  const hostRef = React.useRef<HTMLDivElement | null>(null);
@@ -168,6 +172,7 @@ function useRuntimeGraphUpdate(
168
172
  renderNode,
169
173
  spacingFactor,
170
174
  styleRules,
175
+ topologyUpdatePolicy,
171
176
  } = props;
172
177
 
173
178
  React.useEffect(() => {
@@ -186,6 +191,7 @@ function useRuntimeGraphUpdate(
186
191
  richNodeRendering: renderNode !== undefined,
187
192
  spacingFactor,
188
193
  styleRules,
194
+ topologyUpdatePolicy,
189
195
  });
190
196
  }, [
191
197
  edges,
@@ -203,6 +209,7 @@ function useRuntimeGraphUpdate(
203
209
  runtimeRef,
204
210
  spacingFactor,
205
211
  styleRules,
212
+ topologyUpdatePolicy,
206
213
  ]);
207
214
  }
208
215
 
@@ -109,6 +109,52 @@ test('fits changed topology but preserves viewport and avoids relayout for highl
109
109
  }
110
110
  });
111
111
 
112
+ test('preserves a stable topology removal without relayout, fit, or retained-node movement', async () => {
113
+ const ready = Promise.withResolvers<GraphViewController>();
114
+ const calls = { sort: 0 };
115
+ const runtime = createGraphRuntime(undefined, { current: { onReady: ready.resolve } });
116
+ const nodes = Array.from({ length: 87 }, (_, index) => ({ id: `repository-${index}` }));
117
+ const input = {
118
+ nodes,
119
+ edges: nodes.slice(1).flatMap((node, index) => {
120
+ const source = nodes.at(index);
121
+ return source ? [{ id: `dependency-${index}`, source: source.id, target: node.id }] : [];
122
+ }),
123
+ layout: 'grid' as const,
124
+ layoutOptions: {
125
+ sort: () => {
126
+ calls.sort += 1;
127
+ return 0;
128
+ },
129
+ },
130
+ richNodeRendering: false,
131
+ topologyUpdatePolicy: 'preserve-positions' as const,
132
+ };
133
+ try {
134
+ runtime.update(input);
135
+ const controller = await ready.promise;
136
+ controller.setZoom(0.7);
137
+ controller.setPan({ x: 40, y: 30 });
138
+ runtime.setSelectedNodeIds(['repository-0']);
139
+ const retainedIds = nodes.slice(0, -1).map((node) => node.id);
140
+ const before = controller.measureNodes?.(retainedIds);
141
+ const viewport = controller.getViewport();
142
+ const sortCount = calls.sort;
143
+
144
+ runtime.update({
145
+ ...input,
146
+ nodes: nodes.slice(0, -1),
147
+ edges: input.edges.slice(0, -1),
148
+ });
149
+
150
+ expect(controller.measureNodes?.(retainedIds)).toEqual(before);
151
+ expect(controller.getViewport()).toEqual(viewport);
152
+ expect(calls.sort).toBe(sortCount);
153
+ } finally {
154
+ runtime.destroy();
155
+ }
156
+ });
157
+
112
158
  test('fits a changed layout algorithm even when visible topology is unchanged', async () => {
113
159
  const initial = Promise.withResolvers<GraphViewController>();
114
160
  const completed = Promise.withResolvers<GraphViewController>();
@@ -314,3 +360,34 @@ test('settles the pending initial layout when presentation changes before readin
314
360
  runtime.destroy();
315
361
  }
316
362
  });
363
+
364
+ test('lays out 0 → 1 → 5 topology updates before preserve-positions becomes active', async () => {
365
+ const ready = Promise.withResolvers<GraphViewController>();
366
+ const calls = { sort: 0 };
367
+ const runtime = createGraphRuntime(undefined, { current: { onReady: ready.resolve } });
368
+ const layoutOptions = {
369
+ sort: () => {
370
+ calls.sort += 1;
371
+ return 0;
372
+ },
373
+ };
374
+ const fiveNodes = Array.from({ length: 5 }, (_, index) => ({ id: `repository-${index}` }));
375
+ const input = {
376
+ edges: [],
377
+ layout: 'grid' as const,
378
+ layoutOptions,
379
+ richNodeRendering: false,
380
+ topologyUpdatePolicy: 'preserve-positions' as const,
381
+ };
382
+ try {
383
+ runtime.update({ ...input, nodes: [] });
384
+ runtime.update({ ...input, nodes: fiveNodes.slice(0, 1) });
385
+ runtime.update({ ...input, nodes: fiveNodes });
386
+ const controller = await ready.promise;
387
+
388
+ expect(calls.sort).toBeGreaterThan(0);
389
+ expect(controller.measureNodes?.(fiveNodes.map((node) => node.id))?.nodes).toHaveLength(5);
390
+ } finally {
391
+ runtime.destroy();
392
+ }
393
+ });
@@ -18,6 +18,7 @@ import { createGraphResizeObserver, type GraphResizeObserver } from './createGra
18
18
  import { getGraphGeometryKey } from './getGraphGeometryKey';
19
19
  import { getGraphTopologyKey } from './getGraphTopologyKey';
20
20
  import { hasGraphLayoutChanged } from './hasGraphLayoutChanged';
21
+ import { placeAddedGraphNodes } from './placeAddedGraphNodes';
21
22
  import { readGraphRenderedNodes } from './readGraphRenderedNodes';
22
23
  import { registerGraphLayouts } from './registerGraphLayouts';
23
24
  import { runGraphLayout } from './runGraphLayout';
@@ -172,9 +173,14 @@ function updateRuntime(state: GraphRuntimeState, input: GraphRuntimeUpdate) {
172
173
  state.latestUpdateRef.current = input;
173
174
  state.fitPaddingRef.current = input.fitPadding ?? 50;
174
175
  state.viewport.configure(input);
176
+ const preservesTopology = shouldPreserveTopology(state, previous, input);
177
+ const retainedNodeIds = getRetainedNodeIds(previous, input, preservesTopology);
178
+ const retainedGeometry =
179
+ retainedNodeIds === null ? null : getGraphGeometryKey(state.cy, retainedNodeIds);
175
180
  state.cy.batch(() => {
176
181
  if (previous?.nodes !== input.nodes || previous.edges !== input.edges) {
177
182
  syncGraphElements(state.cy, input.nodes, input.edges);
183
+ if (preservesTopology) placeAddedGraphNodes(state.cy, previous?.nodes ?? [], input.nodes);
178
184
  }
179
185
  if (
180
186
  previous?.styleRules !== input.styleRules ||
@@ -194,7 +200,11 @@ function updateRuntime(state: GraphRuntimeState, input: GraphRuntimeUpdate) {
194
200
  const geometry = getGraphGeometryKey(state.cy);
195
201
  // Keep native double-press targets stable for paint-only class changes. A class that changes
196
202
  // measured node dimensions remains a geometry change and must relayout.
197
- const relayout = hasGraphLayoutChanged(previous, input) || geometry !== state.geometryRef.current;
203
+ const geometryChanged =
204
+ retainedGeometry === null
205
+ ? geometry !== state.geometryRef.current
206
+ : retainedGeometry !== getGraphGeometryKey(state.cy, retainedNodeIds ?? undefined);
207
+ const relayout = hasGraphLayoutChanged(previous, input, preservesTopology) || geometryChanged;
198
208
  state.geometryRef.current = geometry;
199
209
  if (!relayout) {
200
210
  if (
@@ -208,8 +218,6 @@ function updateRuntime(state: GraphRuntimeState, input: GraphRuntimeUpdate) {
208
218
  state.viewport.settle(previous?.zoomMode !== input.zoomMode);
209
219
  }
210
220
  emitRenderedNodes(state);
211
- if (!state.layoutRunningRef.current && !state.pendingInitialFitRef.current)
212
- state.callbacksRef.current.onLayoutComplete?.(state.controller);
213
221
  return;
214
222
  }
215
223
  stopCurrentLayout(state);
@@ -218,6 +226,31 @@ function updateRuntime(state: GraphRuntimeState, input: GraphRuntimeUpdate) {
218
226
  startCurrentLayout(state, input);
219
227
  }
220
228
 
229
+ /*** Preserve only opt-in topology updates after the initial layout and fit have settled. */
230
+ function shouldPreserveTopology(
231
+ state: GraphRuntimeState,
232
+ previous: GraphRuntimeUpdate | null,
233
+ input: GraphRuntimeUpdate,
234
+ ): boolean {
235
+ return (
236
+ previous !== null &&
237
+ state.readyRef.current &&
238
+ !state.pendingInitialFitRef.current &&
239
+ input.topologyUpdatePolicy === 'preserve-positions'
240
+ );
241
+ }
242
+
243
+ /*** Limit stable-update geometry checks to nodes that existed before reconciliation. */
244
+ function getRetainedNodeIds(
245
+ previous: GraphRuntimeUpdate | null,
246
+ input: GraphRuntimeUpdate,
247
+ preservesTopology: boolean,
248
+ ): ReadonlySet<string> | null {
249
+ if (!preservesTopology || previous === null) return null;
250
+ const nextNodeIds = new Set(input.nodes.map((node) => node.id));
251
+ return new Set(previous.nodes.map((node) => node.id).filter((id) => nextNodeIds.has(id)));
252
+ }
253
+
221
254
  /*** Start a generation-safe layout whose completion is the only normal automatic fit trigger. */
222
255
  function startCurrentLayout(state: GraphRuntimeState, input: GraphRuntimeUpdate) {
223
256
  state.pendingInitialFitRef.current = false;
@@ -7,18 +7,22 @@ import type { Core } from 'cytoscape';
7
7
  * bounds follow child positions, so keying their measured bounds would feed layout output back
8
8
  * into input. Styled geometry tests and runtime interaction tests protect these distinctions.
9
9
  */
10
- export function getGraphGeometryKey(cy: Core): string {
10
+ export function getGraphGeometryKey(cy: Core, nodeIds?: ReadonlySet<string>): string {
11
11
  return JSON.stringify(
12
- cy.nodes().map((node) => {
13
- if (node.isParent()) return [node.id()];
14
- const labelBounds = node.boundingBox({
15
- includeEdges: false,
16
- includeLabels: true,
17
- includeNodes: false,
18
- includeOverlays: false,
19
- includeUnderlays: false,
20
- });
21
- return [node.id(), node.outerWidth(), node.outerHeight(), labelBounds.w, labelBounds.h];
22
- }),
12
+ cy
13
+ .nodes()
14
+ .map((node) => {
15
+ if (nodeIds !== undefined && !nodeIds.has(node.id())) return null;
16
+ if (node.isParent()) return [node.id()];
17
+ const labelBounds = node.boundingBox({
18
+ includeEdges: false,
19
+ includeLabels: true,
20
+ includeNodes: false,
21
+ includeOverlays: false,
22
+ includeUnderlays: false,
23
+ });
24
+ return [node.id(), node.outerWidth(), node.outerHeight(), labelBounds.w, labelBounds.h];
25
+ })
26
+ .filter((entry) => entry !== null),
23
27
  );
24
28
  }
@@ -10,6 +10,7 @@ import { getGraphTopologyKey } from './getGraphTopologyKey';
10
10
  export function hasGraphLayoutChanged(
11
11
  previous: GraphRuntimeUpdate | null,
12
12
  input: GraphRuntimeUpdate,
13
+ preservesTopology: boolean,
13
14
  ): boolean {
14
15
  return (
15
16
  previous === null ||
@@ -17,7 +18,8 @@ export function hasGraphLayoutChanged(
17
18
  previous.spacingFactor !== input.spacingFactor ||
18
19
  previous.layoutOptions !== input.layoutOptions ||
19
20
  previous.richNodeRendering !== input.richNodeRendering ||
20
- getGraphTopologyKey(previous.nodes, previous.edges) !==
21
- getGraphTopologyKey(input.nodes, input.edges)
21
+ (!preservesTopology &&
22
+ getGraphTopologyKey(previous.nodes, previous.edges) !==
23
+ getGraphTopologyKey(input.nodes, input.edges))
22
24
  );
23
25
  }
@@ -0,0 +1,37 @@
1
+ import type { Core } from 'cytoscape';
2
+
3
+ import type { GraphViewNode } from '../../../../../types/graph-view';
4
+
5
+ const GRID_GAP = 120;
6
+
7
+ /***
8
+ * Give stable-topology additions deterministic positions without moving settled nodes.
9
+ * This deliberately is not an incremental layout: callers can request a complete layout by
10
+ * changing the configured algorithm, while ordinary controlled additions keep the user viewport.
11
+ */
12
+ export function placeAddedGraphNodes(
13
+ cy: Core,
14
+ previousNodes: readonly GraphViewNode[],
15
+ nodes: readonly GraphViewNode[],
16
+ ) {
17
+ const previousNodeIds = new Set(previousNodes.map((node) => node.id));
18
+ const addedNodes = nodes
19
+ .filter((node) => !previousNodeIds.has(node.id))
20
+ .sort((left, right) => left.id.localeCompare(right.id));
21
+ if (addedNodes.length === 0) return;
22
+
23
+ const retainedNodes = cy
24
+ .nodes()
25
+ .filter((node) => previousNodeIds.has(node.id()) && !node.isParent());
26
+ const bounds = retainedNodes.boundingBox({ includeEdges: false, includeLabels: true });
27
+ const origin = retainedNodes.empty() ? { x: 0, y: 0 } : { x: bounds.x2 + GRID_GAP, y: bounds.y1 };
28
+ const columns = Math.ceil(Math.sqrt(addedNodes.length));
29
+ addedNodes.forEach((node, index) => {
30
+ const graphNode = cy.getElementById(node.id);
31
+ if (graphNode.empty() || graphNode.isParent()) return;
32
+ graphNode.position({
33
+ x: origin.x + (index % columns) * GRID_GAP,
34
+ y: origin.y + Math.floor(index / columns) * GRID_GAP,
35
+ });
36
+ });
37
+ }
@@ -16,6 +16,7 @@ export type {
16
16
  GraphViewRenderedNode,
17
17
  GraphViewSize,
18
18
  GraphViewStyleRule,
19
+ GraphViewTopologyUpdatePolicy,
19
20
  GraphViewViewport,
20
21
  } from '../../types/graph-view';
21
22
  export { GraphView } from './adapters/inbound/web-artifact/GraphView';
@@ -2,6 +2,7 @@ import type { SelectionIntent } from '@ankhorage/utility/selection';
2
2
  import type React from 'react';
3
3
 
4
4
  export type GraphViewLayoutName = 'breadthfirst' | 'circle' | 'concentric' | 'elk' | 'grid';
5
+ export type GraphViewTopologyUpdatePolicy = 'preserve-positions';
5
6
  export type GraphViewElementEventType =
6
7
  'press' | 'double-press' | 'select' | 'unselect' | 'pointer-enter' | 'pointer-leave';
7
8
 
@@ -104,6 +105,12 @@ export interface GraphViewProps {
104
105
  readonly edges: readonly GraphViewEdge[];
105
106
  readonly layout?: GraphViewLayoutName;
106
107
  readonly layoutOptions?: Readonly<Record<string, unknown>>;
108
+ /**
109
+ * Preserve the settled viewport and retained-node positions during controlled topology updates.
110
+ * New nodes receive a deterministic initial position; call controller.fit() or change layout to
111
+ * intentionally fit or relayout the graph. Without this opt-in, topology changes relayout.
112
+ */
113
+ readonly topologyUpdatePolicy?: GraphViewTopologyUpdatePolicy;
107
114
  readonly spacingFactor?: number;
108
115
  readonly styleRules?: readonly GraphViewStyleRule[];
109
116
  readonly selectedNodeIds?: readonly string[];
@@ -3,6 +3,7 @@ import type {
3
3
  GraphViewLayoutName,
4
4
  GraphViewNode,
5
5
  GraphViewStyleRule,
6
+ GraphViewTopologyUpdatePolicy,
6
7
  } from './graph-view';
7
8
 
8
9
  export interface GraphRuntimeUpdate {
@@ -20,4 +21,5 @@ export interface GraphRuntimeUpdate {
20
21
  readonly richNodeRendering: boolean;
21
22
  readonly spacingFactor?: number;
22
23
  readonly styleRules?: readonly GraphViewStyleRule[];
24
+ readonly topologyUpdatePolicy?: GraphViewTopologyUpdatePolicy;
23
25
  }
@@ -18,6 +18,10 @@ import type { GraphViewProps } from './GraphView.types-0';
18
18
  * Ordinary zoom never adjusts spacing or relayouts. Explicit optimization preserves layout ordering,
19
19
  * stops once effective fit reaches maxFitLabelSize, keeps labels and unrelated compound boundaries
20
20
  * collision-safe, and permits only a small rendered background-overlap fallback for dense graphs.
21
+ * topologyUpdatePolicy Use `preserve-positions` for controlled incremental topology changes. It
22
+ * retains settled nodes and the user viewport, and initially places new nodes on a deterministic
23
+ * local grid. Use an explicit controller fit or a layout change when a complete rearrangement is
24
+ * intentional.
21
25
  */
22
26
  export declare function GraphView(props: GraphViewProps): React.JSX.Element;
23
27
 
@@ -27,4 +31,4 @@ export declare namespace GraphView {
27
31
  readonly layoutComplete: "zora-graph-view-layout-complete";
28
32
  };
29
33
  }
30
- export type { GraphViewCallbacks, GraphViewController, GraphViewDomControllerEventDetail, GraphViewEdge, GraphViewElementEvent, GraphViewElementEventType, GraphViewFitOptions, GraphViewLayoutName, GraphViewMeasurement, GraphViewNode, GraphViewNodeMeasurement, GraphViewNodeRenderContext, GraphViewPoint, GraphViewProps, GraphViewRenderedNode, GraphViewSize, GraphViewStyleRule, GraphViewViewport } from './GraphView.types-0';
34
+ export type { GraphViewCallbacks, GraphViewController, GraphViewDomControllerEventDetail, GraphViewEdge, GraphViewElementEvent, GraphViewElementEventType, GraphViewFitOptions, GraphViewLayoutName, GraphViewMeasurement, GraphViewNode, GraphViewNodeMeasurement, GraphViewNodeRenderContext, GraphViewPoint, GraphViewProps, GraphViewRenderedNode, GraphViewSize, GraphViewStyleRule, GraphViewTopologyUpdatePolicy, GraphViewViewport } from './GraphView.types-0';
@@ -123426,8 +123426,10 @@ function readResizeObserverConstructor() {
123426
123426
  }
123427
123427
 
123428
123428
  // src/features/graph-view/adapters/inbound/web-artifact/getGraphGeometryKey.ts
123429
- function getGraphGeometryKey(cy) {
123429
+ function getGraphGeometryKey(cy, nodeIds) {
123430
123430
  return JSON.stringify(cy.nodes().map((node) => {
123431
+ if (nodeIds !== undefined && !nodeIds.has(node.id()))
123432
+ return null;
123431
123433
  if (node.isParent())
123432
123434
  return [node.id()];
123433
123435
  const labelBounds = node.boundingBox({
@@ -123438,7 +123440,7 @@ function getGraphGeometryKey(cy) {
123438
123440
  includeUnderlays: false
123439
123441
  });
123440
123442
  return [node.id(), node.outerWidth(), node.outerHeight(), labelBounds.w, labelBounds.h];
123441
- }));
123443
+ }).filter((entry) => entry !== null));
123442
123444
  }
123443
123445
 
123444
123446
  // src/features/graph-view/adapters/inbound/web-artifact/getGraphTopologyKey.ts
@@ -123450,8 +123452,30 @@ function getGraphTopologyKey(nodes, edges) {
123450
123452
  }
123451
123453
 
123452
123454
  // src/features/graph-view/adapters/inbound/web-artifact/hasGraphLayoutChanged.ts
123453
- function hasGraphLayoutChanged(previous, input) {
123454
- return previous === null || previous.layout !== input.layout || previous.spacingFactor !== input.spacingFactor || previous.layoutOptions !== input.layoutOptions || previous.richNodeRendering !== input.richNodeRendering || getGraphTopologyKey(previous.nodes, previous.edges) !== getGraphTopologyKey(input.nodes, input.edges);
123455
+ function hasGraphLayoutChanged(previous, input, preservesTopology) {
123456
+ return previous === null || previous.layout !== input.layout || previous.spacingFactor !== input.spacingFactor || previous.layoutOptions !== input.layoutOptions || previous.richNodeRendering !== input.richNodeRendering || !preservesTopology && getGraphTopologyKey(previous.nodes, previous.edges) !== getGraphTopologyKey(input.nodes, input.edges);
123457
+ }
123458
+
123459
+ // src/features/graph-view/adapters/inbound/web-artifact/placeAddedGraphNodes.ts
123460
+ var GRID_GAP = 120;
123461
+ function placeAddedGraphNodes(cy, previousNodes, nodes) {
123462
+ const previousNodeIds = new Set(previousNodes.map((node) => node.id));
123463
+ const addedNodes = nodes.filter((node) => !previousNodeIds.has(node.id)).sort((left, right) => left.id.localeCompare(right.id));
123464
+ if (addedNodes.length === 0)
123465
+ return;
123466
+ const retainedNodes = cy.nodes().filter((node) => previousNodeIds.has(node.id()) && !node.isParent());
123467
+ const bounds = retainedNodes.boundingBox({ includeEdges: false, includeLabels: true });
123468
+ const origin = retainedNodes.empty() ? { x: 0, y: 0 } : { x: bounds.x2 + GRID_GAP, y: bounds.y1 };
123469
+ const columns = Math.ceil(Math.sqrt(addedNodes.length));
123470
+ addedNodes.forEach((node, index) => {
123471
+ const graphNode = cy.getElementById(node.id);
123472
+ if (graphNode.empty() || graphNode.isParent())
123473
+ return;
123474
+ graphNode.position({
123475
+ x: origin.x + index % columns * GRID_GAP,
123476
+ y: origin.y + Math.floor(index / columns) * GRID_GAP
123477
+ });
123478
+ });
123455
123479
  }
123456
123480
 
123457
123481
  // src/features/graph-view/adapters/inbound/web-artifact/readGraphRenderedNodes.ts
@@ -124078,9 +124102,14 @@ function updateRuntime(state, input) {
124078
124102
  state.latestUpdateRef.current = input;
124079
124103
  state.fitPaddingRef.current = input.fitPadding ?? 50;
124080
124104
  state.viewport.configure(input);
124105
+ const preservesTopology = shouldPreserveTopology(state, previous, input);
124106
+ const retainedNodeIds = getRetainedNodeIds(previous, input, preservesTopology);
124107
+ const retainedGeometry = retainedNodeIds === null ? null : getGraphGeometryKey(state.cy, retainedNodeIds);
124081
124108
  state.cy.batch(() => {
124082
124109
  if (previous?.nodes !== input.nodes || previous.edges !== input.edges) {
124083
124110
  syncGraphElements(state.cy, input.nodes, input.edges);
124111
+ if (preservesTopology)
124112
+ placeAddedGraphNodes(state.cy, previous?.nodes ?? [], input.nodes);
124084
124113
  }
124085
124114
  if (previous?.styleRules !== input.styleRules || previous?.richNodeRendering !== input.richNodeRendering) {
124086
124115
  state.loopSizer.reset();
@@ -124091,15 +124120,14 @@ function updateRuntime(state, input) {
124091
124120
  applyKnownNodeSizes(state);
124092
124121
  state.loopSizer.update();
124093
124122
  const geometry = getGraphGeometryKey(state.cy);
124094
- const relayout = hasGraphLayoutChanged(previous, input) || geometry !== state.geometryRef.current;
124123
+ const geometryChanged = retainedGeometry === null ? geometry !== state.geometryRef.current : retainedGeometry !== getGraphGeometryKey(state.cy, retainedNodeIds ?? undefined);
124124
+ const relayout = hasGraphLayoutChanged(previous, input, preservesTopology) || geometryChanged;
124095
124125
  state.geometryRef.current = geometry;
124096
124126
  if (!relayout) {
124097
124127
  if (previous?.zoomMode !== input.zoomMode || previous?.fitPadding !== input.fitPadding || previous?.minZoom !== input.minZoom || previous?.maxZoom !== input.maxZoom || previous?.minReadableLabelSize !== input.minReadableLabelSize || previous?.maxFitLabelSize !== input.maxFitLabelSize) {
124098
124128
  state.viewport.settle(previous?.zoomMode !== input.zoomMode);
124099
124129
  }
124100
124130
  emitRenderedNodes(state);
124101
- if (!state.layoutRunningRef.current && !state.pendingInitialFitRef.current)
124102
- state.callbacksRef.current.onLayoutComplete?.(state.controller);
124103
124131
  return;
124104
124132
  }
124105
124133
  stopCurrentLayout(state);
@@ -124107,6 +124135,15 @@ function updateRuntime(state, input) {
124107
124135
  state.optimizedSpacingRef.current = null;
124108
124136
  startCurrentLayout(state, input);
124109
124137
  }
124138
+ function shouldPreserveTopology(state, previous, input) {
124139
+ return previous !== null && state.readyRef.current && !state.pendingInitialFitRef.current && input.topologyUpdatePolicy === "preserve-positions";
124140
+ }
124141
+ function getRetainedNodeIds(previous, input, preservesTopology) {
124142
+ if (!preservesTopology || previous === null)
124143
+ return null;
124144
+ const nextNodeIds = new Set(input.nodes.map((node) => node.id));
124145
+ return new Set(previous.nodes.map((node) => node.id).filter((id) => nextNodeIds.has(id)));
124146
+ }
124110
124147
  function startCurrentLayout(state, input) {
124111
124148
  state.pendingInitialFitRef.current = false;
124112
124149
  const generation = state.generationRef.current + 1;
@@ -124495,7 +124532,8 @@ function useRuntimeGraphUpdate(runtimeRef, props) {
124495
124532
  nodes,
124496
124533
  renderNode,
124497
124534
  spacingFactor,
124498
- styleRules
124535
+ styleRules,
124536
+ topologyUpdatePolicy
124499
124537
  } = props;
124500
124538
  React2.useEffect(() => {
124501
124539
  runtimeRef.current?.update({
@@ -124512,7 +124550,8 @@ function useRuntimeGraphUpdate(runtimeRef, props) {
124512
124550
  nodes,
124513
124551
  richNodeRendering: renderNode !== undefined,
124514
124552
  spacingFactor,
124515
- styleRules
124553
+ styleRules,
124554
+ topologyUpdatePolicy
124516
124555
  });
124517
124556
  }, [
124518
124557
  edges,
@@ -124529,7 +124568,8 @@ function useRuntimeGraphUpdate(runtimeRef, props) {
124529
124568
  renderNode,
124530
124569
  runtimeRef,
124531
124570
  spacingFactor,
124532
- styleRules
124571
+ styleRules,
124572
+ topologyUpdatePolicy
124533
124573
  ]);
124534
124574
  }
124535
124575
  function useRuntimeSelection(runtimeRef, selectedNodeIds) {
@@ -1,6 +1,7 @@
1
1
  import type { SelectionIntent } from '@ankhorage/utility/selection';
2
2
  import type React from 'react';
3
3
  export type GraphViewLayoutName = 'breadthfirst' | 'circle' | 'concentric' | 'elk' | 'grid';
4
+ export type GraphViewTopologyUpdatePolicy = 'preserve-positions';
4
5
  export type GraphViewElementEventType = 'press' | 'double-press' | 'select' | 'unselect' | 'pointer-enter' | 'pointer-leave';
5
6
  export interface GraphViewNode {
6
7
  readonly id: string;
@@ -90,6 +91,12 @@ export interface GraphViewProps {
90
91
  readonly edges: readonly GraphViewEdge[];
91
92
  readonly layout?: GraphViewLayoutName;
92
93
  readonly layoutOptions?: Readonly<Record<string, unknown>>;
94
+ /**
95
+ * Preserve the settled viewport and retained-node positions during controlled topology updates.
96
+ * New nodes receive a deterministic initial position; call controller.fit() or change layout to
97
+ * intentionally fit or relayout the graph. Without this opt-in, topology changes relayout.
98
+ */
99
+ readonly topologyUpdatePolicy?: GraphViewTopologyUpdatePolicy;
93
100
  readonly spacingFactor?: number;
94
101
  readonly styleRules?: readonly GraphViewStyleRule[];
95
102
  readonly selectedNodeIds?: readonly string[];