@nubitio/ui 1.1.2 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.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,532 @@ 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)(react_aria_components.Input, {
1034
+ ...inputProps,
1035
+ ref: inputRef,
1036
+ id: inputId,
1037
+ className: `nb-input nb-combobox__input${invalid || error ? " nb-input--invalid" : ""}${inputClassName ? ` ${inputClassName}` : ""}`,
1038
+ onKeyDown: (event) => {
1039
+ inputProps.onKeyDown?.(event);
1040
+ if (open && event.key === "Escape") event.stopPropagation();
1041
+ if (!event.defaultPrevented && event.key === "PageDown" && remote.hasMore) {
1042
+ event.preventDefault();
1043
+ remote.loadMore();
1044
+ }
1045
+ },
1046
+ "aria-invalid": inputProps["aria-invalid"] ?? (invalid || !!error || void 0),
1047
+ "aria-describedby": description
1048
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1049
+ className: "nb-combobox__actions",
1050
+ children: [clearable && !readOnly && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ComboboxClear, {
1051
+ label: clearLabel ?? strings.clear,
1052
+ disabled,
1053
+ multiple
1054
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_aria_components.Button, {
1055
+ className: "nb-combobox__action",
1056
+ "aria-label": openLabel ?? strings.openOptions,
1057
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("svg", {
1058
+ viewBox: "0 0 24 24",
1059
+ "aria-hidden": "true",
1060
+ focusable: "false",
1061
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", { d: "m6 9 6 6 6-6" })
1062
+ })
1063
+ })]
1064
+ })]
819
1065
  }),
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,
1066
+ 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, {
1067
+ "aria-label": selectedLabel ?? strings.selectedOptions,
1068
+ onRemove: disabled || readOnly ? void 0 : (keys) => onChange(selected.filter((key) => !keys.has(key))),
1069
+ className: "nb-combobox-tags",
1070
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_aria_components.TagList, {
1071
+ items: selectedOptions,
1072
+ children: (option) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_aria_components.Tag, {
1073
+ id: option.value,
1074
+ textValue: option.label,
1075
+ className: "nb-combobox-tags__tag",
1076
+ children: [option.label, !disabled && !readOnly && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_aria_components.Button, {
1077
+ slot: "remove",
1078
+ className: "nb-combobox-tags__remove",
1079
+ "aria-label": removeLabel?.(option) ?? strings.removeOption,
1080
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("svg", {
1081
+ viewBox: "0 0 24 24",
1082
+ "aria-hidden": "true",
1083
+ focusable: "false",
1084
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", { d: "m6 6 12 12M18 6 6 18" })
1085
+ })
1086
+ })]
1087
+ })
1088
+ })
1089
+ }) }),
1090
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_aria_components.Popover, {
1091
+ UNSTABLE_portalContainer: overlayContainer ?? void 0,
1092
+ className: "nb-combobox-popup",
1093
+ offset: 4,
1094
+ isNonModal: true,
1095
+ onScroll: (event) => {
1096
+ const panel = event.currentTarget;
1097
+ if (panel.scrollHeight - panel.scrollTop <= panel.clientHeight + 20) remote.loadMore();
1098
+ },
824
1099
  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);
1100
+ remoteStatus && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
1101
+ className: "nb-combobox-popup__empty",
1102
+ role: remote.failed ? "alert" : "status",
1103
+ children: remoteStatus
1104
+ }),
1105
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_aria_components.ListBox, {
1106
+ className: "nb-combobox-popup__list",
1107
+ "aria-busy": remote.loading || void 0,
1108
+ renderEmptyState: () => remoteStatus ? null : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
1109
+ className: "nb-combobox-popup__empty",
1110
+ children: emptyMessage ?? strings.noOptions
1111
+ }),
1112
+ children: (option) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_aria_components.ListBoxItem, {
1113
+ id: option.value,
1114
+ textValue: option.label,
1115
+ isDisabled: option.disabled,
1116
+ className: "nb-combobox-popup__item",
1117
+ children: ({ isSelected }) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1118
+ className: "nb-combobox-popup__indicator",
1119
+ "aria-hidden": "true",
1120
+ children: isSelected ? "✓" : ""
1121
+ }), option.content ?? option.label] })
855
1122
  })
856
1123
  }),
857
- menuFooter
1124
+ remote.hasMore && !remote.failed && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_aria_components.Button, {
1125
+ slot: null,
1126
+ className: "nb-combobox__action",
1127
+ isDisabled: remote.loading,
1128
+ onPress: () => {
1129
+ remote.loadMore();
1130
+ },
1131
+ children: strings.loadMore
1132
+ }),
1133
+ remote.failed && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_aria_components.Button, {
1134
+ className: "nb-combobox__action",
1135
+ onPress: remote.retry,
1136
+ children: strings.retrySearch
1137
+ })
858
1138
  ]
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
1139
  }),
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
1140
+ message && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1141
+ id: messageId,
1142
+ className: error ? "nb-form-field__error" : "nb-form-field__help",
1143
+ role: error ? "alert" : void 0,
1144
+ children: message
1145
+ })
881
1146
  ]
882
1147
  });
883
1148
  }
1149
+ function ComboboxClear({ label, disabled, multiple }) {
1150
+ const state = (0, react.useContext)(react_aria_components.ComboBoxStateContext);
1151
+ const hasValue = multiple ? Array.isArray(state?.value) && state.value.length > 0 : !!state?.inputValue;
1152
+ if (!state || !hasValue || state.isOpen) return null;
1153
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_aria_components.Button, {
1154
+ slot: null,
1155
+ isDisabled: disabled,
1156
+ className: "nb-combobox__action nb-combobox__clear",
1157
+ "aria-label": label,
1158
+ onPress: () => {
1159
+ state.setValue(multiple ? [] : null);
1160
+ state.setInputValue("");
1161
+ },
1162
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("svg", {
1163
+ viewBox: "0 0 24 24",
1164
+ "aria-hidden": "true",
1165
+ focusable: "false",
1166
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", { d: "m6 6 12 12M18 6 6 18" })
1167
+ })
1168
+ });
1169
+ }
884
1170
  //#endregion
885
1171
  //#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, {
1172
+ const toOption = (option) => ({
1173
+ value: option.value,
1174
+ label: option.selectedLabel ?? option.label,
1175
+ disabled: option.disabled,
1176
+ content: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
1177
+ className: "nb-dropdown__option-content",
1178
+ children: [option.iconText && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1179
+ className: "nb-dropdown__option-icon",
1180
+ "aria-hidden": "true",
1181
+ children: option.iconText
1182
+ }), option.label]
1183
+ })
1184
+ });
1185
+ 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 }) {
1186
+ const loadOptions = (0, react.useCallback)(async (query, { signal }) => {
1187
+ const results = await onSearch(query.trim());
1188
+ if (signal.aborted) throw new DOMException("Search cancelled", "AbortError");
1189
+ return { options: results.map(toOption) };
1190
+ }, [onSearch]);
1191
+ if (!searchable) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(AppDropdown, {
1003
1192
  ...rest,
1193
+ options,
1004
1194
  value,
1005
1195
  onChange,
1006
1196
  placeholder,
1007
1197
  disabled,
1008
- options: [{
1009
- value: "",
1010
- label: placeholder ?? "Seleccionar…"
1011
- }, ...resolvedOptions],
1012
- menuHeader,
1013
- menuFooter,
1014
- onOpenChange: setOpen
1198
+ label,
1199
+ showFieldLabel,
1200
+ variant,
1201
+ icon: _icon,
1202
+ menuMinWidth: _menuMinWidth,
1203
+ menuHeader: _header,
1204
+ menuFooter: _footer
1205
+ });
1206
+ const seeds = selectedOption && !options.some((option) => option.value === selectedOption.value) ? [...options, selectedOption] : options;
1207
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Combobox, {
1208
+ ...rest,
1209
+ label: showFieldLabel === false ? void 0 : label,
1210
+ "aria-label": showFieldLabel === false && typeof label === "string" ? label : void 0,
1211
+ placeholder: placeholder ?? searchPlaceholder,
1212
+ options: seeds.map(toOption),
1213
+ value: value || null,
1214
+ onChange: (next) => onChange(next ?? ""),
1215
+ disabled,
1216
+ loadOptions: onSearch ? loadOptions : void 0,
1217
+ minSearchLength,
1218
+ emptyMessage: emptySearchLabel,
1219
+ loadingMessage: loadingLabel
1015
1220
  });
