@nubitio/ui 1.1.1 → 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.mjs CHANGED
@@ -1,7 +1,13 @@
1
- import React, { createContext, forwardRef, useCallback, useContext, useEffect, useId, useLayoutEffect, useMemo, useRef, useState } from "react";
1
+ import React, { cloneElement, createContext, forwardRef, isValidElement, useCallback, useContext, useEffect, useId, useLayoutEffect, useMemo, useRef, useState } from "react";
2
2
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
3
- import { createPortal } from "react-dom";
3
+ import { Dialog } from "@base-ui/react/dialog";
4
4
  import { useDropzone } from "react-dropzone";
5
+ import { Select } from "@base-ui/react/select";
6
+ import { Button as Button$1, Calendar, CalendarCell, CalendarGrid, CalendarGridBody, CalendarGridHeader, CalendarHeaderCell, CalendarMonthPicker, CalendarYearPicker, ComboBox, ComboBoxStateContext, ComboBoxValue, DateInput, DatePicker as DatePicker$1, DateRangePicker as DateRangePicker$1, DateSegment, Dialog as Dialog$1, Group, Heading, I18nProvider, Input, Label, ListBox, ListBoxItem, Popover as Popover$1, RangeCalendar, Tag, TagGroup, TagList, TimeField } from "react-aria-components";
7
+ import { Menu } from "@base-ui/react/menu";
8
+ import { getLocalTimeZone, parseDate, parseTime, today } from "@internationalized/date";
9
+ import { Popover as Popover$2 } from "@base-ui/react/popover";
10
+ import { Tooltip as Tooltip$1 } from "@base-ui/react/tooltip";
5
11
  //#region packages/ui/Avatar.tsx
