@aircall/ds 0.34.0 → 0.35.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.js CHANGED
@@ -1,13 +1,11 @@
1
+ import { C as Button, E as cn, S as registerI18nNamespace, T as linkStyle, _ as ActionBarHeight, a as TableFooter, b as detectInitialLanguage, c as TableRow, d as Checkbox, f as Spinner, g as ActionBarContext, h as ActionBarButton, i as TableCell, l as useFetchMoreSentinel, m as ActionBar, n as Table, o as TableHead, p as spinnerVariants, r as TableBody, s as TableHeader, t as DataTable, u as Skeleton, v as useDsTranslation, w as buttonVariants, x as dsI18n, y as SUPPORTED_LANGUAGES } from "./data-table-DpKxtE_u.js";
1
2
  import * as React from "react";
2
- import { createContext, useCallback, useContext, useSyncExternalStore } from "react";
3
+ import { createContext, useContext, useSyncExternalStore } from "react";
3
4
  import { Accordion as Accordion$1 } from "@base-ui/react/accordion";
4
- import { clsx } from "clsx";
5
- import { extendTailwindMerge } from "tailwind-merge";
6
- import { ArrowDownToLine, ArrowLeft, ArrowRight, Backward10, Bold, CalendarDaysIcon, CheckIcon, ChevronDownIcon, ChevronLeftIcon, ChevronRightIcon, ChevronUpIcon, ChevronsUpDownIcon, CircleAlert, CircleAlertIcon, CircleCheck, Code, ExternalLink, FLAGS, FastForward, FlagUs, Forward10, Info, Italic, Link, List as List$1, ListOrdered, Loader2Icon, Minus, MinusIcon, MoreHorizontalIcon, PanelLeftIcon, Pause, Play, Plus, PlusIcon, Rewind, RotateCcw, Search, Smile, Strikethrough, Text, TriangleAlertIcon, Underline, Unlink, XIcon } from "@aircall/react-icons";
5
+ import { ArrowDownToLine, ArrowLeft, ArrowRight, Backward10, Bold, CalendarDaysIcon, CheckIcon, ChevronDownIcon, ChevronLeftIcon, ChevronRightIcon, ChevronUpIcon, CircleAlert, CircleAlertIcon, CircleCheck, Code, ExternalLink, FLAGS, FastForward, FlagUs, Forward10, Info, Italic, Link, List as List$1, ListOrdered, Loader2Icon, Minus, MinusIcon, MoreHorizontalIcon, PanelLeftIcon, Pause, Play, Plus, PlusIcon, Rewind, RotateCcw, Search, Smile, Strikethrough, Text, TriangleAlertIcon, Underline, Unlink, XIcon } from "@aircall/react-icons";
7
6
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
8
7
  import { Button as Button$1 } from "@base-ui/react/button";
9
8
  import { cva } from "class-variance-authority";
10
- import i18next from "i18next";
11
9
  import { mergeProps } from "@base-ui/react/merge-props";
12
10
  import { Slider as Slider$1 } from "@base-ui/react/slider";
13
11
  import { useRender } from "@base-ui/react/use-render";
@@ -24,7 +22,6 @@ import { useVirtualizer } from "@tanstack/react-virtual";
24
22
  import { useControllableState } from "@aircall/hooks";
25
23
  import { Command as Command$1 } from "cmdk";
26
24
  import { Dialog as Dialog$1 } from "@base-ui/react/dialog";
27
- import { flexRender, getCoreRowModel, useReactTable } from "@tanstack/react-table";
28
25
  import { checkboxesFeature, hotkeysCoreFeature, selectionFeature, syncDataLoaderFeature } from "@headless-tree/core";
29
26
  import { useTree } from "@headless-tree/react";
30
27
  import { endOfDay, format, getDaysInMonth, startOfDay } from "date-fns";
@@ -64,67 +61,6 @@ import { Toaster as Toaster$1, toast } from "sonner";
64
61
  import { Switch as Switch$1 } from "@base-ui/react/switch";
65
62
  import { Tabs as Tabs$1 } from "@base-ui/react/tabs";
66
63
  import { ToggleGroup as ToggleGroup$1 } from "@base-ui/react/toggle-group";
67
- //#region src/lib/utils.ts
68
- const DS_COLORS = [
69
- "background",
70
- "foreground",
71
- "card",
72
- "card-foreground",
73
- "popover",
74
- "popover-foreground",
75
- "primary",
76
- "primary-foreground",
77
- "secondary",
78
- "secondary-foreground",
79
- "info",
80
- "info-foreground",
81
- "info-background",
82
- "success",
83
- "success-foreground",
84
- "success-background",
85
- "warning",
86
- "warning-foreground",
87
- "warning-background",
88
- "destructive",
89
- "destructive-foreground",
90
- "destructive-background",
91
- "muted",
92
- "muted-foreground",
93
- "accent",
94
- "accent-foreground",
95
- "border",
96
- "input",
97
- "ring",
98
- "chart-1",
99
- "chart-2",
100
- "chart-3",
101
- "chart-4",
102
- "chart-5",
103
- "sidebar",
104
- "sidebar-foreground",
105
- "sidebar-primary",
106
- "sidebar-primary-foreground",
107
- "sidebar-accent",
108
- "sidebar-accent-foreground",
109
- "sidebar-border",
110
- "sidebar-ring"
111
- ];
112
- const BLOCKS_COLORS = [
113
- "page-background",
114
- "navbar-foreground",
115
- "navbar-accent",
116
- "navbar-accent-foreground",
117
- "navbar-icon-bg"
118
- ];
119
- const twMerge = extendTailwindMerge({ extend: { theme: {
120
- color: [...DS_COLORS, ...BLOCKS_COLORS],
121
- text: ["tiny"],
122
- animate: ["caret-blink"]
123
- } } });
124
- function cn(...inputs) {
125
- return twMerge(clsx(inputs));
126
- }
127
- //#endregion
128
64
  //#region src/components/accordion.tsx
