@dxos/plugin-explorer 0.8.3 → 0.8.4-main.1c7ec43d41

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 (201) hide show
  1. package/dist/lib/browser/chunk-HPIS2WXY.mjs +24 -0
  2. package/dist/lib/browser/chunk-HPIS2WXY.mjs.map +7 -0
  3. package/dist/lib/browser/chunk-J5LGTIGS.mjs +10 -0
  4. package/dist/lib/browser/chunk-J5LGTIGS.mjs.map +7 -0
  5. package/dist/lib/browser/{chunk-JRKQNHS6.mjs → components/index.mjs} +357 -412
  6. package/dist/lib/{node-esm/chunk-IUFYOE44.mjs.map → browser/components/index.mjs.map} +4 -4
  7. package/dist/lib/browser/hooks/index.mjs +40 -0
  8. package/dist/lib/browser/hooks/index.mjs.map +7 -0
  9. package/dist/lib/browser/index.mjs +6 -104
  10. package/dist/lib/browser/index.mjs.map +4 -4
  11. package/dist/lib/browser/meta.json +1 -1
  12. package/dist/lib/browser/meta.mjs +2 -3
  13. package/dist/lib/browser/types/index.mjs +68 -6
  14. package/dist/lib/browser/types/index.mjs.map +4 -4
  15. package/dist/lib/node-esm/{chunk-3CMBLK6W.mjs → chunk-6EUBRHHX.mjs} +9 -6
  16. package/dist/lib/node-esm/chunk-6EUBRHHX.mjs.map +7 -0
  17. package/dist/lib/node-esm/chunk-HSLMI22Q.mjs +11 -0
  18. package/dist/lib/node-esm/chunk-HSLMI22Q.mjs.map +7 -0
  19. package/dist/lib/node-esm/{chunk-IUFYOE44.mjs → components/index.mjs} +356 -412
  20. package/dist/lib/{browser/chunk-JRKQNHS6.mjs.map → node-esm/components/index.mjs.map} +4 -4
  21. package/dist/lib/node-esm/hooks/index.mjs +41 -0
  22. package/dist/lib/node-esm/hooks/index.mjs.map +7 -0
  23. package/dist/lib/node-esm/index.mjs +6 -104
  24. package/dist/lib/node-esm/index.mjs.map +4 -4
  25. package/dist/lib/node-esm/meta.json +1 -1
  26. package/dist/lib/node-esm/meta.mjs +2 -3
  27. package/dist/lib/node-esm/types/index.mjs +68 -6
  28. package/dist/lib/node-esm/types/index.mjs.map +4 -4
  29. package/dist/types/data/cities.d.ts +4 -4
  30. package/dist/types/data/cities.d.ts.map +1 -1
  31. package/dist/types/data/countries-110m.d.ts +19 -22
  32. package/dist/types/data/countries-110m.d.ts.map +1 -1
  33. package/dist/types/src/ExplorerPlugin.d.ts +3 -1
  34. package/dist/types/src/ExplorerPlugin.d.ts.map +1 -1
  35. package/dist/types/src/ExplorerPlugin.test.d.ts +2 -0
  36. package/dist/types/src/ExplorerPlugin.test.d.ts.map +1 -0
  37. package/dist/types/src/capabilities/create-object.d.ts +11 -0
  38. package/dist/types/src/capabilities/create-object.d.ts.map +1 -0
  39. package/dist/types/src/capabilities/index.d.ts +8 -2
  40. package/dist/types/src/capabilities/index.d.ts.map +1 -1
  41. package/dist/types/src/capabilities/react-surface.d.ts +3 -2
  42. package/dist/types/src/capabilities/react-surface.d.ts.map +1 -1
  43. package/dist/types/src/components/Chart/Chart.d.ts.map +1 -1
  44. package/dist/types/src/components/Chart/Chart.stories.d.ts +12 -5
  45. package/dist/types/src/components/Chart/Chart.stories.d.ts.map +1 -1
  46. package/dist/types/src/components/Globe/Globe.d.ts.map +1 -1
  47. package/dist/types/src/components/Globe/Globe.stories.d.ts +12 -5
  48. package/dist/types/src/components/Globe/Globe.stories.d.ts.map +1 -1
  49. package/dist/types/src/components/Graph/CanvasForceGraph.d.ts +13 -0
  50. package/dist/types/src/components/Graph/CanvasForceGraph.d.ts.map +1 -0
  51. package/dist/types/src/components/Graph/CanvasForceGraph.stories.d.ts +17 -0
  52. package/dist/types/src/components/Graph/CanvasForceGraph.stories.d.ts.map +1 -0
  53. package/dist/types/src/components/Graph/ForceGraph.d.ts +12 -5
  54. package/dist/types/src/components/Graph/ForceGraph.d.ts.map +1 -1
  55. package/dist/types/src/components/Graph/ForceGraph.stories.d.ts +15 -4
  56. package/dist/types/src/components/Graph/ForceGraph.stories.d.ts.map +1 -1
  57. package/dist/types/src/components/Graph/{adapter.d.ts → graph-adapter.d.ts} +2 -2
  58. package/dist/types/src/components/Graph/graph-adapter.d.ts.map +1 -0
  59. package/dist/types/src/components/Graph/index.d.ts +1 -1
  60. package/dist/types/src/components/Graph/index.d.ts.map +1 -1
  61. package/dist/types/src/components/Graph/testing.d.ts +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 +16 -15
  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 +2 -2
  84. package/dist/types/src/hooks/useGraphModel.d.ts.map +1 -1
  85. package/dist/types/src/index.d.ts +2 -3
  86. package/dist/types/src/index.d.ts.map +1 -1
  87. package/dist/types/src/meta.d.ts +2 -3
  88. package/dist/types/src/meta.d.ts.map +1 -1
  89. package/dist/types/src/translations.d.ts +36 -22
  90. package/dist/types/src/translations.d.ts.map +1 -1
  91. package/dist/types/src/types/ExplorerAction.d.ts +6 -0
  92. package/dist/types/src/types/ExplorerAction.d.ts.map +1 -0
  93. package/dist/types/src/types/Graph.d.ts +23 -0
  94. package/dist/types/src/types/Graph.d.ts.map +1 -0
  95. package/dist/types/src/types/index.d.ts +2 -2
  96. package/dist/types/src/types/index.d.ts.map +1 -1
  97. package/dist/types/tsconfig.tsbuildinfo +1 -1
  98. package/package.json +88 -51
  99. package/src/ExplorerPlugin.test.ts +26 -0
  100. package/src/ExplorerPlugin.tsx +15 -54
  101. package/src/capabilities/create-object.ts +36 -0
  102. package/src/capabilities/index.ts +3 -3
  103. package/src/capabilities/react-surface.tsx +24 -15
  104. package/src/components/Chart/Chart.stories.tsx +22 -27
  105. package/src/components/Chart/Chart.tsx +1 -1
  106. package/src/components/Globe/Globe.stories.tsx +25 -26
  107. package/src/components/Globe/Globe.tsx +1 -1
  108. package/src/components/Graph/CanvasForceGraph.stories.tsx +83 -0
  109. package/src/components/Graph/CanvasForceGraph.tsx +124 -0
  110. package/src/components/Graph/ForceGraph.stories.tsx +90 -39
  111. package/src/components/Graph/ForceGraph.tsx +104 -85
  112. package/src/components/Graph/{adapter.ts → graph-adapter.ts} +14 -8
  113. package/src/components/Graph/index.ts +1 -1
  114. package/src/components/Graph/testing.ts +13 -10
  115. package/src/components/Tree/Tree.stories.tsx +57 -43
  116. package/src/components/Tree/Tree.tsx +11 -6
  117. package/src/components/Tree/testing/generator.ts +4 -2
  118. package/src/components/Tree/types/tree.test.ts +9 -7
  119. package/src/components/Tree/types/tree.ts +42 -21
  120. package/src/components/Tree/types/types.ts +1 -1
  121. package/src/components/index.ts +0 -4
  122. package/src/containers/ExplorerContainer/ExplorerContainer.tsx +51 -0
  123. package/src/containers/ExplorerContainer/index.ts +5 -0
  124. package/src/containers/index.ts +7 -0
  125. package/src/hooks/useGraphModel.ts +19 -11
  126. package/src/index.ts +5 -3
  127. package/src/meta.ts +9 -6
  128. package/src/translations.ts +20 -13
  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-DXL34I3F.mjs +0 -37
  134. package/dist/lib/browser/ExplorerContainer-DXL34I3F.mjs.map +0 -7
  135. package/dist/lib/browser/chunk-73YTQHOT.mjs +0 -38
  136. package/dist/lib/browser/chunk-73YTQHOT.mjs.map +0 -7
  137. package/dist/lib/browser/chunk-OBAFAA5V.mjs +0 -21
  138. package/dist/lib/browser/chunk-OBAFAA5V.mjs.map +0 -7
  139. package/dist/lib/browser/chunk-SLB2F5AO.mjs +0 -30
  140. package/dist/lib/browser/chunk-SLB2F5AO.mjs.map +0 -7
  141. package/dist/lib/browser/chunk-Z5BGAHLD.mjs +0 -187
  142. package/dist/lib/browser/chunk-Z5BGAHLD.mjs.map +0 -7
  143. package/dist/lib/browser/intent-resolver-JZKYVFQJ.mjs +0 -24
  144. package/dist/lib/browser/intent-resolver-JZKYVFQJ.mjs.map +0 -7
  145. package/dist/lib/browser/react-surface-IAEP2GBT.mjs +0 -31
  146. package/dist/lib/browser/react-surface-IAEP2GBT.mjs.map +0 -7
  147. package/dist/lib/node/ExplorerContainer-VUXH55VV.cjs +0 -61
  148. package/dist/lib/node/ExplorerContainer-VUXH55VV.cjs.map +0 -7
  149. package/dist/lib/node/chunk-4T4LCT5R.cjs +0 -52
  150. package/dist/lib/node/chunk-4T4LCT5R.cjs.map +0 -7
  151. package/dist/lib/node/chunk-BCDVG2CH.cjs +0 -44
  152. package/dist/lib/node/chunk-BCDVG2CH.cjs.map +0 -7
  153. package/dist/lib/node/chunk-MLRYW4WQ.cjs +0 -56
  154. package/dist/lib/node/chunk-MLRYW4WQ.cjs.map +0 -7
  155. package/dist/lib/node/chunk-SVU4VMYX.cjs +0 -11339
  156. package/dist/lib/node/chunk-SVU4VMYX.cjs.map +0 -7
  157. package/dist/lib/node/chunk-TY543HPV.cjs +0 -214
  158. package/dist/lib/node/chunk-TY543HPV.cjs.map +0 -7
  159. package/dist/lib/node/index.cjs +0 -130
  160. package/dist/lib/node/index.cjs.map +0 -7
  161. package/dist/lib/node/intent-resolver-G2MFNIXA.cjs +0 -39
  162. package/dist/lib/node/intent-resolver-G2MFNIXA.cjs.map +0 -7
  163. package/dist/lib/node/meta.cjs +0 -31
  164. package/dist/lib/node/meta.cjs.map +0 -7
  165. package/dist/lib/node/meta.json +0 -1
  166. package/dist/lib/node/react-surface-UJD5RGRZ.cjs +0 -53
  167. package/dist/lib/node/react-surface-UJD5RGRZ.cjs.map +0 -7
  168. package/dist/lib/node/types/index.cjs +0 -32
  169. package/dist/lib/node/types/index.cjs.map +0 -7
  170. package/dist/lib/node-esm/ExplorerContainer-MFE7PXF4.mjs +0 -38
  171. package/dist/lib/node-esm/ExplorerContainer-MFE7PXF4.mjs.map +0 -7
  172. package/dist/lib/node-esm/chunk-3CMBLK6W.mjs.map +0 -7
  173. package/dist/lib/node-esm/chunk-AE7VHUJM.mjs +0 -189
  174. package/dist/lib/node-esm/chunk-AE7VHUJM.mjs.map +0 -7
  175. package/dist/lib/node-esm/chunk-N6VEANUZ.mjs +0 -39
  176. package/dist/lib/node-esm/chunk-N6VEANUZ.mjs.map +0 -7
  177. package/dist/lib/node-esm/chunk-VSORIAHH.mjs +0 -32
  178. package/dist/lib/node-esm/chunk-VSORIAHH.mjs.map +0 -7
  179. package/dist/lib/node-esm/intent-resolver-7G6ZKM6E.mjs +0 -25
  180. package/dist/lib/node-esm/intent-resolver-7G6ZKM6E.mjs.map +0 -7
  181. package/dist/lib/node-esm/react-surface-XBH3WZDL.mjs +0 -32
  182. package/dist/lib/node-esm/react-surface-XBH3WZDL.mjs.map +0 -7
  183. package/dist/types/src/capabilities/intent-resolver.d.ts +0 -4
  184. package/dist/types/src/capabilities/intent-resolver.d.ts.map +0 -1
  185. package/dist/types/src/components/ExplorerContainer.d.ts +0 -9
  186. package/dist/types/src/components/ExplorerContainer.d.ts.map +0 -1
  187. package/dist/types/src/components/Graph/D3ForceGraph.d.ts +0 -14
  188. package/dist/types/src/components/Graph/D3ForceGraph.d.ts.map +0 -1
  189. package/dist/types/src/components/Graph/D3ForceGraph.stories.d.ts +0 -6
  190. package/dist/types/src/components/Graph/D3ForceGraph.stories.d.ts.map +0 -1
  191. package/dist/types/src/components/Graph/adapter.d.ts.map +0 -1
  192. package/dist/types/src/types/schema.d.ts +0 -12
  193. package/dist/types/src/types/schema.d.ts.map +0 -1
  194. package/dist/types/src/types/types.d.ts +0 -18
  195. package/dist/types/src/types/types.d.ts.map +0 -1
  196. package/src/capabilities/intent-resolver.ts +0 -19
  197. package/src/components/ExplorerContainer.tsx +0 -36
  198. package/src/components/Graph/D3ForceGraph.stories.tsx +0 -64
  199. package/src/components/Graph/D3ForceGraph.tsx +0 -101
  200. package/src/types/schema.ts +0 -16
  201. package/src/types/types.ts +0 -21
