@dxos/react-ui-graph 0.8.4-main.1da679c → 0.8.4-main.21d9917
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/lib/browser/chunk-LKC455GK.mjs +52 -0
- package/dist/lib/browser/chunk-LKC455GK.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +1113 -335
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +3 -3
- package/dist/lib/browser/testing/index.mjs.map +3 -3
- package/dist/lib/node-esm/chunk-JE4KZCUF.mjs +54 -0
- package/dist/lib/node-esm/chunk-JE4KZCUF.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +1113 -335
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/testing/index.mjs +3 -3
- package/dist/lib/node-esm/testing/index.mjs.map +3 -3
- package/dist/types/src/components/Graph/Graph.d.ts +4 -5
- package/dist/types/src/components/Graph/Graph.d.ts.map +1 -1
- package/dist/types/src/components/Graph/Graph.stories.d.ts +2 -2
- package/dist/types/src/components/Graph/Graph.stories.d.ts.map +1 -1
- package/dist/types/src/components/Mesh/Mesh.stories.d.ts +3 -1
- package/dist/types/src/components/Mesh/Mesh.stories.d.ts.map +1 -1
- package/dist/types/src/components/SVG/Root.d.ts +1 -1
- package/dist/types/src/components/SVG/SVG.d.ts +14 -17
- package/dist/types/src/components/SVG/SVG.d.ts.map +1 -1
- package/dist/types/src/components/SVG/Svg.stories.d.ts +3 -1
- package/dist/types/src/components/SVG/Svg.stories.d.ts.map +1 -1
- package/dist/types/src/fx/fx.stories.d.ts +3 -1
- package/dist/types/src/fx/fx.stories.d.ts.map +1 -1
- package/dist/types/src/graph/projector/graph-force-projector.d.ts +1 -1
- package/dist/types/src/graph/projector/graph-force-projector.d.ts.map +1 -1
- package/dist/types/src/graph/projector/graph-hierarchical-projector.d.ts +1 -1
- package/dist/types/src/graph/projector/graph-hierarchical-projector.d.ts.map +1 -1
- package/dist/types/src/graph/projector/graph-projector.d.ts +2 -2
- package/dist/types/src/graph/projector/graph-projector.d.ts.map +1 -1
- package/dist/types/src/graph/projector/graph-radial-projector.d.ts +1 -1
- package/dist/types/src/graph/projector/graph-radial-projector.d.ts.map +1 -1
- package/dist/types/src/graph/projector/graph-relational-projector.d.ts +1 -1
- package/dist/types/src/graph/projector/graph-relational-projector.d.ts.map +1 -1
- package/dist/types/src/graph/types.d.ts +1 -1
- package/dist/types/src/graph/types.d.ts.map +1 -1
- package/dist/types/src/stories/hooks.stories.d.ts +6 -3
- package/dist/types/src/stories/hooks.stories.d.ts.map +1 -1
- package/dist/types/src/testing/data.d.ts +4 -4
- package/dist/types/src/testing/data.d.ts.map +1 -1
- package/dist/types/src/testing/hooks.d.ts +2 -16
- package/dist/types/src/testing/hooks.d.ts.map +1 -1
- package/dist/types/src/testing/model.d.ts +4 -8
- package/dist/types/src/testing/model.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +31 -26
- package/src/components/Graph/Graph.stories.tsx +37 -34
- package/src/components/Graph/Graph.tsx +18 -11
- package/src/components/Mesh/Mesh.stories.tsx +5 -4
- package/src/components/SVG/Grid.tsx +1 -1
- package/src/components/SVG/Markers.tsx +1 -1
- package/src/components/SVG/Root.tsx +1 -1
- package/src/components/SVG/SVG.tsx +10 -1
- package/src/components/SVG/Svg.stories.tsx +5 -4
- package/src/fx/fx.stories.tsx +6 -5
- package/src/graph/projector/graph-force-projector.ts +1 -1
- package/src/graph/projector/graph-hierarchical-projector.ts +3 -3
- package/src/graph/projector/graph-projector.ts +2 -2
- package/src/graph/projector/graph-radial-projector.ts +1 -1
- package/src/graph/projector/graph-relational-projector.ts +3 -3
- package/src/graph/types.ts +1 -1
- package/src/hooks/useStateRef.ts +1 -1
- package/src/stories/hooks.stories.tsx +18 -11
- package/src/testing/data.ts +5 -5
- package/src/testing/hooks.ts +1 -1
- package/src/testing/model.ts +3 -3
- package/dist/lib/browser/chunk-PDEA4KBO.mjs +0 -966
- package/dist/lib/browser/chunk-PDEA4KBO.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-NJGJKPL7.mjs +0 -968
- package/dist/lib/node-esm/chunk-NJGJKPL7.mjs.map +0 -7
package/package.json
CHANGED
|
@@ -1,12 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/react-ui-graph",
|
|
3
|
-
"version": "0.8.4-main.
|
|
3
|
+
"version": "0.8.4-main.21d9917",
|
|
4
4
|
"description": "GEM Graph.",
|
|
5
5
|
"homepage": "https://dxos.org",
|
|
6
6
|
"bugs": "https://github.com/dxos/dxos/issues",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/dxos/dxos"
|
|
10
|
+
},
|
|
7
11
|
"license": "MIT",
|
|
8
12
|
"author": "DXOS.org",
|
|
9
|
-
"sideEffects":
|
|
13
|
+
"sideEffects": [
|
|
14
|
+
"*.css"
|
|
15
|
+
],
|
|
10
16
|
"type": "module",
|
|
11
17
|
"exports": {
|
|
12
18
|
".": {
|
|
@@ -37,8 +43,7 @@
|
|
|
37
43
|
"styles"
|
|
38
44
|
],
|
|
39
45
|
"dependencies": {
|
|
40
|
-
"@
|
|
41
|
-
"@preact/signals-core": "^1.9.0",
|
|
46
|
+
"@effect-atom/atom-react": "^0.4.6",
|
|
42
47
|
"d3": "^7.9.0",
|
|
43
48
|
"d3-force": "~3.0.0",
|
|
44
49
|
"immutability-helper": "^3.0.2",
|
|
@@ -46,40 +51,40 @@
|
|
|
46
51
|
"lodash.defaultsdeep": "^4.6.1",
|
|
47
52
|
"react-resize-detector": "^11.0.1",
|
|
48
53
|
"topojson-client": "^3.1.0",
|
|
49
|
-
"@dxos/async": "0.8.4-main.
|
|
50
|
-
"@dxos/debug": "0.8.4-main.
|
|
51
|
-
"@dxos/
|
|
52
|
-
"@dxos/
|
|
53
|
-
"@dxos/
|
|
54
|
-
"@dxos/
|
|
55
|
-
"@dxos/
|
|
54
|
+
"@dxos/async": "0.8.4-main.21d9917",
|
|
55
|
+
"@dxos/debug": "0.8.4-main.21d9917",
|
|
56
|
+
"@dxos/invariant": "0.8.4-main.21d9917",
|
|
57
|
+
"@dxos/node-std": "0.8.4-main.21d9917",
|
|
58
|
+
"@dxos/graph": "0.8.4-main.21d9917",
|
|
59
|
+
"@dxos/react-ui-mosaic": "0.8.4-main.21d9917",
|
|
60
|
+
"@dxos/log": "0.8.4-main.21d9917"
|
|
56
61
|
},
|
|
57
62
|
"devDependencies": {
|
|
58
63
|
"@babel/core": "^7.18.13",
|
|
59
64
|
"@types/d3": "^7.4.3",
|
|
60
65
|
"@types/lodash.defaultsdeep": "^4.6.6",
|
|
61
|
-
"@types/react": "~
|
|
62
|
-
"@types/react-dom": "~
|
|
66
|
+
"@types/react": "~19.2.7",
|
|
67
|
+
"@types/react-dom": "~19.2.3",
|
|
63
68
|
"@types/topojson-client": "^3.1.4",
|
|
64
69
|
"@types/topojson-specification": "^1.0.5",
|
|
65
70
|
"postcss": "^8.4.41",
|
|
66
|
-
"react": "~
|
|
67
|
-
"react-dom": "~
|
|
68
|
-
"@dxos/random": "0.8.4-main.
|
|
69
|
-
"@dxos/react-ui
|
|
70
|
-
"@dxos/react-ui": "0.8.4-main.
|
|
71
|
-
"@dxos/react-ui-
|
|
72
|
-
"@dxos/
|
|
73
|
-
"@dxos/storybook-utils": "0.8.4-main.
|
|
71
|
+
"react": "~19.2.3",
|
|
72
|
+
"react-dom": "~19.2.3",
|
|
73
|
+
"@dxos/random": "0.8.4-main.21d9917",
|
|
74
|
+
"@dxos/react-ui": "0.8.4-main.21d9917",
|
|
75
|
+
"@dxos/react-ui-stack": "0.8.4-main.21d9917",
|
|
76
|
+
"@dxos/react-ui-syntax-highlighter": "0.8.4-main.21d9917",
|
|
77
|
+
"@dxos/ui-theme": "0.8.4-main.21d9917",
|
|
78
|
+
"@dxos/storybook-utils": "0.8.4-main.21d9917"
|
|
74
79
|
},
|
|
75
80
|
"peerDependencies": {
|
|
76
|
-
"react": "~
|
|
77
|
-
"react-dom": "~
|
|
78
|
-
"@dxos/react-ui": "0.8.4-main.
|
|
79
|
-
"@dxos/
|
|
81
|
+
"react": "~19.2.3",
|
|
82
|
+
"react-dom": "~19.2.3",
|
|
83
|
+
"@dxos/react-ui": "0.8.4-main.21d9917",
|
|
84
|
+
"@dxos/ui-theme": "0.8.4-main.21d9917"
|
|
80
85
|
},
|
|
81
86
|
"optionalDependencies": {
|
|
82
|
-
"@dxos/random": "0.8.4-main.
|
|
87
|
+
"@dxos/random": "0.8.4-main.21d9917"
|
|
83
88
|
},
|
|
84
89
|
"publishConfig": {
|
|
85
90
|
"access": "public"
|
|
@@ -2,19 +2,18 @@
|
|
|
2
2
|
// Copyright 2022 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import '@
|
|
6
|
-
|
|
7
|
-
import { effect } from '@preact/signals-core';
|
|
5
|
+
import { RegistryContext } from '@effect-atom/atom-react';
|
|
8
6
|
import { type Meta, type StoryObj } from '@storybook/react-vite';
|
|
9
7
|
import { select } from 'd3';
|
|
10
|
-
import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
8
|
+
import React, { useCallback, useContext, useEffect, useMemo, useRef, useState } from 'react';
|
|
11
9
|
|
|
12
10
|
import { type Graph, type GraphModel, SelectionModel } from '@dxos/graph';
|
|
13
11
|
import { IconButton, Popover, Toolbar } from '@dxos/react-ui';
|
|
14
|
-
import {
|
|
12
|
+
import { withTheme } from '@dxos/react-ui/testing';
|
|
13
|
+
import { Card } from '@dxos/react-ui-mosaic';
|
|
15
14
|
import { JsonFilter, SyntaxHighlighter } from '@dxos/react-ui-syntax-highlighter';
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
15
|
+
import { withRegistry } from '@dxos/storybook-utils';
|
|
16
|
+
import { getHashStyles, mx } from '@dxos/ui-theme';
|
|
18
17
|
|
|
19
18
|
import { Pulsar } from '../../fx';
|
|
20
19
|
import {
|
|
@@ -56,7 +55,7 @@ type StoryProps = GraphProps & {
|
|
|
56
55
|
grid?: boolean | SVGGridProps;
|
|
57
56
|
inspect?: boolean;
|
|
58
57
|
singleSelect?: boolean;
|
|
59
|
-
graph: () => Graph;
|
|
58
|
+
graph: () => Graph.Any;
|
|
60
59
|
projectorType?: ProjectorType;
|
|
61
60
|
projectorOptions?:
|
|
62
61
|
| GraphForceProjectorOptions
|
|
@@ -77,9 +76,13 @@ const DefaultStory = ({
|
|
|
77
76
|
}: StoryProps) => {
|
|
78
77
|
const graphRef = useRef<GraphController | null>(null);
|
|
79
78
|
const context = useRef<SVGContext>(null);
|
|
79
|
+
const registry = useContext(RegistryContext);
|
|
80
80
|
|
|
81
81
|
// Models.
|
|
82
|
-
const [model, setModel] = useState<GraphModel | undefined>(() =>
|
|
82
|
+
const [model, setModel] = useState<GraphModel.GraphModel | undefined>(() => {
|
|
83
|
+
const graph = _graph?.();
|
|
84
|
+
return graph ? new TestGraphModel(registry, graph) : undefined;
|
|
85
|
+
});
|
|
83
86
|
const selection = useMemo(() => new SelectionModel(singleSelect), [singleSelect]);
|
|
84
87
|
|
|
85
88
|
// Projector.
|
|
@@ -157,8 +160,9 @@ const DefaultStory = ({
|
|
|
157
160
|
}, [model]);
|
|
158
161
|
|
|
159
162
|
const handleRegenerate = useCallback(() => {
|
|
160
|
-
|
|
161
|
-
|
|
163
|
+
const graph = _graph?.();
|
|
164
|
+
setModel(graph ? new TestGraphModel(registry, graph) : undefined);
|
|
165
|
+
}, [_graph, registry]);
|
|
162
166
|
|
|
163
167
|
const handleClear = useCallback(() => {
|
|
164
168
|
setModel(undefined);
|
|
@@ -182,7 +186,7 @@ const DefaultStory = ({
|
|
|
182
186
|
|
|
183
187
|
const active = useMemo(() => new SelectionModel(), []);
|
|
184
188
|
const handlePing = useCallback(() => {
|
|
185
|
-
for (const id of active.
|
|
189
|
+
for (const id of active.getSelectedIds()) {
|
|
186
190
|
const node = graphRef.current?.findNode(id);
|
|
187
191
|
if (node) {
|
|
188
192
|
Pulsar.remove(select(node));
|
|
@@ -190,7 +194,7 @@ const DefaultStory = ({
|
|
|
190
194
|
}
|
|
191
195
|
|
|
192
196
|
active.clear();
|
|
193
|
-
for (const id of selection.
|
|
197
|
+
for (const id of selection.getSelectedIds()) {
|
|
194
198
|
const node = graphRef.current?.findNode(id);
|
|
195
199
|
if (node) {
|
|
196
200
|
active.add(id);
|
|
@@ -202,7 +206,7 @@ const DefaultStory = ({
|
|
|
202
206
|
|
|
203
207
|
return (
|
|
204
208
|
<Popover.Root open={!!popover} onOpenChange={(state) => !state && setPopover(undefined)}>
|
|
205
|
-
<div className={mx('
|
|
209
|
+
<div className={mx('bs-full is-full grid divide-x divide-separator', debug && 'grid-cols-[1fr_30rem]')}>
|
|
206
210
|
<SVG.Root ref={context}>
|
|
207
211
|
<SVG.Markers />
|
|
208
212
|
{grid && <SVG.Grid {...(typeof grid === 'boolean' ? { axis: grid } : grid)} />}
|
|
@@ -217,7 +221,7 @@ const DefaultStory = ({
|
|
|
217
221
|
attributes={{
|
|
218
222
|
node: (node: GraphLayoutNode<TestNode>) => ({
|
|
219
223
|
data: {
|
|
220
|
-
color:
|
|
224
|
+
color: getHashStyles(node.data?.type ?? node.type)?.hue,
|
|
221
225
|
},
|
|
222
226
|
classes: {
|
|
223
227
|
'dx-selected': selection.contains(node.id),
|
|
@@ -225,7 +229,7 @@ const DefaultStory = ({
|
|
|
225
229
|
}),
|
|
226
230
|
edge: (edge: GraphLayoutEdge<TestNode>) => ({
|
|
227
231
|
data: {
|
|
228
|
-
color:
|
|
232
|
+
color: getHashStyles(edge.data?.type ?? edge.type)?.hue,
|
|
229
233
|
},
|
|
230
234
|
}),
|
|
231
235
|
}}
|
|
@@ -256,13 +260,13 @@ const DefaultStory = ({
|
|
|
256
260
|
<Popover.VirtualTrigger virtualRef={popoverAnchorRef} />
|
|
257
261
|
<Popover.Content onOpenAutoFocus={(event) => event.preventDefault()}>
|
|
258
262
|
<Popover.Viewport>
|
|
259
|
-
<Card.
|
|
263
|
+
<Card.Root>
|
|
260
264
|
<SyntaxHighlighter
|
|
261
265
|
language='json'
|
|
262
266
|
classNames='text-xs mlb-cardSpacingBlock pli-cardSpacingInline bg-transparent'
|
|
263
267
|
code={JSON.stringify(popover, null, 2)}
|
|
264
268
|
/>
|
|
265
|
-
</Card.
|
|
269
|
+
</Card.Root>
|
|
266
270
|
</Popover.Viewport>
|
|
267
271
|
<Popover.Arrow />
|
|
268
272
|
</Popover.Content>
|
|
@@ -283,7 +287,7 @@ const Debug = ({
|
|
|
283
287
|
onDelete,
|
|
284
288
|
onPing,
|
|
285
289
|
}: {
|
|
286
|
-
model?: GraphModel;
|
|
290
|
+
model?: GraphModel.GraphModel;
|
|
287
291
|
selection: SelectionModel;
|
|
288
292
|
projector: ProjectorType;
|
|
289
293
|
onToggleProjector: () => void;
|
|
@@ -297,26 +301,24 @@ const Debug = ({
|
|
|
297
301
|
}) => {
|
|
298
302
|
const [data, setData] = useState({});
|
|
299
303
|
useEffect(() => {
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
model: model?.toJSON(),
|
|
305
|
-
});
|
|
304
|
+
setData({
|
|
305
|
+
projector,
|
|
306
|
+
selection: selection.toJSON(),
|
|
307
|
+
model: model?.toJSON(),
|
|
306
308
|
});
|
|
307
309
|
}, [model, selection, projector]);
|
|
308
310
|
|
|
309
311
|
return (
|
|
310
312
|
<div className='flex flex-col overflow-hidden'>
|
|
311
313
|
<Toolbar.Root>
|
|
312
|
-
<IconButton onClick={onToggleProjector}
|
|
313
|
-
<IconButton onClick={onRefresh}
|
|
314
|
-
<IconButton onClick={onRepaint}
|
|
315
|
-
<IconButton onClick={onRegenerate}
|
|
316
|
-
<IconButton onClick={onClear}
|
|
317
|
-
<IconButton onClick={onAdd}
|
|
318
|
-
<IconButton onClick={onDelete}
|
|
319
|
-
<IconButton onClick={onPing}
|
|
314
|
+
<IconButton onClick={onToggleProjector} label='Projector' icon='ph--graph--regular' iconOnly />
|
|
315
|
+
<IconButton onClick={onRefresh} label='Refresh' icon='ph--arrow-clockwise--regular' iconOnly />
|
|
316
|
+
<IconButton onClick={onRepaint} label='Repaint' icon='ph--paint-roller--regular' iconOnly />
|
|
317
|
+
<IconButton onClick={onRegenerate} label='Regenerate' icon='ph--arrows-clockwise--regular' iconOnly />
|
|
318
|
+
<IconButton onClick={onClear} label='Clear' icon='ph--trash--regular' iconOnly />
|
|
319
|
+
<IconButton onClick={onAdd} label='Add' icon='ph--plus--regular' iconOnly />
|
|
320
|
+
<IconButton onClick={onDelete} label='Delete' icon='ph--x--regular' iconOnly />
|
|
321
|
+
<IconButton onClick={onPing} label='Delete' icon='ph--crosshair-simple--regular' iconOnly />
|
|
320
322
|
</Toolbar.Root>
|
|
321
323
|
<JsonFilter data={data} classNames='text-sm' />
|
|
322
324
|
</div>
|
|
@@ -326,8 +328,9 @@ const Debug = ({
|
|
|
326
328
|
const meta = {
|
|
327
329
|
title: 'ui/react-ui-graph/Graph',
|
|
328
330
|
render: DefaultStory,
|
|
329
|
-
decorators: [
|
|
331
|
+
decorators: [withRegistry, withTheme],
|
|
330
332
|
parameters: {
|
|
333
|
+
layout: 'fullscreen',
|
|
331
334
|
controls: { disable: true },
|
|
332
335
|
},
|
|
333
336
|
} satisfies Meta<typeof DefaultStory>;
|
|
@@ -2,14 +2,13 @@
|
|
|
2
2
|
// Copyright 2022 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { effect } from '@preact/signals-core';
|
|
6
5
|
import React, { type JSX, type Ref, forwardRef, useEffect, useImperativeHandle, useMemo, useRef } from 'react';
|
|
7
6
|
|
|
8
7
|
import { combine } from '@dxos/async';
|
|
9
|
-
import { type
|
|
8
|
+
import { type Graph as Graph$, type GraphModel } from '@dxos/graph';
|
|
10
9
|
import { log } from '@dxos/log';
|
|
11
10
|
import { type ThemedClassName } from '@dxos/react-ui';
|
|
12
|
-
import { mx } from '@dxos/
|
|
11
|
+
import { mx } from '@dxos/ui-theme';
|
|
13
12
|
|
|
14
13
|
import {
|
|
15
14
|
GraphForceProjector,
|
|
@@ -27,9 +26,9 @@ export type GraphController = {
|
|
|
27
26
|
findNode: (id: string) => SVGGElement | null;
|
|
28
27
|
};
|
|
29
28
|
|
|
30
|
-
export type GraphProps<Node extends
|
|
29
|
+
export type GraphProps<Node extends Graph$.Node.Any = any, Edge extends Graph$.Edge.Any = any> = ThemedClassName<
|
|
31
30
|
Pick<GraphRendererOptions<Node>, 'labels' | 'subgraphs' | 'attributes'> & {
|
|
32
|
-
model?: GraphModel<Node, Edge>; // TODO(burdon): ReactiveGraphModel
|
|
31
|
+
model?: GraphModel.GraphModel<Node, Edge>; // TODO(burdon): ReactiveGraphModel
|
|
33
32
|
projector?: GraphProjector<Node>;
|
|
34
33
|
renderer?: GraphRenderer<Node>;
|
|
35
34
|
drag?: boolean;
|
|
@@ -39,7 +38,7 @@ export type GraphProps<Node extends BaseGraphNode = any, Edge extends BaseGraphE
|
|
|
39
38
|
}
|
|
40
39
|
>;
|
|
41
40
|
|
|
42
|
-
|
|
41
|
+
const GraphInner = <Node extends Graph$.Node.Any = any, Edge extends Graph$.Edge.Any = any>(
|
|
43
42
|
{
|
|
44
43
|
classNames,
|
|
45
44
|
model,
|
|
@@ -54,7 +53,7 @@ export const GraphInner = <Node extends BaseGraphNode = any, Edge extends BaseGr
|
|
|
54
53
|
forwardedRef: Ref<GraphController>,
|
|
55
54
|
) => {
|
|
56
55
|
const context = useSvgContext();
|
|
57
|
-
const graphRef = useRef<SVGGElement>();
|
|
56
|
+
const graphRef = useRef<SVGGElement>(null);
|
|
58
57
|
|
|
59
58
|
const { projector, renderer } = useMemo(() => {
|
|
60
59
|
let projector = _projector;
|
|
@@ -96,10 +95,18 @@ export const GraphInner = <Node extends BaseGraphNode = any, Edge extends BaseGr
|
|
|
96
95
|
|
|
97
96
|
// Subscriptions.
|
|
98
97
|
useEffect(() => {
|
|
98
|
+
projector.updateData(model?.graph);
|
|
99
|
+
|
|
100
|
+
// Subscribe to model changes if reactive model.
|
|
101
|
+
const unsubscribeModel =
|
|
102
|
+
model && 'subscribe' in model
|
|
103
|
+
? (model as GraphModel.ReactiveGraphModel).subscribe(() => {
|
|
104
|
+
projector.updateData(model?.graph);
|
|
105
|
+
})
|
|
106
|
+
: undefined;
|
|
107
|
+
|
|
99
108
|
return combine(
|
|
100
|
-
|
|
101
|
-
projector.updateData(model?.graph);
|
|
102
|
-
}),
|
|
109
|
+
unsubscribeModel,
|
|
103
110
|
projector.updated.on(({ layout }) => {
|
|
104
111
|
try {
|
|
105
112
|
renderer.render(layout);
|
|
@@ -125,6 +132,6 @@ export const GraphInner = <Node extends BaseGraphNode = any, Edge extends BaseGr
|
|
|
125
132
|
/**
|
|
126
133
|
* SVG Graph.
|
|
127
134
|
*/
|
|
128
|
-
export const Graph = forwardRef(GraphInner) as <Node extends
|
|
135
|
+
export const Graph = forwardRef(GraphInner) as <Node extends Graph$.Node.Any = any, Edge extends Graph$.Edge.Any = any>(
|
|
129
136
|
props: GraphProps<Node, Edge> & { ref?: Ref<GraphController> },
|
|
130
137
|
) => JSX.Element;
|
|
@@ -2,12 +2,10 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import '@dxos-theme';
|
|
6
|
-
|
|
7
5
|
import { type Meta, type StoryObj } from '@storybook/react-vite';
|
|
8
6
|
import React, { useEffect, useState } from 'react';
|
|
9
7
|
|
|
10
|
-
import {
|
|
8
|
+
import { withTheme } from '@dxos/react-ui/testing';
|
|
11
9
|
|
|
12
10
|
import { SVG, type SVGRootProps } from '../SVG';
|
|
13
11
|
|
|
@@ -39,7 +37,10 @@ const DefaultStory = (props: SVGRootProps) => {
|
|
|
39
37
|
const meta = {
|
|
40
38
|
title: 'ui/react-ui-graph/Mesh',
|
|
41
39
|
render: DefaultStory,
|
|
42
|
-
decorators: [withTheme
|
|
40
|
+
decorators: [withTheme],
|
|
41
|
+
parameters: {
|
|
42
|
+
layout: 'fullscreen',
|
|
43
|
+
},
|
|
43
44
|
} satisfies Meta<typeof DefaultStory>;
|
|
44
45
|
|
|
45
46
|
export default meta;
|
|
@@ -16,7 +16,7 @@ export type MarkersProps = {
|
|
|
16
16
|
* SVG markers wrapper.
|
|
17
17
|
*/
|
|
18
18
|
export const Markers = ({ arrowSize, className }: MarkersProps) => {
|
|
19
|
-
const ref = useRef();
|
|
19
|
+
const ref = useRef(null);
|
|
20
20
|
useEffect(() => {
|
|
21
21
|
select(ref.current).call(createMarkers({ arrowSize }));
|
|
22
22
|
}, [ref]);
|
|
@@ -7,7 +7,7 @@ import React, { type PropsWithChildren, forwardRef, useEffect, useImperativeHand
|
|
|
7
7
|
import { useResizeDetector } from 'react-resize-detector';
|
|
8
8
|
|
|
9
9
|
import { type ThemedClassName } from '@dxos/react-ui';
|
|
10
|
-
import { mx } from '@dxos/
|
|
10
|
+
import { mx } from '@dxos/ui-theme';
|
|
11
11
|
|
|
12
12
|
import { SVGContext, type SVGContextOptions, SVGContextProvider } from '../../hooks';
|
|
13
13
|
|
|
@@ -16,7 +16,16 @@ import { type ZoomProps as SVGZoomProps, Zoom } from './Zoom';
|
|
|
16
16
|
|
|
17
17
|
export type SVGProps = PropsWithChildren<ThemedClassName>;
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
type SVG = {
|
|
20
|
+
Root: typeof Root;
|
|
21
|
+
Grid: typeof Grid;
|
|
22
|
+
Markers: typeof Markers;
|
|
23
|
+
Mesh: typeof Mesh;
|
|
24
|
+
Zoom: typeof Zoom;
|
|
25
|
+
Graph: typeof Graph;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export const SVG: SVG = {
|
|
20
29
|
Root,
|
|
21
30
|
Grid,
|
|
22
31
|
Markers,
|
|
@@ -2,12 +2,10 @@
|
|
|
2
2
|
// Copyright 2022 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import '@dxos-theme';
|
|
6
|
-
|
|
7
5
|
import { type Meta, type StoryObj } from '@storybook/react-vite';
|
|
8
6
|
import React, { useRef } from 'react';
|
|
9
7
|
|
|
10
|
-
import {
|
|
8
|
+
import { withTheme } from '@dxos/react-ui/testing';
|
|
11
9
|
|
|
12
10
|
import { type SVGContext, useGrid, useZoom } from '../../hooks';
|
|
13
11
|
|
|
@@ -47,7 +45,10 @@ const DefaultStory = (props: ComponentProps) => {
|
|
|
47
45
|
const meta = {
|
|
48
46
|
title: 'ui/react-ui-graph/SVGRoot',
|
|
49
47
|
render: DefaultStory,
|
|
50
|
-
decorators: [withTheme
|
|
48
|
+
decorators: [withTheme],
|
|
49
|
+
parameters: {
|
|
50
|
+
layout: 'fullscreen',
|
|
51
|
+
},
|
|
51
52
|
} satisfies Meta<typeof DefaultStory>;
|
|
52
53
|
|
|
53
54
|
export default meta;
|
package/src/fx/fx.stories.tsx
CHANGED
|
@@ -2,13 +2,11 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import '@dxos-theme';
|
|
6
|
-
|
|
7
5
|
import { type Meta, type StoryObj } from '@storybook/react-vite';
|
|
8
6
|
import { select } from 'd3';
|
|
9
7
|
import React, { type FC, useEffect, useMemo, useRef } from 'react';
|
|
10
8
|
|
|
11
|
-
import {
|
|
9
|
+
import { withTheme } from '@dxos/react-ui/testing';
|
|
12
10
|
|
|
13
11
|
import { SVG } from '../components';
|
|
14
12
|
import { useGrid, useZoom } from '../hooks';
|
|
@@ -54,7 +52,7 @@ const StoryComponent: FC<StoryProps> = ({ count = 1, ...options }) => {
|
|
|
54
52
|
const grid = useGrid({ axis: true, grid: false });
|
|
55
53
|
const zoom = useZoom();
|
|
56
54
|
|
|
57
|
-
const root = useRef<SVGGElement>();
|
|
55
|
+
const root = useRef<SVGGElement>(null);
|
|
58
56
|
useEffect(() => {
|
|
59
57
|
select(root.current)
|
|
60
58
|
.selectAll('g')
|
|
@@ -96,7 +94,10 @@ const createNode: D3Callable<SVGGElement, Datum> = (group, classNames, options)
|
|
|
96
94
|
const meta = {
|
|
97
95
|
title: 'ui/react-ui-graph/fx',
|
|
98
96
|
render: DefaultStory,
|
|
99
|
-
decorators: [withTheme
|
|
97
|
+
decorators: [withTheme],
|
|
98
|
+
parameters: {
|
|
99
|
+
layout: 'fullscreen',
|
|
100
|
+
},
|
|
100
101
|
} satisfies Meta<typeof DefaultStory>;
|
|
101
102
|
|
|
102
103
|
export default meta;
|
|
@@ -223,7 +223,7 @@ export class GraphForceProjector<NodeData = any> extends GraphProjector<NodeData
|
|
|
223
223
|
this.restart();
|
|
224
224
|
}
|
|
225
225
|
|
|
226
|
-
override onUpdate(graph?: Graph): void {
|
|
226
|
+
override onUpdate(graph?: Graph.Any): void {
|
|
227
227
|
log('onUpdate', { graph: { nodes: graph?.nodes.length, edges: graph?.edges.length } });
|
|
228
228
|
this._simulation.stop();
|
|
229
229
|
this.mergeData(graph);
|
|
@@ -20,14 +20,14 @@ export class GraphHierarchicalProjector<
|
|
|
20
20
|
NodeData = any,
|
|
21
21
|
Options extends GraphHierarchicalProjectorOptions = any,
|
|
22
22
|
> extends GraphRadialProjector<NodeData, Options> {
|
|
23
|
-
protected override onUpdate(graph?: Graph) {
|
|
23
|
+
protected override onUpdate(graph?: Graph.Any) {
|
|
24
24
|
log('onUpdate', {
|
|
25
25
|
graph: { nodes: graph?.nodes.length, edges: graph?.edges.length },
|
|
26
|
-
selection: this.selection?.
|
|
26
|
+
selection: this.selection?.getSelectedIds(),
|
|
27
27
|
});
|
|
28
28
|
|
|
29
29
|
this.mergeData(graph);
|
|
30
|
-
const selected = this.selection?.
|
|
30
|
+
const selected = this.selection?.getSelectedIds()[0];
|
|
31
31
|
if (selected) {
|
|
32
32
|
const node = this.layout.graph.nodes.find((node) => node.id === selected);
|
|
33
33
|
if (node) {
|
|
@@ -15,7 +15,7 @@ export type GraphProjectorOptions = ProjectorOptions & {};
|
|
|
15
15
|
* Base class for graph projectors.
|
|
16
16
|
*/
|
|
17
17
|
export abstract class GraphProjector<NodeData = any, Options extends GraphProjectorOptions = any> extends Projector<
|
|
18
|
-
Graph,
|
|
18
|
+
Graph.Any,
|
|
19
19
|
GraphLayout<NodeData>,
|
|
20
20
|
Options
|
|
21
21
|
> {
|
|
@@ -60,7 +60,7 @@ export abstract class GraphProjector<NodeData = any, Options extends GraphProjec
|
|
|
60
60
|
* Merge external data with internal representation (e.g., so force properties like position are preserved).
|
|
61
61
|
* @param data
|
|
62
62
|
*/
|
|
63
|
-
protected mergeData(data: Graph = emptyGraph) {
|
|
63
|
+
protected mergeData(data: Graph.Any = emptyGraph) {
|
|
64
64
|
// Merge nodes.
|
|
65
65
|
const nodes: GraphLayoutNode[] = data.nodes.map((node) => {
|
|
66
66
|
let current: GraphLayoutNode = this._layout.graph.nodes.find((n) => n.id === this.options.idAccessor(node));
|
|
@@ -28,7 +28,7 @@ export class GraphRadialProjector<
|
|
|
28
28
|
return undefined;
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
protected override onUpdate(graph?: Graph) {
|
|
31
|
+
protected override onUpdate(graph?: Graph.Any) {
|
|
32
32
|
log('onUpdate', { graph: { nodes: graph?.nodes.length, edges: graph?.edges.length } });
|
|
33
33
|
this.mergeData(graph);
|
|
34
34
|
this.doRadialLayout();
|
|
@@ -20,14 +20,14 @@ export class GraphRelationalProjector<
|
|
|
20
20
|
NodeData = any,
|
|
21
21
|
Options extends GraphRelationalProjectorOptions = any,
|
|
22
22
|
> extends GraphRadialProjector<NodeData, Options> {
|
|
23
|
-
protected override onUpdate(graph?: Graph) {
|
|
23
|
+
protected override onUpdate(graph?: Graph.Any) {
|
|
24
24
|
log('onUpdate', {
|
|
25
25
|
graph: { nodes: graph?.nodes.length, edges: graph?.edges.length },
|
|
26
|
-
selection: this.selection?.
|
|
26
|
+
selection: this.selection?.getSelectedIds(),
|
|
27
27
|
});
|
|
28
28
|
|
|
29
29
|
this.mergeData(graph);
|
|
30
|
-
const selected = this.selection?.
|
|
30
|
+
const selected = this.selection?.getSelectedIds()[0];
|
|
31
31
|
if (selected) {
|
|
32
32
|
const node = this.layout.graph.nodes.find((node) => node.id === selected);
|
|
33
33
|
if (node) {
|
package/src/graph/types.ts
CHANGED
package/src/hooks/useStateRef.ts
CHANGED
|
@@ -16,7 +16,7 @@ export const useStateRef = <V>(
|
|
|
16
16
|
initialValue?: V | (() => V),
|
|
17
17
|
): [V | undefined, Dispatch<SetStateAction<V | undefined>>, RefObject<V | undefined>] => {
|
|
18
18
|
const [value, setValue] = useState<V | undefined>(initialValue);
|
|
19
|
-
const ref = useRef<V>();
|
|
19
|
+
const ref = useRef<V>(null);
|
|
20
20
|
useEffect(() => {
|
|
21
21
|
ref.current = value;
|
|
22
22
|
}, [initialValue, value]);
|