129
65
  /**
130
66
  * Root container for an accordion, wrapping Base UI's `Accordion.Root`.
@@ -213,469 +149,6 @@ const AccordionContent = React.forwardRef((componentProps, forwardRef) => {
213
149
  });
214
150
  AccordionContent.displayName = "AccordionContent";
215
151
  //#endregion
216
- //#region src/components/button.tsx
217
- /** Tailwind class string for link-styled buttons and anchors (primary color, underlined). */
218
- const linkStyle = "text-primary underline underline-offset-4";
219
- /** `cva` variant definitions for {@link Button} — resolves `variant`, `size`, and `block` into class names. */
220
- const buttonVariants = cva("group/button inline-flex shrink-0 items-center justify-center rounded-md border border-transparent bg-clip-padding text-sm font-medium whitespace-nowrap transition-all outline-none select-none focus-visible:ring-3 focus-visible:ring-ring/50 active:not-aria-[haspopup]:translate-y-px active:not-aria-[haspopup]:opacity-60 disabled:pointer-events-auto disabled:opacity-50 disabled:cursor-not-allowed aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4", {
221
- variants: {
222
- variant: {
223
- default: "bg-primary text-primary-foreground hover:bg-primary/90",
224
- outline: "border-border bg-background/80 text-foreground hover:bg-muted hover:text-accent-foreground aria-expanded:bg-muted aria-expanded:text-accent-foreground dark:border-input dark:hover:bg-input/50",
225
- secondary: "bg-secondary text-secondary-foreground hover:bg-secondary/80 aria-expanded:bg-secondary aria-expanded:text-secondary-foreground",
226
- ghost: "hover:bg-muted hover:text-accent-foreground aria-expanded:bg-muted aria-expanded:text-accent-foreground dark:hover:bg-input/50",
227
- destructive: "bg-destructive/10 text-destructive hover:bg-destructive/20 focus-visible:ring-destructive/20 dark:bg-destructive/20 dark:hover:bg-destructive/30 dark:focus-visible:ring-destructive/40",
228
- link: linkStyle
229
- },
230
- size: {
231
- default: "h-8 gap-1.5 px-2 has-data-[icon=inline-end]:pr-1.5 has-data-[icon=inline-start]:pl-1.5",
232
- sm: "h-6 gap-1.5 px-2 has-data-[icon=inline-end]:pr-1.5 has-data-[icon=inline-start]:pl-1.5",
233
- lg: "h-10 gap-1.5 px-4 [&_svg:not([class*='size-'])]:size-5 has-data-[icon=inline-end]:pr-3 has-data-[icon=inline-start]:pl-3",
234
- icon: "size-8",
235
- "icon-sm": "size-6",
236
- "icon-lg": "size-10 [&_svg:not([class*='size-'])]:size-6"
237
- },
238
- block: { true: "w-full" }
239
- },
240
- defaultVariants: {
241
- variant: "default",
242
- size: "default",
243
- block: false
244
- }
245
- });
246
- /**
247
- * Clickable button. Renders a Base UI `Button` primitive as a `<button>` element,
248
- * styled via `buttonVariants` (variant / size / block).
249
- *
250
- * @example
251
- * ```tsx
252
- * <Button variant="outline" size="sm">Save</Button>
253
- * ```
254
- */
255
- const Button = React.forwardRef((componentProps, forwardRef) => {
256
- const { className, variant = "default", size = "default", block = false, ...props } = componentProps;
257
- return /* @__PURE__ */ jsx(Button$1, {
258
- ref: forwardRef,
259
- "data-slot": "button",
260
- "data-variant": variant,
261
- className: cn(buttonVariants({
262
- variant,
263
- size,
264
- block,
265
- className
266
- })),
267
- ...props
268
- });
269
- });
270
- Button.displayName = "Button";
271
- //#endregion
272
- //#region src/i18n/locales/de.ts
273
- const de = {
274
- "spinner.loading": "Laden",
275
- "pagination.label": "Seitennavigation",
276
- "pagination.previousPage": "Zur vorherigen Seite",
277
- "pagination.nextPage": "Zur nächsten Seite",
278
- "dataTable.selectAllRows": "Alle Zeilen auswählen",
279
- "dataTable.selectRow": "Zeile auswählen",
280
- "dataCombobox.noResults": "Keine Ergebnisse",
281
- "tree.collapse": "Minimieren",
282
- "tree.expand": "Erweitern",
283
- "multiselect.remove": "Entfernen",
284
- "multiselect.clearAll": "Alles löschen",
285
- "multiselect.addItem": "Hinzufügen",
286
- "multiselect.search": "Suchen",
287
- "sidebar.toggle": "Seitenleiste umschalten",
288
- "drawer.close": "Schließen",
289
- "emojiPicker.emoji": "Emoji",
290
- "emojiPicker.choose": "Emoji auswählen",
291
- "actionBar.selectionActions": "Auswahlaktionen",
292
- "pagination.previous": "Zurück",
293
- "pagination.next": "Weiter",
294
- "actionBar.clearSelection": "Auswahl aufheben",
295
- "actionBar.itemsSelected": "{{count}} Elemente ausgewählt.",
296
- "fieldLabel.required": "(erforderlich)",
297
- "fieldLabel.optional": "(optional)",
298
- "fieldLabel.moreInfo": "Weitere Informationen",
299
- "datePicker.beforeMin": "Das Datum liegt vor dem frühesten verfügbaren Datum ({{date}})",
300
- "datePicker.afterMax": "Das Datum liegt nach dem spätesten verfügbaren Datum ({{date}})",
301
- "datePicker.unavailable": "Dieses Datum ist nicht verfügbar",
302
- "datePicker.rangeOrder": "Das Startdatum muss vor oder gleich dem Enddatum sein",
303
- "richTextarea.noResults": "Keine Ergebnisse",
304
- "richTextarea.slashNoCommands": "Keine Befehle",
305
- "richTextarea.bold": "Fett",
306
- "richTextarea.italic": "Kursiv",
307
- "richTextarea.underline": "Unterstrichen",
308
- "richTextarea.strikethrough": "Durchgestrichen",
309
- "richTextarea.inlineCode": "Inline-Code",
310
- "richTextarea.bulletedList": "Aufzählungsliste",
311
- "richTextarea.numberedList": "Nummerierte Liste",
312
- "richTextarea.link": "Link",
313
- "richTextarea.linkPlaceholder": "Link einfügen",
314
- "richTextarea.linkText": "Anzuzeigender Text",
315
- "richTextarea.linkEdit": "Link bearbeiten",
316
- "richTextarea.linkOpen": "Link in neuem Tab öffnen",
317
- "richTextarea.linkRemove": "Link entfernen"
318
- };
319
- //#endregion
320
- //#region src/i18n/locales/en.ts
321
- const en = {
322
- "spinner.loading": "Loading",
323
- "pagination.label": "pagination",
324
- "pagination.previousPage": "Go to previous page",
325
- "pagination.nextPage": "Go to next page",
326
- "dataTable.selectAllRows": "Select all rows",
327
- "dataTable.selectRow": "Select row",
328
- "dataCombobox.noResults": "No results found",
329
- "tree.collapse": "Collapse",
330
- "tree.expand": "Expand",
331
- "multiselect.remove": "Remove",
332
- "multiselect.clearAll": "Clear all",
333
- "multiselect.addItem": "Add item",
334
- "multiselect.search": "Search",
335
- "sidebar.toggle": "Toggle Sidebar",
336
- "drawer.close": "Close",
337
- "emojiPicker.emoji": "Emoji",
338
- "emojiPicker.choose": "Choose an emoji",
339
- "actionBar.selectionActions": "Selection actions",
340
- "pagination.previous": "Previous",
341
- "pagination.next": "Next",
342
- "actionBar.clearSelection": "Clear selection",
343
- "actionBar.itemsSelected": "{{count}} items selected.",
344
- "fieldLabel.required": "(required)",
345
- "fieldLabel.optional": "(optional)",
346
- "fieldLabel.moreInfo": "More information",
347
- "datePicker.beforeMin": "Date is before the earliest available date ({{date}})",
348
- "datePicker.afterMax": "Date is after the latest available date ({{date}})",
349
- "datePicker.unavailable": "That date isn't available",
350
- "datePicker.rangeOrder": "Start date must be on or before the end date",
351
- "richTextarea.noResults": "No results",
352
- "richTextarea.slashNoCommands": "No commands",
353
- "richTextarea.bold": "Bold",
354
- "richTextarea.italic": "Italic",
355
- "richTextarea.underline": "Underline",
356
- "richTextarea.strikethrough": "Strikethrough",
357
- "richTextarea.inlineCode": "Inline code",
358
- "richTextarea.bulletedList": "Bulleted list",
359
- "richTextarea.numberedList": "Numbered list",
360
- "richTextarea.link": "Link",
361
- "richTextarea.linkPlaceholder": "Paste link",
362
- "richTextarea.linkText": "Text to display",
363
- "richTextarea.linkEdit": "Edit link",
364
- "richTextarea.linkOpen": "Open link in a new tab",
365
- "richTextarea.linkRemove": "Remove link"
366
- };
367
- //#endregion
368
- //#region src/i18n/locales/es.ts
369
- const es = {
370
- "spinner.loading": "Cargando",
371
- "pagination.label": "paginación",
372
- "pagination.previousPage": "Ir a la página anterior",
373
- "pagination.nextPage": "Ir a la página siguiente",
374
- "dataTable.selectAllRows": "Seleccionar todas las filas",
375
- "dataTable.selectRow": "Seleccionar fila",
376
- "dataCombobox.noResults": "Sin resultados",
377
- "tree.collapse": "Minimizar",
378
- "tree.expand": "Ampliar",
379
- "multiselect.remove": "Eliminar",
380
- "multiselect.clearAll": "Borrar todo",
381
- "multiselect.addItem": "Añadir",
382
- "multiselect.search": "Buscar",
383
- "sidebar.toggle": "Alternar barra lateral",
384
- "drawer.close": "Cerrar",
385
- "emojiPicker.emoji": "Emoji",
386
- "emojiPicker.choose": "Elegir un emoji",
387
- "actionBar.selectionActions": "Acciones de selección",
388
- "pagination.previous": "Anterior",
389
- "pagination.next": "Siguiente",
390
- "actionBar.clearSelection": "Borrar selección",
391
- "actionBar.itemsSelected": "{{count}} elementos seleccionados.",
392
- "fieldLabel.required": "(obligatorio)",
393
- "fieldLabel.optional": "(opcional)",
394
- "fieldLabel.moreInfo": "Más información",
395
- "datePicker.beforeMin": "La fecha es anterior a la fecha más antigua disponible ({{date}})",
396
- "datePicker.afterMax": "La fecha es posterior a la fecha más reciente disponible ({{date}})",
397
- "datePicker.unavailable": "Esa fecha no está disponible",
398
- "datePicker.rangeOrder": "La fecha de inicio debe ser anterior o igual a la fecha de fin",
399
- "richTextarea.noResults": "Sin resultados",
400
- "richTextarea.slashNoCommands": "Sin comandos",
401
- "richTextarea.bold": "Negrita",
402
- "richTextarea.italic": "Cursiva",
403
- "richTextarea.underline": "Subrayado",
404
- "richTextarea.strikethrough": "Tachado",
405
- "richTextarea.inlineCode": "Código en línea",
406
- "richTextarea.bulletedList": "Lista con viñetas",
407
- "richTextarea.numberedList": "Lista numerada",
408
- "richTextarea.link": "Enlace",
409
- "richTextarea.linkPlaceholder": "Pegar enlace",
410
- "richTextarea.linkText": "Texto para mostrar",
411
- "richTextarea.linkEdit": "Editar enlace",
412
- "richTextarea.linkOpen": "Abrir enlace en una pestaña nueva",
413
- "richTextarea.linkRemove": "Eliminar enlace"
414
- };
415
- //#endregion
416
- //#region src/i18n/locales/fr.ts
417
- const fr = {
418
- "spinner.loading": "Chargement",
419
- "pagination.label": "pagination",
420
- "pagination.previousPage": "Aller à la page précédente",
421
- "pagination.nextPage": "Aller à la page suivante",
422
- "dataTable.selectAllRows": "Sélectionner toutes les lignes",
423
- "dataTable.selectRow": "Sélectionner la ligne",
424
- "dataCombobox.noResults": "Aucun résultat",
425
- "tree.collapse": "Réduire",
426
- "tree.expand": "Développer",
427
- "multiselect.remove": "Supprimer",
428
- "multiselect.clearAll": "Tout effacer",
429
- "multiselect.addItem": "Ajouter",
430
- "multiselect.search": "Rechercher",
431
- "sidebar.toggle": "Basculer la barre latérale",
432
- "drawer.close": "Fermer",
433
- "emojiPicker.emoji": "Émoji",
434
- "emojiPicker.choose": "Choisir un émoji",
435
- "actionBar.selectionActions": "Actions de sélection",
436
- "pagination.previous": "Précédent",
437
- "pagination.next": "Suivant",
438
- "actionBar.clearSelection": "Effacer la sélection",
439
- "actionBar.itemsSelected": "{{count}} éléments sélectionnés.",
440
- "fieldLabel.required": "(obligatoire)",
441
- "fieldLabel.optional": "(facultatif)",
442
- "fieldLabel.moreInfo": "Plus d'informations",
443
- "datePicker.beforeMin": "La date est antérieure à la date la plus ancienne disponible ({{date}})",
444
- "datePicker.afterMax": "La date est postérieure à la date la plus récente disponible ({{date}})",
445
- "datePicker.unavailable": "Cette date n'est pas disponible",
446
- "datePicker.rangeOrder": "La date de debut doit etre anterieure ou egale a la date de fin",
447
- "richTextarea.noResults": "Aucun résultat",
448
- "richTextarea.slashNoCommands": "Aucune commande",
449
- "richTextarea.bold": "Gras",
450
- "richTextarea.italic": "Italique",
451
- "richTextarea.underline": "Souligné",
452
- "richTextarea.strikethrough": "Barré",
453
- "richTextarea.inlineCode": "Code en ligne",
454
- "richTextarea.bulletedList": "Liste à puces",
455
- "richTextarea.numberedList": "Liste numérotée",
456
- "richTextarea.link": "Lien",
457
- "richTextarea.linkPlaceholder": "Coller le lien",
458
- "richTextarea.linkText": "Texte à afficher",
459
- "richTextarea.linkEdit": "Modifier le lien",
460
- "richTextarea.linkOpen": "Ouvrir le lien dans un nouvel onglet",
461
- "richTextarea.linkRemove": "Supprimer le lien"
462
- };
463
- //#endregion
464
- //#region src/i18n/locales/it.ts
465
- const it = {
466
- "spinner.loading": "Caricamento",
467
- "pagination.label": "paginazione",
468
- "pagination.nextPage": "Vai alla pagina successiva",
469
- "pagination.previousPage": "Vai alla pagina precedente",
470
- "dataTable.selectAllRows": "Seleziona tutte le righe",
471
- "dataTable.selectRow": "Seleziona riga",
472
- "dataCombobox.noResults": "Nessun risultato",
473
- "tree.collapse": "Ridurre",
474
- "tree.expand": "Espandi",
475
- "multiselect.remove": "Rimuovi",
476
- "multiselect.clearAll": "Cancella tutto",
477
- "multiselect.addItem": "Aggiungi",
478
- "multiselect.search": "Cerca",
479
- "sidebar.toggle": "Attiva/disattiva barra laterale",
480
- "drawer.close": "Chiudi",
481
- "emojiPicker.emoji": "Emoji",
482
- "emojiPicker.choose": "Scegli un emoji",
483
- "actionBar.selectionActions": "Azioni di selezione",
484
- "pagination.previous": "Precedente",
485
- "pagination.next": "Successivo",
486
- "actionBar.clearSelection": "Cancella selezione",
487
- "actionBar.itemsSelected": "{{count}} elementi selezionati.",
488
- "fieldLabel.required": "(obbligatorio)",
489
- "fieldLabel.optional": "(facoltativo)",
490
- "fieldLabel.moreInfo": "Maggiori informazioni",
491
- "datePicker.beforeMin": "La data è precedente alla prima data disponibile ({{date}})",
492
- "datePicker.afterMax": "La data è successiva all'ultima data disponibile ({{date}})",
493
- "datePicker.unavailable": "Questa data non è disponibile",
494
- "datePicker.rangeOrder": "La data di inizio deve essere precedente o uguale alla data di fine",
495
- "richTextarea.noResults": "Nessun risultato",
496
- "richTextarea.slashNoCommands": "Nessun comando",
497
- "richTextarea.bold": "Grassetto",
498
- "richTextarea.italic": "Corsivo",
499
- "richTextarea.underline": "Sottolineato",
500
- "richTextarea.strikethrough": "Barrato",
501
- "richTextarea.inlineCode": "Codice inline",
502
- "richTextarea.bulletedList": "Elenco puntato",
503
- "richTextarea.numberedList": "Elenco numerato",
504
- "richTextarea.link": "Collegamento",
505
- "richTextarea.linkPlaceholder": "Incolla il link",
506
- "richTextarea.linkText": "Testo da visualizzare",
507
- "richTextarea.linkEdit": "Modifica link",
508
- "richTextarea.linkOpen": "Apri il link in una nuova scheda",
509
- "richTextarea.linkRemove": "Rimuovi link"
510
- };
511
- //#endregion
512
- //#region src/i18n/instance.ts
513
- const SUPPORTED_LANGUAGES = [
514
- "en",
515
- "fr",
516
- "es",
517
- "de",
518
- "it"
519
- ];
520
- const FALLBACK_LANGUAGE = "en";
521
- /** Resolve the initial language from the environment, falling back to English. */
522
- function detectInitialLanguage() {
523
- if (typeof navigator === "undefined" || !navigator.language) return FALLBACK_LANGUAGE;
524
- const base = navigator.language.split("-")[0];
525
- return SUPPORTED_LANGUAGES.includes(base) ? base : FALLBACK_LANGUAGE;
526
- }
527
- /** The single private i18next instance owned by @aircall/ds. Isolated from any consumer instance. */
528
- const dsI18n = i18next.createInstance();
529
- dsI18n.init({
530
- lng: detectInitialLanguage(),
531
- fallbackLng: FALLBACK_LANGUAGE,
532
- supportedLngs: [...SUPPORTED_LANGUAGES],
533
- load: "languageOnly",
534
- ns: ["ds"],
535
- defaultNS: "ds",
536
- resources: {
537
- en: { ds: en },
538
- fr: { ds: fr },
539
- es: { ds: es },
540
- de: { ds: de },
541
- it: { ds: it }
542
- },
543
- interpolation: { escapeValue: false },
544
- keySeparator: false,
545
- returnNull: false,
546
- initImmediate: false
547
- });
548
- /** Register an additional namespace's resources into the shared instance (used by @aircall/blocks). */
549
- function registerI18nNamespace(ns, resources) {
550
- for (const [lng, bundle] of Object.entries(resources)) dsI18n.addResourceBundle(lng, ns, bundle, true, true);
551
- }
552
- //#endregion
553
- //#region src/i18n/use-ds-translation.ts
554
- function subscribe(onChange) {
555
- dsI18n.on("languageChanged", onChange);
556
- return () => dsI18n.off("languageChanged", onChange);
557
- }
558
- function getLanguageSnapshot() {
559
- return dsI18n.language;
560
- }
561
- /**
562
- * @internal
563
- * Reads translations from the shared ds instance and re-renders on language change.
564
- * Used by @aircall/ds and @aircall/blocks components only — not part of the consumer contract.
565
- */
566
- function useDsTranslation(ns) {
567
- const language = useSyncExternalStore(subscribe, getLanguageSnapshot, getLanguageSnapshot);
568
- return useCallback((key, opts) => dsI18n.t(key, {
569
- ns,
570
- ...opts
571
- }), [ns, language]);
572
- }
573
- //#endregion
574
- //#region src/components/action-bar.tsx
575
- /** Fixed height of the ActionBar (px). Single source of truth — the bar uses it
576
- * for its own height and consumers (e.g. DataTable) reserve space with it. */
577
- const ActionBarHeight = 48;
578
- /**
579
- * Lets a parent (e.g. `DataTable`) supply the selected `count` and an `onClear`
580
- * handler so an `<ActionBar>` rendered inside it doesn't have to be passed them.
581
- * Explicit `count`/`onClear` props on `ActionBar` always take precedence, so the
582
- * component still works standalone. Mirrors React Spectrum's `ActionBarContext`.
583
- */
584
- const ActionBarContext = React.createContext(null);
585
- const ActionBarButton = React.forwardRef((componentProps, forwardRef) => {
586
- const { size = "default", ...props } = componentProps;
587
- return /* @__PURE__ */ jsx(Button, {
588
- ref: forwardRef,
589
- variant: "ghost",
590
- size,
591
- ...props
592
- });
593
- });
594
- ActionBarButton.displayName = "ActionBarButton";
595
- /**
596
- * A selection action bar: shows the selected-item count with a clear button and hosts
597
- * contextual action buttons on the right. Renders a `<div role="toolbar">`. `count` and
598
- * `onClear` fall back to `ActionBarContext` (e.g. supplied by `DataTable`) when omitted.
599
- *
600
- * @example
601
- * ```tsx
602
- * <ActionBar count={3} onClear={clearSelection}>
603
- * <ActionBarButton>Delete</ActionBarButton>
604
- * </ActionBar>
605
- * ```
606
- */
607
- const ActionBar = React.forwardRef((componentProps, forwardRef) => {
608
- const { className, count, onClear, children, label, clearLabel, style, ...props } = componentProps;
609
- const t = useDsTranslation("ds");
610
- const ctx = React.useContext(ActionBarContext);
611
- const resolvedCount = count ?? ctx?.count ?? 0;
612
- const resolvedOnClear = onClear ?? ctx?.onClear;
613
- const resolvedClearLabel = clearLabel ?? t("actionBar.clearSelection");
614
- return /* @__PURE__ */ jsxs("div", {
615
- ref: forwardRef,
616
- role: "toolbar",
617
- "aria-label": t("actionBar.selectionActions"),
618
- "data-slot": "action-bar",
619
- className: cn("relative flex w-full items-center gap-2 rounded-md border border-border bg-popover px-2 text-popover-foreground shadow-lg", className),
620
- style: {
621
- ...style,
622
- height: 48
623
- },
624
- ...props,
625
- children: [
626
- resolvedOnClear ? /* @__PURE__ */ jsx(ActionBarButton, {
627
- size: "icon",
628
- onClick: resolvedOnClear,
629
- "aria-label": resolvedClearLabel,
630
- children: /* @__PURE__ */ jsx(XIcon, {})
631
- }) : null,
632
- /* @__PURE__ */ jsx("span", {
633
- className: "flex-1 truncate text-sm",
634
- children: label ? label(resolvedCount) : t("actionBar.itemsSelected", { count: resolvedCount })
635
- }),
636
- children ? /* @__PURE__ */ jsx("div", {
637
- className: "flex shrink-0 items-center gap-2",
638
- children
639
- }) : null
640
- ]
641
- });
642
- });
643
- ActionBar.displayName = "ActionBar";
644
- //#endregion
645
- //#region src/components/spinner.tsx
646
- /** Class variants for `Spinner`, controlling its `size` (`default`, `sm`, `lg`, `xl`). */
647
- const spinnerVariants = cva("animate-spin text-current", {
648
- variants: { size: {
649
- default: "size-4",
650
- sm: "size-3",
651
- lg: "size-5",
652
- xl: "size-6"
653
- } },
654
- defaultVariants: { size: "default" }
655
- });
656
- /**
657
- * Animated loading indicator. Renders a spinning `<svg>` (Loader icon) with
658
- * `role="status"` and a localized `aria-label` for assistive technology.
659
- *
660
- * @example
661
- * ```tsx
662
- * <Spinner size="lg" />
663
- * ```
664
- */
665
- const Spinner = React.forwardRef((componentProps, forwardRef) => {
666
- const { className, size, ...props } = componentProps;
667
- const t = useDsTranslation("ds");
668
- return /* @__PURE__ */ jsx(Loader2Icon, {
669
- ref: forwardRef,
670
- "data-slot": "spinner",
671
- role: "status",
672
- "aria-label": t("spinner.loading"),
673
- className: cn(spinnerVariants({ size }), className),
674
- ...props
675
- });
676
- });
677
- Spinner.displayName = "Spinner";
678
- //#endregion
679
152
  //#region src/components/audio-player.tsx
