@ankhorage/zora 27.4.0 → 27.4.1

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 (40) 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.map +1 -1
  4. package/dist/features/graph-view/adapters/inbound/web-artifact/GraphView.js +11 -7
  5. package/dist/features/graph-view/adapters/inbound/web-artifact/GraphView.js.map +1 -1
  6. package/dist/features/graph-view/adapters/inbound/web-artifact/bindGraphEvents.d.ts +2 -2
  7. package/dist/features/graph-view/adapters/inbound/web-artifact/bindGraphEvents.d.ts.map +1 -1
  8. package/dist/features/graph-view/adapters/inbound/web-artifact/bindGraphEvents.js +7 -7
  9. package/dist/features/graph-view/adapters/inbound/web-artifact/bindGraphEvents.js.map +1 -1
  10. package/dist/features/graph-view/adapters/inbound/web-artifact/createGraphPointerDownReader.d.ts +7 -0
  11. package/dist/features/graph-view/adapters/inbound/web-artifact/createGraphPointerDownReader.d.ts.map +1 -0
  12. package/dist/features/graph-view/adapters/inbound/web-artifact/createGraphPointerDownReader.js +40 -0
  13. package/dist/features/graph-view/adapters/inbound/web-artifact/createGraphPointerDownReader.js.map +1 -0
  14. package/dist/features/graph-view/adapters/inbound/web-artifact/createGraphRuntime.d.ts +1 -1
  15. package/dist/features/graph-view/adapters/inbound/web-artifact/createGraphRuntime.d.ts.map +1 -1
  16. package/dist/features/graph-view/adapters/inbound/web-artifact/createGraphRuntime.js +28 -4
  17. package/dist/features/graph-view/adapters/inbound/web-artifact/createGraphRuntime.js.map +1 -1
  18. package/dist/features/selection/application/resolveSelectionEventIntent.d.ts +1 -1
  19. package/dist/features/selection/application/resolveSelectionEventIntent.d.ts.map +1 -1
  20. package/dist/features/selection/application/resolveSelectionEventIntent.js +14 -5
  21. package/dist/features/selection/application/resolveSelectionEventIntent.js.map +1 -1
  22. package/package.json +1 -1
  23. package/src/features/graph-view/adapters/inbound/web-artifact/GraphView.tsx +16 -4
  24. package/src/features/graph-view/adapters/inbound/web-artifact/bindGraphEvents.ts +24 -4
  25. package/src/features/graph-view/adapters/inbound/web-artifact/createGraphPointerDownReader.test.ts +28 -0
  26. package/src/features/graph-view/adapters/inbound/web-artifact/createGraphPointerDownReader.ts +48 -0
  27. package/src/features/graph-view/adapters/inbound/web-artifact/createGraphRuntime.test.ts +16 -6
  28. package/src/features/graph-view/adapters/inbound/web-artifact/createGraphRuntime.ts +34 -3
  29. package/src/features/selection/application/resolveSelectionEventIntent.test.ts +1 -0
  30. package/src/features/selection/application/resolveSelectionEventIntent.ts +18 -4
  31. package/web-dist/authoring/index.js +6 -5
  32. package/web-dist/chunks/{Accordion-md1g54wg.js → Accordion-eq27a9ms.js} +6 -5
  33. package/web-dist/chunks/{Accordion-9n062we9.js → Accordion-x33am5bc.js} +1 -1
  34. package/web-dist/components/graph-view/GraphView.js +81 -18
  35. package/web-dist/components/matrix-grid/MatrixGrid.js +2 -2
  36. package/web-dist/components/selectable-item/SelectableItem.js +1 -1
  37. package/web-dist/components/selection-provider/SelectionProvider.js +1 -1
  38. package/web-dist/components/tree-item/TreeItem.js +2 -2
  39. package/web-dist/components/tree-view/TreeView.js +1 -1
  40. package/web-dist/manifest.json +11 -11
@@ -1,18 +1,27 @@
1
1
  import { resolveSelectionIntent, } from '@ankhorage/utility/interaction';
2
2
  import { isRecord } from '@ankhorage/utility/object';
3
3
  /*** Normalize DOM, React Native, and renderer events into one semantic selection intent. */
