@nubitio/ui 1.1.2 → 1.2.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/index.cjs CHANGED
@@ -24,8 +24,14 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
24
24
  let react = require("react");
25
25
  react = __toESM(react, 1);
26
26
  let react_jsx_runtime = require("react/jsx-runtime");
27
- let react_dom = require("react-dom");
27
+ let _base_ui_react_dialog = require("@base-ui/react/dialog");
28
28
  let react_dropzone = require("react-dropzone");
29
+ let _base_ui_react_select = require("@base-ui/react/select");
30
+ let react_aria_components = require("react-aria-components");
31
+ let _base_ui_react_menu = require("@base-ui/react/menu");
32
+ let _internationalized_date = require("@internationalized/date");
33
+ let _base_ui_react_popover = require("@base-ui/react/popover");
34
+ let _base_ui_react_tooltip = require("@base-ui/react/tooltip");
29
35
  //#region packages/ui/Avatar.tsx
30
36
  /**
31
37
  * 8 semantic hues aligned with the Fluent / @nubitio design palette.
@@ -84,32 +90,104 @@ const Avatar = ({ owner = "", size, variant = "md", shape = "circle", alt, class
84
90
  });
85
91
  };
86
92
  //#endregion
93
+ //#region packages/ui/OverlayContainer.tsx
94
+ /** Keeps nested portals within the modal's focus and accessibility boundary. */
95
+ const OverlayContainerContext = (0, react.createContext)(null);
96
+ const useOverlayContainer = () => (0, react.useContext)(OverlayContainerContext);
97
+ //#endregion
98
+ //#region packages/ui/ModalSurface.tsx
99
+ /** Shared modal behavior for centered dialogs and side sheets. */
100
+ function ModalSurface({ open, onClose, children, rootClassName, className, style, scrimClassName, scrimLabel, labelledBy, ariaLabel, role = "dialog", keepMounted = false, restoreFocus = true, closeOnEscape = true, initialFocus, closeOnOutsideClick = true }) {
101
+ const parentContainer = useOverlayContainer();
102
+ const [container, setContainer] = (0, react.useState)(null);
103
+ const returnFocus = (0, react.useRef)(null);
104
+ (0, react.useLayoutEffect)(() => {
105
+ if (!open) return;
106
+ const active = document.activeElement;
107
+ if (active instanceof HTMLElement && !container?.contains(active)) returnFocus.current = active;
108
+ }, [open, container]);
109
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_base_ui_react_dialog.Dialog.Root, {
110
+ open,
111
+ disablePointerDismissal: !closeOnOutsideClick,
112
+ onOpenChange: (next, details) => {
113
+ if (!next) {
114
+ if (details.reason === "escape-key" && !closeOnEscape) details.cancel();
115
+ else onClose();
116
+ }
117
+ },
118
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_base_ui_react_dialog.Dialog.Portal, {
119
+ container: parentContainer ?? void 0,
120
+ keepMounted,
121
+ className: rootClassName,
122
+ "aria-hidden": !open || void 0,
123
+ style: {
124
+ visibility: open ? void 0 : "hidden",
125
+ pointerEvents: open ? void 0 : "none"
126
+ },
127
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_base_ui_react_dialog.Dialog.Backdrop, {
128
+ forceRender: true,
129
+ className: scrimClassName,
130
+ render: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
131
+ type: "button",
132
+ tabIndex: -1,
133
+ "aria-label": scrimLabel
134
+ })
135
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_base_ui_react_dialog.Dialog.Popup, {
136
+ ref: setContainer,
137
+ role,
138
+ "aria-labelledby": labelledBy,
139
+ "aria-label": ariaLabel,
140
+ className,
141
+ style,
142
+ finalFocus: restoreFocus ? () => returnFocus.current ?? true : false,
143
+ initialFocus,
144
+ onKeyDown: (event) => {
145
+ if (event.key === "Escape" && !event.defaultPrevented) {
146
+ event.stopPropagation();
147
+ if (closeOnEscape) onClose();
148
+ }
149
+ },
150
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(OverlayContainerContext.Provider, {
151
+ value: container,
152
+ children
153
+ })
154
+ })]
155
+ })
156
+ });
157
+ }
158
+ //#endregion
87
159
  //#region packages/ui/Button.tsx
88
- const cx$5 = (...values) => values.filter(Boolean).join(" ");
89
- const Button = ({ variant = "secondary", size = "md", fullWidth = false, icon, loading = false, className, children, disabled, ...props }) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
90
- ...props,
91
- type: props.type ?? "button",
92
- disabled: disabled || loading,
93
- "aria-busy": loading || void 0,
94
- className: cx$5("nb-button", `nb-button--${variant}`, size === "sm" && "nb-button--sm", fullWidth && "nb-button--full", className),
95
- children: [loading ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
96
- className: "nb-button-spinner",
97
- "aria-hidden": "true"
98
- }) : icon ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("i", {
99
- className: icon,
100
- "aria-hidden": "true"
101
- }) : null, children]
160
+ const cx$2 = (...values) => values.filter(Boolean).join(" ");
161
+ const Button = (0, react.forwardRef)(function Button({ variant = "secondary", size = "md", fullWidth = false, icon, loading = false, className, children, disabled, ...props }, ref) {
162
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
163
+ ...props,
164
+ ref,
165
+ type: props.type ?? "button",
166
+ disabled: disabled || loading,
167
+ "aria-busy": loading || void 0,
168
+ className: cx$2("nb-button", `nb-button--${variant}`, size === "sm" && "nb-button--sm", fullWidth && "nb-button--full", className),
169
+ children: [loading ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
170
+ className: "nb-button-spinner",
171
+ "aria-hidden": "true"
172
+ }) : icon ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("i", {
173
+ className: icon,
174
+ "aria-hidden": "true"
175
+ }) : null, children]
176
+ });
102
177
  });
103
- const IconButton = ({ icon, label, variant = "default", className, ...props }) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
104
- ...props,
105
- type: props.type ?? "button",
106
- "aria-label": props["aria-label"] ?? label,
107
- title: props.title ?? label,
108
- className: cx$5("nb-icon-button", variant === "danger" && "nb-icon-button--danger", className),
109
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("i", {
110
- className: icon,
111
- "aria-hidden": "true"
112
- })
178
+ const IconButton = (0, react.forwardRef)(function IconButton({ icon, label, variant = "default", className, ...props }, ref) {
179
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
180
+ ...props,
181
+ ref,
182
+ type: props.type ?? "button",
183
+ "aria-label": props["aria-label"] ?? label,
184
+ title: props.title ?? label,
185
+ className: cx$2("nb-icon-button", variant === "danger" && "nb-icon-button--danger", className),
186
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("i", {
187
+ className: icon,
188
+ "aria-hidden": "true"
189
+ })
190
+ });
113
191
  });
114
192
  //#endregion
115
193
  //#region packages/ui/UiStrings.tsx
@@ -122,6 +200,9 @@ const EN_UI_STRINGS = {
122
200
  openCalendar: "Open calendar",
123
201
  selectDate: "Select date",
124
202
  selectDateRange: "Select date range",
203
+ startDate: "Start date",
204
+ endDate: "End date",
205
+ selectTime: "Select time",
125
206
  previousMonth: "Previous month",
126
207
  nextMonth: "Next month",
127
208
  previousYear: "Previous year",
@@ -129,6 +210,16 @@ const EN_UI_STRINGS = {
129
210
  selectMonthAndYear: "Select month and year",
130
211
  selectYear: "Select year",
131
212
  clear: "Clear",
213
+ openOptions: "Open options",
214
+ noOptions: "No options found",
215
+ searching: "Searching…",
216
+ searchFailed: "Could not load options",
217
+ enterSearch: "Type to search",
218
+ loadingMore: "Loading more…",
219
+ loadMore: "Load more",
220
+ retrySearch: "Retry search",
221
+ selectedOptions: "Selected options",
222
+ removeOption: "Remove",
132
223
  today: "Today",
133
224
  cancel: "Cancel",
134
225
  confirm: "Confirm",
@@ -181,6 +272,9 @@ const ES_UI_STRINGS = {
181
272
  openCalendar: "Abrir calendario",
182
273
  selectDate: "Seleccionar fecha",
183
274
  selectDateRange: "Seleccionar rango de fechas",
275
+ startDate: "Fecha inicio",
276
+ endDate: "Fecha fin",
277
+ selectTime: "Seleccionar hora",
184
278
  previousMonth: "Mes anterior",
185
279
  nextMonth: "Mes siguiente",
186
280
  previousYear: "Año anterior",
@@ -188,6 +282,16 @@ const ES_UI_STRINGS = {
188
282
  selectMonthAndYear: "Seleccionar mes y año",
189
283
  selectYear: "Seleccionar año",
190
284
  clear: "Limpiar",
285
+ openOptions: "Abrir opciones",
286
+ noOptions: "No se encontraron opciones",
287
+ searching: "Buscando…",
288
+ searchFailed: "No se pudieron cargar las opciones",
289
+ enterSearch: "Escribe para buscar",
290
+ loadingMore: "Cargando más…",
291
+ loadMore: "Cargar más",
292
+ retrySearch: "Reintentar búsqueda",
293
+ selectedOptions: "Opciones seleccionadas",
294
+ removeOption: "Quitar",
191
295
  today: "Hoy",
192
296
  cancel: "Cancelar",
193
297
  confirm: "Confirmar",
@@ -250,103 +354,61 @@ const formatSize = (value) => {
250
354
  return typeof value === "number" ? `${value}px` : value;
251
355
  };
252
356
  const joinClassNames = (...values) => values.filter(Boolean).join(" ");
253
- const AppDialog = ({ visible, open, title, onClose, children, footer, width, maxWidth, height, fullScreen = false, showCloseButton = true, closeLabel, scrimLabel, closeOnOutsideClick = true, closeOnEscape = true, restoreFocus = true, keepMounted = false, rootClassName, className, headerClassName, titleClassName, bodyClassName, footerClassName, role = "dialog" }) => {
357
+ const AppDialog = ({ visible, open, title, onClose, children, footer, width, maxWidth, height, fullScreen = false, showCloseButton = true, closeLabel, scrimLabel, closeOnOutsideClick = true, closeOnEscape = true, restoreFocus = true, keepMounted = false, initialFocus, rootClassName, className, headerClassName, titleClassName, bodyClassName, footerClassName, role = "dialog" }) => {
254
358
  const strings = useUiStrings();
255
359
  const resolvedCloseLabel = closeLabel ?? strings.close;
256
360
  const resolvedScrimLabel = scrimLabel ?? strings.closeDialog;
257
361
  const isVisible = visible ?? open ?? false;
258
362
  const titleId = (0, react.useId)();
259
- const dialogRef = (0, react.useRef)(null);
260
- const lastFocusedElementRef = (0, react.useRef)(null);
261
- const restoreFocusRef = (0, react.useRef)(restoreFocus);
262
- (0, react.useEffect)(() => {
263
- restoreFocusRef.current = restoreFocus;
264
- }, [restoreFocus]);
265
- (0, react.useEffect)(() => {
266
- if (!isVisible) return;
267
- lastFocusedElementRef.current = document.activeElement;
268
- window.setTimeout(() => {
269
- (dialogRef.current?.querySelector("button:not(:disabled), [href], input:not(:disabled), select:not(:disabled), textarea:not(:disabled), [tabindex]:not([tabindex=\"-1\"])"))?.focus();
270
- });
271
- return () => {
272
- if (restoreFocusRef.current) lastFocusedElementRef.current?.focus?.();
273
- };
274
- }, [isVisible]);
275
- (0, react.useEffect)(() => {
276
- if (!isVisible || !closeOnEscape) return;
277
- const handleKeyDown = (event) => {
278
- if (event.key === "Escape") {
279
- event.preventDefault();
280
- onClose();
281
- }
282
- };
283
- document.addEventListener("keydown", handleKeyDown);
284
- return () => document.removeEventListener("keydown", handleKeyDown);
285
- }, [
286
- closeOnEscape,
363
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(ModalSurface, {
364
+ open: isVisible,
287
365
  onClose,
288
- isVisible
289
- ]);
290
- if (!isVisible && !keepMounted) return null;
291
- return (0, react_dom.createPortal)(/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
292
- className: joinClassNames("nb-dialog-root", rootClassName),
293
- "aria-hidden": !isVisible,
366
+ rootClassName: joinClassNames("nb-dialog-root", rootClassName),
367
+ className: joinClassNames("nb-dialog", fullScreen && "nb-dialog--fullscreen", className),
368
+ scrimClassName: "nb-dialog__scrim",
369
+ scrimLabel: resolvedScrimLabel,
370
+ labelledBy: titleId,
371
+ role,
372
+ closeOnEscape,
373
+ closeOnOutsideClick,
374
+ restoreFocus,
375
+ keepMounted,
376
+ initialFocus,
294
377
  style: {
295
- pointerEvents: isVisible ? void 0 : "none",
296
- visibility: isVisible ? void 0 : "hidden"
378
+ width: formatSize(width),
379
+ maxWidth: formatSize(maxWidth),
380
+ height: formatSize(height)
297
381
  },
298
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
299
- className: "nb-dialog__scrim",
300
- type: "button",
301
- "aria-label": resolvedScrimLabel,
302
- onClick: closeOnOutsideClick ? onClose : void 0
303
- }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
304
- className: joinClassNames("nb-dialog", fullScreen && "nb-dialog--fullscreen", className),
305
- role,
306
- "aria-modal": "true",
307
- "aria-labelledby": titleId,
308
- ref: dialogRef,
309
- onKeyDownCapture: (event) => {
310
- if (!closeOnEscape && event.key === "Escape") {
311
- event.preventDefault();
312
- event.stopPropagation();
313
- }
314
- },
315
- style: {
316
- width: formatSize(width),
317
- maxWidth: formatSize(maxWidth),
318
- height: formatSize(height)
319
- },
320
- children: [
321
- /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
322
- className: joinClassNames("nb-dialog__header", headerClassName),
323
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("h2", {
324
- className: joinClassNames("nb-dialog__title", titleClassName),
325
- id: titleId,
326
- children: title
327
- }), showCloseButton && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(IconButton, {
328
- className: "nb-dialog__close",
329
- icon: "ph ph-x",
330
- label: resolvedCloseLabel,
331
- onClick: onClose
332
- })]
333
- }),
334
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
335
- className: joinClassNames("nb-dialog__body", bodyClassName),
336
- children
337
- }),
338
- footer && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
339
- className: joinClassNames("nb-dialog__footer", footerClassName),
340
- children: footer
341
- })
342
- ]
343
- })]
344
- }), document.body);
382
+ children: [
383
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
384
+ className: joinClassNames("nb-dialog__header", headerClassName),
385
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("h2", {
386
+ className: joinClassNames("nb-dialog__title", titleClassName),
387
+ id: titleId,
388
+ children: title
389
+ }), showCloseButton && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(IconButton, {
390
+ className: "nb-dialog__close",
391
+ icon: "ph ph-x",
392
+ label: resolvedCloseLabel,
393
+ onClick: onClose
394
+ })]
395
+ }),
396
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
397
+ className: joinClassNames("nb-dialog__body", bodyClassName),
398
+ children
399
+ }),
400
+ footer && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
401
+ className: joinClassNames("nb-dialog__footer", footerClassName),
402
+ children: footer
403
+ })
404
+ ]
405
+ });
345
406
  };
346
407
  //#endregion
347
408
  //#region packages/ui/ConfirmDialog.tsx