680
153
  const AudioPlayerContext = React.createContext(null);
681
154
  const AudioPlayerTimeContext = React.createContext(null);
@@ -3269,34 +2742,6 @@ const CarouselNext = React.forwardRef((componentProps, forwardRef) => {
3269
2742
  });
3270
2743
  CarouselNext.displayName = "CarouselNext";
3271
2744
  //#endregion
3272
- //#region src/components/checkbox.tsx
3273
- /**
3274
- * A checkbox for toggling a single value, wrapping Base UI's `Checkbox.Root`.
3275
- * Renders a `<button role="checkbox">` containing a check (checked) or minus
3276
- * (indeterminate) indicator.
3277
- *
3278
- * @example
3279
- * ```tsx
3280
- * <Checkbox defaultChecked />
3281
- * ```
3282
- */
3283
- const Checkbox = React.forwardRef((componentProps, forwardRef) => {
3284
- const { className, ...props } = componentProps;
3285
- return /* @__PURE__ */ jsx(Checkbox$1.Root, {
3286
- ref: forwardRef,
3287
- "data-slot": "checkbox",
3288
- className: cn("peer relative flex size-4 shrink-0 items-center justify-center rounded-[4px] border border-input transition-[color,box-shadow,opacity] outline-none active:opacity-60 group-has-disabled/field:opacity-50 after:absolute after:-inset-x-3 after:-inset-y-2 focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 data-disabled:cursor-not-allowed data-disabled:bg-input/50 data-disabled:opacity-50 dark:data-disabled:bg-input/80 aria-invalid:border-destructive focus-visible:aria-invalid:ring-3 focus-visible:aria-invalid:ring-destructive/20 hover:aria-invalid:data-unchecked:bg-destructive-background focus-visible:aria-invalid:data-unchecked:bg-destructive-background bg-background dark:bg-input/30 dark:aria-invalid:border-destructive/50 dark:focus-visible:aria-invalid:ring-destructive/40 data-checked:border-primary data-checked:bg-primary data-checked:text-primary-foreground data-indeterminate:border-primary data-indeterminate:bg-primary data-indeterminate:text-primary-foreground aria-invalid:data-checked:border-destructive aria-invalid:data-checked:bg-destructive aria-invalid:data-indeterminate:border-destructive aria-invalid:data-indeterminate:bg-destructive dark:data-checked:bg-primary dark:data-indeterminate:bg-primary", className),
3289
- ...props,
3290
- children: /* @__PURE__ */ jsxs(Checkbox$1.Indicator, {
3291
- "data-slot": "checkbox-indicator",
3292
- keepMounted: true,
3293
- className: "group/indicator grid place-content-center text-current transition-none [&>svg]:size-3.5",
3294
- children: [/* @__PURE__ */ jsx(CheckIcon, { className: "hidden group-data-[checked]/indicator:block" }), /* @__PURE__ */ jsx(MinusIcon, { className: "hidden group-data-[indeterminate]/indicator:block" })]
3295
- })
3296
- });
3297
- });
3298
- Checkbox.displayName = "Checkbox";
3299
- //#endregion
3300
2745
  //#region src/components/chip.tsx
