@dxos/react-ui-graph 0.8.4-main.66e292d → 0.8.4-main.69d29f4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib/browser/chunk-LKC455GK.mjs +52 -0
- package/dist/lib/browser/chunk-LKC455GK.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +1074 -229
- 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 +1074 -229
- 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 +1 -1
- package/dist/types/src/components/Graph/Graph.stories.d.ts.map +1 -1
- package/dist/types/src/components/SVG/Root.d.ts +1 -1
- package/dist/types/src/components/SVG/SVG.d.ts +14 -17
- package/dist/types/src/components/SVG/SVG.d.ts.map +1 -1
- package/dist/types/src/graph/projector/graph-force-projector.d.ts +1 -1
- package/dist/types/src/graph/projector/graph-force-projector.d.ts.map +1 -1
- package/dist/types/src/graph/projector/graph-hierarchical-projector.d.ts +1 -1
- package/dist/types/src/graph/projector/graph-hierarchical-projector.d.ts.map +1 -1
- package/dist/types/src/graph/projector/graph-projector.d.ts +2 -2
- package/dist/types/src/graph/projector/graph-projector.d.ts.map +1 -1
- package/dist/types/src/graph/projector/graph-radial-projector.d.ts +1 -1
- package/dist/types/src/graph/projector/graph-radial-projector.d.ts.map +1 -1
- package/dist/types/src/graph/projector/graph-relational-projector.d.ts +1 -1
- package/dist/types/src/graph/projector/graph-relational-projector.d.ts.map +1 -1
- package/dist/types/src/graph/types.d.ts +1 -1
- package/dist/types/src/graph/types.d.ts.map +1 -1
- package/dist/types/src/stories/hooks.stories.d.ts +3 -2
- package/dist/types/src/stories/hooks.stories.d.ts.map +1 -1
- package/dist/types/src/testing/data.d.ts +4 -4
- package/dist/types/src/testing/data.d.ts.map +1 -1
- package/dist/types/src/testing/hooks.d.ts +2 -16
- package/dist/types/src/testing/hooks.d.ts.map +1 -1
- package/dist/types/src/testing/model.d.ts +4 -8
- package/dist/types/src/testing/model.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +31 -26
- package/src/components/Graph/Graph.stories.tsx +25 -21
- package/src/components/Graph/Graph.tsx +17 -10
- package/src/components/SVG/Grid.tsx +1 -1
- package/src/components/SVG/Root.tsx +1 -1
- package/src/components/SVG/SVG.tsx +10 -1
- package/src/graph/projector/graph-force-projector.ts +1 -1
- package/src/graph/projector/graph-hierarchical-projector.ts +3 -3
- package/src/graph/projector/graph-projector.ts +2 -2
- package/src/graph/projector/graph-radial-projector.ts +1 -1
- package/src/graph/projector/graph-relational-projector.ts +3 -3
- package/src/graph/types.ts +1 -1
- package/src/stories/hooks.stories.tsx +12 -6
- package/src/testing/data.ts +5 -5
- package/src/testing/hooks.ts +1 -1
- package/src/testing/model.ts +3 -3
- package/dist/lib/browser/chunk-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.69d29f4",
|
|
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.12.1",
|
|
46
|
+
"@effect-atom/atom-react": "^0.4.6",
|
|
42
47
|
"d3": "^7.9.0",
|
|
43
48
|
"d3-force": "~3.0.0",
|
|
44
49
|
"immutability-helper": "^3.0.2",
|
|
@@ -46,40 +51,40 @@
|
|
|
46
51
|
"lodash.defaultsdeep": "^4.6.1",
|
|
47
52
|
"react-resize-detector": "^11.0.1",
|
|
48
53
|
"topojson-client": "^3.1.0",
|
|
49
|
-
"@dxos/async": "0.8.4-main.
|
|
50
|
-
"@dxos/
|
|
51
|
-
"@dxos/
|
|
52
|
-
"@dxos/
|
|
53
|
-
"@dxos/log": "0.8.4-main.
|
|
54
|
-
"@dxos/
|
|
55
|
-
"@dxos/
|
|
54
|
+
"@dxos/async": "0.8.4-main.69d29f4",
|
|
55
|
+
"@dxos/debug": "0.8.4-main.69d29f4",
|
|
56
|
+
"@dxos/invariant": "0.8.4-main.69d29f4",
|
|
57
|
+
"@dxos/node-std": "0.8.4-main.69d29f4",
|
|
58
|
+
"@dxos/log": "0.8.4-main.69d29f4",
|
|
59
|
+
"@dxos/react-ui-mosaic": "0.8.4-main.69d29f4",
|
|
60
|
+
"@dxos/graph": "0.8.4-main.69d29f4"
|
|
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": "~19.2.
|
|
62
|
-
"@types/react-dom": "~19.2.
|
|
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": "~19.2.
|
|
67
|
-
"react-dom": "~19.2.
|
|
68
|
-
"@dxos/random": "0.8.4-main.
|
|
69
|
-
"@dxos/react-ui": "0.8.4-main.
|
|
70
|
-
"@dxos/react-ui-
|
|
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.69d29f4",
|
|
74
|
+
"@dxos/react-ui": "0.8.4-main.69d29f4",
|
|
75
|
+
"@dxos/react-ui-stack": "0.8.4-main.69d29f4",
|
|
76
|
+
"@dxos/react-ui-syntax-highlighter": "0.8.4-main.69d29f4",
|
|
77
|
+
"@dxos/ui-theme": "0.8.4-main.69d29f4",
|
|
78
|
+
"@dxos/storybook-utils": "0.8.4-main.69d29f4"
|
|
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.69d29f4",
|
|
84
|
+
"@dxos/ui-theme": "0.8.4-main.69d29f4"
|
|
80
85
|
},
|
|
81
86
|
"optionalDependencies": {
|
|
82
|
-
"@dxos/random": "0.8.4-main.
|
|
87
|
+
"@dxos/random": "0.8.4-main.69d29f4"
|
|
83
88
|
},
|
|
84
89
|
"publishConfig": {
|
|
85
90
|
"access": "public"
|
|
@@ -2,17 +2,18 @@
|
|
|
2
2
|
// Copyright 2022 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import { RegistryContext } from '@effect-atom/atom-react';
|
|
6
6
|
import { type Meta, type StoryObj } from '@storybook/react-vite';
|
|
7
7
|
import { select } from 'd3';
|
|
8
|
-
import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
8
|
+
import React, { useCallback, useContext, useEffect, useMemo, useRef, useState } from 'react';
|
|
9
9
|
|
|
10
10
|
import { type Graph, type GraphModel, SelectionModel } from '@dxos/graph';
|
|
11
11
|
import { IconButton, Popover, Toolbar } from '@dxos/react-ui';
|
|
12
12
|
import { withTheme } from '@dxos/react-ui/testing';
|
|
13
|
-
import { Card } from '@dxos/react-ui-
|
|
13
|
+
import { Card } from '@dxos/react-ui-mosaic';
|
|
14
14
|
import { JsonFilter, SyntaxHighlighter } from '@dxos/react-ui-syntax-highlighter';
|
|
15
|
-
import {
|
|
15
|
+
import { withRegistry } from '@dxos/storybook-utils';
|
|
16
|
+
import { getHashStyles, mx } from '@dxos/ui-theme';
|
|
16
17
|
|
|
17
18
|
import { Pulsar } from '../../fx';
|
|
18
19
|
import {
|
|
@@ -54,7 +55,7 @@ type StoryProps = GraphProps & {
|
|
|
54
55
|
grid?: boolean | SVGGridProps;
|
|
55
56
|
inspect?: boolean;
|
|
56
57
|
singleSelect?: boolean;
|
|
57
|
-
graph: () => Graph;
|
|
58
|
+
graph: () => Graph.Any;
|
|
58
59
|
projectorType?: ProjectorType;
|
|
59
60
|
projectorOptions?:
|
|
60
61
|
| GraphForceProjectorOptions
|
|
@@ -75,9 +76,13 @@ const DefaultStory = ({
|
|
|
75
76
|
}: StoryProps) => {
|
|
76
77
|
const graphRef = useRef<GraphController | null>(null);
|
|
77
78
|
const context = useRef<SVGContext>(null);
|
|
79
|
+
const registry = useContext(RegistryContext);
|
|
78
80
|
|
|
79
81
|
// Models.
|
|
80
|
-
const [model, setModel] = useState<GraphModel | undefined>(() =>
|
|
82
|
+
const [model, setModel] = useState<GraphModel.GraphModel | undefined>(() => {
|
|
83
|
+
const graph = _graph?.();
|
|
84
|
+
return graph ? new TestGraphModel(registry, graph) : undefined;
|
|
85
|
+
});
|
|
81
86
|
const selection = useMemo(() => new SelectionModel(singleSelect), [singleSelect]);
|
|
82
87
|
|
|
83
88
|
// Projector.
|
|
@@ -155,8 +160,9 @@ const DefaultStory = ({
|
|
|
155
160
|
}, [model]);
|
|
156
161
|
|
|
157
162
|
const handleRegenerate = useCallback(() => {
|
|
158
|
-
|
|
159
|
-
|
|
163
|
+
const graph = _graph?.();
|
|
164
|
+
setModel(graph ? new TestGraphModel(registry, graph) : undefined);
|
|
165
|
+
}, [_graph, registry]);
|
|
160
166
|
|
|
161
167
|
const handleClear = useCallback(() => {
|
|
162
168
|
setModel(undefined);
|
|
@@ -180,7 +186,7 @@ const DefaultStory = ({
|
|
|
180
186
|
|
|
181
187
|
const active = useMemo(() => new SelectionModel(), []);
|
|
182
188
|
const handlePing = useCallback(() => {
|
|
183
|
-
for (const id of active.
|
|
189
|
+
for (const id of active.getSelectedIds()) {
|
|
184
190
|
const node = graphRef.current?.findNode(id);
|
|
185
191
|
if (node) {
|
|
186
192
|
Pulsar.remove(select(node));
|
|
@@ -188,7 +194,7 @@ const DefaultStory = ({
|
|
|
188
194
|
}
|
|
189
195
|
|
|
190
196
|
active.clear();
|
|
191
|
-
for (const id of selection.
|
|
197
|
+
for (const id of selection.getSelectedIds()) {
|
|
192
198
|
const node = graphRef.current?.findNode(id);
|
|
193
199
|
if (node) {
|
|
194
200
|
active.add(id);
|
|
@@ -200,7 +206,7 @@ const DefaultStory = ({
|
|
|
200
206
|
|
|
201
207
|
return (
|
|
202
208
|
<Popover.Root open={!!popover} onOpenChange={(state) => !state && setPopover(undefined)}>
|
|
203
|
-
<div className={mx('is-full grid divide-x divide-separator', debug && 'grid-cols-[1fr_30rem]')}>
|
|
209
|
+
<div className={mx('bs-full is-full grid divide-x divide-separator', debug && 'grid-cols-[1fr_30rem]')}>
|
|
204
210
|
<SVG.Root ref={context}>
|
|
205
211
|
<SVG.Markers />
|
|
206
212
|
{grid && <SVG.Grid {...(typeof grid === 'boolean' ? { axis: grid } : grid)} />}
|
|
@@ -254,13 +260,13 @@ const DefaultStory = ({
|
|
|
254
260
|
<Popover.VirtualTrigger virtualRef={popoverAnchorRef} />
|
|
255
261
|
<Popover.Content onOpenAutoFocus={(event) => event.preventDefault()}>
|
|
256
262
|
<Popover.Viewport>
|
|
257
|
-
<Card.
|
|
263
|
+
<Card.Root>
|
|
258
264
|
<SyntaxHighlighter
|
|
259
265
|
language='json'
|
|
260
266
|
classNames='text-xs mlb-cardSpacingBlock pli-cardSpacingInline bg-transparent'
|
|
261
267
|
code={JSON.stringify(popover, null, 2)}
|
|
262
268
|
/>
|
|
263
|
-
</Card.
|
|
269
|
+
</Card.Root>
|
|
264
270
|
</Popover.Viewport>
|
|
265
271
|
<Popover.Arrow />
|
|
266
272
|
</Popover.Content>
|
|
@@ -281,7 +287,7 @@ const Debug = ({
|
|
|
281
287
|
onDelete,
|
|
282
288
|
onPing,
|
|
283
289
|
}: {
|
|
284
|
-
model?: GraphModel;
|
|
290
|
+
model?: GraphModel.GraphModel;
|
|
285
291
|
selection: SelectionModel;
|
|
286
292
|
projector: ProjectorType;
|
|
287
293
|
onToggleProjector: () => void;
|
|
@@ -295,12 +301,10 @@ const Debug = ({
|
|
|
295
301
|
}) => {
|
|
296
302
|
const [data, setData] = useState({});
|
|
297
303
|
useEffect(() => {
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
model: model?.toJSON(),
|
|
303
|
-
});
|
|
304
|
+
setData({
|
|
305
|
+
projector,
|
|
306
|
+
selection: selection.toJSON(),
|
|
307
|
+
model: model?.toJSON(),
|
|
304
308
|
});
|
|
305
309
|
}, [model, selection, projector]);
|
|
306
310
|
|
|
@@ -324,7 +328,7 @@ const Debug = ({
|
|
|
324
328
|
const meta = {
|
|
325
329
|
title: 'ui/react-ui-graph/Graph',
|
|
326
330
|
render: DefaultStory,
|
|
327
|
-
decorators: [withTheme],
|
|
331
|
+
decorators: [withRegistry, withTheme],
|
|
328
332
|
parameters: {
|
|
329
333
|
layout: 'fullscreen',
|
|
330
334
|
controls: { disable: true },
|
|
@@ -2,14 +2,13 @@
|
|
|
2
2
|
// Copyright 2022 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { effect } from '@preact/signals-core';
|
|
6
5
|
import React, { type JSX, type Ref, forwardRef, useEffect, useImperativeHandle, useMemo, useRef } from 'react';
|
|
7
6
|
|
|
8
7
|
import { combine } from '@dxos/async';
|
|
9
|
-
import { type
|
|
8
|
+
import { type Graph as Graph$, type GraphModel } from '@dxos/graph';
|
|
10
9
|
import { log } from '@dxos/log';
|
|
11
10
|
import { type ThemedClassName } from '@dxos/react-ui';
|
|
12
|
-
import { mx } from '@dxos/
|
|
11
|
+
import { mx } from '@dxos/ui-theme';
|
|
13
12
|
|
|
14
13
|
import {
|
|
15
14
|
GraphForceProjector,
|
|
@@ -27,9 +26,9 @@ export type GraphController = {
|
|
|
27
26
|
findNode: (id: string) => SVGGElement | null;
|
|
28
27
|
};
|
|
29
28
|
|
|
30
|
-
export type GraphProps<Node extends
|
|
29
|
+
export type GraphProps<Node extends Graph$.Node.Any = any, Edge extends Graph$.Edge.Any = any> = ThemedClassName<
|
|
31
30
|
Pick<GraphRendererOptions<Node>, 'labels' | 'subgraphs' | 'attributes'> & {
|
|
32
|
-
model?: GraphModel<Node, Edge>; // TODO(burdon): ReactiveGraphModel
|
|
31
|
+
model?: GraphModel.GraphModel<Node, Edge>; // TODO(burdon): ReactiveGraphModel
|
|
33
32
|
projector?: GraphProjector<Node>;
|
|
34
33
|
renderer?: GraphRenderer<Node>;
|
|
35
34
|
drag?: boolean;
|
|
@@ -39,7 +38,7 @@ export type GraphProps<Node extends BaseGraphNode = any, Edge extends BaseGraphE
|
|
|
39
38
|
}
|
|
40
39
|
>;
|
|
41
40
|
|
|
42
|
-
|
|
41
|
+
const GraphInner = <Node extends Graph$.Node.Any = any, Edge extends Graph$.Edge.Any = any>(
|
|
43
42
|
{
|
|
44
43
|
classNames,
|
|
45
44
|
model,
|
|
@@ -96,10 +95,18 @@ export const GraphInner = <Node extends BaseGraphNode = any, Edge extends BaseGr
|
|
|
96
95
|
|
|
97
96
|
// Subscriptions.
|
|
98
97
|
useEffect(() => {
|
|
98
|
+
projector.updateData(model?.graph);
|
|
99
|
+
|
|
100
|
+
// Subscribe to model changes if reactive model.
|
|
101
|
+
const unsubscribeModel =
|
|
102
|
+
model && 'subscribe' in model
|
|
103
|
+
? (model as GraphModel.ReactiveGraphModel).subscribe(() => {
|
|
104
|
+
projector.updateData(model?.graph);
|
|
105
|
+
})
|
|
106
|
+
: undefined;
|
|
107
|
+
|
|
99
108
|
return combine(
|
|
100
|
-
|
|
101
|
-
projector.updateData(model?.graph);
|
|
102
|
-
}),
|
|
109
|
+
unsubscribeModel,
|
|
103
110
|
projector.updated.on(({ layout }) => {
|
|
104
111
|
try {
|
|
105
112
|
renderer.render(layout);
|
|
@@ -125,6 +132,6 @@ export const GraphInner = <Node extends BaseGraphNode = any, Edge extends BaseGr
|
|
|
125
132
|
/**
|
|
126
133
|
* SVG Graph.
|
|
127
134
|
*/
|
|
128
|
-
export const Graph = forwardRef(GraphInner) as <Node extends
|
|
135
|
+
export const Graph = forwardRef(GraphInner) as <Node extends Graph$.Node.Any = any, Edge extends Graph$.Edge.Any = any>(
|
|
129
136
|
props: GraphProps<Node, Edge> & { ref?: Ref<GraphController> },
|
|
130
137
|
) => JSX.Element;
|
|
@@ -7,7 +7,7 @@ import React, { type PropsWithChildren, forwardRef, useEffect, useImperativeHand
|
|
|
7
7
|
import { useResizeDetector } from 'react-resize-detector';
|
|
8
8
|
|
|
9
9
|
import { type ThemedClassName } from '@dxos/react-ui';
|
|
10
|
-
import { mx } from '@dxos/
|
|
10
|
+
import { mx } from '@dxos/ui-theme';
|
|
11
11
|
|
|
12
12
|
import { SVGContext, type SVGContextOptions, SVGContextProvider } from '../../hooks';
|
|
13
13
|
|
|
@@ -16,7 +16,16 @@ import { type ZoomProps as SVGZoomProps, Zoom } from './Zoom';
|
|
|
16
16
|
|
|
17
17
|
export type SVGProps = PropsWithChildren<ThemedClassName>;
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
type SVG = {
|
|
20
|
+
Root: typeof Root;
|
|
21
|
+
Grid: typeof Grid;
|
|
22
|
+
Markers: typeof Markers;
|
|
23
|
+
Mesh: typeof Mesh;
|
|
24
|
+
Zoom: typeof Zoom;
|
|
25
|
+
Graph: typeof Graph;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export const SVG: SVG = {
|
|
20
29
|
Root,
|
|
21
30
|
Grid,
|
|
22
31
|
Markers,
|
|
@@ -223,7 +223,7 @@ export class GraphForceProjector<NodeData = any> extends GraphProjector<NodeData
|
|
|
223
223
|
this.restart();
|
|
224
224
|
}
|
|
225
225
|
|
|
226
|
-
override onUpdate(graph?: Graph): void {
|
|
226
|
+
override onUpdate(graph?: Graph.Any): void {
|
|
227
227
|
log('onUpdate', { graph: { nodes: graph?.nodes.length, edges: graph?.edges.length } });
|
|
228
228
|
this._simulation.stop();
|
|
229
229
|
this.mergeData(graph);
|
|
@@ -20,14 +20,14 @@ export class GraphHierarchicalProjector<
|
|
|
20
20
|
NodeData = any,
|
|
21
21
|
Options extends GraphHierarchicalProjectorOptions = any,
|
|
22
22
|
> extends GraphRadialProjector<NodeData, Options> {
|
|
23
|
-
protected override onUpdate(graph?: Graph) {
|
|
23
|
+
protected override onUpdate(graph?: Graph.Any) {
|
|
24
24
|
log('onUpdate', {
|
|
25
25
|
graph: { nodes: graph?.nodes.length, edges: graph?.edges.length },
|
|
26
|
-
selection: this.selection?.
|
|
26
|
+
selection: this.selection?.getSelectedIds(),
|
|
27
27
|
});
|
|
28
28
|
|
|
29
29
|
this.mergeData(graph);
|
|
30
|
-
const selected = this.selection?.
|
|
30
|
+
const selected = this.selection?.getSelectedIds()[0];
|
|
31
31
|
if (selected) {
|
|
32
32
|
const node = this.layout.graph.nodes.find((node) => node.id === selected);
|
|
33
33
|
if (node) {
|
|
@@ -15,7 +15,7 @@ export type GraphProjectorOptions = ProjectorOptions & {};
|
|
|
15
15
|
* Base class for graph projectors.
|
|
16
16
|
*/
|
|
17
17
|
export abstract class GraphProjector<NodeData = any, Options extends GraphProjectorOptions = any> extends Projector<
|
|
18
|
-
Graph,
|
|
18
|
+
Graph.Any,
|
|
19
19
|
GraphLayout<NodeData>,
|
|
20
20
|
Options
|
|
21
21
|
> {
|
|
@@ -60,7 +60,7 @@ export abstract class GraphProjector<NodeData = any, Options extends GraphProjec
|
|
|
60
60
|
* Merge external data with internal representation (e.g., so force properties like position are preserved).
|
|
61
61
|
* @param data
|
|
62
62
|
*/
|
|
63
|
-
protected mergeData(data: Graph = emptyGraph) {
|
|
63
|
+
protected mergeData(data: Graph.Any = emptyGraph) {
|
|
64
64
|
// Merge nodes.
|
|
65
65
|
const nodes: GraphLayoutNode[] = data.nodes.map((node) => {
|
|
66
66
|
let current: GraphLayoutNode = this._layout.graph.nodes.find((n) => n.id === this.options.idAccessor(node));
|
|
@@ -28,7 +28,7 @@ export class GraphRadialProjector<
|
|
|
28
28
|
return undefined;
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
protected override onUpdate(graph?: Graph) {
|
|
31
|
+
protected override onUpdate(graph?: Graph.Any) {
|
|
32
32
|
log('onUpdate', { graph: { nodes: graph?.nodes.length, edges: graph?.edges.length } });
|
|
33
33
|
this.mergeData(graph);
|
|
34
34
|
this.doRadialLayout();
|
|
@@ -20,14 +20,14 @@ export class GraphRelationalProjector<
|
|
|
20
20
|
NodeData = any,
|
|
21
21
|
Options extends GraphRelationalProjectorOptions = any,
|
|
22
22
|
> extends GraphRadialProjector<NodeData, Options> {
|
|
23
|
-
protected override onUpdate(graph?: Graph) {
|
|
23
|
+
protected override onUpdate(graph?: Graph.Any) {
|
|
24
24
|
log('onUpdate', {
|
|
25
25
|
graph: { nodes: graph?.nodes.length, edges: graph?.edges.length },
|
|
26
|
-
selection: this.selection?.
|
|
26
|
+
selection: this.selection?.getSelectedIds(),
|
|
27
27
|
});
|
|
28
28
|
|
|
29
29
|
this.mergeData(graph);
|
|
30
|
-
const selected = this.selection?.
|
|
30
|
+
const selected = this.selection?.getSelectedIds()[0];
|
|
31
31
|
if (selected) {
|
|
32
32
|
const node = this.layout.graph.nodes.find((node) => node.id === selected);
|
|
33
33
|
if (node) {
|
package/src/graph/types.ts
CHANGED
|
@@ -2,13 +2,16 @@
|
|
|
2
2
|
// Copyright 2020 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
+
import { RegistryContext } from '@effect-atom/atom-react';
|
|
5
6
|
import { type Meta, type StoryObj } from '@storybook/react-vite';
|
|
6
7
|
import { select } from 'd3';
|
|
7
|
-
import React, { type PropsWithChildren, useEffect, useMemo, useRef } from 'react';
|
|
8
|
+
import React, { type PropsWithChildren, useContext, useEffect, useMemo, useRef } from 'react';
|
|
8
9
|
|
|
9
10
|
import { combine } from '@dxos/async';
|
|
11
|
+
import { type Graph } from '@dxos/graph';
|
|
10
12
|
import { log } from '@dxos/log';
|
|
11
13
|
import { withTheme } from '@dxos/react-ui/testing';
|
|
14
|
+
import { withRegistry } from '@dxos/storybook-utils';
|
|
12
15
|
|
|
13
16
|
import { SVG } from '../components';
|
|
14
17
|
import {
|
|
@@ -27,7 +30,7 @@ import { TestGraphModel, type TestNode, convertTreeToGraph, createTree } from '.
|
|
|
27
30
|
import '../../styles/graph.css';
|
|
28
31
|
|
|
29
32
|
type ComponentProps = PropsWithChildren<{
|
|
30
|
-
|
|
33
|
+
graph: () => Graph.Graph<TestNode, Graph.Edge.Any>;
|
|
31
34
|
projectorOptions?: GraphForceProjectorOptions;
|
|
32
35
|
count?: number;
|
|
33
36
|
interval?: number;
|
|
@@ -36,13 +39,16 @@ type ComponentProps = PropsWithChildren<{
|
|
|
36
39
|
}>;
|
|
37
40
|
|
|
38
41
|
const Component = ({
|
|
39
|
-
|
|
42
|
+
graph: graphFactory,
|
|
40
43
|
projectorOptions,
|
|
41
44
|
count = 0,
|
|
42
45
|
interval = 200,
|
|
43
46
|
link = false,
|
|
44
47
|
grid: showGrid = false,
|
|
45
48
|
}: ComponentProps) => {
|
|
49
|
+
const registry = useContext(RegistryContext);
|
|
50
|
+
const model = useMemo(() => new TestGraphModel(registry, graphFactory()), [registry, graphFactory]);
|
|
51
|
+
|
|
46
52
|
const context = useSvgContext();
|
|
47
53
|
const graphRef = useRef<SVGGElement>(null);
|
|
48
54
|
const markersRef = useRef<SVGGElement>(null);
|
|
@@ -152,7 +158,7 @@ const DefaultStory = ({ children, ...props }: ComponentProps) => {
|
|
|
152
158
|
const meta = {
|
|
153
159
|
title: 'ui/react-ui-graph/hooks',
|
|
154
160
|
render: DefaultStory,
|
|
155
|
-
decorators: [withTheme],
|
|
161
|
+
decorators: [withRegistry, withTheme],
|
|
156
162
|
parameters: {
|
|
157
163
|
layout: 'fullscreen',
|
|
158
164
|
},
|
|
@@ -164,7 +170,7 @@ type Story = StoryObj<typeof meta>;
|
|
|
164
170
|
|
|
165
171
|
export const Default: Story = {
|
|
166
172
|
args: {
|
|
167
|
-
|
|
173
|
+
graph: () => convertTreeToGraph(createTree({ depth: 3 })),
|
|
168
174
|
grid: true,
|
|
169
175
|
count: 300,
|
|
170
176
|
interval: 20,
|
|
@@ -189,7 +195,7 @@ export const Default: Story = {
|
|
|
189
195
|
|
|
190
196
|
export const Bullets: Story = {
|
|
191
197
|
args: {
|
|
192
|
-
|
|
198
|
+
graph: () => convertTreeToGraph(createTree({ depth: 4 })),
|
|
193
199
|
children: <span>⌘-DRAG to edge or create node; ⌘-CLICK to delete edge.</span>,
|
|
194
200
|
link: true,
|
|
195
201
|
grid: false,
|
package/src/testing/data.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// Copyright 2020 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { type
|
|
5
|
+
import { type Graph } from '@dxos/graph';
|
|
6
6
|
import { faker } from '@dxos/random';
|
|
7
7
|
|
|
8
8
|
import { type TestNode } from './model';
|
|
@@ -23,7 +23,7 @@ export const createNode = (type: string = undefined): TestNode => ({
|
|
|
23
23
|
export const createNodes = (n = 0, types?: string[]): TestNode[] =>
|
|
24
24
|
Array.from({ length: n }, () => createNode(types ? faker.helpers.arrayElement(types) : undefined));
|
|
25
25
|
|
|
26
|
-
export const createEdge = (source: TestNode, target: TestNode):
|
|
26
|
+
export const createEdge = (source: TestNode, target: TestNode): Graph.Edge.Any => ({
|
|
27
27
|
id: `${source.id}-${target.id}`,
|
|
28
28
|
source: source.id,
|
|
29
29
|
target: target.id,
|
|
@@ -54,8 +54,8 @@ export const createTree = ({ depth = 2, children = 3 } = {}): TestNode => {
|
|
|
54
54
|
* Converts a tree into a graph.
|
|
55
55
|
* @param root
|
|
56
56
|
*/
|
|
57
|
-
export const convertTreeToGraph = (root: TestNode): Graph => {
|
|
58
|
-
const traverse = (node: TestNode, graph: Graph) => {
|
|
57
|
+
export const convertTreeToGraph = (root: TestNode): Graph.Any => {
|
|
58
|
+
const traverse = (node: TestNode, graph: Graph.Any) => {
|
|
59
59
|
graph.nodes.push(node);
|
|
60
60
|
node.children?.forEach((child) => {
|
|
61
61
|
graph.edges.push(createEdge(node, child));
|
|
@@ -76,7 +76,7 @@ export const convertTreeToGraph = (root: TestNode): Graph => {
|
|
|
76
76
|
* @param numNodes
|
|
77
77
|
* @param numEdges
|
|
78
78
|
*/
|
|
79
|
-
export const createGraph = (numNodes = 0, numEdges = 0, types?: string[]): Graph => {
|
|
79
|
+
export const createGraph = (numNodes = 0, numEdges = 0, types?: string[]): Graph.Any => {
|
|
80
80
|
const nodes = createNodes(numNodes, types);
|
|
81
81
|
|
|
82
82
|
const edges = new Map();
|
package/src/testing/hooks.ts
CHANGED
|
@@ -47,7 +47,7 @@ export const useObjectMutator = <T>(initalValue: T): ObjectMutator<T> => {
|
|
|
47
47
|
/**
|
|
48
48
|
* Test data set generator and mutator.
|
|
49
49
|
*/
|
|
50
|
-
export const useGraphGenerator = (options: { data?: Graph } = {}) => {
|
|
50
|
+
export const useGraphGenerator = (options: { data?: Graph.Any } = {}) => {
|
|
51
51
|
const [data, setData, updateData] = useObjectMutator(options.data || { nodes: [], edges: [] });
|
|
52
52
|
|
|
53
53
|
let interval;
|
package/src/testing/model.ts
CHANGED
|
@@ -2,17 +2,17 @@
|
|
|
2
2
|
// Copyright 2022 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { type
|
|
5
|
+
import { type Graph, GraphModel } from '@dxos/graph';
|
|
6
6
|
import { faker } from '@dxos/random';
|
|
7
7
|
|
|
8
8
|
import { createEdge, createNode } from './data';
|
|
9
9
|
|
|
10
|
-
export type TestNode =
|
|
10
|
+
export type TestNode = Graph.Node.Any & {
|
|
11
11
|
label?: string;
|
|
12
12
|
children?: TestNode[];
|
|
13
13
|
};
|
|
14
14
|
|
|
15
|
-
export class TestGraphModel extends ReactiveGraphModel<TestNode> {
|
|
15
|
+
export class TestGraphModel extends GraphModel.ReactiveGraphModel<TestNode> {
|
|
16
16
|
getRandomNode() {
|
|
17
17
|
return faker.helpers.arrayElement(this._graph.nodes);
|
|
18
18
|
}
|