@dxos/plugin-explorer 0.8.4-main.dedc0f3 → 0.8.4-main.dfabb4ec29

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 (194) hide show
  1. package/dist/lib/neutral/ExplorerContainer-5TOK2ZEY.mjs +40 -0
  2. package/dist/lib/neutral/ExplorerContainer-5TOK2ZEY.mjs.map +7 -0
  3. package/dist/lib/neutral/ExplorerPlugin.mjs +26 -0
  4. package/dist/lib/neutral/ExplorerPlugin.mjs.map +7 -0
  5. package/dist/lib/neutral/capabilities/index.mjs +11 -0
  6. package/dist/lib/neutral/capabilities/index.mjs.map +7 -0
  7. package/dist/lib/neutral/chunk-5X5ATGCS.mjs +73 -0
  8. package/dist/lib/neutral/chunk-5X5ATGCS.mjs.map +7 -0
  9. package/dist/lib/neutral/chunk-HPIS2WXY.mjs +24 -0
  10. package/dist/lib/neutral/chunk-HPIS2WXY.mjs.map +7 -0
  11. package/dist/lib/neutral/chunk-J5LGTIGS.mjs +10 -0
  12. package/dist/lib/{browser/chunk-VNOGW2JS.mjs → neutral/components/index.mjs} +344 -411
  13. package/dist/lib/{node-esm/chunk-ODMJ7DPA.mjs.map → neutral/components/index.mjs.map} +4 -4
  14. package/dist/lib/neutral/containers/index.mjs +9 -0
  15. package/dist/lib/neutral/containers/index.mjs.map +7 -0
  16. package/dist/lib/neutral/create-object-F6TKVAGV.mjs +39 -0
  17. package/dist/lib/neutral/create-object-F6TKVAGV.mjs.map +7 -0
  18. package/dist/lib/neutral/hooks/index.mjs +40 -0
  19. package/dist/lib/neutral/hooks/index.mjs.map +7 -0
  20. package/dist/lib/neutral/index.mjs +14 -0
  21. package/dist/lib/neutral/meta.json +1 -0
  22. package/dist/lib/{browser → neutral}/meta.mjs +2 -3
  23. package/dist/lib/neutral/plugin.mjs +12 -0
  24. package/dist/lib/neutral/plugin.mjs.map +7 -0
  25. package/dist/lib/neutral/react-surface-U3JEY7V7.mjs +26 -0
  26. package/dist/lib/neutral/react-surface-U3JEY7V7.mjs.map +7 -0
  27. package/dist/lib/neutral/translations.mjs +33 -0
  28. package/dist/lib/neutral/translations.mjs.map +7 -0
  29. package/dist/lib/neutral/types/index.mjs +10 -0
  30. package/dist/types/data/cities.d.ts +4 -4
  31. package/dist/types/data/cities.d.ts.map +1 -1
  32. package/dist/types/data/countries-110m.d.ts +19 -22
  33. package/dist/types/data/countries-110m.d.ts.map +1 -1
  34. package/dist/types/src/ExplorerPlugin.d.ts +3 -1
  35. package/dist/types/src/ExplorerPlugin.d.ts.map +1 -1
  36. package/dist/types/src/ExplorerPlugin.test.d.ts +2 -0
  37. package/dist/types/src/ExplorerPlugin.test.d.ts.map +1 -0
  38. package/dist/types/src/capabilities/create-object.d.ts +11 -0
  39. package/dist/types/src/capabilities/create-object.d.ts.map +1 -0
  40. package/dist/types/src/capabilities/index.d.ts +8 -2
  41. package/dist/types/src/capabilities/index.d.ts.map +1 -1
  42. package/dist/types/src/capabilities/react-surface.d.ts +3 -2
  43. package/dist/types/src/capabilities/react-surface.d.ts.map +1 -1
  44. package/dist/types/src/components/Chart/Chart.d.ts.map +1 -1
  45. package/dist/types/src/components/Chart/Chart.stories.d.ts +7 -2
  46. package/dist/types/src/components/Chart/Chart.stories.d.ts.map +1 -1
  47. package/dist/types/src/components/Globe/Globe.d.ts.map +1 -1
  48. package/dist/types/src/components/Globe/Globe.stories.d.ts +8 -3
  49. package/dist/types/src/components/Globe/Globe.stories.d.ts.map +1 -1
  50. package/dist/types/src/components/Graph/CanvasForceGraph.d.ts +13 -0
  51. package/dist/types/src/components/Graph/CanvasForceGraph.d.ts.map +1 -0
  52. package/dist/types/src/components/Graph/CanvasForceGraph.stories.d.ts +17 -0
  53. package/dist/types/src/components/Graph/CanvasForceGraph.stories.d.ts.map +1 -0
  54. package/dist/types/src/components/Graph/ForceGraph.d.ts +12 -5
  55. package/dist/types/src/components/Graph/ForceGraph.d.ts.map +1 -1
  56. package/dist/types/src/components/Graph/ForceGraph.stories.d.ts +7 -3
  57. package/dist/types/src/components/Graph/ForceGraph.stories.d.ts.map +1 -1
  58. package/dist/types/src/components/Graph/{adapter.d.ts → graph-adapter.d.ts} +2 -2
  59. package/dist/types/src/components/Graph/graph-adapter.d.ts.map +1 -0
  60. package/dist/types/src/components/Graph/index.d.ts +1 -1
  61. package/dist/types/src/components/Graph/index.d.ts.map +1 -1
  62. package/dist/types/src/components/Graph/testing.d.ts.map +1 -1
  63. package/dist/types/src/components/Tree/Tree.d.ts.map +1 -1
  64. package/dist/types/src/components/Tree/Tree.stories.d.ts +5 -2
  65. package/dist/types/src/components/Tree/Tree.stories.d.ts.map +1 -1
  66. package/dist/types/src/components/Tree/layout/HierarchicalEdgeBundling.d.ts.map +1 -1
  67. package/dist/types/src/components/Tree/layout/RadialTree.d.ts.map +1 -1
  68. package/dist/types/src/components/Tree/layout/TidyTree.d.ts.map +1 -1
  69. package/dist/types/src/components/Tree/testing/generator.d.ts.map +1 -1
  70. package/dist/types/src/components/Tree/types/tree.d.ts +19 -17
  71. package/dist/types/src/components/Tree/types/tree.d.ts.map +1 -1
  72. package/dist/types/src/components/Tree/types/types.d.ts +1 -1
  73. package/dist/types/src/components/Tree/types/types.d.ts.map +1 -1
  74. package/dist/types/src/components/index.d.ts +0 -4
  75. package/dist/types/src/components/index.d.ts.map +1 -1
  76. package/dist/types/src/components/plot.d.ts.map +1 -1
  77. package/dist/types/src/containers/ExplorerContainer/ExplorerContainer.d.ts +6 -0
  78. package/dist/types/src/containers/ExplorerContainer/ExplorerContainer.d.ts.map +1 -0
  79. package/dist/types/src/containers/ExplorerContainer/index.d.ts +2 -0
  80. package/dist/types/src/containers/ExplorerContainer/index.d.ts.map +1 -0
  81. package/dist/types/src/containers/index.d.ts +3 -0
  82. package/dist/types/src/containers/index.d.ts.map +1 -0
  83. package/dist/types/src/hooks/useGraphModel.d.ts.map +1 -1
  84. package/dist/types/src/index.d.ts +1 -3
  85. package/dist/types/src/index.d.ts.map +1 -1
  86. package/dist/types/src/meta.d.ts +2 -3
  87. package/dist/types/src/meta.d.ts.map +1 -1
  88. package/dist/types/src/plugin.d.ts +3 -0
  89. package/dist/types/src/plugin.d.ts.map +1 -0
  90. package/dist/types/src/translations.d.ts +34 -13
  91. package/dist/types/src/translations.d.ts.map +1 -1
  92. package/dist/types/src/types/ExplorerAction.d.ts +6 -0
  93. package/dist/types/src/types/ExplorerAction.d.ts.map +1 -0
  94. package/dist/types/src/types/Graph.d.ts +23 -0
  95. package/dist/types/src/types/Graph.d.ts.map +1 -0
  96. package/dist/types/src/types/index.d.ts +2 -2
  97. package/dist/types/src/types/index.d.ts.map +1 -1
  98. package/dist/types/tsconfig.tsbuildinfo +1 -1
  99. package/package.json +107 -59
  100. package/src/ExplorerPlugin.test.ts +26 -0
  101. package/src/ExplorerPlugin.tsx +15 -54
  102. package/src/capabilities/create-object.ts +36 -0
  103. package/src/capabilities/index.ts +3 -3
  104. package/src/capabilities/react-surface.tsx +24 -15
  105. package/src/components/Chart/Chart.stories.tsx +19 -25
  106. package/src/components/Globe/Globe.stories.tsx +22 -24
  107. package/src/components/Graph/CanvasForceGraph.stories.tsx +83 -0
  108. package/src/components/Graph/CanvasForceGraph.tsx +124 -0
  109. package/src/components/Graph/ForceGraph.stories.tsx +83 -35
  110. package/src/components/Graph/ForceGraph.tsx +104 -85
  111. package/src/components/Graph/{adapter.ts → graph-adapter.ts} +14 -8
  112. package/src/components/Graph/index.ts +1 -1
  113. package/src/components/Graph/testing.ts +11 -8
  114. package/src/components/Tree/Tree.stories.tsx +44 -38
  115. package/src/components/Tree/Tree.tsx +10 -5
  116. package/src/components/Tree/testing/generator.ts +4 -2
  117. package/src/components/Tree/types/tree.test.ts +7 -6
  118. package/src/components/Tree/types/tree.ts +42 -21
  119. package/src/components/Tree/types/types.ts +1 -1
  120. package/src/components/index.ts +0 -4
  121. package/src/containers/ExplorerContainer/ExplorerContainer.tsx +51 -0
  122. package/src/containers/ExplorerContainer/index.ts +5 -0
  123. package/src/containers/index.ts +7 -0
  124. package/src/hooks/useGraphModel.ts +17 -10
  125. package/src/index.ts +1 -4
  126. package/src/meta.ts +9 -6
  127. package/src/plugin.ts +9 -0
  128. package/src/translations.ts +17 -12
  129. package/src/types/ExplorerAction.ts +20 -0
  130. package/src/types/Graph.ts +49 -0
  131. package/src/types/index.ts +2 -2
  132. package/src/typings.d.ts +8 -0
  133. package/dist/lib/browser/ExplorerContainer-7MTDS2TQ.mjs +0 -37
  134. package/dist/lib/browser/ExplorerContainer-7MTDS2TQ.mjs.map +0 -7
  135. package/dist/lib/browser/chunk-2MKBRIUT.mjs +0 -31
  136. package/dist/lib/browser/chunk-2MKBRIUT.mjs.map +0 -7
  137. package/dist/lib/browser/chunk-3YITRGGW.mjs +0 -203
  138. package/dist/lib/browser/chunk-3YITRGGW.mjs.map +0 -7
  139. package/dist/lib/browser/chunk-CZZ3DDR7.mjs +0 -38
  140. package/dist/lib/browser/chunk-CZZ3DDR7.mjs.map +0 -7
  141. package/dist/lib/browser/chunk-UL5EDJPE.mjs +0 -21
  142. package/dist/lib/browser/chunk-UL5EDJPE.mjs.map +0 -7
  143. package/dist/lib/browser/chunk-VNOGW2JS.mjs.map +0 -7
  144. package/dist/lib/browser/index.mjs +0 -112
  145. package/dist/lib/browser/index.mjs.map +0 -7
  146. package/dist/lib/browser/intent-resolver-7MVEYNX7.mjs +0 -24
  147. package/dist/lib/browser/intent-resolver-7MVEYNX7.mjs.map +0 -7
  148. package/dist/lib/browser/meta.json +0 -1
  149. package/dist/lib/browser/react-surface-VLGQKYBI.mjs +0 -31
  150. package/dist/lib/browser/react-surface-VLGQKYBI.mjs.map +0 -7
  151. package/dist/lib/browser/types/index.mjs +0 -10
  152. package/dist/lib/node-esm/ExplorerContainer-OBSRVHZZ.mjs +0 -38
  153. package/dist/lib/node-esm/ExplorerContainer-OBSRVHZZ.mjs.map +0 -7
  154. package/dist/lib/node-esm/chunk-3ODK27PU.mjs +0 -33
  155. package/dist/lib/node-esm/chunk-3ODK27PU.mjs.map +0 -7
  156. package/dist/lib/node-esm/chunk-4GWDNZ4Z.mjs +0 -39
  157. package/dist/lib/node-esm/chunk-4GWDNZ4Z.mjs.map +0 -7
  158. package/dist/lib/node-esm/chunk-GFYXDQQV.mjs +0 -205
  159. package/dist/lib/node-esm/chunk-GFYXDQQV.mjs.map +0 -7
  160. package/dist/lib/node-esm/chunk-ODMJ7DPA.mjs +0 -11343
  161. package/dist/lib/node-esm/chunk-PIAXA43R.mjs +0 -23
  162. package/dist/lib/node-esm/chunk-PIAXA43R.mjs.map +0 -7
  163. package/dist/lib/node-esm/index.mjs +0 -113
  164. package/dist/lib/node-esm/index.mjs.map +0 -7
  165. package/dist/lib/node-esm/intent-resolver-NL3SR2XF.mjs +0 -25
  166. package/dist/lib/node-esm/intent-resolver-NL3SR2XF.mjs.map +0 -7
  167. package/dist/lib/node-esm/meta.json +0 -1
  168. package/dist/lib/node-esm/meta.mjs +0 -10
  169. package/dist/lib/node-esm/react-surface-BYJABDS5.mjs +0 -32
  170. package/dist/lib/node-esm/react-surface-BYJABDS5.mjs.map +0 -7
  171. package/dist/lib/node-esm/types/index.mjs +0 -11
  172. package/dist/types/src/capabilities/intent-resolver.d.ts +0 -4
  173. package/dist/types/src/capabilities/intent-resolver.d.ts.map +0 -1
  174. package/dist/types/src/components/ExplorerContainer.d.ts +0 -9
  175. package/dist/types/src/components/ExplorerContainer.d.ts.map +0 -1
  176. package/dist/types/src/components/Graph/D3ForceGraph.d.ts +0 -14
  177. package/dist/types/src/components/Graph/D3ForceGraph.d.ts.map +0 -1
  178. package/dist/types/src/components/Graph/D3ForceGraph.stories.d.ts +0 -20
  179. package/dist/types/src/components/Graph/D3ForceGraph.stories.d.ts.map +0 -1
  180. package/dist/types/src/components/Graph/adapter.d.ts.map +0 -1
  181. package/dist/types/src/types/schema.d.ts +0 -12
  182. package/dist/types/src/types/schema.d.ts.map +0 -1
  183. package/dist/types/src/types/types.d.ts +0 -18
  184. package/dist/types/src/types/types.d.ts.map +0 -1
  185. package/src/capabilities/intent-resolver.ts +0 -19
  186. package/src/components/ExplorerContainer.tsx +0 -37
  187. package/src/components/Graph/D3ForceGraph.stories.tsx +0 -67
  188. package/src/components/Graph/D3ForceGraph.tsx +0 -101
  189. package/src/types/schema.ts +0 -16
  190. package/src/types/types.ts +0 -22
  191. /package/dist/lib/{browser/meta.mjs.map → neutral/chunk-J5LGTIGS.mjs.map} +0 -0
  192. /package/dist/lib/{browser/types → neutral}/index.mjs.map +0 -0
  193. /package/dist/lib/{node-esm → neutral}/meta.mjs.map +0 -0
  194. /package/dist/lib/{node-esm → neutral}/types/index.mjs.map +0 -0
