@dxos/plugin-explorer 0.8.0 → 0.8.1-main.ae460ac

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 (49) hide show
  1. package/dist/lib/browser/{ExplorerContainer-GJTCBEM4.mjs → ExplorerContainer-T5CTMBIS.mjs} +2 -2
  2. package/dist/lib/{node-esm/chunk-BRJI3QC2.mjs → browser/chunk-SU3K2HL7.mjs} +240 -3
  3. package/dist/lib/{node-esm/chunk-BRJI3QC2.mjs.map → browser/chunk-SU3K2HL7.mjs.map} +4 -4
  4. package/dist/lib/browser/chunk-V23FAKIX.mjs +205 -0
  5. package/dist/lib/browser/chunk-V23FAKIX.mjs.map +7 -0
  6. package/dist/lib/browser/index.mjs +7 -7
  7. package/dist/lib/browser/meta.json +1 -1
  8. package/dist/lib/browser/{react-surface-3X2V3VPN.mjs → react-surface-Q7OT6GXC.mjs} +3 -3
  9. package/dist/lib/node/{ExplorerContainer-RJT54IOS.cjs → ExplorerContainer-SO5XAXFS.cjs} +6 -6
  10. package/dist/lib/node/chunk-6GTOKVKH.cjs +236 -0
  11. package/dist/lib/node/chunk-6GTOKVKH.cjs.map +7 -0
  12. package/dist/lib/node/{chunk-VSACDC6F.cjs → chunk-CQYBCGC4.cjs} +234 -8
  13. package/dist/lib/node/chunk-CQYBCGC4.cjs.map +7 -0
  14. package/dist/lib/node/index.cjs +10 -10
  15. package/dist/lib/node/meta.json +1 -1
  16. package/dist/lib/node/{react-surface-36YIY7NA.cjs → react-surface-5G52HSJW.cjs} +7 -7
  17. package/dist/lib/node-esm/{ExplorerContainer-TM3VIXVK.mjs → ExplorerContainer-DTUTEZLK.mjs} +2 -2
  18. package/dist/lib/{browser/chunk-S3QNIEBS.mjs → node-esm/chunk-4IST6Y3Z.mjs} +242 -2
  19. package/dist/lib/{browser/chunk-S3QNIEBS.mjs.map → node-esm/chunk-4IST6Y3Z.mjs.map} +4 -4
  20. package/dist/lib/node-esm/chunk-Q2IQDIKJ.mjs +207 -0
  21. package/dist/lib/node-esm/chunk-Q2IQDIKJ.mjs.map +7 -0
  22. package/dist/lib/node-esm/index.mjs +7 -7
  23. package/dist/lib/node-esm/meta.json +1 -1
  24. package/dist/lib/node-esm/{react-surface-YDY7IBMY.mjs → react-surface-QSQVINGP.mjs} +3 -3
  25. package/dist/types/src/components/Graph/Graph.d.ts +0 -3
  26. package/dist/types/src/components/Graph/Graph.d.ts.map +1 -1
  27. package/dist/types/src/components/Graph/Graph.stories.d.ts +1 -1
  28. package/dist/types/src/components/Graph/Graph.stories.d.ts.map +1 -1
  29. package/dist/types/src/components/Graph/graph-model.d.ts.map +1 -1
  30. package/dist/types/src/components/Tree/types.d.ts +1 -1
  31. package/dist/types/src/components/Tree/types.d.ts.map +1 -1
  32. package/package.json +24 -25
  33. package/src/components/Graph/Graph.stories.tsx +2 -2
  34. package/src/components/Graph/Graph.tsx +15 -142
  35. package/src/components/Graph/graph-model.ts +2 -0
  36. package/src/components/Tree/types.ts +2 -1
  37. package/dist/lib/browser/chunk-YQL7YE6N.mjs +0 -546
  38. package/dist/lib/browser/chunk-YQL7YE6N.mjs.map +0 -7
  39. package/dist/lib/node/chunk-VSACDC6F.cjs.map +0 -7
  40. package/dist/lib/node/chunk-YH4QYCZH.cjs +0 -567
  41. package/dist/lib/node/chunk-YH4QYCZH.cjs.map +0 -7
  42. package/dist/lib/node-esm/chunk-3KRWHGBM.mjs +0 -548
  43. package/dist/lib/node-esm/chunk-3KRWHGBM.mjs.map +0 -7
  44. /package/dist/lib/browser/{ExplorerContainer-GJTCBEM4.mjs.map → ExplorerContainer-T5CTMBIS.mjs.map} +0 -0
  45. /package/dist/lib/browser/{react-surface-3X2V3VPN.mjs.map → react-surface-Q7OT6GXC.mjs.map} +0 -0
  46. /package/dist/lib/node/{ExplorerContainer-RJT54IOS.cjs.map → ExplorerContainer-SO5XAXFS.cjs.map} +0 -0
  47. /package/dist/lib/node/{react-surface-36YIY7NA.cjs.map → react-surface-5G52HSJW.cjs.map} +0 -0
  48. /package/dist/lib/node-esm/{ExplorerContainer-TM3VIXVK.mjs.map → ExplorerContainer-DTUTEZLK.mjs.map} +0 -0
  49. /package/dist/lib/node-esm/{react-surface-YDY7IBMY.mjs.map → react-surface-QSQVINGP.mjs.map} +0 -0
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  Graph
3
- } from "./chunk-YQL7YE6N.mjs";
3
+ } from "./chunk-V23FAKIX.mjs";
4
4
 
