@dxos/react-ui-graph 0.8.4-main.1da679c → 0.8.4-main.21d9917

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 (73) hide show
  1. package/dist/lib/browser/chunk-LKC455GK.mjs +52 -0
  2. package/dist/lib/browser/chunk-LKC455GK.mjs.map +7 -0
  3. package/dist/lib/browser/index.mjs +1113 -335
  4. package/dist/lib/browser/index.mjs.map +4 -4
  5. package/dist/lib/browser/meta.json +1 -1
  6. package/dist/lib/browser/testing/index.mjs +3 -3
  7. package/dist/lib/browser/testing/index.mjs.map +3 -3
  8. package/dist/lib/node-esm/chunk-JE4KZCUF.mjs +54 -0
  9. package/dist/lib/node-esm/chunk-JE4KZCUF.mjs.map +7 -0
  10. package/dist/lib/node-esm/index.mjs +1113 -335
  11. package/dist/lib/node-esm/index.mjs.map +4 -4
  12. package/dist/lib/node-esm/meta.json +1 -1
  13. package/dist/lib/node-esm/testing/index.mjs +3 -3
  14. package/dist/lib/node-esm/testing/index.mjs.map +3 -3
  15. package/dist/types/src/components/Graph/Graph.d.ts +4 -5
  16. package/dist/types/src/components/Graph/Graph.d.ts.map +1 -1
  17. package/dist/types/src/components/Graph/Graph.stories.d.ts +2 -2
  18. package/dist/types/src/components/Graph/Graph.stories.d.ts.map +1 -1
  19. package/dist/types/src/components/Mesh/Mesh.stories.d.ts +3 -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 +1 -1
  22. package/dist/types/src/components/SVG/SVG.d.ts +14 -17
  23. package/dist/types/src/components/SVG/SVG.d.ts.map +1 -1
  24. package/dist/types/src/components/SVG/Svg.stories.d.ts +3 -1
  25. package/dist/types/src/components/SVG/Svg.stories.d.ts.map +1 -1
  26. package/dist/types/src/fx/fx.stories.d.ts +3 -1
  27. package/dist/types/src/fx/fx.stories.d.ts.map +1 -1
  28. package/dist/types/src/graph/projector/graph-force-projector.d.ts +1 -1
  29. package/dist/types/src/graph/projector/graph-force-projector.d.ts.map +1 -1
  30. package/dist/types/src/graph/projector/graph-hierarchical-projector.d.ts +1 -1
  31. package/dist/types/src/graph/projector/graph-hierarchical-projector.d.ts.map +1 -1
  32. package/dist/types/src/graph/projector/graph-projector.d.ts +2 -2
  33. package/dist/types/src/graph/projector/graph-projector.d.ts.map +1 -1
  34. package/dist/types/src/graph/projector/graph-radial-projector.d.ts +1 -1
  35. package/dist/types/src/graph/projector/graph-radial-projector.d.ts.map +1 -1
  36. package/dist/types/src/graph/projector/graph-relational-projector.d.ts +1 -1
  37. package/dist/types/src/graph/projector/graph-relational-projector.d.ts.map +1 -1
  38. package/dist/types/src/graph/types.d.ts +1 -1
  39. package/dist/types/src/graph/types.d.ts.map +1 -1
  40. package/dist/types/src/stories/hooks.stories.d.ts +6 -3
  41. package/dist/types/src/stories/hooks.stories.d.ts.map +1 -1
  42. package/dist/types/src/testing/data.d.ts +4 -4
  43. package/dist/types/src/testing/data.d.ts.map +1 -1
  44. package/dist/types/src/testing/hooks.d.ts +2 -16
  45. package/dist/types/src/testing/hooks.d.ts.map +1 -1
  46. package/dist/types/src/testing/model.d.ts +4 -8
  47. package/dist/types/src/testing/model.d.ts.map +1 -1
  48. package/dist/types/tsconfig.tsbuildinfo +1 -1
  49. package/package.json +31 -26
  50. package/src/components/Graph/Graph.stories.tsx +37 -34
  51. package/src/components/Graph/Graph.tsx +18 -11
  52. package/src/components/Mesh/Mesh.stories.tsx +5 -4
  53. package/src/components/SVG/Grid.tsx +1 -1
  54. package/src/components/SVG/Markers.tsx +1 -1
  55. package/src/components/SVG/Root.tsx +1 -1
  56. package/src/components/SVG/SVG.tsx +10 -1
  57. package/src/components/SVG/Svg.stories.tsx +5 -4
  58. package/src/fx/fx.stories.tsx +6 -5
  59. package/src/graph/projector/graph-force-projector.ts +1 -1
  60. package/src/graph/projector/graph-hierarchical-projector.ts +3 -3
  61. package/src/graph/projector/graph-projector.ts +2 -2
  62. package/src/graph/projector/graph-radial-projector.ts +1 -1
  63. package/src/graph/projector/graph-relational-projector.ts +3 -3
  64. package/src/graph/types.ts +1 -1
  65. package/src/hooks/useStateRef.ts +1 -1
  66. package/src/stories/hooks.stories.tsx +18 -11
  67. package/src/testing/data.ts +5 -5
  68. package/src/testing/hooks.ts +1 -1
  69. package/src/testing/model.ts +3 -3
  70. package/dist/lib/browser/chunk-PDEA4KBO.mjs +0 -966
  71. package/dist/lib/browser/chunk-PDEA4KBO.mjs.map +0 -7
  72. package/dist/lib/node-esm/chunk-NJGJKPL7.mjs +0 -968
  73. package/dist/lib/node-esm/chunk-NJGJKPL7.mjs.map +0 -7