@@ -2,53 +2,59 @@
2
2
  // Copyright 2023 DXOS.org
3
3
  //
4
4
 
5
- import '@dxos-theme';
6
-
7
5
  import { type Meta, type StoryObj } from '@storybook/react-vite';
8
- import React, { useEffect, useState } from 'react';
9
-
10
- import { faker } from '@dxos/random';
11
- import { useClient } from '@dxos/react-client';
12
- import { type ClientRepeatedComponentProps, ClientRepeater } from '@dxos/react-client/testing';
13
- import { withLayout, withTheme } from '@dxos/storybook-utils';
14
-
6
+ import * as Effect from 'effect/Effect';
7
+ import React from 'react';
8
+
9
+ import { withPluginManager } from '@dxos/app-framework/testing';
10
+ import { Filter } from '@dxos/echo';
11
+ import { ClientPlugin } from '@dxos/plugin-client/plugin';
12
+ import { initializeIdentity } from '@dxos/plugin-client/testing';
13
+ import { corePlugins } from '@dxos/plugin-testing';
14
+ import { random } from '@dxos/random';
15
+ import { useQuery, useSpaces } from '@dxos/react-client/echo';
16
+ import { Loading, withLayout, withTheme } from '@dxos/react-ui/testing';
17
+
18
+ import { createTree } from './testing';
15
19
  import { Tree, type TreeComponentProps } from './Tree';
