@constructive-io/ui 0.2.0 → 0.3.1
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/components/checkbox.js +1 -1
- package/dist/components/checkbox.js.map +1 -1
- package/dist/components/combobox.js +1 -1
- package/dist/components/combobox.js.map +1 -1
- package/dist/components/dropdown-menu.js +3 -3
- package/dist/components/dropdown-menu.js.map +1 -1
- package/dist/components/input-group.js +1 -1
- package/dist/components/input-group.js.map +1 -1
- package/dist/components/org-chart/index.d.ts +54 -0
- package/dist/components/org-chart/index.js +861 -0
- package/dist/components/org-chart/index.js.map +1 -0
- package/dist/components/record-picker.js +2 -2
- package/dist/components/record-picker.js.map +1 -1
- package/dist/components/toast/index.js +435 -32
- package/dist/components/toast/index.js.map +1 -1
- package/dist/index.cjs +618 -44
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +61 -1
- package/dist/index.d.ts +61 -1
- package/dist/index.js +610 -38
- package/dist/index.js.map +1 -1
- package/package.json +13 -2
package/dist/index.js
CHANGED
|
@@ -13,7 +13,7 @@ import { Radio as Radio$1 } from '@base-ui/react/radio';
|
|
|
13
13
|
import { RadioGroup as RadioGroup$1 } from '@base-ui/react/radio-group';
|
|
14
14
|
import { Switch as Switch$1 } from '@base-ui/react/switch';
|
|
15
15
|
import { Select as Select$1 } from '@base-ui/react/select';
|
|
16
|
-
import { ChevronsUpDownIcon, XCircle, XIcon, ChevronDown, SearchIcon, CheckIcon, ChevronRight, ChevronUpIcon, ChevronDownIcon, CircleIcon, ChevronRightIcon, X, GripVerticalIcon, ChevronLeftIcon, MoreHorizontalIcon, LoaderCircleIcon, PanelLeftIcon, WandSparkles,
|
|
16
|
+
import { ChevronsUpDownIcon, XCircle, XIcon, ChevronDown, SearchIcon, CheckIcon, Ellipsis, Pencil, Trash2, ChevronRight, ChevronUpIcon, ChevronDownIcon, CircleIcon, ChevronRightIcon, X, GripVerticalIcon, ChevronLeftIcon, MoreHorizontalIcon, LoaderCircleIcon, PanelLeftIcon, WandSparkles, InfoIcon, CheckCircleIcon, AlertTriangleIcon, Loader2, AlertCircleIcon, CopyIcon, CircleAlert, CheckCircle2, Network, UserPlus } from 'lucide-react';
|
|
17
17
|
import { Progress as Progress$1 } from '@base-ui/react/progress';
|
|
18
18
|
import { FormProvider, Controller, useFormContext, useFormState } from 'react-hook-form';
|
|
19
19
|
import { Tooltip as Tooltip$1 } from '@base-ui/react/tooltip';
|
|
@@ -29,15 +29,17 @@ import { Collapsible as Collapsible$1 } from '@base-ui/react/collapsible';
|
|
|
29
29
|
import * as ResizablePrimitive from 'react-resizable-panels';
|
|
30
30
|
import { Avatar as Avatar$1 } from '@base-ui/react/avatar';
|
|
31
31
|
import { Autocomplete as Autocomplete$1 } from '@base-ui/react/autocomplete';
|
|
32
|
+
import { Handle, Position, useReactFlow, Panel, ReactFlowProvider, useNodesState, useEdgesState, ReactFlow, Background, BackgroundVariant, getSmoothStepPath, BaseEdge } from '@xyflow/react';
|
|
33
|
+
import { RiAddLine, RiSubtractLine, RiFocus3Line, RiSearchLine, RiLoader4Line, RiCheckLine, RiCloseLine } from '@remixicon/react';
|
|
32
34
|
import { Command as Command$1 } from 'cmdk';
|
|
33
35
|
import { Combobox as Combobox$1 } from '@base-ui/react/combobox';
|
|
34
|
-
import { RiSearchLine, RiLoader4Line, RiCheckLine, RiCloseLine } from '@remixicon/react';
|
|
35
36
|
import { matchSorter } from 'match-sorter';
|
|
36
37
|
import { today, getLocalTimeZone } from '@internationalized/date';
|
|
37
38
|
import { Calendar as Calendar$1, composeRenderProps, RangeCalendar as RangeCalendar$1, Button as Button$1, Heading, CalendarGrid, CalendarGridHeader, CalendarHeaderCell, CalendarGridBody, CalendarCell } from 'react-aria-components';
|
|
38
39
|
import { Toaster as Toaster$1, toast } from 'sonner';
|
|
39
40
|
import { createPortal } from 'react-dom';
|
|
40
41
|
import { useDrag } from '@use-gesture/react';
|
|
42
|
+
import '@xyflow/react/dist/style.css';
|
|
41
43
|
|
|
42
44
|
// src/lib/utils.ts
|
|
43
45
|
function cn(...inputs) {
|
|
@@ -564,7 +566,7 @@ var Checkbox = React19.forwardRef(({ className, ...props }, ref) => {
|
|
|
564
566
|
{
|
|
565
567
|
ref,
|
|
566
568
|
className: cn(
|
|
567
|
-
"relative inline-flex size-4.5 shrink-0 items-center justify-center rounded-[4px] border border-input bg-background bg-clip-padding
|
|
569
|
+
"relative inline-flex size-4.5 shrink-0 items-center justify-center rounded-[4px] border border-input bg-background bg-clip-padding outline-none ring-ring transition-shadow before:pointer-events-none before:absolute before:inset-0 before:rounded-[3px] not-data-disabled:not-data-checked:not-aria-invalid:before:shadow-[0_1px_--theme(--color-black/4%)] focus-visible:ring-2 focus-visible:ring-offset-1 focus-visible:ring-offset-background aria-invalid:border-destructive/36 focus-visible:aria-invalid:border-destructive/64 focus-visible:aria-invalid:ring-destructive/48 data-disabled:opacity-64 sm:size-4 dark:not-data-checked:bg-input/32 dark:bg-clip-border dark:aria-invalid:ring-destructive/24 dark:not-data-disabled:not-data-checked:not-aria-invalid:before:shadow-[0_-1px_--theme(--color-white/8%)] [[data-disabled],[data-checked],[aria-invalid]]:shadow-none",
|
|
568
570
|
className
|
|
569
571
|
),
|
|
570
572
|
"data-slot": "checkbox",
|
|
@@ -1152,7 +1154,7 @@ function InputGroup({ className, ...props }) {
|
|
|
1152
1154
|
"div",
|
|
1153
1155
|
{
|
|
1154
1156
|
className: cn(
|
|
1155
|
-
"relative inline-flex w-full min-w-0 items-center rounded-lg border border-input bg-background bg-clip-padding text-base
|
|
1157
|
+
"relative inline-flex w-full min-w-0 items-center rounded-lg border border-input bg-background bg-clip-padding text-base transition-shadow before:pointer-events-none before:absolute before:inset-0 before:rounded-[calc(var(--radius-lg)-1px)] not-has-[input:disabled,textarea:disabled]:not-has-[input:focus-visible,textarea:focus-visible]:not-has-[input[aria-invalid],textarea[aria-invalid]]:before:shadow-[0_1px_--theme(--color-black/4%)] has-[input:focus-visible,textarea:focus-visible]:has-[input[aria-invalid],textarea[aria-invalid]]:border-destructive/64 has-[input:focus-visible,textarea:focus-visible]:has-[input[aria-invalid],textarea[aria-invalid]]:ring-destructive/16 has-[textarea]:h-auto has-data-[align=block-end]:h-auto has-data-[align=block-start]:h-auto has-data-[align=block-end]:flex-col has-data-[align=block-start]:flex-col has-[input:focus-visible,textarea:focus-visible]:border-primary/60 has-[input[aria-invalid],textarea[aria-invalid]]:border-destructive/36 has-[input:disabled,textarea:disabled]:opacity-64 has-[input:disabled,textarea:disabled,input:focus-visible,textarea:focus-visible,input[aria-invalid],textarea[aria-invalid]]:shadow-none has-[input:focus-visible,textarea:focus-visible]:ring-[3px] has-[input:focus-visible,textarea:focus-visible]:ring-primary/35 sm:text-sm dark:bg-input/32 dark:bg-clip-border dark:has-[input[aria-invalid],textarea[aria-invalid]]:ring-destructive/24 dark:not-has-[input:disabled,textarea:disabled]:not-has-[input:focus-visible,textarea:focus-visible]:not-has-[input[aria-invalid],textarea[aria-invalid]]:before:shadow-[0_-1px_--theme(--color-white/8%)] has-data-[align=inline-start]:**:[[data-size=sm]_input]:ps-1.5 has-data-[align=inline-end]:**:[[data-size=sm]_input]:pe-1.5 *:[[data-slot=input-control],[data-slot=textarea-control]]:contents *:[[data-slot=input-control],[data-slot=textarea-control]]:before:hidden has-[[data-align=block-start],[data-align=block-end]]:**:[input]:h-auto has-data-[align=inline-start]:**:[input]:ps-2 has-data-[align=inline-end]:**:[input]:pe-2 has-data-[align=block-end]:**:[input]:pt-1.5 has-data-[align=block-start]:**:[input]:pb-1.5 **:[textarea]:min-h-20.5 **:[textarea]:resize-none **:[textarea]:py-[calc(--spacing(3)-1px)] **:[textarea]:max-sm:min-h-23.5 **:[textarea_button]:rounded-[calc(var(--radius-md)-1px)]",
|
|
1156
1158
|
className
|
|
1157
1159
|
),
|
|
1158
1160
|
"data-slot": "input-group",
|
|
@@ -1680,6 +1682,19 @@ function DialogDescription({
|
|
|
1680
1682
|
}
|
|
1681
1683
|
);
|
|
1682
1684
|
}
|
|
1685
|
+
function DialogPanel({ className, ...props }) {
|
|
1686
|
+
return /* @__PURE__ */ jsx(ScrollArea, { children: /* @__PURE__ */ jsx(
|
|
1687
|
+
"div",
|
|
1688
|
+
{
|
|
1689
|
+
className: cn(
|
|
1690
|
+
"px-6 in-[[data-slot=dialog-popup]:has([data-slot=dialog-header])]:pt-1 in-[[data-slot=dialog-popup]:not(:has([data-slot=dialog-header]))]:pt-6 in-[[data-slot=dialog-popup]:not(:has([data-slot=dialog-footer]))]:pb-6! in-[[data-slot=dialog-popup]:not(:has([data-slot=dialog-footer].border-t))]:pb-1 pb-6",
|
|
1691
|
+
className
|
|
1692
|
+
),
|
|
1693
|
+
"data-slot": "dialog-panel",
|
|
1694
|
+
...props
|
|
1695
|
+
}
|
|
1696
|
+
) });
|
|
1697
|
+
}
|
|
1683
1698
|
function AlertDialog({ ...props }) {
|
|
1684
1699
|
return /* @__PURE__ */ jsx(AlertDialog$1.Root, { "data-slot": "alert-dialog", ...props });
|
|
1685
1700
|
}
|
|
@@ -1884,10 +1899,10 @@ function DropdownMenuItem({
|
|
|
1884
1899
|
...props
|
|
1885
1900
|
}) {
|
|
1886
1901
|
const itemClassName = cn(
|
|
1887
|
-
`data-[highlighted]:bg-accent data-[highlighted]:text-accent-foreground data-[variant=destructive]:text-destructive
|
|
1902
|
+
`data-[highlighted]:bg-accent data-[highlighted]:text-accent-foreground data-[variant=destructive]:text-destructive
|
|
1888
1903
|
data-[variant=destructive]:data-[highlighted]:bg-destructive/10 dark:data-[variant=destructive]:data-[highlighted]:bg-destructive/40
|
|
1889
|
-
data-[variant=destructive]:data-[highlighted]:text-destructive
|
|
1890
|
-
data-[variant=destructive]:*:[svg]:!text-destructive
|
|
1904
|
+
data-[variant=destructive]:data-[highlighted]:text-destructive
|
|
1905
|
+
data-[variant=destructive]:*:[svg]:!text-destructive relative flex cursor-default items-center gap-2
|
|
1891
1906
|
rounded-sm px-2 py-1.5 text-sm outline-hidden select-none data-[disabled]:pointer-events-none
|
|
1892
1907
|
data-[disabled]:opacity-50 data-[inset]:pl-8 [&_svg]:pointer-events-none [&_svg]:shrink-0`,
|
|
1893
1908
|
className
|
|
@@ -3099,6 +3114,31 @@ function AutocompleteTrigger({
|
|
|
3099
3114
|
}
|
|
3100
3115
|
);
|
|
3101
3116
|
}
|
|
3117
|
+
var BUTTON_CLASS = "text-muted-foreground/80 hover:text-muted-foreground bg-card size-10 rounded-none shadow-none first:rounded-s-lg last:rounded-e-lg focus-visible:z-10";
|
|
3118
|
+
function FlowZoomPanel({
|
|
3119
|
+
className,
|
|
3120
|
+
position = "bottom-right",
|
|
3121
|
+
fitViewIcon = /* @__PURE__ */ jsx(RiFocus3Line, { className: "size-5", "aria-hidden": "true" }),
|
|
3122
|
+
fitViewOptions
|
|
3123
|
+
}) {
|
|
3124
|
+
const { zoomIn, zoomOut, fitView } = useReactFlow();
|
|
3125
|
+
const onFitView = useCallback(() => {
|
|
3126
|
+
fitView(fitViewOptions);
|
|
3127
|
+
}, [fitView, fitViewOptions]);
|
|
3128
|
+
return /* @__PURE__ */ jsxs(
|
|
3129
|
+
Panel,
|
|
3130
|
+
{
|
|
3131
|
+
"data-slot": "flow-zoom-panel",
|
|
3132
|
+
position,
|
|
3133
|
+
className: cn("inline-flex -space-x-px rounded-md shadow-xs rtl:space-x-reverse", className),
|
|
3134
|
+
children: [
|
|
3135
|
+
/* @__PURE__ */ jsx(Button, { variant: "outline", size: "icon", className: BUTTON_CLASS, onClick: () => zoomIn(), "aria-label": "Zoom in", children: /* @__PURE__ */ jsx(RiAddLine, { className: "size-5", "aria-hidden": "true" }) }),
|
|
3136
|
+
/* @__PURE__ */ jsx(Button, { variant: "outline", size: "icon", className: BUTTON_CLASS, onClick: () => zoomOut(), "aria-label": "Zoom out", children: /* @__PURE__ */ jsx(RiSubtractLine, { className: "size-5", "aria-hidden": "true" }) }),
|
|
3137
|
+
/* @__PURE__ */ jsx(Button, { variant: "outline", size: "icon", className: BUTTON_CLASS, onClick: onFitView, "aria-label": "Fit view", children: fitViewIcon })
|
|
3138
|
+
]
|
|
3139
|
+
}
|
|
3140
|
+
);
|
|
3141
|
+
}
|
|
3102
3142
|
function Command({
|
|
3103
3143
|
className,
|
|
3104
3144
|
...props
|
|
@@ -3248,7 +3288,7 @@ function ComboboxInput({
|
|
|
3248
3288
|
"div",
|
|
3249
3289
|
{
|
|
3250
3290
|
"aria-hidden": "true",
|
|
3251
|
-
className: "[&_svg]:-mx-0.5 pointer-events-none absolute inset-y-0 start-px z-10 flex items-center ps-[calc(--spacing(3)-1px)]
|
|
3291
|
+
className: "[&_svg]:-mx-0.5 pointer-events-none absolute inset-y-0 start-px z-10 flex items-center ps-[calc(--spacing(3)-1px)] has-[+[data-size=sm]]:ps-[calc(--spacing(2.5)-1px)] [&_svg:not([class*='size-'])]:size-4.5 sm:[&_svg:not([class*='size-'])]:size-4 [&_svg]:opacity-80",
|
|
3252
3292
|
"data-slot": "combobox-start-addon",
|
|
3253
3293
|
children: startAddon
|
|
3254
3294
|
}
|
|
@@ -7197,37 +7237,94 @@ function DefaultCardSkeleton() {
|
|
|
7197
7237
|
] })
|
|
7198
7238
|
] });
|
|
7199
7239
|
}
|
|
7200
|
-
|
|
7201
|
-
|
|
7202
|
-
|
|
7203
|
-
|
|
7204
|
-
|
|
7205
|
-
|
|
7206
|
-
|
|
7207
|
-
|
|
7208
|
-
|
|
7209
|
-
|
|
7210
|
-
|
|
7211
|
-
|
|
7212
|
-
|
|
7213
|
-
|
|
7240
|
+
var LONG_DESCRIPTION_THRESHOLD = 140;
|
|
7241
|
+
function isLongDescription(description) {
|
|
7242
|
+
if (!description) return false;
|
|
7243
|
+
return description.length > LONG_DESCRIPTION_THRESHOLD || description.includes("\n");
|
|
7244
|
+
}
|
|
7245
|
+
function ToastErrorContent({
|
|
7246
|
+
toastId,
|
|
7247
|
+
message,
|
|
7248
|
+
description,
|
|
7249
|
+
action,
|
|
7250
|
+
onDismiss
|
|
7251
|
+
}) {
|
|
7252
|
+
const [detailsOpen, setDetailsOpen] = useState(false);
|
|
7253
|
+
const [copied, setCopied] = useState(false);
|
|
7254
|
+
const showDetails = isLongDescription(description);
|
|
7255
|
+
const handleCopy = async () => {
|
|
7256
|
+
if (!description) return;
|
|
7257
|
+
try {
|
|
7258
|
+
await navigator.clipboard.writeText(description);
|
|
7259
|
+
setCopied(true);
|
|
7260
|
+
setTimeout(() => setCopied(false), 1500);
|
|
7261
|
+
} catch {
|
|
7262
|
+
}
|
|
7263
|
+
};
|
|
7264
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
7265
|
+
/* @__PURE__ */ jsx(
|
|
7266
|
+
"div",
|
|
7267
|
+
{
|
|
7268
|
+
className: "bg-background text-foreground border-destructive/20 w-full rounded-md border px-4 py-3 shadow-lg\n sm:w-[var(--width)]",
|
|
7269
|
+
children: /* @__PURE__ */ jsxs("div", { className: "flex gap-2", children: [
|
|
7270
|
+
/* @__PURE__ */ jsxs("div", { className: "flex min-w-0 grow gap-3", children: [
|
|
7271
|
+
/* @__PURE__ */ jsx(AlertCircleIcon, { className: "text-destructive mt-0.5 shrink-0", size: 16, "aria-hidden": "true" }),
|
|
7272
|
+
/* @__PURE__ */ jsxs("div", { className: "flex min-w-0 grow flex-col gap-1", children: [
|
|
7273
|
+
/* @__PURE__ */ jsx("p", { className: "text-destructive text-sm font-medium break-words", children: message }),
|
|
7274
|
+
description && /* @__PURE__ */ jsx("p", { className: "text-muted-foreground line-clamp-3 text-sm break-words", children: description }),
|
|
7275
|
+
(showDetails || action) && /* @__PURE__ */ jsxs("div", { className: "flex flex-wrap gap-x-4 gap-y-1", children: [
|
|
7276
|
+
showDetails && /* @__PURE__ */ jsx(
|
|
7277
|
+
"button",
|
|
7278
|
+
{
|
|
7279
|
+
className: "text-muted-foreground hover:text-foreground text-xs font-medium underline underline-offset-2 decoration-dotted",
|
|
7280
|
+
onClick: () => setDetailsOpen(true),
|
|
7281
|
+
children: "View details"
|
|
7282
|
+
}
|
|
7283
|
+
),
|
|
7284
|
+
action && /* @__PURE__ */ jsx(
|
|
7285
|
+
"button",
|
|
7286
|
+
{
|
|
7287
|
+
className: "text-destructive text-sm font-medium hover:underline",
|
|
7288
|
+
onClick: action.onClick,
|
|
7289
|
+
children: action.label
|
|
7290
|
+
}
|
|
7291
|
+
)
|
|
7292
|
+
] })
|
|
7293
|
+
] })
|
|
7294
|
+
] }),
|
|
7295
|
+
/* @__PURE__ */ jsx(
|
|
7296
|
+
Button,
|
|
7297
|
+
{
|
|
7298
|
+
variant: "ghost",
|
|
7299
|
+
className: "group -my-1.5 -me-2 size-8 shrink-0 p-0 hover:bg-transparent",
|
|
7300
|
+
onClick: () => {
|
|
7301
|
+
toast.dismiss(toastId);
|
|
7302
|
+
onDismiss?.();
|
|
7303
|
+
},
|
|
7304
|
+
"aria-label": "Close error notification",
|
|
7305
|
+
children: /* @__PURE__ */ jsx(XIcon, { size: 16, className: "opacity-60 transition-opacity group-hover:opacity-100", "aria-hidden": "true" })
|
|
7306
|
+
}
|
|
7307
|
+
)
|
|
7308
|
+
] })
|
|
7309
|
+
}
|
|
7310
|
+
),
|
|
7311
|
+
showDetails && description && /* @__PURE__ */ jsx(Dialog, { open: detailsOpen, onOpenChange: setDetailsOpen, children: /* @__PURE__ */ jsxs(DialogPopup, { className: "max-w-2xl", children: [
|
|
7312
|
+
/* @__PURE__ */ jsx(DialogHeader, { children: /* @__PURE__ */ jsx(DialogTitle, { children: message }) }),
|
|
7313
|
+
/* @__PURE__ */ jsx(DialogPanel, { children: /* @__PURE__ */ jsx("pre", { className: "bg-muted text-foreground rounded-md p-3 text-xs break-words whitespace-pre-wrap", children: description }) }),
|
|
7314
|
+
/* @__PURE__ */ jsxs(DialogFooter, { children: [
|
|
7315
|
+
/* @__PURE__ */ jsxs(Button, { variant: "outline", size: "sm", onClick: handleCopy, children: [
|
|
7316
|
+
copied ? /* @__PURE__ */ jsx(CheckIcon, { size: 14, "aria-hidden": "true" }) : /* @__PURE__ */ jsx(CopyIcon, { size: 14, "aria-hidden": "true" }),
|
|
7317
|
+
copied ? "Copied" : "Copy"
|
|
7214
7318
|
] }),
|
|
7215
|
-
/* @__PURE__ */ jsx(
|
|
7216
|
-
Button,
|
|
7217
|
-
{
|
|
7218
|
-
variant: "ghost",
|
|
7219
|
-
className: "group -my-1.5 -me-2 size-8 shrink-0 p-0 hover:bg-transparent",
|
|
7220
|
-
onClick: () => {
|
|
7221
|
-
toast.dismiss(t);
|
|
7222
|
-
onDismiss?.();
|
|
7223
|
-
},
|
|
7224
|
-
"aria-label": "Close error notification",
|
|
7225
|
-
children: /* @__PURE__ */ jsx(XIcon, { size: 16, className: "opacity-60 transition-opacity group-hover:opacity-100", "aria-hidden": "true" })
|
|
7226
|
-
}
|
|
7227
|
-
)
|
|
7319
|
+
/* @__PURE__ */ jsx(DialogClose, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "sm", children: "Close" }) })
|
|
7228
7320
|
] })
|
|
7229
|
-
}
|
|
7230
|
-
)
|
|
7321
|
+
] }) })
|
|
7322
|
+
] });
|
|
7323
|
+
}
|
|
7324
|
+
function showErrorToast(props) {
|
|
7325
|
+
return toast.custom((t) => /* @__PURE__ */ jsx(ToastErrorContent, { toastId: t, ...props }), {
|
|
7326
|
+
duration: Infinity
|
|
7327
|
+
});
|
|
7231
7328
|
}
|
|
7232
7329
|
function showInfoToast(props) {
|
|
7233
7330
|
const { message, description, action, onDismiss } = props;
|
|
@@ -7355,6 +7452,481 @@ var toast5 = {
|
|
|
7355
7452
|
warning: showWarningToast
|
|
7356
7453
|
};
|
|
7357
7454
|
|
|
7358
|
-
|
|
7455
|
+
// src/components/org-chart/layout.ts
|
|
7456
|
+
var NODE_WIDTH = 260;
|
|
7457
|
+
var NODE_HEIGHT = 100;
|
|
7458
|
+
var RANK_SEP = 80;
|
|
7459
|
+
var NODE_SEP = 40;
|
|
7460
|
+
var ROOT_KEY = "__root__";
|
|
7461
|
+
function computeLayout(edges) {
|
|
7462
|
+
const edgeById = /* @__PURE__ */ new Map();
|
|
7463
|
+
const childCountMap = /* @__PURE__ */ new Map();
|
|
7464
|
+
const childrenMap = /* @__PURE__ */ new Map();
|
|
7465
|
+
for (const e of edges) {
|
|
7466
|
+
edgeById.set(e.id, e);
|
|
7467
|
+
if (e.parentId) {
|
|
7468
|
+
childCountMap.set(e.parentId, (childCountMap.get(e.parentId) ?? 0) + 1);
|
|
7469
|
+
}
|
|
7470
|
+
const parent = e.parentId ?? ROOT_KEY;
|
|
7471
|
+
const bucket = childrenMap.get(parent);
|
|
7472
|
+
if (bucket) bucket.push(e.id);
|
|
7473
|
+
else childrenMap.set(parent, [e.id]);
|
|
7474
|
+
}
|
|
7475
|
+
for (const children of childrenMap.values()) {
|
|
7476
|
+
children.sort((a, b) => {
|
|
7477
|
+
const nameA = edgeById.get(a)?.displayName?.toLowerCase() ?? "";
|
|
7478
|
+
const nameB = edgeById.get(b)?.displayName?.toLowerCase() ?? "";
|
|
7479
|
+
return nameA.localeCompare(nameB);
|
|
7480
|
+
});
|
|
7481
|
+
}
|
|
7482
|
+
const widthCache = /* @__PURE__ */ new Map();
|
|
7483
|
+
const subtreeWidth = (nodeId) => {
|
|
7484
|
+
if (widthCache.has(nodeId)) return widthCache.get(nodeId);
|
|
7485
|
+
const children = childrenMap.get(nodeId);
|
|
7486
|
+
if (!children || children.length === 0) {
|
|
7487
|
+
widthCache.set(nodeId, NODE_WIDTH);
|
|
7488
|
+
return NODE_WIDTH;
|
|
7489
|
+
}
|
|
7490
|
+
const totalChildWidth = children.reduce((sum, c) => sum + subtreeWidth(c), 0);
|
|
7491
|
+
const gaps = (children.length - 1) * NODE_SEP;
|
|
7492
|
+
const w = Math.max(NODE_WIDTH, totalChildWidth + gaps);
|
|
7493
|
+
widthCache.set(nodeId, w);
|
|
7494
|
+
return w;
|
|
7495
|
+
};
|
|
7496
|
+
const positions = /* @__PURE__ */ new Map();
|
|
7497
|
+
const positionSubtree = (nodeId, centerX, y) => {
|
|
7498
|
+
positions.set(nodeId, { x: centerX, y });
|
|
7499
|
+
const children = childrenMap.get(nodeId);
|
|
7500
|
+
if (!children || children.length === 0) return;
|
|
7501
|
+
const totalWidth = children.reduce((sum, c) => sum + subtreeWidth(c), 0) + (children.length - 1) * NODE_SEP;
|
|
7502
|
+
let currentX = centerX - totalWidth / 2;
|
|
7503
|
+
for (const childId of children) {
|
|
7504
|
+
const childW = subtreeWidth(childId);
|
|
7505
|
+
positionSubtree(childId, currentX + childW / 2, y + NODE_HEIGHT + RANK_SEP);
|
|
7506
|
+
currentX += childW + NODE_SEP;
|
|
7507
|
+
}
|
|
7508
|
+
};
|
|
7509
|
+
const roots = childrenMap.get(ROOT_KEY) ?? [];
|
|
7510
|
+
if (roots.length === 1) {
|
|
7511
|
+
positionSubtree(roots[0], 0, 0);
|
|
7512
|
+
} else {
|
|
7513
|
+
const totalWidth = roots.reduce((sum, r) => sum + subtreeWidth(r), 0) + (roots.length - 1) * NODE_SEP;
|
|
7514
|
+
let currentX = -totalWidth / 2;
|
|
7515
|
+
for (const rootId of roots) {
|
|
7516
|
+
const w = subtreeWidth(rootId);
|
|
7517
|
+
positionSubtree(rootId, currentX + w / 2, 0);
|
|
7518
|
+
currentX += w + NODE_SEP;
|
|
7519
|
+
}
|
|
7520
|
+
}
|
|
7521
|
+
const nodes = edges.map((e) => {
|
|
7522
|
+
const pos = positions.get(e.id);
|
|
7523
|
+
return {
|
|
7524
|
+
id: e.id,
|
|
7525
|
+
type: "orgChartNode",
|
|
7526
|
+
width: NODE_WIDTH,
|
|
7527
|
+
height: NODE_HEIGHT,
|
|
7528
|
+
position: {
|
|
7529
|
+
x: pos.x - NODE_WIDTH / 2,
|
|
7530
|
+
y: pos.y
|
|
7531
|
+
},
|
|
7532
|
+
data: {
|
|
7533
|
+
id: e.id,
|
|
7534
|
+
displayName: e.displayName,
|
|
7535
|
+
avatarUrl: e.avatarUrl,
|
|
7536
|
+
positionTitle: e.positionTitle,
|
|
7537
|
+
parentId: e.parentId,
|
|
7538
|
+
childCount: childCountMap.get(e.id) ?? 0,
|
|
7539
|
+
isRoot: !e.parentId
|
|
7540
|
+
}
|
|
7541
|
+
};
|
|
7542
|
+
});
|
|
7543
|
+
const flowEdges = edges.filter((e) => e.parentId).map((e) => ({
|
|
7544
|
+
id: `edge-${e.parentId}-${e.id}`,
|
|
7545
|
+
source: e.parentId,
|
|
7546
|
+
target: e.id,
|
|
7547
|
+
type: "orgChartEdge"
|
|
7548
|
+
}));
|
|
7549
|
+
return { nodes, edges: flowEdges };
|
|
7550
|
+
}
|
|
7551
|
+
var NodeActionsContext = createContext(null);
|
|
7552
|
+
var OrgChartContext = createContext(null);
|
|
7553
|
+
function OrgChartProvider({ children, editable }) {
|
|
7554
|
+
const [selectedNodeId, setSelectedNodeId] = useState(null);
|
|
7555
|
+
const [draggedNodeId, setDraggedNodeId] = useState(null);
|
|
7556
|
+
const [dropTargetNodeId, setDropTargetNodeId] = useState(null);
|
|
7557
|
+
const selectNode = useCallback((nodeId) => setSelectedNodeId(nodeId), []);
|
|
7558
|
+
const clearSelection = useCallback(() => setSelectedNodeId(null), []);
|
|
7559
|
+
const value = useMemo(
|
|
7560
|
+
() => ({
|
|
7561
|
+
selectedNodeId,
|
|
7562
|
+
selectNode,
|
|
7563
|
+
clearSelection,
|
|
7564
|
+
editable,
|
|
7565
|
+
draggedNodeId,
|
|
7566
|
+
setDraggedNodeId,
|
|
7567
|
+
dropTargetNodeId,
|
|
7568
|
+
setDropTargetNodeId
|
|
7569
|
+
}),
|
|
7570
|
+
[selectedNodeId, selectNode, clearSelection, editable, draggedNodeId, dropTargetNodeId]
|
|
7571
|
+
);
|
|
7572
|
+
return /* @__PURE__ */ jsx(OrgChartContext.Provider, { value, children });
|
|
7573
|
+
}
|
|
7574
|
+
function useOrgChartContext() {
|
|
7575
|
+
const ctx = useContext(OrgChartContext);
|
|
7576
|
+
if (!ctx) throw new Error("useOrgChartContext must be used within OrgChartProvider");
|
|
7577
|
+
return ctx;
|
|
7578
|
+
}
|
|
7579
|
+
function NodeActionsProvider({
|
|
7580
|
+
children,
|
|
7581
|
+
onEditNode,
|
|
7582
|
+
onRemoveNode
|
|
7583
|
+
}) {
|
|
7584
|
+
const value = useMemo(() => ({ onEditNode, onRemoveNode }), [onEditNode, onRemoveNode]);
|
|
7585
|
+
return /* @__PURE__ */ jsx(NodeActionsContext.Provider, { value, children });
|
|
7586
|
+
}
|
|
7587
|
+
function useNodeActions() {
|
|
7588
|
+
const ctx = useContext(NodeActionsContext);
|
|
7589
|
+
if (!ctx) throw new Error("useNodeActions must be used within NodeActionsProvider");
|
|
7590
|
+
return ctx;
|
|
7591
|
+
}
|
|
7592
|
+
function OrgChartEdge({
|
|
7593
|
+
sourceX,
|
|
7594
|
+
sourceY,
|
|
7595
|
+
targetX,
|
|
7596
|
+
targetY,
|
|
7597
|
+
sourcePosition,
|
|
7598
|
+
targetPosition,
|
|
7599
|
+
style = {}
|
|
7600
|
+
}) {
|
|
7601
|
+
const [edgePath] = getSmoothStepPath({
|
|
7602
|
+
sourceX,
|
|
7603
|
+
sourceY,
|
|
7604
|
+
sourcePosition,
|
|
7605
|
+
targetX,
|
|
7606
|
+
targetY,
|
|
7607
|
+
targetPosition,
|
|
7608
|
+
borderRadius: 12
|
|
7609
|
+
});
|
|
7610
|
+
return /* @__PURE__ */ jsx(BaseEdge, { path: edgePath, style });
|
|
7611
|
+
}
|
|
7612
|
+
function OrgChartEmpty({ editable, onAddRoot }) {
|
|
7613
|
+
return /* @__PURE__ */ jsxs("div", { className: "bg-card border-border/60 flex flex-col items-center justify-center rounded-xl border py-16", children: [
|
|
7614
|
+
/* @__PURE__ */ jsx("div", { className: "bg-muted mb-4 flex size-14 items-center justify-center rounded-2xl", children: /* @__PURE__ */ jsx(Network, { className: "text-muted-foreground size-7" }) }),
|
|
7615
|
+
/* @__PURE__ */ jsx("h3", { className: "text-foreground text-base font-semibold", children: "No Org Chart Yet" }),
|
|
7616
|
+
/* @__PURE__ */ jsx("p", { className: "text-muted-foreground mt-1.5 max-w-sm text-center text-sm", children: "Build your organization hierarchy by adding the first person." }),
|
|
7617
|
+
editable && /* @__PURE__ */ jsxs(Button, { className: "mt-5 gap-1.5", onClick: onAddRoot, children: [
|
|
7618
|
+
/* @__PURE__ */ jsx(UserPlus, { className: "size-3.5" }),
|
|
7619
|
+
"Add First Member"
|
|
7620
|
+
] })
|
|
7621
|
+
] });
|
|
7622
|
+
}
|
|
7623
|
+
|
|
7624
|
+
// src/components/org-chart/org-chart-utils.ts
|
|
7625
|
+
function getInitials(name) {
|
|
7626
|
+
if (!name) return "--";
|
|
7627
|
+
const parts = name.trim().split(/\s+/).filter(Boolean);
|
|
7628
|
+
if (parts.length === 0) return "--";
|
|
7629
|
+
if (parts.length === 1) return parts[0].slice(0, 2).toUpperCase();
|
|
7630
|
+
return (parts[0][0] + parts[1][0]).toUpperCase();
|
|
7631
|
+
}
|
|
7632
|
+
function OrgChartNodeComponent({ id, data }) {
|
|
7633
|
+
const { selectedNodeId, dropTargetNodeId, editable } = useOrgChartContext();
|
|
7634
|
+
const { onEditNode, onRemoveNode } = useNodeActions();
|
|
7635
|
+
const isSelected = selectedNodeId === id;
|
|
7636
|
+
const isDropTarget = dropTargetNodeId === id;
|
|
7637
|
+
const [isHovered, setIsHovered] = useState(false);
|
|
7638
|
+
const [isMenuOpen, setIsMenuOpen] = useState(false);
|
|
7639
|
+
return /* @__PURE__ */ jsxs(
|
|
7640
|
+
"div",
|
|
7641
|
+
{
|
|
7642
|
+
style: { width: NODE_WIDTH },
|
|
7643
|
+
className: cn(
|
|
7644
|
+
"bg-card dark:bg-muted relative rounded-xl border shadow-sm transition-all",
|
|
7645
|
+
"border-border/60",
|
|
7646
|
+
isSelected && "ring-primary ring-2 ring-offset-2 dark:ring-offset-zinc-900",
|
|
7647
|
+
isDropTarget && "ring-primary/50 border-primary scale-105 ring-2"
|
|
7648
|
+
),
|
|
7649
|
+
onMouseEnter: () => setIsHovered(true),
|
|
7650
|
+
onMouseLeave: () => setIsHovered(false),
|
|
7651
|
+
children: [
|
|
7652
|
+
!data.isRoot && /* @__PURE__ */ jsx(Handle, { type: "target", position: Position.Top, className: "!bg-border !size-2 !rounded-full !border-0" }),
|
|
7653
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-3 px-4 py-3", children: [
|
|
7654
|
+
/* @__PURE__ */ jsxs(Avatar, { className: "size-10 shrink-0", children: [
|
|
7655
|
+
data.avatarUrl && /* @__PURE__ */ jsx(AvatarImage, { src: data.avatarUrl, alt: data.displayName ?? "" }),
|
|
7656
|
+
/* @__PURE__ */ jsx(AvatarFallback, { className: "bg-primary/10 text-primary text-xs font-medium", children: getInitials(data.displayName) })
|
|
7657
|
+
] }),
|
|
7658
|
+
/* @__PURE__ */ jsxs("div", { className: "min-w-0 flex-1", children: [
|
|
7659
|
+
/* @__PURE__ */ jsx("p", { className: "text-foreground truncate text-sm font-semibold", children: data.displayName ?? "Unknown" }),
|
|
7660
|
+
data.positionTitle && /* @__PURE__ */ jsx("p", { className: "text-muted-foreground truncate text-xs", children: data.positionTitle })
|
|
7661
|
+
] }),
|
|
7662
|
+
editable && (isHovered || isMenuOpen) ? /* @__PURE__ */ jsx("div", { className: "nodrag nopan shrink-0", children: /* @__PURE__ */ jsxs(DropdownMenu, { open: isMenuOpen, onOpenChange: setIsMenuOpen, children: [
|
|
7663
|
+
/* @__PURE__ */ jsx(DropdownMenuTrigger, { asChild: true, children: /* @__PURE__ */ jsx(
|
|
7664
|
+
Button,
|
|
7665
|
+
{
|
|
7666
|
+
variant: "ghost",
|
|
7667
|
+
size: "icon",
|
|
7668
|
+
className: "size-7 rounded-full",
|
|
7669
|
+
onClick: (e) => e.stopPropagation(),
|
|
7670
|
+
children: /* @__PURE__ */ jsx(Ellipsis, { className: "size-4" })
|
|
7671
|
+
}
|
|
7672
|
+
) }),
|
|
7673
|
+
/* @__PURE__ */ jsxs(DropdownMenuContent, { align: "start", side: "right", className: "translate-x-1 -translate-y-3.5", children: [
|
|
7674
|
+
/* @__PURE__ */ jsxs(
|
|
7675
|
+
DropdownMenuItem,
|
|
7676
|
+
{
|
|
7677
|
+
onClick: (e) => {
|
|
7678
|
+
e.stopPropagation();
|
|
7679
|
+
setIsMenuOpen(false);
|
|
7680
|
+
onEditNode(data);
|
|
7681
|
+
},
|
|
7682
|
+
children: [
|
|
7683
|
+
/* @__PURE__ */ jsx(Pencil, { className: "mr-2 size-3.5" }),
|
|
7684
|
+
"Edit Position"
|
|
7685
|
+
]
|
|
7686
|
+
}
|
|
7687
|
+
),
|
|
7688
|
+
/* @__PURE__ */ jsx(DropdownMenuSeparator, {}),
|
|
7689
|
+
/* @__PURE__ */ jsxs(
|
|
7690
|
+
DropdownMenuItem,
|
|
7691
|
+
{
|
|
7692
|
+
className: "text-destructive hover:bg-destructive/10 focus:bg-destructive/10 hover:text-destructive\n focus:text-destructive data-[highlighted]:bg-destructive/10 data-[highlighted]:text-destructive",
|
|
7693
|
+
onClick: (e) => {
|
|
7694
|
+
e.stopPropagation();
|
|
7695
|
+
setIsMenuOpen(false);
|
|
7696
|
+
onRemoveNode(data);
|
|
7697
|
+
},
|
|
7698
|
+
children: [
|
|
7699
|
+
/* @__PURE__ */ jsx(Trash2, { className: "mr-2 size-3.5" }),
|
|
7700
|
+
"Remove from Chart"
|
|
7701
|
+
]
|
|
7702
|
+
}
|
|
7703
|
+
)
|
|
7704
|
+
] })
|
|
7705
|
+
] }) }) : data.childCount > 0 && /* @__PURE__ */ jsx(Badge, { variant: "secondary", className: "shrink-0 text-[10px]", children: data.childCount })
|
|
7706
|
+
] }),
|
|
7707
|
+
/* @__PURE__ */ jsx(Handle, { type: "source", position: Position.Bottom, className: "!bg-border !size-2 !rounded-full !border-0" })
|
|
7708
|
+
]
|
|
7709
|
+
}
|
|
7710
|
+
);
|
|
7711
|
+
}
|
|
7712
|
+
var OrgChartNodeMemo = memo(OrgChartNodeComponent);
|
|
7713
|
+
var FIT_VIEW_OPTIONS = { padding: 0.12 };
|
|
7714
|
+
function getDescendantIds(nodeId, nodes) {
|
|
7715
|
+
const descendants = /* @__PURE__ */ new Set();
|
|
7716
|
+
const queue = [nodeId];
|
|
7717
|
+
while (queue.length > 0) {
|
|
7718
|
+
const current = queue.pop();
|
|
7719
|
+
for (const n of nodes) {
|
|
7720
|
+
if (n.data.parentId === current && !descendants.has(n.id)) {
|
|
7721
|
+
descendants.add(n.id);
|
|
7722
|
+
queue.push(n.id);
|
|
7723
|
+
}
|
|
7724
|
+
}
|
|
7725
|
+
}
|
|
7726
|
+
return descendants;
|
|
7727
|
+
}
|
|
7728
|
+
function mergeWithMeasured(prev, layoutNodes) {
|
|
7729
|
+
const prevMap = new Map(prev.map((n) => [n.id, n]));
|
|
7730
|
+
return layoutNodes.map((n) => {
|
|
7731
|
+
const existing = prevMap.get(n.id);
|
|
7732
|
+
if (!existing) return n;
|
|
7733
|
+
return existing.data.isRoot !== n.data.isRoot ? n : { ...n, measured: existing.measured };
|
|
7734
|
+
});
|
|
7735
|
+
}
|
|
7736
|
+
function OrgChartInner({
|
|
7737
|
+
className,
|
|
7738
|
+
edges: controlledEdges,
|
|
7739
|
+
defaultEdges,
|
|
7740
|
+
isLoading = false,
|
|
7741
|
+
editable = true,
|
|
7742
|
+
onReparent,
|
|
7743
|
+
onAddToChart,
|
|
7744
|
+
onEditNode,
|
|
7745
|
+
onRemoveNode,
|
|
7746
|
+
onReparentSuccess,
|
|
7747
|
+
onReparentError
|
|
7748
|
+
}) {
|
|
7749
|
+
const isControlled = controlledEdges !== void 0;
|
|
7750
|
+
const {
|
|
7751
|
+
selectNode,
|
|
7752
|
+
clearSelection,
|
|
7753
|
+
setDraggedNodeId,
|
|
7754
|
+
setDropTargetNodeId
|
|
7755
|
+
} = useOrgChartContext();
|
|
7756
|
+
const [internalEdges, setInternalEdges] = useState(defaultEdges ?? []);
|
|
7757
|
+
const defaultEdgesHash = useMemo(
|
|
7758
|
+
() => defaultEdges?.map((e) => `${e.id}:${e.parentId}:${e.positionTitle ?? ""}:${e.displayName ?? ""}`).join(",") ?? "",
|
|
7759
|
+
[defaultEdges]
|
|
7760
|
+
);
|
|
7761
|
+
useEffect(() => {
|
|
7762
|
+
if (!isControlled && defaultEdges) {
|
|
7763
|
+
setInternalEdges(defaultEdges);
|
|
7764
|
+
}
|
|
7765
|
+
}, [defaultEdgesHash]);
|
|
7766
|
+
const apiEdges = controlledEdges ?? internalEdges;
|
|
7767
|
+
const layout = useMemo(() => apiEdges.length > 0 ? computeLayout(apiEdges) : null, [apiEdges]);
|
|
7768
|
+
const layoutNodes = layout?.nodes ?? [];
|
|
7769
|
+
const layoutEdges = layout?.edges ?? [];
|
|
7770
|
+
const isEmpty = apiEdges.length === 0 && !isLoading;
|
|
7771
|
+
const { fitView, getIntersectingNodes } = useReactFlow();
|
|
7772
|
+
const [nodes, setNodes, onNodesChange] = useNodesState([]);
|
|
7773
|
+
const [rfEdges, setRfEdges, onEdgesChange] = useEdgesState([]);
|
|
7774
|
+
const nodesHash = useMemo(
|
|
7775
|
+
() => layoutNodes.map((n) => `${n.id}:${n.data.parentId ?? ""}:${n.data.positionTitle ?? ""}:${n.data.displayName ?? ""}`).join(","),
|
|
7776
|
+
[layoutNodes]
|
|
7777
|
+
);
|
|
7778
|
+
const edgesHash = useMemo(() => layoutEdges.map((e) => `${e.id}:${e.source}:${e.target}`).join(","), [layoutEdges]);
|
|
7779
|
+
const fitViewRef = useRef(fitView);
|
|
7780
|
+
fitViewRef.current = fitView;
|
|
7781
|
+
useEffect(() => {
|
|
7782
|
+
setNodes((prev) => mergeWithMeasured(prev, layoutNodes));
|
|
7783
|
+
setRfEdges(layoutEdges);
|
|
7784
|
+
const raf = requestAnimationFrame(() => fitViewRef.current(FIT_VIEW_OPTIONS));
|
|
7785
|
+
return () => cancelAnimationFrame(raf);
|
|
7786
|
+
}, [nodesHash, edgesHash]);
|
|
7787
|
+
const draggedNodeRef = useRef(null);
|
|
7788
|
+
const dropTargetIdRef = useRef(null);
|
|
7789
|
+
const nodeTypes = useMemo(() => ({ orgChartNode: OrgChartNodeMemo }), []);
|
|
7790
|
+
const edgeTypes = useMemo(() => ({ orgChartEdge: OrgChartEdge }), []);
|
|
7791
|
+
const onNodeDragStart = useCallback(
|
|
7792
|
+
(_, node) => {
|
|
7793
|
+
if (!editable) return;
|
|
7794
|
+
draggedNodeRef.current = node.id;
|
|
7795
|
+
setDraggedNodeId(node.id);
|
|
7796
|
+
},
|
|
7797
|
+
[editable, setDraggedNodeId]
|
|
7798
|
+
);
|
|
7799
|
+
const onNodeDrag = useCallback(
|
|
7800
|
+
(_, node) => {
|
|
7801
|
+
if (!editable || !draggedNodeRef.current) return;
|
|
7802
|
+
const intersecting = getIntersectingNodes(node);
|
|
7803
|
+
const target = intersecting.find((n) => n.id !== node.id);
|
|
7804
|
+
const targetId = target?.id ?? null;
|
|
7805
|
+
if (targetId === dropTargetIdRef.current) return;
|
|
7806
|
+
dropTargetIdRef.current = targetId;
|
|
7807
|
+
setDropTargetNodeId(targetId);
|
|
7808
|
+
},
|
|
7809
|
+
[editable, getIntersectingNodes, setDropTargetNodeId]
|
|
7810
|
+
);
|
|
7811
|
+
const applyOptimisticReparent = useCallback((childId, newParentId) => {
|
|
7812
|
+
setInternalEdges(
|
|
7813
|
+
(prev) => prev.map((e) => e.id === childId ? { ...e, parentId: newParentId } : e)
|
|
7814
|
+
);
|
|
7815
|
+
}, []);
|
|
7816
|
+
const snapBack = useCallback(() => {
|
|
7817
|
+
setNodes((prev) => mergeWithMeasured(prev, layoutNodes));
|
|
7818
|
+
}, [layoutNodes, setNodes]);
|
|
7819
|
+
const onNodeDragStop = useCallback(
|
|
7820
|
+
async (_, _node) => {
|
|
7821
|
+
if (!editable || !draggedNodeRef.current) return;
|
|
7822
|
+
const childId = draggedNodeRef.current;
|
|
7823
|
+
const newParentId = dropTargetIdRef.current;
|
|
7824
|
+
draggedNodeRef.current = null;
|
|
7825
|
+
dropTargetIdRef.current = null;
|
|
7826
|
+
setDraggedNodeId(null);
|
|
7827
|
+
setDropTargetNodeId(null);
|
|
7828
|
+
if (!newParentId || newParentId === childId) {
|
|
7829
|
+
snapBack();
|
|
7830
|
+
return;
|
|
7831
|
+
}
|
|
7832
|
+
if (getDescendantIds(childId, layoutNodes).has(newParentId)) {
|
|
7833
|
+
onReparentError?.("Cannot create circular reporting chain");
|
|
7834
|
+
snapBack();
|
|
7835
|
+
return;
|
|
7836
|
+
}
|
|
7837
|
+
const draggedData = layoutNodes.find((n) => n.id === childId)?.data;
|
|
7838
|
+
if (!draggedData || newParentId === draggedData.parentId) {
|
|
7839
|
+
snapBack();
|
|
7840
|
+
return;
|
|
7841
|
+
}
|
|
7842
|
+
const targetName = layoutNodes.find((n) => n.id === newParentId)?.data.displayName;
|
|
7843
|
+
const preserve = { positionTitle: draggedData.positionTitle };
|
|
7844
|
+
if (!isControlled) {
|
|
7845
|
+
const snapshotEdges = internalEdges;
|
|
7846
|
+
applyOptimisticReparent(childId, newParentId);
|
|
7847
|
+
try {
|
|
7848
|
+
await onReparent?.(childId, newParentId, preserve);
|
|
7849
|
+
onReparentSuccess?.(draggedData.displayName ?? "Member", targetName ?? "new manager");
|
|
7850
|
+
} catch (err) {
|
|
7851
|
+
console.error("[OrgChart] reparent failed", err);
|
|
7852
|
+
setInternalEdges(snapshotEdges);
|
|
7853
|
+
onReparentError?.("Failed to update reporting line");
|
|
7854
|
+
}
|
|
7855
|
+
} else {
|
|
7856
|
+
snapBack();
|
|
7857
|
+
try {
|
|
7858
|
+
await onReparent?.(childId, newParentId, preserve);
|
|
7859
|
+
onReparentSuccess?.(draggedData.displayName ?? "Member", targetName ?? "new manager");
|
|
7860
|
+
} catch (err) {
|
|
7861
|
+
console.error("[OrgChart] reparent failed", err);
|
|
7862
|
+
onReparentError?.("Failed to update reporting line");
|
|
7863
|
+
}
|
|
7864
|
+
}
|
|
7865
|
+
},
|
|
7866
|
+
[editable, isControlled, internalEdges, layoutNodes, onReparent, onReparentSuccess, onReparentError, applyOptimisticReparent, snapBack, setDraggedNodeId, setDropTargetNodeId]
|
|
7867
|
+
);
|
|
7868
|
+
const onNodeClick = useCallback((_, node) => selectNode(node.id), [selectNode]);
|
|
7869
|
+
const onPaneClick = useCallback(() => clearSelection(), [clearSelection]);
|
|
7870
|
+
const handleEditNode = useCallback(
|
|
7871
|
+
(nodeData) => onEditNode?.(nodeData),
|
|
7872
|
+
[onEditNode]
|
|
7873
|
+
);
|
|
7874
|
+
const handleRemoveNode = useCallback(
|
|
7875
|
+
(nodeData) => onRemoveNode?.(nodeData),
|
|
7876
|
+
[onRemoveNode]
|
|
7877
|
+
);
|
|
7878
|
+
if (isLoading) {
|
|
7879
|
+
return /* @__PURE__ */ jsx("div", { className: "bg-card border-border/60 flex items-center justify-center rounded-xl border p-16", children: /* @__PURE__ */ jsx(Loader2, { className: "text-muted-foreground size-6 animate-spin" }) });
|
|
7880
|
+
}
|
|
7881
|
+
if (isEmpty) {
|
|
7882
|
+
return /* @__PURE__ */ jsx(OrgChartEmpty, { editable, onAddRoot: onAddToChart ?? (() => {
|
|
7883
|
+
}) });
|
|
7884
|
+
}
|
|
7885
|
+
return /* @__PURE__ */ jsx(NodeActionsProvider, { onEditNode: handleEditNode, onRemoveNode: handleRemoveNode, children: /* @__PURE__ */ jsx("div", { className: cn("border-border/60 h-[600px] overflow-hidden rounded-xl border", className), children: /* @__PURE__ */ jsxs(
|
|
7886
|
+
ReactFlow,
|
|
7887
|
+
{
|
|
7888
|
+
nodes,
|
|
7889
|
+
edges: rfEdges,
|
|
7890
|
+
onNodesChange,
|
|
7891
|
+
onEdgesChange,
|
|
7892
|
+
onNodeClick,
|
|
7893
|
+
proOptions: { hideAttribution: true },
|
|
7894
|
+
onPaneClick,
|
|
7895
|
+
onNodeDragStart,
|
|
7896
|
+
onNodeDrag,
|
|
7897
|
+
onNodeDragStop,
|
|
7898
|
+
nodeTypes,
|
|
7899
|
+
edgeTypes,
|
|
7900
|
+
fitView: true,
|
|
7901
|
+
fitViewOptions: FIT_VIEW_OPTIONS,
|
|
7902
|
+
minZoom: 0.3,
|
|
7903
|
+
maxZoom: 1.5,
|
|
7904
|
+
nodesDraggable: editable,
|
|
7905
|
+
nodesConnectable: false,
|
|
7906
|
+
elementsSelectable: true,
|
|
7907
|
+
selectNodesOnDrag: false,
|
|
7908
|
+
panOnDrag: true,
|
|
7909
|
+
zoomOnScroll: true,
|
|
7910
|
+
preventScrolling: true,
|
|
7911
|
+
style: {
|
|
7912
|
+
"--xy-background-pattern-dots-color-default": "var(--color-border)",
|
|
7913
|
+
"--xy-edge-stroke-width-default": 2,
|
|
7914
|
+
"--xy-edge-stroke-default": "var(--color-border)",
|
|
7915
|
+
"--xy-edge-stroke-selected-default": "var(--color-foreground)",
|
|
7916
|
+
"--xy-attribution-background-color-default": "transparent"
|
|
7917
|
+
},
|
|
7918
|
+
attributionPosition: "bottom-left",
|
|
7919
|
+
children: [
|
|
7920
|
+
/* @__PURE__ */ jsx(Background, { variant: BackgroundVariant.Dots, gap: 20, size: 2 }),
|
|
7921
|
+
/* @__PURE__ */ jsx(FlowZoomPanel, { fitViewOptions: FIT_VIEW_OPTIONS })
|
|
7922
|
+
]
|
|
7923
|
+
}
|
|
7924
|
+
) }) });
|
|
7925
|
+
}
|
|
7926
|
+
function OrgChart(props) {
|
|
7927
|
+
return /* @__PURE__ */ jsx(ReactFlowProvider, { children: /* @__PURE__ */ jsx(OrgChartProvider, { editable: props.editable ?? true, children: /* @__PURE__ */ jsx(TooltipProvider, { children: /* @__PURE__ */ jsx(OrgChartInner, { ...props }) }) }) });
|
|
7928
|
+
}
|
|
7929
|
+
|
|
7930
|
+
export { Alert, AlertDescription, AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogPortal, AlertDialogTitle, AlertDialogTrigger, AlertTitle, Autocomplete, AutocompleteEmpty, AutocompleteInput, AutocompleteItem, AutocompletePopup, AutocompleteSeparator, Avatar, AvatarFallback, AvatarImage, Badge, Breadcrumb, BreadcrumbEllipsis, BreadcrumbItem, BreadcrumbLink, BreadcrumbList, BreadcrumbPage, BreadcrumbSeparator, Button, Calendar, Card, CardAction, CardContent, CardDescription, CardFooter, CardHeader, CardStackProvider, CardStackViewport, CardTitle, Checkbox, CheckboxGroup, Collapsible, CollapsiblePanel as CollapsibleContent, CollapsibleTrigger, Combobox, ComboboxContent, ComboboxEmpty, ComboboxGroup, ComboboxInput, ComboboxItem, ComboboxList, ComboboxSeparator, ComboboxTrigger, Command, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList, DEFAULT_ANIMATION_CONFIG, DeferredCardContent, Dialog, DialogBackdrop, DialogClose, DialogPopup as DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogPortal, DialogTitle, DialogTrigger, Dock, DockIcon, Drawer, DrawerClose, DrawerContent, DrawerDescription, DrawerFooter, DrawerHeader, DrawerOverlay, DrawerPortal, DrawerTitle, DrawerTrigger, DropdownMenu, DropdownMenuCheckboxItem, DropdownMenuContent, DropdownMenuGroup, DropdownMenuItem, DropdownMenuLabel, DropdownMenuPortal, DropdownMenuRadioGroup, DropdownMenuRadioItem, DropdownMenuSeparator, DropdownMenuShortcut, DropdownMenuSub, DropdownMenuSubContent, DropdownMenuSubTrigger, DropdownMenuTrigger, Field, FieldRow, FlickeringGrid, FlowZoomPanel, Form, FormControl, FormControl2 as FormControlComponent, FormDescription, FormField, FormItem, FormLabel, FormMessage, Input, InputGroup, InputGroupAddon, InputGroupInput, InputGroupText, InputGroupTextarea, JsonEditor, JsonInput, Label, ModalPortalScope, MotionGrid, MultiSelect, OrgChart, PORTAL_ROOT_ID, PageHeader, Pagination, PaginationContent, PaginationEllipsis, PaginationItem, PaginationLink, PaginationNext, PaginationPrevious, Popover, PopoverAnchor, PopoverContent, PopoverTrigger, PortalRoot, Progress, ProgressiveBlur, ProgressiveBlurScrollContainer, Radio, RadioGroup, Radio as RadioGroupItem, RangeCalendar, RecordPicker, ResizableHandle, ResizablePanel, ResizablePanelGroup, ResponsiveDiagram, ScrollArea, ScrollBar, Select, SelectPopup as SelectContent, SelectFieldItem, SelectGroup, SelectGroupLabel, SelectItem, SelectGroupLabel as SelectLabel, SelectPopup, SelectRichItem, SelectSeparator, SelectTrigger, SelectValue, Separator, Sheet, SheetClose, SheetContent, SheetDescription, SheetFooter, SheetHeader, SheetTitle, SheetTrigger, Sidebar, SidebarContent, SidebarFooter, SidebarGroup, SidebarGroupAction, SidebarGroupContent, SidebarGroupLabel, SidebarHeader, SidebarInput, SidebarInset, SidebarMenu, SidebarMenuAction, SidebarMenuBadge, SidebarMenuButton, SidebarMenuItem, SidebarMenuSkeleton, SidebarMenuSub, SidebarMenuSubButton, SidebarMenuSubItem, SidebarProvider, SidebarSeparator, SidebarTrigger, Skeleton, Slot, Slottable, StackBackdrop, StackCard, StackHeader, StackHeaderSlot, Stepper, StepperDescription, StepperIndicator, StepperItem, StepperSeparator, StepperTitle, StepperTrigger, Switch, Table, TableBody, TableCaption, TableCell, TableFooter, TableHead, TableHeader, TableRow, Tabs, TabsContent, TabsList, TabsTrigger, Tags, TagsContent, TagsEmpty, TagsGroup, TagsInput, TagsItem, TagsList, TagsTrigger, TagsValue, Textarea, Toaster, Tooltip, TooltipContent, TooltipProvider, TooltipTrigger, UnlinkButton, alertVariants, backdropVariants, badgeVariants, buttonVariants, calculateResponsiveOffset, cardVariants, cn, composeRefs, createCardVariants, createOffsetTransition, createReducedMotionVariants, dockVariants, durations, easings, getCardOffset, getCardZIndex, getCascadeOffset, getResponsiveCardOffset, getSideBySideOffset, getVisibleCardIndices, isCardVisible, mergeProps, normalizeWidth, parseWidthToPixels, peekDragSpring, peekHoverSpring, peekSlideSpring, reducedMotionBackdropVariants, showErrorToast, showInfoToast, showSuccessToast, showWarningToast, snapBackSpring, springs, swipeDismissTransition, toast5 as toast, transitions, useCardIndex, useCardInjectedProps, useCardReady, useCardStack, useControllableState, useFloatingOverlayPortalProps, useFormField, useInModalOverlay, useIsMobile2 as useIsMobile, useIsTopCard, usePeekGestures, usePortalContainer, usePortalContext, useRootPortalContainer, useSidebar, useStackCards, useStackContext, useStackGestures, useStackLayoutMode, useStackResponsive, validateJson, variants };
|
|
7359
7931
|
//# sourceMappingURL=index.js.map
|
|
7360
7932
|
//# sourceMappingURL=index.js.map
|