1016
1221
  }
1017
1222
  //#endregion
@@ -1074,7 +1279,7 @@ function applyThemeAttributes(theme, themePrefix) {
1074
1279
  themeValues.forEach((value) => root.classList.remove(`${themePrefix}${value}`));
1075
1280
  root.classList.add(`${themePrefix}${theme}`);
1076
1281
  }
1077
- const ThemeProvider = ({ storageKey = "nb-theme", themePrefix = "nb-theme-", basePath = "/themes/", children }) => {
1282
+ const ThemeProvider = ({ storageKey = "nb-theme", themePrefix = "nb-theme-", basePath = "/themes/", visualStyle = "default", children }) => {
1078
1283
  const getPersistedMode = () => {
1079
1284
  const persisted = window.localStorage.getItem(storageKey);
1080
1285
  return persisted && themeModes.includes(persisted) ? persisted : "auto";
@@ -1083,6 +1288,15 @@ const ThemeProvider = ({ storageKey = "nb-theme", themePrefix = "nb-theme-", bas
1083
1288
  const [systemTheme, setSystemTheme] = (0, react.useState)(getSystemTheme);
1084
1289
  const [isLoaded, setIsLoaded] = (0, react.useState)(false);
1085
1290
  const theme = (0, react.useMemo)(() => resolveTheme(mode, systemTheme), [mode, systemTheme]);
1291
+ (0, react.useEffect)(() => {
1292
+ const root = document.documentElement;
1293
+ const previous = root.getAttribute("data-visual-style");
1294
+ root.setAttribute("data-visual-style", visualStyle);
1295
+ return () => {
1296
+ if (previous === null) root.removeAttribute("data-visual-style");
1297
+ else root.setAttribute("data-visual-style", previous);
1298
+ };
1299
+ }, [visualStyle]);
1086
1300
  (0, react.useEffect)(() => {
1087
1301
  applyThemeAttributes(theme, themePrefix);
1088
1302
  setThemeToDOM(`${basePath}${themePrefix}${theme}.css`).then(() => setIsLoaded(true));
@@ -1425,7 +1639,7 @@ const DEFAULT_ICONS = {
1425
1639
  warning: "warning",
1426
1640
  success: "check-circle"
1427
1641
  };
1428
- const EmptyState = ({ icon, variant = "default", title, description, action, size = "md", fill = false, className }) => {
1642
+ const EmptyState = ({ icon, illustration, variant = "default", title, description, action, size = "md", fill = false, className }) => {
1429
1643
  const iconName = icon ?? DEFAULT_ICONS[variant];
1430
1644
  const classes = [
1431
1645
  "nb-empty-state",
@@ -1441,7 +1655,7 @@ const EmptyState = ({ icon, variant = "default", title, description, action, siz
1441
1655
  children: [
1442
1656
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
1443
1657
  className: "nb-empty-state__icon-wrap",
1444
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("i", {
1658
+ children: illustration ?? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("i", {
1445
1659
  className: `ph ph-${iconName}`,
1446
1660
  "aria-hidden": "true"
1447
1661
  })
@@ -1522,73 +1736,51 @@ const Toggle = ({ checked, onChange, label, size = "md", disabled = false, "aria
1522
1736
  };
1523
1737
  //#endregion
1524
1738
  //#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
1739
  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
- });
1740
+ const container = useOverlayContainer();
1741
+ const triggerRef = (0, react.useRef)(null);
1742
+ const restoreFocus = (0, react.useRef)(false);
1550
1743
  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)]
1744
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_base_ui_react_menu.Menu.Root, {
1745
+ modal: false,
1746
+ onOpenChange: (open, details) => {
1747
+ restoreFocus.current = !open && (details.reason === "item-press" || details.reason === "escape-key");
1748
+ },
1749
+ onOpenChangeComplete: (open) => {
1750
+ if (!open && restoreFocus.current) triggerRef.current?.focus({ preventScroll: true });
1751
+ },
1752
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1753
+ className: `nb-context-menu${className ? ` ${className}` : ""}`,
1754
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_base_ui_react_menu.Menu.Trigger, {
1755
+ ref: triggerRef,
1756
+ render: (0, react.isValidElement)(trigger) ? trigger : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(IconButton, {
1757
+ icon: "ph ph-dots-three",
1758
+ label: triggerLabel,
1759
+ children: trigger
1760
+ })
1761
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_base_ui_react_menu.Menu.Portal, {
1762
+ container: container ?? void 0,
1763
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_base_ui_react_menu.Menu.Positioner, {
1764
+ align: align === "right" ? "end" : "start",
1765
+ sideOffset: 4,
1766
+ className: "nb-context-menu-positioner",
1767
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_base_ui_react_menu.Menu.Popup, {
1768
+ finalFocus: triggerRef,
1769
+ className: "nb-context-menu__dropdown",
1770
+ 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, {
1771
+ disabled: item.disabled,
1772
+ label: item.label,
1773
+ className: `nb-context-menu__item${item.danger ? " nb-context-menu__item--danger" : ""}`,
1774
+ onClick: item.onClick,
1775
+ children: [item.icon && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("i", {
1776
+ className: item.icon,
1777
+ "aria-hidden": "true"
1778
+ }), item.label]
1779
+ })] }, index))
1780
+ })
1781
+ })
1782
+ })]
1783
+ })
1592
1784
  });
1593
1785
  };
1594
1786
  //#endregion
@@ -1913,6 +2105,7 @@ const CollapsibleSection = ({ label, icon, open, onToggle, children, trailing, c
1913
2105
  className: "nb-collapsible__header",
1914
2106
  children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
1915
2107
  type: "button",
2108
+ id: `${bodyId}-trigger`,
1916
2109
  className: "nb-collapsible__trigger",
1917
2110
  "aria-expanded": open,
1918
2111
  "aria-controls": bodyId,
@@ -1939,1124 +2132,699 @@ const CollapsibleSection = ({ label, icon, open, onToggle, children, trailing, c
1939
2132
  id: bodyId,
1940
2133
  className: ["nb-collapsible__body", bodyClassName].filter(Boolean).join(" "),
1941
2134
  role: "region",
1942
- "aria-labelledby": void 0,
2135
+ "aria-labelledby": `${bodyId}-trigger`,
1943
2136
  hidden: !open,
1944
2137
  children
1945
2138
  })]
1946
2139
  });
1947
2140
  };
1948
2141
  //#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 {