348
409
  function ConfirmDialog({ open, title, message, onConfirm, onCancel, confirmLabel, cancelLabel, variant = "warning" }) {
349
410
  const strings = useUiStrings();
411
+ const cancelRef = (0, react.useRef)(null);
350
412
  const resolvedConfirmLabel = confirmLabel ?? strings.confirm;
351
413
  const resolvedCancelLabel = cancelLabel ?? strings.cancel;
352
414
  return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(AppDialog, {
@@ -355,10 +417,11 @@ function ConfirmDialog({ open, title, message, onConfirm, onCancel, confirmLabel
355
417
  onClose: onCancel,
356
418
  maxWidth: 420,
357
419
  role: "alertdialog",
420
+ initialFocus: cancelRef,
358
421
  footer: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(Button, {
359
422
  variant: "secondary",
360
423
  onClick: onCancel,
361
- autoFocus: true,
424
+ ref: cancelRef,
362
425
  children: resolvedCancelLabel
363
426
  }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Button, {
364
427
  variant: variant === "danger" ? "danger" : "primary",
@@ -444,10 +507,10 @@ const Card = ({ title, description, variant = "auth", className, children }) =>
444
507
  };
445
508
  //#endregion
446
509
  //#region packages/ui/FormControls.tsx
447
- const cx$4 = (...values) => values.filter(Boolean).join(" ");
510
+ const cx$1 = (...values) => values.filter(Boolean).join(" ");
448
511
  const FormField = ({ label, error, helpText, children, className, ...props }) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("label", {
449
512
  ...props,
450
- className: cx$4("nb-form-field", !!error && "nb-form-field--error", className),
513
+ className: cx$1("nb-form-field", !!error && "nb-form-field--error", className),
451
514
  children: [
452
515
  label && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
453
516
  className: "nb-form-field__label",
@@ -468,14 +531,14 @@ const TextField = (0, react.forwardRef)(function TextField({ className, invalid,
468
531
  return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
469
532
  ...props,
470
533
  ref,
471
- className: cx$4("nb-input", invalid && "nb-input--invalid", className)
534
+ className: cx$1("nb-input", invalid && "nb-input--invalid", className)
472
535
  });
473
536
  });
474
537
  const SelectField = (0, react.forwardRef)(function SelectField({ className, invalid, children, ...props }, ref) {
475
538
  return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("select", {
476
539
  ...props,
477
540
  ref,
478
- className: cx$4("nb-input", "nb-select", invalid && "nb-input--invalid", className),
541
+ className: cx$1("nb-input", "nb-select", invalid && "nb-input--invalid", className),
479
542
  children
480
543
  });
481
544
  });
@@ -483,12 +546,12 @@ const TextAreaField = (0, react.forwardRef)(function TextAreaField({ className,
483
546
  return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("textarea", {
484
547
  ...props,
485
548
  ref,
486
- className: cx$4("nb-input", "nb-textarea", invalid && "nb-input--invalid", className)
549
+ className: cx$1("nb-input", "nb-textarea", invalid && "nb-input--invalid", className)
487
550
  });
488
551
  });
489
552
  //#endregion
490
553
  //#region packages/ui/FileDropzone.tsx
491
- function cx$3(...values) {
554
+ function cx(...values) {
492
555
  return values.filter(Boolean).join(" ");
493
556
  }
494
557
  function buildDropzoneAccept(accept) {
@@ -533,10 +596,10 @@ function FileDropzone({ accept, value = null, image = false, disabled = false, r
533
596
  const placeholderTitle = isDragActive ? labels?.dropPrompt ?? "Drop file here" : image ? labels?.imagePrompt ?? "Drop image here or click to browse" : labels?.prompt ?? "Drop file here or click to browse";
534
597
  const placeholderHint = image ? labels?.imageHint ?? "PNG, JPG, WebP or GIF" : labels?.hint ?? "Select one file";
535
598
  return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
536
- className: cx$3("nb-file-dropzone", image && "nb-file-dropzone--image", invalid && "nb-file-dropzone--invalid", className),
599
+ className: cx("nb-file-dropzone", image && "nb-file-dropzone--image", invalid && "nb-file-dropzone--invalid", className),
537
600
  children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
538
- ...getRootProps({ className: cx$3("nb-file-dropzone__zone", isDragActive && "nb-file-dropzone__zone--active", hasContent && "nb-file-dropzone__zone--filled", uploading && "nb-file-dropzone__zone--uploading", !isInteractive && "nb-file-dropzone__zone--disabled") }),
539
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", { ...getInputProps({
601
+ ...getRootProps({ className: cx("nb-file-dropzone__zone", isDragActive && "nb-file-dropzone__zone--active", hasContent && "nb-file-dropzone__zone--filled", uploading && "nb-file-dropzone__zone--uploading", disabled && "nb-file-dropzone__zone--disabled", readOnly && "nb-file-dropzone__zone--readonly") }),
602
+ children: [!readOnly && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", { ...getInputProps({
540
603
  id: inputId,
541
604
  "aria-label": inputLabel
542
605
  }) }), hasContent ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
@@ -609,9 +672,9 @@ function FileDropzone({ accept, value = null, image = false, disabled = false, r
609
672
  }),
610
673
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
611
674
  className: "nb-file-dropzone__title",
612
- children: placeholderTitle
675
+ children: readOnly ? labels?.empty ?? (image ? "No image" : "No file") : placeholderTitle
613
676
  }),
614
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
677
+ !readOnly && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
615
678
  className: "nb-file-dropzone__hint",
616
679
  children: placeholderHint
617
680
  })
@@ -628,390 +691,550 @@ function FileDropzone({ accept, value = null, image = false, disabled = false, r
628
691
  });
629
692
  }
630
693
  //#endregion
631
- //#region packages/ui/useFloatingPanel.ts
632
- /** Style applied to an anchored panel before its first position is computed. */
633
- const HIDDEN_PANEL_STYLE = {
634
- position: "fixed",
635
- visibility: "hidden",
636
- margin: 0
637
- };
638
- /**
639
- * Fixed-position style for a panel anchored to an element, clamped to the
640
- * viewport with an 8px gutter and flipped above the anchor when it fits
641
- * better there.
642
- */
643
- function computeAnchoredStyle(anchor, options = {}) {
644
- if (!anchor) return HIDDEN_PANEL_STYLE;
645
- const { align = "start", minWidth = 0, matchAnchorWidth = false, offset = 4, flipThreshold = 250, zIndex = 9999 } = options;
646
- const rect = anchor.getBoundingClientRect();
647
- const width = Math.max(matchAnchorWidth ? rect.width : 0, minWidth);
648
- const left = align === "end" ? Math.max(8, Math.min(rect.right - width, window.innerWidth - width - 8)) : Math.max(8, Math.min(rect.left, window.innerWidth - width - 8));
649
- const spaceBelow = window.innerHeight - rect.bottom;
650
- if (spaceBelow < flipThreshold && rect.top > spaceBelow) return {
651
- position: "fixed",
652
- left: `${left}px`,
653
- width: `${width}px`,
654
- bottom: `${window.innerHeight - rect.top + offset}px`,
655
- top: "auto",
656
- margin: 0,
657
- zIndex,
658
- visibility: "visible"
659
- };
660
- return {
661
- position: "fixed",
662
- left: `${left}px`,
663
- width: `${width}px`,
664
- top: `${rect.bottom + offset}px`,
665
- bottom: "auto",
666
- margin: 0,
667
- zIndex,
668
- visibility: "visible"
669
- };
670
- }
671
- function useFloatingPanel(options = {}) {
672
- const [open, setOpenState] = (0, react.useState)(false);
673
- const [panelStyle, setPanelStyle] = (0, react.useState)(HIDDEN_PANEL_STYLE);
674
- const containerRef = (0, react.useRef)(null);
675
- const panelRef = (0, react.useRef)(null);
676
- const optionsRef = (0, react.useRef)(options);
677
- optionsRef.current = options;
678
- const anchored = !!options.computeStyle;
679
- const dismissEvent = options.dismissEvent ?? "pointerdown";
680
- const setOpen = (0, react.useCallback)((next) => {
681
- setOpenState(next);
682
- if (!next) optionsRef.current.onClose?.();
683
- optionsRef.current.onOpenChange?.(next);
684
- }, []);
685
- const applyStyle = (0, react.useCallback)(() => {
686
- const compute = optionsRef.current.computeStyle;
687
- if (!compute) return;
688
- const style = compute(containerRef.current);
689
- if (style) setPanelStyle(style);
690
- }, []);
691
- const openPanel = (0, react.useCallback)(() => {
692
- applyStyle();
693
- setOpen(true);
694
- }, [applyStyle, setOpen]);
695
- const toggle = (0, react.useCallback)(() => open ? setOpen(false) : openPanel(), [
694
+ //#region packages/ui/AppDropdown.tsx
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 }) {
696
+ const generatedId = (0, react.useId)();
697
+ const id = idProp ?? generatedId;
698
+ const container = useOverlayContainer();
699
+ const [open, setOpen] = (0, react.useState)(false);
700
+ const selected = options.find((option) => option.value === value);
701
+ const labelled = !!label && (showFieldLabel || variant === "toolbar");
702
+ const message = error ?? helpText;
703
+ const iconClass = icon?.startsWith("ph ") ? icon : icon?.startsWith("ph-") ? `ph ${icon}` : `ph ph-${icon}`;
704
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_base_ui_react_select.Select.Root, {
705
+ value,
706
+ onValueChange: (next) => {
707
+ if (next !== null) onChange(next);
708
+ },
709
+ disabled,
696
710
  open,
697
- openPanel,
698
- setOpen
699
- ]);
711
+ onOpenChange: (next) => {
712
+ setOpen(next);
713
+ onOpenChange?.(next);
714
+ },
715
+ modal: false,
716
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
717
+ className: showFieldLabel && variant !== "toolbar" ? "nb-form-field" : void 0,
718
+ children: [
719
+ showFieldLabel && variant !== "toolbar" && label && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("label", {
720
+ className: "nb-form-field__label",
721
+ id: `${id}-label`,
722
+ htmlFor: id,
723
+ children: label
724
+ }),
725
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
726
+ className: [
727
+ "nb-dropdown",
728
+ `nb-dropdown--${variant}`,
729
+ open && "nb-dropdown--open",
730
+ disabled && "nb-dropdown--disabled",
731
+ className
732
+ ].filter(Boolean).join(" "),
733
+ children: [
734
+ variant === "toolbar" && label && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
735
+ className: "nb-dropdown__toolbar-label",
736
+ id: `${id}-label`,
737
+ children: [icon && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("i", {
738
+ className: iconClass,
739
+ "aria-hidden": "true"
740
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: label })]
741
+ }),
742
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_base_ui_react_select.Select.Trigger, {
743
+ id,
744
+ className: "nb-dropdown__trigger",
745
+ onKeyDownCapture: (event) => {
746
+ if (open && event.key === "Escape") {
747
+ event.preventDefault();
748
+ event.stopPropagation();
749
+ setOpen(false);
750
+ onOpenChange?.(false);
751
+ }
752
+ },
753
+ "aria-label": ariaLabel,
754
+ "aria-labelledby": ariaLabel ? void 0 : labelled ? `${id}-label ${id}-value` : `${id}-value`,
755
+ "aria-describedby": message ? `${id}-message` : void 0,
756
+ "aria-invalid": !!error || void 0,
757
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
758
+ className: "nb-dropdown__value",
759
+ id: `${id}-value`,
760
+ children: selected?.selectedLabel ?? selected?.label ?? placeholder
761
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("i", {
762
+ className: "ph ph-caret-down nb-dropdown__caret",
763
+ "aria-hidden": "true"
764
+ })]
765
+ }),
766
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_base_ui_react_select.Select.Portal, {
767
+ container: container ?? void 0,
768
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_base_ui_react_select.Select.Positioner, {
769
+ align: "start",
770
+ sideOffset: 4,
771
+ alignItemWithTrigger: false,
772
+ className: "nb-dropdown-positioner",
773
+ style: { minWidth: menuMinWidth },
774
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_base_ui_react_select.Select.Popup, {
775
+ onKeyDownCapture: (event) => {
776
+ if (event.key === "Escape") {
777
+ event.preventDefault();
778
+ event.stopPropagation();
779
+ setOpen(false);
780
+ onOpenChange?.(false);
781
+ }
782
+ },
783
+ className: `nb-dropdown__menu nb-dropdown__menu--${variant}`,
784
+ children: [
785
+ menuHeader,
786
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_base_ui_react_select.Select.List, {
787
+ className: "nb-dropdown__menu-list",
788
+ children: options.map((option) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_base_ui_react_select.Select.Item, {
789
+ value: option.value,
790
+ label: option.label,
791
+ disabled: option.disabled,
792
+ className: ({ selected }) => `nb-dropdown__option${selected ? " nb-dropdown__option--active" : ""}`,
793
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_base_ui_react_select.Select.ItemText, {
794
+ className: "nb-dropdown__option-content",
795
+ children: [option.iconText && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
796
+ className: "nb-dropdown__option-icon",
797
+ "aria-hidden": "true",
798
+ children: option.iconText
799
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: option.label })]
800
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_base_ui_react_select.Select.ItemIndicator, {
801
+ className: "nb-dropdown__selected",
802
+ "aria-hidden": "true",
803
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("i", { className: "ph ph-check" })
804
+ })]
805
+ }, option.value))
806
+ }),
807
+ menuFooter
808
+ ]
809
+ })
810
+ })
811
+ })
812
+ ]
813
+ }),
814
+ message && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
815
+ id: `${id}-message`,
816
+ className: error ? "nb-form-field__error" : "nb-form-field__help",
817
+ role: error ? "alert" : void 0,
818
+ children: message
819
+ })
820
+ ]
821
+ })
822
+ });
823
+ }
824
+ //#endregion
825
+ //#region packages/ui/useComboboxOptions.ts
826
+ function mergeOptions(...groups) {
827
+ const map = /* @__PURE__ */ new Map();
828
+ for (const group of groups) for (const option of group) map.set(option.value, option);
829
+ return [...map.values()];
830
+ }
831
+ function useComboboxOptions({ options, selected, loadOptions, open, query, debounceMs, minSearchLength }) {
832
+ const [state, setState] = (0, react.useState)({
833
+ query: "",
834
+ options: [],
835
+ known: [],
836
+ loading: false,
837
+ failed: false
838
+ });
839
+ const [revision, setRevision] = (0, react.useState)(0);
840
+ const generation = (0, react.useRef)(0);
841
+ const request = (0, react.useRef)(null);
842
+ const normalizedQuery = query.trim();
843
+ const eligible = normalizedQuery.length >= minSearchLength;
700
844
  (0, react.useEffect)(() => {
701
- if (!open) return;
702
- const handleOutside = (e) => {
703
- const target = e.target;
704
- if (containerRef.current?.contains(target) || panelRef.current?.contains(target)) return;
705
- setOpen(false);
706
- };
707
- const handleKeyDown = (e) => {
708
- if (e.key !== "Escape") return;
709
- setOpen(false);
710
- optionsRef.current.onEscape?.(e);
711
- };
712
- document.addEventListener(dismissEvent, handleOutside);
713
- document.addEventListener("keydown", handleKeyDown);
845
+ const currentGeneration = ++generation.current;
846
+ request.current?.abort();
847
+ request.current = null;
848
+ if (!loadOptions || !open || !eligible) return;
849
+ const controller = new AbortController();
850
+ request.current = controller;
851
+ const timer = setTimeout(async () => {
852
+ setState((previous) => ({
853
+ loader: loadOptions,
854
+ query: normalizedQuery,
855
+ options: [],
856
+ known: previous.loader === loadOptions ? previous.known : [],
857
+ loading: true,
858
+ failed: false
859
+ }));
860
+ try {
861
+ const page = await loadOptions(normalizedQuery, { signal: controller.signal });
862
+ if (controller.signal.aborted || generation.current !== currentGeneration) return;
863
+ setState((previous) => ({
864
+ loader: loadOptions,
865
+ query: normalizedQuery,
866
+ options: mergeOptions(page.options),
867
+ known: mergeOptions(previous.known, page.options),
868
+ nextCursor: page.nextCursor,
869
+ loading: false,
870
+ failed: false
871
+ }));
872
+ } catch {
873
+ if (controller.signal.aborted || generation.current !== currentGeneration) return;
874
+ setState((previous) => ({
875
+ ...previous,
876
+ loading: false,
877
+ failed: true
878
+ }));
879
+ } finally {
880
+ if (request.current === controller) request.current = null;
881
+ }
882
+ }, Math.max(0, debounceMs));
714
883
  return () => {
715
- document.removeEventListener(dismissEvent, handleOutside);
716
- document.removeEventListener("keydown", handleKeyDown);
884
+ clearTimeout(timer);
885
+ controller.abort();
717
886
  };
718
887
  }, [
719
- dismissEvent,
888
+ loadOptions,
720
889
  open,
721
- setOpen
890
+ normalizedQuery,
891
+ eligible,
892
+ debounceMs,
893
+ revision
722
894
  ]);
723
- (0, react.useLayoutEffect)(() => {
724
- if (!open || !anchored) return;
725
- const update = () => {
726
- const container = containerRef.current;
727
- if (!container) return;
728
- if (optionsRef.current.closeOnViewportExit) {
729
- const rect = container.getBoundingClientRect();
730
- if ((rect.width > 0 || rect.height > 0) && (rect.top >= window.innerHeight || rect.bottom <= 0)) {
731
- setOpen(false);
732
- return;
733
- }
734
- }
735
- applyStyle();
736
- };
737
- update();
738
- window.addEventListener("resize", update);
739
- window.addEventListener("scroll", update, {
740
- capture: true,
741
- passive: true
742
- });
743
- return () => {
744
- window.removeEventListener("resize", update);
745
- window.removeEventListener("scroll", update, { capture: true });
746
- };
895
+ const current = state.loader === loadOptions && state.query === normalizedQuery;
896
+ const loading = !!loadOptions && open && eligible && (!current || state.loading);
897
+ const failed = !!loadOptions && open && current && state.failed;
898
+ const known = mergeOptions(options, state.loader === loadOptions ? state.known : []);
899
+ const pinned = known.filter((option) => selected.includes(option.value));
900
+ const items = loadOptions ? mergeOptions(pinned, current && eligible ? state.options : []) : options;
901
+ const loadMore = (0, react.useCallback)(async () => {
902
+ if (!loadOptions || !open || !current || state.loading || request.current || state.nextCursor == null || !eligible) return;
903
+ const controller = new AbortController();
904
+ const currentGeneration = generation.current;
905
+ request.current = controller;
906
+ setState((previous) => ({
907
+ ...previous,
908
+ loading: true,
909
+ failed: false
910
+ }));
911
+ try {
912
+ const page = await loadOptions(normalizedQuery, {
913
+ signal: controller.signal,
914
+ cursor: state.nextCursor
915
+ });
916
+ if (controller.signal.aborted || currentGeneration !== generation.current) return;
917
+ setState((previous) => ({
918
+ ...previous,
919
+ options: mergeOptions(previous.options, page.options),
920
+ known: mergeOptions(previous.known, page.options),
921
+ nextCursor: page.nextCursor,
922
+ loading: false,
923
+ failed: false
924
+ }));
925
+ } catch {
926
+ if (controller.signal.aborted || currentGeneration !== generation.current) return;
927
+ setState((previous) => ({
928
+ ...previous,
929
+ loading: false,
930
+ failed: true
931
+ }));
932
+ } finally {
933
+ if (request.current === controller) request.current = null;
934
+ }
747
935
  }, [
748
- anchored,
749
- applyStyle,
936
+ loadOptions,
750
937
  open,
751
- setOpen
938
+ current,
939
+ state.loading,
940
+ state.nextCursor,
941
+ eligible,
942
+ normalizedQuery
752
943
  ]);
753
- return {
944
+ (0, react.useEffect)(() => () => {
945
+ request.current?.abort();
946
+ }, [
754
947
  open,
755
- setOpen,
756
- toggle,
757
- openPanel,
758
- containerRef,
759
- panelRef,
760
- panelStyle
948
+ normalizedQuery,
949
+ loadOptions
950
+ ]);
951
+ return {
952
+ items,
953
+ known,
954
+ loading,
955
+ failed,
956
+ eligible,
957
+ hasMore: !!loadOptions && open && eligible && current && state.nextCursor != null,
958
+ loadMore,
959
+ retry: () => setRevision((previous) => previous + 1)
761
960
  };
762
961
  }
763
962
  //#endregion
764
- //#region packages/ui/AppDropdown.tsx
765
- function cx$2(...values) {
766
- return values.filter(Boolean).join(" ");
767
- }
768
- function normalizeIcon$2(icon) {
769
- if (!icon) return void 0;
770
- if (icon.startsWith("ph ")) return icon;
771
- if (icon.startsWith("ph-")) return `ph ${icon}`;
772
- return `ph ph-${icon}`;
773
- }
774
- function AppDropdown({ id: idProp, label, icon, value, options, onChange, disabled = false, placeholder = "Seleccionar…", variant = "form", className, showFieldLabel = variant === "form", menuMinWidth, error, helpText, menuHeader, menuFooter, onOpenChange }) {
775
- const generatedId = (0, react.useId)();
776
- const id = idProp ?? generatedId;
777
- const { open, setOpen: setMenuOpen, openPanel: openMenu, containerRef, panelRef: menuRef, panelStyle: menuStyle } = useFloatingPanel({
778
- onOpenChange,
779
- dismissEvent: "mousedown",
780
- closeOnViewportExit: true,
781
- computeStyle: (container) => {
782
- return computeAnchoredStyle(container?.querySelector(".nb-dropdown__trigger") ?? container, {
783
- matchAnchorWidth: true,
784
- minWidth: menuMinWidth ?? 72
785
- });
786
- }
963
+ //#region packages/ui/Combobox.tsx
964
+ const Combobox = (0, react.forwardRef)(function Combobox(props, ref) {
965
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(SelectionCombobox, {
966
+ ...props,
967
+ inputRef: ref,
968
+ multiple: false,
969
+ onChange: (value) => props.onChange(typeof value === "string" ? value : null)
787
970
  });
788
- const selected = options.find((option) => option.value === value);
789
- const control = /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
790
- ref: containerRef,
791
- className: cx$2("nb-dropdown", `nb-dropdown--${variant}`, open && "nb-dropdown--open", disabled && "nb-dropdown--disabled", className),
792
- role: "group",
793
- "aria-labelledby": label ? `${id}-label` : void 0,
971
+ });
972
+ const MultiSelect = (0, react.forwardRef)(function MultiSelect(props, ref) {
973
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(SelectionCombobox, {
974
+ ...props,
975
+ inputRef: ref,
976
+ multiple: true,
977
+ onChange: (value) => props.onChange(Array.isArray(value) ? value : [])
978
+ });
979
+ });
980
+ function SelectionCombobox({ options, value, onChange, label, error, helpText, invalid = false, clearable = true, emptyMessage, openLabel, clearLabel, id, name, disabled, readOnly, required, form, className, inputClassName, "aria-describedby": describedBy, loadOptions, debounceMs = 250, minSearchLength = 0, loadingMessage, searchErrorMessage, onOpenChange, multiple, inputRef, selectedLabel, removeLabel, ...inputProps }) {
981
+ const overlayContainer = useOverlayContainer();
982
+ const generatedId = (0, react.useId)();
983
+ const inputId = id ?? generatedId;
984
+ const strings = useUiStrings();
985
+ const [open, setOpen] = (0, react.useState)(false);
986
+ const [query, setQuery] = (0, react.useState)("");
987
+ const selected = Array.isArray(value) ? value : value === null ? [] : [value];
988
+ const remote = useComboboxOptions({
989
+ options,
990
+ selected,
991
+ loadOptions,
992
+ open: open && !disabled && !readOnly,
993
+ query,
994
+ debounceMs,
995
+ minSearchLength
996
+ });
997
+ const message = error ?? helpText;
998
+ const messageId = `${inputId}-message`;
999
+ const description = [describedBy, message ? messageId : void 0].filter(Boolean).join(" ") || void 0;
1000
+ const selectedOptions = selected.map((key) => remote.known.find((option) => option.value === key) ?? {
1001
+ value: key,
1002
+ label: key
1003
+ });
1004
+ const remoteStatus = remote.failed ? searchErrorMessage ?? strings.searchFailed : remote.loading ? loadingMessage ?? strings.searching : !remote.eligible && loadOptions ? strings.enterSearch : void 0;
1005
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_aria_components.ComboBox, {
1006
+ ...loadOptions ? { items: remote.items } : { defaultItems: options },
1007
+ selectionMode: multiple ? "multiple" : "single",
1008
+ value,
1009
+ onChange: (keys) => onChange(Array.isArray(keys) ? keys.map(String) : keys === null ? null : String(keys)),
1010
+ onInputChange: setQuery,
1011
+ onOpenChange: (nextOpen, trigger) => {
1012
+ setOpen(nextOpen);
1013
+ onOpenChange?.(nextOpen);
1014
+ if (!nextOpen || trigger !== "input") setQuery("");
1015
+ },
1016
+ name,
1017
+ form,
1018
+ isDisabled: disabled,
1019
+ isReadOnly: readOnly,
1020
+ isRequired: required,
1021
+ isInvalid: invalid || !!error,
1022
+ allowsEmptyCollection: true,
1023
+ "aria-label": inputProps["aria-label"],
1024
+ "aria-labelledby": inputProps["aria-labelledby"],
1025
+ className: `nb-form-field${className ? ` ${className}` : ""}`,
794
1026
  children: [
795
- variant === "toolbar" && label && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
796
- className: "nb-dropdown__toolbar-label",
797
- id: `${id}-label`,
798
- children: [icon && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("i", {
799
- className: normalizeIcon$2(icon),
800
- "aria-hidden": "true"
801
- }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: label })]
1027
+ label && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_aria_components.Label, {
1028
+ className: "nb-form-field__label",
1029
+ children: label
802
1030
  }),
803
- /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
804
- type: "button",
805
- className: "nb-dropdown__trigger",
806
- "aria-haspopup": "listbox",
807
- "aria-expanded": open,
808
- "aria-labelledby": label ? `${id}-label ${id}-value` : `${id}-value`,
809
- disabled,
810
- onClick: () => open ? setMenuOpen(false) : openMenu(),
811
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
812
- className: "nb-dropdown__value",
813
- id: `${id}-value`,
814
- children: selected?.selectedLabel ?? selected?.label ?? placeholder
815
- }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("i", {
816
- className: "ph ph-caret-down nb-dropdown__caret",
817
- "aria-hidden": "true"
818
- })]
1031
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1032
+ className: "nb-combobox",
1033
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(ComboboxInput, {
1034
+ ...inputProps,
1035
+ openOnClick: !disabled && !readOnly,
1036
+ ref: inputRef,
1037
+ id: inputId,
1038
+ className: `nb-input nb-combobox__input${invalid || error ? " nb-input--invalid" : ""}${inputClassName ? ` ${inputClassName}` : ""}`,
1039
+ onKeyDown: (event) => {
1040
+ inputProps.onKeyDown?.(event);
1041
+ if (open && event.key === "Escape") event.stopPropagation();
1042
+ if (!event.defaultPrevented && event.key === "PageDown" && remote.hasMore) {
1043
+ event.preventDefault();
1044
+ remote.loadMore();
1045
+ }
1046
+ },
1047
+ "aria-invalid": inputProps["aria-invalid"] ?? (invalid || !!error || void 0),
1048
+ "aria-describedby": description
1049
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1050
+ className: "nb-combobox__actions",
1051
+ children: [clearable && !readOnly && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ComboboxClear, {
1052
+ label: clearLabel ?? strings.clear,
1053
+ disabled,
1054
+ multiple
1055
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_aria_components.Button, {
1056
+ className: "nb-combobox__action",
1057
+ "aria-label": openLabel ?? strings.openOptions,
1058
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("svg", {
1059
+ viewBox: "0 0 24 24",
1060
+ "aria-hidden": "true",
1061
+ focusable: "false",
1062
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", { d: "m6 9 6 6 6-6" })
1063
+ })
1064
+ })]
1065
+ })]
819
1066
  }),
820
- open && !disabled && (0, react_dom.createPortal)(/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
821
- ref: menuRef,
822
- className: cx$2("nb-dropdown__menu", `nb-dropdown__menu--${variant}`),
823
- style: menuStyle,
1067
+ multiple && selectedOptions.length > 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_aria_components.ComboBoxValue, { children: () => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_aria_components.TagGroup, {
1068
+ "aria-label": selectedLabel ?? strings.selectedOptions,
1069
+ onRemove: disabled || readOnly ? void 0 : (keys) => onChange(selected.filter((key) => !keys.has(key))),
1070
+ className: "nb-combobox-tags",
1071
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_aria_components.TagList, {
1072
+ items: selectedOptions,
1073
+ children: (option) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_aria_components.Tag, {
1074
+ id: option.value,
1075
+ textValue: option.label,
1076
+ className: "nb-combobox-tags__tag",
1077
+ children: [option.label, !disabled && !readOnly && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_aria_components.Button, {
1078
+ slot: "remove",
1079
+ className: "nb-combobox-tags__remove",
1080
+ "aria-label": removeLabel?.(option) ?? strings.removeOption,
1081
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("svg", {
1082
+ viewBox: "0 0 24 24",
1083
+ "aria-hidden": "true",
1084
+ focusable: "false",
1085
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", { d: "m6 6 12 12M18 6 6 18" })
1086
+ })
1087
+ })]
1088
+ })
1089
+ })
1090
+ }) }),
1091
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_aria_components.Popover, {
1092
+ UNSTABLE_portalContainer: overlayContainer ?? void 0,
1093
+ className: "nb-combobox-popup",
1094
+ offset: 4,
1095
+ isNonModal: true,
1096
+ onScroll: (event) => {
1097
+ const panel = event.currentTarget;
1098
+ if (panel.scrollHeight - panel.scrollTop <= panel.clientHeight + 20) remote.loadMore();
1099
+ },
824
1100
  children: [
825
- menuHeader,
826
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("ul", {
827
- role: "listbox",
828
- "aria-labelledby": label ? `${id}-label` : void 0,
829
- className: "nb-dropdown__menu-list",
830
- children: options.map((option) => {
831
- const isActive = option.value === value;
832
- return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("li", {
833
- role: "presentation",
834
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
835
- type: "button",
836
- role: "option",
837
- "aria-selected": isActive,
838
- disabled: option.disabled,
839
- className: cx$2("nb-dropdown__option", isActive && "nb-dropdown__option--active"),
840
- onClick: () => {
841
- if (option.disabled) return;
842
- onChange(option.value);
843
- setMenuOpen(false);
844
- },
845
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
846
- className: "nb-dropdown__option-content",
847
- children: [option.iconText && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
848
- className: "nb-dropdown__option-icon",
849
- "aria-hidden": "true",
850
- children: option.iconText
851
- }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: option.label })]
852
- })
853
- })
854
- }, option.value);
1101
+ remoteStatus && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
1102
+ className: "nb-combobox-popup__empty",
1103
+ role: remote.failed ? "alert" : "status",
1104
+ children: remoteStatus
1105
+ }),
1106
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_aria_components.ListBox, {
1107
+ className: "nb-combobox-popup__list",
1108
+ "aria-busy": remote.loading || void 0,
1109
+ renderEmptyState: () => remoteStatus ? null : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
1110
+ className: "nb-combobox-popup__empty",
1111
+ children: emptyMessage ?? strings.noOptions
1112
+ }),
1113
+ children: (option) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_aria_components.ListBoxItem, {
1114
+ id: option.value,
1115
+ textValue: option.label,
1116
+ isDisabled: option.disabled,
1117
+ className: "nb-combobox-popup__item",
1118
+ children: ({ isSelected }) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1119
+ className: "nb-combobox-popup__indicator",
1120
+ "aria-hidden": "true",
1121
+ children: isSelected ? "✓" : ""
1122
+ }), option.content ?? option.label] })
855
1123
  })