16
- import { Tree as TreeModel, TreeType } from './types';
17
-
18
- // TODO(burdon): Storybook for Graph/Tree/Plot (generics); incl. GraphModel.
19
- // TODO(burdon): Type for all Explorer components (Space, Object, Query, etc.) incl.
20
+ import { TreeType } from './types';
20
21
 
21
- faker.seed(1);
22
+ random.seed(1);
22
23
 
23
- type ComponentProps = ClientRepeatedComponentProps & { type?: TreeComponentProps<any>['variant'] };
24
+ type StoryArgs = { variant?: TreeComponentProps<any>['variant'] };
24
25
 
25
- const Component = ({ type }: ComponentProps) => {
26
- const client = useClient();
27
- const space = client.spaces.default;
28
- const [object, setObject] = useState<TreeType>();
29
- useEffect(() => {
30
- setTimeout(() => {
31
- const tree = space.db.add(TreeModel.create());
32
- setObject(tree);
33
- });
34
- }, []);
35
-
36
- if (!object) {
37
- return null;
26
+ const DefaultStory = ({ variant }: StoryArgs) => {
27
+ const [space] = useSpaces();
28
+ const [tree] = useQuery(space?.db, Filter.type(TreeType));
29
+ if (!space || !tree) {
30
+ return <Loading data={{ space: !!space, tree: !!tree }} />;
38
31
  }
39
32
 
40
- return <Tree space={space} selected={object?.id} variant={type} />;
41
- };
42
-
43
- const DefaultStory = () => {
44
- return <ClientRepeater component={Component} types={[TreeType]} createSpace />;
33
+ return <Tree space={space} selected={tree.id} variant={variant} />;
45
34
  };
46
35
 
47
36
  const meta = {
48
- title: 'plugins/plugin-explorer/Tree',
37
+ title: 'plugins/plugin-explorer/components/Tree',
49
38
  component: Tree as any,
50
39
  render: DefaultStory,
51
- decorators: [withTheme, withLayout({ fullscreen: true })],
40
+ decorators: [
41
+ withTheme(),
42
+ withLayout({ layout: 'fullscreen' }),
43
+ withPluginManager({
44
+ plugins: [
45
+ ...corePlugins(),
46
+ ClientPlugin({
47
+ types: [TreeType],
48
+ onClientInitialized: ({ client }) =>
49
+ Effect.gen(function* () {
50
+ const { personalSpace } = yield* initializeIdentity(client);
51
+ const tree = createTree([3, [2, 4], [1, 3]]).tree;
52
+ personalSpace.db.add(tree);
53
+ }),
54
+ }),
55
+ ],
56
+ }),
57
+ ],
52
58
  parameters: {
53
59
  layout: 'fullscreen',
54
60
  },
@@ -60,18 +66,18 @@ type Story = StoryObj<typeof meta>;
60
66
 
61
67
  export const Tidy: Story = {
62
68
  args: {
63
- type: 'tidy',
69
+ variant: 'tidy',
64
70
  },
65
71
  };
66
72
 
67
73
  export const Radial: Story = {
68
74
  args: {
69
- type: 'radial',
75
+ variant: 'radial',
70
76
  },
71
77
  };
72
78
 
73
79
  export const Edge: Story = {
74
80
  args: {
75
- type: 'edge',
81
+ variant: 'edge',
76
82
  },
77
83
  };
@@ -2,7 +2,8 @@
2
2
  // Copyright 2023 DXOS.org
3
3
  //
4
4
 
5
- import React, { useEffect, useRef, useState } from 'react';
5
+ import { RegistryContext } from '@effect-atom/atom-react';
6
+ import React, { useContext, useEffect, useRef, useState } from 'react';
6
7
 
7
8
  import { type Space } from '@dxos/client/echo';
8
9
  import { useAsyncState } from '@dxos/react-ui';
@@ -62,7 +63,11 @@ export type TreeComponentProps<N = unknown> = {
62
63
 
63
64
  // TODO(burdon): Label accessor.
64
65
  export const Tree = <N,>({ space, selected, variant = 'tidy', onNodeClick }: TreeComponentProps<N>) => {
65
- const [model] = useAsyncState(async () => (space ? new SpaceGraphModel().open(space) : undefined), [space, selected]);
66
+ const registry = useContext(RegistryContext);
67
+ const [model] = useAsyncState(
68
+ async () => (space ? new SpaceGraphModel(registry).open(space.db) : undefined),
69
+ [space, selected, registry],
70
+ );
66
71
 
67
72
  const [tree, setTree] = useState<TreeNode>();
68
73
  useEffect(() => {
@@ -75,8 +80,8 @@ export const Tree = <N,>({ space, selected, variant = 'tidy', onNodeClick }: Tre
75
80
  const context = useRef<SVGContext>(null);
76
81
 
77
82
  useEffect(() => {
78
- if (context.current) {
79
- const { width, height } = context.current.size!;
83
+ if (context.current?.size) {
84
+ const { width, height } = context.current.size;
80
85
  const size = Math.min(width, height);
81
86
  const radius = size * 0.4;
82
87
  const options = {
@@ -100,7 +105,7 @@ export const Tree = <N,>({ space, selected, variant = 'tidy', onNodeClick }: Tre
100
105
  }, [context.current, tree]);
101
106
 
102
107
  return (
103
- <div onClick={() => onNodeClick?.()}>
108
+ <div className='grow' onClick={() => onNodeClick?.()}>
104
109
  <SVG.Root ref={context} />
105
110
  </div>
106
111
  );
@@ -2,7 +2,7 @@
2
2
  // Copyright 2025 DXOS.org
3
3
  //
4
4
 
5
- import { Key } from '@dxos/echo';
5
+ import { Key, Obj } from '@dxos/echo';
6
6
  import { range } from '@dxos/util';
7
7
 
8
8
  import { Tree, type TreeNodeType } from '../types';
@@ -16,7 +16,9 @@ const random = (min: number, max: number) => Math.floor(Math.random() * (max - m
16
16
  */
17
17
  export const createTree = (spec: NumberOrNumberArray[] = [], createText?: () => string): Tree => {
18
18
  const tree = new Tree();
19
- tree.root.data = { text: 'root' };
19
+ Obj.update(tree.tree, () => {
20
+ tree.root.data = { text: 'root' };
21
+ });
20
22
 
21
23
  const createNodes = (parent: TreeNodeType, spec: NumberOrNumberArray = 0): TreeNodeType[] => {
22
24
  const count = Array.isArray(spec) ? random(spec[0], spec[1]) : spec;
@@ -5,14 +5,13 @@
5
5
  import { describe, test } from 'vitest';
6
6
 
7
7
  import { Obj, Ref } from '@dxos/echo';
8
- import { faker } from '@dxos/random';
9
- import { DataType } from '@dxos/schema';
8
+ import { random } from '@dxos/random';
9
+ import { Task } from '@dxos/types';
10
10
 
11
11
  import { createTree } from '../testing';
12
-
13
12
  import { type Tree } from './tree';
14
13
 
15
- faker.seed(0);
14
+ random.seed(0);
16
15
 
17
16
  const print = (tree: Tree) => {
18
17
  let count = 0;
@@ -124,11 +123,13 @@ describe('tree', () => {
124
123
  });
125
124
 
126
125
  test('task', ({ expect }) => {
127
- const task = Obj.make(DataType.Task, { title: 'Test task.' });
126
+ const task = Obj.make(Task.Task, { title: 'Test task.' });
128
127
  expect(task.title).to.eq('Test task.');
129
128
 
130
129
  const tree = createTree();
131
130
  const node = tree.addNode(tree.root);
132
- node.ref = Ref.make(task);
131
+ Obj.update(tree.tree, () => {
132
+ node.ref = Ref.make(task);
133
+ });
133
134
  });
134
135
  });
@@ -2,9 +2,10 @@
2
2
  // Copyright 2023 DXOS.org
3
3
  //
4
4
 
5
- import { Schema } from 'effect';
5
+ import * as Schema from 'effect/Schema';
6
6
 
7
- import { Key, Obj, Type } from '@dxos/echo';
7
+ import { Key, Obj, Ref, Type } from '@dxos/echo';
8
+ import { TestSchema } from '@dxos/echo/testing';
8
9
  import { invariant } from '@dxos/invariant';
9
10
 
10
11
  // TODO(burdon): Reconcile with @dxos/graph (i.e., common types).
@@ -13,7 +14,7 @@ export const TreeNodeType = Schema.Struct({
13
14
  id: Key.ObjectId,
14
15
  children: Schema.mutable(Schema.Array(Key.ObjectId)),
15
16
  data: Schema.mutable(Schema.Record({ key: Schema.String, value: Schema.Any })),
16
- ref: Schema.optional(Type.Ref(Type.Expando)),
17
+ ref: Schema.optional(Ref.Ref(TestSchema.Expando)),
17
18
  }).pipe(Schema.mutable);
18
19
 
19
20
  export interface TreeNodeType extends Schema.Schema.Type<typeof TreeNodeType> {}
@@ -22,8 +23,8 @@ export const TreeType = Schema.Struct({
22
23
  root: Key.ObjectId,
23
24
  nodes: Schema.mutable(Schema.Record({ key: Key.ObjectId, value: TreeNodeType })),
24
25
  }).pipe(
25
- Type.Obj({
26
- typename: 'dxos.org/type/Tree',
26
+ Type.object({
27
+ typename: 'org.dxos.type.tree',
27
28
  version: '0.1.0',
28
29
  }),
29
30
  );
@@ -184,9 +185,11 @@ export class Tree {
184
185
  clear(): void {
185
186
  const root = this._tree.nodes[this._tree.root];
186
187
  root.children.length = 0;
187
- this._tree.nodes = {
188
- [root.id]: root,
189
- };
188
+ Obj.update(this._tree, (obj) => {
189
+ obj.nodes = {
190
+ [root.id]: root,
191
+ };
192
+ });
190
193
  }
191
194
 
192
195
  /**
@@ -198,8 +201,11 @@ export class Tree {
198
201
  node = { id, children: [], data: { text: '' } }; // TODO(burdon): Generic.
199
202
  }
200
203
 
201
- this._tree.nodes[node.id] = node;
202
- parent.children.splice(index ?? parent.children.length, 0, node.id);
204
+ const nodeToAdd = node;
205
+ Obj.update(this._tree, (obj) => {
206
+ obj.nodes[nodeToAdd.id] = nodeToAdd;
207
+ parent.children.splice(index ?? parent.children.length, 0, nodeToAdd.id);
208
+ });
203
209
  return node;
204
210
  }
205
211
 
@@ -212,10 +218,14 @@ export class Tree {
212
218
  return undefined;
213
219
  }
214
220
 
215
- delete this._tree.nodes[node.id];
221
+ Obj.update(this._tree, (obj) => {
222
+ delete obj.nodes[node.id];
223
+ });
216
224
  const idx = parent.children.findIndex((child) => child === id);
217
225
  if (idx !== -1) {
218
- parent.children.splice(idx, 1);
226
+ Obj.update(this._tree, () => {
227
+ parent.children.splice(idx, 1);
228
+ });
219
229
  }
220
230
 
221
231
  return node;
@@ -232,8 +242,10 @@ export class Tree {
232
242
  }
233
243
 
234
244
  const child = node.children[from];
235
- node.children.splice(from, 1);
236
- node.children.splice(to, 0, child);
245
+ Obj.update(this._tree, () => {
246
+ node.children.splice(from, 1);
247
+ node.children.splice(to, 0, child);
248
+ });
237
249
  return this.getNode(child);
238
250
  }
239
251
 
@@ -252,8 +264,10 @@ export class Tree {
252
264
  }
253
265
 
254
266
  const previous = this.getNode(parent.children[idx - 1]);
255
- parent.children.splice(idx, 1);
256
- previous.children.push(node.id);
267
+ Obj.update(this._tree, () => {
268
+ parent.children.splice(idx, 1);
269
+ previous.children.push(node.id);
270
+ });
257
271
  }
258
272
 
259
273
  /**
@@ -270,16 +284,23 @@ export class Tree {
270
284
  return;
271
285
  }
272
286
 
273
- // Remove node from parent.
287
+ // Remove node from parent and get following siblings.
274
288
  const nodeIdx = parent.children.findIndex((id) => id === node.id);
275
- const [_, ...rest] = parent.children.splice(nodeIdx, parent.children.length - nodeIdx);
276
- parent.children.splice(nodeIdx, parent.children.length - nodeIdx);
289
+ let rest: Key.ObjectId[] = [];
290
+ Obj.update(this._tree, () => {
291
+ const removed = parent.children.splice(nodeIdx, parent.children.length - nodeIdx);
292
+ rest = removed.slice(1); // Skip the node itself.
293
+ });
277
294
 
278
295
  // Add to ancestor.
279
296
  const parentIdx = this.getChildNodes(ancestor).findIndex((n) => n.id === parent.id);
280
- ancestor.children.splice(parentIdx + 1, 0, node.id);
297
+ Obj.update(this._tree, () => {
298
+ ancestor.children.splice(parentIdx + 1, 0, node.id);
299
+ });
281
300
 
282
301
  // Transplant following siblings to current node.
283
- node.children.push(...rest);
302
+ Obj.update(this._tree, () => {
303
+ node.children.push(...rest);
304
+ });
284
305
  }
285
306
  }
@@ -10,7 +10,7 @@ export type TreeNode = {
10
10
  children?: TreeNode[];
11
11
  };
12
12
 
13
- export const mapGraphToTreeData = (model: GraphModel, maxDepth = 8): TreeNode | undefined => {
13
+ export const mapGraphToTreeData = (model: GraphModel.GraphModel, maxDepth = 8): TreeNode | undefined => {
14
14
  // TODO(burdon): Convert to common/graph.
15
15
  // const mapNode = (node: N, depth = 0): TreeNode => {
16
16
  // const treeNode: TreeNode = {
@@ -2,10 +2,6 @@
2
2
  // Copyright 2023 DXOS.org
3
3
  //
4
4
 
5
- import { lazy } from 'react';
6
-
7
- export const ExplorerContainer = lazy(() => import('./ExplorerContainer'));
8
-
9
5
  export * from './Chart';
10
6
  export * from './Globe';
11
7
  export * from './Graph';
@@ -0,0 +1,51 @@
1
+ //
2
+ // Copyright 2023 DXOS.org
3
+ //
4
+
5
+ import React, { useCallback, useMemo, useState } from 'react';
6
+
7
+ import { type AppSurface } from '@dxos/app-toolkit/ui';
8
+ import { type Filter } from '@dxos/echo';
9
+ import { type View } from '@dxos/echo';
10
+ import { QueryBuilder } from '@dxos/echo-query';
11
+ import { getSpace, useObject } from '@dxos/react-client/echo';
12
+ import { Panel, Toolbar } from '@dxos/react-ui';
13
+ import { QueryEditor, type QueryEditorProps } from '@dxos/react-ui-components';
14
+
15
+ import { ForceGraph } from '#components';
16
+ import { useGraphModel } from '#hooks';
17
+
18
+ export type ExplorerContainerProps = AppSurface.ObjectArticleProps<View.View>;
19
+
20
+ export const ExplorerContainer = ({ role, subject, attendableId: _attendableId }: ExplorerContainerProps) => {
21
+ const [view] = useObject(subject);
22
+ const space = view && getSpace(view);
23
+ const [filter, setFilter] = useState<Filter.Any>();
24
+ const model = useGraphModel(space, filter);
25
+
26
+ const builder = useMemo(() => new QueryBuilder(), []);
27
+ const handleChange = useCallback<NonNullable<QueryEditorProps['onChange']>>((value) => {
28
+ setFilter(builder.build(value).filter);
29
+ }, []);
30
+
31
+ const showToolbar = role === 'article';
32
+
33
+ if (!space || !model) {
34
+ return null;
35
+ }
36
+
37
+ return (
38
+ <Panel.Root role={role}>
39
+ {showToolbar && (
40
+ <Panel.Toolbar asChild>
41
+ <Toolbar.Root>
42
+ <QueryEditor db={space.db} onChange={handleChange} />
43
+ </Toolbar.Root>
44
+ </Panel.Toolbar>
45
+ )}
46
+ <Panel.Content asChild>
47
+ <ForceGraph model={model} />
48
+ </Panel.Content>
49
+ </Panel.Root>
50
+ );
51
+ };
@@ -0,0 +1,5 @@
1
+ //
2
+ // Copyright 2023 DXOS.org
3
+ //
4
+
5
+ export { ExplorerContainer as default } from './ExplorerContainer';
@@ -0,0 +1,7 @@
1
+ //
2
+ // Copyright 2023 DXOS.org
3
+ //
4
+
5
+ import { type ComponentType, lazy } from 'react';
6
+
7
+ export const ExplorerContainer: ComponentType<any> = lazy(() => import('./ExplorerContainer'));
@@ -4,6 +4,8 @@
4
4
 
5
5
  import { useEffect, useState } from 'react';
6
6
 
7
+ import { Capabilities } from '@dxos/app-framework';
8
+ import { useCapability } from '@dxos/app-framework/ui';
7
9
  import { type Filter, type Queue, type Space } from '@dxos/client/echo';
8
10
  import { SpaceGraphModel, type SpaceGraphModelOptions } from '@dxos/schema';
9
11
 
@@ -14,23 +16,28 @@ export const useGraphModel = (
14
16
  options?: SpaceGraphModelOptions,
15
17
  queue?: Queue,
16
18
  ): SpaceGraphModel | undefined => {
19
+ const registry = useCapability(Capabilities.AtomRegistry);
17
20
  const [model, setModel] = useState<SpaceGraphModel | undefined>(undefined);
21
+
18
22
  useEffect(() => {
19
23
  if (!space) {
20
- void model?.close();
21
24
  setModel(undefined);
22
25
  return;
23
26
  }
24
27
 
25
- // TODO(burdon): Does this need to be a dependency?
26
- if (!model || model.queue !== queue) {
27
- const model = new SpaceGraphModel().setFilter(filter).setOptions(options);
28
- void model.open(space, queue);
29
- setModel(model);
30
- } else {
31
- model.setFilter(filter).setOptions(options);
32
- }
33
- }, [space, filter, options, queue]);
28
+ const newModel = new SpaceGraphModel(registry);
29
+ void newModel.open(space.db, queue);
30
+ setModel(newModel);
31
+
32
+ return () => {
33
+ setModel(undefined);
34
+ void newModel.close();
35
+ };
36
+ }, [space, registry, queue]);
37
+
38
+ useEffect(() => {
39
+ model?.setFilter(filter).setOptions(options);
40
+ }, [model, filter, options]);
34
41
 
35
42
  return model;
36
43
  };
package/src/index.ts CHANGED
@@ -2,8 +2,5 @@
2
2
  // Copyright 2023 DXOS.org
3
3
  //
4
4
 
5
- export * from './components';
6
- export * from './hooks';
7
5
  export * from './meta';
8
-
9
- export * from './ExplorerPlugin';
6
+ export * from './types';
package/src/meta.ts CHANGED
@@ -2,15 +2,18 @@
2
2
  // Copyright 2023 DXOS.org
3
3
  //
4
4
 
5
- import { type PluginMeta } from '@dxos/app-framework';
5
+ import { type Plugin } from '@dxos/app-framework';
6
+ import { trim } from '@dxos/util';
6
7
 
7
- export const EXPLORER_PLUGIN = 'dxos.org/plugin/explorer';
8
-
9
- export const meta: PluginMeta = {
10
- id: EXPLORER_PLUGIN,
8
+ export const meta: Plugin.Meta = {
9
+ id: 'org.dxos.plugin.explorer',
11
10
  name: 'Explorer',
12
- description: 'Install this plugin to view a hypergraph of all objects inside of your Space.',
11
+ description: trim`
12
+ Interactive hypergraph visualization that reveals relationships between objects in your workspace.
13
+ Navigate complex data structures and discover connections through a dynamic network view.
14
+ `,
13
15
  icon: 'ph--graph--regular',
16
+ iconHue: 'green',
14
17
  source: 'https://github.com/dxos/dxos/tree/main/packages/plugins/plugin-explorer',
15
18
  tags: ['labs'],
16
19
  screenshots: ['https://dxos.network/plugin-details-explorer-dark.png'],
package/src/plugin.ts ADDED
@@ -0,0 +1,9 @@
1
+ //
2
+ // Copyright 2023 DXOS.org
3
+ //
4
+
5
+ import { Plugin } from '@dxos/app-framework';
6
+
7
+ import { meta } from './meta';
8
+
9
+ export const ExplorerPlugin = Plugin.lazy(meta, () => import('#plugin'));
@@ -2,27 +2,32 @@
2
2
  // Copyright 2023 DXOS.org
3
3
  //
4
4
 
5
+ import { Type } from '@dxos/echo';
5
6
  import { type Resource } from '@dxos/react-ui';
7
+ import { translations as componentsTranslations } from '@dxos/react-ui-components/translations';
6
8
 
7
- import { meta } from './meta';
8
- import { ViewType } from './types';
9
+ import { meta } from '#meta';
10
+ import { Graph } from '#types';
9
11
 
10
12
  export const translations = [
11
13
  {
12
14
  'en-US': {
13
- [ViewType.typename]: {
14
- 'typename label': 'Explorer',
15
- 'typename label_zero': 'Explorers',
16
- 'typename label_one': 'Explorer',
17
- 'typename label_other': 'Explorers',
18
- 'object name placeholder': 'New explorer',
19
- 'rename object label': 'Rename explorer',
20
- 'delete object label': 'Delete explorer',
15
+ [Type.getTypename(Graph.Graph)]: {
16
+ 'typename.label': 'Explorer',
17
+ 'typename.label_zero': 'Explorers',
18
+ 'typename.label_one': 'Explorer',
19
+ 'typename.label_other': 'Explorers',
20
+ 'object-name.placeholder': 'New explorer',
21
+ 'add-object.label': 'Add explorer',
22
+ 'rename-object.label': 'Rename explorer',
23
+ 'delete-object.label': 'Delete explorer',
24
+ 'object-deleted.label': 'Explorer deleted',
21
25
  },
22
26
  [meta.id]: {
23
- 'plugin name': 'Explorer',
24
- 'object title label': 'Title',
27
+ 'plugin.name': 'Explorer',
28
+ 'object-title.label': 'Title',
25
29
  },
26
30
  },
27
31
  },
32
+ ...componentsTranslations,
28
33
  ] as const satisfies Resource[];
@@ -0,0 +1,20 @@
1
+ //
2
+ // Copyright 2023 DXOS.org
3
+ //
4
+
5
+ import * as Schema from 'effect/Schema';
6
+
7
+ import { TypeInputOptionsAnnotation } from '@dxos/plugin-space';
8
+
9
+ export const GraphProps = Schema.Struct({
10
+ name: Schema.optional(Schema.String),
11
+ // TODO(wittjosiah): This should be a query input instead.
12
+ typename: Schema.String.pipe(
13
+ Schema.annotations({ title: 'Select type' }),
14
+ TypeInputOptionsAnnotation.set({
15
+ location: ['database', 'runtime'],
16
+ kind: ['user'],
17
+ }),
18
+ Schema.optional,
19
+ ),
20
+ });
@@ -0,0 +1,49 @@
1
+ //
2
+ // Copyright 2024 DXOS.org
3
+ //
4
+
5
+ import * as Schema from 'effect/Schema';
6
+
7
+ import { Annotation, Filter, Obj, Query, QueryAST, Ref, Type } from '@dxos/echo';
8
+ import { View } from '@dxos/echo';
9
+ import { FormInputAnnotation, LabelAnnotation } from '@dxos/echo/internal';
10
+ import { ViewAnnotation } from '@dxos/schema';
11
+
12
+ const GraphSchema = Schema.Struct({
13
+ name: Schema.optional(Schema.String),
14
+
15
+ view: Ref.Ref(View.View).pipe(FormInputAnnotation.set(false)),
16
+
17
+ query: Schema.Struct({
18
+ raw: Schema.optional(Schema.String),
19
+ ast: QueryAST.Query,
20
+ }).pipe(FormInputAnnotation.set(false)),
21
+ }).pipe(
22
+ Type.object({
23
+ typename: 'org.dxos.type.graph',
24
+ version: '0.1.0',
25
+ }),
26
+ LabelAnnotation.set(['name']),
27
+ ViewAnnotation.set(['view']),
28
+ Annotation.IconAnnotation.set({
29
+ icon: 'ph--graph--regular',
30
+ hue: 'green',
31
+ }),
32
+ );
33
+ export interface Graph extends Schema.Schema.Type<typeof GraphSchema> {}
34
+ export const Graph: Type.Obj<Graph> = GraphSchema as any;
35
+
36
+ type MakeProps = Omit<Partial<Obj.MakeProps<typeof Graph>>, 'view'> & {
37
+ view: View.View;
38
+ };
39
+
40
+ /**
41
+ * Make a graph as a view of a data set.
42
+ */
43
+ export const make = ({
44
+ name,
45
+ query = { raw: '', ast: Query.select(Filter.nothing()).ast },
46
+ view,
47
+ }: MakeProps): Graph => {
48
+ return Obj.make(Graph, { name, view: Ref.make(view), query });
49
+ };
@@ -2,5 +2,5 @@
2
2
  // Copyright 2024 DXOS.org
3
3
  //
4
4
 
5
- export * from './schema';
6
- export * from './types';
5
+ export * as ExplorerAction from './ExplorerAction';
6
+ export * as Graph from './Graph';
@@ -0,0 +1,8 @@
1
+ //
2
+ // Copyright 2024 DXOS.org
3
+ //
4
+
5
+ declare module '*.css' {
6
+ const content: undefined;
7
+ export default content;
8
+ }