5
5
  // packages/plugins/experimental/plugin-explorer/src/components/ExplorerContainer.tsx
6
6
  import React from "react";
@@ -25,4 +25,4 @@ var ExplorerContainer_default = ExplorerContainer;
25
25
  export {
26
26
  ExplorerContainer_default as default
27
27
  };
28
- //# sourceMappingURL=ExplorerContainer-GJTCBEM4.mjs.map
28
+ //# sourceMappingURL=ExplorerContainer-T5CTMBIS.mjs.map
@@ -1,4 +1,6 @@
1
- import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
1
+ import {
2
+ SpaceGraphModel
3
+ } from "./chunk-V23FAKIX.mjs";
2
4
 
3
5
  // packages/plugins/experimental/plugin-explorer/src/components/Chart/Chart.tsx
4
6
  import * as Plot from "@observablehq/plot";
@@ -10822,13 +10824,248 @@ var Globe = ({ items = [], accessor, projection = "orthographic", options = defa
10822
10824
  });
10823
10825
  };
10824
10826
 
10827
+ // packages/plugins/experimental/plugin-explorer/src/components/Tree/Tree.tsx
10828
+ import React3, { useEffect as useEffect3, useState } from "react";
10829
+ import { useResizeDetector as useResizeDetector3 } from "react-resize-detector";
10830
+ import { createSvgContext, SVG, SVGRoot } from "@dxos/gem-core";
10831
+ import { useAsyncState } from "@dxos/react-ui";
10832
+
10833
+ // packages/plugins/experimental/plugin-explorer/src/components/Tree/layout/HierarchicalEdgeBundling.ts
10834
+ import * as d3 from "d3";
10835
+ var HierarchicalEdgeBundling = (s, data, options) => {
10836
+ const svg = d3.select(s);
10837
+ svg.selectAll("*").remove();
10838
+ const { radius = 600, padding = 100, slots } = options;
10839
+ const root = d3.hierarchy(flatten(data));
10840
+ const tree3 = d3.cluster().size([
10841
+ 2 * Math.PI,
10842
+ radius - padding
10843
+ ]);
10844
+ const layout = tree3(addLinks(root));
10845
+ const node = svg.append("g").selectAll().data(layout.leaves()).join("g").attr("transform", (d) => `rotate(${d.x * (180 / Math.PI) - 90}) translate(${d.y},0)`).append("text").attr("class", slots?.text ?? "").attr("dy", "0.31em").attr("x", (d) => d.x < Math.PI ? 6 : -6).attr("text-anchor", (d) => d.x < Math.PI ? "start" : "end").attr("transform", (d) => d.x >= Math.PI ? "rotate(180)" : null).call((text) => text.text((d) => d.data.id.slice(0, 8)));
10846
+ const line = d3.lineRadial().curve(d3.curveBundle.beta(0.85)).radius((d) => d.y).angle((d) => d.x);
10847
+ const links = svg.append("g").selectAll().data(layout.leaves().flatMap((leaf) => leaf.outgoing)).join("path").style("mix-blend-mode", "multiply").attr("class", slots?.path ?? "").attr("d", ([i, o]) => {
10848
+ return line(i.path(o));
10849
+ }).each(function(d) {
10850
+ d.path = this;
10851
+ });
10852
+ };
10853
+ var addLinks = (root) => {
10854
+ const nodes = new Map(root.descendants().map((d) => [
10855
+ d.data.id,
10856
+ d
10857
+ ]));
10858
+ const parents = root.descendants().reduce((map, d) => {
10859
+ if (d.children?.length) {
10860
+ map.set(d.data.id, d);
10861
+ }
10862
+ return map;
10863
+ }, /* @__PURE__ */ new Map());
10864
+ for (const d of root.leaves()) {
10865
+ const parent = parents.get(d.data.id);
10866
+ if (parent) {
10867
+ d.outgoing = parent.data.children?.slice(1).map((child) => {
10868
+ return [
10869
+ d,
10870
+ nodes.get(child.id)
10871
+ ];
10872
+ }) ?? [];
10873
+ } else {
10874
+ d.outgoing = [];
10875
+ }
10876
+ }
10877
+ return root;
10878
+ };
10879
+ var flatten = (node) => {
10880
+ const clone = {
10881
+ id: node.id
10882
+ };
10883
+ if (node.children?.length) {
10884
+ const children = node.children.map((child) => flatten(child));
10885
+ clone.children = [
10886
+ {
10887
+ id: node.id
10888
+ },
10889
+ ...children
10890
+ ];
10891
+ }
10892
+ return clone;
10893
+ };
10894
+ var HierarchicalEdgeBundling_default = HierarchicalEdgeBundling;
10895
+
10896
+ // packages/plugins/experimental/plugin-explorer/src/components/Tree/layout/RadialTree.ts
10897
+ import * as d32 from "d3";
10898
+ var RadialTree = (s, data, options) => {
10899
+ const svg = d32.select(s);
10900
+ svg.selectAll("*").remove();
10901
+ const { label, radius = 400, r = 4, slots } = options;
10902
+ const arc = 2 * Math.PI;
10903
+ const root = d32.hierarchy(data);
10904
+ const descendants = root.descendants();
10905
+ const getLabel = label === null ? null : descendants.map((d) => label(d.data));
10906
+ const layout = d32.tree().size([
10907
+ arc,
10908
+ radius
10909
+ ]).separation((a, b) => (a.parent === b.parent ? 1 : 2) / a.depth);
10910
+ layout(root);
10911
+ svg.append("g").selectAll("path").data(root.links()).join("path").attr("class", slots?.path ?? "").attr("d", d32.linkRadial().angle((d) => d.x + Math.PI / 2).radius((d) => d.y));
10912
+ const node = svg.append("g").selectAll("a").data(root.descendants()).join("a").attr("transform", (d) => `rotate(${d.x * 180 / Math.PI}) translate(${d.y},0)`);
10913
+ node.append("circle").attr("class", slots?.node ?? "").attr("r", r);
10914
+ if (getLabel) {
10915
+ node.append("text").attr("transform", (d) => `rotate(${d.x >= Math.PI ? 180 : 0})`).attr("dy", "0.32em").attr("x", (d) => d.x < Math.PI === !d.children ? 6 : -6).attr("text-anchor", (d) => d.x < Math.PI === !d.children ? "start" : "end").attr("class", slots?.text ?? "").text((d, i) => getLabel[i]);
10916
+ }
10917
+ return svg.node();
10918
+ };
10919
+ var RadialTree_default = RadialTree;
10920
+
10921
+ // packages/plugins/experimental/plugin-explorer/src/components/Tree/layout/TidyTree.ts
10922
+ import * as d33 from "d3";
10923
+ var TidyTree = (s, data, options) => {
10924
+ const svg = d33.select(s);
10925
+ svg.selectAll("*").remove();
10926
+ const { label, width, height, r = 4, padding = 4, margin = 60, slots } = options;
10927
+ const root = d33.hierarchy(data);
10928
+ const descendants = root.descendants();
10929
+ const getLabel = label == null ? null : descendants.map((d) => label(d.data));
10930
+ const dx = 16;
10931
+ const dy = width / (root.height + padding);
10932
+ const layout = d33.tree().nodeSize([
10933
+ dx,
10934
+ dy
10935
+ ]);
10936
+ layout(root);
10937
+ let x0 = Infinity;
10938
+ let x1 = -x0;
10939
+ let y0 = Infinity;
10940
+ let y1 = -y0;
10941
+ root.each((d) => {
10942
+ if (d.x > x1) {
10943
+ x1 = d.x;
10944
+ }
10945
+ if (d.x < x0) {
10946
+ x0 = d.x;
10947
+ }
10948
+ if (d.y > y1) {
10949
+ y1 = d.y;
10950
+ }
10951
+ if (d.y < y0) {
10952
+ y0 = d.y;
10953
+ }
10954
+ });
10955
+ const sx = Math.min(2, Math.max(1, (height - margin * 2) / (x1 - x0)));
10956
+ const oy = -(width - (y1 - y0)) / 2;
10957
+ svg.append("g").selectAll("path").data(root.links()).join("path").attr("class", slots?.path ?? "").attr("d", d33.link(d33.curveBumpX).x((d) => d.y + oy).y((d) => d.x * sx));
10958
+ const node = svg.append("g").selectAll("a").data(root.descendants()).join("a").attr("transform", (d) => `translate(${d.y + oy},${d.x * sx})`);
10959
+ node.append("circle").attr("class", slots?.node ?? "").attr("r", r);
10960
+ if (getLabel) {
10961
+ node.append("text").attr("dy", "0.32em").attr("x", (d) => d.children ? -6 : 6).attr("text-anchor", (d) => d.children ? "end" : "start").attr("class", slots?.text ?? "").text((d, i) => getLabel[i]);
10962
+ }
10963
+ };
10964
+ var TidyTree_default = TidyTree;
10965
+
10966
+ // packages/plugins/experimental/plugin-explorer/src/components/Tree/types.ts
10967
+ var mapGraphToTreeData = (model, maxDepth = 8) => {
10968
+ const mapNode = (node, depth = 0) => {
10969
+ const treeNode = {
10970
+ id: model.idAccessor(node),
10971
+ label: model.idAccessor(node).slice(0, 8)
10972
+ };
10973
+ const links = model.graph.links.filter((link2) => link2.source === treeNode.id);
10974
+ if (depth < maxDepth) {
10975
+ treeNode.children = links.map((link2) => mapNode(model.graph.nodes.find((node2) => model.idAccessor(node2) === link2.target), depth + 1));
10976
+ }
10977
+ return treeNode;
10978
+ };
10979
+ let data;
10980
+ if (model.selected) {
10981
+ const node = model.graph.nodes.find((node2) => model.idAccessor(node2) === model.selected);
10982
+ if (node) {
10983
+ data = mapNode(node);
10984
+ }
10985
+ }
10986
+ return data;
10987
+ };
10988
+
10989
+ // packages/plugins/experimental/plugin-explorer/src/components/Tree/Tree.tsx
10990
+ var defaultTreeLayoutSlots = {
10991
+ node: "fill-blue-600",
10992
+ path: "fill-none stroke-blue-400 stroke-[0.5px]",
10993
+ text: "stroke-[0.5px] stroke-neutral-700 text-xs"
10994
+ };
10995
+ var renderers = /* @__PURE__ */ new Map([
10996
+ [
10997
+ "tidy",
10998
+ TidyTree_default
10999
+ ],
11000
+ [
11001
+ "radial",
11002
+ RadialTree_default
11003
+ ],
11004
+ [
11005
+ "edge",
11006
+ HierarchicalEdgeBundling_default
11007
+ ]
11008
+ ]);
11009
+ var Tree = ({ space, selected, variant = "tidy", onNodeClick }) => {
11010
+ const [model] = useAsyncState(async () => space ? new SpaceGraphModel().open(space, selected) : void 0, [
11011
+ space,
11012
+ selected
11013
+ ]);
11014
+ const [tree3, setTree] = useState();
11015
+ useEffect3(() => {
11016
+ return model?.subscribe(() => {
11017
+ const tree4 = mapGraphToTreeData(model);
11018
+ setTree(tree4);
11019
+ }, true);
11020
+ }, [
11021
+ model
11022
+ ]);
11023
+ const context = createSvgContext();
11024
+ const { ref, width = 0, height = 0 } = useResizeDetector3();
11025
+ useEffect3(() => {
11026
+ if (width && height) {
11027
+ const size = Math.min(width, height);
11028
+ const radius = size * 0.4;
11029
+ const options = {
11030
+ // TODO(burdon): Type.
11031
+ label: (d) => d.label ?? d.id,
11032
+ width,
11033
+ height,
11034
+ radius,
11035
+ marginLeft: (width - radius * 2) / 2,
11036
+ marginRight: (width - radius * 2) / 2,
11037
+ marginTop: (height - radius * 2) / 2,
11038
+ marginBottom: (height - radius * 2) / 2,
11039
+ slots: defaultTreeLayoutSlots
11040
+ };
11041
+ if (tree3) {
11042
+ const renderer = renderers.get(variant);
11043
+ renderer?.(context.ref.current, tree3, options);
11044
+ }
11045
+ }
11046
+ }, [
11047
+ tree3,
11048
+ width,
11049
+ height
11050
+ ]);
11051
+ return /* @__PURE__ */ React3.createElement("div", {
11052
+ ref,
11053
+ className: "flex grow overflow-hidden",
11054
+ onClick: () => onNodeClick?.()
11055
+ }, /* @__PURE__ */ React3.createElement(SVGRoot, {
11056
+ context
11057
+ }, /* @__PURE__ */ React3.createElement(SVG, null)));
11058
+ };
11059
+
10825
11060
  // packages/plugins/experimental/plugin-explorer/src/components/index.ts
10826
11061
  import { lazy } from "react";
10827
- var ExplorerContainer = lazy(() => import("./ExplorerContainer-TM3VIXVK.mjs"));
11062
+ var ExplorerContainer = lazy(() => import("./ExplorerContainer-T5CTMBIS.mjs"));
10828
11063
 
10829
11064
  export {
10830
11065
  Chart,
10831
11066
  Globe,
11067
+ defaultTreeLayoutSlots,
11068
+ Tree,
10832
11069
  ExplorerContainer
10833
11070
  };
10834
- //# sourceMappingURL=chunk-BRJI3QC2.mjs.map
11071
+ //# sourceMappingURL=chunk-SU3K2HL7.mjs.map