@dxos/react-ui-graph 0.9.1-main.c7dcc2e112 → 0.10.0

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 (57) hide show
  1. package/dist/lib/browser/index.mjs +753 -15
  2. package/dist/lib/browser/index.mjs.map +4 -4
  3. package/dist/lib/browser/meta.json +1 -1
  4. package/dist/lib/node-esm/index.mjs +753 -15
  5. package/dist/lib/node-esm/index.mjs.map +4 -4
  6. package/dist/lib/node-esm/meta.json +1 -1
  7. package/dist/types/src/components/Graph/Graph.stories.d.ts +2 -2
  8. package/dist/types/src/components/Graph/Graph.stories.d.ts.map +1 -1
  9. package/dist/types/src/components/SVG/SVG.d.ts +1 -1
  10. package/dist/types/src/components/SVG/SVG.d.ts.map +1 -1
  11. package/dist/types/src/components/Tree/Tree.d.ts +26 -0
  12. package/dist/types/src/components/Tree/Tree.d.ts.map +1 -0
  13. package/dist/types/src/components/Tree/index.d.ts +4 -0
  14. package/dist/types/src/components/Tree/index.d.ts.map +1 -0
  15. package/dist/types/src/components/Tree/layout/HierarchicalEdgeBundling.d.ts +40 -0
  16. package/dist/types/src/components/Tree/layout/HierarchicalEdgeBundling.d.ts.map +1 -0
  17. package/dist/types/src/components/Tree/layout/RadialTree.d.ts +37 -0
  18. package/dist/types/src/components/Tree/layout/RadialTree.d.ts.map +1 -0
  19. package/dist/types/src/components/Tree/layout/TidyTree.d.ts +26 -0
  20. package/dist/types/src/components/Tree/layout/TidyTree.d.ts.map +1 -0
  21. package/dist/types/src/components/Tree/layout/hierarchy.d.ts +17 -0
  22. package/dist/types/src/components/Tree/layout/hierarchy.d.ts.map +1 -0
  23. package/dist/types/src/components/Tree/layout/index.d.ts +7 -0
  24. package/dist/types/src/components/Tree/layout/index.d.ts.map +1 -0
  25. package/dist/types/src/components/Tree/layout/slots.d.ts +13 -0
  26. package/dist/types/src/components/Tree/layout/slots.d.ts.map +1 -0
  27. package/dist/types/src/components/Tree/layout/useContainerSize.d.ts +15 -0
  28. package/dist/types/src/components/Tree/layout/useContainerSize.d.ts.map +1 -0
  29. package/dist/types/src/components/Tree/types.d.ts +11 -0
  30. package/dist/types/src/components/Tree/types.d.ts.map +1 -0
  31. package/dist/types/src/components/index.d.ts +1 -0
  32. package/dist/types/src/components/index.d.ts.map +1 -1
  33. package/dist/types/src/fx/fx.stories.d.ts +2 -2
  34. package/dist/types/src/fx/fx.stories.d.ts.map +1 -1
  35. package/dist/types/src/graph/projector/graph-tree-projector.d.ts +40 -0
  36. package/dist/types/src/graph/projector/graph-tree-projector.d.ts.map +1 -0
  37. package/dist/types/src/graph/projector/index.d.ts +1 -0
  38. package/dist/types/src/graph/projector/index.d.ts.map +1 -1
  39. package/dist/types/tsconfig.tsbuildinfo +1 -1
  40. package/package.json +21 -22
  41. package/src/components/Graph/Graph.stories.tsx +2 -2
  42. package/src/components/SVG/SVG.tsx +1 -1
  43. package/src/components/Tree/Tree.tsx +85 -0
  44. package/src/components/Tree/index.ts +7 -0
  45. package/src/components/Tree/layout/HierarchicalEdgeBundling.tsx +332 -0
  46. package/src/components/Tree/layout/RadialTree.tsx +240 -0
  47. package/src/components/Tree/layout/TidyTree.tsx +246 -0
  48. package/src/components/Tree/layout/hierarchy.ts +32 -0
  49. package/src/components/Tree/layout/index.ts +10 -0
  50. package/src/components/Tree/layout/slots.ts +25 -0
  51. package/src/components/Tree/layout/useContainerSize.ts +43 -0
  52. package/src/components/Tree/types.ts +14 -0
  53. package/src/components/index.ts +1 -0
  54. package/src/fx/fx.stories.tsx +3 -3
  55. package/src/graph/projector/graph-bundle-projector.ts +1 -1
  56. package/src/graph/projector/graph-tree-projector.ts +251 -0
  57. package/src/graph/projector/index.ts +1 -0
@@ -8,7 +8,7 @@ import {
8
8
  // src/components/Graph/Graph.tsx
9
9
  import React, { forwardRef, useEffect as useEffect3, useImperativeHandle, useMemo as useMemo3, useRef as useRef3 } from "react";
10
10
  import { combine } from "@dxos/async";
11
- import { log as log11 } from "@dxos/log";
11
+ import { log as log12 } from "@dxos/log";
12
12
  import { mx } from "@dxos/ui-theme";
13
13
 
14
14
  // src/graph/markers.ts
@@ -63,7 +63,7 @@ var createMarkers = ({ arrowSize = 12 } = {}) => (group) => {
63
63
  };
64
64
 
65
65
  // src/graph/projector/graph-bundle-projector.ts
66
- import { cluster as d3Cluster, curveBundle, hierarchy, lineRadial } from "d3";
66
+ import { curveBundle, cluster as d3Cluster, hierarchy, lineRadial } from "d3";
67
67
  import { log as log2 } from "@dxos/log";
68
68
 
69
69
  // src/graph/projector/graph-radial-projector.ts
@@ -2277,10 +2277,212 @@ var GraphSwarmProjector = class extends GraphProjector {
2277
2277
  }
2278
2278
  };
2279
2279
 
