@dxos/react-ui-graph 0.8.4-main.72ec0f3 → 0.8.4-main.74a063c4e0

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.
Files changed (79) hide show
  1. package/README.md +5 -7
  2. package/dist/lib/browser/chunk-LKC455GK.mjs +52 -0
  3. package/dist/lib/browser/chunk-LKC455GK.mjs.map +7 -0
  4. package/dist/lib/browser/index.mjs +1088 -238
  5. package/dist/lib/browser/index.mjs.map +4 -4
  6. package/dist/lib/browser/meta.json +1 -1
  7. package/dist/lib/browser/testing/index.mjs +16 -16
  8. package/dist/lib/browser/testing/index.mjs.map +3 -3
  9. package/dist/lib/node-esm/chunk-JE4KZCUF.mjs +54 -0
  10. package/dist/lib/node-esm/chunk-JE4KZCUF.mjs.map +7 -0
  11. package/dist/lib/node-esm/index.mjs +1088 -238
  12. package/dist/lib/node-esm/index.mjs.map +4 -4
  13. package/dist/lib/node-esm/meta.json +1 -1
  14. package/dist/lib/node-esm/testing/index.mjs +16 -16
  15. package/dist/lib/node-esm/testing/index.mjs.map +3 -3
  16. package/dist/types/src/components/Graph/Graph.d.ts +4 -5
  17. package/dist/types/src/components/Graph/Graph.d.ts.map +1 -1
  18. package/dist/types/src/components/Graph/Graph.stories.d.ts +4 -4
  19. package/dist/types/src/components/Graph/Graph.stories.d.ts.map +1 -1
  20. package/dist/types/src/components/Mesh/Mesh.stories.d.ts.map +1 -1
  21. package/dist/types/src/components/SVG/Root.d.ts +4 -4
  22. package/dist/types/src/components/SVG/Root.d.ts.map +1 -1
  23. package/dist/types/src/components/SVG/SVG.d.ts +14 -17
  24. package/dist/types/src/components/SVG/SVG.d.ts.map +1 -1
  25. package/dist/types/src/components/SVG/Svg.stories.d.ts +1 -1
  26. package/dist/types/src/components/SVG/Svg.stories.d.ts.map +1 -1
  27. package/dist/types/src/fx/fx.stories.d.ts +3 -3
  28. package/dist/types/src/fx/fx.stories.d.ts.map +1 -1
  29. package/dist/types/src/graph/projector/graph-drag.d.ts.map +1 -1
  30. package/dist/types/src/graph/projector/graph-force-projector.d.ts +1 -1
  31. package/dist/types/src/graph/projector/graph-force-projector.d.ts.map +1 -1
  32. package/dist/types/src/graph/projector/graph-hierarchical-projector.d.ts +1 -1
  33. package/dist/types/src/graph/projector/graph-hierarchical-projector.d.ts.map +1 -1
  34. package/dist/types/src/graph/projector/graph-projector.d.ts +2 -2
  35. package/dist/types/src/graph/projector/graph-projector.d.ts.map +1 -1
  36. package/dist/types/src/graph/projector/graph-radial-projector.d.ts +1 -1
  37. package/dist/types/src/graph/projector/graph-radial-projector.d.ts.map +1 -1
  38. package/dist/types/src/graph/projector/graph-relational-projector.d.ts +1 -1
  39. package/dist/types/src/graph/projector/graph-relational-projector.d.ts.map +1 -1
  40. package/dist/types/src/graph/renderer/graph-renderer.d.ts.map +1 -1
  41. package/dist/types/src/graph/types.d.ts +1 -1
  42. package/dist/types/src/graph/types.d.ts.map +1 -1
  43. package/dist/types/src/stories/hooks.stories.d.ts +4 -3
  44. package/dist/types/src/stories/hooks.stories.d.ts.map +1 -1
  45. package/dist/types/src/testing/data.d.ts +4 -4
  46. package/dist/types/src/testing/data.d.ts.map +1 -1
  47. package/dist/types/src/testing/hooks.d.ts +2 -16
  48. package/dist/types/src/testing/hooks.d.ts.map +1 -1
  49. package/dist/types/src/testing/model.d.ts +4 -8
  50. package/dist/types/src/testing/model.d.ts.map +1 -1
  51. package/dist/types/src/util/fraction.d.ts +1 -1
  52. package/dist/types/tsconfig.tsbuildinfo +1 -1
  53. package/package.json +31 -26
  54. package/src/components/Graph/Graph.stories.tsx +38 -30
  55. package/src/components/Graph/Graph.tsx +23 -15
  56. package/src/components/Mesh/Mesh.stories.tsx +2 -3
  57. package/src/components/SVG/Grid.tsx +1 -1
  58. package/src/components/SVG/Root.tsx +14 -7
  59. package/src/components/SVG/SVG.tsx +10 -2
  60. package/src/components/SVG/Svg.stories.tsx +4 -5
  61. package/src/fx/fx.stories.tsx +7 -8
  62. package/src/graph/projector/graph-drag.ts +0 -1
  63. package/src/graph/projector/graph-force-projector.ts +1 -2
  64. package/src/graph/projector/graph-hierarchical-projector.ts +3 -4
  65. package/src/graph/projector/graph-projector.ts +2 -3
  66. package/src/graph/projector/graph-radial-projector.ts +1 -2
  67. package/src/graph/projector/graph-relational-projector.ts +3 -4
  68. package/src/graph/renderer/graph-renderer.ts +0 -1
  69. package/src/graph/types.ts +1 -1
  70. package/src/stories/hooks.stories.tsx +15 -9
  71. package/src/testing/data.ts +14 -14
  72. package/src/testing/hooks.ts +3 -4
  73. package/src/testing/model.ts +6 -6
  74. package/src/util/fraction.ts +1 -1
  75. package/styles/graph.css +292 -43
  76. package/dist/lib/browser/chunk-XWA2XJDX.mjs +0 -955
  77. package/dist/lib/browser/chunk-XWA2XJDX.mjs.map +0 -7
  78. package/dist/lib/node-esm/chunk-3RLSFEEV.mjs +0 -957
  79. 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.72ec0f3",