2142
+ //#region packages/ui/CalendarContent.tsx
2143
+ /** Shared presentation; React Aria owns navigation, focus and range preview. */
2144
+ function CalendarContent() {
2145
+ const strings = useUiStrings();
2146
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("header", {
2147
+ className: "nb-calendar__header",
2148
+ children: [
2149
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_aria_components.Button, {
2150
+ slot: "previous",
2151
+ className: "nb-date-picker__nav",
2152
+ "aria-label": strings.previousMonth,
2153
+ children: "‹"
2154
+ }),
2155
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
2156
+ className: "nb-calendar__selectors",
2157
+ children: [
2158
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_aria_components.Heading, { className: "nb-calendar__heading" }),
2159
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_aria_components.CalendarMonthPicker, { children: ({ items, value, onChange, ...props }) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("select", {
2160
+ ...props,
2161
+ value,
2162
+ onChange: (event) => onChange(Number(event.target.value)),
2163
+ children: items.map((item) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("option", {
2164
+ value: item.id,
2165
+ children: item.formatted
2166
+ }, item.id))
2167
+ }) }),
2168
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_aria_components.CalendarYearPicker, { children: ({ items, value, onChange, ...props }) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("select", {
2169
+ ...props,
2170
+ value,
2171
+ onChange: (event) => onChange(Number(event.target.value)),
2172
+ children: items.map((item) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("option", {
2173
+ value: item.id,
2174
+ children: item.formatted
2175
+ }, item.id))
2176
+ }) })
2177
+ ]
2178
+ }),
2179
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_aria_components.Button, {
2180
+ slot: "next",
2181
+ className: "nb-date-picker__nav",
2182
+ "aria-label": strings.nextMonth,
2183
+ children: "›"
2184
+ })
2185
+ ]
2186
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_aria_components.CalendarGrid, {
2187
+ className: "nb-calendar__grid",
2188
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_aria_components.CalendarGridHeader, { children: (day) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_aria_components.CalendarHeaderCell, {
2189
+ className: "nb-calendar__weekday",
2190
+ children: day
2191
+ }) }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_aria_components.CalendarGridBody, { children: (date) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_aria_components.CalendarCell, {
2012
2192
  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);
2193
+ className: "nb-calendar__day"
2194
+ }) })]
2195
+ })] });
2196
+ }
2197
+ /** A parent modal owns containment; a standalone picker needs its own focus scope. */
2198
+ function CalendarDialog({ id, ariaLabel, children }) {
2199
+ return useOverlayContainer() ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("section", {
2200
+ id,
2201
+ "aria-label": ariaLabel,
2202
+ role: "dialog",
2203
+ tabIndex: -1,
2204
+ children
2205
+ }) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_aria_components.Dialog, {
2206
+ id,
2207
+ "aria-label": ariaLabel,
2208
+ children
2034
2209
  });
