@dxos/react-ui-graph 0.8.4-main.f5c0578 → 0.8.4-main.fcfe5033a5
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/README.md +5 -7
- 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 +1089 -240
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +16 -16
- 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 +1089 -240
- 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 +16 -16
- 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 +17 -8
- package/dist/types/src/components/Graph/Graph.stories.d.ts.map +1 -1
- package/dist/types/src/components/Mesh/Mesh.stories.d.ts +9 -5
- package/dist/types/src/components/Mesh/Mesh.stories.d.ts.map +1 -1
- package/dist/types/src/components/SVG/Root.d.ts +4 -4
- package/dist/types/src/components/SVG/Root.d.ts.map +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 +11 -9
- package/dist/types/src/components/SVG/Svg.stories.d.ts.map +1 -1
- package/dist/types/src/fx/fx.stories.d.ts +16 -15
- package/dist/types/src/fx/fx.stories.d.ts.map +1 -1
- package/dist/types/src/graph/projector/graph-drag.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/renderer/graph-renderer.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 +14 -9
- 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/src/util/fraction.d.ts +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +31 -26
- package/src/components/Graph/Graph.stories.tsx +61 -56
- package/src/components/Graph/Graph.tsx +24 -16
- package/src/components/Mesh/Mesh.stories.tsx +9 -9
- package/src/components/SVG/Grid.tsx +1 -1
- package/src/components/SVG/Markers.tsx +1 -1
- package/src/components/SVG/Root.tsx +14 -7
- package/src/components/SVG/SVG.tsx +10 -2
- package/src/components/SVG/Svg.stories.tsx +22 -19
- package/src/fx/fx.stories.tsx +17 -15
- package/src/graph/projector/graph-drag.ts +0 -1
- package/src/graph/projector/graph-force-projector.ts +1 -2
- package/src/graph/projector/graph-hierarchical-projector.ts +3 -4
- package/src/graph/projector/graph-projector.ts +2 -3
- package/src/graph/projector/graph-radial-projector.ts +1 -2
- package/src/graph/projector/graph-relational-projector.ts +3 -4
- package/src/graph/renderer/graph-renderer.ts +0 -1
- package/src/graph/types.ts +1 -1
- package/src/hooks/useStateRef.ts +1 -1
- package/src/stories/hooks.stories.tsx +38 -31
- package/src/testing/data.ts +14 -14
- package/src/testing/hooks.ts +3 -4
- package/src/testing/model.ts +6 -6
- package/src/util/fraction.ts +1 -1
- package/styles/graph.css +292 -43
- package/dist/lib/browser/chunk-HLAKLUDC.mjs +0 -958
- package/dist/lib/browser/chunk-HLAKLUDC.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-O6GWCXDC.mjs +0 -960
- package/dist/lib/node-esm/chunk-O6GWCXDC.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.fcfe5033a5",
|
|
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.5.0",
|
|
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/
|
|
50
|
-
"@dxos/
|
|
51
|
-
"@dxos/
|
|
52
|
-
"@dxos/
|
|
53
|
-
"@dxos/
|
|
54
|
-
"@dxos/
|
|
55
|
-
"@dxos/
|
|
54
|
+
"@dxos/debug": "0.8.4-main.fcfe5033a5",
|
|
55
|
+
"@dxos/graph": "0.8.4-main.fcfe5033a5",
|
|
56
|
+
"@dxos/async": "0.8.4-main.fcfe5033a5",
|
|
57
|
+
"@dxos/node-std": "0.8.4-main.fcfe5033a5",
|
|
58
|
+
"@dxos/invariant": "0.8.4-main.fcfe5033a5",
|
|
59
|
+
"@dxos/log": "0.8.4-main.fcfe5033a5",
|
|
60
|
+
"@dxos/react-ui-mosaic": "0.8.4-main.fcfe5033a5"
|
|
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/
|
|
69
|
-
"@dxos/react-ui": "0.8.4-main.
|
|
70
|
-
"@dxos/react-ui-syntax-highlighter": "0.8.4-main.
|
|
71
|
-
"@dxos/
|
|
72
|
-
"@dxos/
|
|
73
|
-
"@dxos/
|
|
71
|
+
"react": "~19.2.3",
|
|
72
|
+
"react-dom": "~19.2.3",
|
|
73
|
+
"@dxos/react-ui": "0.8.4-main.fcfe5033a5",
|
|
74
|
+
"@dxos/react-ui-stack": "0.8.4-main.fcfe5033a5",
|
|
75
|
+
"@dxos/react-ui-syntax-highlighter": "0.8.4-main.fcfe5033a5",
|
|
76
|
+
"@dxos/random": "0.8.4-main.fcfe5033a5",
|
|
77
|
+
"@dxos/ui-theme": "0.8.4-main.fcfe5033a5",
|
|
78
|
+
"@dxos/storybook-utils": "0.8.4-main.fcfe5033a5"
|
|
74
79
|
},
|
|
75
80
|
"peerDependencies": {
|
|
76
|
-
"react": "~
|
|
77
|
-
"react-dom": "~
|
|
78
|
-
"@dxos/
|
|
79
|
-
"@dxos/react-ui
|
|
81
|
+
"react": "~19.2.3",
|
|
82
|
+
"react-dom": "~19.2.3",
|
|
83
|
+
"@dxos/ui-theme": "0.8.4-main.fcfe5033a5",
|
|
84
|
+
"@dxos/react-ui": "0.8.4-main.fcfe5033a5"
|
|
80
85
|
},
|
|
81
86
|
"optionalDependencies": {
|
|
82
|
-
"@dxos/random": "0.8.4-main.
|
|
87
|
+
"@dxos/random": "0.8.4-main.fcfe5033a5"
|
|
83
88
|
},
|
|
84
89
|
"publishConfig": {
|
|
85
90
|
"access": "public"
|
|
@@ -2,19 +2,20 @@
|
|
|
2
2
|
// Copyright 2022 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import '
|
|
5
|
+
import '../../../styles/graph.css';
|
|
6
6
|
|
|
7
|
-
import {
|
|
8
|
-
import { type StoryObj } from '@storybook/react-vite';
|
|
7
|
+
import { RegistryContext } from '@effect-atom/atom-react';
|
|
8
|
+
import { type Meta, type StoryObj } from '@storybook/react-vite';
|
|
9
9
|
import { select } from 'd3';
|
|
10
|
-
import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
10
|
+
import React, { useCallback, useContext, useEffect, useMemo, useRef, useState } from 'react';
|
|
11
11
|
|
|
12
12
|
import { type Graph, type GraphModel, SelectionModel } from '@dxos/graph';
|
|
13
13
|
import { IconButton, Popover, Toolbar } from '@dxos/react-ui';
|
|
14
|
-
import { Card } from '@dxos/react-ui
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
14
|
+
import { Card } from '@dxos/react-ui';
|
|
15
|
+
import { Json, SyntaxHighlighter } from '@dxos/react-ui-syntax-highlighter';
|
|
16
|
+
import { withLayout, withTheme } from '@dxos/react-ui/testing';
|
|
17
|
+
import { withRegistry } from '@dxos/storybook-utils';
|
|
18
|
+
import { getHashStyles, mx } from '@dxos/ui-theme';
|
|
18
19
|
|
|
19
20
|
import { Pulsar } from '../../fx';
|
|
20
21
|
import {
|
|
@@ -33,11 +34,8 @@ import {
|
|
|
33
34
|
import { type SVGContext } from '../../hooks';
|
|
34
35
|
import { TestGraphModel, type TestNode, convertTreeToGraph, createGraph, createNode, createTree } from '../../testing';
|
|
35
36
|
import { SVG, type SVGGridProps } from '../SVG';
|
|
36
|
-
|
|
37
37
|
import { Graph as GraphComponent, type GraphController, type GraphProps } from './Graph';
|
|
38
38
|
|
|
39
|
-
import '../../../styles/graph.css';
|
|
40
|
-
|
|
41
39
|
type ProjectorType = 'force' | 'radial' | 'hierarchical' | 'relational';
|
|
42
40
|
|
|
43
41
|
type Factory = {
|
|
@@ -51,12 +49,12 @@ const projectorTypes: Record<ProjectorType, Factory> = {
|
|
|
51
49
|
relational: GraphRelationalProjector as Factory,
|
|
52
50
|
};
|
|
53
51
|
|
|
54
|
-
type
|
|
52
|
+
type DefaultStoryProps = GraphProps & {
|
|
55
53
|
debug?: boolean;
|
|
56
54
|
grid?: boolean | SVGGridProps;
|
|
57
55
|
inspect?: boolean;
|
|
58
56
|
singleSelect?: boolean;
|
|
59
|
-
graph: () => Graph;
|
|
57
|
+
graph: () => Graph.Any;
|
|
60
58
|
projectorType?: ProjectorType;
|
|
61
59
|
projectorOptions?:
|
|
62
60
|
| GraphForceProjectorOptions
|
|
@@ -74,12 +72,16 @@ const DefaultStory = ({
|
|
|
74
72
|
projectorType: _projectorType = 'force',
|
|
75
73
|
projectorOptions,
|
|
76
74
|
...props
|
|
77
|
-
}:
|
|
75
|
+
}: DefaultStoryProps) => {
|
|
78
76
|
const graphRef = useRef<GraphController | null>(null);
|
|
79
77
|
const context = useRef<SVGContext>(null);
|
|
78
|
+
const registry = useContext(RegistryContext);
|
|
80
79
|
|
|
81
80
|
// Models.
|
|
82
|
-
const [model, setModel] = useState<GraphModel | undefined>(() =>
|
|
81
|
+
const [model, setModel] = useState<GraphModel.ReactiveGraphModel | undefined>(() => {
|
|
82
|
+
const graph = _graph?.();
|
|
83
|
+
return graph ? new TestGraphModel(registry, graph) : undefined;
|
|
84
|
+
});
|
|
83
85
|
const selection = useMemo(() => new SelectionModel(singleSelect), [singleSelect]);
|
|
84
86
|
|
|
85
87
|
// Projector.
|
|
@@ -157,8 +159,9 @@ const DefaultStory = ({
|
|
|
157
159
|
}, [model]);
|
|
158
160
|
|
|
159
161
|
const handleRegenerate = useCallback(() => {
|
|
160
|
-
|
|
161
|
-
|
|
162
|
+
const graph = _graph?.();
|
|
163
|
+
setModel(graph ? new TestGraphModel(registry, graph) : undefined);
|
|
164
|
+
}, [_graph, registry]);
|
|
162
165
|
|
|
163
166
|
const handleClear = useCallback(() => {
|
|
164
167
|
setModel(undefined);
|
|
@@ -182,7 +185,7 @@ const DefaultStory = ({
|
|
|
182
185
|
|
|
183
186
|
const active = useMemo(() => new SelectionModel(), []);
|
|
184
187
|
const handlePing = useCallback(() => {
|
|
185
|
-
for (const id of active.
|
|
188
|
+
for (const id of active.getSelectedIds()) {
|
|
186
189
|
const node = graphRef.current?.findNode(id);
|
|
187
190
|
if (node) {
|
|
188
191
|
Pulsar.remove(select(node));
|
|
@@ -190,7 +193,7 @@ const DefaultStory = ({
|
|
|
190
193
|
}
|
|
191
194
|
|
|
192
195
|
active.clear();
|
|
193
|
-
for (const id of selection.
|
|
196
|
+
for (const id of selection.getSelectedIds()) {
|
|
194
197
|
const node = graphRef.current?.findNode(id);
|
|
195
198
|
if (node) {
|
|
196
199
|
active.add(id);
|
|
@@ -202,7 +205,7 @@ const DefaultStory = ({
|
|
|
202
205
|
|
|
203
206
|
return (
|
|
204
207
|
<Popover.Root open={!!popover} onOpenChange={(state) => !state && setPopover(undefined)}>
|
|
205
|
-
<div className={mx('w-full grid divide-x divide-separator', debug && 'grid-cols-[1fr_30rem]')}>
|
|
208
|
+
<div className={mx('h-full w-full grid divide-x divide-separator', debug && 'grid-cols-[1fr_30rem]')}>
|
|
206
209
|
<SVG.Root ref={context}>
|
|
207
210
|
<SVG.Markers />
|
|
208
211
|
{grid && <SVG.Grid {...(typeof grid === 'boolean' ? { axis: grid } : grid)} />}
|
|
@@ -217,7 +220,7 @@ const DefaultStory = ({
|
|
|
217
220
|
attributes={{
|
|
218
221
|
node: (node: GraphLayoutNode<TestNode>) => ({
|
|
219
222
|
data: {
|
|
220
|
-
color:
|
|
223
|
+
color: getHashStyles(node.data?.type ?? node.type)?.hue,
|
|
221
224
|
},
|
|
222
225
|
classes: {
|
|
223
226
|
'dx-selected': selection.contains(node.id),
|
|
@@ -225,7 +228,7 @@ const DefaultStory = ({
|
|
|
225
228
|
}),
|
|
226
229
|
edge: (edge: GraphLayoutEdge<TestNode>) => ({
|
|
227
230
|
data: {
|
|
228
|
-
color:
|
|
231
|
+
color: getHashStyles(edge.data?.type ?? edge.type)?.hue,
|
|
229
232
|
},
|
|
230
233
|
}),
|
|
231
234
|
}}
|
|
@@ -256,13 +259,13 @@ const DefaultStory = ({
|
|
|
256
259
|
<Popover.VirtualTrigger virtualRef={popoverAnchorRef} />
|
|
257
260
|
<Popover.Content onOpenAutoFocus={(event) => event.preventDefault()}>
|
|
258
261
|
<Popover.Viewport>
|
|
259
|
-
<Card.
|
|
262
|
+
<Card.Root>
|
|
260
263
|
<SyntaxHighlighter
|
|
261
|
-
classNames='bg-transparent text-xs !mlb-cardSpacingBlock !pli-cardSpacingInline !overflow-visible'
|
|
262
264
|
language='json'
|
|
265
|
+
classNames='text-xs my-form-padding px-form-padding bg-transparent'
|
|
263
266
|
code={JSON.stringify(popover, null, 2)}
|
|
264
267
|
/>
|
|
265
|
-
</Card.
|
|
268
|
+
</Card.Root>
|
|
266
269
|
</Popover.Viewport>
|
|
267
270
|
<Popover.Arrow />
|
|
268
271
|
</Popover.Content>
|
|
@@ -283,7 +286,7 @@ const Debug = ({
|
|
|
283
286
|
onDelete,
|
|
284
287
|
onPing,
|
|
285
288
|
}: {
|
|
286
|
-
model?: GraphModel;
|
|
289
|
+
model?: GraphModel.ReactiveGraphModel;
|
|
287
290
|
selection: SelectionModel;
|
|
288
291
|
projector: ProjectorType;
|
|
289
292
|
onToggleProjector: () => void;
|
|
@@ -297,44 +300,48 @@ const Debug = ({
|
|
|
297
300
|
}) => {
|
|
298
301
|
const [data, setData] = useState({});
|
|
299
302
|
useEffect(() => {
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
model: model?.toJSON(),
|
|
305
|
-
});
|
|
303
|
+
setData({
|
|
304
|
+
projector,
|
|
305
|
+
selection: selection.toJSON(),
|
|
306
|
+
model: model?.toJSON(),
|
|
306
307
|
});
|
|
307
308
|
}, [model, selection, projector]);
|
|
308
309
|
|
|
309
310
|
return (
|
|
310
311
|
<div className='flex flex-col overflow-hidden'>
|
|
311
312
|
<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}
|
|
313
|
+
<IconButton onClick={onToggleProjector} label='Projector' icon='ph--graph--regular' iconOnly />
|
|
314
|
+
<IconButton onClick={onRefresh} label='Refresh' icon='ph--arrow-clockwise--regular' iconOnly />
|
|
315
|
+
<IconButton onClick={onRepaint} label='Repaint' icon='ph--paint-roller--regular' iconOnly />
|
|
316
|
+
<IconButton onClick={onRegenerate} label='Regenerate' icon='ph--arrows-clockwise--regular' iconOnly />
|
|
317
|
+
<IconButton onClick={onClear} label='Clear' icon='ph--trash--regular' iconOnly />
|
|
318
|
+
<IconButton onClick={onAdd} label='Add' icon='ph--plus--regular' iconOnly />
|
|
319
|
+
<IconButton onClick={onDelete} label='Delete' icon='ph--x--regular' iconOnly />
|
|
320
|
+
<IconButton onClick={onPing} label='Delete' icon='ph--crosshair-simple--regular' iconOnly />
|
|
320
321
|
</Toolbar.Root>
|
|
321
|
-
<
|
|
322
|
+
<Json.Root data={data}>
|
|
323
|
+
<Json.Content>
|
|
324
|
+
<Json.Filter />
|
|
325
|
+
<Json.Data classNames='text-sm' />
|
|
326
|
+
</Json.Content>
|
|
327
|
+
</Json.Root>
|
|
322
328
|
</div>
|
|
323
329
|
);
|
|
324
330
|
};
|
|
325
331
|
|
|
326
|
-
const meta
|
|
332
|
+
const meta = {
|
|
327
333
|
title: 'ui/react-ui-graph/Graph',
|
|
328
334
|
render: DefaultStory,
|
|
329
|
-
decorators: [withTheme, withLayout({
|
|
335
|
+
decorators: [withRegistry, withTheme(), withLayout({ layout: 'fullscreen' })],
|
|
330
336
|
parameters: {
|
|
337
|
+
layout: 'fullscreen',
|
|
331
338
|
controls: { disable: true },
|
|
332
339
|
},
|
|
333
|
-
}
|
|
340
|
+
} satisfies Meta<typeof DefaultStory>;
|
|
334
341
|
|
|
335
342
|
export default meta;
|
|
336
343
|
|
|
337
|
-
type Story = StoryObj<
|
|
344
|
+
type Story = StoryObj<typeof meta>;
|
|
338
345
|
|
|
339
346
|
export const Default: Story = {
|
|
340
347
|
args: {
|
|
@@ -450,14 +457,12 @@ export const WithPopover: Story = {
|
|
|
450
457
|
},
|
|
451
458
|
};
|
|
452
459
|
|
|
453
|
-
export const Empty
|
|
454
|
-
|
|
455
|
-
<SVG.
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
<
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
),
|
|
463
|
-
};
|
|
460
|
+
export const Empty = () => (
|
|
461
|
+
<SVG.Root>
|
|
462
|
+
<SVG.Markers />
|
|
463
|
+
<SVG.Grid axis />
|
|
464
|
+
<SVG.Zoom extent={[1 / 4, 4]}>
|
|
465
|
+
<GraphComponent />
|
|
466
|
+
</SVG.Zoom>
|
|
467
|
+
</SVG.Root>
|
|
468
|
+
);
|
|
@@ -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 {
|
|
8
|
+
import { GraphModel, type Graph as Graph$ } 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>;
|
|
31
|
+
model?: GraphModel.ReactiveGraphModel<Node, Edge>;
|
|
33
32
|
projector?: GraphProjector<Node>;
|
|
34
33
|
renderer?: GraphRenderer<Node>;
|
|
35
34
|
drag?: boolean;
|
|
@@ -39,12 +38,12 @@ 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,
|
|
46
|
-
projector:
|
|
47
|
-
renderer:
|
|
45
|
+
projector: projectorProp,
|
|
46
|
+
renderer: rendererProp,
|
|
48
47
|
drag,
|
|
49
48
|
arrows,
|
|
50
49
|
onSelect,
|
|
@@ -54,15 +53,17 @@ 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);
|
|
57
|
+
// TODO(wittjosiah): This doesn't work for some reason.
|
|
58
|
+
// const graph = useAtomValue(model?.graphAtom ?? EMPTY_ATOM);
|
|
58
59
|
|
|
59
60
|
const { projector, renderer } = useMemo(() => {
|
|
60
|
-
let projector =
|
|
61
|
+
let projector = projectorProp;
|
|
61
62
|
if (!projector) {
|
|
62
63
|
projector = new GraphForceProjector<Node>(context);
|
|
63
64
|
}
|
|
64
65
|
|
|
65
|
-
let renderer =
|
|
66
|
+
let renderer = rendererProp;
|
|
66
67
|
if (!renderer) {
|
|
67
68
|
renderer = new GraphRenderer<Node>(context, graphRef, {
|
|
68
69
|
...props,
|
|
@@ -75,7 +76,7 @@ export const GraphInner = <Node extends BaseGraphNode = any, Edge extends BaseGr
|
|
|
75
76
|
}
|
|
76
77
|
|
|
77
78
|
return { projector, renderer };
|
|
78
|
-
}, [context,
|
|
79
|
+
}, [context, projectorProp, rendererProp, drag]);
|
|
79
80
|
|
|
80
81
|
// External API.
|
|
81
82
|
useImperativeHandle(
|
|
@@ -96,10 +97,17 @@ export const GraphInner = <Node extends BaseGraphNode = any, Edge extends BaseGr
|
|
|
96
97
|
|
|
97
98
|
// Subscriptions.
|
|
98
99
|
useEffect(() => {
|
|
100
|
+
projector.updateData(model?.graph);
|
|
101
|
+
|
|
102
|
+
// Subscribe to model changes if reactive model.
|
|
103
|
+
const unsubscribeModel = model
|
|
104
|
+
? model.subscribe(() => {
|
|
105
|
+
projector.updateData(model?.graph);
|
|
106
|
+
})
|
|
107
|
+
: undefined;
|
|
108
|
+
|
|
99
109
|
return combine(
|
|
100
|
-
|
|
101
|
-
projector.updateData(model?.graph);
|
|
102
|
-
}),
|
|
110
|
+
unsubscribeModel,
|
|
103
111
|
projector.updated.on(({ layout }) => {
|
|
104
112
|
try {
|
|
105
113
|
renderer.render(layout);
|
|
@@ -125,6 +133,6 @@ export const GraphInner = <Node extends BaseGraphNode = any, Edge extends BaseGr
|
|
|
125
133
|
/**
|
|
126
134
|
* SVG Graph.
|
|
127
135
|
*/
|
|
128
|
-
export const Graph = forwardRef(GraphInner) as <Node extends
|
|
136
|
+
export const Graph = forwardRef(GraphInner) as <Node extends Graph$.Node.Any = any, Edge extends Graph$.Edge.Any = any>(
|
|
129
137
|
props: GraphProps<Node, Edge> & { ref?: Ref<GraphController> },
|
|
130
138
|
) => JSX.Element;
|
|
@@ -2,15 +2,12 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import '@
|
|
6
|
-
|
|
7
|
-
import { type StoryObj } from '@storybook/react-vite';
|
|
5
|
+
import { type Meta, type StoryObj } from '@storybook/react-vite';
|
|
8
6
|
import React, { useEffect, useState } from 'react';
|
|
9
7
|
|
|
10
|
-
import {
|
|
8
|
+
import { withLayout, withTheme } from '@dxos/react-ui/testing';
|
|
11
9
|
|
|
12
10
|
import { SVG, type SVGRootProps } from '../SVG';
|
|
13
|
-
|
|
14
11
|
import { Mesh } from './Mesh';
|
|
15
12
|
|
|
16
13
|
// TODO(burdon): Create waves/game of life.
|
|
@@ -36,15 +33,18 @@ const DefaultStory = (props: SVGRootProps) => {
|
|
|
36
33
|
);
|
|
37
34
|
};
|
|
38
35
|
|
|
39
|
-
const meta
|
|
36
|
+
const meta = {
|
|
40
37
|
title: 'ui/react-ui-graph/Mesh',
|
|
41
38
|
render: DefaultStory,
|
|
42
|
-
decorators: [withTheme, withLayout({
|
|
43
|
-
|
|
39
|
+
decorators: [withTheme(), withLayout({ layout: 'fullscreen' })],
|
|
40
|
+
parameters: {
|
|
41
|
+
layout: 'fullscreen',
|
|
42
|
+
},
|
|
43
|
+
} satisfies Meta<typeof DefaultStory>;
|
|
44
44
|
|
|
45
45
|
export default meta;
|
|
46
46
|
|
|
47
|
-
type Story = StoryObj<typeof
|
|
47
|
+
type Story = StoryObj<typeof meta>;
|
|
48
48
|
|
|
49
49
|
export const Default: Story = {
|
|
50
50
|
args: {
|
|
@@ -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]);
|
|
@@ -3,26 +3,33 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
import { select } from 'd3';
|
|
6
|
-
import React, {
|
|
6
|
+
import React, {
|
|
7
|
+
type ComponentPropsWithoutRef,
|
|
8
|
+
type PropsWithChildren,
|
|
9
|
+
forwardRef,
|
|
10
|
+
useEffect,
|
|
11
|
+
useImperativeHandle,
|
|
12
|
+
useMemo,
|
|
13
|
+
} from 'react';
|
|
7
14
|
import { useResizeDetector } from 'react-resize-detector';
|
|
8
15
|
|
|
9
16
|
import { type ThemedClassName } from '@dxos/react-ui';
|
|
10
|
-
import { mx } from '@dxos/
|
|
17
|
+
import { composableProps, mx } from '@dxos/ui-theme';
|
|
11
18
|
|
|
12
19
|
import { SVGContext, type SVGContextOptions, SVGContextProvider } from '../../hooks';
|
|
13
20
|
|
|
14
|
-
export type RootProps = ThemedClassName<PropsWithChildren<SVGContextOptions
|
|
21
|
+
export type RootProps = ThemedClassName<PropsWithChildren<SVGContextOptions & ComponentPropsWithoutRef<'div'>>>;
|
|
15
22
|
|
|
16
23
|
/**
|
|
17
24
|
* Makes the SVG context available to child nodes.
|
|
18
25
|
* Automatically resizes the SVG element, which expands to fit the container.
|
|
19
26
|
*/
|
|
20
|
-
export const Root = forwardRef<SVGContext, RootProps>(({
|
|
27
|
+
export const Root = forwardRef<SVGContext, RootProps>(({ children, scale, centered, ...props }, ref) => {
|
|
21
28
|
const { ref: containerRef, width = 0, height = 0 } = useResizeDetector({ refreshRate: 200 });
|
|
22
29
|
|
|
23
30
|
const context = useMemo<SVGContext>(() => {
|
|
24
|
-
return new SVGContext(
|
|
25
|
-
}, [
|
|
31
|
+
return new SVGContext({ scale, centered });
|
|
32
|
+
}, [scale, centered]);
|
|
26
33
|
|
|
27
34
|
useImperativeHandle(ref, () => context, [context]);
|
|
28
35
|
|
|
@@ -41,7 +48,7 @@ export const Root = forwardRef<SVGContext, RootProps>(({ classNames, children, .
|
|
|
41
48
|
|
|
42
49
|
return (
|
|
43
50
|
<SVGContextProvider value={context}>
|
|
44
|
-
<div
|
|
51
|
+
<div {...composableProps(props, { classNames: 'dx-expander' })} ref={containerRef}>
|
|
45
52
|
<svg
|
|
46
53
|
xmlns='http://www.w3.org/2000/svg'
|
|
47
54
|
ref={context.ref}
|
|
@@ -8,7 +8,6 @@ import { type ThemedClassName } from '@dxos/react-ui';
|
|
|
8
8
|
|
|
9
9
|
import { Graph, type GraphProps as SVGGraphProps } from '../Graph';
|
|
10
10
|
import { Mesh, type MeshProps as SVGMeshProps } from '../Mesh';
|
|
11
|
-
|
|
12
11
|
import { Grid, type GridProps as SVGGridProps } from './Grid';
|
|
13
12
|
import { Markers, type MarkersProps as SVGMarkersProps } from './Markers';
|
|
14
13
|
import { Root, type RootProps as SVGRootProps } from './Root';
|
|
@@ -16,7 +15,16 @@ import { type ZoomProps as SVGZoomProps, Zoom } from './Zoom';
|
|
|
16
15
|
|
|
17
16
|
export type SVGProps = PropsWithChildren<ThemedClassName>;
|
|
18
17
|
|
|
19
|
-
|
|
18
|
+
type SVG = {
|
|
19
|
+
Root: typeof Root;
|
|
20
|
+
Grid: typeof Grid;
|
|
21
|
+
Markers: typeof Markers;
|
|
22
|
+
Mesh: typeof Mesh;
|
|
23
|
+
Zoom: typeof Zoom;
|
|
24
|
+
Graph: typeof Graph;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export const SVG: SVG = {
|
|
20
28
|
Root,
|
|
21
29
|
Grid,
|
|
22
30
|
Markers,
|
|
@@ -2,33 +2,21 @@
|
|
|
2
2
|
// Copyright 2022 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import '
|
|
5
|
+
import '../../../styles/graph.css';
|
|
6
6
|
|
|
7
|
+
import { type Meta, type StoryObj } from '@storybook/react-vite';
|
|
7
8
|
import React, { useRef } from 'react';
|
|
8
9
|
|
|
9
|
-
import {
|
|
10
|
+
import { withLayout, withTheme } from '@dxos/react-ui/testing';
|
|
10
11
|
|
|
11
12
|
import { type SVGContext, useGrid, useZoom } from '../../hooks';
|
|
12
|
-
|
|
13
13
|
import { SVG } from './SVG';
|
|
14
14
|
|
|
15
|
-
import '../../../styles/graph.css';
|
|
16
|
-
|
|
17
15
|
type ComponentProps = {
|
|
18
16
|
grid?: boolean;
|
|
19
17
|
zoom?: boolean;
|
|
20
18
|
};
|
|
21
19
|
|
|
22
|
-
const DefaultStory = (props: ComponentProps) => {
|
|
23
|
-
const context = useRef<SVGContext>(null);
|
|
24
|
-
|
|
25
|
-
return (
|
|
26
|
-
<SVG.Root ref={context}>
|
|
27
|
-
<Component {...props} />
|
|
28
|
-
</SVG.Root>
|
|
29
|
-
);
|
|
30
|
-
};
|
|
31
|
-
|
|
32
20
|
const Component = (options: ComponentProps) => {
|
|
33
21
|
const grid = useGrid({ visible: options.grid, axis: true });
|
|
34
22
|
const zoom = useZoom({ enabled: options.zoom });
|
|
@@ -43,15 +31,30 @@ const Component = (options: ComponentProps) => {
|
|
|
43
31
|
);
|
|
44
32
|
};
|
|
45
33
|
|
|
46
|
-
const
|
|
34
|
+
const DefaultStory = (props: ComponentProps) => {
|
|
35
|
+
const context = useRef<SVGContext>(null);
|
|
36
|
+
|
|
37
|
+
return (
|
|
38
|
+
<SVG.Root ref={context}>
|
|
39
|
+
<Component {...props} />
|
|
40
|
+
</SVG.Root>
|
|
41
|
+
);
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const meta = {
|
|
47
45
|
title: 'ui/react-ui-graph/SVGRoot',
|
|
48
46
|
render: DefaultStory,
|
|
49
|
-
decorators: [withTheme, withLayout({
|
|
50
|
-
|
|
47
|
+
decorators: [withTheme(), withLayout({ layout: 'fullscreen' })],
|
|
48
|
+
parameters: {
|
|
49
|
+
layout: 'fullscreen',
|
|
50
|
+
},
|
|
51
|
+
} satisfies Meta<typeof DefaultStory>;
|
|
51
52
|
|
|
52
53
|
export default meta;
|
|
53
54
|
|
|
54
|
-
|
|
55
|
+
type Story = StoryObj<typeof meta>;
|
|
56
|
+
|
|
57
|
+
export const Default: Story = {
|
|
55
58
|
args: {
|
|
56
59
|
grid: true,
|
|
57
60
|
},
|