2280
+ // src/graph/projector/graph-tree-projector.ts
2281
+ import { tree as d3Tree, hierarchy as hierarchy4, linkHorizontal } from "d3";
2282
+ import { log as log10 } from "@dxos/log";
2283
+ var __dxlog_file12 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/projector/graph-tree-projector.ts";
2284
+ var TREE_NODE_TYPE_ROOT = "tree-root";
2285
+ var TREE_NODE_TYPE_NODE = "tree-node";
2286
+ var TREE_NODE_TYPE_INBOUND = "tree-inbound";
2287
+ var HIER_EDGE_PREFIX3 = "__tree_hier__:";
2288
+ var linkPath3 = linkHorizontal().x((d) => d.x).y((d) => d.y);
2289
+ var GraphTreeProjector = class extends GraphRadialProjector {
2290
+ // Snapshots taken right after mergeData — doTreeLayout reads from these because it overwrites
2291
+ // layout.graph.edges with the synthesized hierarchy edges.
2292
+ #dataNodes = [];
2293
+ #dataEdges = [];
2294
+ #resizeCleanup;
2295
+ async onStart() {
2296
+ this.#resizeCleanup = this.context.resized.on(() => {
2297
+ if (this.#dataNodes.length) {
2298
+ this.doTreeLayout();
2299
+ this.emitUpdate("topology");
2300
+ this.animate();
2301
+ }
2302
+ });
2303
+ }
2304
+ async onStop() {
2305
+ this.#resizeCleanup?.();
2306
+ this.#resizeCleanup = void 0;
2307
+ await super.onStop();
2308
+ }
2309
+ onUpdate(graph) {
2310
+ log10("onUpdate", {
2311
+ graph: {
2312
+ nodes: graph?.nodes.length,
2313
+ edges: graph?.edges.length
2314
+ }
2315
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file12, L: 46, S: this });
2316
+ this.mergeData(graph);
2317
+ this.#dataNodes = [
2318
+ ...this.layout.graph.nodes
2319
+ ];
2320
+ this.#dataEdges = [
2321
+ ...this.layout.graph.edges
2322
+ ];
2323
+ this.doTreeLayout();
2324
+ this.emitUpdate("topology");
2325
+ this.animate();
2326
+ }
2327
+ onTickFrame(_t) {
2328
+ for (const edge of this.layout.graph.edges) {
2329
+ if (edge.type !== "hierarchy") {
2330
+ continue;
2331
+ }
2332
+ const { source, target } = edge;
2333
+ edge.path = linkPath3({
2334
+ source: {
2335
+ x: source.x ?? 0,
2336
+ y: source.y ?? 0
2337
+ },
2338
+ target: {
2339
+ x: target.x ?? 0,
2340
+ y: target.y ?? 0
2341
+ }
2342
+ }) ?? void 0;
2343
+ }
2344
+ }
2345
+ doTreeLayout() {
2346
+ if (!this.context.size) {
2347
+ return;
2348
+ }
2349
+ const dataNodes = this.#dataNodes;
2350
+ if (!dataNodes.length) {
2351
+ return;
2352
+ }
2353
+ const focusId = this.options.focus;
2354
+ const focusNode = focusId ? dataNodes.find((node) => node.id === focusId) : void 0;
2355
+ if (!focusNode) {
2356
+ this.doRadialLayout();
2357
+ return;
2358
+ }
2359
+ const nodesById = new Map(dataNodes.map((node) => [
2360
+ node.id,
2361
+ node
2362
+ ]));
2363
+ const makeDatum = (id) => ({
2364
+ id,
2365
+ node: nodesById.get(id)
2366
+ });
2367
+ const outgoing = /* @__PURE__ */ new Map();
2368
+ for (const edge of this.#dataEdges) {
2369
+ const list = outgoing.get(edge.source.id) ?? [];
2370
+ list.push(edge.target.id);
2371
+ outgoing.set(edge.source.id, list);
2372
+ }
2373
+ const rightChildren = /* @__PURE__ */ new Map();
2374
+ const visited = /* @__PURE__ */ new Set([
2375
+ focusId
2376
+ ]);
2377
+ let frontier = [
2378
+ focusId
2379
+ ];
2380
+ while (frontier.length) {
2381
+ const next = [];
2382
+ for (const id of frontier) {
2383
+ for (const target of outgoing.get(id) ?? []) {
2384
+ if (!visited.has(target)) {
2385
+ visited.add(target);
2386
+ const list = rightChildren.get(id) ?? [];
2387
+ list.push(target);
2388
+ rightChildren.set(id, list);
2389
+ next.push(target);
2390
+ }
2391
+ }
2392
+ }
2393
+ frontier = next;
2394
+ }
2395
+ const leftSources = [];
2396
+ for (const edge of this.#dataEdges) {
2397
+ const source = edge.source.id;
2398
+ if (edge.target.id === focusId && source !== focusId && !visited.has(source)) {
2399
+ visited.add(source);
2400
+ leftSources.push(source);
2401
+ }
2402
+ }
2403
+ const rightRoot = hierarchy4(makeDatum(focusId), (d) => (rightChildren.get(d.id) ?? []).map(makeDatum));
2404
+ const leftRoot = hierarchy4(makeDatum(focusId), (d) => d.id === focusId ? leftSources.map(makeDatum) : []);
2405
+ const { width } = this.context.size;
2406
+ const margin = this.options.margin ?? 80;
2407
+ const rowGap = this.options.rowGap ?? 28;
2408
+ const maxColumnGap = this.options.maxColumnGap ?? 300;
2409
+ const sideDepth = Math.max(1, rightRoot.height, leftRoot.height);
2410
+ const columnGap = Math.min(maxColumnGap, Math.max(0, (width / 2 - margin) / sideDepth));
2411
+ const layoutTree = d3Tree().nodeSize([
2412
+ rowGap,
2413
+ columnGap
2414
+ ]);
2415
+ const rightPoint = layoutTree(rightRoot);
2416
+ const leftPoint = layoutTree(leftRoot);
2417
+ const nodeR = this.options.nodeRadius ?? 6;
2418
+ const rootR = this.options.rootRadius ?? nodeR * 2;
2419
+ const placed = [];
2420
+ updateNode(focusNode, [
2421
+ 0,
2422
+ 0
2423
+ ], rootR);
2424
+ focusNode.type = TREE_NODE_TYPE_ROOT;
2425
+ placed.push(focusNode);
2426
+ const rightBreadth = rightPoint.x;
2427
+ rightPoint.each((d) => {
2428
+ if (d.data.id === focusId || !d.data.node) {
2429
+ return;
2430
+ }
2431
+ updateNode(d.data.node, [
2432
+ d.y,
2433
+ d.x - rightBreadth
2434
+ ], nodeR);
2435
+ d.data.node.type = TREE_NODE_TYPE_NODE;
2436
+ placed.push(d.data.node);
2437
+ });
2438
+ const leftBreadth = leftPoint.x;
2439
+ leftPoint.each((d) => {
2440
+ if (d.data.id === focusId || !d.data.node) {
2441
+ return;
2442
+ }
2443
+ updateNode(d.data.node, [
2444
+ -d.y,
2445
+ d.x - leftBreadth
2446
+ ], nodeR);
2447
+ d.data.node.type = TREE_NODE_TYPE_INBOUND;
2448
+ placed.push(d.data.node);
2449
+ });
2450
+ this.layout.graph.nodes = placed;
2451
+ const edges = [];
2452
+ const addLinks = (root, reverse = false) => {
2453
+ root.links().forEach((link) => {
2454
+ const parent = link.source.data;
2455
+ const child = link.target.data;
2456
+ const [from, to] = reverse ? [
2457
+ child,
2458
+ parent
2459
+ ] : [
2460
+ parent,
2461
+ child
2462
+ ];
2463
+ if (!from.node || !to.node) {
2464
+ return;
2465
+ }
2466
+ edges.push({
2467
+ id: `${HIER_EDGE_PREFIX3}${from.id}->${to.id}`,
2468
+ type: "hierarchy",
2469
+ source: from.node,
2470
+ target: to.node,
2471
+ data: void 0
2472
+ });
2473
+ });
2474
+ };
2475
+ addLinks(rightPoint);
2476
+ addLinks(leftPoint, true);
2477
+ this.layout.graph.edges = edges;
2478
+ this.onTickFrame(0);
2479
+ }
2480
+ };
2481
+
2280
2482
  // src/graph/renderer/graph-renderer.ts