2210
+ }
2211
+ //#endregion
2212
+ //#region packages/ui/dateValues.ts
2213
+ const getDateLocale = (locale) => locale || typeof document !== "undefined" && document.documentElement.lang || typeof navigator !== "undefined" && navigator.language || "en-US";
2214
+ const calendarDate = (value) => {
2215
+ if (!value || !/^\d{4}-\d{2}-\d{2}$/.test(value)) return null;
2216
+ try {
2217
+ return (0, _internationalized_date.parseDate)(value);
2218
+ } catch {
2219
+ return null;
2220
+ }
2035
2221
  };
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
- });
2222
+ const formatDate = (value, locale) => {
2223
+ const date = calendarDate(value);
2224
+ return date ? new Intl.DateTimeFormat(locale, {
2225
+ day: "2-digit",
2226
+ month: "2-digit",
2227
+ year: "numeric",
2228
+ timeZone: "UTC"
2229
+ }).format(date.toDate("UTC")) : "";
2043
2230
  };
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) => {
2231
+ const dateAllowed = (value, min, max) => Boolean(calendarDate(value)) && (!min || value >= min) && (!max || value <= max);
2232
+ const dateOrder = (locale) => new Intl.DateTimeFormat(getDateLocale(locale), {
2233
+ day: "2-digit",
2234
+ month: "2-digit",
2235
+ year: "numeric",
2236
+ timeZone: "UTC"
2237
+ }).formatToParts(new Date(Date.UTC(2026, 10, 23))).filter((part) => [
2238
+ "day",
2239
+ "month",
2240
+ "year"
2241
+ ].includes(part.type)).map((part) => part.type);
2242
+ const datePlaceholder = (locale) => dateOrder(locale).map((part) => part === "year" ? "yyyy" : part === "month" ? "mm" : "dd").join("/");
2243
+ const applyDateMask = (rawValue, prevValue, locale) => {
2244
+ if (/^\d{4}-\d{2}-\d{2}$/.test(rawValue)) return rawValue;
2052
2245
  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 += "/";
2246
+ const adding = digits.length > prevValue.replace(/\D/g, "").length;
2247
+ const sizes = dateOrder(locale ?? "es-PE").map((part) => part === "year" ? 4 : 2);
2248
+ let offset = 0;
2249
+ let result = "";
2250
+ for (const [i, size] of sizes.entries()) {
2251
+ result += digits.slice(offset, offset + size);
2252
+ offset += size;
2253
+ if (i < 2 && (digits.length > offset || adding && digits.length === offset)) result += "/";
2254
+ }
2060
2255
  return result;
2061
2256
  };
2062
- /**
2063
- * Parses dd/mm/yyyy or ISO yyyy-mm-dd to ISO string.
2064
- * Returns null if not a valid date.
2065
- */
2066
2257
  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;
2258
+ if (calendarDate(text)) return text;
2259
+ const order = dateOrder(locale);
2260
+ const digits = text.match(/\d+/g);
2261
+ if (!digits || digits.length !== 3) return null;
2262
+ const fields = Object.fromEntries(order.map((key, i) => [key, digits[i]]));
2263
+ if (fields.year?.length !== 4) return null;
2264
+ const iso = `${fields.year}-${fields.month?.padStart(2, "0")}-${fields.day?.padStart(2, "0")}`;
2265
+ return calendarDate(iso) ? iso : null;
2076
2266
  };
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();
2267
+ //#endregion
2268
+ //#region packages/ui/DateTextInput.tsx
2269
+ /** Keeps the real input/ref/ID contract used by CRUD forms. */
2270
+ const DateTextInput = (0, react.forwardRef)(function DateTextInput({ value, locale, min, max, onChange, onOpen, onBlur, onKeyDown, ...props }, ref) {
2271
+ const [draft, setDraft] = (0, react.useState)(null);
2272
+ const commit = () => {
2273
+ if (draft === null) return;
2274
+ const iso = parseDisplayDate(draft.trim(), locale);
2275
+ if (!draft.trim()) onChange("");
2276
+ else if (iso && dateAllowed(iso, min, max)) onChange(iso);
2277
+ setDraft(null);
2278
+ };
2279
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
2280
+ ...props,
2281
+ ref,
2282
+ type: "text",
2283
+ inputMode: "numeric",
2284
+ onPointerDown: (event) => event.stopPropagation(),
2285
+ onPointerUp: (event) => event.stopPropagation(),
2286
+ onMouseDown: (event) => event.stopPropagation(),
2287
+ onClick: (event) => event.stopPropagation(),
2288
+ value: draft ?? formatDate(value, locale),
2289
+ onChange: (event) => setDraft(applyDateMask(event.target.value, draft ?? "", locale)),
2290
+ onBlur: (event) => {
2291
+ commit();
2292
+ onBlur?.(event);
2101
2293
  },
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
- };
2294
+ onKeyDown: (event) => {
2295
+ if (event.key !== "Escape") event.stopPropagation();
2296
+ onKeyDown?.(event);
2297
+ if (event.defaultPrevented) return;
2298
+ if (event.key === "Enter") {
2299
+ event.preventDefault();
2300
+ commit();
2301
+ }
2302
+ if (event.key === "Escape") setDraft(null);
2303
+ if (event.key === "ArrowDown" && !props.disabled && !props.readOnly) {
2304
+ event.preventDefault();
2305
+ commit();
2306
+ onOpen();
2307
+ }
2112
2308
  }
2113
2309
  });
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]);
2310
+ });
2311
+ //#endregion
2312
+ //#region packages/ui/useCalendarPopover.ts
2313
+ /** Bridge focus restoration between React Aria's popup and a parent Base UI modal. */
2314
+ function useCalendarPopover() {
2315
+ const container = useOverlayContainer();
2316
+ const groupRef = (0, react.useRef)(null);
2317
+ const panelRef = (0, react.useRef)(null);
2318
+ const frame = (0, react.useRef)(null);
2319
+ const outsideTarget = (0, react.useRef)(null);
2320
+ const [open, updateOpen] = (0, react.useState)(false);
2126
2321
  (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;
2322
+ if (!open || !container) return;
2323
+ const rememberTarget = (event) => {
2324
+ 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\"])");
2325
+ };
2326
+ document.addEventListener("pointerdown", rememberTarget, true);
2327
+ return () => document.removeEventListener("pointerdown", rememberTarget, true);
2328
+ }, [open, container]);
2329
+ (0, react.useEffect)(() => () => {
2330
+ if (frame.current !== null) cancelAnimationFrame(frame.current);
2331
+ }, []);
2332
+ return {
2333
+ container,
2334
+ groupRef,
2335
+ panelRef,
2336
+ open,
2337
+ setOpen: (0, react.useCallback)((next) => {
2338
+ if (frame.current !== null) cancelAnimationFrame(frame.current);
2339
+ if (next) outsideTarget.current = null;
2340
+ const active = document.activeElement;
2341
+ const target = outsideTarget.current ?? groupRef.current?.querySelector("input");
2342
+ const restore = !next && container && (outsideTarget.current || panelRef.current?.contains(active));
2343
+ updateOpen(next);
2344
+ if (restore) frame.current = requestAnimationFrame(() => {
2345
+ frame.current = requestAnimationFrame(() => {
2346
+ frame.current = null;
2347
+ if (document.activeElement === active || document.activeElement === container || document.activeElement === document.body) target?.focus();
2348
+ });
2349
+ });
2350
+ }, [container])
2240
2351
  };
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}`))
2352
+ }
2353
+ //#endregion
2354
+ //#region packages/ui/DatePicker.tsx
2355
+ 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) {
2356
+ const generatedId = (0, react.useId)();
2357
+ const inputId = id ?? generatedId;
2358
+ const { container, groupRef, panelRef, open, setOpen } = useCalendarPopover();
2359
+ const strings = useUiStrings();
2360
+ const resolvedLocale = getDateLocale(locale);
2361
+ const change = (next) => onChange?.(next);
2362
+ const todayIso = (0, _internationalized_date.today)((0, _internationalized_date.getLocalTimeZone)()).toString();
2363
+ const prefix = "nb-date-picker";
2364
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_aria_components.I18nProvider, {
2365
+ locale: resolvedLocale,
2366
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_aria_components.DatePicker, {
2367
+ "aria-label": ariaLabel ?? strings.selectDate,
2368
+ value: calendarDate(value),
2369
+ onChange: (date) => change(date?.toString() ?? ""),
2370
+ minValue: calendarDate(min) ?? void 0,
2371
+ maxValue: calendarDate(max) ?? void 0,
2372
+ isDisabled: disabled,
2373
+ isReadOnly: readOnly,
2374
+ isRequired: required,
2375
+ isInvalid: invalid,
2376
+ validationBehavior: "aria",
2377
+ isOpen: open,
2378
+ onOpenChange: setOpen,
2379
+ className: [prefix, className].filter(Boolean).join(" "),
2380
+ children: [
2381
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
2382
+ type: "hidden",
2383
+ name,
2384
+ value: value ?? "",
2385
+ disabled
2386
+ }),
2387
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_aria_components.Group, {
2388
+ ref: groupRef,
2389
+ className: [
2390
+ `${prefix}__trigger`,
2391
+ disabled && `${prefix}__trigger--disabled`,
2392
+ readOnly && `${prefix}__trigger--readonly`,
2393
+ invalid && `${prefix}__trigger--invalid`,
2394
+ open && `${prefix}__trigger--open`
2395
+ ].filter(Boolean).join(" "),
2396
+ children: [
2397
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DateTextInput, {
2398
+ ref,
2399
+ id: inputId,
2400
+ value,
2401
+ locale: resolvedLocale,
2402
+ min,
2403
+ max,
2404
+ placeholder: placeholder ?? datePlaceholder(resolvedLocale),
2405
+ disabled,
2406
+ readOnly,
2407
+ required,
2408
+ "aria-label": ariaLabel ?? (id ? void 0 : strings.selectDate),
2409
+ "aria-invalid": invalid || void 0,
2410
+ role: "combobox",
2411
+ "aria-haspopup": "dialog",
2412
+ "aria-expanded": open,
2413
+ "aria-controls": open ? `${inputId}-panel` : void 0,
2414
+ className: `${prefix}__input`,
2415
+ onChange: change,
2416
+ onOpen: () => setOpen(true),
2417
+ onBlur,
2418
+ onKeyDown: (event) => {
2419
+ if (event.key === "Escape" && open) {
2420
+ event.stopPropagation();
2421
+ setOpen(false);
2422
+ }
2423
+ }
2350
2424
  }),
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))
2425
+ clearable && value && !disabled && !readOnly && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_aria_components.Button, {
2426
+ slot: null,
2427
+ className: `${prefix}__clear`,
2428
+ "aria-label": strings.clearDate,
2429
+ onPress: () => change(""),
2430
+ children: "×"
2367
2431
  }),
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(""),
2432
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_aria_components.Button, {
2433
+ className: `${prefix}__calendar-btn`,
2434
+ "aria-label": strings.openCalendar,
2435
+ onPress: () => groupRef.current?.querySelector("input")?.focus(),
2436
+ isDisabled: disabled || readOnly,
2437
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("i", {
2438
+ "aria-hidden": "true",
2439
+ className: "ph ph-calendar-blank"
2440
+ })
2441
+ })
2442
+ ]
2443
+ }),
2444
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_aria_components.Popover, {
2445
+ isNonModal: Boolean(container),
2446
+ ref: panelRef,
2447
+ UNSTABLE_portalContainer: container ?? void 0,
2448
+ className: `${prefix}__panel`,
2449
+ offset: 4,
2450
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(CalendarDialog, {
2451
+ id: `${inputId}-panel`,
2452
+ ariaLabel: strings.selectDate,
2453
+ 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", {
2454
+ className: `${prefix}__footer`,
2455
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_aria_components.Button, {
2456
+ slot: null,
2457
+ className: `${prefix}__text-button`,
2458
+ onPress: () => {
2459
+ change("");
2460
+ setOpen(false);
2461
+ },
2374
2462
  children: strings.clear
2375
- }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
2376
- type: "button",
2377
- className: "nb-date-picker__text-button",
2378
- onClick: handleToday,
2463
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_aria_components.Button, {
2464
+ slot: null,
2465
+ className: `${prefix}__text-button`,
2466
+ isDisabled: !dateAllowed(todayIso, min, max),
2467
+ onPress: () => {
2468
+ change(todayIso);
2469
+ setOpen(false);
2470
+ },
2379
2471
  children: strings.today
2380
2472
  })]
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
- ]
2473
+ })]
2474
+ })
2475
+ })
2476
+ ]
2477
+ })
2527
2478
  });
2528
2479
  });
2529
2480
  //#endregion
2530
2481
  //#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)();
2482
+ function DateRangePicker({ startValue, endValue, placeholder, disabled = false, clearable = true, readOnly = false, required = false, invalid = false, locale, min, max, className, ariaLabel, onChange, onBlur }) {
2483
+ const { container, groupRef, panelRef, open, setOpen } = useCalendarPopover();
2602
2484
  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,
2485
+ const resolvedLocale = getDateLocale(locale);
2486
+ const start = calendarDate(startValue);
2487
+ const end = calendarDate(endValue);
2488
+ const change = (a, b) => a && b && a > b ? onChange?.(b, a) : onChange?.(a, b);
2489
+ const todayIso = (0, _internationalized_date.today)((0, _internationalized_date.getLocalTimeZone)()).toString();
2490
+ const prefix = "nb-date-range-picker";
2491
+ const inputProps = {
2492
+ locale: resolvedLocale,
2620
2493
  min,
2621
2494
  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);
2495
+ placeholder: placeholder ?? datePlaceholder(resolvedLocale),
2496
+ disabled,
2497
+ readOnly,
2498
+ required,
2499
+ "aria-invalid": invalid || void 0,
2500
+ className: `${prefix}__input`,
2501
+ onOpen: () => setOpen(true),
2502
+ onBlur,
2503
+ onKeyDown: (event) => {
2504
+ if (event.key === "Escape" && open) {
2505
+ event.stopPropagation();
2506
+ setOpen(false);
2507
+ }
2753
2508
  }
2754
2509
  };
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,
2510
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_aria_components.I18nProvider, {
2511
+ locale: resolvedLocale,
2512
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_aria_components.DateRangePicker, {
2513
+ "aria-label": ariaLabel ?? strings.selectDateRange,
2514
+ value: start && end && start.compare(end) <= 0 ? {
2515
+ start,
2516
+ end
2517
+ } : null,
2518
+ onChange: (range) => change(range?.start.toString() ?? "", range?.end.toString() ?? ""),
2519
+ minValue: calendarDate(min) ?? void 0,
2520
+ maxValue: calendarDate(max) ?? void 0,
2521
+ placeholderValue: start ?? end ?? void 0,
2522
+ isDisabled: disabled,
2523
+ isReadOnly: readOnly,
2524
+ isRequired: required,
2525
+ isInvalid: invalid,
2526
+ validationBehavior: "aria",
2527
+ isOpen: open,
2528
+ onOpenChange: setOpen,
2529
+ className: [prefix, className].filter(Boolean).join(" "),
2530
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_aria_components.Group, {
2531
+ ref: groupRef,
2532
+ className: [
2533
+ `${prefix}__trigger`,
2534
+ disabled && `${prefix}__trigger--disabled`,
2535
+ readOnly && `${prefix}__trigger--readonly`,
2536
+ invalid && `${prefix}__trigger--invalid`,
2537
+ open && `${prefix}__trigger--open`
2538
+ ].filter(Boolean).join(" "),
2773
2539
  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
2540
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DateTextInput, {
2541
+ ...inputProps,
2542
+ "aria-label": [strings.startDate, ariaLabel].filter(Boolean).join(" "),
2543
+ value: startValue,
2544
+ onChange: (next) => change(next, endValue ?? "")
2791
2545
  }),
2792
2546
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
2793
- className: "nb-date-range-picker__sep",
2547
+ className: `${prefix}__sep`,
2794
2548
  "aria-hidden": "true",
2795
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("i", { className: "ph ph-arrow-right" })
2549
+ children: "→"
2796
2550
  }),
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
2551
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DateTextInput, {
2552
+ ...inputProps,
2553
+ "aria-label": [strings.endDate, ariaLabel].filter(Boolean).join(" "),
2554
+ value: endValue,
2555
+ onChange: (next) => change(startValue ?? "", next)
2813
2556
  }),
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
- })]
2557
+ clearable && (startValue || endValue) && !disabled && !readOnly && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_aria_components.Button, {
2558
+ slot: null,
2559
+ className: `${prefix}__clear`,
2560
+ "aria-label": strings.clearDateRange,
2561
+ onPress: () => change("", ""),
2562
+ children: "×"
2563
+ }),
2564
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_aria_components.Button, {
2565
+ className: `${prefix}__calendar-btn`,
2566
+ "aria-label": strings.openCalendar,
2567
+ onPress: () => groupRef.current?.querySelector("input")?.focus(),
2568
+ isDisabled: disabled || readOnly,
2569
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("i", {
2570
+ "aria-hidden": "true",
2571
+ className: "ph ph-calendar-blank"
2572
+ })
2837
2573
  })
2838
2574
  ]
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", {
2575
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_aria_components.Popover, {
2576
+ isNonModal: Boolean(container),
2847
2577
  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();
2578
+ UNSTABLE_portalContainer: container ?? void 0,
2579
+ className: `${prefix}__panel`,
2580
+ offset: 4,
2581
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(CalendarDialog, {
2582
+ ariaLabel: strings.selectDateRange,
2583
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_aria_components.RangeCalendar, {
2584
+ className: "nb-calendar--range",
2585
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CalendarContent, {})
2586
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
2587
+ className: `${prefix}__footer`,
2588
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_aria_components.Button, {
2589
+ slot: null,
2590
+ className: `${prefix}__text-button`,
2591
+ onPress: () => {
2592
+ change("", "");
2593
+ setOpen(false);
2925
2594
  },
2926
2595
  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();
2596
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_aria_components.Button, {
2597
+ slot: null,
2598
+ className: `${prefix}__text-button`,
2599
+ isDisabled: !dateAllowed(todayIso, min, max),
2600
+ onPress: () => {
2601
+ change(todayIso, todayIso);
2602
+ setOpen(false);
2946
2603
  },
2947
2604
  children: strings.today
2948
2605
  })]
2949
- })
2950
- ]
2951
- }), document.body)
2952
- ]
2606
+ })]
2607
+ })
2608
+ })]
2609
+ })
2953
2610
  });
2954
2611
  }
2955
2612
  //#endregion
2956
2613
  //#region packages/ui/Popover.tsx
2957
2614
  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
- })]
2615
+ const [open, setOpen] = (0, react.useState)(false);
2616
+ const triggerRef = (0, react.useRef)(null);
2617
+ const [restoreFocus, setRestoreFocus] = (0, react.useState)(true);
2618
+ const changeOpen = (next) => {
2619
+ setRestoreFocus(true);
2620
+ setOpen(next);
2621
+ };
2622
+ const container = useOverlayContainer();
2623
+ const triggerNode = trigger({
2624
+ open,
2625
+ toggle: () => changeOpen(!open)
2626
+ });
2627
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_base_ui_react_popover.Popover.Root, {
2628
+ open,
2629
+ onOpenChange: (next, details) => {
2630
+ setRestoreFocus(details.reason !== "outside-press" && details.reason !== "focus-out");
2631
+ setOpen(next);
2632
+ },
2633
+ onOpenChangeComplete: (next) => {
2634
+ if (!next && restoreFocus) triggerRef.current?.focus({ preventScroll: true });
2635
+ },
2636
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
2637
+ className: [
2638
+ "nb-popover",
2639
+ `nb-popover--${align}`,
2640
+ open && "nb-popover--open",
2641
+ className
2642
+ ].filter(Boolean).join(" "),
2643
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_base_ui_react_popover.Popover.Trigger, {
2644
+ ref: triggerRef,
2645
+ render: (0, react.isValidElement)(triggerNode) ? triggerNode : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
2646
+ type: "button",
2647
+ children: triggerNode
2648
+ })
2649
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_base_ui_react_popover.Popover.Portal, {
2650
+ container: container ?? void 0,
2651
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_base_ui_react_popover.Popover.Positioner, {
2652
+ align,
2653
+ sideOffset: 8,
2654
+ className: "nb-popover-positioner",
2655
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_base_ui_react_popover.Popover.Popup, {
2656
+ finalFocus: triggerRef,
2657
+ onKeyDownCapture: (event) => {
2658
+ if (event.key === "Escape") {
2659
+ event.preventDefault();
2660
+ event.stopPropagation();
2661
+ changeOpen(false);
2662
+ }
2663
+ },
2664
+ className: "nb-popover__panel",
2665
+ "aria-label": ariaLabel,
2666
+ children: panel({ close: () => changeOpen(false) })
2667
+ })
2668
+ })
2669
+ })]
2670
+ })
2976
2671
  });
2977
2672
  };
2978
2673
  //#endregion
2674
+ //#region packages/ui/useFloatingPanel.ts
2675
+ /** Style applied to an anchored panel before its first position is computed. */
2676
+ const HIDDEN_PANEL_STYLE = {
2677
+ position: "fixed",
2678
+ visibility: "hidden",
2679
+ margin: 0
2680
+ };
2681
+ function useFloatingPanel(options = {}) {
2682
+ const [open, setOpenState] = (0, react.useState)(false);
2683
+ const [panelStyle, setPanelStyle] = (0, react.useState)(HIDDEN_PANEL_STYLE);
2684
+ const containerRef = (0, react.useRef)(null);
2685
+ const panelRef = (0, react.useRef)(null);
2686
+ const optionsRef = (0, react.useRef)(options);
2687
+ optionsRef.current = options;
2688
+ const anchored = !!options.computeStyle;
2689
+ const dismissEvent = options.dismissEvent ?? "pointerdown";
2690
+ const setOpen = (0, react.useCallback)((next) => {
2691
+ setOpenState(next);
2692
+ if (!next) optionsRef.current.onClose?.();
2693
+ optionsRef.current.onOpenChange?.(next);
2694
+ }, []);
2695
+ const applyStyle = (0, react.useCallback)(() => {
2696
+ const compute = optionsRef.current.computeStyle;
2697
+ if (!compute) return;
2698
+ const style = compute(containerRef.current);
2699
+ if (style) setPanelStyle(style);
2700
+ }, []);
2701
+ const openPanel = (0, react.useCallback)(() => {
2702
+ applyStyle();
2703
+ setOpen(true);
2704
+ }, [applyStyle, setOpen]);
2705
+ const toggle = (0, react.useCallback)(() => open ? setOpen(false) : openPanel(), [
2706
+ open,
2707
+ openPanel,
2708
+ setOpen
2709
+ ]);
2710
+ (0, react.useEffect)(() => {
2711
+ if (!open) return;
2712
+ const handleOutside = (e) => {
2713
+ const target = e.target;
2714
+ if (containerRef.current?.contains(target) || panelRef.current?.contains(target)) return;
2715
+ setOpen(false);
2716
+ };
2717
+ const handleKeyDown = (e) => {
2718
+ if (e.key !== "Escape" || e.defaultPrevented) return;
2719
+ e.preventDefault();
2720
+ e.stopPropagation();
2721
+ setOpen(false);
2722
+ optionsRef.current.onEscape?.(e);
2723
+ };
2724
+ document.addEventListener(dismissEvent, handleOutside);
2725
+ document.addEventListener("keydown", handleKeyDown, true);
2726
+ return () => {
2727
+ document.removeEventListener(dismissEvent, handleOutside);
2728
+ document.removeEventListener("keydown", handleKeyDown, true);
2729
+ };
2730
+ }, [
2731
+ dismissEvent,
2732
+ open,
2733
+ setOpen
2734
+ ]);
2735
+ (0, react.useLayoutEffect)(() => {
2736
+ if (!open || !anchored) return;
2737
+ const update = () => {
2738
+ const container = containerRef.current;
2739
+ if (!container) return;
2740
+ if (optionsRef.current.closeOnViewportExit) {
2741
+ const rect = container.getBoundingClientRect();
2742
+ if ((rect.width > 0 || rect.height > 0) && (rect.top >= window.innerHeight || rect.bottom <= 0)) {
2743
+ setOpen(false);
2744
+ return;
2745
+ }
2746
+ }
2747
+ applyStyle();
2748
+ };
2749
+ update();
2750
+ window.addEventListener("resize", update);
2751
+ window.addEventListener("scroll", update, {
2752
+ capture: true,
2753
+ passive: true
2754
+ });
2755
+ return () => {
2756
+ window.removeEventListener("resize", update);
2757
+ window.removeEventListener("scroll", update, { capture: true });
2758
+ };
2759
+ }, [
2760
+ anchored,
2761
+ applyStyle,
2762
+ open,
2763
+ setOpen
2764
+ ]);
2765
+ return {
2766
+ open,
2767
+ setOpen,
2768
+ toggle,
2769
+ openPanel,
2770
+ containerRef,
2771
+ panelRef,
2772
+ panelStyle
2773
+ };
2774
+ }
2775
+ //#endregion
2979
2776
  //#region packages/ui/Drawer.tsx
2980
2777
  const formatWidth = (value) => {
2981
2778
  if (value === void 0) return void 0;
2982
2779
  return typeof value === "number" ? `${value}px` : value;
2983
2780
  };
2984
- const Drawer = ({ isOpen, onClose, title, width, side = "right", scrim = "subtle", children, footer, closeLabel, scrimLabel, className, "aria-label": ariaLabel }) => {
2781
+ const Drawer = ({ isOpen, busy = false, onClose, title, width, side = "right", scrim = "subtle", children, footer, closeLabel, scrimLabel, className, "aria-label": ariaLabel }) => {
2985
2782
  const strings = useUiStrings();
2986
2783
  const resolvedCloseLabel = closeLabel ?? strings.close;
2987
2784
  const resolvedScrimLabel = scrimLabel ?? strings.closePanel;
2988
2785
  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: [
2786
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(ModalSurface, {
2787
+ open: isOpen,
2788
+ onClose,
2789
+ closeOnEscape: !busy,
2790
+ closeOnOutsideClick: !busy,
2791
+ rootClassName: [
3015
2792
  "nb-drawer-root",
3016
2793
  isOpen && "nb-drawer-root--open",
3017
2794
  `nb-drawer-root--${side}`
3018
2795
  ].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);
2796
+ className: ["nb-drawer", className].filter(Boolean).join(" "),
2797
+ scrimClassName: `nb-drawer__scrim nb-drawer__scrim--${scrim}`,
2798
+ scrimLabel: resolvedScrimLabel,
2799
+ labelledBy: title ? titleId : void 0,
2800
+ ariaLabel: !title ? ariaLabel : void 0,
2801
+ style: { width: formatWidth(width) },
2802
+ keepMounted: true,
2803
+ children: [
2804
+ title !== void 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("header", {
2805
+ className: "nb-drawer__header",
2806
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("h2", {
2807
+ className: "nb-drawer__title",
2808
+ id: titleId,
2809
+ children: title
2810
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(IconButton, {
2811
+ className: "nb-drawer__close",
2812
+ icon: "ph ph-x",
2813
+ label: resolvedCloseLabel,
2814
+ onClick: onClose,
2815
+ disabled: busy
2816
+ })]
2817
+ }),
2818
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
2819
+ className: "nb-drawer__body",
2820
+ children
2821
+ }),
2822
+ footer && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("footer", {
2823
+ className: "nb-drawer__footer",
2824
+ children: footer
2825
+ })
2826
+ ]
2827
+ });
3060
2828
  };
3061
2829
  //#endregion
3062
2830
  //#region packages/ui/Timeline.tsx
@@ -3166,7 +2934,7 @@ function Page({ children, fill, wide, narrow, gap = 5, className, ...props }) {
3166
2934
  }
3167
2935
  //#endregion
3168
2936
  //#region packages/ui/PageHeader.tsx
3169
- function PageHeader({ title, subtitle, breadcrumb, breadcrumbSlot, badge, actions, className }) {
2937
+ function PageHeader({ title, subtitle, metadata, breadcrumb, breadcrumbSlot, badge, actions, className }) {
3170
2938
  const breadcrumbNode = breadcrumbSlot ?? (breadcrumb ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("a", {
3171
2939
  href: breadcrumb.href,
3172
2940
  className: "nb-page-header__breadcrumb",
@@ -3185,6 +2953,10 @@ function PageHeader({ title, subtitle, breadcrumb, breadcrumbSlot, badge, action
3185
2953
  className: "nb-page-header__title",
3186
2954
  children: title
3187
2955
  }),
2956
+ metadata && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
2957
+ className: "nb-page-header__metadata",
2958
+ children: metadata
2959
+ }),
3188
2960
  subtitle && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
3189
2961
  className: "nb-page-header__subtitle",
3190
2962
  children: subtitle
@@ -3254,9 +3026,9 @@ function Col({ children, span, spanSm, spanMd, spanLg, fullWidth, className, ...
3254
3026
  }
3255
3027
  //#endregion
3256
3028
  //#region packages/ui/Section.tsx
3257
- function Section({ title, children, className }) {
3029
+ function Section({ title, children, className, variant = "label" }) {
3258
3030
  return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("section", {
3259
- className: joinClasses("nb-section", className),
3031
+ className: joinClasses("nb-section", variant === "panel" && "nb-section--panel", className),
3260
3032
  children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("h2", {
3261
3033
  className: "nb-section__title",
3262
3034
  children: title
@@ -3459,6 +3231,241 @@ function useConfirm() {
3459
3231
  };
3460
3232
  }
3461
3233
  //#endregion
3234
+ //#region packages/ui/Checkbox.tsx
3235
+ /** Native checkbox, including the mixed state used by bulk selection. */
3236
+ const Checkbox = (0, react.forwardRef)(function Checkbox({ label, indeterminate = false, invalid = false, id, className, ...props }, ref) {
3237
+ const generatedId = (0, react.useId)();
3238
+ const inputRef = (0, react.useRef)(null);
3239
+ (0, react.useEffect)(() => {
3240
+ if (inputRef.current) inputRef.current.indeterminate = indeterminate;
3241
+ }, [indeterminate]);
3242
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("label", {
3243
+ className: `nb-selection-control${className ? ` ${className}` : ""}`,
3244
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
3245
+ ...props,
3246
+ id: id ?? generatedId,
3247
+ type: "checkbox",
3248
+ "aria-invalid": props["aria-invalid"] ?? (invalid || void 0),
3249
+ ref: (node) => {
3250
+ inputRef.current = node;
3251
+ if (typeof ref === "function") return ref(node);
3252
+ if (ref) ref.current = node;
3253
+ }
3254
+ }), label && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: label })]
3255
+ });
3256
+ });
3257
+ //#endregion
3258
+ //#region packages/ui/RadioGroup.tsx
3259
+ /** Native radios share a name for browser keyboard navigation and form submission. */
3260
+ function RadioGroup({ label, name, value, options, onChange, orientation = "vertical", required, invalid = false, disabled, className, ...props }) {
3261
+ const generatedName = (0, react.useId)();
3262
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("fieldset", {
3263
+ ...props,
3264
+ disabled,
3265
+ "aria-invalid": props["aria-invalid"] ?? (invalid || void 0),
3266
+ className: `nb-radio-group${className ? ` ${className}` : ""}`,
3267
+ children: [label && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("legend", { children: label }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
3268
+ className: `nb-radio-group__options nb-radio-group__options--${orientation}`,
3269
+ children: options.map((option) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("label", {
3270
+ className: "nb-selection-control",
3271
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
3272
+ type: "radio",
3273
+ name: name ?? generatedName,
3274
+ value: option.value,
3275
+ checked: value === option.value,
3276
+ disabled: disabled || option.disabled,
3277
+ required,
3278
+ onChange: () => onChange(option.value)
3279
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: option.label })]
3280
+ }, option.value))
3281
+ })]
3282
+ });
3283
+ }
3284
+ //#endregion
3285
+ //#region packages/ui/Tabs.tsx
3286
+ function Tabs({ items, value, onChange, "aria-label": ariaLabel, orientation = "horizontal", activationMode = "automatic", keepMounted = false, className }) {
3287
+ const id = (0, react.useId)();
3288
+ const listRef = (0, react.useRef)(null);
3289
+ const [focusedValue, setFocusedValue] = (0, react.useState)(null);
3290
+ const selectedIndex = items.findIndex((item) => item.value === value && !item.disabled);
3291
+ const focusedIndex = items.findIndex((item) => item.value === focusedValue && !item.disabled);
3292
+ const tabStop = activationMode === "manual" && focusedIndex >= 0 ? focusedIndex : selectedIndex >= 0 ? selectedIndex : items.findIndex((item) => !item.disabled);
3293
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
3294
+ className: `nb-tabs nb-tabs--${orientation}${className ? ` ${className}` : ""}`,
3295
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
3296
+ ref: listRef,
3297
+ role: "tablist",
3298
+ "aria-label": ariaLabel,
3299
+ "aria-orientation": orientation,
3300
+ className: "nb-tabs__list",
3301
+ children: items.map((item, index) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
3302
+ type: "button",
3303
+ role: "tab",
3304
+ id: `${id}-tab-${index}`,
3305
+ "aria-controls": `${id}-panel-${index}`,
3306
+ "aria-selected": index === selectedIndex,
3307
+ disabled: item.disabled,
3308
+ tabIndex: index === tabStop ? 0 : -1,
3309
+ className: "nb-tabs__tab",
3310
+ onFocus: () => setFocusedValue(item.value),
3311
+ onClick: () => onChange(item.value),
3312
+ onKeyDown: (event) => {
3313
+ const nextKey = orientation === "horizontal" ? "ArrowRight" : "ArrowDown";
3314
+ if (![
3315
+ nextKey,
3316
+ orientation === "horizontal" ? "ArrowLeft" : "ArrowUp",
3317
+ "Home",
3318
+ "End"
3319
+ ].includes(event.key)) return;
3320
+ event.preventDefault();
3321
+ const enabled = items.map((entry, i) => entry.disabled ? -1 : i).filter((i) => i >= 0);
3322
+ const position = enabled.indexOf(index);
3323
+ 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];
3324
+ if (next === void 0) return;
3325
+ listRef.current?.querySelectorAll("[role=\"tab\"]")[next]?.focus();
3326
+ if (activationMode === "automatic") onChange(items[next].value);
3327
+ },
3328
+ children: item.label
3329
+ }, item.value))
3330
+ }), items.map((item, index) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
3331
+ role: "tabpanel",
3332
+ id: `${id}-panel-${index}`,
3333
+ "aria-labelledby": `${id}-tab-${index}`,
3334
+ hidden: index !== selectedIndex,
3335
+ tabIndex: 0,
3336
+ className: "nb-tabs__panel",
3337
+ children: keepMounted || index === selectedIndex ? item.content : null
3338
+ }, item.value))]
3339
+ });
3340
+ }
3341
+ //#endregion
3342
+ //#region packages/ui/Spinner.tsx
3343
+ function Spinner({ label, size = "md", className, ...props }) {
3344
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
3345
+ ...props,
3346
+ className: `nb-spinner nb-spinner--${size}${className ? ` ${className}` : ""}`,
3347
+ role: label ? "status" : void 0,
3348
+ "aria-label": label,
3349
+ "aria-hidden": label ? void 0 : true
3350
+ });
3351
+ }
3352
+ //#endregion
3353
+ //#region packages/ui/Progress.tsx
3354
+ /** Omit value for indeterminate progress; max defaults to 100. */
3355
+ function Progress({ label, id, max = 100, className, ...props }) {
3356
+ const generatedId = (0, react.useId)();
3357
+ const progressId = id ?? generatedId;
3358
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
3359
+ className: "nb-progress-field",
3360
+ children: [label && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("label", {
3361
+ htmlFor: progressId,
3362
+ children: label
3363
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("progress", {
3364
+ ...props,
3365
+ id: progressId,
3366
+ max,
3367
+ className: `nb-progress${className ? ` ${className}` : ""}`
3368
+ })]
3369
+ });
3370
+ }
3371
+ //#endregion
3372
+ //#region packages/ui/Tooltip.tsx
3373
+ const TooltipProvider = _base_ui_react_tooltip.Tooltip.Provider;
3374
+ /** Uses the existing child as the trigger without adding a nested button. */
3375
+ function Tooltip({ children, content, side = "top", delay, disabled, className }) {
3376
+ const overlayContainer = useOverlayContainer();
3377
+ const id = (0, react.useId)();
3378
+ const [open, setOpen] = (0, react.useState)(false);
3379
+ const description = [children.props["aria-describedby"], open && !disabled ? id : void 0].filter(Boolean).join(" ") || void 0;
3380
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_base_ui_react_tooltip.Tooltip.Root, {
3381
+ open,
3382
+ disabled,
3383
+ onOpenChange: setOpen,
3384
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_base_ui_react_tooltip.Tooltip.Trigger, {
3385
+ render: (0, react.cloneElement)(children, { "aria-describedby": description }),
3386
+ onKeyDownCapture: (event) => {
3387
+ if (open && event.key === "Escape") {
3388
+ event.stopPropagation();
3389
+ setOpen(false);
3390
+ }
3391
+ },
3392
+ delay
3393
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_base_ui_react_tooltip.Tooltip.Portal, {
3394
+ container: overlayContainer ?? void 0,
3395
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_base_ui_react_tooltip.Tooltip.Positioner, {
3396
+ side,
3397
+ sideOffset: 8,
3398
+ className: "nb-tooltip-positioner",
3399
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_base_ui_react_tooltip.Tooltip.Popup, {
3400
+ id,
3401
+ role: "tooltip",
3402
+ className: `nb-tooltip${className ? ` ${className}` : ""}`,
3403
+ children: content
3404
+ })
3405
+ })
3406
+ })]
3407
+ });
3408
+ }
3409
+ //#endregion
3410
+ //#region packages/ui/TimePicker.tsx
3411
+ const timeValue = (value) => {
3412
+ if (!value) return null;
3413
+ try {
3414
+ return (0, _internationalized_date.parseTime)(value);
3415
+ } catch {
3416
+ return null;
3417
+ }
3418
+ };
3419
+ /** Accessible segmented time entry. Values never pass through Date or a timezone. */
3420
+ 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) {
3421
+ const strings = useUiStrings();
3422
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_aria_components.I18nProvider, {
3423
+ locale: getDateLocale(locale),
3424
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_aria_components.TimeField, {
3425
+ id,
3426
+ name,
3427
+ "aria-label": ariaLabel ?? strings.selectTime,
3428
+ value: timeValue(value),
3429
+ onChange: (next) => onChange?.(next ? next.toString().slice(0, granularity === "second" ? 8 : 5) : ""),
3430
+ onBlur,
3431
+ minValue: timeValue(min) ?? void 0,
3432
+ maxValue: timeValue(max) ?? void 0,
3433
+ granularity,
3434
+ hourCycle,
3435
+ isDisabled: disabled,
3436
+ isReadOnly: readOnly,
3437
+ isRequired: required,
3438
+ isInvalid: invalid,
3439
+ validationBehavior: "aria",
3440
+ className: ["nb-time-picker", className].filter(Boolean).join(" "),
3441
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_aria_components.DateInput, {
3442
+ ref,
3443
+ className: "nb-time-picker__input",
3444
+ children: (segment) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_aria_components.DateSegment, {
3445
+ segment,
3446
+ className: "nb-time-picker__segment"
3447
+ })
3448
+ })
3449
+ })
3450
+ });
3451
+ });
3452
+ //#endregion
3453
+ //#region packages/ui/DetailLayout.tsx
3454
+ /** Responsive main/aside composition for record detail pages. */
3455
+ function DetailLayout({ children, aside, asideLabel, className }) {
3456
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
3457
+ className: joinClasses("nb-detail-layout", className),
3458
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
3459
+ className: "nb-detail-layout__main",
3460
+ children
3461
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("aside", {
3462
+ className: "nb-detail-layout__aside",
3463
+ "aria-label": asideLabel,
3464
+ children: aside
3465
+ })]
3466
+ });
3467
+ }
3468
+ //#endregion
3462
3469
  exports.ACCENT_PRESETS = ACCENT_PRESETS;
3463
3470
  exports.Alert = Alert;
3464
3471
  exports.AppDialog = AppDialog;
@@ -3468,11 +3475,13 @@ exports.Avatar = Avatar;
3468
3475
  exports.Badge = Badge;
3469
3476
  exports.Button = Button;
3470
3477
  exports.Card = Card;
3478
+ exports.Checkbox = Checkbox;
3471
3479
  exports.Chip = Chip;
3472
3480
  exports.Cluster = Cluster;
3473
3481
  exports.Code = Code;
3474
3482
  exports.Col = Col;
3475
3483
  exports.CollapsibleSection = CollapsibleSection;
3484
+ exports.Combobox = Combobox;
3476
3485
  exports.ConfirmDialog = ConfirmDialog;
3477
3486
  exports.ContextMenu = ContextMenu;
3478
3487
  exports.DataTable = DataTable;
@@ -3481,6 +3490,7 @@ exports.DateRangePicker = DateRangePicker;
3481
3490
  exports.DensityContext = DensityContext;
3482
3491
  exports.DensityProvider = DensityProvider;
3483
3492
  exports.DescriptionList = DescriptionList;
3493
+ exports.DetailLayout = DetailLayout;
3484
3494
  exports.Drawer = Drawer;
3485
3495
  exports.EN_UI_STRINGS = EN_UI_STRINGS;
3486
3496
  exports.ES_UI_STRINGS = ES_UI_STRINGS;
@@ -3495,11 +3505,14 @@ exports.Grid = Grid;
3495
3505
  exports.HubPanel = HubPanel;
3496
3506
  exports.IconButton = IconButton;
3497
3507
  exports.KpiMetricRow = KpiMetricRow;
3508
+ exports.MultiSelect = MultiSelect;
3498
3509
  exports.OperationCardGrid = OperationCardGrid;
3499
3510
  exports.Page = Page;
3500
3511
  exports.PageHeader = PageHeader;
3501
3512
  exports.Pagination = Pagination;
3502
3513
  exports.Popover = Popover;
3514
+ exports.Progress = Progress;
3515
+ exports.RadioGroup = RadioGroup;
3503
3516
  exports.Row = Row;
3504
3517
  exports.RowActions = RowActions;
3505
3518
  exports.ScopeTabs = ScopeTabs;
@@ -3509,17 +3522,22 @@ exports.SegmentedControl = SegmentedControl;
3509
3522
  exports.SelectField = SelectField;
3510
3523
  exports.SettingsPanel = SettingsPanel;
3511
3524
  exports.Skeleton = Skeleton;
3525
+ exports.Spinner = Spinner;
3512
3526
  exports.Stack = Stack;
3513
3527
  exports.StatCard = StatCard;
3528
+ exports.Tabs = Tabs;
3514
3529
  exports.Text = Text;
3515
3530
  exports.TextAreaField = TextAreaField;
3516
3531
  exports.TextField = TextField;
3517
3532
  exports.ThemeContext = ThemeContext;
3518
3533
  exports.ThemeProvider = ThemeProvider;
3519
3534
  exports.ThemeSwitcher = ThemeSwitcher;
3535
+ exports.TimePicker = TimePicker;
3520
3536
  exports.Timeline = Timeline;
3521
3537
  exports.TimelineItem = TimelineItem;
3522
3538
  exports.Toggle = Toggle;
3539
+ exports.Tooltip = Tooltip;
3540
+ exports.TooltipProvider = TooltipProvider;
3523
3541
  exports.UiStringsProvider = UiStringsProvider;
3524
3542
  exports.getAvatarHue = getAvatarHue;
3525
3543
  exports.getAvatarInitials = getAvatarInitials;
@@ -3527,5 +3545,6 @@ exports.useAccentColor = useAccentColor;
3527
3545
  exports.useConfirm = useConfirm;
3528
3546
  exports.useDensity = useDensity;
3529
3547
  exports.useFloatingPanel = useFloatingPanel;
3548
+ exports.useOverlayContainer = useOverlayContainer;
3530
3549
  exports.useTheme = useTheme;
3531
3550
  exports.useUiStrings = useUiStrings;