@particle-academy/react-fancy 2.10.0 → 3.0.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.
package/dist/index.js CHANGED
@@ -2,7 +2,7 @@ import { forwardRef, createContext, useId, useRef, useEffect, useState, useCallb
2
2
  import { clsx } from 'clsx';
3
3
  import { twMerge } from 'tailwind-merge';
4
4
  import * as LucideIcons from 'lucide-react';
5
- import { X, ChevronUp, ChevronDown, ChevronLeft, ChevronRight, Search, Menu, File, Upload, PanelLeftOpen, PanelLeftClose, ZoomIn, ZoomOut, RotateCcw, Maximize, Check, XCircle, AlertTriangle, Info } from 'lucide-react';
5
+ import { X, ChevronUp, ChevronDown, ChevronLeft, ChevronRight, Search, Menu, File, Upload, PanelLeftOpen, PanelLeftClose, Check, XCircle, AlertTriangle, Info } from 'lucide-react';
6
6
  import { jsx, Fragment, jsxs } from 'react/jsx-runtime';
7
7
  import { createPortal } from 'react-dom';
8
8
  import { marked } from 'marked';
@@ -11454,1653 +11454,6 @@ var Kanban = Object.assign(KanbanRoot, {
11454
11454
  Card: KanbanCard,
11455
11455
  ColumnHandle: KanbanColumnHandle
11456
11456
  });
11457
- var CanvasContext = createContext(null);
11458
- function useCanvas() {
11459
- const ctx = useContext(CanvasContext);
11460
- if (!ctx) throw new Error("useCanvas must be used within a Canvas component");
11461
- return ctx;
11462
- }
11463
- function CanvasNode({ children, id, x, y, draggable, onPositionChange, className, style }) {
11464
- const { registerNode, unregisterNode, viewport, gridSize, snapToGrid } = useCanvas();
11465
- const nodeRef = useRef(null);
11466
- const isDragging = useRef(false);
11467
- const dragStart = useRef({ mouseX: 0, mouseY: 0, nodeX: 0, nodeY: 0 });
11468
- useEffect(() => {
11469
- const el = nodeRef.current;
11470
- if (!el) return;
11471
- const updateRect = () => {
11472
- registerNode(id, { x, y, width: el.offsetWidth, height: el.offsetHeight });
11473
- };
11474
- updateRect();
11475
- const observer = new ResizeObserver(updateRect);
11476
- observer.observe(el);
11477
- return () => {
11478
- observer.disconnect();
11479
- unregisterNode(id);
11480
- };
11481
- }, [id, x, y, registerNode, unregisterNode]);
11482
- const handlePointerDown = useCallback(
11483
- (e) => {
11484
- if (!draggable || e.button !== 0) return;
11485
- e.stopPropagation();
11486
- isDragging.current = true;
11487
- dragStart.current = { mouseX: e.clientX, mouseY: e.clientY, nodeX: x, nodeY: y };
11488
- e.target.setPointerCapture(e.pointerId);
11489
- },
11490
- [draggable, x, y]
11491
- );
11492
- const handlePointerMove = useCallback(
11493
- (e) => {
11494
- if (!isDragging.current) return;
11495
- const dx = (e.clientX - dragStart.current.mouseX) / viewport.zoom;
11496
- const dy = (e.clientY - dragStart.current.mouseY) / viewport.zoom;
11497
- let nx = dragStart.current.nodeX + dx;
11498
- let ny = dragStart.current.nodeY + dy;
11499
- if (snapToGrid && gridSize > 0) {
11500
- nx = Math.round(nx / gridSize) * gridSize;
11501
- ny = Math.round(ny / gridSize) * gridSize;
11502
- }
11503
- onPositionChange?.(nx, ny);
11504
- },
11505
- [viewport.zoom, onPositionChange, snapToGrid, gridSize]
11506
- );
11507
- const handlePointerUp = useCallback(() => {
11508
- isDragging.current = false;
11509
- }, []);
11510
- return /* @__PURE__ */ jsx(
11511
- "div",
11512
- {
11513
- ref: nodeRef,
11514
- "data-react-fancy-canvas-node": "",
11515
- "data-node-id": id,
11516
- className: cn("absolute", draggable && "cursor-grab active:cursor-grabbing", className),
11517
- style: { left: x, top: y, ...style },
11518
- onPointerDown: handlePointerDown,
11519
- onPointerMove: handlePointerMove,
11520
- onPointerUp: handlePointerUp,
11521
- children
11522
- }
11523
- );
11524
- }
11525
- CanvasNode.displayName = "CanvasNode";
11526
-
11527
- // src/components/Canvas/canvas.utils.ts
11528
- function getAnchorPoint(rect, anchor, otherRect) {
11529
- const cx = rect.x + rect.width / 2;
11530
- const cy = rect.y + rect.height / 2;
11531
- if (anchor === "auto" && otherRect) {
11532
- const ocx = otherRect.x + otherRect.width / 2;
11533
- const ocy = otherRect.y + otherRect.height / 2;
11534
- const dx = ocx - cx;
11535
- const dy = ocy - cy;
11536
- if (Math.abs(dx) > Math.abs(dy)) {
11537
- return dx > 0 ? { x: rect.x + rect.width, y: cy } : { x: rect.x, y: cy };
11538
- }
11539
- return dy > 0 ? { x: cx, y: rect.y + rect.height } : { x: cx, y: rect.y };
11540
- }
11541
- switch (anchor) {
11542
- case "top":
11543
- return { x: cx, y: rect.y };
11544
- case "bottom":
11545
- return { x: cx, y: rect.y + rect.height };
11546
- case "left":
11547
- return { x: rect.x, y: cy };
11548
- case "right":
11549
- return { x: rect.x + rect.width, y: cy };
11550
- case "center":
11551
- return { x: cx, y: cy };
11552
- default:
11553
- return { x: cx, y: cy };
11554
- }
11555
- }
11556
- function bezierPath(from, to) {
11557
- const dx = Math.abs(to.x - from.x);
11558
- const dy = Math.abs(to.y - from.y);
11559
- if (dx > dy) {
11560
- const offset2 = dx * 0.5;
11561
- const cp1x = from.x + (to.x > from.x ? offset2 : -offset2);
11562
- const cp2x = to.x + (to.x > from.x ? -offset2 : offset2);
11563
- return `M${from.x},${from.y} C${cp1x},${from.y} ${cp2x},${to.y} ${to.x},${to.y}`;
11564
- }
11565
- const offset = Math.max(dy * 0.5, 30);
11566
- const cp1y = from.y + (to.y > from.y ? offset : -offset);
11567
- const cp2y = to.y + (to.y > from.y ? -offset : offset);
11568
- return `M${from.x},${from.y} C${from.x},${cp1y} ${to.x},${cp2y} ${to.x},${to.y}`;
11569
- }
11570
- function stepPath(from, to) {
11571
- const midX = (from.x + to.x) / 2;
11572
- return `M${from.x},${from.y} H${midX} V${to.y} H${to.x}`;
11573
- }
11574
- function straightPath(from, to) {
11575
- return `M${from.x},${from.y} L${to.x},${to.y}`;
11576
- }
11577
- function getEdgePath(from, to, curve = "bezier") {
11578
- switch (curve) {
11579
- case "bezier":
11580
- return bezierPath(from, to);
11581
- case "step":
11582
- return stepPath(from, to);
11583
- case "straight":
11584
- return straightPath(from, to);
11585
- }
11586
- }
11587
- function CanvasEdge({
11588
- from,
11589
- to,
11590
- fromAnchor = "auto",
11591
- toAnchor = "auto",
11592
- curve = "bezier",
11593
- color = "currentColor",
11594
- strokeWidth = 2,
11595
- dashed = false,
11596
- animated = false,
11597
- label,
11598
- className,
11599
- markerStart,
11600
- markerEnd
11601
- }) {
11602
- const { nodeRects, registryVersion } = useCanvas();
11603
- const path = useMemo(() => {
11604
- const fromRect = nodeRects.get(from);
11605
- const toRect = nodeRects.get(to);
11606
- if (!fromRect || !toRect) return null;
11607
- const fromPt = getAnchorPoint(fromRect, fromAnchor, toRect);
11608
- const toPt = getAnchorPoint(toRect, toAnchor, fromRect);
11609
- return {
11610
- d: getEdgePath(fromPt, toPt, curve),
11611
- midX: (fromPt.x + toPt.x) / 2,
11612
- midY: (fromPt.y + toPt.y) / 2
11613
- };
11614
- }, [from, to, fromAnchor, toAnchor, curve, nodeRects, registryVersion]);
11615
- if (!path) return null;
11616
- return /* @__PURE__ */ jsxs("g", { "data-react-fancy-canvas-edge": "", className: cn("text-zinc-300 dark:text-zinc-600", className), children: [
11617
- /* @__PURE__ */ jsx(
11618
- "path",
11619
- {
11620
- d: path.d,
11621
- fill: "none",
11622
- stroke: color,
11623
- strokeWidth,
11624
- strokeDasharray: dashed ? "6 4" : void 0,
11625
- markerStart: markerStart ? `url(#${markerStart})` : void 0,
11626
- markerEnd: markerEnd ? `url(#${markerEnd})` : void 0,
11627
- className: animated ? "animate-[dash_1s_linear_infinite]" : "",
11628
- style: animated ? { strokeDasharray: "8 4" } : void 0
11629
- }
11630
- ),
11631
- label && /* @__PURE__ */ jsx("foreignObject", { x: path.midX - 40, y: path.midY - 12, width: 80, height: 24, children: /* @__PURE__ */ jsx("div", { className: "flex items-center justify-center text-xs text-zinc-500", children: label }) })
11632
- ] });
11633
- }
11634
- CanvasEdge.displayName = "CanvasEdge";
11635
- function CanvasMinimap({ width = 150, height = 100, className }) {
11636
- const { nodeRects, registryVersion, viewport } = useCanvas();
11637
- const bounds = useMemo(() => {
11638
- if (nodeRects.size === 0) return { minX: 0, minY: 0, maxX: 500, maxY: 300 };
11639
- let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;
11640
- nodeRects.forEach((r) => {
11641
- minX = Math.min(minX, r.x);
11642
- minY = Math.min(minY, r.y);
11643
- maxX = Math.max(maxX, r.x + r.width);
11644
- maxY = Math.max(maxY, r.y + r.height);
11645
- });
11646
- const padding = 50;
11647
- return { minX: minX - padding, minY: minY - padding, maxX: maxX + padding, maxY: maxY + padding };
11648
- }, [nodeRects, registryVersion]);
11649
- const scaleX = width / (bounds.maxX - bounds.minX || 1);
11650
- const scaleY = height / (bounds.maxY - bounds.minY || 1);
11651
- const scale = Math.min(scaleX, scaleY);
11652
- return /* @__PURE__ */ jsx(
11653
- "div",
11654
- {
11655
- "data-react-fancy-canvas-minimap": "",
11656
- className: cn(
11657
- "absolute right-3 bottom-3 overflow-hidden rounded-lg border border-zinc-200 bg-white/90 dark:border-zinc-700 dark:bg-zinc-900/90",
11658
- className
11659
- ),
11660
- style: { width, height },
11661
- children: /* @__PURE__ */ jsxs("svg", { width, height, children: [
11662
- Array.from(nodeRects.entries()).map(([id, rect]) => /* @__PURE__ */ jsx(
11663
- "rect",
11664
- {
11665
- x: (rect.x - bounds.minX) * scale,
11666
- y: (rect.y - bounds.minY) * scale,
11667
- width: Math.max(rect.width * scale, 4),
11668
- height: Math.max(rect.height * scale, 3),
11669
- rx: 1,
11670
- className: "fill-blue-400/60"
11671
- },
11672
- id
11673
- )),
11674
- /* @__PURE__ */ jsx(
11675
- "rect",
11676
- {
11677
- x: (-viewport.panX / viewport.zoom - bounds.minX) * scale,
11678
- y: (-viewport.panY / viewport.zoom - bounds.minY) * scale,
11679
- width: (width / viewport.zoom / scale > 0 ? width / viewport.zoom : width) * scale / (bounds.maxX - bounds.minX || 1) * (bounds.maxX - bounds.minX),
11680
- height: (height / viewport.zoom / scale > 0 ? height / viewport.zoom : height) * scale / (bounds.maxY - bounds.minY || 1) * (bounds.maxY - bounds.minY),
11681
- fill: "none",
11682
- stroke: "currentColor",
11683
- strokeWidth: 1,
11684
- className: "text-blue-500"
11685
- }
11686
- )
11687
- ] })
11688
- }
11689
- );
11690
- }
11691
- CanvasMinimap.displayName = "CanvasMinimap";
11692
- function CanvasControls({
11693
- className,
11694
- showZoomIn = true,
11695
- showZoomOut = true,
11696
- showReset = true,
11697
- showFitAll = true
11698
- }) {
11699
- const { setViewport, nodeRects, containerRef } = useCanvas();
11700
- const zoomIn = () => setViewport((v) => ({ ...v, zoom: Math.min(3, v.zoom * 1.25) }));
11701
- const zoomOut = () => setViewport((v) => ({ ...v, zoom: Math.max(0.1, v.zoom / 1.25) }));
11702
- const reset = () => setViewport({ panX: 0, panY: 0, zoom: 1 });
11703
- const fitAll = () => {
11704
- const container = containerRef.current;
11705
- if (!container || nodeRects.size === 0) return reset();
11706
- let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;
11707
- nodeRects.forEach((r) => {
11708
- minX = Math.min(minX, r.x);
11709
- minY = Math.min(minY, r.y);
11710
- maxX = Math.max(maxX, r.x + r.width);
11711
- maxY = Math.max(maxY, r.y + r.height);
11712
- });
11713
- const padding = 40;
11714
- const contentW = maxX - minX + padding * 2;
11715
- const contentH = maxY - minY + padding * 2;
11716
- const cw = container.clientWidth;
11717
- const ch = container.clientHeight;
11718
- const zoom = Math.min(cw / contentW, ch / contentH, 1.5);
11719
- const panX = (cw - contentW * zoom) / 2 - minX * zoom + padding * zoom;
11720
- const panY = (ch - contentH * zoom) / 2 - minY * zoom + padding * zoom;
11721
- setViewport({ panX, panY, zoom });
11722
- };
11723
- const btnClass = "flex h-8 w-8 items-center justify-center rounded-md text-zinc-500 hover:bg-zinc-100 hover:text-zinc-700 dark:hover:bg-zinc-800 dark:hover:text-zinc-300 transition-colors";
11724
- return /* @__PURE__ */ jsxs(
11725
- "div",
11726
- {
11727
- "data-react-fancy-canvas-controls": "",
11728
- className: cn(
11729
- "absolute bottom-3 left-3 flex gap-1 rounded-lg border border-zinc-200 bg-white/90 p-1 shadow-sm dark:border-zinc-700 dark:bg-zinc-900/90",
11730
- className
11731
- ),
11732
- children: [
11733
- showZoomIn && /* @__PURE__ */ jsx("button", { type: "button", onClick: zoomIn, className: btnClass, "aria-label": "Zoom in", children: /* @__PURE__ */ jsx(ZoomIn, { size: 16 }) }),
11734
- showZoomOut && /* @__PURE__ */ jsx("button", { type: "button", onClick: zoomOut, className: btnClass, "aria-label": "Zoom out", children: /* @__PURE__ */ jsx(ZoomOut, { size: 16 }) }),
11735
- showReset && /* @__PURE__ */ jsx("button", { type: "button", onClick: reset, className: btnClass, "aria-label": "Reset view", children: /* @__PURE__ */ jsx(RotateCcw, { size: 16 }) }),
11736
- showFitAll && /* @__PURE__ */ jsx("button", { type: "button", onClick: fitAll, className: btnClass, "aria-label": "Fit all", children: /* @__PURE__ */ jsx(Maximize, { size: 16 }) })
11737
- ]
11738
- }
11739
- );
11740
- }
11741
- CanvasControls.displayName = "CanvasControls";
11742
- var DEFAULT_VIEWPORT = { panX: 0, panY: 0, zoom: 1 };
11743
- function CanvasRoot({
11744
- children,
11745
- viewport: controlledViewport,
11746
- defaultViewport = DEFAULT_VIEWPORT,
11747
- onViewportChange,
11748
- minZoom = 0.1,
11749
- maxZoom = 3,
11750
- pannable = true,
11751
- zoomable = true,
11752
- showGrid = false,
11753
- gridStyle = "dots",
11754
- gridSize = 20,
11755
- gridColor = "rgb(161 161 170 / 0.3)",
11756
- snapToGrid = false,
11757
- fitOnMount = false,
11758
- className,
11759
- style
11760
- }) {
11761
- const containerRef = useRef(null);
11762
- const [viewport, setViewport] = useControllableState(controlledViewport, defaultViewport, onViewportChange);
11763
- const { registerNode, unregisterNode, nodeRects, version: registryVersion } = useNodeRegistry();
11764
- const { containerProps } = usePanZoom({
11765
- viewport,
11766
- setViewport,
11767
- minZoom,
11768
- maxZoom,
11769
- pannable,
11770
- zoomable,
11771
- containerRef
11772
- });
11773
- const ctx = useMemo(
11774
- () => ({ viewport, setViewport, registerNode, unregisterNode, nodeRects, registryVersion, containerRef, gridSize, snapToGrid }),
11775
- [viewport, setViewport, registerNode, unregisterNode, nodeRects, registryVersion, gridSize, snapToGrid]
11776
- );
11777
- const hasFitted = useRef(false);
11778
- useEffect(() => {
11779
- if (!fitOnMount || hasFitted.current || nodeRects.size === 0) return;
11780
- const container = containerRef.current;
11781
- if (!container || container.clientWidth === 0) return;
11782
- hasFitted.current = true;
11783
- requestAnimationFrame(() => {
11784
- let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;
11785
- nodeRects.forEach((r) => {
11786
- minX = Math.min(minX, r.x);
11787
- minY = Math.min(minY, r.y);
11788
- maxX = Math.max(maxX, r.x + r.width);
11789
- maxY = Math.max(maxY, r.y + r.height);
11790
- });
11791
- const padding = 40;
11792
- const contentW = maxX - minX + padding * 2;
11793
- const contentH = maxY - minY + padding * 2;
11794
- const cw = container.clientWidth;
11795
- const ch = container.clientHeight;
11796
- const zoom = Math.min(cw / contentW, ch / contentH, 1.5);
11797
- const panX = (cw - contentW * zoom) / 2 - minX * zoom + padding * zoom;
11798
- const panY = (ch - contentH * zoom) / 2 - minY * zoom + padding * zoom;
11799
- setViewport({ panX, panY, zoom });
11800
- });
11801
- }, [fitOnMount, nodeRects, registryVersion, setViewport]);
11802
- const edges = [];
11803
- const others = [];
11804
- const overlays = [];
11805
- Children.forEach(children, (child) => {
11806
- const el = child;
11807
- if (!el || !el.type) return;
11808
- const elType = el.type;
11809
- if (elType === CanvasEdge || elType?._isCanvasEdge) {
11810
- edges.push(el);
11811
- } else if (elType === CanvasMinimap || elType === CanvasControls) {
11812
- overlays.push(el);
11813
- } else {
11814
- others.push(el);
11815
- }
11816
- });
11817
- return /* @__PURE__ */ jsx(CanvasContext.Provider, { value: ctx, children: /* @__PURE__ */ jsxs(
11818
- "div",
11819
- {
11820
- ref: containerRef,
11821
- "data-react-fancy-canvas": "",
11822
- className: cn("relative overflow-hidden", className),
11823
- style: { touchAction: "none", ...style },
11824
- ...containerProps,
11825
- children: [
11826
- /* @__PURE__ */ jsx(
11827
- "div",
11828
- {
11829
- "data-canvas-bg": "",
11830
- className: "absolute inset-0",
11831
- style: showGrid && gridStyle !== "none" ? gridStyle === "lines" ? {
11832
- backgroundImage: `linear-gradient(to right, ${gridColor} 1px, transparent 1px), linear-gradient(to bottom, ${gridColor} 1px, transparent 1px)`,
11833
- backgroundSize: `${gridSize * viewport.zoom}px ${gridSize * viewport.zoom}px`,
11834
- backgroundPosition: `${viewport.panX}px ${viewport.panY}px`
11835
- } : {
11836
- backgroundImage: `radial-gradient(circle, ${gridColor} 1px, transparent 1px)`,
11837
- backgroundSize: `${gridSize * viewport.zoom}px ${gridSize * viewport.zoom}px`,
11838
- backgroundPosition: `${viewport.panX}px ${viewport.panY}px`
11839
- } : void 0
11840
- }
11841
- ),
11842
- /* @__PURE__ */ jsx(
11843
- "div",
11844
- {
11845
- className: "absolute origin-top-left",
11846
- style: {
11847
- transform: `translate(${viewport.panX}px, ${viewport.panY}px) scale(${viewport.zoom})`
11848
- },
11849
- children: others
11850
- }
11851
- ),
11852
- /* @__PURE__ */ jsxs(
11853
- "svg",
11854
- {
11855
- className: "pointer-events-none absolute inset-0 h-full w-full",
11856
- style: {
11857
- transform: `translate(${viewport.panX}px, ${viewport.panY}px) scale(${viewport.zoom})`,
11858
- transformOrigin: "0 0"
11859
- },
11860
- children: [
11861
- /* @__PURE__ */ jsxs("defs", { children: [
11862
- /* @__PURE__ */ jsx("marker", { id: "canvas-arrow", viewBox: "0 0 10 10", refX: "10", refY: "5", markerWidth: "8", markerHeight: "8", orient: "auto", children: /* @__PURE__ */ jsx("path", { d: "M0,0 L10,5 L0,10 Z", fill: "#71717a" }) }),
11863
- /* @__PURE__ */ jsx("marker", { id: "canvas-circle", viewBox: "0 0 10 10", refX: "5", refY: "5", markerWidth: "8", markerHeight: "8", orient: "auto", children: /* @__PURE__ */ jsx("circle", { cx: "5", cy: "5", r: "3.5", fill: "#71717a" }) }),
11864
- /* @__PURE__ */ jsx("marker", { id: "canvas-diamond", viewBox: "0 0 12 12", refX: "6", refY: "6", markerWidth: "10", markerHeight: "10", orient: "auto", children: /* @__PURE__ */ jsx("polygon", { points: "6,0 12,6 6,12 0,6", fill: "none", stroke: "#71717a", strokeWidth: "1.5" }) }),
11865
- /* @__PURE__ */ jsx("marker", { id: "canvas-one", viewBox: "0 0 2 16", refX: "1", refY: "8", markerWidth: "2", markerHeight: "14", orient: "auto", children: /* @__PURE__ */ jsx("line", { x1: "1", y1: "0", x2: "1", y2: "16", stroke: "#71717a", strokeWidth: "2" }) }),
11866
- /* @__PURE__ */ jsxs("marker", { id: "canvas-crow-foot", viewBox: "0 0 16 16", refX: "16", refY: "8", markerWidth: "14", markerHeight: "14", orient: "auto", children: [
11867
- /* @__PURE__ */ jsx("line", { x1: "16", y1: "8", x2: "0", y2: "0", stroke: "#71717a", strokeWidth: "2", strokeLinecap: "round" }),
11868
- /* @__PURE__ */ jsx("line", { x1: "16", y1: "8", x2: "0", y2: "8", stroke: "#71717a", strokeWidth: "2", strokeLinecap: "round" }),
11869
- /* @__PURE__ */ jsx("line", { x1: "16", y1: "8", x2: "0", y2: "16", stroke: "#71717a", strokeWidth: "2", strokeLinecap: "round" }),
11870
- /* @__PURE__ */ jsx("line", { x1: "16", y1: "0", x2: "16", y2: "16", stroke: "#71717a", strokeWidth: "2", strokeLinecap: "round" })
11871
- ] })
11872
- ] }),
11873
- edges
11874
- ]
11875
- }
11876
- ),
11877
- overlays
11878
- ]
11879
- }
11880
- ) });
11881
- }
11882
- var Canvas = Object.assign(CanvasRoot, {
11883
- Node: CanvasNode,
11884
- Edge: CanvasEdge,
11885
- Minimap: CanvasMinimap,
11886
- Controls: CanvasControls
11887
- });
11888
- var DiagramContext = createContext(null);
11889
- function useDiagram() {
11890
- const ctx = useContext(DiagramContext);
11891
- if (!ctx) {
11892
- throw new Error("useDiagram must be used within a <Diagram> component");
11893
- }
11894
- return ctx;
11895
- }
11896
- function DiagramField({
11897
- name,
11898
- type,
11899
- primary = false,
11900
- foreign = false,
11901
- nullable = false,
11902
- className
11903
- }) {
11904
- return /* @__PURE__ */ jsxs(
11905
- "div",
11906
- {
11907
- "data-react-fancy-diagram-field": "",
11908
- className: cn(
11909
- "flex items-center justify-between gap-2 border-t border-zinc-200 px-3 py-1 text-sm dark:border-zinc-700",
11910
- className
11911
- ),
11912
- children: [
11913
- /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1.5", children: [
11914
- primary && /* @__PURE__ */ jsx("span", { className: "inline-flex items-center rounded bg-blue-100 px-1 py-0.5 text-[10px] font-semibold leading-none text-blue-700 dark:bg-blue-900/50 dark:text-blue-300", children: "PK" }),
11915
- foreign && /* @__PURE__ */ jsx("span", { className: "inline-flex items-center rounded bg-amber-100 px-1 py-0.5 text-[10px] font-semibold leading-none text-amber-700 dark:bg-amber-900/50 dark:text-amber-300", children: "FK" }),
11916
- /* @__PURE__ */ jsx("span", { className: "text-zinc-800 dark:text-zinc-200", children: name })
11917
- ] }),
11918
- type && /* @__PURE__ */ jsxs("span", { className: "shrink-0 text-xs text-zinc-400 dark:text-zinc-500", children: [
11919
- type,
11920
- nullable && "?"
11921
- ] })
11922
- ]
11923
- }
11924
- );
11925
- }
11926
- DiagramField.displayName = "DiagramField";
11927
- function DiagramEntity({
11928
- children,
11929
- id: idProp,
11930
- name,
11931
- x = 0,
11932
- y = 0,
11933
- color = "bg-blue-600 dark:bg-blue-500",
11934
- draggable,
11935
- onPositionChange,
11936
- className
11937
- }) {
11938
- const id = idProp ?? name;
11939
- const fields = [];
11940
- const other = [];
11941
- Children.forEach(children, (child) => {
11942
- const el = child;
11943
- if (!el || !el.type) return;
11944
- if (el.type === DiagramField) {
11945
- fields.push(el);
11946
- } else {
11947
- other.push(el);
11948
- }
11949
- });
11950
- return /* @__PURE__ */ jsx(Canvas.Node, { id, x, y, draggable, onPositionChange, children: /* @__PURE__ */ jsxs(
11951
- "div",
11952
- {
11953
- "data-react-fancy-diagram-entity": "",
11954
- "data-entity-id": id,
11955
- className: cn(
11956
- "w-[220px] overflow-hidden rounded-lg border border-zinc-200 bg-white shadow-sm dark:border-zinc-700 dark:bg-zinc-800",
11957
- className
11958
- ),
11959
- children: [
11960
- /* @__PURE__ */ jsx(
11961
- "div",
11962
- {
11963
- className: cn(
11964
- "px-3 py-2 text-sm font-semibold text-white",
11965
- color
11966
- ),
11967
- children: name
11968
- }
11969
- ),
11970
- fields.length > 0 && /* @__PURE__ */ jsx("div", { children: fields }),
11971
- other
11972
- ]
11973
- }
11974
- ) });
11975
- }
11976
- DiagramEntity.displayName = "DiagramEntity";
11977
-
11978
- // src/components/Diagram/diagram.markers.ts
11979
- function defaultMarkersForType(type) {
11980
- switch (type) {
11981
- case "one-to-one":
11982
- return { fromMarker: "one", toMarker: "one", lineStyle: "solid" };
11983
- case "one-to-many":
11984
- return { fromMarker: "one", toMarker: "many", lineStyle: "solid" };
11985
- case "many-to-one":
11986
- return { fromMarker: "many", toMarker: "one", lineStyle: "solid" };
11987
- case "many-to-many":
11988
- return { fromMarker: "many", toMarker: "many", lineStyle: "solid" };
11989
- case "association":
11990
- return { fromMarker: "none", toMarker: "arrow", lineStyle: "solid" };
11991
- case "aggregation":
11992
- return { fromMarker: "diamond-open", toMarker: "none", lineStyle: "solid" };
11993
- case "composition":
11994
- return { fromMarker: "diamond", toMarker: "none", lineStyle: "solid" };
11995
- case "inheritance":
11996
- return { fromMarker: "none", toMarker: "triangle-open", lineStyle: "solid" };
11997
- case "implementation":
11998
- return { fromMarker: "none", toMarker: "triangle-open", lineStyle: "dashed" };
11999
- case "dependency":
12000
- return { fromMarker: "none", toMarker: "arrow", lineStyle: "dashed" };
12001
- default:
12002
- return { fromMarker: "none", toMarker: "none", lineStyle: "solid" };
12003
- }
12004
- }
12005
- var SIZE = 12;
12006
- function renderMarker(marker, pt, direction) {
12007
- if (typeof marker === "string" && marker.startsWith("emoji:")) {
12008
- return { paths: [], text: marker.slice(6) };
12009
- }
12010
- switch (marker) {
12011
- case "none":
12012
- return null;
12013
- case "arrow":
12014
- return { paths: [{ d: arrowPath(pt, direction), fill: "stroke" }] };
12015
- case "arrow-open":
12016
- return { paths: [{ d: arrowPath(pt, direction), fill: "none" }] };
12017
- case "circle":
12018
- return { paths: [{ d: circlePath(pt), fill: "stroke" }] };
12019
- case "circle-open":
12020
- return { paths: [{ d: circlePath(pt), fill: "background" }] };
12021
- case "square":
12022
- return { paths: [{ d: squarePath(pt, direction), fill: "stroke" }] };
12023
- case "square-open":
12024
- return { paths: [{ d: squarePath(pt, direction), fill: "background" }] };
12025
- case "diamond":
12026
- return { paths: [{ d: diamondPath(pt, direction), fill: "stroke" }] };
12027
- case "diamond-open":
12028
- return { paths: [{ d: diamondPath(pt, direction), fill: "background" }] };
12029
- case "triangle":
12030
- return { paths: [{ d: trianglePath(pt, direction), fill: "stroke" }] };
12031
- case "triangle-open":
12032
- return { paths: [{ d: trianglePath(pt, direction), fill: "background" }] };
12033
- case "cross":
12034
- return { paths: [{ d: crossPath(pt, direction), fill: "none" }] };
12035
- case "one":
12036
- return { paths: [{ d: oneSymbol(pt, direction), fill: "none" }] };
12037
- case "many":
12038
- return { paths: [{ d: crowFootSymbol(pt, direction), fill: "none" }] };
12039
- case "optional-one":
12040
- return {
12041
- paths: [
12042
- { d: circleOuter(pt, direction), fill: "background" },
12043
- { d: oneSymbolOffset(pt, direction), fill: "none" }
12044
- ]
12045
- };
12046
- case "optional-many":
12047
- return {
12048
- paths: [
12049
- { d: circleOuter(pt, direction), fill: "background" },
12050
- { d: crowFootSymbolOffset(pt, direction), fill: "none" }
12051
- ]
12052
- };
12053
- default:
12054
- if (typeof marker === "string" && marker !== "") {
12055
- return { paths: [], text: marker };
12056
- }
12057
- return null;
12058
- }
12059
- }
12060
- function markerInset(marker) {
12061
- if (marker === "none" || marker === void 0) return 0;
12062
- if (typeof marker === "string" && (marker.startsWith("emoji:") || !KNOWN_MARKERS.has(marker))) {
12063
- return SIZE;
12064
- }
12065
- switch (marker) {
12066
- case "circle":
12067
- case "circle-open":
12068
- return SIZE * 0.6;
12069
- case "one":
12070
- return 0;
12071
- // bar sits AT endpoint
12072
- case "many":
12073
- return SIZE;
12074
- case "optional-one":
12075
- return SIZE * 1.2;
12076
- case "optional-many":
12077
- return SIZE * 1.8;
12078
- default:
12079
- return SIZE;
12080
- }
12081
- }
12082
- var KNOWN_MARKERS = /* @__PURE__ */ new Set([
12083
- "none",
12084
- "arrow",
12085
- "arrow-open",
12086
- "circle",
12087
- "circle-open",
12088
- "square",
12089
- "square-open",
12090
- "diamond",
12091
- "diamond-open",
12092
- "triangle",
12093
- "triangle-open",
12094
- "one",
12095
- "many",
12096
- "optional-one",
12097
- "optional-many",
12098
- "cross"
12099
- ]);
12100
- function dirVec(direction) {
12101
- switch (direction) {
12102
- case "left":
12103
- return [-1, 0];
12104
- case "right":
12105
- return [1, 0];
12106
- case "up":
12107
- return [0, -1];
12108
- case "down":
12109
- return [0, 1];
12110
- }
12111
- }
12112
- function perpVec(direction) {
12113
- switch (direction) {
12114
- case "left":
12115
- case "right":
12116
- return [0, 1];
12117
- case "up":
12118
- case "down":
12119
- return [1, 0];
12120
- }
12121
- }
12122
- function arrowPath(pt, direction, _filled) {
12123
- const [dx, dy] = dirVec(direction);
12124
- const [px, py] = perpVec(direction);
12125
- const tipX = pt.x + dx * SIZE;
12126
- const tipY = pt.y + dy * SIZE;
12127
- const baseAX = pt.x + px * (SIZE * 0.55);
12128
- const baseAY = pt.y + py * (SIZE * 0.55);
12129
- const baseBX = pt.x - px * (SIZE * 0.55);
12130
- const baseBY = pt.y - py * (SIZE * 0.55);
12131
- return `M${baseAX},${baseAY} L${tipX},${tipY} L${baseBX},${baseBY} Z`;
12132
- }
12133
- function circlePath(pt, _filled) {
12134
- const r = SIZE * 0.45;
12135
- return `M${pt.x - r},${pt.y} a${r},${r} 0 1 0 ${r * 2},0 a${r},${r} 0 1 0 ${-r * 2},0 Z`;
12136
- }
12137
- function squarePath(pt, direction, _filled) {
12138
- const [dx, dy] = dirVec(direction);
12139
- const [px, py] = perpVec(direction);
12140
- const half = SIZE * 0.5;
12141
- const cx = pt.x + dx * half;
12142
- const cy = pt.y + dy * half;
12143
- const tlX = cx - px * half - dx * half;
12144
- const tlY = cy - py * half - dy * half;
12145
- const trX = cx + px * half - dx * half;
12146
- const trY = cy + py * half - dy * half;
12147
- const brX = cx + px * half + dx * half;
12148
- const brY = cy + py * half + dy * half;
12149
- const blX = cx - px * half + dx * half;
12150
- const blY = cy - py * half + dy * half;
12151
- return `M${tlX},${tlY} L${trX},${trY} L${brX},${brY} L${blX},${blY} Z`;
12152
- }
12153
- function diamondPath(pt, direction, _filled) {
12154
- const [dx, dy] = dirVec(direction);
12155
- const [px, py] = perpVec(direction);
12156
- const len = SIZE * 1.2;
12157
- const cx = pt.x + dx * (len / 2);
12158
- const cy = pt.y + dy * (len / 2);
12159
- const aX = pt.x;
12160
- const aY = pt.y;
12161
- const bX = cx + px * (SIZE * 0.45);
12162
- const bY = cy + py * (SIZE * 0.45);
12163
- const tX = pt.x + dx * len;
12164
- const tY = pt.y + dy * len;
12165
- const dX = cx - px * (SIZE * 0.45);
12166
- const dY = cy - py * (SIZE * 0.45);
12167
- return `M${aX},${aY} L${bX},${bY} L${tX},${tY} L${dX},${dY} Z`;
12168
- }
12169
- function trianglePath(pt, direction, _filled) {
12170
- const [dx, dy] = dirVec(direction);
12171
- const [px, py] = perpVec(direction);
12172
- const len = SIZE * 1.1;
12173
- const baseCX = pt.x + dx * len;
12174
- const baseCY = pt.y + dy * len;
12175
- const baseAX = baseCX + px * (SIZE * 0.6);
12176
- const baseAY = baseCY + py * (SIZE * 0.6);
12177
- const baseBX = baseCX - px * (SIZE * 0.6);
12178
- const baseBY = baseCY - py * (SIZE * 0.6);
12179
- return `M${pt.x},${pt.y} L${baseAX},${baseAY} L${baseBX},${baseBY} Z`;
12180
- }
12181
- function crossPath(pt, direction) {
12182
- const [dx, dy] = dirVec(direction);
12183
- const [px, py] = perpVec(direction);
12184
- const s = SIZE * 0.5;
12185
- const cx = pt.x + dx * (SIZE * 0.5);
12186
- const cy = pt.y + dy * (SIZE * 0.5);
12187
- return [
12188
- `M${cx - s * (px + dx)},${cy - s * (py + dy)} L${cx + s * (px + dx)},${cy + s * (py + dy)}`,
12189
- `M${cx - s * (px - dx)},${cy - s * (py - dy)} L${cx + s * (px - dx)},${cy + s * (py - dy)}`
12190
- ].join(" ");
12191
- }
12192
- function oneSymbol(pt, direction) {
12193
- const [, py] = perpVec(direction);
12194
- const [px] = perpVec(direction);
12195
- const half = SIZE * 0.6;
12196
- return `M${pt.x - px * half},${pt.y - py * half} L${pt.x + px * half},${pt.y + py * half}`;
12197
- }
12198
- function crowFootSymbol(pt, direction) {
12199
- const [dx, dy] = dirVec(direction);
12200
- const [px, py] = perpVec(direction);
12201
- const tipX = pt.x + dx * SIZE;
12202
- const tipY = pt.y + dy * SIZE;
12203
- const spread = SIZE * 0.8;
12204
- const aX = pt.x + px * spread, aY = pt.y + py * spread;
12205
- const cX = pt.x - px * spread, cY = pt.y - py * spread;
12206
- return [
12207
- `M${aX},${aY} L${tipX},${tipY}`,
12208
- `M${pt.x},${pt.y} L${tipX},${tipY}`,
12209
- `M${cX},${cY} L${tipX},${tipY}`,
12210
- `M${aX},${aY} L${cX},${cY}`
12211
- ].join(" ");
12212
- }
12213
- function circleOuter(pt, direction) {
12214
- const [dx, dy] = dirVec(direction);
12215
- const r = SIZE * 0.4;
12216
- const cx = pt.x + dx * (SIZE * 0.4 + r);
12217
- const cy = pt.y + dy * (SIZE * 0.4 + r);
12218
- return `M${cx - r},${cy} a${r},${r} 0 1 0 ${r * 2},0 a${r},${r} 0 1 0 ${-r * 2},0 Z`;
12219
- }
12220
- function oneSymbolOffset(pt, direction) {
12221
- const [px, py] = perpVec(direction);
12222
- const half = SIZE * 0.6;
12223
- return `M${pt.x - px * half},${pt.y - py * half} L${pt.x + px * half},${pt.y + py * half}`;
12224
- }
12225
- function crowFootSymbolOffset(pt, direction) {
12226
- const [dx, dy] = dirVec(direction);
12227
- const [px, py] = perpVec(direction);
12228
- const inset = SIZE * 0.8;
12229
- const startX = pt.x + dx * inset;
12230
- const startY = pt.y + dy * inset;
12231
- const tipX = pt.x + dx * (inset + SIZE);
12232
- const tipY = pt.y + dy * (inset + SIZE);
12233
- const spread = SIZE * 0.8;
12234
- const aX = startX + px * spread, aY = startY + py * spread;
12235
- const cX = startX - px * spread, cY = startY - py * spread;
12236
- return [
12237
- `M${aX},${aY} L${tipX},${tipY}`,
12238
- `M${startX},${startY} L${tipX},${tipY}`,
12239
- `M${cX},${cY} L${tipX},${tipY}`
12240
- ].join(" ");
12241
- }
12242
-
12243
- // src/components/Diagram/diagram.routing.ts
12244
- var STUB = 24;
12245
- var DODGE_PADDING = 16;
12246
- var MAX_DODGE_ITERATIONS = 6;
12247
- function pickAnchors(from, to, fromY, toY) {
12248
- const fcx = from.x + from.width / 2;
12249
- const fcy = from.y + from.height / 2;
12250
- const tcx = to.x + to.width / 2;
12251
- const tcy = to.y + to.height / 2;
12252
- const dx = tcx - fcx;
12253
- const dy = tcy - fcy;
12254
- let fromSide, toSide;
12255
- if (Math.abs(dx) >= Math.abs(dy)) {
12256
- fromSide = dx >= 0 ? "right" : "left";
12257
- toSide = dx >= 0 ? "left" : "right";
12258
- } else {
12259
- fromSide = dy >= 0 ? "bottom" : "top";
12260
- toSide = dy >= 0 ? "top" : "bottom";
12261
- }
12262
- return {
12263
- from: anchorOnSide(from, fromSide, fromY),
12264
- to: anchorOnSide(to, toSide, toY)
12265
- };
12266
- }
12267
- function anchorOnSide(box, side, fieldY) {
12268
- switch (side) {
12269
- case "right":
12270
- return { side, x: box.x + box.width, y: box.y + (fieldY ?? box.height / 2) };
12271
- case "left":
12272
- return { side, x: box.x, y: box.y + (fieldY ?? box.height / 2) };
12273
- case "top":
12274
- return { side, x: box.x + box.width / 2, y: box.y };
12275
- case "bottom":
12276
- return { side, x: box.x + box.width / 2, y: box.y + box.height };
12277
- }
12278
- }
12279
- function stubOut(a, distance2 = STUB) {
12280
- switch (a.side) {
12281
- case "right":
12282
- return { x: a.x + distance2, y: a.y };
12283
- case "left":
12284
- return { x: a.x - distance2, y: a.y };
12285
- case "top":
12286
- return { x: a.x, y: a.y - distance2 };
12287
- case "bottom":
12288
- return { x: a.x, y: a.y + distance2 };
12289
- }
12290
- }
12291
- function manhattanPath(from, to, obstacles = []) {
12292
- const f = { x: from.x, y: from.y };
12293
- const t = { x: to.x, y: to.y };
12294
- const fs = stubOut(from);
12295
- const ts = stubOut(to);
12296
- const fHoriz = from.side === "left" || from.side === "right";
12297
- const tHoriz = to.side === "left" || to.side === "right";
12298
- if (fHoriz && tHoriz) {
12299
- const midX = pickClearMidX((fs.x + ts.x) / 2, fs.y, ts.y, obstacles);
12300
- return uniqPath([
12301
- f,
12302
- fs,
12303
- { x: midX, y: fs.y },
12304
- { x: midX, y: ts.y },
12305
- ts,
12306
- t
12307
- ]);
12308
- }
12309
- if (!fHoriz && !tHoriz) {
12310
- const midY = pickClearMidY((fs.y + ts.y) / 2, fs.x, ts.x, obstacles);
12311
- return uniqPath([
12312
- f,
12313
- fs,
12314
- { x: fs.x, y: midY },
12315
- { x: ts.x, y: midY },
12316
- ts,
12317
- t
12318
- ]);
12319
- }
12320
- if (fHoriz) {
12321
- return uniqPath([
12322
- f,
12323
- fs,
12324
- { x: ts.x, y: fs.y },
12325
- ts,
12326
- t
12327
- ]);
12328
- }
12329
- return uniqPath([
12330
- f,
12331
- fs,
12332
- { x: fs.x, y: ts.y },
12333
- ts,
12334
- t
12335
- ]);
12336
- }
12337
- function pickClearMidX(idealX, y1, y2, obstacles) {
12338
- if (obstacles.length === 0) return idealX;
12339
- const yMin = Math.min(y1, y2);
12340
- const yMax = Math.max(y1, y2);
12341
- let midX = idealX;
12342
- for (let i = 0; i < 4; i++) {
12343
- let shifted = false;
12344
- for (const ob of obstacles) {
12345
- if (ob.y + ob.height + DODGE_PADDING < yMin) continue;
12346
- if (ob.y - DODGE_PADDING > yMax) continue;
12347
- const left = ob.x - DODGE_PADDING;
12348
- const right = ob.x + ob.width + DODGE_PADDING;
12349
- if (midX > left && midX < right) {
12350
- midX = Math.abs(midX - left) <= Math.abs(midX - right) ? left - 1 : right + 1;
12351
- shifted = true;
12352
- }
12353
- }
12354
- if (!shifted) break;
12355
- }
12356
- return midX;
12357
- }
12358
- function pickClearMidY(idealY, x1, x2, obstacles) {
12359
- if (obstacles.length === 0) return idealY;
12360
- const xMin = Math.min(x1, x2);
12361
- const xMax = Math.max(x1, x2);
12362
- let midY = idealY;
12363
- for (let i = 0; i < 4; i++) {
12364
- let shifted = false;
12365
- for (const ob of obstacles) {
12366
- if (ob.x + ob.width + DODGE_PADDING < xMin) continue;
12367
- if (ob.x - DODGE_PADDING > xMax) continue;
12368
- const top = ob.y - DODGE_PADDING;
12369
- const bot = ob.y + ob.height + DODGE_PADDING;
12370
- if (midY > top && midY < bot) {
12371
- midY = Math.abs(midY - top) <= Math.abs(midY - bot) ? top - 1 : bot + 1;
12372
- shifted = true;
12373
- }
12374
- }
12375
- if (!shifted) break;
12376
- }
12377
- return midY;
12378
- }
12379
- function uniqPath(points) {
12380
- const out = [];
12381
- for (const p of points) {
12382
- const last = out[out.length - 1];
12383
- if (!last || Math.abs(last.x - p.x) > 0.5 || Math.abs(last.y - p.y) > 0.5) {
12384
- out.push(p);
12385
- }
12386
- }
12387
- return out;
12388
- }
12389
- function dodgeObstacles(path, obstacles, padding = DODGE_PADDING) {
12390
- if (obstacles.length === 0 || path.length < 2) return path;
12391
- let working = path.slice();
12392
- for (let iter = 0; iter < MAX_DODGE_ITERATIONS; iter++) {
12393
- let dodged = false;
12394
- const result = [working[0]];
12395
- for (let i = 1; i < working.length; i++) {
12396
- const a = result[result.length - 1];
12397
- const b = working[i];
12398
- const detour = detourAround(a, b, obstacles, padding);
12399
- if (detour.length === 0) {
12400
- result.push(b);
12401
- } else {
12402
- for (const p of detour) result.push(p);
12403
- result.push(b);
12404
- dodged = true;
12405
- }
12406
- }
12407
- working = uniqPath(result);
12408
- if (!dodged) break;
12409
- }
12410
- return working;
12411
- }
12412
- function detourAround(a, b, obstacles, padding) {
12413
- const isHorizontal = Math.abs(a.y - b.y) < 0.5;
12414
- const isVertical = Math.abs(a.x - b.x) < 0.5;
12415
- if (!isHorizontal && !isVertical) return [];
12416
- let best = null;
12417
- for (const r of obstacles) {
12418
- const expanded = expandRect(r, padding);
12419
- if (!segmentCrossesRect(a, b, expanded)) continue;
12420
- let entry, exit;
12421
- if (isHorizontal) {
12422
- entry = b.x > a.x ? expanded.x : expanded.x + expanded.width;
12423
- exit = b.x > a.x ? expanded.x + expanded.width : expanded.x;
12424
- } else {
12425
- entry = b.y > a.y ? expanded.y : expanded.y + expanded.height;
12426
- exit = b.y > a.y ? expanded.y + expanded.height : expanded.y;
12427
- }
12428
- const dist = isHorizontal ? Math.abs(entry - a.x) : Math.abs(entry - a.y);
12429
- if (!best || dist < (isHorizontal ? Math.abs(best.entry - a.x) : Math.abs(best.entry - a.y))) {
12430
- best = { rect: expanded, entry, exit };
12431
- }
12432
- }
12433
- if (!best) return [];
12434
- if (isHorizontal) {
12435
- const aboveY = best.rect.y - 1;
12436
- const belowY = best.rect.y + best.rect.height + 1;
12437
- const detourY = Math.abs(a.y - aboveY) <= Math.abs(a.y - belowY) ? aboveY : belowY;
12438
- return [
12439
- { x: best.entry, y: a.y },
12440
- { x: best.entry, y: detourY },
12441
- { x: best.exit, y: detourY },
12442
- { x: best.exit, y: a.y }
12443
- ];
12444
- } else {
12445
- const leftX = best.rect.x - 1;
12446
- const rightX = best.rect.x + best.rect.width + 1;
12447
- const detourX = Math.abs(a.x - leftX) <= Math.abs(a.x - rightX) ? leftX : rightX;
12448
- return [
12449
- { x: a.x, y: best.entry },
12450
- { x: detourX, y: best.entry },
12451
- { x: detourX, y: best.exit },
12452
- { x: a.x, y: best.exit }
12453
- ];
12454
- }
12455
- }
12456
- function expandRect(r, padding) {
12457
- return {
12458
- x: r.x - padding,
12459
- y: r.y - padding,
12460
- width: r.width + padding * 2,
12461
- height: r.height + padding * 2
12462
- };
12463
- }
12464
- function segmentCrossesRect(a, b, rect) {
12465
- const xMin = Math.min(a.x, b.x);
12466
- const xMax = Math.max(a.x, b.x);
12467
- const yMin = Math.min(a.y, b.y);
12468
- const yMax = Math.max(a.y, b.y);
12469
- if (xMax < rect.x) return false;
12470
- if (xMin > rect.x + rect.width) return false;
12471
- if (yMax < rect.y) return false;
12472
- if (yMin > rect.y + rect.height) return false;
12473
- if (a.x >= rect.x + 1 && a.x <= rect.x + rect.width - 1 && a.y >= rect.y + 1 && a.y <= rect.y + rect.height - 1) return false;
12474
- if (b.x >= rect.x + 1 && b.x <= rect.x + rect.width - 1 && b.y >= rect.y + 1 && b.y <= rect.y + rect.height - 1) return false;
12475
- return true;
12476
- }
12477
- function pathFromPoints(points, cornerRadius = 8) {
12478
- if (points.length === 0) return "";
12479
- if (points.length === 1) return `M${points[0].x},${points[0].y}`;
12480
- if (points.length === 2 || cornerRadius <= 0) {
12481
- return points.map((p, i) => `${i === 0 ? "M" : "L"}${p.x},${p.y}`).join(" ");
12482
- }
12483
- let d = `M${points[0].x},${points[0].y}`;
12484
- for (let i = 1; i < points.length - 1; i++) {
12485
- const prev = points[i - 1];
12486
- const curr = points[i];
12487
- const next = points[i + 1];
12488
- const r = Math.min(
12489
- cornerRadius,
12490
- distance(prev, curr) / 2,
12491
- distance(curr, next) / 2
12492
- );
12493
- if (r < 1) {
12494
- d += ` L${curr.x},${curr.y}`;
12495
- continue;
12496
- }
12497
- const beforeX = curr.x + Math.sign(prev.x - curr.x) * r;
12498
- const beforeY = curr.y + Math.sign(prev.y - curr.y) * r;
12499
- const afterX = curr.x + Math.sign(next.x - curr.x) * r;
12500
- const afterY = curr.y + Math.sign(next.y - curr.y) * r;
12501
- d += ` L${beforeX},${beforeY} Q${curr.x},${curr.y} ${afterX},${afterY}`;
12502
- }
12503
- const last = points[points.length - 1];
12504
- d += ` L${last.x},${last.y}`;
12505
- return d;
12506
- }
12507
- function distance(a, b) {
12508
- return Math.hypot(b.x - a.x, b.y - a.y);
12509
- }
12510
- function bezierPath2(from, to) {
12511
- const fs = stubOut(from, Math.max(40, distance(from, to) * 0.3));
12512
- const ts = stubOut(to, Math.max(40, distance(from, to) * 0.3));
12513
- return `M${from.x},${from.y} C${fs.x},${fs.y} ${ts.x},${ts.y} ${to.x},${to.y}`;
12514
- }
12515
- function midPoint(points) {
12516
- if (points.length === 0) return { x: 0, y: 0 };
12517
- if (points.length === 1) return points[0];
12518
- let total = 0;
12519
- const segLens = [];
12520
- for (let i = 1; i < points.length; i++) {
12521
- const len = distance(points[i - 1], points[i]);
12522
- segLens.push(len);
12523
- total += len;
12524
- }
12525
- let target = total / 2;
12526
- for (let i = 0; i < segLens.length; i++) {
12527
- if (target <= segLens[i]) {
12528
- const t = segLens[i] === 0 ? 0 : target / segLens[i];
12529
- const a = points[i];
12530
- const b = points[i + 1];
12531
- return { x: a.x + (b.x - a.x) * t, y: a.y + (b.y - a.y) * t };
12532
- }
12533
- target -= segLens[i];
12534
- }
12535
- return points[points.length - 1];
12536
- }
12537
- function insetEndpoints(points, inset) {
12538
- if (points.length < 2) return points;
12539
- const result = points.slice();
12540
- if (inset.from > 0) {
12541
- const a = result[0];
12542
- const b = result[1];
12543
- const len = distance(a, b);
12544
- if (len > inset.from) {
12545
- const t = inset.from / len;
12546
- result[0] = { x: a.x + (b.x - a.x) * t, y: a.y + (b.y - a.y) * t };
12547
- }
12548
- }
12549
- if (inset.to > 0) {
12550
- const lastIdx = result.length - 1;
12551
- const a = result[lastIdx];
12552
- const b = result[lastIdx - 1];
12553
- const len = distance(a, b);
12554
- if (len > inset.to) {
12555
- const t = inset.to / len;
12556
- result[lastIdx] = { x: a.x + (b.x - a.x) * t, y: a.y + (b.y - a.y) * t };
12557
- }
12558
- }
12559
- return result;
12560
- }
12561
- var HEADER_HEIGHT = 36;
12562
- var FIELD_HEIGHT = 29;
12563
- var DEFAULT_COLOR2 = "#71717a";
12564
- function markerDirection(side) {
12565
- switch (side) {
12566
- case "left":
12567
- return "right";
12568
- // entity body is to the right of a left-side anchor
12569
- case "right":
12570
- return "left";
12571
- case "top":
12572
- return "down";
12573
- case "bottom":
12574
- return "up";
12575
- }
12576
- }
12577
- function strokeDashArray(style) {
12578
- switch (style) {
12579
- case "dashed":
12580
- return "8 4";
12581
- case "dotted":
12582
- return "2 4";
12583
- default:
12584
- return void 0;
12585
- }
12586
- }
12587
- function DiagramRelation({
12588
- from,
12589
- to,
12590
- fromField: fromFieldProp,
12591
- toField: toFieldProp,
12592
- type,
12593
- fromMarker: fromMarkerProp,
12594
- toMarker: toMarkerProp,
12595
- lineStyle: lineStyleProp,
12596
- routing = "manhattan",
12597
- color = DEFAULT_COLOR2,
12598
- strokeWidth = 2,
12599
- label
12600
- }) {
12601
- const { nodeRects, registryVersion } = useCanvas();
12602
- const { schema } = useDiagram();
12603
- const result = useMemo(() => {
12604
- const fromRect = nodeRects.get(from);
12605
- const toRect = nodeRects.get(to);
12606
- if (!fromRect || !toRect) return null;
12607
- const defaults = defaultMarkersForType(type);
12608
- const fromMarker = fromMarkerProp ?? defaults.fromMarker;
12609
- const toMarker = toMarkerProp ?? defaults.toMarker;
12610
- const lineStyle = lineStyleProp ?? defaults.lineStyle;
12611
- const fromEntity = schema.entities.find((e) => (e.id ?? e.name) === from);
12612
- const toEntity = schema.entities.find((e) => (e.id ?? e.name) === to);
12613
- const fromFieldY = resolveFieldY(fromRect, fromEntity?.fields, fromFieldProp, true);
12614
- const toFieldY = resolveFieldY(toRect, toEntity?.fields, toFieldProp, false, fromEntity?.name ?? from);
12615
- const anchors = pickAnchors(fromRect, toRect, fromFieldY, toFieldY);
12616
- if (anchors.from.side === "top" || anchors.from.side === "bottom") {
12617
- anchors.from.x = fromRect.x + fromRect.width / 2;
12618
- }
12619
- if (anchors.to.side === "top" || anchors.to.side === "bottom") {
12620
- anchors.to.x = toRect.x + toRect.width / 2;
12621
- }
12622
- let points;
12623
- if (routing === "straight") {
12624
- points = [
12625
- { x: anchors.from.x, y: anchors.from.y },
12626
- { x: anchors.to.x, y: anchors.to.y }
12627
- ];
12628
- } else if (routing === "bezier") {
12629
- points = [];
12630
- } else {
12631
- const obstacles = [];
12632
- nodeRects.forEach((rect, id) => {
12633
- if (id === from || id === to) return;
12634
- obstacles.push(rect);
12635
- });
12636
- const initial = manhattanPath(anchors.from, anchors.to, obstacles);
12637
- points = dodgeObstacles(initial, obstacles);
12638
- }
12639
- const insetAmount = { from: markerInset(fromMarker), to: markerInset(toMarker) };
12640
- if (routing !== "bezier") {
12641
- points = insetEndpoints(points, insetAmount);
12642
- }
12643
- const linePath = routing === "bezier" ? bezierPath2(anchors.from, anchors.to) : pathFromPoints(points);
12644
- const fromMarkerRenderable = renderMarker(
12645
- fromMarker,
12646
- { x: anchors.from.x, y: anchors.from.y },
12647
- markerDirection(anchors.from.side)
12648
- );
12649
- const toMarkerRenderable = renderMarker(
12650
- toMarker,
12651
- { x: anchors.to.x, y: anchors.to.y },
12652
- markerDirection(anchors.to.side)
12653
- );
12654
- const mid = routing === "bezier" ? { x: (anchors.from.x + anchors.to.x) / 2, y: (anchors.from.y + anchors.to.y) / 2 } : midPoint(points);
12655
- return {
12656
- linePath,
12657
- fromMarker: fromMarkerRenderable,
12658
- toMarker: toMarkerRenderable,
12659
- fromAnchor: anchors.from,
12660
- toAnchor: anchors.to,
12661
- mid,
12662
- lineStyle
12663
- };
12664
- }, [
12665
- from,
12666
- to,
12667
- fromFieldProp,
12668
- toFieldProp,
12669
- type,
12670
- fromMarkerProp,
12671
- toMarkerProp,
12672
- lineStyleProp,
12673
- routing,
12674
- schema,
12675
- nodeRects,
12676
- registryVersion
12677
- ]);
12678
- if (!result) return null;
12679
- const dashArray = strokeDashArray(result.lineStyle);
12680
- return /* @__PURE__ */ jsxs("g", { "data-react-fancy-diagram-relation": "", children: [
12681
- /* @__PURE__ */ jsx(
12682
- "path",
12683
- {
12684
- d: result.linePath,
12685
- fill: "none",
12686
- stroke: color,
12687
- strokeWidth,
12688
- strokeDasharray: dashArray,
12689
- strokeLinecap: "round",
12690
- strokeLinejoin: "round"
12691
- }
12692
- ),
12693
- result.fromMarker?.paths.map((shape, i) => /* @__PURE__ */ jsx(
12694
- "path",
12695
- {
12696
- d: shape.d,
12697
- fill: shape.fill === "stroke" ? color : shape.fill === "background" ? "#ffffff" : "none",
12698
- stroke: color,
12699
- strokeWidth,
12700
- strokeLinecap: "round",
12701
- strokeLinejoin: "round"
12702
- },
12703
- `fm-${i}`
12704
- )),
12705
- result.fromMarker?.text && /* @__PURE__ */ jsx(
12706
- "text",
12707
- {
12708
- x: result.fromAnchor.x,
12709
- y: result.fromAnchor.y,
12710
- fontSize: 16,
12711
- textAnchor: "middle",
12712
- dominantBaseline: "middle",
12713
- style: { userSelect: "none" },
12714
- children: result.fromMarker.text
12715
- }
12716
- ),
12717
- result.toMarker?.text && /* @__PURE__ */ jsx(
12718
- "text",
12719
- {
12720
- x: result.toAnchor.x,
12721
- y: result.toAnchor.y,
12722
- fontSize: 16,
12723
- textAnchor: "middle",
12724
- dominantBaseline: "middle",
12725
- style: { userSelect: "none" },
12726
- children: result.toMarker.text
12727
- }
12728
- ),
12729
- result.toMarker?.paths.map((shape, i) => /* @__PURE__ */ jsx(
12730
- "path",
12731
- {
12732
- d: shape.d,
12733
- fill: shape.fill === "stroke" ? color : shape.fill === "background" ? "#ffffff" : "none",
12734
- stroke: color,
12735
- strokeWidth,
12736
- strokeLinecap: "round",
12737
- strokeLinejoin: "round"
12738
- },
12739
- `tm-${i}`
12740
- )),
12741
- label && /* @__PURE__ */ jsx("foreignObject", { x: result.mid.x - 50, y: result.mid.y - 12, width: 100, height: 24, children: /* @__PURE__ */ jsx("div", { className: "flex items-center justify-center text-xs text-zinc-500", children: /* @__PURE__ */ jsx("span", { className: "rounded bg-white/90 px-1.5 py-0.5 dark:bg-zinc-900/90", children: label }) }) })
12742
- ] });
12743
- }
12744
- function resolveFieldY(rect, fields, fieldProp, isFrom, fromName) {
12745
- if (!fields || fields.length === 0) return void 0;
12746
- let idx = -1;
12747
- if (fieldProp) {
12748
- idx = fields.findIndex((f) => f.name === fieldProp);
12749
- } else if (isFrom) {
12750
- idx = fields.findIndex((f) => f.primary);
12751
- } else {
12752
- const lower = (fromName ?? "").toLowerCase();
12753
- idx = fields.findIndex(
12754
- (f) => f.foreign && (f.name === `${lower}_id` || f.name === `${lower}Id`)
12755
- );
12756
- if (idx === -1) idx = fields.findIndex((f) => f.foreign);
12757
- }
12758
- if (idx < 0) return void 0;
12759
- return HEADER_HEIGHT + idx * FIELD_HEIGHT + FIELD_HEIGHT / 2;
12760
- }
12761
- DiagramRelation._isCanvasEdge = true;
12762
- DiagramRelation.displayName = "DiagramRelation";
12763
- var FORMAT_LABELS = {
12764
- erd: "ERD",
12765
- uml: "UML",
12766
- dfd: "DFD"
12767
- };
12768
- var FORMAT_EXTENSIONS = {
12769
- erd: "erd",
12770
- uml: "puml",
12771
- dfd: "dfd"
12772
- };
12773
- function DiagramToolbar({ className }) {
12774
- const { schema, downloadableRef, importableRef, exportFormats, onImport } = useDiagram();
12775
- const fileInputRef = useRef(null);
12776
- const canDownload = downloadableRef.current;
12777
- const canImport = importableRef.current;
12778
- const handleDownload = useCallback(
12779
- async (format) => {
12780
- const { serializeToERD, serializeToUML, serializeToDFD } = await import('./diagram.serializers-6RPUO46U.js');
12781
- let content;
12782
- switch (format) {
12783
- case "erd":
12784
- content = serializeToERD(schema);
12785
- break;
12786
- case "uml":
12787
- content = serializeToUML(schema);
12788
- break;
12789
- case "dfd":
12790
- content = serializeToDFD(schema);
12791
- break;
12792
- }
12793
- const blob = new Blob([content], { type: "text/plain;charset=utf-8" });
12794
- const url = URL.createObjectURL(blob);
12795
- const a = document.createElement("a");
12796
- a.href = url;
12797
- a.download = `diagram.${FORMAT_EXTENSIONS[format]}`;
12798
- document.body.appendChild(a);
12799
- a.click();
12800
- document.body.removeChild(a);
12801
- URL.revokeObjectURL(url);
12802
- },
12803
- [schema]
12804
- );
12805
- const handleFileChange = useCallback(
12806
- async (e) => {
12807
- const file = e.target.files?.[0];
12808
- if (!file || !onImport) return;
12809
- const text = await file.text();
12810
- const ext = file.name.split(".").pop()?.toLowerCase();
12811
- const { deserializeSchema } = await import('./diagram.serializers-6RPUO46U.js');
12812
- let format = "erd";
12813
- if (ext === "puml" || ext === "uml") format = "uml";
12814
- else if (ext === "dfd") format = "dfd";
12815
- const parsed = deserializeSchema(text, format);
12816
- onImport(parsed);
12817
- if (fileInputRef.current) {
12818
- fileInputRef.current.value = "";
12819
- }
12820
- },
12821
- [onImport]
12822
- );
12823
- if (!canDownload && !canImport) return null;
12824
- return /* @__PURE__ */ jsxs(
12825
- "div",
12826
- {
12827
- "data-react-fancy-diagram-toolbar": "",
12828
- className: cn(
12829
- "absolute right-3 top-3 z-10 flex items-center gap-1 rounded-lg border border-zinc-200 bg-white/90 p-1 shadow-sm backdrop-blur-sm dark:border-zinc-700 dark:bg-zinc-800/90",
12830
- className
12831
- ),
12832
- children: [
12833
- canDownload && exportFormats.map((format) => /* @__PURE__ */ jsx(
12834
- "button",
12835
- {
12836
- type: "button",
12837
- onClick: () => handleDownload(format),
12838
- className: "rounded px-2 py-1 text-xs font-medium text-zinc-600 transition-colors hover:bg-zinc-100 hover:text-zinc-900 dark:text-zinc-400 dark:hover:bg-zinc-700 dark:hover:text-zinc-200",
12839
- children: FORMAT_LABELS[format]
12840
- },
12841
- format
12842
- )),
12843
- canImport && /* @__PURE__ */ jsxs(Fragment, { children: [
12844
- /* @__PURE__ */ jsx(
12845
- "button",
12846
- {
12847
- type: "button",
12848
- onClick: () => fileInputRef.current?.click(),
12849
- className: "rounded px-2 py-1 text-xs font-medium text-zinc-600 transition-colors hover:bg-zinc-100 hover:text-zinc-900 dark:text-zinc-400 dark:hover:bg-zinc-700 dark:hover:text-zinc-200",
12850
- children: "Import"
12851
- }
12852
- ),
12853
- /* @__PURE__ */ jsx(
12854
- "input",
12855
- {
12856
- ref: fileInputRef,
12857
- type: "file",
12858
- accept: ".erd,.puml,.uml,.dfd,.txt",
12859
- className: "hidden",
12860
- onChange: handleFileChange
12861
- }
12862
- )
12863
- ] })
12864
- ]
12865
- }
12866
- );
12867
- }
12868
- DiagramToolbar.displayName = "DiagramToolbar";
12869
-
12870
- // src/components/Diagram/diagram.layout.ts
12871
- var ENTITY_WIDTH = 220;
12872
- var HEADER_HEIGHT2 = 40;
12873
- var FIELD_HEIGHT2 = 28;
12874
- var HORIZONTAL_GAP = 80;
12875
- var VERTICAL_GAP = 60;
12876
- function getEntityHeight(fieldCount) {
12877
- return HEADER_HEIGHT2 + Math.max(fieldCount, 1) * FIELD_HEIGHT2;
12878
- }
12879
- function resolveEntityId(entity) {
12880
- return entity.id ?? entity.name;
12881
- }
12882
- function computeDiagramLayout(schema) {
12883
- const positions = /* @__PURE__ */ new Map();
12884
- const entityIds = new Set(schema.entities.map(resolveEntityId));
12885
- const incoming = /* @__PURE__ */ new Map();
12886
- for (const id of entityIds) {
12887
- incoming.set(id, /* @__PURE__ */ new Set());
12888
- }
12889
- for (const rel of schema.relations) {
12890
- if (entityIds.has(rel.from) && entityIds.has(rel.to)) {
12891
- incoming.get(rel.to).add(rel.from);
12892
- }
12893
- }
12894
- const rowAssignment = /* @__PURE__ */ new Map();
12895
- const assigned = /* @__PURE__ */ new Set();
12896
- const queue = [];
12897
- for (const id of entityIds) {
12898
- if (incoming.get(id).size === 0) {
12899
- rowAssignment.set(id, 0);
12900
- assigned.add(id);
12901
- queue.push(id);
12902
- }
12903
- }
12904
- if (queue.length === 0 && entityIds.size > 0) {
12905
- const firstId = resolveEntityId(schema.entities[0]);
12906
- rowAssignment.set(firstId, 0);
12907
- assigned.add(firstId);
12908
- queue.push(firstId);
12909
- }
12910
- const outgoing = /* @__PURE__ */ new Map();
12911
- for (const id of entityIds) {
12912
- outgoing.set(id, []);
12913
- }
12914
- for (const rel of schema.relations) {
12915
- if (entityIds.has(rel.from) && entityIds.has(rel.to)) {
12916
- outgoing.get(rel.from).push(rel.to);
12917
- }
12918
- }
12919
- let head = 0;
12920
- while (head < queue.length) {
12921
- const current = queue[head++];
12922
- const currentRow = rowAssignment.get(current);
12923
- for (const neighbor of outgoing.get(current) ?? []) {
12924
- if (!assigned.has(neighbor)) {
12925
- rowAssignment.set(neighbor, currentRow + 1);
12926
- assigned.add(neighbor);
12927
- queue.push(neighbor);
12928
- }
12929
- }
12930
- }
12931
- for (const id of entityIds) {
12932
- if (!assigned.has(id)) {
12933
- rowAssignment.set(id, 0);
12934
- }
12935
- }
12936
- const rows = /* @__PURE__ */ new Map();
12937
- for (const [id, row] of rowAssignment) {
12938
- if (!rows.has(row)) {
12939
- rows.set(row, []);
12940
- }
12941
- rows.get(row).push(id);
12942
- }
12943
- const fieldCounts = /* @__PURE__ */ new Map();
12944
- for (const entity of schema.entities) {
12945
- fieldCounts.set(resolveEntityId(entity), entity.fields?.length ?? 0);
12946
- }
12947
- const sortedRows = Array.from(rows.keys()).sort((a, b) => a - b);
12948
- let currentY = 0;
12949
- for (const rowIndex of sortedRows) {
12950
- const rowEntities = rows.get(rowIndex);
12951
- const totalWidth = rowEntities.length * ENTITY_WIDTH + (rowEntities.length - 1) * HORIZONTAL_GAP;
12952
- const startX = -totalWidth / 2 + ENTITY_WIDTH / 2;
12953
- let maxHeight = 0;
12954
- for (let i = 0; i < rowEntities.length; i++) {
12955
- const entityId = rowEntities[i];
12956
- const x = startX + i * (ENTITY_WIDTH + HORIZONTAL_GAP) - ENTITY_WIDTH / 2;
12957
- positions.set(entityId, { x, y: currentY });
12958
- const height = getEntityHeight(fieldCounts.get(entityId) ?? 0);
12959
- if (height > maxHeight) {
12960
- maxHeight = height;
12961
- }
12962
- }
12963
- currentY += maxHeight + VERTICAL_GAP;
12964
- }
12965
- return positions;
12966
- }
12967
- function DiagramRoot({
12968
- children,
12969
- schema,
12970
- type = "general",
12971
- viewport,
12972
- defaultViewport,
12973
- onViewportChange,
12974
- downloadable = false,
12975
- importable = false,
12976
- exportFormats = ["erd"],
12977
- onImport,
12978
- minimap = false,
12979
- className
12980
- }) {
12981
- const downloadableRef = useRef(downloadable);
12982
- const importableRef = useRef(importable);
12983
- const normalizedSchema = useMemo(() => {
12984
- if (!schema) return { entities: [], relations: [] };
12985
- const entities = schema.entities.map((e) => ({
12986
- ...e,
12987
- id: e.id ?? e.name
12988
- }));
12989
- const relations = schema.relations.map((r, i) => ({
12990
- ...r,
12991
- id: r.id ?? `rel-${i}`
12992
- }));
12993
- return { entities, relations };
12994
- }, [schema]);
12995
- const initialPositions = useMemo(() => {
12996
- if (normalizedSchema.entities.length === 0) return /* @__PURE__ */ new Map();
12997
- const layout = computeDiagramLayout(normalizedSchema);
12998
- const positions = /* @__PURE__ */ new Map();
12999
- for (const entity of normalizedSchema.entities) {
13000
- if (entity.x !== void 0 && entity.y !== void 0) {
13001
- positions.set(entity.id, { x: entity.x, y: entity.y });
13002
- } else {
13003
- const pos = layout.get(entity.id);
13004
- positions.set(entity.id, pos ?? { x: 0, y: 0 });
13005
- }
13006
- }
13007
- return positions;
13008
- }, [normalizedSchema]);
13009
- const computedDefaultViewport = useMemo(() => {
13010
- if (defaultViewport) return defaultViewport;
13011
- if (initialPositions.size === 0) return { panX: 0, panY: 0, zoom: 1 };
13012
- let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;
13013
- initialPositions.forEach((pos) => {
13014
- minX = Math.min(minX, pos.x);
13015
- minY = Math.min(minY, pos.y);
13016
- maxX = Math.max(maxX, pos.x + 220);
13017
- maxY = Math.max(maxY, pos.y + 200);
13018
- });
13019
- const padding = 40;
13020
- const panX = -minX + padding;
13021
- const panY = -minY + padding;
13022
- return { panX, panY, zoom: 1 };
13023
- }, [defaultViewport, initialPositions]);
13024
- const [entityPositions, setEntityPositions] = useState(initialPositions);
13025
- const handleEntityMove = useCallback((entityId, x, y) => {
13026
- setEntityPositions((prev) => {
13027
- const next = new Map(prev);
13028
- next.set(entityId, { x, y });
13029
- return next;
13030
- });
13031
- }, []);
13032
- const ctx = useMemo(
13033
- () => ({
13034
- diagramType: type,
13035
- schema: normalizedSchema,
13036
- downloadableRef,
13037
- importableRef,
13038
- exportFormats,
13039
- onImport
13040
- }),
13041
- [type, normalizedSchema, exportFormats, onImport]
13042
- );
13043
- return /* @__PURE__ */ jsx(DiagramContext.Provider, { value: ctx, children: /* @__PURE__ */ jsx("div", { "data-react-fancy-diagram": "", className: "relative h-full w-full", children: /* @__PURE__ */ jsxs(
13044
- Canvas,
13045
- {
13046
- viewport,
13047
- defaultViewport: computedDefaultViewport,
13048
- onViewportChange,
13049
- showGrid: true,
13050
- fitOnMount: true,
13051
- className: cn("h-full w-full", className),
13052
- children: [
13053
- normalizedSchema.entities.map((entity) => {
13054
- const pos = entityPositions.get(entity.id) ?? { x: 0, y: 0 };
13055
- return /* @__PURE__ */ jsx(
13056
- DiagramEntity,
13057
- {
13058
- id: entity.id,
13059
- name: entity.name,
13060
- x: pos.x,
13061
- y: pos.y,
13062
- draggable: true,
13063
- onPositionChange: (nx, ny) => handleEntityMove(entity.id, nx, ny),
13064
- children: entity.fields?.map((field) => /* @__PURE__ */ jsx(
13065
- DiagramField,
13066
- {
13067
- name: field.name,
13068
- type: field.type,
13069
- primary: field.primary,
13070
- foreign: field.foreign,
13071
- nullable: field.nullable
13072
- },
13073
- field.name
13074
- ))
13075
- },
13076
- entity.id
13077
- );
13078
- }),
13079
- normalizedSchema.relations.map((rel) => /* @__PURE__ */ jsx(
13080
- DiagramRelation,
13081
- {
13082
- from: rel.from,
13083
- to: rel.to,
13084
- fromField: rel.fromField,
13085
- toField: rel.toField,
13086
- type: rel.type,
13087
- label: rel.label
13088
- },
13089
- rel.id
13090
- )),
13091
- children,
13092
- /* @__PURE__ */ jsx(Canvas.Controls, {}),
13093
- minimap && /* @__PURE__ */ jsx(Canvas.Minimap, {})
13094
- ]
13095
- }
13096
- ) }) });
13097
- }
13098
- var Diagram = Object.assign(DiagramRoot, {
13099
- Entity: DiagramEntity,
13100
- Field: DiagramField,
13101
- Relation: DiagramRelation,
13102
- Toolbar: DiagramToolbar
13103
- });
13104
11457
  var TreeNavContext = createContext(null);
