@dxos/plugin-explorer 0.8.2-main.f11618f → 0.8.2-staging.42af850

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 (161) hide show
  1. package/dist/lib/browser/ExplorerContainer-BBZ54DJS.mjs +37 -0
  2. package/dist/lib/browser/ExplorerContainer-BBZ54DJS.mjs.map +7 -0
  3. package/dist/lib/browser/{chunk-RRXH3JYB.mjs → chunk-73GQ46YO.mjs} +415 -155
  4. package/dist/lib/{node-esm/chunk-VNMYGDGZ.mjs.map → browser/chunk-73GQ46YO.mjs.map} +4 -4
  5. package/dist/lib/browser/{chunk-QLQLPZNI.mjs → chunk-73YTQHOT.mjs} +12 -11
  6. package/dist/lib/browser/chunk-73YTQHOT.mjs.map +7 -0
  7. package/dist/lib/browser/chunk-M2BGAY6H.mjs +177 -0
  8. package/dist/lib/browser/chunk-M2BGAY6H.mjs.map +7 -0
  9. package/dist/lib/browser/{chunk-Z2SDLMQM.mjs → chunk-OBAFAA5V.mjs} +3 -3
  10. package/dist/lib/browser/{chunk-Z2SDLMQM.mjs.map → chunk-OBAFAA5V.mjs.map} +1 -1
  11. package/dist/lib/browser/chunk-SLB2F5AO.mjs +30 -0
  12. package/dist/lib/browser/chunk-SLB2F5AO.mjs.map +7 -0
  13. package/dist/lib/browser/index.mjs +15 -11
  14. package/dist/lib/browser/index.mjs.map +1 -1
  15. package/dist/lib/browser/{intent-resolver-P4YLQHXF.mjs → intent-resolver-FJDVBDE3.mjs} +3 -3
  16. package/dist/lib/browser/meta.json +1 -1
  17. package/dist/lib/browser/meta.mjs +1 -1
  18. package/dist/lib/browser/{react-surface-TPR4VUPE.mjs → react-surface-H3YDMXAQ.mjs} +5 -5
  19. package/dist/lib/browser/types/index.mjs +2 -2
  20. package/dist/lib/node/{ExplorerContainer-73AHSBAG.cjs → ExplorerContainer-MVP2AM7R.cjs} +24 -16
  21. package/dist/lib/node/ExplorerContainer-MVP2AM7R.cjs.map +7 -0
  22. package/dist/lib/node/chunk-4T4LCT5R.cjs +52 -0
  23. package/dist/lib/node/chunk-4T4LCT5R.cjs.map +7 -0
  24. package/dist/lib/node/{chunk-4QUNUHKB.cjs → chunk-72H5HBTK.cjs} +414 -153
  25. package/dist/lib/node/{chunk-4QUNUHKB.cjs.map → chunk-72H5HBTK.cjs.map} +4 -4
  26. package/dist/lib/node/{chunk-VB3QE6XY.cjs → chunk-BCDVG2CH.cjs} +6 -6
  27. package/dist/lib/node/{chunk-VB3QE6XY.cjs.map → chunk-BCDVG2CH.cjs.map} +1 -1
  28. package/dist/lib/node/{chunk-YLL7H7CZ.cjs → chunk-MLRYW4WQ.cjs} +15 -14
  29. package/dist/lib/node/chunk-MLRYW4WQ.cjs.map +7 -0
  30. package/dist/lib/node/chunk-NELWWGBU.cjs +204 -0
  31. package/dist/lib/node/chunk-NELWWGBU.cjs.map +7 -0
  32. package/dist/lib/node/index.cjs +34 -31
  33. package/dist/lib/node/index.cjs.map +1 -1
  34. package/dist/lib/node/{intent-resolver-T2R4PJVP.cjs → intent-resolver-DRT67ZU4.cjs} +8 -8
  35. package/dist/lib/node/meta.cjs +3 -3
  36. package/dist/lib/node/meta.cjs.map +1 -1
  37. package/dist/lib/node/meta.json +1 -1
  38. package/dist/lib/node/{react-surface-OLIOGYOK.cjs → react-surface-6ESLSM33.cjs} +11 -11
  39. package/dist/lib/node/types/index.cjs +4 -4
  40. package/dist/lib/node/types/index.cjs.map +1 -1
  41. package/dist/lib/node-esm/ExplorerContainer-APGUQI4M.mjs +38 -0
  42. package/dist/lib/node-esm/ExplorerContainer-APGUQI4M.mjs.map +7 -0
  43. package/dist/lib/node-esm/{chunk-VNMYGDGZ.mjs → chunk-34X2VFQN.mjs} +415 -154
  44. package/dist/lib/{browser/chunk-RRXH3JYB.mjs.map → node-esm/chunk-34X2VFQN.mjs.map} +4 -4
  45. package/dist/lib/node-esm/{chunk-PUFSCMN4.mjs → chunk-3CMBLK6W.mjs} +3 -3
  46. package/dist/lib/node-esm/{chunk-PUFSCMN4.mjs.map → chunk-3CMBLK6W.mjs.map} +1 -1
  47. package/dist/lib/node-esm/{chunk-QZH2GDN5.mjs → chunk-N6VEANUZ.mjs} +12 -11
  48. package/dist/lib/node-esm/chunk-N6VEANUZ.mjs.map +7 -0
  49. package/dist/lib/node-esm/chunk-PVII2K2B.mjs +179 -0
  50. package/dist/lib/node-esm/chunk-PVII2K2B.mjs.map +7 -0
  51. package/dist/lib/node-esm/chunk-VSORIAHH.mjs +32 -0
  52. package/dist/lib/node-esm/chunk-VSORIAHH.mjs.map +7 -0
  53. package/dist/lib/node-esm/index.mjs +15 -11
  54. package/dist/lib/node-esm/index.mjs.map +1 -1
  55. package/dist/lib/node-esm/{intent-resolver-OMUHLTGU.mjs → intent-resolver-4RBV644N.mjs} +3 -3
  56. package/dist/lib/node-esm/meta.json +1 -1
  57. package/dist/lib/node-esm/meta.mjs +1 -1
  58. package/dist/lib/node-esm/{react-surface-QLB55AWT.mjs → react-surface-ZEVL3FXG.mjs} +5 -5
  59. package/dist/lib/node-esm/types/index.mjs +2 -2
  60. package/dist/types/src/components/Chart/Chart.d.ts.map +1 -1
  61. package/dist/types/src/components/ExplorerContainer.d.ts +4 -3
  62. package/dist/types/src/components/ExplorerContainer.d.ts.map +1 -1
  63. package/dist/types/src/components/Globe/Globe.d.ts.map +1 -1
  64. package/dist/types/src/components/Graph/D3ForceGraph.d.ts +14 -0
  65. package/dist/types/src/components/Graph/D3ForceGraph.d.ts.map +1 -0
  66. package/dist/types/src/components/Graph/D3ForceGraph.stories.d.ts +6 -0
  67. package/dist/types/src/components/Graph/D3ForceGraph.stories.d.ts.map +1 -0
  68. package/dist/types/src/components/Graph/ForceGraph.d.ts +8 -0
  69. package/dist/types/src/components/Graph/ForceGraph.d.ts.map +1 -0
  70. package/dist/types/src/components/Graph/{Graph.stories.d.ts → ForceGraph.stories.d.ts} +1 -1
  71. package/dist/types/src/components/Graph/ForceGraph.stories.d.ts.map +1 -0
  72. package/dist/types/src/components/Graph/adapter.d.ts +21 -0
  73. package/dist/types/src/components/Graph/adapter.d.ts.map +1 -0
  74. package/dist/types/src/components/Graph/index.d.ts +2 -2
  75. package/dist/types/src/components/Graph/index.d.ts.map +1 -1
  76. package/dist/types/src/components/Graph/testing.d.ts +14 -0
  77. package/dist/types/src/components/Graph/testing.d.ts.map +1 -0
  78. package/dist/types/src/components/Tree/Tree.d.ts.map +1 -1
  79. package/dist/types/src/components/Tree/layout/HierarchicalEdgeBundling.d.ts.map +1 -1
  80. package/dist/types/src/components/Tree/layout/RadialTree.d.ts.map +1 -1
  81. package/dist/types/src/components/Tree/layout/TidyTree.d.ts.map +1 -1
  82. package/dist/types/src/components/Tree/testing/generator.d.ts +8 -0
  83. package/dist/types/src/components/Tree/testing/generator.d.ts.map +1 -0
  84. package/dist/types/src/components/Tree/testing/index.d.ts +2 -0
  85. package/dist/types/src/components/Tree/testing/index.d.ts.map +1 -0
  86. package/dist/types/src/components/Tree/types/index.d.ts +3 -0
  87. package/dist/types/src/components/Tree/types/index.d.ts.map +1 -0
  88. package/dist/types/src/components/Tree/types/tree.d.ts +83 -0
  89. package/dist/types/src/components/Tree/types/tree.d.ts.map +1 -0
  90. package/dist/types/src/components/Tree/types/tree.test.d.ts +2 -0
  91. package/dist/types/src/components/Tree/types/tree.test.d.ts.map +1 -0
  92. package/dist/types/src/components/Tree/types/types.d.ts +8 -0
  93. package/dist/types/src/components/Tree/types/types.d.ts.map +1 -0
  94. package/dist/types/src/components/index.d.ts +2 -2
  95. package/dist/types/src/components/plot.d.ts.map +1 -1
  96. package/dist/types/src/hooks/index.d.ts +2 -0
  97. package/dist/types/src/hooks/index.d.ts.map +1 -0
  98. package/dist/types/src/hooks/useGraphModel.d.ts +4 -0
  99. package/dist/types/src/hooks/useGraphModel.d.ts.map +1 -0
  100. package/dist/types/src/index.d.ts +2 -1
  101. package/dist/types/src/index.d.ts.map +1 -1
  102. package/dist/types/src/translations.d.ts +2 -8
  103. package/dist/types/src/translations.d.ts.map +1 -1
  104. package/dist/types/src/types/schema.d.ts +6 -6
  105. package/dist/types/src/types/schema.d.ts.map +1 -1
  106. package/dist/types/src/types/types.d.ts +6 -6
  107. package/dist/types/src/types/types.d.ts.map +1 -1
  108. package/dist/types/tsconfig.tsbuildinfo +1 -1
  109. package/package.json +30 -27
  110. package/src/components/ExplorerContainer.tsx +11 -4
  111. package/src/components/Graph/D3ForceGraph.stories.tsx +64 -0
  112. package/src/components/Graph/D3ForceGraph.tsx +101 -0
  113. package/src/components/Graph/ForceGraph.stories.tsx +64 -0
  114. package/src/components/Graph/{Graph.tsx → ForceGraph.tsx} +19 -26
  115. package/src/components/Graph/adapter.ts +47 -0
  116. package/src/components/Graph/index.ts +2 -3
  117. package/src/components/Graph/testing.ts +57 -0
  118. package/src/components/Tree/Tree.stories.tsx +1 -1
  119. package/src/components/Tree/Tree.tsx +11 -18
  120. package/src/components/Tree/testing/generator.ts +46 -0
  121. package/src/components/Tree/testing/index.ts +5 -0
  122. package/src/components/Tree/types/index.ts +6 -0
  123. package/src/components/Tree/types/tree.test.ts +133 -0
  124. package/src/components/Tree/types/tree.ts +287 -0
  125. package/src/components/Tree/types/types.ts +41 -0
  126. package/src/hooks/index.ts +5 -0
  127. package/src/hooks/useGraphModel.ts +35 -0
  128. package/src/index.ts +2 -2
  129. package/src/meta.ts +2 -2
  130. package/src/types/schema.ts +5 -3
  131. package/src/types/types.ts +5 -5
  132. package/dist/lib/browser/ExplorerContainer-HL532ODG.mjs +0 -27
  133. package/dist/lib/browser/ExplorerContainer-HL532ODG.mjs.map +0 -7
  134. package/dist/lib/browser/chunk-QLQLPZNI.mjs.map +0 -7
  135. package/dist/lib/browser/chunk-SBLNE7FL.mjs +0 -205
  136. package/dist/lib/browser/chunk-SBLNE7FL.mjs.map +0 -7
  137. package/dist/lib/node/ExplorerContainer-73AHSBAG.cjs.map +0 -7
  138. package/dist/lib/node/chunk-OIHH6TVE.cjs +0 -236
  139. package/dist/lib/node/chunk-OIHH6TVE.cjs.map +0 -7
  140. package/dist/lib/node/chunk-YLL7H7CZ.cjs.map +0 -7
  141. package/dist/lib/node-esm/ExplorerContainer-NMI55PYM.mjs +0 -28
  142. package/dist/lib/node-esm/ExplorerContainer-NMI55PYM.mjs.map +0 -7
  143. package/dist/lib/node-esm/chunk-QZH2GDN5.mjs.map +0 -7
  144. package/dist/lib/node-esm/chunk-SZRRNWYT.mjs +0 -207
  145. package/dist/lib/node-esm/chunk-SZRRNWYT.mjs.map +0 -7
  146. package/dist/types/src/components/Graph/Graph.d.ts +0 -8
  147. package/dist/types/src/components/Graph/Graph.d.ts.map +0 -1
  148. package/dist/types/src/components/Graph/Graph.stories.d.ts.map +0 -1
  149. package/dist/types/src/components/Graph/graph-model.d.ts +0 -39
  150. package/dist/types/src/components/Graph/graph-model.d.ts.map +0 -1
  151. package/dist/types/src/components/Tree/types.d.ts +0 -8
  152. package/dist/types/src/components/Tree/types.d.ts.map +0 -1
  153. package/src/components/Graph/Graph.stories.tsx +0 -62
  154. package/src/components/Graph/graph-model.ts +0 -193
  155. package/src/components/Tree/types.ts +0 -40
  156. /package/dist/lib/browser/{intent-resolver-P4YLQHXF.mjs.map → intent-resolver-FJDVBDE3.mjs.map} +0 -0
  157. /package/dist/lib/browser/{react-surface-TPR4VUPE.mjs.map → react-surface-H3YDMXAQ.mjs.map} +0 -0
  158. /package/dist/lib/node/{intent-resolver-T2R4PJVP.cjs.map → intent-resolver-DRT67ZU4.cjs.map} +0 -0
  159. /package/dist/lib/node/{react-surface-OLIOGYOK.cjs.map → react-surface-6ESLSM33.cjs.map} +0 -0
  160. /package/dist/lib/node-esm/{intent-resolver-OMUHLTGU.mjs.map → intent-resolver-4RBV644N.mjs.map} +0 -0
  161. /package/dist/lib/node-esm/{react-surface-QLB55AWT.mjs.map → react-surface-ZEVL3FXG.mjs.map} +0 -0
