@krak-stack/registry 0.1.51 → 0.1.52

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,3655 @@
1
+ // ../../src/components/ui/data-table.tsx
2
+ import { useAtom, useAtomSet } from "@effect/atom-react";
3
+ import { BrowserKeyValueStore } from "@effect/platform-browser";
4
+ import { DateTime, Option, Schema } from "effect";
5
+ import { AsyncResult, Atom } from "effect/reactivity";
6
+ import {
7
+ ArrowDown,
8
+ ArrowUp,
9
+ ChevronDown,
10
+ ChevronRight as ChevronRight2,
11
+ ChevronsUpDown,
12
+ Download,
13
+ EyeOff,
14
+ FileJson,
15
+ FileText,
16
+ GripVertical,
17
+ LayoutGrid,
18
+ MoreHorizontal,
19
+ Plus,
20
+ RefreshCw,
21
+ Rows3,
22
+ Search,
23
+ Settings2,
24
+ Trash2,
25
+ X
26
+ } from "lucide-react";
27
+ import {
28
+ createContext,
29
+ isValidElement,
30
+ useCallback,
31
+ useContext,
32
+ useLayoutEffect,
33
+ useMemo,
34
+ useRef,
35
+ useState
36
+ } from "react";
37
+ import { createPortal } from "react-dom";
38
+
39
+ // ../../src/components/ui/badge.tsx
40
+ import { mergeProps } from "@base-ui/react/merge-props";
41
+ import { useRender } from "@base-ui/react/use-render";
42
+ import { cva } from "class-variance-authority";
43
+
44
+ // ../../src/lib/utils.ts
45
+ import { cn } from "cn";
46
+
47
+ // ../../src/components/ui/badge.tsx
48
+ var badgeVariants = cva("group/badge inline-flex h-5 w-fit shrink-0 items-center justify-center gap-1 overflow-hidden rounded-4xl border border-transparent px-2 py-0.5 text-xs font-medium whitespace-nowrap transition-all focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 has-data-[icon=inline-end]:pr-1.5 has-data-[icon=inline-start]:pl-1.5 aria-invalid:border-destructive aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 [&>svg]:pointer-events-none [&>svg]:size-3!", {
49
+ variants: {
50
+ variant: {
51
+ default: "bg-primary text-primary-foreground [a]:hover:bg-primary/80",
52
+ secondary: "bg-secondary text-secondary-foreground [a]:hover:bg-secondary/80",
53
+ destructive: "bg-destructive/10 text-destructive focus-visible:ring-destructive/20 dark:bg-destructive/20 dark:focus-visible:ring-destructive/40 [a]:hover:bg-destructive/20",
54
+ outline: "border-border text-foreground [a]:hover:bg-muted [a]:hover:text-muted-foreground",
55
+ ghost: "hover:bg-muted hover:text-muted-foreground dark:hover:bg-muted/50",
56
+ link: "text-primary underline-offset-4 hover:underline"
57
+ }
58
+ },
59
+ defaultVariants: {
60
+ variant: "default"
61
+ }
62
+ });
63
+ function Badge({
64
+ className,
65
+ variant = "default",
66
+ render,
67
+ ...props
68
+ }) {
69
+ return useRender({
70
+ defaultTagName: "span",
71
+ props: mergeProps({
72
+ className: cn(badgeVariants({ variant }), className)
73
+ }, props),
74
+ render,
75
+ state: {
76
+ slot: "badge",
77
+ variant
78
+ }
79
+ });
80
+ }
81
+
82
+ // ../../src/components/ui/button.tsx
83
+ import { Button as ButtonPrimitive } from "@base-ui/react/button";
84
+ import { cva as cva2 } from "class-variance-authority";
85
+ import { jsx } from "react/jsx-runtime";
86
+ var buttonVariants = cva2("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:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 active:not-aria-[haspopup]:translate-y-px disabled:pointer-events-none disabled:opacity-50 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", {
87
+ variants: {
88
+ variant: {
89
+ default: "bg-primary text-primary-foreground hover:bg-primary/80",
90
+ outline: "border-border bg-background shadow-xs hover:bg-muted hover:text-foreground aria-expanded:bg-muted aria-expanded:text-foreground dark:border-input dark:bg-input/30 dark:hover:bg-input/50",
91
+ secondary: "bg-secondary text-secondary-foreground hover:bg-[color-mix(in_oklch,var(--secondary),var(--foreground)_5%)] aria-expanded:bg-secondary aria-expanded:text-secondary-foreground",
92
+ ghost: "hover:bg-muted hover:text-foreground aria-expanded:bg-muted aria-expanded:text-foreground dark:hover:bg-muted/50",
93
+ destructive: "bg-destructive/10 text-destructive hover:bg-destructive/20 focus-visible:border-destructive/40 focus-visible:ring-destructive/20 dark:bg-destructive/20 dark:hover:bg-destructive/30 dark:focus-visible:ring-destructive/40",
94
+ link: "text-primary underline-offset-4 hover:underline"
95
+ },
96
+ size: {
97
+ default: "h-9 gap-1.5 px-2.5 in-data-[slot=button-group]:rounded-md has-data-[icon=inline-end]:pr-2 has-data-[icon=inline-start]:pl-2",
98
+ xs: "h-6 gap-1 rounded-[min(var(--radius-md),8px)] px-2 text-xs in-data-[slot=button-group]:rounded-md has-data-[icon=inline-end]:pr-1.5 has-data-[icon=inline-start]:pl-1.5 [&_svg:not([class*='size-'])]:size-3",
99
+ sm: "h-8 gap-1 rounded-[min(var(--radius-md),10px)] px-2.5 in-data-[slot=button-group]:rounded-md has-data-[icon=inline-end]:pr-1.5 has-data-[icon=inline-start]:pl-1.5",
100
+ lg: "h-10 gap-1.5 px-2.5 has-data-[icon=inline-end]:pr-2 has-data-[icon=inline-start]:pl-2",
101
+ icon: "size-9",
102
+ "icon-xs": "size-6 rounded-[min(var(--radius-md),8px)] in-data-[slot=button-group]:rounded-md [&_svg:not([class*='size-'])]:size-3",
103
+ "icon-sm": "size-8 rounded-[min(var(--radius-md),10px)] in-data-[slot=button-group]:rounded-md",
104
+ "icon-lg": "size-10"
105
+ }
106
+ },
107
+ defaultVariants: {
108
+ variant: "default",
109
+ size: "default"
110
+ }
111
+ });
112
+ function Button({
113
+ className,
114
+ variant = "default",
115
+ size = "default",
116
+ ...props
117
+ }) {
118
+ return /* @__PURE__ */ jsx(ButtonPrimitive, {
119
+ "data-slot": "button",
120
+ className: cn(buttonVariants({ variant, size, className })),
121
+ ...props
122
+ });
123
+ }
124
+
125
+ // ../../src/components/ui/card.tsx
126
+ import { jsx as jsx2 } from "react/jsx-runtime";
127
+ function Card({
128
+ className,
129
+ size = "default",
130
+ ...props
131
+ }) {
132
+ return /* @__PURE__ */ jsx2("div", {
133
+ "data-slot": "card",
134
+ "data-size": size,
135
+ className: cn("group/card flex flex-col gap-(--card-spacing) overflow-hidden rounded-xl bg-card py-(--card-spacing) text-sm text-card-foreground shadow-xs ring-1 ring-foreground/10 [--card-spacing:--spacing(6)] has-[>img:first-child]:pt-0 data-[size=sm]:[--card-spacing:--spacing(4)] *:[img:first-child]:rounded-t-xl *:[img:last-child]:rounded-b-xl", className),
136
+ ...props
137
+ });
138
+ }
139
+ function CardHeader({ className, ...props }) {
140
+ return /* @__PURE__ */ jsx2("div", {
141
+ "data-slot": "card-header",
142
+ className: cn("group/card-header @container/card-header grid auto-rows-min items-start gap-1 rounded-t-xl px-(--card-spacing) has-data-[slot=card-action]:grid-cols-[1fr_auto] has-data-[slot=card-description]:grid-rows-[auto_auto] [.border-b]:pb-(--card-spacing)", className),
143
+ ...props
144
+ });
145
+ }
146
+ function CardTitle({ className, ...props }) {
147
+ return /* @__PURE__ */ jsx2("div", {
148
+ "data-slot": "card-title",
149
+ className: cn("text-base leading-normal font-medium group-data-[size=sm]/card:text-sm", className),
150
+ ...props
151
+ });
152
+ }
153
+
154
+ // ../../src/components/ui/checkbox.tsx
155
+ import { Checkbox as CheckboxPrimitive } from "@base-ui/react/checkbox";
156
+ import { CheckIcon } from "lucide-react";
157
+ import { jsx as jsx3 } from "react/jsx-runtime";
158
+ "use client";
159
+ function Checkbox({ className, ...props }) {
160
+ return /* @__PURE__ */ jsx3(CheckboxPrimitive.Root, {
161
+ "data-slot": "checkbox",
162
+ className: cn("peer relative flex size-4 shrink-0 items-center justify-center rounded-[4px] border border-input shadow-xs transition-shadow outline-none 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 disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 aria-invalid:aria-checked:border-primary dark:bg-input/30 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40 data-checked:border-primary data-checked:bg-primary data-checked:text-primary-foreground dark:data-checked:bg-primary", className),
163
+ ...props,
164
+ children: /* @__PURE__ */ jsx3(CheckboxPrimitive.Indicator, {
165
+ "data-slot": "checkbox-indicator",
166
+ className: "grid place-content-center text-current transition-none [&>svg]:size-3.5",
167
+ children: /* @__PURE__ */ jsx3(CheckIcon, {})
168
+ })
169
+ });
170
+ }
171
+
172
+ // ../../src/components/ui/dropdown-menu.tsx
173
+ import { Menu as MenuPrimitive } from "@base-ui/react/menu";
174
+ import { ChevronRightIcon, CheckIcon as CheckIcon2 } from "lucide-react";
175
+ import { jsx as jsx4, jsxs } from "react/jsx-runtime";
176
+ function DropdownMenu({ ...props }) {
177
+ return /* @__PURE__ */ jsx4(MenuPrimitive.Root, {
178
+ "data-slot": "dropdown-menu",
179
+ ...props
180
+ });
181
+ }
182
+ function DropdownMenuTrigger({ ...props }) {
183
+ return /* @__PURE__ */ jsx4(MenuPrimitive.Trigger, {
184
+ "data-slot": "dropdown-menu-trigger",
185
+ ...props
186
+ });
187
+ }
188
+ function DropdownMenuContent({
189
+ align = "start",
190
+ alignOffset = 0,
191
+ side = "bottom",
192
+ sideOffset = 4,
193
+ className,
194
+ ...props
195
+ }) {
196
+ return /* @__PURE__ */ jsx4(MenuPrimitive.Portal, {
197
+ children: /* @__PURE__ */ jsx4(MenuPrimitive.Positioner, {
198
+ className: "isolate z-50 outline-none",
199
+ align,
200
+ alignOffset,
201
+ side,
202
+ sideOffset,
203
+ children: /* @__PURE__ */ jsx4(MenuPrimitive.Popup, {
204
+ "data-slot": "dropdown-menu-content",
205
+ className: cn("z-50 max-h-(--available-height) w-(--anchor-width) min-w-32 origin-(--transform-origin) overflow-x-hidden overflow-y-auto rounded-md bg-popover p-1 text-popover-foreground shadow-md ring-1 ring-foreground/10 duration-100 outline-none data-[side=bottom]:slide-in-from-top-2 data-[side=inline-end]:slide-in-from-left-2 data-[side=inline-start]:slide-in-from-right-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:overflow-hidden data-closed:fade-out-0 data-closed:zoom-out-95", className),
206
+ ...props
207
+ })
208
+ })
209
+ });
210
+ }
211
+ function DropdownMenuGroup({ ...props }) {
212
+ return /* @__PURE__ */ jsx4(MenuPrimitive.Group, {
213
+ "data-slot": "dropdown-menu-group",
214
+ ...props
215
+ });
216
+ }
217
+ function DropdownMenuLabel({
218
+ className,
219
+ inset,
220
+ ...props
221
+ }) {
222
+ return /* @__PURE__ */ jsx4(MenuPrimitive.GroupLabel, {
223
+ "data-slot": "dropdown-menu-label",
224
+ "data-inset": inset,
225
+ className: cn("px-2 py-1.5 text-xs font-medium text-muted-foreground data-inset:pl-8", className),
226
+ ...props
227
+ });
228
+ }
229
+ function DropdownMenuItem({
230
+ className,
231
+ inset,
232
+ variant = "default",
233
+ ...props
234
+ }) {
235
+ return /* @__PURE__ */ jsx4(MenuPrimitive.Item, {
236
+ "data-slot": "dropdown-menu-item",
237
+ "data-inset": inset,
238
+ "data-variant": variant,
239
+ className: cn("group/dropdown-menu-item relative flex cursor-default items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground not-data-[variant=destructive]:focus:**:text-accent-foreground data-inset:pl-8 data-[variant=destructive]:text-destructive data-[variant=destructive]:focus:bg-destructive/10 data-[variant=destructive]:focus:text-destructive dark:data-[variant=destructive]:focus:bg-destructive/20 data-disabled:pointer-events-none data-disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 data-[variant=destructive]:*:[svg]:text-destructive", className),
240
+ ...props
241
+ });
242
+ }
243
+ function DropdownMenuSub({ ...props }) {
244
+ return /* @__PURE__ */ jsx4(MenuPrimitive.SubmenuRoot, {
245
+ "data-slot": "dropdown-menu-sub",
246
+ ...props
247
+ });
248
+ }
249
+ function DropdownMenuSubTrigger({
250
+ className,
251
+ inset,
252
+ children,
253
+ ...props
254
+ }) {
255
+ return /* @__PURE__ */ jsxs(MenuPrimitive.SubmenuTrigger, {
256
+ "data-slot": "dropdown-menu-sub-trigger",
257
+ "data-inset": inset,
258
+ className: cn("flex cursor-default items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground not-data-[variant=destructive]:focus:**:text-accent-foreground data-inset:pl-8 data-popup-open:bg-accent data-popup-open:text-accent-foreground data-open:bg-accent data-open:text-accent-foreground [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4", className),
259
+ ...props,
260
+ children: [
261
+ children,
262
+ /* @__PURE__ */ jsx4(ChevronRightIcon, {
263
+ className: "ml-auto"
264
+ })
265
+ ]
266
+ });
267
+ }
268
+ function DropdownMenuSubContent({
269
+ align = "start",
270
+ alignOffset = -3,
271
+ side = "right",
272
+ sideOffset = 0,
273
+ className,
274
+ ...props
275
+ }) {
276
+ return /* @__PURE__ */ jsx4(DropdownMenuContent, {
277
+ "data-slot": "dropdown-menu-sub-content",
278
+ className: cn("w-auto min-w-[96px] rounded-md bg-popover p-1 text-popover-foreground shadow-lg ring-1 ring-foreground/10 duration-100 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95", className),
279
+ align,
280
+ alignOffset,
281
+ side,
282
+ sideOffset,
283
+ ...props
284
+ });
285
+ }
286
+ function DropdownMenuRadioGroup({ ...props }) {
287
+ return /* @__PURE__ */ jsx4(MenuPrimitive.RadioGroup, {
288
+ "data-slot": "dropdown-menu-radio-group",
289
+ ...props
290
+ });
291
+ }
292
+ function DropdownMenuSeparator({
293
+ className,
294
+ ...props
295
+ }) {
296
+ return /* @__PURE__ */ jsx4(MenuPrimitive.Separator, {
297
+ "data-slot": "dropdown-menu-separator",
298
+ className: cn("-mx-1 my-1 h-px bg-border", className),
299
+ ...props
300
+ });
301
+ }
302
+
303
+ // ../../src/components/ui/input.tsx
304
+ import { Input as InputPrimitive } from "@base-ui/react/input";
305
+ import { jsx as jsx5 } from "react/jsx-runtime";
306
+ function Input({ className, type, ...props }) {
307
+ return /* @__PURE__ */ jsx5(InputPrimitive, {
308
+ type,
309
+ "data-slot": "input",
310
+ className: cn("h-9 w-full min-w-0 rounded-md border border-input bg-transparent px-2.5 py-1 text-base shadow-xs transition-[color,box-shadow] outline-none file:inline-flex file:h-7 file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 md:text-sm dark:bg-input/30 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40", className),
311
+ ...props
312
+ });
313
+ }
314
+
315
+ // ../../src/components/ui/loading.tsx
316
+ import { Loader2 } from "lucide-react";
317
+ import { useKrakstackLocale } from "@krak-stack/registry/krakstack-provider";
318
+ import { jsx as jsx6, jsxs as jsxs2 } from "react/jsx-runtime";
319
+ var labels = {
320
+ en: {
321
+ loading: "Loading..."
322
+ },
323
+ fr: {
324
+ loading: "Chargement..."
325
+ }
326
+ };
327
+ var loadingLabel = (locale, messages) => messages?.[locale]?.loading ?? messages?.[locale.split("-")[0] ?? locale]?.loading ?? (locale.startsWith("fr") ? labels.fr.loading : labels.en.loading);
328
+ function Loading({
329
+ className,
330
+ label,
331
+ locale: localeOverride,
332
+ messages,
333
+ variant = "inline"
334
+ }) {
335
+ const locale = useKrakstackLocale(localeOverride);
336
+ return /* @__PURE__ */ jsxs2("div", {
337
+ className: cn("text-muted-foreground flex items-center justify-center gap-2 text-sm", variant === "centered" && "min-h-[50svh] w-full", className),
338
+ children: [
339
+ /* @__PURE__ */ jsx6(Loader2, {
340
+ className: "size-4 animate-spin"
341
+ }),
342
+ label ?? loadingLabel(locale, messages)
343
+ ]
344
+ });
345
+ }
346
+
347
+ // ../../src/components/ui/menubar.tsx
348
+ import { Menu as MenuPrimitive2 } from "@base-ui/react/menu";
349
+ import { Menubar as MenubarPrimitive } from "@base-ui/react/menubar";
350
+ import { CheckIcon as CheckIcon3 } from "lucide-react";
351
+ import { jsx as jsx7, jsxs as jsxs3 } from "react/jsx-runtime";
352
+ "use client";
353
+ function Menubar({ className, ...props }) {
354
+ return /* @__PURE__ */ jsx7(MenubarPrimitive, {
355
+ "data-slot": "menubar",
356
+ className: cn("flex h-9 items-center gap-1 rounded-md border p-1 shadow-xs", className),
357
+ ...props
358
+ });
359
+ }
360
+ function MenubarMenu({ ...props }) {
361
+ return /* @__PURE__ */ jsx7(DropdownMenu, {
362
+ "data-slot": "menubar-menu",
363
+ ...props
364
+ });
365
+ }
366
+ function MenubarGroup({
367
+ ...props
368
+ }) {
369
+ return /* @__PURE__ */ jsx7(DropdownMenuGroup, {
370
+ "data-slot": "menubar-group",
371
+ ...props
372
+ });
373
+ }
374
+ function MenubarTrigger({
375
+ className,
376
+ ...props
377
+ }) {
378
+ return /* @__PURE__ */ jsx7(DropdownMenuTrigger, {
379
+ "data-slot": "menubar-trigger",
380
+ className: cn("flex items-center rounded-sm px-2 py-1 text-sm font-medium outline-hidden select-none hover:bg-muted aria-expanded:bg-muted", className),
381
+ ...props
382
+ });
383
+ }
384
+ function MenubarContent({
385
+ className,
386
+ align = "start",
387
+ alignOffset = -4,
388
+ sideOffset = 8,
389
+ ...props
390
+ }) {
391
+ return /* @__PURE__ */ jsx7(DropdownMenuContent, {
392
+ "data-slot": "menubar-content",
393
+ align,
394
+ alignOffset,
395
+ sideOffset,
396
+ className: cn("min-w-36 rounded-md bg-popover p-1 text-popover-foreground shadow-md ring-1 ring-foreground/10 duration-100 data-[side=bottom]:slide-in-from-top-2 data-[side=inline-end]:slide-in-from-left-2 data-[side=inline-start]:slide-in-from-right-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95", className),
397
+ ...props
398
+ });
399
+ }
400
+ function MenubarItem({
401
+ className,
402
+ inset,
403
+ variant = "default",
404
+ ...props
405
+ }) {
406
+ return /* @__PURE__ */ jsx7(DropdownMenuItem, {
407
+ "data-slot": "menubar-item",
408
+ "data-inset": inset,
409
+ "data-variant": variant,
410
+ className: cn("group/menubar-item gap-2 rounded-sm px-2 py-1.5 text-sm focus:bg-accent focus:text-accent-foreground not-data-[variant=destructive]:focus:**:text-accent-foreground data-inset:pl-8 data-[variant=destructive]:text-destructive data-[variant=destructive]:focus:bg-destructive/10 data-[variant=destructive]:focus:text-destructive dark:data-[variant=destructive]:focus:bg-destructive/20 data-disabled:opacity-50 [&_svg:not([class*='size-'])]:size-4 data-[variant=destructive]:*:[svg]:text-destructive!", className),
411
+ ...props
412
+ });
413
+ }
414
+ function MenubarCheckboxItem({
415
+ className,
416
+ children,
417
+ checked,
418
+ inset,
419
+ ...props
420
+ }) {
421
+ return /* @__PURE__ */ jsxs3(MenuPrimitive2.CheckboxItem, {
422
+ "data-slot": "menubar-checkbox-item",
423
+ "data-inset": inset,
424
+ className: cn("relative flex cursor-default items-center gap-2 rounded-md py-1.5 pr-2 pl-8 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground focus:**:text-accent-foreground data-inset:pl-8 data-disabled:pointer-events-none data-disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0", className),
425
+ checked,
426
+ ...props,
427
+ children: [
428
+ /* @__PURE__ */ jsx7("span", {
429
+ className: "pointer-events-none absolute left-2 flex size-4 items-center justify-center [&_svg:not([class*='size-'])]:size-4",
430
+ children: /* @__PURE__ */ jsx7(MenuPrimitive2.CheckboxItemIndicator, {
431
+ children: /* @__PURE__ */ jsx7(CheckIcon3, {})
432
+ })
433
+ }),
434
+ children
435
+ ]
436
+ });
437
+ }
438
+ function MenubarRadioGroup({
439
+ ...props
440
+ }) {
441
+ return /* @__PURE__ */ jsx7(DropdownMenuRadioGroup, {
442
+ "data-slot": "menubar-radio-group",
443
+ ...props
444
+ });
445
+ }
446
+ function MenubarRadioItem({
447
+ className,
448
+ children,
449
+ inset,
450
+ ...props
451
+ }) {
452
+ return /* @__PURE__ */ jsxs3(MenuPrimitive2.RadioItem, {
453
+ "data-slot": "menubar-radio-item",
454
+ "data-inset": inset,
455
+ className: cn("relative flex cursor-default items-center gap-2 rounded-md py-1.5 pr-2 pl-8 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground focus:**:text-accent-foreground data-inset:pl-8 data-disabled:pointer-events-none data-disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4", className),
456
+ ...props,
457
+ children: [
458
+ /* @__PURE__ */ jsx7("span", {
459
+ className: "pointer-events-none absolute left-2 flex size-4 items-center justify-center [&_svg:not([class*='size-'])]:size-4",
460
+ children: /* @__PURE__ */ jsx7(MenuPrimitive2.RadioItemIndicator, {
461
+ children: /* @__PURE__ */ jsx7(CheckIcon3, {})
462
+ })
463
+ }),
464
+ children
465
+ ]
466
+ });
467
+ }
468
+ function MenubarLabel({
469
+ className,
470
+ inset,
471
+ ...props
472
+ }) {
473
+ return /* @__PURE__ */ jsx7(DropdownMenuLabel, {
474
+ "data-slot": "menubar-label",
475
+ "data-inset": inset,
476
+ className: cn("px-2 py-1.5 text-sm font-medium data-inset:pl-8", className),
477
+ ...props
478
+ });
479
+ }
480
+ function MenubarSeparator({
481
+ className,
482
+ ...props
483
+ }) {
484
+ return /* @__PURE__ */ jsx7(DropdownMenuSeparator, {
485
+ "data-slot": "menubar-separator",
486
+ className: cn("-mx-1 my-1 h-px bg-border", className),
487
+ ...props
488
+ });
489
+ }
490
+ function MenubarSub({
491
+ ...props
492
+ }) {
493
+ return /* @__PURE__ */ jsx7(DropdownMenuSub, {
494
+ "data-slot": "menubar-sub",
495
+ ...props
496
+ });
497
+ }
498
+ function MenubarSubTrigger({
499
+ className,
500
+ inset,
501
+ ...props
502
+ }) {
503
+ return /* @__PURE__ */ jsx7(DropdownMenuSubTrigger, {
504
+ "data-slot": "menubar-sub-trigger",
505
+ "data-inset": inset,
506
+ className: cn("gap-2 rounded-sm px-2 py-1.5 text-sm focus:bg-accent focus:text-accent-foreground data-inset:pl-8 data-open:bg-accent data-open:text-accent-foreground [&_svg:not([class*='size-'])]:size-4", className),
507
+ ...props
508
+ });
509
+ }
510
+ function MenubarSubContent({
511
+ className,
512
+ ...props
513
+ }) {
514
+ return /* @__PURE__ */ jsx7(DropdownMenuSubContent, {
515
+ "data-slot": "menubar-sub-content",
516
+ className: cn("min-w-32 rounded-md bg-popover p-1 text-popover-foreground shadow-lg ring-1 ring-foreground/10 duration-100 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95", className),
517
+ ...props
518
+ });
519
+ }
520
+
521
+ // ../../src/components/ui/pagination.tsx
522
+ import {
523
+ ChevronLeft,
524
+ ChevronRight,
525
+ ChevronsLeft,
526
+ ChevronsRight
527
+ } from "lucide-react";
528
+ import { useId } from "react";
529
+
530
+ // ../../src/components/ui/label.tsx
531
+ import { jsx as jsx8 } from "react/jsx-runtime";
532
+ "use client";
533
+ function Label({ className, ...props }) {
534
+ return /* @__PURE__ */ jsx8("label", {
535
+ "data-slot": "label",
536
+ className: cn("flex items-center gap-2 text-sm leading-none font-medium select-none group-data-[disabled=true]:pointer-events-none group-data-[disabled=true]:opacity-50 peer-disabled:cursor-not-allowed peer-disabled:opacity-50", className),
537
+ ...props
538
+ });
539
+ }
540
+
541
+ // ../../src/components/ui/select.tsx
542
+ import { Select as SelectPrimitive } from "@base-ui/react/select";
543
+ import { ChevronDownIcon, CheckIcon as CheckIcon4, ChevronUpIcon } from "lucide-react";
544
+ import { jsx as jsx9, jsxs as jsxs4 } from "react/jsx-runtime";
545
+ "use client";
546
+ var Select = SelectPrimitive.Root;
547
+ function SelectValue({ className, ...props }) {
548
+ return /* @__PURE__ */ jsx9(SelectPrimitive.Value, {
549
+ "data-slot": "select-value",
550
+ className: cn("flex flex-1 text-left", className),
551
+ ...props
552
+ });
553
+ }
554
+ function SelectTrigger({
555
+ className,
556
+ size = "default",
557
+ children,
558
+ ...props
559
+ }) {
560
+ return /* @__PURE__ */ jsxs4(SelectPrimitive.Trigger, {
561
+ "data-slot": "select-trigger",
562
+ "data-size": size,
563
+ className: cn("flex w-fit items-center justify-between gap-1.5 rounded-md border border-input bg-transparent py-2 pr-2 pl-2.5 text-sm whitespace-nowrap shadow-xs transition-[color,box-shadow] outline-none focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 data-placeholder:text-muted-foreground data-[size=default]:h-9 data-[size=sm]:h-8 *:data-[slot=select-value]:line-clamp-1 *:data-[slot=select-value]:flex *:data-[slot=select-value]:items-center *:data-[slot=select-value]:gap-1.5 dark:bg-input/30 dark:hover:bg-input/50 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", className),
564
+ ...props,
565
+ children: [
566
+ children,
567
+ /* @__PURE__ */ jsx9(SelectPrimitive.Icon, {
568
+ render: /* @__PURE__ */ jsx9(ChevronDownIcon, {
569
+ className: "text-muted-foreground pointer-events-none size-4"
570
+ })
571
+ })
572
+ ]
573
+ });
574
+ }
575
+ function SelectContent({
576
+ className,
577
+ children,
578
+ side = "bottom",
579
+ sideOffset = 4,
580
+ align = "center",
581
+ alignOffset = 0,
582
+ alignItemWithTrigger = true,
583
+ ...props
584
+ }) {
585
+ return /* @__PURE__ */ jsx9(SelectPrimitive.Portal, {
586
+ children: /* @__PURE__ */ jsx9(SelectPrimitive.Positioner, {
587
+ side,
588
+ sideOffset,
589
+ align,
590
+ alignOffset,
591
+ alignItemWithTrigger,
592
+ className: "isolate z-50",
593
+ children: /* @__PURE__ */ jsxs4(SelectPrimitive.Popup, {
594
+ "data-slot": "select-content",
595
+ "data-align-trigger": alignItemWithTrigger,
596
+ className: cn("relative isolate z-50 max-h-(--available-height) w-(--anchor-width) min-w-36 origin-(--transform-origin) overflow-x-hidden overflow-y-auto rounded-md bg-popover text-popover-foreground shadow-md ring-1 ring-foreground/10 duration-100 data-[align-trigger=true]:animate-none data-[side=bottom]:slide-in-from-top-2 data-[side=inline-end]:slide-in-from-left-2 data-[side=inline-start]:slide-in-from-right-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95", className),
597
+ ...props,
598
+ children: [
599
+ /* @__PURE__ */ jsx9(SelectScrollUpButton, {}),
600
+ /* @__PURE__ */ jsx9(SelectPrimitive.List, {
601
+ children
602
+ }),
603
+ /* @__PURE__ */ jsx9(SelectScrollDownButton, {})
604
+ ]
605
+ })
606
+ })
607
+ });
608
+ }
609
+ function SelectItem({
610
+ className,
611
+ children,
612
+ ...props
613
+ }) {
614
+ return /* @__PURE__ */ jsxs4(SelectPrimitive.Item, {
615
+ "data-slot": "select-item",
616
+ className: cn("relative flex w-full cursor-default items-center gap-2 rounded-sm py-1.5 pr-8 pl-2 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground not-data-[variant=destructive]:focus:**:text-accent-foreground data-disabled:pointer-events-none data-disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 *:[span]:last:flex *:[span]:last:items-center *:[span]:last:gap-2", className),
617
+ ...props,
618
+ children: [
619
+ /* @__PURE__ */ jsx9(SelectPrimitive.ItemText, {
620
+ className: "flex flex-1 shrink-0 gap-2 whitespace-nowrap",
621
+ children
622
+ }),
623
+ /* @__PURE__ */ jsx9(SelectPrimitive.ItemIndicator, {
624
+ render: /* @__PURE__ */ jsx9("span", {
625
+ className: "pointer-events-none absolute right-2 flex size-4 items-center justify-center"
626
+ }),
627
+ children: /* @__PURE__ */ jsx9(CheckIcon4, {
628
+ className: "pointer-events-none"
629
+ })
630
+ })
631
+ ]
632
+ });
633
+ }
634
+ function SelectScrollUpButton({
635
+ className,
636
+ ...props
637
+ }) {
638
+ return /* @__PURE__ */ jsx9(SelectPrimitive.ScrollUpArrow, {
639
+ "data-slot": "select-scroll-up-button",
640
+ className: cn("top-0 z-10 flex w-full cursor-default items-center justify-center bg-popover py-1 [&_svg:not([class*='size-'])]:size-4", className),
641
+ ...props,
642
+ children: /* @__PURE__ */ jsx9(ChevronUpIcon, {})
643
+ });
644
+ }
645
+ function SelectScrollDownButton({
646
+ className,
647
+ ...props
648
+ }) {
649
+ return /* @__PURE__ */ jsx9(SelectPrimitive.ScrollDownArrow, {
650
+ "data-slot": "select-scroll-down-button",
651
+ className: cn("bottom-0 z-10 flex w-full cursor-default items-center justify-center bg-popover py-1 [&_svg:not([class*='size-'])]:size-4", className),
652
+ ...props,
653
+ children: /* @__PURE__ */ jsx9(ChevronDownIcon, {})
654
+ });
655
+ }
656
+
657
+ // ../../src/components/ui/pagination.tsx
658
+ import { useKrakstackLocale as useKrakstackLocale2 } from "@krak-stack/registry/krakstack-provider";
659
+ import { jsx as jsx10, jsxs as jsxs5 } from "react/jsx-runtime";
660
+ var messages = {
661
+ en: {
662
+ pageSize: "Page size",
663
+ results: (count) => `${count} results`,
664
+ selectedOf: (selected, total) => `${selected} of ${total}`,
665
+ pageOf: (page, total) => `Page ${page} of ${total}`,
666
+ goToFirstPage: "Go to first page",
667
+ goToPreviousPage: "Go to previous page",
668
+ goToNextPage: "Go to next page",
669
+ goToLastPage: "Go to last page"
670
+ },
671
+ fr: {
672
+ pageSize: "Taille de la page",
673
+ results: (count) => `${count} résultats`,
674
+ selectedOf: (selected, total) => `${selected} sur ${total}`,
675
+ pageOf: (page, total) => `Page ${page} sur ${total}`,
676
+ goToFirstPage: "Aller à la première page",
677
+ goToPreviousPage: "Aller à la page précédente",
678
+ goToNextPage: "Aller à la page suivante",
679
+ goToLastPage: "Aller à la dernière page"
680
+ }
681
+ };
682
+ var paginationMessages = (locale = "en", translations) => ({
683
+ ...locale.startsWith("fr") ? messages.fr : messages.en,
684
+ ...translations?.[locale.split("-")[0] ?? locale],
685
+ ...translations?.[locale]
686
+ });
687
+ function Pagination({
688
+ compact = false,
689
+ locale: localeOverride,
690
+ messages: messageOverrides,
691
+ onPageChange,
692
+ onPageSizeChange,
693
+ page,
694
+ pageCount,
695
+ pageSize,
696
+ pageSizes = [10, 20, 30, 40, 50],
697
+ selectedRows = 0,
698
+ showResults = true,
699
+ totalRows
700
+ }) {
701
+ const locale = useKrakstackLocale2(localeOverride);
702
+ const labels = paginationMessages(locale, messageOverrides);
703
+ const pageSizeId = useId();
704
+ const canGoBack = page > 0;
705
+ const canGoForward = page + 1 < pageCount;
706
+ return /* @__PURE__ */ jsxs5("div", {
707
+ className: cn("flex flex-col gap-3 px-2 sm:flex-row sm:items-center sm:justify-between", compact && "gap-2 px-0 sm:flex-col sm:items-stretch"),
708
+ children: [
709
+ showResults ? /* @__PURE__ */ jsxs5("div", {
710
+ className: "text-muted-foreground flex flex-wrap items-center gap-x-3 gap-y-1 text-sm",
711
+ children: [
712
+ /* @__PURE__ */ jsx10("span", {
713
+ children: labels.results(totalRows)
714
+ }),
715
+ selectedRows > 0 ? /* @__PURE__ */ jsx10("span", {
716
+ children: labels.selectedOf(selectedRows, totalRows)
717
+ }) : null
718
+ ]
719
+ }) : null,
720
+ /* @__PURE__ */ jsxs5("div", {
721
+ className: cn("flex items-center gap-4 sm:justify-end", compact && "flex-wrap justify-between gap-2 sm:justify-between"),
722
+ children: [
723
+ /* @__PURE__ */ jsxs5("div", {
724
+ className: "flex items-center gap-2",
725
+ children: [
726
+ /* @__PURE__ */ jsx10(Label, {
727
+ htmlFor: pageSizeId,
728
+ className: cn("hidden text-sm sm:block", compact && "block"),
729
+ children: labels.pageSize
730
+ }),
731
+ /* @__PURE__ */ jsxs5(Select, {
732
+ items: pageSizes.map((size) => ({
733
+ label: size.toString(),
734
+ value: size.toString()
735
+ })),
736
+ value: `${pageSize}`,
737
+ onValueChange: (value) => onPageSizeChange(Number(value)),
738
+ children: [
739
+ /* @__PURE__ */ jsx10(SelectTrigger, {
740
+ className: "h-8 w-[70px]",
741
+ id: pageSizeId,
742
+ children: /* @__PURE__ */ jsx10(SelectValue, {
743
+ placeholder: pageSize
744
+ })
745
+ }),
746
+ /* @__PURE__ */ jsx10(SelectContent, {
747
+ side: "top",
748
+ children: pageSizes.map((size) => /* @__PURE__ */ jsx10(SelectItem, {
749
+ value: `${size}`,
750
+ children: size
751
+ }, size))
752
+ })
753
+ ]
754
+ })
755
+ ]
756
+ }),
757
+ /* @__PURE__ */ jsxs5("div", {
758
+ className: "flex items-center gap-2",
759
+ children: [
760
+ /* @__PURE__ */ jsx10("div", {
761
+ className: "flex items-center justify-center text-sm font-medium sm:block",
762
+ children: labels.pageOf(page + 1, pageCount)
763
+ }),
764
+ /* @__PURE__ */ jsxs5("div", {
765
+ className: "flex items-center gap-1",
766
+ children: [
767
+ /* @__PURE__ */ jsxs5(Button, {
768
+ className: cn("hidden h-8 w-8 p-0 lg:flex", compact && "!hidden"),
769
+ disabled: !canGoBack,
770
+ onClick: () => onPageChange(0),
771
+ type: "button",
772
+ children: [
773
+ /* @__PURE__ */ jsx10("span", {
774
+ className: "sr-only",
775
+ children: labels.goToFirstPage
776
+ }),
777
+ /* @__PURE__ */ jsx10(ChevronsLeft, {})
778
+ ]
779
+ }),
780
+ /* @__PURE__ */ jsxs5(Button, {
781
+ className: "h-8 w-8 p-0",
782
+ disabled: !canGoBack,
783
+ onClick: () => onPageChange(page - 1),
784
+ type: "button",
785
+ children: [
786
+ /* @__PURE__ */ jsx10("span", {
787
+ className: "sr-only",
788
+ children: labels.goToPreviousPage
789
+ }),
790
+ /* @__PURE__ */ jsx10(ChevronLeft, {})
791
+ ]
792
+ }),
793
+ /* @__PURE__ */ jsxs5(Button, {
794
+ className: "h-8 w-8 p-0",
795
+ disabled: !canGoForward,
796
+ onClick: () => onPageChange(page + 1),
797
+ type: "button",
798
+ children: [
799
+ /* @__PURE__ */ jsx10("span", {
800
+ className: "sr-only",
801
+ children: labels.goToNextPage
802
+ }),
803
+ /* @__PURE__ */ jsx10(ChevronRight, {})
804
+ ]
805
+ }),
806
+ /* @__PURE__ */ jsxs5(Button, {
807
+ className: cn("hidden h-8 w-8 p-0 lg:flex", compact && "!hidden"),
808
+ disabled: !canGoForward,
809
+ onClick: () => onPageChange(pageCount - 1),
810
+ type: "button",
811
+ children: [
812
+ /* @__PURE__ */ jsx10("span", {
813
+ className: "sr-only",
814
+ children: labels.goToLastPage
815
+ }),
816
+ /* @__PURE__ */ jsx10(ChevronsRight, {})
817
+ ]
818
+ })
819
+ ]
820
+ })
821
+ ]
822
+ })
823
+ ]
824
+ })
825
+ ]
826
+ });
827
+ }
828
+
829
+ // ../../src/components/ui/scroll-area.tsx
830
+ import { ScrollArea as ScrollAreaPrimitive } from "@base-ui/react/scroll-area";
831
+ import { jsx as jsx11, jsxs as jsxs6 } from "react/jsx-runtime";
832
+ function ScrollArea({
833
+ className,
834
+ children,
835
+ ...props
836
+ }) {
837
+ return /* @__PURE__ */ jsxs6(ScrollAreaPrimitive.Root, {
838
+ "data-slot": "scroll-area",
839
+ className: cn("relative", className),
840
+ ...props,
841
+ children: [
842
+ /* @__PURE__ */ jsx11(ScrollAreaPrimitive.Viewport, {
843
+ "data-slot": "scroll-area-viewport",
844
+ className: "focus-visible:ring-ring/50 size-full rounded-[inherit] transition-[color,box-shadow] outline-none focus-visible:ring-[3px] focus-visible:outline-1",
845
+ children
846
+ }),
847
+ /* @__PURE__ */ jsx11(ScrollBar, {}),
848
+ /* @__PURE__ */ jsx11(ScrollAreaPrimitive.Corner, {})
849
+ ]
850
+ });
851
+ }
852
+ function ScrollBar({
853
+ className,
854
+ orientation = "vertical",
855
+ ...props
856
+ }) {
857
+ return /* @__PURE__ */ jsx11(ScrollAreaPrimitive.Scrollbar, {
858
+ "data-slot": "scroll-area-scrollbar",
859
+ "data-orientation": orientation,
860
+ orientation,
861
+ className: cn("flex touch-none p-px transition-colors select-none data-horizontal:h-2.5 data-horizontal:flex-col data-horizontal:border-t data-horizontal:border-t-transparent data-vertical:h-full data-vertical:w-2.5 data-vertical:border-l data-vertical:border-l-transparent", className),
862
+ ...props,
863
+ children: /* @__PURE__ */ jsx11(ScrollAreaPrimitive.Thumb, {
864
+ "data-slot": "scroll-area-thumb",
865
+ className: "bg-border relative flex-1 rounded-full"
866
+ })
867
+ });
868
+ }
869
+
870
+ // ../../src/components/ui/table.tsx
871
+ import { jsx as jsx12 } from "react/jsx-runtime";
872
+ function Table({ className, ...props }) {
873
+ return /* @__PURE__ */ jsx12("div", {
874
+ "data-slot": "table-container",
875
+ className: "relative w-full overflow-x-auto",
876
+ children: /* @__PURE__ */ jsx12("table", {
877
+ "data-slot": "table",
878
+ className: cn("w-full caption-bottom text-sm", className),
879
+ ...props
880
+ })
881
+ });
882
+ }
883
+ function TableHeader({ className, ...props }) {
884
+ return /* @__PURE__ */ jsx12("thead", {
885
+ "data-slot": "table-header",
886
+ className: cn("[&_tr]:border-b", className),
887
+ ...props
888
+ });
889
+ }
890
+ function TableBody({ className, ...props }) {
891
+ return /* @__PURE__ */ jsx12("tbody", {
892
+ "data-slot": "table-body",
893
+ className: cn("[&_tr:last-child]:border-0", className),
894
+ ...props
895
+ });
896
+ }
897
+ function TableRow({ className, ...props }) {
898
+ return /* @__PURE__ */ jsx12("tr", {
899
+ "data-slot": "table-row",
900
+ className: cn("border-b transition-colors hover:bg-muted/50 has-aria-expanded:bg-muted/50 data-[state=selected]:bg-muted", className),
901
+ ...props
902
+ });
903
+ }
904
+ function TableHead({ className, ...props }) {
905
+ return /* @__PURE__ */ jsx12("th", {
906
+ "data-slot": "table-head",
907
+ className: cn("h-10 px-2 text-left align-middle font-medium whitespace-nowrap text-foreground [&:has([role=checkbox])]:pr-0", className),
908
+ ...props
909
+ });
910
+ }
911
+ function TableCell({ className, ...props }) {
912
+ return /* @__PURE__ */ jsx12("td", {
913
+ "data-slot": "table-cell",
914
+ className: cn("p-2 align-middle whitespace-nowrap [&:has([role=checkbox])]:pr-0", className),
915
+ ...props
916
+ });
917
+ }
918
+
919
+ // ../../src/components/ui/tooltip.tsx
920
+ import { Tooltip as TooltipPrimitive } from "@base-ui/react/tooltip";
921
+ import { jsx as jsx13, jsxs as jsxs7 } from "react/jsx-runtime";
922
+ "use client";
923
+ function TooltipProvider({
924
+ delay = 0,
925
+ ...props
926
+ }) {
927
+ return /* @__PURE__ */ jsx13(TooltipPrimitive.Provider, {
928
+ "data-slot": "tooltip-provider",
929
+ delay,
930
+ ...props
931
+ });
932
+ }
933
+ function Tooltip({ ...props }) {
934
+ return /* @__PURE__ */ jsx13(TooltipPrimitive.Root, {
935
+ "data-slot": "tooltip",
936
+ ...props
937
+ });
938
+ }
939
+ function TooltipTrigger({ ...props }) {
940
+ return /* @__PURE__ */ jsx13(TooltipPrimitive.Trigger, {
941
+ "data-slot": "tooltip-trigger",
942
+ ...props
943
+ });
944
+ }
945
+ function TooltipContent({
946
+ className,
947
+ side = "top",
948
+ sideOffset = 4,
949
+ align = "center",
950
+ alignOffset = 0,
951
+ children,
952
+ ...props
953
+ }) {
954
+ return /* @__PURE__ */ jsx13(TooltipPrimitive.Portal, {
955
+ children: /* @__PURE__ */ jsx13(TooltipPrimitive.Positioner, {
956
+ align,
957
+ alignOffset,
958
+ side,
959
+ sideOffset,
960
+ className: "isolate z-50",
961
+ children: /* @__PURE__ */ jsxs7(TooltipPrimitive.Popup, {
962
+ "data-slot": "tooltip-content",
963
+ className: cn("z-50 inline-flex w-fit max-w-xs origin-(--transform-origin) items-center gap-1.5 rounded-md bg-foreground px-3 py-1.5 text-xs text-background has-data-[slot=kbd]:pr-1.5 data-[side=bottom]:slide-in-from-top-2 data-[side=inline-end]:slide-in-from-left-2 data-[side=inline-start]:slide-in-from-right-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 **:data-[slot=kbd]:relative **:data-[slot=kbd]:isolate **:data-[slot=kbd]:z-50 **:data-[slot=kbd]:rounded-sm data-[state=delayed-open]:animate-in data-[state=delayed-open]:fade-in-0 data-[state=delayed-open]:zoom-in-95 data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95", className),
964
+ ...props,
965
+ children: [
966
+ children,
967
+ /* @__PURE__ */ jsx13(TooltipPrimitive.Arrow, {
968
+ className: "bg-foreground fill-foreground z-50 size-2.5 translate-y-[calc(-50%-2px)] rotate-45 rounded-[2px] data-[side=bottom]:top-1 data-[side=inline-end]:top-1/2! data-[side=inline-end]:-left-1 data-[side=inline-end]:-translate-y-1/2 data-[side=inline-start]:top-1/2! data-[side=inline-start]:-right-1 data-[side=inline-start]:-translate-y-1/2 data-[side=left]:top-1/2! data-[side=left]:-right-1 data-[side=left]:-translate-y-1/2 data-[side=right]:top-1/2! data-[side=right]:-left-1 data-[side=right]:-translate-y-1/2 data-[side=top]:-bottom-2.5"
969
+ })
970
+ ]
971
+ })
972
+ })
973
+ });
974
+ }
975
+
976
+ // ../../src/components/ui/data-table.tsx
977
+ import { useKrakstackLocale as useKrakstackLocale3 } from "@krak-stack/registry/krakstack-provider";
978
+ import { jsx as jsx14, jsxs as jsxs8, Fragment } from "react/jsx-runtime";
979
+ var DataTablePersistedUiStateSchema = Schema.Struct({
980
+ columnVisibility: Schema.Record(Schema.String, Schema.Boolean),
981
+ columnSizing: Schema.Record(Schema.String, Schema.Number),
982
+ grouping: Schema.optionalKey(Schema.Array(Schema.String)),
983
+ view: Schema.Literals(["table", "gallery"])
984
+ }).annotate({ identifier: "DataTablePersistedUiState" });
985
+ var dataTableStorageRuntime = Atom.runtime(BrowserKeyValueStore.layerLocalStorage);
986
+ var DataTableReferenceCell = ({
987
+ item,
988
+ emptyLabel = "—",
989
+ imageVariant = "circle"
990
+ }) => {
991
+ const [failedImage, setFailedImage] = useState();
992
+ if (!item)
993
+ return emptyLabel;
994
+ const initials = item.label.trim().split(/\s+/).slice(0, 2).map((word) => word.slice(0, 1)).join("").toLocaleUpperCase();
995
+ return /* @__PURE__ */ jsxs8("div", {
996
+ className: "flex min-w-0 items-center gap-2",
997
+ children: [
998
+ /* @__PURE__ */ jsx14("div", {
999
+ className: cn("bg-muted flex size-8 shrink-0 items-center justify-center overflow-hidden text-xs font-medium", imageVariant === "circle" ? "rounded-full" : "rounded-md"),
1000
+ children: item.imageSrc && item.imageSrc !== failedImage ? /* @__PURE__ */ jsx14("img", {
1001
+ src: item.imageSrc,
1002
+ alt: item.label,
1003
+ className: "size-full object-cover",
1004
+ onError: () => setFailedImage(item.imageSrc ?? undefined)
1005
+ }) : /* @__PURE__ */ jsx14("span", {
1006
+ "aria-hidden": "true",
1007
+ children: initials
1008
+ })
1009
+ }),
1010
+ /* @__PURE__ */ jsxs8("div", {
1011
+ className: "flex min-w-0 flex-col leading-tight",
1012
+ children: [
1013
+ /* @__PURE__ */ jsx14("span", {
1014
+ className: "truncate font-medium",
1015
+ children: item.label
1016
+ }),
1017
+ item.description ? /* @__PURE__ */ jsx14("span", {
1018
+ className: "text-muted-foreground truncate text-xs",
1019
+ children: item.description
1020
+ }) : null
1021
+ ]
1022
+ })
1023
+ ]
1024
+ });
1025
+ };
1026
+ var referenceText = (item) => item ? [item.label, item.description].filter(Boolean).join(" — ") : "";
1027
+ var messages2 = {
1028
+ en: {
1029
+ ...paginationMessages("en"),
1030
+ actions: "Actions",
1031
+ addItem: "Add item...",
1032
+ empty: "No results.",
1033
+ loading: "Loading...",
1034
+ filter: "Filter results...",
1035
+ export: "Export",
1036
+ exportCsv: "CSV",
1037
+ exportJson: "JSON",
1038
+ exportFailed: "Export failed. Please try again.",
1039
+ refresh: "Refresh",
1040
+ view: "View",
1041
+ tableView: "Table",
1042
+ galleryView: "Gallery",
1043
+ columns: "Columns",
1044
+ groupBy: "Group by",
1045
+ sortAsc: "Ascending",
1046
+ sortDesc: "Descending",
1047
+ sortClear: "Clear sorting",
1048
+ sortBy: "Sort by",
1049
+ hideColumn: "Hide column",
1050
+ reorder: "Drag to reorder",
1051
+ removeItem: "Remove",
1052
+ moveUp: "Move up",
1053
+ moveDown: "Move down",
1054
+ resizeColumn: (column) => `Resize ${column} column`,
1055
+ listDetails: "View all items",
1056
+ selectAllRows: "Select all rows on this page",
1057
+ selectRow: "Select row",
1058
+ selected: "Selected"
1059
+ },
1060
+ fr: {
1061
+ ...paginationMessages("fr"),
1062
+ actions: "Actions",
1063
+ addItem: "Ajouter un élément...",
1064
+ empty: "Aucun résultat.",
1065
+ loading: "Chargement...",
1066
+ filter: "Filtrer les résultats...",
1067
+ export: "Exporter",
1068
+ exportCsv: "CSV",
1069
+ exportJson: "JSON",
1070
+ exportFailed: "L’exportation a échoué. Veuillez réessayer.",
1071
+ refresh: "Rafraîchir",
1072
+ view: "Affichage",
1073
+ tableView: "Tableau",
1074
+ galleryView: "Galerie",
1075
+ columns: "Colonnes",
1076
+ groupBy: "Grouper par",
1077
+ sortAsc: "Croissant",
1078
+ sortDesc: "Décroissant",
1079
+ sortClear: "Effacer le tri",
1080
+ sortBy: "Trier par",
1081
+ hideColumn: "Masquer la colonne",
1082
+ reorder: "Glisser pour réordonner",
1083
+ removeItem: "Retirer",
1084
+ moveUp: "Déplacer vers le haut",
1085
+ moveDown: "Déplacer vers le bas",
1086
+ resizeColumn: (column) => `Redimensionner la colonne ${column}`,
1087
+ listDetails: "Afficher tous les éléments",
1088
+ selectAllRows: "Sélectionner toutes les lignes de cette page",
1089
+ selectRow: "Sélectionner la ligne",
1090
+ selected: "Sélectionnés"
1091
+ }
1092
+ };
1093
+ var dataTableMessages = (locale = "en", translations) => ({
1094
+ ...locale.startsWith("fr") ? messages2.fr : messages2.en,
1095
+ ...translations?.[locale.split("-")[0] ?? locale],
1096
+ ...translations?.[locale]
1097
+ });
1098
+ var DEFAULT_MIN_WIDTH = 96;
1099
+ var DEFAULT_WIDTH = 208;
1100
+ var DEFAULT_MAX_WIDTH = 640;
1101
+ var DEFAULT_QUERY = {
1102
+ page: 0,
1103
+ pageSize: 20
1104
+ };
1105
+ var DEFAULT_UI_STATE = {
1106
+ columnVisibility: {},
1107
+ columnSizing: {},
1108
+ rowSelection: {},
1109
+ grouping: [],
1110
+ collapsedGroups: {},
1111
+ view: "table"
1112
+ };
1113
+ var persistedUiFromState = (state) => ({
1114
+ columnVisibility: state.columnVisibility,
1115
+ columnSizing: state.columnSizing,
1116
+ grouping: state.grouping,
1117
+ view: state.view
1118
+ });
1119
+ var transientUiFromState = (state) => ({
1120
+ rowSelection: state.rowSelection,
1121
+ collapsedGroups: state.collapsedGroups
1122
+ });
1123
+ var clampWidth = (column, width) => Math.min(column.maxWidth ?? DEFAULT_MAX_WIDTH, Math.max(column.minWidth ?? DEFAULT_MIN_WIDTH, width));
1124
+ var normalizeDataTableColumns = (columnDefs, columnSizing = {}) => {
1125
+ const ids = new Set;
1126
+ return columnDefs.map((colDef) => {
1127
+ const id = colDef.field ?? colDef.colId;
1128
+ if (!id) {
1129
+ throw new Error("DataTable columns require a field or colId");
1130
+ }
1131
+ if (ids.has(id)) {
1132
+ throw new Error(`DataTable column IDs must be unique: ${id}`);
1133
+ }
1134
+ ids.add(id);
1135
+ return {
1136
+ id,
1137
+ colDef,
1138
+ width: clampWidth(colDef, columnSizing[id] ?? colDef.width ?? DEFAULT_WIDTH)
1139
+ };
1140
+ });
1141
+ };
1142
+ var getDataTableWidth = (columns, utilityColumns = 0) => columns.reduce((total, column) => total + column.width, 0) + utilityColumns * 40;
1143
+ var buildDataTableRows = (rowData, columns, getRowId) => {
1144
+ const ids = new Set;
1145
+ return rowData.map((data, index) => {
1146
+ const id = getRowId?.(data) ?? String(index);
1147
+ if (ids.has(id))
1148
+ throw new Error(`DataTable row IDs must be unique: ${id}`);
1149
+ ids.add(id);
1150
+ return {
1151
+ id,
1152
+ data,
1153
+ index,
1154
+ values: new Map(columns.map((column) => {
1155
+ const { colDef } = column;
1156
+ const value = colDef.valueGetter ? colDef.valueGetter({ data, rowId: id, rowIndex: index, colDef }) : colDef.type === "list" ? colDef.typeOptions.getItems(data).map((item) => item.label).join(", ") : colDef.type === "reference" ? referenceText(colDef.typeOptions.getItem(data)) : colDef.field ? data[colDef.field] : undefined;
1157
+ return [column.id, value];
1158
+ }))
1159
+ };
1160
+ });
1161
+ };
1162
+ var CalendarDate = Schema.String.check(Schema.isPattern(/^\d{4}-\d{2}-\d{2}$/), Schema.makeFilter((value) => Option.exists(DateTime.make(value), (date) => DateTime.formatIsoDateUtc(date) === value))).annotate({ identifier: "DataTableCalendarDate" });
1163
+ var InstantString = Schema.String.check(Schema.isPattern(/^\d{4}-\d{2}-\d{2}T(?:[01]\d|2[0-3]):[0-5]\d(?::[0-5]\d(?:\.\d+)?)?(?:Z|[+-](?:[01]\d|2[0-3]):[0-5]\d)$/), Schema.makeFilter((value) => Schema.is(CalendarDate)(value.slice(0, 10)))).annotate({ identifier: "DataTableInstantString" });
1164
+ var DateInput = Schema.Union([
1165
+ Schema.Date,
1166
+ Schema.Int,
1167
+ CalendarDate,
1168
+ InstantString
1169
+ ]).annotate({ identifier: "DataTableDateInput" });
1170
+ var decodeDateInput = Schema.decodeUnknownOption(DateInput);
1171
+ var resolveDate = (value, type) => Option.getOrUndefined(Option.flatMap(decodeDateInput(value), (input) => {
1172
+ const calendarOnly = Schema.is(CalendarDate)(input);
1173
+ if (calendarOnly && type === "dateTime")
1174
+ return Option.none();
1175
+ return Option.map(DateTime.make(input), (instant) => ({
1176
+ instant,
1177
+ calendarOnly
1178
+ }));
1179
+ }));
1180
+ var formatDateValue = (date, column, locale = "en") => DateTime.format(date.instant, {
1181
+ locale: column.typeOptions?.locale ?? locale,
1182
+ timeZone: date.calendarOnly ? "UTC" : column.typeOptions?.timeZone ?? "UTC",
1183
+ dateStyle: column.typeOptions?.dateStyle ?? "medium",
1184
+ timeStyle: column.type === "dateTime" ? column.typeOptions?.timeStyle ?? "short" : undefined,
1185
+ hour12: column.type === "dateTime" ? column.typeOptions?.hour12 : undefined
1186
+ });
1187
+ var dateIsoValue = (date) => date.calendarOnly ? DateTime.formatIsoDateUtc(date.instant) : DateTime.formatIso(date.instant);
1188
+ var NumberValue = Schema.Finite.annotate({
1189
+ identifier: "DataTableNumberValue"
1190
+ });
1191
+ var BooleanValue = Schema.Boolean.annotate({
1192
+ identifier: "DataTableBooleanValue"
1193
+ });
1194
+ var decodeNumberValue = Schema.decodeUnknownOption(NumberValue);
1195
+ var decodeBooleanValue = Schema.decodeUnknownOption(BooleanValue);
1196
+ var formatNumberValue = (value, options = {}, defaultLocale = "en") => {
1197
+ const {
1198
+ locale,
1199
+ emptyLabel: _emptyLabel,
1200
+ nulls: _nulls,
1201
+ exportFormat: _exportFormat,
1202
+ ...format
1203
+ } = options;
1204
+ return new Intl.NumberFormat(locale ?? defaultLocale, format).format(value);
1205
+ };
1206
+ var booleanLabel = (value, options) => value ? options?.trueLabel : options?.falseLabel;
1207
+ var getDataTableExportValue = (row, column, locale = "en") => {
1208
+ const value = row.values.get(column.id);
1209
+ const colDef = column.colDef;
1210
+ if (colDef.type === "number") {
1211
+ const number = Option.getOrUndefined(decodeNumberValue(value));
1212
+ if (number === undefined)
1213
+ return null;
1214
+ return colDef.typeOptions?.exportFormat === "formatted" ? formatNumberValue(number, colDef.typeOptions, locale) : number;
1215
+ }
1216
+ if (colDef.type === "boolean") {
1217
+ const boolean = Option.getOrUndefined(decodeBooleanValue(value));
1218
+ if (boolean === undefined)
1219
+ return null;
1220
+ return colDef.typeOptions?.exportFormat === "formatted" ? booleanLabel(boolean, colDef.typeOptions) ?? String(boolean) : boolean;
1221
+ }
1222
+ if (colDef.type !== "date" && colDef.type !== "dateTime")
1223
+ return value;
1224
+ const date = resolveDate(value, colDef.type);
1225
+ if (!date)
1226
+ return null;
1227
+ return colDef.typeOptions?.exportFormat === "formatted" ? formatDateValue(date, colDef, locale) : dateIsoValue(date);
1228
+ };
1229
+ var filterDataTableRows = (rows, columns, globalFilter, locale = "en") => {
1230
+ const query = globalFilter.trim().toLocaleLowerCase();
1231
+ if (!query)
1232
+ return [...rows];
1233
+ const searchable = columns.filter(({ colDef }) => colDef.searchable !== false);
1234
+ return rows.filter((row) => searchable.some((column) => {
1235
+ const value = row.values.get(column.id);
1236
+ const colDef = column.colDef;
1237
+ let text = String(value ?? "");
1238
+ if (colDef.type === "date" || colDef.type === "dateTime") {
1239
+ const date = resolveDate(value, colDef.type);
1240
+ text = date ? `${formatDateValue(date, colDef, locale)} ${dateIsoValue(date)}` : "";
1241
+ } else if (colDef.type === "number") {
1242
+ const number = Option.getOrUndefined(decodeNumberValue(value));
1243
+ text = number === undefined ? "" : `${formatNumberValue(number, colDef.typeOptions, locale)} ${number}`;
1244
+ } else if (colDef.type === "boolean") {
1245
+ const boolean = Option.getOrUndefined(decodeBooleanValue(value));
1246
+ text = boolean === undefined ? "" : `${booleanLabel(boolean, colDef.typeOptions) ?? ""} ${boolean}`;
1247
+ }
1248
+ return text.toLocaleLowerCase().includes(query);
1249
+ }));
1250
+ };
1251
+ var sortDataTableRows = (rows, columns, sorting) => {
1252
+ const byId = new Map(columns.map((column) => [column.id, column]));
1253
+ return rows.map((row, stableIndex) => ({ row, stableIndex })).sort((left, right) => {
1254
+ for (const sort of sorting) {
1255
+ const column = byId.get(sort.id);
1256
+ if (!column)
1257
+ continue;
1258
+ const leftValue = left.row.values.get(sort.id);
1259
+ const rightValue = right.row.values.get(sort.id);
1260
+ const colDef = column.colDef;
1261
+ if (!colDef.comparator && (colDef.type === "number" || colDef.type === "boolean")) {
1262
+ const leftScalar = colDef.type === "number" ? Option.getOrUndefined(decodeNumberValue(leftValue)) : Option.getOrUndefined(Option.map(decodeBooleanValue(leftValue), Number));
1263
+ const rightScalar = colDef.type === "number" ? Option.getOrUndefined(decodeNumberValue(rightValue)) : Option.getOrUndefined(Option.map(decodeBooleanValue(rightValue), Number));
1264
+ if (leftScalar === undefined || rightScalar === undefined) {
1265
+ if (leftScalar === undefined && rightScalar === undefined)
1266
+ continue;
1267
+ const nullOrder = colDef.typeOptions?.nulls === "first" ? -1 : 1;
1268
+ return leftScalar === undefined ? nullOrder : -nullOrder;
1269
+ }
1270
+ const comparison = leftScalar - rightScalar;
1271
+ if (comparison !== 0)
1272
+ return sort.direction === "desc" ? -comparison : comparison;
1273
+ continue;
1274
+ }
1275
+ if (!colDef.comparator && (colDef.type === "date" || colDef.type === "dateTime")) {
1276
+ const leftDate = resolveDate(leftValue, colDef.type);
1277
+ const rightDate = resolveDate(rightValue, colDef.type);
1278
+ if (!leftDate || !rightDate) {
1279
+ if (!leftDate && !rightDate)
1280
+ continue;
1281
+ const nullOrder = colDef.typeOptions?.nulls === "first" ? -1 : 1;
1282
+ return !leftDate ? nullOrder : -nullOrder;
1283
+ }
1284
+ const comparison = DateTime.toEpochMillis(leftDate.instant) - DateTime.toEpochMillis(rightDate.instant);
1285
+ if (comparison !== 0)
1286
+ return sort.direction === "desc" ? -comparison : comparison;
1287
+ continue;
1288
+ }
1289
+ const comparison = column.colDef.comparator ? column.colDef.comparator(leftValue, rightValue, left.row.data, right.row.data) : Object.is(leftValue, rightValue) ? 0 : leftValue === null || leftValue === undefined ? 1 : rightValue === null || rightValue === undefined ? -1 : Schema.is(Schema.Number)(leftValue) && Schema.is(Schema.Number)(rightValue) ? leftValue - rightValue : String(leftValue).localeCompare(String(rightValue), undefined, { numeric: true, sensitivity: "base" });
1290
+ if (comparison !== 0)
1291
+ return sort.direction === "desc" ? -comparison : comparison;
1292
+ }
1293
+ return left.stableIndex - right.stableIndex;
1294
+ }).map(({ row }) => row);
1295
+ };
1296
+ var paginateDataTableRows = (rows, pagination) => {
1297
+ const pageSize = Math.max(1, pagination.pageSize);
1298
+ const lastPageIndex = Math.max(0, Math.ceil(rows.length / pageSize) - 1);
1299
+ const pageIndex = Math.min(lastPageIndex, Math.max(0, pagination.page));
1300
+ const start = pageIndex * pageSize;
1301
+ return rows.slice(start, start + pageSize);
1302
+ };
1303
+ var sameDataTableState = (left, right) => left.page === right.page && left.pageSize === right.pageSize && left.globalFilter === right.globalFilter && left.sort === right.sort && left.columnVisibility === right.columnVisibility && left.columnSizing === right.columnSizing && left.rowSelection === right.rowSelection && left.grouping === right.grouping && left.collapsedGroups === right.collapsedGroups && left.view === right.view;
1304
+ var reorderDataTableRows = (rows, sourceRowId, targetRowId) => {
1305
+ const sourceIndex = rows.findIndex((row) => row.id === sourceRowId);
1306
+ const targetIndex = rows.findIndex((row) => row.id === targetRowId);
1307
+ const reordered = rows.map((row) => row.data);
1308
+ if (sourceIndex === -1 || targetIndex === -1 || sourceIndex === targetIndex) {
1309
+ return reordered;
1310
+ }
1311
+ const [source] = reordered.splice(sourceIndex, 1);
1312
+ if (source)
1313
+ reordered.splice(targetIndex, 0, source);
1314
+ return reordered;
1315
+ };
1316
+ var RowIdContext = createContext(null);
1317
+ var ColumnIdContext = createContext(null);
1318
+ var useRequiredId = (context) => {
1319
+ const id = useContext(context);
1320
+ if (!id)
1321
+ throw new Error("DataTable internal ID context is missing");
1322
+ return id;
1323
+ };
1324
+ var getGroupDropKey = (fieldId, groupId) => `${encodeURIComponent(fieldId)}:${encodeURIComponent(groupId)}`;
1325
+ var parseGroupDropKey = (key) => {
1326
+ const separator = key.indexOf(":");
1327
+ if (separator === -1)
1328
+ return null;
1329
+ return {
1330
+ fieldId: decodeURIComponent(key.slice(0, separator)),
1331
+ groupId: decodeURIComponent(key.slice(separator + 1))
1332
+ };
1333
+ };
1334
+ var findTableDragTarget = (elements, selector, root) => {
1335
+ for (const element of elements) {
1336
+ const target = element.closest(selector);
1337
+ if (target instanceof HTMLElement && root?.contains(target))
1338
+ return target;
1339
+ }
1340
+ return null;
1341
+ };
1342
+ var clearDragPresentation = (root) => {
1343
+ root?.querySelectorAll("[data-drag-source], [data-drop-target], [data-drop-position]").forEach((element) => {
1344
+ element.removeAttribute("data-drag-source");
1345
+ element.removeAttribute("data-drop-target");
1346
+ element.removeAttribute("data-drop-position");
1347
+ });
1348
+ };
1349
+ var resolveConfig = (props, onUiStateChange) => {
1350
+ const features = props.features ?? {};
1351
+ const selection = features.selection;
1352
+ const getRowId = selection && selection.getRowId || props.getRowId || undefined;
1353
+ if ((selection || features.reordering) && !getRowId) {
1354
+ throw new Error("DataTable requires getRowId when selection or reordering is enabled");
1355
+ }
1356
+ return {
1357
+ getRowId,
1358
+ onStateChange: props.onStateChange,
1359
+ onUiStateChange,
1360
+ status: props.status ?? {},
1361
+ features,
1362
+ onRowClicked: props.onRowClicked,
1363
+ labels: dataTableMessages(props.locale, props.messages),
1364
+ locale: props.locale ?? "en"
1365
+ };
1366
+ };
1367
+ var queryFromState = (state) => ({
1368
+ page: state.page,
1369
+ pageSize: state.pageSize,
1370
+ globalFilter: state.globalFilter,
1371
+ sort: state.sort
1372
+ });
1373
+ var uiFromState = (state) => ({
1374
+ columnVisibility: state.columnVisibility,
1375
+ columnSizing: state.columnSizing,
1376
+ rowSelection: state.rowSelection,
1377
+ grouping: state.grouping,
1378
+ collapsedGroups: state.collapsedGroups,
1379
+ view: state.view
1380
+ });
1381
+ var sameUiState = (left, right) => left.columnVisibility === right.columnVisibility && left.columnSizing === right.columnSizing && left.rowSelection === right.rowSelection && left.grouping === right.grouping && left.collapsedGroups === right.collapsedGroups && left.view === right.view;
1382
+ var sameQueryState = (left, right) => left.page === right.page && left.pageSize === right.pageSize && left.globalFilter === right.globalFilter && left.sort === right.sort;
1383
+ var initialPublicState = (props, uiState) => ({
1384
+ ...queryFromState(props.state ?? { ...DEFAULT_QUERY, ...props.initialState }),
1385
+ ...uiState
1386
+ });
1387
+ var buildDataTableModel = (store) => {
1388
+ const columns = normalizeDataTableColumns(store.columnDefs, store.state.columnSizing);
1389
+ const selection = store.config.features.selection;
1390
+ const rowId = selection && selection.getRowId || store.config.getRowId || undefined;
1391
+ const rows = buildDataTableRows(store.rowData, columns, rowId);
1392
+ const pagination = store.config.features.pagination ?? { mode: "client" };
1393
+ const server = pagination !== false && pagination.mode === "server";
1394
+ const filteredRows = server ? [...rows] : filterDataTableRows(rows, columns, store.state.globalFilter ?? "", store.config.locale);
1395
+ const sortedRows = server ? filteredRows : sortDataTableRows(filteredRows, columns, store.state.sort ?? []);
1396
+ const pageRows = pagination === false || server ? sortedRows : paginateDataTableRows(sortedRows, store.state);
1397
+ const totalRows = server ? pagination.rowCount : sortedRows.length;
1398
+ return {
1399
+ columns,
1400
+ visibleColumns: columns.filter(({ id }) => store.state.columnVisibility[id] !== false),
1401
+ rows,
1402
+ filteredRows,
1403
+ sortedRows,
1404
+ pageRows,
1405
+ pageCount: Math.max(1, Math.ceil(totalRows / Math.max(1, store.state.pageSize))),
1406
+ totalRows
1407
+ };
1408
+ };
1409
+ var useTableAtom = (tableAtom) => useAtom(tableAtom);
1410
+ var changeState = (setStore, update) => {
1411
+ setStore((store) => {
1412
+ const proposed = update(store.state);
1413
+ const query = queryFromState(proposed);
1414
+ if (!sameQueryState(query, store.state)) {
1415
+ store.config.onStateChange?.(query);
1416
+ }
1417
+ const uiState = uiFromState(proposed);
1418
+ if (!sameUiState(uiState, store.state)) {
1419
+ store.config.onUiStateChange(uiState);
1420
+ }
1421
+ const state = store.controlledState ? { ...proposed, ...queryFromState(store.controlledState) } : proposed;
1422
+ if (sameDataTableState(state, store.state))
1423
+ return store;
1424
+ const next = { ...store, state };
1425
+ return { ...next, model: buildDataTableModel(next) };
1426
+ });
1427
+ };
1428
+ var deriveModel = (store) => store.model;
1429
+ var groupDataTableRows = (rows, fields, depth = 0, parentKey = "") => {
1430
+ const field = fields[0];
1431
+ if (!field)
1432
+ return [];
1433
+ const groups = new Map;
1434
+ field.getGroupIds?.().forEach((id) => groups.set(id, []));
1435
+ rows.forEach((row) => {
1436
+ const ids = field.getRowGroupIds?.(row.data) ?? [
1437
+ field.getGroupId(row.data)
1438
+ ];
1439
+ ids.forEach((id) => groups.set(id, [...groups.get(id) ?? [], row]));
1440
+ });
1441
+ return Array.from(groups, ([groupId, groupRows]) => {
1442
+ const segment = `${encodeURIComponent(field.id)}:${encodeURIComponent(groupId)}`;
1443
+ const key = `${parentKey}${parentKey ? "/" : ""}${segment}`;
1444
+ return {
1445
+ key,
1446
+ groupId,
1447
+ depth,
1448
+ field,
1449
+ rows: groupRows,
1450
+ children: groupDataTableRows(groupRows, fields.slice(1), depth + 1, key)
1451
+ };
1452
+ });
1453
+ };
1454
+ var getDataTableSelectableRows = (model, grouped, isRowSelectable) => (grouped ? model.sortedRows : model.pageRows).filter((row) => isRowSelectable?.(row.data) ?? true);
1455
+ var getActiveGrouping = (store) => {
1456
+ const grouping = store.config.features.grouping;
1457
+ if (!grouping)
1458
+ return [];
1459
+ return store.state.grouping.flatMap((id) => {
1460
+ const field = grouping.fields.find((candidate) => candidate.id === id);
1461
+ return field ? [field] : [];
1462
+ });
1463
+ };
1464
+ var canReorderRows = (store) => {
1465
+ const pagination = store.config.features.pagination;
1466
+ return !!store.config.features.reordering && !getActiveGrouping(store).length && !store.state.globalFilter && !store.state.sort?.length && !(pagination && pagination.mode === "server");
1467
+ };
1468
+ var canMoveRowsToGroups = (store) => getActiveGrouping(store).some((field) => !!field.onMoveToGroup);
1469
+ var canDragRows = (store) => getActiveGrouping(store).length ? canMoveRowsToGroups(store) : canReorderRows(store);
1470
+ var hasRowActionMenu = (store) => !!store.config.features.rowActions || canReorderRows(store);
1471
+ var getSelectedRows = (store, model) => model.rows.filter((row) => store.state.rowSelection[row.id]).map((row) => row.data);
1472
+ var renderCell = (row, column, locale = "en", labels = dataTableMessages(locale)) => {
1473
+ const value = row.values.get(column.id);
1474
+ const params = {
1475
+ data: row.data,
1476
+ value,
1477
+ rowId: row.id,
1478
+ rowIndex: row.index,
1479
+ colDef: column.colDef
1480
+ };
1481
+ const CellRenderer = column.colDef.cellRenderer;
1482
+ if (CellRenderer)
1483
+ return /* @__PURE__ */ jsx14(CellRenderer, {
1484
+ ...params
1485
+ });
1486
+ const colDef = column.colDef;
1487
+ if (colDef.type === "reference") {
1488
+ if (colDef.valueFormatter)
1489
+ return colDef.valueFormatter(params);
1490
+ return /* @__PURE__ */ jsx14(DataTableReferenceCell, {
1491
+ item: colDef.typeOptions.getItem(row.data),
1492
+ emptyLabel: colDef.typeOptions.emptyLabel,
1493
+ imageVariant: colDef.typeOptions.imageVariant
1494
+ });
1495
+ }
1496
+ if (colDef.type === "number") {
1497
+ if (colDef.valueFormatter)
1498
+ return colDef.valueFormatter(params);
1499
+ const number = Option.getOrUndefined(decodeNumberValue(value));
1500
+ return /* @__PURE__ */ jsx14("span", {
1501
+ className: "block text-left tabular-nums",
1502
+ children: number === undefined ? colDef.typeOptions?.emptyLabel ?? "—" : formatNumberValue(number, colDef.typeOptions, locale)
1503
+ });
1504
+ }
1505
+ if (colDef.type === "boolean") {
1506
+ if (colDef.valueFormatter)
1507
+ return colDef.valueFormatter(params);
1508
+ const boolean = Option.getOrUndefined(decodeBooleanValue(value));
1509
+ if (boolean === undefined)
1510
+ return colDef.typeOptions?.emptyLabel ?? "—";
1511
+ const options = colDef.typeOptions;
1512
+ return /* @__PURE__ */ jsx14("label", {
1513
+ "data-slot": "data-table-boolean-cell",
1514
+ className: cn("flex min-h-16 w-full items-center justify-start border border-transparent px-2 outline-none focus-within:border-ring focus-within:ring-3 focus-within:ring-ring/50 focus-within:ring-inset in-[[data-slot=table-cell]]:absolute in-[[data-slot=table-cell]]:inset-0 in-[[data-slot=table-cell]]:min-h-0", options?.onChange && !options.disabled?.(row.data) && "cursor-pointer hover:bg-muted/50"),
1515
+ onClick: (event) => event.stopPropagation(),
1516
+ onPointerDown: (event) => event.stopPropagation(),
1517
+ children: /* @__PURE__ */ jsx14(Checkbox, {
1518
+ "aria-label": options?.getAriaLabel?.(row.data) ?? columnLabel(column),
1519
+ className: "focus-visible:ring-0 focus-visible:outline-none",
1520
+ checked: boolean,
1521
+ readOnly: !options?.onChange,
1522
+ disabled: options?.disabled?.(row.data),
1523
+ onCheckedChange: (checked) => options?.onChange?.({ value: checked, row: row.data })
1524
+ })
1525
+ });
1526
+ }
1527
+ if (colDef.type === "date" || colDef.type === "dateTime") {
1528
+ if (colDef.valueFormatter)
1529
+ return colDef.valueFormatter(params);
1530
+ const date = resolveDate(value, colDef.type);
1531
+ return date ? /* @__PURE__ */ jsx14("time", {
1532
+ dateTime: dateIsoValue(date),
1533
+ children: formatDateValue(date, colDef, locale)
1534
+ }) : colDef.typeOptions?.emptyLabel ?? "—";
1535
+ }
1536
+ if (colDef.type === "list") {
1537
+ const config = colDef.typeOptions;
1538
+ const itemActions = config.itemActions?.map((action) => ({
1539
+ ...action,
1540
+ onClick: (item) => action.onClick({ item, row: row.data }),
1541
+ visible: (item) => action.visible?.({ item, row: row.data }) ?? true,
1542
+ disabled: (item) => action.disabled?.({ item, row: row.data }) ?? false
1543
+ }));
1544
+ if (config.getOptions) {
1545
+ return /* @__PURE__ */ jsx14(DataTableListCell, {
1546
+ ...config,
1547
+ itemActions,
1548
+ onItemClick: config.onItemClick ? (item) => config.onItemClick?.({ item, row: row.data }) : undefined,
1549
+ items: config.getItems(row.data),
1550
+ locale,
1551
+ messages: { [locale]: labels },
1552
+ options: config.getOptions(row.data),
1553
+ totalCount: config.getTotalCount?.(row.data),
1554
+ onAdd: config.onAdd ? (value) => config.onAdd?.({ value, row: row.data }) : undefined,
1555
+ onRemove: config.onRemove ? (value) => config.onRemove?.({ value, row: row.data }) : undefined
1556
+ });
1557
+ }
1558
+ return /* @__PURE__ */ jsx14(DataTableListCell, {
1559
+ ...config,
1560
+ itemActions,
1561
+ onItemClick: config.onItemClick ? (item) => config.onItemClick?.({ item, row: row.data }) : undefined,
1562
+ items: config.getItems(row.data),
1563
+ locale,
1564
+ messages: { [locale]: labels },
1565
+ totalCount: config.getTotalCount?.(row.data)
1566
+ });
1567
+ }
1568
+ return column.colDef.valueFormatter?.(params) ?? (value === null || value === undefined ? null : String(value));
1569
+ };
1570
+ var nodeText = (node) => {
1571
+ if (Schema.is(Schema.String)(node) || Schema.is(Schema.Number)(node))
1572
+ return String(node);
1573
+ if (!isValidElement(node))
1574
+ return "";
1575
+ if (Schema.is(Schema.String)(node.props.title))
1576
+ return node.props.title;
1577
+ return nodeText(node.props.children);
1578
+ };
1579
+ var columnLabel = (column) => nodeText(column.colDef.headerName) || column.id;
1580
+ var withExtension = (fileName, extension) => fileName.includes(".") ? fileName.replace(/\.[^/.]+$/, `.${extension}`) : `${fileName}.${extension}`;
1581
+ var escapeCsvValue = (value) => {
1582
+ if (value === null || value === undefined)
1583
+ return "";
1584
+ const text = String(value);
1585
+ return /[",\n]/.test(text) ? `"${text.replace(/"/g, '""')}"` : text;
1586
+ };
1587
+ var downloadCsv = (headers, data, fileName = "data.csv") => {
1588
+ const content = [headers, ...data].map((row) => row.map(escapeCsvValue).join(",")).join(`
1589
+ `);
1590
+ downloadBlob(content, "text/csv;charset=utf-8", withExtension(fileName, "csv"));
1591
+ };
1592
+ var downloadJson = (data, fileName = "data.json") => downloadBlob(JSON.stringify(data, null, 2), "application/json;charset=utf-8", withExtension(fileName, "json"));
1593
+ var downloadBlob = (content, type, fileName) => {
1594
+ const url = window.URL.createObjectURL(new Blob([content], { type }));
1595
+ const link = document.createElement("a");
1596
+ link.href = url;
1597
+ link.download = fileName;
1598
+ document.body.appendChild(link);
1599
+ link.click();
1600
+ link.remove();
1601
+ requestAnimationFrame(() => window.URL.revokeObjectURL(url));
1602
+ };
1603
+ var DataTableRowActions = ({
1604
+ actions,
1605
+ row,
1606
+ title
1607
+ }) => {
1608
+ const visible = actions.filter((action) => !action.visible || action.visible(row));
1609
+ if (!visible.length)
1610
+ return null;
1611
+ return /* @__PURE__ */ jsxs8(DropdownMenu, {
1612
+ children: [
1613
+ /* @__PURE__ */ jsx14(DropdownMenuTrigger, {
1614
+ onClick: (event) => event.stopPropagation(),
1615
+ render: /* @__PURE__ */ jsxs8(Button, {
1616
+ className: "size-8 focus-visible:ring-inset [&_svg:not([class*='size-'])]:size-4",
1617
+ size: "icon",
1618
+ variant: "ghost",
1619
+ children: [
1620
+ /* @__PURE__ */ jsx14("span", {
1621
+ className: "sr-only",
1622
+ children: title
1623
+ }),
1624
+ /* @__PURE__ */ jsx14(MoreHorizontal, {})
1625
+ ]
1626
+ })
1627
+ }),
1628
+ /* @__PURE__ */ jsx14(DropdownMenuContent, {
1629
+ align: "end",
1630
+ className: "w-max",
1631
+ children: /* @__PURE__ */ jsxs8(DropdownMenuGroup, {
1632
+ children: [
1633
+ /* @__PURE__ */ jsx14(DropdownMenuLabel, {
1634
+ children: title
1635
+ }),
1636
+ /* @__PURE__ */ jsx14(DropdownMenuSeparator, {}),
1637
+ visible.map((action) => /* @__PURE__ */ jsxs8(DropdownMenuItem, {
1638
+ onClick: (event) => {
1639
+ event.stopPropagation();
1640
+ action.onClick(row);
1641
+ },
1642
+ variant: action.variant ?? "default",
1643
+ children: [
1644
+ action.icon,
1645
+ action.name
1646
+ ]
1647
+ }, action.id ?? action.name))
1648
+ ]
1649
+ })
1650
+ })
1651
+ ]
1652
+ });
1653
+ };
1654
+ var DataTableRowActionMenu = ({
1655
+ tableAtom
1656
+ }) => {
1657
+ const [store] = useTableAtom(tableAtom);
1658
+ const rowId = useRequiredId(RowIdContext);
1659
+ const model = deriveModel(store);
1660
+ const row = model.sortedRows.find((candidate) => candidate.id === rowId);
1661
+ if (!row)
1662
+ return null;
1663
+ const rowActions = store.config.features.rowActions || undefined;
1664
+ const visibleRows = model.pageRows;
1665
+ const rowIndex = visibleRows.findIndex((candidate) => candidate.id === rowId);
1666
+ const reordering = store.config.features.reordering;
1667
+ const reorderActions = [];
1668
+ if (reordering && canReorderRows(store)) {
1669
+ const move = (targetIndex) => reordering.onReorder(reorderDataTableRows(model.rows, rowId, visibleRows[targetIndex].id));
1670
+ if (rowIndex > 0) {
1671
+ reorderActions.push({
1672
+ id: "data-table-move-up",
1673
+ name: store.config.labels.moveUp,
1674
+ icon: /* @__PURE__ */ jsx14(ArrowUp, {}),
1675
+ onClick: () => move(rowIndex - 1)
1676
+ });
1677
+ }
1678
+ if (rowIndex !== -1 && rowIndex < visibleRows.length - 1) {
1679
+ reorderActions.push({
1680
+ id: "data-table-move-down",
1681
+ name: store.config.labels.moveDown,
1682
+ icon: /* @__PURE__ */ jsx14(ArrowDown, {}),
1683
+ onClick: () => move(rowIndex + 1)
1684
+ });
1685
+ }
1686
+ }
1687
+ return /* @__PURE__ */ jsx14(DataTableRowActions, {
1688
+ actions: [...reorderActions, ...rowActions ? rowActions.items : []],
1689
+ row: row.data,
1690
+ title: rowActions?.label ?? store.config.labels.actions
1691
+ });
1692
+ };
1693
+ var DataTableToolbar = ({
1694
+ tableAtom
1695
+ }) => {
1696
+ const [store, setStore] = useTableAtom(tableAtom);
1697
+ const exportPending = useRef(false);
1698
+ const [exporting, setExporting] = useState(false);
1699
+ const [exportFailed, setExportFailed] = useState(false);
1700
+ const { features, labels } = store.config;
1701
+ const model = deriveModel(store);
1702
+ const selectedRows = getSelectedRows(store, model);
1703
+ const grouping = features.grouping;
1704
+ const toolbar = features.toolbar;
1705
+ const bulkActions = features.selection && features.selection.bulkActions;
1706
+ const hasToolbar = !!toolbar || features.search !== false || features.sorting !== false || features.columnVisibility !== false || !!features.export || !!features.gallery || !!grouping || !!features.refresh || !!bulkActions && selectedRows.length > 0;
1707
+ if (!hasToolbar)
1708
+ return null;
1709
+ const update = (next) => changeState(setStore, next);
1710
+ const visibleBulkActions = bulkActions ? bulkActions.items.filter((action) => !action.visible || action.visible(selectedRows)) : [];
1711
+ const exportRows = features.export && features.export.scope === "filteredRows" ? model.filteredRows : model.pageRows;
1712
+ const exportFeature = features.export;
1713
+ const exportActions = exportFeature ? exportFeature.actions ?? [] : [];
1714
+ const builtInExport = exportFeature && exportFeature.builtIn !== false;
1715
+ const canExport = builtInExport && exportRows.length > 0 || exportActions.some((action) => !action.disabled);
1716
+ const runExport = async (action) => {
1717
+ if (exportPending.current || action.disabled)
1718
+ return;
1719
+ exportPending.current = true;
1720
+ setExporting(true);
1721
+ setExportFailed(false);
1722
+ try {
1723
+ await action.onExport();
1724
+ } catch (error) {
1725
+ setExportFailed(true);
1726
+ if (exportFeature)
1727
+ exportFeature.onError?.(error, action);
1728
+ } finally {
1729
+ exportPending.current = false;
1730
+ setExporting(false);
1731
+ }
1732
+ };
1733
+ return /* @__PURE__ */ jsxs8("div", {
1734
+ className: "flex flex-col gap-2 pb-4",
1735
+ children: [
1736
+ features.search !== false ? /* @__PURE__ */ jsxs8("div", {
1737
+ className: "relative min-w-0",
1738
+ children: [
1739
+ /* @__PURE__ */ jsx14(Search, {
1740
+ className: "text-muted-foreground pointer-events-none absolute top-1/2 left-3 size-4 -translate-y-1/2"
1741
+ }),
1742
+ /* @__PURE__ */ jsx14(Input, {
1743
+ className: "px-9",
1744
+ onChange: (event) => update((state) => ({
1745
+ ...state,
1746
+ globalFilter: event.target.value,
1747
+ page: 0
1748
+ })),
1749
+ placeholder: labels.filter,
1750
+ value: store.state.globalFilter ?? ""
1751
+ }),
1752
+ store.state.globalFilter ? /* @__PURE__ */ jsx14(Button, {
1753
+ "aria-label": labels.filter,
1754
+ className: "absolute top-1/2 right-1 size-7 -translate-y-1/2 active:not-aria-[haspopup]:-translate-y-1/2",
1755
+ onClick: () => update((state) => ({
1756
+ ...state,
1757
+ globalFilter: undefined,
1758
+ page: 0
1759
+ })),
1760
+ size: "icon",
1761
+ variant: "ghost",
1762
+ children: /* @__PURE__ */ jsx14(X, {})
1763
+ }) : null
1764
+ ]
1765
+ }) : null,
1766
+ /* @__PURE__ */ jsx14("div", {
1767
+ className: "-m-1 flex overflow-x-auto p-1",
1768
+ children: /* @__PURE__ */ jsxs8(Menubar, {
1769
+ className: "h-auto w-max min-w-full justify-start bg-transparent shadow-none [&_[data-slot=menubar-trigger]]:gap-2 [&_[data-slot=menubar-trigger]_svg]:size-4",
1770
+ children: [
1771
+ toolbar && toolbar.items,
1772
+ visibleBulkActions.length ? /* @__PURE__ */ jsxs8(MenubarMenu, {
1773
+ children: [
1774
+ /* @__PURE__ */ jsxs8(MenubarTrigger, {
1775
+ className: "bg-primary text-primary-foreground hover:bg-primary/90 aria-expanded:bg-primary/90",
1776
+ children: [
1777
+ labels.selected,
1778
+ /* @__PURE__ */ jsx14(Badge, {
1779
+ variant: "secondary",
1780
+ children: selectedRows.length
1781
+ }),
1782
+ /* @__PURE__ */ jsx14(ChevronDown, {})
1783
+ ]
1784
+ }),
1785
+ /* @__PURE__ */ jsx14(MenubarContent, {
1786
+ align: "end",
1787
+ className: "w-max",
1788
+ children: /* @__PURE__ */ jsxs8(MenubarGroup, {
1789
+ children: [
1790
+ /* @__PURE__ */ jsx14(MenubarLabel, {
1791
+ children: bulkActions && bulkActions.label ? bulkActions.label : labels.actions
1792
+ }),
1793
+ /* @__PURE__ */ jsx14(MenubarSeparator, {}),
1794
+ visibleBulkActions.map((action) => /* @__PURE__ */ jsxs8(MenubarItem, {
1795
+ onClick: () => action.onClick(selectedRows),
1796
+ variant: action.variant ?? "default",
1797
+ children: [
1798
+ action.icon,
1799
+ action.name
1800
+ ]
1801
+ }, action.id ?? action.name))
1802
+ ]
1803
+ })
1804
+ })
1805
+ ]
1806
+ }) : null,
1807
+ grouping ? /* @__PURE__ */ jsxs8(MenubarMenu, {
1808
+ children: [
1809
+ /* @__PURE__ */ jsxs8(MenubarTrigger, {
1810
+ "aria-label": labels.groupBy,
1811
+ children: [
1812
+ /* @__PURE__ */ jsx14(Rows3, {}),
1813
+ /* @__PURE__ */ jsx14("span", {
1814
+ className: "hidden sm:inline",
1815
+ children: labels.groupBy
1816
+ })
1817
+ ]
1818
+ }),
1819
+ /* @__PURE__ */ jsx14(MenubarContent, {
1820
+ align: "end",
1821
+ children: /* @__PURE__ */ jsxs8(MenubarGroup, {
1822
+ children: [
1823
+ /* @__PURE__ */ jsx14(MenubarLabel, {
1824
+ children: labels.groupBy
1825
+ }),
1826
+ /* @__PURE__ */ jsx14(MenubarSeparator, {}),
1827
+ grouping.fields.map((field) => /* @__PURE__ */ jsx14(MenubarCheckboxItem, {
1828
+ checked: store.state.grouping.includes(field.id),
1829
+ onCheckedChange: (checked) => update((state) => ({
1830
+ ...state,
1831
+ grouping: checked ? [...state.grouping, field.id] : state.grouping.filter((id) => id !== field.id)
1832
+ })),
1833
+ children: field.label
1834
+ }, field.id))
1835
+ ]
1836
+ })
1837
+ })
1838
+ ]
1839
+ }) : null,
1840
+ features.sorting !== false ? /* @__PURE__ */ jsx14(SortMenu, {
1841
+ tableAtom
1842
+ }) : null,
1843
+ features.gallery ? /* @__PURE__ */ jsx14(ViewMenu, {
1844
+ tableAtom
1845
+ }) : null,
1846
+ features.columnVisibility !== false ? /* @__PURE__ */ jsx14(ColumnMenu, {
1847
+ tableAtom
1848
+ }) : null,
1849
+ features.refresh ? /* @__PURE__ */ jsx14(MenubarMenu, {
1850
+ children: /* @__PURE__ */ jsxs8(MenubarTrigger, {
1851
+ "aria-label": labels.refresh,
1852
+ onClick: features.refresh,
1853
+ children: [
1854
+ /* @__PURE__ */ jsx14(RefreshCw, {}),
1855
+ /* @__PURE__ */ jsx14("span", {
1856
+ className: "hidden sm:inline",
1857
+ children: labels.refresh
1858
+ })
1859
+ ]
1860
+ })
1861
+ }) : null,
1862
+ features.export ? /* @__PURE__ */ jsxs8(MenubarMenu, {
1863
+ children: [
1864
+ /* @__PURE__ */ jsxs8(MenubarTrigger, {
1865
+ "aria-label": labels.export,
1866
+ "aria-busy": exporting,
1867
+ disabled: exporting || !canExport,
1868
+ children: [
1869
+ exporting ? /* @__PURE__ */ jsx14(RefreshCw, {
1870
+ className: "animate-spin"
1871
+ }) : /* @__PURE__ */ jsx14(Download, {}),
1872
+ /* @__PURE__ */ jsx14("span", {
1873
+ className: "hidden sm:inline",
1874
+ children: exporting ? labels.loading : labels.export
1875
+ })
1876
+ ]
1877
+ }),
1878
+ /* @__PURE__ */ jsx14(MenubarContent, {
1879
+ align: "end",
1880
+ children: /* @__PURE__ */ jsxs8(MenubarGroup, {
1881
+ children: [
1882
+ /* @__PURE__ */ jsx14(MenubarLabel, {
1883
+ children: labels.export
1884
+ }),
1885
+ /* @__PURE__ */ jsx14(MenubarSeparator, {}),
1886
+ builtInExport ? /* @__PURE__ */ jsxs8(Fragment, {
1887
+ children: [
1888
+ /* @__PURE__ */ jsxs8(MenubarItem, {
1889
+ disabled: exporting || !exportRows.length,
1890
+ onClick: () => downloadCsv(model.visibleColumns.map(columnLabel), exportRows.map((row) => model.visibleColumns.map((column) => String(getDataTableExportValue(row, column, store.config.locale) ?? ""))), features.export ? features.export.baseName : "table"),
1891
+ children: [
1892
+ /* @__PURE__ */ jsx14(FileText, {}),
1893
+ labels.exportCsv
1894
+ ]
1895
+ }),
1896
+ /* @__PURE__ */ jsxs8(MenubarItem, {
1897
+ disabled: exporting || !exportRows.length,
1898
+ onClick: () => downloadJson(exportRows.map((row) => Object.fromEntries(model.visibleColumns.map((column) => [
1899
+ column.id,
1900
+ getDataTableExportValue(row, column, store.config.locale)
1901
+ ]))), features.export ? features.export.baseName : "table"),
1902
+ children: [
1903
+ /* @__PURE__ */ jsx14(FileJson, {}),
1904
+ labels.exportJson
1905
+ ]
1906
+ })
1907
+ ]
1908
+ }) : null,
1909
+ builtInExport && exportActions.length ? /* @__PURE__ */ jsx14(MenubarSeparator, {}) : null,
1910
+ exportActions.map((action) => /* @__PURE__ */ jsxs8(MenubarItem, {
1911
+ disabled: exporting || action.disabled,
1912
+ onClick: () => void runExport(action),
1913
+ children: [
1914
+ action.icon,
1915
+ action.label
1916
+ ]
1917
+ }, action.id))
1918
+ ]
1919
+ })
1920
+ })
1921
+ ]
1922
+ }) : null
1923
+ ]
1924
+ })
1925
+ }),
1926
+ exportFeature && exportFailed ? /* @__PURE__ */ jsx14("p", {
1927
+ role: "alert",
1928
+ className: "text-destructive text-sm",
1929
+ children: labels.exportFailed ?? dataTableMessages(store.config.locale).exportFailed
1930
+ }) : null
1931
+ ]
1932
+ });
1933
+ };
1934
+ var SortMenu = ({
1935
+ tableAtom
1936
+ }) => {
1937
+ const [store, setStore] = useTableAtom(tableAtom);
1938
+ const columns = deriveModel(store).columns.filter(({ colDef }) => colDef.sortable !== false);
1939
+ if (!columns.length)
1940
+ return null;
1941
+ const current = store.state.sort?.[0];
1942
+ const sort = (id, direction) => changeState(setStore, (state) => ({
1943
+ ...state,
1944
+ sort: [{ id, direction }],
1945
+ page: 0
1946
+ }));
1947
+ return /* @__PURE__ */ jsxs8(MenubarMenu, {
1948
+ children: [
1949
+ /* @__PURE__ */ jsxs8(MenubarTrigger, {
1950
+ "aria-label": store.config.labels.sortBy,
1951
+ children: [
1952
+ current ? current.direction === "desc" ? /* @__PURE__ */ jsx14(ArrowDown, {}) : /* @__PURE__ */ jsx14(ArrowUp, {}) : /* @__PURE__ */ jsx14(ChevronsUpDown, {}),
1953
+ /* @__PURE__ */ jsx14("span", {
1954
+ className: "hidden sm:inline",
1955
+ children: store.config.labels.sortBy
1956
+ })
1957
+ ]
1958
+ }),
1959
+ /* @__PURE__ */ jsx14(MenubarContent, {
1960
+ align: "end",
1961
+ className: "w-52",
1962
+ children: columns.map((column) => {
1963
+ const sortState = store.state.sort?.find(({ id }) => id === column.id);
1964
+ return /* @__PURE__ */ jsxs8(MenubarSub, {
1965
+ children: [
1966
+ /* @__PURE__ */ jsxs8(MenubarSubTrigger, {
1967
+ children: [
1968
+ sortState ? sortState.direction === "desc" ? /* @__PURE__ */ jsx14(ArrowDown, {}) : /* @__PURE__ */ jsx14(ArrowUp, {}) : null,
1969
+ columnLabel(column)
1970
+ ]
1971
+ }),
1972
+ /* @__PURE__ */ jsxs8(MenubarSubContent, {
1973
+ children: [
1974
+ /* @__PURE__ */ jsxs8(MenubarItem, {
1975
+ onClick: () => sort(column.id, "asc"),
1976
+ children: [
1977
+ /* @__PURE__ */ jsx14(ArrowUp, {}),
1978
+ " ",
1979
+ store.config.labels.sortAsc
1980
+ ]
1981
+ }),
1982
+ /* @__PURE__ */ jsxs8(MenubarItem, {
1983
+ onClick: () => sort(column.id, "desc"),
1984
+ children: [
1985
+ /* @__PURE__ */ jsx14(ArrowDown, {}),
1986
+ " ",
1987
+ store.config.labels.sortDesc
1988
+ ]
1989
+ }),
1990
+ sortState ? /* @__PURE__ */ jsxs8(Fragment, {
1991
+ children: [
1992
+ /* @__PURE__ */ jsx14(MenubarSeparator, {}),
1993
+ /* @__PURE__ */ jsxs8(MenubarItem, {
1994
+ onClick: () => changeState(setStore, (state) => ({
1995
+ ...state,
1996
+ sort: state.sort?.filter(({ id }) => id !== column.id)
1997
+ })),
1998
+ children: [
1999
+ /* @__PURE__ */ jsx14(X, {}),
2000
+ " ",
2001
+ store.config.labels.sortClear
2002
+ ]
2003
+ })
2004
+ ]
2005
+ }) : null
2006
+ ]
2007
+ })
2008
+ ]
2009
+ }, column.id);
2010
+ })
2011
+ })
2012
+ ]
2013
+ });
2014
+ };
2015
+ var ViewMenu = ({
2016
+ tableAtom
2017
+ }) => {
2018
+ const [store, setStore] = useTableAtom(tableAtom);
2019
+ return /* @__PURE__ */ jsxs8(MenubarMenu, {
2020
+ children: [
2021
+ /* @__PURE__ */ jsxs8(MenubarTrigger, {
2022
+ "aria-label": store.config.labels.view,
2023
+ children: [
2024
+ store.state.view === "gallery" ? /* @__PURE__ */ jsx14(LayoutGrid, {}) : /* @__PURE__ */ jsx14(Rows3, {}),
2025
+ /* @__PURE__ */ jsx14("span", {
2026
+ className: "hidden sm:inline",
2027
+ children: store.config.labels.view
2028
+ })
2029
+ ]
2030
+ }),
2031
+ /* @__PURE__ */ jsx14(MenubarContent, {
2032
+ align: "end",
2033
+ children: /* @__PURE__ */ jsxs8(MenubarRadioGroup, {
2034
+ onValueChange: (view) => {
2035
+ if (view === "table" || view === "gallery") {
2036
+ changeState(setStore, (state) => ({ ...state, view }));
2037
+ }
2038
+ },
2039
+ value: store.state.view,
2040
+ children: [
2041
+ /* @__PURE__ */ jsxs8(MenubarRadioItem, {
2042
+ value: "table",
2043
+ children: [
2044
+ /* @__PURE__ */ jsx14(Rows3, {}),
2045
+ " ",
2046
+ store.config.labels.tableView
2047
+ ]
2048
+ }),
2049
+ /* @__PURE__ */ jsxs8(MenubarRadioItem, {
2050
+ value: "gallery",
2051
+ children: [
2052
+ /* @__PURE__ */ jsx14(LayoutGrid, {}),
2053
+ " ",
2054
+ store.config.labels.galleryView
2055
+ ]
2056
+ })
2057
+ ]
2058
+ })
2059
+ })
2060
+ ]
2061
+ });
2062
+ };
2063
+ var ColumnMenu = ({
2064
+ tableAtom
2065
+ }) => {
2066
+ const [store, setStore] = useTableAtom(tableAtom);
2067
+ const columns = deriveModel(store).columns.filter(({ colDef }) => colDef.hideable !== false);
2068
+ if (!columns.length)
2069
+ return null;
2070
+ return /* @__PURE__ */ jsxs8(MenubarMenu, {
2071
+ children: [
2072
+ /* @__PURE__ */ jsxs8(MenubarTrigger, {
2073
+ "aria-label": store.config.labels.columns,
2074
+ children: [
2075
+ /* @__PURE__ */ jsx14(Settings2, {}),
2076
+ /* @__PURE__ */ jsx14("span", {
2077
+ className: "hidden sm:inline",
2078
+ children: store.config.labels.columns
2079
+ })
2080
+ ]
2081
+ }),
2082
+ /* @__PURE__ */ jsx14(MenubarContent, {
2083
+ align: "end",
2084
+ children: /* @__PURE__ */ jsxs8(MenubarGroup, {
2085
+ children: [
2086
+ /* @__PURE__ */ jsx14(MenubarLabel, {
2087
+ children: store.config.labels.columns
2088
+ }),
2089
+ /* @__PURE__ */ jsx14(MenubarSeparator, {}),
2090
+ columns.map((column) => /* @__PURE__ */ jsx14(MenubarCheckboxItem, {
2091
+ checked: store.state.columnVisibility[column.id] !== false,
2092
+ onCheckedChange: (visible) => changeState(setStore, (state) => ({
2093
+ ...state,
2094
+ columnVisibility: {
2095
+ ...state.columnVisibility,
2096
+ [column.id]: visible
2097
+ }
2098
+ })),
2099
+ children: columnLabel(column)
2100
+ }, column.id))
2101
+ ]
2102
+ })
2103
+ })
2104
+ ]
2105
+ });
2106
+ };
2107
+ var ResizeHandle = ({
2108
+ tableAtom
2109
+ }) => {
2110
+ const [store, setStore] = useTableAtom(tableAtom);
2111
+ const columnId = useRequiredId(ColumnIdContext);
2112
+ const resizeRef = useRef(null);
2113
+ const column = deriveModel(store).columns.find(({ id }) => id === columnId);
2114
+ if (!column || column.colDef.resizable === false)
2115
+ return null;
2116
+ const resize = (width) => changeState(setStore, (state) => ({
2117
+ ...state,
2118
+ columnSizing: {
2119
+ ...state.columnSizing,
2120
+ [column.id]: clampWidth(column.colDef, width)
2121
+ }
2122
+ }));
2123
+ const onPointerDown = (event) => {
2124
+ if (event.button !== 0)
2125
+ return;
2126
+ event.preventDefault();
2127
+ event.currentTarget.setPointerCapture(event.pointerId);
2128
+ resizeRef.current = {
2129
+ pointerId: event.pointerId,
2130
+ startX: event.clientX,
2131
+ startWidth: column.width
2132
+ };
2133
+ };
2134
+ const onPointerMove = (event) => {
2135
+ const drag = resizeRef.current;
2136
+ if (!drag || drag.pointerId !== event.pointerId)
2137
+ return;
2138
+ resize(drag.startWidth + event.clientX - drag.startX);
2139
+ };
2140
+ const reset = () => {
2141
+ resizeRef.current = null;
2142
+ };
2143
+ return /* @__PURE__ */ jsx14("button", {
2144
+ "aria-label": store.config.labels.resizeColumn(columnLabel(column)),
2145
+ "aria-orientation": "vertical",
2146
+ "aria-valuemax": column.colDef.maxWidth ?? DEFAULT_MAX_WIDTH,
2147
+ "aria-valuemin": column.colDef.minWidth ?? DEFAULT_MIN_WIDTH,
2148
+ "aria-valuenow": column.width,
2149
+ className: "after:bg-border hover:after:bg-primary/60 focus-visible:after:bg-ring absolute inset-y-0 right-0 z-10 w-2 cursor-col-resize touch-none outline-none after:absolute after:inset-y-3 after:right-0 after:w-px hover:after:w-0.5 focus-visible:after:w-0.5",
2150
+ onDoubleClick: () => resize(column.colDef.width ?? DEFAULT_WIDTH),
2151
+ onKeyDown: (event) => {
2152
+ const delta = event.key === "ArrowLeft" ? -8 : event.key === "ArrowRight" ? 8 : 0;
2153
+ if (delta) {
2154
+ event.preventDefault();
2155
+ resize(column.width + delta);
2156
+ }
2157
+ },
2158
+ onPointerDown,
2159
+ onPointerMove,
2160
+ onPointerUp: reset,
2161
+ onPointerCancel: reset,
2162
+ onLostPointerCapture: reset,
2163
+ role: "separator",
2164
+ type: "button"
2165
+ });
2166
+ };
2167
+ var DragHandle = ({
2168
+ tableAtom
2169
+ }) => {
2170
+ const [store, setStore] = useTableAtom(tableAtom);
2171
+ const rowId = useRequiredId(RowIdContext);
2172
+ const dragRef = useRef(null);
2173
+ const [overlay, setOverlay] = useState(null);
2174
+ const reset = (element) => {
2175
+ clearDragPresentation(element.closest("[data-table-root]"));
2176
+ dragRef.current = null;
2177
+ setOverlay(null);
2178
+ };
2179
+ const onPointerDown = (event) => {
2180
+ event.stopPropagation();
2181
+ event.currentTarget.setPointerCapture(event.pointerId);
2182
+ const row = deriveModel(store).rows.find((candidate) => candidate.id === rowId);
2183
+ const grouping = store.config.features.grouping;
2184
+ const reordering = store.config.features.reordering;
2185
+ dragRef.current = {
2186
+ pointerId: event.pointerId,
2187
+ rowId,
2188
+ label: row && grouping && grouping.getRowLabel?.(row.data) || row && reordering && reordering.getRowLabel?.(row.data) || rowId,
2189
+ startX: event.clientX,
2190
+ startY: event.clientY,
2191
+ active: false
2192
+ };
2193
+ };
2194
+ const onPointerMove = (event) => {
2195
+ const drag = dragRef.current;
2196
+ if (!drag || drag.pointerId !== event.pointerId)
2197
+ return;
2198
+ const root = event.currentTarget.closest("[data-table-root]");
2199
+ const active = drag.active || Math.hypot(event.clientX - drag.startX, event.clientY - drag.startY) >= 8;
2200
+ drag.active = active;
2201
+ clearDragPresentation(root);
2202
+ if (!active)
2203
+ return;
2204
+ const elements = document.elementsFromPoint(event.clientX, event.clientY);
2205
+ const rowTarget = findTableDragTarget(elements, "[data-table-row]", root);
2206
+ const groupTarget = findTableDragTarget(elements, "[data-table-group]", root);
2207
+ event.currentTarget.closest("[data-table-row]")?.setAttribute("data-drag-source", "true");
2208
+ if (canMoveRowsToGroups(store)) {
2209
+ groupTarget?.setAttribute("data-drop-target", "true");
2210
+ } else if (rowTarget?.dataset.tableRow !== drag.rowId) {
2211
+ const rows = deriveModel(store).pageRows;
2212
+ const sourceIndex = rows.findIndex((row) => row.id === drag.rowId);
2213
+ const targetIndex = rows.findIndex((row) => row.id === rowTarget?.dataset.tableRow);
2214
+ if (sourceIndex !== -1 && targetIndex !== -1) {
2215
+ rowTarget?.setAttribute("data-drop-position", sourceIndex < targetIndex ? "after" : "before");
2216
+ }
2217
+ }
2218
+ setOverlay({ label: drag.label, x: event.clientX, y: event.clientY });
2219
+ };
2220
+ const finish = (event) => {
2221
+ const drag = dragRef.current;
2222
+ if (!drag || drag.pointerId !== event.pointerId)
2223
+ return;
2224
+ const root = event.currentTarget.closest("[data-table-root]");
2225
+ const elements = document.elementsFromPoint(event.clientX, event.clientY);
2226
+ const rowTarget = findTableDragTarget(elements, "[data-table-row]", root);
2227
+ const groupTarget = findTableDragTarget(elements, "[data-table-group]", root);
2228
+ setStore((current) => {
2229
+ const targetRowId = rowTarget?.dataset.tableRow;
2230
+ const targetGroupKey = groupTarget?.dataset.tableGroup;
2231
+ const model = deriveModel(current);
2232
+ const source = model.sortedRows.find((row) => row.id === drag.rowId);
2233
+ const grouping = current.config.features.grouping;
2234
+ const reordering = current.config.features.reordering;
2235
+ if (drag.active && source && targetGroupKey && grouping) {
2236
+ const target = parseGroupDropKey(targetGroupKey);
2237
+ const field = grouping.fields.find(({ id }) => id === target?.fieldId);
2238
+ if (target && field?.onMoveToGroup && field.getGroupId(source.data) !== target.groupId) {
2239
+ field.onMoveToGroup(source.data, target.groupId);
2240
+ }
2241
+ } else if (drag.active && source && targetRowId && reordering && canReorderRows(current) && source.id !== targetRowId) {
2242
+ reordering.onReorder(reorderDataTableRows(model.rows, source.id, targetRowId));
2243
+ }
2244
+ return current;
2245
+ });
2246
+ reset(event.currentTarget);
2247
+ };
2248
+ const cancel = (event) => {
2249
+ if (dragRef.current?.pointerId === event.pointerId) {
2250
+ reset(event.currentTarget);
2251
+ }
2252
+ };
2253
+ const reorderWithKeyboard = (direction) => {
2254
+ const reordering = store.config.features.reordering;
2255
+ if (!reordering || !canReorderRows(store))
2256
+ return;
2257
+ const model = deriveModel(store);
2258
+ const visibleRows = model.pageRows;
2259
+ const sourceIndex = visibleRows.findIndex((row) => row.id === rowId);
2260
+ const target = visibleRows[sourceIndex + direction];
2261
+ if (sourceIndex !== -1 && target) {
2262
+ reordering.onReorder(reorderDataTableRows(model.rows, rowId, target.id));
2263
+ }
2264
+ };
2265
+ return /* @__PURE__ */ jsxs8(Fragment, {
2266
+ children: [
2267
+ /* @__PURE__ */ jsx14(Button, {
2268
+ "aria-label": store.config.features.reordering && store.config.features.reordering.handleLabel ? store.config.features.reordering.handleLabel : store.config.labels.reorder,
2269
+ className: "size-8 cursor-grab touch-none active:cursor-grabbing",
2270
+ onClick: (event) => event.stopPropagation(),
2271
+ onKeyDown: (event) => {
2272
+ if (event.key === "ArrowUp" || event.key === "ArrowDown") {
2273
+ event.preventDefault();
2274
+ event.stopPropagation();
2275
+ reorderWithKeyboard(event.key === "ArrowUp" ? -1 : 1);
2276
+ }
2277
+ },
2278
+ onPointerCancel: cancel,
2279
+ onPointerDown,
2280
+ onLostPointerCapture: cancel,
2281
+ onPointerMove,
2282
+ onPointerUp: finish,
2283
+ size: "icon",
2284
+ variant: "ghost",
2285
+ children: /* @__PURE__ */ jsx14(GripVertical, {})
2286
+ }),
2287
+ overlay ? createPortal(/* @__PURE__ */ jsx14("div", {
2288
+ "aria-hidden": "true",
2289
+ className: "bg-background pointer-events-none fixed z-[100] rounded-md border px-3 py-2 text-sm shadow-lg",
2290
+ style: { left: overlay.x + 12, top: overlay.y + 12 },
2291
+ children: overlay.label
2292
+ }), document.body) : null
2293
+ ]
2294
+ });
2295
+ };
2296
+ var toggleRow = (store, setStore, rowId, selected) => changeState(setStore, (state) => {
2297
+ const rowSelection = { ...state.rowSelection, [rowId]: selected };
2298
+ const selection = store.config.features.selection;
2299
+ if (selection) {
2300
+ const model = deriveModel(store);
2301
+ selection.onSelectionChange?.(model.rows.filter((row) => rowSelection[row.id]).map((row) => row.data));
2302
+ }
2303
+ return { ...state, rowSelection };
2304
+ });
2305
+ var TableDataRow = ({
2306
+ tableAtom
2307
+ }) => {
2308
+ const [store, setStore] = useTableAtom(tableAtom);
2309
+ const rowId = useRequiredId(RowIdContext);
2310
+ const model = deriveModel(store);
2311
+ const row = model.sortedRows.find((candidate) => candidate.id === rowId);
2312
+ if (!row)
2313
+ return null;
2314
+ const selection = store.config.features.selection;
2315
+ const selectable = !!selection && (selection.isRowSelectable?.(row.data) ?? true);
2316
+ const draggable = canDragRows(store);
2317
+ return /* @__PURE__ */ jsxs8(TableRow, {
2318
+ className: cn("group/row h-16 data-[drag-source=true]:opacity-40 data-[drop-position=before]:[&>td]:border-t-2 data-[drop-position=before]:[&>td]:border-primary data-[drop-position=after]:[&>td]:border-b-2 data-[drop-position=after]:[&>td]:border-primary", store.config.onRowClicked && "cursor-pointer"),
2319
+ "data-state": store.state.rowSelection[row.id] && "selected",
2320
+ "data-table-row": row.id,
2321
+ onClick: () => store.config.onRowClicked?.(row.data),
2322
+ onKeyDown: (event) => {
2323
+ if (event.target === event.currentTarget && store.config.onRowClicked && (event.key === "Enter" || event.key === " ")) {
2324
+ event.preventDefault();
2325
+ store.config.onRowClicked(row.data);
2326
+ }
2327
+ },
2328
+ tabIndex: store.config.onRowClicked ? 0 : undefined,
2329
+ children: [
2330
+ selection ? /* @__PURE__ */ jsx14(TableCell, {
2331
+ className: "w-10 pr-0",
2332
+ onClick: (event) => event.stopPropagation(),
2333
+ children: /* @__PURE__ */ jsx14(Checkbox, {
2334
+ "aria-label": store.config.labels.selectRow,
2335
+ checked: !!store.state.rowSelection[row.id],
2336
+ disabled: !selectable,
2337
+ onCheckedChange: (checked) => toggleRow(store, setStore, row.id, checked)
2338
+ })
2339
+ }) : null,
2340
+ draggable ? /* @__PURE__ */ jsx14(TableCell, {
2341
+ className: "w-10 pr-0",
2342
+ children: /* @__PURE__ */ jsx14(DragHandle, {
2343
+ tableAtom
2344
+ })
2345
+ }) : null,
2346
+ model.visibleColumns.map((column) => /* @__PURE__ */ jsx14(TableCell, {
2347
+ className: cn("min-w-24 overflow-hidden has-[[data-slot=data-table-list-cell]]:relative has-[[data-slot=data-table-list-cell]]:p-0 has-[[data-slot=data-table-boolean-cell]]:relative has-[[data-slot=data-table-boolean-cell]]:p-0", column.colDef.truncate ? "whitespace-nowrap" : "whitespace-normal"),
2348
+ style: { width: column.width },
2349
+ children: /* @__PURE__ */ jsx14("div", {
2350
+ className: cn("min-w-0", column.colDef.truncate && "truncate"),
2351
+ children: renderCell(row, column, store.config.locale, store.config.labels)
2352
+ })
2353
+ }, column.id)),
2354
+ hasRowActionMenu(store) ? /* @__PURE__ */ jsx14(TableCell, {
2355
+ className: "bg-background group-data-[state=selected]/row:bg-muted sticky right-0 z-20 w-10 min-w-10 cursor-default p-0 transition-colors group-hover/row:bg-[color-mix(in_oklab,var(--muted)_50%,var(--background))]",
2356
+ onClick: (event) => event.stopPropagation(),
2357
+ children: /* @__PURE__ */ jsx14("div", {
2358
+ className: "flex h-16 items-center justify-center",
2359
+ children: /* @__PURE__ */ jsx14(DataTableRowActionMenu, {
2360
+ tableAtom
2361
+ })
2362
+ })
2363
+ }) : null
2364
+ ]
2365
+ });
2366
+ };
2367
+ var GroupActions = ({
2368
+ actions,
2369
+ groupId,
2370
+ title
2371
+ }) => {
2372
+ const visible = actions?.filter((action) => !action.visible || action.visible(groupId));
2373
+ if (!visible?.length)
2374
+ return null;
2375
+ return /* @__PURE__ */ jsxs8(DropdownMenu, {
2376
+ children: [
2377
+ /* @__PURE__ */ jsx14(DropdownMenuTrigger, {
2378
+ onClick: (event) => event.stopPropagation(),
2379
+ render: /* @__PURE__ */ jsxs8(Button, {
2380
+ size: "icon",
2381
+ variant: "ghost",
2382
+ children: [
2383
+ /* @__PURE__ */ jsx14("span", {
2384
+ className: "sr-only",
2385
+ children: title
2386
+ }),
2387
+ /* @__PURE__ */ jsx14(MoreHorizontal, {})
2388
+ ]
2389
+ })
2390
+ }),
2391
+ /* @__PURE__ */ jsx14(DropdownMenuContent, {
2392
+ align: "end",
2393
+ children: /* @__PURE__ */ jsx14(DropdownMenuGroup, {
2394
+ children: visible.map((action) => /* @__PURE__ */ jsxs8(DropdownMenuItem, {
2395
+ onClick: () => action.onClick(groupId),
2396
+ variant: action.variant ?? "default",
2397
+ children: [
2398
+ action.icon,
2399
+ " ",
2400
+ action.name
2401
+ ]
2402
+ }, action.name))
2403
+ })
2404
+ })
2405
+ ]
2406
+ });
2407
+ };
2408
+ var GroupedTable = ({
2409
+ tableAtom,
2410
+ sections
2411
+ }) => {
2412
+ const [store, setStore] = useTableAtom(tableAtom);
2413
+ const model = deriveModel(store);
2414
+ const extra = (store.config.features.selection ? 1 : 0) + (hasRowActionMenu(store) ? 1 : 0) + (canDragRows(store) ? 1 : 0);
2415
+ const renderSections = (items) => items.flatMap((section) => {
2416
+ const collapsed = !!store.state.collapsedGroups[section.key];
2417
+ const targetKey = getGroupDropKey(section.field.id, section.groupId);
2418
+ const toggleCollapsed = () => changeState(setStore, (state) => ({
2419
+ ...state,
2420
+ collapsedGroups: {
2421
+ ...state.collapsedGroups,
2422
+ [section.key]: !collapsed
2423
+ }
2424
+ }));
2425
+ const body = /* @__PURE__ */ jsxs8(TableBody, {
2426
+ className: "data-[drop-target=true]:outline-primary relative data-[drop-target=true]:z-30 data-[drop-target=true]:outline-2 data-[drop-target=true]:-outline-offset-2 data-[drop-target=true]:[&>tr]:border-transparent data-[drop-target=true]:[&>tr>td:last-child]:z-0",
2427
+ "data-table-group": section.field.onMoveToGroup ? targetKey : undefined,
2428
+ children: [
2429
+ /* @__PURE__ */ jsx14(TableRow, {
2430
+ className: "bg-muted/40 hover:bg-accent! cursor-pointer",
2431
+ onClick: toggleCollapsed,
2432
+ children: /* @__PURE__ */ jsx14(TableCell, {
2433
+ colSpan: model.visibleColumns.length + extra,
2434
+ children: /* @__PURE__ */ jsxs8("div", {
2435
+ className: "flex items-center gap-2",
2436
+ style: { paddingLeft: section.depth * 20 },
2437
+ children: [
2438
+ /* @__PURE__ */ jsxs8("button", {
2439
+ "aria-expanded": !collapsed,
2440
+ className: "flex flex-1 cursor-pointer items-center gap-2 text-left font-medium",
2441
+ type: "button",
2442
+ children: [
2443
+ collapsed ? /* @__PURE__ */ jsx14(ChevronRight2, {
2444
+ className: "size-4"
2445
+ }) : /* @__PURE__ */ jsx14(ChevronDown, {
2446
+ className: "size-4"
2447
+ }),
2448
+ /* @__PURE__ */ jsx14("span", {
2449
+ className: "flex-1",
2450
+ children: section.field.renderGroupLabel?.(section.groupId, section.rows.map((row) => row.data)) ?? section.groupId
2451
+ })
2452
+ ]
2453
+ }),
2454
+ /* @__PURE__ */ jsx14(Badge, {
2455
+ variant: "secondary",
2456
+ children: section.rows.length
2457
+ }),
2458
+ /* @__PURE__ */ jsx14(GroupActions, {
2459
+ actions: section.field.actions,
2460
+ groupId: section.groupId,
2461
+ title: section.field.actionsLabel ?? store.config.labels.actions
2462
+ })
2463
+ ]
2464
+ })
2465
+ })
2466
+ }),
2467
+ !collapsed && !section.children.length ? section.rows.length ? section.rows.map((row) => /* @__PURE__ */ jsx14(RowIdContext.Provider, {
2468
+ value: row.id,
2469
+ children: /* @__PURE__ */ jsx14(TableDataRow, {
2470
+ tableAtom
2471
+ })
2472
+ }, `${section.key}:${row.id}`)) : [
2473
+ /* @__PURE__ */ jsx14(TableRow, {
2474
+ children: /* @__PURE__ */ jsx14(TableCell, {
2475
+ className: "text-muted-foreground h-16",
2476
+ colSpan: model.visibleColumns.length + extra,
2477
+ children: section.field.renderEmptyGroup?.(section.groupId) ?? store.config.labels.empty
2478
+ })
2479
+ }, `${section.key}:empty`)
2480
+ ] : null
2481
+ ]
2482
+ }, section.key);
2483
+ return !collapsed && section.children.length ? [body, renderSections(section.children)] : [body];
2484
+ });
2485
+ return /* @__PURE__ */ jsx14(Fragment, {
2486
+ children: renderSections(sections)
2487
+ });
2488
+ };
2489
+ var ColumnHeaderMenu = ({
2490
+ tableAtom
2491
+ }) => {
2492
+ const [store, setStore] = useTableAtom(tableAtom);
2493
+ const columnId = useRequiredId(ColumnIdContext);
2494
+ const column = deriveModel(store).columns.find(({ id }) => id === columnId);
2495
+ if (!column)
2496
+ return null;
2497
+ const sortingEnabled = store.config.features.sorting !== false && column.colDef.sortable !== false;
2498
+ const hidingEnabled = store.config.features.columnVisibility !== false && column.colDef.hideable !== false;
2499
+ const sort = store.state.sort?.find(({ id }) => id === column.id);
2500
+ const update = (next) => changeState(setStore, next);
2501
+ const setSort = (direction) => update((state) => ({
2502
+ ...state,
2503
+ sort: [{ id: column.id, direction }],
2504
+ page: 0
2505
+ }));
2506
+ const label = columnLabel(column);
2507
+ if (!sortingEnabled && !hidingEnabled) {
2508
+ return /* @__PURE__ */ jsx14("div", {
2509
+ className: "truncate px-2",
2510
+ children: column.colDef.headerName
2511
+ });
2512
+ }
2513
+ return /* @__PURE__ */ jsxs8(DropdownMenu, {
2514
+ children: [
2515
+ /* @__PURE__ */ jsx14(DropdownMenuTrigger, {
2516
+ render: /* @__PURE__ */ jsxs8(Button, {
2517
+ "aria-label": label,
2518
+ className: "absolute inset-0 h-full w-full min-w-0 justify-start rounded-none px-2 pr-4 focus-visible:ring-inset",
2519
+ variant: "ghost",
2520
+ children: [
2521
+ /* @__PURE__ */ jsx14("span", {
2522
+ className: "truncate",
2523
+ children: column.colDef.headerName
2524
+ }),
2525
+ sort ? sort.direction === "desc" ? /* @__PURE__ */ jsx14(ArrowDown, {}) : /* @__PURE__ */ jsx14(ArrowUp, {}) : null
2526
+ ]
2527
+ })
2528
+ }),
2529
+ /* @__PURE__ */ jsx14(DropdownMenuContent, {
2530
+ align: "start",
2531
+ className: "w-48",
2532
+ children: /* @__PURE__ */ jsxs8(DropdownMenuGroup, {
2533
+ children: [
2534
+ sortingEnabled ? /* @__PURE__ */ jsxs8(Fragment, {
2535
+ children: [
2536
+ /* @__PURE__ */ jsxs8(DropdownMenuItem, {
2537
+ onClick: () => setSort("asc"),
2538
+ children: [
2539
+ /* @__PURE__ */ jsx14(ArrowUp, {}),
2540
+ " ",
2541
+ store.config.labels.sortAsc
2542
+ ]
2543
+ }),
2544
+ /* @__PURE__ */ jsxs8(DropdownMenuItem, {
2545
+ onClick: () => setSort("desc"),
2546
+ children: [
2547
+ /* @__PURE__ */ jsx14(ArrowDown, {}),
2548
+ " ",
2549
+ store.config.labels.sortDesc
2550
+ ]
2551
+ }),
2552
+ sort ? /* @__PURE__ */ jsxs8(DropdownMenuItem, {
2553
+ onClick: () => update((state) => ({
2554
+ ...state,
2555
+ sort: state.sort?.filter(({ id }) => id !== column.id)
2556
+ })),
2557
+ children: [
2558
+ /* @__PURE__ */ jsx14(X, {}),
2559
+ " ",
2560
+ store.config.labels.sortClear
2561
+ ]
2562
+ }) : null
2563
+ ]
2564
+ }) : null,
2565
+ sortingEnabled && hidingEnabled ? /* @__PURE__ */ jsx14(DropdownMenuSeparator, {}) : null,
2566
+ hidingEnabled ? /* @__PURE__ */ jsxs8(DropdownMenuItem, {
2567
+ onClick: () => update((state) => ({
2568
+ ...state,
2569
+ columnVisibility: {
2570
+ ...state.columnVisibility,
2571
+ [column.id]: false
2572
+ }
2573
+ })),
2574
+ children: [
2575
+ /* @__PURE__ */ jsx14(EyeOff, {}),
2576
+ " ",
2577
+ store.config.labels.hideColumn
2578
+ ]
2579
+ }) : null
2580
+ ]
2581
+ })
2582
+ })
2583
+ ]
2584
+ });
2585
+ };
2586
+ var DataTableHeader = ({
2587
+ tableAtom
2588
+ }) => {
2589
+ const [store, setStore] = useTableAtom(tableAtom);
2590
+ const model = deriveModel(store);
2591
+ const selection = store.config.features.selection;
2592
+ const grouped = getActiveGrouping(store).length > 0;
2593
+ const draggable = canDragRows(store);
2594
+ const selectableRows = getDataTableSelectableRows(model, grouped, selection ? selection.isRowSelectable : undefined);
2595
+ const allSelected = selectableRows.length > 0 && selectableRows.every((row) => store.state.rowSelection[row.id]);
2596
+ const someSelected = selectableRows.some((row) => store.state.rowSelection[row.id]);
2597
+ return /* @__PURE__ */ jsx14(TableHeader, {
2598
+ children: /* @__PURE__ */ jsxs8(TableRow, {
2599
+ children: [
2600
+ selection ? /* @__PURE__ */ jsx14(TableHead, {
2601
+ className: "w-10 pr-0",
2602
+ children: /* @__PURE__ */ jsx14(Checkbox, {
2603
+ "aria-label": store.config.labels.selectAllRows,
2604
+ checked: allSelected,
2605
+ indeterminate: someSelected && !allSelected,
2606
+ onCheckedChange: (checked) => {
2607
+ changeState(setStore, (state) => {
2608
+ const rowSelection = { ...state.rowSelection };
2609
+ selectableRows.forEach((row) => rowSelection[row.id] = checked);
2610
+ selection.onSelectionChange?.(model.rows.filter((row) => rowSelection[row.id]).map((row) => row.data));
2611
+ return { ...state, rowSelection };
2612
+ });
2613
+ }
2614
+ })
2615
+ }) : null,
2616
+ draggable ? /* @__PURE__ */ jsx14(TableHead, {
2617
+ className: "w-10"
2618
+ }) : null,
2619
+ model.visibleColumns.map((column) => {
2620
+ const direction = store.state.sort?.find(({ id }) => id === column.id)?.direction;
2621
+ return /* @__PURE__ */ jsx14(TableHead, {
2622
+ "aria-sort": direction === "asc" ? "ascending" : direction === "desc" ? "descending" : undefined,
2623
+ className: "relative h-12 p-0",
2624
+ scope: "col",
2625
+ style: { width: column.width },
2626
+ children: /* @__PURE__ */ jsxs8(ColumnIdContext.Provider, {
2627
+ value: column.id,
2628
+ children: [
2629
+ /* @__PURE__ */ jsx14(ColumnHeaderMenu, {
2630
+ tableAtom
2631
+ }),
2632
+ /* @__PURE__ */ jsx14(ResizeHandle, {
2633
+ tableAtom
2634
+ })
2635
+ ]
2636
+ })
2637
+ }, column.id);
2638
+ }),
2639
+ hasRowActionMenu(store) ? /* @__PURE__ */ jsx14(TableHead, {
2640
+ className: "w-10"
2641
+ }) : null
2642
+ ]
2643
+ })
2644
+ });
2645
+ };
2646
+ var DataTableBody = ({
2647
+ tableAtom
2648
+ }) => {
2649
+ const [store] = useTableAtom(tableAtom);
2650
+ const model = deriveModel(store);
2651
+ const fields = getActiveGrouping(store);
2652
+ const grouped = fields.length > 0;
2653
+ const rows = grouped ? model.sortedRows : model.pageRows;
2654
+ const sections = groupDataTableRows(rows, fields);
2655
+ const colSpan = model.visibleColumns.length + (store.config.features.selection ? 1 : 0) + (hasRowActionMenu(store) ? 1 : 0) + (canDragRows(store) ? 1 : 0);
2656
+ if (sections.length && (rows.length || !store.config.status.loading) && !store.config.status.error) {
2657
+ return /* @__PURE__ */ jsx14(GroupedTable, {
2658
+ tableAtom,
2659
+ sections
2660
+ });
2661
+ }
2662
+ return /* @__PURE__ */ jsx14(TableBody, {
2663
+ children: store.config.status.error || !rows.length && !store.config.status.loading ? /* @__PURE__ */ jsx14(TableRow, {
2664
+ children: /* @__PURE__ */ jsx14(TableCell, {
2665
+ className: "h-24 text-center",
2666
+ colSpan: Math.max(colSpan, 1),
2667
+ children: store.config.status.error ?? store.config.status.empty ?? store.config.labels.empty
2668
+ })
2669
+ }) : store.config.status.loading && !rows.length ? /* @__PURE__ */ jsx14(TableRow, {
2670
+ children: /* @__PURE__ */ jsx14(TableCell, {
2671
+ className: "h-24 text-center",
2672
+ colSpan: Math.max(colSpan, 1),
2673
+ children: /* @__PURE__ */ jsx14(Loading, {
2674
+ label: store.config.labels.loading
2675
+ })
2676
+ })
2677
+ }) : rows.map((row) => /* @__PURE__ */ jsx14(RowIdContext.Provider, {
2678
+ value: row.id,
2679
+ children: /* @__PURE__ */ jsx14(TableDataRow, {
2680
+ tableAtom
2681
+ })
2682
+ }, row.id))
2683
+ });
2684
+ };
2685
+ var GalleryCard = ({
2686
+ tableAtom
2687
+ }) => {
2688
+ const [store, setStore] = useTableAtom(tableAtom);
2689
+ const rowId = useRequiredId(RowIdContext);
2690
+ const model = deriveModel(store);
2691
+ const row = model.sortedRows.find((candidate) => candidate.id === rowId);
2692
+ const gallery = store.config.features.gallery;
2693
+ if (!row || !gallery)
2694
+ return null;
2695
+ const find = (id) => id ? model.visibleColumns.find((column) => column.id === id) : undefined;
2696
+ const name = find(gallery.name);
2697
+ const description = find(gallery.description);
2698
+ const tag = find(gallery.tag);
2699
+ const selection = store.config.features.selection;
2700
+ const selectable = !!selection && (selection.isRowSelectable?.(row.data) ?? true);
2701
+ const draggable = canDragRows(store);
2702
+ return /* @__PURE__ */ jsx14(Card, {
2703
+ className: cn("relative gap-3 data-[drag-source=true]:opacity-40 data-[drop-position=before]:border-t-2 data-[drop-position=before]:border-t-primary data-[drop-position=after]:border-b-2 data-[drop-position=after]:border-b-primary", store.config.onRowClicked && "cursor-pointer"),
2704
+ "data-table-row": row.id,
2705
+ onClick: () => store.config.onRowClicked?.(row.data),
2706
+ onKeyDown: (event) => {
2707
+ if (event.target === event.currentTarget && store.config.onRowClicked && (event.key === "Enter" || event.key === " ")) {
2708
+ event.preventDefault();
2709
+ store.config.onRowClicked(row.data);
2710
+ }
2711
+ },
2712
+ tabIndex: store.config.onRowClicked ? 0 : undefined,
2713
+ children: /* @__PURE__ */ jsxs8(CardHeader, {
2714
+ className: "pr-12",
2715
+ children: [
2716
+ /* @__PURE__ */ jsxs8("div", {
2717
+ className: "flex items-center gap-2",
2718
+ children: [
2719
+ selection ? /* @__PURE__ */ jsx14(Checkbox, {
2720
+ "aria-label": store.config.labels.selectRow,
2721
+ checked: !!store.state.rowSelection[row.id],
2722
+ disabled: !selectable,
2723
+ onCheckedChange: (checked) => toggleRow(store, setStore, row.id, checked),
2724
+ onClick: (event) => event.stopPropagation()
2725
+ }) : null,
2726
+ draggable ? /* @__PURE__ */ jsx14(DragHandle, {
2727
+ tableAtom
2728
+ }) : null,
2729
+ tag ? /* @__PURE__ */ jsxs8(Badge, {
2730
+ variant: "secondary",
2731
+ children: [
2732
+ gallery.tagIcon,
2733
+ renderCell(row, tag, store.config.locale, store.config.labels)
2734
+ ]
2735
+ }) : null
2736
+ ]
2737
+ }),
2738
+ /* @__PURE__ */ jsx14(CardTitle, {
2739
+ children: name ? renderCell(row, name, store.config.locale, store.config.labels) : row.id
2740
+ }),
2741
+ description ? /* @__PURE__ */ jsx14("div", {
2742
+ className: "text-muted-foreground line-clamp-3 text-sm",
2743
+ children: renderCell(row, description, store.config.locale, store.config.labels)
2744
+ }) : null,
2745
+ hasRowActionMenu(store) ? /* @__PURE__ */ jsx14("div", {
2746
+ className: "absolute top-4 right-4",
2747
+ onClick: (event) => event.stopPropagation(),
2748
+ children: /* @__PURE__ */ jsx14(DataTableRowActionMenu, {
2749
+ tableAtom
2750
+ })
2751
+ }) : null
2752
+ ]
2753
+ })
2754
+ });
2755
+ };
2756
+ var DataTableGallery = ({
2757
+ tableAtom
2758
+ }) => {
2759
+ const [store, setStore] = useTableAtom(tableAtom);
2760
+ const model = deriveModel(store);
2761
+ const fields = getActiveGrouping(store);
2762
+ const rows = fields.length ? model.sortedRows : model.pageRows;
2763
+ const sections = groupDataTableRows(rows, fields);
2764
+ if (store.config.status.error) {
2765
+ return /* @__PURE__ */ jsx14("div", {
2766
+ className: "text-destructive rounded-lg border border-dashed p-10 text-center",
2767
+ children: store.config.status.error
2768
+ });
2769
+ }
2770
+ if (store.config.status.loading && !rows.length) {
2771
+ return /* @__PURE__ */ jsx14("div", {
2772
+ className: "rounded-lg border border-dashed p-10 text-center",
2773
+ children: /* @__PURE__ */ jsx14(Loading, {
2774
+ label: store.config.labels.loading
2775
+ })
2776
+ });
2777
+ }
2778
+ if (!rows.length && !sections.length) {
2779
+ return /* @__PURE__ */ jsx14("div", {
2780
+ className: "text-muted-foreground rounded-lg border border-dashed p-10 text-center",
2781
+ children: store.config.status.empty ?? store.config.labels.empty
2782
+ });
2783
+ }
2784
+ if (!fields.length) {
2785
+ return /* @__PURE__ */ jsx14("div", {
2786
+ className: "grid gap-3 sm:grid-cols-2 xl:grid-cols-3",
2787
+ children: rows.map((row) => /* @__PURE__ */ jsx14(RowIdContext.Provider, {
2788
+ value: row.id,
2789
+ children: /* @__PURE__ */ jsx14(GalleryCard, {
2790
+ tableAtom
2791
+ })
2792
+ }, row.id))
2793
+ });
2794
+ }
2795
+ const renderSections = (sections) => sections.map((section) => {
2796
+ const collapsed = !!store.state.collapsedGroups[section.key];
2797
+ const targetKey = getGroupDropKey(section.field.id, section.groupId);
2798
+ const toggleCollapsed = () => changeState(setStore, (state) => ({
2799
+ ...state,
2800
+ collapsedGroups: {
2801
+ ...state.collapsedGroups,
2802
+ [section.key]: !collapsed
2803
+ }
2804
+ }));
2805
+ return /* @__PURE__ */ jsxs8("section", {
2806
+ className: "data-[drop-target=true]:ring-primary space-y-3 rounded-lg transition-shadow data-[drop-target=true]:ring-2",
2807
+ "data-table-group": section.field.onMoveToGroup ? targetKey : undefined,
2808
+ children: [
2809
+ /* @__PURE__ */ jsxs8("div", {
2810
+ className: "hover:bg-accent flex cursor-pointer items-center gap-2 rounded-lg border p-3 transition-colors",
2811
+ onClick: toggleCollapsed,
2812
+ children: [
2813
+ /* @__PURE__ */ jsxs8("button", {
2814
+ "aria-expanded": !collapsed,
2815
+ className: "flex flex-1 cursor-pointer items-center gap-2 text-left font-medium",
2816
+ type: "button",
2817
+ children: [
2818
+ collapsed ? /* @__PURE__ */ jsx14(ChevronRight2, {
2819
+ className: "size-4"
2820
+ }) : /* @__PURE__ */ jsx14(ChevronDown, {
2821
+ className: "size-4"
2822
+ }),
2823
+ /* @__PURE__ */ jsx14("span", {
2824
+ className: "flex-1",
2825
+ children: section.field.renderGroupLabel?.(section.groupId, section.rows.map((row) => row.data)) ?? section.groupId
2826
+ }),
2827
+ /* @__PURE__ */ jsx14(Badge, {
2828
+ variant: "secondary",
2829
+ children: section.rows.length
2830
+ })
2831
+ ]
2832
+ }),
2833
+ /* @__PURE__ */ jsx14(GroupActions, {
2834
+ actions: section.field.actions,
2835
+ groupId: section.groupId,
2836
+ title: section.field.actionsLabel ?? store.config.labels.actions
2837
+ })
2838
+ ]
2839
+ }),
2840
+ !collapsed ? section.children.length ? renderSections(section.children) : section.rows.length ? /* @__PURE__ */ jsx14("div", {
2841
+ className: "grid gap-3 sm:grid-cols-2 xl:grid-cols-3",
2842
+ children: section.rows.map((row) => /* @__PURE__ */ jsx14(RowIdContext.Provider, {
2843
+ value: row.id,
2844
+ children: /* @__PURE__ */ jsx14(GalleryCard, {
2845
+ tableAtom
2846
+ })
2847
+ }, `${section.key}:${row.id}`))
2848
+ }) : /* @__PURE__ */ jsx14("div", {
2849
+ className: "text-muted-foreground rounded-lg border border-dashed p-8 text-center",
2850
+ children: section.field.renderEmptyGroup?.(section.groupId) ?? store.config.labels.empty
2851
+ }) : null
2852
+ ]
2853
+ }, section.key);
2854
+ });
2855
+ return /* @__PURE__ */ jsx14("div", {
2856
+ className: "space-y-4",
2857
+ children: renderSections(sections)
2858
+ });
2859
+ };
2860
+ var DataTablePagination = ({
2861
+ tableAtom
2862
+ }) => {
2863
+ const [store, setStore] = useTableAtom(tableAtom);
2864
+ const model = deriveModel(store);
2865
+ const pagination = store.config.features.pagination ?? { mode: "client" };
2866
+ const clientGrouping = pagination !== false && pagination.mode === "client" && getActiveGrouping(store).length > 0;
2867
+ const paginationVisible = pagination !== false && !clientGrouping;
2868
+ const pageIndex = store.state.page;
2869
+ const maxPageIndex = model.pageCount - 1;
2870
+ useLayoutEffect(() => {
2871
+ if (paginationVisible && pageIndex > maxPageIndex) {
2872
+ changeState(setStore, (state) => ({
2873
+ ...state,
2874
+ page: maxPageIndex
2875
+ }));
2876
+ }
2877
+ }, [maxPageIndex, pageIndex, paginationVisible, setStore]);
2878
+ if (!paginationVisible)
2879
+ return null;
2880
+ const selected = model.rows.filter((row) => store.state.rowSelection[row.id]).length;
2881
+ const setPagination = (next) => changeState(setStore, (state) => ({ ...state, ...next }));
2882
+ return /* @__PURE__ */ jsx14("div", {
2883
+ className: "pt-4",
2884
+ children: /* @__PURE__ */ jsx14(Pagination, {
2885
+ locale: store.config.locale,
2886
+ messages: { [store.config.locale]: store.config.labels },
2887
+ onPageChange: (page) => setPagination({ page, pageSize: store.state.pageSize }),
2888
+ onPageSizeChange: (pageSize) => setPagination({ page: 0, pageSize }),
2889
+ page: Math.min(store.state.page, model.pageCount - 1),
2890
+ pageCount: model.pageCount,
2891
+ pageSize: store.state.pageSize,
2892
+ pageSizes: pagination.pageSizes,
2893
+ selectedRows: selected,
2894
+ totalRows: model.totalRows
2895
+ })
2896
+ });
2897
+ };
2898
+ var HydratedDataTable = ({
2899
+ persistedUiState,
2900
+ setPersistedUiState,
2901
+ ...props
2902
+ }) => {
2903
+ const [initialGrouping] = useState(() => {
2904
+ const grouping = props.features?.grouping;
2905
+ return grouping && grouping.initial ? grouping.initial : [];
2906
+ });
2907
+ const [transientUiAtom] = useState(() => Atom.make(transientUiFromState(DEFAULT_UI_STATE)));
2908
+ const [transientUiState, setTransientUiState] = useAtom(transientUiAtom);
2909
+ const uiState = useMemo(() => ({
2910
+ ...persistedUiState,
2911
+ ...transientUiState,
2912
+ grouping: persistedUiState.grouping ?? initialGrouping
2913
+ }), [persistedUiState, transientUiState, initialGrouping]);
2914
+ const setUiState = useCallback((state) => {
2915
+ setPersistedUiState(persistedUiFromState(state));
2916
+ setTransientUiState(transientUiFromState(state));
2917
+ }, [setPersistedUiState, setTransientUiState]);
2918
+ const validatedConfig = resolveConfig(props, (state) => setUiState(state));
2919
+ const [tableAtom] = useState(() => {
2920
+ const initial = {
2921
+ rowData: props.rowData,
2922
+ columnDefs: props.columnDefs,
2923
+ config: validatedConfig,
2924
+ state: initialPublicState(props, uiState),
2925
+ controlledState: props.state
2926
+ };
2927
+ return Atom.make({
2928
+ ...initial,
2929
+ model: buildDataTableModel(initial)
2930
+ });
2931
+ });
2932
+ const setStore = useAtomSet(tableAtom);
2933
+ useLayoutEffect(() => {
2934
+ setStore((store) => {
2935
+ const features = props.features ?? {};
2936
+ const selection = features.selection;
2937
+ const config = {
2938
+ getRowId: selection && selection.getRowId || props.getRowId || undefined,
2939
+ onStateChange: props.onStateChange,
2940
+ onUiStateChange: (state) => setUiState(state),
2941
+ status: props.status ?? {},
2942
+ features,
2943
+ onRowClicked: props.onRowClicked,
2944
+ labels: dataTableMessages(props.locale, props.messages),
2945
+ locale: props.locale ?? "en"
2946
+ };
2947
+ const state = {
2948
+ ...store.state,
2949
+ ...uiState,
2950
+ ...queryFromState(props.state ?? store.state)
2951
+ };
2952
+ const modelChanged = store.rowData !== props.rowData || store.columnDefs !== props.columnDefs || !sameDataTableState(store.state, state) || store.config.getRowId !== config.getRowId || store.config.features.pagination !== config.features.pagination;
2953
+ const next = {
2954
+ ...store,
2955
+ rowData: props.rowData,
2956
+ columnDefs: props.columnDefs,
2957
+ config,
2958
+ controlledState: props.state,
2959
+ state
2960
+ };
2961
+ return modelChanged ? { ...next, model: buildDataTableModel(next) } : next;
2962
+ });
2963
+ }, [
2964
+ props.columnDefs,
2965
+ props.features,
2966
+ props.getRowId,
2967
+ props.locale,
2968
+ props.messages,
2969
+ props.onRowClicked,
2970
+ props.onStateChange,
2971
+ props.rowData,
2972
+ props.state,
2973
+ props.status,
2974
+ setStore,
2975
+ setUiState,
2976
+ uiState
2977
+ ]);
2978
+ return /* @__PURE__ */ jsxs8("div", {
2979
+ className: "w-full max-w-full min-w-0 rounded-md",
2980
+ "data-table-root": "",
2981
+ children: [
2982
+ /* @__PURE__ */ jsx14(DataTableToolbar, {
2983
+ tableAtom
2984
+ }),
2985
+ /* @__PURE__ */ jsx14(DataTableContent, {
2986
+ tableAtom
2987
+ }),
2988
+ /* @__PURE__ */ jsx14(DataTablePagination, {
2989
+ tableAtom
2990
+ })
2991
+ ]
2992
+ });
2993
+ };
2994
+ var DataTable = (props) => {
2995
+ const locale = useKrakstackLocale3(props.locale);
2996
+ const [initialColumnVisibility] = useState(() => props.initialState?.columnVisibility ?? {});
2997
+ const [persistedUiAtom] = useState(() => {
2998
+ const pathname = globalThis.window?.location.pathname ?? "/";
2999
+ const columnIds = normalizeDataTableColumns(props.columnDefs).map(({ id }) => id).join(",");
3000
+ const viewCapability = props.features?.gallery ? "gallery" : "table";
3001
+ return Atom.kvs({
3002
+ mode: "async",
3003
+ runtime: dataTableStorageRuntime,
3004
+ key: `data-table:${pathname}:${columnIds}:${viewCapability}:ui`,
3005
+ schema: DataTablePersistedUiStateSchema,
3006
+ defaultValue: () => ({
3007
+ ...persistedUiFromState(DEFAULT_UI_STATE),
3008
+ grouping: props.features?.grouping ? props.features.grouping.initial ?? [] : []
3009
+ })
3010
+ });
3011
+ });
3012
+ const [persistedUiResult, setPersistedUiState] = useAtom(persistedUiAtom);
3013
+ const persistedUiState = useMemo(() => AsyncResult.isSuccess(persistedUiResult) ? {
3014
+ ...persistedUiResult.value,
3015
+ columnVisibility: {
3016
+ ...initialColumnVisibility,
3017
+ ...persistedUiResult.value.columnVisibility
3018
+ }
3019
+ } : undefined, [initialColumnVisibility, persistedUiResult]);
3020
+ if (!persistedUiState || AsyncResult.isWaiting(persistedUiResult)) {
3021
+ return /* @__PURE__ */ jsx14("div", {
3022
+ "aria-busy": "true",
3023
+ className: "invisible w-full max-w-full min-w-0 rounded-md",
3024
+ "data-table-root": ""
3025
+ });
3026
+ }
3027
+ return /* @__PURE__ */ jsx14(HydratedDataTable, {
3028
+ ...props,
3029
+ locale,
3030
+ persistedUiState,
3031
+ setPersistedUiState
3032
+ });
3033
+ };
3034
+ var DataTableContent = ({
3035
+ tableAtom
3036
+ }) => {
3037
+ const [store] = useTableAtom(tableAtom);
3038
+ if (store.config.features.gallery && store.state.view === "gallery") {
3039
+ return /* @__PURE__ */ jsx14(DataTableGallery, {
3040
+ tableAtom
3041
+ });
3042
+ }
3043
+ const model = deriveModel(store);
3044
+ const width = getDataTableWidth(model.visibleColumns, (store.config.features.selection ? 1 : 0) + (hasRowActionMenu(store) ? 1 : 0) + (canDragRows(store) ? 1 : 0));
3045
+ return /* @__PURE__ */ jsxs8(ScrollArea, {
3046
+ className: "max-w-full min-w-0",
3047
+ children: [
3048
+ /* @__PURE__ */ jsxs8(Table, {
3049
+ className: "table-fixed",
3050
+ style: { width: `max(100%, ${width}px)` },
3051
+ children: [
3052
+ /* @__PURE__ */ jsx14(DataTableHeader, {
3053
+ tableAtom
3054
+ }),
3055
+ /* @__PURE__ */ jsx14(DataTableBody, {
3056
+ tableAtom
3057
+ })
3058
+ ]
3059
+ }),
3060
+ /* @__PURE__ */ jsx14(ScrollBar, {
3061
+ orientation: "horizontal"
3062
+ })
3063
+ ]
3064
+ });
3065
+ };
3066
+ var DataTableListCell = (props) => {
3067
+ const locale = useKrakstackLocale3(props.locale);
3068
+ const resolvedProps = { ...props, locale };
3069
+ if (resolvedProps.options && (resolvedProps.onAdd || resolvedProps.onRemove)) {
3070
+ return /* @__PURE__ */ jsx14(EditableDataTableListCell, {
3071
+ ...resolvedProps
3072
+ });
3073
+ }
3074
+ const { actionsLabel, itemActions, onItemClick, ...summaryProps } = resolvedProps;
3075
+ const labels = dataTableMessages(locale, resolvedProps.messages);
3076
+ const hasItems = resolvedProps.items.length > 0;
3077
+ if (!itemActions?.length && !hasItems) {
3078
+ return /* @__PURE__ */ jsx14(DataTableListSummary, {
3079
+ ...summaryProps
3080
+ });
3081
+ }
3082
+ const menuLabel = actionsLabel ?? (itemActions?.length ? labels.actions : labels.listDetails);
3083
+ return /* @__PURE__ */ jsx14("div", {
3084
+ className: "grid min-h-16 in-[[data-slot=table-cell]]:absolute in-[[data-slot=table-cell]]:inset-0 in-[[data-slot=table-cell]]:min-h-0",
3085
+ "data-slot": "data-table-list-cell",
3086
+ onClick: (event) => event.stopPropagation(),
3087
+ onPointerDown: (event) => event.stopPropagation(),
3088
+ children: /* @__PURE__ */ jsx14(DataTableListMenu, {
3089
+ actions: itemActions ?? [],
3090
+ display: resolvedProps.display,
3091
+ force: hasItems,
3092
+ label: menuLabel,
3093
+ items: resolvedProps.items,
3094
+ locale,
3095
+ messages: resolvedProps.messages,
3096
+ onItemClick,
3097
+ trigger: /* @__PURE__ */ jsxs8(Button, {
3098
+ "aria-label": menuLabel,
3099
+ className: "h-full w-full min-w-0 justify-between rounded-none px-2 focus-visible:ring-inset",
3100
+ variant: "ghost",
3101
+ children: [
3102
+ /* @__PURE__ */ jsx14(DataTableListSummaryContent, {
3103
+ ...summaryProps,
3104
+ showMenu: false
3105
+ }),
3106
+ /* @__PURE__ */ jsx14(ChevronDown, {})
3107
+ ]
3108
+ })
3109
+ })
3110
+ });
3111
+ };
3112
+ var EditableDataTableListCell = ({
3113
+ emptyLabel,
3114
+ manageLabel,
3115
+ onAdd,
3116
+ onRemove,
3117
+ options,
3118
+ items,
3119
+ display,
3120
+ visibleCount,
3121
+ totalCount,
3122
+ actionsLabel,
3123
+ itemActions,
3124
+ onItemClick,
3125
+ locale = "en",
3126
+ messages
3127
+ }) => {
3128
+ const [selected, setSelected] = useState([...items]);
3129
+ useLayoutEffect(() => setSelected([...items]), [items]);
3130
+ const selectedValues = new Set(selected.map((item) => item.value));
3131
+ const available = options.filter((item) => !selectedValues.has(item.value));
3132
+ const canAdd = !!onAdd && available.length > 0;
3133
+ const selectedTotal = totalCount === undefined ? selected.length : totalCount + selected.length - items.length;
3134
+ const labels = dataTableMessages(locale, messages);
3135
+ const actions = [
3136
+ ...itemActions ?? [],
3137
+ ...onRemove ? [
3138
+ {
3139
+ id: "data-table-list-remove",
3140
+ closeOnClick: false,
3141
+ name: labels.removeItem,
3142
+ icon: /* @__PURE__ */ jsx14(Trash2, {}),
3143
+ variant: "destructive",
3144
+ onClick: (item) => {
3145
+ if (item.value === undefined)
3146
+ return;
3147
+ onRemove(item.value);
3148
+ setSelected((current) => current.filter((candidate) => candidate.value !== item.value));
3149
+ }
3150
+ }
3151
+ ] : []
3152
+ ];
3153
+ return /* @__PURE__ */ jsx14("div", {
3154
+ "data-slot": "data-table-list-cell",
3155
+ className: "grid min-h-16 in-[[data-slot=table-cell]]:absolute in-[[data-slot=table-cell]]:inset-0 in-[[data-slot=table-cell]]:min-h-0",
3156
+ onClick: (event) => event.stopPropagation(),
3157
+ onPointerDown: (event) => event.stopPropagation(),
3158
+ children: /* @__PURE__ */ jsx14(DataTableListMenu, {
3159
+ actions,
3160
+ addEmptyLabel: emptyLabel,
3161
+ addLabel: labels.addItem,
3162
+ addOptions: canAdd ? available : undefined,
3163
+ addSearchLabel: manageLabel,
3164
+ display,
3165
+ force: true,
3166
+ items: selected,
3167
+ onItemClick,
3168
+ label: actionsLabel ?? manageLabel,
3169
+ locale,
3170
+ messages,
3171
+ onAdd: canAdd ? (item) => {
3172
+ onAdd(item.value);
3173
+ setSelected((current) => [...current, item]);
3174
+ } : undefined,
3175
+ trigger: /* @__PURE__ */ jsxs8(Button, {
3176
+ "aria-label": manageLabel,
3177
+ className: "h-full w-full min-w-0 justify-between rounded-none px-2 focus-visible:ring-inset",
3178
+ variant: "ghost",
3179
+ children: [
3180
+ /* @__PURE__ */ jsx14(DataTableListSummaryContent, {
3181
+ emptyLabel,
3182
+ items: selected,
3183
+ display,
3184
+ showMenu: false,
3185
+ visibleCount,
3186
+ totalCount: selectedTotal
3187
+ }),
3188
+ /* @__PURE__ */ jsx14(ChevronDown, {})
3189
+ ]
3190
+ })
3191
+ })
3192
+ });
3193
+ };
3194
+ var DataTableListMenu = ({
3195
+ actions,
3196
+ addEmptyLabel,
3197
+ addLabel,
3198
+ addOptions,
3199
+ addSearchLabel,
3200
+ className,
3201
+ display = "list",
3202
+ force = false,
3203
+ items,
3204
+ label,
3205
+ locale = "en",
3206
+ messages,
3207
+ onAdd,
3208
+ onItemClick,
3209
+ trigger
3210
+ }) => {
3211
+ const entries = items.map((item) => {
3212
+ const normalized = Schema.is(Schema.String)(item) ? { label: item } : item;
3213
+ const visibleActions = actions.filter((action) => action.visible?.(normalized) ?? true);
3214
+ return { item: normalized, visibleActions };
3215
+ });
3216
+ const hasActions = entries.some(({ visibleActions }) => visibleActions.length);
3217
+ if (!force && !hasActions && !onAdd)
3218
+ return null;
3219
+ const labels = dataTableMessages(locale, messages);
3220
+ const resolvedLabel = label ?? (hasActions ? labels.actions : labels.listDetails);
3221
+ return /* @__PURE__ */ jsxs8(DropdownMenu, {
3222
+ children: [
3223
+ /* @__PURE__ */ jsx14(DropdownMenuTrigger, {
3224
+ onClick: (event) => event.stopPropagation(),
3225
+ onPointerDown: (event) => event.stopPropagation(),
3226
+ render: trigger ?? /* @__PURE__ */ jsx14(Button, {
3227
+ "aria-label": resolvedLabel,
3228
+ className: cn("size-8 shrink-0", className),
3229
+ size: "icon",
3230
+ variant: "ghost",
3231
+ children: /* @__PURE__ */ jsx14(MoreHorizontal, {})
3232
+ })
3233
+ }),
3234
+ /* @__PURE__ */ jsx14(DropdownMenuContent, {
3235
+ align: "end",
3236
+ className: "max-h-[min(18rem,var(--available-height))] w-72 max-w-[calc(100vw-2rem)]",
3237
+ onClick: (event) => event.stopPropagation(),
3238
+ onPointerDown: (event) => event.stopPropagation(),
3239
+ children: /* @__PURE__ */ jsxs8(DropdownMenuGroup, {
3240
+ children: [
3241
+ /* @__PURE__ */ jsx14(DropdownMenuLabel, {
3242
+ children: resolvedLabel
3243
+ }),
3244
+ /* @__PURE__ */ jsx14(DropdownMenuSeparator, {}),
3245
+ entries.map(({ item, visibleActions }, index) => visibleActions.length ? /* @__PURE__ */ jsxs8(DropdownMenuSub, {
3246
+ children: [
3247
+ /* @__PURE__ */ jsx14(DropdownMenuSubTrigger, {
3248
+ children: /* @__PURE__ */ jsx14(DataTableListEntry, {
3249
+ item,
3250
+ appearance: display === "icon" ? "detail" : "list"
3251
+ })
3252
+ }),
3253
+ /* @__PURE__ */ jsx14(DropdownMenuSubContent, {
3254
+ className: "w-max",
3255
+ children: visibleActions.map((action) => /* @__PURE__ */ jsxs8(DropdownMenuItem, {
3256
+ closeOnClick: action.closeOnClick,
3257
+ disabled: action.disabled?.(item),
3258
+ onClick: (event) => {
3259
+ event.stopPropagation();
3260
+ action.onClick(item);
3261
+ },
3262
+ variant: action.variant ?? "default",
3263
+ children: [
3264
+ action.icon,
3265
+ action.name
3266
+ ]
3267
+ }, action.id ?? action.name))
3268
+ })
3269
+ ]
3270
+ }, item.value ?? `${item.label}-${index}`) : /* @__PURE__ */ jsx14(DropdownMenuItem, {
3271
+ closeOnClick: Boolean(onItemClick),
3272
+ onClick: (event) => {
3273
+ event.stopPropagation();
3274
+ onItemClick?.(item);
3275
+ },
3276
+ children: /* @__PURE__ */ jsx14(DataTableListEntry, {
3277
+ item,
3278
+ appearance: display === "icon" ? "detail" : "list"
3279
+ })
3280
+ }, item.value ?? `${item.label}-${index}`)),
3281
+ onAdd && addOptions?.length ? /* @__PURE__ */ jsxs8(Fragment, {
3282
+ children: [
3283
+ entries.length ? /* @__PURE__ */ jsx14(DropdownMenuSeparator, {}) : null,
3284
+ /* @__PURE__ */ jsx14(DataTableListAddMenu, {
3285
+ emptyLabel: addEmptyLabel,
3286
+ label: addLabel ?? labels.addItem,
3287
+ locale,
3288
+ messages,
3289
+ onAdd,
3290
+ options: addOptions,
3291
+ searchLabel: addSearchLabel ?? labels.filter,
3292
+ display
3293
+ })
3294
+ ]
3295
+ }) : null
3296
+ ]
3297
+ })
3298
+ })
3299
+ ]
3300
+ });
3301
+ };
3302
+ var DataTableListAddMenu = ({
3303
+ emptyLabel,
3304
+ display,
3305
+ label,
3306
+ locale = "en",
3307
+ messages,
3308
+ onAdd,
3309
+ options,
3310
+ searchLabel
3311
+ }) => {
3312
+ const [search, setSearch] = useState("");
3313
+ const focusSearch = useCallback((input) => {
3314
+ input?.focus({ preventScroll: true });
3315
+ }, []);
3316
+ const labels = dataTableMessages(locale, messages);
3317
+ const normalizedSearch = search.trim().toLocaleLowerCase(locale);
3318
+ const filtered = normalizedSearch ? options.filter((item) => item.label.toLocaleLowerCase(locale).includes(normalizedSearch)) : options;
3319
+ return /* @__PURE__ */ jsxs8(DropdownMenuSub, {
3320
+ onOpenChange: (open) => {
3321
+ if (!open)
3322
+ setSearch("");
3323
+ },
3324
+ children: [
3325
+ /* @__PURE__ */ jsxs8(DropdownMenuSubTrigger, {
3326
+ children: [
3327
+ /* @__PURE__ */ jsx14(Plus, {}),
3328
+ label
3329
+ ]
3330
+ }),
3331
+ /* @__PURE__ */ jsxs8(DropdownMenuSubContent, {
3332
+ className: "w-64",
3333
+ children: [
3334
+ /* @__PURE__ */ jsxs8("div", {
3335
+ className: "relative p-1",
3336
+ children: [
3337
+ /* @__PURE__ */ jsx14(Search, {
3338
+ className: "text-muted-foreground pointer-events-none absolute top-1/2 left-3 size-4 -translate-y-1/2"
3339
+ }),
3340
+ /* @__PURE__ */ jsx14(Input, {
3341
+ "aria-label": searchLabel,
3342
+ className: "h-8 pl-8",
3343
+ onChange: (event) => setSearch(event.target.value),
3344
+ onKeyDown: (event) => {
3345
+ if (event.key !== "Escape")
3346
+ event.stopPropagation();
3347
+ },
3348
+ placeholder: labels.filter,
3349
+ ref: focusSearch,
3350
+ value: search
3351
+ })
3352
+ ]
3353
+ }),
3354
+ /* @__PURE__ */ jsx14(DropdownMenuSeparator, {}),
3355
+ filtered.length ? filtered.map((item) => /* @__PURE__ */ jsx14(DropdownMenuItem, {
3356
+ closeOnClick: false,
3357
+ onClick: () => onAdd(item),
3358
+ children: /* @__PURE__ */ jsx14(DataTableListEntry, {
3359
+ item,
3360
+ appearance: display === "icon" ? "detail" : "list"
3361
+ })
3362
+ }, item.value)) : /* @__PURE__ */ jsx14("div", {
3363
+ className: "text-muted-foreground px-2 py-1.5 text-sm",
3364
+ children: emptyLabel
3365
+ })
3366
+ ]
3367
+ })
3368
+ ]
3369
+ });
3370
+ };
3371
+ var DataTableListSummaryContent = ({
3372
+ emptyLabel,
3373
+ items,
3374
+ locale,
3375
+ messages,
3376
+ totalCount = items.length,
3377
+ display = "list",
3378
+ showMenu,
3379
+ visibleCount = 3
3380
+ }) => {
3381
+ const normalized = items.map((item) => Schema.is(Schema.String)(item) ? { label: item } : item);
3382
+ if (!normalized.length)
3383
+ return /* @__PURE__ */ jsx14("span", {
3384
+ className: "text-muted-foreground",
3385
+ children: emptyLabel
3386
+ });
3387
+ const visible = normalized.slice(0, Math.max(0, visibleCount));
3388
+ const remaining = Math.max(totalCount - visible.length, 0);
3389
+ if (display === "icon") {
3390
+ return /* @__PURE__ */ jsx14(TooltipProvider, {
3391
+ children: /* @__PURE__ */ jsxs8("span", {
3392
+ className: "flex items-center",
3393
+ children: [
3394
+ visible.map((item, index) => /* @__PURE__ */ jsx14(DataTableListEntry, {
3395
+ item,
3396
+ appearance: "icon"
3397
+ }, item.value ?? `${item.label}-${index}`)),
3398
+ remaining ? /* @__PURE__ */ jsxs8("span", {
3399
+ className: "bg-secondary text-secondary-foreground -ml-1 flex size-8 items-center justify-center rounded-full",
3400
+ children: [
3401
+ "+",
3402
+ remaining
3403
+ ]
3404
+ }) : null,
3405
+ remaining && showMenu ? /* @__PURE__ */ jsx14(DataTableListMenu, {
3406
+ actions: [],
3407
+ display,
3408
+ force: true,
3409
+ items: normalized,
3410
+ locale,
3411
+ messages
3412
+ }) : null
3413
+ ]
3414
+ })
3415
+ });
3416
+ }
3417
+ return /* @__PURE__ */ jsxs8("span", {
3418
+ className: "inline-flex min-w-0 items-center gap-2 text-sm",
3419
+ children: [
3420
+ /* @__PURE__ */ jsxs8("span", {
3421
+ className: "truncate",
3422
+ children: [
3423
+ visible.map((item) => item.label).join(", "),
3424
+ remaining ? ` +${remaining}` : ""
3425
+ ]
3426
+ }),
3427
+ remaining && showMenu ? /* @__PURE__ */ jsx14(DataTableListMenu, {
3428
+ actions: [],
3429
+ display,
3430
+ force: true,
3431
+ items: normalized,
3432
+ locale,
3433
+ messages
3434
+ }) : null
3435
+ ]
3436
+ });
3437
+ };
3438
+ var DataTableListSummary = (props) => /* @__PURE__ */ jsx14(DataTableListSummaryContent, {
3439
+ ...props,
3440
+ showMenu: true
3441
+ });
3442
+ var DataTableListEntry = ({
3443
+ item,
3444
+ appearance
3445
+ }) => {
3446
+ const icon = /* @__PURE__ */ jsx14("span", {
3447
+ "aria-hidden": "true",
3448
+ className: "bg-secondary text-secondary-foreground flex size-8 shrink-0 items-center justify-center overflow-hidden rounded-full",
3449
+ children: item.imageSrc ? /* @__PURE__ */ jsx14("img", {
3450
+ alt: "",
3451
+ src: item.imageSrc,
3452
+ className: "size-full object-cover"
3453
+ }) : item.icon ?? item.label.slice(0, 2).toUpperCase()
3454
+ });
3455
+ if (appearance === "list") {
3456
+ return /* @__PURE__ */ jsx14("span", {
3457
+ className: "min-w-0 flex-1 truncate",
3458
+ title: item.label,
3459
+ children: item.label
3460
+ });
3461
+ }
3462
+ return appearance === "icon" ? /* @__PURE__ */ jsxs8(Tooltip, {
3463
+ children: [
3464
+ /* @__PURE__ */ jsx14(TooltipTrigger, {
3465
+ render: /* @__PURE__ */ jsx14("span", {
3466
+ className: "-ml-1 inline-flex rounded-full",
3467
+ "aria-label": item.label
3468
+ }),
3469
+ children: icon
3470
+ }),
3471
+ /* @__PURE__ */ jsx14(TooltipContent, {
3472
+ children: item.label
3473
+ })
3474
+ ]
3475
+ }) : /* @__PURE__ */ jsxs8("span", {
3476
+ className: "flex min-w-0 flex-1 items-center gap-2 text-left",
3477
+ children: [
3478
+ icon,
3479
+ /* @__PURE__ */ jsx14("span", {
3480
+ className: "truncate",
3481
+ children: item.label
3482
+ })
3483
+ ]
3484
+ });
3485
+ };
3486
+
3487
+ // ../../src/services/events/client/audit-log-table.tsx
3488
+ import { useKrakstackLocale as useKrakstackLocale4 } from "@krak-stack/registry/krakstack-provider";
3489
+
3490
+ // ../../src/services/events/record.ts
3491
+ import { Option as Option2, Schema as Schema2 } from "effect";
3492
+ var TextValue = Schema2.Struct({ stringValue: Schema2.String }).annotate({
3493
+ identifier: "EventTextValue"
3494
+ });
3495
+ var TextArrayValue = Schema2.Struct({
3496
+ arrayValue: Schema2.Struct({ values: Schema2.Array(TextValue) })
3497
+ }).annotate({ identifier: "EventTextArrayValue" });
3498
+ var eventTextAttribute = (record, key) => Schema2.decodeUnknownOption(TextValue)(record.attributes.find((attribute) => attribute.key === key)?.value).pipe(Option2.map((value) => value.stringValue), Option2.getOrNull);
3499
+
3500
+ // ../../src/services/events/client/audit-log-table.tsx
3501
+ import { jsx as jsx15, jsxs as jsxs9 } from "react/jsx-runtime";
3502
+ var translations = {
3503
+ en: {
3504
+ title: "Audit log",
3505
+ time: "Time",
3506
+ action: "Action",
3507
+ target: "Target",
3508
+ actor: "Actor",
3509
+ method: "Method",
3510
+ actorMember: "Member",
3511
+ impersonatedBy: "Impersonated by",
3512
+ actorOrganization: "Organization",
3513
+ methodApiKey: "API Key",
3514
+ methodSession: "User session",
3515
+ methodUnknown: "Unknown"
3516
+ },
3517
+ fr: {
3518
+ title: "Journal d’audit",
3519
+ time: "Date",
3520
+ action: "Action",
3521
+ target: "Cible",
3522
+ actor: "Acteur",
3523
+ method: "Méthode",
3524
+ actorMember: "Membre",
3525
+ impersonatedBy: "Identité empruntée par",
3526
+ actorOrganization: "Organisation",
3527
+ methodApiKey: "Clé API",
3528
+ methodSession: "Session utilisateur",
3529
+ methodUnknown: "Inconnue"
3530
+ }
3531
+ };
3532
+ var AuditLogTable = ({
3533
+ entries,
3534
+ rowCount,
3535
+ locale: localeOverride,
3536
+ messages,
3537
+ actors = [],
3538
+ renderAction,
3539
+ state,
3540
+ onStateChange,
3541
+ ...status
3542
+ }) => {
3543
+ const locale = useKrakstackLocale4(localeOverride);
3544
+ const base = locale.split("-")[0];
3545
+ const labels = {
3546
+ ...translations.en,
3547
+ ...base === "fr" ? translations.fr : translations.en,
3548
+ ...messages?.[base],
3549
+ ...messages?.[locale]
3550
+ };
3551
+ const methods = new Map([
3552
+ ["session", labels.methodSession],
3553
+ ["api_key", labels.methodApiKey]
3554
+ ]);
3555
+ const actorsByKey = new Map(actors.map((actor) => [`${actor.type}:${actor.id}`, actor]));
3556
+ const getActor = (entry) => {
3557
+ const type = eventTextAttribute(entry, "app.actor.type");
3558
+ const id = eventTextAttribute(entry, "app.actor.id");
3559
+ const actor = actorsByKey.get(`${type}:${id}`);
3560
+ if (actor)
3561
+ return actor;
3562
+ if (type === "organization") {
3563
+ return { label: labels.actorOrganization, description: id };
3564
+ }
3565
+ if (type === "user") {
3566
+ return { label: labels.actorMember, description: id };
3567
+ }
3568
+ return { label: type ?? labels.actor, description: id };
3569
+ };
3570
+ const columns = [
3571
+ {
3572
+ colId: "time",
3573
+ headerName: labels.time,
3574
+ type: "dateTime",
3575
+ valueGetter: ({ data }) => new Date(Number(BigInt(data.timeUnixNano) / 1000000n))
3576
+ },
3577
+ {
3578
+ field: "eventName",
3579
+ headerName: labels.action,
3580
+ cellRenderer: ({ data }) => renderAction?.(data) ?? data.eventName
3581
+ },
3582
+ {
3583
+ colId: "record",
3584
+ headerName: labels.target,
3585
+ type: "reference",
3586
+ typeOptions: {
3587
+ imageVariant: "square",
3588
+ getItem: (entry) => {
3589
+ const id = eventTextAttribute(entry, "app.audit.target.id");
3590
+ const name = eventTextAttribute(entry, "app.audit.target.name");
3591
+ return id === null ? null : {
3592
+ label: name || id,
3593
+ description: name && name !== id ? id : null
3594
+ };
3595
+ }
3596
+ }
3597
+ },
3598
+ {
3599
+ colId: "actor",
3600
+ headerName: labels.actor,
3601
+ sortable: false,
3602
+ type: "reference",
3603
+ typeOptions: {
3604
+ getItem: getActor
3605
+ },
3606
+ cellRenderer: ({ data }) => {
3607
+ const impersonatorId = eventTextAttribute(data, "app.auth.impersonator.id");
3608
+ return /* @__PURE__ */ jsxs9("div", {
3609
+ className: "flex min-w-0 flex-col gap-1",
3610
+ children: [
3611
+ /* @__PURE__ */ jsx15(DataTableReferenceCell, {
3612
+ item: getActor(data)
3613
+ }),
3614
+ impersonatorId !== null ? /* @__PURE__ */ jsxs9("span", {
3615
+ className: "text-muted-foreground text-xs",
3616
+ children: [
3617
+ labels.impersonatedBy,
3618
+ ":",
3619
+ " ",
3620
+ actorsByKey.get(`user:${impersonatorId}`)?.label ?? impersonatorId
3621
+ ]
3622
+ }) : null
3623
+ ]
3624
+ });
3625
+ }
3626
+ },
3627
+ {
3628
+ colId: "method",
3629
+ headerName: labels.method,
3630
+ sortable: false,
3631
+ valueGetter: ({ data }) => {
3632
+ const method = eventTextAttribute(data, "app.auth.method");
3633
+ return method === null ? labels.methodUnknown : methods.get(method) ?? labels.methodUnknown;
3634
+ }
3635
+ }
3636
+ ];
3637
+ return /* @__PURE__ */ jsx15("section", {
3638
+ "aria-label": labels.title,
3639
+ children: /* @__PURE__ */ jsx15(DataTable, {
3640
+ locale,
3641
+ status,
3642
+ state,
3643
+ onStateChange,
3644
+ features: {
3645
+ pagination: { mode: "server", rowCount }
3646
+ },
3647
+ columnDefs: columns,
3648
+ rowData: entries,
3649
+ getRowId: (entry) => eventTextAttribute(entry, "log.record.uid") ?? `${entry.timeUnixNano}:${entry.eventName}`
3650
+ })
3651
+ });
3652
+ };
3653
+ export {
3654
+ AuditLogTable
3655
+ };