856
1124
  }),
857
- menuFooter
1125
+ remote.hasMore && !remote.failed && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_aria_components.Button, {
1126
+ slot: null,
1127
+ className: "nb-combobox__action",
1128
+ isDisabled: remote.loading,
1129
+ onPress: () => {
1130
+ remote.loadMore();
1131
+ },
1132
+ children: strings.loadMore
1133
+ }),
1134
+ remote.failed && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_aria_components.Button, {
1135
+ className: "nb-combobox__action",
1136
+ onPress: remote.retry,
1137
+ children: strings.retrySearch
1138
+ })
858
1139
  ]
859
- }), document.body)
860
- ]
861
- });
862
- if (!showFieldLabel || variant === "toolbar") return control;
863
- return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("label", {
864
- className: cx$2("nb-form-field", !!error && "nb-form-field--error"),
865
- htmlFor: id,
866
- children: [
867
- label && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
868
- className: "nb-form-field__label",
869
- id: `${id}-label`,
870
- children: label
871
1140
  }),
872
- control,
873
- error ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
874
- className: "nb-form-field__error",
875
- role: "alert",
876
- children: error
877
- }) : helpText ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
878
- className: "nb-form-field__help",
879
- children: helpText
880
- }) : null
1141
+ message && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1142
+ id: messageId,
1143
+ className: error ? "nb-form-field__error" : "nb-form-field__help",
1144
+ role: error ? "alert" : void 0,
1145
+ children: message
1146
+ })
881
1147
  ]
882
1148
  });
883
1149
  }
1150
+ /**
1151
+ * Editable combobox input that also opens its list on click. React Aria opens
1152
+ * on typing or ArrowDown by default; users expect a click on a dropdown-style
1153
+ * field to show the options. Keyboard behaviour is unchanged (no open on focus).
1154
+ */
1155
+ const ComboboxInput = (0, react.forwardRef)(function ComboboxInput({ onClick, openOnClick, ...props }, ref) {
1156
+ const state = (0, react.useContext)(react_aria_components.ComboBoxStateContext);
1157
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_aria_components.Input, {
1158
+ ...props,
1159
+ ref,
1160
+ onClick: (event) => {
1161
+ onClick?.(event);
1162
+ if (!openOnClick || event.defaultPrevented || !state || state.isOpen) return;
1163
+ state.open(null, "manual");
1164
+ }
1165
+ });
1166
+ });
1167
+ function ComboboxClear({ label, disabled, multiple }) {
1168
+ const state = (0, react.useContext)(react_aria_components.ComboBoxStateContext);
1169
+ const hasValue = multiple ? Array.isArray(state?.value) && state.value.length > 0 : !!state?.inputValue;
1170
+ if (!state || !hasValue || state.isOpen) return null;
1171
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_aria_components.Button, {
1172
+ slot: null,
1173
+ isDisabled: disabled,
1174
+ className: "nb-combobox__action nb-combobox__clear",
1175
+ "aria-label": label,
1176
+ onPress: () => {
1177
+ state.setValue(multiple ? [] : null);
1178
+ state.setInputValue("");
1179
+ },
1180
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("svg", {
1181
+ viewBox: "0 0 24 24",
1182
+ "aria-hidden": "true",
1183
+ focusable: "false",
1184
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", { d: "m6 6 12 12M18 6 6 18" })
1185
+ })
1186
+ });
1187
+ }
884
1188
  //#endregion
885
1189
  //#region packages/ui/SearchableAppDropdown.tsx
886
- function normalizeSearch(value) {
887
- return value.trim().toLowerCase();
888
- }
889
- function filterOptions(options, query) {
890
- const needle = normalizeSearch(query);
891
- if (!needle) return options;
892
- return options.filter((option) => {
893
- return [
894
- option.label,
895
- option.selectedLabel,
896
- option.value
897
- ].filter(Boolean).join(" ").toLowerCase().includes(needle);
898
- });
899
- }
900
- function SearchableAppDropdown({ options = [], searchable = true, searchPlaceholder = "Buscar…", onSearch, minSearchLength = 2, emptySearchLabel = "Sin resultados", loadingLabel = "Buscando…", selectedOption = null, value, onChange, placeholder, disabled, ...rest }) {
901
- const searchInputId = (0, react.useId)();
902
- const [open, setOpen] = (0, react.useState)(false);
903
- const [searchQuery, setSearchQuery] = (0, react.useState)("");
904
- const [remoteOptions, setRemoteOptions] = (0, react.useState)([]);
905
- const [loading, setLoading] = (0, react.useState)(false);
906
- const requestIdRef = (0, react.useRef)(0);
907
- const staticSelected = (0, react.useMemo)(() => options.find((option) => option.value === value) ?? selectedOption ?? null, [
908
- options,
909
- selectedOption,
910
- value
911
- ]);
912
- const resolvedOptions = (0, react.useMemo)(() => {
913
- const merged = /* @__PURE__ */ new Map();
914
- for (const option of [...options, ...remoteOptions]) if (option.value) merged.set(option.value, option);
915
- if (staticSelected?.value) merged.set(staticSelected.value, staticSelected);
916
- const base = Array.from(merged.values()).filter((option) => option.value !== "");
917
- if (!searchable) return base;
918
- if (onSearch) return base;
919
- return filterOptions(base, searchQuery);
920
- }, [
921
- onSearch,
922
- options,
923
- remoteOptions,
924
- searchable,
925
- searchQuery,
926
- staticSelected
927
- ]);
928
- const runSearch = (0, react.useCallback)(async (query) => {
929
- if (!onSearch) return;
930
- const trimmed = query.trim();
931
- if (trimmed.length < minSearchLength) {
932
- setRemoteOptions([]);
933
- setLoading(false);
934
- return;
935
- }
936
- const requestId = ++requestIdRef.current;
937
- setLoading(true);
938
- try {
939
- const results = await onSearch(trimmed);
940
- if (requestId !== requestIdRef.current) return;
941
- setRemoteOptions(results.filter((option) => option.value !== ""));
942
- } catch {
943
- if (requestId !== requestIdRef.current) return;
944
- setRemoteOptions([]);
945
- } finally {
946
- if (requestId === requestIdRef.current) setLoading(false);
947
- }
948
- }, [minSearchLength, onSearch]);
949
- (0, react.useEffect)(() => {
950
- if (!open || !onSearch) return;
951
- const timer = window.setTimeout(() => {
952
- runSearch(searchQuery);
953
- }, 250);
954
- return () => window.clearTimeout(timer);
955
- }, [
956
- open,
957
- onSearch,
958
- runSearch,
959
- searchQuery
960
- ]);
961
- (0, react.useEffect)(() => {
962
- if (open) return;
963
- setSearchQuery("");
964
- setRemoteOptions([]);
965
- setLoading(false);
966
- }, [open]);
967
- const menuHeader = searchable ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
968
- className: "nb-searchable-dropdown__search",
969
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("i", {
970
- className: "ph ph-magnifying-glass",
971
- "aria-hidden": "true"
972
- }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
973
- id: searchInputId,
974
- type: "search",
975
- value: searchQuery,
976
- onChange: (event) => setSearchQuery(event.target.value),
977
- placeholder: searchPlaceholder,
978
- autoComplete: "off",
979
- onKeyDown: (event) => event.stopPropagation()
980
- })]
981
- }) : null;
982
- const menuFooter = (() => {
983
- if (!searchable || !onSearch) return null;
984
- if (loading) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
985
- className: "nb-searchable-dropdown__status",
986
- children: loadingLabel
987
- });
988
- if (searchQuery.trim().length < minSearchLength) return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
989
- className: "nb-searchable-dropdown__status",
990
- children: [
991
- "Escribe al menos ",
992
- minSearchLength,
993
- " caracteres"
994
- ]
995
- });
996
- if (resolvedOptions.length === 0) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
997
- className: "nb-searchable-dropdown__status",
998
- children: emptySearchLabel
999
- });
1000
- return null;
1001
- })();
1002
- return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(AppDropdown, {
1190
+ const toOption = (option) => ({
1191
+ value: option.value,
1192
+ label: option.selectedLabel ?? option.label,
1193
+ disabled: option.disabled,
1194
+ content: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
1195
+ className: "nb-dropdown__option-content",
1196
+ children: [option.iconText && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1197
+ className: "nb-dropdown__option-icon",
1198
+ "aria-hidden": "true",
1199
+ children: option.iconText
1200
+ }), option.label]
1201
+ })
1202
+ });
1203
+ function SearchableAppDropdown({ options = [], searchable = true, searchPlaceholder = "Buscar…", onSearch, minSearchLength = 2, emptySearchLabel = "Sin resultados", loadingLabel = "Buscando…", selectedOption, value, onChange, placeholder, disabled, label, showFieldLabel, variant, icon: _icon, menuMinWidth: _menuMinWidth, menuHeader: _header, menuFooter: _footer, ...rest }) {
1204
+ const loadOptions = (0, react.useCallback)(async (query, { signal }) => {
1205
+ const results = await onSearch(query.trim());
1206
+ if (signal.aborted) throw new DOMException("Search cancelled", "AbortError");
1207
+ return { options: results.map(toOption) };
1208
+ }, [onSearch]);
1209
+ if (!searchable) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(AppDropdown, {
1003
1210
  ...rest,
1211
+ options,
1004
1212
  value,
1005
1213
  onChange,
1006
1214
  placeholder,
1007
1215
  disabled,
1008
- options: [{
1009
- value: "",
1010
- label: placeholder ?? "Seleccionar…"
1011
- }, ...resolvedOptions],
1012
- menuHeader,
1013
- menuFooter,
1014
- onOpenChange: setOpen
1216
+ label,
1217
+ showFieldLabel,
1218
+ variant,
1219
+ icon: _icon,
1220
+ menuMinWidth: _menuMinWidth,
1221
+ menuHeader: _header,
1222
+ menuFooter: _footer
1223
+ });
1224
+ const seeds = selectedOption && !options.some((option) => option.value === selectedOption.value) ? [...options, selectedOption] : options;
1225
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Combobox, {
1226
+ ...rest,
1227
+ label: showFieldLabel === false ? void 0 : label,
1228
+ "aria-label": showFieldLabel === false && typeof label === "string" ? label : void 0,
1229
+ placeholder: placeholder ?? searchPlaceholder,
1230
+ options: seeds.map(toOption),
1231
+ value: value || null,
1232
+ onChange: (next) => onChange(next ?? ""),
1233
+ disabled,
1234
+ loadOptions: onSearch ? loadOptions : void 0,
1235
+ minSearchLength,
1236
+ emptyMessage: emptySearchLabel,
1237
+ loadingMessage: loadingLabel
1015
1238
  });
1016
1239
  }
1017
1240
  //#endregion
@@ -1074,7 +1297,7 @@ function applyThemeAttributes(theme, themePrefix) {
1074
1297
  themeValues.forEach((value) => root.classList.remove(`${themePrefix}${value}`));
1075
1298
  root.classList.add(`${themePrefix}${theme}`);
1076
1299
  }
