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

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