2281
2483
  import { easeCubicOut, line as line2, polygonHull, select as select4 } from "d3";
2282
2484
  import * as Clipper from "js-clipper";
2283
- import { log as log10 } from "@dxos/log";
2485
+ import { log as log11 } from "@dxos/log";
2284
2486
 
2285
2487
  // src/graph/renderer/bullets.ts
2286
2488
  import { easeLinear, interpolate, select as select3 } from "d3";
@@ -2349,7 +2551,7 @@ var Renderer = class {
2349
2551
  };
2350
2552
 
2351
2553
  // src/graph/renderer/graph-renderer.ts
2352
- var __dxlog_file12 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/renderer/graph-renderer.ts";
2554
+ var __dxlog_file13 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/renderer/graph-renderer.ts";
2353
2555
  var createLine2 = line2();
2354
2556
  var EDGE_FADE_MS = 300;
2355
2557
  var NODE_HIDE_MS = 500;
@@ -2368,7 +2570,7 @@ var GraphRenderer = class extends Renderer {
2368
2570
  this.#firstRender = false;
2369
2571
  this.root.replaceChildren();
2370
2572
  }
2371
- log10("render", layout, { "~LogMeta": "~LogMeta", F: __dxlog_file12, L: 35, S: this });
2573
+ log11("render", layout, { "~LogMeta": "~LogMeta", F: __dxlog_file13, L: 35, S: this });
2372
2574
  const root = select4(this.root);
2373
2575
  if (layout.guides) {
2374
2576
  root.selectAll("g.dx-guides").data([
@@ -2579,9 +2781,9 @@ var updateNode2 = (group, options) => {
2579
2781
  }
2580
2782
  });
2581
2783
  } catch (error) {
2582
- log10.error("updateNode", {
2784
+ log11.error("updateNode", {
2583
2785
  error: error?.message
2584
- }, { "~LogMeta": "~LogMeta", F: __dxlog_file12, L: 303, S: void 0 });
2786
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file13, L: 303, S: void 0 });
2585
2787
  }
2586
2788
  }
2587
2789
  const groupOrTransition = options.transition ? group.transition(options.transition()) : group;
@@ -2632,9 +2834,9 @@ var updateEdge = (group, options, nodeGroup) => {
2632
2834
  }
2633
2835
  });
2634
2836
  } catch (error) {
2635
- log10.error("updateEdge", {
2837
+ log11.error("updateEdge", {
2636
2838
  error: error?.message
2637
- }, { "~LogMeta": "~LogMeta", F: __dxlog_file12, L: 371, S: void 0 });
2839
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file13, L: 371, S: void 0 });
2638
2840
  }
2639
2841
  const groupOrTransition = options.transition ? group.transition(options.transition()) : group;
2640
2842
  groupOrTransition.selectAll("path").attr("d", function() {
@@ -3130,7 +3332,7 @@ var useZoom = (options = defaultZoomOptions) => {
3130
3332
  };
3131
3333
 
3132
3334
  // src/components/Graph/Graph.tsx
3133
- var __dxlog_file13 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/components/Graph/Graph.tsx";
3335
+ var __dxlog_file14 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/components/Graph/Graph.tsx";
3134
3336
  var GraphInner = ({ classNames, model, projector: projectorProp, renderer: rendererProp, drag: drag2, arrows, onSelect, onInspect, onPointerMove, onPointerLeave, ...props }, forwardedRef) => {
3135
3337
  const context = useSvgContext();
3136
3338
  const graphRef = useRef3(null);
@@ -3211,7 +3413,7 @@ var GraphInner = ({ classNames, model, projector: projectorProp, renderer: rende
3211
3413
  renderer.render(layout);
3212
3414
  }
3213
3415
  } catch (error) {
3214
- log11.catch(error, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file13, L: 95, S: void 0 });
3416
+ log12.catch(error, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file14, L: 95, S: void 0 });
3215
3417
  void projector.stop();
3216
3418
  }
3217
3419
  })
@@ -3607,8 +3809,531 @@ var SVG = {
3607
3809
  FPS
3608
3810
  };
3609
3811
 
