@dxos/react-ui-graph 0.8.4-main.72ec0f3 → 0.8.4-main.765dc60934
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/LICENSE +102 -5
- package/README.md +5 -7
- package/dist/lib/browser/chunk-EASNZZ7B.mjs +52 -0
- package/dist/lib/browser/chunk-EASNZZ7B.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +1116 -291
- 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-JSE2X4ML.mjs +54 -0
- package/dist/lib/node-esm/chunk-JSE2X4ML.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +1116 -291
- 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 +6 -6
- package/dist/types/src/components/Graph/Graph.stories.d.ts.map +1 -1
- package/dist/types/src/components/Mesh/Mesh.d.ts.map +1 -1
- package/dist/types/src/components/Mesh/Mesh.stories.d.ts.map +1 -1
- package/dist/types/src/components/SVG/Grid.d.ts.map +1 -1
- package/dist/types/src/components/SVG/Markers.d.ts.map +1 -1
- package/dist/types/src/components/SVG/Root.d.ts +8 -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 +1 -1
- package/dist/types/src/components/SVG/Svg.stories.d.ts.map +1 -1
- package/dist/types/src/fx/fx.stories.d.ts +3 -3
- package/dist/types/src/fx/fx.stories.d.ts.map +1 -1
- package/dist/types/src/fx/pulsar.d.ts.map +1 -1
- package/dist/types/src/graph/markers.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-forces.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/projector/projector.d.ts.map +1 -1
- package/dist/types/src/graph/renderer/bullets.d.ts.map +1 -1
- package/dist/types/src/graph/renderer/graph-renderer.d.ts.map +1 -1
- package/dist/types/src/graph/renderer/renderer.d.ts +6 -1
- package/dist/types/src/graph/renderer/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/hooks/useGrid.d.ts.map +1 -1
- package/dist/types/src/hooks/useStateRef.d.ts.map +1 -1
- package/dist/types/src/hooks/useSvgContext.d.ts.map +1 -1
- package/dist/types/src/hooks/useZoom.d.ts.map +1 -1
- package/dist/types/src/stories/hooks.stories.d.ts +4 -3
- package/dist/types/src/stories/hooks.stories.d.ts.map +1 -1
- package/dist/types/src/testing/data.d.ts +5 -5
- 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/events.d.ts.map +1 -1
- package/dist/types/src/util/fraction.d.ts +1 -1
- package/dist/types/src/util/fraction.d.ts.map +1 -1
- package/dist/types/src/util/points.d.ts.map +1 -1
- package/dist/types/src/util/scale.d.ts.map +1 -1
- package/dist/types/src/util/screen.d.ts.map +1 -1
- package/dist/types/src/util/vector.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +33 -35
- package/src/components/Graph/Graph.stories.tsx +45 -39
- package/src/components/Graph/Graph.tsx +23 -18
- package/src/components/Mesh/Mesh.stories.tsx +8 -7
- package/src/components/Mesh/Mesh.tsx +43 -35
- package/src/components/SVG/Grid.tsx +1 -1
- package/src/components/SVG/Root.tsx +41 -9
- package/src/components/SVG/SVG.tsx +10 -2
- package/src/components/SVG/Svg.stories.tsx +4 -5
- package/src/fx/fx.stories.tsx +7 -8
- 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 +13 -5
- package/src/graph/renderer/renderer.ts +6 -4
- package/src/graph/types.ts +1 -1
- package/src/stories/hooks.stories.tsx +21 -10
- 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-XWA2XJDX.mjs +0 -955
- package/dist/lib/browser/chunk-XWA2XJDX.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-3RLSFEEV.mjs +0 -957
- package/dist/lib/node-esm/chunk-3RLSFEEV.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.765dc60934",
|
|
4
4
|
"description": "GEM Graph.",
|
|
5
5
|
"homepage": "https://dxos.org",
|
|
6
6
|
"bugs": "https://github.com/dxos/dxos/issues",
|
|
7
|
-
"
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/dxos/dxos"
|
|
10
|
+
},
|
|
11
|
+
"license": "FSL-1.1-Apache-2.0",
|
|
8
12
|
"author": "DXOS.org",
|
|
9
|
-
"sideEffects":
|
|
13
|
+
"sideEffects": [
|
|
14
|
+
"*.css"
|
|
15
|
+
],
|
|
10
16
|
"type": "module",
|
|
11
17
|
"exports": {
|
|
12
18
|
".": {
|
|
@@ -22,13 +28,6 @@
|
|
|
22
28
|
"./styles/graph.css": "./styles/graph.css"
|
|
23
29
|
},
|
|
24
30
|
"types": "dist/types/src/index.d.ts",
|
|
25
|
-
"typesVersions": {
|
|
26
|
-
"*": {
|
|
27
|
-
"testing": [
|
|
28
|
-
"dist/types/src/testing/index.d.ts"
|
|
29
|
-
]
|
|
30
|
-
}
|
|
31
|
-
},
|
|
32
31
|
"files": [
|
|
33
32
|
"testing.d.ts",
|
|
34
33
|
"testing.js",
|
|
@@ -37,8 +36,7 @@
|
|
|
37
36
|
"styles"
|
|
38
37
|
],
|
|
39
38
|
"dependencies": {
|
|
40
|
-
"@
|
|
41
|
-
"@preact/signals-core": "^1.12.1",
|
|
39
|
+
"@effect-atom/atom-react": "^0.5.0",
|
|
42
40
|
"d3": "^7.9.0",
|
|
43
41
|
"d3-force": "~3.0.0",
|
|
44
42
|
"immutability-helper": "^3.0.2",
|
|
@@ -46,40 +44,40 @@
|
|
|
46
44
|
"lodash.defaultsdeep": "^4.6.1",
|
|
47
45
|
"react-resize-detector": "^11.0.1",
|
|
48
46
|
"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/
|
|
47
|
+
"@dxos/async": "0.8.4-main.765dc60934",
|
|
48
|
+
"@dxos/debug": "0.8.4-main.765dc60934",
|
|
49
|
+
"@dxos/invariant": "0.8.4-main.765dc60934",
|
|
50
|
+
"@dxos/log": "0.8.4-main.765dc60934",
|
|
51
|
+
"@dxos/node-std": "0.8.4-main.765dc60934",
|
|
52
|
+
"@dxos/react-ui-mosaic": "0.8.4-main.765dc60934",
|
|
53
|
+
"@dxos/graph": "0.8.4-main.765dc60934"
|
|
56
54
|
},
|
|
57
55
|
"devDependencies": {
|
|
58
56
|
"@babel/core": "^7.18.13",
|
|
59
57
|
"@types/d3": "^7.4.3",
|
|
60
58
|
"@types/lodash.defaultsdeep": "^4.6.6",
|
|
61
|
-
"@types/react": "~19.2.
|
|
62
|
-
"@types/react-dom": "~19.2.
|
|
59
|
+
"@types/react": "~19.2.7",
|
|
60
|
+
"@types/react-dom": "~19.2.3",
|
|
63
61
|
"@types/topojson-client": "^3.1.4",
|
|
64
62
|
"@types/topojson-specification": "^1.0.5",
|
|
65
|
-
"postcss": "^8.
|
|
66
|
-
"react": "~19.2.
|
|
67
|
-
"react-dom": "~19.2.
|
|
68
|
-
"@dxos/
|
|
69
|
-
"@dxos/react-ui
|
|
70
|
-
"@dxos/
|
|
71
|
-
"@dxos/
|
|
72
|
-
"@dxos/
|
|
73
|
-
"@dxos/
|
|
63
|
+
"postcss": "^8.5.12",
|
|
64
|
+
"react": "~19.2.3",
|
|
65
|
+
"react-dom": "~19.2.3",
|
|
66
|
+
"@dxos/random": "0.8.4-main.765dc60934",
|
|
67
|
+
"@dxos/react-ui": "0.8.4-main.765dc60934",
|
|
68
|
+
"@dxos/react-ui-stack": "0.8.4-main.765dc60934",
|
|
69
|
+
"@dxos/storybook-utils": "0.8.4-main.765dc60934",
|
|
70
|
+
"@dxos/ui-theme": "0.8.4-main.765dc60934",
|
|
71
|
+
"@dxos/react-ui-syntax-highlighter": "0.8.4-main.765dc60934"
|
|
74
72
|
},
|
|
75
73
|
"peerDependencies": {
|
|
76
|
-
"react": "
|
|
77
|
-
"react-dom": "
|
|
78
|
-
"@dxos/
|
|
79
|
-
"@dxos/react-ui": "0.8.4-main.
|
|
74
|
+
"react": "~19.2.3",
|
|
75
|
+
"react-dom": "~19.2.3",
|
|
76
|
+
"@dxos/ui-theme": "0.8.4-main.765dc60934",
|
|
77
|
+
"@dxos/react-ui": "0.8.4-main.765dc60934"
|
|
80
78
|
},
|
|
81
79
|
"optionalDependencies": {
|
|
82
|
-
"@dxos/random": "0.8.4-main.
|
|
80
|
+
"@dxos/random": "0.8.4-main.765dc60934"
|
|
83
81
|
},
|
|
84
82
|
"publishConfig": {
|
|
85
83
|
"access": "public"
|
|
@@ -2,17 +2,20 @@
|
|
|
2
2
|
// Copyright 2022 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import
|
|
5
|
+
import '../../../styles/graph.css';
|
|
6
|
+
|
|
7
|
+
import { RegistryContext } from '@effect-atom/atom-react';
|
|
6
8
|
import { type Meta, type StoryObj } from '@storybook/react-vite';
|
|
7
9
|
import { select } from 'd3';
|
|
8
|
-
import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
10
|
+
import React, { useCallback, useContext, useEffect, useMemo, useRef, useState } from 'react';
|
|
9
11
|
|
|
10
|
-
import { type Graph, type GraphModel, SelectionModel } from '@dxos/graph';
|
|
12
|
+
import { type Graph, type GraphModel, type SelectionMode, SelectionModel } from '@dxos/graph';
|
|
11
13
|
import { IconButton, Popover, Toolbar } from '@dxos/react-ui';
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
14
|
+
import { Card } from '@dxos/react-ui';
|
|
15
|
+
import { JsonHighlighter, Syntax } 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';
|
|
16
19
|
|
|
17
20
|
import { Pulsar } from '../../fx';
|
|
18
21
|
import {
|
|
@@ -31,11 +34,8 @@ import {
|
|
|
31
34
|
import { type SVGContext } from '../../hooks';
|
|
32
35
|
import { TestGraphModel, type TestNode, convertTreeToGraph, createGraph, createNode, createTree } from '../../testing';
|
|
33
36
|
import { SVG, type SVGGridProps } from '../SVG';
|
|
34
|
-
|
|
35
37
|
import { Graph as GraphComponent, type GraphController, type GraphProps } from './Graph';
|
|
36
38
|
|
|
37
|
-
import '../../../styles/graph.css';
|
|
38
|
-
|
|
39
39
|
type ProjectorType = 'force' | 'radial' | 'hierarchical' | 'relational';
|
|
40
40
|
|
|
41
41
|
type Factory = {
|
|
@@ -49,12 +49,12 @@ const projectorTypes: Record<ProjectorType, Factory> = {
|
|
|
49
49
|
relational: GraphRelationalProjector as Factory,
|
|
50
50
|
};
|
|
51
51
|
|
|
52
|
-
type
|
|
52
|
+
type DefaultStoryProps = GraphProps & {
|
|
53
53
|
debug?: boolean;
|
|
54
54
|
grid?: boolean | SVGGridProps;
|
|
55
55
|
inspect?: boolean;
|
|
56
|
-
|
|
57
|
-
|
|
56
|
+
graph: () => Graph.Any;
|
|
57
|
+
selectionMode?: SelectionMode;
|
|
58
58
|
projectorType?: ProjectorType;
|
|
59
59
|
projectorOptions?:
|
|
60
60
|
| GraphForceProjectorOptions
|
|
@@ -67,18 +67,22 @@ const DefaultStory = ({
|
|
|
67
67
|
debug,
|
|
68
68
|
grid,
|
|
69
69
|
inspect,
|
|
70
|
-
|
|
70
|
+
selectionMode,
|
|
71
71
|
graph: _graph,
|
|
72
72
|
projectorType: _projectorType = 'force',
|
|
73
73
|
projectorOptions,
|
|
74
74
|
...props
|
|
75
|
-
}:
|
|
75
|
+
}: DefaultStoryProps) => {
|
|
76
76
|
const graphRef = useRef<GraphController | null>(null);
|
|
77
77
|
const context = useRef<SVGContext>(null);
|
|
78
|
+
const registry = useContext(RegistryContext);
|
|
78
79
|
|
|
79
80
|
// Models.
|
|
80
|
-
const
|
|
81
|
-
const
|
|
81
|
+
const selection = useMemo(() => new SelectionModel({ mode: selectionMode }), [selectionMode]);
|
|
82
|
+
const [model, setModel] = useState<GraphModel.ReactiveGraphModel | undefined>(() => {
|
|
83
|
+
const graph = _graph?.();
|
|
84
|
+
return graph ? new TestGraphModel(registry, graph) : undefined;
|
|
85
|
+
});
|
|
82
86
|
|
|
83
87
|
// Projector.
|
|
84
88
|
const [projectorType, setProjectorType] = useState<ProjectorType>(_projectorType);
|
|
@@ -155,8 +159,9 @@ const DefaultStory = ({
|
|
|
155
159
|
}, [model]);
|
|
156
160
|
|
|
157
161
|
const handleRegenerate = useCallback(() => {
|
|
158
|
-
|
|
159
|
-
|
|
162
|
+
const graph = _graph?.();
|
|
163
|
+
setModel(graph ? new TestGraphModel(registry, graph) : undefined);
|
|
164
|
+
}, [_graph, registry]);
|
|
160
165
|
|
|
161
166
|
const handleClear = useCallback(() => {
|
|
162
167
|
setModel(undefined);
|
|
@@ -180,7 +185,7 @@ const DefaultStory = ({
|
|
|
180
185
|
|
|
181
186
|
const active = useMemo(() => new SelectionModel(), []);
|
|
182
187
|
const handlePing = useCallback(() => {
|
|
183
|
-
for (const id of active.
|
|
188
|
+
for (const id of active.getSelectedIds()) {
|
|
184
189
|
const node = graphRef.current?.findNode(id);
|
|
185
190
|
if (node) {
|
|
186
191
|
Pulsar.remove(select(node));
|
|
@@ -188,7 +193,7 @@ const DefaultStory = ({
|
|
|
188
193
|
}
|
|
189
194
|
|
|
190
195
|
active.clear();
|
|
191
|
-
for (const id of selection.
|
|
196
|
+
for (const id of selection.getSelectedIds()) {
|
|
192
197
|
const node = graphRef.current?.findNode(id);
|
|
193
198
|
if (node) {
|
|
194
199
|
active.add(id);
|
|
@@ -200,7 +205,7 @@ const DefaultStory = ({
|
|
|
200
205
|
|
|
201
206
|
return (
|
|
202
207
|
<Popover.Root open={!!popover} onOpenChange={(state) => !state && setPopover(undefined)}>
|
|
203
|
-
<div className={mx('
|
|
208
|
+
<div className={mx('h-full w-full grid divide-x divide-separator', debug && 'grid-cols-[1fr_30rem]')}>
|
|
204
209
|
<SVG.Root ref={context}>
|
|
205
210
|
<SVG.Markers />
|
|
206
211
|
{grid && <SVG.Grid {...(typeof grid === 'boolean' ? { axis: grid } : grid)} />}
|
|
@@ -254,13 +259,9 @@ const DefaultStory = ({
|
|
|
254
259
|
<Popover.VirtualTrigger virtualRef={popoverAnchorRef} />
|
|
255
260
|
<Popover.Content onOpenAutoFocus={(event) => event.preventDefault()}>
|
|
256
261
|
<Popover.Viewport>
|
|
257
|
-
<Card.
|
|
258
|
-
<
|
|
259
|
-
|
|
260
|
-
classNames='text-xs mlb-cardSpacingBlock pli-cardSpacingInline bg-transparent'
|
|
261
|
-
code={JSON.stringify(popover, null, 2)}
|
|
262
|
-
/>
|
|
263
|
-
</Card.SurfaceRoot>
|
|
262
|
+
<Card.Root>
|
|
263
|
+
<JsonHighlighter data={popover} classNames='text-xs my-form-padding px-form-padding bg-transparent' />
|
|
264
|
+
</Card.Root>
|
|
264
265
|
</Popover.Viewport>
|
|
265
266
|
<Popover.Arrow />
|
|
266
267
|
</Popover.Content>
|
|
@@ -281,7 +282,7 @@ const Debug = ({
|
|
|
281
282
|
onDelete,
|
|
282
283
|
onPing,
|
|
283
284
|
}: {
|
|
284
|
-
model?: GraphModel;
|
|
285
|
+
model?: GraphModel.ReactiveGraphModel;
|
|
285
286
|
selection: SelectionModel;
|
|
286
287
|
projector: ProjectorType;
|
|
287
288
|
onToggleProjector: () => void;
|
|
@@ -295,12 +296,10 @@ const Debug = ({
|
|
|
295
296
|
}) => {
|
|
296
297
|
const [data, setData] = useState({});
|
|
297
298
|
useEffect(() => {
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
model: model?.toJSON(),
|
|
303
|
-
});
|
|
299
|
+
setData({
|
|
300
|
+
projector,
|
|
301
|
+
selection: selection.toJSON(),
|
|
302
|
+
model: model?.toJSON(),
|
|
304
303
|
});
|
|
305
304
|
}, [model, selection, projector]);
|
|
306
305
|
|
|
@@ -316,7 +315,14 @@ const Debug = ({
|
|
|
316
315
|
<IconButton onClick={onDelete} label='Delete' icon='ph--x--regular' iconOnly />
|
|
317
316
|
<IconButton onClick={onPing} label='Delete' icon='ph--crosshair-simple--regular' iconOnly />
|
|
318
317
|
</Toolbar.Root>
|
|
319
|
-
<
|
|
318
|
+
<Syntax.Root data={data}>
|
|
319
|
+
<Syntax.Content>
|
|
320
|
+
<Syntax.Filter />
|
|
321
|
+
<Syntax.Viewport>
|
|
322
|
+
<Syntax.Code classNames='text-sm' />
|
|
323
|
+
</Syntax.Viewport>
|
|
324
|
+
</Syntax.Content>
|
|
325
|
+
</Syntax.Root>
|
|
320
326
|
</div>
|
|
321
327
|
);
|
|
322
328
|
};
|
|
@@ -324,7 +330,7 @@ const Debug = ({
|
|
|
324
330
|
const meta = {
|
|
325
331
|
title: 'ui/react-ui-graph/Graph',
|
|
326
332
|
render: DefaultStory,
|
|
327
|
-
decorators: [withTheme],
|
|
333
|
+
decorators: [withRegistry, withTheme(), withLayout({ layout: 'fullscreen' })],
|
|
328
334
|
parameters: {
|
|
329
335
|
layout: 'fullscreen',
|
|
330
336
|
controls: { disable: true },
|
|
@@ -353,7 +359,7 @@ export const Projector: Story = {
|
|
|
353
359
|
debug: true,
|
|
354
360
|
drag: true,
|
|
355
361
|
arrows: true,
|
|
356
|
-
|
|
362
|
+
selectionMode: 'single',
|
|
357
363
|
projectorType: 'hierarchical',
|
|
358
364
|
projectorOptions: {
|
|
359
365
|
duration: 500,
|
|
@@ -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,
|
|
@@ -57,25 +56,25 @@ export const GraphInner = <Node extends BaseGraphNode = any, Edge extends BaseGr
|
|
|
57
56
|
const graphRef = useRef<SVGGElement>(null);
|
|
58
57
|
|
|
59
58
|
const { projector, renderer } = useMemo(() => {
|
|
60
|
-
let projector =
|
|
59
|
+
let projector = projectorProp;
|
|
61
60
|
if (!projector) {
|
|
62
61
|
projector = new GraphForceProjector<Node>(context);
|
|
63
62
|
}
|
|
64
63
|
|
|
65
|
-
let renderer =
|
|
64
|
+
let renderer = rendererProp;
|
|
66
65
|
if (!renderer) {
|
|
67
66
|
renderer = new GraphRenderer<Node>(context, graphRef, {
|
|
68
67
|
...props,
|
|
69
68
|
// TODO(burdon): Replace drag when projector is updated.
|
|
70
69
|
drag: drag ? createGraphDrag(context, projector) : undefined,
|
|
71
70
|
arrows: { end: arrows },
|
|
72
|
-
onNodeClick: onSelect
|
|
73
|
-
onNodePointerEnter: onInspect
|
|
71
|
+
onNodeClick: onSelect,
|
|
72
|
+
onNodePointerEnter: onInspect,
|
|
74
73
|
});
|
|
75
74
|
}
|
|
76
75
|
|
|
77
76
|
return { projector, renderer };
|
|
78
|
-
}, [context,
|
|
77
|
+
}, [context, projectorProp, rendererProp, drag]);
|
|
79
78
|
|
|
80
79
|
// External API.
|
|
81
80
|
useImperativeHandle(
|
|
@@ -96,16 +95,22 @@ export const GraphInner = <Node extends BaseGraphNode = any, Edge extends BaseGr
|
|
|
96
95
|
|
|
97
96
|
// Subscriptions.
|
|
98
97
|
useEffect(() => {
|
|
98
|
+
projector.updateData(model?.graph);
|
|
99
|
+
|
|
99
100
|
return combine(
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
101
|
+
// Subscribe to model changes if reactive model.
|
|
102
|
+
model
|
|
103
|
+
? model.subscribe(() => {
|
|
104
|
+
projector.updateData(model?.graph);
|
|
105
|
+
})
|
|
106
|
+
: undefined,
|
|
107
|
+
|
|
103
108
|
projector.updated.on(({ layout }) => {
|
|
104
109
|
try {
|
|
105
110
|
renderer.render(layout);
|
|
106
111
|
} catch (error) {
|
|
107
|
-
void projector.stop();
|
|
108
112
|
log.catch(error);
|
|
113
|
+
void projector.stop();
|
|
109
114
|
}
|
|
110
115
|
}),
|
|
111
116
|
);
|
|
@@ -125,6 +130,6 @@ export const GraphInner = <Node extends BaseGraphNode = any, Edge extends BaseGr
|
|
|
125
130
|
/**
|
|
126
131
|
* SVG Graph.
|
|
127
132
|
*/
|
|
128
|
-
export const Graph = forwardRef(GraphInner) as <Node extends
|
|
133
|
+
export const Graph = forwardRef(GraphInner) as <Node extends Graph$.Node.Any = any, Edge extends Graph$.Edge.Any = any>(
|
|
129
134
|
props: GraphProps<Node, Edge> & { ref?: Ref<GraphController> },
|
|
130
135
|
) => JSX.Element;
|
|
@@ -5,10 +5,9 @@
|
|
|
5
5
|
import { type Meta, type StoryObj } from '@storybook/react-vite';
|
|
6
6
|
import React, { useEffect, useState } from 'react';
|
|
7
7
|
|
|
8
|
-
import { withTheme } from '@dxos/react-ui/testing';
|
|
8
|
+
import { withLayout, withTheme } from '@dxos/react-ui/testing';
|
|
9
9
|
|
|
10
10
|
import { SVG, type SVGRootProps } from '../SVG';
|
|
11
|
-
|
|
12
11
|
import { Mesh } from './Mesh';
|
|
13
12
|
|
|
14
13
|
// TODO(burdon): Create waves/game of life.
|
|
@@ -37,7 +36,7 @@ const DefaultStory = (props: SVGRootProps) => {
|
|
|
37
36
|
const meta = {
|
|
38
37
|
title: 'ui/react-ui-graph/Mesh',
|
|
39
38
|
render: DefaultStory,
|
|
40
|
-
decorators: [withTheme],
|
|
39
|
+
decorators: [withTheme(), withLayout({ layout: 'fullscreen' })],
|
|
41
40
|
parameters: {
|
|
42
41
|
layout: 'fullscreen',
|
|
43
42
|
},
|
|
@@ -47,18 +46,20 @@ export default meta;
|
|
|
47
46
|
|
|
48
47
|
type Story = StoryObj<typeof meta>;
|
|
49
48
|
|
|
49
|
+
// Selectors use the descendant combinator (`[&_X]`) — the mesh / hexagon / border elements
|
|
50
|
+
// live inside the SVG inside the div, so direct-child (`>`) selectors don't match.
|
|
50
51
|
export const Default: Story = {
|
|
51
52
|
args: {
|
|
52
53
|
classNames: [
|
|
53
|
-
'[
|
|
54
|
-
'[
|
|
55
|
-
'[
|
|
54
|
+
'[&_.mesh]:fill-none',
|
|
55
|
+
'[&_.hexagon>path.fill]:fill-blue-800 [&_.hexagon]:stroke-blue-700',
|
|
56
|
+
'[&_.border]:fill-none [&_.border]:stroke-blue-500 [&_.border]:stroke-2',
|
|
56
57
|
],
|
|
57
58
|
},
|
|
58
59
|
};
|
|
59
60
|
|
|
60
61
|
export const Outline: Story = {
|
|
61
62
|
args: {
|
|
62
|
-
classNames: ['[
|
|
63
|
+
classNames: ['[&_.mesh]:fill-none', '[&_.border]:fill-none [&_.border]:stroke-red-500 [&_.border]:stroke-2'],
|
|
63
64
|
},
|
|
64
65
|
};
|
|
@@ -20,43 +20,51 @@ export const Mesh = ({ radius = 16, value = 0.5 }: MeshProps) => {
|
|
|
20
20
|
const { svg, size } = useSvgContext();
|
|
21
21
|
|
|
22
22
|
useEffect(() => {
|
|
23
|
-
if (size) {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
23
|
+
if (!size) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const topology = hexTopology(size, radius, value);
|
|
28
|
+
const projection = hexProjection(radius);
|
|
29
|
+
const path = geoPath().projection(projection);
|
|
30
|
+
|
|
31
|
+
// Replace the previous render: idempotent join on a single keyed root group, then
|
|
32
|
+
// recreate the inner layers. Without this the effect re-runs (e.g. animating `value`
|
|
33
|
+
// or on resize) appended new groups on top of the old ones instead of replacing them.
|
|
34
|
+
const root = select(svg)
|
|
35
|
+
.selectAll<SVGGElement, null>('g.dx-mesh-root')
|
|
36
|
+
.data([null])
|
|
37
|
+
.join('g')
|
|
38
|
+
.classed('dx-mesh-root', true);
|
|
39
|
+
root.selectAll('*').remove();
|
|
40
|
+
|
|
41
|
+
root
|
|
42
|
+
.append('g')
|
|
43
|
+
.attr('class', 'hexagon')
|
|
44
|
+
.selectAll('path')
|
|
45
|
+
.data(topology.objects.hexagons.geometries)
|
|
46
|
+
.enter()
|
|
47
|
+
.append('path')
|
|
48
|
+
.attr('d', (d) => path(feature(topology, d)))
|
|
49
|
+
.attr('class', (d) => ((d.properties as Custom)?.fill ? 'fill' : null));
|
|
50
|
+
|
|
51
|
+
root.append('path').datum(mesh(topology, topology.objects.hexagons)).attr('class', 'mesh').attr('d', path);
|
|
52
|
+
|
|
53
|
+
const redraw = (border: any) => {
|
|
54
|
+
border.attr(
|
|
55
|
+
'd',
|
|
56
|
+
path(
|
|
57
|
+
mesh(
|
|
58
|
+
topology,
|
|
59
|
+
topology.objects.hexagons,
|
|
60
|
+
(a, b) => (a.properties as Custom).fill !== (b.properties as Custom).fill,
|
|
53
61
|
),
|
|
54
|
-
)
|
|
55
|
-
|
|
62
|
+
),
|
|
63
|
+
);
|
|
64
|
+
};
|
|
56
65
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
}, [svg, size, value]);
|
|
66
|
+
root.append('path').attr('class', 'border').call(redraw);
|
|
67
|
+
}, [svg, size, value, radius]);
|
|
60
68
|
|
|
61
69
|
return null;
|
|
62
70
|
};
|
|
@@ -3,26 +3,58 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
import { select } from 'd3';
|
|
6
|
-
import React, {
|
|
7
|
-
|
|
6
|
+
import React, {
|
|
7
|
+
type ComponentPropsWithoutRef,
|
|
8
|
+
type PropsWithChildren,
|
|
9
|
+
forwardRef,
|
|
10
|
+
useEffect,
|
|
11
|
+
useImperativeHandle,
|
|
12
|
+
useMemo,
|
|
13
|
+
useState,
|
|
14
|
+
} from 'react';
|
|
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.
|
|
26
|
+
*
|
|
27
|
+
* NOTE: Uses `ResizeObserver` directly rather than `react-resize-detector` — the latter's
|
|
28
|
+
* `useResizeDetector` was flaky in our Storybook environment (sometimes never fired its
|
|
29
|
+
* initial measurement), leaving the SVG stuck at `opacity-0` with no rendered content.
|
|
19
30
|
*/
|
|
20
|
-
export const Root = forwardRef<SVGContext, RootProps>(({
|
|
21
|
-
const
|
|
31
|
+
export const Root = forwardRef<SVGContext, RootProps>(({ children, scale, centered, ...props }, ref) => {
|
|
32
|
+
const [container, setContainer] = useState<HTMLDivElement | null>(null);
|
|
33
|
+
const [size, setSize] = useState<{ width: number; height: number }>({ width: 0, height: 0 });
|
|
34
|
+
|
|
35
|
+
useEffect(() => {
|
|
36
|
+
if (!container) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
const rect = container.getBoundingClientRect();
|
|
40
|
+
setSize({ width: rect.width, height: rect.height });
|
|
41
|
+
const observer = new ResizeObserver((entries) => {
|
|
42
|
+
const entry = entries[0];
|
|
43
|
+
if (!entry) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
const { width, height } = entry.contentRect;
|
|
47
|
+
setSize((prev) => (prev.width === width && prev.height === height ? prev : { width, height }));
|
|
48
|
+
});
|
|
49
|
+
observer.observe(container);
|
|
50
|
+
return () => observer.disconnect();
|
|
51
|
+
}, [container]);
|
|
52
|
+
|
|
53
|
+
const { width, height } = size;
|
|
22
54
|
|
|
23
55
|
const context = useMemo<SVGContext>(() => {
|
|
24
|
-
return new SVGContext(
|
|
25
|
-
}, [
|
|
56
|
+
return new SVGContext({ scale, centered });
|
|
57
|
+
}, [scale, centered]);
|
|
26
58
|
|
|
27
59
|
useImperativeHandle(ref, () => context, [context]);
|
|
28
60
|
|
|
@@ -41,7 +73,7 @@ export const Root = forwardRef<SVGContext, RootProps>(({ classNames, children, .
|
|
|
41
73
|
|
|
42
74
|
return (
|
|
43
75
|
<SVGContextProvider value={context}>
|
|
44
|
-
<div
|
|
76
|
+
<div {...composableProps(props, { classNames: 'dx-expander' })} ref={setContainer}>
|
|
45
77
|
<svg
|
|
46
78
|
xmlns='http://www.w3.org/2000/svg'
|
|
47
79
|
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,
|