@dxos/react-ui-graph 0.8.4-main.28f8d3d → 0.8.4-main.2c6827d
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-HLAKLUDC.mjs → chunk-XWA2XJDX.mjs} +119 -122
- package/dist/lib/browser/{chunk-HLAKLUDC.mjs.map → chunk-XWA2XJDX.mjs.map} +3 -3
- package/dist/lib/browser/index.mjs +4 -5
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +1 -1
- package/dist/lib/node-esm/{chunk-O6GWCXDC.mjs → chunk-3RLSFEEV.mjs} +119 -122
- package/dist/lib/node-esm/{chunk-O6GWCXDC.mjs.map → chunk-3RLSFEEV.mjs.map} +3 -3
- package/dist/lib/node-esm/index.mjs +4 -5
- package/dist/lib/node-esm/index.mjs.map +3 -3
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/testing/index.mjs +1 -1
- package/dist/types/src/components/Graph/Graph.stories.d.ts +14 -5
- 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/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/fx/fx.stories.d.ts +16 -15
- package/dist/types/src/fx/fx.stories.d.ts.map +1 -1
- package/dist/types/src/stories/hooks.stories.d.ts +10 -6
- package/dist/types/src/stories/hooks.stories.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +24 -24
- package/src/components/Graph/Graph.stories.tsx +29 -32
- package/src/components/Graph/Graph.tsx +1 -1
- package/src/components/Mesh/Mesh.stories.tsx +9 -8
- package/src/components/SVG/Markers.tsx +1 -1
- package/src/components/SVG/Svg.stories.tsx +21 -17
- package/src/fx/fx.stories.tsx +13 -10
- package/src/hooks/useStateRef.ts +1 -1
- package/src/stories/hooks.stories.tsx +26 -25
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/react-ui-graph",
|
|
3
|
-
"version": "0.8.4-main.
|
|
3
|
+
"version": "0.8.4-main.2c6827d",
|
|
4
4
|
"description": "GEM Graph.",
|
|
5
5
|
"homepage": "https://dxos.org",
|
|
6
6
|
"bugs": "https://github.com/dxos/dxos/issues",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
],
|
|
39
39
|
"dependencies": {
|
|
40
40
|
"@preact-signals/safe-react": "^0.9.0",
|
|
41
|
-
"@preact/signals-core": "^1.
|
|
41
|
+
"@preact/signals-core": "^1.12.1",
|
|
42
42
|
"d3": "^7.9.0",
|
|
43
43
|
"d3-force": "~3.0.0",
|
|
44
44
|
"immutability-helper": "^3.0.2",
|
|
@@ -46,40 +46,40 @@
|
|
|
46
46
|
"lodash.defaultsdeep": "^4.6.1",
|
|
47
47
|
"react-resize-detector": "^11.0.1",
|
|
48
48
|
"topojson-client": "^3.1.0",
|
|
49
|
-
"@dxos/async": "0.8.4-main.
|
|
50
|
-
"@dxos/
|
|
51
|
-
"@dxos/
|
|
52
|
-
"@dxos/
|
|
53
|
-
"@dxos/
|
|
54
|
-
"@dxos/
|
|
55
|
-
"@dxos/
|
|
49
|
+
"@dxos/async": "0.8.4-main.2c6827d",
|
|
50
|
+
"@dxos/echo-signals": "0.8.4-main.2c6827d",
|
|
51
|
+
"@dxos/graph": "0.8.4-main.2c6827d",
|
|
52
|
+
"@dxos/debug": "0.8.4-main.2c6827d",
|
|
53
|
+
"@dxos/log": "0.8.4-main.2c6827d",
|
|
54
|
+
"@dxos/node-std": "0.8.4-main.2c6827d",
|
|
55
|
+
"@dxos/invariant": "0.8.4-main.2c6827d"
|
|
56
56
|
},
|
|
57
57
|
"devDependencies": {
|
|
58
58
|
"@babel/core": "^7.18.13",
|
|
59
59
|
"@types/d3": "^7.4.3",
|
|
60
60
|
"@types/lodash.defaultsdeep": "^4.6.6",
|
|
61
|
-
"@types/react": "~
|
|
62
|
-
"@types/react-dom": "~
|
|
61
|
+
"@types/react": "~19.2.2",
|
|
62
|
+
"@types/react-dom": "~19.2.2",
|
|
63
63
|
"@types/topojson-client": "^3.1.4",
|
|
64
64
|
"@types/topojson-specification": "^1.0.5",
|
|
65
65
|
"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/react-ui-stack": "0.8.4-main.
|
|
71
|
-
"@dxos/react-ui-
|
|
72
|
-
"@dxos/storybook-utils": "0.8.4-main.
|
|
73
|
-
"@dxos/react-ui-
|
|
66
|
+
"react": "~19.2.0",
|
|
67
|
+
"react-dom": "~19.2.0",
|
|
68
|
+
"@dxos/random": "0.8.4-main.2c6827d",
|
|
69
|
+
"@dxos/react-ui": "0.8.4-main.2c6827d",
|
|
70
|
+
"@dxos/react-ui-stack": "0.8.4-main.2c6827d",
|
|
71
|
+
"@dxos/react-ui-theme": "0.8.4-main.2c6827d",
|
|
72
|
+
"@dxos/storybook-utils": "0.8.4-main.2c6827d",
|
|
73
|
+
"@dxos/react-ui-syntax-highlighter": "0.8.4-main.2c6827d"
|
|
74
74
|
},
|
|
75
75
|
"peerDependencies": {
|
|
76
|
-
"react": "
|
|
77
|
-
"react-dom": "
|
|
78
|
-
"@dxos/react-ui": "0.8.4-main.
|
|
79
|
-
"@dxos/react-ui-theme": "0.8.4-main.
|
|
76
|
+
"react": "^19.0.0",
|
|
77
|
+
"react-dom": "^19.0.0",
|
|
78
|
+
"@dxos/react-ui": "0.8.4-main.2c6827d",
|
|
79
|
+
"@dxos/react-ui-theme": "0.8.4-main.2c6827d"
|
|
80
80
|
},
|
|
81
81
|
"optionalDependencies": {
|
|
82
|
-
"@dxos/random": "0.8.4-main.
|
|
82
|
+
"@dxos/random": "0.8.4-main.2c6827d"
|
|
83
83
|
},
|
|
84
84
|
"publishConfig": {
|
|
85
85
|
"access": "public"
|
|
@@ -2,19 +2,17 @@
|
|
|
2
2
|
// Copyright 2022 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import '@dxos-theme';
|
|
6
|
-
|
|
7
5
|
import { effect } from '@preact/signals-core';
|
|
8
|
-
import { type StoryObj } from '@storybook/react-vite';
|
|
6
|
+
import { type Meta, type StoryObj } from '@storybook/react-vite';
|
|
9
7
|
import { select } from 'd3';
|
|
10
8
|
import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
11
9
|
|
|
12
10
|
import { type Graph, type GraphModel, SelectionModel } from '@dxos/graph';
|
|
13
11
|
import { IconButton, Popover, Toolbar } from '@dxos/react-ui';
|
|
12
|
+
import { withTheme } from '@dxos/react-ui/testing';
|
|
14
13
|
import { Card } from '@dxos/react-ui-stack';
|
|
15
14
|
import { JsonFilter, SyntaxHighlighter } from '@dxos/react-ui-syntax-highlighter';
|
|
16
|
-
import {
|
|
17
|
-
import { type Meta, withLayout, withTheme } from '@dxos/storybook-utils';
|
|
15
|
+
import { getHashStyles, mx } from '@dxos/react-ui-theme';
|
|
18
16
|
|
|
19
17
|
import { Pulsar } from '../../fx';
|
|
20
18
|
import {
|
|
@@ -202,7 +200,7 @@ const DefaultStory = ({
|
|
|
202
200
|
|
|
203
201
|
return (
|
|
204
202
|
<Popover.Root open={!!popover} onOpenChange={(state) => !state && setPopover(undefined)}>
|
|
205
|
-
<div className={mx('
|
|
203
|
+
<div className={mx('is-full grid divide-x divide-separator', debug && 'grid-cols-[1fr_30rem]')}>
|
|
206
204
|
<SVG.Root ref={context}>
|
|
207
205
|
<SVG.Markers />
|
|
208
206
|
{grid && <SVG.Grid {...(typeof grid === 'boolean' ? { axis: grid } : grid)} />}
|
|
@@ -217,7 +215,7 @@ const DefaultStory = ({
|
|
|
217
215
|
attributes={{
|
|
218
216
|
node: (node: GraphLayoutNode<TestNode>) => ({
|
|
219
217
|
data: {
|
|
220
|
-
color:
|
|
218
|
+
color: getHashStyles(node.data?.type ?? node.type)?.hue,
|
|
221
219
|
},
|
|
222
220
|
classes: {
|
|
223
221
|
'dx-selected': selection.contains(node.id),
|
|
@@ -225,7 +223,7 @@ const DefaultStory = ({
|
|
|
225
223
|
}),
|
|
226
224
|
edge: (edge: GraphLayoutEdge<TestNode>) => ({
|
|
227
225
|
data: {
|
|
228
|
-
color:
|
|
226
|
+
color: getHashStyles(edge.data?.type ?? edge.type)?.hue,
|
|
229
227
|
},
|
|
230
228
|
}),
|
|
231
229
|
}}
|
|
@@ -258,8 +256,8 @@ const DefaultStory = ({
|
|
|
258
256
|
<Popover.Viewport>
|
|
259
257
|
<Card.SurfaceRoot role='card--popover'>
|
|
260
258
|
<SyntaxHighlighter
|
|
261
|
-
classNames='bg-transparent text-xs !mlb-cardSpacingBlock !pli-cardSpacingInline !overflow-visible'
|
|
262
259
|
language='json'
|
|
260
|
+
classNames='text-xs mlb-cardSpacingBlock pli-cardSpacingInline bg-transparent'
|
|
263
261
|
code={JSON.stringify(popover, null, 2)}
|
|
264
262
|
/>
|
|
265
263
|
</Card.SurfaceRoot>
|
|
@@ -309,32 +307,33 @@ const Debug = ({
|
|
|
309
307
|
return (
|
|
310
308
|
<div className='flex flex-col overflow-hidden'>
|
|
311
309
|
<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}
|
|
310
|
+
<IconButton onClick={onToggleProjector} label='Projector' icon='ph--graph--regular' iconOnly />
|
|
311
|
+
<IconButton onClick={onRefresh} label='Refresh' icon='ph--arrow-clockwise--regular' iconOnly />
|
|
312
|
+
<IconButton onClick={onRepaint} label='Repaint' icon='ph--paint-roller--regular' iconOnly />
|
|
313
|
+
<IconButton onClick={onRegenerate} label='Regenerate' icon='ph--arrows-clockwise--regular' iconOnly />
|
|
314
|
+
<IconButton onClick={onClear} label='Clear' icon='ph--trash--regular' iconOnly />
|
|
315
|
+
<IconButton onClick={onAdd} label='Add' icon='ph--plus--regular' iconOnly />
|
|
316
|
+
<IconButton onClick={onDelete} label='Delete' icon='ph--x--regular' iconOnly />
|
|
317
|
+
<IconButton onClick={onPing} label='Delete' icon='ph--crosshair-simple--regular' iconOnly />
|
|
320
318
|
</Toolbar.Root>
|
|
321
319
|
<JsonFilter data={data} classNames='text-sm' />
|
|
322
320
|
</div>
|
|
323
321
|
);
|
|
324
322
|
};
|
|
325
323
|
|
|
326
|
-
const meta
|
|
324
|
+
const meta = {
|
|
327
325
|
title: 'ui/react-ui-graph/Graph',
|
|
328
326
|
render: DefaultStory,
|
|
329
|
-
decorators: [withTheme
|
|
327
|
+
decorators: [withTheme],
|
|
330
328
|
parameters: {
|
|
329
|
+
layout: 'fullscreen',
|
|
331
330
|
controls: { disable: true },
|
|
332
331
|
},
|
|
333
|
-
}
|
|
332
|
+
} satisfies Meta<typeof DefaultStory>;
|
|
334
333
|
|
|
335
334
|
export default meta;
|
|
336
335
|
|
|
337
|
-
type Story = StoryObj<
|
|
336
|
+
type Story = StoryObj<typeof meta>;
|
|
338
337
|
|
|
339
338
|
export const Default: Story = {
|
|
340
339
|
args: {
|
|
@@ -450,14 +449,12 @@ export const WithPopover: Story = {
|
|
|
450
449
|
},
|
|
451
450
|
};
|
|
452
451
|
|
|
453
|
-
export const Empty
|
|
454
|
-
|
|
455
|
-
<SVG.
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
<
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
),
|
|
463
|
-
};
|
|
452
|
+
export const Empty = () => (
|
|
453
|
+
<SVG.Root>
|
|
454
|
+
<SVG.Markers />
|
|
455
|
+
<SVG.Grid axis />
|
|
456
|
+
<SVG.Zoom extent={[1 / 4, 4]}>
|
|
457
|
+
<GraphComponent />
|
|
458
|
+
</SVG.Zoom>
|
|
459
|
+
</SVG.Root>
|
|
460
|
+
);
|
|
@@ -54,7 +54,7 @@ export const GraphInner = <Node extends BaseGraphNode = any, Edge extends BaseGr
|
|
|
54
54
|
forwardedRef: Ref<GraphController>,
|
|
55
55
|
) => {
|
|
56
56
|
const context = useSvgContext();
|
|
57
|
-
const graphRef = useRef<SVGGElement>();
|
|
57
|
+
const graphRef = useRef<SVGGElement>(null);
|
|
58
58
|
|
|
59
59
|
const { projector, renderer } = useMemo(() => {
|
|
60
60
|
let projector = _projector;
|
|
@@ -2,12 +2,10 @@
|
|
|
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 { withTheme } from '@dxos/react-ui/testing';
|
|
11
9
|
|
|
12
10
|
import { SVG, type SVGRootProps } from '../SVG';
|
|
13
11
|
|
|
@@ -36,15 +34,18 @@ const DefaultStory = (props: SVGRootProps) => {
|
|
|
36
34
|
);
|
|
37
35
|
};
|
|
38
36
|
|
|
39
|
-
const meta
|
|
37
|
+
const meta = {
|
|
40
38
|
title: 'ui/react-ui-graph/Mesh',
|
|
41
39
|
render: DefaultStory,
|
|
42
|
-
decorators: [withTheme
|
|
43
|
-
|
|
40
|
+
decorators: [withTheme],
|
|
41
|
+
parameters: {
|
|
42
|
+
layout: 'fullscreen',
|
|
43
|
+
},
|
|
44
|
+
} satisfies Meta<typeof DefaultStory>;
|
|
44
45
|
|
|
45
46
|
export default meta;
|
|
46
47
|
|
|
47
|
-
type Story = StoryObj<typeof
|
|
48
|
+
type Story = StoryObj<typeof meta>;
|
|
48
49
|
|
|
49
50
|
export const Default: Story = {
|
|
50
51
|
args: {
|
|
@@ -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]);
|
|
@@ -2,11 +2,10 @@
|
|
|
2
2
|
// Copyright 2022 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import '@
|
|
6
|
-
|
|
5
|
+
import { type Meta, type StoryObj } from '@storybook/react-vite';
|
|
7
6
|
import React, { useRef } from 'react';
|
|
8
7
|
|
|
9
|
-
import {
|
|
8
|
+
import { withTheme } from '@dxos/react-ui/testing';
|
|
10
9
|
|
|
11
10
|
import { type SVGContext, useGrid, useZoom } from '../../hooks';
|
|
12
11
|
|
|
@@ -19,16 +18,6 @@ type ComponentProps = {
|
|
|
19
18
|
zoom?: boolean;
|
|
20
19
|
};
|
|
21
20
|
|
|
22
|
-
const DefaultStory = (props: ComponentProps) => {
|
|
23
|
-
const context = useRef<SVGContext>(null);
|
|
24
|
-
|
|
25
|
-
return (
|
|
26
|
-
<SVG.Root ref={context}>
|
|
27
|
-
<Component {...props} />
|
|
28
|
-
</SVG.Root>
|
|
29
|
-
);
|
|
30
|
-
};
|
|
31
|
-
|
|
32
21
|
const Component = (options: ComponentProps) => {
|
|
33
22
|
const grid = useGrid({ visible: options.grid, axis: true });
|
|
34
23
|
const zoom = useZoom({ enabled: options.zoom });
|
|
@@ -43,15 +32,30 @@ const Component = (options: ComponentProps) => {
|
|
|
43
32
|
);
|
|
44
33
|
};
|
|
45
34
|
|
|
46
|
-
const
|
|
35
|
+
const DefaultStory = (props: ComponentProps) => {
|
|
36
|
+
const context = useRef<SVGContext>(null);
|
|
37
|
+
|
|
38
|
+
return (
|
|
39
|
+
<SVG.Root ref={context}>
|
|
40
|
+
<Component {...props} />
|
|
41
|
+
</SVG.Root>
|
|
42
|
+
);
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const meta = {
|
|
47
46
|
title: 'ui/react-ui-graph/SVGRoot',
|
|
48
47
|
render: DefaultStory,
|
|
49
|
-
decorators: [withTheme
|
|
50
|
-
|
|
48
|
+
decorators: [withTheme],
|
|
49
|
+
parameters: {
|
|
50
|
+
layout: 'fullscreen',
|
|
51
|
+
},
|
|
52
|
+
} satisfies Meta<typeof DefaultStory>;
|
|
51
53
|
|
|
52
54
|
export default meta;
|
|
53
55
|
|
|
54
|
-
|
|
56
|
+
type Story = StoryObj<typeof meta>;
|
|
57
|
+
|
|
58
|
+
export const Default: Story = {
|
|
55
59
|
args: {
|
|
56
60
|
grid: true,
|
|
57
61
|
},
|
package/src/fx/fx.stories.tsx
CHANGED
|
@@ -2,13 +2,11 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import '@
|
|
6
|
-
|
|
7
|
-
import { type Meta } from '@storybook/react-vite';
|
|
5
|
+
import { type Meta, type StoryObj } from '@storybook/react-vite';
|
|
8
6
|
import { select } from 'd3';
|
|
9
7
|
import React, { type FC, useEffect, useMemo, useRef } from 'react';
|
|
10
8
|
|
|
11
|
-
import {
|
|
9
|
+
import { withTheme } from '@dxos/react-ui/testing';
|
|
12
10
|
|
|
13
11
|
import { SVG } from '../components';
|
|
14
12
|
import { useGrid, useZoom } from '../hooks';
|
|
@@ -54,7 +52,7 @@ const StoryComponent: FC<StoryProps> = ({ count = 1, ...options }) => {
|
|
|
54
52
|
const grid = useGrid({ axis: true, grid: false });
|
|
55
53
|
const zoom = useZoom();
|
|
56
54
|
|
|
57
|
-
const root = useRef<SVGGElement>();
|
|
55
|
+
const root = useRef<SVGGElement>(null);
|
|
58
56
|
useEffect(() => {
|
|
59
57
|
select(root.current)
|
|
60
58
|
.selectAll('g')
|
|
@@ -93,21 +91,26 @@ const createNode: D3Callable<SVGGElement, Datum> = (group, classNames, options)
|
|
|
93
91
|
});
|
|
94
92
|
};
|
|
95
93
|
|
|
96
|
-
const meta
|
|
94
|
+
const meta = {
|
|
97
95
|
title: 'ui/react-ui-graph/fx',
|
|
98
96
|
render: DefaultStory,
|
|
99
|
-
decorators: [withTheme
|
|
100
|
-
|
|
97
|
+
decorators: [withTheme],
|
|
98
|
+
parameters: {
|
|
99
|
+
layout: 'fullscreen',
|
|
100
|
+
},
|
|
101
|
+
} satisfies Meta<typeof DefaultStory>;
|
|
101
102
|
|
|
102
103
|
export default meta;
|
|
103
104
|
|
|
104
|
-
|
|
105
|
+
type Story = StoryObj<typeof meta>;
|
|
106
|
+
|
|
107
|
+
export const DefaultPulse: Story = {
|
|
105
108
|
args: {
|
|
106
109
|
count: 20,
|
|
107
110
|
},
|
|
108
111
|
};
|
|
109
112
|
|
|
110
|
-
export const RapidPulse = {
|
|
113
|
+
export const RapidPulse: Story = {
|
|
111
114
|
args: {
|
|
112
115
|
count: 20,
|
|
113
116
|
duration: 1_000,
|
package/src/hooks/useStateRef.ts
CHANGED
|
@@ -16,7 +16,7 @@ export const useStateRef = <V>(
|
|
|
16
16
|
initialValue?: V | (() => V),
|
|
17
17
|
): [V | undefined, Dispatch<SetStateAction<V | undefined>>, RefObject<V | undefined>] => {
|
|
18
18
|
const [value, setValue] = useState<V | undefined>(initialValue);
|
|
19
|
-
const ref = useRef<V>();
|
|
19
|
+
const ref = useRef<V>(null);
|
|
20
20
|
useEffect(() => {
|
|
21
21
|
ref.current = value;
|
|
22
22
|
}, [initialValue, value]);
|
|
@@ -2,15 +2,13 @@
|
|
|
2
2
|
// Copyright 2020 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 { select } from 'd3';
|
|
9
7
|
import React, { type PropsWithChildren, useEffect, useMemo, useRef } from 'react';
|
|
10
8
|
|
|
11
9
|
import { combine } from '@dxos/async';
|
|
12
10
|
import { log } from '@dxos/log';
|
|
13
|
-
import {
|
|
11
|
+
import { withTheme } from '@dxos/react-ui/testing';
|
|
14
12
|
|
|
15
13
|
import { SVG } from '../components';
|
|
16
14
|
import {
|
|
@@ -28,7 +26,7 @@ import { TestGraphModel, type TestNode, convertTreeToGraph, createTree } from '.
|
|
|
28
26
|
|
|
29
27
|
import '../../styles/graph.css';
|
|
30
28
|
|
|
31
|
-
type
|
|
29
|
+
type ComponentProps = PropsWithChildren<{
|
|
32
30
|
model: TestGraphModel;
|
|
33
31
|
projectorOptions?: GraphForceProjectorOptions;
|
|
34
32
|
count?: number;
|
|
@@ -37,28 +35,17 @@ type StoryProps = PropsWithChildren<{
|
|
|
37
35
|
grid?: boolean;
|
|
38
36
|
}>;
|
|
39
37
|
|
|
40
|
-
const
|
|
41
|
-
return (
|
|
42
|
-
<>
|
|
43
|
-
<SVG.Root>
|
|
44
|
-
<StoryComponent {...props} />
|
|
45
|
-
</SVG.Root>
|
|
46
|
-
{children && <div className='absolute left-4 bottom-4 font-mono text-green-500 text-xs'>{children}</div>}
|
|
47
|
-
</>
|
|
48
|
-
);
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
const StoryComponent = ({
|
|
38
|
+
const Component = ({
|
|
52
39
|
model,
|
|
53
40
|
projectorOptions,
|
|
54
41
|
count = 0,
|
|
55
42
|
interval = 200,
|
|
56
43
|
link = false,
|
|
57
44
|
grid: showGrid = false,
|
|
58
|
-
}:
|
|
45
|
+
}: ComponentProps) => {
|
|
59
46
|
const context = useSvgContext();
|
|
60
|
-
const graphRef = useRef<SVGGElement>();
|
|
61
|
-
const markersRef = useRef<SVGGElement>();
|
|
47
|
+
const graphRef = useRef<SVGGElement>(null);
|
|
48
|
+
const markersRef = useRef<SVGGElement>(null);
|
|
62
49
|
const grid = useGrid({ visible: showGrid });
|
|
63
50
|
const zoom = useZoom();
|
|
64
51
|
|
|
@@ -94,7 +81,7 @@ const StoryComponent = ({
|
|
|
94
81
|
labels: {
|
|
95
82
|
text: (node: GraphLayoutNode<TestNode>) => node.id.substring(0, 4),
|
|
96
83
|
},
|
|
97
|
-
onNodeClick: (node: GraphLayoutNode<TestNode
|
|
84
|
+
onNodeClick: (node: GraphLayoutNode<TestNode>) => {
|
|
98
85
|
renderer.fireBullet(node);
|
|
99
86
|
},
|
|
100
87
|
onLinkClick: (edge: GraphLayoutEdge<TestNode>, event: MouseEvent) => {
|
|
@@ -151,15 +138,29 @@ const StoryComponent = ({
|
|
|
151
138
|
);
|
|
152
139
|
};
|
|
153
140
|
|
|
154
|
-
const
|
|
141
|
+
const DefaultStory = ({ children, ...props }: ComponentProps) => {
|
|
142
|
+
return (
|
|
143
|
+
<>
|
|
144
|
+
<SVG.Root>
|
|
145
|
+
<Component {...props} />
|
|
146
|
+
</SVG.Root>
|
|
147
|
+
{children && <div className='absolute left-4 bottom-4 font-mono text-green-500 text-xs'>{children}</div>}
|
|
148
|
+
</>
|
|
149
|
+
);
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
const meta = {
|
|
155
153
|
title: 'ui/react-ui-graph/hooks',
|
|
156
154
|
render: DefaultStory,
|
|
157
|
-
decorators: [withTheme
|
|
158
|
-
|
|
155
|
+
decorators: [withTheme],
|
|
156
|
+
parameters: {
|
|
157
|
+
layout: 'fullscreen',
|
|
158
|
+
},
|
|
159
|
+
} satisfies Meta<typeof DefaultStory>;
|
|
159
160
|
|
|
160
161
|
export default meta;
|
|
161
162
|
|
|
162
|
-
type Story = StoryObj<typeof
|
|
163
|
+
type Story = StoryObj<typeof meta>;
|
|
163
164
|
|
|
164
165
|
export const Default: Story = {
|
|
165
166
|
args: {
|