@@ -1,9 +1,7 @@
1
1
  import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
2
- import {
3
- SpaceGraphModel
4
- } from "./chunk-SZRRNWYT.mjs";
5
2
 
6
3
  // packages/plugins/plugin-explorer/src/components/Chart/Chart.tsx
4
+ import { useSignals as _useSignals } from "@preact-signals/safe-react/tracking";
7
5
  import * as Plot from "@observablehq/plot";
8
6
  import React, { useEffect } from "react";
9
7
  import { useResizeDetector } from "react-resize-detector";
@@ -21,43 +19,49 @@ var defaultOptions = {
21
19
  fillOpacity: 0.2
22
20
  };
23
21
  var Chart = ({ items = [], accessor, options = defaultOptions }) => {
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,
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,
33
51
  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
- ]
52
+ height
53
+ ]);
54
+ return /* @__PURE__ */ React.createElement("div", {
55
+ ref: containerRef,
56
+ className: "grow"
46
57
  });
47
- containerRef.current.append(plot3);
48
- return () => plot3?.remove();
49
- }, [
50
- items,
51
- width,
52
- height
53
- ]);
54
- return /* @__PURE__ */ React.createElement("div", {
55
- ref: containerRef,
56
- className: "grow"
57
- });
58
+ } finally {
59
+ _effect.f();
60
+ }
58
61
  };
