@nubitio/ui 1.3.0 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +44 -0
- package/dist/index.cjs +686 -159
- package/dist/index.d.cts +207 -240
- package/dist/index.d.mts +207 -240
- package/dist/index.mjs +681 -157
- package/dist/style.css +160 -0
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
|
|
2
|
+
// \0rolldown/runtime.js
|
|
3
3
|
var __create = Object.create;
|
|
4
4
|
var __defProp = Object.defineProperty;
|
|
5
5
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
@@ -20,9 +20,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
20
20
|
value: mod,
|
|
21
21
|
enumerable: true
|
|
22
22
|
}) : target, mod));
|
|
23
|
-
//#endregion
|
|
24
23
|
let react = require("react");
|
|
25
|
-
react = __toESM(react, 1);
|
|
26
24
|
let react_jsx_runtime = require("react/jsx-runtime");
|
|
27
25
|
let _base_ui_react_dialog = require("@base-ui/react/dialog");
|
|
28
26
|
let react_dropzone = require("react-dropzone");
|
|
@@ -32,7 +30,8 @@ let _base_ui_react_menu = require("@base-ui/react/menu");
|
|
|
32
30
|
let _internationalized_date = require("@internationalized/date");
|
|
33
31
|
let _base_ui_react_popover = require("@base-ui/react/popover");
|
|
34
32
|
let _base_ui_react_tooltip = require("@base-ui/react/tooltip");
|
|
35
|
-
|
|
33
|
+
react = __toESM(react, 1);
|
|
34
|
+
// packages/ui/Avatar.tsx
|
|
36
35
|
/**
|
|
37
36
|
* 8 semantic hues aligned with the Fluent / @nubitio design palette.
|
|
38
37
|
* Expressed as HSL so the lightness can be adjusted for dark mode via CSS.
|
|
@@ -64,7 +63,7 @@ function getAvatarInitials(owner = "") {
|
|
|
64
63
|
}
|
|
65
64
|
function getAvatarHue(owner = "") {
|
|
66
65
|
let hash = 0;
|
|
67
|
-
for (let i = 0; i < owner.length; i++) hash = hash * 31 + owner.charCodeAt(i) &
|
|
66
|
+
for (let i = 0; i < owner.length; i++) hash = hash * 31 + owner.charCodeAt(i) & 0xfffffff;
|
|
68
67
|
return AVATAR_HUES[Math.abs(hash) % AVATAR_HUES.length];
|
|
69
68
|
}
|
|
70
69
|
const Avatar = ({ owner = "", size, variant = "md", shape = "circle", alt, className }) => {
|
|
@@ -89,13 +88,11 @@ const Avatar = ({ owner = "", size, variant = "md", shape = "circle", alt, class
|
|
|
89
88
|
children: initials
|
|
90
89
|
});
|
|
91
90
|
};
|
|
92
|
-
|
|
93
|
-
//#region packages/ui/OverlayContainer.tsx
|
|
91
|
+
// packages/ui/OverlayContainer.tsx
|
|
94
92
|
/** Keeps nested portals within the modal's focus and accessibility boundary. */
|
|
95
93
|
const OverlayContainerContext = (0, react.createContext)(null);
|
|
96
94
|
const useOverlayContainer = () => (0, react.useContext)(OverlayContainerContext);
|
|
97
|
-
|
|
98
|
-
//#region packages/ui/ModalSurface.tsx
|
|
95
|
+
// packages/ui/ModalSurface.tsx
|
|
99
96
|
/** Shared modal behavior for centered dialogs and side sheets. */
|
|
100
97
|
function ModalSurface({ open, onClose, children, rootClassName, className, style, scrimClassName, scrimLabel, labelledBy, ariaLabel, role = "dialog", keepMounted = false, restoreFocus = true, closeOnEscape = true, initialFocus, closeOnOutsideClick = true }) {
|
|
101
98
|
const parentContainer = useOverlayContainer();
|
|
@@ -155,8 +152,7 @@ function ModalSurface({ open, onClose, children, rootClassName, className, style
|
|
|
155
152
|
})
|
|
156
153
|
});
|
|
157
154
|
}
|
|
158
|
-
|
|
159
|
-
//#region packages/ui/Button.tsx
|
|
155
|
+
// packages/ui/Button.tsx
|
|
160
156
|
const cx$2 = (...values) => values.filter(Boolean).join(" ");
|
|
161
157
|
const Button = (0, react.forwardRef)(function Button({ variant = "secondary", size = "md", fullWidth = false, icon, loading = false, className, children, disabled, ...props }, ref) {
|
|
162
158
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
|
|
@@ -189,8 +185,7 @@ const IconButton = (0, react.forwardRef)(function IconButton({ icon, label, vari
|
|
|
189
185
|
})
|
|
190
186
|
});
|
|
191
187
|
});
|
|
192
|
-
|
|
193
|
-
//#region packages/ui/UiStrings.tsx
|
|
188
|
+
// packages/ui/UiStrings.tsx
|
|
194
189
|
const EN_UI_STRINGS = {
|
|
195
190
|
close: "Close",
|
|
196
191
|
closeDialog: "Close dialog",
|
|
@@ -261,7 +256,15 @@ const EN_UI_STRINGS = {
|
|
|
261
256
|
redo: "Redo (Ctrl+Y)",
|
|
262
257
|
featureUnavailable: "This feature is not available on your current plan.",
|
|
263
258
|
featureRequiresPlan: "This feature requires the {plan} plan. Upgrade your plan to unlock it.",
|
|
264
|
-
viewPlans: "View plans"
|
|
259
|
+
viewPlans: "View plans",
|
|
260
|
+
treeListFilter: "Filter rows",
|
|
261
|
+
treeListEmpty: "No rows to display",
|
|
262
|
+
treeListExpand: "Expand",
|
|
263
|
+
treeListCollapse: "Collapse",
|
|
264
|
+
treeListSelect: "Select row",
|
|
265
|
+
treeListSelectAll: "Select all visible rows",
|
|
266
|
+
treeListEdit: "Edit",
|
|
267
|
+
treeListMoveFailed: "The row could not be moved."
|
|
265
268
|
};
|
|
266
269
|
const ES_UI_STRINGS = {
|
|
267
270
|
close: "Cerrar",
|
|
@@ -333,7 +336,15 @@ const ES_UI_STRINGS = {
|
|
|
333
336
|
redo: "Rehacer (Ctrl+Y)",
|
|
334
337
|
featureUnavailable: "Esta función no está disponible en tu plan actual.",
|
|
335
338
|
featureRequiresPlan: "Esta función requiere el plan {plan}. Actualiza tu plan para desbloquearla.",
|
|
336
|
-
viewPlans: "Ver planes"
|
|
339
|
+
viewPlans: "Ver planes",
|
|
340
|
+
treeListFilter: "Filtrar filas",
|
|
341
|
+
treeListEmpty: "No hay filas para mostrar",
|
|
342
|
+
treeListExpand: "Expandir",
|
|
343
|
+
treeListCollapse: "Contraer",
|
|
344
|
+
treeListSelect: "Seleccionar fila",
|
|
345
|
+
treeListSelectAll: "Seleccionar todas las filas visibles",
|
|
346
|
+
treeListEdit: "Editar",
|
|
347
|
+
treeListMoveFailed: "No se pudo mover la fila."
|
|
337
348
|
};
|
|
338
349
|
const UiStringsContext = (0, react.createContext)(EN_UI_STRINGS);
|
|
339
350
|
const UiStringsProvider = ({ strings, children }) => {
|
|
@@ -347,8 +358,7 @@ const UiStringsProvider = ({ strings, children }) => {
|
|
|
347
358
|
});
|
|
348
359
|
};
|
|
349
360
|
const useUiStrings = () => (0, react.useContext)(UiStringsContext);
|
|
350
|
-
|
|
351
|
-
//#region packages/ui/AppDialog.tsx
|
|
361
|
+
// packages/ui/AppDialog.tsx
|
|
352
362
|
const formatSize = (value) => {
|
|
353
363
|
if (value === void 0) return void 0;
|
|
354
364
|
return typeof value === "number" ? `${value}px` : value;
|
|
@@ -404,8 +414,7 @@ const AppDialog = ({ visible, open, title, onClose, children, footer, width, max
|
|
|
404
414
|
]
|
|
405
415
|
});
|
|
406
416
|
};
|
|
407
|
-
|
|
408
|
-
//#region packages/ui/ConfirmDialog.tsx
|
|
417
|
+
// packages/ui/ConfirmDialog.tsx
|
|
409
418
|
function ConfirmDialog({ open, title, message, onConfirm, onCancel, confirmLabel, cancelLabel, variant = "warning" }) {
|
|
410
419
|
const strings = useUiStrings();
|
|
411
420
|
const cancelRef = (0, react.useRef)(null);
|
|
@@ -434,8 +443,7 @@ function ConfirmDialog({ open, title, message, onConfirm, onCancel, confirmLabel
|
|
|
434
443
|
})
|
|
435
444
|
});
|
|
436
445
|
}
|
|
437
|
-
|
|
438
|
-
//#region packages/ui/AppToolbar.tsx
|
|
446
|
+
// packages/ui/AppToolbar.tsx
|
|
439
447
|
const AppToolbar = ({ title, additionalToolbarContent, showRefreshButton = true, onRefresh, icon, refreshLabel = "Refresh", children }) => {
|
|
440
448
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
441
449
|
className: "view-wrapper view-wrapper-dashboard",
|
|
@@ -468,8 +476,7 @@ const AppToolbar = ({ title, additionalToolbarContent, showRefreshButton = true,
|
|
|
468
476
|
}), children]
|
|
469
477
|
});
|
|
470
478
|
};
|
|
471
|
-
|
|
472
|
-
//#region packages/ui/layoutUtils.ts
|
|
479
|
+
// packages/ui/layoutUtils.ts
|
|
473
480
|
function joinClasses(...parts) {
|
|
474
481
|
return parts.filter(Boolean).join(" ");
|
|
475
482
|
}
|
|
@@ -484,8 +491,7 @@ function colSpanClasses(span, spanSm, spanMd, spanLg) {
|
|
|
484
491
|
if (spanLg != null) classes.push(`nb-col--span-lg-${spanLg}`);
|
|
485
492
|
return classes;
|
|
486
493
|
}
|
|
487
|
-
|
|
488
|
-
//#region packages/ui/Card.tsx
|
|
494
|
+
// packages/ui/Card.tsx
|
|
489
495
|
const Card = ({ title, description, variant = "auth", className, children }) => {
|
|
490
496
|
const showHeader = Boolean(title || description);
|
|
491
497
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
@@ -505,8 +511,7 @@ const Card = ({ title, description, variant = "auth", className, children }) =>
|
|
|
505
511
|
})
|
|
506
512
|
});
|
|
507
513
|
};
|
|
508
|
-
|
|
509
|
-
//#region packages/ui/FormControls.tsx
|
|
514
|
+
// packages/ui/FormControls.tsx
|
|
510
515
|
const cx$1 = (...values) => values.filter(Boolean).join(" ");
|
|
511
516
|
const FormField = ({ label, error, helpText, children, className, ...props }) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("label", {
|
|
512
517
|
...props,
|
|
@@ -549,8 +554,7 @@ const TextAreaField = (0, react.forwardRef)(function TextAreaField({ className,
|
|
|
549
554
|
className: cx$1("nb-input", "nb-textarea", invalid && "nb-input--invalid", className)
|
|
550
555
|
});
|
|
551
556
|
});
|
|
552
|
-
|
|
553
|
-
//#region packages/ui/FileDropzone.tsx
|
|
557
|
+
// packages/ui/FileDropzone.tsx
|
|
554
558
|
function cx(...values) {
|
|
555
559
|
return values.filter(Boolean).join(" ");
|
|
556
560
|
}
|
|
@@ -690,9 +694,8 @@ function FileDropzone({ accept, value = null, image = false, disabled = false, r
|
|
|
690
694
|
})]
|
|
691
695
|
});
|
|
692
696
|
}
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
function AppDropdown({ id: idProp, ariaLabel, label, icon, value, options, onChange, disabled = false, placeholder = "Seleccionar…", variant = "form", className, showFieldLabel = variant === "form", menuMinWidth, error, helpText, menuHeader, menuFooter, onOpenChange }) {
|
|
697
|
+
// packages/ui/AppDropdown.tsx
|
|
698
|
+
function AppDropdown({ id: idProp, ariaLabel, label, icon, value, options, onChange, disabled = false, placeholder = "Seleccionar…", variant = "form", className, showFieldLabel = variant === "form", menuMinWidth, error, helpText, menuHeader, menuFooter, onOpenChange, triggerIcon }) {
|
|
696
699
|
const generatedId = (0, react.useId)();
|
|
697
700
|
const id = idProp ?? generatedId;
|
|
698
701
|
const container = useOverlayContainer();
|
|
@@ -700,6 +703,7 @@ function AppDropdown({ id: idProp, ariaLabel, label, icon, value, options, onCha
|
|
|
700
703
|
const selected = options.find((option) => option.value === value);
|
|
701
704
|
const labelled = !!label && (showFieldLabel || variant === "toolbar");
|
|
702
705
|
const message = error ?? helpText;
|
|
706
|
+
const triggerIconClass = triggerIcon?.startsWith("ph ") ? triggerIcon : triggerIcon?.startsWith("ph-") ? `ph ${triggerIcon}` : `ph ph-${triggerIcon}`;
|
|
703
707
|
const iconClass = icon?.startsWith("ph ") ? icon : icon?.startsWith("ph-") ? `ph ${icon}` : `ph ph-${icon}`;
|
|
704
708
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_base_ui_react_select.Select.Root, {
|
|
705
709
|
value,
|
|
@@ -751,17 +755,25 @@ function AppDropdown({ id: idProp, ariaLabel, label, icon, value, options, onCha
|
|
|
751
755
|
}
|
|
752
756
|
},
|
|
753
757
|
"aria-label": ariaLabel,
|
|
758
|
+
title: triggerIcon ? ariaLabel ?? selected?.label : void 0,
|
|
754
759
|
"aria-labelledby": ariaLabel ? void 0 : labelled ? `${id}-label ${id}-value` : `${id}-value`,
|
|
755
760
|
"aria-describedby": message ? `${id}-message` : void 0,
|
|
756
761
|
"aria-invalid": !!error || void 0,
|
|
757
|
-
children: [
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
762
|
+
children: [
|
|
763
|
+
triggerIcon && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("i", {
|
|
764
|
+
className: `${triggerIconClass} nb-dropdown__trigger-icon`,
|
|
765
|
+
"aria-hidden": "true"
|
|
766
|
+
}),
|
|
767
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
768
|
+
className: `nb-dropdown__value${triggerIcon ? " nb-sr-only" : ""}`,
|
|
769
|
+
id: `${id}-value`,
|
|
770
|
+
children: selected?.selectedLabel ?? selected?.label ?? placeholder
|
|
771
|
+
}),
|
|
772
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("i", {
|
|
773
|
+
className: "ph ph-caret-down nb-dropdown__caret",
|
|
774
|
+
"aria-hidden": "true"
|
|
775
|
+
})
|
|
776
|
+
]
|
|
765
777
|
}),
|
|
766
778
|
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_base_ui_react_select.Select.Portal, {
|
|
767
779
|
container: container ?? void 0,
|
|
@@ -821,8 +833,7 @@ function AppDropdown({ id: idProp, ariaLabel, label, icon, value, options, onCha
|
|
|
821
833
|
})
|
|
822
834
|
});
|
|
823
835
|
}
|
|
824
|
-
|
|
825
|
-
//#region packages/ui/useComboboxOptions.ts
|
|
836
|
+
// packages/ui/useComboboxOptions.ts
|
|
826
837
|
function mergeOptions(...groups) {
|
|
827
838
|
const map = /* @__PURE__ */ new Map();
|
|
828
839
|
for (const group of groups) for (const option of group) map.set(option.value, option);
|
|
@@ -959,8 +970,7 @@ function useComboboxOptions({ options, selected, loadOptions, open, query, debou
|
|
|
959
970
|
retry: () => setRevision((previous) => previous + 1)
|
|
960
971
|
};
|
|
961
972
|
}
|
|
962
|
-
|
|
963
|
-
//#region packages/ui/Combobox.tsx
|
|
973
|
+
// packages/ui/Combobox.tsx
|
|
964
974
|
const Combobox = (0, react.forwardRef)(function Combobox(props, ref) {
|
|
965
975
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(SelectionCombobox, {
|
|
966
976
|
...props,
|
|
@@ -1185,8 +1195,7 @@ function ComboboxClear({ label, disabled, multiple }) {
|
|
|
1185
1195
|
})
|
|
1186
1196
|
});
|
|
1187
1197
|
}
|
|
1188
|
-
|
|
1189
|
-
//#region packages/ui/SearchableAppDropdown.tsx
|
|
1198
|
+
// packages/ui/SearchableAppDropdown.tsx
|
|
1190
1199
|
const toOption = (option) => ({
|
|
1191
1200
|
value: option.value,
|
|
1192
1201
|
label: option.selectedLabel ?? option.label,
|
|
@@ -1237,8 +1246,7 @@ function SearchableAppDropdown({ options = [], searchable = true, searchPlacehol
|
|
|
1237
1246
|
loadingMessage: loadingLabel
|
|
1238
1247
|
});
|
|
1239
1248
|
}
|
|
1240
|
-
|
|
1241
|
-
//#region packages/ui/theme/ThemeProvider.tsx
|
|
1249
|
+
// packages/ui/theme/ThemeProvider.tsx
|
|
1242
1250
|
const ThemeContext = react.default.createContext(null);
|
|
1243
1251
|
function useTheme() {
|
|
1244
1252
|
const ctx = (0, react.useContext)(ThemeContext);
|
|
@@ -1360,8 +1368,7 @@ const ThemeProvider = ({ storageKey = "nb-theme", themePrefix = "nb-theme-", bas
|
|
|
1360
1368
|
children
|
|
1361
1369
|
});
|
|
1362
1370
|
};
|
|
1363
|
-
|
|
1364
|
-
//#region packages/ui/theme/ThemeSwitcher.tsx
|
|
1371
|
+
// packages/ui/theme/ThemeSwitcher.tsx
|
|
1365
1372
|
const iconByMode = {
|
|
1366
1373
|
light: "ph ph-sun",
|
|
1367
1374
|
dark: "ph ph-moon",
|
|
@@ -1385,8 +1392,7 @@ const ThemeSwitcher = ({ labelByMode: overrides } = {}) => {
|
|
|
1385
1392
|
onClick: switchTheme
|
|
1386
1393
|
}) });
|
|
1387
1394
|
};
|
|
1388
|
-
|
|
1389
|
-
//#region packages/ui/theme/DensityProvider.tsx
|
|
1395
|
+
// packages/ui/theme/DensityProvider.tsx
|
|
1390
1396
|
const DensityContext = (0, react.createContext)(null);
|
|
1391
1397
|
function useDensity() {
|
|
1392
1398
|
const ctx = (0, react.useContext)(DensityContext);
|
|
@@ -1414,8 +1420,7 @@ const DensityProvider = ({ children }) => {
|
|
|
1414
1420
|
children
|
|
1415
1421
|
});
|
|
1416
1422
|
};
|
|
1417
|
-
|
|
1418
|
-
//#region packages/ui/theme/useAccentColor.ts
|
|
1423
|
+
// packages/ui/theme/useAccentColor.ts
|
|
1419
1424
|
const ACCENT_PRESETS = [
|
|
1420
1425
|
{
|
|
1421
1426
|
label: "Azure",
|
|
@@ -1467,8 +1472,7 @@ function useAccentColor() {
|
|
|
1467
1472
|
presets: ACCENT_PRESETS
|
|
1468
1473
|
};
|
|
1469
1474
|
}
|
|
1470
|
-
|
|
1471
|
-
//#region packages/ui/SettingsPanel.tsx
|
|
1475
|
+
// packages/ui/SettingsPanel.tsx
|
|
1472
1476
|
const SettingsPanel = ({ onClose: _onClose }) => {
|
|
1473
1477
|
const strings = useUiStrings();
|
|
1474
1478
|
const { density, toggleDensity } = useDensity();
|
|
@@ -1531,8 +1535,7 @@ const SettingsPanel = ({ onClose: _onClose }) => {
|
|
|
1531
1535
|
]
|
|
1532
1536
|
});
|
|
1533
1537
|
};
|
|
1534
|
-
|
|
1535
|
-
//#region packages/ui/Badge.tsx
|
|
1538
|
+
// packages/ui/Badge.tsx
|
|
1536
1539
|
const Badge = ({ variant = "primary", size = "md", outlined = false, pill = true, dot = false, children, className }) => {
|
|
1537
1540
|
const classes = [
|
|
1538
1541
|
"nb-badge",
|
|
@@ -1548,8 +1551,7 @@ const Badge = ({ variant = "primary", size = "md", outlined = false, pill = true
|
|
|
1548
1551
|
children: dot ? null : children
|
|
1549
1552
|
});
|
|
1550
1553
|
};
|
|
1551
|
-
|
|
1552
|
-
//#region packages/ui/FeatureGate.tsx
|
|
1554
|
+
// packages/ui/FeatureGate.tsx
|
|
1553
1555
|
function FeatureGate({ featureKey, children, enabled = false, behavior = "lock", planBadge = "Pro", upgradeMessage, upgradeUrl = "/settings", lockTooltip }) {
|
|
1554
1556
|
const strings = useUiStrings();
|
|
1555
1557
|
const tooltip = lockTooltip ?? strings.featureUnavailable;
|
|
@@ -1623,8 +1625,7 @@ function UpgradeGate({ planBadge, upgradeMessage, upgradeUrl, children }) {
|
|
|
1623
1625
|
]
|
|
1624
1626
|
});
|
|
1625
1627
|
}
|
|
1626
|
-
|
|
1627
|
-
//#region packages/ui/Skeleton.tsx
|
|
1628
|
+
// packages/ui/Skeleton.tsx
|
|
1628
1629
|
const fmtSize = (v) => v === void 0 ? void 0 : typeof v === "number" ? `${v}px` : v;
|
|
1629
1630
|
const Skeleton = ({ variant = "rect", width, height, lines = 1, className }) => {
|
|
1630
1631
|
const base = [
|
|
@@ -1649,8 +1650,7 @@ const Skeleton = ({ variant = "rect", width, height, lines = 1, className }) =>
|
|
|
1649
1650
|
"aria-hidden": "true"
|
|
1650
1651
|
});
|
|
1651
1652
|
};
|
|
1652
|
-
|
|
1653
|
-
//#region packages/ui/EmptyState.tsx
|
|
1653
|
+
// packages/ui/EmptyState.tsx
|
|
1654
1654
|
const DEFAULT_ICONS = {
|
|
1655
1655
|
default: "folder-open",
|
|
1656
1656
|
danger: "warning-circle",
|
|
@@ -1693,8 +1693,7 @@ const EmptyState = ({ icon, illustration, variant = "default", title, descriptio
|
|
|
1693
1693
|
]
|
|
1694
1694
|
});
|
|
1695
1695
|
};
|
|
1696
|
-
|
|
1697
|
-
//#region packages/ui/Chip.tsx
|
|
1696
|
+
// packages/ui/Chip.tsx
|
|
1698
1697
|
/**
|
|
1699
1698
|
* Pill-shaped filter/tag chip. Stateless — caller controls `active`.
|
|
1700
1699
|
* Use for category filters, tag lists, and multi-select inputs.
|
|
@@ -1721,8 +1720,7 @@ const Chip = ({ label, active = false, count, icon, size = "md", disabled = fals
|
|
|
1721
1720
|
]
|
|
1722
1721
|
});
|
|
1723
1722
|
};
|
|
1724
|
-
|
|
1725
|
-
//#region packages/ui/Toggle.tsx
|
|
1723
|
+
// packages/ui/Toggle.tsx
|
|
1726
1724
|
/**
|
|
1727
1725
|
* Accessible toggle switch. Always controlled — pass `checked` + `onChange`.
|
|
1728
1726
|
* Renders a visually-hidden `<input type="checkbox">` with a custom track.
|
|
@@ -1752,8 +1750,7 @@ const Toggle = ({ checked, onChange, label, size = "md", disabled = false, "aria
|
|
|
1752
1750
|
children: [label && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: label }), input]
|
|
1753
1751
|
});
|
|
1754
1752
|
};
|
|
1755
|
-
|
|
1756
|
-
//#region packages/ui/ContextMenu.tsx
|
|
1753
|
+
// packages/ui/ContextMenu.tsx
|
|
1757
1754
|
const ContextMenu = ({ items, visible = true, trigger, triggerLabel = "Opciones", align = "right", className = "" }) => {
|
|
1758
1755
|
const container = useOverlayContainer();
|
|
1759
1756
|
const triggerRef = (0, react.useRef)(null);
|
|
@@ -1801,8 +1798,7 @@ const ContextMenu = ({ items, visible = true, trigger, triggerLabel = "Opciones"
|
|
|
1801
1798
|
})
|
|
1802
1799
|
});
|
|
1803
1800
|
};
|
|
1804
|
-
|
|
1805
|
-
//#region packages/ui/StatCard.tsx
|
|
1801
|
+
// packages/ui/StatCard.tsx
|
|
1806
1802
|
/**
|
|
1807
1803
|
* General-purpose analytics / dashboard card.
|
|
1808
1804
|
* Replaces the legacy `shared/ui/card-analytics/CardAnalytics` component.
|
|
@@ -1827,8 +1823,7 @@ const StatCard = ({ title, headerExtra, menuVisible = true, menuItems = [{ label
|
|
|
1827
1823
|
children
|
|
1828
1824
|
})]
|
|
1829
1825
|
});
|
|
1830
|
-
|
|
1831
|
-
//#region packages/ui/KpiMetricRow.tsx
|
|
1826
|
+
// packages/ui/KpiMetricRow.tsx
|
|
1832
1827
|
function normalizeIcon$1(icon) {
|
|
1833
1828
|
if (!icon) return void 0;
|
|
1834
1829
|
if (icon.startsWith("ph ")) return icon;
|
|
@@ -1871,8 +1866,7 @@ function KpiMetricRow({ items, className = "", layout = "cards", density = "defa
|
|
|
1871
1866
|
})
|
|
1872
1867
|
});
|
|
1873
1868
|
}
|
|
1874
|
-
|
|
1875
|
-
//#region packages/ui/SegmentedControl.tsx
|
|
1869
|
+
// packages/ui/SegmentedControl.tsx
|
|
1876
1870
|
function SegmentedControl({ options, value, onChange, ariaLabel, className = "", size = "md" }) {
|
|
1877
1871
|
if (options.length === 0) return null;
|
|
1878
1872
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
@@ -1892,8 +1886,7 @@ function SegmentedControl({ options, value, onChange, ariaLabel, className = "",
|
|
|
1892
1886
|
})
|
|
1893
1887
|
});
|
|
1894
1888
|
}
|
|
1895
|
-
|
|
1896
|
-
//#region packages/ui/FilterPanel.tsx
|
|
1889
|
+
// packages/ui/FilterPanel.tsx
|
|
1897
1890
|
function FilterPanel({ category, status, layout = "stacked", density = "default", className = "", testId }) {
|
|
1898
1891
|
const [search, setSearch] = (0, react.useState)("");
|
|
1899
1892
|
const threshold = category.searchThreshold ?? 10;
|
|
@@ -2002,8 +1995,7 @@ function FilterPanel({ category, status, layout = "stacked", density = "default"
|
|
|
2002
1995
|
})]
|
|
2003
1996
|
});
|
|
2004
1997
|
}
|
|
2005
|
-
|
|
2006
|
-
//#region packages/ui/ScopeTabs.tsx
|
|
1998
|
+
// packages/ui/ScopeTabs.tsx
|
|
2007
1999
|
/**
|
|
2008
2000
|
* Pill tabs for scoping a list view (warehouse, branch, period, etc.).
|
|
2009
2001
|
* Hides itself when there is at most one scope option.
|
|
@@ -2032,8 +2024,7 @@ function ScopeTabs({ options, selectedKey, onChange, allLabel = "Todos", ariaLab
|
|
|
2032
2024
|
}, option.key))]
|
|
2033
2025
|
});
|
|
2034
2026
|
}
|
|
2035
|
-
|
|
2036
|
-
//#region packages/ui/OperationCardGrid.tsx
|
|
2027
|
+
// packages/ui/OperationCardGrid.tsx
|
|
2037
2028
|
function normalizeIcon(icon) {
|
|
2038
2029
|
if (icon.startsWith("ph ")) return icon;
|
|
2039
2030
|
if (icon.startsWith("ph-")) return `ph ${icon}`;
|
|
@@ -2088,8 +2079,7 @@ function OperationCardGrid({ title, description, operations, className = "", tes
|
|
|
2088
2079
|
})]
|
|
2089
2080
|
});
|
|
2090
2081
|
}
|
|
2091
|
-
|
|
2092
|
-
//#region packages/ui/HubPanel.tsx
|
|
2082
|
+
// packages/ui/HubPanel.tsx
|
|
2093
2083
|
/**
|
|
2094
2084
|
* Card shell for feature-hub chrome above a CRUD grid (KPIs, scope tabs, filters).
|
|
2095
2085
|
*/
|
|
@@ -2100,8 +2090,7 @@ function HubPanel({ children, variant = "card", className = "", testId }) {
|
|
|
2100
2090
|
children
|
|
2101
2091
|
});
|
|
2102
2092
|
}
|
|
2103
|
-
|
|
2104
|
-
//#region packages/ui/CollapsibleSection.tsx
|
|
2093
|
+
// packages/ui/CollapsibleSection.tsx
|
|
2105
2094
|
/**
|
|
2106
2095
|
* Accessible collapsible section with a labelled header trigger.
|
|
2107
2096
|
*
|
|
@@ -2156,8 +2145,7 @@ const CollapsibleSection = ({ label, icon, open, onToggle, children, trailing, c
|
|
|
2156
2145
|
})]
|
|
2157
2146
|
});
|
|
2158
2147
|
};
|
|
2159
|
-
|
|
2160
|
-
//#region packages/ui/CalendarContent.tsx
|
|
2148
|
+
// packages/ui/CalendarContent.tsx
|
|
2161
2149
|
/** Shared presentation; React Aria owns navigation, focus and range preview. */
|
|
2162
2150
|
function CalendarContent() {
|
|
2163
2151
|
const strings = useUiStrings();
|
|
@@ -2226,8 +2214,7 @@ function CalendarDialog({ id, ariaLabel, children }) {
|
|
|
2226
2214
|
children
|
|
2227
2215
|
});
|
|
2228
2216
|
}
|
|
2229
|
-
|
|
2230
|
-
//#region packages/ui/dateValues.ts
|
|
2217
|
+
// packages/ui/dateValues.ts
|
|
2231
2218
|
const getDateLocale = (locale) => locale || typeof document !== "undefined" && document.documentElement.lang || typeof navigator !== "undefined" && navigator.language || "en-US";
|
|
2232
2219
|
const calendarDate = (value) => {
|
|
2233
2220
|
if (!value || !/^\d{4}-\d{2}-\d{2}$/.test(value)) return null;
|
|
@@ -2282,8 +2269,7 @@ const parseDisplayDate = (text, locale) => {
|
|
|
2282
2269
|
const iso = `${fields.year}-${fields.month?.padStart(2, "0")}-${fields.day?.padStart(2, "0")}`;
|
|
2283
2270
|
return calendarDate(iso) ? iso : null;
|
|
2284
2271
|
};
|
|
2285
|
-
|
|
2286
|
-
//#region packages/ui/DateTextInput.tsx
|
|
2272
|
+
// packages/ui/DateTextInput.tsx
|
|
2287
2273
|
/** Keeps the real input/ref/ID contract used by CRUD forms. */
|
|
2288
2274
|
const DateTextInput = (0, react.forwardRef)(function DateTextInput({ value, locale, min, max, onChange, onOpen, onBlur, onKeyDown, ...props }, ref) {
|
|
2289
2275
|
const [draft, setDraft] = (0, react.useState)(null);
|
|
@@ -2326,8 +2312,7 @@ const DateTextInput = (0, react.forwardRef)(function DateTextInput({ value, loca
|
|
|
2326
2312
|
}
|
|
2327
2313
|
});
|
|
2328
2314
|
});
|
|
2329
|
-
|
|
2330
|
-
//#region packages/ui/useCalendarPopover.ts
|
|
2315
|
+
// packages/ui/useCalendarPopover.ts
|
|
2331
2316
|
/** Bridge focus restoration between React Aria's popup and a parent Base UI modal. */
|
|
2332
2317
|
function useCalendarPopover() {
|
|
2333
2318
|
const container = useOverlayContainer();
|
|
@@ -2368,8 +2353,7 @@ function useCalendarPopover() {
|
|
|
2368
2353
|
}, [container])
|
|
2369
2354
|
};
|
|
2370
2355
|
}
|
|
2371
|
-
|
|
2372
|
-
//#region packages/ui/DatePicker.tsx
|
|
2356
|
+
// packages/ui/DatePicker.tsx
|
|
2373
2357
|
const DatePicker = (0, react.forwardRef)(function DatePicker({ id, name, value, placeholder, disabled = false, readOnly = false, required = false, invalid = false, clearable = true, locale, min, max, className, ariaLabel, onChange, onBlur }, ref) {
|
|
2374
2358
|
const generatedId = (0, react.useId)();
|
|
2375
2359
|
const inputId = id ?? generatedId;
|
|
@@ -2495,8 +2479,7 @@ const DatePicker = (0, react.forwardRef)(function DatePicker({ id, name, value,
|
|
|
2495
2479
|
})
|
|
2496
2480
|
});
|
|
2497
2481
|
});
|
|
2498
|
-
|
|
2499
|
-
//#region packages/ui/DateRangePicker.tsx
|
|
2482
|
+
// packages/ui/DateRangePicker.tsx
|
|
2500
2483
|
function DateRangePicker({ startValue, endValue, placeholder, disabled = false, clearable = true, readOnly = false, required = false, invalid = false, locale, min, max, className, ariaLabel, onChange, onBlur }) {
|
|
2501
2484
|
const { container, groupRef, panelRef, open, setOpen } = useCalendarPopover();
|
|
2502
2485
|
const strings = useUiStrings();
|
|
@@ -2627,8 +2610,7 @@ function DateRangePicker({ startValue, endValue, placeholder, disabled = false,
|
|
|
2627
2610
|
})
|
|
2628
2611
|
});
|
|
2629
2612
|
}
|
|
2630
|
-
|
|
2631
|
-
//#region packages/ui/Popover.tsx
|
|
2613
|
+
// packages/ui/Popover.tsx
|
|
2632
2614
|
const Popover = ({ trigger, panel, align = "end", ariaLabel, className }) => {
|
|
2633
2615
|
const [open, setOpen] = (0, react.useState)(false);
|
|
2634
2616
|
const triggerRef = (0, react.useRef)(null);
|
|
@@ -2688,8 +2670,7 @@ const Popover = ({ trigger, panel, align = "end", ariaLabel, className }) => {
|
|
|
2688
2670
|
})
|
|
2689
2671
|
});
|
|
2690
2672
|
};
|
|
2691
|
-
|
|
2692
|
-
//#region packages/ui/useFloatingPanel.ts
|
|
2673
|
+
// packages/ui/useFloatingPanel.ts
|
|
2693
2674
|
/** Style applied to an anchored panel before its first position is computed. */
|
|
2694
2675
|
const HIDDEN_PANEL_STYLE = {
|
|
2695
2676
|
position: "fixed",
|
|
@@ -2790,8 +2771,7 @@ function useFloatingPanel(options = {}) {
|
|
|
2790
2771
|
panelStyle
|
|
2791
2772
|
};
|
|
2792
2773
|
}
|
|
2793
|
-
|
|
2794
|
-
//#region packages/ui/Drawer.tsx
|
|
2774
|
+
// packages/ui/Drawer.tsx
|
|
2795
2775
|
const formatWidth = (value) => {
|
|
2796
2776
|
if (value === void 0) return void 0;
|
|
2797
2777
|
return typeof value === "number" ? `${value}px` : value;
|
|
@@ -2844,8 +2824,7 @@ const Drawer = ({ isOpen, busy = false, onClose, title, width, side = "right", s
|
|
|
2844
2824
|
]
|
|
2845
2825
|
});
|
|
2846
2826
|
};
|
|
2847
|
-
|
|
2848
|
-
//#region packages/ui/Timeline.tsx
|
|
2827
|
+
// packages/ui/Timeline.tsx
|
|
2849
2828
|
const TimelineVariantContext = (0, react.createContext)("stepper");
|
|
2850
2829
|
function useTimelineVariant() {
|
|
2851
2830
|
return (0, react.useContext)(TimelineVariantContext);
|
|
@@ -2941,8 +2920,7 @@ function Timeline({ variant = "stepper", orientation = "vertical", title, descri
|
|
|
2941
2920
|
})
|
|
2942
2921
|
});
|
|
2943
2922
|
}
|
|
2944
|
-
|
|
2945
|
-
//#region packages/ui/Page.tsx
|
|
2923
|
+
// packages/ui/Page.tsx
|
|
2946
2924
|
function Page({ children, fill, wide, narrow, gap = 5, className, ...props }) {
|
|
2947
2925
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
2948
2926
|
className: joinClasses("nb-page", fill && "nb-page--fill", wide && "nb-page--wide", narrow && "nb-page--narrow", gapClass("nb-page", gap), className),
|
|
@@ -2950,8 +2928,7 @@ function Page({ children, fill, wide, narrow, gap = 5, className, ...props }) {
|
|
|
2950
2928
|
children
|
|
2951
2929
|
});
|
|
2952
2930
|
}
|
|
2953
|
-
|
|
2954
|
-
//#region packages/ui/PageHeader.tsx
|
|
2931
|
+
// packages/ui/PageHeader.tsx
|
|
2955
2932
|
function PageHeader({ title, subtitle, metadata, breadcrumb, breadcrumbSlot, badge, actions, className }) {
|
|
2956
2933
|
const breadcrumbNode = breadcrumbSlot ?? (breadcrumb ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("a", {
|
|
2957
2934
|
href: breadcrumb.href,
|
|
@@ -2990,8 +2967,7 @@ function PageHeader({ title, subtitle, metadata, breadcrumb, breadcrumbSlot, bad
|
|
|
2990
2967
|
})]
|
|
2991
2968
|
});
|
|
2992
2969
|
}
|
|
2993
|
-
|
|
2994
|
-
//#region packages/ui/Stack.tsx
|
|
2970
|
+
// packages/ui/Stack.tsx
|
|
2995
2971
|
function Stack({ children, gap = 4, align, justify, fill, className, ...props }) {
|
|
2996
2972
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
2997
2973
|
className: joinClasses("nb-stack", gapClass("nb-stack", gap), align && `nb-stack--align-${align}`, justify && `nb-stack--justify-${justify}`, fill && "nb-stack--fill", className),
|
|
@@ -2999,8 +2975,7 @@ function Stack({ children, gap = 4, align, justify, fill, className, ...props })
|
|
|
2999
2975
|
children
|
|
3000
2976
|
});
|
|
3001
2977
|
}
|
|
3002
|
-
|
|
3003
|
-
//#region packages/ui/Row.tsx
|
|
2978
|
+
// packages/ui/Row.tsx
|
|
3004
2979
|
function Row({ children, gap = 2, align, justify, wrap, fill, className, ...props }) {
|
|
3005
2980
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
3006
2981
|
className: joinClasses("nb-row", gapClass("nb-row", gap), align && `nb-row--align-${align}`, justify && `nb-row--justify-${justify}`, wrap && "nb-row--wrap", fill && "nb-row--fill", className),
|
|
@@ -3008,8 +2983,7 @@ function Row({ children, gap = 2, align, justify, wrap, fill, className, ...prop
|
|
|
3008
2983
|
children
|
|
3009
2984
|
});
|
|
3010
2985
|
}
|
|
3011
|
-
|
|
3012
|
-
//#region packages/ui/Cluster.tsx
|
|
2986
|
+
// packages/ui/Cluster.tsx
|
|
3013
2987
|
/** Inline flex row that wraps — ideal for button groups and filter actions. */
|
|
3014
2988
|
function Cluster({ children, gap = 2, className, ...props }) {
|
|
3015
2989
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
@@ -3018,8 +2992,7 @@ function Cluster({ children, gap = 2, className, ...props }) {
|
|
|
3018
2992
|
children
|
|
3019
2993
|
});
|
|
3020
2994
|
}
|
|
3021
|
-
|
|
3022
|
-
//#region packages/ui/Grid.tsx
|
|
2995
|
+
// packages/ui/Grid.tsx
|
|
3023
2996
|
function Grid({ children, cols = 12, gap = 4, minColWidth, fill, className, style, ...props }) {
|
|
3024
2997
|
const gridStyle = {
|
|
3025
2998
|
...style,
|
|
@@ -3033,8 +3006,7 @@ function Grid({ children, cols = 12, gap = 4, minColWidth, fill, className, styl
|
|
|
3033
3006
|
children
|
|
3034
3007
|
});
|
|
3035
3008
|
}
|
|
3036
|
-
|
|
3037
|
-
//#region packages/ui/Col.tsx
|
|
3009
|
+
// packages/ui/Col.tsx
|
|
3038
3010
|
function Col({ children, span, spanSm, spanMd, spanLg, fullWidth, className, ...props }) {
|
|
3039
3011
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
3040
3012
|
className: joinClasses(...colSpanClasses(span, spanSm, spanMd, spanLg), fullWidth && "nb-span-full", className),
|
|
@@ -3042,8 +3014,7 @@ function Col({ children, span, spanSm, spanMd, spanLg, fullWidth, className, ...
|
|
|
3042
3014
|
children
|
|
3043
3015
|
});
|
|
3044
3016
|
}
|
|
3045
|
-
|
|
3046
|
-
//#region packages/ui/Section.tsx
|
|
3017
|
+
// packages/ui/Section.tsx
|
|
3047
3018
|
function Section({ title, children, className, variant = "label" }) {
|
|
3048
3019
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("section", {
|
|
3049
3020
|
className: joinClasses("nb-section", variant === "panel" && "nb-section--panel", className),
|
|
@@ -3053,8 +3024,7 @@ function Section({ title, children, className, variant = "label" }) {
|
|
|
3053
3024
|
}), children]
|
|
3054
3025
|
});
|
|
3055
3026
|
}
|
|
3056
|
-
|
|
3057
|
-
//#region packages/ui/FormLayout.tsx
|
|
3027
|
+
// packages/ui/FormLayout.tsx
|
|
3058
3028
|
function FormLayout({ children, variant = "stack", minColWidth, className, style, ...props }) {
|
|
3059
3029
|
const formStyle = {
|
|
3060
3030
|
...style,
|
|
@@ -3067,16 +3037,14 @@ function FormLayout({ children, variant = "stack", minColWidth, className, style
|
|
|
3067
3037
|
children
|
|
3068
3038
|
});
|
|
3069
3039
|
}
|
|
3070
|
-
|
|
3071
|
-
//#region packages/ui/FormActions.tsx
|
|
3040
|
+
// packages/ui/FormActions.tsx
|
|
3072
3041
|
function FormActions({ children, className }) {
|
|
3073
3042
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
3074
3043
|
className: joinClasses("nb-form-actions", className),
|
|
3075
3044
|
children
|
|
3076
3045
|
});
|
|
3077
3046
|
}
|
|
3078
|
-
|
|
3079
|
-
//#region packages/ui/Alert.tsx
|
|
3047
|
+
// packages/ui/Alert.tsx
|
|
3080
3048
|
const ICONS = {
|
|
3081
3049
|
danger: "ph-warning-circle",
|
|
3082
3050
|
warning: "ph-warning",
|
|
@@ -3092,8 +3060,7 @@ function Alert({ tone = "info", children, className }) {
|
|
|
3092
3060
|
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children })]
|
|
3093
3061
|
});
|
|
3094
3062
|
}
|
|
3095
|
-
|
|
3096
|
-
//#region packages/ui/DescriptionList.tsx
|
|
3063
|
+
// packages/ui/DescriptionList.tsx
|
|
3097
3064
|
function DescriptionList({ items, className }) {
|
|
3098
3065
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("dl", {
|
|
3099
3066
|
className: joinClasses("nb-description-list", className),
|
|
@@ -3103,16 +3070,14 @@ function DescriptionList({ items, className }) {
|
|
|
3103
3070
|
}, item.term))
|
|
3104
3071
|
});
|
|
3105
3072
|
}
|
|
3106
|
-
|
|
3107
|
-
//#region packages/ui/Code.tsx
|
|
3073
|
+
// packages/ui/Code.tsx
|
|
3108
3074
|
function Code({ children, className }) {
|
|
3109
3075
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("code", {
|
|
3110
3076
|
className: joinClasses("nb-code", className),
|
|
3111
3077
|
children
|
|
3112
3078
|
});
|
|
3113
3079
|
}
|
|
3114
|
-
|
|
3115
|
-
//#region packages/ui/Text.tsx
|
|
3080
|
+
// packages/ui/Text.tsx
|
|
3116
3081
|
function Text({ children, tone = "default", as: Tag = "span", className, ...props }) {
|
|
3117
3082
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Tag, {
|
|
3118
3083
|
className: joinClasses(tone === "muted" && "nb-text-muted", className),
|
|
@@ -3120,8 +3085,7 @@ function Text({ children, tone = "default", as: Tag = "span", className, ...prop
|
|
|
3120
3085
|
children
|
|
3121
3086
|
});
|
|
3122
3087
|
}
|
|
3123
|
-
|
|
3124
|
-
//#region packages/ui/Pagination.tsx
|
|
3088
|
+
// packages/ui/Pagination.tsx
|
|
3125
3089
|
function Pagination({ page, totalPages, onPageChange, ariaLabel, maxVisible = 7, className }) {
|
|
3126
3090
|
const strings = useUiStrings();
|
|
3127
3091
|
if (totalPages <= 1) return null;
|
|
@@ -3161,8 +3125,7 @@ function Pagination({ page, totalPages, onPageChange, ariaLabel, maxVisible = 7,
|
|
|
3161
3125
|
]
|
|
3162
3126
|
});
|
|
3163
3127
|
}
|
|
3164
|
-
|
|
3165
|
-
//#region packages/ui/RowActions.tsx
|
|
3128
|
+
// packages/ui/RowActions.tsx
|
|
3166
3129
|
/** Context menu preset for table row overflow actions. */
|
|
3167
3130
|
function RowActions({ items, triggerLabel, align = "right", className }) {
|
|
3168
3131
|
const strings = useUiStrings();
|
|
@@ -3175,8 +3138,7 @@ function RowActions({ items, triggerLabel, align = "right", className }) {
|
|
|
3175
3138
|
visible: true
|
|
3176
3139
|
});
|
|
3177
3140
|
}
|
|
3178
|
-
|
|
3179
|
-
//#region packages/ui/DataTable.tsx
|
|
3141
|
+
// packages/ui/DataTable.tsx
|
|
3180
3142
|
function alignClass(align) {
|
|
3181
3143
|
if (align === "right") return "nb-data-table__cell--num";
|
|
3182
3144
|
if (align === "center") return "nb-data-table__cell--center";
|
|
@@ -3220,8 +3182,7 @@ function DataTable({ columns, rows, getRowKey, emptyMessage, fill, variant = "de
|
|
|
3220
3182
|
})
|
|
3221
3183
|
}), pagination && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Pagination, { ...pagination })] });
|
|
3222
3184
|
}
|
|
3223
|
-
|
|
3224
|
-
//#region packages/ui/useConfirm.tsx
|
|
3185
|
+
// packages/ui/useConfirm.tsx
|
|
3225
3186
|
function useConfirm() {
|
|
3226
3187
|
const strings = useUiStrings();
|
|
3227
3188
|
const [pending, setPending] = (0, react.useState)(null);
|
|
@@ -3248,8 +3209,7 @@ function useConfirm() {
|
|
|
3248
3209
|
ConfirmHost
|
|
3249
3210
|
};
|
|
3250
3211
|
}
|
|
3251
|
-
|
|
3252
|
-
//#region packages/ui/Checkbox.tsx
|
|
3212
|
+
// packages/ui/Checkbox.tsx
|
|
3253
3213
|
/** Native checkbox, including the mixed state used by bulk selection. */
|
|
3254
3214
|
const Checkbox = (0, react.forwardRef)(function Checkbox({ label, indeterminate = false, invalid = false, id, className, ...props }, ref) {
|
|
3255
3215
|
const generatedId = (0, react.useId)();
|
|
@@ -3272,8 +3232,7 @@ const Checkbox = (0, react.forwardRef)(function Checkbox({ label, indeterminate
|
|
|
3272
3232
|
}), label && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: label })]
|
|
3273
3233
|
});
|
|
3274
3234
|
});
|
|
3275
|
-
|
|
3276
|
-
//#region packages/ui/RadioGroup.tsx
|
|
3235
|
+
// packages/ui/RadioGroup.tsx
|
|
3277
3236
|
/** Native radios share a name for browser keyboard navigation and form submission. */
|
|
3278
3237
|
function RadioGroup({ label, name, value, options, onChange, orientation = "vertical", required, invalid = false, disabled, className, ...props }) {
|
|
3279
3238
|
const generatedName = (0, react.useId)();
|
|
@@ -3299,8 +3258,7 @@ function RadioGroup({ label, name, value, options, onChange, orientation = "vert
|
|
|
3299
3258
|
})]
|
|
3300
3259
|
});
|
|
3301
3260
|
}
|
|
3302
|
-
|
|
3303
|
-
//#region packages/ui/Tabs.tsx
|
|
3261
|
+
// packages/ui/Tabs.tsx
|
|
3304
3262
|
function Tabs({ items, value, onChange, "aria-label": ariaLabel, orientation = "horizontal", activationMode = "automatic", keepMounted = false, className }) {
|
|
3305
3263
|
const id = (0, react.useId)();
|
|
3306
3264
|
const listRef = (0, react.useRef)(null);
|
|
@@ -3356,8 +3314,7 @@ function Tabs({ items, value, onChange, "aria-label": ariaLabel, orientation = "
|
|
|
3356
3314
|
}, item.value))]
|
|
3357
3315
|
});
|
|
3358
3316
|
}
|
|
3359
|
-
|
|
3360
|
-
//#region packages/ui/Spinner.tsx
|
|
3317
|
+
// packages/ui/Spinner.tsx
|
|
3361
3318
|
function Spinner({ label, size = "md", className, ...props }) {
|
|
3362
3319
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
3363
3320
|
...props,
|
|
@@ -3367,8 +3324,7 @@ function Spinner({ label, size = "md", className, ...props }) {
|
|
|
3367
3324
|
"aria-hidden": label ? void 0 : true
|
|
3368
3325
|
});
|
|
3369
3326
|
}
|
|
3370
|
-
|
|
3371
|
-
//#region packages/ui/Progress.tsx
|
|
3327
|
+
// packages/ui/Progress.tsx
|
|
3372
3328
|
/** Omit value for indeterminate progress; max defaults to 100. */
|
|
3373
3329
|
function Progress({ label, id, max = 100, className, ...props }) {
|
|
3374
3330
|
const generatedId = (0, react.useId)();
|
|
@@ -3386,8 +3342,7 @@ function Progress({ label, id, max = 100, className, ...props }) {
|
|
|
3386
3342
|
})]
|
|
3387
3343
|
});
|
|
3388
3344
|
}
|
|
3389
|
-
|
|
3390
|
-
//#region packages/ui/Tooltip.tsx
|
|
3345
|
+
// packages/ui/Tooltip.tsx
|
|
3391
3346
|
const TooltipProvider = _base_ui_react_tooltip.Tooltip.Provider;
|
|
3392
3347
|
/** Uses the existing child as the trigger without adding a nested button. */
|
|
3393
3348
|
function Tooltip({ children, content, side = "top", delay, disabled, className }) {
|
|
@@ -3424,8 +3379,7 @@ function Tooltip({ children, content, side = "top", delay, disabled, className }
|
|
|
3424
3379
|
})]
|
|
3425
3380
|
});
|
|
3426
3381
|
}
|
|
3427
|
-
|
|
3428
|
-
//#region packages/ui/TimePicker.tsx
|
|
3382
|
+
// packages/ui/TimePicker.tsx
|
|
3429
3383
|
const timeValue = (value) => {
|
|
3430
3384
|
if (!value) return null;
|
|
3431
3385
|
try {
|
|
@@ -3467,8 +3421,7 @@ const TimePicker = (0, react.forwardRef)(function TimePicker({ id, name, value,
|
|
|
3467
3421
|
})
|
|
3468
3422
|
});
|
|
3469
3423
|
});
|
|
3470
|
-
|
|
3471
|
-
//#region packages/ui/DetailLayout.tsx
|
|
3424
|
+
// packages/ui/DetailLayout.tsx
|
|
3472
3425
|
/** Responsive main/aside composition for record detail pages. */
|
|
3473
3426
|
function DetailLayout({ children, aside, asideLabel, className }) {
|
|
3474
3427
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
@@ -3483,7 +3436,577 @@ function DetailLayout({ children, aside, asideLabel, className }) {
|
|
|
3483
3436
|
})]
|
|
3484
3437
|
});
|
|
3485
3438
|
}
|
|
3486
|
-
|
|
3439
|
+
// packages/ui/treeListModel.ts
|
|
3440
|
+
/**
|
|
3441
|
+
* Normalizes either nested records or a flat parentId collection into a
|
|
3442
|
+
* deterministic tree. A record may not be supplied through both relationships.
|
|
3443
|
+
*/
|
|
3444
|
+
function buildTreeListModel(items, options) {
|
|
3445
|
+
const { getId, getParentId, getChildren } = options;
|
|
3446
|
+
const records = /* @__PURE__ */ new Map();
|
|
3447
|
+
const nestedChildren = /* @__PURE__ */ new Map();
|
|
3448
|
+
const visitNested = (item, ancestors) => {
|
|
3449
|
+
const id = getId(item);
|
|
3450
|
+
if (records.has(id)) throw new Error(`TreeList contains duplicate id "${id}".`);
|
|
3451
|
+
if (ancestors.has(id)) throw new Error(`TreeList contains a cycle at id "${id}".`);
|
|
3452
|
+
records.set(id, item);
|
|
3453
|
+
const children = getChildren?.(item) ?? [];
|
|
3454
|
+
const nextAncestors = new Set(ancestors).add(id);
|
|
3455
|
+
const childIds = [];
|
|
3456
|
+
for (const child of children) {
|
|
3457
|
+
const childId = getId(child);
|
|
3458
|
+
childIds.push(childId);
|
|
3459
|
+
visitNested(child, nextAncestors);
|
|
3460
|
+
}
|
|
3461
|
+
nestedChildren.set(id, childIds);
|
|
3462
|
+
};
|
|
3463
|
+
for (const item of items) visitNested(item, /* @__PURE__ */ new Set());
|
|
3464
|
+
const nestedIds = /* @__PURE__ */ new Set();
|
|
3465
|
+
for (const ids of nestedChildren.values()) for (const id of ids) nestedIds.add(id);
|
|
3466
|
+
const parentById = /* @__PURE__ */ new Map();
|
|
3467
|
+
for (const [id, item] of records) {
|
|
3468
|
+
const parentId = getParentId?.(item);
|
|
3469
|
+
if (parentId != null && nestedIds.has(id)) throw new Error(`TreeList record "${id}" has both nested and parentId relationships.`);
|
|
3470
|
+
parentById.set(id, parentId == null ? null : parentId);
|
|
3471
|
+
}
|
|
3472
|
+
for (const [parentId, childIds] of nestedChildren) for (const childId of childIds) parentById.set(childId, parentId);
|
|
3473
|
+
const childrenByParent = /* @__PURE__ */ new Map();
|
|
3474
|
+
for (const [id, parentId] of parentById) {
|
|
3475
|
+
if (parentId != null && !records.has(parentId)) throw new Error(`TreeList record "${id}" refers to missing parent "${parentId}".`);
|
|
3476
|
+
const siblings = childrenByParent.get(parentId) ?? [];
|
|
3477
|
+
siblings.push(id);
|
|
3478
|
+
childrenByParent.set(parentId, siblings);
|
|
3479
|
+
}
|
|
3480
|
+
const visiting = /* @__PURE__ */ new Set();
|
|
3481
|
+
const built = /* @__PURE__ */ new Map();
|
|
3482
|
+
const makeNode = (id, depth) => {
|
|
3483
|
+
if (visiting.has(id)) throw new Error(`TreeList contains a parentId cycle at id "${id}".`);
|
|
3484
|
+
const existing = built.get(id);
|
|
3485
|
+
if (existing) return existing;
|
|
3486
|
+
visiting.add(id);
|
|
3487
|
+
const node = {
|
|
3488
|
+
id,
|
|
3489
|
+
item: records.get(id),
|
|
3490
|
+
depth,
|
|
3491
|
+
children: (childrenByParent.get(id) ?? []).map((childId) => makeNode(childId, depth + 1))
|
|
3492
|
+
};
|
|
3493
|
+
visiting.delete(id);
|
|
3494
|
+
built.set(id, node);
|
|
3495
|
+
return node;
|
|
3496
|
+
};
|
|
3497
|
+
const result = (childrenByParent.get(null) ?? []).map((id) => makeNode(id, 0));
|
|
3498
|
+
if (built.size !== records.size) {
|
|
3499
|
+
const orphanedCycle = [...records.keys()].find((id) => !built.has(id));
|
|
3500
|
+
throw new Error(`TreeList contains an unreachable parentId cycle at id "${orphanedCycle}".`);
|
|
3501
|
+
}
|
|
3502
|
+
return result;
|
|
3503
|
+
}
|
|
3504
|
+
function flattenVisibleTree(roots, expandedIds) {
|
|
3505
|
+
const visible = [];
|
|
3506
|
+
const visit = (node) => {
|
|
3507
|
+
visible.push(node);
|
|
3508
|
+
if (expandedIds.has(node.id)) node.children.forEach(visit);
|
|
3509
|
+
};
|
|
3510
|
+
roots.forEach(visit);
|
|
3511
|
+
return visible;
|
|
3512
|
+
}
|
|
3513
|
+
function getDescendantIds(node) {
|
|
3514
|
+
const ids = [];
|
|
3515
|
+
const visit = (current) => {
|
|
3516
|
+
for (const child of current.children) {
|
|
3517
|
+
ids.push(child.id);
|
|
3518
|
+
visit(child);
|
|
3519
|
+
}
|
|
3520
|
+
};
|
|
3521
|
+
visit(node);
|
|
3522
|
+
return ids;
|
|
3523
|
+
}
|
|
3524
|
+
// packages/ui/TreeList.tsx
|
|
3525
|
+
function itemValue(column, item) {
|
|
3526
|
+
if (column.value) return column.value(item);
|
|
3527
|
+
return item[column.id];
|
|
3528
|
+
}
|
|
3529
|
+
function compareValues(left, right) {
|
|
3530
|
+
if (left == null) return right == null ? 0 : -1;
|
|
3531
|
+
if (right == null) return 1;
|
|
3532
|
+
if (typeof left === "number" && typeof right === "number") return left - right;
|
|
3533
|
+
return String(left).localeCompare(String(right), void 0, {
|
|
3534
|
+
numeric: true,
|
|
3535
|
+
sensitivity: "base"
|
|
3536
|
+
});
|
|
3537
|
+
}
|
|
3538
|
+
function filterTree(nodes, query, columns) {
|
|
3539
|
+
if (!query) return [...nodes];
|
|
3540
|
+
const normalizedQuery = query.toLocaleLowerCase();
|
|
3541
|
+
const result = [];
|
|
3542
|
+
for (const node of nodes) {
|
|
3543
|
+
const children = filterTree(node.children, query, columns);
|
|
3544
|
+
if (columns.some((column) => String(itemValue(column, node.item) ?? "").toLocaleLowerCase().includes(normalizedQuery)) || children.length > 0) result.push({
|
|
3545
|
+
...node,
|
|
3546
|
+
children
|
|
3547
|
+
});
|
|
3548
|
+
}
|
|
3549
|
+
return result;
|
|
3550
|
+
}
|
|
3551
|
+
function sortTree(nodes, column, direction) {
|
|
3552
|
+
const result = nodes.map((node) => ({
|
|
3553
|
+
...node,
|
|
3554
|
+
children: sortTree(node.children, column, direction)
|
|
3555
|
+
}));
|
|
3556
|
+
if (!column || !direction) return result;
|
|
3557
|
+
const multiplier = direction === "asc" ? 1 : -1;
|
|
3558
|
+
return result.sort((left, right) => multiplier * compareValues(itemValue(column, left.item), itemValue(column, right.item)));
|
|
3559
|
+
}
|
|
3560
|
+
function TreeList({ items, columns, getId, getParentId, getChildren, hasChildren, loadChildren, withParent, expandedIds: controlledExpandedIds, defaultExpandedIds = /* @__PURE__ */ new Set(), onExpandedIdsChange, selectionMode = "none", selectedIds: controlledSelectedIds, defaultSelectedIds = /* @__PURE__ */ new Set(), onSelectedIdsChange, onSelectedItemsChange, selectDescendants = true, rowActions, onRowActivate, onMove, onEdit, editable, filter: controlledFilter, onFilterChange, filterable = true, loading = false, emptyState, error, ariaLabel, className, density = "comfortable", testId }) {
|
|
3561
|
+
const strings = useUiStrings();
|
|
3562
|
+
const [localItems, setLocalItems] = (0, react.useState)(items);
|
|
3563
|
+
const [localExpandedIds, setLocalExpandedIds] = (0, react.useState)(defaultExpandedIds);
|
|
3564
|
+
const [localSelectedIds, setLocalSelectedIds] = (0, react.useState)(defaultSelectedIds);
|
|
3565
|
+
const [localFilter, setLocalFilter] = (0, react.useState)("");
|
|
3566
|
+
const [sort, setSort] = (0, react.useState)(null);
|
|
3567
|
+
const [editingCell, setEditingCell] = (0, react.useState)(null);
|
|
3568
|
+
const [editValue, setEditValue] = (0, react.useState)("");
|
|
3569
|
+
const [moveError, setMoveError] = (0, react.useState)(false);
|
|
3570
|
+
const [loadingIds, setLoadingIds] = (0, react.useState)(() => /* @__PURE__ */ new Set());
|
|
3571
|
+
const [loadErrors, setLoadErrors] = (0, react.useState)(() => /* @__PURE__ */ new Map());
|
|
3572
|
+
const [editErrors, setEditErrors] = (0, react.useState)(() => /* @__PURE__ */ new Map());
|
|
3573
|
+
const controllers = (0, react.useRef)(/* @__PURE__ */ new Map());
|
|
3574
|
+
const rows = (0, react.useRef)(/* @__PURE__ */ new Map());
|
|
3575
|
+
const filter = controlledFilter ?? localFilter;
|
|
3576
|
+
const expandedIds = controlledExpandedIds ?? localExpandedIds;
|
|
3577
|
+
const selectedIds = controlledSelectedIds ?? localSelectedIds;
|
|
3578
|
+
react.default.useEffect(() => setLocalItems(items), [items]);
|
|
3579
|
+
react.default.useEffect(() => () => {
|
|
3580
|
+
controllers.current.forEach((controller) => controller.abort());
|
|
3581
|
+
controllers.current.clear();
|
|
3582
|
+
}, []);
|
|
3583
|
+
const modelOptions = (0, react.useMemo)(() => ({
|
|
3584
|
+
getId,
|
|
3585
|
+
getParentId,
|
|
3586
|
+
getChildren
|
|
3587
|
+
}), [
|
|
3588
|
+
getChildren,
|
|
3589
|
+
getId,
|
|
3590
|
+
getParentId
|
|
3591
|
+
]);
|
|
3592
|
+
const tree = (0, react.useMemo)(() => buildTreeListModel(localItems, modelOptions), [localItems, modelOptions]);
|
|
3593
|
+
const filteredTree = (0, react.useMemo)(() => filterTree(tree, filter.trim(), columns), [
|
|
3594
|
+
columns,
|
|
3595
|
+
filter,
|
|
3596
|
+
tree
|
|
3597
|
+
]);
|
|
3598
|
+
const sortColumn = sort ? columns.find((column) => column.id === sort.columnId) : void 0;
|
|
3599
|
+
const sortedTree = (0, react.useMemo)(() => sortTree(filteredTree, sortColumn, sort?.direction), [
|
|
3600
|
+
filteredTree,
|
|
3601
|
+
sort?.direction,
|
|
3602
|
+
sortColumn
|
|
3603
|
+
]);
|
|
3604
|
+
const filterExpandedIds = (0, react.useMemo)(() => {
|
|
3605
|
+
const ids = /* @__PURE__ */ new Set();
|
|
3606
|
+
const visit = (node) => {
|
|
3607
|
+
if (node.children.length > 0) ids.add(node.id);
|
|
3608
|
+
node.children.forEach(visit);
|
|
3609
|
+
};
|
|
3610
|
+
sortedTree.forEach(visit);
|
|
3611
|
+
return ids;
|
|
3612
|
+
}, [sortedTree]);
|
|
3613
|
+
const visibleNodes = (0, react.useMemo)(() => flattenVisibleTree(sortedTree, filter.trim() ? filterExpandedIds : expandedIds), [
|
|
3614
|
+
expandedIds,
|
|
3615
|
+
filter,
|
|
3616
|
+
filterExpandedIds,
|
|
3617
|
+
sortedTree
|
|
3618
|
+
]);
|
|
3619
|
+
const effectiveExpandedIds = filter.trim() ? filterExpandedIds : expandedIds;
|
|
3620
|
+
const nodeById = (0, react.useMemo)(() => {
|
|
3621
|
+
const result = /* @__PURE__ */ new Map();
|
|
3622
|
+
const visit = (node) => {
|
|
3623
|
+
result.set(node.id, node);
|
|
3624
|
+
node.children.forEach(visit);
|
|
3625
|
+
};
|
|
3626
|
+
tree.forEach(visit);
|
|
3627
|
+
return result;
|
|
3628
|
+
}, [tree]);
|
|
3629
|
+
const updateExpanded = (0, react.useCallback)((next) => {
|
|
3630
|
+
if (controlledExpandedIds === void 0) setLocalExpandedIds(next);
|
|
3631
|
+
onExpandedIdsChange?.(next);
|
|
3632
|
+
}, [controlledExpandedIds, onExpandedIdsChange]);
|
|
3633
|
+
const updateSelected = (0, react.useCallback)((next) => {
|
|
3634
|
+
if (controlledSelectedIds === void 0) setLocalSelectedIds(next);
|
|
3635
|
+
onSelectedIdsChange?.(next);
|
|
3636
|
+
if (onSelectedItemsChange) onSelectedItemsChange([...next].flatMap((id) => {
|
|
3637
|
+
const node = nodeById.get(id);
|
|
3638
|
+
return node ? [node.item] : [];
|
|
3639
|
+
}));
|
|
3640
|
+
}, [
|
|
3641
|
+
controlledSelectedIds,
|
|
3642
|
+
nodeById,
|
|
3643
|
+
onSelectedIdsChange,
|
|
3644
|
+
onSelectedItemsChange
|
|
3645
|
+
]);
|
|
3646
|
+
const updateFilter = (value) => {
|
|
3647
|
+
if (controlledFilter === void 0) setLocalFilter(value);
|
|
3648
|
+
onFilterChange?.(value);
|
|
3649
|
+
};
|
|
3650
|
+
const expand = (0, react.useCallback)(async (node) => {
|
|
3651
|
+
const next = new Set(expandedIds);
|
|
3652
|
+
if (next.has(node.id) && !loadErrors.has(node.id)) {
|
|
3653
|
+
controllers.current.get(node.id)?.abort();
|
|
3654
|
+
next.delete(node.id);
|
|
3655
|
+
updateExpanded(next);
|
|
3656
|
+
return;
|
|
3657
|
+
}
|
|
3658
|
+
next.add(node.id);
|
|
3659
|
+
updateExpanded(next);
|
|
3660
|
+
if (!loadChildren || (hasChildren ? !hasChildren(node.item) : false) || node.children.length > 0) return;
|
|
3661
|
+
const controller = new AbortController();
|
|
3662
|
+
controllers.current.get(node.id)?.abort();
|
|
3663
|
+
controllers.current.set(node.id, controller);
|
|
3664
|
+
setLoadingIds((current) => new Set(current).add(node.id));
|
|
3665
|
+
setLoadErrors((current) => {
|
|
3666
|
+
const nextErrors = new Map(current);
|
|
3667
|
+
nextErrors.delete(node.id);
|
|
3668
|
+
return nextErrors;
|
|
3669
|
+
});
|
|
3670
|
+
try {
|
|
3671
|
+
const children = await loadChildren(node.item, { signal: controller.signal });
|
|
3672
|
+
if (controller.signal.aborted) return;
|
|
3673
|
+
const normalized = withParent ? children.map((child) => withParent(child, node.item)) : children;
|
|
3674
|
+
setLocalItems((current) => [...current, ...normalized]);
|
|
3675
|
+
} catch (cause) {
|
|
3676
|
+
if (!controller.signal.aborted) setLoadErrors((current) => new Map(current).set(node.id, cause));
|
|
3677
|
+
} finally {
|
|
3678
|
+
if (controllers.current.get(node.id) === controller) controllers.current.delete(node.id);
|
|
3679
|
+
setLoadingIds((current) => {
|
|
3680
|
+
const nextLoading = new Set(current);
|
|
3681
|
+
nextLoading.delete(node.id);
|
|
3682
|
+
return nextLoading;
|
|
3683
|
+
});
|
|
3684
|
+
}
|
|
3685
|
+
}, [
|
|
3686
|
+
expandedIds,
|
|
3687
|
+
hasChildren,
|
|
3688
|
+
loadChildren,
|
|
3689
|
+
loadErrors,
|
|
3690
|
+
updateExpanded,
|
|
3691
|
+
withParent
|
|
3692
|
+
]);
|
|
3693
|
+
const toggleSelected = (node) => {
|
|
3694
|
+
const next = new Set(selectionMode === "single" ? [] : selectedIds);
|
|
3695
|
+
if (selectedIds.has(node.id)) next.delete(node.id);
|
|
3696
|
+
else next.add(node.id);
|
|
3697
|
+
if (selectionMode === "multiple" && selectDescendants) for (const id of getDescendantIds(node)) if (selectedIds.has(node.id)) next.delete(id);
|
|
3698
|
+
else next.add(id);
|
|
3699
|
+
updateSelected(next);
|
|
3700
|
+
};
|
|
3701
|
+
const parentOf = (targetId) => {
|
|
3702
|
+
const find = (nodes) => {
|
|
3703
|
+
for (const node of nodes) {
|
|
3704
|
+
if (node.children.some((child) => child.id === targetId)) return node;
|
|
3705
|
+
const found = find(node.children);
|
|
3706
|
+
if (found) return found;
|
|
3707
|
+
}
|
|
3708
|
+
return null;
|
|
3709
|
+
};
|
|
3710
|
+
return find(tree);
|
|
3711
|
+
};
|
|
3712
|
+
const siblingsOf = (parent) => parent ? parent.children : tree;
|
|
3713
|
+
const moveRow = (item, target, position = "inside") => {
|
|
3714
|
+
if (!onMove) return;
|
|
3715
|
+
const sourceId = getId(item);
|
|
3716
|
+
const sourceNode = nodeById.get(sourceId);
|
|
3717
|
+
if (!sourceNode) return;
|
|
3718
|
+
if (target?.id === sourceId) return;
|
|
3719
|
+
const parent = position === "inside" ? target : target ? parentOf(target.id) : null;
|
|
3720
|
+
if (parent && (parent.id === sourceId || getDescendantIds(sourceNode).includes(parent.id))) return;
|
|
3721
|
+
const siblings = siblingsOf(parent).filter((node) => node.id !== sourceId);
|
|
3722
|
+
const targetIndex = target ? siblings.findIndex((node) => node.id === target.id) : -1;
|
|
3723
|
+
const index = targetIndex < 0 ? siblings.length : targetIndex + (position === "after" ? 1 : 0);
|
|
3724
|
+
Promise.resolve(onMove({
|
|
3725
|
+
item,
|
|
3726
|
+
newParent: parent?.item ?? null,
|
|
3727
|
+
index,
|
|
3728
|
+
position
|
|
3729
|
+
})).then(() => setMoveError(false)).catch(() => setMoveError(true));
|
|
3730
|
+
};
|
|
3731
|
+
const saveEdit = async (node, columnId) => {
|
|
3732
|
+
const key = `${String(node.id)}:${columnId}`;
|
|
3733
|
+
setEditingCell(null);
|
|
3734
|
+
try {
|
|
3735
|
+
await onEdit?.(node.item, columnId, editValue);
|
|
3736
|
+
setEditErrors((current) => {
|
|
3737
|
+
const next = new Map(current);
|
|
3738
|
+
next.delete(key);
|
|
3739
|
+
return next;
|
|
3740
|
+
});
|
|
3741
|
+
} catch (cause) {
|
|
3742
|
+
setEditErrors((current) => new Map(current).set(key, cause));
|
|
3743
|
+
setEditingCell({
|
|
3744
|
+
id: node.id,
|
|
3745
|
+
columnId
|
|
3746
|
+
});
|
|
3747
|
+
}
|
|
3748
|
+
};
|
|
3749
|
+
const onRowKeyDown = (event, index) => {
|
|
3750
|
+
if (event.key === "ArrowDown" || event.key === "ArrowUp") {
|
|
3751
|
+
event.preventDefault();
|
|
3752
|
+
const target = visibleNodes[index + (event.key === "ArrowDown" ? 1 : -1)];
|
|
3753
|
+
if (target) rows.current.get(target.id)?.focus();
|
|
3754
|
+
}
|
|
3755
|
+
if (event.key === "ArrowRight" && visibleNodes[index]) {
|
|
3756
|
+
event.preventDefault();
|
|
3757
|
+
const node = visibleNodes[index];
|
|
3758
|
+
if ((node.children.length > 0 || hasChildren?.(node.item)) && !expandedIds.has(node.id)) expand(node);
|
|
3759
|
+
else if (expandedIds.has(node.id) && node.children[0]) rows.current.get(node.children[0].id)?.focus();
|
|
3760
|
+
}
|
|
3761
|
+
if (event.key === "ArrowLeft" && visibleNodes[index]) {
|
|
3762
|
+
event.preventDefault();
|
|
3763
|
+
const node = visibleNodes[index];
|
|
3764
|
+
if (expandedIds.has(node.id)) expand(node);
|
|
3765
|
+
else {
|
|
3766
|
+
const parentId = getParentId?.(node.item);
|
|
3767
|
+
if (parentId != null) rows.current.get(parentId)?.focus();
|
|
3768
|
+
}
|
|
3769
|
+
}
|
|
3770
|
+
if (event.key === "Enter" && visibleNodes[index]) onRowActivate?.(visibleNodes[index].item);
|
|
3771
|
+
};
|
|
3772
|
+
const classNames = [
|
|
3773
|
+
"nb-tree-list",
|
|
3774
|
+
`nb-tree-list--${density}`,
|
|
3775
|
+
className
|
|
3776
|
+
].filter(Boolean).join(" ");
|
|
3777
|
+
const hasSelection = selectionMode !== "none";
|
|
3778
|
+
const allVisibleSelected = visibleNodes.length > 0 && visibleNodes.every((node) => selectedIds.has(node.id));
|
|
3779
|
+
const someVisibleSelected = !allVisibleSelected && visibleNodes.some((node) => selectedIds.has(node.id));
|
|
3780
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
3781
|
+
className: classNames,
|
|
3782
|
+
"data-testid": testId,
|
|
3783
|
+
children: [
|
|
3784
|
+
filterable && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
3785
|
+
className: "nb-tree-list__toolbar",
|
|
3786
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("label", {
|
|
3787
|
+
className: "nb-tree-list__filter",
|
|
3788
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
3789
|
+
className: "nb-tree-list__sr-only",
|
|
3790
|
+
children: strings.treeListFilter
|
|
3791
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
|
|
3792
|
+
type: "search",
|
|
3793
|
+
value: filter,
|
|
3794
|
+
placeholder: strings.treeListFilter,
|
|
3795
|
+
onChange: (event) => updateFilter(event.currentTarget.value)
|
|
3796
|
+
})]
|
|
3797
|
+
}), filter && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
3798
|
+
type: "button",
|
|
3799
|
+
className: "nb-tree-list__clear-filter",
|
|
3800
|
+
onClick: () => updateFilter(""),
|
|
3801
|
+
children: strings.clear
|
|
3802
|
+
})]
|
|
3803
|
+
}),
|
|
3804
|
+
error && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
3805
|
+
className: "nb-tree-list__error",
|
|
3806
|
+
role: "alert",
|
|
3807
|
+
children: error
|
|
3808
|
+
}),
|
|
3809
|
+
moveError && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
3810
|
+
className: "nb-tree-list__error",
|
|
3811
|
+
role: "alert",
|
|
3812
|
+
children: strings.treeListMoveFailed
|
|
3813
|
+
}),
|
|
3814
|
+
loading && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
3815
|
+
className: "nb-tree-list__loading",
|
|
3816
|
+
role: "status",
|
|
3817
|
+
children: strings.searching
|
|
3818
|
+
}),
|
|
3819
|
+
!loading && visibleNodes.length === 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
3820
|
+
className: "nb-tree-list__empty",
|
|
3821
|
+
children: emptyState ?? strings.treeListEmpty
|
|
3822
|
+
}) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
3823
|
+
className: "nb-tree-list__scroll",
|
|
3824
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("table", {
|
|
3825
|
+
className: "nb-tree-list__table",
|
|
3826
|
+
role: "treegrid",
|
|
3827
|
+
"aria-label": ariaLabel,
|
|
3828
|
+
"aria-busy": loading || loadingIds.size > 0,
|
|
3829
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("thead", { children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("tr", { children: [
|
|
3830
|
+
hasSelection && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("th", {
|
|
3831
|
+
className: "nb-tree-list__selection-cell",
|
|
3832
|
+
children: selectionMode === "multiple" && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Checkbox, {
|
|
3833
|
+
"aria-label": strings.treeListSelectAll,
|
|
3834
|
+
checked: allVisibleSelected,
|
|
3835
|
+
indeterminate: someVisibleSelected,
|
|
3836
|
+
onChange: () => {
|
|
3837
|
+
const next = new Set(selectedIds);
|
|
3838
|
+
for (const node of visibleNodes) if (allVisibleSelected) next.delete(node.id);
|
|
3839
|
+
else next.add(node.id);
|
|
3840
|
+
updateSelected(next);
|
|
3841
|
+
}
|
|
3842
|
+
})
|
|
3843
|
+
}),
|
|
3844
|
+
columns.map((column, index) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("th", {
|
|
3845
|
+
scope: "col",
|
|
3846
|
+
"aria-sort": sort?.columnId === column.id ? sort.direction === "asc" ? "ascending" : "descending" : void 0,
|
|
3847
|
+
style: column.width ? { width: column.width } : void 0,
|
|
3848
|
+
className: `nb-tree-list__align--${column.align ?? "start"}`,
|
|
3849
|
+
children: column.sortable === false || index === 0 ? column.header : /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
|
|
3850
|
+
type: "button",
|
|
3851
|
+
className: "nb-tree-list__sort",
|
|
3852
|
+
onClick: () => setSort((current) => current?.columnId === column.id ? current.direction === "asc" ? {
|
|
3853
|
+
columnId: column.id,
|
|
3854
|
+
direction: "desc"
|
|
3855
|
+
} : null : {
|
|
3856
|
+
columnId: column.id,
|
|
3857
|
+
direction: "asc"
|
|
3858
|
+
}),
|
|
3859
|
+
children: [column.header, /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
3860
|
+
"aria-hidden": "true",
|
|
3861
|
+
children: sort?.columnId === column.id ? sort.direction === "asc" ? "↑" : "↓" : "↕"
|
|
3862
|
+
})]
|
|
3863
|
+
})
|
|
3864
|
+
}, column.id)),
|
|
3865
|
+
rowActions && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("th", {
|
|
3866
|
+
scope: "col",
|
|
3867
|
+
"aria-label": strings.rowActions
|
|
3868
|
+
})
|
|
3869
|
+
] }) }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("tbody", {
|
|
3870
|
+
onDragOver: (event) => {
|
|
3871
|
+
if (onMove && event.target === event.currentTarget) {
|
|
3872
|
+
event.preventDefault();
|
|
3873
|
+
event.dataTransfer.dropEffect = "move";
|
|
3874
|
+
}
|
|
3875
|
+
},
|
|
3876
|
+
onDrop: (event) => {
|
|
3877
|
+
if (!onMove || event.target !== event.currentTarget) return;
|
|
3878
|
+
event.preventDefault();
|
|
3879
|
+
const draggedId = event.dataTransfer.getData("text/plain");
|
|
3880
|
+
const dragged = nodeById.get(draggedId) ?? nodeById.get(Number(draggedId));
|
|
3881
|
+
if (dragged) moveRow(dragged.item, null, "after");
|
|
3882
|
+
},
|
|
3883
|
+
children: visibleNodes.map((node, index) => {
|
|
3884
|
+
const expanded = effectiveExpandedIds.has(node.id);
|
|
3885
|
+
const canExpand = node.children.length > 0 || (hasChildren ? hasChildren(node.item) : !!loadChildren);
|
|
3886
|
+
const selected = selectedIds.has(node.id);
|
|
3887
|
+
const parent = getParentId?.(node.item);
|
|
3888
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("tr", {
|
|
3889
|
+
ref: (element) => {
|
|
3890
|
+
if (element) rows.current.set(node.id, element);
|
|
3891
|
+
else rows.current.delete(node.id);
|
|
3892
|
+
},
|
|
3893
|
+
role: "row",
|
|
3894
|
+
"aria-level": node.depth + 1,
|
|
3895
|
+
"aria-expanded": canExpand ? expanded : void 0,
|
|
3896
|
+
"aria-selected": hasSelection ? selected : void 0,
|
|
3897
|
+
tabIndex: index === 0 ? 0 : -1,
|
|
3898
|
+
draggable: !!onMove,
|
|
3899
|
+
onKeyDown: (event) => onRowKeyDown(event, index),
|
|
3900
|
+
onClick: () => onRowActivate?.(node.item),
|
|
3901
|
+
onDragStart: (event) => {
|
|
3902
|
+
event.dataTransfer.setData("text/plain", String(node.id));
|
|
3903
|
+
event.dataTransfer.effectAllowed = "move";
|
|
3904
|
+
},
|
|
3905
|
+
onDragOver: (event) => {
|
|
3906
|
+
if (onMove) {
|
|
3907
|
+
event.preventDefault();
|
|
3908
|
+
event.dataTransfer.dropEffect = "move";
|
|
3909
|
+
}
|
|
3910
|
+
},
|
|
3911
|
+
onDrop: (event) => {
|
|
3912
|
+
event.preventDefault();
|
|
3913
|
+
event.stopPropagation();
|
|
3914
|
+
const draggedId = event.dataTransfer.getData("text/plain");
|
|
3915
|
+
const dragged = nodeById.get(draggedId) ?? nodeById.get(Number(draggedId));
|
|
3916
|
+
const bounds = event.currentTarget.getBoundingClientRect();
|
|
3917
|
+
const relativeY = event.clientY - bounds.top;
|
|
3918
|
+
const position = relativeY < bounds.height * .25 ? "before" : relativeY > bounds.height * .75 ? "after" : "inside";
|
|
3919
|
+
if (dragged) moveRow(dragged.item, node, position);
|
|
3920
|
+
},
|
|
3921
|
+
onDragEnd: () => {},
|
|
3922
|
+
"data-parent-id": parent == null ? void 0 : String(parent),
|
|
3923
|
+
children: [
|
|
3924
|
+
hasSelection && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("td", {
|
|
3925
|
+
className: "nb-tree-list__selection-cell",
|
|
3926
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Checkbox, {
|
|
3927
|
+
"aria-label": `${strings.treeListSelect} ${String(getId(node.item))}`,
|
|
3928
|
+
checked: selected,
|
|
3929
|
+
onClick: (event) => event.stopPropagation(),
|
|
3930
|
+
onChange: () => toggleSelected(node)
|
|
3931
|
+
})
|
|
3932
|
+
}),
|
|
3933
|
+
columns.map((column, columnIndex) => {
|
|
3934
|
+
const isEditing = editingCell?.id === node.id && editingCell.columnId === column.id;
|
|
3935
|
+
const rawValue = itemValue(column, node.item);
|
|
3936
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("td", {
|
|
3937
|
+
className: `nb-tree-list__align--${column.align ?? "start"}`,
|
|
3938
|
+
onDoubleClick: () => {
|
|
3939
|
+
const columnCanEdit = column.editable === true || typeof column.editable === "function" && column.editable(node.item) || editable?.(node.item, column.id) === true;
|
|
3940
|
+
if (!onEdit || !columnCanEdit) return;
|
|
3941
|
+
setEditingCell({
|
|
3942
|
+
id: node.id,
|
|
3943
|
+
columnId: column.id
|
|
3944
|
+
});
|
|
3945
|
+
setEditValue(String(rawValue ?? ""));
|
|
3946
|
+
},
|
|
3947
|
+
children: [
|
|
3948
|
+
columnIndex === 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
3949
|
+
className: "nb-tree-list__indent",
|
|
3950
|
+
style: { "--nb-tree-depth": node.depth },
|
|
3951
|
+
children: canExpand ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(IconButton, {
|
|
3952
|
+
icon: loadingIds.has(node.id) ? "ph ph-spinner" : expanded ? "ph ph-caret-down" : "ph ph-caret-right",
|
|
3953
|
+
label: `${expanded ? strings.treeListCollapse : strings.treeListExpand} ${String(getId(node.item))}`,
|
|
3954
|
+
disabled: loadingIds.has(node.id),
|
|
3955
|
+
onClick: (event) => {
|
|
3956
|
+
event.stopPropagation();
|
|
3957
|
+
expand(node);
|
|
3958
|
+
}
|
|
3959
|
+
}) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { className: "nb-tree-list__spacer" })
|
|
3960
|
+
}),
|
|
3961
|
+
isEditing ? column.editor ? column.editor({
|
|
3962
|
+
item: node.item,
|
|
3963
|
+
value: editValue,
|
|
3964
|
+
onChange: setEditValue
|
|
3965
|
+
}) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
|
|
3966
|
+
autoFocus: true,
|
|
3967
|
+
value: editValue,
|
|
3968
|
+
"aria-label": `${strings.treeListEdit} ${column.id}`,
|
|
3969
|
+
onChange: (event) => setEditValue(event.currentTarget.value),
|
|
3970
|
+
onBlur: () => void saveEdit(node, column.id),
|
|
3971
|
+
onKeyDown: (event) => {
|
|
3972
|
+
if (event.key === "Enter") saveEdit(node, column.id);
|
|
3973
|
+
if (event.key === "Escape") setEditingCell(null);
|
|
3974
|
+
}
|
|
3975
|
+
}) : column.render ? column.render(node.item, {
|
|
3976
|
+
depth: node.depth,
|
|
3977
|
+
expanded
|
|
3978
|
+
}) : String(rawValue ?? ""),
|
|
3979
|
+
loadErrors.has(node.id) && columnIndex === 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
3980
|
+
type: "button",
|
|
3981
|
+
className: "nb-tree-list__retry",
|
|
3982
|
+
onClick: () => void expand(node),
|
|
3983
|
+
children: strings.retrySearch
|
|
3984
|
+
}),
|
|
3985
|
+
editErrors.has(`${String(node.id)}:${column.id}`) && isEditing && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
3986
|
+
className: "nb-tree-list__edit-error",
|
|
3987
|
+
role: "alert",
|
|
3988
|
+
children: strings.searchFailed
|
|
3989
|
+
})
|
|
3990
|
+
]
|
|
3991
|
+
}, column.id);
|
|
3992
|
+
}),
|
|
3993
|
+
rowActions && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("td", {
|
|
3994
|
+
className: "nb-tree-list__actions-cell",
|
|
3995
|
+
onClick: (event) => event.stopPropagation(),
|
|
3996
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(RowActions, {
|
|
3997
|
+
items: rowActions(node.item),
|
|
3998
|
+
triggerLabel: strings.rowActions
|
|
3999
|
+
})
|
|
4000
|
+
})
|
|
4001
|
+
]
|
|
4002
|
+
}, node.id);
|
|
4003
|
+
})
|
|
4004
|
+
})]
|
|
4005
|
+
})
|
|
4006
|
+
})
|
|
4007
|
+
]
|
|
4008
|
+
});
|
|
4009
|
+
}
|
|
3487
4010
|
exports.ACCENT_PRESETS = ACCENT_PRESETS;
|
|
3488
4011
|
exports.Alert = Alert;
|
|
3489
4012
|
exports.AppDialog = AppDialog;
|
|
@@ -3556,9 +4079,13 @@ exports.TimelineItem = TimelineItem;
|
|
|
3556
4079
|
exports.Toggle = Toggle;
|
|
3557
4080
|
exports.Tooltip = Tooltip;
|
|
3558
4081
|
exports.TooltipProvider = TooltipProvider;
|
|
4082
|
+
exports.TreeList = TreeList;
|
|
3559
4083
|
exports.UiStringsProvider = UiStringsProvider;
|
|
4084
|
+
exports.buildTreeListModel = buildTreeListModel;
|
|
4085
|
+
exports.flattenVisibleTree = flattenVisibleTree;
|
|
3560
4086
|
exports.getAvatarHue = getAvatarHue;
|
|
3561
4087
|
exports.getAvatarInitials = getAvatarInitials;
|
|
4088
|
+
exports.getDescendantIds = getDescendantIds;
|
|
3562
4089
|
exports.useAccentColor = useAccentColor;
|
|
3563
4090
|
exports.useConfirm = useConfirm;
|
|
3564
4091
|
exports.useDensity = useDensity;
|