@dxos/react-ui-graph 0.8.4-main.b97322e → 0.8.4-main.bcb3aa67d6
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 +1101 -245
- 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 +1101 -245
- 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 +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/Grid.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 +10 -8
- 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/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/useZoom.d.ts.map +1 -1
- package/dist/types/src/stories/hooks.stories.d.ts +13 -8
- 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/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 +31 -26
- package/src/components/Graph/Graph.stories.tsx +67 -60
- package/src/components/Graph/Graph.tsx +25 -17
- package/src/components/Mesh/Mesh.stories.tsx +11 -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 +14 -4
- package/src/components/SVG/Svg.stories.tsx +23 -18
- package/src/components/SVG/Zoom.tsx +1 -1
- package/src/fx/fx.stories.tsx +18 -14
- package/src/graph/projector/graph-drag.ts +2 -1
- package/src/graph/projector/graph-force-projector.ts +3 -2
- package/src/graph/projector/graph-forces.ts +1 -1
- package/src/graph/projector/graph-hierarchical-projector.ts +5 -4
- package/src/graph/projector/graph-projector.ts +6 -5
- package/src/graph/projector/graph-radial-projector.ts +4 -3
- package/src/graph/projector/graph-relational-projector.ts +5 -4
- package/src/graph/projector/projector.ts +1 -1
- package/src/graph/renderer/bullets.ts +1 -1
- package/src/graph/renderer/graph-renderer.ts +4 -3
- 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 +42 -35
- package/src/testing/data.ts +5 -5
- package/src/testing/hooks.ts +4 -3
- package/src/testing/model.ts +3 -3
- package/src/util/fraction.ts +1 -1
- 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-MGVY54T5.mjs +0 -979
- package/dist/lib/browser/chunk-MGVY54T5.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-X5YVOSXZ.mjs +0 -981
- package/dist/lib/node-esm/chunk-X5YVOSXZ.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.bcb3aa67d6",
|
|
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/async": "0.8.4-main.
|
|
50
|
-
"@dxos/
|
|
51
|
-
"@dxos/
|
|
52
|
-
"@dxos/
|
|
53
|
-
"@dxos/
|
|
54
|
-
"@dxos/
|
|
55
|
-
"@dxos/
|
|
54
|
+
"@dxos/async": "0.8.4-main.bcb3aa67d6",
|
|
55
|
+
"@dxos/invariant": "0.8.4-main.bcb3aa67d6",
|
|
56
|
+
"@dxos/log": "0.8.4-main.bcb3aa67d6",
|
|
57
|
+
"@dxos/node-std": "0.8.4-main.bcb3aa67d6",
|
|
58
|
+
"@dxos/graph": "0.8.4-main.bcb3aa67d6",
|
|
59
|
+
"@dxos/react-ui-mosaic": "0.8.4-main.bcb3aa67d6",
|
|
60
|
+
"@dxos/debug": "0.8.4-main.bcb3aa67d6"
|
|
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": "0.8.4-main.
|
|
70
|
-
"@dxos/
|
|
71
|
-
"@dxos/react-ui-
|
|
72
|
-
"@dxos/
|
|
73
|
-
"@dxos/
|
|
71
|
+
"react": "~19.2.3",
|
|
72
|
+
"react-dom": "~19.2.3",
|
|
73
|
+
"@dxos/random": "0.8.4-main.bcb3aa67d6",
|
|
74
|
+
"@dxos/react-ui-syntax-highlighter": "0.8.4-main.bcb3aa67d6",
|
|
75
|
+
"@dxos/storybook-utils": "0.8.4-main.bcb3aa67d6",
|
|
76
|
+
"@dxos/react-ui-stack": "0.8.4-main.bcb3aa67d6",
|
|
77
|
+
"@dxos/ui-theme": "0.8.4-main.bcb3aa67d6",
|
|
78
|
+
"@dxos/react-ui": "0.8.4-main.bcb3aa67d6"
|
|
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.bcb3aa67d6",
|
|
84
|
+
"@dxos/ui-theme": "0.8.4-main.bcb3aa67d6"
|
|
80
85
|
},
|
|
81
86
|
"optionalDependencies": {
|
|
82
|
-
"@dxos/random": "0.8.4-main.
|
|
87
|
+
"@dxos/random": "0.8.4-main.bcb3aa67d6"
|
|
83
88
|
},
|
|
84
89
|
"publishConfig": {
|
|
85
90
|
"access": "public"
|
|
@@ -2,39 +2,39 @@
|
|
|
2
2
|
// Copyright 2022 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import '@
|
|
6
|
-
|
|
7
|
-
import { effect } from '@preact/signals-core';
|
|
8
|
-
import { type StoryObj } from '@storybook/react-vite';
|
|
5
|
+
import { RegistryContext } from '@effect-atom/atom-react';
|
|
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
|
-
import { type GraphModel, SelectionModel
|
|
10
|
+
import { type Graph, type GraphModel, SelectionModel } from '@dxos/graph';
|
|
13
11
|
import { IconButton, Popover, Toolbar } from '@dxos/react-ui';
|
|
14
|
-
import { Card } from '@dxos/react-ui
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
12
|
+
import { Card } from '@dxos/react-ui';
|
|
13
|
+
import { withLayout, withTheme } from '@dxos/react-ui/testing';
|
|
14
|
+
import { Json, SyntaxHighlighter } from '@dxos/react-ui-syntax-highlighter';
|
|
15
|
+
import { withRegistry } from '@dxos/storybook-utils';
|
|
16
|
+
import { getHashStyles, mx } from '@dxos/ui-theme';
|
|
18
17
|
|
|
19
|
-
import { Graph as GraphComponent, type GraphController, type GraphProps } from './Graph';
|
|
20
18
|
import { Pulsar } from '../../fx';
|
|
21
19
|
import {
|
|
22
20
|
GraphForceProjector,
|
|
23
21
|
type GraphForceProjectorOptions,
|
|
24
22
|
GraphHierarchicalProjector,
|
|
25
23
|
type GraphHierarchicalProjectorOptions,
|
|
24
|
+
type GraphLayoutEdge,
|
|
25
|
+
type GraphLayoutNode,
|
|
26
|
+
type GraphProjector,
|
|
26
27
|
GraphRadialProjector,
|
|
27
28
|
type GraphRadialProjectorOptions,
|
|
28
29
|
GraphRelationalProjector,
|
|
29
30
|
type GraphRelationalProjectorOptions,
|
|
30
|
-
type GraphLayoutEdge,
|
|
31
|
-
type GraphLayoutNode,
|
|
32
|
-
type GraphProjector,
|
|
33
31
|
} from '../../graph';
|
|
34
32
|
import { type SVGContext } from '../../hooks';
|
|
35
|
-
import { convertTreeToGraph, createGraph, createNode, createTree
|
|
33
|
+
import { TestGraphModel, type TestNode, convertTreeToGraph, createGraph, createNode, createTree } from '../../testing';
|
|
36
34
|
import { SVG, type SVGGridProps } from '../SVG';
|
|
37
35
|
|
|
36
|
+
import { Graph as GraphComponent, type GraphController, type GraphProps } from './Graph';
|
|
37
|
+
|
|
38
38
|
import '../../../styles/graph.css';
|
|
39
39
|
|
|
40
40
|
type ProjectorType = 'force' | 'radial' | 'hierarchical' | 'relational';
|
|
@@ -50,12 +50,12 @@ const projectorTypes: Record<ProjectorType, Factory> = {
|
|
|
50
50
|
relational: GraphRelationalProjector as Factory,
|
|
51
51
|
};
|
|
52
52
|
|
|
53
|
-
type
|
|
53
|
+
type DefaultStoryProps = GraphProps & {
|
|
54
54
|
debug?: boolean;
|
|
55
55
|
grid?: boolean | SVGGridProps;
|
|
56
56
|
inspect?: boolean;
|
|
57
57
|
singleSelect?: boolean;
|
|
58
|
-
graph: () => Graph;
|
|
58
|
+
graph: () => Graph.Any;
|
|
59
59
|
projectorType?: ProjectorType;
|
|
60
60
|
projectorOptions?:
|
|
61
61
|
| GraphForceProjectorOptions
|
|
@@ -73,12 +73,16 @@ const DefaultStory = ({
|
|
|
73
73
|
projectorType: _projectorType = 'force',
|
|
74
74
|
projectorOptions,
|
|
75
75
|
...props
|
|
76
|
-
}:
|
|
76
|
+
}: DefaultStoryProps) => {
|
|
77
77
|
const graphRef = useRef<GraphController | null>(null);
|
|
78
78
|
const context = useRef<SVGContext>(null);
|
|
79
|
+
const registry = useContext(RegistryContext);
|
|
79
80
|
|
|
80
81
|
// Models.
|
|
81
|
-
const [model, setModel] = useState<GraphModel | undefined>(() =>
|
|
82
|
+
const [model, setModel] = useState<GraphModel.ReactiveGraphModel | undefined>(() => {
|
|
83
|
+
const graph = _graph?.();
|
|
84
|
+
return graph ? new TestGraphModel(registry, graph) : undefined;
|
|
85
|
+
});
|
|
82
86
|
const selection = useMemo(() => new SelectionModel(singleSelect), [singleSelect]);
|
|
83
87
|
|
|
84
88
|
// Projector.
|
|
@@ -156,8 +160,9 @@ const DefaultStory = ({
|
|
|
156
160
|
}, [model]);
|
|
157
161
|
|
|
158
162
|
const handleRegenerate = useCallback(() => {
|
|
159
|
-
|
|
160
|
-
|
|
163
|
+
const graph = _graph?.();
|
|
164
|
+
setModel(graph ? new TestGraphModel(registry, graph) : undefined);
|
|
165
|
+
}, [_graph, registry]);
|
|
161
166
|
|
|
162
167
|
const handleClear = useCallback(() => {
|
|
163
168
|
setModel(undefined);
|
|
@@ -181,7 +186,7 @@ const DefaultStory = ({
|
|
|
181
186
|
|
|
182
187
|
const active = useMemo(() => new SelectionModel(), []);
|
|
183
188
|
const handlePing = useCallback(() => {
|
|
184
|
-
for (const id of active.
|
|
189
|
+
for (const id of active.getSelectedIds()) {
|
|
185
190
|
const node = graphRef.current?.findNode(id);
|
|
186
191
|
if (node) {
|
|
187
192
|
Pulsar.remove(select(node));
|
|
@@ -189,7 +194,7 @@ const DefaultStory = ({
|
|
|
189
194
|
}
|
|
190
195
|
|
|
191
196
|
active.clear();
|
|
192
|
-
for (const id of selection.
|
|
197
|
+
for (const id of selection.getSelectedIds()) {
|
|
193
198
|
const node = graphRef.current?.findNode(id);
|
|
194
199
|
if (node) {
|
|
195
200
|
active.add(id);
|
|
@@ -201,7 +206,7 @@ const DefaultStory = ({
|
|
|
201
206
|
|
|
202
207
|
return (
|
|
203
208
|
<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]')}>
|
|
209
|
+
<div className={mx('h-full w-full grid divide-x divide-separator', debug && 'grid-cols-[1fr_30rem]')}>
|
|
205
210
|
<SVG.Root ref={context}>
|
|
206
211
|
<SVG.Markers />
|
|
207
212
|
{grid && <SVG.Grid {...(typeof grid === 'boolean' ? { axis: grid } : grid)} />}
|
|
@@ -216,7 +221,7 @@ const DefaultStory = ({
|
|
|
216
221
|
attributes={{
|
|
217
222
|
node: (node: GraphLayoutNode<TestNode>) => ({
|
|
218
223
|
data: {
|
|
219
|
-
color:
|
|
224
|
+
color: getHashStyles(node.data?.type ?? node.type)?.hue,
|
|
220
225
|
},
|
|
221
226
|
classes: {
|
|
222
227
|
'dx-selected': selection.contains(node.id),
|
|
@@ -224,7 +229,7 @@ const DefaultStory = ({
|
|
|
224
229
|
}),
|
|
225
230
|
edge: (edge: GraphLayoutEdge<TestNode>) => ({
|
|
226
231
|
data: {
|
|
227
|
-
color:
|
|
232
|
+
color: getHashStyles(edge.data?.type ?? edge.type)?.hue,
|
|
228
233
|
},
|
|
229
234
|
}),
|
|
230
235
|
}}
|
|
@@ -255,13 +260,13 @@ const DefaultStory = ({
|
|
|
255
260
|
<Popover.VirtualTrigger virtualRef={popoverAnchorRef} />
|
|
256
261
|
<Popover.Content onOpenAutoFocus={(event) => event.preventDefault()}>
|
|
257
262
|
<Popover.Viewport>
|
|
258
|
-
<Card.
|
|
263
|
+
<Card.Root>
|
|
259
264
|
<SyntaxHighlighter
|
|
260
|
-
classNames='bg-transparent text-xs !mlb-cardSpacingBlock !pli-cardSpacingInline !overflow-visible'
|
|
261
265
|
language='json'
|
|
266
|
+
classNames='text-xs my-form-padding px-form-padding bg-transparent'
|
|
262
267
|
code={JSON.stringify(popover, null, 2)}
|
|
263
268
|
/>
|
|
264
|
-
</Card.
|
|
269
|
+
</Card.Root>
|
|
265
270
|
</Popover.Viewport>
|
|
266
271
|
<Popover.Arrow />
|
|
267
272
|
</Popover.Content>
|
|
@@ -282,7 +287,7 @@ const Debug = ({
|
|
|
282
287
|
onDelete,
|
|
283
288
|
onPing,
|
|
284
289
|
}: {
|
|
285
|
-
model?: GraphModel;
|
|
290
|
+
model?: GraphModel.ReactiveGraphModel;
|
|
286
291
|
selection: SelectionModel;
|
|
287
292
|
projector: ProjectorType;
|
|
288
293
|
onToggleProjector: () => void;
|
|
@@ -296,44 +301,48 @@ const Debug = ({
|
|
|
296
301
|
}) => {
|
|
297
302
|
const [data, setData] = useState({});
|
|
298
303
|
useEffect(() => {
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
model: model?.toJSON(),
|
|
304
|
-
});
|
|
304
|
+
setData({
|
|
305
|
+
projector,
|
|
306
|
+
selection: selection.toJSON(),
|
|
307
|
+
model: model?.toJSON(),
|
|
305
308
|
});
|
|
306
309
|
}, [model, selection, projector]);
|
|
307
310
|
|
|
308
311
|
return (
|
|
309
312
|
<div className='flex flex-col overflow-hidden'>
|
|
310
313
|
<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}
|
|
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 />
|
|
319
322
|
</Toolbar.Root>
|
|
320
|
-
<
|
|
323
|
+
<Json.Root data={data}>
|
|
324
|
+
<Json.Content>
|
|
325
|
+
<Json.Filter />
|
|
326
|
+
<Json.Data classNames='text-sm' />
|
|
327
|
+
</Json.Content>
|
|
328
|
+
</Json.Root>
|
|
321
329
|
</div>
|
|
322
330
|
);
|
|
323
331
|
};
|
|
324
332
|
|
|
325
|
-
const meta
|
|
333
|
+
const meta = {
|
|
326
334
|
title: 'ui/react-ui-graph/Graph',
|
|
327
335
|
render: DefaultStory,
|
|
328
|
-
decorators: [withTheme, withLayout({
|
|
336
|
+
decorators: [withRegistry, withTheme(), withLayout({ layout: 'fullscreen' })],
|
|
329
337
|
parameters: {
|
|
338
|
+
layout: 'fullscreen',
|
|
330
339
|
controls: { disable: true },
|
|
331
340
|
},
|
|
332
|
-
}
|
|
341
|
+
} satisfies Meta<typeof DefaultStory>;
|
|
333
342
|
|
|
334
343
|
export default meta;
|
|
335
344
|
|
|
336
|
-
type Story = StoryObj<
|
|
345
|
+
type Story = StoryObj<typeof meta>;
|
|
337
346
|
|
|
338
347
|
export const Default: Story = {
|
|
339
348
|
args: {
|
|
@@ -449,14 +458,12 @@ export const WithPopover: Story = {
|
|
|
449
458
|
},
|
|
450
459
|
};
|
|
451
460
|
|
|
452
|
-
export const Empty
|
|
453
|
-
|
|
454
|
-
<SVG.
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
<
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
),
|
|
462
|
-
};
|
|
461
|
+
export const Empty = () => (
|
|
462
|
+
<SVG.Root>
|
|
463
|
+
<SVG.Markers />
|
|
464
|
+
<SVG.Grid axis />
|
|
465
|
+
<SVG.Zoom extent={[1 / 4, 4]}>
|
|
466
|
+
<GraphComponent />
|
|
467
|
+
</SVG.Zoom>
|
|
468
|
+
</SVG.Root>
|
|
469
|
+
);
|
|
@@ -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,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,16 +2,15 @@
|
|
|
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
|
-
import { Mesh } from './Mesh';
|
|
13
10
|
import { SVG, type SVGRootProps } from '../SVG';
|
|
14
11
|
|
|
12
|
+
import { Mesh } from './Mesh';
|
|
13
|
+
|
|
15
14
|
// TODO(burdon): Create waves/game of life.
|
|
16
15
|
const DefaultStory = (props: SVGRootProps) => {
|
|
17
16
|
const [value, setValue] = useState(1);
|
|
@@ -35,15 +34,18 @@ const DefaultStory = (props: SVGRootProps) => {
|
|
|
35
34
|
);
|
|
36
35
|
};
|
|
37
36
|
|
|
38
|
-
const meta
|
|
37
|
+
const meta = {
|
|
39
38
|
title: 'ui/react-ui-graph/Mesh',
|
|
40
39
|
render: DefaultStory,
|
|
41
|
-
decorators: [withTheme, withLayout({
|
|
42
|
-
|
|
40
|
+
decorators: [withTheme(), withLayout({ layout: 'fullscreen' })],
|
|
41
|
+
parameters: {
|
|
42
|
+
layout: 'fullscreen',
|
|
43
|
+
},
|
|
44
|
+
} satisfies Meta<typeof DefaultStory>;
|
|
43
45
|
|
|
44
46
|
export default meta;
|
|
45
47
|
|
|
46
|
-
type Story = StoryObj<typeof
|
|
48
|
+
type Story = StoryObj<typeof meta>;
|
|
47
49
|
|
|
48
50
|
export const Default: Story = {
|
|
49
51
|
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}
|
|
@@ -6,16 +6,26 @@ import { type PropsWithChildren } from 'react';
|
|
|
6
6
|
|
|
7
7
|
import { type ThemedClassName } from '@dxos/react-ui';
|
|
8
8
|
|
|
9
|
+
import { Graph, type GraphProps as SVGGraphProps } from '../Graph';
|
|
10
|
+
import { Mesh, type MeshProps as SVGMeshProps } from '../Mesh';
|
|
11
|
+
|
|
9
12
|
import { Grid, type GridProps as SVGGridProps } from './Grid';
|
|
10
13
|
import { Markers, type MarkersProps as SVGMarkersProps } from './Markers';
|
|
11
14
|
import { Root, type RootProps as SVGRootProps } from './Root';
|
|
12
|
-
import {
|
|
13
|
-
import { Graph, type GraphProps as SVGGraphProps } from '../Graph';
|
|
14
|
-
import { Mesh, type MeshProps as SVGMeshProps } from '../Mesh';
|
|
15
|
+
import { type ZoomProps as SVGZoomProps, Zoom } from './Zoom';
|
|
15
16
|
|
|
16
17
|
export type SVGProps = PropsWithChildren<ThemedClassName>;
|
|
17
18
|
|
|
18
|
-
|
|
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 = {
|
|
19
29
|
Root,
|
|
20
30
|
Grid,
|
|
21
31
|
Markers,
|