3301
2746
  const chipGlowVariants = cva("", {
3302
2747
  variants: {
@@ -3882,95 +3327,8 @@ function useComboboxAnchor() {
3882
3327
  return React.useRef(null);
3883
3328
  }
3884
3329
  //#endregion
3885
- //#region src/components/skeleton.tsx
3886
- /**
3887
- * Pulsing placeholder shown while content is loading. Renders a `<div>`;
3888
- * set its dimensions via `className` to match the content it stands in for.
3889
- *
3890
- * @example
3891
- * ```tsx
3892
- * <Skeleton className="h-4 w-32" />
3893
- * ```
3894
- */
3895
- const Skeleton = React.forwardRef((componentProps, forwardRef) => {
3896
- const { className, ...props } = componentProps;
3897
- return /* @__PURE__ */ jsx("div", {
3898
- ref: forwardRef,
3899
- "data-slot": "skeleton",
3900
- className: cn("animate-pulse rounded-md bg-muted", className),
3901
- ...props
3902
- });
3903
- });
3904
- Skeleton.displayName = "Skeleton";
3905
- //#endregion
3906
- //#region src/lib/use-fetch-more-sentinel.ts
3907
- /**
3908
- * Returns a callback ref for a scroll sentinel element placed at the bottom of a
3909
- * scrollable list. When the sentinel scrolls into view (within `rootMargin`),
3910
- * `onFetchMore` fires once. The observer is (re)attached whenever the sentinel
3911
- * node mounts — so it works even if the sentinel only appears after the first
3912
- * page loads — and re-arms whenever `resetKey` changes (a page arrived, or the
3913
- * list reset), so pagination keeps going while the sentinel stays in view and
3914
- * pauses once it scrolls away. It fires at most once per intersection, so a
3915
- * sentinel that stays in view can't trigger duplicate loads or a tight retry
3916
- * loop when a fetch fails and the data is unchanged.
3917
- *
3918
- * `getRoot` resolves the scroll container the sentinel is measured against, given
3919
- * the sentinel node — return the scrolling ancestor (a table container, a
3920
- * combobox list, …) so `rootMargin` gives prefetch headroom inside a clipped
3921
- * scroll area, or `null` to measure against the viewport.
3922
- *
3923
- * @example
3924
- * ```tsx
3925
- * const sentinelRef = useFetchMoreSentinel<HTMLDivElement>(
3926
- * onFetchMore,
3927
- * node => node.closest<HTMLElement>('[data-slot="combobox-list"]'),
3928
- * items.length
3929
- * );
3930
- * // …later, at the bottom of the list:
3931
- * <div aria-hidden ref={sentinelRef} />
3932
- * ```
3933
- */
3934
- function useFetchMoreSentinel(onFetchMore, getRoot, resetKey) {
3935
- const onFetchMoreRef = React.useRef(onFetchMore);
3936
- onFetchMoreRef.current = onFetchMore;
3937
- const getRootRef = React.useRef(getRoot);
3938
- getRootRef.current = getRoot;
3939
- const observerRef = React.useRef(null);
3940
- const nodeRef = React.useRef(null);
3941
- const armedRef = React.useRef(true);
3942
- const observe = React.useCallback(() => {
3943
- observerRef.current?.disconnect();
3944
- observerRef.current = null;
3945
- const node = nodeRef.current;
3946
- if (!node) return;
3947
- const root = getRootRef.current(node);
3948
- const observer = new IntersectionObserver((entries) => {
3949
- if (entries[entries.length - 1]?.isIntersecting) {
3950
- if (armedRef.current) {
3951
- armedRef.current = false;
3952
- onFetchMoreRef.current?.();
3953
- }
3954
- } else armedRef.current = true;
3955
- }, {
3956
- root,
3957
- rootMargin: "200px"
3958
- });
3959
- observer.observe(node);
3960
- observerRef.current = observer;
3961
- }, []);
3962
- React.useEffect(() => {
3963
- armedRef.current = true;
3964
- observe();
3965
- }, [resetKey, observe]);
3966
- return React.useCallback((node) => {
3967
- nodeRef.current = node;
3968
- observe();
3969
- }, [observe]);
3970
- }
3971
- //#endregion
3972
3330
  //#region src/components/combobox-rows.tsx
3973
- const DEFAULT_SKELETON_COUNT$1 = 5;
3331
+ const DEFAULT_SKELETON_COUNT = 5;
3974
3332
  const DEFAULT_ROW_HEIGHT = 36;
3975
3333
  const VIRTUAL_ROW_OVERSCAN = 8;
3976
3334
  /**
@@ -4015,7 +3373,7 @@ function useComboboxItemGroups(items, getGroupKey, getGroupLabel) {
4015
3373
  * Internal to the package: not exported from `src/index.ts`.
4016
3374
  */
4017
3375
  function ComboboxRows(componentProps) {
4018
- const { items, groups, getItemValue, getItemLabel, renderItem, disabledKeys, loadingState = "idle", skeletonCount = DEFAULT_SKELETON_COUNT$1, onFetchMore, hasMore = false, emptyState, listClassName, listTabIndex, virtualizeRows = false, estimateRowHeight = DEFAULT_ROW_HEIGHT, scrollRowIntoViewRef, "aria-label": ariaLabel } = componentProps;
3376
+ const { items, groups, getItemValue, getItemLabel, renderItem, disabledKeys, loadingState = "idle", skeletonCount = DEFAULT_SKELETON_COUNT, onFetchMore, hasMore = false, emptyState, listClassName, listTabIndex, virtualizeRows = false, estimateRowHeight = DEFAULT_ROW_HEIGHT, scrollRowIntoViewRef, "aria-label": ariaLabel } = componentProps;
4019
3377
  const isInitialLoading = loadingState === "loading";
4020
3378
  const isFiltering = loadingState === "filtering";
4021
3379
  const isLoadingMore = loadingState === "loadingMore";
@@ -4190,7 +3548,7 @@ function ComboboxSkeletonRows({ count }) {
4190
3548
  }
4191
3549
  //#endregion
4192
3550
  //#region src/lib/use-combobox-item-selection.ts
4193
- const EMPTY_KEYS$1 = /* @__PURE__ */ new Set();
3551
+ const EMPTY_KEYS = /* @__PURE__ */ new Set();
4194
3552
  /**
4195
3553
  * The `onInputValueChange` reasons a POPUP combobox forwards to `onSearch`
4196
3554
  * (`DataCombobox`'s three layouts):
@@ -4246,7 +3604,7 @@ function useComboboxItemSelection(options) {
4246
3604
  prop: selectedKeys,
4247
3605
  defaultProp: defaultSelectedKeys
4248
3606
  });
4249
- const keys = selectionSet ?? EMPTY_KEYS$1;
3607
+ const keys = selectionSet ?? EMPTY_KEYS;
4250
3608
  const selectedObjects = [];
4251
3609
  for (const key of keys) {
4252
3610
  const item = itemCache.get(key);
@@ -4869,560 +4227,6 @@ function DataCombobox(componentProps) {
4869
4227
  }, selectionMode);
4870
4228
  }
4871
4229
  //#endregion
4872
- //#region src/components/table.tsx
4873
- /**
4874
- * Root data table. Renders a `<table>` inside a scrollable, bordered `<div>` container.
4875
- *
4876
- * @example
4877
- * ```tsx
4878
- * <Table>
4879
- * <TableHeader>
4880
- * <TableRow>
4881
- * <TableHead>Name</TableHead>
4882
- * </TableRow>
4883
- * </TableHeader>
4884
- * <TableBody>
4885
- * <TableRow>
4886
- * <TableCell>Ada</TableCell>
4887
- * </TableRow>
4888
- * </TableBody>
4889
- * </Table>
4890
- * ```
4891
- */
4892
- const Table = React.forwardRef((componentProps, forwardRef) => {
4893
- const { className, containerClassName, containerStyle, containerRef, ...props } = componentProps;
4894
- return /* @__PURE__ */ jsx("div", {
4895
- ref: containerRef,
4896
- "data-slot": "table-container",
4897
- style: containerStyle,
4898
- className: cn("relative w-full overflow-x-auto rounded-lg border border-border", containerClassName),
4899
- children: /* @__PURE__ */ jsx("table", {
4900
- ref: forwardRef,
4901
- "data-slot": "table",
4902
- className: cn("w-full caption-bottom text-sm text-foreground bg-background [&_tbody_tr:last-child]:border-b-0", className),
4903
- ...props
4904
- })
4905
- });
4906
- });
4907
- Table.displayName = "Table";
4908
- /** Table header section. Renders a `<thead>`; place `TableRow`/`TableHead` inside it. */
4909
- const TableHeader = React.forwardRef((componentProps, forwardRef) => {
4910
- const { className, ...props } = componentProps;
4911
- return /* @__PURE__ */ jsx("thead", {
4912
- ref: forwardRef,
4913
- "data-slot": "table-header",
4914
- className: cn("bg-background [&_tr]:border-b [&_tr]:hover:bg-transparent", className),
4915
- ...props
4916
- });
4917
- });
4918
- TableHeader.displayName = "TableHeader";
4919
- /** Table body section. Renders a `<tbody>` holding the data `TableRow`s. */
4920
- const TableBody = React.forwardRef((componentProps, forwardRef) => {
4921
- const { className, ...props } = componentProps;
4922
- return /* @__PURE__ */ jsx("tbody", {
4923
- ref: forwardRef,
4924
- "data-slot": "table-body",
4925
- className: cn("bg-background [&_tr:last-child]:border-0", className),
4926
- ...props
4927
- });
4928
- });
4929
- TableBody.displayName = "TableBody";
4930
- /** Table footer section. Renders a muted `<tfoot>`, e.g. for totals or summary rows. */
4931
- const TableFooter = React.forwardRef((componentProps, forwardRef) => {
4932
- const { className, ...props } = componentProps;
4933
- return /* @__PURE__ */ jsx("tfoot", {
4934
- ref: forwardRef,
4935
- "data-slot": "table-footer",
4936
- className: cn("border-t bg-muted/50 font-medium [&>tr]:last:border-b-0 [&>tr]:hover:bg-transparent", className),
4937
- ...props
4938
- });
4939
- });
4940
- TableFooter.displayName = "TableFooter";
4941
- /** A single table row. Renders a `<tr>`; highlights on hover and when `data-state="selected"`. */
4942
- const TableRow = React.forwardRef((componentProps, forwardRef) => {
4943
- const { className, ...props } = componentProps;
4944
- return /* @__PURE__ */ jsx("tr", {
4945
- ref: forwardRef,
4946
- "data-slot": "table-row",
4947
- className: cn("border-b transition-colors hover:bg-accent/30 data-[state=selected]:bg-accent/50", className),
4948
- ...props
4949
- });
4950
- });
4951
- TableRow.displayName = "TableRow";
4952
- /** A header cell. Renders a `<th>` with medium-weight, left-aligned text. */
4953
- const TableHead = React.forwardRef((componentProps, forwardRef) => {
4954
- const { className, ...props } = componentProps;
4955
- return /* @__PURE__ */ jsx("th", {
4956
- ref: forwardRef,
4957
- "data-slot": "table-head",
4958
- className: cn("h-10 px-2 text-left align-middle font-medium whitespace-nowrap text-foreground [&:has([role=checkbox])]:pr-0", className),
4959
- ...props
4960
- });
4961
- });
4962
- TableHead.displayName = "TableHead";
4963
- /** A data cell. Renders a `<td>` with middle-aligned content. */
4964
- const TableCell = React.forwardRef((componentProps, forwardRef) => {
4965
- const { className, ...props } = componentProps;
4966
- return /* @__PURE__ */ jsx("td", {
4967
- ref: forwardRef,
4968
- "data-slot": "table-cell",
4969
- className: cn("p-2 align-middle whitespace-nowrap [&:has([role=checkbox])]:pr-0", className),
4970
- ...props
4971
- });
4972
- });
4973
- TableCell.displayName = "TableCell";
4974
- //#endregion
4975
- //#region src/lib/use-horizontal-scroll-edges.ts
4976
- /**
4977
- * Tracks whether a horizontally scrollable container is flush with its left
4978
- * and/or right content edge. Used by pinned DataTable columns to show an edge
4979
- * separator only while content is obscured behind the pin.
4980
- *
4981
- * @param contentSizeKey - Optional signal that content width may have changed
4982
- * without the container box resizing (e.g. column sizes / `table.getTotalSize()`).
4983
- * Re-runs the edge measurement when it changes.
4984
- */
4985
- function useHorizontalScrollEdges(containerRef, enabled, contentSizeKey) {
4986
- const [atLeftEdge, setAtLeftEdge] = React.useState(true);
4987
- const [atRightEdge, setAtRightEdge] = React.useState(true);
4988
- React.useEffect(() => {
4989
- if (!enabled) {
4990
- setAtLeftEdge(true);
4991
- setAtRightEdge(true);
4992
- return;
4993
- }
4994
- const el = containerRef.current;
4995
- if (!el) return;
4996
- const update = () => {
4997
- const { scrollLeft, scrollWidth, clientWidth } = el;
4998
- setAtLeftEdge(scrollLeft <= 0);
4999
- setAtRightEdge(scrollLeft + clientWidth >= scrollWidth - 1);
5000
- };
5001
- update();
5002
- el.addEventListener("scroll", update, { passive: true });
5003
- window.addEventListener("resize", update);
5004
- const ro = typeof ResizeObserver !== "undefined" ? new ResizeObserver(update) : null;
5005
- ro?.observe(el);
5006
- const content = el.querySelector("[data-slot=\"table\"]") ?? el.firstElementChild;
5007
- if (content instanceof HTMLElement && content !== el) ro?.observe(content);
5008
- return () => {
5009
- el.removeEventListener("scroll", update);
5010
- window.removeEventListener("resize", update);
5011
- ro?.disconnect();
5012
- };
5013
- }, [
5014
- containerRef,
5015
- enabled,
5016
- contentSizeKey
5017
- ]);
5018
- return {
5019
- atLeftEdge,
5020
- atRightEdge
5021
- };
5022
- }
5023
- //#endregion
5024
- //#region src/components/data-table.tsx
5025
- const SELECT_COLUMN_ID = "__select";
5026
- const DEFAULT_SKELETON_COUNT = 5;
5027
- const EMPTY_KEYS = /* @__PURE__ */ new Set();
5028
- const EMPTY_COLUMN_PINNING = {
5029
- left: [],
5030
- right: []
5031
- };
5032
- /**
5033
- * Data grid built on TanStack Table. Renders a `<div>` wrapper around a DS
5034
- * `<Table>` (`<table>`), driven by `columns` + `data`, with opt-in sorting,
5035
- * row selection, column resizing, column pinning (`meta.pin`), virtualization,
5036
- * infinite scroll, a floating action bar, and loading/empty states.
5037
- *
5038
- * @example
5039
- * ```tsx
5040
- * <DataTable
5041
- * columns={columns}
5042
- * data={rows}
5043
- * getRowId={row => row.id}
5044
- * />
5045
- * ```
5046
- */
5047
- function DataTable(componentProps) {
5048
- const { columns, data, getRowId, loadingState = "idle", skeletonCount = DEFAULT_SKELETON_COUNT, emptyState, sorting, onSortingChange, selectionMode = "none", selectedKeys, defaultSelectedKeys, onSelectionChange, disabledKeys, disabledBehavior = "all", actionBar, onFetchMore, hasMore = false, enableColumnResizing = false, fillHeight = false, fixedLayout = false, onRowClick, className } = componentProps;
5049
- const sortingEnabled = !!onSortingChange;
5050
- const selectionEnabled = selectionMode !== "none";
5051
- const multiSelect = selectionMode === "multiple";
5052
- const disabledKeySet = disabledKeys ?? EMPTY_KEYS;
5053
- const userColumnPinning = React.useMemo(() => deriveColumnPinning(columns), [columns]);
5054
- const hasUserPinnedColumns = (userColumnPinning.left?.length ?? 0) > 0 || (userColumnPinning.right?.length ?? 0) > 0;
5055
- const finalColumns = React.useMemo(() => {
5056
- if (!selectionEnabled) return columns;
5057
- return [makeSelectColumn(multiSelect, { pin: hasUserPinnedColumns }), ...columns];
5058
- }, [
5059
- columns,
5060
- selectionEnabled,
5061
- multiSelect,
5062
- hasUserPinnedColumns
5063
- ]);
5064
- const columnPinning = React.useMemo(() => deriveColumnPinning(finalColumns), [finalColumns]);
5065
- const hasPinnedColumns = (columnPinning.left?.length ?? 0) > 0 || (columnPinning.right?.length ?? 0) > 0;
5066
- const [selectionSet, setSelectionSet] = useControllableState({
5067
- prop: selectedKeys,
5068
- defaultProp: defaultSelectedKeys,
5069
- onChange: onSelectionChange
5070
- });
5071
- const selection = selectionSet ?? EMPTY_KEYS;
5072
- const rowSelection = React.useMemo(() => {
5073
- const record = {};
5074
- for (const key of selection) record[key] = true;
5075
- return record;
5076
- }, [selection]);
5077
- const handleRowSelectionChange = React.useCallback((updater) => {
5078
- const next = typeof updater === "function" ? updater(rowSelection) : updater;
5079
- setSelectionSet(new Set(Object.keys(next).filter((key) => next[key])));
5080
- }, [rowSelection, setSelectionSet]);
5081
- const table = useReactTable({
5082
- data,
5083
- columns: finalColumns,
5084
- getCoreRowModel: getCoreRowModel(),
5085
- getRowId,
5086
- enableSorting: sortingEnabled,
5087
- manualSorting: sortingEnabled,
5088
- enableRowSelection: selectionEnabled ? (row) => !disabledKeySet.has(row.id) : false,
5089
- enableMultiRowSelection: multiSelect,
5090
- enableColumnResizing,
5091
- enableColumnPinning: hasPinnedColumns,
5092
- columnResizeMode: "onChange",
5093
- onSortingChange,
5094
- onRowSelectionChange: handleRowSelectionChange,
5095
- state: {
5096
- ...sorting !== void 0 && { sorting },
5097
- rowSelection,
5098
- ...hasPinnedColumns && { columnPinning }
5099
- }
5100
- });
5101
- const rows = table.getRowModel().rows;
5102
- const selectedCount = table.getSelectedRowModel().rows.length;
5103
- const hasSelection = selectedCount > 0;
5104
- const hasFooter = finalColumns.some((col) => col.footer != null);
5105
- const isInitialLoading = loadingState === "loading";
5106
- const isRefreshing = loadingState === "sorting" || loadingState === "filtering";
5107
- const isLoadingMore = loadingState === "loadingMore";
5108
- const showEmptyState = !isInitialLoading && rows.length === 0 && !!emptyState;
5109
- const anySelected = hasSelection;
5110
- const rowClickable = selectionEnabled || !!onRowClick;
5111
- const isRowInert = (row) => disabledBehavior === "all" && disabledKeySet.has(row.id);
5112
- const handleRowActivate = (row) => {
5113
- if (isRowInert(row)) return;
5114
- if (selectionEnabled && (anySelected || !onRowClick)) {
5115
- if (row.getCanSelect()) row.toggleSelected();
5116
- } else if (onRowClick) onRowClick(row.original);
5117
- };
5118
- const virtualizeRows = (componentProps.virtualizeRows ?? false) && fillHeight;
5119
- const pinWidths = enableColumnResizing || virtualizeRows || fixedLayout || hasPinnedColumns;
5120
- const containerRef = React.useRef(null);
5121
- const { atLeftEdge, atRightEdge } = useHorizontalScrollEdges(containerRef, hasPinnedColumns, table.getTotalSize());
5122
- const getCellPinProps = (column, variant) => getPinnedCellProps(column, {
5123
- pinWidths,
5124
- variant,
5125
- fillHeight,
5126
- showLeftEdgeShadow: !atLeftEdge,
5127
- showRightEdgeShadow: !atRightEdge
5128
- });
5129
- const rowVirtualizer = useVirtualizer({
5130
- count: virtualizeRows ? rows.length : 0,
5131
- getScrollElement: () => virtualizeRows ? containerRef.current : null,
5132
- estimateSize: () => 48,
5133
- measureElement: typeof window !== "undefined" && navigator.userAgent.indexOf("Firefox") === -1 ? (el) => el?.getBoundingClientRect().height : void 0,
5134
- overscan: 5
5135
- });
5136
- const virtualItems = virtualizeRows ? rowVirtualizer.getVirtualItems() : null;
5137
- const paddingTop = virtualItems && virtualItems.length > 0 ? virtualItems[0].start : 0;
5138
- const paddingBottom = virtualItems && virtualItems.length > 0 ? rowVirtualizer.getTotalSize() - virtualItems[virtualItems.length - 1].end : 0;
5139
- const showActionBar = !!actionBar && hasSelection;
5140
- const reservedBottom = showActionBar ? 64 : void 0;
5141
- const sentinelRef = useFetchMoreSentinel(onFetchMore, (node) => fillHeight ? node.closest("[data-slot=\"table-container\"]") : null, data.length);
5142
- const leafColumnCount = table.getVisibleLeafColumns().length;
5143
- return /* @__PURE__ */ jsxs("div", {
5144
- className: cn("relative w-full", fillHeight && "flex min-h-0 flex-1 flex-col", className),
5145
- "aria-busy": isInitialLoading || isRefreshing || void 0,
5146
- children: [
5147
- /* @__PURE__ */ jsxs(Table, {
5148
- containerRef,
5149
- className: cn(pinWidths && "table-fixed", hasPinnedColumns && cn("border-separate border-spacing-0", "[&_[data-slot=table-cell]]:border-b [&_[data-slot=table-cell]]:border-border", "[&_tbody_tr:last-child_[data-slot=table-cell]]:border-b-0", "[&_tfoot_[data-slot=table-cell]]:border-t [&_tfoot_tr:last-child_[data-slot=table-cell]]:border-b-0", !fillHeight && "[&_[data-slot=table-head]]:border-b [&_[data-slot=table-head]]:border-border"), fillHeight && "[&_[data-slot=table-head]]:sticky [&_[data-slot=table-head]]:top-0 [&_[data-slot=table-head]]:z-10 [&_[data-slot=table-head]]:bg-background [&_thead_tr]:border-b-0 [&_[data-slot=table-head]]:shadow-[inset_0_-1px_0_0_var(--border)]", fillHeight && showEmptyState && "h-full"),
5150
- containerClassName: fillHeight ? "min-h-0 flex-1 overflow-y-auto" : void 0,
5151
- containerStyle: reservedBottom ? {
5152
- paddingBottom: reservedBottom,
5153
- scrollPaddingBottom: reservedBottom
5154
- } : void 0,
5155
- style: pinWidths ? { width: `max(100%, ${table.getTotalSize()}px)` } : void 0,
5156
- children: [
5157
- /* @__PURE__ */ jsx(TableHeader, { children: table.getHeaderGroups().map((headerGroup) => /* @__PURE__ */ jsx(TableRow, {
5158
- className: enableColumnResizing ? "group/header-row" : void 0,
5159
- children: headerGroup.headers.map((header) => {
5160
- const pinProps = getCellPinProps(header.column, "header");
5161
- return /* @__PURE__ */ jsxs(TableHead, {
5162
- style: pinProps.style,
5163
- className: cn(enableColumnResizing && "relative", pinProps.className),
5164
- children: [header.isPlaceholder ? null : header.column.getCanSort() ? /* @__PURE__ */ jsx(SortableHeader, { header }) : flexRender(header.column.columnDef.header, header.getContext()), enableColumnResizing && header.column.getCanResize() ? /* @__PURE__ */ jsx(ResizeHandle, { header }) : null]
5165
- }, header.id);
5166
- })
5167
- }, headerGroup.id)) }),
5168
- /* @__PURE__ */ jsx(TableBody, { children: isInitialLoading ? /* @__PURE__ */ jsx(SkeletonRows, {
5169
- columns: table.getVisibleLeafColumns(),
5170
- count: skeletonCount,
5171
- getCellPinProps,
5172
- groupRows: hasPinnedColumns
5173
- }) : rows.length ? /* @__PURE__ */ jsxs(Fragment, { children: [
5174
- virtualItems ? /* @__PURE__ */ jsxs(Fragment, { children: [
5175
- paddingTop > 0 && /* @__PURE__ */ jsx("tr", {
5176
- "aria-hidden": true,
5177
- children: /* @__PURE__ */ jsx("td", {
5178
- colSpan: leafColumnCount,
5179
- style: { height: paddingTop }
5180
- })
5181
- }),
5182
- virtualItems.map((vi) => {
5183
- const row = rows[vi.index];
5184
- const inert = isRowInert(row);
5185
- const clickable = rowClickable && !inert;
5186
- return /* @__PURE__ */ jsx(TableRow, {
5187
- ref: (node) => rowVirtualizer.measureElement(node),
5188
- "data-index": vi.index,
5189
- "data-state": row.getIsSelected() ? "selected" : void 0,
5190
- "aria-disabled": inert || void 0,
5191
- onClick: clickable ? () => handleRowActivate(row) : void 0,
5192
- className: cn(hasPinnedColumns && "group", clickable && "cursor-pointer", inert && "opacity-50"),
5193
- children: row.getVisibleCells().map((cell) => {
5194
- const pinProps = getCellPinProps(cell.column, "body");
5195
- return /* @__PURE__ */ jsx(TableCell, {
5196
- style: pinProps.style,
5197
- className: pinProps.className,
5198
- children: flexRender(cell.column.columnDef.cell, cell.getContext())
5199
- }, cell.id);
5200
- })
5201
- }, row.id);
5202
- }),
5203
- paddingBottom > 0 && /* @__PURE__ */ jsx("tr", {
5204
- "aria-hidden": true,
5205
- children: /* @__PURE__ */ jsx("td", {
5206
- colSpan: leafColumnCount,
5207
- style: { height: paddingBottom }
5208
- })
5209
- })
5210
- ] }) : rows.map((row) => {
5211
- const inert = isRowInert(row);
5212
- const clickable = rowClickable && !inert;
5213
- return /* @__PURE__ */ jsx(TableRow, {
5214
- "data-state": row.getIsSelected() ? "selected" : void 0,
5215
- "aria-disabled": inert || void 0,
5216
- onClick: clickable ? () => handleRowActivate(row) : void 0,
5217
- className: cn(hasPinnedColumns && "group", clickable && "cursor-pointer", inert && "opacity-50"),
5218
- children: row.getVisibleCells().map((cell) => {
5219
- const pinProps = getCellPinProps(cell.column, "body");
5220
- return /* @__PURE__ */ jsx(TableCell, {
5221
- style: pinProps.style,
5222
- className: pinProps.className,
5223
- children: flexRender(cell.column.columnDef.cell, cell.getContext())
5224
- }, cell.id);
5225
- })
5226
- }, row.id);
5227
- }),
5228
- isLoadingMore ? /* @__PURE__ */ jsx(TableRow, {
5229
- className: "hover:bg-transparent",
5230
- children: /* @__PURE__ */ jsx(TableCell, {
5231
- colSpan: leafColumnCount,
5232
- className: "py-3",
5233
- children: /* @__PURE__ */ jsx("div", {
5234
- className: "flex items-center justify-center text-muted-foreground",
5235
- children: /* @__PURE__ */ jsx(Spinner, {})
5236
- })
5237
- })
5238
- }) : null,
5239
- onFetchMore && hasMore && !isLoadingMore ? /* @__PURE__ */ jsx("tr", {
5240
- "aria-hidden": true,
5241
- ref: sentinelRef,
5242
- children: /* @__PURE__ */ jsx("td", {
5243
- colSpan: leafColumnCount,
5244
- className: "h-px"
5245
- })
5246
- }) : null
5247
- ] }) : emptyState ? /* @__PURE__ */ jsx(TableRow, {
5248
- className: "hover:bg-transparent",
5249
- children: /* @__PURE__ */ jsx(TableCell, {
5250
- colSpan: leafColumnCount,
5251
- className: "h-full p-0",
5252
- children: /* @__PURE__ */ jsx("div", {
5253
- className: cn("flex h-full items-center justify-center", !fillHeight && "min-h-60"),
5254
- children: emptyState
5255
- })
5256
- })
5257
- }) : null }),
5258
- hasFooter && !isInitialLoading ? /* @__PURE__ */ jsx(TableFooter, { children: table.getFooterGroups().map((footerGroup) => /* @__PURE__ */ jsx(TableRow, { children: footerGroup.headers.map((header) => {
5259
- const pinProps = getCellPinProps(header.column, "footer");
5260
- return /* @__PURE__ */ jsx(TableCell, {
5261
- style: pinProps.style,
5262
- className: pinProps.className,
5263
- children: header.isPlaceholder ? null : flexRender(header.column.columnDef.footer, header.getContext())
5264
- }, header.id);
5265
- }) }, footerGroup.id)) }) : null
5266
- ]
5267
- }),
5268
- isRefreshing ? /* @__PURE__ */ jsx("div", {
5269
- "data-slot": "table-loading-overlay",
5270
- className: "bg-background/60 absolute inset-0 z-40 flex items-center justify-center",
5271
- children: /* @__PURE__ */ jsx(Spinner, {
5272
- size: "lg",
5273
- className: "text-muted-foreground"
5274
- })
5275
- }) : null,
5276
- showActionBar ? /* @__PURE__ */ jsx("div", {
5277
- className: "pointer-events-none absolute inset-x-0 bottom-0 z-20 flex justify-center p-2",
5278
- children: /* @__PURE__ */ jsx("div", {
5279
- className: "animate-in fade-in slide-in-from-bottom-4 pointer-events-auto w-full duration-200 ease-out",
5280
- children: /* @__PURE__ */ jsx(ActionBarContext.Provider, {
5281
- value: {
5282
- count: selectedCount,
5283
- onClear: () => table.resetRowSelection()
5284
- },
5285
- children: actionBar
5286
- })
5287
- })
5288
- }) : null
5289
- ]
5290
- });
5291
- }
5292
- function SelectAllHeader({ table }) {
5293
- const t = useDsTranslation("ds");
5294
- const allSelected = table.getIsAllRowsSelected();
5295
- const someSelected = table.getIsSomeRowsSelected();
5296
- return /* @__PURE__ */ jsx(Checkbox, {
5297
- checked: allSelected,
5298
- indeterminate: !allSelected && someSelected,
5299
- onCheckedChange: (value) => table.toggleAllRowsSelected(value === true),
5300
- "aria-label": t("dataTable.selectAllRows")
5301
- });
5302
- }
5303
- function SelectRowCell({ row }) {
5304
- const t = useDsTranslation("ds");
5305
- if (!row.getCanSelect()) return null;
5306
- return /* @__PURE__ */ jsx("span", {
5307
- className: "contents",
5308
- onClick: (e) => e.stopPropagation(),
5309
- children: /* @__PURE__ */ jsx(Checkbox, {
5310
- checked: row.getIsSelected(),
5311
- onCheckedChange: (value) => row.toggleSelected(value === true),
5312
- "aria-label": t("dataTable.selectRow")
5313
- })
5314
- });
5315
- }
5316
- function makeSelectColumn(multiSelect, options) {
5317
- return {
5318
- id: SELECT_COLUMN_ID,
5319
- header: multiSelect ? ({ table }) => /* @__PURE__ */ jsx(SelectAllHeader, { table }) : () => null,
5320
- cell: ({ row }) => /* @__PURE__ */ jsx(SelectRowCell, { row }),
5321
- enableSorting: false,
5322
- enableHiding: false,
5323
- enableResizing: false,
5324
- size: 40,
5325
- ...options?.pin ? { meta: { pin: "left" } } : {}
5326
- };
5327
- }
5328
- function ResizeHandle({ header }) {
5329
- const isResizing = header.column.getIsResizing();
5330
- return /* @__PURE__ */ jsx("span", {
5331
- "aria-hidden": true,
5332
- onMouseDown: header.getResizeHandler(),
5333
- onTouchStart: header.getResizeHandler(),
5334
- onClick: (e) => e.stopPropagation(),
5335
- className: cn("absolute top-0 right-0 z-10 h-full w-1 cursor-col-resize touch-none select-none bg-border opacity-0 transition-opacity group-hover/header-row:opacity-100 hover:opacity-100", isResizing && "bg-primary opacity-100")
5336
- });
5337
- }
5338
- function SortableHeader({ header }) {
5339
- const direction = header.column.getIsSorted();
5340
- const Icon = direction === "asc" ? ChevronUpIcon : direction === "desc" ? ChevronDownIcon : ChevronsUpDownIcon;
5341
- return /* @__PURE__ */ jsxs(Button, {
5342
- variant: "ghost",
5343
- size: "sm",
5344
- className: "-ml-2 h-7 data-[icon=inline-end]:pr-2",
5345
- onClick: header.column.getToggleSortingHandler(),
5346
- children: [flexRender(header.column.columnDef.header, header.getContext()), /* @__PURE__ */ jsx(Icon, {
5347
- "data-icon": "inline-end",
5348
- className: cn("size-3.5", direction === false && "opacity-50")
5349
- })]
5350
- });
5351
- }
5352
- /**
5353
- * Resolves a TanStack column id the same way the table does
5354
- * (`id` → `accessorKey` → string `header`). See `@tanstack/table-core`
5355
- * `createColumn`.
5356
- */
5357
- function getColumnDefId(col) {
5358
- if (col.id != null) return col.id;
5359
- if ("accessorKey" in col && typeof col.accessorKey === "string") return col.accessorKey.replace(/\./g, "_");
5360
- if (typeof col.header === "string") return col.header;
5361
- }
5362
- /** Builds TanStack `columnPinning` state from declarative `meta.pin` on column defs. */
5363
- function deriveColumnPinning(columns) {
5364
- const left = [];
5365
- const right = [];
5366
- for (const col of columns) {
5367
- const pin = col.meta?.pin;
5368
- if (!pin) continue;
5369
- const id = getColumnDefId(col);
5370
- if (!id) {
5371
- console.warn("[DataTable] Column with `meta.pin` has no resolvable id. Set `id`, a string `accessorKey`, or a string `header` so pinning can apply.");
5372
- continue;
5373
- }
5374
- if (pin === "left") left.push(id);
5375
- else right.push(id);
5376
- }
5377
- if (left.length === 0 && right.length === 0) return EMPTY_COLUMN_PINNING;
5378
- return {
5379
- left,
5380
- right
5381
- };
5382
- }
5383
- /**
5384
- * Position/size/shadow props for a pinned (or width-pinned) cell. Uses CSS
5385
- * `position: sticky` under the hood (TanStack column-pinning pattern). Edge
5386
- * inset shadows only render on the outermost pinned column per side, and only
5387
- * while horizontal scroll has moved away from that edge.
5388
- */
5389
- function getPinnedCellProps(column, options) {
5390
- const { pinWidths, variant, fillHeight, showLeftEdgeShadow, showRightEdgeShadow } = options;
5391
- const style = pinWidths ? { width: `${column.getSize()}px` } : {};
5392
- const isPinned = column.getIsPinned();
5393
- if (!isPinned) return { style };
5394
- style.position = "sticky";
5395
- if (isPinned === "left") style.left = `${column.getStart("left")}px`;
5396
- else style.right = `${column.getAfter("right")}px`;
5397
- if (variant === "header" && fillHeight) style.top = 0;
5398
- style.zIndex = variant === "header" ? 30 : 1;
5399
- const isEdgeLeft = isPinned === "left" && column.getIsLastColumn("left");
5400
- const isEdgeRight = isPinned === "right" && column.getIsFirstColumn("right");
5401
- const shadows = [];
5402
- if (variant === "header" && fillHeight) shadows.push("inset 0 -1px 0 0 var(--border)");
5403
- if (isEdgeLeft && showLeftEdgeShadow) shadows.push("inset -1px 0 0 0 var(--border)");
5404
- if (isEdgeRight && showRightEdgeShadow) shadows.push("inset 1px 0 0 0 var(--border)");
5405
- if (shadows.length > 0) style.boxShadow = shadows.join(", ");
5406
- return {
5407
- style,
5408
- className: cn(variant === "footer" ? "bg-[color-mix(in_oklch,var(--muted)_50%,var(--background))]" : variant === "body" ? cn("bg-background", "group-hover:bg-[color-mix(in_oklch,var(--accent)_30%,var(--background))]", "group-data-[state=selected]:bg-[color-mix(in_oklch,var(--accent)_50%,var(--background))]", "group-data-[state=selected]:group-hover:bg-[color-mix(in_oklch,var(--accent)_50%,var(--background))]") : "bg-background")
5409
- };
5410
- }
5411
- function SkeletonRows({ columns, count, getCellPinProps, groupRows }) {
5412
- return /* @__PURE__ */ jsx(Fragment, { children: Array.from({ length: count }, (_, i) => /* @__PURE__ */ jsx(TableRow, {
5413
- className: groupRows ? "group" : void 0,
5414
- children: columns.map((col) => {
5415
- const pinProps = getCellPinProps(col, "body");
5416
- return /* @__PURE__ */ jsx(TableCell, {
5417
- "data-test": "loading-cell",
5418
- style: pinProps.style,
5419
- className: pinProps.className,
5420
- children: /* @__PURE__ */ jsx(Skeleton, { className: "h-4 w-full max-w-full" })
5421
- }, col.id);
5422
- })
5423
- }, `skeleton-${i}`)) });
5424
- }
5425
- //#endregion
5426
4230
  //#region src/components/tree.tsx
5427
4231
  const TreeContext = React.createContext({
5428
4232
  currentItem: void 0,