@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.cjs
CHANGED
|
@@ -30,15 +30,17 @@ var collapsible = require('@base-ui/react/collapsible');
|
|
|
30
30
|
var ResizablePrimitive = require('react-resizable-panels');
|
|
31
31
|
var avatar = require('@base-ui/react/avatar');
|
|
32
32
|
var autocomplete = require('@base-ui/react/autocomplete');
|
|
33
|
+
var react$1 = require('@xyflow/react');
|
|
34
|
+
var react$2 = require('@remixicon/react');
|
|
33
35
|
var cmdk = require('cmdk');
|
|
34
36
|
var combobox = require('@base-ui/react/combobox');
|
|
35
|
-
var react$1 = require('@remixicon/react');
|
|
36
37
|
var matchSorter = require('match-sorter');
|
|
37
38
|
var date = require('@internationalized/date');
|
|
38
39
|
var reactAriaComponents = require('react-aria-components');
|
|
39
40
|
var sonner = require('sonner');
|
|
40
41
|
var reactDom = require('react-dom');
|
|
41
|
-
var react$
|
|
42
|
+
var react$3 = require('@use-gesture/react');
|
|
43
|
+
require('@xyflow/react/dist/style.css');
|
|
42
44
|
|
|
43
45
|
function _interopNamespace(e) {
|
|
44
46
|
if (e && e.__esModule) return e;
|
|
@@ -586,7 +588,7 @@ var Checkbox = React19__namespace.forwardRef(({ className, ...props }, ref) => {
|
|
|
586
588
|
{
|
|
587
589
|
ref,
|
|
588
590
|
className: cn(
|
|
589
|
-
"relative inline-flex size-4.5 shrink-0 items-center justify-center rounded-[4px] border border-input bg-background bg-clip-padding
|
|
591
|
+
"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",
|
|
590
592
|
className
|
|
591
593
|
),
|
|
592
594
|
"data-slot": "checkbox",
|
|
@@ -1174,7 +1176,7 @@ function InputGroup({ className, ...props }) {
|
|
|
1174
1176
|
"div",
|
|
1175
1177
|
{
|
|
1176
1178
|
className: cn(
|
|
1177
|
-
"relative inline-flex w-full min-w-0 items-center rounded-lg border border-input bg-background bg-clip-padding text-base
|
|
1179
|
+
"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)]",
|
|
1178
1180
|
className
|
|
1179
1181
|
),
|
|
1180
1182
|
"data-slot": "input-group",
|
|
@@ -1702,6 +1704,19 @@ function DialogDescription({
|
|
|
1702
1704
|
}
|
|
1703
1705
|
);
|
|
1704
1706
|
}
|
|
1707
|
+
function DialogPanel({ className, ...props }) {
|
|
1708
|
+
return /* @__PURE__ */ jsxRuntime.jsx(ScrollArea, { children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
1709
|
+
"div",
|
|
1710
|
+
{
|
|
1711
|
+
className: cn(
|
|
1712
|
+
"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",
|
|
1713
|
+
className
|
|
1714
|
+
),
|
|
1715
|
+
"data-slot": "dialog-panel",
|
|
1716
|
+
...props
|
|
1717
|
+
}
|
|
1718
|
+
) });
|
|
1719
|
+
}
|
|
1705
1720
|
function AlertDialog({ ...props }) {
|
|
1706
1721
|
return /* @__PURE__ */ jsxRuntime.jsx(alertDialog.AlertDialog.Root, { "data-slot": "alert-dialog", ...props });
|
|
1707
1722
|
}
|
|
@@ -1906,10 +1921,10 @@ function DropdownMenuItem({
|
|
|
1906
1921
|
...props
|
|
1907
1922
|
}) {
|
|
1908
1923
|
const itemClassName = cn(
|
|
1909
|
-
`data-[highlighted]:bg-accent data-[highlighted]:text-accent-foreground data-[variant=destructive]:text-destructive
|
|
1924
|
+
`data-[highlighted]:bg-accent data-[highlighted]:text-accent-foreground data-[variant=destructive]:text-destructive
|
|
1910
1925
|
data-[variant=destructive]:data-[highlighted]:bg-destructive/10 dark:data-[variant=destructive]:data-[highlighted]:bg-destructive/40
|
|
1911
|
-
data-[variant=destructive]:data-[highlighted]:text-destructive
|
|
1912
|
-
data-[variant=destructive]:*:[svg]:!text-destructive
|
|
1926
|
+
data-[variant=destructive]:data-[highlighted]:text-destructive
|
|
1927
|
+
data-[variant=destructive]:*:[svg]:!text-destructive relative flex cursor-default items-center gap-2
|
|
1913
1928
|
rounded-sm px-2 py-1.5 text-sm outline-hidden select-none data-[disabled]:pointer-events-none
|
|
1914
1929
|
data-[disabled]:opacity-50 data-[inset]:pl-8 [&_svg]:pointer-events-none [&_svg]:shrink-0`,
|
|
1915
1930
|
className
|
|
@@ -3121,6 +3136,31 @@ function AutocompleteTrigger({
|
|
|
3121
3136
|
}
|
|
3122
3137
|
);
|
|
3123
3138
|
}
|
|
3139
|
+
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";
|
|
3140
|
+
function FlowZoomPanel({
|
|
3141
|
+
className,
|
|
3142
|
+
position = "bottom-right",
|
|
3143
|
+
fitViewIcon = /* @__PURE__ */ jsxRuntime.jsx(react$2.RiFocus3Line, { className: "size-5", "aria-hidden": "true" }),
|
|
3144
|
+
fitViewOptions
|
|
3145
|
+
}) {
|
|
3146
|
+
const { zoomIn, zoomOut, fitView } = react$1.useReactFlow();
|
|
3147
|
+
const onFitView = React19.useCallback(() => {
|
|
3148
|
+
fitView(fitViewOptions);
|
|
3149
|
+
}, [fitView, fitViewOptions]);
|
|
3150
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
3151
|
+
react$1.Panel,
|
|
3152
|
+
{
|
|
3153
|
+
"data-slot": "flow-zoom-panel",
|
|
3154
|
+
position,
|
|
3155
|
+
className: cn("inline-flex -space-x-px rounded-md shadow-xs rtl:space-x-reverse", className),
|
|
3156
|
+
children: [
|
|
3157
|
+
/* @__PURE__ */ jsxRuntime.jsx(Button, { variant: "outline", size: "icon", className: BUTTON_CLASS, onClick: () => zoomIn(), "aria-label": "Zoom in", children: /* @__PURE__ */ jsxRuntime.jsx(react$2.RiAddLine, { className: "size-5", "aria-hidden": "true" }) }),
|
|
3158
|
+
/* @__PURE__ */ jsxRuntime.jsx(Button, { variant: "outline", size: "icon", className: BUTTON_CLASS, onClick: () => zoomOut(), "aria-label": "Zoom out", children: /* @__PURE__ */ jsxRuntime.jsx(react$2.RiSubtractLine, { className: "size-5", "aria-hidden": "true" }) }),
|
|
3159
|
+
/* @__PURE__ */ jsxRuntime.jsx(Button, { variant: "outline", size: "icon", className: BUTTON_CLASS, onClick: onFitView, "aria-label": "Fit view", children: fitViewIcon })
|
|
3160
|
+
]
|
|
3161
|
+
}
|
|
3162
|
+
);
|
|
3163
|
+
}
|
|
3124
3164
|
function Command({
|
|
3125
3165
|
className,
|
|
3126
3166
|
...props
|
|
@@ -3270,7 +3310,7 @@ function ComboboxInput({
|
|
|
3270
3310
|
"div",
|
|
3271
3311
|
{
|
|
3272
3312
|
"aria-hidden": "true",
|
|
3273
|
-
className: "[&_svg]:-mx-0.5 pointer-events-none absolute inset-y-0 start-px z-10 flex items-center ps-[calc(--spacing(3)-1px)]
|
|
3313
|
+
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",
|
|
3274
3314
|
"data-slot": "combobox-start-addon",
|
|
3275
3315
|
children: startAddon
|
|
3276
3316
|
}
|
|
@@ -4255,7 +4295,7 @@ function RecordPicker({
|
|
|
4255
4295
|
);
|
|
4256
4296
|
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-3", children: [
|
|
4257
4297
|
/* @__PURE__ */ jsxRuntime.jsxs(InputGroup, { children: [
|
|
4258
|
-
/* @__PURE__ */ jsxRuntime.jsx(InputGroupAddon, { children: /* @__PURE__ */ jsxRuntime.jsx(react$
|
|
4298
|
+
/* @__PURE__ */ jsxRuntime.jsx(InputGroupAddon, { children: /* @__PURE__ */ jsxRuntime.jsx(react$2.RiSearchLine, {}) }),
|
|
4259
4299
|
/* @__PURE__ */ jsxRuntime.jsx(
|
|
4260
4300
|
InputGroupInput,
|
|
4261
4301
|
{
|
|
@@ -4299,7 +4339,7 @@ function RecordPicker({
|
|
|
4299
4339
|
children: label
|
|
4300
4340
|
}
|
|
4301
4341
|
),
|
|
4302
|
-
isLinking && /* @__PURE__ */ jsxRuntime.jsx(react$
|
|
4342
|
+
isLinking && /* @__PURE__ */ jsxRuntime.jsx(react$2.RiLoader4Line, { className: "text-muted-foreground h-4 w-4 flex-shrink-0 animate-spin" })
|
|
4303
4343
|
]
|
|
4304
4344
|
},
|
|
4305
4345
|
recordId
|
|
@@ -4316,17 +4356,17 @@ function RecordPicker({
|
|
|
4316
4356
|
const recordId = getRecordId(record);
|
|
4317
4357
|
const label = getRecordLabel(record);
|
|
4318
4358
|
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-muted/30 flex items-center space-x-3 rounded-md p-2", children: [
|
|
4319
|
-
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex h-4 w-4 flex-shrink-0 items-center justify-center", children: /* @__PURE__ */ jsxRuntime.jsx(react$
|
|
4359
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex h-4 w-4 flex-shrink-0 items-center justify-center", children: /* @__PURE__ */ jsxRuntime.jsx(react$2.RiCheckLine, { className: "h-3 w-3 text-green-600" }) }),
|
|
4320
4360
|
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-muted-foreground flex-1 truncate text-sm", title: label, children: label })
|
|
4321
4361
|
] }, recordId);
|
|
4322
4362
|
})
|
|
4323
4363
|
] }),
|
|
4324
4364
|
filteredRecords.length === 0 && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-muted-foreground py-8 text-center", children: [
|
|
4325
|
-
/* @__PURE__ */ jsxRuntime.jsx(react$
|
|
4365
|
+
/* @__PURE__ */ jsxRuntime.jsx(react$2.RiSearchLine, { className: "mx-auto mb-2 h-8 w-8 opacity-50" }),
|
|
4326
4366
|
/* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-sm", children: searchQuery ? "No records match your search" : "No records available" })
|
|
4327
4367
|
] }),
|
|
4328
4368
|
filteredRecords.length > 0 && unlinkableRecords.length === 0 && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-muted-foreground py-4 text-center", children: [
|
|
4329
|
-
/* @__PURE__ */ jsxRuntime.jsx(react$
|
|
4369
|
+
/* @__PURE__ */ jsxRuntime.jsx(react$2.RiCheckLine, { className: "mx-auto mb-2 h-6 w-6 opacity-50" }),
|
|
4330
4370
|
/* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-sm", children: "All matching records are already linked" })
|
|
4331
4371
|
] })
|
|
4332
4372
|
] }) })
|
|
@@ -5807,7 +5847,7 @@ function UnlinkButton({
|
|
|
5807
5847
|
),
|
|
5808
5848
|
"aria-label": ariaLabel,
|
|
5809
5849
|
title: isUnlinking ? "Unlinking..." : "Unlink record",
|
|
5810
|
-
children: isUnlinking ? /* @__PURE__ */ jsxRuntime.jsx(react$
|
|
5850
|
+
children: isUnlinking ? /* @__PURE__ */ jsxRuntime.jsx(react$2.RiLoader4Line, { className: "h-3 w-3 animate-spin" }) : /* @__PURE__ */ jsxRuntime.jsx(react$2.RiCloseLine, { className: "h-3 w-3" })
|
|
5811
5851
|
}
|
|
5812
5852
|
);
|
|
5813
5853
|
}
|
|
@@ -6883,7 +6923,7 @@ function useStackGestures(options) {
|
|
|
6883
6923
|
}, [onDismiss]);
|
|
6884
6924
|
const dismissedRef = React19.useRef(false);
|
|
6885
6925
|
const velocityMinDistance = Math.max(MIN_VELOCITY_DISTANCE, swipeThreshold * 0.25);
|
|
6886
|
-
const bind = react$
|
|
6926
|
+
const bind = react$3.useDrag(
|
|
6887
6927
|
({ active, movement: [mx], velocity: [vx], direction: [dx], initial: [initialX], xy: [currentX], cancel, first }) => {
|
|
6888
6928
|
if (first && initialX < EDGE_IGNORE_ZONE) {
|
|
6889
6929
|
cancel();
|
|
@@ -7219,37 +7259,94 @@ function DefaultCardSkeleton() {
|
|
|
7219
7259
|
] })
|
|
7220
7260
|
] });
|
|
7221
7261
|
}
|
|
7222
|
-
|
|
7223
|
-
|
|
7224
|
-
|
|
7225
|
-
|
|
7226
|
-
|
|
7227
|
-
|
|
7228
|
-
|
|
7229
|
-
|
|
7230
|
-
|
|
7231
|
-
|
|
7232
|
-
|
|
7233
|
-
|
|
7234
|
-
|
|
7235
|
-
|
|
7262
|
+
var LONG_DESCRIPTION_THRESHOLD = 140;
|
|
7263
|
+
function isLongDescription(description) {
|
|
7264
|
+
if (!description) return false;
|
|
7265
|
+
return description.length > LONG_DESCRIPTION_THRESHOLD || description.includes("\n");
|
|
7266
|
+
}
|
|
7267
|
+
function ToastErrorContent({
|
|
7268
|
+
toastId,
|
|
7269
|
+
message,
|
|
7270
|
+
description,
|
|
7271
|
+
action,
|
|
7272
|
+
onDismiss
|
|
7273
|
+
}) {
|
|
7274
|
+
const [detailsOpen, setDetailsOpen] = React19.useState(false);
|
|
7275
|
+
const [copied, setCopied] = React19.useState(false);
|
|
7276
|
+
const showDetails = isLongDescription(description);
|
|
7277
|
+
const handleCopy = async () => {
|
|
7278
|
+
if (!description) return;
|
|
7279
|
+
try {
|
|
7280
|
+
await navigator.clipboard.writeText(description);
|
|
7281
|
+
setCopied(true);
|
|
7282
|
+
setTimeout(() => setCopied(false), 1500);
|
|
7283
|
+
} catch {
|
|
7284
|
+
}
|
|
7285
|
+
};
|
|
7286
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
7287
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
7288
|
+
"div",
|
|
7289
|
+
{
|
|
7290
|
+
className: "bg-background text-foreground border-destructive/20 w-full rounded-md border px-4 py-3 shadow-lg\n sm:w-[var(--width)]",
|
|
7291
|
+
children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex gap-2", children: [
|
|
7292
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex min-w-0 grow gap-3", children: [
|
|
7293
|
+
/* @__PURE__ */ jsxRuntime.jsx(lucideReact.AlertCircleIcon, { className: "text-destructive mt-0.5 shrink-0", size: 16, "aria-hidden": "true" }),
|
|
7294
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex min-w-0 grow flex-col gap-1", children: [
|
|
7295
|
+
/* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-destructive text-sm font-medium break-words", children: message }),
|
|
7296
|
+
description && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-muted-foreground line-clamp-3 text-sm break-words", children: description }),
|
|
7297
|
+
(showDetails || action) && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-wrap gap-x-4 gap-y-1", children: [
|
|
7298
|
+
showDetails && /* @__PURE__ */ jsxRuntime.jsx(
|
|
7299
|
+
"button",
|
|
7300
|
+
{
|
|
7301
|
+
className: "text-muted-foreground hover:text-foreground text-xs font-medium underline underline-offset-2 decoration-dotted",
|
|
7302
|
+
onClick: () => setDetailsOpen(true),
|
|
7303
|
+
children: "View details"
|
|
7304
|
+
}
|
|
7305
|
+
),
|
|
7306
|
+
action && /* @__PURE__ */ jsxRuntime.jsx(
|
|
7307
|
+
"button",
|
|
7308
|
+
{
|
|
7309
|
+
className: "text-destructive text-sm font-medium hover:underline",
|
|
7310
|
+
onClick: action.onClick,
|
|
7311
|
+
children: action.label
|
|
7312
|
+
}
|
|
7313
|
+
)
|
|
7314
|
+
] })
|
|
7315
|
+
] })
|
|
7316
|
+
] }),
|
|
7317
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
7318
|
+
Button,
|
|
7319
|
+
{
|
|
7320
|
+
variant: "ghost",
|
|
7321
|
+
className: "group -my-1.5 -me-2 size-8 shrink-0 p-0 hover:bg-transparent",
|
|
7322
|
+
onClick: () => {
|
|
7323
|
+
sonner.toast.dismiss(toastId);
|
|
7324
|
+
onDismiss?.();
|
|
7325
|
+
},
|
|
7326
|
+
"aria-label": "Close error notification",
|
|
7327
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.XIcon, { size: 16, className: "opacity-60 transition-opacity group-hover:opacity-100", "aria-hidden": "true" })
|
|
7328
|
+
}
|
|
7329
|
+
)
|
|
7330
|
+
] })
|
|
7331
|
+
}
|
|
7332
|
+
),
|
|
7333
|
+
showDetails && description && /* @__PURE__ */ jsxRuntime.jsx(Dialog, { open: detailsOpen, onOpenChange: setDetailsOpen, children: /* @__PURE__ */ jsxRuntime.jsxs(DialogPopup, { className: "max-w-2xl", children: [
|
|
7334
|
+
/* @__PURE__ */ jsxRuntime.jsx(DialogHeader, { children: /* @__PURE__ */ jsxRuntime.jsx(DialogTitle, { children: message }) }),
|
|
7335
|
+
/* @__PURE__ */ jsxRuntime.jsx(DialogPanel, { children: /* @__PURE__ */ jsxRuntime.jsx("pre", { className: "bg-muted text-foreground rounded-md p-3 text-xs break-words whitespace-pre-wrap", children: description }) }),
|
|
7336
|
+
/* @__PURE__ */ jsxRuntime.jsxs(DialogFooter, { children: [
|
|
7337
|
+
/* @__PURE__ */ jsxRuntime.jsxs(Button, { variant: "outline", size: "sm", onClick: handleCopy, children: [
|
|
7338
|
+
copied ? /* @__PURE__ */ jsxRuntime.jsx(lucideReact.CheckIcon, { size: 14, "aria-hidden": "true" }) : /* @__PURE__ */ jsxRuntime.jsx(lucideReact.CopyIcon, { size: 14, "aria-hidden": "true" }),
|
|
7339
|
+
copied ? "Copied" : "Copy"
|
|
7236
7340
|
] }),
|
|
7237
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
7238
|
-
Button,
|
|
7239
|
-
{
|
|
7240
|
-
variant: "ghost",
|
|
7241
|
-
className: "group -my-1.5 -me-2 size-8 shrink-0 p-0 hover:bg-transparent",
|
|
7242
|
-
onClick: () => {
|
|
7243
|
-
sonner.toast.dismiss(t);
|
|
7244
|
-
onDismiss?.();
|
|
7245
|
-
},
|
|
7246
|
-
"aria-label": "Close error notification",
|
|
7247
|
-
children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.XIcon, { size: 16, className: "opacity-60 transition-opacity group-hover:opacity-100", "aria-hidden": "true" })
|
|
7248
|
-
}
|
|
7249
|
-
)
|
|
7341
|
+
/* @__PURE__ */ jsxRuntime.jsx(DialogClose, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(Button, { size: "sm", children: "Close" }) })
|
|
7250
7342
|
] })
|
|
7251
|
-
}
|
|
7252
|
-
)
|
|
7343
|
+
] }) })
|
|
7344
|
+
] });
|
|
7345
|
+
}
|
|
7346
|
+
function showErrorToast(props) {
|
|
7347
|
+
return sonner.toast.custom((t) => /* @__PURE__ */ jsxRuntime.jsx(ToastErrorContent, { toastId: t, ...props }), {
|
|
7348
|
+
duration: Infinity
|
|
7349
|
+
});
|
|
7253
7350
|
}
|
|
7254
7351
|
function showInfoToast(props) {
|
|
7255
7352
|
const { message, description, action, onDismiss } = props;
|
|
@@ -7377,6 +7474,481 @@ var toast5 = {
|
|
|
7377
7474
|
warning: showWarningToast
|
|
7378
7475
|
};
|
|
7379
7476
|
|
|
7477
|
+
// src/components/org-chart/layout.ts
|
|
7478
|
+
var NODE_WIDTH = 260;
|
|
7479
|
+
var NODE_HEIGHT = 100;
|
|
7480
|
+
var RANK_SEP = 80;
|
|
7481
|
+
var NODE_SEP = 40;
|
|
7482
|
+
var ROOT_KEY = "__root__";
|
|
7483
|
+
function computeLayout(edges) {
|
|
7484
|
+
const edgeById = /* @__PURE__ */ new Map();
|
|
7485
|
+
const childCountMap = /* @__PURE__ */ new Map();
|
|
7486
|
+
const childrenMap = /* @__PURE__ */ new Map();
|
|
7487
|
+
for (const e of edges) {
|
|
7488
|
+
edgeById.set(e.id, e);
|
|
7489
|
+
if (e.parentId) {
|
|
7490
|
+
childCountMap.set(e.parentId, (childCountMap.get(e.parentId) ?? 0) + 1);
|
|
7491
|
+
}
|
|
7492
|
+
const parent = e.parentId ?? ROOT_KEY;
|
|
7493
|
+
const bucket = childrenMap.get(parent);
|
|
7494
|
+
if (bucket) bucket.push(e.id);
|
|
7495
|
+
else childrenMap.set(parent, [e.id]);
|
|
7496
|
+
}
|
|
7497
|
+
for (const children of childrenMap.values()) {
|
|
7498
|
+
children.sort((a, b) => {
|
|
7499
|
+
const nameA = edgeById.get(a)?.displayName?.toLowerCase() ?? "";
|
|
7500
|
+
const nameB = edgeById.get(b)?.displayName?.toLowerCase() ?? "";
|
|
7501
|
+
return nameA.localeCompare(nameB);
|
|
7502
|
+
});
|
|
7503
|
+
}
|
|
7504
|
+
const widthCache = /* @__PURE__ */ new Map();
|
|
7505
|
+
const subtreeWidth = (nodeId) => {
|
|
7506
|
+
if (widthCache.has(nodeId)) return widthCache.get(nodeId);
|
|
7507
|
+
const children = childrenMap.get(nodeId);
|
|
7508
|
+
if (!children || children.length === 0) {
|
|
7509
|
+
widthCache.set(nodeId, NODE_WIDTH);
|
|
7510
|
+
return NODE_WIDTH;
|
|
7511
|
+
}
|
|
7512
|
+
const totalChildWidth = children.reduce((sum, c) => sum + subtreeWidth(c), 0);
|
|
7513
|
+
const gaps = (children.length - 1) * NODE_SEP;
|
|
7514
|
+
const w = Math.max(NODE_WIDTH, totalChildWidth + gaps);
|
|
7515
|
+
widthCache.set(nodeId, w);
|
|
7516
|
+
return w;
|
|
7517
|
+
};
|
|
7518
|
+
const positions = /* @__PURE__ */ new Map();
|
|
7519
|
+
const positionSubtree = (nodeId, centerX, y) => {
|
|
7520
|
+
positions.set(nodeId, { x: centerX, y });
|
|
7521
|
+
const children = childrenMap.get(nodeId);
|
|
7522
|
+
if (!children || children.length === 0) return;
|
|
7523
|
+
const totalWidth = children.reduce((sum, c) => sum + subtreeWidth(c), 0) + (children.length - 1) * NODE_SEP;
|
|
7524
|
+
let currentX = centerX - totalWidth / 2;
|
|
7525
|
+
for (const childId of children) {
|
|
7526
|
+
const childW = subtreeWidth(childId);
|
|
7527
|
+
positionSubtree(childId, currentX + childW / 2, y + NODE_HEIGHT + RANK_SEP);
|
|
7528
|
+
currentX += childW + NODE_SEP;
|
|
7529
|
+
}
|
|
7530
|
+
};
|
|
7531
|
+
const roots = childrenMap.get(ROOT_KEY) ?? [];
|
|
7532
|
+
if (roots.length === 1) {
|
|
7533
|
+
positionSubtree(roots[0], 0, 0);
|
|
7534
|
+
} else {
|
|
7535
|
+
const totalWidth = roots.reduce((sum, r) => sum + subtreeWidth(r), 0) + (roots.length - 1) * NODE_SEP;
|
|
7536
|
+
let currentX = -totalWidth / 2;
|
|
7537
|
+
for (const rootId of roots) {
|
|
7538
|
+
const w = subtreeWidth(rootId);
|
|
7539
|
+
positionSubtree(rootId, currentX + w / 2, 0);
|
|
7540
|
+
currentX += w + NODE_SEP;
|
|
7541
|
+
}
|
|
7542
|
+
}
|
|
7543
|
+
const nodes = edges.map((e) => {
|
|
7544
|
+
const pos = positions.get(e.id);
|
|
7545
|
+
return {
|
|
7546
|
+
id: e.id,
|
|
7547
|
+
type: "orgChartNode",
|
|
7548
|
+
width: NODE_WIDTH,
|
|
7549
|
+
height: NODE_HEIGHT,
|
|
7550
|
+
position: {
|
|
7551
|
+
x: pos.x - NODE_WIDTH / 2,
|
|
7552
|
+
y: pos.y
|
|
7553
|
+
},
|
|
7554
|
+
data: {
|
|
7555
|
+
id: e.id,
|
|
7556
|
+
displayName: e.displayName,
|
|
7557
|
+
avatarUrl: e.avatarUrl,
|
|
7558
|
+
positionTitle: e.positionTitle,
|
|
7559
|
+
parentId: e.parentId,
|
|
7560
|
+
childCount: childCountMap.get(e.id) ?? 0,
|
|
7561
|
+
isRoot: !e.parentId
|
|
7562
|
+
}
|
|
7563
|
+
};
|
|
7564
|
+
});
|
|
7565
|
+
const flowEdges = edges.filter((e) => e.parentId).map((e) => ({
|
|
7566
|
+
id: `edge-${e.parentId}-${e.id}`,
|
|
7567
|
+
source: e.parentId,
|
|
7568
|
+
target: e.id,
|
|
7569
|
+
type: "orgChartEdge"
|
|
7570
|
+
}));
|
|
7571
|
+
return { nodes, edges: flowEdges };
|
|
7572
|
+
}
|
|
7573
|
+
var NodeActionsContext = React19.createContext(null);
|
|
7574
|
+
var OrgChartContext = React19.createContext(null);
|
|
7575
|
+
function OrgChartProvider({ children, editable }) {
|
|
7576
|
+
const [selectedNodeId, setSelectedNodeId] = React19.useState(null);
|
|
7577
|
+
const [draggedNodeId, setDraggedNodeId] = React19.useState(null);
|
|
7578
|
+
const [dropTargetNodeId, setDropTargetNodeId] = React19.useState(null);
|
|
7579
|
+
const selectNode = React19.useCallback((nodeId) => setSelectedNodeId(nodeId), []);
|
|
7580
|
+
const clearSelection = React19.useCallback(() => setSelectedNodeId(null), []);
|
|
7581
|
+
const value = React19.useMemo(
|
|
7582
|
+
() => ({
|
|
7583
|
+
selectedNodeId,
|
|
7584
|
+
selectNode,
|
|
7585
|
+
clearSelection,
|
|
7586
|
+
editable,
|
|
7587
|
+
draggedNodeId,
|
|
7588
|
+
setDraggedNodeId,
|
|
7589
|
+
dropTargetNodeId,
|
|
7590
|
+
setDropTargetNodeId
|
|
7591
|
+
}),
|
|
7592
|
+
[selectedNodeId, selectNode, clearSelection, editable, draggedNodeId, dropTargetNodeId]
|
|
7593
|
+
);
|
|
7594
|
+
return /* @__PURE__ */ jsxRuntime.jsx(OrgChartContext.Provider, { value, children });
|
|
7595
|
+
}
|
|
7596
|
+
function useOrgChartContext() {
|
|
7597
|
+
const ctx = React19.useContext(OrgChartContext);
|
|
7598
|
+
if (!ctx) throw new Error("useOrgChartContext must be used within OrgChartProvider");
|
|
7599
|
+
return ctx;
|
|
7600
|
+
}
|
|
7601
|
+
function NodeActionsProvider({
|
|
7602
|
+
children,
|
|
7603
|
+
onEditNode,
|
|
7604
|
+
onRemoveNode
|
|
7605
|
+
}) {
|
|
7606
|
+
const value = React19.useMemo(() => ({ onEditNode, onRemoveNode }), [onEditNode, onRemoveNode]);
|
|
7607
|
+
return /* @__PURE__ */ jsxRuntime.jsx(NodeActionsContext.Provider, { value, children });
|
|
7608
|
+
}
|
|
7609
|
+
function useNodeActions() {
|
|
7610
|
+
const ctx = React19.useContext(NodeActionsContext);
|
|
7611
|
+
if (!ctx) throw new Error("useNodeActions must be used within NodeActionsProvider");
|
|
7612
|
+
return ctx;
|
|
7613
|
+
}
|
|
7614
|
+
function OrgChartEdge({
|
|
7615
|
+
sourceX,
|
|
7616
|
+
sourceY,
|
|
7617
|
+
targetX,
|
|
7618
|
+
targetY,
|
|
7619
|
+
sourcePosition,
|
|
7620
|
+
targetPosition,
|
|
7621
|
+
style = {}
|
|
7622
|
+
}) {
|
|
7623
|
+
const [edgePath] = react$1.getSmoothStepPath({
|
|
7624
|
+
sourceX,
|
|
7625
|
+
sourceY,
|
|
7626
|
+
sourcePosition,
|
|
7627
|
+
targetX,
|
|
7628
|
+
targetY,
|
|
7629
|
+
targetPosition,
|
|
7630
|
+
borderRadius: 12
|
|
7631
|
+
});
|
|
7632
|
+
return /* @__PURE__ */ jsxRuntime.jsx(react$1.BaseEdge, { path: edgePath, style });
|
|
7633
|
+
}
|
|
7634
|
+
function OrgChartEmpty({ editable, onAddRoot }) {
|
|
7635
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-card border-border/60 flex flex-col items-center justify-center rounded-xl border py-16", children: [
|
|
7636
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "bg-muted mb-4 flex size-14 items-center justify-center rounded-2xl", children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Network, { className: "text-muted-foreground size-7" }) }),
|
|
7637
|
+
/* @__PURE__ */ jsxRuntime.jsx("h3", { className: "text-foreground text-base font-semibold", children: "No Org Chart Yet" }),
|
|
7638
|
+
/* @__PURE__ */ jsxRuntime.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." }),
|
|
7639
|
+
editable && /* @__PURE__ */ jsxRuntime.jsxs(Button, { className: "mt-5 gap-1.5", onClick: onAddRoot, children: [
|
|
7640
|
+
/* @__PURE__ */ jsxRuntime.jsx(lucideReact.UserPlus, { className: "size-3.5" }),
|
|
7641
|
+
"Add First Member"
|
|
7642
|
+
] })
|
|
7643
|
+
] });
|
|
7644
|
+
}
|
|
7645
|
+
|
|
7646
|
+
// src/components/org-chart/org-chart-utils.ts
|
|
7647
|
+
function getInitials(name) {
|
|
7648
|
+
if (!name) return "--";
|
|
7649
|
+
const parts = name.trim().split(/\s+/).filter(Boolean);
|
|
7650
|
+
if (parts.length === 0) return "--";
|
|
7651
|
+
if (parts.length === 1) return parts[0].slice(0, 2).toUpperCase();
|
|
7652
|
+
return (parts[0][0] + parts[1][0]).toUpperCase();
|
|
7653
|
+
}
|
|
7654
|
+
function OrgChartNodeComponent({ id, data }) {
|
|
7655
|
+
const { selectedNodeId, dropTargetNodeId, editable } = useOrgChartContext();
|
|
7656
|
+
const { onEditNode, onRemoveNode } = useNodeActions();
|
|
7657
|
+
const isSelected = selectedNodeId === id;
|
|
7658
|
+
const isDropTarget = dropTargetNodeId === id;
|
|
7659
|
+
const [isHovered, setIsHovered] = React19.useState(false);
|
|
7660
|
+
const [isMenuOpen, setIsMenuOpen] = React19.useState(false);
|
|
7661
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
7662
|
+
"div",
|
|
7663
|
+
{
|
|
7664
|
+
style: { width: NODE_WIDTH },
|
|
7665
|
+
className: cn(
|
|
7666
|
+
"bg-card dark:bg-muted relative rounded-xl border shadow-sm transition-all",
|
|
7667
|
+
"border-border/60",
|
|
7668
|
+
isSelected && "ring-primary ring-2 ring-offset-2 dark:ring-offset-zinc-900",
|
|
7669
|
+
isDropTarget && "ring-primary/50 border-primary scale-105 ring-2"
|
|
7670
|
+
),
|
|
7671
|
+
onMouseEnter: () => setIsHovered(true),
|
|
7672
|
+
onMouseLeave: () => setIsHovered(false),
|
|
7673
|
+
children: [
|
|
7674
|
+
!data.isRoot && /* @__PURE__ */ jsxRuntime.jsx(react$1.Handle, { type: "target", position: react$1.Position.Top, className: "!bg-border !size-2 !rounded-full !border-0" }),
|
|
7675
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-3 px-4 py-3", children: [
|
|
7676
|
+
/* @__PURE__ */ jsxRuntime.jsxs(Avatar, { className: "size-10 shrink-0", children: [
|
|
7677
|
+
data.avatarUrl && /* @__PURE__ */ jsxRuntime.jsx(AvatarImage, { src: data.avatarUrl, alt: data.displayName ?? "" }),
|
|
7678
|
+
/* @__PURE__ */ jsxRuntime.jsx(AvatarFallback, { className: "bg-primary/10 text-primary text-xs font-medium", children: getInitials(data.displayName) })
|
|
7679
|
+
] }),
|
|
7680
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "min-w-0 flex-1", children: [
|
|
7681
|
+
/* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-foreground truncate text-sm font-semibold", children: data.displayName ?? "Unknown" }),
|
|
7682
|
+
data.positionTitle && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-muted-foreground truncate text-xs", children: data.positionTitle })
|
|
7683
|
+
] }),
|
|
7684
|
+
editable && (isHovered || isMenuOpen) ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "nodrag nopan shrink-0", children: /* @__PURE__ */ jsxRuntime.jsxs(DropdownMenu, { open: isMenuOpen, onOpenChange: setIsMenuOpen, children: [
|
|
7685
|
+
/* @__PURE__ */ jsxRuntime.jsx(DropdownMenuTrigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
7686
|
+
Button,
|
|
7687
|
+
{
|
|
7688
|
+
variant: "ghost",
|
|
7689
|
+
size: "icon",
|
|
7690
|
+
className: "size-7 rounded-full",
|
|
7691
|
+
onClick: (e) => e.stopPropagation(),
|
|
7692
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Ellipsis, { className: "size-4" })
|
|
7693
|
+
}
|
|
7694
|
+
) }),
|
|
7695
|
+
/* @__PURE__ */ jsxRuntime.jsxs(DropdownMenuContent, { align: "start", side: "right", className: "translate-x-1 -translate-y-3.5", children: [
|
|
7696
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
7697
|
+
DropdownMenuItem,
|
|
7698
|
+
{
|
|
7699
|
+
onClick: (e) => {
|
|
7700
|
+
e.stopPropagation();
|
|
7701
|
+
setIsMenuOpen(false);
|
|
7702
|
+
onEditNode(data);
|
|
7703
|
+
},
|
|
7704
|
+
children: [
|
|
7705
|
+
/* @__PURE__ */ jsxRuntime.jsx(lucideReact.Pencil, { className: "mr-2 size-3.5" }),
|
|
7706
|
+
"Edit Position"
|
|
7707
|
+
]
|
|
7708
|
+
}
|
|
7709
|
+
),
|
|
7710
|
+
/* @__PURE__ */ jsxRuntime.jsx(DropdownMenuSeparator, {}),
|
|
7711
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
7712
|
+
DropdownMenuItem,
|
|
7713
|
+
{
|
|
7714
|
+
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",
|
|
7715
|
+
onClick: (e) => {
|
|
7716
|
+
e.stopPropagation();
|
|
7717
|
+
setIsMenuOpen(false);
|
|
7718
|
+
onRemoveNode(data);
|
|
7719
|
+
},
|
|
7720
|
+
children: [
|
|
7721
|
+
/* @__PURE__ */ jsxRuntime.jsx(lucideReact.Trash2, { className: "mr-2 size-3.5" }),
|
|
7722
|
+
"Remove from Chart"
|
|
7723
|
+
]
|
|
7724
|
+
}
|
|
7725
|
+
)
|
|
7726
|
+
] })
|
|
7727
|
+
] }) }) : data.childCount > 0 && /* @__PURE__ */ jsxRuntime.jsx(Badge, { variant: "secondary", className: "shrink-0 text-[10px]", children: data.childCount })
|
|
7728
|
+
] }),
|
|
7729
|
+
/* @__PURE__ */ jsxRuntime.jsx(react$1.Handle, { type: "source", position: react$1.Position.Bottom, className: "!bg-border !size-2 !rounded-full !border-0" })
|
|
7730
|
+
]
|
|
7731
|
+
}
|
|
7732
|
+
);
|
|
7733
|
+
}
|
|
7734
|
+
var OrgChartNodeMemo = React19.memo(OrgChartNodeComponent);
|
|
7735
|
+
var FIT_VIEW_OPTIONS = { padding: 0.12 };
|
|
7736
|
+
function getDescendantIds(nodeId, nodes) {
|
|
7737
|
+
const descendants = /* @__PURE__ */ new Set();
|
|
7738
|
+
const queue = [nodeId];
|
|
7739
|
+
while (queue.length > 0) {
|
|
7740
|
+
const current = queue.pop();
|
|
7741
|
+
for (const n of nodes) {
|
|
7742
|
+
if (n.data.parentId === current && !descendants.has(n.id)) {
|
|
7743
|
+
descendants.add(n.id);
|
|
7744
|
+
queue.push(n.id);
|
|
7745
|
+
}
|
|
7746
|
+
}
|
|
7747
|
+
}
|
|
7748
|
+
return descendants;
|
|
7749
|
+
}
|
|
7750
|
+
function mergeWithMeasured(prev, layoutNodes) {
|
|
7751
|
+
const prevMap = new Map(prev.map((n) => [n.id, n]));
|
|
7752
|
+
return layoutNodes.map((n) => {
|
|
7753
|
+
const existing = prevMap.get(n.id);
|
|
7754
|
+
if (!existing) return n;
|
|
7755
|
+
return existing.data.isRoot !== n.data.isRoot ? n : { ...n, measured: existing.measured };
|
|
7756
|
+
});
|
|
7757
|
+
}
|
|
7758
|
+
function OrgChartInner({
|
|
7759
|
+
className,
|
|
7760
|
+
edges: controlledEdges,
|
|
7761
|
+
defaultEdges,
|
|
7762
|
+
isLoading = false,
|
|
7763
|
+
editable = true,
|
|
7764
|
+
onReparent,
|
|
7765
|
+
onAddToChart,
|
|
7766
|
+
onEditNode,
|
|
7767
|
+
onRemoveNode,
|
|
7768
|
+
onReparentSuccess,
|
|
7769
|
+
onReparentError
|
|
7770
|
+
}) {
|
|
7771
|
+
const isControlled = controlledEdges !== void 0;
|
|
7772
|
+
const {
|
|
7773
|
+
selectNode,
|
|
7774
|
+
clearSelection,
|
|
7775
|
+
setDraggedNodeId,
|
|
7776
|
+
setDropTargetNodeId
|
|
7777
|
+
} = useOrgChartContext();
|
|
7778
|
+
const [internalEdges, setInternalEdges] = React19.useState(defaultEdges ?? []);
|
|
7779
|
+
const defaultEdgesHash = React19.useMemo(
|
|
7780
|
+
() => defaultEdges?.map((e) => `${e.id}:${e.parentId}:${e.positionTitle ?? ""}:${e.displayName ?? ""}`).join(",") ?? "",
|
|
7781
|
+
[defaultEdges]
|
|
7782
|
+
);
|
|
7783
|
+
React19.useEffect(() => {
|
|
7784
|
+
if (!isControlled && defaultEdges) {
|
|
7785
|
+
setInternalEdges(defaultEdges);
|
|
7786
|
+
}
|
|
7787
|
+
}, [defaultEdgesHash]);
|
|
7788
|
+
const apiEdges = controlledEdges ?? internalEdges;
|
|
7789
|
+
const layout = React19.useMemo(() => apiEdges.length > 0 ? computeLayout(apiEdges) : null, [apiEdges]);
|
|
7790
|
+
const layoutNodes = layout?.nodes ?? [];
|
|
7791
|
+
const layoutEdges = layout?.edges ?? [];
|
|
7792
|
+
const isEmpty = apiEdges.length === 0 && !isLoading;
|
|
7793
|
+
const { fitView, getIntersectingNodes } = react$1.useReactFlow();
|
|
7794
|
+
const [nodes, setNodes, onNodesChange] = react$1.useNodesState([]);
|
|
7795
|
+
const [rfEdges, setRfEdges, onEdgesChange] = react$1.useEdgesState([]);
|
|
7796
|
+
const nodesHash = React19.useMemo(
|
|
7797
|
+
() => layoutNodes.map((n) => `${n.id}:${n.data.parentId ?? ""}:${n.data.positionTitle ?? ""}:${n.data.displayName ?? ""}`).join(","),
|
|
7798
|
+
[layoutNodes]
|
|
7799
|
+
);
|
|
7800
|
+
const edgesHash = React19.useMemo(() => layoutEdges.map((e) => `${e.id}:${e.source}:${e.target}`).join(","), [layoutEdges]);
|
|
7801
|
+
const fitViewRef = React19.useRef(fitView);
|
|
7802
|
+
fitViewRef.current = fitView;
|
|
7803
|
+
React19.useEffect(() => {
|
|
7804
|
+
setNodes((prev) => mergeWithMeasured(prev, layoutNodes));
|
|
7805
|
+
setRfEdges(layoutEdges);
|
|
7806
|
+
const raf = requestAnimationFrame(() => fitViewRef.current(FIT_VIEW_OPTIONS));
|
|
7807
|
+
return () => cancelAnimationFrame(raf);
|
|
7808
|
+
}, [nodesHash, edgesHash]);
|
|
7809
|
+
const draggedNodeRef = React19.useRef(null);
|
|
7810
|
+
const dropTargetIdRef = React19.useRef(null);
|
|
7811
|
+
const nodeTypes = React19.useMemo(() => ({ orgChartNode: OrgChartNodeMemo }), []);
|
|
7812
|
+
const edgeTypes = React19.useMemo(() => ({ orgChartEdge: OrgChartEdge }), []);
|
|
7813
|
+
const onNodeDragStart = React19.useCallback(
|
|
7814
|
+
(_, node) => {
|
|
7815
|
+
if (!editable) return;
|
|
7816
|
+
draggedNodeRef.current = node.id;
|
|
7817
|
+
setDraggedNodeId(node.id);
|
|
7818
|
+
},
|
|
7819
|
+
[editable, setDraggedNodeId]
|
|
7820
|
+
);
|
|
7821
|
+
const onNodeDrag = React19.useCallback(
|
|
7822
|
+
(_, node) => {
|
|
7823
|
+
if (!editable || !draggedNodeRef.current) return;
|
|
7824
|
+
const intersecting = getIntersectingNodes(node);
|
|
7825
|
+
const target = intersecting.find((n) => n.id !== node.id);
|
|
7826
|
+
const targetId = target?.id ?? null;
|
|
7827
|
+
if (targetId === dropTargetIdRef.current) return;
|
|
7828
|
+
dropTargetIdRef.current = targetId;
|
|
7829
|
+
setDropTargetNodeId(targetId);
|
|
7830
|
+
},
|
|
7831
|
+
[editable, getIntersectingNodes, setDropTargetNodeId]
|
|
7832
|
+
);
|
|
7833
|
+
const applyOptimisticReparent = React19.useCallback((childId, newParentId) => {
|
|
7834
|
+
setInternalEdges(
|
|
7835
|
+
(prev) => prev.map((e) => e.id === childId ? { ...e, parentId: newParentId } : e)
|
|
7836
|
+
);
|
|
7837
|
+
}, []);
|
|
7838
|
+
const snapBack = React19.useCallback(() => {
|
|
7839
|
+
setNodes((prev) => mergeWithMeasured(prev, layoutNodes));
|
|
7840
|
+
}, [layoutNodes, setNodes]);
|
|
7841
|
+
const onNodeDragStop = React19.useCallback(
|
|
7842
|
+
async (_, _node) => {
|
|
7843
|
+
if (!editable || !draggedNodeRef.current) return;
|
|
7844
|
+
const childId = draggedNodeRef.current;
|
|
7845
|
+
const newParentId = dropTargetIdRef.current;
|
|
7846
|
+
draggedNodeRef.current = null;
|
|
7847
|
+
dropTargetIdRef.current = null;
|
|
7848
|
+
setDraggedNodeId(null);
|
|
7849
|
+
setDropTargetNodeId(null);
|
|
7850
|
+
if (!newParentId || newParentId === childId) {
|
|
7851
|
+
snapBack();
|
|
7852
|
+
return;
|
|
7853
|
+
}
|
|
7854
|
+
if (getDescendantIds(childId, layoutNodes).has(newParentId)) {
|
|
7855
|
+
onReparentError?.("Cannot create circular reporting chain");
|
|
7856
|
+
snapBack();
|
|
7857
|
+
return;
|
|
7858
|
+
}
|
|
7859
|
+
const draggedData = layoutNodes.find((n) => n.id === childId)?.data;
|
|
7860
|
+
if (!draggedData || newParentId === draggedData.parentId) {
|
|
7861
|
+
snapBack();
|
|
7862
|
+
return;
|
|
7863
|
+
}
|
|
7864
|
+
const targetName = layoutNodes.find((n) => n.id === newParentId)?.data.displayName;
|
|
7865
|
+
const preserve = { positionTitle: draggedData.positionTitle };
|
|
7866
|
+
if (!isControlled) {
|
|
7867
|
+
const snapshotEdges = internalEdges;
|
|
7868
|
+
applyOptimisticReparent(childId, newParentId);
|
|
7869
|
+
try {
|
|
7870
|
+
await onReparent?.(childId, newParentId, preserve);
|
|
7871
|
+
onReparentSuccess?.(draggedData.displayName ?? "Member", targetName ?? "new manager");
|
|
7872
|
+
} catch (err) {
|
|
7873
|
+
console.error("[OrgChart] reparent failed", err);
|
|
7874
|
+
setInternalEdges(snapshotEdges);
|
|
7875
|
+
onReparentError?.("Failed to update reporting line");
|
|
7876
|
+
}
|
|
7877
|
+
} else {
|
|
7878
|
+
snapBack();
|
|
7879
|
+
try {
|
|
7880
|
+
await onReparent?.(childId, newParentId, preserve);
|
|
7881
|
+
onReparentSuccess?.(draggedData.displayName ?? "Member", targetName ?? "new manager");
|
|
7882
|
+
} catch (err) {
|
|
7883
|
+
console.error("[OrgChart] reparent failed", err);
|
|
7884
|
+
onReparentError?.("Failed to update reporting line");
|
|
7885
|
+
}
|
|
7886
|
+
}
|
|
7887
|
+
},
|
|
7888
|
+
[editable, isControlled, internalEdges, layoutNodes, onReparent, onReparentSuccess, onReparentError, applyOptimisticReparent, snapBack, setDraggedNodeId, setDropTargetNodeId]
|
|
7889
|
+
);
|
|
7890
|
+
const onNodeClick = React19.useCallback((_, node) => selectNode(node.id), [selectNode]);
|
|
7891
|
+
const onPaneClick = React19.useCallback(() => clearSelection(), [clearSelection]);
|
|
7892
|
+
const handleEditNode = React19.useCallback(
|
|
7893
|
+
(nodeData) => onEditNode?.(nodeData),
|
|
7894
|
+
[onEditNode]
|
|
7895
|
+
);
|
|
7896
|
+
const handleRemoveNode = React19.useCallback(
|
|
7897
|
+
(nodeData) => onRemoveNode?.(nodeData),
|
|
7898
|
+
[onRemoveNode]
|
|
7899
|
+
);
|
|
7900
|
+
if (isLoading) {
|
|
7901
|
+
return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "bg-card border-border/60 flex items-center justify-center rounded-xl border p-16", children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Loader2, { className: "text-muted-foreground size-6 animate-spin" }) });
|
|
7902
|
+
}
|
|
7903
|
+
if (isEmpty) {
|
|
7904
|
+
return /* @__PURE__ */ jsxRuntime.jsx(OrgChartEmpty, { editable, onAddRoot: onAddToChart ?? (() => {
|
|
7905
|
+
}) });
|
|
7906
|
+
}
|
|
7907
|
+
return /* @__PURE__ */ jsxRuntime.jsx(NodeActionsProvider, { onEditNode: handleEditNode, onRemoveNode: handleRemoveNode, children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: cn("border-border/60 h-[600px] overflow-hidden rounded-xl border", className), children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
7908
|
+
react$1.ReactFlow,
|
|
7909
|
+
{
|
|
7910
|
+
nodes,
|
|
7911
|
+
edges: rfEdges,
|
|
7912
|
+
onNodesChange,
|
|
7913
|
+
onEdgesChange,
|
|
7914
|
+
onNodeClick,
|
|
7915
|
+
proOptions: { hideAttribution: true },
|
|
7916
|
+
onPaneClick,
|
|
7917
|
+
onNodeDragStart,
|
|
7918
|
+
onNodeDrag,
|
|
7919
|
+
onNodeDragStop,
|
|
7920
|
+
nodeTypes,
|
|
7921
|
+
edgeTypes,
|
|
7922
|
+
fitView: true,
|
|
7923
|
+
fitViewOptions: FIT_VIEW_OPTIONS,
|
|
7924
|
+
minZoom: 0.3,
|
|
7925
|
+
maxZoom: 1.5,
|
|
7926
|
+
nodesDraggable: editable,
|
|
7927
|
+
nodesConnectable: false,
|
|
7928
|
+
elementsSelectable: true,
|
|
7929
|
+
selectNodesOnDrag: false,
|
|
7930
|
+
panOnDrag: true,
|
|
7931
|
+
zoomOnScroll: true,
|
|
7932
|
+
preventScrolling: true,
|
|
7933
|
+
style: {
|
|
7934
|
+
"--xy-background-pattern-dots-color-default": "var(--color-border)",
|
|
7935
|
+
"--xy-edge-stroke-width-default": 2,
|
|
7936
|
+
"--xy-edge-stroke-default": "var(--color-border)",
|
|
7937
|
+
"--xy-edge-stroke-selected-default": "var(--color-foreground)",
|
|
7938
|
+
"--xy-attribution-background-color-default": "transparent"
|
|
7939
|
+
},
|
|
7940
|
+
attributionPosition: "bottom-left",
|
|
7941
|
+
children: [
|
|
7942
|
+
/* @__PURE__ */ jsxRuntime.jsx(react$1.Background, { variant: react$1.BackgroundVariant.Dots, gap: 20, size: 2 }),
|
|
7943
|
+
/* @__PURE__ */ jsxRuntime.jsx(FlowZoomPanel, { fitViewOptions: FIT_VIEW_OPTIONS })
|
|
7944
|
+
]
|
|
7945
|
+
}
|
|
7946
|
+
) }) });
|
|
7947
|
+
}
|
|
7948
|
+
function OrgChart(props) {
|
|
7949
|
+
return /* @__PURE__ */ jsxRuntime.jsx(react$1.ReactFlowProvider, { children: /* @__PURE__ */ jsxRuntime.jsx(OrgChartProvider, { editable: props.editable ?? true, children: /* @__PURE__ */ jsxRuntime.jsx(TooltipProvider, { children: /* @__PURE__ */ jsxRuntime.jsx(OrgChartInner, { ...props }) }) }) });
|
|
7950
|
+
}
|
|
7951
|
+
|
|
7380
7952
|
exports.Alert = Alert;
|
|
7381
7953
|
exports.AlertDescription = AlertDescription;
|
|
7382
7954
|
exports.AlertDialog = AlertDialog;
|
|
@@ -7480,6 +8052,7 @@ exports.DropdownMenuTrigger = DropdownMenuTrigger;
|
|
|
7480
8052
|
exports.Field = Field;
|
|
7481
8053
|
exports.FieldRow = FieldRow;
|
|
7482
8054
|
exports.FlickeringGrid = FlickeringGrid;
|
|
8055
|
+
exports.FlowZoomPanel = FlowZoomPanel;
|
|
7483
8056
|
exports.Form = Form;
|
|
7484
8057
|
exports.FormControl = FormControl;
|
|
7485
8058
|
exports.FormControlComponent = FormControl2;
|
|
@@ -7500,6 +8073,7 @@ exports.Label = Label;
|
|
|
7500
8073
|
exports.ModalPortalScope = ModalPortalScope;
|
|
7501
8074
|
exports.MotionGrid = MotionGrid;
|
|
7502
8075
|
exports.MultiSelect = MultiSelect;
|
|
8076
|
+
exports.OrgChart = OrgChart;
|
|
7503
8077
|
exports.PORTAL_ROOT_ID = PORTAL_ROOT_ID;
|
|
7504
8078
|
exports.PageHeader = PageHeader;
|
|
7505
8079
|
exports.Pagination = Pagination;
|