@dxos/plugin-explorer 0.8.4-main.c85a9c8dae → 0.8.4-main.d9fc60f731

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 (261) hide show
  1. package/LICENSE +102 -5
  2. package/PLUGIN.mdl +340 -0
  3. package/dist/lib/neutral/ExplorerArticle-4I7PNGDC.mjs +459 -0
  4. package/dist/lib/neutral/ExplorerArticle-4I7PNGDC.mjs.map +7 -0
  5. package/dist/lib/neutral/ExplorerPlugin.mjs +10 -0
  6. package/dist/lib/neutral/capabilities/index.mjs +11 -0
  7. package/dist/lib/neutral/capabilities/index.mjs.map +7 -0
  8. package/dist/lib/neutral/chunk-3D7BYXOR.mjs +37 -0
  9. package/dist/lib/neutral/chunk-3D7BYXOR.mjs.map +7 -0
  10. package/dist/lib/neutral/chunk-42BYLQQA.mjs +42 -0
  11. package/dist/lib/neutral/chunk-42BYLQQA.mjs.map +7 -0
  12. package/dist/lib/neutral/chunk-7XUDLV6E.mjs +287 -0
  13. package/dist/lib/neutral/chunk-7XUDLV6E.mjs.map +7 -0
  14. package/dist/lib/{browser/chunk-4NFGHCGO.mjs → neutral/chunk-HI324IB4.mjs} +10 -25
  15. package/dist/lib/neutral/chunk-HI324IB4.mjs.map +7 -0
  16. package/dist/lib/neutral/chunk-IKHJV3Q4.mjs +20 -0
  17. package/dist/lib/neutral/chunk-IKHJV3Q4.mjs.map +7 -0
  18. package/dist/lib/{browser/chunk-6AZY4CDH.mjs → neutral/components/index.mjs} +747 -358
  19. package/dist/lib/neutral/components/index.mjs.map +7 -0
  20. package/dist/lib/neutral/containers/index.mjs +9 -0
  21. package/dist/lib/neutral/containers/index.mjs.map +7 -0
  22. package/dist/lib/neutral/create-object-F6TKVAGV.mjs +39 -0
  23. package/dist/lib/neutral/create-object-F6TKVAGV.mjs.map +7 -0
  24. package/dist/lib/neutral/hooks/index.mjs +45 -0
  25. package/dist/lib/neutral/hooks/index.mjs.map +7 -0
  26. package/dist/lib/neutral/index.mjs +14 -0
  27. package/dist/lib/neutral/meta.json +1 -0
  28. package/dist/lib/{browser → neutral}/meta.mjs +1 -1
  29. package/dist/lib/neutral/plugin.mjs +12 -0
  30. package/dist/lib/neutral/plugin.mjs.map +7 -0
  31. package/dist/lib/neutral/react-surface-APBW2VQG.mjs +26 -0
  32. package/dist/lib/neutral/react-surface-APBW2VQG.mjs.map +7 -0
  33. package/dist/lib/neutral/testing/index.mjs +139 -0
  34. package/dist/lib/neutral/testing/index.mjs.map +7 -0
  35. package/dist/lib/neutral/translations.mjs +33 -0
  36. package/dist/lib/neutral/translations.mjs.map +7 -0
  37. package/dist/lib/{browser → neutral}/types/index.mjs +1 -1
  38. package/dist/types/data/cities.d.ts +4 -4
  39. package/dist/types/data/cities.d.ts.map +1 -1
  40. package/dist/types/data/countries-110m.d.ts +19 -22
  41. package/dist/types/data/countries-110m.d.ts.map +1 -1
  42. package/dist/types/src/ExplorerPlugin.d.ts +1 -0
  43. package/dist/types/src/ExplorerPlugin.d.ts.map +1 -1
  44. package/dist/types/src/ExplorerPlugin.test.d.ts +2 -0
  45. package/dist/types/src/ExplorerPlugin.test.d.ts.map +1 -0
  46. package/dist/types/src/capabilities/create-object.d.ts +11 -0
  47. package/dist/types/src/capabilities/create-object.d.ts.map +1 -0
  48. package/dist/types/src/capabilities/index.d.ts +8 -1
  49. package/dist/types/src/capabilities/index.d.ts.map +1 -1
  50. package/dist/types/src/capabilities/react-surface.d.ts.map +1 -0
  51. package/dist/types/src/components/Chart/Chart.d.ts +1 -1
  52. package/dist/types/src/components/Chart/Chart.d.ts.map +1 -1
  53. package/dist/types/src/components/Chart/Chart.stories.d.ts +4 -1
  54. package/dist/types/src/components/Chart/Chart.stories.d.ts.map +1 -1
  55. package/dist/types/src/components/Globe/Globe.d.ts +1 -1
  56. package/dist/types/src/components/Globe/Globe.d.ts.map +1 -1
  57. package/dist/types/src/components/Globe/Globe.stories.d.ts +5 -2
  58. package/dist/types/src/components/Globe/Globe.stories.d.ts.map +1 -1
  59. package/dist/types/src/components/Graph/CanvasForceGraph.d.ts +13 -0
  60. package/dist/types/src/components/Graph/CanvasForceGraph.d.ts.map +1 -0
  61. package/dist/types/src/components/Graph/CanvasForceGraph.stories.d.ts +17 -0
  62. package/dist/types/src/components/Graph/CanvasForceGraph.stories.d.ts.map +1 -0
  63. package/dist/types/src/components/Graph/ForceGraph.d.ts +12 -5
  64. package/dist/types/src/components/Graph/ForceGraph.d.ts.map +1 -1
  65. package/dist/types/src/components/Graph/ForceGraph.stories.d.ts +4 -2
  66. package/dist/types/src/components/Graph/ForceGraph.stories.d.ts.map +1 -1
  67. package/dist/types/src/components/Graph/{adapter.d.ts → graph-adapter.d.ts} +1 -1
  68. package/dist/types/src/components/Graph/graph-adapter.d.ts.map +1 -0
  69. package/dist/types/src/components/Graph/index.d.ts +1 -1
  70. package/dist/types/src/components/Graph/index.d.ts.map +1 -1
  71. package/dist/types/src/components/Lattice/Lattice.d.ts +20 -0
  72. package/dist/types/src/components/Lattice/Lattice.d.ts.map +1 -0
  73. package/dist/types/src/components/Lattice/Lattice.stories.d.ts +8 -0
  74. package/dist/types/src/components/Lattice/Lattice.stories.d.ts.map +1 -0
  75. package/dist/types/src/components/Lattice/index.d.ts +2 -0
  76. package/dist/types/src/components/Lattice/index.d.ts.map +1 -0
  77. package/dist/types/src/components/Tree/EdgeBundling.stories.d.ts +21 -0
  78. package/dist/types/src/components/Tree/EdgeBundling.stories.d.ts.map +1 -0
  79. package/dist/types/src/components/Tree/Tree.d.ts +20 -23
  80. package/dist/types/src/components/Tree/Tree.d.ts.map +1 -1
  81. package/dist/types/src/components/Tree/Tree.stories.d.ts +5 -12
  82. package/dist/types/src/components/Tree/Tree.stories.d.ts.map +1 -1
  83. package/dist/types/src/components/Tree/index.d.ts +2 -0
  84. package/dist/types/src/components/Tree/index.d.ts.map +1 -1
  85. package/dist/types/src/components/Tree/layout/HierarchicalEdgeBundling.d.ts +37 -2
  86. package/dist/types/src/components/Tree/layout/HierarchicalEdgeBundling.d.ts.map +1 -1
  87. package/dist/types/src/components/Tree/layout/RadialTree.d.ts +35 -2
  88. package/dist/types/src/components/Tree/layout/RadialTree.d.ts.map +1 -1
  89. package/dist/types/src/components/Tree/layout/TidyTree.d.ts +24 -2
  90. package/dist/types/src/components/Tree/layout/TidyTree.d.ts.map +1 -1
  91. package/dist/types/src/components/Tree/layout/hierarchy.d.ts +17 -0
  92. package/dist/types/src/components/Tree/layout/hierarchy.d.ts.map +1 -0
  93. package/dist/types/src/components/Tree/layout/index.d.ts +5 -4
  94. package/dist/types/src/components/Tree/layout/index.d.ts.map +1 -1
  95. package/dist/types/src/components/Tree/layout/slots.d.ts +7 -0
  96. package/dist/types/src/components/Tree/layout/slots.d.ts.map +1 -0
  97. package/dist/types/src/components/Tree/layout/useContainerSize.d.ts +15 -0
  98. package/dist/types/src/components/Tree/layout/useContainerSize.d.ts.map +1 -0
  99. package/dist/types/src/components/Tree/types/tree.d.ts +41 -20
  100. package/dist/types/src/components/Tree/types/tree.d.ts.map +1 -1
  101. package/dist/types/src/components/Tree/types/types.d.ts +14 -4
  102. package/dist/types/src/components/Tree/types/types.d.ts.map +1 -1
  103. package/dist/types/src/components/index.d.ts +1 -0
  104. package/dist/types/src/components/index.d.ts.map +1 -1
  105. package/dist/types/src/containers/ExplorerArticle/ExplorerArticle.d.ts +8 -0
  106. package/dist/types/src/containers/ExplorerArticle/ExplorerArticle.d.ts.map +1 -0
  107. package/dist/types/src/containers/ExplorerArticle/ExplorerArticle.stories.d.ts +15 -0
  108. package/dist/types/src/containers/ExplorerArticle/ExplorerArticle.stories.d.ts.map +1 -0
  109. package/dist/types/src/containers/ExplorerArticle/Visualization.d.ts +18 -0
  110. package/dist/types/src/containers/ExplorerArticle/Visualization.d.ts.map +1 -0
  111. package/dist/types/src/containers/ExplorerArticle/index.d.ts +2 -0
  112. package/dist/types/src/containers/ExplorerArticle/index.d.ts.map +1 -0
  113. package/dist/types/src/containers/ExplorerArticle/variants.d.ts +9 -0
  114. package/dist/types/src/containers/ExplorerArticle/variants.d.ts.map +1 -0
  115. package/dist/types/src/containers/index.d.ts +1 -1
  116. package/dist/types/src/containers/index.d.ts.map +1 -1
  117. package/dist/types/src/hooks/useGraphModel.d.ts +2 -2
  118. package/dist/types/src/hooks/useGraphModel.d.ts.map +1 -1
  119. package/dist/types/src/index.d.ts +1 -3
  120. package/dist/types/src/index.d.ts.map +1 -1
  121. package/dist/types/src/meta.d.ts +1 -1
  122. package/dist/types/src/meta.d.ts.map +1 -1
  123. package/dist/types/src/plugin.d.ts +3 -0
  124. package/dist/types/src/plugin.d.ts.map +1 -0
  125. package/dist/types/src/{components/Tree/testing → testing}/generator.d.ts +1 -1
  126. package/dist/types/src/testing/generator.d.ts.map +1 -0
  127. package/dist/types/src/testing/index.d.ts +4 -0
  128. package/dist/types/src/testing/index.d.ts.map +1 -0
  129. package/dist/types/src/testing/relations.d.ts +32 -0
  130. package/dist/types/src/testing/relations.d.ts.map +1 -0
  131. package/dist/types/src/translations.d.ts +28 -26
  132. package/dist/types/src/translations.d.ts.map +1 -1
  133. package/dist/types/src/types/ExplorerAction.d.ts.map +1 -1
  134. package/dist/types/src/types/Graph.d.ts +5 -13
  135. package/dist/types/src/types/Graph.d.ts.map +1 -1
  136. package/dist/types/src/util/index.d.ts +3 -0
  137. package/dist/types/src/util/index.d.ts.map +1 -0
  138. package/dist/types/src/util/node-color.d.ts +13 -0
  139. package/dist/types/src/util/node-color.d.ts.map +1 -0
  140. package/dist/types/src/{components → util}/plot.d.ts +1 -1
  141. package/dist/types/src/util/plot.d.ts.map +1 -0
  142. package/dist/types/tsconfig.tsbuildinfo +1 -1
  143. package/package.json +104 -62
  144. package/src/ExplorerPlugin.test.ts +26 -0
  145. package/src/ExplorerPlugin.tsx +13 -24
  146. package/src/capabilities/create-object.ts +36 -0
  147. package/src/capabilities/index.ts +4 -1
  148. package/src/capabilities/react-surface.tsx +32 -0
  149. package/src/components/Chart/Chart.stories.tsx +14 -21
  150. package/src/components/Chart/Chart.tsx +1 -1
  151. package/src/components/Globe/Globe.stories.tsx +17 -20
  152. package/src/components/Globe/Globe.tsx +1 -1
  153. package/src/components/Graph/CanvasForceGraph.stories.tsx +97 -0
  154. package/src/components/Graph/CanvasForceGraph.tsx +124 -0
  155. package/src/components/Graph/ForceGraph.stories.tsx +95 -46
  156. package/src/components/Graph/ForceGraph.tsx +105 -85
  157. package/src/components/Graph/index.ts +1 -1
  158. package/src/components/Lattice/Lattice.stories.tsx +104 -0
  159. package/src/components/Lattice/Lattice.tsx +182 -0
  160. package/src/components/Lattice/index.ts +5 -0
  161. package/src/components/Tree/EdgeBundling.stories.tsx +144 -0
  162. package/src/components/Tree/Tree.stories.tsx +19 -38
  163. package/src/components/Tree/Tree.tsx +69 -100
  164. package/src/components/Tree/index.ts +2 -0
  165. package/src/components/Tree/layout/HierarchicalEdgeBundling.tsx +335 -0
  166. package/src/components/Tree/layout/RadialTree.tsx +242 -0
  167. package/src/components/Tree/layout/TidyTree.tsx +246 -0
  168. package/src/components/Tree/layout/hierarchy.ts +32 -0
  169. package/src/components/Tree/layout/index.ts +5 -5
  170. package/src/components/Tree/layout/slots.ts +19 -0
  171. package/src/components/Tree/layout/useContainerSize.ts +43 -0
  172. package/src/components/Tree/types/tree.test.ts +4 -5
  173. package/src/components/Tree/types/tree.ts +26 -31
  174. package/src/components/Tree/types/types.ts +38 -29
  175. package/src/components/index.ts +1 -0
  176. package/src/containers/ExplorerArticle/ExplorerArticle.stories.tsx +152 -0
  177. package/src/containers/ExplorerArticle/ExplorerArticle.tsx +120 -0
  178. package/src/containers/ExplorerArticle/Visualization.tsx +523 -0
  179. package/src/containers/ExplorerArticle/index.ts +5 -0
  180. package/src/containers/ExplorerArticle/variants.ts +47 -0
  181. package/src/containers/index.ts +1 -1
  182. package/src/hooks/useGraphModel.ts +22 -14
  183. package/src/index.ts +1 -4
  184. package/src/meta.ts +26 -7
  185. package/src/plugin.ts +9 -0
  186. package/src/{components/Tree/testing → testing}/generator.ts +3 -3
  187. package/src/testing/index.ts +9 -0
  188. package/src/testing/relations.ts +117 -0
  189. package/src/translations.ts +14 -13
  190. package/src/types/ExplorerAction.ts +1 -2
  191. package/src/types/Graph.ts +6 -28
  192. package/src/typings.d.ts +8 -0
  193. package/src/util/index.ts +6 -0
  194. package/src/util/node-color.ts +23 -0
  195. package/src/{components → util}/plot.ts +16 -4
  196. package/src/vite-env.d.ts +10 -0
  197. package/dist/lib/browser/ExplorerContainer-4RB2TY3G.mjs +0 -48
  198. package/dist/lib/browser/ExplorerContainer-4RB2TY3G.mjs.map +0 -7
  199. package/dist/lib/browser/chunk-4NFGHCGO.mjs.map +0 -7
  200. package/dist/lib/browser/chunk-6AZY4CDH.mjs.map +0 -7
  201. package/dist/lib/browser/chunk-YNQF4CPY.mjs +0 -24
  202. package/dist/lib/browser/chunk-YNQF4CPY.mjs.map +0 -7
  203. package/dist/lib/browser/index.mjs +0 -95
  204. package/dist/lib/browser/index.mjs.map +0 -7
  205. package/dist/lib/browser/meta.json +0 -1
  206. package/dist/lib/browser/react-surface-KAHVDMFX.mjs +0 -38
  207. package/dist/lib/browser/react-surface-KAHVDMFX.mjs.map +0 -7
  208. package/dist/lib/node-esm/ExplorerContainer-LCG425I7.mjs +0 -49
  209. package/dist/lib/node-esm/ExplorerContainer-LCG425I7.mjs.map +0 -7
  210. package/dist/lib/node-esm/chunk-DK77RB6M.mjs +0 -26
  211. package/dist/lib/node-esm/chunk-DK77RB6M.mjs.map +0 -7
  212. package/dist/lib/node-esm/chunk-DOXAIJEC.mjs +0 -11280
  213. package/dist/lib/node-esm/chunk-DOXAIJEC.mjs.map +0 -7
  214. package/dist/lib/node-esm/chunk-HSLMI22Q.mjs +0 -11
  215. package/dist/lib/node-esm/chunk-HSLMI22Q.mjs.map +0 -7
  216. package/dist/lib/node-esm/chunk-V42OFY7B.mjs +0 -85
  217. package/dist/lib/node-esm/chunk-V42OFY7B.mjs.map +0 -7
  218. package/dist/lib/node-esm/index.mjs +0 -96
  219. package/dist/lib/node-esm/index.mjs.map +0 -7
  220. package/dist/lib/node-esm/meta.json +0 -1
  221. package/dist/lib/node-esm/meta.mjs +0 -9
  222. package/dist/lib/node-esm/react-surface-7XILIUI4.mjs +0 -39
  223. package/dist/lib/node-esm/react-surface-7XILIUI4.mjs.map +0 -7
  224. package/dist/lib/node-esm/types/index.mjs +0 -11
  225. package/dist/types/src/capabilities/react-surface/index.d.ts +0 -3
  226. package/dist/types/src/capabilities/react-surface/index.d.ts.map +0 -1
  227. package/dist/types/src/capabilities/react-surface/react-surface.d.ts.map +0 -1
  228. package/dist/types/src/components/Graph/D3ForceGraph.d.ts +0 -14
  229. package/dist/types/src/components/Graph/D3ForceGraph.d.ts.map +0 -1
  230. package/dist/types/src/components/Graph/D3ForceGraph.stories.d.ts +0 -15
  231. package/dist/types/src/components/Graph/D3ForceGraph.stories.d.ts.map +0 -1
  232. package/dist/types/src/components/Graph/adapter.d.ts.map +0 -1
  233. package/dist/types/src/components/Graph/testing.d.ts +0 -14
  234. package/dist/types/src/components/Graph/testing.d.ts.map +0 -1
  235. package/dist/types/src/components/Tree/testing/generator.d.ts.map +0 -1
  236. package/dist/types/src/components/Tree/testing/index.d.ts +0 -2
  237. package/dist/types/src/components/Tree/testing/index.d.ts.map +0 -1
  238. package/dist/types/src/components/plot.d.ts.map +0 -1
  239. package/dist/types/src/containers/ExplorerContainer/ExplorerContainer.d.ts +0 -6
  240. package/dist/types/src/containers/ExplorerContainer/ExplorerContainer.d.ts.map +0 -1
  241. package/dist/types/src/containers/ExplorerContainer/index.d.ts +0 -3
  242. package/dist/types/src/containers/ExplorerContainer/index.d.ts.map +0 -1
  243. package/src/capabilities/react-surface/index.ts +0 -7
  244. package/src/capabilities/react-surface/react-surface.tsx +0 -31
  245. package/src/components/Graph/D3ForceGraph.stories.tsx +0 -84
  246. package/src/components/Graph/D3ForceGraph.tsx +0 -102
  247. package/src/components/Graph/testing.ts +0 -58
  248. package/src/components/Tree/layout/HierarchicalEdgeBundling.ts +0 -162
  249. package/src/components/Tree/layout/RadialTree.ts +0 -94
  250. package/src/components/Tree/layout/TidyTree.ts +0 -101
  251. package/src/components/Tree/testing/index.ts +0 -5
  252. package/src/containers/ExplorerContainer/ExplorerContainer.tsx +0 -53
  253. package/src/containers/ExplorerContainer/index.ts +0 -7
  254. /package/dist/lib/{browser/chunk-J5LGTIGS.mjs.map → neutral/ExplorerPlugin.mjs.map} +0 -0
  255. /package/dist/lib/{browser → neutral}/chunk-J5LGTIGS.mjs +0 -0
  256. /package/dist/lib/{browser/meta.mjs.map → neutral/chunk-J5LGTIGS.mjs.map} +0 -0
  257. /package/dist/lib/{browser/types → neutral}/index.mjs.map +0 -0
  258. /package/dist/lib/{node-esm → neutral}/meta.mjs.map +0 -0
  259. /package/dist/lib/{node-esm → neutral}/types/index.mjs.map +0 -0
  260. /package/dist/types/src/capabilities/{react-surface/react-surface.d.ts → react-surface.d.ts} +0 -0
  261. /package/src/components/Graph/{adapter.ts → graph-adapter.ts} +0 -0