3
+ "version": "0.8.4-main.74a063c4e0",
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": true,
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
- "@preact-signals/safe-react": "^0.9.0",
41
- "@preact/signals-core": "^1.12.1",
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.72ec0f3",
50
- "@dxos/debug": "0.8.4-main.72ec0f3",
51
- "@dxos/echo-signals": "0.8.4-main.72ec0f3",
52
- "@dxos/graph": "0.8.4-main.72ec0f3",
53
- "@dxos/invariant": "0.8.4-main.72ec0f3",
54
- "@dxos/log": "0.8.4-main.72ec0f3",
55
- "@dxos/node-std": "0.8.4-main.72ec0f3"
54
+ "@dxos/debug": "0.8.4-main.74a063c4e0",
55
+ "@dxos/log": "0.8.4-main.74a063c4e0",
56
+ "@dxos/async": "0.8.4-main.74a063c4e0",
57
+ "@dxos/invariant": "0.8.4-main.74a063c4e0",
58
+ "@dxos/node-std": "0.8.4-main.74a063c4e0",
59
+ "@dxos/react-ui-mosaic": "0.8.4-main.74a063c4e0",
60
+ "@dxos/graph": "0.8.4-main.74a063c4e0"
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.2",
62
- "@types/react-dom": "~19.2.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.0",
67
- "react-dom": "~19.2.0",
68
- "@dxos/react-ui": "0.8.4-main.72ec0f3",
69
- "@dxos/react-ui-stack": "0.8.4-main.72ec0f3",
70
- "@dxos/random": "0.8.4-main.72ec0f3",
71
- "@dxos/react-ui-syntax-highlighter": "0.8.4-main.72ec0f3",
72
- "@dxos/react-ui-theme": "0.8.4-main.72ec0f3",
73
- "@dxos/storybook-utils": "0.8.4-main.72ec0f3"
71
+ "react": "~19.2.3",
72
+ "react-dom": "~19.2.3",
73
+ "@dxos/random": "0.8.4-main.74a063c4e0",
74
+ "@dxos/react-ui-syntax-highlighter": "0.8.4-main.74a063c4e0",
75
+ "@dxos/react-ui": "0.8.4-main.74a063c4e0",
76
+ "@dxos/react-ui-stack": "0.8.4-main.74a063c4e0",
77
+ "@dxos/ui-theme": "0.8.4-main.74a063c4e0",
78
+ "@dxos/storybook-utils": "0.8.4-main.74a063c4e0"
74
79
  },