1077
- const ThemeProvider = ({ storageKey = "nb-theme", themePrefix = "nb-theme-", basePath = "/themes/", children }) => {
1300
+ const ThemeProvider = ({ storageKey = "nb-theme", themePrefix = "nb-theme-", basePath = "/themes/", visualStyle = "default", children }) => {
1078
1301
  const getPersistedMode = () => {
1079
1302
  const persisted = window.localStorage.getItem(storageKey);
1080
1303
  return persisted && themeModes.includes(persisted) ? persisted : "auto";
@@ -1083,6 +1306,15 @@ const ThemeProvider = ({ storageKey = "nb-theme", themePrefix = "nb-theme-", bas
1083
1306
  const [systemTheme, setSystemTheme] = (0, react.useState)(getSystemTheme);
1084
1307
  const [isLoaded, setIsLoaded] = (0, react.useState)(false);
1085
1308
  const theme = (0, react.useMemo)(() => resolveTheme(mode, systemTheme), [mode, systemTheme]);
1309
+ (0, react.useEffect)(() => {
1310
+ const root = document.documentElement;
1311
+ const previous = root.getAttribute("data-visual-style");
1312
+ root.setAttribute("data-visual-style", visualStyle);
1313
+ return () => {
1314
+ if (previous === null) root.removeAttribute("data-visual-style");
1315
+ else root.setAttribute("data-visual-style", previous);
1316
+ };
1317
+ }, [visualStyle]);
1086
1318
  (0, react.useEffect)(() => {
1087
1319
  applyThemeAttributes(theme, themePrefix);
1088
1320
  setThemeToDOM(`${basePath}${themePrefix}${theme}.css`).then(() => setIsLoaded(true));
@@ -1425,7 +1657,7 @@ const DEFAULT_ICONS = {
1425
1657
  warning: "warning",
1426
1658
  success: "check-circle"
1427
1659
  };
1428
- const EmptyState = ({ icon, variant = "default", title, description, action, size = "md", fill = false, className }) => {
1660
+ const EmptyState = ({ icon, illustration, variant = "default", title, description, action, size = "md", fill = false, className }) => {
1429
1661
  const iconName = icon ?? DEFAULT_ICONS[variant];
1430
1662
  const classes = [
1431
1663
  "nb-empty-state",
@@ -1441,7 +1673,7 @@ const EmptyState = ({ icon, variant = "default", title, description, action, siz
1441
1673
  children: [
1442
1674
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
1443
1675
  className: "nb-empty-state__icon-wrap",
1444
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("i", {
1676
+ children: illustration ?? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("i", {
1445
1677
  className: `ph ph-${iconName}`,
1446
1678
  "aria-hidden": "true"
1447
1679
  })
@@ -1522,73 +1754,51 @@ const Toggle = ({ checked, onChange, label, size = "md", disabled = false, "aria
1522
1754
  };
1523
1755
  //#endregion
1524
1756
  //#region packages/ui/ContextMenu.tsx
1525
- const MENU_MIN_WIDTH = 190;
1526
- /**
1527
- * Three-dot overflow context menu.
1528
- * Replaces the legacy `shared/ui/library/card-menu/CardMenu` component.
1529
- *
1530
- * Features over CardMenu:
1531
- * - `danger` variant items
1532
- * - `separator` support
1533
- * - `icon` per item
1534
- * - Custom trigger slot
1535
- * - Left/right alignment
1536
- * - Click-outside + Escape to close
1537
- * - Portalled dropdown (avoids clip inside scrollable tables)
1538
- */
1539
1757
  const ContextMenu = ({ items, visible = true, trigger, triggerLabel = "Opciones", align = "right", className = "" }) => {
1540
- const { open, setOpen, toggle, containerRef, panelRef: menuRef, panelStyle: menuStyle } = useFloatingPanel({
1541
- dismissEvent: "mousedown",
1542
- closeOnViewportExit: true,
1543
- computeStyle: (container) => computeAnchoredStyle(container, {
1544
- align: align === "right" ? "end" : "start",
1545
- minWidth: MENU_MIN_WIDTH,
1546
- flipThreshold: 200,
1547
- zIndex: 1600
1548
- })
1549
- });
1758
+ const container = useOverlayContainer();
1759
+ const triggerRef = (0, react.useRef)(null);
1760
+ const restoreFocus = (0, react.useRef)(false);
1550
1761
  if (!visible) return null;
1551
- const dropdown = open ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("ul", {
1552
- ref: menuRef,
1553
- className: "nb-context-menu__dropdown nb-context-menu__dropdown--portaled",
1554
- role: "menu",
1555
- style: menuStyle,
1556
- children: items.map((item, idx) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react.default.Fragment, { children: [item.separator && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("li", {
1557
- role: "none",
1558
- "aria-hidden": "true",
1559
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", { className: "nb-context-menu__separator" })
1560
- }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("li", {
1561
- role: "none",
1562
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
1563
- type: "button",
1564
- role: "menuitem",
1565
- disabled: item.disabled,
1566
- "aria-disabled": item.disabled,
1567
- className: `nb-context-menu__item${item.danger ? " nb-context-menu__item--danger" : ""}`,
1568
- onClick: () => {
1569
- setOpen(false);
1570
- item.onClick?.();
1571
- },
1572
- children: [item.icon && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("i", {
1573
- className: item.icon,
1574
- "aria-hidden": "true"
1575
- }), item.label]
1576
- })
1577
- })] }, idx))
1578
- }) : null;
1579
- return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1580
- ref: containerRef,
1581
- className: `nb-context-menu${className ? ` ${className}` : ""}`,
1582
- children: [trigger ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1583
- onClick: toggle,
1584
- children: trigger
1585
- }) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(IconButton, {
1586
- icon: "ph ph-dots-three",
1587
- label: triggerLabel,
1588
- "aria-haspopup": "menu",
1589
- "aria-expanded": open,
1590
- onClick: toggle
1591
- }), dropdown && (0, react_dom.createPortal)(dropdown, document.body)]
1762
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_base_ui_react_menu.Menu.Root, {
1763
+ modal: false,
1764
+ onOpenChange: (open, details) => {
1765
+ restoreFocus.current = !open && (details.reason === "item-press" || details.reason === "escape-key");
1766
+ },
1767
+ onOpenChangeComplete: (open) => {
1768
+ if (!open && restoreFocus.current) triggerRef.current?.focus({ preventScroll: true });
1769
+ },
1770
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1771
+ className: `nb-context-menu${className ? ` ${className}` : ""}`,
1772
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_base_ui_react_menu.Menu.Trigger, {
1773
+ ref: triggerRef,
1774
+ render: (0, react.isValidElement)(trigger) ? trigger : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(IconButton, {
1775
+ icon: "ph ph-dots-three",
1776
+ label: triggerLabel,
1777
+ children: trigger
1778
+ })
1779
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_base_ui_react_menu.Menu.Portal, {
1780
+ container: container ?? void 0,
1781
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_base_ui_react_menu.Menu.Positioner, {
1782
+ align: align === "right" ? "end" : "start",
1783
+ sideOffset: 4,
1784
+ className: "nb-context-menu-positioner",
1785
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_base_ui_react_menu.Menu.Popup, {
1786
+ finalFocus: triggerRef,
1787
+ className: "nb-context-menu__dropdown",
1788
+ children: items.map((item, index) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react.default.Fragment, { children: [item.separator && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_base_ui_react_menu.Menu.Separator, { className: "nb-context-menu__separator" }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_base_ui_react_menu.Menu.Item, {
1789
+ disabled: item.disabled,
1790
+ label: item.label,
1791
+ className: `nb-context-menu__item${item.danger ? " nb-context-menu__item--danger" : ""}`,
1792
+ onClick: item.onClick,
1793
+ children: [item.icon && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("i", {
1794
+ className: item.icon,
1795
+ "aria-hidden": "true"
1796
+ }), item.label]
1797
+ })] }, index))
1798
+ })
1799
+ })
1800
+ })]
1801
+ })
1592
1802
  });
1593
1803
  };
1594
1804
  //#endregion
@@ -1913,6 +2123,7 @@ const CollapsibleSection = ({ label, icon, open, onToggle, children, trailing, c
1913
2123
  className: "nb-collapsible__header",
1914
2124
  children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
1915
2125
  type: "button",
2126
+ id: `${bodyId}-trigger`,
1916
2127
  className: "nb-collapsible__trigger",
1917
2128
  "aria-expanded": open,
1918
2129
  "aria-controls": bodyId,
@@ -1939,1124 +2150,699 @@ const CollapsibleSection = ({ label, icon, open, onToggle, children, trailing, c
1939
2150
  id: bodyId,
1940
2151
  className: ["nb-collapsible__body", bodyClassName].filter(Boolean).join(" "),
1941
2152
  role: "region",
1942
- "aria-labelledby": void 0,
2153
+ "aria-labelledby": `${bodyId}-trigger`,
1943
2154
  hidden: !open,
1944
2155
  children
1945
2156
  })]
1946
2157
  });
1947
2158
  };
1948
2159
  //#endregion
1949
- //#region packages/ui/DatePicker.tsx
1950
- const cx$1 = (...values) => values.filter(Boolean).join(" ");
1951
- const ISO_DATE_RE$1 = /^\d{4}-\d{2}-\d{2}$/;
1952
- const getLocale$1 = (override) => override || document.documentElement.lang || navigator.language || "en-US";
1953
- const pad$1 = (value) => String(value).padStart(2, "0");
1954
- const toIsoDate$1 = (date) => `${date.getFullYear()}-${pad$1(date.getMonth() + 1)}-${pad$1(date.getDate())}`;
1955
- const parseIsoDate$1 = (value) => {
1956
- if (!value || !ISO_DATE_RE$1.test(value)) return null;
1957
- const [year, month, day] = value.split("-").map(Number);
1958
- const date = new Date(year, month - 1, day);
1959
- if (date.getFullYear() !== year || date.getMonth() !== month - 1 || date.getDate() !== day) return null;
1960
- return date;
1961
- };
1962
- const startOfMonth$1 = (date) => new Date(date.getFullYear(), date.getMonth(), 1);
1963
- const addMonths$1 = (date, months) => new Date(date.getFullYear(), date.getMonth() + months, 1);
1964
- const formatDisplayDate$1 = (value, locale) => {
1965
- const date = parseIsoDate$1(value);
1966
- if (!date) return "";
1967
- return new Intl.DateTimeFormat(getLocale$1(locale), {
1968
- day: "2-digit",
1969
- month: "2-digit",
1970
- year: "numeric"
1971
- }).format(date);
1972
- };
1973
- const formatMonthLabel$1 = (date, locale) => new Intl.DateTimeFormat(getLocale$1(locale), {
1974
- month: "long",
1975
- year: "numeric"
1976
- }).format(date);
1977
- /**
1978
- * Locale-aware first day of week.
1979
- * Uses Intl.Locale.weekInfo (Chrome 99+, FF 126+, Safari 17+) with fallback heuristic.
1980
- */
1981
- const getFirstDayOfWeek = (locale) => {
1982
- try {
1983
- const info = new Intl.Locale(getLocale$1(locale)).weekInfo;
1984
- if (info && typeof info.firstDay === "number") return info.firstDay === 7 ? 0 : info.firstDay;
1985
- } catch {}
1986
- const country = (getLocale$1(locale).split("-")[1] ?? "").toUpperCase();
1987
- return [
1988
- "US",
1989
- "CA",
1990
- "MX",
1991
- "CN",
1992
- "JP",
1993
- "KR",
1994
- "SA",
1995
- "EG",
1996
- "IL",
1997
- "BR"
1998
- ].includes(country) ? 0 : 1;
1999
- };
2000
- const buildCalendarDays$1 = (month, min, max, locale) => {
2001
- const first = startOfMonth$1(month);
2002
- const firstDayOfWeek = getFirstDayOfWeek(locale);
2003
- const offset = (first.getDay() - firstDayOfWeek + 7) % 7;
2004
- const minDate = parseIsoDate$1(min);
2005
- const maxDate = parseIsoDate$1(max);
2006
- const start = new Date(first);
2007
- start.setDate(first.getDate() - offset);
2008
- return Array.from({ length: 42 }, (_, i) => {
2009
- const date = new Date(start);
2010
- date.setDate(start.getDate() + i);
2011
- return {
2160
+ //#region packages/ui/CalendarContent.tsx
2161
+ /** Shared presentation; React Aria owns navigation, focus and range preview. */
2162
+ function CalendarContent() {
2163
+ const strings = useUiStrings();
2164
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("header", {
2165
+ className: "nb-calendar__header",
2166
+ children: [
2167
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_aria_components.Button, {
2168
+ slot: "previous",
2169
+ className: "nb-date-picker__nav",
2170
+ "aria-label": strings.previousMonth,
2171
+ children: "‹"
2172
+ }),
2173
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
2174
+ className: "nb-calendar__selectors",
2175
+ children: [
2176
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_aria_components.Heading, { className: "nb-calendar__heading" }),
2177
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_aria_components.CalendarMonthPicker, { children: ({ items, value, onChange, ...props }) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("select", {
2178
+ ...props,
2179
+ value,
2180
+ onChange: (event) => onChange(Number(event.target.value)),
2181
+ children: items.map((item) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("option", {
2182
+ value: item.id,
2183
+ children: item.formatted
2184
+ }, item.id))
2185
+ }) }),
2186
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_aria_components.CalendarYearPicker, { children: ({ items, value, onChange, ...props }) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("select", {
2187
+ ...props,
2188
+ value,
2189
+ onChange: (event) => onChange(Number(event.target.value)),
2190
+ children: items.map((item) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("option", {
2191
+ value: item.id,
2192
+ children: item.formatted
2193
+ }, item.id))
2194
+ }) })
2195
+ ]
2196
+ }),
2197
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_aria_components.Button, {
2198
+ slot: "next",
2199
+ className: "nb-date-picker__nav",
2200
+ "aria-label": strings.nextMonth,
2201
+ children: "›"
2202
+ })
2203
+ ]
2204
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_aria_components.CalendarGrid, {
2205
+ className: "nb-calendar__grid",
2206
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_aria_components.CalendarGridHeader, { children: (day) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_aria_components.CalendarHeaderCell, {
2207
+ className: "nb-calendar__weekday",
2208
+ children: day
2209
+ }) }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_aria_components.CalendarGridBody, { children: (date) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_aria_components.CalendarCell, {
2012
2210
  date,
2013
- iso: toIsoDate$1(date),
2014
- inCurrentMonth: date.getMonth() === month.getMonth(),
2015
- disabled: Boolean(minDate && date < minDate || maxDate && date > maxDate)
2016
- };
2017
- });
2018
- };
2019
- const isIsoDateDisabled = (iso, min, max) => {
2020
- const date = parseIsoDate$1(iso);
2021
- if (!date) return true;
2022
- const minDate = parseIsoDate$1(min);
2023
- const maxDate = parseIsoDate$1(max);
2024
- return Boolean(minDate && date < minDate || maxDate && date > maxDate);
2025
- };
2026
- const weekDayLabels = (locale) => {
2027
- const firstDayOfWeek = getFirstDayOfWeek(locale);
2028
- const anchor = new Date(2026, 5, 7);
2029
- const formatter = new Intl.DateTimeFormat(getLocale$1(locale), { weekday: "narrow" });
2030
- return Array.from({ length: 7 }, (_, i) => {
2031
- const date = new Date(anchor);
2032
- date.setDate(anchor.getDate() + (firstDayOfWeek + i) % 7);
2033
- return formatter.format(date);
2211
+ className: "nb-calendar__day"
2212
+ }) })]
2213
+ })] });
2214
+ }
2215
+ /** A parent modal owns containment; a standalone picker needs its own focus scope. */
2216
+ function CalendarDialog({ id, ariaLabel, children }) {
2217
+ return useOverlayContainer() ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("section", {
2218
+ id,
2219
+ "aria-label": ariaLabel,
2220
+ role: "dialog",
2221
+ tabIndex: -1,
2222
+ children
2223
+ }) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_aria_components.Dialog, {
2224
+ id,
2225
+ "aria-label": ariaLabel,
2226
+ children
2034
2227
  });
2228
+ }
2229
+ //#endregion
2230
+ //#region packages/ui/dateValues.ts
2231
+ const getDateLocale = (locale) => locale || typeof document !== "undefined" && document.documentElement.lang || typeof navigator !== "undefined" && navigator.language || "en-US";
2232
+ const calendarDate = (value) => {
2233
+ if (!value || !/^\d{4}-\d{2}-\d{2}$/.test(value)) return null;
2234
+ try {
2235
+ return (0, _internationalized_date.parseDate)(value);
2236
+ } catch {
2237
+ return null;
2238
+ }
2035
2239
  };