@@ -0,0 +1,124 @@
1
+ //
2
+ // Copyright 2023 DXOS.org
3
+ //
4
+
5
+ import { forceLink, forceManyBody } from 'd3';
6
+ import NativeForceGraph from 'force-graph';
7
+ import React, {
8
+ type ComponentPropsWithoutRef,
9
+ type Ref,
10
+ RefObject,
11
+ useCallback,
12
+ useEffect,
13
+ useRef,
14
+ useState,
15
+ } from 'react';
16
+ import { useResizeDetector } from 'react-resize-detector';
17
+
18
+ import { composable, composableProps } from '@dxos/react-ui';
19
+ import { type SpaceGraphModel } from '@dxos/schema';
20
+
21
+ import { GraphAdapter } from './graph-adapter';
22
+
23
+ export type CanvasForceGraphProps = {
24
+ model?: SpaceGraphModel;
25
+ match?: RegExp;
26
+ };
27
+
28
+ /**
29
+ * More performance optimized version of the ForceGraph.
30
+ */
31
+ export const CanvasForceGraph = composable<HTMLDivElement, CanvasForceGraphProps>(
32
+ ({ model, match, onClick, ...props }, forwardedRef) => {
33
+ const { ref: resizeRef, width, height } = useResizeDetector({ refreshRate: 200 });
34
+ const setRef = useCallback(
35
+ (node: HTMLDivElement | null) => {
36
+ resizeRef(node);
37
+ assignRef(forwardedRef, node);
38
+ },
39
+ [resizeRef, forwardedRef],
40
+ );
41
+
42
+ const rootRef = useRef<HTMLDivElement>(null);
43
+ const forceGraph = useRef<NativeForceGraph>(null);
44
+
45
+ const [data, setData] = useState<GraphAdapter>();
46
+ useEffect(() => {
47
+ return model?.subscribe((model) => setData(new GraphAdapter(model.graph)));
48
+ }, [model]);
49
+
50
+ useEffect(() => {
51
+ if (rootRef.current) {
52
+ // https://github.com/vasturiano/force-graph
53
+ // https://github.com/vasturiano/3d-force-graph
54
+ forceGraph.current = new NativeForceGraph(rootRef.current)
55
+ // https://github.com/vasturiano/force-graph?tab=readme-ov-file#node-styling
56
+ .nodeRelSize(6)
57
+ .nodeLabel((node: any) => (node.type === 'schema' ? node.data.typename : (node.data.label ?? node.id)))
58
+ .nodeAutoColorBy((node: any) => (node.type === 'schema' ? 'schema' : node.data.typename))
59
+
60
+ // https://github.com/vasturiano/force-graph?tab=readme-ov-file#link-styling
61
+ .linkAutoColorBy((link: any) => link.type);
62
+ }
63
+
64
+ return () => {
65
+ forceGraph.current?.pauseAnimation().graphData({ nodes: [], links: [] });
66
+ forceGraph.current = null;
67
+ };
68
+ }, []);
69
+
70
+ useEffect(() => {
71
+ if (!data || !width || !height || !forceGraph.current) {
72
+ return;
73
+ }
74
+
75
+ // https://github.com/vasturiano/force-graph?tab=readme-ov-file#container-layout
76
+ forceGraph.current
77
+ .pauseAnimation()
78
+ .width(width)
79
+ .height(height)
80
+ .onEngineStop(() => handleZoomToFit())
81
+ .onNodeClick((node: any) => {
82
+ forceGraph.current?.emitParticle(node);
83
+ })
84
+
85
+ // https://github.com/vasturiano/force-graph?tab=readme-ov-file#force-engine-d3-force-configuration
86
+ // .d3Force('center', forceCenter().strength(0.9))
87
+ .d3Force('link', forceLink().distance(160).strength(0.5))
88
+ .d3Force('charge', forceManyBody().strength(-30))
89
+
90
+ .graphData(data)
91
+ .warmupTicks(100)
92
+ .cooldownTime(1_000)
93
+ .resumeAnimation();
94
+ }, [data, width, height]);
95
+
96
+ const handleZoomToFit = () => {
97
+ forceGraph.current?.zoomToFit(400, 40);
98
+ };
99
+
100
+ const handleClick = useCallback<NonNullable<ComponentPropsWithoutRef<'div'>['onClick']>>(
101
+ (event) => {
102
+ onClick?.(event);
103
+ if (!event.defaultPrevented) {
104
+ handleZoomToFit();
105
+ }
106
+ },
107
+ [onClick],
108
+ );
109
+
110
+ return (
111
+ <div {...composableProps(props, { classNames: 'relative grow' })} onClick={handleClick} ref={setRef}>
112
+ <div ref={rootRef} className='absolute inset-0' />
113
+ </div>
114
+ );
115
+ },
116
+ );
117
+
118
+ const assignRef = <T,>(ref: Ref<T> | undefined, value: T | null): void => {
119
+ if (typeof ref === 'function') {
120
+ ref(value);
121
+ } else if (ref) {
122
+ (ref as RefObject<T | null>).current = value;
123
+ }
124
+ };
@@ -3,72 +3,121 @@
3
3
  //