6
12
  /**
7
13
  * 8 semantic hues aligned with the Fluent / @nubitio design palette.
@@ -41,12 +47,13 @@ const Avatar = ({ owner = "", size, variant = "md", shape = "circle", alt, class
41
47
  const px = size ?? NAMED_SIZES[variant];
42
48
  const initials = getAvatarInitials(owner);
43
49
  const hue = getAvatarHue(owner);
50
+ const classes = [
51
+ "nb-avatar",
52
+ shape === "square" && "nb-avatar--square",
53
+ className
54
+ ].filter(Boolean).join(" ");
44
55
  return /* @__PURE__ */ jsx("span", {
45
- className: [
46
- "nb-avatar",
47
- shape === "square" && "nb-avatar--square",
48
- className
49
- ].filter(Boolean).join(" "),
56
+ className: classes,
50
57
  role: "img",
51
58
  "aria-label": alt ?? (owner || "Avatar"),
52
59
  style: {
@@ -59,32 +66,104 @@ const Avatar = ({ owner = "", size, variant = "md", shape = "circle", alt, class
59
66
  });
60
67
  };
61
68
  //#endregion
69
+ //#region packages/ui/OverlayContainer.tsx
70
+ /** Keeps nested portals within the modal's focus and accessibility boundary. */
71
+ const OverlayContainerContext = createContext(null);
72
+ const useOverlayContainer = () => useContext(OverlayContainerContext);
73
+ //#endregion
74
+ //#region packages/ui/ModalSurface.tsx
75
+ /** Shared modal behavior for centered dialogs and side sheets. */
76
+ function ModalSurface({ open, onClose, children, rootClassName, className, style, scrimClassName, scrimLabel, labelledBy, ariaLabel, role = "dialog", keepMounted = false, restoreFocus = true, closeOnEscape = true, initialFocus, closeOnOutsideClick = true }) {
77
+ const parentContainer = useOverlayContainer();
78
+ const [container, setContainer] = useState(null);
79
+ const returnFocus = useRef(null);
80
+ useLayoutEffect(() => {
81
+ if (!open) return;
82
+ const active = document.activeElement;
83
+ if (active instanceof HTMLElement && !container?.contains(active)) returnFocus.current = active;
84
+ }, [open, container]);
85
+ return /* @__PURE__ */ jsx(Dialog.Root, {
86
+ open,
87
+ disablePointerDismissal: !closeOnOutsideClick,
88
+ onOpenChange: (next, details) => {
89
+ if (!next) {
90
+ if (details.reason === "escape-key" && !closeOnEscape) details.cancel();
91
+ else onClose();
92
+ }
93
+ },
94
+ children: /* @__PURE__ */ jsxs(Dialog.Portal, {
95
+ container: parentContainer ?? void 0,
96
+ keepMounted,
97
+ className: rootClassName,
98
+ "aria-hidden": !open || void 0,
99
+ style: {
100
+ visibility: open ? void 0 : "hidden",
101
+ pointerEvents: open ? void 0 : "none"
102
+ },
103
+ children: [/* @__PURE__ */ jsx(Dialog.Backdrop, {
104
+ forceRender: true,
105
+ className: scrimClassName,
106
+ render: /* @__PURE__ */ jsx("button", {
107
+ type: "button",
108
+ tabIndex: -1,
109
+ "aria-label": scrimLabel
110
+ })
111
+ }), /* @__PURE__ */ jsx(Dialog.Popup, {
112
+ ref: setContainer,
113
+ role,
114
+ "aria-labelledby": labelledBy,
115
+ "aria-label": ariaLabel,
116
+ className,
117
+ style,
118
+ finalFocus: restoreFocus ? () => returnFocus.current ?? true : false,
119
+ initialFocus,
120
+ onKeyDown: (event) => {
121
+ if (event.key === "Escape" && !event.defaultPrevented) {
122
+ event.stopPropagation();
123
+ if (closeOnEscape) onClose();
124
+ }
125
+ },
126
+ children: /* @__PURE__ */ jsx(OverlayContainerContext.Provider, {
127
+ value: container,
128
+ children
129
+ })
130
+ })]
131
+ })
132
+ });
133
+ }
134
+ //#endregion
62
135
  //#region packages/ui/Button.tsx
63
- const cx$5 = (...values) => values.filter(Boolean).join(" ");
64
- const Button = ({ variant = "secondary", size = "md", fullWidth = false, icon, loading = false, className, children, disabled, ...props }) => /* @__PURE__ */ jsxs("button", {
65
- ...props,
66
- type: props.type ?? "button",
67
- disabled: disabled || loading,
68
- "aria-busy": loading || void 0,
69
- className: cx$5("nb-button", `nb-button--${variant}`, size === "sm" && "nb-button--sm", fullWidth && "nb-button--full", className),
70
- children: [loading ? /* @__PURE__ */ jsx("span", {
71
- className: "nb-button-spinner",
72
- "aria-hidden": "true"
73
- }) : icon ? /* @__PURE__ */ jsx("i", {
74
- className: icon,
75
- "aria-hidden": "true"
76
- }) : null, children]
136
+ const cx$2 = (...values) => values.filter(Boolean).join(" ");
137
+ const Button = forwardRef(function Button({ variant = "secondary", size = "md", fullWidth = false, icon, loading = false, className, children, disabled, ...props }, ref) {
138
+ return /* @__PURE__ */ jsxs("button", {
139
+ ...props,
140
+ ref,
141
+ type: props.type ?? "button",
142
+ disabled: disabled || loading,
143
+ "aria-busy": loading || void 0,
144
+ className: cx$2("nb-button", `nb-button--${variant}`, size === "sm" && "nb-button--sm", fullWidth && "nb-button--full", className),
145
+ children: [loading ? /* @__PURE__ */ jsx("span", {
146
+ className: "nb-button-spinner",
147
+ "aria-hidden": "true"
148
+ }) : icon ? /* @__PURE__ */ jsx("i", {
149
+ className: icon,
150
+ "aria-hidden": "true"
151
+ }) : null, children]
152
+ });
77
153
  });
78
- const IconButton = ({ icon, label, variant = "default", className, ...props }) => /* @__PURE__ */ jsx("button", {
79
- ...props,
80
- type: props.type ?? "button",
81
- "aria-label": props["aria-label"] ?? label,
82
- title: props.title ?? label,
83
- className: cx$5("nb-icon-button", variant === "danger" && "nb-icon-button--danger", className),
84
- children: /* @__PURE__ */ jsx("i", {
85
- className: icon,
86
- "aria-hidden": "true"
87
- })
154
+ const IconButton = forwardRef(function IconButton({ icon, label, variant = "default", className, ...props }, ref) {
155
+ return /* @__PURE__ */ jsx("button", {
156
+ ...props,
157
+ ref,
158
+ type: props.type ?? "button",
159
+ "aria-label": props["aria-label"] ?? label,
160
+ title: props.title ?? label,
161
+ className: cx$2("nb-icon-button", variant === "danger" && "nb-icon-button--danger", className),
162
+ children: /* @__PURE__ */ jsx("i", {
163
+ className: icon,
164
+ "aria-hidden": "true"
165
+ })
166
+ });
88
167
  });
89
168
  //#endregion
90
169
  //#region packages/ui/UiStrings.tsx
@@ -97,6 +176,9 @@ const EN_UI_STRINGS = {
97
176
  openCalendar: "Open calendar",
98
177
  selectDate: "Select date",
99
178
  selectDateRange: "Select date range",
179
+ startDate: "Start date",
180
+ endDate: "End date",
181
+ selectTime: "Select time",
100
182
  previousMonth: "Previous month",
101
183
  nextMonth: "Next month",
102
184
  previousYear: "Previous year",
@@ -104,6 +186,16 @@ const EN_UI_STRINGS = {
104
186
  selectMonthAndYear: "Select month and year",
105
187
  selectYear: "Select year",
106
188
  clear: "Clear",
189
+ openOptions: "Open options",
190
+ noOptions: "No options found",
191
+ searching: "Searching…",
192
+ searchFailed: "Could not load options",
193
+ enterSearch: "Type to search",
194
+ loadingMore: "Loading more…",
195
+ loadMore: "Load more",
196
+ retrySearch: "Retry search",
197
+ selectedOptions: "Selected options",
198
+ removeOption: "Remove",
107
199
  today: "Today",
108
200
  cancel: "Cancel",
109
201
  confirm: "Confirm",
@@ -114,7 +206,38 @@ const EN_UI_STRINGS = {
114
206
  view: "View",
115
207
  pages: "Pages",
116
208
  previousPage: "Previous page",
117
- nextPage: "Next page"
209
+ nextPage: "Next page",
210
+ settingsMenu: "Display settings",
211
+ accentColor: "Accent color",
212
+ accentColors: "Accent colors",
213
+ density: "Density",
214
+ interfaceDensity: "Interface density",
215
+ densityNormal: "Normal",
216
+ densityCompact: "Compact",
217
+ mainNavigation: "Main navigation",
218
+ mainMenu: "Main menu",
219
+ closeMenu: "Close menu",
220
+ toggleMenu: "Toggle menu",
221
+ mainToolbar: "Main toolbar",
222
+ mainContent: "Main content",
223
+ userMenu: "User menu",
224
+ loadingSession: "Loading session",
225
+ textFormatting: "Text formatting",
226
+ bold: "Bold (Ctrl+B)",
227
+ italic: "Italic (Ctrl+I)",
228
+ strikethrough: "Strikethrough",
229
+ heading2: "Heading 2",
230
+ heading3: "Heading 3",
231
+ bulletList: "Bullet list",
232
+ orderedList: "Ordered list",
233
+ blockquote: "Blockquote",
234
+ addLink: "Add link",
235
+ removeLink: "Remove link",
236
+ undo: "Undo (Ctrl+Z)",
237
+ redo: "Redo (Ctrl+Y)",
238
+ featureUnavailable: "This feature is not available on your current plan.",
239
+ featureRequiresPlan: "This feature requires the {plan} plan. Upgrade your plan to unlock it.",
240
+ viewPlans: "View plans"
118
241
  };
119
242
  const ES_UI_STRINGS = {
120
243
  close: "Cerrar",
@@ -125,6 +248,9 @@ const ES_UI_STRINGS = {
125
248
  openCalendar: "Abrir calendario",
126
249
  selectDate: "Seleccionar fecha",
127
250
  selectDateRange: "Seleccionar rango de fechas",
251
+ startDate: "Fecha inicio",
252
+ endDate: "Fecha fin",
253
+ selectTime: "Seleccionar hora",
128
254
  previousMonth: "Mes anterior",
129
255
  nextMonth: "Mes siguiente",
130
256
  previousYear: "Año anterior",
@@ -132,6 +258,16 @@ const ES_UI_STRINGS = {
132
258
  selectMonthAndYear: "Seleccionar mes y año",
133
259
  selectYear: "Seleccionar año",
134
260
  clear: "Limpiar",
261
+ openOptions: "Abrir opciones",
262
+ noOptions: "No se encontraron opciones",
263
+ searching: "Buscando…",
264
+ searchFailed: "No se pudieron cargar las opciones",
265
+ enterSearch: "Escribe para buscar",
266
+ loadingMore: "Cargando más…",
267
+ loadMore: "Cargar más",
268
+ retrySearch: "Reintentar búsqueda",
269
+ selectedOptions: "Opciones seleccionadas",
270
+ removeOption: "Quitar",
135
271
  today: "Hoy",
136
272
  cancel: "Cancelar",
137
273
  confirm: "Confirmar",
@@ -142,7 +278,38 @@ const ES_UI_STRINGS = {
142
278
  view: "Ver",
143
279
  pages: "Páginas",
144
280
  previousPage: "Página anterior",
145
- nextPage: "Página siguiente"
281
+ nextPage: "Página siguiente",
282
+ settingsMenu: "Ajustes de visualización",
283
+ accentColor: "Color de acento",
284
+ accentColors: "Colores de acento",
285
+ density: "Densidad",
286
+ interfaceDensity: "Densidad de interfaz",
287
+ densityNormal: "Normal",
288
+ densityCompact: "Compacta",
289
+ mainNavigation: "Navegación principal",
290
+ mainMenu: "Menú principal",
291
+ closeMenu: "Cerrar menú",
292
+ toggleMenu: "Alternar menú",
293
+ mainToolbar: "Barra de herramientas principal",
294
+ mainContent: "Contenido principal",
295
+ userMenu: "Menú de usuario",
296
+ loadingSession: "Cargando sesión",
297
+ textFormatting: "Formato de texto",
298
+ bold: "Negrita (Ctrl+B)",
299
+ italic: "Cursiva (Ctrl+I)",
300
+ strikethrough: "Tachado",
301
+ heading2: "Título 2",
302
+ heading3: "Título 3",
303
+ bulletList: "Lista con viñetas",
304
+ orderedList: "Lista numerada",
305
+ blockquote: "Cita",
306
+ addLink: "Añadir enlace",
307
+ removeLink: "Quitar enlace",
308
+ undo: "Deshacer (Ctrl+Z)",
309
+ redo: "Rehacer (Ctrl+Y)",
310
+ featureUnavailable: "Esta función no está disponible en tu plan actual.",
311
+ featureRequiresPlan: "Esta función requiere el plan {plan}. Actualiza tu plan para desbloquearla.",
312
+ viewPlans: "Ver planes"
146
313
  };
147
314
  const UiStringsContext = createContext(EN_UI_STRINGS);
148
315
  const UiStringsProvider = ({ strings, children }) => {
@@ -163,115 +330,75 @@ const formatSize = (value) => {
163
330
  return typeof value === "number" ? `${value}px` : value;
164
331
  };
165
332
  const joinClassNames = (...values) => values.filter(Boolean).join(" ");
166
- 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" }) => {
333
+ 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" }) => {
167
334
  const strings = useUiStrings();
168
335
  const resolvedCloseLabel = closeLabel ?? strings.close;
169
336
  const resolvedScrimLabel = scrimLabel ?? strings.closeDialog;
170
337
  const isVisible = visible ?? open ?? false;
171
338
  const titleId = useId();
172
- const dialogRef = useRef(null);
173
- const lastFocusedElementRef = useRef(null);
174
- const restoreFocusRef = useRef(restoreFocus);
175
- useEffect(() => {
176
- restoreFocusRef.current = restoreFocus;
177
- }, [restoreFocus]);
178
- useEffect(() => {
179
- if (!isVisible) return;
180
- lastFocusedElementRef.current = document.activeElement;
181
- window.setTimeout(() => {
182
- (dialogRef.current?.querySelector("button:not(:disabled), [href], input:not(:disabled), select:not(:disabled), textarea:not(:disabled), [tabindex]:not([tabindex=\"-1\"])"))?.focus();
183
- });
184
- return () => {
185
- if (restoreFocusRef.current) lastFocusedElementRef.current?.focus?.();
186
- };
187
- }, [isVisible]);
188
- useEffect(() => {
189
- if (!isVisible || !closeOnEscape) return;
190
- const handleKeyDown = (event) => {
191
- if (event.key === "Escape") {
192
- event.preventDefault();
193
- onClose();
194
- }
195
- };
196
- document.addEventListener("keydown", handleKeyDown);
197
- return () => document.removeEventListener("keydown", handleKeyDown);
198
- }, [
199
- closeOnEscape,
339
+ return /* @__PURE__ */ jsxs(ModalSurface, {
340
+ open: isVisible,
200
341
  onClose,
201
- isVisible
202
- ]);
203
- if (!isVisible && !keepMounted) return null;
204
- return createPortal(/* @__PURE__ */ jsxs("div", {
205
- className: joinClassNames("nb-dialog-root", rootClassName),
206
- "aria-hidden": !isVisible,
342
+ rootClassName: joinClassNames("nb-dialog-root", rootClassName),
343
+ className: joinClassNames("nb-dialog", fullScreen && "nb-dialog--fullscreen", className),
344
+ scrimClassName: "nb-dialog__scrim",
345
+ scrimLabel: resolvedScrimLabel,
346
+ labelledBy: titleId,
347
+ role,
348
+ closeOnEscape,
349
+ closeOnOutsideClick,
350
+ restoreFocus,
351
+ keepMounted,
352
+ initialFocus,
207
353
  style: {
208
- pointerEvents: isVisible ? void 0 : "none",
209
- visibility: isVisible ? void 0 : "hidden"
354
+ width: formatSize(width),
355
+ maxWidth: formatSize(maxWidth),
356
+ height: formatSize(height)
210
357
  },
211
- children: [/* @__PURE__ */ jsx("button", {
212
- className: "nb-dialog__scrim",
213
- type: "button",
214
- "aria-label": resolvedScrimLabel,
215
- onClick: closeOnOutsideClick ? onClose : void 0
216
- }), /* @__PURE__ */ jsxs("div", {
217
- className: joinClassNames("nb-dialog", fullScreen && "nb-dialog--fullscreen", className),
218
- role,
219
- "aria-modal": "true",
220
- "aria-labelledby": titleId,
221
- ref: dialogRef,
222
- onKeyDownCapture: (event) => {
223
- if (!closeOnEscape && event.key === "Escape") {
224
- event.preventDefault();
225
- event.stopPropagation();
226
- }
227
- },
228
- style: {
229
- width: formatSize(width),
230
- maxWidth: formatSize(maxWidth),
231
- height: formatSize(height)
232
- },
233
- children: [
234
- /* @__PURE__ */ jsxs("div", {
235
- className: joinClassNames("nb-dialog__header", headerClassName),
236
- children: [/* @__PURE__ */ jsx("h2", {
237
- className: joinClassNames("nb-dialog__title", titleClassName),
238
- id: titleId,
239
- children: title
240
- }), showCloseButton && /* @__PURE__ */ jsx(IconButton, {
241
- className: "nb-dialog__close",
242
- icon: "ph ph-x",
243
- label: resolvedCloseLabel,
244
- onClick: onClose
245
- })]
246
- }),
247
- /* @__PURE__ */ jsx("div", {
248
- className: joinClassNames("nb-dialog__body", bodyClassName),
249
- children
250
- }),
251
- footer && /* @__PURE__ */ jsx("div", {
252
- className: joinClassNames("nb-dialog__footer", footerClassName),
253
- children: footer
254
- })
255
- ]
256
- })]
257
- }), document.body);
358
+ children: [
359
+ /* @__PURE__ */ jsxs("div", {
360
+ className: joinClassNames("nb-dialog__header", headerClassName),
361
+ children: [/* @__PURE__ */ jsx("h2", {
362
+ className: joinClassNames("nb-dialog__title", titleClassName),
363
+ id: titleId,
364
+ children: title
365
+ }), showCloseButton && /* @__PURE__ */ jsx(IconButton, {
366
+ className: "nb-dialog__close",
367
+ icon: "ph ph-x",
368
+ label: resolvedCloseLabel,
369
+ onClick: onClose
370
+ })]
371
+ }),
372
+ /* @__PURE__ */ jsx("div", {
373
+ className: joinClassNames("nb-dialog__body", bodyClassName),
374
+ children
375
+ }),
376
+ footer && /* @__PURE__ */ jsx("div", {
377
+ className: joinClassNames("nb-dialog__footer", footerClassName),
378
+ children: footer
379
+ })
380
+ ]
381
+ });
258
382
  };
259
383
  //#endregion
260
384
  //#region packages/ui/ConfirmDialog.tsx
261
385
  function ConfirmDialog({ open, title, message, onConfirm, onCancel, confirmLabel, cancelLabel, variant = "warning" }) {
262
386
  const strings = useUiStrings();
387
+ const cancelRef = useRef(null);
263
388
  const resolvedConfirmLabel = confirmLabel ?? strings.confirm;
389
+ const resolvedCancelLabel = cancelLabel ?? strings.cancel;
264
390
  return /* @__PURE__ */ jsx(AppDialog, {
265
391
  open,
266
392
  title,
267
393
  onClose: onCancel,
268
394
  maxWidth: 420,
269
395
  role: "alertdialog",
396
+ initialFocus: cancelRef,
270
397
  footer: /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(Button, {
271
398
  variant: "secondary",
272
399
  onClick: onCancel,
273
- autoFocus: true,
274
- children: cancelLabel ?? strings.cancel
400
+ ref: cancelRef,
401
+ children: resolvedCancelLabel
275
402
  }), /* @__PURE__ */ jsx(Button, {
276
403
  variant: variant === "danger" ? "danger" : "primary",
277
404
  onClick: onConfirm,
@@ -356,10 +483,10 @@ const Card = ({ title, description, variant = "auth", className, children }) =>
356
483
  };
357
484
  //#endregion
358
485
  //#region packages/ui/FormControls.tsx
359
- const cx$4 = (...values) => values.filter(Boolean).join(" ");
486
+ const cx$1 = (...values) => values.filter(Boolean).join(" ");
360
487
  const FormField = ({ label, error, helpText, children, className, ...props }) => /* @__PURE__ */ jsxs("label", {
361
488
  ...props,
362
- className: cx$4("nb-form-field", !!error && "nb-form-field--error", className),
489
+ className: cx$1("nb-form-field", !!error && "nb-form-field--error", className),
363
490
  children: [
364
491
  label && /* @__PURE__ */ jsx("span", {
365
492
  className: "nb-form-field__label",
@@ -380,14 +507,14 @@ const TextField = forwardRef(function TextField({ className, invalid, ...props }
380
507
  return /* @__PURE__ */ jsx("input", {
381
508
  ...props,
382
509
  ref,
383
- className: cx$4("nb-input", invalid && "nb-input--invalid", className)
510
+ className: cx$1("nb-input", invalid && "nb-input--invalid", className)
384
511
  });
385
512
  });
386
513
  const SelectField = forwardRef(function SelectField({ className, invalid, children, ...props }, ref) {
387
514
  return /* @__PURE__ */ jsx("select", {
388
515
  ...props,
389
516
  ref,
390
- className: cx$4("nb-input", "nb-select", invalid && "nb-input--invalid", className),
517
+ className: cx$1("nb-input", "nb-select", invalid && "nb-input--invalid", className),
391
518
  children
392
519
  });
393
520
  });
@@ -395,12 +522,12 @@ const TextAreaField = forwardRef(function TextAreaField({ className, invalid, ..
395
522
  return /* @__PURE__ */ jsx("textarea", {
396
523
  ...props,
397
524
  ref,
398
- className: cx$4("nb-input", "nb-textarea", invalid && "nb-input--invalid", className)
525
+ className: cx$1("nb-input", "nb-textarea", invalid && "nb-input--invalid", className)
399
526
  });
400
527
  });
401
528
  //#endregion
402
529
  //#region packages/ui/FileDropzone.tsx
403
- function cx$3(...values) {
530
+ function cx(...values) {
404
531
  return values.filter(Boolean).join(" ");
405
532
  }
406
533
  function buildDropzoneAccept(accept) {
@@ -445,10 +572,10 @@ function FileDropzone({ accept, value = null, image = false, disabled = false, r
445
572
  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";
446
573
  const placeholderHint = image ? labels?.imageHint ?? "PNG, JPG, WebP or GIF" : labels?.hint ?? "Select one file";
447
574
  return /* @__PURE__ */ jsxs("div", {
448
- className: cx$3("nb-file-dropzone", image && "nb-file-dropzone--image", invalid && "nb-file-dropzone--invalid", className),
575
+ className: cx("nb-file-dropzone", image && "nb-file-dropzone--image", invalid && "nb-file-dropzone--invalid", className),
449
576
  children: [/* @__PURE__ */ jsxs("div", {
450
- ...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") }),
451
- children: [/* @__PURE__ */ jsx("input", { ...getInputProps({
577
+ ...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") }),
578
+ children: [!readOnly && /* @__PURE__ */ jsx("input", { ...getInputProps({
452
579
  id: inputId,
453
580
  "aria-label": inputLabel
454
581
  }) }), hasContent ? /* @__PURE__ */ jsxs(Fragment, { children: [
@@ -521,9 +648,9 @@ function FileDropzone({ accept, value = null, image = false, disabled = false, r
521
648
  }),
522
649
  /* @__PURE__ */ jsx("span", {
523
650
  className: "nb-file-dropzone__title",
524
- children: placeholderTitle
651
+ children: readOnly ? labels?.empty ?? (image ? "No image" : "No file") : placeholderTitle
525
652
  }),
526
- /* @__PURE__ */ jsx("span", {
653
+ !readOnly && /* @__PURE__ */ jsx("span", {
527
654
  className: "nb-file-dropzone__hint",
528
655
  children: placeholderHint
529
656
  })
@@ -540,390 +667,532 @@ function FileDropzone({ accept, value = null, image = false, disabled = false, r
540
667
  });
541
668
  }
542
669
  //#endregion
543
- //#region packages/ui/useFloatingPanel.ts
544
- /** Style applied to an anchored panel before its first position is computed. */
545
- const HIDDEN_PANEL_STYLE = {
546
- position: "fixed",
547
- visibility: "hidden",
548
- margin: 0
549
- };
550
- /**
551
- * Fixed-position style for a panel anchored to an element, clamped to the
552
- * viewport with an 8px gutter and flipped above the anchor when it fits
553
- * better there.
554
- */
555
- function computeAnchoredStyle(anchor, options = {}) {
556
- if (!anchor) return HIDDEN_PANEL_STYLE;
557
- const { align = "start", minWidth = 0, matchAnchorWidth = false, offset = 4, flipThreshold = 250, zIndex = 9999 } = options;
558
- const rect = anchor.getBoundingClientRect();
559
- const width = Math.max(matchAnchorWidth ? rect.width : 0, minWidth);
560
- 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));
561
- const spaceBelow = window.innerHeight - rect.bottom;
562
- if (spaceBelow < flipThreshold && rect.top > spaceBelow) return {
563
- position: "fixed",
564
- left: `${left}px`,
565
- width: `${width}px`,
566
- bottom: `${window.innerHeight - rect.top + offset}px`,
567
- top: "auto",
568
- margin: 0,
569
- zIndex,
570
- visibility: "visible"
571
- };
572
- return {
573
- position: "fixed",
574
- left: `${left}px`,
575
- width: `${width}px`,
576
- top: `${rect.bottom + offset}px`,
577
- bottom: "auto",
578
- margin: 0,
579
- zIndex,
580
- visibility: "visible"
581
- };
582
- }
583
- function useFloatingPanel(options = {}) {
584
- const [open, setOpenState] = useState(false);
585
- const [panelStyle, setPanelStyle] = useState(HIDDEN_PANEL_STYLE);
586
- const containerRef = useRef(null);
587
- const panelRef = useRef(null);
588
- const optionsRef = useRef(options);
589
- optionsRef.current = options;
590
- const anchored = !!options.computeStyle;
591
- const dismissEvent = options.dismissEvent ?? "pointerdown";
592
- const setOpen = useCallback((next) => {
593
- setOpenState(next);
594
- if (!next) optionsRef.current.onClose?.();
595
- optionsRef.current.onOpenChange?.(next);
596
- }, []);
597
- const applyStyle = useCallback(() => {
598
- const compute = optionsRef.current.computeStyle;
599
- if (!compute) return;
600
- const style = compute(containerRef.current);
601
- if (style) setPanelStyle(style);
602
- }, []);
603
- const openPanel = useCallback(() => {
604
- applyStyle();
605
- setOpen(true);
606
- }, [applyStyle, setOpen]);
607
- const toggle = useCallback(() => open ? setOpen(false) : openPanel(), [
670
+ //#region packages/ui/AppDropdown.tsx
671
+ 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 }) {
672
+ const generatedId = useId();
673
+ const id = idProp ?? generatedId;
674
+ const container = useOverlayContainer();
675
+ const [open, setOpen] = useState(false);
676
+ const selected = options.find((option) => option.value === value);
677
+ const labelled = !!label && (showFieldLabel || variant === "toolbar");
678
+ const message = error ?? helpText;
679
+ const iconClass = icon?.startsWith("ph ") ? icon : icon?.startsWith("ph-") ? `ph ${icon}` : `ph ph-${icon}`;
680
+ return /* @__PURE__ */ jsx(Select.Root, {
681
+ value,
682
+ onValueChange: (next) => {
683
+ if (next !== null) onChange(next);
684
+ },
685
+ disabled,
608
686
  open,
609
- openPanel,
610
- setOpen
611
- ]);
687
+ onOpenChange: (next) => {
688
+ setOpen(next);
689
+ onOpenChange?.(next);
690
+ },
691
+ modal: false,
692
+ children: /* @__PURE__ */ jsxs("div", {
693
+ className: showFieldLabel && variant !== "toolbar" ? "nb-form-field" : void 0,
694
+ children: [
695
+ showFieldLabel && variant !== "toolbar" && label && /* @__PURE__ */ jsx("label", {
696
+ className: "nb-form-field__label",
697
+ id: `${id}-label`,
698
+ htmlFor: id,
699
+ children: label
700
+ }),
701
+ /* @__PURE__ */ jsxs("div", {
702
+ className: [
703
+ "nb-dropdown",
704
+ `nb-dropdown--${variant}`,
705
+ open && "nb-dropdown--open",
706
+ disabled && "nb-dropdown--disabled",
707
+ className
708
+ ].filter(Boolean).join(" "),
709
+ children: [
710
+ variant === "toolbar" && label && /* @__PURE__ */ jsxs("span", {
711
+ className: "nb-dropdown__toolbar-label",
712
+ id: `${id}-label`,
713
+ children: [icon && /* @__PURE__ */ jsx("i", {
714
+ className: iconClass,
715
+ "aria-hidden": "true"
716
+ }), /* @__PURE__ */ jsx("span", { children: label })]
717
+ }),
718
+ /* @__PURE__ */ jsxs(Select.Trigger, {
719
+ id,
720
+ className: "nb-dropdown__trigger",
721
+ onKeyDownCapture: (event) => {
722
+ if (open && event.key === "Escape") {
723
+ event.preventDefault();
724
+ event.stopPropagation();
725
+ setOpen(false);
726
+ onOpenChange?.(false);
727
+ }
728
+ },
729
+ "aria-label": ariaLabel,
730
+ "aria-labelledby": ariaLabel ? void 0 : labelled ? `${id}-label ${id}-value` : `${id}-value`,
731
+ "aria-describedby": message ? `${id}-message` : void 0,
732
+ "aria-invalid": !!error || void 0,
733
+ children: [/* @__PURE__ */ jsx("span", {
734
+ className: "nb-dropdown__value",
735
+ id: `${id}-value`,
736
+ children: selected?.selectedLabel ?? selected?.label ?? placeholder
737
+ }), /* @__PURE__ */ jsx("i", {
738
+ className: "ph ph-caret-down nb-dropdown__caret",
739
+ "aria-hidden": "true"
740
+ })]
741
+ }),
742
+ /* @__PURE__ */ jsx(Select.Portal, {
743
+ container: container ?? void 0,
744
+ children: /* @__PURE__ */ jsx(Select.Positioner, {
745
+ align: "start",
746
+ sideOffset: 4,
747
+ alignItemWithTrigger: false,
748
+ className: "nb-dropdown-positioner",
749
+ style: { minWidth: menuMinWidth },
750
+ children: /* @__PURE__ */ jsxs(Select.Popup, {
751
+ onKeyDownCapture: (event) => {
752
+ if (event.key === "Escape") {
753
+ event.preventDefault();
754
+ event.stopPropagation();
755
+ setOpen(false);
756
+ onOpenChange?.(false);
757
+ }
758
+ },
759
+ className: `nb-dropdown__menu nb-dropdown__menu--${variant}`,
760
+ children: [
761
+ menuHeader,
762
+ /* @__PURE__ */ jsx(Select.List, {
763
+ className: "nb-dropdown__menu-list",
764
+ children: options.map((option) => /* @__PURE__ */ jsxs(Select.Item, {
765
+ value: option.value,
766
+ label: option.label,
767
+ disabled: option.disabled,
768
+ className: ({ selected }) => `nb-dropdown__option${selected ? " nb-dropdown__option--active" : ""}`,
769
+ children: [/* @__PURE__ */ jsxs(Select.ItemText, {
770
+ className: "nb-dropdown__option-content",
771
+ children: [option.iconText && /* @__PURE__ */ jsx("span", {
772
+ className: "nb-dropdown__option-icon",
773
+ "aria-hidden": "true",
774
+ children: option.iconText
775
+ }), /* @__PURE__ */ jsx("span", { children: option.label })]
776
+ }), /* @__PURE__ */ jsx(Select.ItemIndicator, {
777
+ className: "nb-dropdown__selected",
778
+ "aria-hidden": "true",
779
+ children: /* @__PURE__ */ jsx("i", { className: "ph ph-check" })
780
+ })]
781
+ }, option.value))
782
+ }),
783
+ menuFooter
784
+ ]
785
+ })
786
+ })
787
+ })
788
+ ]
789
+ }),
790
+ message && /* @__PURE__ */ jsx("span", {
791
+ id: `${id}-message`,
792
+ className: error ? "nb-form-field__error" : "nb-form-field__help",
793
+ role: error ? "alert" : void 0,
794
+ children: message
795
+ })
796
+ ]
797
+ })
798
+ });
799
+ }
800
+ //#endregion
801
+ //#region packages/ui/useComboboxOptions.ts
802
+ function mergeOptions(...groups) {
803
+ const map = /* @__PURE__ */ new Map();
804
+ for (const group of groups) for (const option of group) map.set(option.value, option);
805
+ return [...map.values()];
806
+ }
807
+ function useComboboxOptions({ options, selected, loadOptions, open, query, debounceMs, minSearchLength }) {
808
+ const [state, setState] = useState({
809
+ query: "",
810
+ options: [],
811
+ known: [],
812
+ loading: false,
813
+ failed: false
814
+ });
815
+ const [revision, setRevision] = useState(0);
816
+ const generation = useRef(0);
817
+ const request = useRef(null);
818
+ const normalizedQuery = query.trim();
819
+ const eligible = normalizedQuery.length >= minSearchLength;
612
820
  useEffect(() => {
613
- if (!open) return;
614
- const handleOutside = (e) => {
615
- const target = e.target;
616
- if (containerRef.current?.contains(target) || panelRef.current?.contains(target)) return;
617
- setOpen(false);
618
- };
619
- const handleKeyDown = (e) => {
620
- if (e.key !== "Escape") return;
621
- setOpen(false);
622
- optionsRef.current.onEscape?.(e);
623
- };
624
- document.addEventListener(dismissEvent, handleOutside);
625
- document.addEventListener("keydown", handleKeyDown);
821
+ const currentGeneration = ++generation.current;
822
+ request.current?.abort();
823
+ request.current = null;
824
+ if (!loadOptions || !open || !eligible) return;
825
+ const controller = new AbortController();
826
+ request.current = controller;
827
+ const timer = setTimeout(async () => {
828
+ setState((previous) => ({
829
+ loader: loadOptions,
830
+ query: normalizedQuery,
831
+ options: [],
832
+ known: previous.loader === loadOptions ? previous.known : [],
833
+ loading: true,
834
+ failed: false
835
+ }));
836
+ try {
837
+ const page = await loadOptions(normalizedQuery, { signal: controller.signal });
838
+ if (controller.signal.aborted || generation.current !== currentGeneration) return;
839
+ setState((previous) => ({
840
+ loader: loadOptions,
841
+ query: normalizedQuery,
842
+ options: mergeOptions(page.options),
843
+ known: mergeOptions(previous.known, page.options),
844
+ nextCursor: page.nextCursor,
845
+ loading: false,
846
+ failed: false
847
+ }));
848
+ } catch {
849
+ if (controller.signal.aborted || generation.current !== currentGeneration) return;
850
+ setState((previous) => ({
851
+ ...previous,
852
+ loading: false,
853
+ failed: true
854
+ }));
855
+ } finally {
856
+ if (request.current === controller) request.current = null;
857
+ }
858
+ }, Math.max(0, debounceMs));
626
859
  return () => {
627
- document.removeEventListener(dismissEvent, handleOutside);
628
- document.removeEventListener("keydown", handleKeyDown);
860
+ clearTimeout(timer);
861
+ controller.abort();
629
862
  };
630
863
  }, [
631
- dismissEvent,
864
+ loadOptions,
632
865
  open,
633
- setOpen
866
+ normalizedQuery,
867
+ eligible,
868
+ debounceMs,
869
+ revision
634
870
  ]);
635
- useLayoutEffect(() => {
636
- if (!open || !anchored) return;
637
- const update = () => {
638
- const container = containerRef.current;
639
- if (!container) return;
640
- if (optionsRef.current.closeOnViewportExit) {
641
- const rect = container.getBoundingClientRect();
642
- if ((rect.width > 0 || rect.height > 0) && (rect.top >= window.innerHeight || rect.bottom <= 0)) {
643
- setOpen(false);
644
- return;
645
- }
646
- }
647
- applyStyle();
648
- };
649
- update();
650
- window.addEventListener("resize", update);
651
- window.addEventListener("scroll", update, {
652
- capture: true,
653
- passive: true
654
- });
655
- return () => {
656
- window.removeEventListener("resize", update);
657
- window.removeEventListener("scroll", update, { capture: true });
658
- };
871
+ const current = state.loader === loadOptions && state.query === normalizedQuery;
872
+ const loading = !!loadOptions && open && eligible && (!current || state.loading);
873
+ const failed = !!loadOptions && open && current && state.failed;
874
+ const known = mergeOptions(options, state.loader === loadOptions ? state.known : []);
875
+ const pinned = known.filter((option) => selected.includes(option.value));
876
+ const items = loadOptions ? mergeOptions(pinned, current && eligible ? state.options : []) : options;
877
+ const loadMore = useCallback(async () => {
878
+ if (!loadOptions || !open || !current || state.loading || request.current || state.nextCursor == null || !eligible) return;
879
+ const controller = new AbortController();
880
+ const currentGeneration = generation.current;
881
+ request.current = controller;
882
+ setState((previous) => ({
883
+ ...previous,
884
+ loading: true,
885
+ failed: false
886
+ }));
887
+ try {
888
+ const page = await loadOptions(normalizedQuery, {
889
+ signal: controller.signal,
890
+ cursor: state.nextCursor
891
+ });
892
+ if (controller.signal.aborted || currentGeneration !== generation.current) return;
893
+ setState((previous) => ({
894
+ ...previous,
895
+ options: mergeOptions(previous.options, page.options),
896
+ known: mergeOptions(previous.known, page.options),
897
+ nextCursor: page.nextCursor,
898
+ loading: false,
899
+ failed: false
900
+ }));
901
+ } catch {
902
+ if (controller.signal.aborted || currentGeneration !== generation.current) return;
903
+ setState((previous) => ({
904
+ ...previous,
905
+ loading: false,
906
+ failed: true
907
+ }));
908
+ } finally {
909
+ if (request.current === controller) request.current = null;
910
+ }
659
911
  }, [
660
- anchored,
661
- applyStyle,
912
+ loadOptions,
662
913
  open,
663
- setOpen
914
+ current,
915
+ state.loading,
916
+ state.nextCursor,
917
+ eligible,
918
+ normalizedQuery
664
919
  ]);
665
- return {
920
+ useEffect(() => () => {
921
+ request.current?.abort();
922
+ }, [
666
923
  open,
667
- setOpen,
668
- toggle,
669
- openPanel,
670
- containerRef,
671
- panelRef,
672
- panelStyle
924
+ normalizedQuery,
925
+ loadOptions
926
+ ]);
927
+ return {
928
+ items,
929
+ known,
930
+ loading,
931
+ failed,
932
+ eligible,
933
+ hasMore: !!loadOptions && open && eligible && current && state.nextCursor != null,
934
+ loadMore,
935
+ retry: () => setRevision((previous) => previous + 1)
673
936
  };
674
937
  }
675
938
  //#endregion
676
- //#region packages/ui/AppDropdown.tsx
677
- function cx$2(...values) {
678
- return values.filter(Boolean).join(" ");
679
- }
680
- function normalizeIcon$2(icon) {
681
- if (!icon) return void 0;
682
- if (icon.startsWith("ph ")) return icon;
683
- if (icon.startsWith("ph-")) return `ph ${icon}`;
684
- return `ph ph-${icon}`;
685
- }
686
- 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 }) {
687
- const generatedId = useId();
688
- const id = idProp ?? generatedId;
689
- const { open, setOpen: setMenuOpen, openPanel: openMenu, containerRef, panelRef: menuRef, panelStyle: menuStyle } = useFloatingPanel({
690
- onOpenChange,
691
- dismissEvent: "mousedown",
692
- closeOnViewportExit: true,
693
- computeStyle: (container) => {
694
- return computeAnchoredStyle(container?.querySelector(".nb-dropdown__trigger") ?? container, {
695
- matchAnchorWidth: true,
696
- minWidth: menuMinWidth ?? 72
697
- });
698
- }
939
+ //#region packages/ui/Combobox.tsx
940
+ const Combobox = forwardRef(function Combobox(props, ref) {
941
+ return /* @__PURE__ */ jsx(SelectionCombobox, {
942
+ ...props,
943
+ inputRef: ref,
944
+ multiple: false,
945
+ onChange: (value) => props.onChange(typeof value === "string" ? value : null)
699
946
  });
700
- const selected = options.find((option) => option.value === value);
701
- const control = /* @__PURE__ */ jsxs("div", {
702
- ref: containerRef,
703
- className: cx$2("nb-dropdown", `nb-dropdown--${variant}`, open && "nb-dropdown--open", disabled && "nb-dropdown--disabled", className),
704
- role: "group",
705
- "aria-labelledby": label ? `${id}-label` : void 0,
947
+ });
948
+ const MultiSelect = forwardRef(function MultiSelect(props, ref) {
949
+ return /* @__PURE__ */ jsx(SelectionCombobox, {
950
+ ...props,
951
+ inputRef: ref,
952
+ multiple: true,
953
+ onChange: (value) => props.onChange(Array.isArray(value) ? value : [])
954
+ });
955
+ });
956
+ 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 }) {
957
+ const overlayContainer = useOverlayContainer();
958
+ const generatedId = useId();
959
+ const inputId = id ?? generatedId;
960
+ const strings = useUiStrings();
961
+ const [open, setOpen] = useState(false);
962
+ const [query, setQuery] = useState("");
963
+ const selected = Array.isArray(value) ? value : value === null ? [] : [value];
964
+ const remote = useComboboxOptions({
965
+ options,
966
+ selected,
967
+ loadOptions,
968
+ open: open && !disabled && !readOnly,
969
+ query,
970
+ debounceMs,
971
+ minSearchLength
972
+ });
973
+ const message = error ?? helpText;
974
+ const messageId = `${inputId}-message`;
975
+ const description = [describedBy, message ? messageId : void 0].filter(Boolean).join(" ") || void 0;
976
+ const selectedOptions = selected.map((key) => remote.known.find((option) => option.value === key) ?? {
977
+ value: key,
978
+ label: key
979
+ });
980
+ const remoteStatus = remote.failed ? searchErrorMessage ?? strings.searchFailed : remote.loading ? loadingMessage ?? strings.searching : !remote.eligible && loadOptions ? strings.enterSearch : void 0;
981
+ return /* @__PURE__ */ jsxs(ComboBox, {
982
+ ...loadOptions ? { items: remote.items } : { defaultItems: options },
983
+ selectionMode: multiple ? "multiple" : "single",
984
+ value,
985
+ onChange: (keys) => onChange(Array.isArray(keys) ? keys.map(String) : keys === null ? null : String(keys)),
986
+ onInputChange: setQuery,
987
+ onOpenChange: (nextOpen, trigger) => {
988
+ setOpen(nextOpen);
989
+ onOpenChange?.(nextOpen);
990
+ if (!nextOpen || trigger !== "input") setQuery("");
991
+ },
992
+ name,
993
+ form,
994
+ isDisabled: disabled,
995
+ isReadOnly: readOnly,
996
+ isRequired: required,
997
+ isInvalid: invalid || !!error,
998
+ allowsEmptyCollection: true,
999
+ "aria-label": inputProps["aria-label"],
1000
+ "aria-labelledby": inputProps["aria-labelledby"],
1001
+ className: `nb-form-field${className ? ` ${className}` : ""}`,
706
1002
  children: [
707
- variant === "toolbar" && label && /* @__PURE__ */ jsxs("span", {
708
- className: "nb-dropdown__toolbar-label",
709
- id: `${id}-label`,
710
- children: [icon && /* @__PURE__ */ jsx("i", {
711
- className: normalizeIcon$2(icon),
712
- "aria-hidden": "true"
713
- }), /* @__PURE__ */ jsx("span", { children: label })]
1003
+ label && /* @__PURE__ */ jsx(Label, {
1004
+ className: "nb-form-field__label",
1005
+ children: label
714
1006
  }),
715
- /* @__PURE__ */ jsxs("button", {
716
- type: "button",
717
- className: "nb-dropdown__trigger",
718
- "aria-haspopup": "listbox",
719
- "aria-expanded": open,
720
- "aria-labelledby": label ? `${id}-label ${id}-value` : `${id}-value`,
721
- disabled,
722
- onClick: () => open ? setMenuOpen(false) : openMenu(),
723
- children: [/* @__PURE__ */ jsx("span", {
724
- className: "nb-dropdown__value",
725
- id: `${id}-value`,
726
- children: selected?.selectedLabel ?? selected?.label ?? placeholder
727
- }), /* @__PURE__ */ jsx("i", {
728
- className: "ph ph-caret-down nb-dropdown__caret",
729
- "aria-hidden": "true"
1007
+ /* @__PURE__ */ jsxs("div", {
1008
+ className: "nb-combobox",
1009
+ children: [/* @__PURE__ */ jsx(Input, {
1010
+ ...inputProps,
1011
+ ref: inputRef,
1012
+ id: inputId,
1013
+ className: `nb-input nb-combobox__input${invalid || error ? " nb-input--invalid" : ""}${inputClassName ? ` ${inputClassName}` : ""}`,
1014
+ onKeyDown: (event) => {
1015
+ inputProps.onKeyDown?.(event);
1016
+ if (open && event.key === "Escape") event.stopPropagation();
1017
+ if (!event.defaultPrevented && event.key === "PageDown" && remote.hasMore) {
1018
+ event.preventDefault();
1019
+ remote.loadMore();
1020
+ }
1021
+ },
1022
+ "aria-invalid": inputProps["aria-invalid"] ?? (invalid || !!error || void 0),
1023
+ "aria-describedby": description
1024
+ }), /* @__PURE__ */ jsxs("div", {
1025
+ className: "nb-combobox__actions",
1026
+ children: [clearable && !readOnly && /* @__PURE__ */ jsx(ComboboxClear, {
1027
+ label: clearLabel ?? strings.clear,
1028
+ disabled,
1029
+ multiple
1030
+ }), /* @__PURE__ */ jsx(Button$1, {
1031
+ className: "nb-combobox__action",
1032
+ "aria-label": openLabel ?? strings.openOptions,
1033
+ children: /* @__PURE__ */ jsx("svg", {
1034
+ viewBox: "0 0 24 24",
1035
+ "aria-hidden": "true",
1036
+ focusable: "false",
1037
+ children: /* @__PURE__ */ jsx("path", { d: "m6 9 6 6 6-6" })
1038
+ })
1039
+ })]
730
1040
  })]
731
1041
  }),
732
- open && !disabled && createPortal(/* @__PURE__ */ jsxs("div", {
733
- ref: menuRef,
734
- className: cx$2("nb-dropdown__menu", `nb-dropdown__menu--${variant}`),
735
- style: menuStyle,
1042
+ multiple && selectedOptions.length > 0 && /* @__PURE__ */ jsx(ComboBoxValue, { children: () => /* @__PURE__ */ jsx(TagGroup, {
1043
+ "aria-label": selectedLabel ?? strings.selectedOptions,
1044
+ onRemove: disabled || readOnly ? void 0 : (keys) => onChange(selected.filter((key) => !keys.has(key))),
1045
+ className: "nb-combobox-tags",
1046
+ children: /* @__PURE__ */ jsx(TagList, {
1047
+ items: selectedOptions,
1048
+ children: (option) => /* @__PURE__ */ jsxs(Tag, {
1049
+ id: option.value,
1050
+ textValue: option.label,
1051
+ className: "nb-combobox-tags__tag",
1052
+ children: [option.label, !disabled && !readOnly && /* @__PURE__ */ jsx(Button$1, {
1053
+ slot: "remove",
1054
+ className: "nb-combobox-tags__remove",
1055
+ "aria-label": removeLabel?.(option) ?? strings.removeOption,
1056
+ children: /* @__PURE__ */ jsx("svg", {
1057
+ viewBox: "0 0 24 24",
1058
+ "aria-hidden": "true",
1059
+ focusable: "false",
1060
+ children: /* @__PURE__ */ jsx("path", { d: "m6 6 12 12M18 6 6 18" })
1061
+ })
1062
+ })]
1063
+ })
1064
+ })
1065
+ }) }),
1066
+ /* @__PURE__ */ jsxs(Popover$1, {
1067
+ UNSTABLE_portalContainer: overlayContainer ?? void 0,
1068
+ className: "nb-combobox-popup",
1069
+ offset: 4,
1070
+ isNonModal: true,
1071
+ onScroll: (event) => {
1072
+ const panel = event.currentTarget;
1073
+ if (panel.scrollHeight - panel.scrollTop <= panel.clientHeight + 20) remote.loadMore();
1074
+ },
736
1075
  children: [
737
- menuHeader,
738
- /* @__PURE__ */ jsx("ul", {
739
- role: "listbox",
740
- "aria-labelledby": label ? `${id}-label` : void 0,
741
- className: "nb-dropdown__menu-list",
742
- children: options.map((option) => {
743
- const isActive = option.value === value;
744
- return /* @__PURE__ */ jsx("li", {
745
- role: "presentation",
746
- children: /* @__PURE__ */ jsx("button", {
747
- type: "button",
748
- role: "option",
749
- "aria-selected": isActive,
750
- disabled: option.disabled,
751
- className: cx$2("nb-dropdown__option", isActive && "nb-dropdown__option--active"),
752
- onClick: () => {
753
- if (option.disabled) return;
754
- onChange(option.value);
755
- setMenuOpen(false);
756
- },
757
- children: /* @__PURE__ */ jsxs("span", {
758
- className: "nb-dropdown__option-content",
759
- children: [option.iconText && /* @__PURE__ */ jsx("span", {
760
- className: "nb-dropdown__option-icon",
761
- "aria-hidden": "true",
762
- children: option.iconText
763
- }), /* @__PURE__ */ jsx("span", { children: option.label })]
764
- })
765
- })
766
- }, option.value);
1076
+ remoteStatus && /* @__PURE__ */ jsx("div", {
1077
+ className: "nb-combobox-popup__empty",
1078
+ role: remote.failed ? "alert" : "status",
1079
+ children: remoteStatus
1080
+ }),
1081
+ /* @__PURE__ */ jsx(ListBox, {
1082
+ className: "nb-combobox-popup__list",
1083
+ "aria-busy": remote.loading || void 0,
1084
+ renderEmptyState: () => remoteStatus ? null : /* @__PURE__ */ jsx("div", {
1085
+ className: "nb-combobox-popup__empty",
1086
+ children: emptyMessage ?? strings.noOptions
1087
+ }),
1088
+ children: (option) => /* @__PURE__ */ jsx(ListBoxItem, {
1089
+ id: option.value,
1090
+ textValue: option.label,
1091
+ isDisabled: option.disabled,
1092
+ className: "nb-combobox-popup__item",
1093
+ children: ({ isSelected }) => /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("span", {
1094
+ className: "nb-combobox-popup__indicator",
1095
+ "aria-hidden": "true",
1096
+ children: isSelected ? "✓" : ""
1097
+ }), option.content ?? option.label] })
767
1098
  })
768
1099
  }),
769
- menuFooter
1100
+ remote.hasMore && !remote.failed && /* @__PURE__ */ jsx(Button$1, {
1101
+ slot: null,
1102
+ className: "nb-combobox__action",
1103
+ isDisabled: remote.loading,
1104
+ onPress: () => {
1105
+ remote.loadMore();
1106
+ },
1107
+ children: strings.loadMore
1108
+ }),
1109
+ remote.failed && /* @__PURE__ */ jsx(Button$1, {
1110
+ className: "nb-combobox__action",
1111
+ onPress: remote.retry,
1112
+ children: strings.retrySearch
1113
+ })
770
1114
  ]
771
- }), document.body)
772
- ]
773
- });
774
- if (!showFieldLabel || variant === "toolbar") return control;
775
- return /* @__PURE__ */ jsxs("label", {
776
- className: cx$2("nb-form-field", !!error && "nb-form-field--error"),
777
- htmlFor: id,
778
- children: [
779
- label && /* @__PURE__ */ jsx("span", {
780
- className: "nb-form-field__label",
781
- id: `${id}-label`,
782
- children: label
783
1115
  }),
784
- control,
785
- error ? /* @__PURE__ */ jsx("span", {
786
- className: "nb-form-field__error",
787
- role: "alert",
788
- children: error
789
- }) : helpText ? /* @__PURE__ */ jsx("span", {
790
- className: "nb-form-field__help",
791
- children: helpText
792
- }) : null
1116
+ message && /* @__PURE__ */ jsx("span", {
1117
+ id: messageId,
1118
+ className: error ? "nb-form-field__error" : "nb-form-field__help",
1119
+ role: error ? "alert" : void 0,
1120
+ children: message
1121
+ })
793
1122
  ]
794
1123
  });
795
1124
  }
1125
+ function ComboboxClear({ label, disabled, multiple }) {
1126
+ const state = useContext(ComboBoxStateContext);
1127
+ const hasValue = multiple ? Array.isArray(state?.value) && state.value.length > 0 : !!state?.inputValue;
1128
+ if (!state || !hasValue || state.isOpen) return null;
1129
+ return /* @__PURE__ */ jsx(Button$1, {
1130
+ slot: null,
1131
+ isDisabled: disabled,
1132
+ className: "nb-combobox__action nb-combobox__clear",
1133
+ "aria-label": label,
1134
+ onPress: () => {
1135
+ state.setValue(multiple ? [] : null);
1136
+ state.setInputValue("");
1137
+ },
1138
+ children: /* @__PURE__ */ jsx("svg", {
1139
+ viewBox: "0 0 24 24",
1140
+ "aria-hidden": "true",
1141
+ focusable: "false",
1142
+ children: /* @__PURE__ */ jsx("path", { d: "m6 6 12 12M18 6 6 18" })
1143
+ })
1144
+ });
1145
+ }
796
1146
  //#endregion
797
1147
  //#region packages/ui/SearchableAppDropdown.tsx
798
- function normalizeSearch(value) {
799
- return value.trim().toLowerCase();
800
- }
801
- function filterOptions(options, query) {
802
- const needle = normalizeSearch(query);
803
- if (!needle) return options;
804
- return options.filter((option) => {
805
- return [
806
- option.label,
807
- option.selectedLabel,
808
- option.value
809
- ].filter(Boolean).join(" ").toLowerCase().includes(needle);
810
- });
811
- }
812
- function SearchableAppDropdown({ options = [], searchable = true, searchPlaceholder = "Buscar…", onSearch, minSearchLength = 2, emptySearchLabel = "Sin resultados", loadingLabel = "Buscando…", selectedOption = null, value, onChange, placeholder, disabled, ...rest }) {
813
- const searchInputId = useId();
814
- const [open, setOpen] = useState(false);
815
- const [searchQuery, setSearchQuery] = useState("");
816
- const [remoteOptions, setRemoteOptions] = useState([]);
817
- const [loading, setLoading] = useState(false);
818
- const requestIdRef = useRef(0);
819
- const staticSelected = useMemo(() => options.find((option) => option.value === value) ?? selectedOption ?? null, [
820
- options,
821
- selectedOption,
822
- value
823
- ]);
824
- const resolvedOptions = useMemo(() => {
825
- const merged = /* @__PURE__ */ new Map();
826
- for (const option of [...options, ...remoteOptions]) if (option.value) merged.set(option.value, option);
827
- if (staticSelected?.value) merged.set(staticSelected.value, staticSelected);
828
- const base = Array.from(merged.values()).filter((option) => option.value !== "");
829
- if (!searchable) return base;
830
- if (onSearch) return base;
831
- return filterOptions(base, searchQuery);
832
- }, [
833
- onSearch,
834
- options,
835
- remoteOptions,
836
- searchable,
837
- searchQuery,
838
- staticSelected
839
- ]);
840
- const runSearch = useCallback(async (query) => {
841
- if (!onSearch) return;
842
- const trimmed = query.trim();
843
- if (trimmed.length < minSearchLength) {
844
- setRemoteOptions([]);
845
- setLoading(false);
846
- return;
847
- }
848
- const requestId = ++requestIdRef.current;
849
- setLoading(true);
850
- try {
851
- const results = await onSearch(trimmed);
852
- if (requestId !== requestIdRef.current) return;
853
- setRemoteOptions(results.filter((option) => option.value !== ""));
854
- } catch {
855
- if (requestId !== requestIdRef.current) return;
856
- setRemoteOptions([]);
857
- } finally {
858
- if (requestId === requestIdRef.current) setLoading(false);
859
- }
860
- }, [minSearchLength, onSearch]);
861
- useEffect(() => {
862
- if (!open || !onSearch) return;
863
- const timer = window.setTimeout(() => {
864
- runSearch(searchQuery);
865
- }, 250);
866
- return () => window.clearTimeout(timer);
867
- }, [
868
- open,
869
- onSearch,
870
- runSearch,
871
- searchQuery
872
- ]);
873
- useEffect(() => {
874
- if (open) return;
875
- setSearchQuery("");
876
- setRemoteOptions([]);
877
- setLoading(false);
878
- }, [open]);
879
- const menuHeader = searchable ? /* @__PURE__ */ jsxs("div", {
880
- className: "nb-searchable-dropdown__search",
881
- children: [/* @__PURE__ */ jsx("i", {
882
- className: "ph ph-magnifying-glass",
883
- "aria-hidden": "true"
884
- }), /* @__PURE__ */ jsx("input", {
885
- id: searchInputId,
886
- type: "search",
887
- value: searchQuery,
888
- onChange: (event) => setSearchQuery(event.target.value),
889
- placeholder: searchPlaceholder,
890
- autoComplete: "off",
891
- onKeyDown: (event) => event.stopPropagation()
892
- })]
893
- }) : null;
894
- const menuFooter = (() => {
895
- if (!searchable || !onSearch) return null;
896
- if (loading) return /* @__PURE__ */ jsx("div", {
897
- className: "nb-searchable-dropdown__status",
898
- children: loadingLabel
899
- });
900
- if (searchQuery.trim().length < minSearchLength) return /* @__PURE__ */ jsxs("div", {
901
- className: "nb-searchable-dropdown__status",
902
- children: [
903
- "Escribe al menos ",
904
- minSearchLength,
905
- " caracteres"
906
- ]
907
- });
908
- if (resolvedOptions.length === 0) return /* @__PURE__ */ jsx("div", {
909
- className: "nb-searchable-dropdown__status",
910
- children: emptySearchLabel
911
- });
912
- return null;
913
- })();
914
- return /* @__PURE__ */ jsx(AppDropdown, {
1148
+ const toOption = (option) => ({
1149
+ value: option.value,
1150
+ label: option.selectedLabel ?? option.label,
1151
+ disabled: option.disabled,
1152
+ content: /* @__PURE__ */ jsxs("span", {
1153
+ className: "nb-dropdown__option-content",
1154
+ children: [option.iconText && /* @__PURE__ */ jsx("span", {
1155
+ className: "nb-dropdown__option-icon",
1156
+ "aria-hidden": "true",
1157
+ children: option.iconText
1158
+ }), option.label]
1159
+ })
1160
+ });
1161
+ 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 }) {
1162
+ const loadOptions = useCallback(async (query, { signal }) => {
1163
+ const results = await onSearch(query.trim());
1164
+ if (signal.aborted) throw new DOMException("Search cancelled", "AbortError");
1165
+ return { options: results.map(toOption) };
1166
+ }, [onSearch]);
1167
+ if (!searchable) return /* @__PURE__ */ jsx(AppDropdown, {
915
1168
  ...rest,
1169
+ options,
916
1170
  value,
917
1171
  onChange,
918
1172
  placeholder,
919
1173
  disabled,
920
- options: [{
921
- value: "",
922
- label: placeholder ?? "Seleccionar…"
923
- }, ...resolvedOptions],
924
- menuHeader,
925
- menuFooter,
926
- onOpenChange: setOpen
1174
+ label,
1175
+ showFieldLabel,
1176
+ variant,
1177
+ icon: _icon,
1178
+ menuMinWidth: _menuMinWidth,
1179
+ menuHeader: _header,
1180
+ menuFooter: _footer
1181
+ });
1182
+ const seeds = selectedOption && !options.some((option) => option.value === selectedOption.value) ? [...options, selectedOption] : options;
1183
+ return /* @__PURE__ */ jsx(Combobox, {
1184
+ ...rest,
1185
+ label: showFieldLabel === false ? void 0 : label,
1186
+ "aria-label": showFieldLabel === false && typeof label === "string" ? label : void 0,
1187
+ placeholder: placeholder ?? searchPlaceholder,
1188
+ options: seeds.map(toOption),
1189
+ value: value || null,
1190
+ onChange: (next) => onChange(next ?? ""),
1191
+ disabled,
1192
+ loadOptions: onSearch ? loadOptions : void 0,
1193
+ minSearchLength,
1194
+ emptyMessage: emptySearchLabel,
1195
+ loadingMessage: loadingLabel
927
1196
  });
928
1197
  }
929
1198
  //#endregion
@@ -986,7 +1255,7 @@ function applyThemeAttributes(theme, themePrefix) {
986
1255
  themeValues.forEach((value) => root.classList.remove(`${themePrefix}${value}`));
987
1256
  root.classList.add(`${themePrefix}${theme}`);
988
1257
  }
989
- const ThemeProvider = ({ storageKey = "nb-theme", themePrefix = "nb-theme-", basePath = "/themes/", children }) => {
1258
+ const ThemeProvider = ({ storageKey = "nb-theme", themePrefix = "nb-theme-", basePath = "/themes/", visualStyle = "default", children }) => {
990
1259
  const getPersistedMode = () => {
991
1260
  const persisted = window.localStorage.getItem(storageKey);
992
1261
  return persisted && themeModes.includes(persisted) ? persisted : "auto";
@@ -995,6 +1264,15 @@ const ThemeProvider = ({ storageKey = "nb-theme", themePrefix = "nb-theme-", bas
995
1264
  const [systemTheme, setSystemTheme] = useState(getSystemTheme);
996
1265
  const [isLoaded, setIsLoaded] = useState(false);
997
1266
  const theme = useMemo(() => resolveTheme(mode, systemTheme), [mode, systemTheme]);
1267
+ useEffect(() => {
1268
+ const root = document.documentElement;
1269
+ const previous = root.getAttribute("data-visual-style");
1270
+ root.setAttribute("data-visual-style", visualStyle);
1271
+ return () => {
1272
+ if (previous === null) root.removeAttribute("data-visual-style");
1273
+ else root.setAttribute("data-visual-style", previous);
1274
+ };
1275
+ }, [visualStyle]);
998
1276
  useEffect(() => {
999
1277
  applyThemeAttributes(theme, themePrefix);
1000
1278
  setThemeToDOM(`${basePath}${themePrefix}${theme}.css`).then(() => setIsLoaded(true));
@@ -1150,21 +1428,22 @@ function useAccentColor() {
1150
1428
  //#endregion
1151
1429
  //#region packages/ui/SettingsPanel.tsx
1152
1430
  const SettingsPanel = ({ onClose: _onClose }) => {
1431
+ const strings = useUiStrings();
1153
1432
  const { density, toggleDensity } = useDensity();
1154
1433
  const { accent, changeAccent, presets } = useAccentColor();
1155
1434
  return /* @__PURE__ */ jsxs("div", {
1156
1435
  className: "nb-settings-panel",
1157
1436
  role: "menu",
1158
- "aria-label": "Display settings",
1437
+ "aria-label": strings.settingsMenu,
1159
1438
  children: [
1160
1439
  /* @__PURE__ */ jsx("p", {
1161
1440
  className: "nb-settings-panel__heading",
1162
- children: "Color de acento"
1441
+ children: strings.accentColor
1163
1442
  }),
1164
1443
  /* @__PURE__ */ jsx("div", {
1165
1444
  className: "nb-settings-panel__swatches",
1166
1445
  role: "group",
1167
- "aria-label": "Colores de acento",
1446
+ "aria-label": strings.accentColors,
1168
1447
  children: presets.map((preset) => /* @__PURE__ */ jsx("button", {
1169
1448
  className: "nb-settings-panel__swatch",
1170
1449
  type: "button",
@@ -1181,12 +1460,12 @@ const SettingsPanel = ({ onClose: _onClose }) => {
1181
1460
  /* @__PURE__ */ jsx("hr", { className: "nb-settings-panel__divider" }),
1182
1461
  /* @__PURE__ */ jsx("p", {
1183
1462
  className: "nb-settings-panel__heading",
1184
- children: "Densidad"
1463
+ children: strings.density
1185
1464
  }),
1186
1465
  /* @__PURE__ */ jsxs("div", {
1187
1466
  className: "nb-settings-panel__density",
1188
1467
  role: "group",
1189
- "aria-label": "Densidad de interfaz",
1468
+ "aria-label": strings.interfaceDensity,
1190
1469
  children: [/* @__PURE__ */ jsxs("button", {
1191
1470
  className: "nb-settings-panel__density-btn",
1192
1471
  type: "button",
@@ -1195,7 +1474,7 @@ const SettingsPanel = ({ onClose: _onClose }) => {
1195
1474
  children: [/* @__PURE__ */ jsx("i", {
1196
1475
  className: "ph ph-rows",
1197
1476
  "aria-hidden": "true"
1198
- }), "Normal"]
1477
+ }), strings.densityNormal]
1199
1478
  }), /* @__PURE__ */ jsxs("button", {
1200
1479
  className: "nb-settings-panel__density-btn",
1201
1480
  type: "button",
@@ -1204,7 +1483,7 @@ const SettingsPanel = ({ onClose: _onClose }) => {
1204
1483
  children: [/* @__PURE__ */ jsx("i", {
1205
1484
  className: "ph ph-rows-plus-bottom",
1206
1485
  "aria-hidden": "true"
1207
- }), "Compact"]
1486
+ }), strings.densityCompact]
1208
1487
  })]
1209
1488
  })
1210
1489
  ]
@@ -1213,22 +1492,25 @@ const SettingsPanel = ({ onClose: _onClose }) => {
1213
1492
  //#endregion
1214
1493
  //#region packages/ui/Badge.tsx
1215
1494
  const Badge = ({ variant = "primary", size = "md", outlined = false, pill = true, dot = false, children, className }) => {
1495
+ const classes = [
1496
+ "nb-badge",
1497
+ `nb-badge--${variant}`,
1498
+ size === "sm" && "nb-badge--sm",
1499
+ outlined && "nb-badge--outlined",
1500
+ pill && "nb-badge--pill",
1501
+ dot && "nb-badge--dot",
1502
+ className
1503
+ ].filter(Boolean).join(" ");
1216
1504
  return /* @__PURE__ */ jsx("span", {
1217
- className: [
1218
- "nb-badge",
1219
- `nb-badge--${variant}`,
1220
- size === "sm" && "nb-badge--sm",
1221
- outlined && "nb-badge--outlined",
1222
- pill && "nb-badge--pill",
1223
- dot && "nb-badge--dot",
1224
- className
1225
- ].filter(Boolean).join(" "),
1505
+ className: classes,
1226
1506
  children: dot ? null : children
1227
1507
  });
1228
1508
  };
1229
1509
  //#endregion
1230
1510
  //#region packages/ui/FeatureGate.tsx
1231
- function FeatureGate({ featureKey, children, enabled = false, behavior = "lock", planBadge = "Pro", upgradeMessage, upgradeUrl = "/settings", lockTooltip = "Esta función no está disponible en tu plan actual." }) {
1511
+ function FeatureGate({ featureKey, children, enabled = false, behavior = "lock", planBadge = "Pro", upgradeMessage, upgradeUrl = "/settings", lockTooltip }) {
1512
+ const strings = useUiStrings();
1513
+ const tooltip = lockTooltip ?? strings.featureUnavailable;
1232
1514
  if (enabled) return /* @__PURE__ */ jsx("div", {
1233
1515
  className: "feature-gate",
1234
1516
  children
@@ -1241,15 +1523,16 @@ function FeatureGate({ featureKey, children, enabled = false, behavior = "lock",
1241
1523
  });
1242
1524
  return /* @__PURE__ */ jsx("div", {
1243
1525
  className: "feature-gate--locked",
1244
- title: lockTooltip,
1245
- "aria-label": lockTooltip,
1526
+ title: tooltip,
1527
+ "aria-label": tooltip,
1246
1528
  role: "presentation",
1247
1529
  children
1248
1530
  });
1249
1531
  }
1250
1532
  function UpgradeGate({ planBadge, upgradeMessage, upgradeUrl, children }) {
1533
+ const strings = useUiStrings();
1251
1534
  const [open, setOpen] = useState(false);
1252
- const message = upgradeMessage ?? `Esta función requiere el plan ${planBadge}. Actualiza tu plan para desbloquearla.`;
1535
+ const message = upgradeMessage ?? strings.featureRequiresPlan.replace("{plan}", planBadge);
1253
1536
  return /* @__PURE__ */ jsxs("div", {
1254
1537
  className: "feature-gate--upgrade",
1255
1538
  onBlur: (e) => {
@@ -1285,13 +1568,13 @@ function UpgradeGate({ planBadge, upgradeMessage, upgradeUrl, children }) {
1285
1568
  children: [
1286
1569
  /* @__PURE__ */ jsx(IconButton, {
1287
1570
  icon: "ph ph-x",
1288
- label: "Cerrar",
1571
+ label: strings.close,
1289
1572
  onClick: () => setOpen(false)
1290
1573
  }),
1291
1574
  /* @__PURE__ */ jsx("p", { children: message }),
1292
1575
  /* @__PURE__ */ jsx("a", {
1293
1576
  href: upgradeUrl,
1294
- children: "Ver planes"
1577
+ children: strings.viewPlans
1295
1578
  })
1296
1579
  ]
1297
1580
  })
@@ -1332,22 +1615,23 @@ const DEFAULT_ICONS = {
1332
1615
  warning: "warning",
1333
1616
  success: "check-circle"
1334
1617
  };
1335
- const EmptyState = ({ icon, variant = "default", title, description, action, size = "md", fill = false, className }) => {
1618
+ const EmptyState = ({ icon, illustration, variant = "default", title, description, action, size = "md", fill = false, className }) => {
1336
1619
  const iconName = icon ?? DEFAULT_ICONS[variant];
1620
+ const classes = [
1621
+ "nb-empty-state",
1622
+ `nb-empty-state--${variant}`,
1623
+ `nb-empty-state--${size}`,
1624
+ fill && "nb-empty-state--fill",
1625
+ className
1626
+ ].filter(Boolean).join(" ");
1337
1627
  return /* @__PURE__ */ jsxs("div", {
1338
- className: [
1339
- "nb-empty-state",
1340
- `nb-empty-state--${variant}`,
1341
- `nb-empty-state--${size}`,
1342
- fill && "nb-empty-state--fill",
1343
- className
1344
- ].filter(Boolean).join(" "),
1628
+ className: classes,
1345
1629
  role: "status",
1346
1630
  "aria-live": "polite",
1347
1631
  children: [
1348
1632
  /* @__PURE__ */ jsx("div", {
1349
1633
  className: "nb-empty-state__icon-wrap",
1350
- children: /* @__PURE__ */ jsx("i", {
1634
+ children: illustration ?? /* @__PURE__ */ jsx("i", {
1351
1635
  className: `ph ph-${iconName}`,
1352
1636
  "aria-hidden": "true"
1353
1637
  })
@@ -1374,12 +1658,13 @@ const EmptyState = ({ icon, variant = "default", title, description, action, siz
1374
1658
  * Use for category filters, tag lists, and multi-select inputs.
1375
1659
  */
1376
1660
  const Chip = ({ label, active = false, count, icon, size = "md", disabled = false, onClick, className = "" }) => {
1661
+ const sizeClass = size !== "md" ? ` nb-chip--${size}` : "";
1377
1662
  return /* @__PURE__ */ jsxs("button", {
1378
1663
  type: "button",
1379
1664
  role: "checkbox",
1380
1665
  "aria-checked": active,
1381
1666
  disabled,
1382
- className: `nb-chip${size !== "md" ? ` nb-chip--${size}` : ""}${active ? " is-active" : ""}${className ? ` ${className}` : ""}`,
1667
+ className: `nb-chip${sizeClass}${active ? " is-active" : ""}${className ? ` ${className}` : ""}`,
1383
1668
  onClick,
1384
1669
  children: [
1385
1670
  icon && /* @__PURE__ */ jsx("i", {
@@ -1427,73 +1712,51 @@ const Toggle = ({ checked, onChange, label, size = "md", disabled = false, "aria
1427
1712
  };
1428
1713
  //#endregion
1429
1714
  //#region packages/ui/ContextMenu.tsx
1430
- const MENU_MIN_WIDTH = 190;
1431
- /**
1432
- * Three-dot overflow context menu.
1433
- * Replaces the legacy `shared/ui/library/card-menu/CardMenu` component.
1434
- *
1435
- * Features over CardMenu:
1436
- * - `danger` variant items
1437
- * - `separator` support
1438
- * - `icon` per item
1439
- * - Custom trigger slot
1440
- * - Left/right alignment
1441
- * - Click-outside + Escape to close
1442
- * - Portalled dropdown (avoids clip inside scrollable tables)
1443
- */
1444
1715
  const ContextMenu = ({ items, visible = true, trigger, triggerLabel = "Opciones", align = "right", className = "" }) => {
1445
- const { open, setOpen, toggle, containerRef, panelRef: menuRef, panelStyle: menuStyle } = useFloatingPanel({
1446
- dismissEvent: "mousedown",
1447
- closeOnViewportExit: true,
1448
- computeStyle: (container) => computeAnchoredStyle(container, {
1449
- align: align === "right" ? "end" : "start",
1450
- minWidth: MENU_MIN_WIDTH,
1451
- flipThreshold: 200,
1452
- zIndex: 1600
1453
- })
1454
- });
1716
+ const container = useOverlayContainer();
1717
+ const triggerRef = useRef(null);
1718
+ const restoreFocus = useRef(false);
1455
1719
  if (!visible) return null;
1456
- const dropdown = open ? /* @__PURE__ */ jsx("ul", {
1457
- ref: menuRef,
1458
- className: "nb-context-menu__dropdown nb-context-menu__dropdown--portaled",
1459
- role: "menu",
1460
- style: menuStyle,
1461
- children: items.map((item, idx) => /* @__PURE__ */ jsxs(React.Fragment, { children: [item.separator && /* @__PURE__ */ jsx("li", {
1462
- role: "none",
1463
- "aria-hidden": "true",
1464
- children: /* @__PURE__ */ jsx("div", { className: "nb-context-menu__separator" })
1465
- }), /* @__PURE__ */ jsx("li", {
1466
- role: "none",
1467
- children: /* @__PURE__ */ jsxs("button", {
1468
- type: "button",
1469
- role: "menuitem",
1470
- disabled: item.disabled,
1471
- "aria-disabled": item.disabled,
1472
- className: `nb-context-menu__item${item.danger ? " nb-context-menu__item--danger" : ""}`,
1473
- onClick: () => {
1474
- setOpen(false);
1475
- item.onClick?.();
1476
- },
1477
- children: [item.icon && /* @__PURE__ */ jsx("i", {
1478
- className: item.icon,
1479
- "aria-hidden": "true"
1480
- }), item.label]
1481
- })
1482
- })] }, idx))
1483
- }) : null;
1484
- return /* @__PURE__ */ jsxs("div", {
1485
- ref: containerRef,
1486
- className: `nb-context-menu${className ? ` ${className}` : ""}`,
1487
- children: [trigger ? /* @__PURE__ */ jsx("span", {
1488
- onClick: toggle,
1489
- children: trigger
1490
- }) : /* @__PURE__ */ jsx(IconButton, {
1491
- icon: "ph ph-dots-three",
1492
- label: triggerLabel,
1493
- "aria-haspopup": "menu",
1494
- "aria-expanded": open,
1495
- onClick: toggle
1496
- }), dropdown && createPortal(dropdown, document.body)]
1720
+ return /* @__PURE__ */ jsx(Menu.Root, {
1721
+ modal: false,
1722
+ onOpenChange: (open, details) => {
1723
+ restoreFocus.current = !open && (details.reason === "item-press" || details.reason === "escape-key");
1724
+ },
1725
+ onOpenChangeComplete: (open) => {
1726
+ if (!open && restoreFocus.current) triggerRef.current?.focus({ preventScroll: true });
1727
+ },
1728
+ children: /* @__PURE__ */ jsxs("div", {
1729
+ className: `nb-context-menu${className ? ` ${className}` : ""}`,
1730
+ children: [/* @__PURE__ */ jsx(Menu.Trigger, {
1731
+ ref: triggerRef,
1732
+ render: isValidElement(trigger) ? trigger : /* @__PURE__ */ jsx(IconButton, {
1733
+ icon: "ph ph-dots-three",
1734
+ label: triggerLabel,
1735
+ children: trigger
1736
+ })
1737
+ }), /* @__PURE__ */ jsx(Menu.Portal, {
1738
+ container: container ?? void 0,
1739
+ children: /* @__PURE__ */ jsx(Menu.Positioner, {
1740
+ align: align === "right" ? "end" : "start",
1741
+ sideOffset: 4,
1742
+ className: "nb-context-menu-positioner",
1743
+ children: /* @__PURE__ */ jsx(Menu.Popup, {
1744
+ finalFocus: triggerRef,
1745
+ className: "nb-context-menu__dropdown",
1746
+ children: items.map((item, index) => /* @__PURE__ */ jsxs(React.Fragment, { children: [item.separator && /* @__PURE__ */ jsx(Menu.Separator, { className: "nb-context-menu__separator" }), /* @__PURE__ */ jsxs(Menu.Item, {
1747
+ disabled: item.disabled,
1748
+ label: item.label,
1749
+ className: `nb-context-menu__item${item.danger ? " nb-context-menu__item--danger" : ""}`,
1750
+ onClick: item.onClick,
1751
+ children: [item.icon && /* @__PURE__ */ jsx("i", {
1752
+ className: item.icon,
1753
+ "aria-hidden": "true"
1754
+ }), item.label]
1755
+ })] }, index))
1756
+ })
1757
+ })
1758
+ })]
1759
+ })
1497
1760
  });
1498
1761
  };
1499
1762
  //#endregion
@@ -1818,6 +2081,7 @@ const CollapsibleSection = ({ label, icon, open, onToggle, children, trailing, c
1818
2081
  className: "nb-collapsible__header",
1819
2082
  children: [/* @__PURE__ */ jsxs("button", {
1820
2083
  type: "button",
2084
+ id: `${bodyId}-trigger`,
1821
2085
  className: "nb-collapsible__trigger",
1822
2086
  "aria-expanded": open,
1823
2087
  "aria-controls": bodyId,
@@ -1844,1122 +2108,699 @@ const CollapsibleSection = ({ label, icon, open, onToggle, children, trailing, c
1844
2108
  id: bodyId,
1845
2109
  className: ["nb-collapsible__body", bodyClassName].filter(Boolean).join(" "),
1846
2110
  role: "region",
1847
- "aria-labelledby": void 0,
2111
+ "aria-labelledby": `${bodyId}-trigger`,
1848
2112
  hidden: !open,
1849
2113
  children
1850
2114
  })]
1851
2115
  });
1852
2116
  };
1853
2117
  //#endregion
1854
- //#region packages/ui/DatePicker.tsx
1855
- const cx$1 = (...values) => values.filter(Boolean).join(" ");
1856
- const ISO_DATE_RE$1 = /^\d{4}-\d{2}-\d{2}$/;
1857
- const getLocale$1 = (override) => override || document.documentElement.lang || navigator.language || "en-US";
1858
- const pad$1 = (value) => String(value).padStart(2, "0");
1859
- const toIsoDate$1 = (date) => `${date.getFullYear()}-${pad$1(date.getMonth() + 1)}-${pad$1(date.getDate())}`;
1860
- const parseIsoDate$1 = (value) => {
1861
- if (!value || !ISO_DATE_RE$1.test(value)) return null;
1862
- const [year, month, day] = value.split("-").map(Number);
1863
- const date = new Date(year, month - 1, day);
1864
- if (date.getFullYear() !== year || date.getMonth() !== month - 1 || date.getDate() !== day) return null;
1865
- return date;
1866
- };
1867
- const startOfMonth$1 = (date) => new Date(date.getFullYear(), date.getMonth(), 1);
1868
- const addMonths$1 = (date, months) => new Date(date.getFullYear(), date.getMonth() + months, 1);
1869
- const formatDisplayDate$1 = (value, locale) => {
1870
- const date = parseIsoDate$1(value);
1871
- if (!date) return "";
1872
- return new Intl.DateTimeFormat(getLocale$1(locale), {
1873
- day: "2-digit",
1874
- month: "2-digit",
1875
- year: "numeric"
1876
- }).format(date);
1877
- };
1878
- const formatMonthLabel$1 = (date, locale) => new Intl.DateTimeFormat(getLocale$1(locale), {
1879
- month: "long",
1880
- year: "numeric"
1881
- }).format(date);
1882
- /**
1883
- * Locale-aware first day of week.
1884
- * Uses Intl.Locale.weekInfo (Chrome 99+, FF 126+, Safari 17+) with fallback heuristic.
1885
- */
1886
- const getFirstDayOfWeek = (locale) => {
1887
- try {
1888
- const info = new Intl.Locale(getLocale$1(locale)).weekInfo;
1889
- if (info && typeof info.firstDay === "number") return info.firstDay === 7 ? 0 : info.firstDay;
1890
- } catch {}
1891
- const country = (getLocale$1(locale).split("-")[1] ?? "").toUpperCase();
1892
- return [
1893
- "US",
1894
- "CA",
1895
- "MX",
1896
- "CN",
1897
- "JP",
1898
- "KR",
1899
- "SA",
1900
- "EG",
1901
- "IL",
1902
- "BR"
1903
- ].includes(country) ? 0 : 1;
1904
- };
1905
- const buildCalendarDays$1 = (month, min, max, locale) => {
1906
- const first = startOfMonth$1(month);
1907
- const firstDayOfWeek = getFirstDayOfWeek(locale);
1908
- const offset = (first.getDay() - firstDayOfWeek + 7) % 7;
1909
- const minDate = parseIsoDate$1(min);
1910
- const maxDate = parseIsoDate$1(max);
1911
- const start = new Date(first);
1912
- start.setDate(first.getDate() - offset);
1913
- return Array.from({ length: 42 }, (_, i) => {
1914
- const date = new Date(start);
1915
- date.setDate(start.getDate() + i);
1916
- return {
2118
+ //#region packages/ui/CalendarContent.tsx
2119
+ /** Shared presentation; React Aria owns navigation, focus and range preview. */
2120
+ function CalendarContent() {
2121
+ const strings = useUiStrings();
2122
+ return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsxs("header", {
2123
+ className: "nb-calendar__header",
2124
+ children: [
2125
+ /* @__PURE__ */ jsx(Button$1, {
2126
+ slot: "previous",
2127
+ className: "nb-date-picker__nav",
2128
+ "aria-label": strings.previousMonth,
2129
+ children: "‹"
2130
+ }),
2131
+ /* @__PURE__ */ jsxs("div", {
2132
+ className: "nb-calendar__selectors",
2133
+ children: [
2134
+ /* @__PURE__ */ jsx(Heading, { className: "nb-calendar__heading" }),
2135
+ /* @__PURE__ */ jsx(CalendarMonthPicker, { children: ({ items, value, onChange, ...props }) => /* @__PURE__ */ jsx("select", {
2136
+ ...props,
2137
+ value,
2138
+ onChange: (event) => onChange(Number(event.target.value)),
2139
+ children: items.map((item) => /* @__PURE__ */ jsx("option", {
2140
+ value: item.id,
2141
+ children: item.formatted
2142
+ }, item.id))
2143
+ }) }),
2144
+ /* @__PURE__ */ jsx(CalendarYearPicker, { children: ({ items, value, onChange, ...props }) => /* @__PURE__ */ jsx("select", {
2145
+ ...props,
2146
+ value,
2147
+ onChange: (event) => onChange(Number(event.target.value)),
2148
+ children: items.map((item) => /* @__PURE__ */ jsx("option", {
2149
+ value: item.id,
2150
+ children: item.formatted
2151
+ }, item.id))
2152
+ }) })
2153
+ ]
2154
+ }),
2155
+ /* @__PURE__ */ jsx(Button$1, {
2156
+ slot: "next",
2157
+ className: "nb-date-picker__nav",
2158
+ "aria-label": strings.nextMonth,
2159
+ children: "›"
2160
+ })
2161
+ ]
2162
+ }), /* @__PURE__ */ jsxs(CalendarGrid, {
2163
+ className: "nb-calendar__grid",
2164
+ children: [/* @__PURE__ */ jsx(CalendarGridHeader, { children: (day) => /* @__PURE__ */ jsx(CalendarHeaderCell, {
2165
+ className: "nb-calendar__weekday",
2166
+ children: day
2167
+ }) }), /* @__PURE__ */ jsx(CalendarGridBody, { children: (date) => /* @__PURE__ */ jsx(CalendarCell, {
1917
2168
  date,
1918
- iso: toIsoDate$1(date),
1919
- inCurrentMonth: date.getMonth() === month.getMonth(),
1920
- disabled: Boolean(minDate && date < minDate || maxDate && date > maxDate)
1921
- };
1922
- });
1923
- };
1924
- const isIsoDateDisabled = (iso, min, max) => {
1925
- const date = parseIsoDate$1(iso);
1926
- if (!date) return true;
1927
- const minDate = parseIsoDate$1(min);
1928
- const maxDate = parseIsoDate$1(max);
1929
- return Boolean(minDate && date < minDate || maxDate && date > maxDate);
1930
- };
1931
- const weekDayLabels = (locale) => {
1932
- const firstDayOfWeek = getFirstDayOfWeek(locale);
1933
- const anchor = new Date(2026, 5, 7);
1934
- const formatter = new Intl.DateTimeFormat(getLocale$1(locale), { weekday: "narrow" });
1935
- return Array.from({ length: 7 }, (_, i) => {
1936
- const date = new Date(anchor);
1937
- date.setDate(anchor.getDate() + (firstDayOfWeek + i) % 7);
1938
- return formatter.format(date);
2169
+ className: "nb-calendar__day"
2170
+ }) })]
2171
+ })] });
2172
+ }
2173
+ /** A parent modal owns containment; a standalone picker needs its own focus scope. */
2174
+ function CalendarDialog({ id, ariaLabel, children }) {
2175
+ return useOverlayContainer() ? /* @__PURE__ */ jsx("section", {
2176
+ id,
2177
+ "aria-label": ariaLabel,
2178
+ role: "dialog",
2179
+ tabIndex: -1,
2180
+ children
2181
+ }) : /* @__PURE__ */ jsx(Dialog$1, {
2182
+ id,
2183
+ "aria-label": ariaLabel,
2184
+ children
1939
2185
  });
2186
+ }
2187
+ //#endregion
2188
+ //#region packages/ui/dateValues.ts
2189
+ const getDateLocale = (locale) => locale || typeof document !== "undefined" && document.documentElement.lang || typeof navigator !== "undefined" && navigator.language || "en-US";
2190
+ const calendarDate = (value) => {
2191
+ if (!value || !/^\d{4}-\d{2}-\d{2}$/.test(value)) return null;
2192
+ try {
2193
+ return parseDate(value);
2194
+ } catch {
2195
+ return null;
2196
+ }
1940
2197
  };
1941
- /** Short month labels (Jan, Feb, …) — capitalized for display. */
1942
- const getMonthLabels = (locale) => {
1943
- const formatter = new Intl.DateTimeFormat(getLocale$1(locale), { month: "short" });
1944
- return Array.from({ length: 12 }, (_, i) => {
1945
- const label = formatter.format(new Date(2024, i, 1));
1946
- return label.charAt(0).toUpperCase() + label.slice(1).replace(".", "");
1947
- });
2198
+ const formatDate = (value, locale) => {
2199
+ const date = calendarDate(value);
2200
+ return date ? new Intl.DateTimeFormat(locale, {
2201
+ day: "2-digit",
2202
+ month: "2-digit",
2203
+ year: "numeric",
2204
+ timeZone: "UTC"
2205
+ }).format(date.toDate("UTC")) : "";
1948
2206
  };
1949
- /** Year range: 12-year block containing the given year. */
1950
- const getYearRangeStart = (year) => Math.floor(year / 12) * 12;
1951
- /**
1952
- * Applies dd/mm/yyyy mask.
1953
- * Auto-inserts trailing slash when adding the 2nd or 4th digit.
1954
- * Does NOT add trailing slash when the user is deleting.
1955
- */
1956
- const applyDateMask = (rawValue, prevValue) => {
2207
+ const dateAllowed = (value, min, max) => Boolean(calendarDate(value)) && (!min || value >= min) && (!max || value <= max);
2208
+ const dateOrder = (locale) => new Intl.DateTimeFormat(getDateLocale(locale), {
2209
+ day: "2-digit",
2210
+ month: "2-digit",
2211
+ year: "numeric",
2212
+ timeZone: "UTC"
2213
+ }).formatToParts(new Date(Date.UTC(2026, 10, 23))).filter((part) => [
2214
+ "day",
2215
+ "month",
2216
+ "year"
2217
+ ].includes(part.type)).map((part) => part.type);
2218
+ const datePlaceholder = (locale) => dateOrder(locale).map((part) => part === "year" ? "yyyy" : part === "month" ? "mm" : "dd").join("/");
2219
+ const applyDateMask = (rawValue, prevValue, locale) => {
2220
+ if (/^\d{4}-\d{2}-\d{2}$/.test(rawValue)) return rawValue;
1957
2221
  const digits = rawValue.replace(/\D/g, "").slice(0, 8);
1958
- const prevDigits = prevValue.replace(/\D/g, "");
1959
- const isAdding = digits.length > prevDigits.length;
1960
- if (digits.length === 0) return "";
1961
- let result = digits.slice(0, 2);
1962
- if (digits.length > 2) result += "/" + digits.slice(2, 4);
1963
- if (digits.length > 4) result += "/" + digits.slice(4, 8);
1964
- if (isAdding && (digits.length === 2 || digits.length === 4)) result += "/";
2222
+ const adding = digits.length > prevValue.replace(/\D/g, "").length;
2223
+ const sizes = dateOrder(locale ?? "es-PE").map((part) => part === "year" ? 4 : 2);
2224
+ let offset = 0;
2225
+ let result = "";
2226
+ for (const [i, size] of sizes.entries()) {
2227
+ result += digits.slice(offset, offset + size);
2228
+ offset += size;
2229
+ if (i < 2 && (digits.length > offset || adding && digits.length === offset)) result += "/";
2230
+ }
1965
2231
  return result;
1966
2232
  };
1967
- /**
1968
- * Parses dd/mm/yyyy or ISO yyyy-mm-dd to ISO string.
1969
- * Returns null if not a valid date.
1970
- */
1971
2233
  const parseDisplayDate = (text, locale) => {
1972
- const match = text.match(/^(\d{1,2})[/-](\d{1,2})[/-](\d{4})$/);
1973
- if (match) {
1974
- const [, a, b, year] = match;
1975
- const [dd, mm] = (getLocale$1(locale).split("-")[1] ?? "").toUpperCase() === "US" ? [b, a] : [a, b];
1976
- const iso = `${year}-${mm.padStart(2, "0")}-${dd.padStart(2, "0")}`;
1977
- return parseIsoDate$1(iso) ? iso : null;
1978
- }
1979
- if (ISO_DATE_RE$1.test(text)) return parseIsoDate$1(text) ? text : null;
1980
- return null;
2234
+ if (calendarDate(text)) return text;
2235
+ const order = dateOrder(locale);
2236
+ const digits = text.match(/\d+/g);
2237
+ if (!digits || digits.length !== 3) return null;
2238
+ const fields = Object.fromEntries(order.map((key, i) => [key, digits[i]]));
2239
+ if (fields.year?.length !== 4) return null;
2240
+ const iso = `${fields.year}-${fields.month?.padStart(2, "0")}-${fields.day?.padStart(2, "0")}`;
2241
+ return calendarDate(iso) ? iso : null;
1981
2242
  };
1982
- const DatePicker = 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) {
1983
- const generatedId = useId();
1984
- const inputId = id ?? generatedId;
1985
- const panelId = `${inputId}-panel`;
1986
- const strings = useUiStrings();
1987
- const selectedDate = parseIsoDate$1(value);
1988
- const resolvedLocale = getLocale$1(locale);
1989
- const displayValue = formatDisplayDate$1(value, resolvedLocale);
1990
- const [viewMode, setViewMode] = useState("days");
1991
- const [month, setMonth] = useState(() => startOfMonth$1(selectedDate ?? /* @__PURE__ */ new Date()));
1992
- const [yearRangeStart, setYearRangeStart] = useState(() => getYearRangeStart((/* @__PURE__ */ new Date()).getFullYear()));
1993
- const [focusedIso, setFocusedIso] = useState(null);
1994
- const [inputText, setInputText] = useState("");
1995
- const [isEditing, setIsEditing] = useState(false);
1996
- const inputRef = useRef(null);
1997
- const triggerRef = useRef(null);
1998
- const { open, setOpen, containerRef: rootRef, panelRef, panelStyle } = useFloatingPanel({
1999
- onClose: () => {
2000
- setFocusedIso(null);
2001
- setViewMode("days");
2002
- },
2003
- onEscape: (e) => {
2004
- e.preventDefault();
2005
- inputRef.current?.focus();
2243
+ //#endregion
2244
+ //#region packages/ui/DateTextInput.tsx
2245
+ /** Keeps the real input/ref/ID contract used by CRUD forms. */
2246
+ const DateTextInput = forwardRef(function DateTextInput({ value, locale, min, max, onChange, onOpen, onBlur, onKeyDown, ...props }, ref) {
2247
+ const [draft, setDraft] = useState(null);
2248
+ const commit = () => {
2249
+ if (draft === null) return;
2250
+ const iso = parseDisplayDate(draft.trim(), locale);
2251
+ if (!draft.trim()) onChange("");
2252
+ else if (iso && dateAllowed(iso, min, max)) onChange(iso);
2253
+ setDraft(null);
2254
+ };
2255
+ return /* @__PURE__ */ jsx("input", {
2256
+ ...props,
2257
+ ref,
2258
+ type: "text",
2259
+ inputMode: "numeric",
2260
+ onPointerDown: (event) => event.stopPropagation(),
2261
+ onPointerUp: (event) => event.stopPropagation(),
2262
+ onMouseDown: (event) => event.stopPropagation(),
2263
+ onClick: (event) => event.stopPropagation(),
2264
+ value: draft ?? formatDate(value, locale),
2265
+ onChange: (event) => setDraft(applyDateMask(event.target.value, draft ?? "", locale)),
2266
+ onBlur: (event) => {
2267
+ commit();
2268
+ onBlur?.(event);
2006
2269
  },
2007
- computeStyle: () => {
2008
- const rect = triggerRef.current?.getBoundingClientRect();
2009
- if (!rect) return null;
2010
- const panelWidth = panelRef.current?.offsetWidth ?? 296;
2011
- const left = Math.min(Math.max(8, rect.left), window.innerWidth - panelWidth - 8);
2012
- const top = Math.min(rect.bottom + 6, window.innerHeight - 380);
2013
- return {
2014
- left,
2015
- top: Math.max(8, top)
2016
- };
2270
+ onKeyDown: (event) => {
2271
+ if (event.key !== "Escape") event.stopPropagation();
2272
+ onKeyDown?.(event);
2273
+ if (event.defaultPrevented) return;
2274
+ if (event.key === "Enter") {
2275
+ event.preventDefault();
2276
+ commit();
2277
+ }
2278
+ if (event.key === "Escape") setDraft(null);
2279
+ if (event.key === "ArrowDown" && !props.disabled && !props.readOnly) {
2280
+ event.preventDefault();
2281
+ commit();
2282
+ onOpen();
2283
+ }
2017
2284
  }
2018
2285
  });
2019
- const days = useMemo(() => buildCalendarDays$1(month, min, max, resolvedLocale), [
2020
- max,
2021
- min,
2022
- month,
2023
- resolvedLocale
2024
- ]);
2025
- const weekdayLabels = useMemo(() => weekDayLabels(resolvedLocale), [resolvedLocale]);
2026
- const monthLabels = useMemo(() => getMonthLabels(resolvedLocale), [resolvedLocale]);
2027
- const selectedIso = selectedDate ? toIsoDate$1(selectedDate) : "";
2028
- useEffect(() => {
2029
- if (selectedDate) setMonth(startOfMonth$1(selectedDate));
2030
- }, [value]);
2286
+ });
2287
+ //#endregion
2288
+ //#region packages/ui/useCalendarPopover.ts
2289
+ /** Bridge focus restoration between React Aria's popup and a parent Base UI modal. */
2290
+ function useCalendarPopover() {
2291
+ const container = useOverlayContainer();
2292
+ const groupRef = useRef(null);
2293
+ const panelRef = useRef(null);
2294
+ const frame = useRef(null);
2295
+ const outsideTarget = useRef(null);
2296
+ const [open, updateOpen] = useState(false);
2031
2297
  useEffect(() => {
2032
- if (!open) return;
2033
- const initialIso = selectedDate ? toIsoDate$1(selectedDate) : toIsoDate$1(/* @__PURE__ */ new Date());
2034
- setFocusedIso(initialIso);
2035
- window.setTimeout(() => {
2036
- panelRef.current?.querySelector(`[data-iso="${initialIso}"]`)?.focus();
2037
- }, 0);
2038
- }, [open]);
2039
- const commitValue = useCallback((nextValue) => {
2040
- onChange?.(nextValue);
2041
- setOpen(false);
2042
- setIsEditing(false);
2043
- setInputText("");
2044
- window.setTimeout(() => inputRef.current?.focus());
2045
- }, [onChange, setOpen]);
2046
- const handleToday = useCallback(() => {
2047
- const today = toIsoDate$1(/* @__PURE__ */ new Date());
2048
- if (isIsoDateDisabled(today, min, max)) return;
2049
- setMonth(startOfMonth$1(parseIsoDate$1(today)));
2050
- commitValue(today);
2051
- }, [
2052
- min,
2053
- max,
2054
- commitValue
2055
- ]);
2056
- const handleClear = useCallback((e) => {
2057
- e.preventDefault();
2058
- commitValue("");
2059
- }, [commitValue]);
2060
- const handleInputFocus = () => {
2061
- setIsEditing(true);
2062
- setInputText(displayValue);
2063
- window.setTimeout(() => inputRef.current?.select(), 0);
2064
- };
2065
- const handleInputChange = (e) => {
2066
- if (readOnly || disabled) return;
2067
- setInputText(applyDateMask(e.target.value, inputText));
2068
- };
2069
- const handleInputBlur = (e) => {
2070
- const related = e.relatedTarget;
2071
- if (rootRef.current?.contains(related) || panelRef.current?.contains(related)) return;
2072
- setIsEditing(false);
2073
- const parsed = parseDisplayDate(inputText, resolvedLocale);
2074
- if (parsed !== null) {
2075
- if (parsed !== value) onChange?.(parsed);
2076
- } else if (inputText === "" && value) onChange?.("");
2077
- setInputText("");
2078
- onBlur?.(e);
2079
- };
2080
- const handleInputKeyDown = (e) => {
2081
- if (e.key === "Enter") {
2082
- e.preventDefault();
2083
- const parsed = parseDisplayDate(inputText, resolvedLocale);
2084
- if (parsed !== null) commitValue(parsed);
2085
- else if (inputText === "") commitValue("");
2086
- } else if (e.key === "ArrowDown" || e.key === "F4") {
2087
- e.preventDefault();
2088
- if (!readOnly && !disabled) setOpen(true);
2089
- } else if (e.key === "Escape" && open) setOpen(false);
2090
- };
2091
- const handleCalendarPointerDown = (e) => {
2092
- e.preventDefault();
2093
- if (readOnly || disabled) return;
2094
- setOpen(!open);
2095
- };
2096
- const handleDayKeyDown = useCallback((e, iso) => {
2097
- if (![
2098
- "ArrowLeft",
2099
- "ArrowRight",
2100
- "ArrowUp",
2101
- "ArrowDown",
2102
- "Enter",
2103
- " "
2104
- ].includes(e.key)) return;
2105
- e.preventDefault();
2106
- if (e.key === "Enter" || e.key === " ") {
2107
- const day = days.find((d) => d.iso === iso);
2108
- if (day && !day.disabled) commitValue(iso);
2109
- return;
2110
- }
2111
- const delta = {
2112
- ArrowLeft: -1,
2113
- ArrowRight: 1,
2114
- ArrowUp: -7,
2115
- ArrowDown: 7
2116
- }[e.key] ?? 0;
2117
- const current = parseIsoDate$1(iso);
2118
- if (!current) return;
2119
- const next = new Date(current);
2120
- next.setDate(current.getDate() + delta);
2121
- const nextIso = toIsoDate$1(next);
2122
- if (next.getMonth() !== month.getMonth() || next.getFullYear() !== month.getFullYear()) setMonth(startOfMonth$1(next));
2123
- setFocusedIso(nextIso);
2124
- window.setTimeout(() => {
2125
- panelRef.current?.querySelector(`[data-iso="${nextIso}"]`)?.focus();
2126
- }, 0);
2127
- }, [
2128
- days,
2129
- month,
2130
- commitValue,
2131
- panelRef
2132
- ]);
2133
- const handleMonthSelect = (monthIndex) => {
2134
- setMonth(new Date(month.getFullYear(), monthIndex, 1));
2135
- setViewMode("days");
2136
- };
2137
- const handleYearSelect = (year) => {
2138
- setMonth(new Date(year, month.getMonth(), 1));
2139
- setViewMode("months");
2140
- };
2141
- const setInputRef = (node) => {
2142
- inputRef.current = node;
2143
- if (typeof ref === "function") ref(node);
2144
- else if (ref) ref.current = node;
2298
+ if (!open || !container) return;
2299
+ const rememberTarget = (event) => {
2300
+ 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\"])");
2301
+ };
2302
+ document.addEventListener("pointerdown", rememberTarget, true);
2303
+ return () => document.removeEventListener("pointerdown", rememberTarget, true);
2304
+ }, [open, container]);
2305
+ useEffect(() => () => {
2306
+ if (frame.current !== null) cancelAnimationFrame(frame.current);
2307
+ }, []);
2308
+ return {
2309
+ container,
2310
+ groupRef,
2311
+ panelRef,
2312
+ open,
2313
+ setOpen: useCallback((next) => {
2314
+ if (frame.current !== null) cancelAnimationFrame(frame.current);
2315
+ if (next) outsideTarget.current = null;
2316
+ const active = document.activeElement;
2317
+ const target = outsideTarget.current ?? groupRef.current?.querySelector("input");
2318
+ const restore = !next && container && (outsideTarget.current || panelRef.current?.contains(active));
2319
+ updateOpen(next);
2320
+ if (restore) frame.current = requestAnimationFrame(() => {
2321
+ frame.current = requestAnimationFrame(() => {
2322
+ frame.current = null;
2323
+ if (document.activeElement === active || document.activeElement === container || document.activeElement === document.body) target?.focus();
2324
+ });
2325
+ });
2326
+ }, [container])
2145
2327
  };
2146
- const todayIso = toIsoDate$1(/* @__PURE__ */ new Date());
2147
- return /* @__PURE__ */ jsxs("div", {
2148
- ref: rootRef,
2149
- className: cx$1("nb-date-picker", className),
2150
- children: [
2151
- /* @__PURE__ */ jsx("input", {
2152
- type: "hidden",
2153
- name,
2154
- value: value ?? "",
2155
- required
2156
- }),
2157
- /* @__PURE__ */ jsxs("div", {
2158
- ref: triggerRef,
2159
- 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"),
2160
- children: [/* @__PURE__ */ jsx("input", {
2161
- ref: setInputRef,
2162
- id: inputId,
2163
- type: "text",
2164
- inputMode: "numeric",
2165
- className: cx$1("nb-date-picker__input", !isEditing && !displayValue && "nb-date-picker__input--placeholder"),
2166
- value: isEditing ? inputText : displayValue,
2167
- placeholder,
2168
- disabled,
2169
- readOnly,
2170
- "aria-label": ariaLabel,
2171
- role: "combobox",
2172
- "aria-haspopup": "dialog",
2173
- "aria-expanded": open,
2174
- "aria-controls": open ? panelId : void 0,
2175
- "aria-invalid": invalid || void 0,
2176
- "aria-required": required || void 0,
2177
- autoComplete: "off",
2178
- onFocus: handleInputFocus,
2179
- onBlur: handleInputBlur,
2180
- onChange: handleInputChange,
2181
- onKeyDown: handleInputKeyDown
2182
- }), /* @__PURE__ */ jsxs("span", {
2183
- className: "nb-date-picker__icons",
2184
- children: [clearable && displayValue && !disabled && !readOnly && /* @__PURE__ */ jsx("span", {
2185
- role: "button",
2186
- tabIndex: -1,
2187
- className: "nb-date-picker__clear",
2188
- "aria-label": strings.clearDate,
2189
- onPointerDown: handleClear,
2190
- children: /* @__PURE__ */ jsx("i", {
2191
- className: "ph ph-x",
2192
- "aria-hidden": "true"
2193
- })
2194
- }), /* @__PURE__ */ jsx("span", {
2195
- role: "button",
2196
- tabIndex: -1,
2197
- className: "nb-date-picker__calendar-btn",
2198
- "aria-label": strings.openCalendar,
2199
- onPointerDown: handleCalendarPointerDown,
2200
- children: /* @__PURE__ */ jsx("i", {
2201
- className: "ph ph-calendar-blank",
2202
- "aria-hidden": "true"
2203
- })
2204
- })]
2205
- })]
2206
- }),
2207
- open && createPortal(/* @__PURE__ */ jsxs("div", {
2208
- ref: panelRef,
2209
- id: panelId,
2210
- className: "nb-date-picker__panel",
2211
- role: "dialog",
2212
- "aria-label": strings.selectDate,
2213
- style: panelStyle,
2214
- children: [
2215
- viewMode === "days" && /* @__PURE__ */ jsxs(Fragment, { children: [
2216
- /* @__PURE__ */ jsxs("div", {
2217
- className: "nb-date-picker__header",
2218
- children: [
2219
- /* @__PURE__ */ jsx("button", {
2220
- type: "button",
2221
- className: "nb-date-picker__nav",
2222
- "aria-label": strings.previousMonth,
2223
- onClick: () => setMonth((m) => addMonths$1(m, -1)),
2224
- children: /* @__PURE__ */ jsx("i", {
2225
- className: "ph ph-caret-left",
2226
- "aria-hidden": "true"
2227
- })
2228
- }),
2229
- /* @__PURE__ */ jsxs("button", {
2230
- type: "button",
2231
- className: "nb-date-picker__month nb-date-picker__month--clickable",
2232
- "aria-label": strings.selectMonthAndYear,
2233
- onClick: () => setViewMode("months"),
2234
- children: [formatMonthLabel$1(month, resolvedLocale), /* @__PURE__ */ jsx("i", {
2235
- className: "ph ph-caret-down nb-date-picker__month-caret",
2236
- "aria-hidden": "true"
2237
- })]
2238
- }),
2239
- /* @__PURE__ */ jsx("button", {
2240
- type: "button",
2241
- className: "nb-date-picker__nav",
2242
- "aria-label": strings.nextMonth,
2243
- onClick: () => setMonth((m) => addMonths$1(m, 1)),
2244
- children: /* @__PURE__ */ jsx("i", {
2245
- className: "ph ph-caret-right",
2246
- "aria-hidden": "true"
2247
- })
2248
- })
2249
- ]
2250
- }),
2251
- /* @__PURE__ */ jsx("div", {
2252
- className: "nb-date-picker__weekdays",
2253
- "aria-hidden": "true",
2254
- children: weekdayLabels.map((label, i) => /* @__PURE__ */ jsx("span", { children: label }, `${label}-${i}`))
2328
+ }
2329
+ //#endregion
2330
+ //#region packages/ui/DatePicker.tsx
2331
+ const DatePicker = 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) {
2332
+ const generatedId = useId();
2333
+ const inputId = id ?? generatedId;
2334
+ const { container, groupRef, panelRef, open, setOpen } = useCalendarPopover();
2335
+ const strings = useUiStrings();
2336
+ const resolvedLocale = getDateLocale(locale);
2337
+ const change = (next) => onChange?.(next);
2338
+ const todayIso = today(getLocalTimeZone()).toString();
2339
+ const prefix = "nb-date-picker";
2340
+ return /* @__PURE__ */ jsx(I18nProvider, {
2341
+ locale: resolvedLocale,
2342
+ children: /* @__PURE__ */ jsxs(DatePicker$1, {
2343
+ "aria-label": ariaLabel ?? strings.selectDate,
2344
+ value: calendarDate(value),
2345
+ onChange: (date) => change(date?.toString() ?? ""),
2346
+ minValue: calendarDate(min) ?? void 0,
2347
+ maxValue: calendarDate(max) ?? void 0,
2348
+ isDisabled: disabled,
2349
+ isReadOnly: readOnly,
2350
+ isRequired: required,
2351
+ isInvalid: invalid,
2352
+ validationBehavior: "aria",
2353
+ isOpen: open,
2354
+ onOpenChange: setOpen,
2355
+ className: [prefix, className].filter(Boolean).join(" "),
2356
+ children: [
2357
+ /* @__PURE__ */ jsx("input", {
2358
+ type: "hidden",
2359
+ name,
2360
+ value: value ?? "",
2361
+ disabled
2362
+ }),
2363
+ /* @__PURE__ */ jsxs(Group, {
2364
+ ref: groupRef,
2365
+ className: [
2366
+ `${prefix}__trigger`,
2367
+ disabled && `${prefix}__trigger--disabled`,
2368
+ readOnly && `${prefix}__trigger--readonly`,
2369
+ invalid && `${prefix}__trigger--invalid`,
2370
+ open && `${prefix}__trigger--open`
2371
+ ].filter(Boolean).join(" "),
2372
+ children: [
2373
+ /* @__PURE__ */ jsx(DateTextInput, {
2374
+ ref,
2375
+ id: inputId,
2376
+ value,
2377
+ locale: resolvedLocale,
2378
+ min,
2379
+ max,
2380
+ placeholder: placeholder ?? datePlaceholder(resolvedLocale),
2381
+ disabled,
2382
+ readOnly,
2383
+ required,
2384
+ "aria-label": ariaLabel ?? (id ? void 0 : strings.selectDate),
2385
+ "aria-invalid": invalid || void 0,
2386
+ role: "combobox",
2387
+ "aria-haspopup": "dialog",
2388
+ "aria-expanded": open,
2389
+ "aria-controls": open ? `${inputId}-panel` : void 0,
2390
+ className: `${prefix}__input`,
2391
+ onChange: change,
2392
+ onOpen: () => setOpen(true),
2393
+ onBlur,
2394
+ onKeyDown: (event) => {
2395
+ if (event.key === "Escape" && open) {
2396
+ event.stopPropagation();
2397
+ setOpen(false);
2398
+ }
2399
+ }
2255
2400
  }),
2256
- /* @__PURE__ */ jsx("div", {
2257
- className: "nb-date-picker__days",
2258
- role: "grid",
2259
- "aria-label": formatMonthLabel$1(month, resolvedLocale),
2260
- children: days.map((day) => /* @__PURE__ */ jsx("button", {
2261
- "data-iso": day.iso,
2262
- type: "button",
2263
- 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"),
2264
- disabled: day.disabled,
2265
- role: "gridcell",
2266
- "aria-selected": day.iso === selectedIso,
2267
- tabIndex: day.iso === (focusedIso ?? selectedIso ?? todayIso) ? 0 : -1,
2268
- onClick: () => commitValue(day.iso),
2269
- onKeyDown: (e) => handleDayKeyDown(e, day.iso),
2270
- children: day.date.getDate()
2271
- }, day.iso))
2401
+ clearable && value && !disabled && !readOnly && /* @__PURE__ */ jsx(Button$1, {
2402
+ slot: null,
2403
+ className: `${prefix}__clear`,
2404
+ "aria-label": strings.clearDate,
2405
+ onPress: () => change(""),
2406
+ children: "×"
2272
2407
  }),
2273
- /* @__PURE__ */ jsxs("div", {
2274
- className: "nb-date-picker__footer",
2275
- children: [/* @__PURE__ */ jsx("button", {
2276
- type: "button",
2277
- className: "nb-date-picker__text-button",
2278
- onClick: () => commitValue(""),
2408
+ /* @__PURE__ */ jsx(Button$1, {
2409
+ className: `${prefix}__calendar-btn`,
2410
+ "aria-label": strings.openCalendar,
2411
+ onPress: () => groupRef.current?.querySelector("input")?.focus(),
2412
+ isDisabled: disabled || readOnly,
2413
+ children: /* @__PURE__ */ jsx("i", {
2414
+ "aria-hidden": "true",
2415
+ className: "ph ph-calendar-blank"
2416
+ })
2417
+ })
2418
+ ]
2419
+ }),
2420
+ /* @__PURE__ */ jsx(Popover$1, {
2421
+ isNonModal: Boolean(container),
2422
+ ref: panelRef,
2423
+ UNSTABLE_portalContainer: container ?? void 0,
2424
+ className: `${prefix}__panel`,
2425
+ offset: 4,
2426
+ children: /* @__PURE__ */ jsxs(CalendarDialog, {
2427
+ id: `${inputId}-panel`,
2428
+ ariaLabel: strings.selectDate,
2429
+ children: [/* @__PURE__ */ jsx(Calendar, { children: /* @__PURE__ */ jsx(CalendarContent, {}) }), /* @__PURE__ */ jsxs("div", {
2430
+ className: `${prefix}__footer`,
2431
+ children: [/* @__PURE__ */ jsx(Button$1, {
2432
+ slot: null,
2433
+ className: `${prefix}__text-button`,
2434
+ onPress: () => {
2435
+ change("");
2436
+ setOpen(false);
2437
+ },
2279
2438
  children: strings.clear
2280
- }), /* @__PURE__ */ jsx("button", {
2281
- type: "button",
2282
- className: "nb-date-picker__text-button",
2283
- onClick: handleToday,
2439
+ }), /* @__PURE__ */ jsx(Button$1, {
2440
+ slot: null,
2441
+ className: `${prefix}__text-button`,
2442
+ isDisabled: !dateAllowed(todayIso, min, max),
2443
+ onPress: () => {
2444
+ change(todayIso);
2445
+ setOpen(false);
2446
+ },
2284
2447
  children: strings.today
2285
2448
  })]
2286
- })
2287
- ] }),
2288
- viewMode === "months" && /* @__PURE__ */ jsxs(Fragment, { children: [
2289
- /* @__PURE__ */ jsxs("div", {
2290
- className: "nb-date-picker__header",
2291
- children: [
2292
- /* @__PURE__ */ jsx("button", {
2293
- type: "button",
2294
- className: "nb-date-picker__nav",
2295
- "aria-label": strings.previousYear,
2296
- onClick: () => setMonth((m) => new Date(m.getFullYear() - 1, m.getMonth(), 1)),
2297
- children: /* @__PURE__ */ jsx("i", {
2298
- className: "ph ph-caret-left",
2299
- "aria-hidden": "true"
2300
- })
2301
- }),
2302
- /* @__PURE__ */ jsxs("button", {
2303
- type: "button",
2304
- className: "nb-date-picker__month nb-date-picker__month--clickable",
2305
- "aria-label": strings.selectYear,
2306
- onClick: () => {
2307
- setYearRangeStart(getYearRangeStart(month.getFullYear()));
2308
- setViewMode("years");
2309
- },
2310
- children: [month.getFullYear(), /* @__PURE__ */ jsx("i", {
2311
- className: "ph ph-caret-down nb-date-picker__month-caret",
2312
- "aria-hidden": "true"
2313
- })]
2314
- }),
2315
- /* @__PURE__ */ jsx("button", {
2316
- type: "button",
2317
- className: "nb-date-picker__nav",
2318
- "aria-label": strings.nextYear,
2319
- onClick: () => setMonth((m) => new Date(m.getFullYear() + 1, m.getMonth(), 1)),
2320
- children: /* @__PURE__ */ jsx("i", {
2321
- className: "ph ph-caret-right",
2322
- "aria-hidden": "true"
2323
- })
2324
- })
2325
- ]
2326
- }),
2327
- /* @__PURE__ */ jsx("div", {
2328
- className: "nb-date-picker__months-grid",
2329
- role: "grid",
2330
- "aria-label": `${month.getFullYear()}`,
2331
- children: monthLabels.map((label, i) => {
2332
- const isSelected = selectedDate ? selectedDate.getMonth() === i && selectedDate.getFullYear() === month.getFullYear() : false;
2333
- const isCurrent = (/* @__PURE__ */ new Date()).getMonth() === i && (/* @__PURE__ */ new Date()).getFullYear() === month.getFullYear();
2334
- return /* @__PURE__ */ jsx("button", {
2335
- type: "button",
2336
- className: cx$1("nb-date-picker__month-cell", isSelected && "nb-date-picker__month-cell--selected", isCurrent && "nb-date-picker__month-cell--current"),
2337
- role: "gridcell",
2338
- "aria-selected": isSelected,
2339
- onClick: () => handleMonthSelect(i),
2340
- children: label
2341
- }, i);
2342
- })
2343
- }),
2344
- /* @__PURE__ */ jsx("div", {
2345
- className: "nb-date-picker__footer",
2346
- children: /* @__PURE__ */ jsxs("button", {
2347
- type: "button",
2348
- className: "nb-date-picker__text-button",
2349
- onClick: () => setViewMode("days"),
2350
- children: [
2351
- /* @__PURE__ */ jsx("i", {
2352
- className: "ph ph-arrow-left",
2353
- "aria-hidden": "true"
2354
- }),
2355
- " ",
2356
- strings.back
2357
- ]
2358
- })
2359
- })
2360
- ] }),
2361
- viewMode === "years" && /* @__PURE__ */ jsxs(Fragment, { children: [
2362
- /* @__PURE__ */ jsxs("div", {
2363
- className: "nb-date-picker__header",
2364
- children: [
2365
- /* @__PURE__ */ jsx("button", {
2366
- type: "button",
2367
- className: "nb-date-picker__nav",
2368
- "aria-label": strings.previousYears,
2369
- onClick: () => setYearRangeStart((y) => y - 12),
2370
- children: /* @__PURE__ */ jsx("i", {
2371
- className: "ph ph-caret-left",
2372
- "aria-hidden": "true"
2373
- })
2374
- }),
2375
- /* @__PURE__ */ jsxs("div", {
2376
- className: "nb-date-picker__month",
2377
- children: [
2378
- yearRangeStart,
2379
- "–",
2380
- yearRangeStart + 11
2381
- ]
2382
- }),
2383
- /* @__PURE__ */ jsx("button", {
2384
- type: "button",
2385
- className: "nb-date-picker__nav",
2386
- "aria-label": strings.nextYears,
2387
- onClick: () => setYearRangeStart((y) => y + 12),
2388
- children: /* @__PURE__ */ jsx("i", {
2389
- className: "ph ph-caret-right",
2390
- "aria-hidden": "true"
2391
- })
2392
- })
2393
- ]
2394
- }),
2395
- /* @__PURE__ */ jsx("div", {
2396
- className: "nb-date-picker__years-grid",
2397
- role: "grid",
2398
- "aria-label": `${yearRangeStart}–${yearRangeStart + 11}`,
2399
- children: Array.from({ length: 12 }, (_, i) => yearRangeStart + i).map((year) => {
2400
- const isSelected = selectedDate ? selectedDate.getFullYear() === year : false;
2401
- const isCurrent = (/* @__PURE__ */ new Date()).getFullYear() === year;
2402
- return /* @__PURE__ */ jsx("button", {
2403
- type: "button",
2404
- className: cx$1("nb-date-picker__year-cell", isSelected && "nb-date-picker__year-cell--selected", isCurrent && "nb-date-picker__year-cell--current"),
2405
- role: "gridcell",
2406
- "aria-selected": isSelected,
2407
- onClick: () => handleYearSelect(year),
2408
- children: year
2409
- }, year);
2410
- })
2411
- }),
2412
- /* @__PURE__ */ jsx("div", {
2413
- className: "nb-date-picker__footer",
2414
- children: /* @__PURE__ */ jsxs("button", {
2415
- type: "button",
2416
- className: "nb-date-picker__text-button",
2417
- onClick: () => setViewMode("months"),
2418
- children: [
2419
- /* @__PURE__ */ jsx("i", {
2420
- className: "ph ph-arrow-left",
2421
- "aria-hidden": "true"
2422
- }),
2423
- " ",
2424
- strings.back
2425
- ]
2426
- })
2427
- })
2428
- ] })
2429
- ]
2430
- }), document.body)
2431
- ]
2449
+ })]
2450
+ })
2451
+ })
2452
+ ]
2453
+ })
2432
2454
  });
2433
2455
  });
2434
2456
  //#endregion
2435
2457
  //#region packages/ui/DateRangePicker.tsx
2436
- /**
2437
- * DateRangePicker — enterprise date range selector.
2438
- *
2439
- * A single trigger with two text inputs (start + end) sharing one calendar
2440
- * panel. Supports hover-preview, range highlighting, keyboard entry, min/max
2441
- * constraints, and full density/theme token compliance.
2442
- *
2443
- * Usage:
2444
- * <DateRangePicker
2445
- * startValue="2026-06-01"
2446
- * endValue="2026-06-30"
2447
- * onChange={(start, end) => ...}
2448
- * />
2449
- */
2450
- const ISO_DATE_RE = /^\d{4}-\d{2}-\d{2}$/;
2451
- const pad = (v) => String(v).padStart(2, "0");
2452
- const toIsoDate = (d) => `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())}`;
2453
- const parseIsoDate = (value) => {
2454
- if (!value || !ISO_DATE_RE.test(value)) return null;
2455
- const [year, month, day] = value.split("-").map(Number);
2456
- const d = new Date(year, month - 1, day);
2457
- if (d.getFullYear() !== year || d.getMonth() !== month - 1 || d.getDate() !== day) return null;
2458
- return d;
2459
- };
2460
- const cx = (...vals) => vals.filter(Boolean).join(" ");
2461
- const getLocale = (override) => override || document.documentElement.lang || navigator.language || "en-US";
2462
- const startOfMonth = (date) => new Date(date.getFullYear(), date.getMonth(), 1);
2463
- const addMonths = (date, months) => new Date(date.getFullYear(), date.getMonth() + months, 1);
2464
- const formatDisplayDate = (value, locale) => {
2465
- const date = parseIsoDate(value);
2466
- if (!date) return "";
2467
- return new Intl.DateTimeFormat(getLocale(locale), {
2468
- day: "2-digit",
2469
- month: "2-digit",
2470
- year: "numeric"
2471
- }).format(date);
2472
- };
2473
- const formatMonthLabel = (date, locale) => new Intl.DateTimeFormat(getLocale(locale), {
2474
- month: "long",
2475
- year: "numeric"
2476
- }).format(date);
2477
- const buildCalendarDays = (month, min, max, locale) => {
2478
- const first = startOfMonth(month);
2479
- const firstDayOfWeek = getFirstDayOfWeek(locale);
2480
- const offset = (first.getDay() - firstDayOfWeek + 7) % 7;
2481
- const minDate = parseIsoDate(min);
2482
- const maxDate = parseIsoDate(max);
2483
- const start = new Date(first);
2484
- start.setDate(first.getDate() - offset);
2485
- return Array.from({ length: 42 }, (_, i) => {
2486
- const date = new Date(start);
2487
- date.setDate(start.getDate() + i);
2488
- return {
2489
- date,
2490
- iso: toIsoDate(date),
2491
- inCurrentMonth: date.getMonth() === month.getMonth(),
2492
- disabled: Boolean(minDate && date < minDate || maxDate && date > maxDate)
2493
- };
2494
- });
2495
- };
2496
- const getDayRoleInRange = (iso, startIso, endIso) => {
2497
- if (!startIso) return "none";
2498
- if (!endIso || startIso === endIso) return iso === startIso ? "single" : "none";
2499
- if (iso === startIso) return "start";
2500
- if (iso === endIso) return "end";
2501
- if (iso > startIso && iso < endIso) return "in-range";
2502
- return "none";
2503
- };
2504
- function DateRangePicker({ startValue, endValue, placeholder = "dd/mm/yyyy", disabled = false, readOnly = false, required = false, invalid = false, locale, min, max, className, ariaLabel, onChange, onBlur }) {
2505
- const startId = useId();
2506
- const endId = useId();
2458
+ function DateRangePicker({ startValue, endValue, placeholder, disabled = false, clearable = true, readOnly = false, required = false, invalid = false, locale, min, max, className, ariaLabel, onChange, onBlur }) {
2459
+ const { container, groupRef, panelRef, open, setOpen } = useCalendarPopover();
2507
2460
  const strings = useUiStrings();
2508
- const resolvedLocale = getLocale(locale);
2509
- const startDisplay = formatDisplayDate(startValue, resolvedLocale);
2510
- const endDisplay = formatDisplayDate(endValue, resolvedLocale);
2511
- const startIso = parseIsoDate(startValue) ? startValue : null;
2512
- const endIso = parseIsoDate(endValue) ? endValue : null;
2513
- const [phase, setPhase] = useState("idle");
2514
- const [pendingStart, setPendingStart] = useState(null);
2515
- const [hoverIso, setHoverIso] = useState(null);
2516
- const [month, setMonth] = useState(() => startOfMonth(parseIsoDate(startValue) ?? /* @__PURE__ */ new Date()));
2517
- const [startText, setStartText] = useState("");
2518
- const [endText, setEndText] = useState("");
2519
- const [editingField, setEditingField] = useState(null);
2520
- const triggerRef = useRef(null);
2521
- const startInputRef = useRef(null);
2522
- const endInputRef = useRef(null);
2523
- const days = useMemo(() => buildCalendarDays(month, min, max, resolvedLocale), [
2524
- month,
2461
+ const resolvedLocale = getDateLocale(locale);
2462
+ const start = calendarDate(startValue);
2463
+ const end = calendarDate(endValue);
2464
+ const change = (a, b) => a && b && a > b ? onChange?.(b, a) : onChange?.(a, b);
2465
+ const todayIso = today(getLocalTimeZone()).toString();
2466
+ const prefix = "nb-date-range-picker";
2467
+ const inputProps = {
2468
+ locale: resolvedLocale,
2525
2469
  min,
2526
2470
  max,
2527
- resolvedLocale
2528
- ]);
2529
- const weekdayLbls = useMemo(() => weekDayLabels(resolvedLocale), [resolvedLocale]);
2530
- const todayIso = toIsoDate(/* @__PURE__ */ new Date());
2531
- useEffect(() => {
2532
- const anchor = parseIsoDate(startValue) ?? parseIsoDate(endValue);
2533
- if (anchor) setMonth(startOfMonth(anchor));
2534
- }, [startValue]);
2535
- const { open, setOpen, containerRef: rootRef, panelRef, panelStyle } = useFloatingPanel({
2536
- onClose: () => {
2537
- setPhase("idle");
2538
- setPendingStart(null);
2539
- setHoverIso(null);
2540
- },
2541
- onEscape: (e) => {
2542
- e.preventDefault();
2543
- startInputRef.current?.focus();
2544
- },
2545
- computeStyle: () => {
2546
- const rect = triggerRef.current?.getBoundingClientRect();
2547
- if (!rect) return null;
2548
- const panelWidth = panelRef.current?.offsetWidth ?? 296;
2549
- const left = Math.min(Math.max(8, rect.left), window.innerWidth - panelWidth - 8);
2550
- const top = Math.min(rect.bottom + 6, window.innerHeight - 380);
2551
- return {
2552
- left,
2553
- top: Math.max(8, top)
2554
- };
2555
- }
2556
- });
2557
- const closePanel = useCallback(() => {
2558
- setOpen(false);
2559
- }, [setOpen]);
2560
- const commitRange = useCallback((start, end) => {
2561
- const [a, b] = start <= end ? [start, end] : [end, start];
2562
- onChange?.(a, b);
2563
- closePanel();
2564
- window.setTimeout(() => startInputRef.current?.focus());
2565
- }, [onChange, closePanel]);
2566
- const handleDayClick = useCallback((iso) => {
2567
- if (phase === "idle") {
2568
- setPendingStart(iso);
2569
- setPhase("selecting-end");
2570
- } else commitRange(pendingStart ?? iso, iso);
2571
- }, [
2572
- phase,
2573
- pendingStart,
2574
- commitRange
2575
- ]);
2576
- const getEffectiveRange = () => {
2577
- if (phase === "selecting-end" && pendingStart) {
2578
- const effectiveEnd = hoverIso ?? null;
2579
- return {
2580
- effectiveStart: pendingStart <= (effectiveEnd ?? pendingStart) ? pendingStart : effectiveEnd,
2581
- effectiveEnd: pendingStart <= (effectiveEnd ?? pendingStart) ? effectiveEnd : pendingStart
2582
- };
2583
- }
2584
- return {
2585
- effectiveStart: startIso,
2586
- effectiveEnd: endIso
2587
- };
2588
- };
2589
- const { effectiveStart, effectiveEnd } = getEffectiveRange();
2590
- const handleStartFocus = () => {
2591
- setEditingField("start");
2592
- setStartText(startDisplay);
2593
- window.setTimeout(() => startInputRef.current?.select(), 0);
2594
- };
2595
- const handleEndFocus = () => {
2596
- setEditingField("end");
2597
- setEndText(endDisplay);
2598
- window.setTimeout(() => endInputRef.current?.select(), 0);
2599
- };
2600
- const handleStartChange = (e) => {
2601
- if (readOnly || disabled) return;
2602
- setStartText(applyDateMask(e.target.value, startText));
2603
- };
2604
- const handleEndChange = (e) => {
2605
- if (readOnly || disabled) return;
2606
- setEndText(applyDateMask(e.target.value, endText));
2607
- };
2608
- const commitTextInput = (field, text) => {
2609
- const parsed = parseDisplayDate(text, resolvedLocale);
2610
- if (parsed !== null) {
2611
- const newStart = field === "start" ? parsed : startIso ?? "";
2612
- const newEnd = field === "end" ? parsed : endIso ?? "";
2613
- if (newStart && newEnd) {
2614
- const [a, b] = newStart <= newEnd ? [newStart, newEnd] : [newEnd, newStart];
2615
- onChange?.(a, b);
2616
- } else if (field === "start") onChange?.(parsed, endIso ?? "");
2617
- else onChange?.(startIso ?? "", parsed);
2618
- } else if (text === "") if (field === "start") onChange?.("", endIso ?? "");
2619
- else onChange?.(startIso ?? "", "");
2620
- };
2621
- const handleStartBlur = (e) => {
2622
- const related = e.relatedTarget;
2623
- if (rootRef.current?.contains(related) || panelRef.current?.contains(related)) return;
2624
- commitTextInput("start", startText);
2625
- setEditingField(null);
2626
- setStartText("");
2627
- onBlur?.(e);
2628
- };
2629
- const handleEndBlur = (e) => {
2630
- const related = e.relatedTarget;
2631
- if (rootRef.current?.contains(related) || panelRef.current?.contains(related)) return;
2632
- commitTextInput("end", endText);
2633
- setEditingField(null);
2634
- setEndText("");
2635
- onBlur?.(e);
2636
- };
2637
- const handleStartKeyDown = (e) => {
2638
- if (e.key === "Enter") {
2639
- e.preventDefault();
2640
- const parsed = parseDisplayDate(startText);
2641
- if (parsed) onChange?.(parsed, endIso ?? "");
2642
- endInputRef.current?.focus();
2643
- } else if (e.key === "ArrowDown" || e.key === "F4") {
2644
- e.preventDefault();
2645
- if (!readOnly && !disabled) setOpen(true);
2646
- }
2647
- };
2648
- const handleEndKeyDown = (e) => {
2649
- if (e.key === "Enter") {
2650
- e.preventDefault();
2651
- const parsed = parseDisplayDate(endText);
2652
- if (parsed) onChange?.(startIso ?? "", parsed);
2653
- } else if (e.key === "ArrowDown" || e.key === "F4") {
2654
- e.preventDefault();
2655
- if (!readOnly && !disabled) setOpen(true);
2471
+ placeholder: placeholder ?? datePlaceholder(resolvedLocale),
2472
+ disabled,
2473
+ readOnly,
2474
+ required,
2475
+ "aria-invalid": invalid || void 0,
2476
+ className: `${prefix}__input`,
2477
+ onOpen: () => setOpen(true),
2478
+ onBlur,
2479
+ onKeyDown: (event) => {
2480
+ if (event.key === "Escape" && open) {
2481
+ event.stopPropagation();
2482
+ setOpen(false);
2483
+ }
2656
2484
  }
2657
2485
  };
2658
- const handleCalendarPointerDown = (e) => {
2659
- e.preventDefault();
2660
- if (readOnly || disabled) return;
2661
- setOpen(!open);
2662
- };
2663
- const handleClear = (e) => {
2664
- e.preventDefault();
2665
- onChange?.("", "");
2666
- closePanel();
2667
- };
2668
- return /* @__PURE__ */ jsxs("div", {
2669
- ref: rootRef,
2670
- className: cx("nb-date-range-picker", className),
2671
- children: [
2672
- /* @__PURE__ */ jsxs("div", {
2673
- ref: triggerRef,
2674
- 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"),
2675
- "aria-label": ariaLabel,
2676
- children: [
2677
- /* @__PURE__ */ jsx("input", {
2678
- ref: startInputRef,
2679
- id: startId,
2680
- type: "text",
2681
- inputMode: "numeric",
2682
- className: cx("nb-date-range-picker__input", !editingField && !startDisplay && "nb-date-range-picker__input--placeholder"),
2683
- value: editingField === "start" ? startText : startDisplay,
2684
- placeholder,
2685
- disabled,
2686
- readOnly,
2687
- autoComplete: "off",
2688
- "aria-label": `Fecha inicio${ariaLabel ? ` ${ariaLabel}` : ""}`,
2689
- "aria-required": required || void 0,
2690
- onFocus: handleStartFocus,
2691
- onBlur: handleStartBlur,
2692
- onChange: handleStartChange,
2693
- onKeyDown: handleStartKeyDown
2694
- }),
2695
- /* @__PURE__ */ jsx("span", {
2696
- className: "nb-date-range-picker__sep",
2697
- "aria-hidden": "true",
2698
- children: /* @__PURE__ */ jsx("i", { className: "ph ph-arrow-right" })
2699
- }),
2700
- /* @__PURE__ */ jsx("input", {
2701
- ref: endInputRef,
2702
- id: endId,
2703
- type: "text",
2704
- inputMode: "numeric",
2705
- className: cx("nb-date-range-picker__input", !editingField && !endDisplay && "nb-date-range-picker__input--placeholder"),
2706
- value: editingField === "end" ? endText : endDisplay,
2707
- placeholder,
2708
- disabled,
2709
- readOnly,
2710
- autoComplete: "off",
2711
- "aria-label": `Fecha fin${ariaLabel ? ` ${ariaLabel}` : ""}`,
2712
- onFocus: handleEndFocus,
2713
- onBlur: handleEndBlur,
2714
- onChange: handleEndChange,
2715
- onKeyDown: handleEndKeyDown
2716
- }),
2717
- /* @__PURE__ */ jsxs("span", {
2718
- className: "nb-date-range-picker__icons",
2719
- children: [(startDisplay || endDisplay) && !disabled && !readOnly && /* @__PURE__ */ jsx("span", {
2720
- role: "button",
2721
- tabIndex: -1,
2722
- className: "nb-date-range-picker__clear",
2723
- "aria-label": strings.clearDateRange,
2724
- onPointerDown: handleClear,
2725
- children: /* @__PURE__ */ jsx("i", {
2726
- className: "ph ph-x",
2727
- "aria-hidden": "true"
2728
- })
2729
- }), /* @__PURE__ */ jsx("span", {
2730
- role: "button",
2731
- tabIndex: -1,
2732
- className: "nb-date-range-picker__calendar-btn",
2733
- "aria-label": strings.openCalendar,
2734
- onPointerDown: handleCalendarPointerDown,
2735
- children: /* @__PURE__ */ jsx("i", {
2736
- className: "ph ph-calendar-blank",
2737
- "aria-hidden": "true"
2738
- })
2739
- })]
2740
- })
2741
- ]
2742
- }),
2743
- phase === "selecting-end" && /* @__PURE__ */ jsx("div", {
2744
- className: "nb-date-range-picker__hint",
2745
- role: "status",
2746
- "aria-live": "polite",
2747
- children: "Selecciona la fecha de fin"
2748
- }),
2749
- open && createPortal(/* @__PURE__ */ jsxs("div", {
2750
- ref: panelRef,
2751
- className: "nb-date-range-picker__panel",
2752
- role: "dialog",
2753
- "aria-label": strings.selectDateRange,
2754
- style: panelStyle,
2486
+ return /* @__PURE__ */ jsx(I18nProvider, {
2487
+ locale: resolvedLocale,
2488
+ children: /* @__PURE__ */ jsxs(DateRangePicker$1, {
2489
+ "aria-label": ariaLabel ?? strings.selectDateRange,
2490
+ value: start && end && start.compare(end) <= 0 ? {
2491
+ start,
2492
+ end
2493
+ } : null,
2494
+ onChange: (range) => change(range?.start.toString() ?? "", range?.end.toString() ?? ""),
2495
+ minValue: calendarDate(min) ?? void 0,
2496
+ maxValue: calendarDate(max) ?? void 0,
2497
+ placeholderValue: start ?? end ?? void 0,
2498
+ isDisabled: disabled,
2499
+ isReadOnly: readOnly,
2500
+ isRequired: required,
2501
+ isInvalid: invalid,
2502
+ validationBehavior: "aria",
2503
+ isOpen: open,
2504
+ onOpenChange: setOpen,
2505
+ className: [prefix, className].filter(Boolean).join(" "),
2506
+ children: [/* @__PURE__ */ jsxs(Group, {
2507
+ ref: groupRef,
2508
+ className: [
2509
+ `${prefix}__trigger`,
2510
+ disabled && `${prefix}__trigger--disabled`,
2511
+ readOnly && `${prefix}__trigger--readonly`,
2512
+ invalid && `${prefix}__trigger--invalid`,
2513
+ open && `${prefix}__trigger--open`
2514
+ ].filter(Boolean).join(" "),
2755
2515
  children: [
2756
- /* @__PURE__ */ jsxs("div", {
2757
- className: "nb-date-range-picker__header",
2758
- children: [
2759
- /* @__PURE__ */ jsx("button", {
2760
- type: "button",
2761
- className: "nb-date-range-picker__nav",
2762
- "aria-label": strings.previousMonth,
2763
- onClick: () => setMonth((m) => addMonths(m, -1)),
2764
- children: /* @__PURE__ */ jsx("i", {
2765
- className: "ph ph-caret-left",
2766
- "aria-hidden": "true"
2767
- })
2768
- }),
2769
- /* @__PURE__ */ jsx("div", {
2770
- className: "nb-date-range-picker__month",
2771
- "aria-live": "polite",
2772
- children: formatMonthLabel(month, resolvedLocale)
2773
- }),
2774
- /* @__PURE__ */ jsx("button", {
2775
- type: "button",
2776
- className: "nb-date-range-picker__nav",
2777
- "aria-label": strings.nextMonth,
2778
- onClick: () => setMonth((m) => addMonths(m, 1)),
2779
- children: /* @__PURE__ */ jsx("i", {
2780
- className: "ph ph-caret-right",
2781
- "aria-hidden": "true"
2782
- })
2783
- })
2784
- ]
2516
+ /* @__PURE__ */ jsx(DateTextInput, {
2517
+ ...inputProps,
2518
+ "aria-label": [strings.startDate, ariaLabel].filter(Boolean).join(" "),
2519
+ value: startValue,
2520
+ onChange: (next) => change(next, endValue ?? "")
2785
2521
  }),
2786
- /* @__PURE__ */ jsx("div", {
2787
- className: "nb-date-range-picker__weekdays",
2522
+ /* @__PURE__ */ jsx("span", {
2523
+ className: `${prefix}__sep`,
2788
2524
  "aria-hidden": "true",
2789
- children: weekdayLbls.map((label, i) => /* @__PURE__ */ jsx("span", { children: label }, `${label}-${i}`))
2525
+ children: "→"
2790
2526
  }),
2791
- phase === "selecting-end" && /* @__PURE__ */ jsxs("div", {
2792
- className: "nb-date-range-picker__phase-banner",
2793
- children: [/* @__PURE__ */ jsx("i", {
2794
- className: "ph ph-info",
2795
- "aria-hidden": "true"
2796
- }), "Ahora selecciona la fecha de fin"]
2527
+ /* @__PURE__ */ jsx(DateTextInput, {
2528
+ ...inputProps,
2529
+ "aria-label": [strings.endDate, ariaLabel].filter(Boolean).join(" "),
2530
+ value: endValue,
2531
+ onChange: (next) => change(startValue ?? "", next)
2797
2532
  }),
2798
- /* @__PURE__ */ jsx("div", {
2799
- className: "nb-date-range-picker__days",
2800
- role: "grid",
2801
- "aria-label": formatMonthLabel(month, resolvedLocale),
2802
- children: days.map((day) => {
2803
- const role = getDayRoleInRange(day.iso, effectiveStart, effectiveEnd);
2804
- return /* @__PURE__ */ jsx("button", {
2805
- type: "button",
2806
- 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"),
2807
- disabled: day.disabled,
2808
- role: "gridcell",
2809
- "aria-selected": role !== "none",
2810
- onMouseEnter: () => phase === "selecting-end" && setHoverIso(day.iso),
2811
- onMouseLeave: () => phase === "selecting-end" && setHoverIso(null),
2812
- onClick: () => !day.disabled && handleDayClick(day.iso),
2813
- children: /* @__PURE__ */ jsx("span", {
2814
- className: "nb-date-range-picker__day-inner",
2815
- children: day.date.getDate()
2816
- })
2817
- }, day.iso);
2818
- })
2533
+ clearable && (startValue || endValue) && !disabled && !readOnly && /* @__PURE__ */ jsx(Button$1, {
2534
+ slot: null,
2535
+ className: `${prefix}__clear`,
2536
+ "aria-label": strings.clearDateRange,
2537
+ onPress: () => change("", ""),
2538
+ children: "×"
2819
2539
  }),
2820
- /* @__PURE__ */ jsxs("div", {
2821
- className: "nb-date-range-picker__footer",
2822
- children: [/* @__PURE__ */ jsx("button", {
2823
- type: "button",
2824
- className: "nb-date-range-picker__text-button",
2825
- onClick: () => {
2826
- onChange?.("", "");
2827
- closePanel();
2540
+ /* @__PURE__ */ jsx(Button$1, {
2541
+ className: `${prefix}__calendar-btn`,
2542
+ "aria-label": strings.openCalendar,
2543
+ onPress: () => groupRef.current?.querySelector("input")?.focus(),
2544
+ isDisabled: disabled || readOnly,
2545
+ children: /* @__PURE__ */ jsx("i", {
2546
+ "aria-hidden": "true",
2547
+ className: "ph ph-calendar-blank"
2548
+ })
2549
+ })
2550
+ ]
2551
+ }), /* @__PURE__ */ jsx(Popover$1, {
2552
+ isNonModal: Boolean(container),
2553
+ ref: panelRef,
2554
+ UNSTABLE_portalContainer: container ?? void 0,
2555
+ className: `${prefix}__panel`,
2556
+ offset: 4,
2557
+ children: /* @__PURE__ */ jsxs(CalendarDialog, {
2558
+ ariaLabel: strings.selectDateRange,
2559
+ children: [/* @__PURE__ */ jsx(RangeCalendar, {
2560
+ className: "nb-calendar--range",
2561
+ children: /* @__PURE__ */ jsx(CalendarContent, {})
2562
+ }), /* @__PURE__ */ jsxs("div", {
2563
+ className: `${prefix}__footer`,
2564
+ children: [/* @__PURE__ */ jsx(Button$1, {
2565
+ slot: null,
2566
+ className: `${prefix}__text-button`,
2567
+ onPress: () => {
2568
+ change("", "");
2569
+ setOpen(false);
2828
2570
  },
2829
2571
  children: strings.clear
2830
- }), phase === "selecting-end" ? /* @__PURE__ */ jsx("button", {
2831
- type: "button",
2832
- className: "nb-date-range-picker__text-button",
2833
- onClick: () => {
2834
- setPendingStart(null);
2835
- setPhase("idle");
2836
- setHoverIso(null);
2837
- },
2838
- children: strings.cancel
2839
- }) : /* @__PURE__ */ jsx("button", {
2840
- type: "button",
2841
- className: "nb-date-range-picker__text-button",
2842
- onClick: () => {
2843
- const today = toIsoDate(/* @__PURE__ */ new Date());
2844
- setMonth(startOfMonth(/* @__PURE__ */ new Date()));
2845
- if (!startIso) onChange?.(today, endIso ?? "");
2846
- else if (!endIso) onChange?.(startIso, today);
2847
- else onChange?.(today, today);
2848
- closePanel();
2572
+ }), /* @__PURE__ */ jsx(Button$1, {
2573
+ slot: null,
2574
+ className: `${prefix}__text-button`,
2575
+ isDisabled: !dateAllowed(todayIso, min, max),
2576
+ onPress: () => {
2577
+ change(todayIso, todayIso);
2578
+ setOpen(false);
2849
2579
  },
2850
2580
  children: strings.today
2851
2581
  })]
2852
- })
2853
- ]
2854
- }), document.body)
2855
- ]
2582
+ })]
2583
+ })
2584
+ })]
2585
+ })
2856
2586
  });
2857
2587
  }
2858
2588
  //#endregion
2859
2589
  //#region packages/ui/Popover.tsx
2860
2590
  const Popover = ({ trigger, panel, align = "end", ariaLabel, className }) => {
2861
- const { open, setOpen, toggle, containerRef } = useFloatingPanel();
2862
- return /* @__PURE__ */ jsxs("div", {
2863
- ref: containerRef,
2864
- className: [
2865
- "nb-popover",
2866
- `nb-popover--${align}`,
2867
- open && "nb-popover--open",
2868
- className
2869
- ].filter(Boolean).join(" "),
2870
- children: [trigger({
2871
- open,
2872
- toggle
2873
- }), open && /* @__PURE__ */ jsx("div", {
2874
- className: "nb-popover__panel",
2875
- role: "dialog",
2876
- "aria-label": ariaLabel,
2877
- children: panel({ close: () => setOpen(false) })
2878
- })]
2591
+ const [open, setOpen] = useState(false);
2592
+ const triggerRef = useRef(null);
2593
+ const [restoreFocus, setRestoreFocus] = useState(true);
2594
+ const changeOpen = (next) => {
2595
+ setRestoreFocus(true);
2596
+ setOpen(next);
2597
+ };
2598
+ const container = useOverlayContainer();
2599
+ const triggerNode = trigger({
2600
+ open,
2601
+ toggle: () => changeOpen(!open)
2602
+ });
2603
+ return /* @__PURE__ */ jsx(Popover$2.Root, {
2604
+ open,
2605
+ onOpenChange: (next, details) => {
2606
+ setRestoreFocus(details.reason !== "outside-press" && details.reason !== "focus-out");
2607
+ setOpen(next);
2608
+ },
2609
+ onOpenChangeComplete: (next) => {
2610
+ if (!next && restoreFocus) triggerRef.current?.focus({ preventScroll: true });
2611
+ },
2612
+ children: /* @__PURE__ */ jsxs("div", {
2613
+ className: [
2614
+ "nb-popover",
2615
+ `nb-popover--${align}`,
2616
+ open && "nb-popover--open",
2617
+ className
2618
+ ].filter(Boolean).join(" "),
2619
+ children: [/* @__PURE__ */ jsx(Popover$2.Trigger, {
2620
+ ref: triggerRef,
2621
+ render: isValidElement(triggerNode) ? triggerNode : /* @__PURE__ */ jsx("button", {
2622
+ type: "button",
2623
+ children: triggerNode
2624
+ })
2625
+ }), /* @__PURE__ */ jsx(Popover$2.Portal, {
2626
+ container: container ?? void 0,
2627
+ children: /* @__PURE__ */ jsx(Popover$2.Positioner, {
2628
+ align,
2629
+ sideOffset: 8,
2630
+ className: "nb-popover-positioner",
2631
+ children: /* @__PURE__ */ jsx(Popover$2.Popup, {
2632
+ finalFocus: triggerRef,
2633
+ onKeyDownCapture: (event) => {
2634
+ if (event.key === "Escape") {
2635
+ event.preventDefault();
2636
+ event.stopPropagation();
2637
+ changeOpen(false);
2638
+ }
2639
+ },
2640
+ className: "nb-popover__panel",
2641
+ "aria-label": ariaLabel,
2642
+ children: panel({ close: () => changeOpen(false) })
2643
+ })
2644
+ })
2645
+ })]
2646
+ })
2879
2647
  });
2880
2648
  };
2881
2649
  //#endregion
2650
+ //#region packages/ui/useFloatingPanel.ts
2651
+ /** Style applied to an anchored panel before its first position is computed. */
2652
+ const HIDDEN_PANEL_STYLE = {
2653
+ position: "fixed",
2654
+ visibility: "hidden",
2655
+ margin: 0
2656
+ };
2657
+ function useFloatingPanel(options = {}) {
2658
+ const [open, setOpenState] = useState(false);
2659
+ const [panelStyle, setPanelStyle] = useState(HIDDEN_PANEL_STYLE);
2660
+ const containerRef = useRef(null);
2661
+ const panelRef = useRef(null);
2662
+ const optionsRef = useRef(options);
2663
+ optionsRef.current = options;
2664
+ const anchored = !!options.computeStyle;
2665
+ const dismissEvent = options.dismissEvent ?? "pointerdown";
2666
+ const setOpen = useCallback((next) => {
2667
+ setOpenState(next);
2668
+ if (!next) optionsRef.current.onClose?.();
2669
+ optionsRef.current.onOpenChange?.(next);
2670
+ }, []);
2671
+ const applyStyle = useCallback(() => {
2672
+ const compute = optionsRef.current.computeStyle;
2673
+ if (!compute) return;
2674
+ const style = compute(containerRef.current);
2675
+ if (style) setPanelStyle(style);
2676
+ }, []);
2677
+ const openPanel = useCallback(() => {
2678
+ applyStyle();
2679
+ setOpen(true);
2680
+ }, [applyStyle, setOpen]);
2681
+ const toggle = useCallback(() => open ? setOpen(false) : openPanel(), [
2682
+ open,
2683
+ openPanel,
2684
+ setOpen
2685
+ ]);
2686
+ useEffect(() => {
2687
+ if (!open) return;
2688
+ const handleOutside = (e) => {
2689
+ const target = e.target;
2690
+ if (containerRef.current?.contains(target) || panelRef.current?.contains(target)) return;
2691
+ setOpen(false);
2692
+ };
2693
+ const handleKeyDown = (e) => {
2694
+ if (e.key !== "Escape" || e.defaultPrevented) return;
2695
+ e.preventDefault();
2696
+ e.stopPropagation();
2697
+ setOpen(false);
2698
+ optionsRef.current.onEscape?.(e);
2699
+ };
2700
+ document.addEventListener(dismissEvent, handleOutside);
2701
+ document.addEventListener("keydown", handleKeyDown, true);
2702
+ return () => {
2703
+ document.removeEventListener(dismissEvent, handleOutside);
2704
+ document.removeEventListener("keydown", handleKeyDown, true);
2705
+ };
2706
+ }, [
2707
+ dismissEvent,
2708
+ open,
2709
+ setOpen
2710
+ ]);
2711
+ useLayoutEffect(() => {
2712
+ if (!open || !anchored) return;
2713
+ const update = () => {
2714
+ const container = containerRef.current;
2715
+ if (!container) return;
2716
+ if (optionsRef.current.closeOnViewportExit) {
2717
+ const rect = container.getBoundingClientRect();
2718
+ if ((rect.width > 0 || rect.height > 0) && (rect.top >= window.innerHeight || rect.bottom <= 0)) {
2719
+ setOpen(false);
2720
+ return;
2721
+ }
2722
+ }
2723
+ applyStyle();
2724
+ };
2725
+ update();
2726
+ window.addEventListener("resize", update);
2727
+ window.addEventListener("scroll", update, {
2728
+ capture: true,
2729
+ passive: true
2730
+ });
2731
+ return () => {
2732
+ window.removeEventListener("resize", update);
2733
+ window.removeEventListener("scroll", update, { capture: true });
2734
+ };
2735
+ }, [
2736
+ anchored,
2737
+ applyStyle,
2738
+ open,
2739
+ setOpen
2740
+ ]);
2741
+ return {
2742
+ open,
2743
+ setOpen,
2744
+ toggle,
2745
+ openPanel,
2746
+ containerRef,
2747
+ panelRef,
2748
+ panelStyle
2749
+ };
2750
+ }
2751
+ //#endregion
2882
2752
  //#region packages/ui/Drawer.tsx
2883
2753
  const formatWidth = (value) => {
2884
2754
  if (value === void 0) return void 0;
2885
2755
  return typeof value === "number" ? `${value}px` : value;
2886
2756
  };
2887
- const Drawer = ({ isOpen, onClose, title, width, side = "right", scrim = "subtle", children, footer, closeLabel, scrimLabel, className, "aria-label": ariaLabel }) => {
2757
+ const Drawer = ({ isOpen, busy = false, onClose, title, width, side = "right", scrim = "subtle", children, footer, closeLabel, scrimLabel, className, "aria-label": ariaLabel }) => {
2888
2758
  const strings = useUiStrings();
2889
2759
  const resolvedCloseLabel = closeLabel ?? strings.close;
2890
2760
  const resolvedScrimLabel = scrimLabel ?? strings.closePanel;
2891
2761
  const titleId = useId();
2892
- const panelRef = useRef(null);
2893
- const lastFocusRef = useRef(null);
2894
- useEffect(() => {
2895
- if (!isOpen) return;
2896
- lastFocusRef.current = document.activeElement;
2897
- const timer = window.setTimeout(() => {
2898
- (panelRef.current?.querySelector("button:not(:disabled), [href], input:not(:disabled), select:not(:disabled), textarea:not(:disabled), [tabindex]:not([tabindex=\"-1\"])"))?.focus();
2899
- });
2900
- return () => {
2901
- clearTimeout(timer);
2902
- lastFocusRef.current?.focus?.();
2903
- };
2904
- }, [isOpen]);
2905
- useEffect(() => {
2906
- if (!isOpen) return;
2907
- const handler = (e) => {
2908
- if (e.key === "Escape") {
2909
- e.preventDefault();
2910
- onClose();
2911
- }
2912
- };
2913
- document.addEventListener("keydown", handler);
2914
- return () => document.removeEventListener("keydown", handler);
2915
- }, [isOpen, onClose]);
2916
- return createPortal(/* @__PURE__ */ jsxs("div", {
2917
- className: [
2762
+ return /* @__PURE__ */ jsxs(ModalSurface, {
2763
+ open: isOpen,
2764
+ onClose,
2765
+ closeOnEscape: !busy,
2766
+ closeOnOutsideClick: !busy,
2767
+ rootClassName: [
2918
2768
  "nb-drawer-root",
2919
2769
  isOpen && "nb-drawer-root--open",
2920
2770
  `nb-drawer-root--${side}`
2921
2771
  ].filter(Boolean).join(" "),
2922
- "aria-hidden": !isOpen,
2923
- style: { pointerEvents: isOpen ? void 0 : "none" },
2924
- children: [/* @__PURE__ */ jsx("button", {
2925
- className: `nb-drawer__scrim nb-drawer__scrim--${scrim}`,
2926
- type: "button",
2927
- "aria-label": resolvedScrimLabel,
2928
- tabIndex: -1,
2929
- onClick: onClose
2930
- }), /* @__PURE__ */ jsxs("aside", {
2931
- ref: panelRef,
2932
- className: ["nb-drawer", className].filter(Boolean).join(" "),
2933
- role: "dialog",
2934
- "aria-modal": "false",
2935
- "aria-labelledby": title ? titleId : void 0,
2936
- "aria-label": !title ? ariaLabel : void 0,
2937
- style: { width: formatWidth(width) },
2938
- children: [
2939
- title !== void 0 && /* @__PURE__ */ jsxs("header", {
2940
- className: "nb-drawer__header",
2941
- children: [/* @__PURE__ */ jsx("h2", {
2942
- className: "nb-drawer__title",
2943
- id: titleId,
2944
- children: title
2945
- }), /* @__PURE__ */ jsx(IconButton, {
2946
- className: "nb-drawer__close",
2947
- icon: "ph ph-x",
2948
- label: resolvedCloseLabel,
2949
- onClick: onClose
2950
- })]
2951
- }),
2952
- /* @__PURE__ */ jsx("div", {
2953
- className: "nb-drawer__body",
2954
- children
2955
- }),
2956
- footer && /* @__PURE__ */ jsx("footer", {
2957
- className: "nb-drawer__footer",
2958
- children: footer
2959
- })
2960
- ]
2961
- })]
2962
- }), document.body);
2772
+ className: ["nb-drawer", className].filter(Boolean).join(" "),
2773
+ scrimClassName: `nb-drawer__scrim nb-drawer__scrim--${scrim}`,
2774
+ scrimLabel: resolvedScrimLabel,
2775
+ labelledBy: title ? titleId : void 0,
2776
+ ariaLabel: !title ? ariaLabel : void 0,
2777
+ style: { width: formatWidth(width) },
2778
+ keepMounted: true,
2779
+ children: [
2780
+ title !== void 0 && /* @__PURE__ */ jsxs("header", {
2781
+ className: "nb-drawer__header",
2782
+ children: [/* @__PURE__ */ jsx("h2", {
2783
+ className: "nb-drawer__title",
2784
+ id: titleId,
2785
+ children: title
2786
+ }), /* @__PURE__ */ jsx(IconButton, {
2787
+ className: "nb-drawer__close",
2788
+ icon: "ph ph-x",
2789
+ label: resolvedCloseLabel,
2790
+ onClick: onClose,
2791
+ disabled: busy
2792
+ })]
2793
+ }),
2794
+ /* @__PURE__ */ jsx("div", {
2795
+ className: "nb-drawer__body",
2796
+ children
2797
+ }),
2798
+ footer && /* @__PURE__ */ jsx("footer", {
2799
+ className: "nb-drawer__footer",
2800
+ children: footer
2801
+ })
2802
+ ]
2803
+ });
2963
2804
  };
2964
2805
  //#endregion
2965
2806
  //#region packages/ui/Timeline.tsx
@@ -2998,13 +2839,14 @@ function TimelineMarker({ status, variant, marker }) {
2998
2839
  }
2999
2840
  function TimelineItem({ status, title, marker, timestamp, dateTime, tone = "default", children, className }) {
3000
2841
  const variant = useTimelineVariant();
2842
+ const classes = [
2843
+ "nb-timeline__item",
2844
+ `nb-timeline__item--${status}`,
2845
+ variant === "log" && `nb-timeline__item--tone-${tone}`,
2846
+ className
2847
+ ].filter(Boolean).join(" ");
3001
2848
  return /* @__PURE__ */ jsxs("li", {
3002
- className: [
3003
- "nb-timeline__item",
3004
- `nb-timeline__item--${status}`,
3005
- variant === "log" && `nb-timeline__item--tone-${tone}`,
3006
- className
3007
- ].filter(Boolean).join(" "),
2849
+ className: classes,
3008
2850
  children: [/* @__PURE__ */ jsx("div", {
3009
2851
  className: "nb-timeline__marker-col",
3010
2852
  children: /* @__PURE__ */ jsx(TimelineMarker, {
@@ -3068,7 +2910,7 @@ function Page({ children, fill, wide, narrow, gap = 5, className, ...props }) {
3068
2910
  }
3069
2911
  //#endregion
3070
2912
  //#region packages/ui/PageHeader.tsx
3071
- function PageHeader({ title, subtitle, breadcrumb, breadcrumbSlot, badge, actions, className }) {
2913
+ function PageHeader({ title, subtitle, metadata, breadcrumb, breadcrumbSlot, badge, actions, className }) {
3072
2914
  const breadcrumbNode = breadcrumbSlot ?? (breadcrumb ? /* @__PURE__ */ jsxs("a", {
3073
2915
  href: breadcrumb.href,
3074
2916
  className: "nb-page-header__breadcrumb",
@@ -3087,6 +2929,10 @@ function PageHeader({ title, subtitle, breadcrumb, breadcrumbSlot, badge, action
3087
2929
  className: "nb-page-header__title",
3088
2930
  children: title
3089
2931
  }),
2932
+ metadata && /* @__PURE__ */ jsx("div", {
2933
+ className: "nb-page-header__metadata",
2934
+ children: metadata
2935
+ }),
3090
2936
  subtitle && /* @__PURE__ */ jsx("p", {
3091
2937
  className: "nb-page-header__subtitle",
3092
2938
  children: subtitle
@@ -3137,8 +2983,9 @@ function Grid({ children, cols = 12, gap = 4, minColWidth, fill, className, styl
3137
2983
  ...style,
3138
2984
  ...minColWidth ? { "--nb-grid-min-col": minColWidth } : {}
3139
2985
  };
2986
+ const colsClass = cols === 12 ? "nb-grid--cols-12" : cols === "auto" ? "nb-grid--cols-auto" : `nb-grid--cols-${cols}`;
3140
2987
  return /* @__PURE__ */ jsx("div", {
3141
- className: joinClasses("nb-grid", cols === 12 ? "nb-grid--cols-12" : cols === "auto" ? "nb-grid--cols-auto" : `nb-grid--cols-${cols}`, gapClass("nb-grid", gap), fill && "nb-grid--fill", className),
2988
+ className: joinClasses("nb-grid", colsClass, gapClass("nb-grid", gap), fill && "nb-grid--fill", className),
3142
2989
  style: gridStyle,
3143
2990
  ...props,
3144
2991
  children
@@ -3155,9 +3002,9 @@ function Col({ children, span, spanSm, spanMd, spanLg, fullWidth, className, ...
3155
3002
  }
3156
3003
  //#endregion
3157
3004
  //#region packages/ui/Section.tsx
3158
- function Section({ title, children, className }) {
3005
+ function Section({ title, children, className, variant = "label" }) {
3159
3006
  return /* @__PURE__ */ jsxs("section", {
3160
- className: joinClasses("nb-section", className),
3007
+ className: joinClasses("nb-section", variant === "panel" && "nb-section--panel", className),
3161
3008
  children: [/* @__PURE__ */ jsx("h2", {
3162
3009
  className: "nb-section__title",
3163
3010
  children: title
@@ -3360,4 +3207,239 @@ function useConfirm() {
3360
3207
  };
3361
3208
  }
3362
3209
  //#endregion
3363
- export { ACCENT_PRESETS, Alert, AppDialog, AppDropdown, AppToolbar, Avatar, Badge, Button, Card, Chip, Cluster, Code, Col, CollapsibleSection, ConfirmDialog, ContextMenu, DataTable, DatePicker, DateRangePicker, DensityContext, DensityProvider, DescriptionList, Drawer, EN_UI_STRINGS, ES_UI_STRINGS, EmptyState, FeatureGate, FileDropzone, FilterPanel, FormActions, FormField, FormLayout, Grid, HubPanel, IconButton, KpiMetricRow, OperationCardGrid, Page, PageHeader, Pagination, Popover, Row, RowActions, ScopeTabs, SearchableAppDropdown, Section, SegmentedControl, SelectField, SettingsPanel, Skeleton, Stack, StatCard, Text, TextAreaField, TextField, ThemeContext, ThemeProvider, ThemeSwitcher, Timeline, TimelineItem, Toggle, UiStringsProvider, getAvatarHue, getAvatarInitials, useAccentColor, useConfirm, useDensity, useFloatingPanel, useTheme, useUiStrings };
3210
+ //#region packages/ui/Checkbox.tsx
3211
+ /** Native checkbox, including the mixed state used by bulk selection. */
3212
+ const Checkbox = forwardRef(function Checkbox({ label, indeterminate = false, invalid = false, id, className, ...props }, ref) {
3213
+ const generatedId = useId();
3214
+ const inputRef = useRef(null);
3215
+ useEffect(() => {
3216
+ if (inputRef.current) inputRef.current.indeterminate = indeterminate;
3217
+ }, [indeterminate]);
3218
+ return /* @__PURE__ */ jsxs("label", {
3219
+ className: `nb-selection-control${className ? ` ${className}` : ""}`,
3220
+ children: [/* @__PURE__ */ jsx("input", {
3221
+ ...props,
3222
+ id: id ?? generatedId,
3223
+ type: "checkbox",
3224
+ "aria-invalid": props["aria-invalid"] ?? (invalid || void 0),
3225
+ ref: (node) => {
3226
+ inputRef.current = node;
3227
+ if (typeof ref === "function") return ref(node);
3228
+ if (ref) ref.current = node;
3229
+ }
3230
+ }), label && /* @__PURE__ */ jsx("span", { children: label })]
3231
+ });
3232
+ });
3233
+ //#endregion
3234
+ //#region packages/ui/RadioGroup.tsx
3235
+ /** Native radios share a name for browser keyboard navigation and form submission. */
3236
+ function RadioGroup({ label, name, value, options, onChange, orientation = "vertical", required, invalid = false, disabled, className, ...props }) {
3237
+ const generatedName = useId();
3238
+ return /* @__PURE__ */ jsxs("fieldset", {
3239
+ ...props,
3240
+ disabled,
3241
+ "aria-invalid": props["aria-invalid"] ?? (invalid || void 0),
3242
+ className: `nb-radio-group${className ? ` ${className}` : ""}`,
3243
+ children: [label && /* @__PURE__ */ jsx("legend", { children: label }), /* @__PURE__ */ jsx("div", {
3244
+ className: `nb-radio-group__options nb-radio-group__options--${orientation}`,
3245
+ children: options.map((option) => /* @__PURE__ */ jsxs("label", {
3246
+ className: "nb-selection-control",
3247
+ children: [/* @__PURE__ */ jsx("input", {
3248
+ type: "radio",
3249
+ name: name ?? generatedName,
3250
+ value: option.value,
3251
+ checked: value === option.value,
3252
+ disabled: disabled || option.disabled,
3253
+ required,
3254
+ onChange: () => onChange(option.value)
3255
+ }), /* @__PURE__ */ jsx("span", { children: option.label })]
3256
+ }, option.value))
3257
+ })]
3258
+ });
3259
+ }
3260
+ //#endregion
3261
+ //#region packages/ui/Tabs.tsx
3262
+ function Tabs({ items, value, onChange, "aria-label": ariaLabel, orientation = "horizontal", activationMode = "automatic", keepMounted = false, className }) {
3263
+ const id = useId();
3264
+ const listRef = useRef(null);
3265
+ const [focusedValue, setFocusedValue] = useState(null);
3266
+ const selectedIndex = items.findIndex((item) => item.value === value && !item.disabled);
3267
+ const focusedIndex = items.findIndex((item) => item.value === focusedValue && !item.disabled);
3268
+ const tabStop = activationMode === "manual" && focusedIndex >= 0 ? focusedIndex : selectedIndex >= 0 ? selectedIndex : items.findIndex((item) => !item.disabled);
3269
+ return /* @__PURE__ */ jsxs("div", {
3270
+ className: `nb-tabs nb-tabs--${orientation}${className ? ` ${className}` : ""}`,
3271
+ children: [/* @__PURE__ */ jsx("div", {
3272
+ ref: listRef,
3273
+ role: "tablist",
3274
+ "aria-label": ariaLabel,
3275
+ "aria-orientation": orientation,
3276
+ className: "nb-tabs__list",
3277
+ children: items.map((item, index) => /* @__PURE__ */ jsx("button", {
3278
+ type: "button",
3279
+ role: "tab",
3280
+ id: `${id}-tab-${index}`,
3281
+ "aria-controls": `${id}-panel-${index}`,
3282
+ "aria-selected": index === selectedIndex,
3283
+ disabled: item.disabled,
3284
+ tabIndex: index === tabStop ? 0 : -1,
3285
+ className: "nb-tabs__tab",
3286
+ onFocus: () => setFocusedValue(item.value),
3287
+ onClick: () => onChange(item.value),
3288
+ onKeyDown: (event) => {
3289
+ const nextKey = orientation === "horizontal" ? "ArrowRight" : "ArrowDown";
3290
+ if (![
3291
+ nextKey,
3292
+ orientation === "horizontal" ? "ArrowLeft" : "ArrowUp",
3293
+ "Home",
3294
+ "End"
3295
+ ].includes(event.key)) return;
3296
+ event.preventDefault();
3297
+ const enabled = items.map((entry, i) => entry.disabled ? -1 : i).filter((i) => i >= 0);
3298
+ const position = enabled.indexOf(index);
3299
+ 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];
3300
+ if (next === void 0) return;
3301
+ listRef.current?.querySelectorAll("[role=\"tab\"]")[next]?.focus();
3302
+ if (activationMode === "automatic") onChange(items[next].value);
3303
+ },
3304
+ children: item.label
3305
+ }, item.value))
3306
+ }), items.map((item, index) => /* @__PURE__ */ jsx("div", {
3307
+ role: "tabpanel",
3308
+ id: `${id}-panel-${index}`,
3309
+ "aria-labelledby": `${id}-tab-${index}`,
3310
+ hidden: index !== selectedIndex,
3311
+ tabIndex: 0,
3312
+ className: "nb-tabs__panel",
3313
+ children: keepMounted || index === selectedIndex ? item.content : null
3314
+ }, item.value))]
3315
+ });
3316
+ }
3317
+ //#endregion
3318
+ //#region packages/ui/Spinner.tsx
3319
+ function Spinner({ label, size = "md", className, ...props }) {
3320
+ return /* @__PURE__ */ jsx("span", {
3321
+ ...props,
3322
+ className: `nb-spinner nb-spinner--${size}${className ? ` ${className}` : ""}`,
3323
+ role: label ? "status" : void 0,
3324
+ "aria-label": label,
3325
+ "aria-hidden": label ? void 0 : true
3326
+ });
3327
+ }
3328
+ //#endregion
3329
+ //#region packages/ui/Progress.tsx
3330
+ /** Omit value for indeterminate progress; max defaults to 100. */
3331
+ function Progress({ label, id, max = 100, className, ...props }) {
3332
+ const generatedId = useId();
3333
+ const progressId = id ?? generatedId;
3334
+ return /* @__PURE__ */ jsxs("div", {
3335
+ className: "nb-progress-field",
3336
+ children: [label && /* @__PURE__ */ jsx("label", {
3337
+ htmlFor: progressId,
3338
+ children: label
3339
+ }), /* @__PURE__ */ jsx("progress", {
3340
+ ...props,
3341
+ id: progressId,
3342
+ max,
3343
+ className: `nb-progress${className ? ` ${className}` : ""}`
3344
+ })]
3345
+ });
3346
+ }
3347
+ //#endregion
3348
+ //#region packages/ui/Tooltip.tsx
3349
+ const TooltipProvider = Tooltip$1.Provider;
3350
+ /** Uses the existing child as the trigger without adding a nested button. */
3351
+ function Tooltip({ children, content, side = "top", delay, disabled, className }) {
3352
+ const overlayContainer = useOverlayContainer();
3353
+ const id = useId();
3354
+ const [open, setOpen] = useState(false);
3355
+ const description = [children.props["aria-describedby"], open && !disabled ? id : void 0].filter(Boolean).join(" ") || void 0;
3356
+ return /* @__PURE__ */ jsxs(Tooltip$1.Root, {
3357
+ open,
3358
+ disabled,
3359
+ onOpenChange: setOpen,
3360
+ children: [/* @__PURE__ */ jsx(Tooltip$1.Trigger, {
3361
+ render: cloneElement(children, { "aria-describedby": description }),
3362
+ onKeyDownCapture: (event) => {
3363
+ if (open && event.key === "Escape") {
3364
+ event.stopPropagation();
3365
+ setOpen(false);
3366
+ }
3367
+ },
3368
+ delay
3369
+ }), /* @__PURE__ */ jsx(Tooltip$1.Portal, {
3370
+ container: overlayContainer ?? void 0,
3371
+ children: /* @__PURE__ */ jsx(Tooltip$1.Positioner, {
3372
+ side,
3373
+ sideOffset: 8,
3374
+ className: "nb-tooltip-positioner",
3375
+ children: /* @__PURE__ */ jsx(Tooltip$1.Popup, {
3376
+ id,
3377
+ role: "tooltip",
3378
+ className: `nb-tooltip${className ? ` ${className}` : ""}`,
3379
+ children: content
3380
+ })
3381
+ })
3382
+ })]
3383
+ });
3384
+ }
3385
+ //#endregion
3386
+ //#region packages/ui/TimePicker.tsx
3387
+ const timeValue = (value) => {
3388
+ if (!value) return null;
3389
+ try {
3390
+ return parseTime(value);
3391
+ } catch {
3392
+ return null;
3393
+ }
3394
+ };
3395
+ /** Accessible segmented time entry. Values never pass through Date or a timezone. */
3396
+ const TimePicker = forwardRef(function TimePicker({ id, name, value, onChange, onBlur, min, max, locale, hourCycle, granularity = "minute", disabled, readOnly, required, invalid, className, ariaLabel }, ref) {
3397
+ const strings = useUiStrings();
3398
+ return /* @__PURE__ */ jsx(I18nProvider, {
3399
+ locale: getDateLocale(locale),
3400
+ children: /* @__PURE__ */ jsx(TimeField, {
3401
+ id,
3402
+ name,
3403
+ "aria-label": ariaLabel ?? strings.selectTime,
3404
+ value: timeValue(value),
3405
+ onChange: (next) => onChange?.(next ? next.toString().slice(0, granularity === "second" ? 8 : 5) : ""),
3406
+ onBlur,
3407
+ minValue: timeValue(min) ?? void 0,
3408
+ maxValue: timeValue(max) ?? void 0,
3409
+ granularity,
3410
+ hourCycle,
3411
+ isDisabled: disabled,
3412
+ isReadOnly: readOnly,
3413
+ isRequired: required,
3414
+ isInvalid: invalid,
3415
+ validationBehavior: "aria",
3416
+ className: ["nb-time-picker", className].filter(Boolean).join(" "),
3417
+ children: /* @__PURE__ */ jsx(DateInput, {
3418
+ ref,
3419
+ className: "nb-time-picker__input",
3420
+ children: (segment) => /* @__PURE__ */ jsx(DateSegment, {
3421
+ segment,
3422
+ className: "nb-time-picker__segment"
3423
+ })
3424
+ })
3425
+ })
3426
+ });
3427
+ });
3428
+ //#endregion
3429
+ //#region packages/ui/DetailLayout.tsx
3430
+ /** Responsive main/aside composition for record detail pages. */
3431
+ function DetailLayout({ children, aside, asideLabel, className }) {
3432
+ return /* @__PURE__ */ jsxs("div", {
3433
+ className: joinClasses("nb-detail-layout", className),
3434
+ children: [/* @__PURE__ */ jsx("div", {
3435
+ className: "nb-detail-layout__main",
3436
+ children
3437
+ }), /* @__PURE__ */ jsx("aside", {
3438
+ className: "nb-detail-layout__aside",
3439
+ "aria-label": asideLabel,
3440
+ children: aside
3441
+ })]
3442
+ });
3443
+ }
3444
+ //#endregion
3445
+ export { ACCENT_PRESETS, Alert, AppDialog, AppDropdown, AppToolbar, Avatar, Badge, Button, Card, Checkbox, Chip, Cluster, Code, Col, CollapsibleSection, Combobox, ConfirmDialog, ContextMenu, DataTable, DatePicker, DateRangePicker, DensityContext, DensityProvider, DescriptionList, DetailLayout, Drawer, EN_UI_STRINGS, ES_UI_STRINGS, EmptyState, FeatureGate, FileDropzone, FilterPanel, FormActions, FormField, FormLayout, Grid, HubPanel, IconButton, KpiMetricRow, MultiSelect, OperationCardGrid, Page, PageHeader, Pagination, Popover, Progress, RadioGroup, Row, RowActions, ScopeTabs, SearchableAppDropdown, Section, SegmentedControl, SelectField, SettingsPanel, Skeleton, Spinner, Stack, StatCard, Tabs, Text, TextAreaField, TextField, ThemeContext, ThemeProvider, ThemeSwitcher, TimePicker, Timeline, TimelineItem, Toggle, Tooltip, TooltipProvider, UiStringsProvider, getAvatarHue, getAvatarInitials, useAccentColor, useConfirm, useDensity, useFloatingPanel, useOverlayContainer, useTheme, useUiStrings };