@statelyai/flow-dom 3.4.6 → 3.5.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.
@@ -1,5 +1,11 @@
1
1
  import { EdgePathData, FlowColorMode, FlowController, FlowEngine, FlowEntityChangeNotifierOptions, FlowInputEffects, FlowInputEvent, FlowResult, FlowStore, FlowStoreContext, Point, Rect } from "@statelyai/flow";
2
2
  export * from "@statelyai/flow";
3
+ //#region src/appearance-bounds.d.ts
4
+ /** Observe one appearance-local connection border without changing visual bounds. */
5
+ declare function observeAppearanceBounds(store: FlowStore, wrapper: Element, key: string, observer: MeasurementObserver, options?: {
6
+ selector?: string;
7
+ }): () => void;
8
+ //#endregion
3
9
  //#region src/clipboard.d.ts
4
10
  declare const FLOW_CONTENT_MIME = "application/vnd.stately.flow+json";
5
11
  type ClipboardTransport = {
@@ -177,6 +183,9 @@ type ResolvedFlowColorMode = 'light' | 'dark';
177
183
  declare function resolveFlowColorMode(colorMode: FlowColorMode, targetWindow?: Pick<Window, 'matchMedia'> | undefined): ResolvedFlowColorMode;
178
184
  declare function applyFlowColorMode(element: HTMLElement, colorMode: FlowColorMode, targetWindow?: Pick<Window, 'matchMedia'> | undefined): ResolvedFlowColorMode;
179
185
  type MeasurementTarget = {
186
+ appearanceId: string;
187
+ relativeTo: Element;
188
+ } | {
180
189
  nodeId: string;
181
190
  } | {
182
191
  nodeId: string;
@@ -240,4 +249,4 @@ type AttachInputOptions = {
240
249
  };
241
250
  declare function attachInput(options: AttachInputOptions): () => void;
242
251
  //#endregion
243
- export { AttachInputOptions, type ClipboardTransport, type ComputeRenderableIdsOptions, type EntityBoundsTarget, type EntityEdgeTarget, type EntityGeometryObserver, type EntityGeometryObserverOptions, type EntityRectTarget, FLOW_CONTENT_MIME, type FlowClipboard, type FlowImageExportOptions, type FlowImageExportResult, type FlowView, MeasurementObserver, MeasurementObserverOptions, MeasurementTarget, type NodePositionStyle, type RenderableIds, ResolvedFlowColorMode, type ViewportStyle, ViewportTransformOptions, applyFlowColorMode, attachContainer, attachInput, attachViewportTransform, canvasToClient, clientToCanvas, computeRenderableIds, createEntityGeometryObserver, createFlowClipboard, createFlowView, createMeasurementObserver, exportFlowImage, getAttachedContainer, nodePositionStyle, renderableIdsEqual, resolveFlowColorMode, viewportStyle };
252
+ export { AttachInputOptions, type ClipboardTransport, type ComputeRenderableIdsOptions, type EntityBoundsTarget, type EntityEdgeTarget, type EntityGeometryObserver, type EntityGeometryObserverOptions, type EntityRectTarget, FLOW_CONTENT_MIME, type FlowClipboard, type FlowImageExportOptions, type FlowImageExportResult, type FlowView, MeasurementObserver, MeasurementObserverOptions, MeasurementTarget, type NodePositionStyle, type RenderableIds, ResolvedFlowColorMode, type ViewportStyle, ViewportTransformOptions, applyFlowColorMode, attachContainer, attachInput, attachViewportTransform, canvasToClient, clientToCanvas, computeRenderableIds, createEntityGeometryObserver, createFlowClipboard, createFlowView, createMeasurementObserver, exportFlowImage, getAttachedContainer, nodePositionStyle, observeAppearanceBounds, renderableIdsEqual, resolveFlowColorMode, viewportStyle };
package/dist/esm/index.js CHANGED
@@ -1,5 +1,69 @@
1
1
  import { createEntityChangeNotifier, pathToSVG } from "@statelyai/flow";
2
2
  export * from "@statelyai/flow";
3
+ //#region src/appearance-bounds.ts
4
+ /** Observe one appearance-local connection border without changing visual bounds. */
5
+ function observeAppearanceBounds(store, wrapper, key, observer, options = {}) {
6
+ let boundary = null;
7
+ const clear = () => {
8
+ if (boundary) observer.unobserve(boundary);
9
+ boundary = null;
10
+ if (store.getSnapshot().context.measurements.has(key)) store.trigger.removeMeasurements({ ids: [key] });
11
+ };
12
+ const refresh = () => {
13
+ let matches;
14
+ try {
15
+ matches = wrapper.querySelectorAll(options.selector ?? "[data-flow-connection-bounds]");
16
+ } catch {}
17
+ const next = matches?.length === 1 ? matches[0] : null;
18
+ if (!next || next !== boundary) {
19
+ clear();
20
+ boundary = next;
21
+ if (boundary) observer.observe(boundary, {
22
+ appearanceId: key,
23
+ relativeTo: wrapper
24
+ });
25
+ }
26
+ observer.measure(wrapper);
27
+ if (boundary) observer.measure(boundary);
28
+ };
29
+ const targetWindow = wrapper.ownerDocument.defaultView;
30
+ const resize = new ((targetWindow?.ResizeObserver) ?? ResizeObserver)(refresh);
31
+ resize.observe(wrapper);
32
+ const style = wrapper.ownerDocument.createElement("div").style;
33
+ const layoutStyle = () => {
34
+ style.cssText = wrapper.getAttribute("style") ?? "";
35
+ return JSON.stringify(Array.from(style).sort().filter((property) => {
36
+ if (property === "will-change") return false;
37
+ return property !== "transform" || !/^translate\([^)]*\)$/.test(style.getPropertyValue(property));
38
+ }).map((property) => [
39
+ property,
40
+ style.getPropertyValue(property),
41
+ style.getPropertyPriority(property)
42
+ ]));
43
+ };
44
+ let previousStyle = layoutStyle();
45
+ const mutations = new ((targetWindow?.MutationObserver) ?? MutationObserver)((records) => {
46
+ const currentStyle = layoutStyle();
47
+ const layoutChanged = currentStyle !== previousStyle;
48
+ previousStyle = currentStyle;
49
+ if (layoutChanged || records.some((record) => record.type !== "attributes" || record.target !== wrapper || record.attributeName !== "style")) refresh();
50
+ });
51
+ mutations.observe(wrapper, {
52
+ subtree: true,
53
+ childList: true,
54
+ attributes: true,
55
+ characterData: true
56
+ });
57
+ wrapper.addEventListener("load", refresh, true);
58
+ refresh();
59
+ return () => {
60
+ resize.disconnect();
61
+ mutations.disconnect();
62
+ wrapper.removeEventListener("load", refresh, true);
63
+ clear();
64
+ };
65
+ }
66
+ //#endregion
3
67
  //#region src/clipboard.ts
4
68
  const FLOW_CONTENT_MIME = "application/vnd.stately.flow+json";
5
69
  function createFlowClipboard(flow, options = {}) {
@@ -491,13 +555,14 @@ function createMeasurementObserver(store, options = {}) {
491
555
  const zoom = viewport.zoom || 1;
492
556
  const rect = element.getBoundingClientRect();
493
557
  const containerRect = (getContainer(options.container) ?? containers.get(store))?.getBoundingClientRect();
558
+ const relativeRect = "relativeTo" in target ? target.relativeTo.getBoundingClientRect() : void 0;
494
559
  const measurement = {
495
- x: (rect.left - (containerRect?.left ?? 0) - viewport.x) / zoom,
496
- y: (rect.top - (containerRect?.top ?? 0) - viewport.y) / zoom,
560
+ x: (rect.left - (relativeRect?.left ?? (containerRect?.left ?? 0) + viewport.x)) / zoom,
561
+ y: (rect.top - (relativeRect?.top ?? (containerRect?.top ?? 0) + viewport.y)) / zoom,
497
562
  width: layoutSize ? layoutSize.width : rect.width / zoom,
498
563
  height: layoutSize ? layoutSize.height : rect.height / zoom
499
564
  };
500
- const id = "portName" in target ? `${target.nodeId}:${target.portName}` : "nodeId" in target ? target.nodeId : target.edgeId;
565
+ const id = "appearanceId" in target ? target.appearanceId : "portName" in target ? `${target.nodeId}:${target.portName}` : "nodeId" in target ? target.nodeId : target.edgeId;
501
566
  const existing = store.getSnapshot().context.measurements.get(id);
502
567
  if (existing && Math.abs(existing.x - measurement.x) < equalityThreshold && Math.abs(existing.y - measurement.y) < equalityThreshold && Math.abs(existing.width - measurement.width) < equalityThreshold && Math.abs(existing.height - measurement.height) < equalityThreshold) return;
503
568
  pendingMeasurements.push({
@@ -544,12 +609,14 @@ function createMeasurementObserver(store, options = {}) {
544
609
  refresh(targets) {
545
610
  const requested = targets ? new Set(targets) : null;
546
611
  for (const [element, target] of elementMap) {
547
- const id = "portName" in target ? `${target.nodeId}:${target.portName}` : "nodeId" in target ? target.nodeId : target.edgeId;
612
+ const id = "appearanceId" in target ? target.appearanceId : "portName" in target ? `${target.nodeId}:${target.portName}` : "nodeId" in target ? target.nodeId : target.edgeId;
548
613
  if (requested && !requested.has(element) && !requested.has(id)) continue;
549
614
  pushMeasurement(element, target);
550
615
  }
551
616
  },
552
617
  unobserve(element) {
618
+ const target = elementMap.get(element);
619
+ if (target && "appearanceId" in target) pendingMeasurements = pendingMeasurements.filter(({ id }) => id !== target.appearanceId);
553
620
  elementMap.delete(element);
554
621
  observer?.unobserve(element);
555
622
  },
@@ -599,11 +666,24 @@ function attachContainer(store, element, options = {}) {
599
666
  preserveCenter: options.preserveViewportCenter
600
667
  });
601
668
  };
669
+ const onScroll = (event) => {
670
+ if (event.target !== element) return;
671
+ const { scrollLeft, scrollTop } = element;
672
+ if (!scrollLeft && !scrollTop) return;
673
+ element.scrollLeft = 0;
674
+ element.scrollTop = 0;
675
+ store.trigger.panBy({
676
+ x: -scrollLeft,
677
+ y: -scrollTop
678
+ });
679
+ };
680
+ element.addEventListener("scroll", onScroll);
602
681
  update();
603
682
  const observer = new ((element.ownerDocument.defaultView?.ResizeObserver) ?? ResizeObserver)(update);
604
683
  observer.observe(element);
605
684
  return () => {
606
685
  if (containers.get(store) === element) containers.delete(store);
686
+ element.removeEventListener("scroll", onScroll);
607
687
  observer.disconnect();
608
688
  };
609
689
  }
@@ -1052,4 +1132,4 @@ function attachInput(options) {
1052
1132
  };
1053
1133
  }
1054
1134
  //#endregion
1055
- export { FLOW_CONTENT_MIME, applyFlowColorMode, attachContainer, attachInput, attachViewportTransform, canvasToClient, clientToCanvas, computeRenderableIds, createEntityGeometryObserver, createFlowClipboard, createFlowView, createMeasurementObserver, exportFlowImage, getAttachedContainer, nodePositionStyle, renderableIdsEqual, resolveFlowColorMode, viewportStyle };
1135
+ export { FLOW_CONTENT_MIME, applyFlowColorMode, attachContainer, attachInput, attachViewportTransform, canvasToClient, clientToCanvas, computeRenderableIds, createEntityGeometryObserver, createFlowClipboard, createFlowView, createMeasurementObserver, exportFlowImage, getAttachedContainer, nodePositionStyle, observeAppearanceBounds, renderableIdsEqual, resolveFlowColorMode, viewportStyle };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@statelyai/flow-dom",
3
- "version": "3.4.6",
3
+ "version": "3.5.0",
4
4
  "description": "DOM-specific helpers for @statelyai/flow with core re-exports.",
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -27,7 +27,7 @@
27
27
  },
28
28
  "license": "MIT",
29
29
  "dependencies": {
30
- "@statelyai/flow": "0.11.0"
30
+ "@statelyai/flow": "0.12.0"
31
31
  },
32
32
  "devDependencies": {
33
33
  "@vitest/coverage-v8": "^4.1.0",