2036
- /** Short month labels (Jan, Feb, …) — capitalized for display. */
2037
- const getMonthLabels = (locale) => {
2038
- const formatter = new Intl.DateTimeFormat(getLocale$1(locale), { month: "short" });
2039
- return Array.from({ length: 12 }, (_, i) => {
2040
- const label = formatter.format(new Date(2024, i, 1));
2041
- return label.charAt(0).toUpperCase() + label.slice(1).replace(".", "");
2042
- });
2240
+ const formatDate = (value, locale) => {
2241
+ const date = calendarDate(value);
2242
+ return date ? new Intl.DateTimeFormat(locale, {
2243
+ day: "2-digit",
2244
+ month: "2-digit",
2245
+ year: "numeric",
2246
+ timeZone: "UTC"
2247
+ }).format(date.toDate("UTC")) : "";
2043
2248
  };
2044
- /** Year range: 12-year block containing the given year. */
2045
- const getYearRangeStart = (year) => Math.floor(year / 12) * 12;
2046
- /**
2047
- * Applies dd/mm/yyyy mask.
2048
- * Auto-inserts trailing slash when adding the 2nd or 4th digit.
2049
- * Does NOT add trailing slash when the user is deleting.
2050
- */
2051
- const applyDateMask = (rawValue, prevValue) => {
2249
+ const dateAllowed = (value, min, max) => Boolean(calendarDate(value)) && (!min || value >= min) && (!max || value <= max);
2250
+ const dateOrder = (locale) => new Intl.DateTimeFormat(getDateLocale(locale), {
2251
+ day: "2-digit",
2252
+ month: "2-digit",
2253
+ year: "numeric",
2254
+ timeZone: "UTC"
2255
+ }).formatToParts(new Date(Date.UTC(2026, 10, 23))).filter((part) => [
2256
+ "day",
2257
+ "month",
2258
+ "year"
2259
+ ].includes(part.type)).map((part) => part.type);
2260
+ const datePlaceholder = (locale) => dateOrder(locale).map((part) => part === "year" ? "yyyy" : part === "month" ? "mm" : "dd").join("/");
2261
+ const applyDateMask = (rawValue, prevValue, locale) => {
2262
+ if (/^\d{4}-\d{2}-\d{2}$/.test(rawValue)) return rawValue;
2052
2263
  const digits = rawValue.replace(/\D/g, "").slice(0, 8);
2053
- const prevDigits = prevValue.replace(/\D/g, "");
2054
- const isAdding = digits.length > prevDigits.length;
2055
- if (digits.length === 0) return "";
2056
- let result = digits.slice(0, 2);
2057
- if (digits.length > 2) result += "/" + digits.slice(2, 4);
2058
- if (digits.length > 4) result += "/" + digits.slice(4, 8);
2059
- if (isAdding && (digits.length === 2 || digits.length === 4)) result += "/";
2264
+ const adding = digits.length > prevValue.replace(/\D/g, "").length;
2265
+ const sizes = dateOrder(locale ?? "es-PE").map((part) => part === "year" ? 4 : 2);
2266
+ let offset = 0;
2267
+ let result = "";
2268
+ for (const [i, size] of sizes.entries()) {
2269
+ result += digits.slice(offset, offset + size);
2270
+ offset += size;
2271
+ if (i < 2 && (digits.length > offset || adding && digits.length === offset)) result += "/";
2272
+ }
2060
2273
  return result;
2061
2274
  };
2062
- /**
2063
- * Parses dd/mm/yyyy or ISO yyyy-mm-dd to ISO string.
2064
- * Returns null if not a valid date.
2065
- */
2066
2275
  const parseDisplayDate = (text, locale) => {
2067
- const match = text.match(/^(\d{1,2})[/-](\d{1,2})[/-](\d{4})$/);
2068
- if (match) {
2069
- const [, a, b, year] = match;
2070
- const [dd, mm] = (getLocale$1(locale).split("-")[1] ?? "").toUpperCase() === "US" ? [b, a] : [a, b];
2071
- const iso = `${year}-${mm.padStart(2, "0")}-${dd.padStart(2, "0")}`;
2072
- return parseIsoDate$1(iso) ? iso : null;
2073
- }
2074
- if (ISO_DATE_RE$1.test(text)) return parseIsoDate$1(text) ? text : null;
2075
- return null;
2276
+ if (calendarDate(text)) return text;
2277
+ const order = dateOrder(locale);
2278
+ const digits = text.match(/\d+/g);
2279
+ if (!digits || digits.length !== 3) return null;
2280
+ const fields = Object.fromEntries(order.map((key, i) => [key, digits[i]]));
2281
+ if (fields.year?.length !== 4) return null;
2282
+ const iso = `${fields.year}-${fields.month?.padStart(2, "0")}-${fields.day?.padStart(2, "0")}`;
2283
+ return calendarDate(iso) ? iso : null;
2076
2284
  };
2077
- const DatePicker = (0, react.forwardRef)(function DatePicker({ id, name, value, placeholder = "dd/mm/yyyy", disabled = false, readOnly = false, required = false, invalid = false, clearable = true, locale, min, max, className, ariaLabel, onChange, onBlur }, ref) {
2078
- const generatedId = (0, react.useId)();
2079
- const inputId = id ?? generatedId;
2080
- const panelId = `${inputId}-panel`;
2081
- const strings = useUiStrings();
2082
- const selectedDate = parseIsoDate$1(value);
2083
- const resolvedLocale = getLocale$1(locale);
2084
- const displayValue = formatDisplayDate$1(value, resolvedLocale);
2085
- const [viewMode, setViewMode] = (0, react.useState)("days");
2086
- const [month, setMonth] = (0, react.useState)(() => startOfMonth$1(selectedDate ?? /* @__PURE__ */ new Date()));
2087
- const [yearRangeStart, setYearRangeStart] = (0, react.useState)(() => getYearRangeStart((/* @__PURE__ */ new Date()).getFullYear()));
2088
- const [focusedIso, setFocusedIso] = (0, react.useState)(null);
2089
- const [inputText, setInputText] = (0, react.useState)("");
2090
- const [isEditing, setIsEditing] = (0, react.useState)(false);
2091
- const inputRef = (0, react.useRef)(null);
2092
- const triggerRef = (0, react.useRef)(null);
2093
- const { open, setOpen, containerRef: rootRef, panelRef, panelStyle } = useFloatingPanel({
2094
- onClose: () => {
2095
- setFocusedIso(null);
2096
- setViewMode("days");
2097
- },
2098
- onEscape: (e) => {
2099
- e.preventDefault();
2100
- inputRef.current?.focus();
2285
+ //#endregion
2286
+ //#region packages/ui/DateTextInput.tsx
2287
+ /** Keeps the real input/ref/ID contract used by CRUD forms. */
2288
+ const DateTextInput = (0, react.forwardRef)(function DateTextInput({ value, locale, min, max, onChange, onOpen, onBlur, onKeyDown, ...props }, ref) {
2289
+ const [draft, setDraft] = (0, react.useState)(null);
2290
+ const commit = () => {
2291
+ if (draft === null) return;
2292
+ const iso = parseDisplayDate(draft.trim(), locale);
2293
+ if (!draft.trim()) onChange("");
2294
+ else if (iso && dateAllowed(iso, min, max)) onChange(iso);
2295
+ setDraft(null);
2296
+ };
2297
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
2298
+ ...props,
2299
+ ref,
2300
+ type: "text",
2301
+ inputMode: "numeric",
2302
+ onPointerDown: (event) => event.stopPropagation(),
2303
+ onPointerUp: (event) => event.stopPropagation(),
2304
+ onMouseDown: (event) => event.stopPropagation(),
2305
+ onClick: (event) => event.stopPropagation(),
2306
+ value: draft ?? formatDate(value, locale),
2307
+ onChange: (event) => setDraft(applyDateMask(event.target.value, draft ?? "", locale)),
2308
+ onBlur: (event) => {
2309
+ commit();
2310
+ onBlur?.(event);
2101
2311
  },
2102
- computeStyle: () => {
2103
- const rect = triggerRef.current?.getBoundingClientRect();
2104
- if (!rect) return null;
2105
- const panelWidth = panelRef.current?.offsetWidth ?? 296;
2106
- const left = Math.min(Math.max(8, rect.left), window.innerWidth - panelWidth - 8);
2107
- const top = Math.min(rect.bottom + 6, window.innerHeight - 380);
2108
- return {
2109
- left,
2110
- top: Math.max(8, top)
2111
- };
2312
+ onKeyDown: (event) => {
2313
+ if (event.key !== "Escape") event.stopPropagation();
2314
+ onKeyDown?.(event);
2315
+ if (event.defaultPrevented) return;
2316
+ if (event.key === "Enter") {
2317
+ event.preventDefault();
2318
+ commit();
2319
+ }
2320
+ if (event.key === "Escape") setDraft(null);
2321
+ if (event.key === "ArrowDown" && !props.disabled && !props.readOnly) {
2322
+ event.preventDefault();
2323
+ commit();
2324
+ onOpen();
2325
+ }
2112
2326
  }
2113
2327
  });
2114
- const days = (0, react.useMemo)(() => buildCalendarDays$1(month, min, max, resolvedLocale), [
2115
- max,
2116
- min,
2117
- month,
2118
- resolvedLocale
2119
- ]);
2120
- const weekdayLabels = (0, react.useMemo)(() => weekDayLabels(resolvedLocale), [resolvedLocale]);
2121
- const monthLabels = (0, react.useMemo)(() => getMonthLabels(resolvedLocale), [resolvedLocale]);
2122
- const selectedIso = selectedDate ? toIsoDate$1(selectedDate) : "";
2123
- (0, react.useEffect)(() => {
2124
- if (selectedDate) setMonth(startOfMonth$1(selectedDate));
2125
- }, [value]);
2328
+ });
2329
+ //#endregion
2330
+ //#region packages/ui/useCalendarPopover.ts
2331
+ /** Bridge focus restoration between React Aria's popup and a parent Base UI modal. */
2332
+ function useCalendarPopover() {
2333
+ const container = useOverlayContainer();
2334
+ const groupRef = (0, react.useRef)(null);
2335
+ const panelRef = (0, react.useRef)(null);
2336
+ const frame = (0, react.useRef)(null);
2337
+ const outsideTarget = (0, react.useRef)(null);
2338
+ const [open, updateOpen] = (0, react.useState)(false);
2126
2339
  (0, react.useEffect)(() => {
2127
- if (!open) return;
2128
- const initialIso = selectedDate ? toIsoDate$1(selectedDate) : toIsoDate$1(/* @__PURE__ */ new Date());
2129
- setFocusedIso(initialIso);
2130
- window.setTimeout(() => {
2131
- panelRef.current?.querySelector(`[data-iso="${initialIso}"]`)?.focus();
2132
- }, 0);
2133
- }, [open]);
2134
- const commitValue = (0, react.useCallback)((nextValue) => {
2135
- onChange?.(nextValue);
2136
- setOpen(false);
2137
- setIsEditing(false);
2138
- setInputText("");
2139
- window.setTimeout(() => inputRef.current?.focus());
2140
- }, [onChange, setOpen]);
2141
- const handleToday = (0, react.useCallback)(() => {
2142
- const today = toIsoDate$1(/* @__PURE__ */ new Date());
2143
- if (isIsoDateDisabled(today, min, max)) return;
2144
- setMonth(startOfMonth$1(parseIsoDate$1(today)));
2145
- commitValue(today);
2146
- }, [
2147
- min,
2148
- max,
2149
- commitValue
2150
- ]);
2151
- const handleClear = (0, react.useCallback)((e) => {
2152
- e.preventDefault();
2153
- commitValue("");
2154
- }, [commitValue]);
2155
- const handleInputFocus = () => {
2156
- setIsEditing(true);
2157
- setInputText(displayValue);
2158
- window.setTimeout(() => inputRef.current?.select(), 0);
2159
- };
2160
- const handleInputChange = (e) => {
2161
- if (readOnly || disabled) return;
2162
- setInputText(applyDateMask(e.target.value, inputText));
2163
- };
2164
- const handleInputBlur = (e) => {
2165
- const related = e.relatedTarget;
2166
- if (rootRef.current?.contains(related) || panelRef.current?.contains(related)) return;
2167
- setIsEditing(false);
2168
- const parsed = parseDisplayDate(inputText, resolvedLocale);
2169
- if (parsed !== null) {
2170
- if (parsed !== value) onChange?.(parsed);
2171
- } else if (inputText === "" && value) onChange?.("");
2172
- setInputText("");
2173
- onBlur?.(e);
2174
- };
2175
- const handleInputKeyDown = (e) => {
2176
- if (e.key === "Enter") {
2177
- e.preventDefault();
2178
- const parsed = parseDisplayDate(inputText, resolvedLocale);
2179
- if (parsed !== null) commitValue(parsed);
2180
- else if (inputText === "") commitValue("");
2181
- } else if (e.key === "ArrowDown" || e.key === "F4") {
2182
- e.preventDefault();
2183
- if (!readOnly && !disabled) setOpen(true);
2184
- } else if (e.key === "Escape" && open) setOpen(false);
2185
- };
2186
- const handleCalendarPointerDown = (e) => {
2187
- e.preventDefault();
2188
- if (readOnly || disabled) return;
2189
- setOpen(!open);
2190
- };
2191
- const handleDayKeyDown = (0, react.useCallback)((e, iso) => {
2192
- if (![
2193
- "ArrowLeft",
2194
- "ArrowRight",
2195
- "ArrowUp",
2196
- "ArrowDown",
2197
- "Enter",
2198
- " "
2199
- ].includes(e.key)) return;
2200
- e.preventDefault();
2201
- if (e.key === "Enter" || e.key === " ") {
2202
- const day = days.find((d) => d.iso === iso);
2203
- if (day && !day.disabled) commitValue(iso);
2204
- return;
2205
- }
2206
- const delta = {
2207
- ArrowLeft: -1,
2208
- ArrowRight: 1,
2209
- ArrowUp: -7,
2210
- ArrowDown: 7
2211
- }[e.key] ?? 0;
2212
- const current = parseIsoDate$1(iso);
2213
- if (!current) return;
2214
- const next = new Date(current);
2215
- next.setDate(current.getDate() + delta);
2216
- const nextIso = toIsoDate$1(next);
2217
- if (next.getMonth() !== month.getMonth() || next.getFullYear() !== month.getFullYear()) setMonth(startOfMonth$1(next));
2218
- setFocusedIso(nextIso);
2219
- window.setTimeout(() => {
2220
- panelRef.current?.querySelector(`[data-iso="${nextIso}"]`)?.focus();
2221
- }, 0);
2222
- }, [
2223
- days,
2224
- month,
2225
- commitValue,
2226
- panelRef
2227
- ]);
2228
- const handleMonthSelect = (monthIndex) => {
2229
- setMonth(new Date(month.getFullYear(), monthIndex, 1));
2230
- setViewMode("days");
2231
- };
2232
- const handleYearSelect = (year) => {
2233
- setMonth(new Date(year, month.getMonth(), 1));
2234
- setViewMode("months");
2235
- };
2236
- const setInputRef = (node) => {
2237
- inputRef.current = node;
2238
- if (typeof ref === "function") ref(node);
2239
- else if (ref) ref.current = node;
2340
+ if (!open || !container) return;
2341
+ const rememberTarget = (event) => {
2342
+ if (event.target instanceof Element && container.contains(event.target) && !panelRef.current?.contains(event.target)) outsideTarget.current = event.target.closest("input, button, select, textarea, a[href], [tabindex]:not([tabindex=\"-1\"])");
2343
+ };
2344
+ document.addEventListener("pointerdown", rememberTarget, true);
2345
+ return () => document.removeEventListener("pointerdown", rememberTarget, true);
2346
+ }, [open, container]);
2347
+ (0, react.useEffect)(() => () => {
2348
+ if (frame.current !== null) cancelAnimationFrame(frame.current);
2349
+ }, []);
2350
+ return {
2351
+ container,
2352
+ groupRef,
2353
+ panelRef,
2354
+ open,
2355
+ setOpen: (0, react.useCallback)((next) => {
2356
+ if (frame.current !== null) cancelAnimationFrame(frame.current);
2357
+ if (next) outsideTarget.current = null;
2358
+ const active = document.activeElement;
2359
+ const target = outsideTarget.current ?? groupRef.current?.querySelector("input");
2360
+ const restore = !next && container && (outsideTarget.current || panelRef.current?.contains(active));
2361
+ updateOpen(next);
2362
+ if (restore) frame.current = requestAnimationFrame(() => {
2363
+ frame.current = requestAnimationFrame(() => {
2364
+ frame.current = null;
2365
+ if (document.activeElement === active || document.activeElement === container || document.activeElement === document.body) target?.focus();
2366
+ });
2367
+ });
2368
+ }, [container])
2240
2369
  };
2241
- const todayIso = toIsoDate$1(/* @__PURE__ */ new Date());
2242
- return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
2243
- ref: rootRef,
2244
- className: cx$1("nb-date-picker", className),
2245
- children: [
2246
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
2247
- type: "hidden",
2248
- name,
2249
- value: value ?? "",
2250
- required
2251
- }),
2252
- /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
2253
- ref: triggerRef,
2254
- className: cx$1("nb-date-picker__trigger", invalid && "nb-date-picker__trigger--invalid", readOnly && "nb-date-picker__trigger--readonly", open && "nb-date-picker__trigger--open", disabled && "nb-date-picker__trigger--disabled"),
2255
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
2256
- ref: setInputRef,
2257
- id: inputId,
2258
- type: "text",
2259
- inputMode: "numeric",
2260
- className: cx$1("nb-date-picker__input", !isEditing && !displayValue && "nb-date-picker__input--placeholder"),
2261
- value: isEditing ? inputText : displayValue,
2262
- placeholder,
2263
- disabled,
2264
- readOnly,
2265
- "aria-label": ariaLabel,
2266
- role: "combobox",
2267
- "aria-haspopup": "dialog",
2268
- "aria-expanded": open,
2269
- "aria-controls": open ? panelId : void 0,
2270
- "aria-invalid": invalid || void 0,
2271
- "aria-required": required || void 0,
2272
- autoComplete: "off",
2273
- onFocus: handleInputFocus,
2274
- onBlur: handleInputBlur,
2275
- onChange: handleInputChange,
2276
- onKeyDown: handleInputKeyDown
2277
- }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
2278
- className: "nb-date-picker__icons",
2279
- children: [clearable && displayValue && !disabled && !readOnly && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
2280
- role: "button",
2281
- tabIndex: -1,
2282
- className: "nb-date-picker__clear",
2283
- "aria-label": strings.clearDate,
2284
- onPointerDown: handleClear,
2285
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("i", {
2286
- className: "ph ph-x",
2287
- "aria-hidden": "true"
2288
- })
2289
- }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
2290
- role: "button",
2291
- tabIndex: -1,
2292
- className: "nb-date-picker__calendar-btn",
2293
- "aria-label": strings.openCalendar,
2294
- onPointerDown: handleCalendarPointerDown,
2295
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("i", {
2296
- className: "ph ph-calendar-blank",
2297
- "aria-hidden": "true"
2298
- })
2299
- })]
2300
- })]
2301
- }),
2302
- open && (0, react_dom.createPortal)(/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
2303
- ref: panelRef,
2304
- id: panelId,
2305
- className: "nb-date-picker__panel",
2306
- role: "dialog",
2307
- "aria-label": strings.selectDate,
2308
- style: panelStyle,
2309
- children: [
2310
- viewMode === "days" && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
2311
- /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
2312
- className: "nb-date-picker__header",
2313
- children: [
2314
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
2315
- type: "button",
2316
- className: "nb-date-picker__nav",
2317
- "aria-label": strings.previousMonth,
2318
- onClick: () => setMonth((m) => addMonths$1(m, -1)),
2319
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("i", {
2320
- className: "ph ph-caret-left",
2321
- "aria-hidden": "true"
2322
- })
2323
- }),
2324
- /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
2325
- type: "button",
2326
- className: "nb-date-picker__month nb-date-picker__month--clickable",
2327
- "aria-label": strings.selectMonthAndYear,
2328
- onClick: () => setViewMode("months"),
2329
- children: [formatMonthLabel$1(month, resolvedLocale), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("i", {
2330
- className: "ph ph-caret-down nb-date-picker__month-caret",
2331
- "aria-hidden": "true"
2332
- })]
2333
- }),
2334
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
2335
- type: "button",
2336
- className: "nb-date-picker__nav",
2337
- "aria-label": strings.nextMonth,
2338
- onClick: () => setMonth((m) => addMonths$1(m, 1)),
2339
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("i", {
2340
- className: "ph ph-caret-right",
2341
- "aria-hidden": "true"
2342
- })
2343
- })
2344
- ]
2345
- }),
2346
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
2347
- className: "nb-date-picker__weekdays",
2348
- "aria-hidden": "true",
2349
- children: weekdayLabels.map((label, i) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: label }, `${label}-${i}`))
2370
+ }
2371
+ //#endregion
2372
+ //#region packages/ui/DatePicker.tsx
2373
+ 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
+ const generatedId = (0, react.useId)();
2375
+ const inputId = id ?? generatedId;
2376
+ const { container, groupRef, panelRef, open, setOpen } = useCalendarPopover();
2377
+ const strings = useUiStrings();
2378
+ const resolvedLocale = getDateLocale(locale);
2379
+ const change = (next) => onChange?.(next);
2380
+ const todayIso = (0, _internationalized_date.today)((0, _internationalized_date.getLocalTimeZone)()).toString();
2381
+ const prefix = "nb-date-picker";
2382
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_aria_components.I18nProvider, {
2383
+ locale: resolvedLocale,
2384
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_aria_components.DatePicker, {
2385
+ "aria-label": ariaLabel ?? strings.selectDate,
2386
+ value: calendarDate(value),
2387
+ onChange: (date) => change(date?.toString() ?? ""),
2388
+ minValue: calendarDate(min) ?? void 0,
2389
+ maxValue: calendarDate(max) ?? void 0,
2390
+ isDisabled: disabled,
2391
+ isReadOnly: readOnly,
2392
+ isRequired: required,
2393
+ isInvalid: invalid,
2394
+ validationBehavior: "aria",
2395
+ isOpen: open,
2396
+ onOpenChange: setOpen,
2397
+ className: [prefix, className].filter(Boolean).join(" "),
2398
+ children: [
2399
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
2400
+ type: "hidden",
2401
+ name,
2402
+ value: value ?? "",
2403
+ disabled
2404
+ }),
2405
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_aria_components.Group, {
2406
+ ref: groupRef,
2407
+ className: [
2408
+ `${prefix}__trigger`,
2409
+ disabled && `${prefix}__trigger--disabled`,
2410
+ readOnly && `${prefix}__trigger--readonly`,
2411
+ invalid && `${prefix}__trigger--invalid`,
2412
+ open && `${prefix}__trigger--open`
2413
+ ].filter(Boolean).join(" "),
2414
+ children: [
2415
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DateTextInput, {
2416
+ ref,
2417
+ id: inputId,
2418
+ value,
2419
+ locale: resolvedLocale,
2420
+ min,
2421
+ max,
2422
+ placeholder: placeholder ?? datePlaceholder(resolvedLocale),
2423
+ disabled,
2424
+ readOnly,
2425
+ required,
2426
+ "aria-label": ariaLabel ?? (id ? void 0 : strings.selectDate),
2427
+ "aria-invalid": invalid || void 0,
2428
+ role: "combobox",
2429
+ "aria-haspopup": "dialog",
2430
+ "aria-expanded": open,
2431
+ "aria-controls": open ? `${inputId}-panel` : void 0,
2432
+ className: `${prefix}__input`,
2433
+ onChange: change,
2434
+ onOpen: () => setOpen(true),
2435
+ onBlur,
2436
+ onKeyDown: (event) => {
2437
+ if (event.key === "Escape" && open) {
2438
+ event.stopPropagation();
2439
+ setOpen(false);
2440
+ }
2441
+ }
2350
2442
  }),
2351
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
2352
- className: "nb-date-picker__days",
2353
- role: "grid",
2354
- "aria-label": formatMonthLabel$1(month, resolvedLocale),
2355
- children: days.map((day) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
2356
- "data-iso": day.iso,
2357
- type: "button",
2358
- className: cx$1("nb-date-picker__day", !day.inCurrentMonth && "nb-date-picker__day--muted", day.iso === selectedIso && "nb-date-picker__day--selected", day.iso === todayIso && "nb-date-picker__day--today"),
2359
- disabled: day.disabled,
2360
- role: "gridcell",
2361
- "aria-selected": day.iso === selectedIso,
2362
- tabIndex: day.iso === (focusedIso ?? selectedIso ?? todayIso) ? 0 : -1,
2363
- onClick: () => commitValue(day.iso),
2364
- onKeyDown: (e) => handleDayKeyDown(e, day.iso),
2365
- children: day.date.getDate()
2366
- }, day.iso))
2443
+ clearable && value && !disabled && !readOnly && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_aria_components.Button, {
2444
+ slot: null,
2445
+ className: `${prefix}__clear`,
2446
+ "aria-label": strings.clearDate,
2447
+ onPress: () => change(""),
2448
+ children: "×"
2367
2449
  }),
