@dxos/react-ui-graph 0.8.4-main.bc674ce → 0.8.4-main.bcb3aa67d6
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/README.md +5 -7
- package/dist/lib/browser/index.mjs +20 -15
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +20 -15
- package/dist/lib/node-esm/index.mjs.map +3 -3
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/src/components/Graph/Graph.d.ts +2 -2
- package/dist/types/src/components/Graph/Graph.d.ts.map +1 -1
- package/dist/types/src/components/Graph/Graph.stories.d.ts +2 -2
- package/dist/types/src/components/Graph/Graph.stories.d.ts.map +1 -1
- package/dist/types/src/components/SVG/Root.d.ts +3 -3
- package/dist/types/src/components/SVG/Root.d.ts.map +1 -1
- package/dist/types/src/fx/fx.stories.d.ts +2 -2
- package/dist/types/src/fx/fx.stories.d.ts.map +1 -1
- package/dist/types/src/util/fraction.d.ts +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +18 -18
- package/src/components/Graph/Graph.stories.tsx +16 -11
- package/src/components/Graph/Graph.tsx +14 -13
- package/src/components/Mesh/Mesh.stories.tsx +2 -2
- package/src/components/SVG/Root.tsx +14 -7
- package/src/components/SVG/Svg.stories.tsx +2 -2
- package/src/fx/fx.stories.tsx +5 -5
- package/src/stories/hooks.stories.tsx +2 -2
- package/src/util/fraction.ts +1 -1
- package/styles/graph.css +292 -43
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.bcb3aa67d6",
|
|
4
4
|
"description": "GEM Graph.",
|
|
5
5
|
"homepage": "https://dxos.org",
|
|
6
6
|
"bugs": "https://github.com/dxos/dxos/issues",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"styles"
|
|
44
44
|
],
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"@effect-atom/atom-react": "^0.
|
|
46
|
+
"@effect-atom/atom-react": "^0.5.0",
|
|
47
47
|
"d3": "^7.9.0",
|
|
48
48
|
"d3-force": "~3.0.0",
|
|
49
49
|
"immutability-helper": "^3.0.2",
|
|
@@ -51,13 +51,13 @@
|
|
|
51
51
|
"lodash.defaultsdeep": "^4.6.1",
|
|
52
52
|
"react-resize-detector": "^11.0.1",
|
|
53
53
|
"topojson-client": "^3.1.0",
|
|
54
|
-
"@dxos/async": "0.8.4-main.
|
|
55
|
-
"@dxos/
|
|
56
|
-
"@dxos/
|
|
57
|
-
"@dxos/
|
|
58
|
-
"@dxos/
|
|
59
|
-
"@dxos/
|
|
60
|
-
"@dxos/
|
|
54
|
+
"@dxos/async": "0.8.4-main.bcb3aa67d6",
|
|
55
|
+
"@dxos/invariant": "0.8.4-main.bcb3aa67d6",
|
|
56
|
+
"@dxos/log": "0.8.4-main.bcb3aa67d6",
|
|
57
|
+
"@dxos/node-std": "0.8.4-main.bcb3aa67d6",
|
|
58
|
+
"@dxos/graph": "0.8.4-main.bcb3aa67d6",
|
|
59
|
+
"@dxos/react-ui-mosaic": "0.8.4-main.bcb3aa67d6",
|
|
60
|
+
"@dxos/debug": "0.8.4-main.bcb3aa67d6"
|
|
61
61
|
},
|
|
62
62
|
"devDependencies": {
|
|
63
63
|
"@babel/core": "^7.18.13",
|
|
@@ -70,21 +70,21 @@
|
|
|
70
70
|
"postcss": "^8.4.41",
|
|
71
71
|
"react": "~19.2.3",
|
|
72
72
|
"react-dom": "~19.2.3",
|
|
73
|
-
"@dxos/random": "0.8.4-main.
|
|
74
|
-
"@dxos/react-ui": "0.8.4-main.
|
|
75
|
-
"@dxos/
|
|
76
|
-
"@dxos/react-ui-
|
|
77
|
-
"@dxos/ui-theme": "0.8.4-main.
|
|
78
|
-
"@dxos/
|
|
73
|
+
"@dxos/random": "0.8.4-main.bcb3aa67d6",
|
|
74
|
+
"@dxos/react-ui-syntax-highlighter": "0.8.4-main.bcb3aa67d6",
|
|
75
|
+
"@dxos/storybook-utils": "0.8.4-main.bcb3aa67d6",
|
|
76
|
+
"@dxos/react-ui-stack": "0.8.4-main.bcb3aa67d6",
|
|
77
|
+
"@dxos/ui-theme": "0.8.4-main.bcb3aa67d6",
|
|
78
|
+
"@dxos/react-ui": "0.8.4-main.bcb3aa67d6"
|
|
79
79
|
},
|
|
80
80
|
"peerDependencies": {
|
|
81
81
|
"react": "~19.2.3",
|
|
82
82
|
"react-dom": "~19.2.3",
|
|
83
|
-
"@dxos/react-ui": "0.8.4-main.
|
|
84
|
-
"@dxos/ui-theme": "0.8.4-main.
|
|
83
|
+
"@dxos/react-ui": "0.8.4-main.bcb3aa67d6",
|
|
84
|
+
"@dxos/ui-theme": "0.8.4-main.bcb3aa67d6"
|
|
85
85
|
},
|
|
86
86
|
"optionalDependencies": {
|
|
87
|
-
"@dxos/random": "0.8.4-main.
|
|
87
|
+
"@dxos/random": "0.8.4-main.bcb3aa67d6"
|
|
88
88
|
},
|
|
89
89
|
"publishConfig": {
|
|
90
90
|
"access": "public"
|
|
@@ -9,9 +9,9 @@ import React, { useCallback, useContext, useEffect, useMemo, useRef, useState }
|
|
|
9
9
|
|
|
10
10
|
import { type Graph, type GraphModel, SelectionModel } from '@dxos/graph';
|
|
11
11
|
import { IconButton, Popover, Toolbar } from '@dxos/react-ui';
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
12
|
+
import { Card } from '@dxos/react-ui';
|
|
13
|
+
import { withLayout, withTheme } from '@dxos/react-ui/testing';
|
|
14
|
+
import { Json, SyntaxHighlighter } from '@dxos/react-ui-syntax-highlighter';
|
|
15
15
|
import { withRegistry } from '@dxos/storybook-utils';
|
|
16
16
|
import { getHashStyles, mx } from '@dxos/ui-theme';
|
|
17
17
|
|
|
@@ -50,7 +50,7 @@ const projectorTypes: Record<ProjectorType, Factory> = {
|
|
|
50
50
|
relational: GraphRelationalProjector as Factory,
|
|
51
51
|
};
|
|
52
52
|
|
|
53
|
-
type
|
|
53
|
+
type DefaultStoryProps = GraphProps & {
|
|
54
54
|
debug?: boolean;
|
|
55
55
|
grid?: boolean | SVGGridProps;
|
|
56
56
|
inspect?: boolean;
|
|
@@ -73,13 +73,13 @@ const DefaultStory = ({
|
|
|
73
73
|
projectorType: _projectorType = 'force',
|
|
74
74
|
projectorOptions,
|
|
75
75
|
...props
|
|
76
|
-
}:
|
|
76
|
+
}: DefaultStoryProps) => {
|
|
77
77
|
const graphRef = useRef<GraphController | null>(null);
|
|
78
78
|
const context = useRef<SVGContext>(null);
|
|
79
79
|
const registry = useContext(RegistryContext);
|
|
80
80
|
|
|
81
81
|
// Models.
|
|
82
|
-
const [model, setModel] = useState<GraphModel.
|
|
82
|
+
const [model, setModel] = useState<GraphModel.ReactiveGraphModel | undefined>(() => {
|
|
83
83
|
const graph = _graph?.();
|
|
84
84
|
return graph ? new TestGraphModel(registry, graph) : undefined;
|
|
85
85
|
});
|
|
@@ -206,7 +206,7 @@ const DefaultStory = ({
|
|
|
206
206
|
|
|
207
207
|
return (
|
|
208
208
|
<Popover.Root open={!!popover} onOpenChange={(state) => !state && setPopover(undefined)}>
|
|
209
|
-
<div className={mx('
|
|
209
|
+
<div className={mx('h-full w-full grid divide-x divide-separator', debug && 'grid-cols-[1fr_30rem]')}>
|
|
210
210
|
<SVG.Root ref={context}>
|
|
211
211
|
<SVG.Markers />
|
|
212
212
|
{grid && <SVG.Grid {...(typeof grid === 'boolean' ? { axis: grid } : grid)} />}
|
|
@@ -263,7 +263,7 @@ const DefaultStory = ({
|
|
|
263
263
|
<Card.Root>
|
|
264
264
|
<SyntaxHighlighter
|
|
265
265
|
language='json'
|
|
266
|
-
classNames='text-xs
|
|
266
|
+
classNames='text-xs my-form-padding px-form-padding bg-transparent'
|
|
267
267
|
code={JSON.stringify(popover, null, 2)}
|
|
268
268
|
/>
|
|
269
269
|
</Card.Root>
|
|
@@ -287,7 +287,7 @@ const Debug = ({
|
|
|
287
287
|
onDelete,
|
|
288
288
|
onPing,
|
|
289
289
|
}: {
|
|
290
|
-
model?: GraphModel.
|
|
290
|
+
model?: GraphModel.ReactiveGraphModel;
|
|
291
291
|
selection: SelectionModel;
|
|
292
292
|
projector: ProjectorType;
|
|
293
293
|
onToggleProjector: () => void;
|
|
@@ -320,7 +320,12 @@ const Debug = ({
|
|
|
320
320
|
<IconButton onClick={onDelete} label='Delete' icon='ph--x--regular' iconOnly />
|
|
321
321
|
<IconButton onClick={onPing} label='Delete' icon='ph--crosshair-simple--regular' iconOnly />
|
|
322
322
|
</Toolbar.Root>
|
|
323
|
-
<
|
|
323
|
+
<Json.Root data={data}>
|
|
324
|
+
<Json.Content>
|
|
325
|
+
<Json.Filter />
|
|
326
|
+
<Json.Data classNames='text-sm' />
|
|
327
|
+
</Json.Content>
|
|
328
|
+
</Json.Root>
|
|
324
329
|
</div>
|
|
325
330
|
);
|
|
326
331
|
};
|
|
@@ -328,7 +333,7 @@ const Debug = ({
|
|
|
328
333
|
const meta = {
|
|
329
334
|
title: 'ui/react-ui-graph/Graph',
|
|
330
335
|
render: DefaultStory,
|
|
331
|
-
decorators: [withRegistry, withTheme],
|
|
336
|
+
decorators: [withRegistry, withTheme(), withLayout({ layout: 'fullscreen' })],
|
|
332
337
|
parameters: {
|
|
333
338
|
layout: 'fullscreen',
|
|
334
339
|
controls: { disable: true },
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
import React, { type JSX, type Ref, forwardRef, useEffect, useImperativeHandle, useMemo, useRef } from 'react';
|
|
6
6
|
|
|
7
7
|
import { combine } from '@dxos/async';
|
|
8
|
-
import { type Graph as Graph
|
|
8
|
+
import { GraphModel, type Graph as Graph$ } from '@dxos/graph';
|
|
9
9
|
import { log } from '@dxos/log';
|
|
10
10
|
import { type ThemedClassName } from '@dxos/react-ui';
|
|
11
11
|
import { mx } from '@dxos/ui-theme';
|
|
@@ -28,7 +28,7 @@ export type GraphController = {
|
|
|
28
28
|
|
|
29
29
|
export type GraphProps<Node extends Graph$.Node.Any = any, Edge extends Graph$.Edge.Any = any> = ThemedClassName<
|
|
30
30
|
Pick<GraphRendererOptions<Node>, 'labels' | 'subgraphs' | 'attributes'> & {
|
|
31
|
-
model?: GraphModel.
|
|
31
|
+
model?: GraphModel.ReactiveGraphModel<Node, Edge>;
|
|
32
32
|
projector?: GraphProjector<Node>;
|
|
33
33
|
renderer?: GraphRenderer<Node>;
|
|
34
34
|
drag?: boolean;
|
|
@@ -42,8 +42,8 @@ const GraphInner = <Node extends Graph$.Node.Any = any, Edge extends Graph$.Edge
|
|
|
42
42
|
{
|
|
43
43
|
classNames,
|
|
44
44
|
model,
|
|
45
|
-
projector:
|
|
46
|
-
renderer:
|
|
45
|
+
projector: projectorProp,
|
|
46
|
+
renderer: rendererProp,
|
|
47
47
|
drag,
|
|
48
48
|
arrows,
|
|
49
49
|
onSelect,
|
|
@@ -54,14 +54,16 @@ const GraphInner = <Node extends Graph$.Node.Any = any, Edge extends Graph$.Edge
|
|
|
54
54
|
) => {
|
|
55
55
|
const context = useSvgContext();
|
|
56
56
|
const graphRef = useRef<SVGGElement>(null);
|
|
57
|
+
// TODO(wittjosiah): This doesn't work for some reason.
|
|
58
|
+
// const graph = useAtomValue(model?.graphAtom ?? EMPTY_ATOM);
|
|
57
59
|
|
|
58
60
|
const { projector, renderer } = useMemo(() => {
|
|
59
|
-
let projector =
|
|
61
|
+
let projector = projectorProp;
|
|
60
62
|
if (!projector) {
|
|
61
63
|
projector = new GraphForceProjector<Node>(context);
|
|
62
64
|
}
|
|
63
65
|
|
|
64
|
-
let renderer =
|
|
66
|
+
let renderer = rendererProp;
|
|
65
67
|
if (!renderer) {
|
|
66
68
|
renderer = new GraphRenderer<Node>(context, graphRef, {
|
|
67
69
|
...props,
|
|
@@ -74,7 +76,7 @@ const GraphInner = <Node extends Graph$.Node.Any = any, Edge extends Graph$.Edge
|
|
|
74
76
|
}
|
|
75
77
|
|
|
76
78
|
return { projector, renderer };
|
|
77
|
-
}, [context,
|
|
79
|
+
}, [context, projectorProp, rendererProp, drag]);
|
|
78
80
|
|
|
79
81
|
// External API.
|
|
80
82
|
useImperativeHandle(
|
|
@@ -98,12 +100,11 @@ const GraphInner = <Node extends Graph$.Node.Any = any, Edge extends Graph$.Edge
|
|
|
98
100
|
projector.updateData(model?.graph);
|
|
99
101
|
|
|
100
102
|
// Subscribe to model changes if reactive model.
|
|
101
|
-
const unsubscribeModel =
|
|
102
|
-
model
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
: undefined;
|
|
103
|
+
const unsubscribeModel = model
|
|
104
|
+
? model.subscribe(() => {
|
|
105
|
+
projector.updateData(model?.graph);
|
|
106
|
+
})
|
|
107
|
+
: undefined;
|
|
107
108
|
|
|
108
109
|
return combine(
|
|
109
110
|
unsubscribeModel,
|
|
@@ -5,7 +5,7 @@
|
|
|
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
11
|
|
|
@@ -37,7 +37,7 @@ const DefaultStory = (props: SVGRootProps) => {
|
|
|
37
37
|
const meta = {
|
|
38
38
|
title: 'ui/react-ui-graph/Mesh',
|
|
39
39
|
render: DefaultStory,
|
|
40
|
-
decorators: [withTheme],
|
|
40
|
+
decorators: [withTheme(), withLayout({ layout: 'fullscreen' })],
|
|
41
41
|
parameters: {
|
|
42
42
|
layout: 'fullscreen',
|
|
43
43
|
},
|
|
@@ -3,26 +3,33 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
import { select } from 'd3';
|
|
6
|
-
import 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/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>(({
|
|
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(
|
|
25
|
-
}, [
|
|
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
|
|
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}
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
import { type Meta, type StoryObj } from '@storybook/react-vite';
|
|
6
6
|
import React, { useRef } 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 { type SVGContext, useGrid, useZoom } from '../../hooks';
|
|
11
11
|
|
|
@@ -45,7 +45,7 @@ const DefaultStory = (props: ComponentProps) => {
|
|
|
45
45
|
const meta = {
|
|
46
46
|
title: 'ui/react-ui-graph/SVGRoot',
|
|
47
47
|
render: DefaultStory,
|
|
48
|
-
decorators: [withTheme],
|
|
48
|
+
decorators: [withTheme(), withLayout({ layout: 'fullscreen' })],
|
|
49
49
|
parameters: {
|
|
50
50
|
layout: 'fullscreen',
|
|
51
51
|
},
|
package/src/fx/fx.stories.tsx
CHANGED
|
@@ -6,7 +6,7 @@ import { type Meta, type StoryObj } from '@storybook/react-vite';
|
|
|
6
6
|
import { select } from 'd3';
|
|
7
7
|
import React, { type FC, useEffect, useMemo, useRef } from 'react';
|
|
8
8
|
|
|
9
|
-
import { withTheme } from '@dxos/react-ui/testing';
|
|
9
|
+
import { withLayout, withTheme } from '@dxos/react-ui/testing';
|
|
10
10
|
|
|
11
11
|
import { SVG } from '../components';
|
|
12
12
|
import { useGrid, useZoom } from '../hooks';
|
|
@@ -22,11 +22,11 @@ type Datum = {
|
|
|
22
22
|
r: number;
|
|
23
23
|
};
|
|
24
24
|
|
|
25
|
-
type
|
|
25
|
+
type DefaultStoryProps = {
|
|
26
26
|
count: number;
|
|
27
27
|
} & Pulsar.Options;
|
|
28
28
|
|
|
29
|
-
const DefaultStory = (props:
|
|
29
|
+
const DefaultStory = (props: DefaultStoryProps) => {
|
|
30
30
|
return (
|
|
31
31
|
<SVG.Root>
|
|
32
32
|
<StoryComponent {...props} />
|
|
@@ -34,7 +34,7 @@ const DefaultStory = (props: StoryProps) => {
|
|
|
34
34
|
);
|
|
35
35
|
};
|
|
36
36
|
|
|
37
|
-
const StoryComponent: FC<
|
|
37
|
+
const StoryComponent: FC<DefaultStoryProps> = ({ count = 1, ...options }) => {
|
|
38
38
|
const items = useMemo<Datum[]>(
|
|
39
39
|
() =>
|
|
40
40
|
Array.from({ length: count }, () => {
|
|
@@ -94,7 +94,7 @@ const createNode: D3Callable<SVGGElement, Datum> = (group, classNames, options)
|
|
|
94
94
|
const meta = {
|
|
95
95
|
title: 'ui/react-ui-graph/fx',
|
|
96
96
|
render: DefaultStory,
|
|
97
|
-
decorators: [withTheme],
|
|
97
|
+
decorators: [withTheme(), withLayout({ layout: 'fullscreen' })],
|
|
98
98
|
parameters: {
|
|
99
99
|
layout: 'fullscreen',
|
|
100
100
|
},
|
|
@@ -10,7 +10,7 @@ import React, { type PropsWithChildren, useContext, useEffect, useMemo, useRef }
|
|
|
10
10
|
import { combine } from '@dxos/async';
|
|
11
11
|
import { type Graph } from '@dxos/graph';
|
|
12
12
|
import { log } from '@dxos/log';
|
|
13
|
-
import { withTheme } from '@dxos/react-ui/testing';
|
|
13
|
+
import { withLayout, withTheme } from '@dxos/react-ui/testing';
|
|
14
14
|
import { withRegistry } from '@dxos/storybook-utils';
|
|
15
15
|
|
|
16
16
|
import { SVG } from '../components';
|
|
@@ -158,7 +158,7 @@ const DefaultStory = ({ children, ...props }: ComponentProps) => {
|
|
|
158
158
|
const meta = {
|
|
159
159
|
title: 'ui/react-ui-graph/hooks',
|
|
160
160
|
render: DefaultStory,
|
|
161
|
-
decorators: [withRegistry, withTheme],
|
|
161
|
+
decorators: [withRegistry, withTheme(), withLayout({ layout: 'fullscreen' })],
|
|
162
162
|
parameters: {
|
|
163
163
|
layout: 'fullscreen',
|
|
164
164
|
},
|