4
4
 
5
5
  import { type Meta, type StoryObj } from '@storybook/react-vite';
6
- import React, { useState } from 'react';
6
+ import * as Effect from 'effect/Effect';
7
+ import React, { useCallback, useMemo } from 'react';
7
8
 
8
- import { Type } from '@dxos/echo';
9
- import { View } from '@dxos/echo';
10
- import { faker } from '@dxos/random';
11
- import { useClient } from '@dxos/react-client';
12
- import { type Space } from '@dxos/react-client/echo';
13
- import { withClientProvider } from '@dxos/react-client/testing';
14
- import { useAsyncEffect } from '@dxos/react-ui';
15
- import { withLayout, withTheme } from '@dxos/react-ui/testing';
16
- import { ViewModel } from '@dxos/schema';
17
- import { type ValueGenerator } from '@dxos/schema/testing';
18
- import { withRegistry } from '@dxos/storybook-utils';
19
- import { render } from '@dxos/storybook-utils';
9
+ import { withPluginManager } from '@dxos/app-framework/testing';
10
+ import { Obj, Type, View } from '@dxos/echo';
11
+ import { SelectionModel } from '@dxos/graph';
12
+ import { ClientPlugin } from '@dxos/plugin-client/testing';
13
+ import { initializeIdentity } from '@dxos/plugin-client/testing';
14
+ import { PreviewPlugin } from '@dxos/plugin-preview/testing';
15
+ import { StorybookPlugin, corePlugins } from '@dxos/plugin-testing';
16
+ import { random } from '@dxos/random';
17
+ import { useSpaces } from '@dxos/react-client/echo';
18
+ import { DxAnchorActivate } from '@dxos/react-ui';
19
+ import { type GraphProps } from '@dxos/react-ui-graph';
20
+ import { Loading, withLayout, withTheme } from '@dxos/react-ui/testing';
21
+ import { type SpaceGraphEdge, type SpaceGraphNode, ViewModel } from '@dxos/schema';
22
+ import { type ValueGenerator, createObjectFactory, createRelationFactory } from '@dxos/schema/testing';
20
23
  import { HasRelationship, Organization, Person, Pipeline } from '@dxos/types';