2368
- /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
2369
- className: "nb-date-picker__footer",
2370
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
2371
- type: "button",
2372
- className: "nb-date-picker__text-button",
2373
- onClick: () => commitValue(""),
2450
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_aria_components.Button, {
2451
+ className: `${prefix}__calendar-btn`,
2452
+ "aria-label": strings.openCalendar,
2453
+ onPress: () => groupRef.current?.querySelector("input")?.focus(),
2454
+ isDisabled: disabled || readOnly,
2455
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("i", {
2456
+ "aria-hidden": "true",
2457
+ className: "ph ph-calendar-blank"
2458
+ })
2459
+ })
2460
+ ]
2461
+ }),
2462
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_aria_components.Popover, {
2463
+ isNonModal: Boolean(container),
2464
+ ref: panelRef,
2465
+ UNSTABLE_portalContainer: container ?? void 0,
2466
+ className: `${prefix}__panel`,
2467
+ offset: 4,
2468
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(CalendarDialog, {
2469
+ id: `${inputId}-panel`,
2470
+ ariaLabel: strings.selectDate,
2471
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_aria_components.Calendar, { children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CalendarContent, {}) }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
2472
+ className: `${prefix}__footer`,
2473
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_aria_components.Button, {
2474
+ slot: null,
2475
+ className: `${prefix}__text-button`,
2476
+ onPress: () => {
2477
+ change("");
2478
+ setOpen(false);
2479
+ },
2374
2480
  children: strings.clear
2375
- }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
2376
- type: "button",
2377
- className: "nb-date-picker__text-button",
2378
- onClick: handleToday,
2481
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_aria_components.Button, {
2482
+ slot: null,
2483
+ className: `${prefix}__text-button`,
2484
+ isDisabled: !dateAllowed(todayIso, min, max),
2485
+ onPress: () => {
2486
+ change(todayIso);
2487
+ setOpen(false);
2488
+ },
2379
2489
  children: strings.today
2380
2490
  })]
2381
- })
2382
- ] }),
2383
- viewMode === "months" && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
2384
- /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
2385
- className: "nb-date-picker__header",
2386
- children: [
2387
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
2388
- type: "button",
2389
- className: "nb-date-picker__nav",
2390
- "aria-label": strings.previousYear,
2391
- onClick: () => setMonth((m) => new Date(m.getFullYear() - 1, m.getMonth(), 1)),
2392
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("i", {
2393
- className: "ph ph-caret-left",
2394
- "aria-hidden": "true"
2395
- })
2396
- }),
2397
- /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
2398
- type: "button",
2399
- className: "nb-date-picker__month nb-date-picker__month--clickable",
2400
- "aria-label": strings.selectYear,
2401
- onClick: () => {
2402
- setYearRangeStart(getYearRangeStart(month.getFullYear()));
2403
- setViewMode("years");
2404
- },
2405
- children: [month.getFullYear(), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("i", {
2406
- className: "ph ph-caret-down nb-date-picker__month-caret",
2407
- "aria-hidden": "true"
2408
- })]
2409
- }),
2410
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
2411
- type: "button",
2412
- className: "nb-date-picker__nav",
2413
- "aria-label": strings.nextYear,
2414
- onClick: () => setMonth((m) => new Date(m.getFullYear() + 1, m.getMonth(), 1)),
2415
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("i", {
2416
- className: "ph ph-caret-right",
2417
- "aria-hidden": "true"
2418
- })
2419
- })
2420
- ]
2421
- }),
2422
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
2423
- className: "nb-date-picker__months-grid",
2424
- role: "grid",
2425
- "aria-label": `${month.getFullYear()}`,
2426
- children: monthLabels.map((label, i) => {
2427
- const isSelected = selectedDate ? selectedDate.getMonth() === i && selectedDate.getFullYear() === month.getFullYear() : false;
2428
- const isCurrent = (/* @__PURE__ */ new Date()).getMonth() === i && (/* @__PURE__ */ new Date()).getFullYear() === month.getFullYear();
2429
- return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
2430
- type: "button",
2431
- className: cx$1("nb-date-picker__month-cell", isSelected && "nb-date-picker__month-cell--selected", isCurrent && "nb-date-picker__month-cell--current"),
2432
- role: "gridcell",
2433
- "aria-selected": isSelected,
2434
- onClick: () => handleMonthSelect(i),
2435
- children: label
2436
- }, i);
2437
- })
2438
- }),
2439
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
2440
- className: "nb-date-picker__footer",
2441
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
2442
- type: "button",
2443
- className: "nb-date-picker__text-button",
2444
- onClick: () => setViewMode("days"),
2445
- children: [
2446
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("i", {
2447
- className: "ph ph-arrow-left",
2448
- "aria-hidden": "true"
2449
- }),
2450
- " ",
2451
- strings.back
2452
- ]
2453
- })
2454
- })
2455
- ] }),
2456
- viewMode === "years" && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
2457
- /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
2458
- className: "nb-date-picker__header",
2459
- children: [
2460
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
2461
- type: "button",
2462
- className: "nb-date-picker__nav",
2463
- "aria-label": strings.previousYears,
2464
- onClick: () => setYearRangeStart((y) => y - 12),
2465
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("i", {
2466
- className: "ph ph-caret-left",
2467
- "aria-hidden": "true"
2468
- })
2469
- }),
2470
- /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
2471
- className: "nb-date-picker__month",
2472
- children: [
2473
- yearRangeStart,
2474
- "–",
2475
- yearRangeStart + 11
2476
- ]
2477
- }),
2478
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
2479
- type: "button",
2480
- className: "nb-date-picker__nav",
2481
- "aria-label": strings.nextYears,
2482
- onClick: () => setYearRangeStart((y) => y + 12),
2483
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("i", {
2484
- className: "ph ph-caret-right",
2485
- "aria-hidden": "true"
2486
- })
2487
- })
2488
- ]
2489
- }),
2490
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
2491
- className: "nb-date-picker__years-grid",
2492
- role: "grid",
2493
- "aria-label": `${yearRangeStart}–${yearRangeStart + 11}`,
2494
- children: Array.from({ length: 12 }, (_, i) => yearRangeStart + i).map((year) => {
2495
- const isSelected = selectedDate ? selectedDate.getFullYear() === year : false;
2496
- const isCurrent = (/* @__PURE__ */ new Date()).getFullYear() === year;
2497
- return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
2498
- type: "button",
2499
- className: cx$1("nb-date-picker__year-cell", isSelected && "nb-date-picker__year-cell--selected", isCurrent && "nb-date-picker__year-cell--current"),
2500
- role: "gridcell",
2501
- "aria-selected": isSelected,
2502
- onClick: () => handleYearSelect(year),
2503
- children: year
2504
- }, year);
2505
- })
2506
- }),
2507
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
2508
- className: "nb-date-picker__footer",
2509
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
2510
- type: "button",
2511
- className: "nb-date-picker__text-button",
2512
- onClick: () => setViewMode("months"),
2513
- children: [
2514
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("i", {
2515
- className: "ph ph-arrow-left",
2516
- "aria-hidden": "true"
2517
- }),
2518
- " ",
2519
- strings.back
2520
- ]
2521
- })
2522
- })
2523
- ] })
2524
- ]
2525
- }), document.body)
2526
- ]
2491
+ })]
2492
+ })
2493
+ })
2494
+ ]
2495
+ })
2527
2496
  });
2528
2497
  });
2529
2498
  //#endregion
2530
2499
  //#region packages/ui/DateRangePicker.tsx
2531
- /**
2532
- * DateRangePicker — enterprise date range selector.
2533
- *
2534
- * A single trigger with two text inputs (start + end) sharing one calendar
2535
- * panel. Supports hover-preview, range highlighting, keyboard entry, min/max
2536
- * constraints, and full density/theme token compliance.
2537
- *
2538
- * Usage:
2539
- * <DateRangePicker
2540
- * startValue="2026-06-01"
2541
- * endValue="2026-06-30"
2542
- * onChange={(start, end) => ...}
2543
- * />
2544
- */
2545
- const ISO_DATE_RE = /^\d{4}-\d{2}-\d{2}$/;
2546
- const pad = (v) => String(v).padStart(2, "0");
2547
- const toIsoDate = (d) => `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())}`;
2548
- const parseIsoDate = (value) => {
2549
- if (!value || !ISO_DATE_RE.test(value)) return null;
2550
- const [year, month, day] = value.split("-").map(Number);
2551
- const d = new Date(year, month - 1, day);
2552
- if (d.getFullYear() !== year || d.getMonth() !== month - 1 || d.getDate() !== day) return null;
2553
- return d;
2554
- };
2555
- const cx = (...vals) => vals.filter(Boolean).join(" ");
2556
- const getLocale = (override) => override || document.documentElement.lang || navigator.language || "en-US";
2557
- const startOfMonth = (date) => new Date(date.getFullYear(), date.getMonth(), 1);
2558
- const addMonths = (date, months) => new Date(date.getFullYear(), date.getMonth() + months, 1);
2559
- const formatDisplayDate = (value, locale) => {
2560
- const date = parseIsoDate(value);
2561
- if (!date) return "";
2562
- return new Intl.DateTimeFormat(getLocale(locale), {
2563
- day: "2-digit",
2564
- month: "2-digit",
2565
- year: "numeric"
2566
- }).format(date);
2567
- };
2568
- const formatMonthLabel = (date, locale) => new Intl.DateTimeFormat(getLocale(locale), {
2569
- month: "long",
2570
- year: "numeric"
2571
- }).format(date);
2572
- const buildCalendarDays = (month, min, max, locale) => {
2573
- const first = startOfMonth(month);
2574
- const firstDayOfWeek = getFirstDayOfWeek(locale);
2575
- const offset = (first.getDay() - firstDayOfWeek + 7) % 7;
2576
- const minDate = parseIsoDate(min);
2577
- const maxDate = parseIsoDate(max);
2578
- const start = new Date(first);
2579
- start.setDate(first.getDate() - offset);
2580
- return Array.from({ length: 42 }, (_, i) => {
2581
- const date = new Date(start);
2582
- date.setDate(start.getDate() + i);
2583
- return {
2584
- date,
2585
- iso: toIsoDate(date),
2586
- inCurrentMonth: date.getMonth() === month.getMonth(),
2587
- disabled: Boolean(minDate && date < minDate || maxDate && date > maxDate)
2588
- };
2589
- });
2590
- };
2591
- const getDayRoleInRange = (iso, startIso, endIso) => {
2592
- if (!startIso) return "none";
2593
- if (!endIso || startIso === endIso) return iso === startIso ? "single" : "none";
2594
- if (iso === startIso) return "start";
2595
- if (iso === endIso) return "end";
2596
- if (iso > startIso && iso < endIso) return "in-range";
2597
- return "none";
2598
- };
2599
- function DateRangePicker({ startValue, endValue, placeholder = "dd/mm/yyyy", disabled = false, readOnly = false, required = false, invalid = false, locale, min, max, className, ariaLabel, onChange, onBlur }) {
2600
- const startId = (0, react.useId)();
2601
- const endId = (0, react.useId)();
2500
+ function DateRangePicker({ startValue, endValue, placeholder, disabled = false, clearable = true, readOnly = false, required = false, invalid = false, locale, min, max, className, ariaLabel, onChange, onBlur }) {
2501
+ const { container, groupRef, panelRef, open, setOpen } = useCalendarPopover();
2602
2502
  const strings = useUiStrings();
2603
- const resolvedLocale = getLocale(locale);
2604
- const startDisplay = formatDisplayDate(startValue, resolvedLocale);
2605
- const endDisplay = formatDisplayDate(endValue, resolvedLocale);
2606
- const startIso = parseIsoDate(startValue) ? startValue : null;
2607
- const endIso = parseIsoDate(endValue) ? endValue : null;
2608
- const [phase, setPhase] = (0, react.useState)("idle");
2609
- const [pendingStart, setPendingStart] = (0, react.useState)(null);
2610
- const [hoverIso, setHoverIso] = (0, react.useState)(null);
2611
- const [month, setMonth] = (0, react.useState)(() => startOfMonth(parseIsoDate(startValue) ?? /* @__PURE__ */ new Date()));
2612
- const [startText, setStartText] = (0, react.useState)("");
2613
- const [endText, setEndText] = (0, react.useState)("");
2614
- const [editingField, setEditingField] = (0, react.useState)(null);
2615
- const triggerRef = (0, react.useRef)(null);
2616
- const startInputRef = (0, react.useRef)(null);
2617
- const endInputRef = (0, react.useRef)(null);
2618
- const days = (0, react.useMemo)(() => buildCalendarDays(month, min, max, resolvedLocale), [
2619
- month,
2503
+ const resolvedLocale = getDateLocale(locale);
2504
+ const start = calendarDate(startValue);
2505
+ const end = calendarDate(endValue);
2506
+ const change = (a, b) => a && b && a > b ? onChange?.(b, a) : onChange?.(a, b);
2507
+ const todayIso = (0, _internationalized_date.today)((0, _internationalized_date.getLocalTimeZone)()).toString();
2508
+ const prefix = "nb-date-range-picker";
2509
+ const inputProps = {
2510
+ locale: resolvedLocale,
2620
2511
  min,
2621
2512
  max,
2622
- resolvedLocale
2623
- ]);
2624
- const weekdayLbls = (0, react.useMemo)(() => weekDayLabels(resolvedLocale), [resolvedLocale]);
2625
- const todayIso = toIsoDate(/* @__PURE__ */ new Date());
2626
- (0, react.useEffect)(() => {
2627
- const anchor = parseIsoDate(startValue) ?? parseIsoDate(endValue);
2628
- if (anchor) setMonth(startOfMonth(anchor));
2629
- }, [startValue]);
2630
- const { open, setOpen, containerRef: rootRef, panelRef, panelStyle } = useFloatingPanel({
2631
- onClose: () => {
2632
- setPhase("idle");
2633
- setPendingStart(null);
2634
- setHoverIso(null);
2635
- },
2636
- onEscape: (e) => {
2637
- e.preventDefault();
2638
- startInputRef.current?.focus();
2639
- },
2640
- computeStyle: () => {
2641
- const rect = triggerRef.current?.getBoundingClientRect();
2642
- if (!rect) return null;
2643
- const panelWidth = panelRef.current?.offsetWidth ?? 296;
2644
- const left = Math.min(Math.max(8, rect.left), window.innerWidth - panelWidth - 8);
2645
- const top = Math.min(rect.bottom + 6, window.innerHeight - 380);
2646
- return {
2647
- left,
2648
- top: Math.max(8, top)
2649
- };
2650
- }
2651
- });
2652
- const closePanel = (0, react.useCallback)(() => {
2653
- setOpen(false);
2654
- }, [setOpen]);
2655
- const commitRange = (0, react.useCallback)((start, end) => {
2656
- const [a, b] = start <= end ? [start, end] : [end, start];
2657
- onChange?.(a, b);
2658
- closePanel();
2659
- window.setTimeout(() => startInputRef.current?.focus());
2660
- }, [onChange, closePanel]);
2661
- const handleDayClick = (0, react.useCallback)((iso) => {
2662
- if (phase === "idle") {
2663
- setPendingStart(iso);
2664
- setPhase("selecting-end");
2665
- } else commitRange(pendingStart ?? iso, iso);
2666
- }, [
2667
- phase,
2668
- pendingStart,
2669
- commitRange
2670
- ]);
2671
- const getEffectiveRange = () => {
2672
- if (phase === "selecting-end" && pendingStart) {
2673
- const effectiveEnd = hoverIso ?? null;
2674
- return {
2675
- effectiveStart: pendingStart <= (effectiveEnd ?? pendingStart) ? pendingStart : effectiveEnd,
2676
- effectiveEnd: pendingStart <= (effectiveEnd ?? pendingStart) ? effectiveEnd : pendingStart
2677
- };
2678
- }
2679
- return {
2680
- effectiveStart: startIso,
2681
- effectiveEnd: endIso
2682
- };
2683
- };
2684
- const { effectiveStart, effectiveEnd } = getEffectiveRange();
2685
- const handleStartFocus = () => {
2686
- setEditingField("start");
2687
- setStartText(startDisplay);
2688
- window.setTimeout(() => startInputRef.current?.select(), 0);
2689
- };
2690
- const handleEndFocus = () => {
2691
- setEditingField("end");
2692
- setEndText(endDisplay);
2693
- window.setTimeout(() => endInputRef.current?.select(), 0);
2694
- };
2695
- const handleStartChange = (e) => {
2696
- if (readOnly || disabled) return;
2697
- setStartText(applyDateMask(e.target.value, startText));
2698
- };
2699
- const handleEndChange = (e) => {
2700
- if (readOnly || disabled) return;
2701
- setEndText(applyDateMask(e.target.value, endText));
2702
- };
2703
- const commitTextInput = (field, text) => {
2704
- const parsed = parseDisplayDate(text, resolvedLocale);
2705
- if (parsed !== null) {
2706
- const newStart = field === "start" ? parsed : startIso ?? "";
2707
- const newEnd = field === "end" ? parsed : endIso ?? "";
2708
- if (newStart && newEnd) {
2709
- const [a, b] = newStart <= newEnd ? [newStart, newEnd] : [newEnd, newStart];
2710
- onChange?.(a, b);
2711
- } else if (field === "start") onChange?.(parsed, endIso ?? "");
2712
- else onChange?.(startIso ?? "", parsed);
2713
- } else if (text === "") {
2714
- if (field === "start") onChange?.("", endIso ?? "");
2715
- else onChange?.(startIso ?? "", "");
2716
- }
2717
- };
2718
- const handleStartBlur = (e) => {
2719
- const related = e.relatedTarget;
2720
- if (rootRef.current?.contains(related) || panelRef.current?.contains(related)) return;
2721
- commitTextInput("start", startText);
2722
- setEditingField(null);
2723
- setStartText("");
2724
- onBlur?.(e);
2725
- };
2726
- const handleEndBlur = (e) => {
2727
- const related = e.relatedTarget;
2728
- if (rootRef.current?.contains(related) || panelRef.current?.contains(related)) return;
2729
- commitTextInput("end", endText);
2730
- setEditingField(null);
2731
- setEndText("");
2732
- onBlur?.(e);
2733
- };
2734
- const handleStartKeyDown = (e) => {
2735
- if (e.key === "Enter") {
2736
- e.preventDefault();
2737
- const parsed = parseDisplayDate(startText);
2738
- if (parsed) onChange?.(parsed, endIso ?? "");
2739
- endInputRef.current?.focus();
2740
- } else if (e.key === "ArrowDown" || e.key === "F4") {
2741
- e.preventDefault();
2742
- if (!readOnly && !disabled) setOpen(true);
2743
- }
2744
- };
2745
- const handleEndKeyDown = (e) => {
2746
- if (e.key === "Enter") {
2747
- e.preventDefault();
2748
- const parsed = parseDisplayDate(endText);
2749
- if (parsed) onChange?.(startIso ?? "", parsed);
2750
- } else if (e.key === "ArrowDown" || e.key === "F4") {
2751
- e.preventDefault();
2752
- if (!readOnly && !disabled) setOpen(true);
2513
+ placeholder: placeholder ?? datePlaceholder(resolvedLocale),
2514
+ disabled,
2515
+ readOnly,
2516
+ required,
2517
+ "aria-invalid": invalid || void 0,
2518
+ className: `${prefix}__input`,
2519
+ onOpen: () => setOpen(true),
2520
+ onBlur,
2521
+ onKeyDown: (event) => {
2522
+ if (event.key === "Escape" && open) {
2523
+ event.stopPropagation();
2524
+ setOpen(false);
2525
+ }
2753
2526
  }
2754
2527
  };
2755
- const handleCalendarPointerDown = (e) => {
2756
- e.preventDefault();
2757
- if (readOnly || disabled) return;
2758
- setOpen(!open);
2759
- };
2760
- const handleClear = (e) => {
2761
- e.preventDefault();
2762
- onChange?.("", "");
2763
- closePanel();
2764
- };
2765
- return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
2766
- ref: rootRef,
2767
- className: cx("nb-date-range-picker", className),
2768
- children: [
2769
- /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
2770
- ref: triggerRef,
2771
- className: cx("nb-date-range-picker__trigger", invalid && "nb-date-range-picker__trigger--invalid", readOnly && "nb-date-range-picker__trigger--readonly", open && "nb-date-range-picker__trigger--open", disabled && "nb-date-range-picker__trigger--disabled"),
2772
- "aria-label": ariaLabel,
2528
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_aria_components.I18nProvider, {
2529
+ locale: resolvedLocale,
2530
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_aria_components.DateRangePicker, {
2531
+ "aria-label": ariaLabel ?? strings.selectDateRange,
2532
+ value: start && end && start.compare(end) <= 0 ? {
2533
+ start,
2534
+ end
2535
+ } : null,
2536
+ onChange: (range) => change(range?.start.toString() ?? "", range?.end.toString() ?? ""),
2537
+ minValue: calendarDate(min) ?? void 0,
2538
+ maxValue: calendarDate(max) ?? void 0,
2539
+ placeholderValue: start ?? end ?? void 0,
2540
+ isDisabled: disabled,
2541
+ isReadOnly: readOnly,
2542
+ isRequired: required,
2543
+ isInvalid: invalid,
2544
+ validationBehavior: "aria",
2545
+ isOpen: open,
2546
+ onOpenChange: setOpen,
2547
+ className: [prefix, className].filter(Boolean).join(" "),
2548
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_aria_components.Group, {
2549
+ ref: groupRef,
2550
+ className: [
2551
+ `${prefix}__trigger`,
2552
+ disabled && `${prefix}__trigger--disabled`,
2553
+ readOnly && `${prefix}__trigger--readonly`,
2554
+ invalid && `${prefix}__trigger--invalid`,
2555
+ open && `${prefix}__trigger--open`
2556
+ ].filter(Boolean).join(" "),
2773
2557
  children: [
2774
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
2775
- ref: startInputRef,
2776
- id: startId,
2777
- type: "text",
2778
- inputMode: "numeric",
2779
- className: cx("nb-date-range-picker__input", !editingField && !startDisplay && "nb-date-range-picker__input--placeholder"),
2780
- value: editingField === "start" ? startText : startDisplay,
2781
- placeholder,
2782
- disabled,
2783
- readOnly,
2784
- autoComplete: "off",
2785
- "aria-label": `Fecha inicio${ariaLabel ? ` ${ariaLabel}` : ""}`,
2786
- "aria-required": required || void 0,
2787
- onFocus: handleStartFocus,
2788
- onBlur: handleStartBlur,
2789
- onChange: handleStartChange,
2790
- onKeyDown: handleStartKeyDown
2558
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DateTextInput, {
2559
+ ...inputProps,
2560
+ "aria-label": [strings.startDate, ariaLabel].filter(Boolean).join(" "),
2561
+ value: startValue,
2562
+ onChange: (next) => change(next, endValue ?? "")
2791
2563
  }),
2792
2564
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
2793
- className: "nb-date-range-picker__sep",
2565
+ className: `${prefix}__sep`,
2794
2566
  "aria-hidden": "true",
2795
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("i", { className: "ph ph-arrow-right" })
2567
+ children: "→"
2796
2568
  }),
2797
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
2798
- ref: endInputRef,
2799
- id: endId,
2800
- type: "text",
2801
- inputMode: "numeric",
2802
- className: cx("nb-date-range-picker__input", !editingField && !endDisplay && "nb-date-range-picker__input--placeholder"),
2803
- value: editingField === "end" ? endText : endDisplay,
2804
- placeholder,
2805
- disabled,
2806
- readOnly,
2807
- autoComplete: "off",
2808
- "aria-label": `Fecha fin${ariaLabel ? ` ${ariaLabel}` : ""}`,
2809
- onFocus: handleEndFocus,
2810
- onBlur: handleEndBlur,
2811
- onChange: handleEndChange,
2812
- onKeyDown: handleEndKeyDown
2569
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DateTextInput, {
2570
+ ...inputProps,
2571
+ "aria-label": [strings.endDate, ariaLabel].filter(Boolean).join(" "),
2572
+ value: endValue,
2573
+ onChange: (next) => change(startValue ?? "", next)
2813
2574
  }),
2814
- /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
2815
- className: "nb-date-range-picker__icons",
2816
- children: [(startDisplay || endDisplay) && !disabled && !readOnly && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
2817
- role: "button",
2818
- tabIndex: -1,
2819
- className: "nb-date-range-picker__clear",
2820
- "aria-label": strings.clearDateRange,
2821
- onPointerDown: handleClear,
2822
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("i", {
2823
- className: "ph ph-x",
2824
- "aria-hidden": "true"
2825
- })
2826
- }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
2827
- role: "button",
2828
- tabIndex: -1,
2829
- className: "nb-date-range-picker__calendar-btn",
2830
- "aria-label": strings.openCalendar,
2831
- onPointerDown: handleCalendarPointerDown,
2832
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("i", {
2833
- className: "ph ph-calendar-blank",
2834
- "aria-hidden": "true"
2835
- })
2836
- })]
2575
+ clearable && (startValue || endValue) && !disabled && !readOnly && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_aria_components.Button, {
2576
+ slot: null,
2577
+ className: `${prefix}__clear`,
2578
+ "aria-label": strings.clearDateRange,
2579
+ onPress: () => change("", ""),
2580
+ children: "×"
2581
+ }),
2582
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_aria_components.Button, {
2583
+ className: `${prefix}__calendar-btn`,
2584
+ "aria-label": strings.openCalendar,
2585
+ onPress: () => groupRef.current?.querySelector("input")?.focus(),
2586
+ isDisabled: disabled || readOnly,
2587
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("i", {
2588
+ "aria-hidden": "true",
2589
+ className: "ph ph-calendar-blank"
2590
+ })
2837
2591
  })
