@dxos/plugin-explorer 0.8.4-main.67995b8 → 0.8.4-main.6fa680abb7

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 (160) hide show
  1. package/dist/lib/browser/ExplorerContainer-JBCVWH3M.mjs +48 -0
  2. package/dist/lib/browser/ExplorerContainer-JBCVWH3M.mjs.map +7 -0
  3. package/dist/lib/browser/chunk-3Y7INKYN.mjs +68 -0
  4. package/dist/lib/browser/chunk-3Y7INKYN.mjs.map +7 -0
  5. package/dist/lib/browser/chunk-J5LGTIGS.mjs +10 -0
  6. package/dist/lib/browser/chunk-J5LGTIGS.mjs.map +7 -0
  7. package/dist/lib/browser/chunk-LSUP47BZ.mjs +24 -0
  8. package/dist/lib/browser/chunk-LSUP47BZ.mjs.map +7 -0
  9. package/dist/lib/browser/{chunk-PVFZFKQ6.mjs → chunk-WX7QIZMF.mjs} +345 -396
  10. package/dist/lib/{node-esm/chunk-S5A2EUSJ.mjs.map → browser/chunk-WX7QIZMF.mjs.map} +4 -4
  11. package/dist/lib/browser/index.mjs +55 -71
  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 -3
  15. package/dist/lib/browser/react-surface-FWNW2HFX.mjs +38 -0
  16. package/dist/lib/browser/react-surface-FWNW2HFX.mjs.map +7 -0
  17. package/dist/lib/browser/types/index.mjs +6 -6
  18. package/dist/lib/node-esm/ExplorerContainer-5JTSMOCL.mjs +49 -0
  19. package/dist/lib/node-esm/ExplorerContainer-5JTSMOCL.mjs.map +7 -0
  20. package/dist/lib/node-esm/{chunk-S5A2EUSJ.mjs → chunk-3Z2WBI3N.mjs} +345 -396
  21. package/dist/lib/{browser/chunk-PVFZFKQ6.mjs.map → node-esm/chunk-3Z2WBI3N.mjs.map} +4 -4
  22. package/dist/lib/node-esm/chunk-6OG6G75N.mjs +69 -0
  23. package/dist/lib/node-esm/chunk-6OG6G75N.mjs.map +7 -0
  24. package/dist/lib/node-esm/{chunk-PIAXA43R.mjs → chunk-EN3JZNEY.mjs} +8 -5
  25. package/dist/lib/node-esm/chunk-EN3JZNEY.mjs.map +7 -0
  26. package/dist/lib/node-esm/chunk-HSLMI22Q.mjs +11 -0
  27. package/dist/lib/node-esm/chunk-HSLMI22Q.mjs.map +7 -0
  28. package/dist/lib/node-esm/index.mjs +55 -71
  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 -3
  32. package/dist/lib/node-esm/react-surface-BDRG4ZLM.mjs +39 -0
  33. package/dist/lib/node-esm/react-surface-BDRG4ZLM.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/Chart/Chart.d.ts.map +1 -1
  44. package/dist/types/src/components/Chart/Chart.stories.d.ts +8 -4
  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 +8 -4
  48. package/dist/types/src/components/Globe/Globe.stories.d.ts.map +1 -1
  49. package/dist/types/src/components/Graph/D3ForceGraph.d.ts +3 -3
  50. package/dist/types/src/components/Graph/D3ForceGraph.d.ts.map +1 -1
  51. package/dist/types/src/components/Graph/D3ForceGraph.stories.d.ts +13 -4
  52. package/dist/types/src/components/Graph/D3ForceGraph.stories.d.ts.map +1 -1
  53. package/dist/types/src/components/Graph/ForceGraph.stories.d.ts +13 -4
  54. package/dist/types/src/components/Graph/ForceGraph.stories.d.ts.map +1 -1
  55. package/dist/types/src/components/Graph/adapter.d.ts +1 -1
  56. package/dist/types/src/components/Graph/adapter.d.ts.map +1 -1
  57. package/dist/types/src/components/Graph/testing.d.ts +1 -1
  58. package/dist/types/src/components/Graph/testing.d.ts.map +1 -1
  59. package/dist/types/src/components/Tree/Tree.d.ts.map +1 -1
  60. package/dist/types/src/components/Tree/Tree.stories.d.ts +13 -16
  61. package/dist/types/src/components/Tree/Tree.stories.d.ts.map +1 -1
  62. package/dist/types/src/components/Tree/testing/generator.d.ts.map +1 -1
  63. package/dist/types/src/components/Tree/types/tree.d.ts +19 -17
  64. package/dist/types/src/components/Tree/types/tree.d.ts.map +1 -1
  65. package/dist/types/src/components/Tree/types/types.d.ts +1 -1
  66. package/dist/types/src/components/Tree/types/types.d.ts.map +1 -1
  67. package/dist/types/src/components/index.d.ts +0 -4
  68. package/dist/types/src/components/index.d.ts.map +1 -1
  69. package/dist/types/src/containers/ExplorerContainer/ExplorerContainer.d.ts +6 -0
  70. package/dist/types/src/containers/ExplorerContainer/ExplorerContainer.d.ts.map +1 -0
  71. package/dist/types/src/containers/ExplorerContainer/index.d.ts +3 -0
  72. package/dist/types/src/containers/ExplorerContainer/index.d.ts.map +1 -0
  73. package/dist/types/src/containers/index.d.ts +3 -0
  74. package/dist/types/src/containers/index.d.ts.map +1 -0
  75. package/dist/types/src/hooks/useGraphModel.d.ts +2 -2
  76. package/dist/types/src/hooks/useGraphModel.d.ts.map +1 -1
  77. package/dist/types/src/meta.d.ts +2 -3
  78. package/dist/types/src/meta.d.ts.map +1 -1
  79. package/dist/types/src/translations.d.ts +26 -5
  80. package/dist/types/src/translations.d.ts.map +1 -1
  81. package/dist/types/src/types/ExplorerAction.d.ts +6 -0
  82. package/dist/types/src/types/ExplorerAction.d.ts.map +1 -0
  83. package/dist/types/src/types/Graph.d.ts +23 -0
  84. package/dist/types/src/types/Graph.d.ts.map +1 -0
  85. package/dist/types/src/types/index.d.ts +2 -2
  86. package/dist/types/src/types/index.d.ts.map +1 -1
  87. package/dist/types/tsconfig.tsbuildinfo +1 -1
  88. package/package.json +51 -44
  89. package/src/ExplorerPlugin.tsx +30 -52
  90. package/src/capabilities/index.ts +1 -4
  91. package/src/capabilities/react-surface/index.ts +7 -0
  92. package/src/capabilities/react-surface/react-surface.tsx +31 -0
  93. package/src/components/Chart/Chart.stories.tsx +10 -8
  94. package/src/components/Chart/Chart.tsx +1 -1
  95. package/src/components/Globe/Globe.stories.tsx +14 -12
  96. package/src/components/Globe/Globe.tsx +1 -1
  97. package/src/components/Graph/D3ForceGraph.stories.tsx +43 -24
  98. package/src/components/Graph/D3ForceGraph.tsx +10 -9
  99. package/src/components/Graph/ForceGraph.stories.tsx +43 -24
  100. package/src/components/Graph/ForceGraph.tsx +4 -4
  101. package/src/components/Graph/adapter.ts +14 -8
  102. package/src/components/Graph/testing.ts +13 -10
  103. package/src/components/Tree/Tree.stories.tsx +29 -22
  104. package/src/components/Tree/Tree.tsx +11 -6
  105. package/src/components/Tree/testing/generator.ts +4 -2
  106. package/src/components/Tree/types/tree.test.ts +7 -4
  107. package/src/components/Tree/types/tree.ts +42 -21
  108. package/src/components/Tree/types/types.ts +1 -1
  109. package/src/components/index.ts +0 -4
  110. package/src/containers/ExplorerContainer/ExplorerContainer.tsx +53 -0
  111. package/src/containers/ExplorerContainer/index.ts +7 -0
  112. package/src/containers/index.ts +7 -0
  113. package/src/hooks/useGraphModel.ts +9 -5
  114. package/src/meta.ts +9 -6
  115. package/src/translations.ts +7 -2
  116. package/src/types/ExplorerAction.ts +20 -0
  117. package/src/types/Graph.ts +45 -0
  118. package/src/types/index.ts +2 -2
  119. package/dist/lib/browser/ExplorerContainer-OGHSHZD5.mjs +0 -37
  120. package/dist/lib/browser/ExplorerContainer-OGHSHZD5.mjs.map +0 -7
  121. package/dist/lib/browser/chunk-EF4BFHTI.mjs +0 -38
  122. package/dist/lib/browser/chunk-EF4BFHTI.mjs.map +0 -7
  123. package/dist/lib/browser/chunk-J2BBZOSF.mjs +0 -187
  124. package/dist/lib/browser/chunk-J2BBZOSF.mjs.map +0 -7
  125. package/dist/lib/browser/chunk-OAOY7SHY.mjs +0 -30
  126. package/dist/lib/browser/chunk-OAOY7SHY.mjs.map +0 -7
  127. package/dist/lib/browser/chunk-UL5EDJPE.mjs +0 -21
  128. package/dist/lib/browser/chunk-UL5EDJPE.mjs.map +0 -7
  129. package/dist/lib/browser/intent-resolver-XH2UO2FM.mjs +0 -24
  130. package/dist/lib/browser/intent-resolver-XH2UO2FM.mjs.map +0 -7
  131. package/dist/lib/browser/react-surface-65VQ42HX.mjs +0 -31
  132. package/dist/lib/browser/react-surface-65VQ42HX.mjs.map +0 -7
  133. package/dist/lib/node-esm/ExplorerContainer-6ON5NA2P.mjs +0 -38
  134. package/dist/lib/node-esm/ExplorerContainer-6ON5NA2P.mjs.map +0 -7
  135. package/dist/lib/node-esm/chunk-4VMSNXYL.mjs +0 -189
  136. package/dist/lib/node-esm/chunk-4VMSNXYL.mjs.map +0 -7
  137. package/dist/lib/node-esm/chunk-PIAXA43R.mjs.map +0 -7
  138. package/dist/lib/node-esm/chunk-PPBUWC7F.mjs +0 -32
  139. package/dist/lib/node-esm/chunk-PPBUWC7F.mjs.map +0 -7
  140. package/dist/lib/node-esm/chunk-VKCOKQRG.mjs +0 -39
  141. package/dist/lib/node-esm/chunk-VKCOKQRG.mjs.map +0 -7
  142. package/dist/lib/node-esm/intent-resolver-AGBBNA67.mjs +0 -25
  143. package/dist/lib/node-esm/intent-resolver-AGBBNA67.mjs.map +0 -7
  144. package/dist/lib/node-esm/react-surface-IJIMYAST.mjs +0 -32
  145. package/dist/lib/node-esm/react-surface-IJIMYAST.mjs.map +0 -7
  146. package/dist/types/src/capabilities/intent-resolver.d.ts +0 -4
  147. package/dist/types/src/capabilities/intent-resolver.d.ts.map +0 -1
  148. package/dist/types/src/capabilities/react-surface.d.ts +0 -4
  149. package/dist/types/src/capabilities/react-surface.d.ts.map +0 -1
  150. package/dist/types/src/components/ExplorerContainer.d.ts +0 -9
  151. package/dist/types/src/components/ExplorerContainer.d.ts.map +0 -1
  152. package/dist/types/src/types/schema.d.ts +0 -12
  153. package/dist/types/src/types/schema.d.ts.map +0 -1
  154. package/dist/types/src/types/types.d.ts +0 -18
  155. package/dist/types/src/types/types.d.ts.map +0 -1
  156. package/src/capabilities/intent-resolver.ts +0 -19
  157. package/src/capabilities/react-surface.tsx +0 -23
  158. package/src/components/ExplorerContainer.tsx +0 -36
  159. package/src/types/schema.ts +0 -16
  160. package/src/types/types.ts +0 -21