3812
+ // src/components/Tree/Tree.tsx
3813
+ import React10, { useMemo as useMemo9 } from "react";
3814
+
3815
+ // src/components/Tree/layout/HierarchicalEdgeBundling.tsx
3816
+ import { cluster, curveBundle as curveBundle2, hierarchy as hierarchy5, lineRadial as lineRadial2, select as select10 } from "d3";
3817
+ import React7, { useEffect as useEffect9, useMemo as useMemo6, useRef as useRef5 } from "react";
3818
+ import { mx as mx5 } from "@dxos/ui-theme";
3819
+
3820
+ // src/components/Tree/layout/slots.ts
3821
+ var defaultTreeLayoutSlots = {
3822
+ // Cursor + transition so the hover swap reads clearly; SVG circles support the `:hover` pseudo-class
3823
+ // via Tailwind variants exactly like HTML elements.
3824
+ node: "fill-blue-600 hover:fill-orange-500 cursor-pointer transition-colors",
3825
+ // 0.5px is fine on a white background, but on a dark Storybook background the lines disappear.
3826
+ // Use stroke-1 with opacity 50% so they read in both themes; dx-bundle-dim/out/in further tune on hover.
3827
+ path: "fill-none stroke-blue-500/50 stroke-[1px] dark:stroke-blue-400/60",
3828
+ text: "fill-neutral-700 dark:fill-neutral-300 text-xs hover:fill-orange-500 cursor-pointer transition-colors"
3829
+ };
3830
+
3831
+ // src/components/Tree/layout/useContainerSize.ts
3832
+ import { useEffect as useEffect8, useState as useState3 } from "react";
3833
+ var useContainerSize = () => {
3834
+ const [el, setEl] = useState3(null);
3835
+ const [size, setSize] = useState3({
3836
+ width: 0,
3837
+ height: 0
3838
+ });
3839
+ useEffect8(() => {
3840
+ if (!el) {
3841
+ return;
3842
+ }
3843
+ const rect = el.getBoundingClientRect();
3844
+ setSize({
3845
+ width: rect.width,
3846
+ height: rect.height
3847
+ });
3848
+ const observer = new ResizeObserver((entries) => {
3849
+ const entry = entries[0];
3850
+ if (!entry) {
3851
+ return;
3852
+ }
3853
+ const { width, height } = entry.contentRect;
3854
+ setSize((prev) => prev.width === width && prev.height === height ? prev : {
3855
+ width,
3856
+ height
3857
+ });
3858
+ });
3859
+ observer.observe(el);
3860
+ return () => observer.disconnect();
3861
+ }, [
3862
+ el
3863
+ ]);
3864
+ return {
3865
+ setRef: setEl,
3866
+ width: size.width,
3867
+ height: size.height
3868
+ };
3869
+ };
3870
+
3871
+ // src/components/Tree/layout/HierarchicalEdgeBundling.tsx
3872
+ var TRANSITION_MS = 350;
3873
+ var HierarchicalEdgeBundling = ({ classNames, data, edges = [], label = (d) => d.label ?? d.id, padding = 120, tension = 0.85, r = 4, slots = defaultTreeLayoutSlots, onNodeHover }) => {
3874
+ const svgRef = useRef5(null);
3875
+ const { setRef, width, height } = useContainerSize();
3876
+ const root = useMemo6(() => buildBundleHierarchy(data, edges), [
3877
+ data,
3878
+ edges
3879
+ ]);
3880
+ const handleHoverRef = useRef5(() => {
3881
+ });
3882
+ handleHoverRef.current = (node, event) => onNodeHover?.(node, event);
3883
+ useEffect9(() => {
3884
+ if (!svgRef.current || !width || !height) {
3885
+ return;
3886
+ }
3887
+ const radius = Math.max(0, Math.min(width, height) / 2 - padding);
3888
+ renderBundling(svgRef.current, root, {
3889
+ radius,
3890
+ r,
3891
+ label,
3892
+ slots,
3893
+ tension,
3894
+ onNodeHover: (n, e) => handleHoverRef.current(n, e)
3895
+ });
3896
+ }, [
3897
+ root,
3898
+ width,
3899
+ height,
3900
+ padding,
3901
+ tension,
3902
+ r,
3903
+ label,
3904
+ slots
3905
+ ]);
3906
+ return /* @__PURE__ */ React7.createElement("div", {
3907
+ ref: setRef,
3908
+ className: mx5("dx-expander relative", classNames)
3909
+ }, width > 0 && height > 0 && /* @__PURE__ */ React7.createElement("svg", {
3910
+ ref: svgRef,
3911
+ xmlns: "http://www.w3.org/2000/svg",
3912
+ width,
3913
+ height,
3914
+ viewBox: `${-width / 2} ${-height / 2} ${width} ${height}`
3915
+ }));
3916
+ };
3917
+ var buildBundleHierarchy = (data, edges) => {
3918
+ const root = hierarchy5(data);
3919
+ const byId = /* @__PURE__ */ new Map();
3920
+ for (const node of root.descendants()) {
3921
+ byId.set(node.data.id, node);
3922
+ node.outgoing = [];
3923
+ node.incoming = [];
3924
+ }
3925
+ for (const edge of edges) {
3926
+ const source = byId.get(edge.source);
3927
+ const target = byId.get(edge.target);
3928
+ if (!source || !target || source === target) {
3929
+ continue;
3930
+ }
3931
+ source.outgoing.push([
3932
+ source,
3933
+ target,
3934
+ edge
3935
+ ]);
3936
+ target.incoming.push([
3937
+ source,
3938
+ target,
3939
+ edge
3940
+ ]);
3941
+ }
3942
+ return root;
3943
+ };
3944
+ var renderBundling = (svgElement, root, options) => {
3945
+ const { radius, r, tension, label, slots, onNodeHover } = options;
3946
+ const svg = select10(svgElement);
3947
+ if (!root.children?.length) {
3948
+ svg.selectAll("g.dx-bundle-root").remove();
3949
+ return;
3950
+ }
3951
+ cluster().size([
3952
+ 2 * Math.PI,
3953
+ radius
3954
+ ])(root);
3955
+ const g = svg.selectAll("g.dx-bundle-root").data([
3956
+ null
3957
+ ]).join("g").classed("dx-bundle-root", true);
3958
+ const linksLayer = g.selectAll("g.dx-bundle-links").data([
3959
+ null
3960
+ ]).join("g").classed("dx-bundle-links", true);
3961
+ const nodesLayer = g.selectAll("g.dx-bundle-nodes").data([
3962
+ null
3963
+ ]).join("g").classed("dx-bundle-nodes", true);
3964
+ const line5 = lineRadial2().curve(curveBundle2.beta(tension)).radius((d) => d.y).angle((d) => d.x);
3965
+ const leaves = root.leaves();
3966
+ const flatEdges = leaves.flatMap((leaf) => leaf.outgoing ?? []);
3967
+ const paths = linksLayer.selectAll("path").data(flatEdges, (d) => `${d[0].data.id}->${d[1].data.id}`).join((enter) => enter.append("path").attr("class", slots.path ?? "").attr("fill", "none").attr("opacity", 0), (update) => update, (exit) => exit.each(function() {
3968
+ select10(this).interrupt();
3969
+ }).transition().duration(TRANSITION_MS).attr("opacity", 0).remove());
3970
+ paths.each(function(d) {
3971
+ d[0].pathEl = this;
3972
+ }).transition().duration(TRANSITION_MS).attr("opacity", 1).attr("d", ([s, t]) => line5(s.path(t)));
3973
+ const labels = nodesLayer.selectAll("g.dx-bundle-leaf").data(leaves, (d) => d.data.id).join((enter) => {
3974
+ const ge = enter.append("g").classed("dx-bundle-leaf", true).attr("opacity", 0);
3975
+ ge.append("circle").style("cursor", "pointer");
3976
+ ge.append("text").attr("dy", "0.32em").attr("paint-order", "stroke").style("cursor", "pointer");
3977
+ return ge;
3978
+ }, (update) => update, (exit) => exit.each(function() {
3979
+ select10(this).interrupt();
3980
+ }).transition().duration(TRANSITION_MS).attr("opacity", 0).remove());
3981
+ labels.transition().duration(TRANSITION_MS).attr("opacity", 1).attr("transform", (d) => `rotate(${d.x * 180 / Math.PI - 90}) translate(${d.y},0)`);
3982
+ const onEnter = function(event, d) {
3983
+ onNodeHover(d.data, event);
3984
+ hover(linksLayer, leaves, d, true);
3985
+ };
3986
+ const onLeave = function(event, d) {
3987
+ onNodeHover(null);
3988
+ hover(linksLayer, leaves, d, false);
3989
+ };
3990
+ labels.select("circle").attr("class", [
3991
+ slots.node ?? "",
3992
+ "dx-leaf"
3993
+ ].filter(Boolean).join(" ")).attr("r", r).style("fill", (d) => slots.nodeFill?.(d.data.data) ?? null).each(function(d) {
3994
+ d.circle = this;
3995
+ }).on("pointerenter", onEnter).on("pointerleave", onLeave);
3996
+ labels.select("text").attr("class", slots.text ?? "").attr("x", (d) => d.x < Math.PI ? r + 4 : -(r + 4)).attr("text-anchor", (d) => d.x < Math.PI ? "start" : "end").attr("transform", (d) => d.x >= Math.PI ? "rotate(180)" : null).each(function(d) {
3997
+ d.text = this;
3998
+ }).text((d) => label(d.data)).on("pointerenter", onEnter).on("pointerleave", onLeave);
3999
+ };
4000
+ var hover = (linksLayer, leaves, focused, on) => {
4001
+ const outgoing = new Set((focused.outgoing ?? []).map(([, t]) => t));
4002
+ const incoming = new Set((focused.incoming ?? []).map(([s]) => s));
4003
+ linksLayer.selectAll("path").style("stroke", (d) => {
4004
+ if (!on) {
4005
+ return null;
4006
+ }
4007
+ if (d[0] === focused) {
4008
+ return "var(--color-orange-500)";
4009
+ }
4010
+ if (d[1] === focused) {
4011
+ return "var(--color-sky-500)";
4012
+ }
4013
+ return null;
4014
+ }).style("stroke-width", (d) => on && (d[0] === focused || d[1] === focused) ? "1.5px" : null).style("opacity", (d) => on && d[0] !== focused && d[1] !== focused ? "0.08" : null);
4015
+ for (const leaf of leaves) {
4016
+ const isOut = outgoing.has(leaf);
4017
+ const isIn = incoming.has(leaf);
4018
+ const isConnected = isOut || isIn;
4019
+ if (leaf.text) {
4020
+ select10(leaf.text).style("fill", () => {
4021
+ if (!on) {
4022
+ return null;
4023
+ }
4024
+ if (leaf === focused) {
4025
+ return "var(--color-neutral-900)";
4026
+ }
4027
+ if (isOut) {
4028
+ return "var(--color-orange-500)";
4029
+ }
4030
+ if (isIn) {
4031
+ return "var(--color-sky-500)";
4032
+ }
4033
+ return null;
4034
+ }).style("font-weight", () => on && leaf === focused ? "600" : null);
4035
+ }
4036
+ if (leaf.circle) {
4037
+ select10(leaf.circle).style("stroke", () => on && isConnected ? "var(--color-orange-400)" : null).style("stroke-width", () => on && isConnected ? "2.5px" : null).style("opacity", () => on && !isConnected && leaf !== focused ? "0.15" : null);
4038
+ }
4039
+ }
4040
+ };
4041
+
4042
+ // src/components/Tree/layout/RadialTree.tsx
4043
+ import { cluster as d3Cluster4, tree as d3Tree2, linkRadial as linkRadial3, select as select11 } from "d3";
4044
+ import React8, { useCallback, useEffect as useEffect10, useMemo as useMemo7, useRef as useRef6, useState as useState4 } from "react";
4045
+ import { mx as mx6 } from "@dxos/ui-theme";
4046
+
4047
+ // src/components/Tree/layout/hierarchy.ts
4048
+ import { hierarchy as d3Hierarchy } from "d3";
4049
+ var buildHierarchy = (data, collapsed = /* @__PURE__ */ new Set()) => {
4050
+ return d3Hierarchy(data, (d) => {
4051
+ if (!d.children?.length) {
4052
+ return void 0;
4053
+ }
4054
+ return collapsed.has(d.id) ? void 0 : d.children;
4055
+ });
4056
+ };
4057
+ var isCollapsed = (data, collapsed) => Boolean(data.children?.length) && collapsed.has(data.id);
4058
+ var isLeaf = (data) => !data.children?.length;
4059
+
4060
+ // src/components/Tree/layout/RadialTree.tsx
4061
+ var TRANSITION_MS2 = 350;
4062
+ var RadialTree = ({ classNames, data, label = (d) => d.label ?? d.id, slots = defaultTreeLayoutSlots, r = 4, padding = 80, initialCollapsed, cluster: cluster2 = false, onNodeClick, onNodeHover }) => {
4063
+ const svgRef = useRef6(null);
4064
+ const { setRef, width, height } = useContainerSize();
4065
+ const [collapsed, setCollapsed] = useState4(() => new Set(initialCollapsed ?? []));
4066
+ const toggle = useCallback((id) => {
4067
+ setCollapsed((prev) => {
4068
+ const next = new Set(prev);
4069
+ if (next.has(id)) {
4070
+ next.delete(id);
4071
+ } else {
4072
+ next.add(id);
4073
+ }
4074
+ return next;
4075
+ });
4076
+ }, []);
4077
+ const handleClickRef = useRef6(() => {
4078
+ });
4079
+ handleClickRef.current = (node) => {
4080
+ onNodeClick?.(node);
4081
+ if (node.children?.length) {
4082
+ toggle(node.id);
4083
+ }
4084
+ };
4085
+ const handleHoverRef = useRef6(() => {
4086
+ });
4087
+ handleHoverRef.current = (node, event) => onNodeHover?.(node, event);
4088
+ const root = useMemo7(() => buildHierarchy(data, collapsed), [
4089
+ data,
4090
+ collapsed
4091
+ ]);
4092
+ useEffect10(() => {
4093
+ if (!svgRef.current || !width || !height) {
4094
+ return;
4095
+ }
4096
+ const radius = Math.max(0, Math.min(width, height) / 2 - padding);
4097
+ renderRadialTree(svgRef.current, root, {
4098
+ radius,
4099
+ r,
4100
+ label,
4101
+ slots,
4102
+ collapsed,
4103
+ cluster: cluster2,
4104
+ onNodeClick: (n) => handleClickRef.current(n),
4105
+ onNodeHover: (n, e) => handleHoverRef.current(n, e)
4106
+ });
4107
+ }, [
4108
+ root,
4109
+ width,
4110
+ height,
4111
+ r,
4112
+ padding,
4113
+ label,
4114
+ slots,
4115
+ collapsed,
4116
+ cluster2
4117
+ ]);
4118
+ return /* @__PURE__ */ React8.createElement("div", {
4119
+ ref: setRef,
4120
+ className: mx6("dx-expander relative", classNames)
4121
+ }, width > 0 && height > 0 && /* @__PURE__ */ React8.createElement("svg", {
4122
+ ref: svgRef,
4123
+ xmlns: "http://www.w3.org/2000/svg",
4124
+ width,
4125
+ height,
4126
+ viewBox: `${-width / 2} ${-height / 2} ${width} ${height}`
4127
+ }));
4128
+ };
4129
+ var renderRadialTree = (svgElement, root, options) => {
4130
+ const { radius, r, label, slots, collapsed, cluster: cluster2, onNodeClick, onNodeHover } = options;
4131
+ const svg = select11(svgElement);
4132
+ const layout = cluster2 ? d3Cluster4() : d3Tree2();
4133
+ layout.size([
4134
+ 2 * Math.PI,
4135
+ radius
4136
+ ]).separation((a, b) => (a.parent === b.parent ? 1 : 2) / Math.max(1, a.depth))(root);
4137
+ const g = svg.selectAll("g.dx-radial-root").data([
4138
+ null
4139
+ ]).join("g").classed("dx-radial-root", true);
4140
+ const linksLayer = g.selectAll("g.dx-radial-links").data([
4141
+ null
4142
+ ]).join("g").classed("dx-radial-links", true);
4143
+ const nodesLayer = g.selectAll("g.dx-radial-nodes").data([
4144
+ null
4145
+ ]).join("g").classed("dx-radial-nodes", true);
4146
+ const linkPath4 = linkRadial3().angle((d) => d.x).radius((d) => d.y);
4147
+ linksLayer.selectAll("path").data(root.links(), (d) => `${d.source.data.id}->${d.target.data.id}`).join((enter) => enter.append("path").attr("class", slots.path ?? "").attr("fill", "none").attr("opacity", 0), (update) => update, (exit) => exit.transition().duration(TRANSITION_MS2).attr("opacity", 0).remove()).transition().duration(TRANSITION_MS2).attr("opacity", 1).attr("d", linkPath4);
4148
+ const node = nodesLayer.selectAll("g.dx-radial-node").data(root.descendants(), (d) => d.data.id);
4149
+ const nodeEnter = node.enter().append("g").classed("dx-radial-node", true).attr("opacity", 0).attr("transform", (d) => `rotate(${d.x * 180 / Math.PI - 90}) translate(${d.y},0)`).style("cursor", (d) => d.data.children?.length ? "pointer" : "default").on("click", (_, d) => onNodeClick(d.data));
4150
+ nodeEnter.append("circle").attr("r", r).on("pointerenter", (event, d) => onNodeHover(d.data, event)).on("pointerleave", (event) => onNodeHover(null, event));
4151
+ nodeEnter.append("text").attr("dy", "0.32em").attr("paint-order", "stroke").text((d) => label(d.data));
4152
+ const nodeMerge = nodeEnter.merge(node);
4153
+ nodeMerge.transition().duration(TRANSITION_MS2).attr("opacity", 1).attr("transform", (d) => `rotate(${d.x * 180 / Math.PI - 90}) translate(${d.y},0)`);
4154
+ nodeMerge.select("circle").attr("class", (d) => {
4155
+ const collapsedHere = isCollapsed(d.data, collapsed);
4156
+ const leaf = isLeaf(d.data);
4157
+ return [
4158
+ slots.node ?? "",
4159
+ collapsedHere ? "dx-collapsed" : leaf ? "dx-leaf" : "dx-branch"
4160
+ ].filter(Boolean).join(" ");
4161
+ }).attr("r", r).style("fill", (d) => isLeaf(d.data) ? slots.nodeFill?.(d.data.data) ?? null : null);
4162
+ nodeMerge.select("text").attr("class", slots.text ?? "").attr("transform", (d) => d.x >= Math.PI ? "rotate(180)" : null).attr("x", (d) => d.x < Math.PI === !d.children ? r + 4 : -(r + 4)).attr("text-anchor", (d) => d.x < Math.PI === !d.children ? "start" : "end").text((d) => label(d.data));
4163
+ node.exit().transition().duration(TRANSITION_MS2).attr("opacity", 0).remove();
4164
+ };
4165
+
4166
+ // src/components/Tree/layout/TidyTree.tsx
4167
+ import { curveBumpX, link as d3Link, tree as d3Tree3, select as select12 } from "d3";
4168
+ import React9, { useCallback as useCallback2, useEffect as useEffect11, useMemo as useMemo8, useRef as useRef7, useState as useState5 } from "react";
4169
+ import { mx as mx7 } from "@dxos/ui-theme";
4170
+ var TRANSITION_MS3 = 350;
4171
+ var TidyTree = ({ classNames, data, label = (d) => d.label ?? d.id, slots = defaultTreeLayoutSlots, r = 4, margin = 24, initialCollapsed, onNodeClick }) => {
4172
+ const svgRef = useRef7(null);
4173
+ const { setRef, width, height } = useContainerSize();
4174
+ const [collapsed, setCollapsed] = useState5(() => new Set(initialCollapsed ?? []));
4175
+ const toggle = useCallback2((id) => {
4176
+ setCollapsed((prev) => {
4177
+ const next = new Set(prev);
4178
+ if (next.has(id)) {
4179
+ next.delete(id);
4180
+ } else {
4181
+ next.add(id);
4182
+ }
4183
+ return next;
4184
+ });
4185
+ }, []);
4186
+ const handleClickRef = useRef7(() => {
4187
+ });
4188
+ handleClickRef.current = (node) => {
4189
+ onNodeClick?.(node);
4190
+ if (node.children?.length) {
4191
+ toggle(node.id);
4192
+ }
4193
+ };
4194
+ const root = useMemo8(() => buildHierarchy(data, collapsed), [
4195
+ data,
4196
+ collapsed
4197
+ ]);
4198
+ useEffect11(() => {
4199
+ if (!svgRef.current || !width || !height) {
4200
+ return;
4201
+ }
4202
+ renderTidyTree(svgRef.current, root, {
4203
+ width,
4204
+ height,
4205
+ r,
4206
+ margin,
4207
+ label,
4208
+ slots,
4209
+ collapsed,
4210
+ onNodeClick: (n) => handleClickRef.current(n)
4211
+ });
4212
+ }, [
4213
+ root,
4214
+ width,
4215
+ height,
4216
+ r,
4217
+ margin,
4218
+ label,
4219
+ slots,
4220
+ collapsed
4221
+ ]);
4222
+ return /* @__PURE__ */ React9.createElement("div", {
4223
+ ref: setRef,
4224
+ className: mx7("dx-expander relative", classNames)
4225
+ }, width > 0 && height > 0 && /* @__PURE__ */ React9.createElement("svg", {
4226
+ ref: svgRef,
4227
+ xmlns: "http://www.w3.org/2000/svg",
4228
+ width,
4229
+ height,
4230
+ viewBox: `${-width / 2} ${-height / 2} ${width} ${height}`
4231
+ }));
4232
+ };
4233
+ var renderTidyTree = (svgElement, root, options) => {
4234
+ const { width, height, r, margin, label, slots, collapsed, onNodeClick } = options;
4235
+ const svg = select12(svgElement);
4236
+ const dx = 18;
4237
+ const dy = Math.max(60, (width - margin * 2) / Math.max(1, root.height + 1));
4238
+ d3Tree3().nodeSize([
4239
+ dx,
4240
+ dy
4241
+ ])(root);
4242
+ let x0 = Infinity;
4243
+ let x1 = -x0;
4244
+ root.each((d) => {
4245
+ if (d.x > x1) {
4246
+ x1 = d.x;
4247
+ }
4248
+ if (d.x < x0) {
4249
+ x0 = d.x;
4250
+ }
4251
+ });
4252
+ const treeWidth = width - margin * 2;
4253
+ const treeHeight = x1 - x0;
4254
+ const scaleY = treeHeight > 0 ? Math.min(1, (height - margin * 2) / treeHeight) : 1;
4255
+ const offsetX = -treeWidth / 2;
4256
+ const offsetY = -(x0 + x1) / 2;
4257
+ const g = svg.selectAll("g.dx-tidy-root").data([
4258
+ null
4259
+ ]).join("g").classed("dx-tidy-root", true);
4260
+ const linksLayer = g.selectAll("g.dx-tidy-links").data([
4261
+ null
4262
+ ]).join("g").classed("dx-tidy-links", true);
4263
+ const nodesLayer = g.selectAll("g.dx-tidy-nodes").data([
4264
+ null
4265
+ ]).join("g").classed("dx-tidy-nodes", true);
4266
+ const linkPath4 = d3Link(curveBumpX).x((d) => offsetX + d.y).y((d) => (d.x + offsetY) * scaleY);
4267
+ linksLayer.selectAll("path").data(root.links(), (d) => `${d.source.data.id}->${d.target.data.id}`).join((enter) => enter.append("path").attr("class", slots.path ?? "").attr("fill", "none").attr("opacity", 0), (update) => update, (exit) => exit.transition().duration(TRANSITION_MS3).attr("opacity", 0).remove()).transition().duration(TRANSITION_MS3).attr("opacity", 1).attr("d", linkPath4);
4268
+ const node = nodesLayer.selectAll("g.dx-tidy-node").data(root.descendants(), (d) => d.data.id);
4269
+ const nodeEnter = node.enter().append("g").classed("dx-tidy-node", true).attr("transform", (d) => `translate(${offsetX + d.y},${(d.x + offsetY) * scaleY})`).attr("opacity", 0).style("cursor", (d) => d.data.children?.length ? "pointer" : "default").on("click", (_, d) => onNodeClick(d.data));
4270
+ nodeEnter.append("circle").attr("r", r);
4271
+ nodeEnter.append("text").attr("dy", "0.32em").attr("x", (d) => d.children ? -(r + 4) : r + 4).attr("text-anchor", (d) => d.children ? "end" : "start").text((d) => label(d.data));
4272
+ const nodeMerge = nodeEnter.merge(node);
4273
+ nodeMerge.transition().duration(TRANSITION_MS3).attr("opacity", 1).attr("transform", (d) => `translate(${offsetX + d.y},${(d.x + offsetY) * scaleY})`);
4274
+ nodeMerge.select("circle").attr("class", (d) => {
4275
+ const collapsedHere = isCollapsed(d.data, collapsed);
4276
+ const leaf = isLeaf(d.data);
4277
+ return [
4278
+ slots.node ?? "",
4279
+ collapsedHere ? "dx-collapsed" : leaf ? "dx-leaf" : "dx-branch"
4280
+ ].filter(Boolean).join(" ");
4281
+ }).attr("r", r);
4282
+ nodeMerge.select("text").attr("class", slots.text ?? "").attr("x", (d) => d.children ? -(r + 4) : r + 4).attr("text-anchor", (d) => d.children ? "end" : "start").text((d) => label(d.data));
4283
+ node.exit().each(function() {
4284
+ select12(this).interrupt();
4285
+ }).transition().duration(TRANSITION_MS3).attr("opacity", 0).remove();
4286
+ };
4287
+
4288
+ // src/components/Tree/Tree.tsx
4289
+ var Tree = ({ classNames, data, edges, variant = "tidy", label, slots, margin, initialCollapsed, onNodeClick, onNodeHover }) => {
4290
+ return useMemo9(() => {
4291
+ switch (variant) {
4292
+ case "tidy":
4293
+ return /* @__PURE__ */ React10.createElement(TidyTree, {
4294
+ classNames,
4295
+ data,
4296
+ label,
4297
+ slots,
4298
+ margin,
4299
+ initialCollapsed,
4300
+ onNodeClick
4301
+ });
4302
+ case "radial":
4303
+ return /* @__PURE__ */ React10.createElement(RadialTree, {
4304
+ classNames,
4305
+ data,
4306
+ label,
4307
+ slots,
4308
+ initialCollapsed,
4309
+ onNodeClick,
4310
+ onNodeHover
4311
+ });
4312
+ case "edge":
4313
+ return /* @__PURE__ */ React10.createElement(HierarchicalEdgeBundling, {
4314
+ classNames,
4315
+ data,
4316
+ edges: edges ?? [],
4317
+ label,
4318
+ slots,
4319
+ onNodeHover
4320
+ });
4321
+ }
4322
+ }, [
4323
+ variant,
4324
+ classNames,
4325
+ data,
4326
+ edges,
4327
+ label,
4328
+ slots,
4329
+ initialCollapsed,
4330
+ onNodeClick,
4331
+ onNodeHover
4332
+ ]);
4333
+ };
4334
+
3610
4335
  // src/fx/pulsar.ts