2838
2592
  ]
2839
- }),
2840
- phase === "selecting-end" && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
2841
- className: "nb-date-range-picker__hint",
2842
- role: "status",
2843
- "aria-live": "polite",
2844
- children: "Selecciona la fecha de fin"
2845
- }),
2846
- open && (0, react_dom.createPortal)(/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
2593
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_aria_components.Popover, {
2594
+ isNonModal: Boolean(container),
2847
2595
  ref: panelRef,
2848
- className: "nb-date-range-picker__panel",
2849
- role: "dialog",
2850
- "aria-label": strings.selectDateRange,
2851
- style: panelStyle,
2852
- children: [
2853
- /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
2854
- className: "nb-date-range-picker__header",
2855
- children: [
2856
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
2857
- type: "button",
2858
- className: "nb-date-range-picker__nav",
2859
- "aria-label": strings.previousMonth,
2860
- onClick: () => setMonth((m) => addMonths(m, -1)),
2861
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("i", {
2862
- className: "ph ph-caret-left",
2863
- "aria-hidden": "true"
2864
- })
2865
- }),
2866
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
2867
- className: "nb-date-range-picker__month",
2868
- "aria-live": "polite",
2869
- children: formatMonthLabel(month, resolvedLocale)
2870
- }),
2871
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
2872
- type: "button",
2873
- className: "nb-date-range-picker__nav",
2874
- "aria-label": strings.nextMonth,
2875
- onClick: () => setMonth((m) => addMonths(m, 1)),
2876
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("i", {
2877
- className: "ph ph-caret-right",
2878
- "aria-hidden": "true"
2879
- })
2880
- })
2881
- ]
2882
- }),
2883
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
2884
- className: "nb-date-range-picker__weekdays",
2885
- "aria-hidden": "true",
2886
- children: weekdayLbls.map((label, i) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: label }, `${label}-${i}`))
2887
- }),
2888
- phase === "selecting-end" && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
2889
- className: "nb-date-range-picker__phase-banner",
2890
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("i", {
2891
- className: "ph ph-info",
2892
- "aria-hidden": "true"
2893
- }), "Ahora selecciona la fecha de fin"]
2894
- }),
2895
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
2896
- className: "nb-date-range-picker__days",
2897
- role: "grid",
2898
- "aria-label": formatMonthLabel(month, resolvedLocale),
2899
- children: days.map((day) => {
2900
- const role = getDayRoleInRange(day.iso, effectiveStart, effectiveEnd);
2901
- return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
2902
- type: "button",
2903
- className: cx("nb-date-range-picker__day", !day.inCurrentMonth && "nb-date-range-picker__day--muted", day.iso === todayIso && "nb-date-range-picker__day--today", role === "start" && "nb-date-range-picker__day--range-start", role === "end" && "nb-date-range-picker__day--range-end", role === "in-range" && "nb-date-range-picker__day--in-range", role === "single" && "nb-date-range-picker__day--range-single", phase === "selecting-end" && "nb-date-range-picker__day--selecting"),
2904
- disabled: day.disabled,
2905
- role: "gridcell",
2906
- "aria-selected": role !== "none",
2907
- onMouseEnter: () => phase === "selecting-end" && setHoverIso(day.iso),
2908
- onMouseLeave: () => phase === "selecting-end" && setHoverIso(null),
2909
- onClick: () => !day.disabled && handleDayClick(day.iso),
2910
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
2911
- className: "nb-date-range-picker__day-inner",
2912
- children: day.date.getDate()
2913
- })
2914
- }, day.iso);
2915
- })
2916
- }),
2917
- /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
2918
- className: "nb-date-range-picker__footer",
2919
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
2920
- type: "button",
2921
- className: "nb-date-range-picker__text-button",
2922
- onClick: () => {
2923
- onChange?.("", "");
2924
- closePanel();
2596
+ UNSTABLE_portalContainer: container ?? void 0,
2597
+ className: `${prefix}__panel`,
2598
+ offset: 4,
2599
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(CalendarDialog, {
2600
+ ariaLabel: strings.selectDateRange,
2601
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_aria_components.RangeCalendar, {
2602
+ className: "nb-calendar--range",
2603
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CalendarContent, {})
2604
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
2605
+ className: `${prefix}__footer`,
2606
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_aria_components.Button, {
2607
+ slot: null,
2608
+ className: `${prefix}__text-button`,
2609
+ onPress: () => {
2610
+ change("", "");
2611
+ setOpen(false);
2925
2612
  },
2926
2613
  children: strings.clear
2927
- }), phase === "selecting-end" ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
2928
- type: "button",
2929
- className: "nb-date-range-picker__text-button",
2930
- onClick: () => {
2931
- setPendingStart(null);
2932
- setPhase("idle");
2933
- setHoverIso(null);
2934
- },
2935
- children: strings.cancel
2936
- }) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
2937
- type: "button",
2938
- className: "nb-date-range-picker__text-button",
2939
- onClick: () => {
2940
- const today = toIsoDate(/* @__PURE__ */ new Date());
2941
- setMonth(startOfMonth(/* @__PURE__ */ new Date()));
2942
- if (!startIso) onChange?.(today, endIso ?? "");
2943
- else if (!endIso) onChange?.(startIso, today);
2944
- else onChange?.(today, today);
2945
- closePanel();
2614
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_aria_components.Button, {
2615
+ slot: null,
2616
+ className: `${prefix}__text-button`,
2617
+ isDisabled: !dateAllowed(todayIso, min, max),
2618
+ onPress: () => {
2619
+ change(todayIso, todayIso);
2620
+ setOpen(false);
2946
2621
  },
2947
2622
  children: strings.today
2948
2623
  })]
2949
- })
2950
- ]
2951
- }), document.body)
2952
- ]
2624
+ })]
2625
+ })
2626
+ })]
2627
+ })
2953
2628
  });
2954
2629
  }
2955
2630
  //#endregion
2956
2631
  //#region packages/ui/Popover.tsx
2957
2632
  const Popover = ({ trigger, panel, align = "end", ariaLabel, className }) => {
2958
- const { open, setOpen, toggle, containerRef } = useFloatingPanel();
2959
- return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
2960
- ref: containerRef,
2961
- className: [
2962
- "nb-popover",
2963
- `nb-popover--${align}`,
2964
- open && "nb-popover--open",
2965
- className
2966
- ].filter(Boolean).join(" "),
2967
- children: [trigger({
2968
- open,
2969
- toggle
2970
- }), open && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
2971
- className: "nb-popover__panel",
2972
- role: "dialog",
2973
- "aria-label": ariaLabel,
2974
- children: panel({ close: () => setOpen(false) })
2975
- })]
2633
+ const [open, setOpen] = (0, react.useState)(false);
2634
+ const triggerRef = (0, react.useRef)(null);
2635
+ const [restoreFocus, setRestoreFocus] = (0, react.useState)(true);
2636
+ const changeOpen = (next) => {
2637
+ setRestoreFocus(true);
2638
+ setOpen(next);
2639
+ };
2640
+ const container = useOverlayContainer();
2641
+ const triggerNode = trigger({
2642
+ open,
2643
+ toggle: () => changeOpen(!open)
2644
+ });
2645
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_base_ui_react_popover.Popover.Root, {
2646
+ open,
2647
+ onOpenChange: (next, details) => {
2648
+ setRestoreFocus(details.reason !== "outside-press" && details.reason !== "focus-out");
2649
+ setOpen(next);
2650
+ },
2651
+ onOpenChangeComplete: (next) => {
2652
+ if (!next && restoreFocus) triggerRef.current?.focus({ preventScroll: true });
2653
+ },
2654
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
2655
+ className: [
2656
+ "nb-popover",
2657
+ `nb-popover--${align}`,
2658
+ open && "nb-popover--open",
2659
+ className
2660
+ ].filter(Boolean).join(" "),
2661
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_base_ui_react_popover.Popover.Trigger, {
2662
+ ref: triggerRef,
2663
+ render: (0, react.isValidElement)(triggerNode) ? triggerNode : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
2664
+ type: "button",
2665
+ children: triggerNode
2666
+ })
2667
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_base_ui_react_popover.Popover.Portal, {
2668
+ container: container ?? void 0,
2669
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_base_ui_react_popover.Popover.Positioner, {
2670
+ align,
2671
+ sideOffset: 8,
2672
+ className: "nb-popover-positioner",
2673
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_base_ui_react_popover.Popover.Popup, {
2674
+ finalFocus: triggerRef,
2675
+ onKeyDownCapture: (event) => {
2676
+ if (event.key === "Escape") {
2677
+ event.preventDefault();
2678
+ event.stopPropagation();
2679
+ changeOpen(false);
2680
+ }
2681
+ },
2682
+ className: "nb-popover__panel",
2683
+ "aria-label": ariaLabel,
2684
+ children: panel({ close: () => changeOpen(false) })
2685
+ })
2686
+ })
2687
+ })]
2688
+ })
2976
2689
  });
2977
2690
  };
2978
2691
  //#endregion
2692
+ //#region packages/ui/useFloatingPanel.ts
2693
+ /** Style applied to an anchored panel before its first position is computed. */
2694
+ const HIDDEN_PANEL_STYLE = {
2695
+ position: "fixed",
2696
+ visibility: "hidden",
2697
+ margin: 0
2698
+ };
2699
+ function useFloatingPanel(options = {}) {
2700
+ const [open, setOpenState] = (0, react.useState)(false);
2701
+ const [panelStyle, setPanelStyle] = (0, react.useState)(HIDDEN_PANEL_STYLE);
2702
+ const containerRef = (0, react.useRef)(null);
2703
+ const panelRef = (0, react.useRef)(null);
2704
+ const optionsRef = (0, react.useRef)(options);
2705
+ optionsRef.current = options;
2706
+ const anchored = !!options.computeStyle;
2707
+ const dismissEvent = options.dismissEvent ?? "pointerdown";
2708
+ const setOpen = (0, react.useCallback)((next) => {
2709
+ setOpenState(next);
2710
+ if (!next) optionsRef.current.onClose?.();
2711
+ optionsRef.current.onOpenChange?.(next);
2712
+ }, []);
2713
+ const applyStyle = (0, react.useCallback)(() => {
2714
+ const compute = optionsRef.current.computeStyle;
2715
+ if (!compute) return;
2716
+ const style = compute(containerRef.current);
2717
+ if (style) setPanelStyle(style);
2718
+ }, []);
2719
+ const openPanel = (0, react.useCallback)(() => {
2720
+ applyStyle();
2721
+ setOpen(true);
2722
+ }, [applyStyle, setOpen]);
2723
+ const toggle = (0, react.useCallback)(() => open ? setOpen(false) : openPanel(), [
2724
+ open,
2725
+ openPanel,
2726
+ setOpen
2727
+ ]);
2728
+ (0, react.useEffect)(() => {
2729
+ if (!open) return;
2730
+ const handleOutside = (e) => {
2731
+ const target = e.target;
2732
+ if (containerRef.current?.contains(target) || panelRef.current?.contains(target)) return;
2733
+ setOpen(false);
2734
+ };
2735
+ const handleKeyDown = (e) => {
2736
+ if (e.key !== "Escape" || e.defaultPrevented) return;
2737
+ e.preventDefault();
2738
+ e.stopPropagation();
2739
+ setOpen(false);
2740
+ optionsRef.current.onEscape?.(e);
2741
+ };
2742
+ document.addEventListener(dismissEvent, handleOutside);
2743
+ document.addEventListener("keydown", handleKeyDown, true);
2744
+ return () => {
2745
+ document.removeEventListener(dismissEvent, handleOutside);
2746
+ document.removeEventListener("keydown", handleKeyDown, true);
2747
+ };
2748
+ }, [
2749
+ dismissEvent,
2750
+ open,
2751
+ setOpen
2752
+ ]);
2753
+ (0, react.useLayoutEffect)(() => {
2754
+ if (!open || !anchored) return;
2755
+ const update = () => {
2756
+ const container = containerRef.current;
2757
+ if (!container) return;
2758
+ if (optionsRef.current.closeOnViewportExit) {
2759
+ const rect = container.getBoundingClientRect();
2760
+ if ((rect.width > 0 || rect.height > 0) && (rect.top >= window.innerHeight || rect.bottom <= 0)) {
2761
+ setOpen(false);
2762
+ return;
2763
+ }
2764
+ }
2765
+ applyStyle();
2766
+ };
2767
+ update();
2768
+ window.addEventListener("resize", update);
2769
+ window.addEventListener("scroll", update, {
2770
+ capture: true,
2771
+ passive: true
2772
+ });
2773
+ return () => {
2774
+ window.removeEventListener("resize", update);
2775
+ window.removeEventListener("scroll", update, { capture: true });
2776
+ };
2777
+ }, [
2778
+ anchored,
2779
+ applyStyle,
2780
+ open,
2781
+ setOpen
2782
+ ]);
2783
+ return {
2784
+ open,
2785
+ setOpen,
2786
+ toggle,
2787
+ openPanel,
2788
+ containerRef,
2789
+ panelRef,
2790
+ panelStyle
2791
+ };
2792
+ }
2793
+ //#endregion
2979
2794
  //#region packages/ui/Drawer.tsx
2980
2795
  const formatWidth = (value) => {
2981
2796
  if (value === void 0) return void 0;
2982
2797
  return typeof value === "number" ? `${value}px` : value;
2983
2798
  };