59
62
 
60
63
  // packages/plugins/plugin-explorer/src/components/Globe/Globe.tsx
64
+ import { useSignals as _useSignals2 } from "@preact-signals/safe-react/tracking";
61
65
  import * as Plot2 from "@observablehq/plot";
62
66
  import React2, { useEffect as useEffect2 } from "react";
63
67
  import { useResizeDetector as useResizeDetector2 } from "react-resize-detector";
@@ -10771,65 +10775,71 @@ var defaultOptions2 = {
10771
10775
  fill: "#003300"
10772
10776
  };
10773
10777
  var Globe = ({ items = [], accessor, projection = "orthographic", options = defaultOptions2 }) => {
10774
- const { ref: containerRef, width = 0, height = 0 } = useResizeDetector2({
10775
- refreshRate: 200
10776
- });
10777
- const land = topojson.feature(countries_110m_default, countries_110m_default.objects.land);
10778
- useEffect2(() => {
10779
- if (!width || !height) {
10780
- return;
10781
- }
10782
- const plot3 = Plot2.plot({
10783
- // https://observablehq.com/plot/features/projections
10784
- projection: {
10785
- type: projection,
10786
- rotate: [
10787
- -100,
10788
- -20
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
+ })
10789
10819
  ]
10790
- },
10791
- // projection: { type: 'equirectangular', rotate: [-140, -30] },
10820
+ });
10821
+ containerRef.current.append(plot3);
10822
+ return () => plot3?.remove();
10823
+ }, [
10824
+ items,
10792
10825
  width,
10793
- height,
10794
- style: {
10795
- background: "transparent"
10796
- },
10797
- // TODO(burdon): Create simple wrapper for Plot with good defaults.
10798
- marks: [
10799
- Plot2.sphere({
10800
- fill: "lightblue",
10801
- fillOpacity: 0.5
10802
- }),
10803
- Plot2.geo(land, {
10804
- fill: "darkgreen",
10805
- fillOpacity: 0.5
10806
- }),
10807
- Plot2.graticule(),
10808
- Plot2.dot(items, {
10809
- x: createAdapter("lat", accessor),
10810
- y: createAdapter("lng", accessor),
10811
- ...options
10812
- })
10813
- ]
10826
+ height
10827
+ ]);
10828
+ return /* @__PURE__ */ React2.createElement("div", {
10829
+ ref: containerRef,
10830
+ className: "grow p-4"
10814
10831
  });