3611
- import { easeCubicOut as easeCubicOut2, select as select10 } from "d3";
4336
+ import { easeCubicOut as easeCubicOut2, select as select13 } from "d3";
3612
4337
  var PROP_PULSAR_ACTIVE = "dx-pulsar-active";
3613
4338
  (function(Pulsar2) {
3614
4339
  Pulsar2.has = (group) => group.select("circle.dx-pulsar").empty();
@@ -3623,10 +4348,10 @@ var PROP_PULSAR_ACTIVE = "dx-pulsar-active";
3623
4348
  var startAnimation = (pulsar, r, options = {}) => {
3624
4349
  const { period = 1e3, duration = 800, ratio = 3 } = options;
3625
4350
  return pulsar.attr("r", r).attr("opacity", 1).transition("pulsar").delay(period - Date.now() % period).duration(Math.min(duration, period - 20)).ease(easeCubicOut2).attr("r", r * ratio).attr("opacity", -0.1).on("end", function() {
3626
- if (select10(this).property(PROP_PULSAR_ACTIVE)) {
3627
- startAnimation(select10(this), r, options);
4351
+ if (select13(this).property(PROP_PULSAR_ACTIVE)) {
4352
+ startAnimation(select13(this), r, options);
3628
4353
  } else {
3629
- select10(this).remove();
4354
+ select13(this).remove();
3630
4355
  }
3631
4356
  });
3632
4357
  };
@@ -3649,30 +4374,42 @@ export {
3649
4374
  GraphRelationalProjector,
3650
4375
  GraphRenderer,
3651
4376
  GraphSwarmProjector,
4377
+ GraphTreeProjector,
3652
4378
  GridController,
4379
+ HierarchicalEdgeBundling,
3653
4380
  Mesh,
3654
4381
  PLEXUS_NODE_TYPE_FOCUS,
3655
4382
  PLEXUS_NODE_TYPE_OBJECT,
3656
4383
  PLEXUS_NODE_TYPE_RELATION,
3657
4384
  Projector,
3658
4385
  Pulsar,
4386
+ RadialTree,
3659
4387
  Renderer,
3660
4388
  SVG,
3661
4389
  SVGContext,
3662
4390
  SVGContextProvider,
3663
4391
  Scale,
3664
4392
  Screen,
4393
+ TREE_NODE_TYPE_INBOUND,
4394
+ TREE_NODE_TYPE_NODE,
4395
+ TREE_NODE_TYPE_ROOT,
4396
+ TidyTree,
4397
+ Tree,
3665
4398
  Vector,
3666
4399
  ZoomHandler,
3667
4400
  appendRadialGroupLabel,
3668
4401
  appendRadialLeafLabel,
3669
4402
  appendRootLabel,
4403
+ buildHierarchy,
3670
4404
  createGraphDrag,
3671
4405
  createMarkers,
3672
4406
  defaultForceOptions,
3673
4407
  defaultIdAccessor,
4408
+ defaultTreeLayoutSlots,
3674
4409
  emptyGraph,
3675
4410
  getCircumferencePoints,
4411
+ isCollapsed,
4412
+ isLeaf,
3676
4413
  layoutHorizontal,
3677
4414
  layoutRadial,
3678
4415
  layoutVertical,
@@ -3680,6 +4417,7 @@ export {
3680
4417
  normal,
3681
4418
  offsetPoints,
3682
4419
  updateNode,
4420
+ useContainerSize,
3683
4421
  useDynamicRef,
3684
4422
  useGrid,
3685
4423
  useStateRef,