@dxos/react-ui-graph 0.8.4-main.fd6878d → 0.8.4-staging.60fe92afc8
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 +2729 -593
- 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 +2729 -593
- 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 +23 -6
- package/dist/types/src/components/Graph/Graph.d.ts.map +1 -1
- package/dist/types/src/components/Graph/Graph.stories.d.ts +19 -10
- 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 +9 -5
- package/dist/types/src/components/Mesh/Mesh.stories.d.ts.map +1 -1
- package/dist/types/src/components/SVG/FPS.d.ts +20 -0
- package/dist/types/src/components/SVG/FPS.d.ts.map +1 -0
- 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 +17 -18
- package/dist/types/src/components/SVG/SVG.d.ts.map +1 -1
- package/dist/types/src/components/SVG/Svg.stories.d.ts +11 -9
- package/dist/types/src/components/SVG/Svg.stories.d.ts.map +1 -1
- package/dist/types/src/fx/fx.stories.d.ts +16 -15
- package/dist/types/src/fx/fx.stories.d.ts.map +1 -1
- package/dist/types/src/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-bundle-projector.d.ts +47 -0
- package/dist/types/src/graph/projector/graph-bundle-projector.d.ts.map +1 -0
- package/dist/types/src/graph/projector/graph-cluster-projector.d.ts +65 -0
- package/dist/types/src/graph/projector/graph-cluster-projector.d.ts.map +1 -0
- 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-lattice-projector.d.ts +23 -0
- package/dist/types/src/graph/projector/graph-lattice-projector.d.ts.map +1 -0
- package/dist/types/src/graph/projector/graph-plexus-projector.d.ts +67 -0
- package/dist/types/src/graph/projector/graph-plexus-projector.d.ts.map +1 -0
- package/dist/types/src/graph/projector/graph-plexus-projector.test.d.ts +2 -0
- package/dist/types/src/graph/projector/graph-plexus-projector.test.d.ts.map +1 -0
- package/dist/types/src/graph/projector/graph-projector.d.ts +10 -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 +7 -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/graph-swarm-projector.d.ts +72 -0
- package/dist/types/src/graph/projector/graph-swarm-projector.d.ts.map +1 -0
- package/dist/types/src/graph/projector/index.d.ts +5 -0
- package/dist/types/src/graph/projector/index.d.ts.map +1 -1
- package/dist/types/src/graph/projector/projector.d.ts +10 -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 +41 -1
- package/dist/types/src/graph/renderer/graph-renderer.d.ts.map +1 -1
- package/dist/types/src/graph/renderer/index.d.ts +1 -0
- package/dist/types/src/graph/renderer/index.d.ts.map +1 -1
- package/dist/types/src/graph/renderer/labels.d.ts +33 -0
- package/dist/types/src/graph/renderer/labels.d.ts.map +1 -0
- package/dist/types/src/graph/renderer/renderer.d.ts +12 -1
- package/dist/types/src/graph/renderer/renderer.d.ts.map +1 -1
- package/dist/types/src/graph/types.d.ts +15 -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/experimental.stories.d.ts +7 -0
- package/dist/types/src/stories/experimental.stories.d.ts.map +1 -0
- package/dist/types/src/stories/hooks.stories.d.ts +14 -9
- package/dist/types/src/stories/hooks.stories.d.ts.map +1 -1
- package/dist/types/src/testing/data.d.ts +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 +68 -65
- package/src/components/Graph/Graph.tsx +127 -24
- package/src/components/Mesh/Mesh.stories.tsx +15 -13
- package/src/components/Mesh/Mesh.tsx +43 -35
- package/src/components/SVG/FPS.tsx +91 -0
- package/src/components/SVG/Grid.tsx +1 -1
- package/src/components/SVG/Markers.tsx +1 -1
- package/src/components/SVG/Root.tsx +42 -9
- package/src/components/SVG/SVG.tsx +14 -3
- package/src/components/SVG/Svg.stories.tsx +22 -19
- package/src/fx/fx.stories.tsx +17 -15
- package/src/graph/projector/graph-bundle-projector.ts +210 -0
- package/src/graph/projector/graph-cluster-projector.ts +337 -0
- package/src/graph/projector/graph-drag.ts +0 -1
- package/src/graph/projector/graph-force-projector.ts +7 -3
- package/src/graph/projector/graph-hierarchical-projector.ts +4 -4
- package/src/graph/projector/graph-lattice-projector.ts +86 -0
- package/src/graph/projector/graph-plexus-projector.test.ts +102 -0
- package/src/graph/projector/graph-plexus-projector.ts +309 -0
- package/src/graph/projector/graph-projector.ts +24 -4
- package/src/graph/projector/graph-radial-projector.ts +31 -4
- package/src/graph/projector/graph-relational-projector.ts +4 -4
- package/src/graph/projector/graph-swarm-projector.ts +373 -0
- package/src/graph/projector/index.ts +5 -0
- package/src/graph/projector/projector.ts +12 -3
- package/src/graph/renderer/graph-renderer.ts +289 -31
- package/src/graph/renderer/index.ts +1 -0
- package/src/graph/renderer/labels.ts +138 -0
- package/src/graph/renderer/renderer.ts +15 -4
- package/src/graph/types.ts +15 -1
- package/src/hooks/useStateRef.ts +1 -1
- package/src/stories/experimental.stories.tsx +446 -0
- package/src/stories/hooks.stories.tsx +44 -32
- 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 +341 -43
- package/dist/lib/browser/chunk-HLAKLUDC.mjs +0 -958
- package/dist/lib/browser/chunk-HLAKLUDC.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-O6GWCXDC.mjs +0 -960
- package/dist/lib/node-esm/chunk-O6GWCXDC.mjs.map +0 -7
package/package.json
CHANGED
|
@@ -1,12 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/react-ui-graph",
|
|
3
|
-
"version": "0.8.4-
|
|
3
|
+
"version": "0.8.4-staging.60fe92afc8",
|
|
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.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/async": "0.8.4-
|
|
50
|
-
"@dxos/debug": "0.8.4-
|
|
51
|
-
"@dxos/
|
|
52
|
-
"@dxos/
|
|
53
|
-
"@dxos/node-std": "0.8.4-
|
|
54
|
-
"@dxos/
|
|
55
|
-
"@dxos/
|
|
47
|
+
"@dxos/async": "0.8.4-staging.60fe92afc8",
|
|
48
|
+
"@dxos/debug": "0.8.4-staging.60fe92afc8",
|
|
49
|
+
"@dxos/graph": "0.8.4-staging.60fe92afc8",
|
|
50
|
+
"@dxos/invariant": "0.8.4-staging.60fe92afc8",
|
|
51
|
+
"@dxos/node-std": "0.8.4-staging.60fe92afc8",
|
|
52
|
+
"@dxos/react-ui-mosaic": "0.8.4-staging.60fe92afc8",
|
|
53
|
+
"@dxos/log": "0.8.4-staging.60fe92afc8"
|
|
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/
|
|
69
|
-
"@dxos/
|
|
70
|
-
"@dxos/react-ui-
|
|
71
|
-
"@dxos/react-ui-
|
|
72
|
-
"@dxos/storybook-utils": "0.8.4-
|
|
73
|
-
"@dxos/
|
|
63
|
+
"postcss": "^8.5.12",
|
|
64
|
+
"react": "~19.2.3",
|
|
65
|
+
"react-dom": "~19.2.3",
|
|
66
|
+
"@dxos/react-ui": "0.8.4-staging.60fe92afc8",
|
|
67
|
+
"@dxos/random": "0.8.4-staging.60fe92afc8",
|
|
68
|
+
"@dxos/react-ui-stack": "0.8.4-staging.60fe92afc8",
|
|
69
|
+
"@dxos/react-ui-syntax-highlighter": "0.8.4-staging.60fe92afc8",
|
|
70
|
+
"@dxos/storybook-utils": "0.8.4-staging.60fe92afc8",
|
|
71
|
+
"@dxos/ui-theme": "0.8.4-staging.60fe92afc8"
|
|
74
72
|
},
|
|
75
73
|
"peerDependencies": {
|
|
76
|
-
"react": "~
|
|
77
|
-
"react-dom": "~
|
|
78
|
-
"@dxos/react-ui": "0.8.4-
|
|
79
|
-
"@dxos/
|
|
74
|
+
"react": "~19.2.3",
|
|
75
|
+
"react-dom": "~19.2.3",
|
|
76
|
+
"@dxos/react-ui": "0.8.4-staging.60fe92afc8",
|
|
77
|
+
"@dxos/ui-theme": "0.8.4-staging.60fe92afc8"
|
|
80
78
|
},
|
|
81
79
|
"optionalDependencies": {
|
|
82
|
-
"@dxos/random": "0.8.4-
|
|
80
|
+
"@dxos/random": "0.8.4-staging.60fe92afc8"
|
|
83
81
|
},
|
|
84
82
|
"publishConfig": {
|
|
85
83
|
"access": "public"
|
|
@@ -2,19 +2,20 @@
|
|
|
2
2
|
// Copyright 2022 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import '
|
|
5
|
+
import '../../../styles/graph.css';
|
|
6
6
|
|
|
7
|
-
import {
|
|
8
|
-
import { type StoryObj } from '@storybook/react-vite';
|
|
7
|
+
import { RegistryContext } from '@effect-atom/atom-react';
|
|
8
|
+
import { type Meta, type StoryObj } from '@storybook/react-vite';
|
|
9
9
|
import { select } from 'd3';
|
|
10
|
-
import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
10
|
+
import React, { useCallback, useContext, useEffect, useMemo, useRef, useState } from 'react';
|
|
11
11
|
|
|
12
|
-
import { type Graph, type GraphModel, SelectionModel } from '@dxos/graph';
|
|
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
20
|
import { Pulsar } from '../../fx';
|
|
20
21
|
import {
|
|
@@ -33,11 +34,8 @@ import {
|
|
|
33
34
|
import { type SVGContext } from '../../hooks';
|
|
34
35
|
import { TestGraphModel, type TestNode, convertTreeToGraph, createGraph, createNode, createTree } from '../../testing';
|
|
35
36
|
import { SVG, type SVGGridProps } from '../SVG';
|
|
36
|
-
|
|
37
37
|
import { Graph as GraphComponent, type GraphController, type GraphProps } from './Graph';
|
|
38
38
|
|
|
39
|
-
import '../../../styles/graph.css';
|
|
40
|
-
|
|
41
39
|
type ProjectorType = 'force' | 'radial' | 'hierarchical' | 'relational';
|
|
42
40
|
|
|
43
41
|
type Factory = {
|
|
@@ -51,12 +49,12 @@ const projectorTypes: Record<ProjectorType, Factory> = {
|
|
|
51
49
|
relational: GraphRelationalProjector as Factory,
|
|
52
50
|
};
|
|
53
51
|
|
|
54
|
-
type
|
|
52
|
+
type DefaultStoryProps = GraphProps & {
|
|
55
53
|
debug?: boolean;
|
|
56
54
|
grid?: boolean | SVGGridProps;
|
|
57
55
|
inspect?: boolean;
|
|
58
|
-
|
|
59
|
-
|
|
56
|
+
graph: () => Graph.Any;
|
|
57
|
+
selectionMode?: SelectionMode;
|
|
60
58
|
projectorType?: ProjectorType;
|
|
61
59
|
projectorOptions?:
|
|
62
60
|
| GraphForceProjectorOptions
|
|
@@ -69,18 +67,22 @@ const DefaultStory = ({
|
|
|
69
67
|
debug,
|
|
70
68
|
grid,
|
|
71
69
|
inspect,
|
|
72
|
-
|
|
70
|
+
selectionMode,
|
|
73
71
|
graph: _graph,
|
|
74
72
|
projectorType: _projectorType = 'force',
|
|
75
73
|
projectorOptions,
|
|
76
74
|
...props
|
|
77
|
-
}:
|
|
75
|
+
}: DefaultStoryProps) => {
|
|
78
76
|
const graphRef = useRef<GraphController | null>(null);
|
|
79
77
|
const context = useRef<SVGContext>(null);
|
|
78
|
+
const registry = useContext(RegistryContext);
|
|
80
79
|
|
|
81
80
|
// Models.
|
|
82
|
-
const
|
|
83
|
-
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
|
+
});
|
|
84
86
|
|
|
85
87
|
// Projector.
|
|
86
88
|
const [projectorType, setProjectorType] = useState<ProjectorType>(_projectorType);
|
|
@@ -157,8 +159,9 @@ const DefaultStory = ({
|
|
|
157
159
|
}, [model]);
|
|
158
160
|
|
|
159
161
|
const handleRegenerate = useCallback(() => {
|
|
160
|
-
|
|
161
|
-
|
|
162
|
+
const graph = _graph?.();
|
|
163
|
+
setModel(graph ? new TestGraphModel(registry, graph) : undefined);
|
|
164
|
+
}, [_graph, registry]);
|
|
162
165
|
|
|
163
166
|
const handleClear = useCallback(() => {
|
|
164
167
|
setModel(undefined);
|
|
@@ -182,7 +185,7 @@ const DefaultStory = ({
|
|
|
182
185
|
|
|
183
186
|
const active = useMemo(() => new SelectionModel(), []);
|
|
184
187
|
const handlePing = useCallback(() => {
|
|
185
|
-
for (const id of active.
|
|
188
|
+
for (const id of active.getSelectedIds()) {
|
|
186
189
|
const node = graphRef.current?.findNode(id);
|
|
187
190
|
if (node) {
|
|
188
191
|
Pulsar.remove(select(node));
|
|
@@ -190,7 +193,7 @@ const DefaultStory = ({
|
|
|
190
193
|
}
|
|
191
194
|
|
|
192
195
|
active.clear();
|
|
193
|
-
for (const id of selection.
|
|
196
|
+
for (const id of selection.getSelectedIds()) {
|
|
194
197
|
const node = graphRef.current?.findNode(id);
|
|
195
198
|
if (node) {
|
|
196
199
|
active.add(id);
|
|
@@ -202,7 +205,7 @@ const DefaultStory = ({
|
|
|
202
205
|
|
|
203
206
|
return (
|
|
204
207
|
<Popover.Root open={!!popover} onOpenChange={(state) => !state && setPopover(undefined)}>
|
|
205
|
-
<div className={mx('w-full grid divide-x divide-separator', debug && 'grid-cols-[1fr_30rem]')}>
|
|
208
|
+
<div className={mx('h-full w-full grid divide-x divide-separator', debug && 'grid-cols-[1fr_30rem]')}>
|
|
206
209
|
<SVG.Root ref={context}>
|
|
207
210
|
<SVG.Markers />
|
|
208
211
|
{grid && <SVG.Grid {...(typeof grid === 'boolean' ? { axis: grid } : grid)} />}
|
|
@@ -217,7 +220,7 @@ const DefaultStory = ({
|
|
|
217
220
|
attributes={{
|
|
218
221
|
node: (node: GraphLayoutNode<TestNode>) => ({
|
|
219
222
|
data: {
|
|
220
|
-
color:
|
|
223
|
+
color: getHashStyles(node.data?.type ?? node.type)?.hue,
|
|
221
224
|
},
|
|
222
225
|
classes: {
|
|
223
226
|
'dx-selected': selection.contains(node.id),
|
|
@@ -225,7 +228,7 @@ const DefaultStory = ({
|
|
|
225
228
|
}),
|
|
226
229
|
edge: (edge: GraphLayoutEdge<TestNode>) => ({
|
|
227
230
|
data: {
|
|
228
|
-
color:
|
|
231
|
+
color: getHashStyles(edge.data?.type ?? edge.type)?.hue,
|
|
229
232
|
},
|
|
230
233
|
}),
|
|
231
234
|
}}
|
|
@@ -256,13 +259,9 @@ const DefaultStory = ({
|
|
|
256
259
|
<Popover.VirtualTrigger virtualRef={popoverAnchorRef} />
|
|
257
260
|
<Popover.Content onOpenAutoFocus={(event) => event.preventDefault()}>
|
|
258
261
|
<Popover.Viewport>
|
|
259
|
-
<Card.
|
|
260
|
-
<
|
|
261
|
-
|
|
262
|
-
language='json'
|
|
263
|
-
code={JSON.stringify(popover, null, 2)}
|
|
264
|
-
/>
|
|
265
|
-
</Card.SurfaceRoot>
|
|
262
|
+
<Card.Root>
|
|
263
|
+
<JsonHighlighter data={popover} classNames='text-xs my-form-padding px-form-padding bg-transparent' />
|
|
264
|
+
</Card.Root>
|
|
266
265
|
</Popover.Viewport>
|
|
267
266
|
<Popover.Arrow />
|
|
268
267
|
</Popover.Content>
|
|
@@ -283,7 +282,7 @@ const Debug = ({
|
|
|
283
282
|
onDelete,
|
|
284
283
|
onPing,
|
|
285
284
|
}: {
|
|
286
|
-
model?: GraphModel;
|
|
285
|
+
model?: GraphModel.ReactiveGraphModel;
|
|
287
286
|
selection: SelectionModel;
|
|
288
287
|
projector: ProjectorType;
|
|
289
288
|
onToggleProjector: () => void;
|
|
@@ -297,44 +296,50 @@ const Debug = ({
|
|
|
297
296
|
}) => {
|
|
298
297
|
const [data, setData] = useState({});
|
|
299
298
|
useEffect(() => {
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
model: model?.toJSON(),
|
|
305
|
-
});
|
|
299
|
+
setData({
|
|
300
|
+
projector,
|
|
301
|
+
selection: selection.toJSON(),
|
|
302
|
+
model: model?.toJSON(),
|
|
306
303
|
});
|
|
307
304
|
}, [model, selection, projector]);
|
|
308
305
|
|
|
309
306
|
return (
|
|
310
307
|
<div className='flex flex-col overflow-hidden'>
|
|
311
308
|
<Toolbar.Root>
|
|
312
|
-
<IconButton onClick={onToggleProjector}
|
|
313
|
-
<IconButton onClick={onRefresh}
|
|
314
|
-
<IconButton onClick={onRepaint}
|
|
315
|
-
<IconButton onClick={onRegenerate}
|
|
316
|
-
<IconButton onClick={onClear}
|
|
317
|
-
<IconButton onClick={onAdd}
|
|
318
|
-
<IconButton onClick={onDelete}
|
|
319
|
-
<IconButton onClick={onPing}
|
|
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 />
|
|
320
317
|
</Toolbar.Root>
|
|
321
|
-
<
|
|
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>
|
|
322
326
|
</div>
|
|
323
327
|
);
|
|
324
328
|
};
|
|
325
329
|
|
|
326
|
-
const meta
|
|
330
|
+
const meta = {
|
|
327
331
|
title: 'ui/react-ui-graph/Graph',
|
|
328
332
|
render: DefaultStory,
|
|
329
|
-
decorators: [withTheme, withLayout({
|
|
333
|
+
decorators: [withRegistry, withTheme(), withLayout({ layout: 'fullscreen' })],
|
|
330
334
|
parameters: {
|
|
335
|
+
layout: 'fullscreen',
|
|
331
336
|
controls: { disable: true },
|
|
332
337
|
},
|
|
333
|
-
}
|
|
338
|
+
} satisfies Meta<typeof DefaultStory>;
|
|
334
339
|
|
|
335
340
|
export default meta;
|
|
336
341
|
|
|
337
|
-
type Story = StoryObj<
|
|
342
|
+
type Story = StoryObj<typeof meta>;
|
|
338
343
|
|
|
339
344
|
export const Default: Story = {
|
|
340
345
|
args: {
|
|
@@ -354,7 +359,7 @@ export const Projector: Story = {
|
|
|
354
359
|
debug: true,
|
|
355
360
|
drag: true,
|
|
356
361
|
arrows: true,
|
|
357
|
-
|
|
362
|
+
selectionMode: 'single',
|
|
358
363
|
projectorType: 'hierarchical',
|
|
359
364
|
projectorOptions: {
|
|
360
365
|
duration: 500,
|
|
@@ -450,14 +455,12 @@ export const WithPopover: Story = {
|
|
|
450
455
|
},
|
|
451
456
|
};
|
|
452
457
|
|
|
453
|
-
export const Empty
|
|
454
|
-
|
|
455
|
-
<SVG.
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
<
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
),
|
|
463
|
-
};
|
|
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,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,55 +26,103 @@ export type GraphController = {
|
|
|
27
26
|
findNode: (id: string) => SVGGElement | null;
|
|
28
27
|
};
|
|
29
28
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
29
|
+
/** Cursor position expressed in the same SVG model coordinates that node `x/y` live in (centered origin, post-zoom). */
|
|
30
|
+
export type ModelPoint = { x: number; y: number };
|
|
31
|
+
|
|
32
|
+
export type GraphProps<Node extends Graph$.Node.Any = any, Edge extends Graph$.Edge.Any = any> = ThemedClassName<
|
|
33
|
+
Pick<
|
|
34
|
+
GraphRendererOptions<Node>,
|
|
35
|
+
'labels' | 'subgraphs' | 'attributes' | 'renderNode' | 'highlightOnHover' | 'applyNode' | 'edgeOpacity'
|
|
36
|
+
> & {
|
|
37
|
+
model?: GraphModel.ReactiveGraphModel<Node, Edge>;
|
|
33
38
|
projector?: GraphProjector<Node>;
|
|
34
39
|
renderer?: GraphRenderer<Node>;
|
|
35
40
|
drag?: boolean;
|
|
36
41
|
arrows?: boolean;
|
|
37
42
|
onSelect?: (node: GraphLayoutNode<Node>, event: MouseEvent) => void;
|
|
38
|
-
|
|
43
|
+
/**
|
|
44
|
+
* Fires on pointerenter with the hovered node, and on pointerleave with `null`.
|
|
45
|
+
* Use the `null` signal to clear hover-driven previews / highlights.
|
|
46
|
+
*/
|
|
47
|
+
onInspect?: (node: GraphLayoutNode<Node> | null, event: MouseEvent) => void;
|
|
48
|
+
/**
|
|
49
|
+
* Pointer-move in SVG model coordinates (the same space `node.x/y` live in — centered
|
|
50
|
+
* origin, post-zoom). The CTM lookup is done against the dx-graph group, so zoom + viewBox
|
|
51
|
+
* are both undone in one step. Pair with `onPointerLeave` to clear cursor-driven state.
|
|
52
|
+
* When either handler is set the renderer's `<svg>` is given `pointer-events: all` so
|
|
53
|
+
* events fire across empty canvas, not just over painted nodes.
|
|
54
|
+
*/
|
|
55
|
+
onPointerMove?: (point: ModelPoint, event: PointerEvent) => void;
|
|
56
|
+
onPointerLeave?: (event: PointerEvent) => void;
|
|
39
57
|
}
|
|
40
58
|
>;
|
|
41
59
|
|
|
42
|
-
|
|
60
|
+
const GraphInner = <Node extends Graph$.Node.Any = any, Edge extends Graph$.Edge.Any = any>(
|
|
43
61
|
{
|
|
44
62
|
classNames,
|
|
45
63
|
model,
|
|
46
|
-
projector:
|
|
47
|
-
renderer:
|
|
64
|
+
projector: projectorProp,
|
|
65
|
+
renderer: rendererProp,
|
|
48
66
|
drag,
|
|
49
67
|
arrows,
|
|
50
68
|
onSelect,
|
|
51
69
|
onInspect,
|
|
70
|
+
onPointerMove,
|
|
71
|
+
onPointerLeave,
|
|
52
72
|
...props
|
|
53
73
|
}: GraphProps<Node, Edge>,
|
|
54
74
|
forwardedRef: Ref<GraphController>,
|
|
55
75
|
) => {
|
|
56
76
|
const context = useSvgContext();
|
|
57
|
-
const graphRef = useRef<SVGGElement>();
|
|
77
|
+
const graphRef = useRef<SVGGElement>(null);
|
|
58
78
|
|
|
59
79
|
const { projector, renderer } = useMemo(() => {
|
|
60
|
-
let projector =
|
|
80
|
+
let projector = projectorProp;
|
|
61
81
|
if (!projector) {
|
|
62
82
|
projector = new GraphForceProjector<Node>(context);
|
|
63
83
|
}
|
|
64
84
|
|
|
65
|
-
let renderer =
|
|
85
|
+
let renderer = rendererProp;
|
|
66
86
|
if (!renderer) {
|
|
67
87
|
renderer = new GraphRenderer<Node>(context, graphRef, {
|
|
68
88
|
...props,
|
|
69
89
|
// TODO(burdon): Replace drag when projector is updated.
|
|
70
90
|
drag: drag ? createGraphDrag(context, projector) : undefined,
|
|
71
91
|
arrows: { end: arrows },
|
|
72
|
-
|
|
73
|
-
|
|
92
|
+
// Projector intercept first so built-in interactions (e.g. cluster collapse) can
|
|
93
|
+
// run without consumers wiring them. Returning true suppresses the user handler.
|
|
94
|
+
onNodeClick: (node, event) => {
|
|
95
|
+
if (projector.handleNodeClick(node, event)) {
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
onSelect?.(node, event);
|
|
99
|
+
},
|
|
100
|
+
onNodePointerEnter: onInspect ? (node, event) => onInspect(node, event) : undefined,
|
|
101
|
+
// Pair pointerenter with leave so consumers can clear hover-driven previews.
|
|
102
|
+
// The callback receives `null` on leave (event still carries the source).
|
|
103
|
+
onNodePointerLeave: onInspect ? (_node, event) => onInspect(null, event) : undefined,
|
|
74
104
|
});
|
|
75
105
|
}
|
|
76
106
|
|
|
77
107
|
return { projector, renderer };
|
|
78
|
-
|
|
108
|
+
// Renderer options are baked into the instance — re-memo when any of them change
|
|
109
|
+
// so a swapped `renderNode` / handler is actually applied.
|
|
110
|
+
}, [
|
|
111
|
+
context,
|
|
112
|
+
projectorProp,
|
|
113
|
+
rendererProp,
|
|
114
|
+
drag,
|
|
115
|
+
arrows,
|
|
116
|
+
onSelect,
|
|
117
|
+
onInspect,
|
|
118
|
+
props.labels,
|
|
119
|
+
props.subgraphs,
|
|
120
|
+
props.attributes,
|
|
121
|
+
props.renderNode,
|
|
122
|
+
props.highlightOnHover,
|
|
123
|
+
props.applyNode,
|
|
124
|
+
props.edgeOpacity,
|
|
125
|
+
]);
|
|
79
126
|
|
|
80
127
|
// External API.
|
|
81
128
|
useImperativeHandle(
|
|
@@ -96,19 +143,34 @@ export const GraphInner = <Node extends BaseGraphNode = any, Edge extends BaseGr
|
|
|
96
143
|
|
|
97
144
|
// Subscriptions.
|
|
98
145
|
useEffect(() => {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
146
|
+
// Wire the renderer listener BEFORE calling updateData so the synchronous
|
|
147
|
+
// 'topology' emit (fired from inside onUpdate) reaches the renderer.
|
|
148
|
+
const cleanup = combine(
|
|
149
|
+
// Subscribe to model changes if reactive model.
|
|
150
|
+
model
|
|
151
|
+
? model.subscribe(() => {
|
|
152
|
+
projector.updateData(model?.graph);
|
|
153
|
+
})
|
|
154
|
+
: undefined,
|
|
155
|
+
|
|
156
|
+
projector.updated.on(({ layout, kind }) => {
|
|
104
157
|
try {
|
|
105
|
-
|
|
158
|
+
// 'positions' is the per-tick fast path; 'topology' (and unset, for back-compat) is the full render.
|
|
159
|
+
if (kind === 'positions') {
|
|
160
|
+
renderer.applyPositions(layout);
|
|
161
|
+
} else {
|
|
162
|
+
renderer.render(layout);
|
|
163
|
+
}
|
|
106
164
|
} catch (error) {
|
|
107
|
-
void projector.stop();
|
|
108
165
|
log.catch(error);
|
|
166
|
+
void projector.stop();
|
|
109
167
|
}
|
|
110
168
|
}),
|
|
111
169
|
);
|
|
170
|
+
|
|
171
|
+
projector.updateData(model?.graph);
|
|
172
|
+
|
|
173
|
+
return cleanup;
|
|
112
174
|
}, [model, projector, renderer]);
|
|
113
175
|
|
|
114
176
|
// Start.
|
|
@@ -119,12 +181,53 @@ export const GraphInner = <Node extends BaseGraphNode = any, Edge extends BaseGr
|
|
|
119
181
|
};
|
|
120
182
|
}, [projector]);
|
|
121
183
|
|
|
184
|
+
// Model-space pointer events. Attached to the SVG element so they fire across the entire
|
|
185
|
+
// canvas (with pointer-events: all), not just over painted nodes. The dx-graph group's CTM
|
|
186
|
+
// undoes both the centered viewBox and any active zoom in one step, landing the cursor in
|
|
187
|
+
// the same coordinate space the projector reads.
|
|
188
|
+
useEffect(() => {
|
|
189
|
+
if (!onPointerMove && !onPointerLeave) {
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
const svg = context.svg;
|
|
193
|
+
if (!svg) {
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
const previousPointerEvents = svg.style.pointerEvents;
|
|
197
|
+
svg.style.pointerEvents = 'all';
|
|
198
|
+
const handleMove = (event: PointerEvent) => {
|
|
199
|
+
if (!onPointerMove) {
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
const target = graphRef.current;
|
|
203
|
+
const ctm = target?.getScreenCTM();
|
|
204
|
+
if (!target || !ctm) {
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
const point = svg.createSVGPoint();
|
|
208
|
+
point.x = event.clientX;
|
|
209
|
+
point.y = event.clientY;
|
|
210
|
+
const modelPoint = point.matrixTransform(ctm.inverse());
|
|
211
|
+
onPointerMove({ x: modelPoint.x, y: modelPoint.y }, event);
|
|
212
|
+
};
|
|
213
|
+
const handleLeave = (event: PointerEvent) => {
|
|
214
|
+
onPointerLeave?.(event);
|
|
215
|
+
};
|
|
216
|
+
svg.addEventListener('pointermove', handleMove);
|
|
217
|
+
svg.addEventListener('pointerleave', handleLeave);
|
|
218
|
+
return () => {
|
|
219
|
+
svg.removeEventListener('pointermove', handleMove);
|
|
220
|
+
svg.removeEventListener('pointerleave', handleLeave);
|
|
221
|
+
svg.style.pointerEvents = previousPointerEvents;
|
|
222
|
+
};
|
|
223
|
+
}, [context, onPointerMove, onPointerLeave]);
|
|
224
|
+
|
|
122
225
|
return <g ref={graphRef} className={mx('dx-graph', classNames)} />;
|
|
123
226
|
};
|
|
124
227
|
|
|
125
228
|
/**
|
|
126
229
|
* SVG Graph.
|
|
127
230
|
*/
|
|
128
|
-
export const Graph = forwardRef(GraphInner) as <Node extends
|
|
231
|
+
export const Graph = forwardRef(GraphInner) as <Node extends Graph$.Node.Any = any, Edge extends Graph$.Edge.Any = any>(
|
|
129
232
|
props: GraphProps<Node, Edge> & { ref?: Ref<GraphController> },
|
|
130
233
|
) => JSX.Element;
|
|
@@ -2,15 +2,12 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import '@
|
|
6
|
-
|
|
7
|
-
import { type StoryObj } from '@storybook/react-vite';
|
|
5
|
+
import { type Meta, type StoryObj } from '@storybook/react-vite';
|
|
8
6
|
import React, { useEffect, useState } from 'react';
|
|
9
7
|
|
|
10
|
-
import {
|
|
8
|
+
import { withLayout, withTheme } from '@dxos/react-ui/testing';
|
|
11
9
|
|
|
12
10
|
import { SVG, type SVGRootProps } from '../SVG';
|
|
13
|
-
|
|
14
11
|
import { Mesh } from './Mesh';
|
|
15
12
|
|
|
16
13
|
// TODO(burdon): Create waves/game of life.
|
|
@@ -36,28 +33,33 @@ const DefaultStory = (props: SVGRootProps) => {
|
|
|
36
33
|
);
|
|
37
34
|
};
|
|
38
35
|
|
|
39
|
-
const meta
|
|
36
|
+
const meta = {
|
|
40
37
|
title: 'ui/react-ui-graph/Mesh',
|
|
41
38
|
render: DefaultStory,
|
|
42
|
-
decorators: [withTheme, withLayout({
|
|
43
|
-
|
|
39
|
+
decorators: [withTheme(), withLayout({ layout: 'fullscreen' })],
|
|
40
|
+
parameters: {
|
|
41
|
+
layout: 'fullscreen',
|
|
42
|
+
},
|
|
43
|
+
} satisfies Meta<typeof DefaultStory>;
|
|
44
44
|
|
|
45
45
|
export default meta;
|
|
46
46
|
|
|
47
|
-
type Story = StoryObj<typeof
|
|
47
|
+
type Story = StoryObj<typeof meta>;
|
|
48
48
|
|
|
49
|
+
// 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.
|
|
49
51
|
export const Default: Story = {
|
|
50
52
|
args: {
|
|
51
53
|
classNames: [
|
|
52
|
-
'[
|
|
53
|
-
'[
|
|
54
|
-
'[
|
|
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',
|
|
55
57
|
],
|
|
56
58
|
},
|
|
57
59
|
};
|
|
58
60
|
|
|
59
61
|
export const Outline: Story = {
|
|
60
62
|
args: {
|
|
61
|
-
classNames: ['[
|
|
63
|
+
classNames: ['[&_.mesh]:fill-none', '[&_.border]:fill-none [&_.border]:stroke-red-500 [&_.border]:stroke-2'],
|
|
62
64
|
},
|
|
63
65
|
};
|