10815
- containerRef.current.append(plot3);
10816
- return () => plot3?.remove();
10817
- }, [
10818
- items,
10819
- width,
10820
- height
10821
- ]);
10822
- return /* @__PURE__ */ React2.createElement("div", {
10823
- ref: containerRef,
10824
- className: "grow p-4"
10825
- });
10832
+ } finally {
10833
+ _effect.f();
10834
+ }
10826
10835
  };
10827
10836
 
10828
10837
  // packages/plugins/plugin-explorer/src/components/Tree/Tree.tsx
10829
- import React3, { useEffect as useEffect3, useState } from "react";
10830
- import { useResizeDetector as useResizeDetector3 } from "react-resize-detector";
10831
- import { createSvgContext, SVG, SVGRoot } from "@dxos/gem-core";
10838
+ import { useSignals as _useSignals3 } from "@preact-signals/safe-react/tracking";
10839
+ import React3, { useEffect as useEffect3, useRef, useState } from "react";
10832
10840
  import { useAsyncState } from "@dxos/react-ui";
10841
+ import { SVG } from "@dxos/react-ui-graph";
10842
+ import { SpaceGraphModel } from "@dxos/schema";
10833
10843
 
10834
10844
  // packages/plugins/plugin-explorer/src/components/Tree/layout/HierarchicalEdgeBundling.ts