21
24
 
22
- import { useGraphModel } from '../../hooks';
23
- import { Graph } from '../../types';
25
+ import { useGraphModel } from '#hooks';
26
+ import { Graph } from '#types';
24
27
 
25
28
  import { ForceGraph } from './ForceGraph';
26
- import { generate } from './testing';
27
29
 
28
- const generator = faker as any as ValueGenerator;
30
+ const generator = random as any as ValueGenerator;
29
31
 
30
- faker.seed(1);
32
+ random.seed(1);
31
33
 
32
34
  const DefaultStory = () => {
33
- const client = useClient();
34
- const [space, setSpace] = useState<Space>();
35
- const [graph, setGraph] = useState<Graph.Graph>();
35
+ const [space] = useSpaces();
36
+ const model = useGraphModel(space?.db);
36
37
 
37
- useAsyncEffect(async () => {
38
- const space = client.spaces.default;
39
- void generate(space, generator);
40
- const { view } = await ViewModel.makeFromDatabase({ db: space.db, typename: Type.getTypename(Graph.Graph) });
41
- const graph = Graph.make({ name: 'Test', view });
42
- space.db.add(graph);
43
- setSpace(space);
44
- setGraph(graph);
45
- }, [client]);
38
+ const selection = useMemo(() => new SelectionModel({ mode: 'single' }), []);
46
39
 
47
- const model = useGraphModel(space);
48
- if (!model || !space || !graph) {
49
- return null;
40
+ const handleInspect = useCallback<NonNullable<GraphProps<SpaceGraphNode, SpaceGraphEdge>['onInspect']>>(
41
+ (node, event) => {
42
+ // `null` node = pointerleave (no preview to open).
43
+ if (!node) {
44
+ return;
45
+ }
46
+ const obj = node.data?.data?.object;
47
+ if (!obj) {
48
+ return;
49
+ }
50
+ const uri = Obj.getURI(obj);
51
+ if (!uri) {
52
+ return;
53
+ }
54
+ const target = event.target as HTMLElement;
55
+ target.dispatchEvent(
56
+ new DxAnchorActivate({
57
+ dxn: uri,
58
+ label: Obj.getLabel(obj) ?? uri,
59
+ trigger: target,
60
+ kind: 'card',
61
+ }),
62
+ );
63
+ },
64
+ [],
65
+ );
66
+
67
+ if (!space || !model) {
68
+ return <Loading data={{ space: !!space, model: !!model }} />;
50
69
  }
51
70
 
52
- return <ForceGraph model={model} />;
71
+ return <ForceGraph model={model} selection={selection} onInspect={handleInspect} />;
53
72
  };
54
73
 
55
74
  const meta = {
56
75
  title: 'plugins/plugin-explorer/components/ForceGraph',
57
76
  component: ForceGraph,
58
- render: render(DefaultStory),
77
+ render: DefaultStory,
59
78
  decorators: [
60
- withRegistry,
61
79
  withTheme(),
62
- withLayout(),
63
- withClientProvider({
64
- createSpace: true,
65
- types: [
66
- Graph.Graph,
67
- View.View,
68
- HasRelationship.HasRelationship,
69
- Organization.Organization,
70
- Pipeline.Pipeline,
71
- Person.Person,
80
+ withLayout({ layout: 'fullscreen' }),
81
+ withPluginManager({
82
+ plugins: [
83
+ ...corePlugins(),
84
+ StorybookPlugin({}),
85
+ ClientPlugin({
86
+ types: [
87
+ Graph.Graph,
88
+ View.View,
89
+ HasRelationship.HasRelationship,
90
+ Organization.Organization,
91
+ Pipeline.Pipeline,
92
+ Person.Person,
93
+ ],
94
+ onClientInitialized: ({ client }) =>
95
+ Effect.gen(function* () {
96
+ const { personalSpace } = yield* initializeIdentity(client);
97
+ yield* Effect.promise(() =>
98
+ createObjectFactory(
99
+ personalSpace.db,
100
+ generator,
101
+ )([
102
+ { type: Organization.Organization, count: 20 },
103
+ { type: Person.Person, count: 30 },
104
+ { type: Pipeline.Pipeline, count: 10 },
105
+ ]),
106
+ );
107
+ yield* Effect.promise(() =>
108
+ createRelationFactory(
109
+ personalSpace.db,
110
+ generator,
111
+ )([{ type: HasRelationship.HasRelationship, count: 20, data: { kind: 'friend' } }]),
112
+ );
113
+ const { view } = yield* Effect.promise(() =>
114
+ ViewModel.makeFromDatabase({ db: personalSpace.db, typename: Type.getTypename(Graph.Graph) }),
115
+ );
116
+ personalSpace.db.add(Graph.make({ name: 'Test', view }));
117
+ yield* Effect.promise(() => personalSpace.db.flush({ indexes: true }));
118
+ }),
119
+ }),
120
+ PreviewPlugin(),
72
121
  ],
73
122
  }),
74
123
  ],
@@ -2,91 +2,111 @@
2
2
  // Copyright 2023 DXOS.org
3
3
  //
4
4
 
5
- import { forceLink, forceManyBody } from 'd3';
6
- import NativeForceGraph from 'force-graph';
7
- import React, { type FC, useEffect, useRef, useState } from 'react';
8
- import { useResizeDetector } from 'react-resize-detector';
9
-
10
- import { type SearchResult, filterObjectsSync } from '@dxos/plugin-search';
11
- import { type SpaceGraphModel } from '@dxos/schema';
12
-
13
- import { GraphAdapter } from './adapter';
5
+ import { Atom, useAtomValue } from '@effect-atom/atom-react';
6
+ import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
7
+
8
+ import { Obj } from '@dxos/echo';
9
+ import { SelectionModel } from '@dxos/graph';
10
+ import { composable, composableProps } from '@dxos/react-ui';
11
+ import {
12
+ type GraphController,
13
+ GraphForceProjector,
14
+ type GraphLayoutNode,
15
+ type GraphProps,
16
+ SVG,
17
+ type SVGContext,
18
+ } from '@dxos/react-ui-graph';
19
+ import { type SpaceGraphEdge, type SpaceGraphModel, type SpaceGraphNode } from '@dxos/schema';
20
+ import { getHashStyles } from '@dxos/ui-theme';
21
+ import '@dxos/react-ui-graph/styles/graph.css';
22
+
23
+ const EMPTY_ATOM = Atom.make<{ nodes: SpaceGraphNode[]; edges: SpaceGraphEdge[] }>({ nodes: [], edges: [] });
14
24
 
15
25
  export type ForceGraphProps = {
16
26
  model?: SpaceGraphModel;
17
- match?: RegExp;
18
- };
19
-
20
- export const ForceGraph: FC<ForceGraphProps> = ({ model, match }) => {
21
- const { ref, width, height } = useResizeDetector({ refreshRate: 200 });
22
- const rootRef = useRef<HTMLDivElement>(null);
23
- const forceGraph = useRef<NativeForceGraph>(null);
24
-
25
- const filteredRef = useRef<SearchResult[]>([]);
26
- filteredRef.current = filterObjectsSync(model?.objects ?? [], match);
27
-
28
- const [data, setData] = useState<GraphAdapter>();
29
- useEffect(() => {
30
- return model?.subscribe((model) => {
31
- setData(new GraphAdapter(model.graph));
32
- });
33
- }, [model]);
34
-
35
- useEffect(() => {
36
- if (rootRef.current) {
37
- // https://github.com/vasturiano/force-graph
38
- // https://github.com/vasturiano/3d-force-graph
39
- forceGraph.current = new NativeForceGraph(rootRef.current)
40
- // https://github.com/vasturiano/force-graph?tab=readme-ov-file#node-styling
41
- .nodeRelSize(6)
42
- .nodeLabel((node: any) => (node.type === 'schema' ? node.data.typename : (node.data.label ?? node.id)))
43
- .nodeAutoColorBy((node: any) => (node.type === 'schema' ? 'schema' : node.data.typename))
44
-
45
- // https://github.com/vasturiano/force-graph?tab=readme-ov-file#link-styling
46
- .linkAutoColorBy((link: any) => link.type);
47
- }
48
-
49
- return () => {
50
- forceGraph.current?.pauseAnimation().graphData({ nodes: [], links: [] });
51
- forceGraph.current = null;
52
- };
53
- }, []);
54
-
55
- useEffect(() => {
56
- if (!data || !width || !height || !forceGraph.current) {
57
- return;
58
- }
59
-
60
- // https://github.com/vasturiano/force-graph?tab=readme-ov-file#container-layout
61
- forceGraph.current
62
- .pauseAnimation()
63
- .width(width)
64
- .height(height)
65
- .onEngineStop(() => {
66
- handleZoomToFit();
67
- })
68
- .onNodeClick((node: any) => {
69
- forceGraph.current?.emitParticle(node);
70
- })
71
-
72
- // https://github.com/vasturiano/force-graph?tab=readme-ov-file#force-engine-d3-force-configuration
73
- // .d3Force('center', forceCenter().strength(0.9))
74
- .d3Force('link', forceLink().distance(160).strength(0.5))
75
- .d3Force('charge', forceManyBody().strength(-30))
76
-
77
- .graphData(data)
78
- .warmupTicks(100)
79
- .cooldownTime(1_000)
80
- .resumeAnimation();
81
- }, [data, width, height, forceGraph.current]);
82
-
83
- const handleZoomToFit = () => {
84
- forceGraph.current?.zoomToFit(400, 40);
85
- };
86
-
87
- return (
88
- <div ref={ref} className='relative grow' onClick={handleZoomToFit}>
89
- <div ref={rootRef} className='absolute inset-0' />
90
- </div>
91
- );
92
- };
27
+ grid?: boolean;
28
+ selection?: SelectionModel;
29
+ onInspect?: GraphProps<SpaceGraphNode, SpaceGraphEdge>['onInspect'];
30
+ } & Pick<GraphProps, 'drag'>;
31
+
32
+ export const ForceGraph = composable<HTMLDivElement, ForceGraphProps>(
33
+ ({ model, selection: selectionProp, grid, drag, onInspect, ...props }, forwardedRef) => {
34
+ // TODO(wittjosiah): This should go into Graph.tsx but for some reason doesn't work.
35
+ useAtomValue(model?.graphAtom ?? EMPTY_ATOM);
36
+
37
+ const graph = useRef<GraphController>(null);
38
+ const selection = useMemo(() => selectionProp ?? new SelectionModel(), [selectionProp]);
39
+ useEffect(() => {
40
+ const unsubscribe = selection.subscribe(() => graph.current?.repaint());
41
+ return unsubscribe;
42
+ }, [selection]);
43
+
44
+ const svgRef = useRef<SVGContext>(null);
45
+ const [projector, setProjector] = useState<GraphForceProjector>();
46
+ useEffect(() => {
47
+ if (svgRef.current) {
48
+ setProjector(
49
+ new GraphForceProjector(svgRef.current, {
50
+ attributes: {
51
+ // TODO(burdon): Check type (currently assumes Employee property).
52
+ // Edge shouldn't contribute to force if it's not active.
53
+ linkForce: (edge) => edge.data?.object?.active !== false,
54
+ },
55
+ forces: {
56
+ point: {
57
+ strength: 0.01,
58
+ },
59
+ },
60
+ }),
61
+ );
62
+ }
63
+ // SVG.Graph owns projector start/stop; nothing to clean up here.
64
+ }, []);
65
+
66
+ const handleSelect = useCallback<NonNullable<GraphProps['onSelect']>>(
67
+ (node) => {
68
+ if (selection.contains(node.id)) {
69
+ selection.remove(node.id);
70
+ } else {
71
+ selection.add(node.id);
72
+ }
73
+ },
74
+ [selection],
75
+ );
76
+
77
+ return (
78
+ <div {...composableProps(props, { classNames: 'dx-container' })} ref={forwardedRef}>
79
+ <SVG.Root ref={svgRef}>
80
+ <SVG.Markers />
81
+ {grid && <SVG.Grid axis />}
82
+ <SVG.Zoom extent={[1 / 2, 2]}>
83
+ <SVG.Graph<SpaceGraphNode, SpaceGraphEdge>
84
+ ref={graph}
85
+ drag={drag}
86
+ model={model}
87
+ projector={projector}
88
+ labels={{
89
+ text: (node) => node.data?.data.label ?? node.id,
90
+ }}
91
+ attributes={{
92
+ node: (node: GraphLayoutNode<SpaceGraphNode>) => {
93
+ const obj = node.data?.data.object;
94
+ return {
95
+ data: {
96
+ color: getHashStyles(obj && Obj.getTypename(obj))?.hue,
97
+ },
98
+ classes: {
99
+ 'dx-selected': selection.contains(node.id),
100
+ },
101
+ };
102
+ },
103
+ }}
104
+ onSelect={handleSelect}
105
+ onInspect={onInspect}
106
+ />
107
+ </SVG.Zoom>
108
+ </SVG.Root>
109
+ </div>
110
+ );
111
+ },
112
+ );
@@ -2,5 +2,5 @@
2
2
  // Copyright 2023 DXOS.org
3
3
  //
4
4
 
5
- export * from './D3ForceGraph';
5
+ export * from './CanvasForceGraph';
6
6
  export * from './ForceGraph';
@@ -0,0 +1,104 @@
1
+ //
2
+ // Copyright 2026 DXOS.org
3
+ //
4
+
5
+ import { Atom, useAtomValue } from '@effect-atom/atom-react';
6
+ import { type Meta, type StoryObj } from '@storybook/react-vite';
7
+ import * as Effect from 'effect/Effect';
8
+ import React, { useMemo } from 'react';
9
+
10
+ import { withPluginManager } from '@dxos/app-framework/testing';
11
+ import { Type, View } from '@dxos/echo';
12
+ import { ClientPlugin, initializeIdentity } from '@dxos/plugin-client/testing';
13
+ import { PreviewPlugin } from '@dxos/plugin-preview/testing';
14
+ import { StorybookPlugin, corePlugins } from '@dxos/plugin-testing';
15
+ import { random } from '@dxos/random';
16
+ import { useSpaces } from '@dxos/react-client/echo';
17
+ import { Loading, withLayout, withTheme } from '@dxos/react-ui/testing';
18
+ import { type SpaceGraphNode, ViewModel } from '@dxos/schema';
19
+ import { type ValueGenerator, createObjectFactory, createRelationFactory } from '@dxos/schema/testing';
20
+ import { HasRelationship, Organization, Person, Pipeline } from '@dxos/types';
21
+
22
+ import { useGraphModel } from '#hooks';
23
+ import { Graph } from '#types';
24
+
25
+ import { Lattice } from './Lattice';
26
+
27
+ const generator = random as any as ValueGenerator;
28
+
29
+ random.seed(7);
30
+
31
+ const EMPTY_ATOM = Atom.make<{ nodes: SpaceGraphNode[] }>({ nodes: [] });
32
+
33
+ const DefaultStory = () => {
34
+ const [space] = useSpaces();
35
+ const model = useGraphModel(space?.db);
36
+ const graphSnapshot = useAtomValue((model?.graphAtom ?? EMPTY_ATOM) as typeof EMPTY_ATOM);
37
+ const nodes = useMemo(() => graphSnapshot.nodes.filter((node) => node.type === 'object'), [graphSnapshot]);
38
+
39
+ if (!space || !model) {
40
+ return <Loading data={{ space: !!space, model: !!model }} />;
41
+ }
42
+
43
+ return <Lattice nodes={nodes} />;
44
+ };
45
+
46
+ const meta: Meta<typeof DefaultStory> = {
47
+ title: 'plugins/plugin-explorer/components/Lattice',
48
+ render: DefaultStory,
49
+ decorators: [
50
+ withTheme(),
51
+ withLayout({ layout: 'fullscreen' }),
52
+ withPluginManager({
53
+ plugins: [
54
+ ...corePlugins(),
55
+ StorybookPlugin({}),
56
+ ClientPlugin({
57
+ types: [
58
+ Graph.Graph,
59
+ View.View,
60
+ HasRelationship.HasRelationship,
61
+ Organization.Organization,
62
+ Pipeline.Pipeline,
63
+ Person.Person,
64
+ ],
65
+ onClientInitialized: ({ client }) =>
66
+ Effect.gen(function* () {
67
+ const { personalSpace } = yield* initializeIdentity(client);
68
+ yield* Effect.promise(() =>
69
+ createObjectFactory(
70
+ personalSpace.db,
71
+ generator,
72
+ )([
73
+ { type: Organization.Organization, count: 20 },
74
+ { type: Person.Person, count: 30 },
75
+ { type: Pipeline.Pipeline, count: 10 },
76
+ ]),
77
+ );
78
+ yield* Effect.promise(() =>
79
+ createRelationFactory(
80
+ personalSpace.db,
81
+ generator,
82
+ )([{ type: HasRelationship.HasRelationship, count: 20, data: { kind: 'friend' } }]),
83
+ );
84
+ const { view } = yield* Effect.promise(() =>
85
+ ViewModel.makeFromDatabase({ db: personalSpace.db, typename: Type.getTypename(Graph.Graph) }),
86
+ );
87
+ personalSpace.db.add(Graph.make({ name: 'Test', view }));
88
+ yield* Effect.promise(() => personalSpace.db.flush({ indexes: true }));
89
+ }),
90
+ }),
91
+ PreviewPlugin(),
92
+ ],
93
+ }),
94
+ ],
95
+ parameters: {
96
+ layout: 'fullscreen',
97
+ },
98
+ };
99
+
100
+ export default meta;
101
+
102
+ type Story = StoryObj<typeof DefaultStory>;
103
+
104
+ export const Default: Story = {};