4
- export function resolveSelectionEventIntent(event, fallbackKind) {
4
+ export function resolveSelectionEventIntent(event, fallbackKind, nativeEvent = {}) {
5
5
  const source = readEventSource(event);
6
6
  const kind = isTouchActivation(source) ? 'touch' : fallbackKind;
7
7
  const sourceModifiers = readInteractionModifiers(source);
8
8
  const wrapperModifiers = readInteractionModifiers(event);
9
+ const nativeModifiers = readInteractionModifiers(nativeEvent);
9
10
  const input = {
10
11
  kind,
11
12
  modifiers: {
12
- altKey: sourceModifiers.altKey === true || wrapperModifiers.altKey === true,
13
- ctrlKey: sourceModifiers.ctrlKey === true || wrapperModifiers.ctrlKey === true,
14
- metaKey: sourceModifiers.metaKey === true || wrapperModifiers.metaKey === true,
15
- shiftKey: sourceModifiers.shiftKey === true || wrapperModifiers.shiftKey === true,
13
+ altKey: sourceModifiers.altKey === true ||
14
+ wrapperModifiers.altKey === true ||
15
+ nativeModifiers.altKey === true,
16
+ ctrlKey: sourceModifiers.ctrlKey === true ||
17
+ wrapperModifiers.ctrlKey === true ||
18
+ nativeModifiers.ctrlKey === true,
19
+ metaKey: sourceModifiers.metaKey === true ||
20
+ wrapperModifiers.metaKey === true ||
21
+ nativeModifiers.metaKey === true,
22
+ shiftKey: sourceModifiers.shiftKey === true ||
23
+ wrapperModifiers.shiftKey === true ||
24
+ nativeModifiers.shiftKey === true,
16
25
  },
17
26
  };
18
27
  return resolveSelectionIntent(input);
@@ -1 +1 @@
1
- {"version":3,"file":"resolveSelectionEventIntent.js","sourceRoot":"","sources":["../../../../src/features/selection/application/resolveSelectionEventIntent.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,sBAAsB,GAGvB,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAC;AAGrD,4FAA4F;AAC5F,MAAM,UAAU,2BAA2B,CACzC,KAAc,EACd,YAAqC;IAErC,MAAM,MAAM,GAAG,eAAe,CAAC,KAAK,CAAC,CAAC;IACtC,MAAM,IAAI,GAA4B,iBAAiB,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,YAAY,CAAC;IACzF,MAAM,eAAe,GAAG,wBAAwB,CAAC,MAAM,CAAC,CAAC;IACzD,MAAM,gBAAgB,GAAG,wBAAwB,CAAC,KAAK,CAAC,CAAC;IACzD,MAAM,KAAK,GAA8B;QACvC,IAAI;QACJ,SAAS,EAAE;YACT,MAAM,EAAE,eAAe,CAAC,MAAM,KAAK,IAAI,IAAI,gBAAgB,CAAC,MAAM,KAAK,IAAI;YAC3E,OAAO,EAAE,eAAe,CAAC,OAAO,KAAK,IAAI,IAAI,gBAAgB,CAAC,OAAO,KAAK,IAAI;YAC9E,OAAO,EAAE,eAAe,CAAC,OAAO,KAAK,IAAI,IAAI,gBAAgB,CAAC,OAAO,KAAK,IAAI;YAC9E,QAAQ,EAAE,eAAe,CAAC,QAAQ,KAAK,IAAI,IAAI,gBAAgB,CAAC,QAAQ,KAAK,IAAI;SAClF;KACF,CAAC;IACF,OAAO,sBAAsB,CAAC,KAAK,CAAC,CAAC;AACvC,CAAC;AAED,gGAAgG;AAChG,SAAS,eAAe,CAAC,KAAc;IACrC,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC;QAAE,OAAO,EAAE,CAAC;IAChC,IAAI,QAAQ,CAAC,KAAK,CAAC,aAAa,CAAC;QAAE,OAAO,KAAK,CAAC,aAAa,CAAC;IAC9D,IAAI,QAAQ,CAAC,KAAK,CAAC,WAAW,CAAC;QAAE,OAAO,KAAK,CAAC,WAAW,CAAC;IAC1D,OAAO,KAAK,CAAC;AACf,CAAC;AAED,0GAA0G;AAC1G,SAAS,iBAAiB,CAAC,MAAyC;IAClE,IAAI,MAAM,CAAC,WAAW,KAAK,OAAO;QAAE,OAAO,IAAI,CAAC;IAChD,IAAI,OAAO,MAAM,CAAC,IAAI,KAAK,QAAQ,IAAI,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC;QAAE,OAAO,IAAI,CAAC;IACpF,OAAO,SAAS,IAAI,MAAM,IAAI,gBAAgB,IAAI,MAAM,CAAC;AAC3D,CAAC;AAED,sGAAsG;AACtG,SAAS,wBAAwB,CAAC,KAAc;IAC9C,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC;QAAE,OAAO,EAAE,CAAC;IAChC,OAAO;QACL,MAAM,EAAE,KAAK,CAAC,MAAM,KAAK,IAAI;QAC7B,OAAO,EAAE,KAAK,CAAC,OAAO,KAAK,IAAI;QAC/B,OAAO,EAAE,KAAK,CAAC,OAAO,KAAK,IAAI;QAC/B,QAAQ,EAAE,KAAK,CAAC,QAAQ,KAAK,IAAI;KAClC,CAAC;AACJ,CAAC","sourcesContent":["import {\n type InteractionModifiers,\n resolveSelectionIntent,\n type SelectionActivationKind,\n type SelectionInteractionInput,\n} from '@ankhorage/utility/interaction';\nimport { isRecord } from '@ankhorage/utility/object';\nimport type { SelectionIntent } from '@ankhorage/utility/selection';\n\n/*** Normalize DOM, React Native, and renderer events into one semantic selection intent. */\nexport function resolveSelectionEventIntent(\n event: unknown,\n fallbackKind: SelectionActivationKind,\n): SelectionIntent {\n const source = readEventSource(event);\n const kind: SelectionActivationKind = isTouchActivation(source) ? 'touch' : fallbackKind;\n const sourceModifiers = readInteractionModifiers(source);\n const wrapperModifiers = readInteractionModifiers(event);\n const input: SelectionInteractionInput = {\n kind,\n modifiers: {\n altKey: sourceModifiers.altKey === true || wrapperModifiers.altKey === true,\n ctrlKey: sourceModifiers.ctrlKey === true || wrapperModifiers.ctrlKey === true,\n metaKey: sourceModifiers.metaKey === true || wrapperModifiers.metaKey === true,\n shiftKey: sourceModifiers.shiftKey === true || wrapperModifiers.shiftKey === true,\n },\n };\n return resolveSelectionIntent(input);\n}\n\n/*** Prefer one nested native/renderer event while preserving structural event compatibility. */\nfunction readEventSource(event: unknown): Readonly<Record<string, unknown>> {\n if (!isRecord(event)) return {};\n if (isRecord(event.originalEvent)) return event.originalEvent;\n if (isRecord(event.nativeEvent)) return event.nativeEvent;\n return event;\n}\n\n/*** Recognize pointer and native/browser touch event shapes without depending on platform event types. */\nfunction isTouchActivation(source: Readonly<Record<string, unknown>>): boolean {\n if (source.pointerType === 'touch') return true;\n if (typeof source.type === 'string' && source.type.startsWith('touch')) return true;\n return 'touches' in source || 'changedTouches' in source;\n}\n\n/*** Read known modifiers explicitly so arbitrary event properties never become dynamic input keys. */\nfunction readInteractionModifiers(value: unknown): InteractionModifiers {\n if (!isRecord(value)) return {};\n return {\n altKey: value.altKey === true,\n ctrlKey: value.ctrlKey === true,\n metaKey: value.metaKey === true,\n shiftKey: value.shiftKey === true,\n };\n}\n"]}
1
+ {"version":3,"file":"resolveSelectionEventIntent.js","sourceRoot":"","sources":["../../../../src/features/selection/application/resolveSelectionEventIntent.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,sBAAsB,GAGvB,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAC;AAGrD,4FAA4F;AAC5F,MAAM,UAAU,2BAA2B,CACzC,KAAc,EACd,YAAqC,EACrC,cAAuB,EAAE;IAEzB,MAAM,MAAM,GAAG,eAAe,CAAC,KAAK,CAAC,CAAC;IACtC,MAAM,IAAI,GAA4B,iBAAiB,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,YAAY,CAAC;IACzF,MAAM,eAAe,GAAG,wBAAwB,CAAC,MAAM,CAAC,CAAC;IACzD,MAAM,gBAAgB,GAAG,wBAAwB,CAAC,KAAK,CAAC,CAAC;IACzD,MAAM,eAAe,GAAG,wBAAwB,CAAC,WAAW,CAAC,CAAC;IAC9D,MAAM,KAAK,GAA8B;QACvC,IAAI;QACJ,SAAS,EAAE;YACT,MAAM,EACJ,eAAe,CAAC,MAAM,KAAK,IAAI;gBAC/B,gBAAgB,CAAC,MAAM,KAAK,IAAI;gBAChC,eAAe,CAAC,MAAM,KAAK,IAAI;YACjC,OAAO,EACL,eAAe,CAAC,OAAO,KAAK,IAAI;gBAChC,gBAAgB,CAAC,OAAO,KAAK,IAAI;gBACjC,eAAe,CAAC,OAAO,KAAK,IAAI;YAClC,OAAO,EACL,eAAe,CAAC,OAAO,KAAK,IAAI;gBAChC,gBAAgB,CAAC,OAAO,KAAK,IAAI;gBACjC,eAAe,CAAC,OAAO,KAAK,IAAI;YAClC,QAAQ,EACN,eAAe,CAAC,QAAQ,KAAK,IAAI;gBACjC,gBAAgB,CAAC,QAAQ,KAAK,IAAI;gBAClC,eAAe,CAAC,QAAQ,KAAK,IAAI;SACpC;KACF,CAAC;IACF,OAAO,sBAAsB,CAAC,KAAK,CAAC,CAAC;AACvC,CAAC;AAED,gGAAgG;AAChG,SAAS,eAAe,CAAC,KAAc;IACrC,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC;QAAE,OAAO,EAAE,CAAC;IAChC,IAAI,QAAQ,CAAC,KAAK,CAAC,aAAa,CAAC;QAAE,OAAO,KAAK,CAAC,aAAa,CAAC;IAC9D,IAAI,QAAQ,CAAC,KAAK,CAAC,WAAW,CAAC;QAAE,OAAO,KAAK,CAAC,WAAW,CAAC;IAC1D,OAAO,KAAK,CAAC;AACf,CAAC;AAED,0GAA0G;AAC1G,SAAS,iBAAiB,CAAC,MAAyC;IAClE,IAAI,MAAM,CAAC,WAAW,KAAK,OAAO;QAAE,OAAO,IAAI,CAAC;IAChD,IAAI,OAAO,MAAM,CAAC,IAAI,KAAK,QAAQ,IAAI,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC;QAAE,OAAO,IAAI,CAAC;IACpF,OAAO,SAAS,IAAI,MAAM,IAAI,gBAAgB,IAAI,MAAM,CAAC;AAC3D,CAAC;AAED,sGAAsG;AACtG,SAAS,wBAAwB,CAAC,KAAc;IAC9C,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC;QAAE,OAAO,EAAE,CAAC;IAChC,OAAO;QACL,MAAM,EAAE,KAAK,CAAC,MAAM,KAAK,IAAI;QAC7B,OAAO,EAAE,KAAK,CAAC,OAAO,KAAK,IAAI;QAC/B,OAAO,EAAE,KAAK,CAAC,OAAO,KAAK,IAAI;QAC/B,QAAQ,EAAE,KAAK,CAAC,QAAQ,KAAK,IAAI;KAClC,CAAC;AACJ,CAAC","sourcesContent":["import {\n type InteractionModifiers,\n resolveSelectionIntent,\n type SelectionActivationKind,\n type SelectionInteractionInput,\n} from '@ankhorage/utility/interaction';\nimport { isRecord } from '@ankhorage/utility/object';\nimport type { SelectionIntent } from '@ankhorage/utility/selection';\n\n/*** Normalize DOM, React Native, and renderer events into one semantic selection intent. */\nexport function resolveSelectionEventIntent(\n event: unknown,\n fallbackKind: SelectionActivationKind,\n nativeEvent: unknown = {},\n): SelectionIntent {\n const source = readEventSource(event);\n const kind: SelectionActivationKind = isTouchActivation(source) ? 'touch' : fallbackKind;\n const sourceModifiers = readInteractionModifiers(source);\n const wrapperModifiers = readInteractionModifiers(event);\n const nativeModifiers = readInteractionModifiers(nativeEvent);\n const input: SelectionInteractionInput = {\n kind,\n modifiers: {\n altKey:\n sourceModifiers.altKey === true ||\n wrapperModifiers.altKey === true ||\n nativeModifiers.altKey === true,\n ctrlKey:\n sourceModifiers.ctrlKey === true ||\n wrapperModifiers.ctrlKey === true ||\n nativeModifiers.ctrlKey === true,\n metaKey:\n sourceModifiers.metaKey === true ||\n wrapperModifiers.metaKey === true ||\n nativeModifiers.metaKey === true,\n shiftKey:\n sourceModifiers.shiftKey === true ||\n wrapperModifiers.shiftKey === true ||\n nativeModifiers.shiftKey === true,\n },\n };\n return resolveSelectionIntent(input);\n}\n\n/*** Prefer one nested native/renderer event while preserving structural event compatibility. */\nfunction readEventSource(event: unknown): Readonly<Record<string, unknown>> {\n if (!isRecord(event)) return {};\n if (isRecord(event.originalEvent)) return event.originalEvent;\n if (isRecord(event.nativeEvent)) return event.nativeEvent;\n return event;\n}\n\n/*** Recognize pointer and native/browser touch event shapes without depending on platform event types. */\nfunction isTouchActivation(source: Readonly<Record<string, unknown>>): boolean {\n if (source.pointerType === 'touch') return true;\n if (typeof source.type === 'string' && source.type.startsWith('touch')) return true;\n return 'touches' in source || 'changedTouches' in source;\n}\n\n/*** Read known modifiers explicitly so arbitrary event properties never become dynamic input keys. */\nfunction readInteractionModifiers(value: unknown): InteractionModifiers {\n if (!isRecord(value)) return {};\n return {\n altKey: value.altKey === true,\n ctrlKey: value.ctrlKey === true,\n metaKey: value.metaKey === true,\n shiftKey: value.shiftKey === true,\n };\n}\n"]}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ankhorage/zora",
3
3
  "type": "module",
4
- "version": "27.4.0",
4
+ "version": "27.4.1",
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": {
@@ -8,6 +8,7 @@ import type {
8
8
  GraphViewRenderedNode,
9
9
  } from '../../../../../types/graph-view';
10
10
  import { GRAPH_VIEW_EVENTS } from '../../../constants/events';
11
+ import { createGraphPointerDownReader } from './createGraphPointerDownReader';
11
12
  import { createGraphRuntime, type GraphRuntime } from './createGraphRuntime';
12
13
  import { createGraphViewDomCallbacks } from './createGraphViewDomCallbacks';
13
14
  import { GraphNodeOverlay } from './GraphNodeOverlay';
@@ -37,11 +38,20 @@ type GraphContainer = NonNullable<CytoscapeOptions['container']>;
37
38
  */
38
39
  export function GraphView(props: GraphViewProps) {
39
40
  const hostRef = React.useRef<HTMLDivElement | null>(null);
40
- const { containerRef, renderedNodes, runtimeRef } = useGraphViewRuntime(props, hostRef);
41
+ const pointerDownReader = React.useMemo(createGraphPointerDownReader, []);
42
+ const { containerRef, renderedNodes, runtimeRef } = useGraphViewRuntime(
43
+ props,
44
+ hostRef,
45
+ pointerDownReader,
46
+ );
41
47
 
42
48
  return (
43
49
  <div
44
50
  ref={hostRef}
51
+ onPointerDown={(event) => {
52
+ pointerDownReader.write(event.nativeEvent);
53
+ }}
54
+ onPointerCancel={pointerDownReader.clear}
45
55
  aria-label={props.ariaLabel ?? 'Graph'}
46
56
  className={props.className}
47
57
  role="application"
@@ -77,13 +87,14 @@ GraphView.events = GRAPH_VIEW_EVENTS;
77
87
  function useGraphViewRuntime(
78
88
  props: GraphViewProps,
79
89
  hostRef: React.RefObject<HTMLDivElement | null>,
90
+ pointerDownReader: ReturnType<typeof createGraphPointerDownReader>,
80
91
  ) {
81
92
  const containerRef = React.useRef<GraphContainer | null>(null);
82
93
  const runtimeRef = React.useRef<GraphRuntime | null>(null);
83
94
  const callbacksRef = useGraphCallbacksRef(props, hostRef);
84
95
  const [renderedNodes, setRenderedNodes] = React.useState<readonly GraphViewRenderedNode[]>([]);
85
96
 
86
- useRuntimeLifecycle(containerRef, runtimeRef, callbacksRef);
97
+ useRuntimeLifecycle(containerRef, runtimeRef, callbacksRef, pointerDownReader);
87
98
  useRuntimeGraphUpdate(runtimeRef, props);
88
99
  useRuntimeSelection(runtimeRef, props.selectedNodeIds);
89
100
  useRenderedNodeSubscription(runtimeRef, props.renderNode, setRenderedNodes);
@@ -139,17 +150,18 @@ function useRuntimeLifecycle(
139
150
  containerRef: { current: GraphContainer | null },
140
151
  runtimeRef: { current: GraphRuntime | null },
141
152
  callbacksRef: { current: GraphViewCallbacks },
153
+ pointerDownReader: ReturnType<typeof createGraphPointerDownReader>,
142
154
  ) {
143
155
  React.useEffect(() => {
144
156
  const container = containerRef.current;
145
157
  if (container === null) return;
146
- const runtime = createGraphRuntime(container, callbacksRef);
158
+ const runtime = createGraphRuntime(container, callbacksRef, pointerDownReader.read);
147
159
  runtimeRef.current = runtime;
148
160
  return () => {
149
161
  runtime.destroy();
150
162
  runtimeRef.current = null;
151
163
  };
152
- }, [callbacksRef, containerRef, runtimeRef]);
164
+ }, [callbacksRef, containerRef, pointerDownReader, runtimeRef]);
153
165
  }
154
166
 
155
167
  /*** Synchronize graph data and layout policy without exposing Cytoscape to React. */
@@ -14,9 +14,22 @@ export function bindGraphEvents(
14
14
  callbacksRef: { current: GraphViewCallbacks },
15
15
  controller: GraphViewController,
16
16
  onRuntimeChange: () => void,
17
+ readLatestPointerDown: (event: EventObject) => unknown = () => null,
17
18
  ) {
18
- const nodeHandlers = bindElementEvents(cy, 'node', callbacksRef, onRuntimeChange);
19
- const edgeHandlers = bindElementEvents(cy, 'edge', callbacksRef, onRuntimeChange);
19
+ const nodeHandlers = bindElementEvents(
20
+ cy,
21
+ 'node',
22
+ callbacksRef,
23
+ onRuntimeChange,
24
+ readLatestPointerDown,
25
+ );
26
+ const edgeHandlers = bindElementEvents(
27
+ cy,
28
+ 'edge',
29
+ callbacksRef,
30
+ onRuntimeChange,
31
+ readLatestPointerDown,
32
+ );
20
33
  const viewportHandler = () => {
21
34
  callbacksRef.current.onViewportChange?.(controller.getViewport());
22
35
  onRuntimeChange();
@@ -43,6 +56,7 @@ function bindElementEvents(
43
56
  selector: ElementSelector,
44
57
  callbacksRef: { current: GraphViewCallbacks },
45
58
  onRuntimeChange: () => void,
59
+ readLatestPointerDown: (event: EventObject) => unknown,
46
60
  ): readonly BoundElementHandler[] {
47
61
  return EVENT_TYPES.map(([cytoscapeEvent, type]) => {
48
62
  const handler = (event: EventObject) => {
@@ -51,7 +65,12 @@ function bindElementEvents(
51
65
  emitElementEvent(
52
66
  callbacksRef.current,
53
67
  selector,
54
- createElementEvent(event, target.id(), type),
68
+ createElementEvent(
69
+ event,
70
+ target.id(),
71
+ type,
72
+ type === 'press' ? readLatestPointerDown(event) : null,
73
+ ),
55
74
  );
56
75
  onRuntimeChange();
57
76
  };
@@ -65,12 +84,13 @@ function createElementEvent(
65
84
  event: EventObject,
66
85
  id: string,
67
86
  type: GraphViewElementEventType,
87
+ nativeEvent: unknown,
68
88
  ): GraphViewElementEvent {
69
89
  if (type !== 'press') return { id, type };
70
90
  return {
71
91
  id,
72
92
  type,
73
- selectionIntent: resolveSelectionEventIntent(event, 'pointer'),
93
+ selectionIntent: resolveSelectionEventIntent(event, 'pointer', nativeEvent),
74
94
  };
75
95
  }
76
96
 
@@ -0,0 +1,28 @@
1
+ import { expect, test } from 'bun:test';
2
+
3
+ import { createGraphPointerDownReader } from './createGraphPointerDownReader';
4
+
5
+ test('uses a Ctrl pointer snapshot only for its matching renderer pointer activation', () => {
6
+ const reader = createGraphPointerDownReader();
7
+ const pointerDown = { ctrlKey: true, pointerId: 7 };
8
+
9
+ reader.write(pointerDown);
10
+
11
+ expect(reader.read({ originalEvent: { pointerId: 7 } })).toBe(pointerDown);
12
+ expect(reader.read({ originalEvent: { pointerId: 7 } })).toBeNull();
13
+ });
14
+
15
+ test('discards a Meta pointer snapshot for unrelated touch, keyboard, programmatic, and mouse events', () => {
16
+ const unrelatedEvents = [
17
+ { originalEvent: { pointerId: 8, pointerType: 'touch' } },
18
+ { originalEvent: { key: 'Enter', type: 'keydown' } },
19
+ {},
20
+ { originalEvent: { pointerId: 9, pointerType: 'mouse' } },
21
+ ];
22
+
23
+ for (const event of unrelatedEvents) {
24
+ const reader = createGraphPointerDownReader();
25
+ reader.write({ metaKey: true, pointerId: 7 });
26
+ expect(reader.read(event)).toBeNull();
27
+ }
28
+ });
@@ -0,0 +1,48 @@
1
+ import { isRecord } from '@ankhorage/utility/object';
2
+
3
+ /*** Correlate one native pointer-down snapshot with its renderer activation without retaining stale modifiers. */
4
+ export function createGraphPointerDownReader() {
5
+ let latestPointerDown: GraphPointerDownSnapshot | null = null;
6
+
7
+ return {
8
+ clear: () => {
9
+ latestPointerDown = null;
10
+ },
11
+ read: (rendererEvent: unknown): unknown => {
12
+ const pointerDown = latestPointerDown;
13
+ latestPointerDown = null;
14
+ if (pointerDown === null) return null;
15
+ return matchesPointerActivation(pointerDown, rendererEvent) ? pointerDown.event : null;
16
+ },
17
+ write: (event: unknown) => {
18
+ latestPointerDown = createPointerDownSnapshot(event);
19
+ },
20
+ };
21
+ }
22
+
23
+ /*** Match only the same browser pointer so unrelated renderer events cannot inherit modifiers. */
24
+ function matchesPointerActivation(
25
+ pointerDown: GraphPointerDownSnapshot,
26
+ rendererEvent: unknown,
27
+ ): boolean {
28
+ return readRendererPointerId(rendererEvent) === pointerDown.pointerId;
29
+ }
30
+
31
+ /*** Retain a browser pointer event only when it provides a stable pointer identity. */
32
+ function createPointerDownSnapshot(event: unknown): GraphPointerDownSnapshot | null {
33
+ if (!isRecord(event) || typeof event.pointerId !== 'number') return null;
34
+ return { event, pointerId: event.pointerId };
35
+ }
36
+
37
+ /*** Read Cytoscape's underlying browser event without trusting programmatic event shapes. */
38
+ function readRendererPointerId(value: unknown): number | null {
39
+ if (!isRecord(value)) return null;
40
+ const { originalEvent } = value;
41
+ if (!isRecord(originalEvent) || typeof originalEvent.pointerId !== 'number') return null;
42
+ return originalEvent.pointerId;
43
+ }
44
+
45
+ interface GraphPointerDownSnapshot {
46
+ readonly event: unknown;
47
+ readonly pointerId: number;
48
+ }
@@ -328,9 +328,12 @@ test('forwards semantic selection intent from rich-node press events', async ()
328
328
 
329
329
  test('settles the pending initial layout when presentation changes before readiness', async () => {
330
330
  const ready = Promise.withResolvers<GraphViewController>();
331
- const calls = { ready: 0, sort: 0 };
331
+ const calls = { completed: 0, ready: 0, sort: 0 };
332
332
  const runtime = createGraphRuntime(undefined, {
333
333
  current: {
334
+ onLayoutComplete: () => {
335
+ calls.completed += 1;
336
+ },
334
337
  onReady: (controller) => {
335
338
  calls.ready += 1;
336
339
  ready.resolve(controller);
@@ -351,11 +354,11 @@ test('settles the pending initial layout when presentation changes before readin
351
354
  };
352
355
  try {
353
356
  runtime.update(input);
354
- const sortCount = calls.sort;
355
357
  runtime.update({ ...input, nodes: [{ id: 'a', classes: 'hovered' }, { id: 'b' }] });
356
358
  await ready.promise;
357
359
  expect(calls.ready).toBe(1);
358
- expect(calls.sort).toBe(sortCount);
360
+ expect(calls.completed).toBe(1);
361
+ expect(calls.sort).toBeGreaterThan(0);
359
362
  } finally {
360
363
  runtime.destroy();
361
364
  }
@@ -363,8 +366,15 @@ test('settles the pending initial layout when presentation changes before readin
363
366
 
364
367
  test('lays out 0 → 1 → 5 topology updates before preserve-positions becomes active', async () => {
365
368
  const ready = Promise.withResolvers<GraphViewController>();
366
- const calls = { sort: 0 };
367
- const runtime = createGraphRuntime(undefined, { current: { onReady: ready.resolve } });
369
+ const calls = { completed: 0, sort: 0 };
370
+ const runtime = createGraphRuntime(undefined, {
371
+ current: {
372
+ onLayoutComplete: () => {
373
+ calls.completed += 1;
374
+ },
375
+ onReady: ready.resolve,
376
+ },
377
+ });
368
378
  const layoutOptions = {
369
379
  sort: () => {
370
380
  calls.sort += 1;
@@ -385,7 +395,7 @@ test('lays out 0 → 1 → 5 topology updates before preserve-positions becomes
385
395
  runtime.update({ ...input, nodes: fiveNodes });
386
396
  const controller = await ready.promise;
387
397
 
388
- expect(calls.sort).toBeGreaterThan(0);
398
+ expect(calls.completed).toBe(1);
389
399
  expect(controller.measureNodes?.(fiveNodes.map((node) => node.id))?.nodes).toHaveLength(5);
390
400
  } finally {
391
401
  runtime.destroy();
@@ -54,6 +54,7 @@ interface GraphRuntimeState {
54
54
  readonly generationRef: { current: number };
55
55
  readonly geometryRef: { current: string | null };
56
56
  readonly hoveredNodeIds: Set<string>;
57
+ readonly initialLayoutScheduledRef: { current: boolean };
57
58
  readonly latestUpdateRef: { current: GraphRuntimeUpdate | null };
58
59
  readonly layoutRef: { current: ReturnType<typeof runGraphLayout> | null };
59
60
  readonly layoutRunningRef: { current: boolean };
@@ -74,6 +75,7 @@ interface GraphRuntimeState {
74
75
  export function createGraphRuntime(
75
76
  container: GraphContainer,
76
77
  callbacksRef: { current: GraphViewCallbacks },
78
+ readLatestPointerDown: (event: unknown) => unknown = () => null,
77
79
  ): GraphRuntime {
78
80
  const cy = cytoscape({
79
81
  container,
@@ -83,7 +85,7 @@ export function createGraphRuntime(
83
85
  selectionType: 'additive',
84
86
  userPanningEnabled: true,
85
87
  });
86
- const state = createRuntimeState(cy, container, callbacksRef);
88
+ const state = createRuntimeState(cy, container, callbacksRef, readLatestPointerDown);
87
89
 
88
90
  return {
89
91
  destroy: () => destroyRuntime(state),
@@ -101,6 +103,7 @@ function createRuntimeState(
101
103
  cy: Core,
102
104
  container: GraphContainer,
103
105
  callbacksRef: { current: GraphViewCallbacks },
106
+ readLatestPointerDown: (event: unknown) => unknown,
104
107
  ): GraphRuntimeState {
105
108
  const fitPaddingRef = { current: 50 };
106
109
  const viewport = createGraphController(cy, fitPaddingRef, (options) =>
@@ -121,6 +124,7 @@ function createRuntimeState(
121
124
  generationRef: { current: 0 },
122
125
  geometryRef: { current: null as string | null },
123
126
  hoveredNodeIds: new Set<string>(),
127
+ initialLayoutScheduledRef: { current: false },
124
128
  latestUpdateRef: { current: null as GraphRuntimeUpdate | null },
125
129
  layoutRef: { current: null as ReturnType<typeof runGraphLayout> | null },
126
130
  layoutRunningRef,
@@ -134,8 +138,12 @@ function createRuntimeState(
134
138
  relayoutScheduledRef: { current: false },
135
139
  renderedNodeListeners,
136
140
  };
137
- const unbindEvents = bindGraphEvents(cy, callbacksRef, controller, () =>
138
- emitRenderedNodes(stateBase),
141
+ const unbindEvents = bindGraphEvents(
142
+ cy,
143
+ callbacksRef,
144
+ controller,
145
+ () => emitRenderedNodes(stateBase),
146
+ readLatestPointerDown,
139
147
  );
140
148
  const resizeObserver = createGraphResizeObserver({
141
149
  container,
@@ -253,6 +261,29 @@ function getRetainedNodeIds(
253
261
 
254
262
  /*** Start a generation-safe layout whose completion is the only normal automatic fit trigger. */
255
263
  function startCurrentLayout(state: GraphRuntimeState, input: GraphRuntimeUpdate) {
264
+ if (!state.readyRef.current) {
265
+ scheduleInitialLayout(state);
266
+ return;
267
+ }
268
+ startGraphLayout(state, input);
269
+ }
270
+
271
+ /*** Coalesce progressive pre-ready topology updates before the initial layout can complete. */
272
+ function scheduleInitialLayout(state: GraphRuntimeState) {
273
+ if (state.initialLayoutScheduledRef.current) return;
274
+ state.initialLayoutScheduledRef.current = true;
275
+ scheduleGraphFrame(() => {
276
+ scheduleGraphFrame(() => {
277
+ state.initialLayoutScheduledRef.current = false;
278
+ const input = state.latestUpdateRef.current;
279
+ if (input === null || state.cy.destroyed() || state.readyRef.current) return;
280
+ startGraphLayout(state, input);
281
+ });
282
+ });
283
+ }
284
+
285
+ /*** Start one layout generation after its input has reached the runtime owner. */
286
+ function startGraphLayout(state: GraphRuntimeState, input: GraphRuntimeUpdate) {
256
287
  state.pendingInitialFitRef.current = false;
257
288
  const generation = state.generationRef.current + 1;
258
289
  state.generationRef.current = generation;
@@ -12,6 +12,7 @@ describe('resolveSelectionEventIntent', () => {
12
12
  expect(resolveSelectionEventIntent({ nativeEvent: { ctrlKey: true } }, 'pointer')).toBe(
13
13
  'toggle',
14
14
  );
15
+ expect(resolveSelectionEventIntent({}, 'pointer', { ctrlKey: true })).toBe('toggle');
15
16
  });
16
17
 
17
18
  test('toggles pointer events reported as touch', () => {
@@ -11,18 +11,32 @@ import type { SelectionIntent } from '@ankhorage/utility/selection';
11
11
  export function resolveSelectionEventIntent(
12
12
  event: unknown,
13
13
  fallbackKind: SelectionActivationKind,
14
+ nativeEvent: unknown = {},
14
15
  ): SelectionIntent {
15
16
  const source = readEventSource(event);
16
17
  const kind: SelectionActivationKind = isTouchActivation(source) ? 'touch' : fallbackKind;
17
18
  const sourceModifiers = readInteractionModifiers(source);
18
19
  const wrapperModifiers = readInteractionModifiers(event);
20
+ const nativeModifiers = readInteractionModifiers(nativeEvent);
19
21
  const input: SelectionInteractionInput = {
20
22
  kind,
21
23
  modifiers: {
22
- altKey: sourceModifiers.altKey === true || wrapperModifiers.altKey === true,
23
- ctrlKey: sourceModifiers.ctrlKey === true || wrapperModifiers.ctrlKey === true,
24
- metaKey: sourceModifiers.metaKey === true || wrapperModifiers.metaKey === true,
25
- shiftKey: sourceModifiers.shiftKey === true || wrapperModifiers.shiftKey === true,
24
+ altKey:
25
+ sourceModifiers.altKey === true ||
26
+ wrapperModifiers.altKey === true ||
27
+ nativeModifiers.altKey === true,
28
+ ctrlKey:
29
+ sourceModifiers.ctrlKey === true ||
30
+ wrapperModifiers.ctrlKey === true ||
31
+ nativeModifiers.ctrlKey === true,
32
+ metaKey:
33
+ sourceModifiers.metaKey === true ||
34
+ wrapperModifiers.metaKey === true ||
35
+ nativeModifiers.metaKey === true,
36
+ shiftKey:
37
+ sourceModifiers.shiftKey === true ||
38
+ wrapperModifiers.shiftKey === true ||
39
+ nativeModifiers.shiftKey === true,
26
40
  },
27
41
  };
28
42
  return resolveSelectionIntent(input);
@@ -23600,18 +23600,19 @@ function resolveSelectionIntent(input) {
23600
23600
  return input.modifiers?.metaKey === true || input.modifiers?.ctrlKey === true ? "toggle" : "replace";
23601
23601
  }
23602
23602
  // src/features/selection/application/resolveSelectionEventIntent.ts
23603
- function resolveSelectionEventIntent(event, fallbackKind) {
23603
+ function resolveSelectionEventIntent(event, fallbackKind, nativeEvent = {}) {
23604
23604
  const source = readEventSource(event);
23605
23605
  const kind = isTouchActivation(source) ? "touch" : fallbackKind;
23606
23606
  const sourceModifiers = readInteractionModifiers(source);
23607
23607
  const wrapperModifiers = readInteractionModifiers(event);
23608
+ const nativeModifiers = readInteractionModifiers(nativeEvent);
23608
23609
  const input = {
23609
23610
  kind,
23610
23611
  modifiers: {
23611
- altKey: sourceModifiers.altKey === true || wrapperModifiers.altKey === true,
23612
- ctrlKey: sourceModifiers.ctrlKey === true || wrapperModifiers.ctrlKey === true,
23613
- metaKey: sourceModifiers.metaKey === true || wrapperModifiers.metaKey === true,
23614
- shiftKey: sourceModifiers.shiftKey === true || wrapperModifiers.shiftKey === true
23612
+ altKey: sourceModifiers.altKey === true || wrapperModifiers.altKey === true || nativeModifiers.altKey === true,
23613
+ ctrlKey: sourceModifiers.ctrlKey === true || wrapperModifiers.ctrlKey === true || nativeModifiers.ctrlKey === true,
23614
+ metaKey: sourceModifiers.metaKey === true || wrapperModifiers.metaKey === true || nativeModifiers.metaKey === true,
23615
+ shiftKey: sourceModifiers.shiftKey === true || wrapperModifiers.shiftKey === true || nativeModifiers.shiftKey === true
23615
23616
  }
23616
23617
  };
23617
23618
  return resolveSelectionIntent(input);
@@ -9,18 +9,19 @@ function resolveSelectionIntent(input) {
9
9
  return input.modifiers?.metaKey === true || input.modifiers?.ctrlKey === true ? "toggle" : "replace";
10
10
  }
11
11
  // src/features/selection/application/resolveSelectionEventIntent.ts
12
- function resolveSelectionEventIntent(event, fallbackKind) {
12
+ function resolveSelectionEventIntent(event, fallbackKind, nativeEvent = {}) {
13
13
  const source = readEventSource(event);
14
14
  const kind = isTouchActivation(source) ? "touch" : fallbackKind;
15
15
  const sourceModifiers = readInteractionModifiers(source);
16
16
  const wrapperModifiers = readInteractionModifiers(event);
17
+ const nativeModifiers = readInteractionModifiers(nativeEvent);
17
18
  const input = {
18
19
  kind,
19
20
  modifiers: {
20
- altKey: sourceModifiers.altKey === true || wrapperModifiers.altKey === true,
21
- ctrlKey: sourceModifiers.ctrlKey === true || wrapperModifiers.ctrlKey === true,
22
- metaKey: sourceModifiers.metaKey === true || wrapperModifiers.metaKey === true,
23
- shiftKey: sourceModifiers.shiftKey === true || wrapperModifiers.shiftKey === true
21
+ altKey: sourceModifiers.altKey === true || wrapperModifiers.altKey === true || nativeModifiers.altKey === true,
22
+ ctrlKey: sourceModifiers.ctrlKey === true || wrapperModifiers.ctrlKey === true || nativeModifiers.ctrlKey === true,
23
+ metaKey: sourceModifiers.metaKey === true || wrapperModifiers.metaKey === true || nativeModifiers.metaKey === true,
24
+ shiftKey: sourceModifiers.shiftKey === true || wrapperModifiers.shiftKey === true || nativeModifiers.shiftKey === true
24
25
  }
25
26
  };
26
27
  return resolveSelectionIntent(input);
@@ -14,7 +14,7 @@ import {
14
14
  } from "./Accordion-mrhkw8n6.js";
15
15
  import {
16
16
  resolveSelectionEventIntent
17
- } from "./Accordion-md1g54wg.js";
17
+ } from "./Accordion-eq27a9ms.js";
18
18
  import {
19
19
  applySelectionIntent
20
20
  } from "./Accordion-n4et7etk.js";