10835
10845
  import { cluster, curveBundle, hierarchy, lineRadial, select } from "d3";
@@ -10964,26 +10974,275 @@ var TidyTree = (s, data, options) => {
10964
10974
  };
10965
10975
  var TidyTree_default = TidyTree;
10966
10976
 
10967
- // packages/plugins/plugin-explorer/src/components/Tree/types.ts
10968
- var mapGraphToTreeData = (model, maxDepth = 8) => {
10969
- const mapNode = (node, depth = 0) => {
10970
- const treeNode = {
10971
- id: model.idAccessor(node),
10972
- label: model.idAccessor(node).slice(0, 8)
10977
+ // packages/plugins/plugin-explorer/src/components/Tree/types/tree.ts
10978
+ import { Schema } from "effect";
10979
+ import { Type } from "@dxos/echo";
10980
+ import { ObjectId, Ref, Expando } from "@dxos/echo-schema";
10981
+ import { invariant } from "@dxos/invariant";
10982
+ import { live } from "@dxos/live-object";
10983
+ var __dxlog_file = "/home/runner/work/dxos/dxos/packages/plugins/plugin-explorer/src/components/Tree/types/tree.ts";
10984
+ var TreeNodeType = Schema.Struct({
10985
+ id: ObjectId,
10986
+ children: Schema.mutable(Schema.Array(ObjectId)),
10987
+ data: Schema.mutable(Schema.Record({
10988
+ key: Schema.String,
10989
+ value: Schema.Any
10990
+ })),
10991
+ ref: Schema.optional(Ref(Expando))
10992
+ }).pipe(Schema.mutable);
10993
+ var TreeType = Schema.Struct({
10994
+ root: ObjectId,
10995
+ nodes: Schema.mutable(Schema.Record({
10996
+ key: ObjectId,
10997
+ value: TreeNodeType
10998
+ }))
10999
+ }).pipe(Type.Obj({
11000
+ typename: "dxos.org/type/Tree",
11001
+ version: "0.1.0"
11002
+ }));
11003
+ var Tree = class _Tree {
11004
+ static {
11005
+ this.create = () => {
11006
+ const id = ObjectId.random();
11007
+ return live(TreeType, {
11008
+ root: id,
11009
+ nodes: {
11010
+ [id]: {
11011
+ id,
11012
+ children: [],
11013
+ data: {
11014
+ text: ""
11015
+ }
11016
+ }
11017
+ }
11018
+ });
10973
11019
  };
10974
- const links = model.graph.links.filter((link2) => link2.source === treeNode.id);
10975
- if (depth < maxDepth) {
10976
- treeNode.children = links.map((link2) => mapNode(model.graph.nodes.find((node2) => model.idAccessor(node2) === link2.target), depth + 1));
11020
+ }
11021
+ constructor(tree3) {
11022
+ this._tree = tree3 ?? _Tree.create();
11023
+ }
11024
+ get tree() {
11025
+ return this._tree;
11026
+ }
11027
+ // TODO(burdon): Make reactive.
11028
+ get size() {
11029
+ return Object.keys(this._tree.nodes).length;
11030
+ }
11031
+ get root() {
11032
+ return this.getNode(this._tree.root);
11033
+ }
11034
+ //
11035
+ // Traversal
11036
+ //
11037
+ /**
11038
+ * Recursively traverse the tree until the callback returns a value.
11039
+ */
11040
+ tranverse(callback, root = this._tree.root, depth = 0) {
11041
+ const node = this._tree.nodes[root];
11042
+ const result = callback(node, depth);
11043
+ if (result !== void 0) {
11044
+ return result;
10977
11045
  }
10978
- return treeNode;
10979
- };
10980
- let data;
10981
- if (model.selected) {
10982
- const node = model.graph.nodes.find((node2) => model.idAccessor(node2) === model.selected);
10983
- if (node) {
10984
- data = mapNode(node);
11046
+ for (const childId of node.children) {
11047
+ const result2 = this.tranverse(callback, childId, depth + 1);
11048
+ if (result2 !== void 0) {
11049
+ return result2;
11050
+ }
10985
11051
  }
10986
11052
  }
11053
+ getNode(id) {
11054
+ const node = this._tree.nodes[id];
11055
+ invariant(node, void 0, {
11056
+ F: __dxlog_file,
11057
+ L: 100,
11058
+ S: this,
11059
+ A: [
11060
+ "node",
11061
+ ""
11062
+ ]
11063
+ });
11064
+ return node;
11065
+ }
11066
+ /**
11067
+ * Get the children of a node.
11068
+ */
11069
+ getChildNodes(node) {
11070
+ return node.children.map((id) => this.getNode(id));
11071
+ }
11072
+ /**
11073
+ * Get the parent of a node.
11074
+ */
11075
+ getParent(node) {
11076
+ const parent = this.tranverse((n) => {
11077
+ if (n.children.includes(node.id)) {
11078
+ return n;
11079
+ }
11080
+ });
11081
+ return parent ?? null;
11082
+ }
11083
+ /**
11084
+ * Get the next node in the tree.
11085
+ */
11086
+ getNext(node, hierarchical = true) {
11087
+ if (hierarchical && node.children.length) {
11088
+ return this.getChildNodes(node)[0];
11089
+ } else {
11090
+ const parent = this.getParent(node);
11091
+ if (parent) {
11092
+ const idx = this.getChildNodes(parent).findIndex(({ id }) => id === node.id);
11093
+ if (idx < parent.children.length - 1) {
11094
+ return this.getNode(parent.children[idx + 1]);
11095
+ } else {
11096
+ return this.getNext(parent, false);
11097
+ }
11098
+ }
11099
+ }
11100
+ }
11101
+ /**
11102
+ * Get the previous node in the tree.
11103
+ */
11104
+ getPrevious(node, hierarchical = true) {
11105
+ const parent = this.getParent(node);
11106
+ const idx = this.getChildNodes(parent).findIndex(({ id }) => id === node.id);
11107
+ if (idx === 0) {
11108
+ if (hierarchical) {
11109
+ return parent;
11110
+ }
11111
+ } else {
11112
+ const previous = this.getNode(parent.children[idx - 1]);
11113
+ if (hierarchical && previous.children.length) {
11114
+ return this.getLastDescendent(previous);
11115
+ }
11116
+ return previous;
11117
+ }
11118
+ }
11119
+ /**
11120
+ * Get the last descendent of a node.
11121
+ */
11122
+ getLastDescendent(node) {
11123
+ const children = this.getChildNodes(node);
11124
+ const last = children.length ? children[children.length - 1] : void 0;
11125
+ if (last) {
11126
+ return this.getLastDescendent(last);
11127
+ }
11128
+ return node;
11129
+ }
11130
+ //
11131
+ // Mutations
11132
+ //
11133
+ /**
11134
+ * Clear tree.
11135
+ */
11136
+ clear() {
11137
+ const root = this._tree.nodes[this._tree.root];
11138
+ root.children.length = 0;
11139
+ this._tree.nodes = {
11140
+ [root.id]: root
11141
+ };
11142
+ }
11143
+ /**
11144
+ * Add node.
11145
+ */
11146
+ addNode(parent, node, index) {
11147
+ if (!node) {
11148
+ const id = ObjectId.random();
11149
+ node = {
11150
+ id,
11151
+ children: [],
11152
+ data: {
11153
+ text: ""
11154
+ }
11155
+ };
11156
+ }
11157
+ this._tree.nodes[node.id] = node;
11158
+ parent.children.splice(index ?? parent.children.length, 0, node.id);
11159
+ return node;
11160
+ }
11161
+ /**
11162
+ * Delete node.
11163
+ */
11164
+ deleteNode(parent, id) {
11165
+ const node = this._tree.nodes[id];
11166
+ if (!node) {
11167
+ return void 0;
11168
+ }
11169
+ delete this._tree.nodes[node.id];
11170
+ const idx = parent.children.findIndex((child) => child === id);
11171
+ if (idx !== -1) {
11172
+ parent.children.splice(idx, 1);
11173
+ }
11174
+ return node;
11175
+ }
11176
+ /**
11177
+ * Move child node.
11178
+ */
11179
+ moveNode(node, from, to) {
11180
+ invariant(from >= 0 && from < node.children.length, void 0, {
11181
+ F: __dxlog_file,
11182
+ L: 230,
11183
+ S: this,
11184
+ A: [
11185
+ "from >= 0 && from < node.children.length",
11186
+ ""
11187
+ ]
11188
+ });
11189
+ invariant(to >= 0 && to < node.children.length, void 0, {
11190
+ F: __dxlog_file,
11191
+ L: 231,
11192
+ S: this,
11193
+ A: [
11194
+ "to >= 0 && to < node.children.length",
11195
+ ""
11196
+ ]
11197
+ });
11198
+ if (from === to) {
11199
+ return null;
11200
+ }
11201
+ const child = node.children[from];
11202
+ node.children.splice(from, 1);
11203
+ node.children.splice(to, 0, child);
11204
+ return this.getNode(child);
11205
+ }
11206
+ /**
11207
+ * Indent node.
11208
+ */
11209
+ indentNode(node) {
11210
+ const parent = this.getParent(node);
11211
+ if (!parent) {
11212
+ return;
11213
+ }
11214
+ const idx = parent.children.findIndex((child) => child === node.id);
11215
+ if (idx < 1 || idx >= parent.children.length) {
11216
+ return;
11217
+ }
11218
+ const previous = this.getNode(parent.children[idx - 1]);
11219
+ parent.children.splice(idx, 1);
11220
+ previous.children.push(node.id);
11221
+ }
11222
+ /**
11223
+ * Unindent node.
11224
+ */
11225
+ unindentNode(node) {
11226
+ const parent = this.getParent(node);
11227
+ if (!parent) {
11228
+ return;
11229
+ }
11230
+ const ancestor = this.getParent(parent);
11231
+ if (!ancestor) {
11232
+ return;
11233
+ }
11234
+ const nodeIdx = parent.children.findIndex((id) => id === node.id);
11235
+ const [_, ...rest] = parent.children.splice(nodeIdx, parent.children.length - nodeIdx);
11236
+ parent.children.splice(nodeIdx, parent.children.length - nodeIdx);
11237
+ const parentIdx = this.getChildNodes(ancestor).findIndex((n) => n.id === parent.id);
11238
+ ancestor.children.splice(parentIdx + 1, 0, node.id);
11239
+ node.children.push(...rest);
11240
+ }
11241
+ };
11242
+
11243
+ // packages/plugins/plugin-explorer/src/components/Tree/types/types.ts
11244
+ var mapGraphToTreeData = (model, maxDepth = 8) => {
11245
+ let data;
10987
11246
  return data;
10988
11247
  };
10989
11248
 
@@ -11007,66 +11266,68 @@ var renderers = /* @__PURE__ */ new Map([
11007
11266
  HierarchicalEdgeBundling_default
11008
11267
  ]
11009
11268
  ]);
11010
- var Tree = ({ space, selected, variant = "tidy", onNodeClick }) => {
11011
- const [model] = useAsyncState(async () => space ? new SpaceGraphModel().open(space, selected) : void 0, [
11012
- space,
11013
- selected
11014
- ]);
11015
- const [tree3, setTree] = useState();
11016
- useEffect3(() => {
11017
- return model?.subscribe(() => {
11018
- const tree4 = mapGraphToTreeData(model);
11019
- setTree(tree4);
11020
- }, true);
11021
- }, [
11022
- model
11023
- ]);
11024
- const context = createSvgContext();
11025
- const { ref, width = 0, height = 0 } = useResizeDetector3();
11026
- useEffect3(() => {
11027
- if (width && height) {
11028
- const size = Math.min(width, height);
11029
- const radius = size * 0.4;
11030
- const options = {
11031
- // TODO(burdon): Type.
11032
- label: (d) => d.label ?? d.id,
11033
- width,
11034
- height,
11035
- radius,
11036
- marginLeft: (width - radius * 2) / 2,
11037
- marginRight: (width - radius * 2) / 2,
11038
- marginTop: (height - radius * 2) / 2,
11039
- marginBottom: (height - radius * 2) / 2,
11040
- slots: defaultTreeLayoutSlots
11041
- };
11042
- if (tree3) {
11043
- const renderer = renderers.get(variant);
11044
- renderer?.(context.ref.current, tree3, options);
11269
+ var Tree2 = ({ space, selected, variant = "tidy", onNodeClick }) => {
11270
+ var _effect = _useSignals3();
11271
+ try {
11272
+ const [model] = useAsyncState(async () => space ? new SpaceGraphModel().open(space) : void 0, [
11273
+ space,
11274
+ selected
11275
+ ]);
11276
+ const [tree3, setTree] = useState();
11277
+ useEffect3(() => {
11278
+ return model?.subscribe(() => {
11279
+ const tree4 = mapGraphToTreeData(model);
11280
+ setTree(tree4);
11281
+ }, true);
11282
+ }, [
11283
+ model
11284
+ ]);
11285
+ const context = useRef(null);
11286
+ useEffect3(() => {
11287
+ if (context.current) {
11288
+ const { width, height } = context.current.size;
11289
+ const size = Math.min(width, height);
11290
+ const radius = size * 0.4;
11291
+ const options = {
11292
+ // TODO(burdon): Type.
11293
+ label: (d) => d.label ?? d.id,
11294
+ width,
11295
+ height,
11296
+ radius,
11297
+ marginLeft: (width - radius * 2) / 2,
11298
+ marginRight: (width - radius * 2) / 2,
11299
+ marginTop: (height - radius * 2) / 2,
11300
+ marginBottom: (height - radius * 2) / 2,
11301
+ slots: defaultTreeLayoutSlots
11302
+ };
11303
+ if (tree3) {
11304
+ const renderer = renderers.get(variant);
11305
+ renderer?.(context.current.svg, tree3, options);
11306
+ }
11045
11307
  }
11046
- }
11047
- }, [
11048
- tree3,
11049
- width,
11050
- height
11051
- ]);
11052
- return /* @__PURE__ */ React3.createElement("div", {
11053
- ref,
11054
- className: "flex grow overflow-hidden",
11055
- onClick: () => onNodeClick?.()
11056
- }, /* @__PURE__ */ React3.createElement(SVGRoot, {
11057
- context
11058
- }, /* @__PURE__ */ React3.createElement(SVG, null)));
11308
+ }, [
11309
+ context.current,
11310
+ tree3
11311
+ ]);
11312
+ return /* @__PURE__ */ React3.createElement("div", {
11313
+ onClick: () => onNodeClick?.()
11314
+ }, /* @__PURE__ */ React3.createElement(SVG.Root, {
11315
+ ref: context
11316
+ }));
11317
+ } finally {
11318
+ _effect.f();
11319
+ }
11059
11320
  };
11060
11321
 
11061
11322
  // packages/plugins/plugin-explorer/src/components/index.ts
11062
11323
  import { lazy } from "react";
11063
- var ExplorerContainer = lazy(() => import("./ExplorerContainer-NMI55PYM.mjs"));
11324
+ var ExplorerContainer = lazy(() => import("./ExplorerContainer-APGUQI4M.mjs"));
11064
11325
 
11065
11326
  export {
11066
11327
  Chart,
11067
11328
  Globe,
11068
11329
  defaultTreeLayoutSlots,
11069
- Tree,
11330
+ Tree2 as Tree,
11070
11331
  ExplorerContainer
11071
11332
  };
11072
- //# sourceMappingURL=chunk-VNMYGDGZ.mjs.map
11333
+ //# sourceMappingURL=chunk-34X2VFQN.mjs.map