@@ -1,17 +1,17 @@
1
1
  import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
2
+ import "../chunk-HSLMI22Q.mjs";
2
3
 
3
- // packages/plugins/plugin-explorer/src/components/Chart/Chart.tsx
4
- import { useSignals as _useSignals } from "@preact-signals/safe-react/tracking";
4
+ // src/components/Chart/Chart.tsx
5
5
  import * as Plot from "@observablehq/plot";
6
6
  import React, { useEffect } from "react";
7
7
  import { useResizeDetector } from "react-resize-detector";
8
8
 
9
- // packages/plugins/plugin-explorer/src/components/plot.ts
9
+ // src/components/plot.ts
10
10
  var createAdapter = (prop, accessor) => accessor ? {
11
11
  transform: (values) => values.map((value) => accessor(value)[prop])
12
12
  } : prop;
13
13
 
14
- // packages/plugins/plugin-explorer/src/components/Chart/Chart.tsx
14
+ // src/components/Chart/Chart.tsx
15
15
  var defaultOptions = {
16
16
  r: 4,
17
17
  stroke: "gray",
@@ -19,55 +19,49 @@ var defaultOptions = {
19
19
  fillOpacity: 0.2
20
20
  };
21
21
  var Chart = ({ items = [], accessor, options = defaultOptions }) => {
22
- var _effect = _useSignals();
23
- try {
24
- const { ref: containerRef, width = 0, height = 0 } = useResizeDetector({
25
- refreshRate: 200
26
- });
27
- useEffect(() => {
28
- if (!width || !height) {
29
- return;
30
- }
31
- const plot3 = Plot.plot({
32
- grid: true,
33
- width,
34
- height,
35
- style: {
36
- background: "transparent"
37
- },
38
- marks: [
39
- Plot.frame(),
40
- Plot.dot(items, {
41
- x: createAdapter("x", accessor),
42
- y: createAdapter("y", accessor),
43
- ...options
44
- })
45
- ]
46
- });
47
- containerRef.current.append(plot3);
48
- return () => plot3?.remove();
49
- }, [
50
- items,
22
+ const { ref: containerRef, width = 0, height = 0 } = useResizeDetector({
23
+ refreshRate: 200
24
+ });
25
+ useEffect(() => {
26
+ if (!width || !height) {
27
+ return;
28
+ }
29
+ const plot3 = Plot.plot({
30
+ grid: true,
51
31
  width,
52
- height
53
- ]);
54
- return /* @__PURE__ */ React.createElement("div", {
55
- ref: containerRef,
56
- className: "grow"
32
+ height,
33
+ style: {
34
+ background: "transparent"
35
+ },
36
+ marks: [
37
+ Plot.frame(),
38
+ Plot.dot(items, {
39
+ x: createAdapter("x", accessor),
40
+ y: createAdapter("y", accessor),
41
+ ...options
42
+ })
43
+ ]
57
44
  });
58
- } finally {
59
- _effect.f();
60
- }
45
+ containerRef.current.append(plot3);
46
+ return () => plot3?.remove();
47
+ }, [
48
+ items,
49
+ width,
50
+ height
51
+ ]);
52
+ return /* @__PURE__ */ React.createElement("div", {
53
+ ref: containerRef,
54
+ className: "grow"
55
+ });
61
56
  };
62
57
 
63
- // packages/plugins/plugin-explorer/src/components/Globe/Globe.tsx
64
- import { useSignals as _useSignals2 } from "@preact-signals/safe-react/tracking";
58
+ // src/components/Globe/Globe.tsx
65
59
  import * as Plot2 from "@observablehq/plot";
66
60
  import React2, { useEffect as useEffect2 } from "react";
67
61
  import { useResizeDetector as useResizeDetector2 } from "react-resize-detector";
68
62
  import * as topojson from "topojson-client";
69
63
 
70
- // packages/plugins/plugin-explorer/data/countries-110m.js
64
+ // data/countries-110m.js
71
65
  var countries_110m_default = {
72
66
  type: "Topology",
73
67
  objects: {
@@ -10769,79 +10763,274 @@ var countries_110m_default = {
10769
10763
  }
10770
10764
  };
10771
10765
 
10772
- // packages/plugins/plugin-explorer/src/components/Globe/Globe.tsx
10766
+ // src/components/Globe/Globe.tsx
10773
10767
  var defaultOptions2 = {
10774
10768
  r: 4,
10775
10769
  fill: "#003300"
10776
10770
  };
10777
10771
  var Globe = ({ items = [], accessor, projection = "orthographic", options = defaultOptions2 }) => {
10778
- var _effect = _useSignals2();
10779
- try {
10780
- const { ref: containerRef, width = 0, height = 0 } = useResizeDetector2({
10781
- refreshRate: 200
10782
- });
10783
- const land = topojson.feature(countries_110m_default, countries_110m_default.objects.land);
10784
- useEffect2(() => {
10785
- if (!width || !height) {
10786
- return;
10787
- }
10788
- const plot3 = Plot2.plot({
10789
- // https://observablehq.com/plot/features/projections
10790
- projection: {
10791
- type: projection,
10792
- rotate: [
10793
- -100,
10794
- -20
10795
- ]
10796
- },
10797
- // projection: { type: 'equirectangular', rotate: [-140, -30] },
10798
- width,
10799
- height,
10800
- style: {
10801
- background: "transparent"
10802
- },
10803
- // TODO(burdon): Create simple wrapper for Plot with good defaults.
10804
- marks: [
10805
- Plot2.sphere({
10806
- fill: "lightblue",
10807
- fillOpacity: 0.5
10808
- }),
10809
- Plot2.geo(land, {
10810
- fill: "darkgreen",
10811
- fillOpacity: 0.5
10812
- }),
10813
- Plot2.graticule(),
10814
- Plot2.dot(items, {
10815
- x: createAdapter("lat", accessor),
10816
- y: createAdapter("lng", accessor),
10817
- ...options
10818
- })
10772
+ const { ref: containerRef, width = 0, height = 0 } = useResizeDetector2({
10773
+ refreshRate: 200
10774
+ });
10775
+ const land = topojson.feature(countries_110m_default, countries_110m_default.objects.land);
10776
+ useEffect2(() => {
10777
+ if (!width || !height) {
10778
+ return;
10779
+ }
10780
+ const plot3 = Plot2.plot({
10781
+ // https://observablehq.com/plot/features/projections
10782
+ projection: {
10783
+ type: projection,
10784
+ rotate: [
10785
+ -100,
10786
+ -20
10819
10787
  ]
10820
- });
10821
- containerRef.current.append(plot3);
10822
- return () => plot3?.remove();
10823
- }, [
10824
- items,
10788
+ },
10789
+ // projection: { type: 'equirectangular', rotate: [-140, -30] },
10825
10790
  width,
10826
- height
10827
- ]);
10828
- return /* @__PURE__ */ React2.createElement("div", {
10829
- ref: containerRef,
10830
- className: "grow p-4"
10791
+ height,
10792
+ style: {
10793
+ background: "transparent"
10794
+ },
10795
+ // TODO(burdon): Create simple wrapper for Plot with good defaults.
10796
+ marks: [
10797
+ Plot2.sphere({
10798
+ fill: "lightblue",
10799
+ fillOpacity: 0.5
10800
+ }),
10801
+ Plot2.geo(land, {
10802
+ fill: "darkgreen",
10803
+ fillOpacity: 0.5
10804
+ }),
10805
+ Plot2.graticule(),
10806
+ Plot2.dot(items, {
10807
+ x: createAdapter("lat", accessor),
10808
+ y: createAdapter("lng", accessor),
10809
+ ...options
10810
+ })
10811
+ ]
10831
10812
  });
10832
- } finally {
10833
- _effect.f();
10813
+ containerRef.current.append(plot3);
10814
+ return () => plot3?.remove();
10815
+ }, [
10816
+ items,
10817
+ width,
10818
+ height
10819
+ ]);
10820
+ return /* @__PURE__ */ React2.createElement("div", {
10821
+ ref: containerRef,
10822
+ className: "grow p-4"
10823
+ });
10824
+ };
10825
+
10826
+ // src/components/Graph/CanvasForceGraph.tsx
10827
+ import { forceLink, forceManyBody } from "d3";
10828
+ import NativeForceGraph from "force-graph";
10829
+ import React3, { useCallback, useEffect as useEffect3, useRef, useState } from "react";
10830
+ import { useResizeDetector as useResizeDetector3 } from "react-resize-detector";
10831
+ import { composable, composableProps } from "@dxos/ui-theme";
10832
+
10833
+ // src/components/Graph/graph-adapter.ts
10834
+ var GraphAdapter = class {
10835
+ graph;
10836
+ _nodes = [];
10837
+ _links = [];
10838
+ constructor(graph) {
10839
+ this.graph = graph;
10840
+ this._nodes = graph.nodes.map((node) => ({
10841
+ id: node.id,
10842
+ type: node.type,
10843
+ data: node.data
10844
+ }));
10845
+ const nodeIds = new Set(this._nodes.map((node) => node.id));
10846
+ this._links = graph.edges.filter((edge) => nodeIds.has(edge.source) && nodeIds.has(edge.target)).map((edge) => ({
10847
+ type: edge.type,
10848
+ source: edge.source,
10849
+ target: edge.target,
10850
+ data: edge.data
10851
+ }));
10852
+ }
10853
+ get nodes() {
10854
+ return this._nodes;
10855
+ }
10856
+ get links() {
10857
+ return this._links;
10834
10858
  }
10835
10859
  };
10836
10860
 
10837
- // packages/plugins/plugin-explorer/src/components/Tree/Tree.tsx
10838
- import { useSignals as _useSignals3 } from "@preact-signals/safe-react/tracking";
10839
- import React3, { useEffect as useEffect3, useRef, useState } from "react";
10861
+ // src/components/Graph/CanvasForceGraph.tsx
10862
+ var CanvasForceGraph = composable(({ model, match, onClick, ...props }, forwardedRef) => {
10863
+ const { ref: resizeRef, width, height } = useResizeDetector3({
10864
+ refreshRate: 200
10865
+ });
10866
+ const setRef = useCallback((node) => {
10867
+ resizeRef(node);
10868
+ assignRef(forwardedRef, node);
10869
+ }, [
10870
+ resizeRef,
10871
+ forwardedRef
10872
+ ]);
10873
+ const rootRef = useRef(null);
10874
+ const forceGraph = useRef(null);
10875
+ const [data, setData] = useState();
10876
+ useEffect3(() => {
10877
+ return model?.subscribe((model2) => setData(new GraphAdapter(model2.graph)));
10878
+ }, [
10879
+ model
10880
+ ]);
10881
+ useEffect3(() => {
10882
+ if (rootRef.current) {
10883
+ forceGraph.current = new NativeForceGraph(rootRef.current).nodeRelSize(6).nodeLabel((node) => node.type === "schema" ? node.data.typename : node.data.label ?? node.id).nodeAutoColorBy((node) => node.type === "schema" ? "schema" : node.data.typename).linkAutoColorBy((link2) => link2.type);
10884
+ }
10885
+ return () => {
10886
+ forceGraph.current?.pauseAnimation().graphData({
10887
+ nodes: [],
10888
+ links: []
10889
+ });
10890
+ forceGraph.current = null;
10891
+ };
10892
+ }, []);
10893
+ useEffect3(() => {
10894
+ if (!data || !width || !height || !forceGraph.current) {
10895
+ return;
10896
+ }
10897
+ forceGraph.current.pauseAnimation().width(width).height(height).onEngineStop(() => handleZoomToFit()).onNodeClick((node) => {
10898
+ forceGraph.current?.emitParticle(node);
10899
+ }).d3Force("link", forceLink().distance(160).strength(0.5)).d3Force("charge", forceManyBody().strength(-30)).graphData(data).warmupTicks(100).cooldownTime(1e3).resumeAnimation();
10900
+ }, [
10901
+ data,
10902
+ width,
10903
+ height
10904
+ ]);
10905
+ const handleZoomToFit = () => {
10906
+ forceGraph.current?.zoomToFit(400, 40);
10907
+ };
10908
+ const handleClick = useCallback((event) => {
10909
+ onClick?.(event);
10910
+ if (!event.defaultPrevented) {
10911
+ handleZoomToFit();
10912
+ }
10913
+ }, [
10914
+ onClick
10915
+ ]);
10916
+ return /* @__PURE__ */ React3.createElement("div", {
10917
+ ...composableProps(props, {
10918
+ classNames: "relative grow"
10919
+ }),
10920
+ onClick: handleClick,
10921
+ ref: setRef
10922
+ }, /* @__PURE__ */ React3.createElement("div", {
10923
+ ref: rootRef,
10924
+ className: "absolute inset-0"
10925
+ }));
10926
+ });
10927
+ var assignRef = (ref, value) => {
10928
+ if (typeof ref === "function") {
10929
+ ref(value);
10930
+ } else if (ref) {
10931
+ ref.current = value;
10932
+ }
10933
+ };
10934
+
10935
+ // src/components/Graph/ForceGraph.tsx
10936
+ import { Atom, useAtomValue } from "@effect-atom/atom-react";
10937
+ import React4, { useCallback as useCallback2, useEffect as useEffect4, useMemo, useRef as useRef2, useState as useState2 } from "react";
10938
+ import { Obj } from "@dxos/echo";
10939
+ import { SelectionModel } from "@dxos/graph";
10940
+ import { GraphForceProjector, SVG } from "@dxos/react-ui-graph";
10941
+ import { composable as composable2, composableProps as composableProps2, getHashStyles } from "@dxos/ui-theme";
10942
+ import "@dxos/react-ui-graph/styles/graph.css";
10943
+ var EMPTY_ATOM = Atom.make({
10944
+ nodes: [],
10945
+ edges: []
10946
+ });
10947
+ var ForceGraph = composable2(({ model, selection: selectionProp, grid, drag, onInspect, ...props }, forwardedRef) => {
10948
+ useAtomValue(model?.graphAtom ?? EMPTY_ATOM);
10949
+ const graph = useRef2(null);
10950
+ const selection = useMemo(() => selectionProp ?? new SelectionModel(), [
10951
+ selectionProp
10952
+ ]);
10953
+ useEffect4(() => {
10954
+ const unsubscribe = selection.subscribe(() => graph.current?.repaint());
10955
+ return unsubscribe;
10956
+ }, [
10957
+ selection
10958
+ ]);
10959
+ const svgRef = useRef2(null);
10960
+ const [projector, setProjector] = useState2();
10961
+ useEffect4(() => {
10962
+ if (svgRef.current) {
10963
+ setProjector(new GraphForceProjector(svgRef.current, {
10964
+ attributes: {
10965
+ // TODO(burdon): Check type (currently assumes Employee property).
10966
+ // Edge shouldn't contribute to force if it's not active.
10967
+ linkForce: (edge) => edge.data?.object?.active !== false
10968
+ },
10969
+ forces: {
10970
+ point: {
10971
+ strength: 0.01
10972
+ }
10973
+ }
10974
+ }));
10975
+ }
10976
+ }, []);
10977
+ const handleSelect = useCallback2((node) => {
10978
+ if (selection.contains(node.id)) {
10979
+ selection.remove(node.id);
10980
+ } else {
10981
+ selection.add(node.id);
10982
+ }
10983
+ }, [
10984
+ selection
10985
+ ]);
10986
+ return /* @__PURE__ */ React4.createElement("div", {
10987
+ ...composableProps2(props, {
10988
+ classNames: "dx-container"
10989
+ }),
10990
+ ref: forwardedRef
10991
+ }, /* @__PURE__ */ React4.createElement(SVG.Root, {
10992
+ ref: svgRef
10993
+ }, /* @__PURE__ */ React4.createElement(SVG.Markers, null), grid && /* @__PURE__ */ React4.createElement(SVG.Grid, {
10994
+ axis: true
10995
+ }), /* @__PURE__ */ React4.createElement(SVG.Zoom, {
10996
+ extent: [
10997
+ 1 / 2,
10998
+ 2
10999
+ ]
11000
+ }, /* @__PURE__ */ React4.createElement(SVG.Graph, {
11001
+ drag,
11002
+ ref: graph,
11003
+ model,
11004
+ projector,
11005
+ labels: {
11006
+ text: (node) => node.data?.data.label ?? node.id
11007
+ },
11008
+ attributes: {
11009
+ node: (node) => {
11010
+ const obj = node.data?.data.object;
11011
+ return {
11012
+ data: {
11013
+ color: getHashStyles(obj && Obj.getTypename(obj))?.hue
11014
+ },
11015
+ classes: {
11016
+ "dx-selected": selection.contains(node.id)
11017
+ }
11018
+ };
11019
+ }
11020
+ },
11021
+ onSelect: handleSelect,
11022
+ onInspect
11023
+ }))));
11024
+ });
11025
+
11026
+ // src/components/Tree/Tree.tsx
11027
+ import { RegistryContext } from "@effect-atom/atom-react";
11028
+ import React5, { useContext, useEffect as useEffect5, useRef as useRef3, useState as useState3 } from "react";
10840
11029
  import { useAsyncState } from "@dxos/react-ui";
10841
- import { SVG } from "@dxos/react-ui-graph";
11030
+ import { SVG as SVG2 } from "@dxos/react-ui-graph";
10842
11031
  import { SpaceGraphModel } from "@dxos/schema";
10843
11032
 
10844
- // packages/plugins/plugin-explorer/src/components/Tree/layout/HierarchicalEdgeBundling.ts
11033
+ // src/components/Tree/layout/HierarchicalEdgeBundling.ts
10845
11034
  import { cluster, curveBundle, hierarchy, lineRadial, select } from "d3";
10846
11035
  var HierarchicalEdgeBundling = (s, data, options) => {
10847
11036
  const svg = select(s);
@@ -10904,7 +11093,7 @@ var flatten = (node) => {
10904
11093
  };
10905
11094
  var HierarchicalEdgeBundling_default = HierarchicalEdgeBundling;
10906
11095
 
10907
- // packages/plugins/plugin-explorer/src/components/Tree/layout/RadialTree.ts
11096
+ // src/components/Tree/layout/RadialTree.ts
10908
11097
  import { hierarchy as hierarchy2, linkRadial, select as select2, tree } from "d3";
10909
11098
  var RadialTree = (s, data, options) => {
10910
11099
  const svg = select2(s);
@@ -10929,7 +11118,7 @@ var RadialTree = (s, data, options) => {
10929
11118
  };
10930
11119
  var RadialTree_default = RadialTree;
10931
11120
 
10932
- // packages/plugins/plugin-explorer/src/components/Tree/layout/TidyTree.ts
11121
+ // src/components/Tree/layout/TidyTree.ts
10933
11122
  import { curveBumpX, hierarchy as hierarchy3, link, select as select3, tree as tree2 } from "d3";
10934
11123
  var TidyTree = (s, data, options) => {
10935
11124
  const svg = select3(s);
@@ -10974,11 +11163,11 @@ var TidyTree = (s, data, options) => {
10974
11163
  };
10975
11164
  var TidyTree_default = TidyTree;
10976
11165
 
10977
- // packages/plugins/plugin-explorer/src/components/Tree/types/tree.ts
10978
- import { Schema } from "effect";
10979
- import { Key, Obj, Type } from "@dxos/echo";
11166
+ // src/components/Tree/types/tree.ts
11167
+ import * as Schema from "effect/Schema";
11168
+ import { Key, Obj as Obj2, Ref, Type } from "@dxos/echo";
11169
+ import { TestSchema } from "@dxos/echo/testing";
10980
11170
  import { invariant } from "@dxos/invariant";
10981
- var __dxlog_file = "/home/runner/work/dxos/dxos/packages/plugins/plugin-explorer/src/components/Tree/types/tree.ts";
10982
11171
  var TreeNodeType = Schema.Struct({
10983
11172
  id: Key.ObjectId,
10984
11173
  children: Schema.mutable(Schema.Array(Key.ObjectId)),
@@ -10986,7 +11175,7 @@ var TreeNodeType = Schema.Struct({
10986
11175
  key: Schema.String,
10987
11176
  value: Schema.Any
10988
11177
  })),
10989
- ref: Schema.optional(Type.Ref(Type.Expando))
11178
+ ref: Schema.optional(Ref.Ref(TestSchema.Expando))
10990
11179
  }).pipe(Schema.mutable);
10991
11180
  var TreeType = Schema.Struct({
10992
11181
  root: Key.ObjectId,
@@ -10994,257 +11183,18 @@ var TreeType = Schema.Struct({
10994
11183
  key: Key.ObjectId,
10995
11184
  value: TreeNodeType
10996
11185
  }))
10997
- }).pipe(Type.Obj({
10998
- typename: "dxos.org/type/Tree",
11186
+ }).pipe(Type.object({
11187
+ typename: "org.dxos.type.tree",
10999
11188
  version: "0.1.0"
11000
11189
  }));
11001
- var Tree = class _Tree {
11002
- static {
11003
- this.create = () => {
11004
- const id = Key.ObjectId.random();
11005
- return Obj.make(TreeType, {
11006
- root: id,
11007
- nodes: {
11008
- [id]: {
11009
- id,
11010
- children: [],
11011
- data: {
11012
- text: ""
11013
- }
11014
- }
11015
- }
11016
- });
11017
- };
11018
- }
11019
- constructor(tree3) {
11020
- this._tree = tree3 ?? _Tree.create();
11021
- }
11022
- get tree() {
11023
- return this._tree;
11024
- }
11025
- // TODO(burdon): Make reactive.
11026
- get size() {
11027
- return Object.keys(this._tree.nodes).length;
11028
- }
11029
- get root() {
11030
- return this.getNode(this._tree.root);
11031
- }
11032
- //
11033
- // Traversal
11034
- //
11035
- /**
11036
- * Recursively traverse the tree until the callback returns a value.
11037
- */
11038
- tranverse(callback, root = this._tree.root, depth = 0) {
11039
- const node = this._tree.nodes[root];
11040
- const result = callback(node, depth);
11041
- if (result !== void 0) {
11042
- return result;
11043
- }
11044
- for (const childId of node.children) {
11045
- const result2 = this.tranverse(callback, childId, depth + 1);
11046
- if (result2 !== void 0) {
11047
- return result2;
11048
- }
11049
- }
11050
- }
11051
- getNode(id) {
11052
- const node = this._tree.nodes[id];
11053
- invariant(node, void 0, {
11054
- F: __dxlog_file,
11055
- L: 98,
11056
- S: this,
11057
- A: [
11058
- "node",
11059
- ""
11060
- ]
11061
- });
11062
- return node;
11063
- }
11064
- /**
11065
- * Get the children of a node.
11066
- */
11067
- getChildNodes(node) {
11068
- return node.children.map((id) => this.getNode(id));
11069
- }
11070
- /**
11071
- * Get the parent of a node.
11072
- */
11073
- getParent(node) {
11074
- const parent = this.tranverse((n) => {
11075
- if (n.children.includes(node.id)) {
11076
- return n;
11077
- }
11078
- });
11079
- return parent ?? null;
11080
- }
11081
- /**
11082
- * Get the next node in the tree.
11083
- */
11084
- getNext(node, hierarchical = true) {
11085
- if (hierarchical && node.children.length) {
11086
- return this.getChildNodes(node)[0];
11087
- } else {
11088
- const parent = this.getParent(node);
11089
- if (parent) {
11090
- const idx = this.getChildNodes(parent).findIndex(({ id }) => id === node.id);
11091
- if (idx < parent.children.length - 1) {
11092
- return this.getNode(parent.children[idx + 1]);
11093
- } else {
11094
- return this.getNext(parent, false);
11095
- }
11096
- }
11097
- }
11098
- }
11099
- /**
11100
- * Get the previous node in the tree.
11101
- */
11102
- getPrevious(node, hierarchical = true) {
11103
- const parent = this.getParent(node);
11104
- const idx = this.getChildNodes(parent).findIndex(({ id }) => id === node.id);
11105
- if (idx === 0) {
11106
- if (hierarchical) {
11107
- return parent;
11108
- }
11109
- } else {
11110
- const previous = this.getNode(parent.children[idx - 1]);
11111
- if (hierarchical && previous.children.length) {
11112
- return this.getLastDescendent(previous);
11113
- }
11114
- return previous;
11115
- }
11116
- }
11117
- /**
11118
- * Get the last descendent of a node.
11119
- */
11120
- getLastDescendent(node) {
11121
- const children = this.getChildNodes(node);
11122
- const last = children.length ? children[children.length - 1] : void 0;
11123
- if (last) {
11124
- return this.getLastDescendent(last);
11125
- }
11126
- return node;
11127
- }
11128
- //
11129
- // Mutations
11130
- //
11131
- /**
11132
- * Clear tree.
11133
- */
11134
- clear() {
11135
- const root = this._tree.nodes[this._tree.root];
11136
- root.children.length = 0;
11137
- this._tree.nodes = {
11138
- [root.id]: root
11139
- };
11140
- }
11141
- /**
11142
- * Add node.
11143
- */
11144
- addNode(parent, node, index) {
11145
- if (!node) {
11146
- const id = Key.ObjectId.random();
11147
- node = {
11148
- id,
11149
- children: [],
11150
- data: {
11151
- text: ""
11152
- }
11153
- };
11154
- }
11155
- this._tree.nodes[node.id] = node;
11156
- parent.children.splice(index ?? parent.children.length, 0, node.id);
11157
- return node;
11158
- }
11159
- /**
11160
- * Delete node.
11161
- */
11162
- deleteNode(parent, id) {
11163
- const node = this._tree.nodes[id];
11164
- if (!node) {
11165
- return void 0;
11166
- }
11167
- delete this._tree.nodes[node.id];
11168
- const idx = parent.children.findIndex((child) => child === id);
11169
- if (idx !== -1) {
11170
- parent.children.splice(idx, 1);
11171
- }
11172
- return node;
11173
- }
11174
- /**
11175
- * Move child node.
11176
- */
11177
- moveNode(node, from, to) {
11178
- invariant(from >= 0 && from < node.children.length, void 0, {
11179
- F: __dxlog_file,
11180
- L: 228,
11181
- S: this,
11182
- A: [
11183
- "from >= 0 && from < node.children.length",
11184
- ""
11185
- ]
11186
- });
11187
- invariant(to >= 0 && to < node.children.length, void 0, {
11188
- F: __dxlog_file,
11189
- L: 229,
11190
- S: this,
11191
- A: [
11192
- "to >= 0 && to < node.children.length",
11193
- ""
11194
- ]
11195
- });
11196
- if (from === to) {
11197
- return null;
11198
- }
11199
- const child = node.children[from];
11200
- node.children.splice(from, 1);
11201
- node.children.splice(to, 0, child);
11202
- return this.getNode(child);
11203
- }
11204
- /**
11205
- * Indent node.
11206
- */
11207
- indentNode(node) {
11208
- const parent = this.getParent(node);
11209
- if (!parent) {
11210
- return;
11211
- }
11212
- const idx = parent.children.findIndex((child) => child === node.id);
11213
- if (idx < 1 || idx >= parent.children.length) {
11214
- return;
11215
- }
11216
- const previous = this.getNode(parent.children[idx - 1]);
11217
- parent.children.splice(idx, 1);
11218
- previous.children.push(node.id);
11219
- }
11220
- /**
11221
- * Unindent node.
11222
- */
11223
- unindentNode(node) {
11224
- const parent = this.getParent(node);
11225
- if (!parent) {
11226
- return;
11227
- }
11228
- const ancestor = this.getParent(parent);
11229
- if (!ancestor) {
11230
- return;
11231
- }
11232
- const nodeIdx = parent.children.findIndex((id) => id === node.id);
11233
- const [_, ...rest] = parent.children.splice(nodeIdx, parent.children.length - nodeIdx);
11234
- parent.children.splice(nodeIdx, parent.children.length - nodeIdx);
11235
- const parentIdx = this.getChildNodes(ancestor).findIndex((n) => n.id === parent.id);
11236
- ancestor.children.splice(parentIdx + 1, 0, node.id);
11237
- node.children.push(...rest);
11238
- }
11239
- };
11240
11190
 
11241
- // packages/plugins/plugin-explorer/src/components/Tree/types/types.ts
11191
+ // src/components/Tree/types/types.ts
11242
11192
  var mapGraphToTreeData = (model, maxDepth = 8) => {
11243
11193
  let data;
11244
11194
  return data;
11245
11195
  };
11246
11196
 
11247
- // packages/plugins/plugin-explorer/src/components/Tree/Tree.tsx
11197
+ // src/components/Tree/Tree.tsx
11248
11198
  var defaultTreeLayoutSlots = {
11249
11199
  node: "fill-blue-600",
11250
11200
  path: "fill-none stroke-blue-400 stroke-[0.5px]",
@@ -11264,68 +11214,62 @@ var renderers = /* @__PURE__ */ new Map([
11264
11214
  HierarchicalEdgeBundling_default
11265
11215
  ]
11266
11216
  ]);
11267
- var Tree2 = ({ space, selected, variant = "tidy", onNodeClick }) => {
11268
- var _effect = _useSignals3();
11269
- try {
11270
- const [model] = useAsyncState(async () => space ? new SpaceGraphModel().open(space) : void 0, [
11271
- space,
11272
- selected
11273
- ]);
11274
- const [tree3, setTree] = useState();
11275
- useEffect3(() => {
11276
- return model?.subscribe(() => {
11277
- const tree4 = mapGraphToTreeData(model);
11278
- setTree(tree4);
11279
- }, true);
11280
- }, [
11281
- model
11282
- ]);
11283
- const context = useRef(null);
11284
- useEffect3(() => {
11285
- if (context.current) {
11286
- const { width, height } = context.current.size;
11287
- const size = Math.min(width, height);
11288
- const radius = size * 0.4;
11289
- const options = {
11290
- // TODO(burdon): Type.
11291
- label: (d) => d.label ?? d.id,
11292
- width,
11293
- height,
11294
- radius,
11295
- marginLeft: (width - radius * 2) / 2,
11296
- marginRight: (width - radius * 2) / 2,
11297
- marginTop: (height - radius * 2) / 2,
11298
- marginBottom: (height - radius * 2) / 2,
11299
- slots: defaultTreeLayoutSlots
11300
- };
11301
- if (tree3) {
11302
- const renderer = renderers.get(variant);
11303
- renderer?.(context.current.svg, tree3, options);
11304
- }
11217
+ var Tree = ({ space, selected, variant = "tidy", onNodeClick }) => {
11218
+ const registry = useContext(RegistryContext);
11219
+ const [model] = useAsyncState(async () => space ? new SpaceGraphModel(registry).open(space.db) : void 0, [
11220
+ space,
11221
+ selected,
11222
+ registry
11223
+ ]);
11224
+ const [tree3, setTree] = useState3();
11225
+ useEffect5(() => {
11226
+ return model?.subscribe(() => {
11227
+ const tree4 = mapGraphToTreeData(model);
11228
+ setTree(tree4);
11229
+ }, true);
11230
+ }, [
11231
+ model
11232
+ ]);
11233
+ const context = useRef3(null);
11234
+ useEffect5(() => {
11235
+ if (context.current?.size) {
11236
+ const { width, height } = context.current.size;
11237
+ const size = Math.min(width, height);
11238
+ const radius = size * 0.4;
11239
+ const options = {
11240
+ // TODO(burdon): Type.
11241
+ label: (d) => d.label ?? d.id,
11242
+ width,
11243
+ height,
11244
+ radius,
11245
+ marginLeft: (width - radius * 2) / 2,
11246
+ marginRight: (width - radius * 2) / 2,
11247
+ marginTop: (height - radius * 2) / 2,
11248
+ marginBottom: (height - radius * 2) / 2,
11249
+ slots: defaultTreeLayoutSlots
11250
+ };
11251
+ if (tree3) {
11252
+ const renderer = renderers.get(variant);
11253
+ renderer?.(context.current.svg, tree3, options);
11305
11254
  }
11306
- }, [
11307
- context.current,
11308
- tree3
11309
- ]);
11310
- return /* @__PURE__ */ React3.createElement("div", {
11311
- onClick: () => onNodeClick?.()
11312
- }, /* @__PURE__ */ React3.createElement(SVG.Root, {
11313
- ref: context
11314
- }));
11315
- } finally {
11316
- _effect.f();
11317
- }
11255
+ }
11256
+ }, [
11257
+ context.current,
11258
+ tree3
11259
+ ]);
11260
+ return /* @__PURE__ */ React5.createElement("div", {
11261
+ className: "grow",
11262
+ onClick: () => onNodeClick?.()
11263
+ }, /* @__PURE__ */ React5.createElement(SVG2.Root, {
11264
+ ref: context
11265
+ }));
11318
11266
  };
11319
-
11320
- // packages/plugins/plugin-explorer/src/components/index.ts
11321
- import { lazy } from "react";
11322
- var ExplorerContainer = lazy(() => import("./ExplorerContainer-MFE7PXF4.mjs"));
11323
-
11324
11267
  export {
11268
+ CanvasForceGraph,
11325
11269
  Chart,
11270
+ ForceGraph,
11326
11271
  Globe,
11327
- defaultTreeLayoutSlots,
11328
- Tree2 as Tree,
11329
- ExplorerContainer
11272
+ Tree,
11273
+ defaultTreeLayoutSlots
11330
11274
  };
11331
- //# sourceMappingURL=chunk-IUFYOE44.mjs.map
11275
+ //# sourceMappingURL=index.mjs.map