75
80
  "peerDependencies": {
76
- "react": "^19.0.0",
77
- "react-dom": "^19.0.0",
78
- "@dxos/react-ui-theme": "0.8.4-main.72ec0f3",
79
- "@dxos/react-ui": "0.8.4-main.72ec0f3"
81
+ "react": "~19.2.3",
82
+ "react-dom": "~19.2.3",
83
+ "@dxos/react-ui": "0.8.4-main.74a063c4e0",
84
+ "@dxos/ui-theme": "0.8.4-main.74a063c4e0"
80
85
  },
81
86
  "optionalDependencies": {
82
- "@dxos/random": "0.8.4-main.72ec0f3"
87
+ "@dxos/random": "0.8.4-main.74a063c4e0"
83
88
  },
84
89
  "publishConfig": {
85
90
  "access": "public"
@@ -2,17 +2,20 @@
2
2
  // Copyright 2022 DXOS.org
3
3
  //
4
4
 
5
- import { effect } from '@preact/signals-core';
5
+ import '../../../styles/graph.css';
6
+
7
+ import { RegistryContext } from '@effect-atom/atom-react';
6
8
  import { type Meta, type StoryObj } from '@storybook/react-vite';
7
9
  import { select } from 'd3';
8
- import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
10
+ import React, { useCallback, useContext, useEffect, useMemo, useRef, useState } from 'react';
9
11
 
10
12
  import { type Graph, type GraphModel, SelectionModel } from '@dxos/graph';
11
13
  import { IconButton, Popover, Toolbar } from '@dxos/react-ui';
12
- import { withTheme } from '@dxos/react-ui/testing';
13
- import { Card } from '@dxos/react-ui-stack';
14
- import { JsonFilter, SyntaxHighlighter } from '@dxos/react-ui-syntax-highlighter';
15
- import { getHashStyles, mx } from '@dxos/react-ui-theme';
14
+ import { Card } from '@dxos/react-ui';
15
+ import { Json, SyntaxHighlighter } 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';
16
19
 
17
20
  import { Pulsar } from '../../fx';
18
21
  import {
@@ -31,11 +34,8 @@ import {
31
34
  import { type SVGContext } from '../../hooks';
32
35
  import { TestGraphModel, type TestNode, convertTreeToGraph, createGraph, createNode, createTree } from '../../testing';
33
36
  import { SVG, type SVGGridProps } from '../SVG';
34
-
35
37
  import { Graph as GraphComponent, type GraphController, type GraphProps } from './Graph';
36
38
 
37
- import '../../../styles/graph.css';
38
-
39
39
  type ProjectorType = 'force' | 'radial' | 'hierarchical' | 'relational';
40
40
 
41
41
  type Factory = {
@@ -49,12 +49,12 @@ const projectorTypes: Record<ProjectorType, Factory> = {
49
49
  relational: GraphRelationalProjector as Factory,
50
50
  };
51
51
 
52
- type StoryProps = GraphProps & {
52
+ type DefaultStoryProps = GraphProps & {
53
53
  debug?: boolean;
54
54
  grid?: boolean | SVGGridProps;
55
55
  inspect?: boolean;
56
56
  singleSelect?: boolean;
57
- graph: () => Graph;
57
+ graph: () => Graph.Any;
58
58
  projectorType?: ProjectorType;
59
59
  projectorOptions?:
60
60
  | GraphForceProjectorOptions
@@ -72,12 +72,16 @@ const DefaultStory = ({
72
72
  projectorType: _projectorType = 'force',
73
73
  projectorOptions,
74
74
  ...props
75
- }: StoryProps) => {
75
+ }: DefaultStoryProps) => {
76
76
  const graphRef = useRef<GraphController | null>(null);
77
77
  const context = useRef<SVGContext>(null);
78
+ const registry = useContext(RegistryContext);
78
79
 
79
80
  // Models.
80
- const [model, setModel] = useState<GraphModel | undefined>(() => new TestGraphModel(_graph?.()));
81
+ const [model, setModel] = useState<GraphModel.ReactiveGraphModel | undefined>(() => {
82
+ const graph = _graph?.();
83
+ return graph ? new TestGraphModel(registry, graph) : undefined;
84
+ });
81
85
  const selection = useMemo(() => new SelectionModel(singleSelect), [singleSelect]);
82
86
 
83
87
  // Projector.
@@ -155,8 +159,9 @@ const DefaultStory = ({
155
159
  }, [model]);
156
160
 
157
161
  const handleRegenerate = useCallback(() => {
158
- setModel(new TestGraphModel(_graph?.()));
159
- }, [_graph]);
162
+ const graph = _graph?.();
163
+ setModel(graph ? new TestGraphModel(registry, graph) : undefined);
164
+ }, [_graph, registry]);
160
165
 
161
166
  const handleClear = useCallback(() => {
162
167
  setModel(undefined);
@@ -180,7 +185,7 @@ const DefaultStory = ({
180
185
 
181
186
  const active = useMemo(() => new SelectionModel(), []);
182
187
  const handlePing = useCallback(() => {
183
- for (const id of active.selected.value) {
188
+ for (const id of active.getSelectedIds()) {
184
189
  const node = graphRef.current?.findNode(id);
185
190
  if (node) {
186
191
  Pulsar.remove(select(node));
@@ -188,7 +193,7 @@ const DefaultStory = ({
188
193
  }
189
194
 
190
195
  active.clear();
191
- for (const id of selection.selected.value) {
196
+ for (const id of selection.getSelectedIds()) {
192
197
  const node = graphRef.current?.findNode(id);
193
198
  if (node) {
194
199
  active.add(id);
@@ -200,7 +205,7 @@ const DefaultStory = ({
200
205
 
201
206
  return (
202
207
  <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]')}>
208
+ <div className={mx('h-full w-full grid divide-x divide-separator', debug && 'grid-cols-[1fr_30rem]')}>
204
209
  <SVG.Root ref={context}>
205
210
  <SVG.Markers />
206
211
  {grid && <SVG.Grid {...(typeof grid === 'boolean' ? { axis: grid } : grid)} />}
@@ -254,13 +259,13 @@ const DefaultStory = ({
254
259
  <Popover.VirtualTrigger virtualRef={popoverAnchorRef} />
255
260
  <Popover.Content onOpenAutoFocus={(event) => event.preventDefault()}>
256
261
  <Popover.Viewport>
257
- <Card.SurfaceRoot role='card--popover'>
262
+ <Card.Root>
258
263
  <SyntaxHighlighter
259
264
  language='json'
260
- classNames='text-xs mlb-cardSpacingBlock pli-cardSpacingInline bg-transparent'
265
+ classNames='text-xs my-form-padding px-form-padding bg-transparent'
261
266
  code={JSON.stringify(popover, null, 2)}
262
267
  />
263
- </Card.SurfaceRoot>
268
+ </Card.Root>
264
269
  </Popover.Viewport>
265
270
  <Popover.Arrow />
266
271
  </Popover.Content>
@@ -281,7 +286,7 @@ const Debug = ({
281
286
  onDelete,
282
287
  onPing,
283
288
  }: {
284
- model?: GraphModel;
289
+ model?: GraphModel.ReactiveGraphModel;
285
290
  selection: SelectionModel;
286
291
  projector: ProjectorType;
287
292
  onToggleProjector: () => void;
@@ -295,12 +300,10 @@ const Debug = ({
295
300
  }) => {
296
301
  const [data, setData] = useState({});
297
302
  useEffect(() => {
298
- effect(() => {
299
- setData({
300
- projector,
301
- selection: selection.toJSON(),
302
- model: model?.toJSON(),
303
- });
303
+ setData({
304
+ projector,
305
+ selection: selection.toJSON(),
306
+ model: model?.toJSON(),
304
307
  });
305
308
  }, [model, selection, projector]);
306
309
 
@@ -316,7 +319,12 @@ const Debug = ({
316
319
  <IconButton onClick={onDelete} label='Delete' icon='ph--x--regular' iconOnly />
317
320
  <IconButton onClick={onPing} label='Delete' icon='ph--crosshair-simple--regular' iconOnly />
318
321
  </Toolbar.Root>
319
- <JsonFilter data={data} classNames='text-sm' />
322
+ <Json.Root data={data}>
323
+ <Json.Content>
324
+ <Json.Filter />
325
+ <Json.Data classNames='text-sm' />
326
+ </Json.Content>
327
+ </Json.Root>
320
328
  </div>
321
329
  );
322
330
  };
@@ -324,7 +332,7 @@ const Debug = ({
324
332
  const meta = {
325
333
  title: 'ui/react-ui-graph/Graph',
326
334
  render: DefaultStory,
327
- decorators: [withTheme],
335
+ decorators: [withRegistry, withTheme(), withLayout({ layout: 'fullscreen' })],
328
336
  parameters: {
329
337
  layout: 'fullscreen',
330
338
  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 BaseGraphEdge, type BaseGraphNode, type GraphModel } from '@dxos/graph';
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/react-ui-theme';
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 BaseGraphNode = any, Edge extends BaseGraphEdge = any> = ThemedClassName<
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.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
- export const GraphInner = <Node extends BaseGraphNode = any, Edge extends BaseGraphEdge = any>(
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: _projector,
47
- renderer: _renderer,
45
+ projector: projectorProp,
46
+ renderer: rendererProp,
48
47
  drag,
49
48
  arrows,
50
49
  onSelect,
@@ -55,14 +54,16 @@ export const GraphInner = <Node extends BaseGraphNode = any, Edge extends BaseGr
55
54
  ) => {
56
55
  const context = useSvgContext();
57
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 = _projector;
61
+ let projector = projectorProp;
61
62
  if (!projector) {
62
63
  projector = new GraphForceProjector<Node>(context);
63
64
  }
64
65
 
65
- let renderer = _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, _projector, _renderer, drag]);
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
- effect(() => {
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 BaseGraphNode = any, Edge extends BaseGraphEdge = any>(
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;
@@ -5,10 +5,9 @@
5
5
  import { type Meta, type StoryObj } from '@storybook/react-vite';
6
6
  import React, { useEffect, useState } from 'react';
7
7
 
8
- import { withTheme } from '@dxos/react-ui/testing';
8
+ import { withLayout, withTheme } from '@dxos/react-ui/testing';
9
9
 
10
10
  import { SVG, type SVGRootProps } from '../SVG';
11
-
12
11
  import { Mesh } from './Mesh';
13
12
 
14
13
  // TODO(burdon): Create waves/game of life.
@@ -37,7 +36,7 @@ const DefaultStory = (props: SVGRootProps) => {
37
36
  const meta = {
38
37
  title: 'ui/react-ui-graph/Mesh',
39
38
  render: DefaultStory,
40
- decorators: [withTheme],
39
+ decorators: [withTheme(), withLayout({ layout: 'fullscreen' })],
41
40
  parameters: {
42
41
  layout: 'fullscreen',
43
42
  },
@@ -5,7 +5,7 @@
5
5
  import React from 'react';
6
6
 
7
7
  import { type ThemedClassName } from '@dxos/react-ui';
8
- import { mx } from '@dxos/react-ui-theme';
8
+ import { mx } from '@dxos/ui-theme';
9
9
 
10
10
  import { type GridOptions, useGrid } from '../../hooks';
11
11
 
@@ -3,26 +3,33 @@
3
3
  //
4
4
 
5
5
  import { select } from 'd3';
6
- import React, { type PropsWithChildren, forwardRef, useEffect, useImperativeHandle, useMemo } from '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/react-ui-theme';
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>(({ classNames, children, ...props }, ref) => {
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(props);
25
- }, [props.scale, props.centered]);
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 ref={containerRef} className={mx('grid grow overflow-hidden', classNames)}>
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}
@@ -8,7 +8,6 @@ import { type ThemedClassName } from '@dxos/react-ui';
8
8
 
9
9
  import { Graph, type GraphProps as SVGGraphProps } from '../Graph';
10
10
  import { Mesh, type MeshProps as SVGMeshProps } from '../Mesh';
11
-
12
11
  import { Grid, type GridProps as SVGGridProps } from './Grid';
13
12
  import { Markers, type MarkersProps as SVGMarkersProps } from './Markers';
14
13
  import { Root, type RootProps as SVGRootProps } from './Root';
@@ -16,7 +15,16 @@ import { type ZoomProps as SVGZoomProps, Zoom } from './Zoom';
16
15
 
17
16
  export type SVGProps = PropsWithChildren<ThemedClassName>;
18
17
 
19
- export const SVG = {
18
+ type SVG = {
19
+ Root: typeof Root;
20
+ Grid: typeof Grid;
21
+ Markers: typeof Markers;
22
+ Mesh: typeof Mesh;
23
+ Zoom: typeof Zoom;
24
+ Graph: typeof Graph;
25
+ };
26
+
27
+ export const SVG: SVG = {
20
28
  Root,
21
29
  Grid,
22
30
  Markers,
@@ -2,17 +2,16 @@
2
2
  // Copyright 2022 DXOS.org
3
3
  //
4
4
 
5
+ import '../../../styles/graph.css';
6
+
5
7
  import { type Meta, type StoryObj } from '@storybook/react-vite';
6
8
  import React, { useRef } from 'react';
7
9
 
8
- import { withTheme } from '@dxos/react-ui/testing';
10
+ import { withLayout, withTheme } from '@dxos/react-ui/testing';
9
11
 
10
12
  import { type SVGContext, useGrid, useZoom } from '../../hooks';
11
-
12
13
  import { SVG } from './SVG';
13
14
 
14
- import '../../../styles/graph.css';
15
-
16
15
  type ComponentProps = {
17
16
  grid?: boolean;
18
17
  zoom?: boolean;
@@ -45,7 +44,7 @@ const DefaultStory = (props: ComponentProps) => {
45
44
  const meta = {
46
45
  title: 'ui/react-ui-graph/SVGRoot',
47
46
  render: DefaultStory,
48
- decorators: [withTheme],
47
+ decorators: [withTheme(), withLayout({ layout: 'fullscreen' })],
49
48
  parameters: {
50
49
  layout: 'fullscreen',
51
50
  },
@@ -2,31 +2,30 @@
2
2
  // Copyright 2025 DXOS.org
3
3
  //
4
4
 
5
+ import '../../styles/graph.css';
6
+
5
7
  import { type Meta, type StoryObj } from '@storybook/react-vite';
6
8
  import { select } from 'd3';
7
9
  import React, { type FC, useEffect, useMemo, useRef } from 'react';
8
10
 
9
- import { withTheme } from '@dxos/react-ui/testing';
11
+ import { withLayout, withTheme } from '@dxos/react-ui/testing';
10
12
 
11
13
  import { SVG } from '../components';
12
14
  import { useGrid, useZoom } from '../hooks';
13
15
  import { type D3Callable } from '../util';
14
-
15
16
  import { Pulsar } from './pulsar';
16
17
 
17
- import '../../styles/graph.css';
18
-
19
18
  type Datum = {
20
19
  x: number;
21
20
  y: number;
22
21
  r: number;
23
22
  };
24
23
 
25
- type StoryProps = {
24
+ type DefaultStoryProps = {
26
25
  count: number;
27
26
  } & Pulsar.Options;
28
27
 
29
- const DefaultStory = (props: StoryProps) => {
28
+ const DefaultStory = (props: DefaultStoryProps) => {
30
29
  return (
31
30
  <SVG.Root>
32
31
  <StoryComponent {...props} />
@@ -34,7 +33,7 @@ const DefaultStory = (props: StoryProps) => {
34
33
  );
35
34
  };
36
35
 
37
- const StoryComponent: FC<StoryProps> = ({ count = 1, ...options }) => {
36
+ const StoryComponent: FC<DefaultStoryProps> = ({ count = 1, ...options }) => {
38
37
  const items = useMemo<Datum[]>(
39
38
  () =>
40
39
  Array.from({ length: count }, () => {
@@ -94,7 +93,7 @@ const createNode: D3Callable<SVGGElement, Datum> = (group, classNames, options)
94
93
  const meta = {
95
94
  title: 'ui/react-ui-graph/fx',
96
95
  render: DefaultStory,
97
- decorators: [withTheme],
96
+ decorators: [withTheme(), withLayout({ layout: 'fullscreen' })],
98
97
  parameters: {
99
98
  layout: 'fullscreen',
100
99
  },
@@ -7,7 +7,6 @@ import { drag, pointer, select } from 'd3';
7
7
  import { type SVGContext } from '../../hooks';
8
8
  import { type Point } from '../../util';
9
9
  import { type GraphLayoutNode } from '../types';
10
-
11
10
  import { type GraphProjector } from './graph-projector';
12
11
 
13
12
  enum Mode {
@@ -18,7 +18,6 @@ import { type Graph } from '@dxos/graph';
18
18
  import { log } from '@dxos/log';
19
19
 
20
20
  import { type GraphLayoutEdge, type GraphLayoutNode } from '../types';
21
-
22
21
  import { forcePoint } from './graph-forces';
23
22
  import { GraphProjector, type GraphProjectorOptions } from './graph-projector';
24
23
 
@@ -223,7 +222,7 @@ export class GraphForceProjector<NodeData = any> extends GraphProjector<NodeData
223
222
  this.restart();
224
223
  }
225
224
 
226
- override onUpdate(graph?: Graph): void {
225
+ override onUpdate(graph?: Graph.Any): void {
227
226
  log('onUpdate', { graph: { nodes: graph?.nodes.length, edges: graph?.edges.length } });
228
227
  this._simulation.stop();
229
228
  this.mergeData(graph);
@@ -6,7 +6,6 @@ import { type Graph } from '@dxos/graph';
6
6
  import { log } from '@dxos/log';
7
7
 
8
8
  import { type GraphLayoutNode } from '../types';
9
-
10
9
  import { type GraphProjectorOptions } from './graph-projector';
11
10
  import { GraphRadialProjector, layoutRadial, updateNode } from './graph-radial-projector';
12
11
 
@@ -20,14 +19,14 @@ export class GraphHierarchicalProjector<
20
19
  NodeData = any,
21
20
  Options extends GraphHierarchicalProjectorOptions = any,
22
21
  > extends GraphRadialProjector<NodeData, Options> {
23
- protected override onUpdate(graph?: Graph) {
22
+ protected override onUpdate(graph?: Graph.Any) {
24
23
  log('onUpdate', {
25
24
  graph: { nodes: graph?.nodes.length, edges: graph?.edges.length },
26
- selection: this.selection?.selected.value,
25
+ selection: this.selection?.getSelectedIds(),
27
26
  });
28
27
 
29
28
  this.mergeData(graph);
30
- const selected = this.selection?.selected.value?.[0];
29
+ const selected = this.selection?.getSelectedIds()[0];
31
30
  if (selected) {
32
31
  const node = this.layout.graph.nodes.find((node) => node.id === selected);
33
32
  if (node) {
@@ -6,7 +6,6 @@ import { type Graph, type SelectionModel } from '@dxos/graph';
6
6
 
7
7
  import { type SVGContext } from '../../hooks';
8
8
  import { type GraphLayout, type GraphLayoutNode, emptyGraph } from '../types';
9
-
10
9
  import { Projector, type ProjectorOptions } from './projector';
11
10
 
12
11
  export type GraphProjectorOptions = ProjectorOptions & {};
@@ -15,7 +14,7 @@ export type GraphProjectorOptions = ProjectorOptions & {};
15
14
  * Base class for graph projectors.
16
15
  */
17
16
  export abstract class GraphProjector<NodeData = any, Options extends GraphProjectorOptions = any> extends Projector<
18
- Graph,
17
+ Graph.Any,
19
18
  GraphLayout<NodeData>,
20
19
  Options
21
20
  > {
@@ -60,7 +59,7 @@ export abstract class GraphProjector<NodeData = any, Options extends GraphProjec
60
59
  * Merge external data with internal representation (e.g., so force properties like position are preserved).
61
60
  * @param data
62
61
  */
63
- protected mergeData(data: Graph = emptyGraph) {
62
+ protected mergeData(data: Graph.Any = emptyGraph) {
64
63
  // Merge nodes.
65
64
  const nodes: GraphLayoutNode[] = data.nodes.map((node) => {
66
65
  let current: GraphLayoutNode = this._layout.graph.nodes.find((n) => n.id === this.options.idAccessor(node));
@@ -9,7 +9,6 @@ import { log } from '@dxos/log';
9
9
 
10
10
  import { type Point } from '../../util';
11
11
  import { type GraphLayoutNode } from '../types';
12
-
13
12
  import { GraphProjector, type GraphProjectorOptions } from './graph-projector';
14
13
 
15
14
  export type GraphRadialProjectorOptions = GraphProjectorOptions & {
@@ -28,7 +27,7 @@ export class GraphRadialProjector<
28
27
  return undefined;
29
28
  }
30
29
 
31
- protected override onUpdate(graph?: Graph) {
30
+ protected override onUpdate(graph?: Graph.Any) {
32
31
  log('onUpdate', { graph: { nodes: graph?.nodes.length, edges: graph?.edges.length } });
33
32
  this.mergeData(graph);
34
33
  this.doRadialLayout();