@dxos/react-ui-graph 0.8.3 → 0.8.4-main.03d5cd7b56
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-EASNZZ7B.mjs +52 -0
- package/dist/lib/browser/chunk-EASNZZ7B.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +1109 -319
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +19 -19
- 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 +1109 -319
- 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 +19 -19
- 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 +21 -12
- 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 +10 -6
- 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 +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/components/SVG/Zoom.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/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 +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 +2 -2
- 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 +2 -2
- package/dist/types/src/graph/projector/graph-hierarchical-projector.d.ts.map +1 -1
- package/dist/types/src/graph/projector/graph-projector.d.ts +4 -4
- package/dist/types/src/graph/projector/graph-projector.d.ts.map +1 -1
- package/dist/types/src/graph/projector/graph-radial-projector.d.ts +2 -2
- 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 +2 -2
- 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 +1 -1
- package/dist/types/src/graph/renderer/graph-renderer.d.ts.map +1 -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 +15 -10
- 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/index.d.ts +2 -2
- package/dist/types/src/util/index.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 +1 -1
- package/dist/types/src/util/screen.d.ts.map +1 -1
- package/dist/types/src/util/vector.d.ts +1 -1
- package/dist/types/src/util/vector.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +32 -34
- package/src/components/Graph/Graph.stories.tsx +73 -69
- package/src/components/Graph/Graph.tsx +25 -20
- package/src/components/Mesh/Mesh.stories.tsx +10 -9
- package/src/components/Mesh/Mesh.tsx +1 -1
- package/src/components/SVG/Grid.tsx +2 -2
- package/src/components/SVG/Markers.tsx +1 -1
- package/src/components/SVG/Root.tsx +14 -7
- package/src/components/SVG/SVG.tsx +13 -4
- package/src/components/SVG/Svg.stories.tsx +23 -19
- package/src/components/SVG/Zoom.tsx +1 -1
- package/src/fx/fx.stories.tsx +18 -15
- package/src/graph/projector/graph-drag.ts +1 -1
- package/src/graph/projector/graph-force-projector.ts +3 -3
- package/src/graph/projector/graph-forces.ts +1 -1
- package/src/graph/projector/graph-hierarchical-projector.ts +4 -4
- package/src/graph/projector/graph-projector.ts +5 -5
- package/src/graph/projector/graph-radial-projector.ts +3 -3
- package/src/graph/projector/graph-relational-projector.ts +4 -4
- package/src/graph/projector/projector.ts +1 -1
- package/src/graph/renderer/bullets.ts +1 -1
- package/src/graph/renderer/graph-renderer.ts +7 -7
- package/src/graph/renderer/renderer.ts +1 -1
- package/src/graph/types.ts +1 -1
- package/src/hooks/useStateRef.ts +1 -1
- package/src/hooks/useZoom.ts +1 -1
- package/src/stories/hooks.stories.tsx +43 -36
- package/src/testing/data.ts +14 -14
- package/src/testing/hooks.ts +5 -5
- package/src/testing/model.ts +6 -6
- package/src/util/fraction.ts +1 -1
- package/src/util/index.ts +2 -2
- package/src/util/screen.test.ts +1 -1
- package/src/util/screen.ts +1 -1
- package/src/util/vector.ts +1 -1
- package/styles/graph.css +292 -43
- package/dist/lib/browser/chunk-2YMRPQU7.mjs +0 -979
- package/dist/lib/browser/chunk-2YMRPQU7.mjs.map +0 -7
- package/dist/lib/node/chunk-WFHWEMPB.cjs +0 -919
- package/dist/lib/node/chunk-WFHWEMPB.cjs.map +0 -7
- package/dist/lib/node/index.cjs +0 -1547
- package/dist/lib/node/index.cjs.map +0 -7
- package/dist/lib/node/meta.json +0 -1
- package/dist/lib/node/testing/index.cjs +0 -214
- package/dist/lib/node/testing/index.cjs.map +0 -7
- package/dist/lib/node-esm/chunk-ITHTKQOY.mjs +0 -981
- package/dist/lib/node-esm/chunk-ITHTKQOY.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.
|
|
3
|
+
"version": "0.8.4-main.03d5cd7b56",
|
|
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
|
".": {
|
|
@@ -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.9.0",
|
|
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/
|
|
50
|
-
"@dxos/
|
|
51
|
-
"@dxos/
|
|
52
|
-
"@dxos/
|
|
53
|
-
"@dxos/
|
|
54
|
-
"@dxos/
|
|
55
|
-
"@dxos/
|
|
47
|
+
"@dxos/async": "0.8.4-main.03d5cd7b56",
|
|
48
|
+
"@dxos/debug": "0.8.4-main.03d5cd7b56",
|
|
49
|
+
"@dxos/graph": "0.8.4-main.03d5cd7b56",
|
|
50
|
+
"@dxos/invariant": "0.8.4-main.03d5cd7b56",
|
|
51
|
+
"@dxos/react-ui-mosaic": "0.8.4-main.03d5cd7b56",
|
|
52
|
+
"@dxos/log": "0.8.4-main.03d5cd7b56",
|
|
53
|
+
"@dxos/node-std": "0.8.4-main.03d5cd7b56"
|
|
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": "~
|
|
62
|
-
"@types/react-dom": "~
|
|
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": "~
|
|
67
|
-
"react-dom": "~
|
|
68
|
-
"@dxos/random": "0.8.
|
|
69
|
-
"@dxos/react-ui": "0.8.
|
|
70
|
-
"@dxos/react-ui-stack": "0.8.
|
|
71
|
-
"@dxos/react-ui-
|
|
72
|
-
"@dxos/
|
|
73
|
-
"@dxos/storybook-utils": "0.8.
|
|
63
|
+
"postcss": "^8.5.12",
|
|
64
|
+
"react": "~19.2.3",
|
|
65
|
+
"react-dom": "~19.2.3",
|
|
66
|
+
"@dxos/random": "0.8.4-main.03d5cd7b56",
|
|
67
|
+
"@dxos/react-ui": "0.8.4-main.03d5cd7b56",
|
|
68
|
+
"@dxos/react-ui-stack": "0.8.4-main.03d5cd7b56",
|
|
69
|
+
"@dxos/react-ui-syntax-highlighter": "0.8.4-main.03d5cd7b56",
|
|
70
|
+
"@dxos/ui-theme": "0.8.4-main.03d5cd7b56",
|
|
71
|
+
"@dxos/storybook-utils": "0.8.4-main.03d5cd7b56"
|
|
74
72
|
},
|
|
75
73
|
"peerDependencies": {
|
|
76
|
-
"react": "~
|
|
77
|
-
"react-dom": "~
|
|
78
|
-
"@dxos/react-ui": "0.8.
|
|
79
|
-
"@dxos/
|
|
74
|
+
"react": "~19.2.3",
|
|
75
|
+
"react-dom": "~19.2.3",
|
|
76
|
+
"@dxos/react-ui": "0.8.4-main.03d5cd7b56",
|
|
77
|
+
"@dxos/ui-theme": "0.8.4-main.03d5cd7b56"
|
|
80
78
|
},
|
|
81
79
|
"optionalDependencies": {
|
|
82
|
-
"@dxos/random": "0.8.
|
|
80
|
+
"@dxos/random": "0.8.4-main.03d5cd7b56"
|
|
83
81
|
},
|
|
84
82
|
"publishConfig": {
|
|
85
83
|
"access": "public"
|
|
@@ -2,40 +2,39 @@
|
|
|
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';
|
|
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
|
-
import { type
|
|
12
|
+
import { type Graph, type GraphModel, type SelectionMode, 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 { 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';
|
|
18
19
|
|
|
19
|
-
import { Graph as GraphComponent, type GraphController, type GraphProps } from './Graph';
|
|
20
20
|
import { Pulsar } from '../../fx';
|
|
21
21
|
import {
|
|
22
22
|
GraphForceProjector,
|
|
23
23
|
type GraphForceProjectorOptions,
|
|
24
24
|
GraphHierarchicalProjector,
|
|
25
25
|
type GraphHierarchicalProjectorOptions,
|
|
26
|
+
type GraphLayoutEdge,
|
|
27
|
+
type GraphLayoutNode,
|
|
28
|
+
type GraphProjector,
|
|
26
29
|
GraphRadialProjector,
|
|
27
30
|
type GraphRadialProjectorOptions,
|
|
28
31
|
GraphRelationalProjector,
|
|
29
32
|
type GraphRelationalProjectorOptions,
|
|
30
|
-
type GraphLayoutEdge,
|
|
31
|
-
type GraphLayoutNode,
|
|
32
|
-
type GraphProjector,
|
|
33
33
|
} from '../../graph';
|
|
34
34
|
import { type SVGContext } from '../../hooks';
|
|
35
|
-
import { convertTreeToGraph, createGraph, createNode, createTree
|
|
35
|
+
import { TestGraphModel, type TestNode, convertTreeToGraph, createGraph, createNode, createTree } from '../../testing';
|
|
36
36
|
import { SVG, type SVGGridProps } from '../SVG';
|
|
37
|
-
|
|
38
|
-
import '../../../styles/graph.css';
|
|
37
|
+
import { Graph as GraphComponent, type GraphController, type GraphProps } from './Graph';
|
|
39
38
|
|
|
40
39
|
type ProjectorType = 'force' | 'radial' | 'hierarchical' | 'relational';
|
|
41
40
|
|
|
@@ -50,12 +49,12 @@ const projectorTypes: Record<ProjectorType, Factory> = {
|
|
|
50
49
|
relational: GraphRelationalProjector as Factory,
|
|
51
50
|
};
|
|
52
51
|
|
|
53
|
-
type
|
|
52
|
+
type DefaultStoryProps = GraphProps & {
|
|
54
53
|
debug?: boolean;
|
|
55
54
|
grid?: boolean | SVGGridProps;
|
|
56
55
|
inspect?: boolean;
|
|
57
|
-
|
|
58
|
-
|
|
56
|
+
graph: () => Graph.Any;
|
|
57
|
+
selectionMode?: SelectionMode;
|
|
59
58
|
projectorType?: ProjectorType;
|
|
60
59
|
projectorOptions?:
|
|
61
60
|
| GraphForceProjectorOptions
|
|
@@ -68,18 +67,22 @@ const DefaultStory = ({
|
|
|
68
67
|
debug,
|
|
69
68
|
grid,
|
|
70
69
|
inspect,
|
|
71
|
-
|
|
70
|
+
selectionMode,
|
|
72
71
|
graph: _graph,
|
|
73
72
|
projectorType: _projectorType = 'force',
|
|
74
73
|
projectorOptions,
|
|
75
74
|
...props
|
|
76
|
-
}:
|
|
75
|
+
}: DefaultStoryProps) => {
|
|
77
76
|
const graphRef = useRef<GraphController | null>(null);
|
|
78
77
|
const context = useRef<SVGContext>(null);
|
|
78
|
+
const registry = useContext(RegistryContext);
|
|
79
79
|
|
|
80
80
|
// Models.
|
|
81
|
-
const
|
|
82
|
-
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
|
+
});
|
|
83
86
|
|
|
84
87
|
// Projector.
|
|
85
88
|
const [projectorType, setProjectorType] = useState<ProjectorType>(_projectorType);
|
|
@@ -156,8 +159,9 @@ const DefaultStory = ({
|
|
|
156
159
|
}, [model]);
|
|
157
160
|
|
|
158
161
|
const handleRegenerate = useCallback(() => {
|
|
159
|
-
|
|
160
|
-
|
|
162
|
+
const graph = _graph?.();
|
|
163
|
+
setModel(graph ? new TestGraphModel(registry, graph) : undefined);
|
|
164
|
+
}, [_graph, registry]);
|
|
161
165
|
|
|
162
166
|
const handleClear = useCallback(() => {
|
|
163
167
|
setModel(undefined);
|
|
@@ -181,7 +185,7 @@ const DefaultStory = ({
|
|
|
181
185
|
|
|
182
186
|
const active = useMemo(() => new SelectionModel(), []);
|
|
183
187
|
const handlePing = useCallback(() => {
|
|
184
|
-
for (const id of active.
|
|
188
|
+
for (const id of active.getSelectedIds()) {
|
|
185
189
|
const node = graphRef.current?.findNode(id);
|
|
186
190
|
if (node) {
|
|
187
191
|
Pulsar.remove(select(node));
|
|
@@ -189,7 +193,7 @@ const DefaultStory = ({
|
|
|
189
193
|
}
|
|
190
194
|
|
|
191
195
|
active.clear();
|
|
192
|
-
for (const id of selection.
|
|
196
|
+
for (const id of selection.getSelectedIds()) {
|
|
193
197
|
const node = graphRef.current?.findNode(id);
|
|
194
198
|
if (node) {
|
|
195
199
|
active.add(id);
|
|
@@ -201,7 +205,7 @@ const DefaultStory = ({
|
|
|
201
205
|
|
|
202
206
|
return (
|
|
203
207
|
<Popover.Root open={!!popover} onOpenChange={(state) => !state && setPopover(undefined)}>
|
|
204
|
-
<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]')}>
|
|
205
209
|
<SVG.Root ref={context}>
|
|
206
210
|
<SVG.Markers />
|
|
207
211
|
{grid && <SVG.Grid {...(typeof grid === 'boolean' ? { axis: grid } : grid)} />}
|
|
@@ -216,7 +220,7 @@ const DefaultStory = ({
|
|
|
216
220
|
attributes={{
|
|
217
221
|
node: (node: GraphLayoutNode<TestNode>) => ({
|
|
218
222
|
data: {
|
|
219
|
-
color:
|
|
223
|
+
color: getHashStyles(node.data?.type ?? node.type)?.hue,
|
|
220
224
|
},
|
|
221
225
|
classes: {
|
|
222
226
|
'dx-selected': selection.contains(node.id),
|
|
@@ -224,7 +228,7 @@ const DefaultStory = ({
|
|
|
224
228
|
}),
|
|
225
229
|
edge: (edge: GraphLayoutEdge<TestNode>) => ({
|
|
226
230
|
data: {
|
|
227
|
-
color:
|
|
231
|
+
color: getHashStyles(edge.data?.type ?? edge.type)?.hue,
|
|
228
232
|
},
|
|
229
233
|
}),
|
|
230
234
|
}}
|
|
@@ -255,13 +259,9 @@ const DefaultStory = ({
|
|
|
255
259
|
<Popover.VirtualTrigger virtualRef={popoverAnchorRef} />
|
|
256
260
|
<Popover.Content onOpenAutoFocus={(event) => event.preventDefault()}>
|
|
257
261
|
<Popover.Viewport>
|
|
258
|
-
<Card.
|
|
259
|
-
<
|
|
260
|
-
|
|
261
|
-
language='json'
|
|
262
|
-
code={JSON.stringify(popover, null, 2)}
|
|
263
|
-
/>
|
|
264
|
-
</Card.Container>
|
|
262
|
+
<Card.Root>
|
|
263
|
+
<JsonHighlighter data={popover} classNames='text-xs my-form-padding px-form-padding bg-transparent' />
|
|
264
|
+
</Card.Root>
|
|
265
265
|
</Popover.Viewport>
|
|
266
266
|
<Popover.Arrow />
|
|
267
267
|
</Popover.Content>
|
|
@@ -282,7 +282,7 @@ const Debug = ({
|
|
|
282
282
|
onDelete,
|
|
283
283
|
onPing,
|
|
284
284
|
}: {
|
|
285
|
-
model?: GraphModel;
|
|
285
|
+
model?: GraphModel.ReactiveGraphModel;
|
|
286
286
|
selection: SelectionModel;
|
|
287
287
|
projector: ProjectorType;
|
|
288
288
|
onToggleProjector: () => void;
|
|
@@ -296,44 +296,50 @@ const Debug = ({
|
|
|
296
296
|
}) => {
|
|
297
297
|
const [data, setData] = useState({});
|
|
298
298
|
useEffect(() => {
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
model: model?.toJSON(),
|
|
304
|
-
});
|
|
299
|
+
setData({
|
|
300
|
+
projector,
|
|
301
|
+
selection: selection.toJSON(),
|
|
302
|
+
model: model?.toJSON(),
|
|
305
303
|
});
|
|
306
304
|
}, [model, selection, projector]);
|
|
307
305
|
|
|
308
306
|
return (
|
|
309
307
|
<div className='flex flex-col overflow-hidden'>
|
|
310
308
|
<Toolbar.Root>
|
|
311
|
-
<IconButton onClick={onToggleProjector}
|
|
312
|
-
<IconButton onClick={onRefresh}
|
|
313
|
-
<IconButton onClick={onRepaint}
|
|
314
|
-
<IconButton onClick={onRegenerate}
|
|
315
|
-
<IconButton onClick={onClear}
|
|
316
|
-
<IconButton onClick={onAdd}
|
|
317
|
-
<IconButton onClick={onDelete}
|
|
318
|
-
<IconButton onClick={onPing}
|
|
309
|
+
<IconButton onClick={onToggleProjector} label='Projector' icon='ph--graph--regular' iconOnly />
|
|
310
|
+
<IconButton onClick={onRefresh} label='Refresh' icon='ph--arrow-clockwise--regular' iconOnly />
|
|
311
|
+
<IconButton onClick={onRepaint} label='Repaint' icon='ph--paint-roller--regular' iconOnly />
|
|
312
|
+
<IconButton onClick={onRegenerate} label='Regenerate' icon='ph--arrows-clockwise--regular' iconOnly />
|
|
313
|
+
<IconButton onClick={onClear} label='Clear' icon='ph--trash--regular' iconOnly />
|
|
314
|
+
<IconButton onClick={onAdd} label='Add' icon='ph--plus--regular' iconOnly />
|
|
315
|
+
<IconButton onClick={onDelete} label='Delete' icon='ph--x--regular' iconOnly />
|
|
316
|
+
<IconButton onClick={onPing} label='Delete' icon='ph--crosshair-simple--regular' iconOnly />
|
|
319
317
|
</Toolbar.Root>
|
|
320
|
-
<
|
|
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>
|
|
321
326
|
</div>
|
|
322
327
|
);
|
|
323
328
|
};
|
|
324
329
|
|
|
325
|
-
const meta
|
|
330
|
+
const meta = {
|
|
326
331
|
title: 'ui/react-ui-graph/Graph',
|
|
327
332
|
render: DefaultStory,
|
|
328
|
-
decorators: [withTheme, withLayout({
|
|
333
|
+
decorators: [withRegistry, withTheme(), withLayout({ layout: 'fullscreen' })],
|
|
329
334
|
parameters: {
|
|
335
|
+
layout: 'fullscreen',
|
|
330
336
|
controls: { disable: true },
|
|
331
337
|
},
|
|
332
|
-
}
|
|
338
|
+
} satisfies Meta<typeof DefaultStory>;
|
|
333
339
|
|
|
334
340
|
export default meta;
|
|
335
341
|
|
|
336
|
-
type Story = StoryObj<
|
|
342
|
+
type Story = StoryObj<typeof meta>;
|
|
337
343
|
|
|
338
344
|
export const Default: Story = {
|
|
339
345
|
args: {
|
|
@@ -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,
|
|
@@ -449,14 +455,12 @@ export const WithPopover: Story = {
|
|
|
449
455
|
},
|
|
450
456
|
};
|
|
451
457
|
|
|
452
|
-
export const Empty
|
|
453
|
-
|
|
454
|
-
<SVG.
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
<
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
),
|
|
462
|
-
};
|
|
458
|
+
export const Empty = () => (
|
|
459
|
+
<SVG.Root>
|
|
460
|
+
<SVG.Markers />
|
|
461
|
+
<SVG.Grid axis />
|
|
462
|
+
<SVG.Zoom extent={[1 / 4, 4]}>
|
|
463
|
+
<GraphComponent />
|
|
464
|
+
</SVG.Zoom>
|
|
465
|
+
</SVG.Root>
|
|
466
|
+
);
|
|
@@ -2,22 +2,21 @@
|
|
|
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
|
-
createGraphDrag,
|
|
16
14
|
GraphForceProjector,
|
|
17
15
|
type GraphLayoutNode,
|
|
18
16
|
type GraphProjector,
|
|
19
17
|
GraphRenderer,
|
|
20
18
|
type GraphRendererOptions,
|
|
19
|
+
createGraphDrag,
|
|
21
20
|
} from '../../graph';
|
|
22
21
|
import { useSvgContext } from '../../hooks';
|
|
23
22
|
|
|
@@ -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,28 +53,28 @@ 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
|
-
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;
|
|
@@ -2,15 +2,13 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import '@
|
|
6
|
-
|
|
7
|
-
import { type StoryObj } from '@storybook/react';
|
|
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
|
-
import { Mesh } from './Mesh';
|
|
13
10
|
import { SVG, type SVGRootProps } from '../SVG';
|
|
11
|
+
import { Mesh } from './Mesh';
|
|
14
12
|
|
|
15
13
|
// TODO(burdon): Create waves/game of life.
|
|
16
14
|
const DefaultStory = (props: SVGRootProps) => {
|
|
@@ -35,15 +33,18 @@ const DefaultStory = (props: SVGRootProps) => {
|
|
|
35
33
|
);
|
|
36
34
|
};
|
|
37
35
|
|
|
38
|
-
const meta
|
|
36
|
+
const meta = {
|
|
39
37
|
title: 'ui/react-ui-graph/Mesh',
|
|
40
38
|
render: DefaultStory,
|
|
41
|
-
decorators: [withTheme, withLayout({
|
|
42
|
-
|
|
39
|
+
decorators: [withTheme(), withLayout({ layout: 'fullscreen' })],
|
|
40
|
+
parameters: {
|
|
41
|
+
layout: 'fullscreen',
|
|
42
|
+
},
|
|
43
|
+
} satisfies Meta<typeof DefaultStory>;
|
|
43
44
|
|
|
44
45
|
export default meta;
|
|
45
46
|
|
|
46
|
-
type Story = StoryObj<typeof
|
|
47
|
+
type Story = StoryObj<typeof meta>;
|
|
47
48
|
|
|
48
49
|
export const Default: Story = {
|
|
49
50
|
args: {
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { geoPath, select
|
|
5
|
+
import { type GeoStream, geoPath, select } from 'd3';
|
|
6
6
|
import { useEffect } from 'react';
|
|
7
7
|
import { feature, mesh } from 'topojson-client';
|
|
8
8
|
import { type GeometryCollection, type GeometryObject, type Objects, type Topology } from 'topojson-specification';
|
|
@@ -5,9 +5,9 @@
|
|
|
5
5
|
import React from 'react';
|
|
6
6
|
|
|
7
7
|
import { type ThemedClassName } from '@dxos/react-ui';
|
|
8
|
-
import { mx } from '@dxos/
|
|
8
|
+
import { mx } from '@dxos/ui-theme';
|
|
9
9
|
|
|
10
|
-
import {
|
|
10
|
+
import { type GridOptions, useGrid } from '../../hooks';
|
|
11
11
|
|
|
12
12
|
export type GridProps = ThemedClassName<GridOptions>;
|
|
13
13
|
|
|
@@ -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}
|