@@ -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
@@ -10975,10 +11136,10 @@ var TidyTree = (s, data, options) => {
10975
11136
  var TidyTree_default = TidyTree;
10976
11137
 
10977
11138
  // src/components/Tree/types/tree.ts
10978
- import { Schema } from "effect";
10979
- import { Key, Obj, Type } from "@dxos/echo";
11139
+ import * as Schema from "effect/Schema";
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
- var __dxlog_file = "/__w/dxos/dxos/packages/plugins/plugin-explorer/src/components/Tree/types/tree.ts";
10982
11143
  var TreeNodeType = Schema.Struct({
10983
11144
  id: Key.ObjectId,
10984
11145
  children: Schema.mutable(Schema.Array(Key.ObjectId)),
@@ -10986,7 +11147,7 @@ var TreeNodeType = Schema.Struct({
10986
11147
  key: Schema.String,
10987
11148
  value: Schema.Any
10988
11149
  })),
10989
- ref: Schema.optional(Type.Ref(Type.Expando))
11150
+ ref: Schema.optional(Ref.Ref(TestSchema.Expando))
10990
11151
  }).pipe(Schema.mutable);
10991
11152
  var TreeType = Schema.Struct({
10992
11153
  root: Key.ObjectId,
@@ -10994,249 +11155,10 @@ var TreeType = Schema.Struct({
10994
11155
  key: Key.ObjectId,
10995
11156
  value: TreeNodeType
10996
11157
  }))
10997
- }).pipe(Type.Obj({
10998
- typename: "dxos.org/type/Tree",
11158
+ }).pipe(Type.object({
11159
+ typename: "org.dxos.type.tree",
10999
11160
  version: "0.1.0"
11000
11161
  }));
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
11162
 
11241
11163
  // src/components/Tree/types/types.ts
11242
11164
  var mapGraphToTreeData = (model, maxDepth = 8) => {
@@ -11264,68 +11186,95 @@ var renderers = /* @__PURE__ */ new Map([
11264
11186
  HierarchicalEdgeBundling_default
11265
11187
  ]
11266
11188
  ]);
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
- }
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);
11305
11226
  }
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
- }
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
+ }));
11318
11238
  };
11319
11239
 
11320
- // src/components/index.ts
11321
- import { lazy } from "react";
11322
- var ExplorerContainer = lazy(() => import("./ExplorerContainer-6ON5NA2P.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
+ };
11323
11270
 
11324
11271
  export {
11325
11272
  Chart,
11326
11273
  Globe,
11274
+ D3ForceGraph,
11275
+ ForceGraph,
11327
11276
  defaultTreeLayoutSlots,
11328
- Tree2 as Tree,
11329
- ExplorerContainer
11277
+ Tree,
11278
+ useGraphModel
11330
11279
  };
11331
- //# sourceMappingURL=chunk-S5A2EUSJ.mjs.map
11280
+ //# sourceMappingURL=chunk-3Z2WBI3N.mjs.map