@@ -2,15 +2,16 @@
2
2
  // Copyright 2020 DXOS.org
3
3
  //
4
4
 
5
- import '@dxos-theme';
6
-
5
+ import { RegistryContext } from '@effect-atom/atom-react';
7
6
  import { type Meta, type StoryObj } from '@storybook/react-vite';
8
7
  import { select } from 'd3';
9
- import React, { type PropsWithChildren, useEffect, useMemo, useRef } from 'react';
8
+ import React, { type PropsWithChildren, useContext, useEffect, useMemo, useRef } from 'react';
10
9
 
11
10
  import { combine } from '@dxos/async';
11
+ import { type Graph } from '@dxos/graph';
12
12
  import { log } from '@dxos/log';
13
- import { withLayout, withTheme } from '@dxos/storybook-utils';
13
+ import { withTheme } from '@dxos/react-ui/testing';
14
+ import { withRegistry } from '@dxos/storybook-utils';
14
15
 
15
16
  import { SVG } from '../components';
16
17
  import {
@@ -29,7 +30,7 @@ import { TestGraphModel, type TestNode, convertTreeToGraph, createTree } from '.
29
30
  import '../../styles/graph.css';
30
31
 
31
32
  type ComponentProps = PropsWithChildren<{
32
- model: TestGraphModel;
33
+ graph: () => Graph.Graph<TestNode, Graph.Edge.Any>;
33
34
  projectorOptions?: GraphForceProjectorOptions;
34
35
  count?: number;
35
36
  interval?: number;
@@ -38,16 +39,19 @@ type ComponentProps = PropsWithChildren<{
38
39
  }>;
39
40
 
40
41
  const Component = ({
41
- model,
42
+ graph: graphFactory,
42
43
  projectorOptions,
43
44
  count = 0,
44
45
  interval = 200,
45
46
  link = false,
46
47
  grid: showGrid = false,
47
48
  }: ComponentProps) => {
49
+ const registry = useContext(RegistryContext);
50
+ const model = useMemo(() => new TestGraphModel(registry, graphFactory()), [registry, graphFactory]);
51
+
48
52
  const context = useSvgContext();
49
- const graphRef = useRef<SVGGElement>();
50
- const markersRef = useRef<SVGGElement>();
53
+ const graphRef = useRef<SVGGElement>(null);
54
+ const markersRef = useRef<SVGGElement>(null);
51
55
  const grid = useGrid({ visible: showGrid });
52
56
  const zoom = useZoom();
53
57
 
@@ -154,7 +158,10 @@ const DefaultStory = ({ children, ...props }: ComponentProps) => {
154
158
  const meta = {
155
159
  title: 'ui/react-ui-graph/hooks',
156
160
  render: DefaultStory,
157
- decorators: [withTheme, withLayout({ fullscreen: true })],
161
+ decorators: [withRegistry, withTheme],
162
+ parameters: {
163
+ layout: 'fullscreen',
164
+ },
158
165
  } satisfies Meta<typeof DefaultStory>;
159
166
 
160
167
  export default meta;
@@ -163,7 +170,7 @@ type Story = StoryObj<typeof meta>;
163
170
 
164
171
  export const Default: Story = {
165
172
  args: {
166
- model: new TestGraphModel(convertTreeToGraph(createTree({ depth: 3 }))),
173
+ graph: () => convertTreeToGraph(createTree({ depth: 3 })),
167
174
  grid: true,
168
175
  count: 300,
169
176
  interval: 20,
@@ -188,7 +195,7 @@ export const Default: Story = {
188
195
 
189
196
  export const Bullets: Story = {
190
197
  args: {
191
- model: new TestGraphModel(convertTreeToGraph(createTree({ depth: 4 }))),
198
+ graph: () => convertTreeToGraph(createTree({ depth: 4 })),
192
199
  children: <span>⌘-DRAG to edge or create node; ⌘-CLICK to delete edge.</span>,
193
200
  link: true,
194
201
  grid: false,
@@ -2,7 +2,7 @@
2
2
  // Copyright 2020 DXOS.org
3
3
  //
4
4
 
5
- import { type BaseGraphEdge, type Graph } from '@dxos/graph';
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): BaseGraphEdge => ({
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();
@@ -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;
@@ -2,17 +2,17 @@
2
2
  // Copyright 2022 DXOS.org
3
3
  //
4
4
 
5
- import { type BaseGraphNode, ReactiveGraphModel } from '@dxos/graph';
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 = BaseGraphNode & {
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
  }