@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.
@@ -0,0 +1,1207 @@
1
+ import * as React from "react";
2
+ import { useCallback, useSyncExternalStore } from "react";
3
+ import { clsx } from "clsx";
4
+ import { extendTailwindMerge } from "tailwind-merge";
5
+ import { CheckIcon, ChevronDownIcon, ChevronUpIcon, ChevronsUpDownIcon, Loader2Icon, MinusIcon, XIcon } from "@aircall/react-icons";
6
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
7
+ import { Button } from "@base-ui/react/button";
8
+ import { cva } from "class-variance-authority";
9
+ import i18next from "i18next";
10
+ import { Checkbox } from "@base-ui/react/checkbox";
11
+ import { useVirtualizer } from "@tanstack/react-virtual";
12
+ import { useControllableState } from "@aircall/hooks";
13
+ import { flexRender, getCoreRowModel, useReactTable } from "@tanstack/react-table";
14
+ //#region src/lib/utils.ts
15
+ const DS_COLORS = [
16
+ "background",
17
+ "foreground",
18
+ "card",
19
+ "card-foreground",
20
+ "popover",
21
+ "popover-foreground",
22
+ "primary",
23
+ "primary-foreground",
24
+ "secondary",
25
+ "secondary-foreground",
26
+ "info",
27
+ "info-foreground",
28
+ "info-background",
29
+ "success",
30
+ "success-foreground",
31
+ "success-background",
32
+ "warning",
33
+ "warning-foreground",
34
+ "warning-background",
35
+ "destructive",
36
+ "destructive-foreground",
37
+ "destructive-background",
38
+ "muted",
39
+ "muted-foreground",
40
+ "accent",
41
+ "accent-foreground",
42
+ "border",
43
+ "input",
44
+ "ring",
45
+ "chart-1",
46
+ "chart-2",
47
+ "chart-3",
48
+ "chart-4",
49
+ "chart-5",
50
+ "sidebar",
51
+ "sidebar-foreground",
52
+ "sidebar-primary",
53
+ "sidebar-primary-foreground",
54
+ "sidebar-accent",
55
+ "sidebar-accent-foreground",
56
+ "sidebar-border",
57
+ "sidebar-ring"
58
+ ];
59
+ const BLOCKS_COLORS = [
60
+ "page-background",
61
+ "navbar-foreground",
62
+ "navbar-accent",
63
+ "navbar-accent-foreground",
64
+ "navbar-icon-bg"
65
+ ];
66
+ const twMerge = extendTailwindMerge({ extend: { theme: {
67
+ color: [...DS_COLORS, ...BLOCKS_COLORS],
68
+ text: ["tiny"],
69
+ animate: ["caret-blink"]
70
+ } } });
71
+ function cn(...inputs) {
72
+ return twMerge(clsx(inputs));
73
+ }
74
+ //#endregion
75
+ //#region src/components/button.tsx
76
+ /** Tailwind class string for link-styled buttons and anchors (primary color, underlined). */
77
+ const linkStyle = "text-primary underline underline-offset-4";
78
+ /** `cva` variant definitions for {@link Button} — resolves `variant`, `size`, and `block` into class names. */
79
+ 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", {
80
+ variants: {
81
+ variant: {
82
+ default: "bg-primary text-primary-foreground hover:bg-primary/90",
83
+ 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",
84
+ secondary: "bg-secondary text-secondary-foreground hover:bg-secondary/80 aria-expanded:bg-secondary aria-expanded:text-secondary-foreground",
85
+ ghost: "hover:bg-muted hover:text-accent-foreground aria-expanded:bg-muted aria-expanded:text-accent-foreground dark:hover:bg-input/50",
86
+ 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",
87
+ link: linkStyle
88
+ },
89
+ size: {
90
+ default: "h-8 gap-1.5 px-2 has-data-[icon=inline-end]:pr-1.5 has-data-[icon=inline-start]:pl-1.5",
91
+ sm: "h-6 gap-1.5 px-2 has-data-[icon=inline-end]:pr-1.5 has-data-[icon=inline-start]:pl-1.5",
92
+ 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",
93
+ icon: "size-8",
94
+ "icon-sm": "size-6",
95
+ "icon-lg": "size-10 [&_svg:not([class*='size-'])]:size-6"
96
+ },
97
+ block: { true: "w-full" }
98
+ },
99
+ defaultVariants: {
100
+ variant: "default",
101
+ size: "default",
102
+ block: false
103
+ }
104
+ });
105
+ /**
106
+ * Clickable button. Renders a Base UI `Button` primitive as a `<button>` element,
107
+ * styled via `buttonVariants` (variant / size / block).
108
+ *
109
+ * @example
110
+ * ```tsx
111
+ * <Button variant="outline" size="sm">Save</Button>
112
+ * ```
113
+ */
114
+ const Button$1 = React.forwardRef((componentProps, forwardRef) => {
115
+ const { className, variant = "default", size = "default", block = false, ...props } = componentProps;
116
+ return /* @__PURE__ */ jsx(Button, {
117
+ ref: forwardRef,
118
+ "data-slot": "button",
119
+ "data-variant": variant,
120
+ className: cn(buttonVariants({
121
+ variant,
122
+ size,
123
+ block,
124
+ className
125
+ })),
126
+ ...props
127
+ });
128
+ });
129
+ Button$1.displayName = "Button";
130
+ //#endregion
131
+ //#region src/i18n/locales/de.ts
132
+ const de = {
133
+ "spinner.loading": "Laden",
134
+ "pagination.label": "Seitennavigation",
135
+ "pagination.previousPage": "Zur vorherigen Seite",
136
+ "pagination.nextPage": "Zur nächsten Seite",
137
+ "dataTable.selectAllRows": "Alle Zeilen auswählen",
138
+ "dataTable.selectRow": "Zeile auswählen",
139
+ "dataCombobox.noResults": "Keine Ergebnisse",
140
+ "tree.collapse": "Minimieren",
141
+ "tree.expand": "Erweitern",
142
+ "multiselect.remove": "Entfernen",
143
+ "multiselect.clearAll": "Alles löschen",
144
+ "multiselect.addItem": "Hinzufügen",
145
+ "multiselect.search": "Suchen",
146
+ "sidebar.toggle": "Seitenleiste umschalten",
147
+ "drawer.close": "Schließen",
148
+ "emojiPicker.emoji": "Emoji",
149
+ "emojiPicker.choose": "Emoji auswählen",
150
+ "actionBar.selectionActions": "Auswahlaktionen",
151
+ "pagination.previous": "Zurück",
152
+ "pagination.next": "Weiter",
153
+ "actionBar.clearSelection": "Auswahl aufheben",
154
+ "actionBar.itemsSelected": "{{count}} Elemente ausgewählt.",
155
+ "fieldLabel.required": "(erforderlich)",
156
+ "fieldLabel.optional": "(optional)",
157
+ "fieldLabel.moreInfo": "Weitere Informationen",
158
+ "datePicker.beforeMin": "Das Datum liegt vor dem frühesten verfügbaren Datum ({{date}})",
159
+ "datePicker.afterMax": "Das Datum liegt nach dem spätesten verfügbaren Datum ({{date}})",
160
+ "datePicker.unavailable": "Dieses Datum ist nicht verfügbar",
161
+ "datePicker.rangeOrder": "Das Startdatum muss vor oder gleich dem Enddatum sein",
162
+ "richTextarea.noResults": "Keine Ergebnisse",
163
+ "richTextarea.slashNoCommands": "Keine Befehle",
164
+ "richTextarea.bold": "Fett",
165
+ "richTextarea.italic": "Kursiv",
166
+ "richTextarea.underline": "Unterstrichen",
167
+ "richTextarea.strikethrough": "Durchgestrichen",
168
+ "richTextarea.inlineCode": "Inline-Code",
169
+ "richTextarea.bulletedList": "Aufzählungsliste",
170
+ "richTextarea.numberedList": "Nummerierte Liste",
171
+ "richTextarea.link": "Link",
172
+ "richTextarea.linkPlaceholder": "Link einfügen",
173
+ "richTextarea.linkText": "Anzuzeigender Text",
174
+ "richTextarea.linkEdit": "Link bearbeiten",
175
+ "richTextarea.linkOpen": "Link in neuem Tab öffnen",
176
+ "richTextarea.linkRemove": "Link entfernen"
177
+ };
178
+ //#endregion
179
+ //#region src/i18n/locales/en.ts
180
+ const en = {
181
+ "spinner.loading": "Loading",
182
+ "pagination.label": "pagination",
183
+ "pagination.previousPage": "Go to previous page",
184
+ "pagination.nextPage": "Go to next page",
185
+ "dataTable.selectAllRows": "Select all rows",
186
+ "dataTable.selectRow": "Select row",
187
+ "dataCombobox.noResults": "No results found",
188
+ "tree.collapse": "Collapse",
189
+ "tree.expand": "Expand",
190
+ "multiselect.remove": "Remove",
191
+ "multiselect.clearAll": "Clear all",
192
+ "multiselect.addItem": "Add item",
193
+ "multiselect.search": "Search",
194
+ "sidebar.toggle": "Toggle Sidebar",
195
+ "drawer.close": "Close",
196
+ "emojiPicker.emoji": "Emoji",
197
+ "emojiPicker.choose": "Choose an emoji",
198
+ "actionBar.selectionActions": "Selection actions",
199
+ "pagination.previous": "Previous",
200
+ "pagination.next": "Next",
201
+ "actionBar.clearSelection": "Clear selection",
202
+ "actionBar.itemsSelected": "{{count}} items selected.",
203
+ "fieldLabel.required": "(required)",
204
+ "fieldLabel.optional": "(optional)",
205
+ "fieldLabel.moreInfo": "More information",
206
+ "datePicker.beforeMin": "Date is before the earliest available date ({{date}})",
207
+ "datePicker.afterMax": "Date is after the latest available date ({{date}})",
208
+ "datePicker.unavailable": "That date isn't available",
209
+ "datePicker.rangeOrder": "Start date must be on or before the end date",
210
+ "richTextarea.noResults": "No results",
211
+ "richTextarea.slashNoCommands": "No commands",
212
+ "richTextarea.bold": "Bold",
213
+ "richTextarea.italic": "Italic",
214
+ "richTextarea.underline": "Underline",
215
+ "richTextarea.strikethrough": "Strikethrough",
216
+ "richTextarea.inlineCode": "Inline code",
217
+ "richTextarea.bulletedList": "Bulleted list",
218
+ "richTextarea.numberedList": "Numbered list",
219
+ "richTextarea.link": "Link",
220
+ "richTextarea.linkPlaceholder": "Paste link",
221
+ "richTextarea.linkText": "Text to display",
222
+ "richTextarea.linkEdit": "Edit link",
223
+ "richTextarea.linkOpen": "Open link in a new tab",
224
+ "richTextarea.linkRemove": "Remove link"
225
+ };
226
+ //#endregion
227
+ //#region src/i18n/locales/es.ts
228
+ const es = {
229
+ "spinner.loading": "Cargando",
230
+ "pagination.label": "paginación",
231
+ "pagination.previousPage": "Ir a la página anterior",
232
+ "pagination.nextPage": "Ir a la página siguiente",
233
+ "dataTable.selectAllRows": "Seleccionar todas las filas",
234
+ "dataTable.selectRow": "Seleccionar fila",
235
+ "dataCombobox.noResults": "Sin resultados",
236
+ "tree.collapse": "Minimizar",
237
+ "tree.expand": "Ampliar",
238
+ "multiselect.remove": "Eliminar",
239
+ "multiselect.clearAll": "Borrar todo",
240
+ "multiselect.addItem": "Añadir",
241
+ "multiselect.search": "Buscar",
242
+ "sidebar.toggle": "Alternar barra lateral",
243
+ "drawer.close": "Cerrar",
244
+ "emojiPicker.emoji": "Emoji",
245
+ "emojiPicker.choose": "Elegir un emoji",
246
+ "actionBar.selectionActions": "Acciones de selección",
247
+ "pagination.previous": "Anterior",
248
+ "pagination.next": "Siguiente",
249
+ "actionBar.clearSelection": "Borrar selección",
250
+ "actionBar.itemsSelected": "{{count}} elementos seleccionados.",
251
+ "fieldLabel.required": "(obligatorio)",
252
+ "fieldLabel.optional": "(opcional)",
253
+ "fieldLabel.moreInfo": "Más información",
254
+ "datePicker.beforeMin": "La fecha es anterior a la fecha más antigua disponible ({{date}})",
255
+ "datePicker.afterMax": "La fecha es posterior a la fecha más reciente disponible ({{date}})",
256
+ "datePicker.unavailable": "Esa fecha no está disponible",
257
+ "datePicker.rangeOrder": "La fecha de inicio debe ser anterior o igual a la fecha de fin",
258
+ "richTextarea.noResults": "Sin resultados",
259
+ "richTextarea.slashNoCommands": "Sin comandos",
260
+ "richTextarea.bold": "Negrita",
261
+ "richTextarea.italic": "Cursiva",
262
+ "richTextarea.underline": "Subrayado",
263
+ "richTextarea.strikethrough": "Tachado",
264
+ "richTextarea.inlineCode": "Código en línea",
265
+ "richTextarea.bulletedList": "Lista con viñetas",
266
+ "richTextarea.numberedList": "Lista numerada",
267
+ "richTextarea.link": "Enlace",
268
+ "richTextarea.linkPlaceholder": "Pegar enlace",
269
+ "richTextarea.linkText": "Texto para mostrar",
270
+ "richTextarea.linkEdit": "Editar enlace",
271
+ "richTextarea.linkOpen": "Abrir enlace en una pestaña nueva",
272
+ "richTextarea.linkRemove": "Eliminar enlace"
273
+ };
274
+ //#endregion
275
+ //#region src/i18n/locales/fr.ts
276
+ const fr = {
277
+ "spinner.loading": "Chargement",
278
+ "pagination.label": "pagination",
279
+ "pagination.previousPage": "Aller à la page précédente",
280
+ "pagination.nextPage": "Aller à la page suivante",
281
+ "dataTable.selectAllRows": "Sélectionner toutes les lignes",
282
+ "dataTable.selectRow": "Sélectionner la ligne",
283
+ "dataCombobox.noResults": "Aucun résultat",
284
+ "tree.collapse": "Réduire",
285
+ "tree.expand": "Développer",
286
+ "multiselect.remove": "Supprimer",
287
+ "multiselect.clearAll": "Tout effacer",
288
+ "multiselect.addItem": "Ajouter",
289
+ "multiselect.search": "Rechercher",
290
+ "sidebar.toggle": "Basculer la barre latérale",
291
+ "drawer.close": "Fermer",
292
+ "emojiPicker.emoji": "Émoji",
293
+ "emojiPicker.choose": "Choisir un émoji",
294
+ "actionBar.selectionActions": "Actions de sélection",
295
+ "pagination.previous": "Précédent",
296
+ "pagination.next": "Suivant",
297
+ "actionBar.clearSelection": "Effacer la sélection",
298
+ "actionBar.itemsSelected": "{{count}} éléments sélectionnés.",
299
+ "fieldLabel.required": "(obligatoire)",
300
+ "fieldLabel.optional": "(facultatif)",
301
+ "fieldLabel.moreInfo": "Plus d'informations",
302
+ "datePicker.beforeMin": "La date est antérieure à la date la plus ancienne disponible ({{date}})",
303
+ "datePicker.afterMax": "La date est postérieure à la date la plus récente disponible ({{date}})",
304
+ "datePicker.unavailable": "Cette date n'est pas disponible",
305
+ "datePicker.rangeOrder": "La date de debut doit etre anterieure ou egale a la date de fin",
306
+ "richTextarea.noResults": "Aucun résultat",
307
+ "richTextarea.slashNoCommands": "Aucune commande",
308
+ "richTextarea.bold": "Gras",
309
+ "richTextarea.italic": "Italique",
310
+ "richTextarea.underline": "Souligné",
311
+ "richTextarea.strikethrough": "Barré",
312
+ "richTextarea.inlineCode": "Code en ligne",
313
+ "richTextarea.bulletedList": "Liste à puces",
314
+ "richTextarea.numberedList": "Liste numérotée",
315
+ "richTextarea.link": "Lien",
316
+ "richTextarea.linkPlaceholder": "Coller le lien",
317
+ "richTextarea.linkText": "Texte à afficher",
318
+ "richTextarea.linkEdit": "Modifier le lien",
319
+ "richTextarea.linkOpen": "Ouvrir le lien dans un nouvel onglet",
320
+ "richTextarea.linkRemove": "Supprimer le lien"
321
+ };
322
+ //#endregion
323
+ //#region src/i18n/locales/it.ts
324
+ const it = {
325
+ "spinner.loading": "Caricamento",
326
+ "pagination.label": "paginazione",
327
+ "pagination.nextPage": "Vai alla pagina successiva",
328
+ "pagination.previousPage": "Vai alla pagina precedente",
329
+ "dataTable.selectAllRows": "Seleziona tutte le righe",
330
+ "dataTable.selectRow": "Seleziona riga",
331
+ "dataCombobox.noResults": "Nessun risultato",
332
+ "tree.collapse": "Ridurre",
333
+ "tree.expand": "Espandi",
334
+ "multiselect.remove": "Rimuovi",
335
+ "multiselect.clearAll": "Cancella tutto",
336
+ "multiselect.addItem": "Aggiungi",
337
+ "multiselect.search": "Cerca",
338
+ "sidebar.toggle": "Attiva/disattiva barra laterale",
339
+ "drawer.close": "Chiudi",
340
+ "emojiPicker.emoji": "Emoji",
341
+ "emojiPicker.choose": "Scegli un emoji",
342
+ "actionBar.selectionActions": "Azioni di selezione",
343
+ "pagination.previous": "Precedente",
344
+ "pagination.next": "Successivo",
345
+ "actionBar.clearSelection": "Cancella selezione",
346
+ "actionBar.itemsSelected": "{{count}} elementi selezionati.",
347
+ "fieldLabel.required": "(obbligatorio)",
348
+ "fieldLabel.optional": "(facoltativo)",
349
+ "fieldLabel.moreInfo": "Maggiori informazioni",
350
+ "datePicker.beforeMin": "La data è precedente alla prima data disponibile ({{date}})",
351
+ "datePicker.afterMax": "La data è successiva all'ultima data disponibile ({{date}})",
352
+ "datePicker.unavailable": "Questa data non è disponibile",
353
+ "datePicker.rangeOrder": "La data di inizio deve essere precedente o uguale alla data di fine",
354
+ "richTextarea.noResults": "Nessun risultato",
355
+ "richTextarea.slashNoCommands": "Nessun comando",
356
+ "richTextarea.bold": "Grassetto",
357
+ "richTextarea.italic": "Corsivo",
358
+ "richTextarea.underline": "Sottolineato",
359
+ "richTextarea.strikethrough": "Barrato",
360
+ "richTextarea.inlineCode": "Codice inline",
361
+ "richTextarea.bulletedList": "Elenco puntato",
362
+ "richTextarea.numberedList": "Elenco numerato",
363
+ "richTextarea.link": "Collegamento",
364
+ "richTextarea.linkPlaceholder": "Incolla il link",
365
+ "richTextarea.linkText": "Testo da visualizzare",
366
+ "richTextarea.linkEdit": "Modifica link",
367
+ "richTextarea.linkOpen": "Apri il link in una nuova scheda",
368
+ "richTextarea.linkRemove": "Rimuovi link"
369
+ };
370
+ //#endregion
371
+ //#region src/i18n/instance.ts
372
+ const SUPPORTED_LANGUAGES = [
373
+ "en",
374
+ "fr",
375
+ "es",
376
+ "de",
377
+ "it"
378
+ ];
379
+ const FALLBACK_LANGUAGE = "en";
380
+ /** Resolve the initial language from the environment, falling back to English. */
381
+ function detectInitialLanguage() {
382
+ if (typeof navigator === "undefined" || !navigator.language) return FALLBACK_LANGUAGE;
383
+ const base = navigator.language.split("-")[0];
384
+ return SUPPORTED_LANGUAGES.includes(base) ? base : FALLBACK_LANGUAGE;
385
+ }
386
+ /** The single private i18next instance owned by @aircall/ds. Isolated from any consumer instance. */
387
+ const dsI18n = i18next.createInstance();
388
+ dsI18n.init({
389
+ lng: detectInitialLanguage(),
390
+ fallbackLng: FALLBACK_LANGUAGE,
391
+ supportedLngs: [...SUPPORTED_LANGUAGES],
392
+ load: "languageOnly",
393
+ ns: ["ds"],
394
+ defaultNS: "ds",
395
+ resources: {
396
+ en: { ds: en },
397
+ fr: { ds: fr },
398
+ es: { ds: es },
399
+ de: { ds: de },
400
+ it: { ds: it }
401
+ },
402
+ interpolation: { escapeValue: false },
403
+ keySeparator: false,
404
+ returnNull: false,
405
+ initImmediate: false
406
+ });
407
+ /** Register an additional namespace's resources into the shared instance (used by @aircall/blocks). */
408
+ function registerI18nNamespace(ns, resources) {
409
+ for (const [lng, bundle] of Object.entries(resources)) dsI18n.addResourceBundle(lng, ns, bundle, true, true);
410
+ }
411
+ //#endregion
412
+ //#region src/i18n/use-ds-translation.ts
413
+ function subscribe(onChange) {
414
+ dsI18n.on("languageChanged", onChange);
415
+ return () => dsI18n.off("languageChanged", onChange);
416
+ }
417
+ function getLanguageSnapshot() {
418
+ return dsI18n.language;
419
+ }
420
+ /**
421
+ * @internal
422
+ * Reads translations from the shared ds instance and re-renders on language change.
423
+ * Used by @aircall/ds and @aircall/blocks components only — not part of the consumer contract.
424
+ */
425
+ function useDsTranslation(ns) {
426
+ const language = useSyncExternalStore(subscribe, getLanguageSnapshot, getLanguageSnapshot);
427
+ return useCallback((key, opts) => dsI18n.t(key, {
428
+ ns,
429
+ ...opts
430
+ }), [ns, language]);
431
+ }
432
+ //#endregion
433
+ //#region src/components/action-bar.tsx
434
+ /** Fixed height of the ActionBar (px). Single source of truth — the bar uses it
435
+ * for its own height and consumers (e.g. DataTable) reserve space with it. */
436
+ const ActionBarHeight = 48;
437
+ /**
438
+ * Lets a parent (e.g. `DataTable`) supply the selected `count` and an `onClear`
439
+ * handler so an `<ActionBar>` rendered inside it doesn't have to be passed them.
440
+ * Explicit `count`/`onClear` props on `ActionBar` always take precedence, so the
441
+ * component still works standalone. Mirrors React Spectrum's `ActionBarContext`.
442
+ */
443
+ const ActionBarContext = React.createContext(null);
444
+ const ActionBarButton = React.forwardRef((componentProps, forwardRef) => {
445
+ const { size = "default", ...props } = componentProps;
446
+ return /* @__PURE__ */ jsx(Button$1, {
447
+ ref: forwardRef,
448
+ variant: "ghost",
449
+ size,
450
+ ...props
451
+ });
452
+ });
453
+ ActionBarButton.displayName = "ActionBarButton";
454
+ /**
455
+ * A selection action bar: shows the selected-item count with a clear button and hosts
456
+ * contextual action buttons on the right. Renders a `<div role="toolbar">`. `count` and
457
+ * `onClear` fall back to `ActionBarContext` (e.g. supplied by `DataTable`) when omitted.
458
+ *
459
+ * @example
460
+ * ```tsx
461
+ * <ActionBar count={3} onClear={clearSelection}>
462
+ * <ActionBarButton>Delete</ActionBarButton>
463
+ * </ActionBar>
464
+ * ```
465
+ */
466
+ const ActionBar = React.forwardRef((componentProps, forwardRef) => {
467
+ const { className, count, onClear, children, label, clearLabel, style, ...props } = componentProps;
468
+ const t = useDsTranslation("ds");
469
+ const ctx = React.useContext(ActionBarContext);
470
+ const resolvedCount = count ?? ctx?.count ?? 0;
471
+ const resolvedOnClear = onClear ?? ctx?.onClear;
472
+ const resolvedClearLabel = clearLabel ?? t("actionBar.clearSelection");
473
+ return /* @__PURE__ */ jsxs("div", {
474
+ ref: forwardRef,
475
+ role: "toolbar",
476
+ "aria-label": t("actionBar.selectionActions"),
477
+ "data-slot": "action-bar",
478
+ 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),
479
+ style: {
480
+ ...style,
481
+ height: 48
482
+ },
483
+ ...props,
484
+ children: [
485
+ resolvedOnClear ? /* @__PURE__ */ jsx(ActionBarButton, {
486
+ size: "icon",
487
+ onClick: resolvedOnClear,
488
+ "aria-label": resolvedClearLabel,
489
+ children: /* @__PURE__ */ jsx(XIcon, {})
490
+ }) : null,
491
+ /* @__PURE__ */ jsx("span", {
492
+ className: "flex-1 truncate text-sm",
493
+ children: label ? label(resolvedCount) : t("actionBar.itemsSelected", { count: resolvedCount })
494
+ }),
495
+ children ? /* @__PURE__ */ jsx("div", {
496
+ className: "flex shrink-0 items-center gap-2",
497
+ children
498
+ }) : null
499
+ ]
500
+ });
501
+ });
502
+ ActionBar.displayName = "ActionBar";
503
+ //#endregion
504
+ //#region src/components/spinner.tsx
505
+ /** Class variants for `Spinner`, controlling its `size` (`default`, `sm`, `lg`, `xl`). */
506
+ const spinnerVariants = cva("animate-spin text-current", {
507
+ variants: { size: {
508
+ default: "size-4",
509
+ sm: "size-3",
510
+ lg: "size-5",
511
+ xl: "size-6"
512
+ } },
513
+ defaultVariants: { size: "default" }
514
+ });
515
+ /**
516
+ * Animated loading indicator. Renders a spinning `<svg>` (Loader icon) with
517
+ * `role="status"` and a localized `aria-label` for assistive technology.
518
+ *
519
+ * @example
520
+ * ```tsx
521
+ * <Spinner size="lg" />
522
+ * ```
523
+ */
524
+ const Spinner = React.forwardRef((componentProps, forwardRef) => {
525
+ const { className, size, ...props } = componentProps;
526
+ const t = useDsTranslation("ds");
527
+ return /* @__PURE__ */ jsx(Loader2Icon, {
528
+ ref: forwardRef,
529
+ "data-slot": "spinner",
530
+ role: "status",
531
+ "aria-label": t("spinner.loading"),
532
+ className: cn(spinnerVariants({ size }), className),
533
+ ...props
534
+ });
535
+ });
536
+ Spinner.displayName = "Spinner";
537
+ //#endregion
538
+ //#region src/components/checkbox.tsx
539
+ /**
540
+ * A checkbox for toggling a single value, wrapping Base UI's `Checkbox.Root`.
541
+ * Renders a `<button role="checkbox">` containing a check (checked) or minus
542
+ * (indeterminate) indicator.
543
+ *
544
+ * @example
545
+ * ```tsx
546
+ * <Checkbox defaultChecked />
547
+ * ```
548
+ */
549
+ const Checkbox$1 = React.forwardRef((componentProps, forwardRef) => {
550
+ const { className, ...props } = componentProps;
551
+ return /* @__PURE__ */ jsx(Checkbox.Root, {
552
+ ref: forwardRef,
553
+ "data-slot": "checkbox",
554
+ 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),
555
+ ...props,
556
+ children: /* @__PURE__ */ jsxs(Checkbox.Indicator, {
557
+ "data-slot": "checkbox-indicator",
558
+ keepMounted: true,
559
+ className: "group/indicator grid place-content-center text-current transition-none [&>svg]:size-3.5",
560
+ children: [/* @__PURE__ */ jsx(CheckIcon, { className: "hidden group-data-[checked]/indicator:block" }), /* @__PURE__ */ jsx(MinusIcon, { className: "hidden group-data-[indeterminate]/indicator:block" })]
561
+ })
562
+ });
563
+ });
564
+ Checkbox$1.displayName = "Checkbox";
565
+ //#endregion
566
+ //#region src/components/skeleton.tsx
567
+ /**
568
+ * Pulsing placeholder shown while content is loading. Renders a `<div>`;
569
+ * set its dimensions via `className` to match the content it stands in for.
570
+ *
571
+ * @example
572
+ * ```tsx
573
+ * <Skeleton className="h-4 w-32" />
574
+ * ```
575
+ */
576
+ const Skeleton = React.forwardRef((componentProps, forwardRef) => {
577
+ const { className, ...props } = componentProps;
578
+ return /* @__PURE__ */ jsx("div", {
579
+ ref: forwardRef,
580
+ "data-slot": "skeleton",
581
+ className: cn("animate-pulse rounded-md bg-muted", className),
582
+ ...props
583
+ });
584
+ });
585
+ Skeleton.displayName = "Skeleton";
586
+ //#endregion
587
+ //#region src/lib/use-fetch-more-sentinel.ts
588
+ /**
589
+ * Returns a callback ref for a scroll sentinel element placed at the bottom of a
590
+ * scrollable list. When the sentinel scrolls into view (within `rootMargin`),
591
+ * `onFetchMore` fires once. The observer is (re)attached whenever the sentinel
592
+ * node mounts — so it works even if the sentinel only appears after the first
593
+ * page loads — and re-arms whenever `resetKey` changes (a page arrived, or the
594
+ * list reset), so pagination keeps going while the sentinel stays in view and
595
+ * pauses once it scrolls away. It fires at most once per intersection, so a
596
+ * sentinel that stays in view can't trigger duplicate loads or a tight retry
597
+ * loop when a fetch fails and the data is unchanged.
598
+ *
599
+ * `getRoot` resolves the scroll container the sentinel is measured against, given
600
+ * the sentinel node — return the scrolling ancestor (a table container, a
601
+ * combobox list, …) so `rootMargin` gives prefetch headroom inside a clipped
602
+ * scroll area, or `null` to measure against the viewport.
603
+ *
604
+ * @example
605
+ * ```tsx
606
+ * const sentinelRef = useFetchMoreSentinel<HTMLDivElement>(
607
+ * onFetchMore,
608
+ * node => node.closest<HTMLElement>('[data-slot="combobox-list"]'),
609
+ * items.length
610
+ * );
611
+ * // …later, at the bottom of the list:
612
+ * <div aria-hidden ref={sentinelRef} />
613
+ * ```
614
+ */
615
+ function useFetchMoreSentinel(onFetchMore, getRoot, resetKey) {
616
+ const onFetchMoreRef = React.useRef(onFetchMore);
617
+ onFetchMoreRef.current = onFetchMore;
618
+ const getRootRef = React.useRef(getRoot);
619
+ getRootRef.current = getRoot;
620
+ const observerRef = React.useRef(null);
621
+ const nodeRef = React.useRef(null);
622
+ const armedRef = React.useRef(true);
623
+ const observe = React.useCallback(() => {
624
+ observerRef.current?.disconnect();
625
+ observerRef.current = null;
626
+ const node = nodeRef.current;
627
+ if (!node) return;
628
+ const root = getRootRef.current(node);
629
+ const observer = new IntersectionObserver((entries) => {
630
+ if (entries[entries.length - 1]?.isIntersecting) {
631
+ if (armedRef.current) {
632
+ armedRef.current = false;
633
+ onFetchMoreRef.current?.();
634
+ }
635
+ } else armedRef.current = true;
636
+ }, {
637
+ root,
638
+ rootMargin: "200px"
639
+ });
640
+ observer.observe(node);
641
+ observerRef.current = observer;
642
+ }, []);
643
+ React.useEffect(() => {
644
+ armedRef.current = true;
645
+ observe();
646
+ }, [resetKey, observe]);
647
+ return React.useCallback((node) => {
648
+ nodeRef.current = node;
649
+ observe();
650
+ }, [observe]);
651
+ }
652
+ //#endregion
653
+ //#region src/components/table.tsx
654
+ /**
655
+ * Root data table. Renders a `<table>` inside a scrollable, bordered `<div>` container.
656
+ *
657
+ * @example
658
+ * ```tsx
659
+ * <Table>
660
+ * <TableHeader>
661
+ * <TableRow>
662
+ * <TableHead>Name</TableHead>
663
+ * </TableRow>
664
+ * </TableHeader>
665
+ * <TableBody>
666
+ * <TableRow>
667
+ * <TableCell>Ada</TableCell>
668
+ * </TableRow>
669
+ * </TableBody>
670
+ * </Table>
671
+ * ```
672
+ */
673
+ const Table = React.forwardRef((componentProps, forwardRef) => {
674
+ const { className, containerClassName, containerStyle, containerRef, ...props } = componentProps;
675
+ return /* @__PURE__ */ jsx("div", {
676
+ ref: containerRef,
677
+ "data-slot": "table-container",
678
+ style: containerStyle,
679
+ className: cn("relative w-full overflow-x-auto rounded-lg border border-border", containerClassName),
680
+ children: /* @__PURE__ */ jsx("table", {
681
+ ref: forwardRef,
682
+ "data-slot": "table",
683
+ className: cn("w-full caption-bottom text-sm text-foreground bg-background [&_tbody_tr:last-child]:border-b-0", className),
684
+ ...props
685
+ })
686
+ });
687
+ });
688
+ Table.displayName = "Table";
689
+ /** Table header section. Renders a `<thead>`; place `TableRow`/`TableHead` inside it. */
690
+ const TableHeader = React.forwardRef((componentProps, forwardRef) => {
691
+ const { className, ...props } = componentProps;
692
+ return /* @__PURE__ */ jsx("thead", {
693
+ ref: forwardRef,
694
+ "data-slot": "table-header",
695
+ className: cn("bg-background [&_tr]:border-b [&_tr]:hover:bg-transparent", className),
696
+ ...props
697
+ });
698
+ });
699
+ TableHeader.displayName = "TableHeader";
700
+ /** Table body section. Renders a `<tbody>` holding the data `TableRow`s. */
701
+ const TableBody = React.forwardRef((componentProps, forwardRef) => {
702
+ const { className, ...props } = componentProps;
703
+ return /* @__PURE__ */ jsx("tbody", {
704
+ ref: forwardRef,
705
+ "data-slot": "table-body",
706
+ className: cn("bg-background [&_tr:last-child]:border-0", className),
707
+ ...props
708
+ });
709
+ });
710
+ TableBody.displayName = "TableBody";
711
+ /** Table footer section. Renders a muted `<tfoot>`, e.g. for totals or summary rows. */
712
+ const TableFooter = React.forwardRef((componentProps, forwardRef) => {
713
+ const { className, ...props } = componentProps;
714
+ return /* @__PURE__ */ jsx("tfoot", {
715
+ ref: forwardRef,
716
+ "data-slot": "table-footer",
717
+ className: cn("border-t bg-muted/50 font-medium [&>tr]:last:border-b-0 [&>tr]:hover:bg-transparent", className),
718
+ ...props
719
+ });
720
+ });
721
+ TableFooter.displayName = "TableFooter";
722
+ /** A single table row. Renders a `<tr>`; highlights on hover and when `data-state="selected"`. */
723
+ const TableRow = React.forwardRef((componentProps, forwardRef) => {
724
+ const { className, ...props } = componentProps;
725
+ return /* @__PURE__ */ jsx("tr", {
726
+ ref: forwardRef,
727
+ "data-slot": "table-row",
728
+ className: cn("border-b transition-colors hover:bg-accent/30 data-[state=selected]:bg-accent/50", className),
729
+ ...props
730
+ });
731
+ });
732
+ TableRow.displayName = "TableRow";
733
+ /** A header cell. Renders a `<th>` with medium-weight, left-aligned text. */
734
+ const TableHead = React.forwardRef((componentProps, forwardRef) => {
735
+ const { className, ...props } = componentProps;
736
+ return /* @__PURE__ */ jsx("th", {
737
+ ref: forwardRef,
738
+ "data-slot": "table-head",
739
+ className: cn("h-10 px-2 text-left align-middle font-medium whitespace-nowrap text-foreground [&:has([role=checkbox])]:pr-0", className),
740
+ ...props
741
+ });
742
+ });
743
+ TableHead.displayName = "TableHead";
744
+ /** A data cell. Renders a `<td>` with middle-aligned content. */
745
+ const TableCell = React.forwardRef((componentProps, forwardRef) => {
746
+ const { className, ...props } = componentProps;
747
+ return /* @__PURE__ */ jsx("td", {
748
+ ref: forwardRef,
749
+ "data-slot": "table-cell",
750
+ className: cn("p-2 align-middle whitespace-nowrap [&:has([role=checkbox])]:pr-0", className),
751
+ ...props
752
+ });
753
+ });
754
+ TableCell.displayName = "TableCell";
755
+ //#endregion
756
+ //#region src/lib/use-horizontal-scroll-edges.ts
757
+ /**
758
+ * Tracks whether a horizontally scrollable container is flush with its left
759
+ * and/or right content edge. Used by pinned DataTable columns to show an edge
760
+ * separator only while content is obscured behind the pin.
761
+ *
762
+ * @param contentSizeKey - Optional signal that content width may have changed
763
+ * without the container box resizing (e.g. column sizes / `table.getTotalSize()`).
764
+ * Re-runs the edge measurement when it changes.
765
+ */
766
+ function useHorizontalScrollEdges(containerRef, enabled, contentSizeKey) {
767
+ const [atLeftEdge, setAtLeftEdge] = React.useState(true);
768
+ const [atRightEdge, setAtRightEdge] = React.useState(true);
769
+ React.useEffect(() => {
770
+ if (!enabled) {
771
+ setAtLeftEdge(true);
772
+ setAtRightEdge(true);
773
+ return;
774
+ }
775
+ const el = containerRef.current;
776
+ if (!el) return;
777
+ const update = () => {
778
+ const { scrollLeft, scrollWidth, clientWidth } = el;
779
+ setAtLeftEdge(scrollLeft <= 0);
780
+ setAtRightEdge(scrollLeft + clientWidth >= scrollWidth - 1);
781
+ };
782
+ update();
783
+ el.addEventListener("scroll", update, { passive: true });
784
+ window.addEventListener("resize", update);
785
+ const ro = typeof ResizeObserver !== "undefined" ? new ResizeObserver(update) : null;
786
+ ro?.observe(el);
787
+ const content = el.querySelector("[data-slot=\"table\"]") ?? el.firstElementChild;
788
+ if (content instanceof HTMLElement && content !== el) ro?.observe(content);
789
+ return () => {
790
+ el.removeEventListener("scroll", update);
791
+ window.removeEventListener("resize", update);
792
+ ro?.disconnect();
793
+ };
794
+ }, [
795
+ containerRef,
796
+ enabled,
797
+ contentSizeKey
798
+ ]);
799
+ return {
800
+ atLeftEdge,
801
+ atRightEdge
802
+ };
803
+ }
804
+ //#endregion
805
+ //#region src/components/data-table.tsx
806
+ const SELECT_COLUMN_ID = "__select";
807
+ const DEFAULT_SKELETON_COUNT = 5;
808
+ const EMPTY_KEYS = /* @__PURE__ */ new Set();
809
+ const EMPTY_COLUMN_PINNING = {
810
+ left: [],
811
+ right: []
812
+ };
813
+ /**
814
+ * Data grid built on TanStack Table. Renders a `<div>` wrapper around a DS
815
+ * `<Table>` (`<table>`), driven by `columns` + `data`, with opt-in sorting,
816
+ * row selection, column resizing, column pinning (`meta.pin`), virtualization,
817
+ * infinite scroll, a floating action bar, and loading/empty states.
818
+ *
819
+ * @example
820
+ * ```tsx
821
+ * <DataTable
822
+ * columns={columns}
823
+ * data={rows}
824
+ * getRowId={row => row.id}
825
+ * />
826
+ * ```
827
+ */
828
+ function DataTable(componentProps) {
829
+ 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;
830
+ const sortingEnabled = !!onSortingChange;
831
+ const selectionEnabled = selectionMode !== "none";
832
+ const multiSelect = selectionMode === "multiple";
833
+ const disabledKeySet = disabledKeys ?? EMPTY_KEYS;
834
+ const userColumnPinning = React.useMemo(() => deriveColumnPinning(columns), [columns]);
835
+ const hasUserPinnedColumns = (userColumnPinning.left?.length ?? 0) > 0 || (userColumnPinning.right?.length ?? 0) > 0;
836
+ const finalColumns = React.useMemo(() => {
837
+ if (!selectionEnabled) return columns;
838
+ return [makeSelectColumn(multiSelect, { pin: hasUserPinnedColumns }), ...columns];
839
+ }, [
840
+ columns,
841
+ selectionEnabled,
842
+ multiSelect,
843
+ hasUserPinnedColumns
844
+ ]);
845
+ const columnPinning = React.useMemo(() => deriveColumnPinning(finalColumns), [finalColumns]);
846
+ const hasPinnedColumns = (columnPinning.left?.length ?? 0) > 0 || (columnPinning.right?.length ?? 0) > 0;
847
+ const [selectionSet, setSelectionSet] = useControllableState({
848
+ prop: selectedKeys,
849
+ defaultProp: defaultSelectedKeys,
850
+ onChange: onSelectionChange
851
+ });
852
+ const selection = selectionSet ?? EMPTY_KEYS;
853
+ const rowSelection = React.useMemo(() => {
854
+ const record = {};
855
+ for (const key of selection) record[key] = true;
856
+ return record;
857
+ }, [selection]);
858
+ const handleRowSelectionChange = React.useCallback((updater) => {
859
+ const next = typeof updater === "function" ? updater(rowSelection) : updater;
860
+ setSelectionSet(new Set(Object.keys(next).filter((key) => next[key])));
861
+ }, [rowSelection, setSelectionSet]);
862
+ const table = useReactTable({
863
+ data,
864
+ columns: finalColumns,
865
+ getCoreRowModel: getCoreRowModel(),
866
+ getRowId,
867
+ enableSorting: sortingEnabled,
868
+ manualSorting: sortingEnabled,
869
+ enableRowSelection: selectionEnabled ? (row) => !disabledKeySet.has(row.id) : false,
870
+ enableMultiRowSelection: multiSelect,
871
+ enableColumnResizing,
872
+ enableColumnPinning: hasPinnedColumns,
873
+ columnResizeMode: "onChange",
874
+ onSortingChange,
875
+ onRowSelectionChange: handleRowSelectionChange,
876
+ state: {
877
+ ...sorting !== void 0 && { sorting },
878
+ rowSelection,
879
+ ...hasPinnedColumns && { columnPinning }
880
+ }
881
+ });
882
+ const rows = table.getRowModel().rows;
883
+ const selectedCount = table.getSelectedRowModel().rows.length;
884
+ const hasSelection = selectedCount > 0;
885
+ const hasFooter = finalColumns.some((col) => col.footer != null);
886
+ const isInitialLoading = loadingState === "loading";
887
+ const isRefreshing = loadingState === "sorting" || loadingState === "filtering";
888
+ const isLoadingMore = loadingState === "loadingMore";
889
+ const showEmptyState = !isInitialLoading && rows.length === 0 && !!emptyState;
890
+ const anySelected = hasSelection;
891
+ const rowClickable = selectionEnabled || !!onRowClick;
892
+ const isRowInert = (row) => disabledBehavior === "all" && disabledKeySet.has(row.id);
893
+ const handleRowActivate = (row) => {
894
+ if (isRowInert(row)) return;
895
+ if (selectionEnabled && (anySelected || !onRowClick)) {
896
+ if (row.getCanSelect()) row.toggleSelected();
897
+ } else if (onRowClick) onRowClick(row.original);
898
+ };
899
+ const virtualizeRows = (componentProps.virtualizeRows ?? false) && fillHeight;
900
+ const pinWidths = enableColumnResizing || virtualizeRows || fixedLayout || hasPinnedColumns;
901
+ const containerRef = React.useRef(null);
902
+ const { atLeftEdge, atRightEdge } = useHorizontalScrollEdges(containerRef, hasPinnedColumns, table.getTotalSize());
903
+ const getCellPinProps = (column, variant) => getPinnedCellProps(column, {
904
+ pinWidths,
905
+ variant,
906
+ fillHeight,
907
+ showLeftEdgeShadow: !atLeftEdge,
908
+ showRightEdgeShadow: !atRightEdge
909
+ });
910
+ const rowVirtualizer = useVirtualizer({
911
+ count: virtualizeRows ? rows.length : 0,
912
+ getScrollElement: () => virtualizeRows ? containerRef.current : null,
913
+ estimateSize: () => 48,
914
+ measureElement: typeof window !== "undefined" && navigator.userAgent.indexOf("Firefox") === -1 ? (el) => el?.getBoundingClientRect().height : void 0,
915
+ overscan: 5
916
+ });
917
+ const virtualItems = virtualizeRows ? rowVirtualizer.getVirtualItems() : null;
918
+ const paddingTop = virtualItems && virtualItems.length > 0 ? virtualItems[0].start : 0;
919
+ const paddingBottom = virtualItems && virtualItems.length > 0 ? rowVirtualizer.getTotalSize() - virtualItems[virtualItems.length - 1].end : 0;
920
+ const showActionBar = !!actionBar && hasSelection;
921
+ const reservedBottom = showActionBar ? 64 : void 0;
922
+ const sentinelRef = useFetchMoreSentinel(onFetchMore, (node) => fillHeight ? node.closest("[data-slot=\"table-container\"]") : null, data.length);
923
+ const leafColumnCount = table.getVisibleLeafColumns().length;
924
+ return /* @__PURE__ */ jsxs("div", {
925
+ className: cn("relative w-full", fillHeight && "flex min-h-0 flex-1 flex-col", className),
926
+ "aria-busy": isInitialLoading || isRefreshing || void 0,
927
+ children: [
928
+ /* @__PURE__ */ jsxs(Table, {
929
+ containerRef,
930
+ 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"),
931
+ containerClassName: fillHeight ? "min-h-0 flex-1 overflow-y-auto" : void 0,
932
+ containerStyle: reservedBottom ? {
933
+ paddingBottom: reservedBottom,
934
+ scrollPaddingBottom: reservedBottom
935
+ } : void 0,
936
+ style: pinWidths ? { width: `max(100%, ${table.getTotalSize()}px)` } : void 0,
937
+ children: [
938
+ /* @__PURE__ */ jsx(TableHeader, { children: table.getHeaderGroups().map((headerGroup) => /* @__PURE__ */ jsx(TableRow, {
939
+ className: enableColumnResizing ? "group/header-row" : void 0,
940
+ children: headerGroup.headers.map((header) => {
941
+ const pinProps = getCellPinProps(header.column, "header");
942
+ return /* @__PURE__ */ jsxs(TableHead, {
943
+ style: pinProps.style,
944
+ className: cn(enableColumnResizing && "relative", pinProps.className),
945
+ 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]
946
+ }, header.id);
947
+ })
948
+ }, headerGroup.id)) }),
949
+ /* @__PURE__ */ jsx(TableBody, { children: isInitialLoading ? /* @__PURE__ */ jsx(SkeletonRows, {
950
+ columns: table.getVisibleLeafColumns(),
951
+ count: skeletonCount,
952
+ getCellPinProps,
953
+ groupRows: hasPinnedColumns
954
+ }) : rows.length ? /* @__PURE__ */ jsxs(Fragment, { children: [
955
+ virtualItems ? /* @__PURE__ */ jsxs(Fragment, { children: [
956
+ paddingTop > 0 && /* @__PURE__ */ jsx("tr", {
957
+ "aria-hidden": true,
958
+ children: /* @__PURE__ */ jsx("td", {
959
+ colSpan: leafColumnCount,
960
+ style: { height: paddingTop }
961
+ })
962
+ }),
963
+ virtualItems.map((vi) => {
964
+ const row = rows[vi.index];
965
+ const inert = isRowInert(row);
966
+ const clickable = rowClickable && !inert;
967
+ return /* @__PURE__ */ jsx(TableRow, {
968
+ ref: (node) => rowVirtualizer.measureElement(node),
969
+ "data-index": vi.index,
970
+ "data-state": row.getIsSelected() ? "selected" : void 0,
971
+ "aria-disabled": inert || void 0,
972
+ onClick: clickable ? () => handleRowActivate(row) : void 0,
973
+ className: cn(hasPinnedColumns && "group", clickable && "cursor-pointer", inert && "opacity-50"),
974
+ children: row.getVisibleCells().map((cell) => {
975
+ const pinProps = getCellPinProps(cell.column, "body");
976
+ return /* @__PURE__ */ jsx(TableCell, {
977
+ style: pinProps.style,
978
+ className: pinProps.className,
979
+ children: flexRender(cell.column.columnDef.cell, cell.getContext())
980
+ }, cell.id);
981
+ })
982
+ }, row.id);
983
+ }),
984
+ paddingBottom > 0 && /* @__PURE__ */ jsx("tr", {
985
+ "aria-hidden": true,
986
+ children: /* @__PURE__ */ jsx("td", {
987
+ colSpan: leafColumnCount,
988
+ style: { height: paddingBottom }
989
+ })
990
+ })
991
+ ] }) : rows.map((row) => {
992
+ const inert = isRowInert(row);
993
+ const clickable = rowClickable && !inert;
994
+ return /* @__PURE__ */ jsx(TableRow, {
995
+ "data-state": row.getIsSelected() ? "selected" : void 0,
996
+ "aria-disabled": inert || void 0,
997
+ onClick: clickable ? () => handleRowActivate(row) : void 0,
998
+ className: cn(hasPinnedColumns && "group", clickable && "cursor-pointer", inert && "opacity-50"),
999
+ children: row.getVisibleCells().map((cell) => {
1000
+ const pinProps = getCellPinProps(cell.column, "body");
1001
+ return /* @__PURE__ */ jsx(TableCell, {
1002
+ style: pinProps.style,
1003
+ className: pinProps.className,
1004
+ children: flexRender(cell.column.columnDef.cell, cell.getContext())
1005
+ }, cell.id);
1006
+ })
1007
+ }, row.id);
1008
+ }),
1009
+ isLoadingMore ? /* @__PURE__ */ jsx(TableRow, {
1010
+ className: "hover:bg-transparent",
1011
+ children: /* @__PURE__ */ jsx(TableCell, {
1012
+ colSpan: leafColumnCount,
1013
+ className: "py-3",
1014
+ children: /* @__PURE__ */ jsx("div", {
1015
+ className: "flex items-center justify-center text-muted-foreground",
1016
+ children: /* @__PURE__ */ jsx(Spinner, {})
1017
+ })
1018
+ })
1019
+ }) : null,
1020
+ onFetchMore && hasMore && !isLoadingMore ? /* @__PURE__ */ jsx("tr", {
1021
+ "aria-hidden": true,
1022
+ ref: sentinelRef,
1023
+ children: /* @__PURE__ */ jsx("td", {
1024
+ colSpan: leafColumnCount,
1025
+ className: "h-px"
1026
+ })
1027
+ }) : null
1028
+ ] }) : emptyState ? /* @__PURE__ */ jsx(TableRow, {
1029
+ className: "hover:bg-transparent",
1030
+ children: /* @__PURE__ */ jsx(TableCell, {
1031
+ colSpan: leafColumnCount,
1032
+ className: "h-full p-0",
1033
+ children: /* @__PURE__ */ jsx("div", {
1034
+ className: cn("flex h-full items-center justify-center", !fillHeight && "min-h-60"),
1035
+ children: emptyState
1036
+ })
1037
+ })
1038
+ }) : null }),
1039
+ hasFooter && !isInitialLoading ? /* @__PURE__ */ jsx(TableFooter, { children: table.getFooterGroups().map((footerGroup) => /* @__PURE__ */ jsx(TableRow, { children: footerGroup.headers.map((header) => {
1040
+ const pinProps = getCellPinProps(header.column, "footer");
1041
+ return /* @__PURE__ */ jsx(TableCell, {
1042
+ style: pinProps.style,
1043
+ className: pinProps.className,
1044
+ children: header.isPlaceholder ? null : flexRender(header.column.columnDef.footer, header.getContext())
1045
+ }, header.id);
1046
+ }) }, footerGroup.id)) }) : null
1047
+ ]
1048
+ }),
1049
+ isRefreshing ? /* @__PURE__ */ jsx("div", {
1050
+ "data-slot": "table-loading-overlay",
1051
+ className: "bg-background/60 absolute inset-0 z-40 flex items-center justify-center",
1052
+ children: /* @__PURE__ */ jsx(Spinner, {
1053
+ size: "lg",
1054
+ className: "text-muted-foreground"
1055
+ })
1056
+ }) : null,
1057
+ showActionBar ? /* @__PURE__ */ jsx("div", {
1058
+ className: "pointer-events-none absolute inset-x-0 bottom-0 z-20 flex justify-center p-2",
1059
+ children: /* @__PURE__ */ jsx("div", {
1060
+ className: "animate-in fade-in slide-in-from-bottom-4 pointer-events-auto w-full duration-200 ease-out",
1061
+ children: /* @__PURE__ */ jsx(ActionBarContext.Provider, {
1062
+ value: {
1063
+ count: selectedCount,
1064
+ onClear: () => table.resetRowSelection()
1065
+ },
1066
+ children: actionBar
1067
+ })
1068
+ })
1069
+ }) : null
1070
+ ]
1071
+ });
1072
+ }
1073
+ function SelectAllHeader({ table }) {
1074
+ const t = useDsTranslation("ds");
1075
+ const allSelected = table.getIsAllRowsSelected();
1076
+ const someSelected = table.getIsSomeRowsSelected();
1077
+ return /* @__PURE__ */ jsx(Checkbox$1, {
1078
+ checked: allSelected,
1079
+ indeterminate: !allSelected && someSelected,
1080
+ onCheckedChange: (value) => table.toggleAllRowsSelected(value === true),
1081
+ "aria-label": t("dataTable.selectAllRows")
1082
+ });
1083
+ }
1084
+ function SelectRowCell({ row }) {
1085
+ const t = useDsTranslation("ds");
1086
+ if (!row.getCanSelect()) return null;
1087
+ return /* @__PURE__ */ jsx("span", {
1088
+ className: "contents",
1089
+ onClick: (e) => e.stopPropagation(),
1090
+ children: /* @__PURE__ */ jsx(Checkbox$1, {
1091
+ checked: row.getIsSelected(),
1092
+ onCheckedChange: (value) => row.toggleSelected(value === true),
1093
+ "aria-label": t("dataTable.selectRow")
1094
+ })
1095
+ });
1096
+ }
1097
+ function makeSelectColumn(multiSelect, options) {
1098
+ return {
1099
+ id: SELECT_COLUMN_ID,
1100
+ header: multiSelect ? ({ table }) => /* @__PURE__ */ jsx(SelectAllHeader, { table }) : () => null,
1101
+ cell: ({ row }) => /* @__PURE__ */ jsx(SelectRowCell, { row }),
1102
+ enableSorting: false,
1103
+ enableHiding: false,
1104
+ enableResizing: false,
1105
+ size: 40,
1106
+ ...options?.pin ? { meta: { pin: "left" } } : {}
1107
+ };
1108
+ }
1109
+ function ResizeHandle({ header }) {
1110
+ const isResizing = header.column.getIsResizing();
1111
+ return /* @__PURE__ */ jsx("span", {
1112
+ "aria-hidden": true,
1113
+ onMouseDown: header.getResizeHandler(),
1114
+ onTouchStart: header.getResizeHandler(),
1115
+ onClick: (e) => e.stopPropagation(),
1116
+ 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")
1117
+ });
1118
+ }
1119
+ function SortableHeader({ header }) {
1120
+ const direction = header.column.getIsSorted();
1121
+ const Icon = direction === "asc" ? ChevronUpIcon : direction === "desc" ? ChevronDownIcon : ChevronsUpDownIcon;
1122
+ return /* @__PURE__ */ jsxs(Button$1, {
1123
+ variant: "ghost",
1124
+ size: "sm",
1125
+ className: "-ml-2 h-7 data-[icon=inline-end]:pr-2",
1126
+ onClick: header.column.getToggleSortingHandler(),
1127
+ children: [flexRender(header.column.columnDef.header, header.getContext()), /* @__PURE__ */ jsx(Icon, {
1128
+ "data-icon": "inline-end",
1129
+ className: cn("size-3.5", direction === false && "opacity-50")
1130
+ })]
1131
+ });
1132
+ }
1133
+ /**
1134
+ * Resolves a TanStack column id the same way the table does
1135
+ * (`id` → `accessorKey` → string `header`). See `@tanstack/table-core`
1136
+ * `createColumn`.
1137
+ */
1138
+ function getColumnDefId(col) {
1139
+ if (col.id != null) return col.id;
1140
+ if ("accessorKey" in col && typeof col.accessorKey === "string") return col.accessorKey.replace(/\./g, "_");
1141
+ if (typeof col.header === "string") return col.header;
1142
+ }
1143
+ /** Builds TanStack `columnPinning` state from declarative `meta.pin` on column defs. */
1144
+ function deriveColumnPinning(columns) {
1145
+ const left = [];
1146
+ const right = [];
1147
+ for (const col of columns) {
1148
+ const pin = col.meta?.pin;
1149
+ if (!pin) continue;
1150
+ const id = getColumnDefId(col);
1151
+ if (!id) {
1152
+ console.warn("[DataTable] Column with `meta.pin` has no resolvable id. Set `id`, a string `accessorKey`, or a string `header` so pinning can apply.");
1153
+ continue;
1154
+ }
1155
+ if (pin === "left") left.push(id);
1156
+ else right.push(id);
1157
+ }
1158
+ if (left.length === 0 && right.length === 0) return EMPTY_COLUMN_PINNING;
1159
+ return {
1160
+ left,
1161
+ right
1162
+ };
1163
+ }
1164
+ /**
1165
+ * Position/size/shadow props for a pinned (or width-pinned) cell. Uses CSS
1166
+ * `position: sticky` under the hood (TanStack column-pinning pattern). Edge
1167
+ * inset shadows only render on the outermost pinned column per side, and only
1168
+ * while horizontal scroll has moved away from that edge.
1169
+ */
1170
+ function getPinnedCellProps(column, options) {
1171
+ const { pinWidths, variant, fillHeight, showLeftEdgeShadow, showRightEdgeShadow } = options;
1172
+ const style = pinWidths ? { width: `${column.getSize()}px` } : {};
1173
+ const isPinned = column.getIsPinned();
1174
+ if (!isPinned) return { style };
1175
+ style.position = "sticky";
1176
+ if (isPinned === "left") style.left = `${column.getStart("left")}px`;
1177
+ else style.right = `${column.getAfter("right")}px`;
1178
+ if (variant === "header" && fillHeight) style.top = 0;
1179
+ style.zIndex = variant === "header" ? 30 : 1;
1180
+ const isEdgeLeft = isPinned === "left" && column.getIsLastColumn("left");
1181
+ const isEdgeRight = isPinned === "right" && column.getIsFirstColumn("right");
1182
+ const shadows = [];
1183
+ if (variant === "header" && fillHeight) shadows.push("inset 0 -1px 0 0 var(--border)");
1184
+ if (isEdgeLeft && showLeftEdgeShadow) shadows.push("inset -1px 0 0 0 var(--border)");
1185
+ if (isEdgeRight && showRightEdgeShadow) shadows.push("inset 1px 0 0 0 var(--border)");
1186
+ if (shadows.length > 0) style.boxShadow = shadows.join(", ");
1187
+ return {
1188
+ style,
1189
+ 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")
1190
+ };
1191
+ }
1192
+ function SkeletonRows({ columns, count, getCellPinProps, groupRows }) {
1193
+ return /* @__PURE__ */ jsx(Fragment, { children: Array.from({ length: count }, (_, i) => /* @__PURE__ */ jsx(TableRow, {
1194
+ className: groupRows ? "group" : void 0,
1195
+ children: columns.map((col) => {
1196
+ const pinProps = getCellPinProps(col, "body");
1197
+ return /* @__PURE__ */ jsx(TableCell, {
1198
+ "data-test": "loading-cell",
1199
+ style: pinProps.style,
1200
+ className: pinProps.className,
1201
+ children: /* @__PURE__ */ jsx(Skeleton, { className: "h-4 w-full max-w-full" })
1202
+ }, col.id);
1203
+ })
1204
+ }, `skeleton-${i}`)) });
1205
+ }
1206
+ //#endregion
1207
+ export { Button$1 as C, cn as E, registerI18nNamespace as S, linkStyle as T, ActionBarHeight as _, TableFooter as a, detectInitialLanguage as b, TableRow as c, Checkbox$1 as d, Spinner as f, ActionBarContext as g, ActionBarButton as h, TableCell as i, useFetchMoreSentinel as l, ActionBar as m, Table as n, TableHead as o, spinnerVariants as p, TableBody as r, TableHeader as s, DataTable as t, Skeleton as u, useDsTranslation as v, buttonVariants as w, dsI18n as x, SUPPORTED_LANGUAGES as y };