2984
- const Drawer = ({ isOpen, onClose, title, width, side = "right", scrim = "subtle", children, footer, closeLabel, scrimLabel, className, "aria-label": ariaLabel }) => {
2799
+ const Drawer = ({ isOpen, busy = false, onClose, title, width, side = "right", scrim = "subtle", children, footer, closeLabel, scrimLabel, className, "aria-label": ariaLabel }) => {
2985
2800
  const strings = useUiStrings();
2986
2801
  const resolvedCloseLabel = closeLabel ?? strings.close;
2987
2802
  const resolvedScrimLabel = scrimLabel ?? strings.closePanel;
2988
2803
  const titleId = (0, react.useId)();
2989
- const panelRef = (0, react.useRef)(null);
2990
- const lastFocusRef = (0, react.useRef)(null);
2991
- (0, react.useEffect)(() => {
2992
- if (!isOpen) return;
2993
- lastFocusRef.current = document.activeElement;
2994
- const timer = window.setTimeout(() => {
2995
- (panelRef.current?.querySelector("button:not(:disabled), [href], input:not(:disabled), select:not(:disabled), textarea:not(:disabled), [tabindex]:not([tabindex=\"-1\"])"))?.focus();
2996
- });
2997
- return () => {
2998
- clearTimeout(timer);
2999
- lastFocusRef.current?.focus?.();
3000
- };
3001
- }, [isOpen]);
3002
- (0, react.useEffect)(() => {
3003
- if (!isOpen) return;
3004
- const handler = (e) => {
3005
- if (e.key === "Escape") {
3006
- e.preventDefault();
3007
- onClose();
3008
- }
3009
- };
3010
- document.addEventListener("keydown", handler);
3011
- return () => document.removeEventListener("keydown", handler);
3012
- }, [isOpen, onClose]);
3013
- return (0, react_dom.createPortal)(/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
3014
- className: [
2804
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(ModalSurface, {
2805
+ open: isOpen,
2806
+ onClose,
2807
+ closeOnEscape: !busy,
2808
+ closeOnOutsideClick: !busy,
2809
+ rootClassName: [
3015
2810
  "nb-drawer-root",
3016
2811
  isOpen && "nb-drawer-root--open",
3017
2812
  `nb-drawer-root--${side}`
3018
2813
  ].filter(Boolean).join(" "),
3019
- "aria-hidden": !isOpen,
3020
- style: { pointerEvents: isOpen ? void 0 : "none" },
3021
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
3022
- className: `nb-drawer__scrim nb-drawer__scrim--${scrim}`,
3023
- type: "button",
3024
- "aria-label": resolvedScrimLabel,
3025
- tabIndex: -1,
3026
- onClick: onClose
3027
- }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("aside", {
3028
- ref: panelRef,
3029
- className: ["nb-drawer", className].filter(Boolean).join(" "),
3030
- role: "dialog",
3031
- "aria-modal": "false",
3032
- "aria-labelledby": title ? titleId : void 0,
3033
- "aria-label": !title ? ariaLabel : void 0,
3034
- style: { width: formatWidth(width) },
3035
- children: [
3036
- title !== void 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("header", {
3037
- className: "nb-drawer__header",
3038
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("h2", {
3039
- className: "nb-drawer__title",
3040
- id: titleId,
3041
- children: title
3042
- }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(IconButton, {
3043
- className: "nb-drawer__close",
3044
- icon: "ph ph-x",
3045
- label: resolvedCloseLabel,
3046
- onClick: onClose
3047
- })]
3048
- }),
3049
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
3050
- className: "nb-drawer__body",
3051
- children
3052
- }),
3053
- footer && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("footer", {
3054
- className: "nb-drawer__footer",
3055
- children: footer
3056
- })
3057
- ]
3058
- })]
3059
- }), document.body);
2814
+ className: ["nb-drawer", className].filter(Boolean).join(" "),
2815
+ scrimClassName: `nb-drawer__scrim nb-drawer__scrim--${scrim}`,
2816
+ scrimLabel: resolvedScrimLabel,
2817
+ labelledBy: title ? titleId : void 0,
2818
+ ariaLabel: !title ? ariaLabel : void 0,
2819
+ style: { width: formatWidth(width) },
2820
+ keepMounted: true,
2821
+ children: [
2822
+ title !== void 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("header", {
2823
+ className: "nb-drawer__header",
2824
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("h2", {
2825
+ className: "nb-drawer__title",
2826
+ id: titleId,
2827
+ children: title
2828
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(IconButton, {
2829
+ className: "nb-drawer__close",
2830
+ icon: "ph ph-x",
2831
+ label: resolvedCloseLabel,
2832
+ onClick: onClose,
2833
+ disabled: busy
2834
+ })]
2835
+ }),
2836
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
2837
+ className: "nb-drawer__body",
2838
+ children
2839
+ }),
2840
+ footer && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("footer", {
2841
+ className: "nb-drawer__footer",
2842
+ children: footer
2843
+ })
2844
+ ]
2845
+ });
3060
2846
  };
3061
2847
  //#endregion
3062
2848
  //#region packages/ui/Timeline.tsx
@@ -3166,7 +2952,7 @@ function Page({ children, fill, wide, narrow, gap = 5, className, ...props }) {
3166
2952
  }
3167
2953
  //#endregion
3168
2954
  //#region packages/ui/PageHeader.tsx
3169
- function PageHeader({ title, subtitle, breadcrumb, breadcrumbSlot, badge, actions, className }) {
2955
+ function PageHeader({ title, subtitle, metadata, breadcrumb, breadcrumbSlot, badge, actions, className }) {
3170
2956
  const breadcrumbNode = breadcrumbSlot ?? (breadcrumb ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("a", {
3171
2957
  href: breadcrumb.href,
3172
2958
  className: "nb-page-header__breadcrumb",
@@ -3185,6 +2971,10 @@ function PageHeader({ title, subtitle, breadcrumb, breadcrumbSlot, badge, action
3185
2971
  className: "nb-page-header__title",
3186
2972
  children: title
3187
2973
  }),
2974
+ metadata && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
2975
+ className: "nb-page-header__metadata",
2976
+ children: metadata
2977
+ }),
3188
2978
  subtitle && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
3189
2979
  className: "nb-page-header__subtitle",
3190
2980
  children: subtitle
@@ -3254,9 +3044,9 @@ function Col({ children, span, spanSm, spanMd, spanLg, fullWidth, className, ...
3254
3044
  }
3255
3045
  //#endregion
3256
3046
  //#region packages/ui/Section.tsx
3257
- function Section({ title, children, className }) {
3047
+ function Section({ title, children, className, variant = "label" }) {
3258
3048
  return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("section", {
3259
- className: joinClasses("nb-section", className),
3049
+ className: joinClasses("nb-section", variant === "panel" && "nb-section--panel", className),
3260
3050
  children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("h2", {
3261
3051
  className: "nb-section__title",
3262
3052
  children: title
@@ -3459,6 +3249,241 @@ function useConfirm() {
3459
3249
  };
3460
3250
  }
3461
3251
  //#endregion
3252
+ //#region packages/ui/Checkbox.tsx
3253
+ /** Native checkbox, including the mixed state used by bulk selection. */
3254
+ const Checkbox = (0, react.forwardRef)(function Checkbox({ label, indeterminate = false, invalid = false, id, className, ...props }, ref) {
3255
+ const generatedId = (0, react.useId)();
3256
+ const inputRef = (0, react.useRef)(null);
3257
+ (0, react.useEffect)(() => {
3258
+ if (inputRef.current) inputRef.current.indeterminate = indeterminate;
3259
+ }, [indeterminate]);
3260
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("label", {
3261
+ className: `nb-selection-control${className ? ` ${className}` : ""}`,
3262
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
3263
+ ...props,
3264
+ id: id ?? generatedId,
3265
+ type: "checkbox",
3266
+ "aria-invalid": props["aria-invalid"] ?? (invalid || void 0),
3267
+ ref: (node) => {
3268
+ inputRef.current = node;
3269
+ if (typeof ref === "function") return ref(node);
3270
+ if (ref) ref.current = node;
3271
+ }
3272
+ }), label && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: label })]
3273
+ });
3274
+ });
3275
+ //#endregion
3276
+ //#region packages/ui/RadioGroup.tsx
3277
+ /** Native radios share a name for browser keyboard navigation and form submission. */
3278
+ function RadioGroup({ label, name, value, options, onChange, orientation = "vertical", required, invalid = false, disabled, className, ...props }) {
3279
+ const generatedName = (0, react.useId)();
3280
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("fieldset", {
3281
+ ...props,
3282
+ disabled,
3283
+ "aria-invalid": props["aria-invalid"] ?? (invalid || void 0),
3284
+ className: `nb-radio-group${className ? ` ${className}` : ""}`,
3285
+ children: [label && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("legend", { children: label }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
3286
+ className: `nb-radio-group__options nb-radio-group__options--${orientation}`,
3287
+ children: options.map((option) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("label", {
3288
+ className: "nb-selection-control",
3289
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
3290
+ type: "radio",
3291
+ name: name ?? generatedName,
3292
+ value: option.value,
3293
+ checked: value === option.value,
3294
+ disabled: disabled || option.disabled,
3295
+ required,
3296
+ onChange: () => onChange(option.value)
3297
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: option.label })]
3298
+ }, option.value))
3299
+ })]
3300
+ });
3301
+ }
3302
+ //#endregion
3303
+ //#region packages/ui/Tabs.tsx
3304
+ function Tabs({ items, value, onChange, "aria-label": ariaLabel, orientation = "horizontal", activationMode = "automatic", keepMounted = false, className }) {
3305
+ const id = (0, react.useId)();
3306
+ const listRef = (0, react.useRef)(null);
3307
+ const [focusedValue, setFocusedValue] = (0, react.useState)(null);
3308
+ const selectedIndex = items.findIndex((item) => item.value === value && !item.disabled);
3309
+ const focusedIndex = items.findIndex((item) => item.value === focusedValue && !item.disabled);
3310
+ const tabStop = activationMode === "manual" && focusedIndex >= 0 ? focusedIndex : selectedIndex >= 0 ? selectedIndex : items.findIndex((item) => !item.disabled);
3311
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
3312
+ className: `nb-tabs nb-tabs--${orientation}${className ? ` ${className}` : ""}`,
3313
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
3314
+ ref: listRef,
3315
+ role: "tablist",
3316
+ "aria-label": ariaLabel,
3317
+ "aria-orientation": orientation,
3318
+ className: "nb-tabs__list",
3319
+ children: items.map((item, index) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
3320
+ type: "button",
3321
+ role: "tab",
3322
+ id: `${id}-tab-${index}`,
3323
+ "aria-controls": `${id}-panel-${index}`,
3324
+ "aria-selected": index === selectedIndex,
3325
+ disabled: item.disabled,
3326
+ tabIndex: index === tabStop ? 0 : -1,
3327
+ className: "nb-tabs__tab",
3328
+ onFocus: () => setFocusedValue(item.value),
3329
+ onClick: () => onChange(item.value),
3330
+ onKeyDown: (event) => {
3331
+ const nextKey = orientation === "horizontal" ? "ArrowRight" : "ArrowDown";
3332
+ if (![
3333
+ nextKey,
3334
+ orientation === "horizontal" ? "ArrowLeft" : "ArrowUp",
3335
+ "Home",
3336
+ "End"
3337
+ ].includes(event.key)) return;
3338
+ event.preventDefault();
3339
+ const enabled = items.map((entry, i) => entry.disabled ? -1 : i).filter((i) => i >= 0);
3340
+ const position = enabled.indexOf(index);
3341
+ const next = event.key === "Home" ? enabled[0] : event.key === "End" ? enabled[enabled.length - 1] : enabled[(position + (event.key === nextKey ? 1 : -1) + enabled.length) % enabled.length];
3342
+ if (next === void 0) return;
3343
+ listRef.current?.querySelectorAll("[role=\"tab\"]")[next]?.focus();
3344
+ if (activationMode === "automatic") onChange(items[next].value);
3345
+ },
3346
+ children: item.label
3347
+ }, item.value))
3348
+ }), items.map((item, index) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
3349
+ role: "tabpanel",
3350
+ id: `${id}-panel-${index}`,
3351
+ "aria-labelledby": `${id}-tab-${index}`,
3352
+ hidden: index !== selectedIndex,
3353
+ tabIndex: 0,
3354
+ className: "nb-tabs__panel",
3355
+ children: keepMounted || index === selectedIndex ? item.content : null
3356
+ }, item.value))]
3357
+ });
3358
+ }
3359
+ //#endregion
3360
+ //#region packages/ui/Spinner.tsx
3361
+ function Spinner({ label, size = "md", className, ...props }) {
3362
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
3363
+ ...props,
3364
+ className: `nb-spinner nb-spinner--${size}${className ? ` ${className}` : ""}`,
3365
+ role: label ? "status" : void 0,
3366
+ "aria-label": label,
3367
+ "aria-hidden": label ? void 0 : true
3368
+ });
3369
+ }
3370
+ //#endregion
3371
+ //#region packages/ui/Progress.tsx
3372
+ /** Omit value for indeterminate progress; max defaults to 100. */
3373
+ function Progress({ label, id, max = 100, className, ...props }) {
3374
+ const generatedId = (0, react.useId)();
3375
+ const progressId = id ?? generatedId;
3376
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
3377
+ className: "nb-progress-field",
3378
+ children: [label && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("label", {
3379
+ htmlFor: progressId,
3380
+ children: label
3381
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("progress", {
3382
+ ...props,
3383
+ id: progressId,
3384
+ max,
3385
+ className: `nb-progress${className ? ` ${className}` : ""}`
3386
+ })]
3387
+ });
3388
+ }
3389
+ //#endregion
3390
+ //#region packages/ui/Tooltip.tsx
3391
+ const TooltipProvider = _base_ui_react_tooltip.Tooltip.Provider;
3392
+ /** Uses the existing child as the trigger without adding a nested button. */
3393
+ function Tooltip({ children, content, side = "top", delay, disabled, className }) {
3394
+ const overlayContainer = useOverlayContainer();
3395
+ const id = (0, react.useId)();
3396
+ const [open, setOpen] = (0, react.useState)(false);
3397
+ const description = [children.props["aria-describedby"], open && !disabled ? id : void 0].filter(Boolean).join(" ") || void 0;
3398
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_base_ui_react_tooltip.Tooltip.Root, {
3399
+ open,
3400
+ disabled,
3401
+ onOpenChange: setOpen,
3402
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_base_ui_react_tooltip.Tooltip.Trigger, {
3403
+ render: (0, react.cloneElement)(children, { "aria-describedby": description }),
3404
+ onKeyDownCapture: (event) => {
3405
+ if (open && event.key === "Escape") {
3406
+ event.stopPropagation();
3407
+ setOpen(false);
3408
+ }
3409
+ },
3410
+ delay
3411
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_base_ui_react_tooltip.Tooltip.Portal, {
3412
+ container: overlayContainer ?? void 0,
3413
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_base_ui_react_tooltip.Tooltip.Positioner, {
3414
+ side,
3415
+ sideOffset: 8,
3416
+ className: "nb-tooltip-positioner",
3417
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_base_ui_react_tooltip.Tooltip.Popup, {
3418
+ id,
3419
+ role: "tooltip",
3420
+ className: `nb-tooltip${className ? ` ${className}` : ""}`,
3421
+ children: content
3422
+ })
3423
+ })
3424
+ })]
3425
+ });
3426
+ }
3427
+ //#endregion
3428
+ //#region packages/ui/TimePicker.tsx
3429
+ const timeValue = (value) => {
3430
+ if (!value) return null;
3431
+ try {
3432
+ return (0, _internationalized_date.parseTime)(value);
3433
+ } catch {
3434
+ return null;
3435
+ }
3436
+ };
3437
+ /** Accessible segmented time entry. Values never pass through Date or a timezone. */
3438
+ const TimePicker = (0, react.forwardRef)(function TimePicker({ id, name, value, onChange, onBlur, min, max, locale, hourCycle, granularity = "minute", disabled, readOnly, required, invalid, className, ariaLabel }, ref) {
3439
+ const strings = useUiStrings();
3440
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_aria_components.I18nProvider, {
3441
+ locale: getDateLocale(locale),
3442
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_aria_components.TimeField, {
3443
+ id,
3444
+ name,
3445
+ "aria-label": ariaLabel ?? strings.selectTime,
3446
+ value: timeValue(value),
3447
+ onChange: (next) => onChange?.(next ? next.toString().slice(0, granularity === "second" ? 8 : 5) : ""),
3448
+ onBlur,
3449
+ minValue: timeValue(min) ?? void 0,
3450
+ maxValue: timeValue(max) ?? void 0,
3451
+ granularity,
3452
+ hourCycle,
3453
+ isDisabled: disabled,
3454
+ isReadOnly: readOnly,
3455
+ isRequired: required,
3456
+ isInvalid: invalid,
3457
+ validationBehavior: "aria",
3458
+ className: ["nb-time-picker", className].filter(Boolean).join(" "),
3459
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_aria_components.DateInput, {
3460
+ ref,
3461
+ className: "nb-time-picker__input",
3462
+ children: (segment) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_aria_components.DateSegment, {
3463
+ segment,
3464
+ className: "nb-time-picker__segment"
3465
+ })
3466
+ })
3467
+ })
3468
+ });
3469
+ });
3470
+ //#endregion
3471
+ //#region packages/ui/DetailLayout.tsx
3472
+ /** Responsive main/aside composition for record detail pages. */
3473
+ function DetailLayout({ children, aside, asideLabel, className }) {
3474
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
3475
+ className: joinClasses("nb-detail-layout", className),
3476
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
3477
+ className: "nb-detail-layout__main",
3478
+ children
3479
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("aside", {
3480
+ className: "nb-detail-layout__aside",
3481
+ "aria-label": asideLabel,
3482
+ children: aside
3483
+ })]
3484
+ });
3485
+ }
3486
+ //#endregion
3462
3487
  exports.ACCENT_PRESETS = ACCENT_PRESETS;
3463
3488
  exports.Alert = Alert;
3464
3489
  exports.AppDialog = AppDialog;
@@ -3468,11 +3493,13 @@ exports.Avatar = Avatar;
3468
3493
  exports.Badge = Badge;
3469
3494
  exports.Button = Button;
3470
3495
  exports.Card = Card;
3496
+ exports.Checkbox = Checkbox;
3471
3497
  exports.Chip = Chip;
3472
3498
  exports.Cluster = Cluster;
3473
3499
  exports.Code = Code;
3474
3500
  exports.Col = Col;
3475
3501
  exports.CollapsibleSection = CollapsibleSection;
3502
+ exports.Combobox = Combobox;
3476
3503
  exports.ConfirmDialog = ConfirmDialog;
3477
3504
  exports.ContextMenu = ContextMenu;
3478
3505
  exports.DataTable = DataTable;
@@ -3481,6 +3508,7 @@ exports.DateRangePicker = DateRangePicker;
3481
3508
  exports.DensityContext = DensityContext;
3482
3509
  exports.DensityProvider = DensityProvider;
3483
3510
  exports.DescriptionList = DescriptionList;
3511
+ exports.DetailLayout = DetailLayout;
3484
3512
  exports.Drawer = Drawer;
3485
3513
  exports.EN_UI_STRINGS = EN_UI_STRINGS;
3486
3514
  exports.ES_UI_STRINGS = ES_UI_STRINGS;
@@ -3495,11 +3523,14 @@ exports.Grid = Grid;
3495
3523
  exports.HubPanel = HubPanel;
3496
3524
  exports.IconButton = IconButton;
3497
3525
  exports.KpiMetricRow = KpiMetricRow;
3526
+ exports.MultiSelect = MultiSelect;
3498
3527
  exports.OperationCardGrid = OperationCardGrid;
3499
3528
  exports.Page = Page;
3500
3529
  exports.PageHeader = PageHeader;
3501
3530
  exports.Pagination = Pagination;
3502
3531
  exports.Popover = Popover;
3532
+ exports.Progress = Progress;
3533
+ exports.RadioGroup = RadioGroup;
3503
3534
  exports.Row = Row;
3504
3535
  exports.RowActions = RowActions;
3505
3536
  exports.ScopeTabs = ScopeTabs;
@@ -3509,17 +3540,22 @@ exports.SegmentedControl = SegmentedControl;
3509
3540
  exports.SelectField = SelectField;
3510
3541
  exports.SettingsPanel = SettingsPanel;
3511
3542
  exports.Skeleton = Skeleton;
3543
+ exports.Spinner = Spinner;
3512
3544
  exports.Stack = Stack;
3513
3545
  exports.StatCard = StatCard;
3546
+ exports.Tabs = Tabs;
3514
3547
  exports.Text = Text;
3515
3548
  exports.TextAreaField = TextAreaField;
3516
3549
  exports.TextField = TextField;
3517
3550
  exports.ThemeContext = ThemeContext;
3518
3551
  exports.ThemeProvider = ThemeProvider;
3519
3552
  exports.ThemeSwitcher = ThemeSwitcher;
3553
+ exports.TimePicker = TimePicker;
3520
3554
  exports.Timeline = Timeline;
3521
3555
  exports.TimelineItem = TimelineItem;
3522
3556
  exports.Toggle = Toggle;
3557
+ exports.Tooltip = Tooltip;
3558
+ exports.TooltipProvider = TooltipProvider;
3523
3559
  exports.UiStringsProvider = UiStringsProvider;
3524
3560
  exports.getAvatarHue = getAvatarHue;
3525
3561
  exports.getAvatarInitials = getAvatarInitials;
@@ -3527,5 +3563,6 @@ exports.useAccentColor = useAccentColor;
3527
3563
  exports.useConfirm = useConfirm;
3528
3564
  exports.useDensity = useDensity;
3529
3565
  exports.useFloatingPanel = useFloatingPanel;
3566
+ exports.useOverlayContainer = useOverlayContainer;
3530
3567
  exports.useTheme = useTheme;
3531
3568
  exports.useUiStrings = useUiStrings;