@multiplatform.one/node-graph 11.3.2 → 11.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/react-flow/NodeGraphWeb.cjs +11 -4
- package/dist/cjs/react-flow/NodeGraphWeb.native.cjs +13 -4
- package/dist/cjs/react-flow/NodeGraphWeb.native.js +13 -4
- package/dist/cjs/react-flow/NodeGraphWeb.native.js.map +1 -1
- package/dist/esm/react-flow/NodeGraphWeb.mjs +11 -4
- package/dist/esm/react-flow/NodeGraphWeb.mjs.map +1 -1
- package/dist/esm/react-flow/NodeGraphWeb.native.js +13 -4
- package/dist/esm/react-flow/NodeGraphWeb.native.js.map +1 -1
- package/dist/jsx/react-flow/NodeGraphWeb.mjs +11 -4
- package/dist/jsx/react-flow/NodeGraphWeb.mjs.map +1 -1
- package/dist/jsx/react-flow/NodeGraphWeb.native.cjs +13 -4
- package/dist/jsx/react-flow/NodeGraphWeb.native.js +13 -4
- package/dist/jsx/react-flow/NodeGraphWeb.native.js.map +1 -1
- package/package.json +6 -6
- package/src/layout/AutoLayout.stories.tsx +9 -0
- package/src/react-flow/NodeGraphWeb.fit.spec.tsx +92 -0
- package/src/react-flow/NodeGraphWeb.tsx +9 -7
- package/types/react-flow/NodeGraphWeb.d.ts.map +1 -1
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* FZ-12131: a canvas says when its measured fit has landed.
|
|
3
|
+
*
|
|
4
|
+
* `NodeGraph/AutoLayout → Large200` is fitted twice on mount, once by React
|
|
5
|
+
* Flow on the seeded node boxes and once by `FitOnFirstMeasure` on the
|
|
6
|
+
* measured ones. A screenshot has to wait for the second, so the canvas root
|
|
7
|
+
* carries `data-graph-fitted` from the moment that fit resolves. happy-dom
|
|
8
|
+
* measures nothing, so these specs write the measurements into React Flow's
|
|
9
|
+
* store themselves.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { Preset, Surface } from "@multiplatform.one/theme";
|
|
13
|
+
import { renderWithProviders } from "@multiplatform.one/test-utils";
|
|
14
|
+
import { act, cleanup, waitFor } from "@testing-library/react";
|
|
15
|
+
import { useEffect } from "react";
|
|
16
|
+
import { afterEach, describe, expect, it } from "vitest";
|
|
17
|
+
import { demoGraphSchema } from "./demoNodeBody";
|
|
18
|
+
import { demoDocumentLarge } from "./fixtures";
|
|
19
|
+
import { resetNodeCensus } from "./nodeCensus";
|
|
20
|
+
import { NodeGraphWeb } from "./NodeGraphWeb";
|
|
21
|
+
import { useStoreApi } from "./xy";
|
|
22
|
+
|
|
23
|
+
afterEach(() => {
|
|
24
|
+
cleanup();
|
|
25
|
+
resetNodeCensus();
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
type Store = ReturnType<typeof useStoreApi>;
|
|
29
|
+
|
|
30
|
+
function StoreProbe({ onStore }: { onStore: (store: Store) => void }) {
|
|
31
|
+
const store = useStoreApi();
|
|
32
|
+
useEffect(() => {
|
|
33
|
+
onStore(store);
|
|
34
|
+
}, [onStore, store]);
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function mountCanvas(fitView?: boolean) {
|
|
39
|
+
let store: Store | undefined;
|
|
40
|
+
const { container } = renderWithProviders(
|
|
41
|
+
<Preset cascade={false}>
|
|
42
|
+
<Surface size="4">
|
|
43
|
+
<NodeGraphWeb
|
|
44
|
+
schema={demoGraphSchema()}
|
|
45
|
+
defaultDocument={demoDocumentLarge(12)}
|
|
46
|
+
fitView={fitView}
|
|
47
|
+
>
|
|
48
|
+
<StoreProbe onStore={(found) => (store = found)} />
|
|
49
|
+
</NodeGraphWeb>
|
|
50
|
+
</Surface>
|
|
51
|
+
</Preset>,
|
|
52
|
+
);
|
|
53
|
+
if (!store) throw new Error("the probe never saw React Flow's store");
|
|
54
|
+
return { container, store };
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function measure(store: Store, count: number) {
|
|
58
|
+
act(() => {
|
|
59
|
+
const lookup = new Map(store.getState().nodeLookup);
|
|
60
|
+
let left = count;
|
|
61
|
+
for (const [id, node] of lookup) {
|
|
62
|
+
if (left-- <= 0) break;
|
|
63
|
+
lookup.set(id, { ...node, measured: { width: 160, height: 147 } });
|
|
64
|
+
}
|
|
65
|
+
store.setState({ nodeLookup: lookup });
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const fitted = (container: HTMLElement) => container.querySelector("[data-graph-fitted]");
|
|
70
|
+
|
|
71
|
+
describe("data-graph-fitted", () => {
|
|
72
|
+
it("is absent while any node is unmeasured", async () => {
|
|
73
|
+
const { container, store } = mountCanvas();
|
|
74
|
+
measure(store, 11);
|
|
75
|
+
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
76
|
+
expect(fitted(container)).toBeNull();
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it("appears once the fit on the measured nodes has landed", async () => {
|
|
80
|
+
const { container, store } = mountCanvas();
|
|
81
|
+
expect(fitted(container)).toBeNull();
|
|
82
|
+
measure(store, 12);
|
|
83
|
+
await waitFor(() => expect(fitted(container)).not.toBeNull());
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
it("never appears on a canvas that does not fit", async () => {
|
|
87
|
+
const { container, store } = mountCanvas(false);
|
|
88
|
+
measure(store, 12);
|
|
89
|
+
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
90
|
+
expect(fitted(container)).toBeNull();
|
|
91
|
+
});
|
|
92
|
+
});
|
|
@@ -121,11 +121,10 @@ export const graphCanvasDefaults = {
|
|
|
121
121
|
* fitting are both right; what was missing is that fitting has to happen after
|
|
122
122
|
* the correction, once.
|
|
123
123
|
*
|
|
124
|
-
*
|
|
125
|
-
*
|
|
126
|
-
* browser found, and it is checked there.
|
|
124
|
+
* happy-dom measures nothing, so `NodeGraphWeb.fit.spec.tsx` writes the
|
|
125
|
+
* measurements into React Flow's store itself.
|
|
127
126
|
*/
|
|
128
|
-
function FitOnFirstMeasure({ enabled }: { enabled: boolean }) {
|
|
127
|
+
function FitOnFirstMeasure({ enabled, onFitted }: { enabled: boolean; onFitted: () => void }) {
|
|
129
128
|
const { fitView } = useReactFlow();
|
|
130
129
|
const allMeasured = useStore((state) => {
|
|
131
130
|
let total = 0;
|
|
@@ -140,8 +139,8 @@ function FitOnFirstMeasure({ enabled }: { enabled: boolean }) {
|
|
|
140
139
|
useEffect(() => {
|
|
141
140
|
if (!enabled || fitted.current || !allMeasured) return;
|
|
142
141
|
fitted.current = true;
|
|
143
|
-
void fitView();
|
|
144
|
-
}, [enabled, allMeasured, fitView]);
|
|
142
|
+
void fitView().then(onFitted);
|
|
143
|
+
}, [enabled, allMeasured, fitView, onFitted]);
|
|
145
144
|
return null;
|
|
146
145
|
}
|
|
147
146
|
|
|
@@ -413,6 +412,8 @@ function NodeGraphCanvas<N extends NodeKindDefs, E extends EdgeKindDefs>(
|
|
|
413
412
|
// to keep.
|
|
414
413
|
const snapSession = useRef(createSnapSession());
|
|
415
414
|
const [guides, setGuides] = useState<readonly SnapGuide[]>([]);
|
|
415
|
+
const [fitted, setFitted] = useState(false);
|
|
416
|
+
const markFitted = useCallback(() => setFitted(true), []);
|
|
416
417
|
const snapOptions = snapContextOptions({
|
|
417
418
|
snapping,
|
|
418
419
|
animation: envelope.knobs.animation as string | undefined,
|
|
@@ -567,6 +568,7 @@ function NodeGraphCanvas<N extends NodeKindDefs, E extends EdgeKindDefs>(
|
|
|
567
568
|
ref={rootRef}
|
|
568
569
|
className={className ? `${graphRootClassName} ${className}` : graphRootClassName}
|
|
569
570
|
data-graph-scheme={envelope.scheme}
|
|
571
|
+
data-graph-fitted={fitted ? "" : undefined}
|
|
570
572
|
style={{ width: "100%", height: "100%", ...style }}
|
|
571
573
|
>
|
|
572
574
|
<GraphVars vars={envelope.vars} scheme={envelope.scheme} revision={envelope.revision} />
|
|
@@ -596,7 +598,7 @@ function NodeGraphCanvas<N extends NodeKindDefs, E extends EdgeKindDefs>(
|
|
|
596
598
|
elementsSelectable
|
|
597
599
|
proOptions={{ hideAttribution: true }}
|
|
598
600
|
>
|
|
599
|
-
<FitOnFirstMeasure enabled={fitView} />
|
|
601
|
+
<FitOnFirstMeasure enabled={fitView} onFitted={markFitted} />
|
|
600
602
|
<GraphZoomVar rootRef={rootRef} />
|
|
601
603
|
<GraphPaintProbe onPaint={onPaint} />
|
|
602
604
|
<GraphCommandBridge
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NodeGraphWeb.d.ts","sourceRoot":"","sources":["../../src/react-flow/NodeGraphWeb.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,8BAA8B,CAAC;AACtC,OAAO,qBAAqB,CAAC;AAG7B,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,0BAA0B,CAAC;AACtD,OAAO,EACL,KAAK,aAAa,EAClB,KAAK,SAAS,EACd,KAAK,GAAG,EAOT,MAAM,OAAO,CAAC;AAOf,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAC;AAGvE,OAAO,KAAK,EAAE,oBAAoB,EAAyB,MAAM,+BAA+B,CAAC;AAMjG,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,KAAK,EACV,iBAAiB,EACjB,YAAY,EACZ,YAAY,EACZ,aAAa,EACb,WAAW,EAEX,YAAY,EAGb,MAAM,gBAAgB,CAAC;AAUxB,OAAO,KAAK,EAAE,gBAAgB,EAAiB,eAAe,EAAE,MAAM,eAAe,CAAC;AAItF,OAAO,KAAK,EAAc,SAAS,EAAE,MAAM,MAAM,CAAC;AAElD;;;;;;;;GAQG;AACH,eAAO,MAAM,mBAAmB;;;IAG9B,kEAAkE;;IAElE;;;;;;;;;;;;OAYG;;;CAGK,CAAC;
|
|
1
|
+
{"version":3,"file":"NodeGraphWeb.d.ts","sourceRoot":"","sources":["../../src/react-flow/NodeGraphWeb.tsx"],"names":[],"mappings":"AA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