13105
11458
  function useTreeNav() {
13106
11459
  const ctx = useContext(TreeNavContext);
@@ -13467,6 +11820,6 @@ var TreeNav = Object.assign(TreeNavRoot, {
13467
11820
  Node: TreeNode
13468
11821
  });
13469
11822
 
13470
- export { Accordion, AccordionPanel, AccordionPanelContent, AccordionPanelSection, AccordionPanelTrigger, Action, Autocomplete, Avatar, Badge, Brand, Breadcrumbs, Calendar, Callout, Canvas, Card, Carousel, Chart, Checkbox, CheckboxGroup, ColorPicker, Command, Composer, ContentRenderer, ContextMenu, DatePicker, Diagram, Dropdown, EMOJI_CATEGORY_ORDER, EMOJI_DATA, EMOJI_ENTRIES, Editor, Emoji, EmojiSelect, Field, FileUpload, Heading, Icon, Input, Kanban, Menu2 as Menu, MobileMenu, Modal, MultiSwitch, Navbar, OtpInput, Pagination, Pillbox, Popover, Portal, Profile, Progress, RadioGroup, SKIN_TONES, Select, Separator, Sidebar, Skeleton, Slider, Switch, Table, Tabs, Text, Textarea, TimePicker, Timeline, Toast, Tooltip, TreeNav, applyTone, cn, configureIcons, find, hasSkinTones, registerExtension, registerExtensions, registerIconSet, registerIcons, resolve, sanitizeHref, sanitizeHtml, search, skinTones, useAccordion, useAccordionPanel, useAccordionSection, useAnimation, useCanvas, useCarousel, useCommand, useContextMenu, useControllableState, useDiagram, useDropdown, useEditor, useEscapeKey, useFileUpload, useFloatingPosition, useFocusTrap, useId12 as useId, useKanban, useMenu, useMobileMenu, useModal, useNavbar, useNodeRegistry, useOutsideClick, usePanZoom, usePopover, useSidebar, useTabs, useToast, useTreeNav };
11823
+ export { Accordion, AccordionPanel, AccordionPanelContent, AccordionPanelSection, AccordionPanelTrigger, Action, Autocomplete, Avatar, Badge, Brand, Breadcrumbs, Calendar, Callout, Card, Carousel, Chart, Checkbox, CheckboxGroup, ColorPicker, Command, Composer, ContentRenderer, ContextMenu, DatePicker, Dropdown, EMOJI_CATEGORY_ORDER, EMOJI_DATA, EMOJI_ENTRIES, Editor, Emoji, EmojiSelect, Field, FileUpload, Heading, Icon, Input, Kanban, Menu2 as Menu, MobileMenu, Modal, MultiSwitch, Navbar, OtpInput, Pagination, Pillbox, Popover, Portal, Profile, Progress, RadioGroup, SKIN_TONES, Select, Separator, Sidebar, Skeleton, Slider, Switch, Table, Tabs, Text, Textarea, TimePicker, Timeline, Toast, Tooltip, TreeNav, applyTone, cn, configureIcons, find, hasSkinTones, registerExtension, registerExtensions, registerIconSet, registerIcons, resolve, sanitizeHref, sanitizeHtml, search, skinTones, useAccordion, useAccordionPanel, useAccordionSection, useAnimation, useCarousel, useCommand, useContextMenu, useControllableState, useDropdown, useEditor, useEscapeKey, useFileUpload, useFloatingPosition, useFocusTrap, useId12 as useId, useKanban, useMenu, useMobileMenu, useModal, useNavbar, useNodeRegistry, useOutsideClick, usePanZoom, usePopover, useSidebar, useTabs, useToast, useTreeNav };
13471
11824
  //# sourceMappingURL=index.js.map
13472
11825
  //# sourceMappingURL=index.js.map