@krak-stack/registry 0.1.60 → 0.1.61

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,4698 @@
1
+ // ../../src/services/webhooks/client/delivery-table.tsx
2
+ import { useState as useState3 } from "react";
3
+ import { Check as Check3, Clock, FileJson as FileJson2, X as X2 } from "lucide-react";
4
+
5
+ // ../../src/components/ui/data-table.tsx
6
+ import { useAtom, useAtomSet } from "@effect/atom-react";
7
+ import { BrowserKeyValueStore } from "@effect/platform-browser";
8
+ import { DateTime as DateTime2, Effect as Effect2, Option as Option2, Schema as Schema2, Stream } from "effect";
9
+ import { Csv } from "effect/encoding";
10
+ import { AsyncResult, Atom } from "effect/reactivity";
11
+ import {
12
+ ArrowDown,
13
+ ArrowUp,
14
+ Check,
15
+ ChevronDown,
16
+ ChevronRight as ChevronRight2,
17
+ ChevronsUpDown,
18
+ Download,
19
+ EyeOff,
20
+ FileJson,
21
+ FileText,
22
+ GripVertical,
23
+ LayoutGrid,
24
+ ListFilter,
25
+ MoreHorizontal,
26
+ Plus,
27
+ RefreshCw,
28
+ Rows3,
29
+ Search,
30
+ Settings2,
31
+ Trash2,
32
+ X
33
+ } from "lucide-react";
34
+ import {
35
+ createContext,
36
+ isValidElement,
37
+ useCallback,
38
+ useContext,
39
+ useId as useId2,
40
+ useLayoutEffect,
41
+ useMemo as useMemo2,
42
+ useRef,
43
+ useState
44
+ } from "react";
45
+ import { createPortal } from "react-dom";
46
+
47
+ // ../../src/components/ui/badge.tsx
48
+ import { mergeProps } from "@base-ui/react/merge-props";
49
+ import { useRender } from "@base-ui/react/use-render";
50
+ import { cva } from "class-variance-authority";
51
+
52
+ // ../../src/lib/utils.ts
53
+ import { cn } from "cn";
54
+
55
+ // ../../src/components/ui/badge.tsx
56
+ 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!", {
57
+ variants: {
58
+ variant: {
59
+ default: "bg-primary text-primary-foreground [a]:hover:bg-primary/80",
60
+ secondary: "bg-secondary text-secondary-foreground [a]:hover:bg-secondary/80",
61
+ 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",
62
+ outline: "border-border text-foreground [a]:hover:bg-muted [a]:hover:text-muted-foreground",
63
+ ghost: "hover:bg-muted hover:text-muted-foreground dark:hover:bg-muted/50",
64
+ link: "text-primary underline-offset-4 hover:underline"
65
+ }
66
+ },
67
+ defaultVariants: {
68
+ variant: "default"
69
+ }
70
+ });
71
+ function Badge({
72
+ className,
73
+ variant = "default",
74
+ render,
75
+ ...props
76
+ }) {
77
+ return useRender({
78
+ defaultTagName: "span",
79
+ props: mergeProps({
80
+ className: cn(badgeVariants({ variant }), className)
81
+ }, props),
82
+ render,
83
+ state: {
84
+ slot: "badge",
85
+ variant
86
+ }
87
+ });
88
+ }
89
+
90
+ // ../../src/components/ui/button.tsx
91
+ import { Button as ButtonPrimitive } from "@base-ui/react/button";
92
+ import { cva as cva2 } from "class-variance-authority";
93
+ import { jsx } from "react/jsx-runtime";
94
+ 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", {
95
+ variants: {
96
+ variant: {
97
+ default: "bg-primary text-primary-foreground hover:bg-primary/80",
98
+ 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",
99
+ 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",
100
+ ghost: "hover:bg-muted hover:text-foreground aria-expanded:bg-muted aria-expanded:text-foreground dark:hover:bg-muted/50",
101
+ 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",
102
+ link: "text-primary underline-offset-4 hover:underline"
103
+ },
104
+ size: {
105
+ 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",
106
+ 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",
107
+ 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",
108
+ lg: "h-10 gap-1.5 px-2.5 has-data-[icon=inline-end]:pr-2 has-data-[icon=inline-start]:pl-2",
109
+ icon: "size-9",
110
+ "icon-xs": "size-6 rounded-[min(var(--radius-md),8px)] in-data-[slot=button-group]:rounded-md [&_svg:not([class*='size-'])]:size-3",
111
+ "icon-sm": "size-8 rounded-[min(var(--radius-md),10px)] in-data-[slot=button-group]:rounded-md",
112
+ "icon-lg": "size-10"
113
+ }
114
+ },
115
+ defaultVariants: {
116
+ variant: "default",
117
+ size: "default"
118
+ }
119
+ });
120
+ function Button({
121
+ className,
122
+ variant = "default",
123
+ size = "default",
124
+ ...props
125
+ }) {
126
+ return /* @__PURE__ */ jsx(ButtonPrimitive, {
127
+ "data-slot": "button",
128
+ className: cn(buttonVariants({ variant, size, className })),
129
+ ...props
130
+ });
131
+ }
132
+
133
+ // ../../src/components/ui/card.tsx
134
+ import { jsx as jsx2 } from "react/jsx-runtime";
135
+ function Card({
136
+ className,
137
+ size = "default",
138
+ ...props
139
+ }) {
140
+ return /* @__PURE__ */ jsx2("div", {
141
+ "data-slot": "card",
142
+ "data-size": size,
143
+ 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),
144
+ ...props
145
+ });
146
+ }
147
+ function CardHeader({ className, ...props }) {
148
+ return /* @__PURE__ */ jsx2("div", {
149
+ "data-slot": "card-header",
150
+ 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),
151
+ ...props
152
+ });
153
+ }
154
+ function CardTitle({ className, ...props }) {
155
+ return /* @__PURE__ */ jsx2("div", {
156
+ "data-slot": "card-title",
157
+ className: cn("text-base leading-normal font-medium group-data-[size=sm]/card:text-sm", className),
158
+ ...props
159
+ });
160
+ }
161
+
162
+ // ../../src/components/ui/checkbox.tsx
163
+ import { Checkbox as CheckboxPrimitive } from "@base-ui/react/checkbox";
164
+ import { CheckIcon } from "lucide-react";
165
+ import { jsx as jsx3 } from "react/jsx-runtime";
166
+ "use client";
167
+ function Checkbox({ className, ...props }) {
168
+ return /* @__PURE__ */ jsx3(CheckboxPrimitive.Root, {
169
+ "data-slot": "checkbox",
170
+ 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),
171
+ ...props,
172
+ children: /* @__PURE__ */ jsx3(CheckboxPrimitive.Indicator, {
173
+ "data-slot": "checkbox-indicator",
174
+ className: "grid place-content-center text-current transition-none [&>svg]:size-3.5",
175
+ children: /* @__PURE__ */ jsx3(CheckIcon, {})
176
+ })
177
+ });
178
+ }
179
+
180
+ // ../../src/components/ui/dropdown-menu.tsx
181
+ import { Menu as MenuPrimitive } from "@base-ui/react/menu";
182
+ import { ChevronRightIcon, CheckIcon as CheckIcon2 } from "lucide-react";
183
+ import { jsx as jsx4, jsxs } from "react/jsx-runtime";
184
+ function DropdownMenu({ ...props }) {
185
+ return /* @__PURE__ */ jsx4(MenuPrimitive.Root, {
186
+ "data-slot": "dropdown-menu",
187
+ ...props
188
+ });
189
+ }
190
+ function DropdownMenuTrigger({ ...props }) {
191
+ return /* @__PURE__ */ jsx4(MenuPrimitive.Trigger, {
192
+ "data-slot": "dropdown-menu-trigger",
193
+ ...props
194
+ });
195
+ }
196
+ function DropdownMenuContent({
197
+ align = "start",
198
+ alignOffset = 0,
199
+ side = "bottom",
200
+ sideOffset = 4,
201
+ className,
202
+ ...props
203
+ }) {
204
+ return /* @__PURE__ */ jsx4(MenuPrimitive.Portal, {
205
+ children: /* @__PURE__ */ jsx4(MenuPrimitive.Positioner, {
206
+ className: "isolate z-50 outline-none",
207
+ align,
208
+ alignOffset,
209
+ side,
210
+ sideOffset,
211
+ children: /* @__PURE__ */ jsx4(MenuPrimitive.Popup, {
212
+ "data-slot": "dropdown-menu-content",
213
+ 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),
214
+ ...props
215
+ })
216
+ })
217
+ });
218
+ }
219
+ function DropdownMenuGroup({ ...props }) {
220
+ return /* @__PURE__ */ jsx4(MenuPrimitive.Group, {
221
+ "data-slot": "dropdown-menu-group",
222
+ ...props
223
+ });
224
+ }
225
+ function DropdownMenuLabel({
226
+ className,
227
+ inset,
228
+ ...props
229
+ }) {
230
+ return /* @__PURE__ */ jsx4(MenuPrimitive.GroupLabel, {
231
+ "data-slot": "dropdown-menu-label",
232
+ "data-inset": inset,
233
+ className: cn("px-2 py-1.5 text-xs font-medium text-muted-foreground data-inset:pl-8", className),
234
+ ...props
235
+ });
236
+ }
237
+ function DropdownMenuItem({
238
+ className,
239
+ inset,
240
+ variant = "default",
241
+ ...props
242
+ }) {
243
+ return /* @__PURE__ */ jsx4(MenuPrimitive.Item, {
244
+ "data-slot": "dropdown-menu-item",
245
+ "data-inset": inset,
246
+ "data-variant": variant,
247
+ 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),
248
+ ...props
249
+ });
250
+ }
251
+ function DropdownMenuSub({ ...props }) {
252
+ return /* @__PURE__ */ jsx4(MenuPrimitive.SubmenuRoot, {
253
+ "data-slot": "dropdown-menu-sub",
254
+ ...props
255
+ });
256
+ }
257
+ function DropdownMenuSubTrigger({
258
+ className,
259
+ inset,
260
+ children,
261
+ ...props
262
+ }) {
263
+ return /* @__PURE__ */ jsxs(MenuPrimitive.SubmenuTrigger, {
264
+ "data-slot": "dropdown-menu-sub-trigger",
265
+ "data-inset": inset,
266
+ 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),
267
+ ...props,
268
+ children: [
269
+ children,
270
+ /* @__PURE__ */ jsx4(ChevronRightIcon, {
271
+ className: "ml-auto"
272
+ })
273
+ ]
274
+ });
275
+ }
276
+ function DropdownMenuSubContent({
277
+ align = "start",
278
+ alignOffset = -3,
279
+ side = "right",
280
+ sideOffset = 0,
281
+ className,
282
+ ...props
283
+ }) {
284
+ return /* @__PURE__ */ jsx4(DropdownMenuContent, {
285
+ "data-slot": "dropdown-menu-sub-content",
286
+ 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),
287
+ align,
288
+ alignOffset,
289
+ side,
290
+ sideOffset,
291
+ ...props
292
+ });
293
+ }
294
+ function DropdownMenuRadioGroup({ ...props }) {
295
+ return /* @__PURE__ */ jsx4(MenuPrimitive.RadioGroup, {
296
+ "data-slot": "dropdown-menu-radio-group",
297
+ ...props
298
+ });
299
+ }
300
+ function DropdownMenuSeparator({
301
+ className,
302
+ ...props
303
+ }) {
304
+ return /* @__PURE__ */ jsx4(MenuPrimitive.Separator, {
305
+ "data-slot": "dropdown-menu-separator",
306
+ className: cn("-mx-1 my-1 h-px bg-border", className),
307
+ ...props
308
+ });
309
+ }
310
+
311
+ // ../../src/components/ui/input.tsx
312
+ import { Input as InputPrimitive } from "@base-ui/react/input";
313
+ import { jsx as jsx5 } from "react/jsx-runtime";
314
+ function Input({ className, type, ...props }) {
315
+ return /* @__PURE__ */ jsx5(InputPrimitive, {
316
+ type,
317
+ "data-slot": "input",
318
+ 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),
319
+ ...props
320
+ });
321
+ }
322
+
323
+ // ../../src/components/ui/field.tsx
324
+ import { useMemo } from "react";
325
+ import { cva as cva3 } from "class-variance-authority";
326
+
327
+ // ../../src/components/ui/label.tsx
328
+ import { jsx as jsx6 } from "react/jsx-runtime";
329
+ "use client";
330
+ function Label({ className, ...props }) {
331
+ return /* @__PURE__ */ jsx6("label", {
332
+ "data-slot": "label",
333
+ 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),
334
+ ...props
335
+ });
336
+ }
337
+
338
+ // ../../src/components/ui/separator.tsx
339
+ import { Separator as SeparatorPrimitive } from "@base-ui/react/separator";
340
+
341
+ // ../../src/components/ui/field.tsx
342
+ import { jsx as jsx7, jsxs as jsxs2 } from "react/jsx-runtime";
343
+ function FieldGroup({ className, ...props }) {
344
+ return /* @__PURE__ */ jsx7("div", {
345
+ "data-slot": "field-group",
346
+ className: cn("group/field-group @container/field-group flex w-full flex-col gap-7 data-[slot=checkbox-group]:gap-3 *:data-[slot=field-group]:gap-4", className),
347
+ ...props
348
+ });
349
+ }
350
+ var fieldVariants = cva3("group/field flex w-full gap-3 data-[invalid=true]:text-destructive", {
351
+ variants: {
352
+ orientation: {
353
+ vertical: "flex-col *:w-full [&>.sr-only]:w-auto",
354
+ horizontal: "flex-row items-center has-[>[data-slot=field-content]]:items-start *:data-[slot=field-label]:flex-auto has-[>[data-slot=field-content]]:[&>[role=checkbox],[role=radio]]:mt-px",
355
+ responsive: "flex-col *:w-full @md/field-group:flex-row @md/field-group:items-center @md/field-group:*:w-auto @md/field-group:has-[>[data-slot=field-content]]:items-start @md/field-group:*:data-[slot=field-label]:flex-auto [&>.sr-only]:w-auto @md/field-group:has-[>[data-slot=field-content]]:[&>[role=checkbox],[role=radio]]:mt-px"
356
+ }
357
+ },
358
+ defaultVariants: {
359
+ orientation: "vertical"
360
+ }
361
+ });
362
+ function Field({
363
+ className,
364
+ orientation = "vertical",
365
+ ...props
366
+ }) {
367
+ return /* @__PURE__ */ jsx7("div", {
368
+ role: "group",
369
+ "data-slot": "field",
370
+ "data-orientation": orientation,
371
+ className: cn(fieldVariants({ orientation }), className),
372
+ ...props
373
+ });
374
+ }
375
+ function FieldLabel({
376
+ className,
377
+ ...props
378
+ }) {
379
+ return /* @__PURE__ */ jsx7(Label, {
380
+ "data-slot": "field-label",
381
+ className: cn("group/field-label peer/field-label flex w-fit gap-2 leading-snug group-data-[disabled=true]/field:opacity-50 has-data-checked:border-primary/30 has-data-checked:bg-primary/5 has-[>[data-slot=field]]:rounded-md has-[>[data-slot=field]]:border *:data-[slot=field]:p-3 dark:has-data-checked:border-primary/20 dark:has-data-checked:bg-primary/10", "has-[>[data-slot=field]]:w-full has-[>[data-slot=field]]:flex-col", className),
382
+ ...props
383
+ });
384
+ }
385
+
386
+ // ../../src/components/ui/select.tsx
387
+ import { Select as SelectPrimitive } from "@base-ui/react/select";
388
+ import { ChevronDownIcon, CheckIcon as CheckIcon3, ChevronUpIcon } from "lucide-react";
389
+ import { jsx as jsx8, jsxs as jsxs3 } from "react/jsx-runtime";
390
+ "use client";
391
+ var Select = SelectPrimitive.Root;
392
+ function SelectGroup({ className, ...props }) {
393
+ return /* @__PURE__ */ jsx8(SelectPrimitive.Group, {
394
+ "data-slot": "select-group",
395
+ className: cn("scroll-my-1 p-1", className),
396
+ ...props
397
+ });
398
+ }
399
+ function SelectValue({ className, ...props }) {
400
+ return /* @__PURE__ */ jsx8(SelectPrimitive.Value, {
401
+ "data-slot": "select-value",
402
+ className: cn("flex flex-1 text-left", className),
403
+ ...props
404
+ });
405
+ }
406
+ function SelectTrigger({
407
+ className,
408
+ size = "default",
409
+ children,
410
+ ...props
411
+ }) {
412
+ return /* @__PURE__ */ jsxs3(SelectPrimitive.Trigger, {
413
+ "data-slot": "select-trigger",
414
+ "data-size": size,
415
+ 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),
416
+ ...props,
417
+ children: [
418
+ children,
419
+ /* @__PURE__ */ jsx8(SelectPrimitive.Icon, {
420
+ render: /* @__PURE__ */ jsx8(ChevronDownIcon, {
421
+ className: "text-muted-foreground pointer-events-none size-4"
422
+ })
423
+ })
424
+ ]
425
+ });
426
+ }
427
+ function SelectContent({
428
+ className,
429
+ children,
430
+ side = "bottom",
431
+ sideOffset = 4,
432
+ align = "center",
433
+ alignOffset = 0,
434
+ alignItemWithTrigger = true,
435
+ ...props
436
+ }) {
437
+ return /* @__PURE__ */ jsx8(SelectPrimitive.Portal, {
438
+ children: /* @__PURE__ */ jsx8(SelectPrimitive.Positioner, {
439
+ side,
440
+ sideOffset,
441
+ align,
442
+ alignOffset,
443
+ alignItemWithTrigger,
444
+ className: "isolate z-50",
445
+ children: /* @__PURE__ */ jsxs3(SelectPrimitive.Popup, {
446
+ "data-slot": "select-content",
447
+ "data-align-trigger": alignItemWithTrigger,
448
+ 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),
449
+ ...props,
450
+ children: [
451
+ /* @__PURE__ */ jsx8(SelectScrollUpButton, {}),
452
+ /* @__PURE__ */ jsx8(SelectPrimitive.List, {
453
+ children
454
+ }),
455
+ /* @__PURE__ */ jsx8(SelectScrollDownButton, {})
456
+ ]
457
+ })
458
+ })
459
+ });
460
+ }
461
+ function SelectItem({
462
+ className,
463
+ children,
464
+ ...props
465
+ }) {
466
+ return /* @__PURE__ */ jsxs3(SelectPrimitive.Item, {
467
+ "data-slot": "select-item",
468
+ 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),
469
+ ...props,
470
+ children: [
471
+ /* @__PURE__ */ jsx8(SelectPrimitive.ItemText, {
472
+ className: "flex flex-1 shrink-0 gap-2 whitespace-nowrap",
473
+ children
474
+ }),
475
+ /* @__PURE__ */ jsx8(SelectPrimitive.ItemIndicator, {
476
+ render: /* @__PURE__ */ jsx8("span", {
477
+ className: "pointer-events-none absolute right-2 flex size-4 items-center justify-center"
478
+ }),
479
+ children: /* @__PURE__ */ jsx8(CheckIcon3, {
480
+ className: "pointer-events-none"
481
+ })
482
+ })
483
+ ]
484
+ });
485
+ }
486
+ function SelectScrollUpButton({
487
+ className,
488
+ ...props
489
+ }) {
490
+ return /* @__PURE__ */ jsx8(SelectPrimitive.ScrollUpArrow, {
491
+ "data-slot": "select-scroll-up-button",
492
+ 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),
493
+ ...props,
494
+ children: /* @__PURE__ */ jsx8(ChevronUpIcon, {})
495
+ });
496
+ }
497
+ function SelectScrollDownButton({
498
+ className,
499
+ ...props
500
+ }) {
501
+ return /* @__PURE__ */ jsx8(SelectPrimitive.ScrollDownArrow, {
502
+ "data-slot": "select-scroll-down-button",
503
+ 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),
504
+ ...props,
505
+ children: /* @__PURE__ */ jsx8(ChevronDownIcon, {})
506
+ });
507
+ }
508
+
509
+ // ../../src/components/ui/loading.tsx
510
+ import { Loader2 } from "lucide-react";
511
+ import { useKrakstackLocale } from "@krak-stack/registry/krakstack-provider";
512
+ import { jsx as jsx9, jsxs as jsxs4 } from "react/jsx-runtime";
513
+ var labels = {
514
+ en: {
515
+ loading: "Loading..."
516
+ },
517
+ fr: {
518
+ loading: "Chargement..."
519
+ }
520
+ };
521
+ var loadingLabel = (locale, messages) => messages?.[locale]?.loading ?? messages?.[locale.split("-")[0] ?? locale]?.loading ?? (locale.startsWith("fr") ? labels.fr.loading : labels.en.loading);
522
+ function Loading({
523
+ className,
524
+ label,
525
+ locale: localeOverride,
526
+ messages,
527
+ variant = "inline"
528
+ }) {
529
+ const locale = useKrakstackLocale(localeOverride);
530
+ return /* @__PURE__ */ jsxs4("div", {
531
+ className: cn("text-muted-foreground flex items-center justify-center gap-2 text-sm", variant === "centered" && "min-h-[50svh] w-full", className),
532
+ children: [
533
+ /* @__PURE__ */ jsx9(Loader2, {
534
+ className: "size-4 animate-spin"
535
+ }),
536
+ label ?? loadingLabel(locale, messages)
537
+ ]
538
+ });
539
+ }
540
+
541
+ // ../../src/components/ui/menubar.tsx
542
+ import { Menu as MenuPrimitive2 } from "@base-ui/react/menu";
543
+ import { Menubar as MenubarPrimitive } from "@base-ui/react/menubar";
544
+ import { CheckIcon as CheckIcon4 } from "lucide-react";
545
+ import { jsx as jsx10, jsxs as jsxs5 } from "react/jsx-runtime";
546
+ "use client";
547
+ function Menubar({ className, ...props }) {
548
+ return /* @__PURE__ */ jsx10(MenubarPrimitive, {
549
+ "data-slot": "menubar",
550
+ className: cn("flex h-9 items-center gap-1 rounded-md border p-1 shadow-xs", className),
551
+ ...props
552
+ });
553
+ }
554
+ function MenubarMenu({ ...props }) {
555
+ return /* @__PURE__ */ jsx10(DropdownMenu, {
556
+ "data-slot": "menubar-menu",
557
+ ...props
558
+ });
559
+ }
560
+ function MenubarGroup({
561
+ ...props
562
+ }) {
563
+ return /* @__PURE__ */ jsx10(DropdownMenuGroup, {
564
+ "data-slot": "menubar-group",
565
+ ...props
566
+ });
567
+ }
568
+ function MenubarTrigger({
569
+ className,
570
+ ...props
571
+ }) {
572
+ return /* @__PURE__ */ jsx10(DropdownMenuTrigger, {
573
+ "data-slot": "menubar-trigger",
574
+ 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),
575
+ ...props
576
+ });
577
+ }
578
+ function MenubarContent({
579
+ className,
580
+ align = "start",
581
+ alignOffset = -4,
582
+ sideOffset = 8,
583
+ ...props
584
+ }) {
585
+ return /* @__PURE__ */ jsx10(DropdownMenuContent, {
586
+ "data-slot": "menubar-content",
587
+ align,
588
+ alignOffset,
589
+ sideOffset,
590
+ 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),
591
+ ...props
592
+ });
593
+ }
594
+ function MenubarItem({
595
+ className,
596
+ inset,
597
+ variant = "default",
598
+ ...props
599
+ }) {
600
+ return /* @__PURE__ */ jsx10(DropdownMenuItem, {
601
+ "data-slot": "menubar-item",
602
+ "data-inset": inset,
603
+ "data-variant": variant,
604
+ 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),
605
+ ...props
606
+ });
607
+ }
608
+ function MenubarCheckboxItem({
609
+ className,
610
+ children,
611
+ checked,
612
+ inset,
613
+ ...props
614
+ }) {
615
+ return /* @__PURE__ */ jsxs5(MenuPrimitive2.CheckboxItem, {
616
+ "data-slot": "menubar-checkbox-item",
617
+ "data-inset": inset,
618
+ 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),
619
+ checked,
620
+ ...props,
621
+ children: [
622
+ /* @__PURE__ */ jsx10("span", {
623
+ className: "pointer-events-none absolute left-2 flex size-4 items-center justify-center [&_svg:not([class*='size-'])]:size-4",
624
+ children: /* @__PURE__ */ jsx10(MenuPrimitive2.CheckboxItemIndicator, {
625
+ children: /* @__PURE__ */ jsx10(CheckIcon4, {})
626
+ })
627
+ }),
628
+ children
629
+ ]
630
+ });
631
+ }
632
+ function MenubarRadioGroup({
633
+ ...props
634
+ }) {
635
+ return /* @__PURE__ */ jsx10(DropdownMenuRadioGroup, {
636
+ "data-slot": "menubar-radio-group",
637
+ ...props
638
+ });
639
+ }
640
+ function MenubarRadioItem({
641
+ className,
642
+ children,
643
+ inset,
644
+ ...props
645
+ }) {
646
+ return /* @__PURE__ */ jsxs5(MenuPrimitive2.RadioItem, {
647
+ "data-slot": "menubar-radio-item",
648
+ "data-inset": inset,
649
+ 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),
650
+ ...props,
651
+ children: [
652
+ /* @__PURE__ */ jsx10("span", {
653
+ className: "pointer-events-none absolute left-2 flex size-4 items-center justify-center [&_svg:not([class*='size-'])]:size-4",
654
+ children: /* @__PURE__ */ jsx10(MenuPrimitive2.RadioItemIndicator, {
655
+ children: /* @__PURE__ */ jsx10(CheckIcon4, {})
656
+ })
657
+ }),
658
+ children
659
+ ]
660
+ });
661
+ }
662
+ function MenubarLabel({
663
+ className,
664
+ inset,
665
+ ...props
666
+ }) {
667
+ return /* @__PURE__ */ jsx10(DropdownMenuLabel, {
668
+ "data-slot": "menubar-label",
669
+ "data-inset": inset,
670
+ className: cn("px-2 py-1.5 text-sm font-medium data-inset:pl-8", className),
671
+ ...props
672
+ });
673
+ }
674
+ function MenubarSeparator({
675
+ className,
676
+ ...props
677
+ }) {
678
+ return /* @__PURE__ */ jsx10(DropdownMenuSeparator, {
679
+ "data-slot": "menubar-separator",
680
+ className: cn("-mx-1 my-1 h-px bg-border", className),
681
+ ...props
682
+ });
683
+ }
684
+ function MenubarSub({
685
+ ...props
686
+ }) {
687
+ return /* @__PURE__ */ jsx10(DropdownMenuSub, {
688
+ "data-slot": "menubar-sub",
689
+ ...props
690
+ });
691
+ }
692
+ function MenubarSubTrigger({
693
+ className,
694
+ inset,
695
+ ...props
696
+ }) {
697
+ return /* @__PURE__ */ jsx10(DropdownMenuSubTrigger, {
698
+ "data-slot": "menubar-sub-trigger",
699
+ "data-inset": inset,
700
+ 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),
701
+ ...props
702
+ });
703
+ }
704
+ function MenubarSubContent({
705
+ className,
706
+ ...props
707
+ }) {
708
+ return /* @__PURE__ */ jsx10(DropdownMenuSubContent, {
709
+ "data-slot": "menubar-sub-content",
710
+ 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),
711
+ ...props
712
+ });
713
+ }
714
+
715
+ // ../../src/components/ui/pagination.tsx
716
+ import {
717
+ ChevronLeft,
718
+ ChevronRight,
719
+ ChevronsLeft,
720
+ ChevronsRight
721
+ } from "lucide-react";
722
+ import { useId } from "react";
723
+ import { useKrakstackLocale as useKrakstackLocale2 } from "@krak-stack/registry/krakstack-provider";
724
+ import { jsx as jsx11, jsxs as jsxs6 } from "react/jsx-runtime";
725
+ var messages = {
726
+ en: {
727
+ pageSize: "Page size",
728
+ results: (count) => `${count} results`,
729
+ selectedOf: (selected, total) => `${selected} of ${total}`,
730
+ pageOf: (page, total) => `Page ${page} of ${total}`,
731
+ goToFirstPage: "Go to first page",
732
+ goToPreviousPage: "Go to previous page",
733
+ goToNextPage: "Go to next page",
734
+ goToLastPage: "Go to last page"
735
+ },
736
+ fr: {
737
+ pageSize: "Taille de la page",
738
+ results: (count) => `${count} résultats`,
739
+ selectedOf: (selected, total) => `${selected} sur ${total}`,
740
+ pageOf: (page, total) => `Page ${page} sur ${total}`,
741
+ goToFirstPage: "Aller à la première page",
742
+ goToPreviousPage: "Aller à la page précédente",
743
+ goToNextPage: "Aller à la page suivante",
744
+ goToLastPage: "Aller à la dernière page"
745
+ }
746
+ };
747
+ var paginationMessages = (locale = "en", translations) => ({
748
+ ...locale.startsWith("fr") ? messages.fr : messages.en,
749
+ ...translations?.[locale.split("-")[0] ?? locale],
750
+ ...translations?.[locale]
751
+ });
752
+ function Pagination({
753
+ compact = false,
754
+ locale: localeOverride,
755
+ messages: messageOverrides,
756
+ onPageChange,
757
+ onPageSizeChange,
758
+ page,
759
+ pageCount,
760
+ pageSize,
761
+ pageSizes = [10, 20, 30, 40, 50],
762
+ selectedRows = 0,
763
+ showResults = true,
764
+ totalRows
765
+ }) {
766
+ const locale = useKrakstackLocale2(localeOverride);
767
+ const labels = paginationMessages(locale, messageOverrides);
768
+ const pageSizeId = useId();
769
+ const canGoBack = page > 0;
770
+ const canGoForward = page + 1 < pageCount;
771
+ return /* @__PURE__ */ jsxs6("div", {
772
+ 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"),
773
+ children: [
774
+ showResults ? /* @__PURE__ */ jsxs6("div", {
775
+ className: "text-muted-foreground flex flex-wrap items-center gap-x-3 gap-y-1 text-sm",
776
+ children: [
777
+ /* @__PURE__ */ jsx11("span", {
778
+ children: labels.results(totalRows)
779
+ }),
780
+ selectedRows > 0 ? /* @__PURE__ */ jsx11("span", {
781
+ children: labels.selectedOf(selectedRows, totalRows)
782
+ }) : null
783
+ ]
784
+ }) : null,
785
+ /* @__PURE__ */ jsxs6("div", {
786
+ className: cn("flex items-center gap-4 sm:justify-end", compact && "flex-wrap justify-between gap-2 sm:justify-between"),
787
+ children: [
788
+ /* @__PURE__ */ jsxs6("div", {
789
+ className: "flex items-center gap-2",
790
+ children: [
791
+ /* @__PURE__ */ jsx11(Label, {
792
+ htmlFor: pageSizeId,
793
+ className: cn("hidden text-sm sm:block", compact && "block"),
794
+ children: labels.pageSize
795
+ }),
796
+ /* @__PURE__ */ jsxs6(Select, {
797
+ items: pageSizes.map((size) => ({
798
+ label: size.toString(),
799
+ value: size.toString()
800
+ })),
801
+ value: `${pageSize}`,
802
+ onValueChange: (value) => onPageSizeChange(Number(value)),
803
+ children: [
804
+ /* @__PURE__ */ jsx11(SelectTrigger, {
805
+ className: "h-8 w-[70px]",
806
+ id: pageSizeId,
807
+ children: /* @__PURE__ */ jsx11(SelectValue, {
808
+ placeholder: pageSize
809
+ })
810
+ }),
811
+ /* @__PURE__ */ jsx11(SelectContent, {
812
+ side: "top",
813
+ children: pageSizes.map((size) => /* @__PURE__ */ jsx11(SelectItem, {
814
+ value: `${size}`,
815
+ children: size
816
+ }, size))
817
+ })
818
+ ]
819
+ })
820
+ ]
821
+ }),
822
+ /* @__PURE__ */ jsxs6("div", {
823
+ className: "flex items-center gap-2",
824
+ children: [
825
+ /* @__PURE__ */ jsx11("div", {
826
+ className: "flex items-center justify-center text-sm font-medium sm:block",
827
+ children: labels.pageOf(page + 1, pageCount)
828
+ }),
829
+ /* @__PURE__ */ jsxs6("div", {
830
+ className: "flex items-center gap-1",
831
+ children: [
832
+ /* @__PURE__ */ jsxs6(Button, {
833
+ className: cn("hidden h-8 w-8 p-0 lg:flex", compact && "!hidden"),
834
+ disabled: !canGoBack,
835
+ onClick: () => onPageChange(0),
836
+ type: "button",
837
+ children: [
838
+ /* @__PURE__ */ jsx11("span", {
839
+ className: "sr-only",
840
+ children: labels.goToFirstPage
841
+ }),
842
+ /* @__PURE__ */ jsx11(ChevronsLeft, {})
843
+ ]
844
+ }),
845
+ /* @__PURE__ */ jsxs6(Button, {
846
+ className: "h-8 w-8 p-0",
847
+ disabled: !canGoBack,
848
+ onClick: () => onPageChange(page - 1),
849
+ type: "button",
850
+ children: [
851
+ /* @__PURE__ */ jsx11("span", {
852
+ className: "sr-only",
853
+ children: labels.goToPreviousPage
854
+ }),
855
+ /* @__PURE__ */ jsx11(ChevronLeft, {})
856
+ ]
857
+ }),
858
+ /* @__PURE__ */ jsxs6(Button, {
859
+ className: "h-8 w-8 p-0",
860
+ disabled: !canGoForward,
861
+ onClick: () => onPageChange(page + 1),
862
+ type: "button",
863
+ children: [
864
+ /* @__PURE__ */ jsx11("span", {
865
+ className: "sr-only",
866
+ children: labels.goToNextPage
867
+ }),
868
+ /* @__PURE__ */ jsx11(ChevronRight, {})
869
+ ]
870
+ }),
871
+ /* @__PURE__ */ jsxs6(Button, {
872
+ className: cn("hidden h-8 w-8 p-0 lg:flex", compact && "!hidden"),
873
+ disabled: !canGoForward,
874
+ onClick: () => onPageChange(pageCount - 1),
875
+ type: "button",
876
+ children: [
877
+ /* @__PURE__ */ jsx11("span", {
878
+ className: "sr-only",
879
+ children: labels.goToLastPage
880
+ }),
881
+ /* @__PURE__ */ jsx11(ChevronsRight, {})
882
+ ]
883
+ })
884
+ ]
885
+ })
886
+ ]
887
+ })
888
+ ]
889
+ })
890
+ ]
891
+ });
892
+ }
893
+
894
+ // ../../src/components/ui/scroll-area.tsx
895
+ import { ScrollArea as ScrollAreaPrimitive } from "@base-ui/react/scroll-area";
896
+ import { jsx as jsx12, jsxs as jsxs7 } from "react/jsx-runtime";
897
+ function ScrollArea({
898
+ className,
899
+ children,
900
+ ...props
901
+ }) {
902
+ return /* @__PURE__ */ jsxs7(ScrollAreaPrimitive.Root, {
903
+ "data-slot": "scroll-area",
904
+ className: cn("relative", className),
905
+ ...props,
906
+ children: [
907
+ /* @__PURE__ */ jsx12(ScrollAreaPrimitive.Viewport, {
908
+ "data-slot": "scroll-area-viewport",
909
+ className: "focus-visible:ring-ring/50 size-full rounded-[inherit] transition-[color,box-shadow] outline-none focus-visible:ring-[3px] focus-visible:outline-1",
910
+ children
911
+ }),
912
+ /* @__PURE__ */ jsx12(ScrollBar, {}),
913
+ /* @__PURE__ */ jsx12(ScrollAreaPrimitive.Corner, {})
914
+ ]
915
+ });
916
+ }
917
+ function ScrollBar({
918
+ className,
919
+ orientation = "vertical",
920
+ ...props
921
+ }) {
922
+ return /* @__PURE__ */ jsx12(ScrollAreaPrimitive.Scrollbar, {
923
+ "data-slot": "scroll-area-scrollbar",
924
+ "data-orientation": orientation,
925
+ orientation,
926
+ 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),
927
+ ...props,
928
+ children: /* @__PURE__ */ jsx12(ScrollAreaPrimitive.Thumb, {
929
+ "data-slot": "scroll-area-thumb",
930
+ className: "bg-border relative flex-1 rounded-full"
931
+ })
932
+ });
933
+ }
934
+
935
+ // ../../src/components/ui/table.tsx
936
+ import { jsx as jsx13 } from "react/jsx-runtime";
937
+ function Table({ className, ...props }) {
938
+ return /* @__PURE__ */ jsx13("div", {
939
+ "data-slot": "table-container",
940
+ className: "relative w-full overflow-x-auto",
941
+ children: /* @__PURE__ */ jsx13("table", {
942
+ "data-slot": "table",
943
+ className: cn("w-full caption-bottom text-sm", className),
944
+ ...props
945
+ })
946
+ });
947
+ }
948
+ function TableHeader({ className, ...props }) {
949
+ return /* @__PURE__ */ jsx13("thead", {
950
+ "data-slot": "table-header",
951
+ className: cn("[&_tr]:border-b", className),
952
+ ...props
953
+ });
954
+ }
955
+ function TableBody({ className, ...props }) {
956
+ return /* @__PURE__ */ jsx13("tbody", {
957
+ "data-slot": "table-body",
958
+ className: cn("[&_tr:last-child]:border-0", className),
959
+ ...props
960
+ });
961
+ }
962
+ function TableRow({ className, ...props }) {
963
+ return /* @__PURE__ */ jsx13("tr", {
964
+ "data-slot": "table-row",
965
+ className: cn("border-b transition-colors hover:bg-muted/50 has-aria-expanded:bg-muted/50 data-[state=selected]:bg-muted", className),
966
+ ...props
967
+ });
968
+ }
969
+ function TableHead({ className, ...props }) {
970
+ return /* @__PURE__ */ jsx13("th", {
971
+ "data-slot": "table-head",
972
+ className: cn("h-10 px-2 text-left align-middle font-medium whitespace-nowrap text-foreground [&:has([role=checkbox])]:pr-0", className),
973
+ ...props
974
+ });
975
+ }
976
+ function TableCell({ className, ...props }) {
977
+ return /* @__PURE__ */ jsx13("td", {
978
+ "data-slot": "table-cell",
979
+ className: cn("p-2 align-middle whitespace-nowrap [&:has([role=checkbox])]:pr-0", className),
980
+ ...props
981
+ });
982
+ }
983
+
984
+ // ../../src/components/ui/tooltip.tsx
985
+ import { Tooltip as TooltipPrimitive } from "@base-ui/react/tooltip";
986
+ import { jsx as jsx14, jsxs as jsxs8 } from "react/jsx-runtime";
987
+ "use client";
988
+ function TooltipProvider({
989
+ delay = 0,
990
+ ...props
991
+ }) {
992
+ return /* @__PURE__ */ jsx14(TooltipPrimitive.Provider, {
993
+ "data-slot": "tooltip-provider",
994
+ delay,
995
+ ...props
996
+ });
997
+ }
998
+ function Tooltip({ ...props }) {
999
+ return /* @__PURE__ */ jsx14(TooltipPrimitive.Root, {
1000
+ "data-slot": "tooltip",
1001
+ ...props
1002
+ });
1003
+ }
1004
+ function TooltipTrigger({ ...props }) {
1005
+ return /* @__PURE__ */ jsx14(TooltipPrimitive.Trigger, {
1006
+ "data-slot": "tooltip-trigger",
1007
+ ...props
1008
+ });
1009
+ }
1010
+ function TooltipContent({
1011
+ className,
1012
+ side = "top",
1013
+ sideOffset = 4,
1014
+ align = "center",
1015
+ alignOffset = 0,
1016
+ children,
1017
+ ...props
1018
+ }) {
1019
+ return /* @__PURE__ */ jsx14(TooltipPrimitive.Portal, {
1020
+ children: /* @__PURE__ */ jsx14(TooltipPrimitive.Positioner, {
1021
+ align,
1022
+ alignOffset,
1023
+ side,
1024
+ sideOffset,
1025
+ className: "isolate z-50",
1026
+ children: /* @__PURE__ */ jsxs8(TooltipPrimitive.Popup, {
1027
+ "data-slot": "tooltip-content",
1028
+ 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),
1029
+ ...props,
1030
+ children: [
1031
+ children,
1032
+ /* @__PURE__ */ jsx14(TooltipPrimitive.Arrow, {
1033
+ 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"
1034
+ })
1035
+ ]
1036
+ })
1037
+ })
1038
+ });
1039
+ }
1040
+
1041
+ // ../../src/lib/query.ts
1042
+ import {
1043
+ DateTime,
1044
+ Effect,
1045
+ Option,
1046
+ Schema,
1047
+ SchemaGetter,
1048
+ SchemaIssue,
1049
+ SchemaTransformation
1050
+ } from "effect";
1051
+ var parseSortParam = (sort) => {
1052
+ const id = sort.startsWith("-") ? sort.slice(1) : sort;
1053
+ if (!id || id.includes(",") || id.includes(":")) {
1054
+ return null;
1055
+ }
1056
+ return { id, direction: sort.startsWith("-") ? "desc" : "asc" };
1057
+ };
1058
+ var SortDirection = Schema.Union([
1059
+ Schema.Literal("asc"),
1060
+ Schema.Literal("desc")
1061
+ ]).pipe(Schema.annotate({
1062
+ identifier: "SortDirection",
1063
+ title: "Sort Direction",
1064
+ description: "Sort direction for list query results.",
1065
+ examples: ["asc", "desc"]
1066
+ }));
1067
+ var SortParam = Schema.Struct({
1068
+ id: Schema.NonEmptyString,
1069
+ direction: SortDirection
1070
+ }).pipe(Schema.annotate({
1071
+ identifier: "SortParam",
1072
+ title: "Sort Parameter",
1073
+ description: "Decoded sort parameter with a field id and direction.",
1074
+ examples: [{ id: "publicName", direction: "asc" }]
1075
+ }));
1076
+ var SortParamFromString = Schema.String.pipe(Schema.decodeTo(SortParam, SchemaTransformation.transformEffect({
1077
+ decode: (sort) => {
1078
+ const sortParam = parseSortParam(sort);
1079
+ if (!sortParam) {
1080
+ return Effect.fail(new SchemaIssue.InvalidValue({ message: 'Expected sort in the format "field" or "-field"' }, sort));
1081
+ }
1082
+ return Effect.succeed(sortParam);
1083
+ },
1084
+ encode: (sort) => Effect.succeed(sort.direction === "desc" ? `-${sort.id}` : sort.id)
1085
+ })), Schema.annotate({
1086
+ identifier: "SortParamFromString",
1087
+ title: "Sort Parameter From String",
1088
+ description: 'URL encoded single sort parameter where descending fields are prefixed with "-".',
1089
+ examples: [{ id: "publicName", direction: "asc" }]
1090
+ }));
1091
+ var SortParamsFromString = Schema.String.pipe(Schema.decodeTo(Schema.Array(SortParam), SchemaTransformation.transformEffect({
1092
+ decode: (sort) => {
1093
+ if (sort === "")
1094
+ return Effect.succeed([]);
1095
+ const parts = sort.split(",");
1096
+ const sortParams = [];
1097
+ for (const part of parts) {
1098
+ const sortParam = parseSortParam(part);
1099
+ if (!sortParam) {
1100
+ return Effect.fail(new SchemaIssue.InvalidValue({ message: 'Expected sort in the format "field,-otherField"' }, sort));
1101
+ }
1102
+ sortParams.push(sortParam);
1103
+ }
1104
+ return Effect.succeed(sortParams);
1105
+ },
1106
+ encode: (sort) => Effect.succeed(sort.map((part) => Schema.encodeSync(SortParamFromString)(part)).join(","))
1107
+ })), Schema.annotate({
1108
+ identifier: "SortParamsFromString",
1109
+ title: "Sort Parameters From String",
1110
+ description: 'URL encoded sort parameters where descending fields are prefixed with "-" and multiple fields are comma-separated.',
1111
+ examples: [
1112
+ [
1113
+ { id: "name", direction: "desc" },
1114
+ { id: "age", direction: "asc" }
1115
+ ]
1116
+ ]
1117
+ }));
1118
+ var SortParamsArray = Schema.Array(SortParam);
1119
+ var SortParams = Schema.declare(Schema.is(SortParamsArray), {
1120
+ identifier: "SortParams",
1121
+ toCodec: () => Schema.link()(SortParamsArray, SchemaTransformation.passthrough()),
1122
+ toCodecStringTree: () => Schema.link()(SortParamsFromString, SchemaTransformation.passthrough())
1123
+ });
1124
+ var TextFilterOperator = Schema.Literals([
1125
+ "contains",
1126
+ "equals",
1127
+ "startsWith",
1128
+ "endsWith"
1129
+ ]).annotate({ identifier: "TextFilterOperator" });
1130
+ var FilterCalendarDate = 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: "FilterCalendarDate" });
1131
+ var ColumnFilter = Schema.Union([
1132
+ Schema.Struct({
1133
+ id: Schema.NonEmptyString,
1134
+ kind: Schema.Literal("text"),
1135
+ operator: TextFilterOperator,
1136
+ value: Schema.NonEmptyString
1137
+ }),
1138
+ Schema.Struct({
1139
+ id: Schema.NonEmptyString,
1140
+ kind: Schema.Literal("number"),
1141
+ min: Schema.optional(Schema.Finite),
1142
+ max: Schema.optional(Schema.Finite)
1143
+ }).check(Schema.makeFilter((range) => (range.min !== undefined || range.max !== undefined) && (range.min === undefined || range.max === undefined || range.min <= range.max))),
1144
+ Schema.Struct({
1145
+ id: Schema.NonEmptyString,
1146
+ kind: Schema.Literal("date"),
1147
+ from: Schema.optional(FilterCalendarDate),
1148
+ to: Schema.optional(FilterCalendarDate)
1149
+ }).check(Schema.makeFilter((range) => (range.from !== undefined || range.to !== undefined) && (range.from === undefined || range.to === undefined || range.from <= range.to))),
1150
+ Schema.Struct({
1151
+ id: Schema.NonEmptyString,
1152
+ kind: Schema.Literal("boolean"),
1153
+ value: Schema.Boolean
1154
+ }),
1155
+ Schema.Struct({
1156
+ id: Schema.NonEmptyString,
1157
+ kind: Schema.Literal("values"),
1158
+ values: Schema.NonEmptyArray(Schema.String)
1159
+ })
1160
+ ]).annotate({ identifier: "ColumnFilter" });
1161
+ var ColumnFiltersArray = Schema.Array(ColumnFilter);
1162
+ var ColumnFilters = Schema.declare(Schema.is(ColumnFiltersArray), {
1163
+ identifier: "ColumnFilters",
1164
+ toCodec: () => Schema.link()(ColumnFiltersArray, SchemaTransformation.passthrough()),
1165
+ toCodecStringTree: () => Schema.link()(Schema.fromJsonString(ColumnFiltersArray), SchemaTransformation.passthrough())
1166
+ });
1167
+ var Query = Schema.Struct({
1168
+ page: Schema.optional(Schema.Union([Schema.Number, Schema.NumberFromString]).check(Schema.isInt(), Schema.isGreaterThanOrEqualTo(0))).pipe(Schema.decodeTo(Schema.Int.check(Schema.isGreaterThanOrEqualTo(0)), {
1169
+ decode: SchemaGetter.withDefault(Effect.succeed(0)),
1170
+ encode: SchemaGetter.transformOptional(Option.filter((page) => page !== 0))
1171
+ })),
1172
+ pageSize: Schema.optional(Schema.Union([Schema.Number, Schema.NumberFromString]).check(Schema.isInt(), Schema.isBetween({ minimum: 1, maximum: 100 }))).pipe(Schema.decodeTo(Schema.Int.check(Schema.isBetween({ minimum: 1, maximum: 100 })), {
1173
+ decode: SchemaGetter.withDefault(Effect.succeed(20)),
1174
+ encode: SchemaGetter.transformOptional(Option.filter((pageSize) => pageSize !== 20))
1175
+ })),
1176
+ globalFilter: Schema.optional(Schema.String),
1177
+ sort: Schema.optional(SortParams),
1178
+ filters: Schema.optional(ColumnFilters)
1179
+ }).annotate({
1180
+ identifier: "Query",
1181
+ title: "Query",
1182
+ description: "Zero-based page request parameters with optional filtering and sorting for list endpoints.",
1183
+ examples: [
1184
+ {
1185
+ page: 0,
1186
+ pageSize: 20,
1187
+ globalFilter: "housing",
1188
+ sort: [
1189
+ { id: "publicName", direction: "desc" },
1190
+ { id: "createdAt", direction: "asc" }
1191
+ ]
1192
+ }
1193
+ ]
1194
+ });
1195
+ var QueryStandard = Schema.toStandardSchemaV1(Query);
1196
+ var PaginationMeta = Schema.Struct({
1197
+ page: Schema.Int,
1198
+ pageSize: Schema.Int,
1199
+ total: Schema.Int,
1200
+ pageCount: Schema.Int
1201
+ }).pipe(Schema.annotate({
1202
+ identifier: "PaginationMeta",
1203
+ title: "Pagination Metadata",
1204
+ description: "Pagination metadata returned with a paginated list response.",
1205
+ examples: [{ page: 0, pageSize: 20, total: 125, pageCount: 7 }]
1206
+ }));
1207
+
1208
+ // ../../src/components/ui/data-table.tsx
1209
+ import { useKrakstackLocale as useKrakstackLocale3 } from "@krak-stack/registry/krakstack-provider";
1210
+ import { jsx as jsx15, jsxs as jsxs9, Fragment } from "react/jsx-runtime";
1211
+ var DataTablePersistedUiStateSchema = Schema2.Struct({
1212
+ columnVisibility: Schema2.Record(Schema2.String, Schema2.Boolean),
1213
+ columnSizing: Schema2.Record(Schema2.String, Schema2.Number),
1214
+ grouping: Schema2.optionalKey(Schema2.Array(Schema2.String)),
1215
+ view: Schema2.Literals(["table", "gallery"])
1216
+ }).annotate({ identifier: "DataTablePersistedUiState" });
1217
+ var dataTableStorageRuntime = Atom.runtime(BrowserKeyValueStore.layerLocalStorage);
1218
+ var DataTableReferenceCell = ({
1219
+ item,
1220
+ emptyLabel = "—",
1221
+ imageVariant = "circle"
1222
+ }) => {
1223
+ const [failedImage, setFailedImage] = useState();
1224
+ if (!item)
1225
+ return emptyLabel;
1226
+ const initials = item.label.trim().split(/\s+/).slice(0, 2).map((word) => word.slice(0, 1)).join("").toLocaleUpperCase();
1227
+ return /* @__PURE__ */ jsxs9("div", {
1228
+ className: "flex min-w-0 items-center gap-2",
1229
+ children: [
1230
+ /* @__PURE__ */ jsx15("div", {
1231
+ 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", item.iconClassName),
1232
+ children: item.icon ? /* @__PURE__ */ jsx15("span", {
1233
+ "aria-hidden": "true",
1234
+ className: "[&_svg]:size-4",
1235
+ children: item.icon
1236
+ }) : item.imageSrc && item.imageSrc !== failedImage ? /* @__PURE__ */ jsx15("img", {
1237
+ src: item.imageSrc,
1238
+ alt: item.label,
1239
+ className: "size-full object-cover",
1240
+ onError: () => setFailedImage(item.imageSrc ?? undefined)
1241
+ }) : /* @__PURE__ */ jsx15("span", {
1242
+ "aria-hidden": "true",
1243
+ children: initials
1244
+ })
1245
+ }),
1246
+ /* @__PURE__ */ jsxs9("div", {
1247
+ className: "flex min-w-0 flex-col leading-tight",
1248
+ children: [
1249
+ /* @__PURE__ */ jsx15("span", {
1250
+ className: "truncate font-medium",
1251
+ children: item.label
1252
+ }),
1253
+ item.description ? /* @__PURE__ */ jsx15("span", {
1254
+ className: "text-muted-foreground truncate text-xs",
1255
+ children: item.description
1256
+ }) : null
1257
+ ]
1258
+ })
1259
+ ]
1260
+ });
1261
+ };
1262
+ var referenceText = (item) => item ? [item.label, item.description].filter(Boolean).join(" — ") : "";
1263
+ var messages2 = {
1264
+ en: {
1265
+ ...paginationMessages("en"),
1266
+ actions: "Actions",
1267
+ addItem: "Add item...",
1268
+ empty: "No results.",
1269
+ loading: "Loading...",
1270
+ filter: "Filter results...",
1271
+ filters: "Filters",
1272
+ filtersClear: "Clear all filters",
1273
+ filterClear: "Clear filter",
1274
+ filterApply: "Apply filter",
1275
+ filterValue: "Value",
1276
+ filterOperator: "Operator",
1277
+ filterContains: "Contains",
1278
+ filterEquals: "Equals",
1279
+ filterStartsWith: "Starts with",
1280
+ filterEndsWith: "Ends with",
1281
+ filterMin: "Minimum",
1282
+ filterMax: "Maximum",
1283
+ filterFrom: "From (UTC)",
1284
+ filterTo: "To (UTC)",
1285
+ filterTrue: "True",
1286
+ filterFalse: "False",
1287
+ filterInvalid: "Enter a valid filter. Ranges must be in ascending order.",
1288
+ export: "Export",
1289
+ exportCsv: "CSV",
1290
+ exportJson: "JSON",
1291
+ exportFailed: "Export failed. Please try again.",
1292
+ refresh: "Refresh",
1293
+ view: "View",
1294
+ tableView: "Table",
1295
+ galleryView: "Gallery",
1296
+ columns: "Columns",
1297
+ groupBy: "Group by",
1298
+ sortAsc: "Ascending",
1299
+ sortDesc: "Descending",
1300
+ sortClear: "Clear sorting",
1301
+ sortBy: "Sort by",
1302
+ hideColumn: "Hide column",
1303
+ reorder: "Drag to reorder",
1304
+ removeItem: "Remove",
1305
+ moveUp: "Move up",
1306
+ moveDown: "Move down",
1307
+ resizeColumn: (column) => `Resize ${column} column`,
1308
+ listDetails: "View all items",
1309
+ selectAllRows: "Select all rows on this page",
1310
+ selectRow: "Select row",
1311
+ selected: "Selected"
1312
+ },
1313
+ fr: {
1314
+ ...paginationMessages("fr"),
1315
+ actions: "Actions",
1316
+ addItem: "Ajouter un élément...",
1317
+ empty: "Aucun résultat.",
1318
+ loading: "Chargement...",
1319
+ filter: "Filtrer les résultats...",
1320
+ filters: "Filtres",
1321
+ filtersClear: "Effacer tous les filtres",
1322
+ filterClear: "Effacer le filtre",
1323
+ filterApply: "Appliquer le filtre",
1324
+ filterValue: "Valeur",
1325
+ filterOperator: "Opérateur",
1326
+ filterContains: "Contient",
1327
+ filterEquals: "Égal à",
1328
+ filterStartsWith: "Commence par",
1329
+ filterEndsWith: "Se termine par",
1330
+ filterMin: "Minimum",
1331
+ filterMax: "Maximum",
1332
+ filterFrom: "Du (UTC)",
1333
+ filterTo: "Au (UTC)",
1334
+ filterTrue: "Vrai",
1335
+ filterFalse: "Faux",
1336
+ filterInvalid: "Saisissez un filtre valide. Les bornes doivent être dans l’ordre croissant.",
1337
+ export: "Exporter",
1338
+ exportCsv: "CSV",
1339
+ exportJson: "JSON",
1340
+ exportFailed: "L’exportation a échoué. Veuillez réessayer.",
1341
+ refresh: "Rafraîchir",
1342
+ view: "Affichage",
1343
+ tableView: "Tableau",
1344
+ galleryView: "Galerie",
1345
+ columns: "Colonnes",
1346
+ groupBy: "Grouper par",
1347
+ sortAsc: "Croissant",
1348
+ sortDesc: "Décroissant",
1349
+ sortClear: "Effacer le tri",
1350
+ sortBy: "Trier par",
1351
+ hideColumn: "Masquer la colonne",
1352
+ reorder: "Glisser pour réordonner",
1353
+ removeItem: "Retirer",
1354
+ moveUp: "Déplacer vers le haut",
1355
+ moveDown: "Déplacer vers le bas",
1356
+ resizeColumn: (column) => `Redimensionner la colonne ${column}`,
1357
+ listDetails: "Afficher tous les éléments",
1358
+ selectAllRows: "Sélectionner toutes les lignes de cette page",
1359
+ selectRow: "Sélectionner la ligne",
1360
+ selected: "Sélectionnés"
1361
+ }
1362
+ };
1363
+ var dataTableMessages = (locale = "en", translations) => ({
1364
+ ...locale.startsWith("fr") ? messages2.fr : messages2.en,
1365
+ ...translations?.[locale.split("-")[0] ?? locale],
1366
+ ...translations?.[locale]
1367
+ });
1368
+ var DEFAULT_MIN_WIDTH = 96;
1369
+ var DEFAULT_WIDTH = 208;
1370
+ var DEFAULT_MAX_WIDTH = 640;
1371
+ var DEFAULT_QUERY = {
1372
+ page: 0,
1373
+ pageSize: 20
1374
+ };
1375
+ var DEFAULT_UI_STATE = {
1376
+ columnVisibility: {},
1377
+ columnSizing: {},
1378
+ rowSelection: {},
1379
+ grouping: [],
1380
+ collapsedGroups: {},
1381
+ view: "table"
1382
+ };
1383
+ var persistedUiFromState = (state) => ({
1384
+ columnVisibility: state.columnVisibility,
1385
+ columnSizing: state.columnSizing,
1386
+ grouping: state.grouping,
1387
+ view: state.view
1388
+ });
1389
+ var transientUiFromState = (state) => ({
1390
+ rowSelection: state.rowSelection,
1391
+ collapsedGroups: state.collapsedGroups
1392
+ });
1393
+ var clampWidth = (column, width) => Math.min(column.maxWidth ?? DEFAULT_MAX_WIDTH, Math.max(column.minWidth ?? DEFAULT_MIN_WIDTH, width));
1394
+ var normalizeDataTableColumns = (columnDefs, columnSizing = {}) => {
1395
+ const ids = new Set;
1396
+ const columns = columnDefs.map((colDef) => {
1397
+ const id = colDef.field ?? colDef.colId;
1398
+ if (!id) {
1399
+ throw new Error("DataTable columns require a field or colId");
1400
+ }
1401
+ if (ids.has(id)) {
1402
+ throw new Error(`DataTable column IDs must be unique: ${id}`);
1403
+ }
1404
+ ids.add(id);
1405
+ return {
1406
+ id,
1407
+ colDef,
1408
+ width: clampWidth(colDef, columnSizing[id] ?? colDef.width ?? DEFAULT_WIDTH)
1409
+ };
1410
+ });
1411
+ for (const column of columns) {
1412
+ for (const field of column.colDef.fields ?? []) {
1413
+ const id = `${column.id}.${field.id}`;
1414
+ if (!field.id || ids.has(id)) {
1415
+ throw new Error(`DataTable field IDs must be nonempty and unique: ${id}`);
1416
+ }
1417
+ ids.add(id);
1418
+ }
1419
+ }
1420
+ return columns;
1421
+ };
1422
+ var getDataTableFieldColumns = (column) => (column.colDef.fields ?? []).map(({ id, export: _export, ...colDef }) => ({
1423
+ id: `${column.id}.${id}`,
1424
+ colDef: { ...colDef, colId: `${column.id}.${id}` },
1425
+ width: column.width
1426
+ }));
1427
+ var getDataTableSortColumns = (columns) => columns.flatMap((column) => column.colDef.sortable === false ? [] : ((column.colDef.fields?.length) ? getDataTableFieldColumns(column) : [column]).filter(({ colDef }) => colDef.sortable !== false));
1428
+ var getDataTableExportColumns = (visibleColumns) => visibleColumns.flatMap((column) => column.colDef.fields?.length ? getDataTableFieldColumns(column).filter((_field, index) => column.colDef.fields?.[index]?.export !== false) : [column]);
1429
+ var getDataTableWidth = (columns, utilityColumns = 0) => columns.reduce((total, column) => total + column.width, 0) + utilityColumns * 40;
1430
+ var buildDataTableRows = (rowData, columns, getRowId) => {
1431
+ const ids = new Set;
1432
+ return rowData.map((data, index) => {
1433
+ const id = getRowId?.(data) ?? String(index);
1434
+ if (ids.has(id))
1435
+ throw new Error(`DataTable row IDs must be unique: ${id}`);
1436
+ ids.add(id);
1437
+ return {
1438
+ id,
1439
+ data,
1440
+ index,
1441
+ values: new Map(columns.flatMap((column) => [column, ...getDataTableFieldColumns(column)]).map((column) => {
1442
+ const { colDef } = column;
1443
+ 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;
1444
+ return [column.id, value];
1445
+ }))
1446
+ };
1447
+ });
1448
+ };
1449
+ var CalendarDate = Schema2.String.check(Schema2.isPattern(/^\d{4}-\d{2}-\d{2}$/), Schema2.makeFilter((value) => Option2.exists(DateTime2.make(value), (date) => DateTime2.formatIsoDateUtc(date) === value))).annotate({ identifier: "DataTableCalendarDate" });
1450
+ var InstantString = Schema2.String.check(Schema2.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)$/), Schema2.makeFilter((value) => Schema2.is(CalendarDate)(value.slice(0, 10)))).annotate({ identifier: "DataTableInstantString" });
1451
+ var DateInput = Schema2.Union([
1452
+ Schema2.Date,
1453
+ Schema2.Int,
1454
+ CalendarDate,
1455
+ InstantString
1456
+ ]).annotate({ identifier: "DataTableDateInput" });
1457
+ var decodeDateInput = Schema2.decodeUnknownOption(DateInput);
1458
+ var resolveDate = (value, type) => Option2.getOrUndefined(Option2.flatMap(decodeDateInput(value), (input) => {
1459
+ const calendarOnly = Schema2.is(CalendarDate)(input);
1460
+ if (calendarOnly && type === "dateTime")
1461
+ return Option2.none();
1462
+ return Option2.map(DateTime2.make(input), (instant) => ({
1463
+ instant,
1464
+ calendarOnly
1465
+ }));
1466
+ }));
1467
+ var formatDateValue = (date, column, locale = "en") => DateTime2.format(date.instant, {
1468
+ locale: column.typeOptions?.locale ?? locale,
1469
+ timeZone: date.calendarOnly ? "UTC" : column.typeOptions?.timeZone ?? "UTC",
1470
+ dateStyle: column.typeOptions?.dateStyle ?? "medium",
1471
+ timeStyle: column.type === "dateTime" ? column.typeOptions?.timeStyle ?? "short" : undefined,
1472
+ hour12: column.type === "dateTime" ? column.typeOptions?.hour12 : undefined
1473
+ });
1474
+ var dateIsoValue = (date) => date.calendarOnly ? DateTime2.formatIsoDateUtc(date.instant) : DateTime2.formatIso(date.instant);
1475
+ var NumberValue = Schema2.Finite.annotate({
1476
+ identifier: "DataTableNumberValue"
1477
+ });
1478
+ var BooleanValue = Schema2.Boolean.annotate({
1479
+ identifier: "DataTableBooleanValue"
1480
+ });
1481
+ var decodeNumberValue = Schema2.decodeUnknownOption(NumberValue);
1482
+ var decodeBooleanValue = Schema2.decodeUnknownOption(BooleanValue);
1483
+ var formatNumberValue = (value, options = {}, defaultLocale = "en") => {
1484
+ const {
1485
+ locale,
1486
+ emptyLabel: _emptyLabel,
1487
+ nulls: _nulls,
1488
+ exportFormat: _exportFormat,
1489
+ ...format
1490
+ } = options;
1491
+ return new Intl.NumberFormat(locale ?? defaultLocale, format).format(value);
1492
+ };
1493
+ var booleanLabel = (value, options) => value ? options?.trueLabel : options?.falseLabel;
1494
+ var getDataTableExportValue = (row, column, locale = "en") => {
1495
+ const value = row.values.get(column.id);
1496
+ const colDef = column.colDef;
1497
+ if (colDef.type === "number") {
1498
+ const number = Option2.getOrUndefined(decodeNumberValue(value));
1499
+ if (number === undefined)
1500
+ return null;
1501
+ return colDef.typeOptions?.exportFormat === "formatted" ? formatNumberValue(number, colDef.typeOptions, locale) : number;
1502
+ }
1503
+ if (colDef.type === "boolean") {
1504
+ const boolean = Option2.getOrUndefined(decodeBooleanValue(value));
1505
+ if (boolean === undefined)
1506
+ return null;
1507
+ return colDef.typeOptions?.exportFormat === "formatted" ? booleanLabel(boolean, colDef.typeOptions) ?? String(boolean) : boolean;
1508
+ }
1509
+ if (colDef.type !== "date" && colDef.type !== "dateTime")
1510
+ return value;
1511
+ const date = resolveDate(value, colDef.type);
1512
+ if (!date)
1513
+ return null;
1514
+ return colDef.typeOptions?.exportFormat === "formatted" ? formatDateValue(date, colDef, locale) : dateIsoValue(date);
1515
+ };
1516
+ var filterDataTableRows = (rows, columns, globalFilter, locale = "en") => {
1517
+ const query = globalFilter.trim().toLocaleLowerCase();
1518
+ if (!query)
1519
+ return [...rows];
1520
+ const searchable = columns.flatMap((column) => column.colDef.searchable === false ? [] : ((column.colDef.fields?.length) ? getDataTableFieldColumns(column) : [column]).filter(({ colDef }) => colDef.searchable !== false));
1521
+ return rows.filter((row) => searchable.some((column) => {
1522
+ const value = row.values.get(column.id);
1523
+ const colDef = column.colDef;
1524
+ let text = String(value ?? "");
1525
+ if (colDef.type === "date" || colDef.type === "dateTime") {
1526
+ const date = resolveDate(value, colDef.type);
1527
+ text = date ? `${formatDateValue(date, colDef, locale)} ${dateIsoValue(date)}` : "";
1528
+ } else if (colDef.type === "number") {
1529
+ const number = Option2.getOrUndefined(decodeNumberValue(value));
1530
+ text = number === undefined ? "" : `${formatNumberValue(number, colDef.typeOptions, locale)} ${number}`;
1531
+ } else if (colDef.type === "boolean") {
1532
+ const boolean = Option2.getOrUndefined(decodeBooleanValue(value));
1533
+ text = boolean === undefined ? "" : `${booleanLabel(boolean, colDef.typeOptions) ?? ""} ${boolean}`;
1534
+ }
1535
+ return text.toLocaleLowerCase().includes(query);
1536
+ }));
1537
+ };
1538
+ var getDataTableFilterColumns = (columns) => columns.flatMap((column) => column.colDef.filterable === false ? [] : ((column.colDef.fields?.length) ? getDataTableFieldColumns(column) : [column]).filter(({ colDef }) => colDef.filterable !== false));
1539
+ var getDataTableFilterKind = ({
1540
+ colDef
1541
+ }) => colDef.filterOptions || colDef.type === "list" ? "values" : colDef.type === "number" ? "number" : colDef.type === "date" || colDef.type === "dateTime" ? "date" : colDef.type === "boolean" ? "boolean" : "text";
1542
+ var getDataTableFilterOptions = (rows, column) => {
1543
+ const { colDef } = column;
1544
+ if (colDef.filterOptions)
1545
+ return colDef.filterOptions;
1546
+ const options = new Map;
1547
+ if (colDef.type === "list") {
1548
+ for (const row of rows) {
1549
+ for (const item of colDef.typeOptions.getItems(row.data)) {
1550
+ const value = item.value ?? item.label;
1551
+ options.set(value, { value, label: item.label });
1552
+ }
1553
+ }
1554
+ }
1555
+ return [...options.values()].sort((left, right) => left.label.localeCompare(right.label));
1556
+ };
1557
+ var filterDataTableColumnRows = (rows, columns, filters) => {
1558
+ const byId = new Map(getDataTableFilterColumns(columns).map((column) => [column.id, column]));
1559
+ return rows.filter((row) => filters.every((filter) => {
1560
+ const column = byId.get(filter.id);
1561
+ if (!column || getDataTableFilterKind(column) !== filter.kind)
1562
+ return true;
1563
+ const value = column.colDef.filterValueGetter ? column.colDef.filterValueGetter({
1564
+ data: row.data,
1565
+ rowId: row.id,
1566
+ rowIndex: row.index,
1567
+ colDef: column.colDef
1568
+ }) : row.values.get(column.id);
1569
+ switch (filter.kind) {
1570
+ case "text": {
1571
+ const text = String(value ?? "").toLocaleLowerCase();
1572
+ const query = filter.value.toLocaleLowerCase();
1573
+ switch (filter.operator) {
1574
+ case "contains":
1575
+ return text.includes(query);
1576
+ case "equals":
1577
+ return text === query;
1578
+ case "startsWith":
1579
+ return text.startsWith(query);
1580
+ case "endsWith":
1581
+ return text.endsWith(query);
1582
+ }
1583
+ }
1584
+ case "number": {
1585
+ const number = Option2.getOrUndefined(decodeNumberValue(value));
1586
+ return number !== undefined && (filter.min === undefined || number >= filter.min) && (filter.max === undefined || number <= filter.max);
1587
+ }
1588
+ case "date": {
1589
+ const date = resolveDate(value, column.colDef.type === "dateTime" ? "dateTime" : "date");
1590
+ if (!date)
1591
+ return false;
1592
+ const day = DateTime2.formatIsoDateUtc(date.instant);
1593
+ return (filter.from === undefined || day >= filter.from) && (filter.to === undefined || day <= filter.to);
1594
+ }
1595
+ case "boolean":
1596
+ return Option2.getOrUndefined(decodeBooleanValue(value)) === filter.value;
1597
+ case "values": {
1598
+ const values = column.colDef.type === "list" ? column.colDef.typeOptions.getItems(row.data).map((item) => item.value ?? item.label) : [String(value ?? "")];
1599
+ return filter.values.some((selected) => values.includes(selected));
1600
+ }
1601
+ }
1602
+ }));
1603
+ };
1604
+ var sortDataTableRows = (rows, columns, sorting) => {
1605
+ const byId = new Map([...columns, ...getDataTableSortColumns(columns)].map((column) => [
1606
+ column.id,
1607
+ column
1608
+ ]));
1609
+ return rows.map((row, stableIndex) => ({ row, stableIndex })).sort((left, right) => {
1610
+ for (const sort of sorting) {
1611
+ const column = byId.get(sort.id);
1612
+ if (!column)
1613
+ continue;
1614
+ const leftValue = left.row.values.get(sort.id);
1615
+ const rightValue = right.row.values.get(sort.id);
1616
+ const colDef = column.colDef;
1617
+ if (!colDef.comparator && (colDef.type === "number" || colDef.type === "boolean")) {
1618
+ const leftScalar = colDef.type === "number" ? Option2.getOrUndefined(decodeNumberValue(leftValue)) : Option2.getOrUndefined(Option2.map(decodeBooleanValue(leftValue), Number));
1619
+ const rightScalar = colDef.type === "number" ? Option2.getOrUndefined(decodeNumberValue(rightValue)) : Option2.getOrUndefined(Option2.map(decodeBooleanValue(rightValue), Number));
1620
+ if (leftScalar === undefined || rightScalar === undefined) {
1621
+ if (leftScalar === undefined && rightScalar === undefined)
1622
+ continue;
1623
+ const nullOrder = colDef.typeOptions?.nulls === "first" ? -1 : 1;
1624
+ return leftScalar === undefined ? nullOrder : -nullOrder;
1625
+ }
1626
+ const comparison = leftScalar - rightScalar;
1627
+ if (comparison !== 0)
1628
+ return sort.direction === "desc" ? -comparison : comparison;
1629
+ continue;
1630
+ }
1631
+ if (!colDef.comparator && (colDef.type === "date" || colDef.type === "dateTime")) {
1632
+ const leftDate = resolveDate(leftValue, colDef.type);
1633
+ const rightDate = resolveDate(rightValue, colDef.type);
1634
+ if (!leftDate || !rightDate) {
1635
+ if (!leftDate && !rightDate)
1636
+ continue;
1637
+ const nullOrder = colDef.typeOptions?.nulls === "first" ? -1 : 1;
1638
+ return !leftDate ? nullOrder : -nullOrder;
1639
+ }
1640
+ const comparison = DateTime2.toEpochMillis(leftDate.instant) - DateTime2.toEpochMillis(rightDate.instant);
1641
+ if (comparison !== 0)
1642
+ return sort.direction === "desc" ? -comparison : comparison;
1643
+ continue;
1644
+ }
1645
+ 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 : Schema2.is(Schema2.Number)(leftValue) && Schema2.is(Schema2.Number)(rightValue) ? leftValue - rightValue : String(leftValue).localeCompare(String(rightValue), undefined, { numeric: true, sensitivity: "base" });
1646
+ if (comparison !== 0)
1647
+ return sort.direction === "desc" ? -comparison : comparison;
1648
+ }
1649
+ return left.stableIndex - right.stableIndex;
1650
+ }).map(({ row }) => row);
1651
+ };
1652
+ var paginateDataTableRows = (rows, pagination) => {
1653
+ const pageSize = Math.max(1, pagination.pageSize);
1654
+ const lastPageIndex = Math.max(0, Math.ceil(rows.length / pageSize) - 1);
1655
+ const pageIndex = Math.min(lastPageIndex, Math.max(0, pagination.page));
1656
+ const start = pageIndex * pageSize;
1657
+ return rows.slice(start, start + pageSize);
1658
+ };
1659
+ var sameDataTableState = (left, right) => left.page === right.page && left.pageSize === right.pageSize && left.globalFilter === right.globalFilter && left.filters === right.filters && 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;
1660
+ var reorderDataTableRows = (rows, sourceRowId, targetRowId) => {
1661
+ const sourceIndex = rows.findIndex((row) => row.id === sourceRowId);
1662
+ const targetIndex = rows.findIndex((row) => row.id === targetRowId);
1663
+ const reordered = rows.map((row) => row.data);
1664
+ if (sourceIndex === -1 || targetIndex === -1 || sourceIndex === targetIndex) {
1665
+ return reordered;
1666
+ }
1667
+ const [source] = reordered.splice(sourceIndex, 1);
1668
+ if (source)
1669
+ reordered.splice(targetIndex, 0, source);
1670
+ return reordered;
1671
+ };
1672
+ var RowIdContext = createContext(null);
1673
+ var ColumnIdContext = createContext(null);
1674
+ var useRequiredId = (context) => {
1675
+ const id = useContext(context);
1676
+ if (!id)
1677
+ throw new Error("DataTable internal ID context is missing");
1678
+ return id;
1679
+ };
1680
+ var getGroupDropKey = (fieldId, groupId) => `${encodeURIComponent(fieldId)}:${encodeURIComponent(groupId)}`;
1681
+ var parseGroupDropKey = (key) => {
1682
+ const separator = key.indexOf(":");
1683
+ if (separator === -1)
1684
+ return null;
1685
+ return {
1686
+ fieldId: decodeURIComponent(key.slice(0, separator)),
1687
+ groupId: decodeURIComponent(key.slice(separator + 1))
1688
+ };
1689
+ };
1690
+ var findTableDragTarget = (elements, selector, root) => {
1691
+ for (const element of elements) {
1692
+ const target = element.closest(selector);
1693
+ if (target instanceof HTMLElement && root?.contains(target))
1694
+ return target;
1695
+ }
1696
+ return null;
1697
+ };
1698
+ var clearDragPresentation = (root) => {
1699
+ root?.querySelectorAll("[data-drag-source], [data-drop-target], [data-drop-position]").forEach((element) => {
1700
+ element.removeAttribute("data-drag-source");
1701
+ element.removeAttribute("data-drop-target");
1702
+ element.removeAttribute("data-drop-position");
1703
+ });
1704
+ };
1705
+ var resolveConfig = (props, onUiStateChange) => {
1706
+ const features = props.features ?? {};
1707
+ const selection = features.selection;
1708
+ const getRowId = selection && selection.getRowId || props.getRowId || undefined;
1709
+ if ((selection || features.reordering) && !getRowId) {
1710
+ throw new Error("DataTable requires getRowId when selection or reordering is enabled");
1711
+ }
1712
+ return {
1713
+ getRowId,
1714
+ onStateChange: props.onStateChange,
1715
+ onUiStateChange,
1716
+ status: props.status ?? {},
1717
+ features,
1718
+ onRowClicked: props.onRowClicked,
1719
+ labels: dataTableMessages(props.locale, props.messages),
1720
+ locale: props.locale ?? "en"
1721
+ };
1722
+ };
1723
+ var queryFromState = (state) => ({
1724
+ page: state.page,
1725
+ pageSize: state.pageSize,
1726
+ globalFilter: state.globalFilter,
1727
+ filters: state.filters,
1728
+ sort: state.sort
1729
+ });
1730
+ var uiFromState = (state) => ({
1731
+ columnVisibility: state.columnVisibility,
1732
+ columnSizing: state.columnSizing,
1733
+ rowSelection: state.rowSelection,
1734
+ grouping: state.grouping,
1735
+ collapsedGroups: state.collapsedGroups,
1736
+ view: state.view
1737
+ });
1738
+ 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;
1739
+ var sameQueryState = (left, right) => left.page === right.page && left.pageSize === right.pageSize && left.globalFilter === right.globalFilter && left.filters === right.filters && left.sort === right.sort;
1740
+ var initialPublicState = (props, uiState) => ({
1741
+ ...queryFromState(props.state ?? { ...DEFAULT_QUERY, ...props.initialState }),
1742
+ ...uiState
1743
+ });
1744
+ var buildDataTableModel = (store) => {
1745
+ const columns = normalizeDataTableColumns(store.columnDefs, store.state.columnSizing);
1746
+ const selection = store.config.features.selection;
1747
+ const rowId = selection && selection.getRowId || store.config.getRowId || undefined;
1748
+ const rows = buildDataTableRows(store.rowData, columns, rowId);
1749
+ const pagination = store.config.features.pagination ?? { mode: "client" };
1750
+ const server = pagination !== false && pagination.mode === "server";
1751
+ const filteredRows = server ? [...rows] : filterDataTableColumnRows(filterDataTableRows(rows, columns, store.state.globalFilter ?? "", store.config.locale), columns, store.state.filters ?? []);
1752
+ const sortedRows = server ? filteredRows : sortDataTableRows(filteredRows, columns, store.state.sort ?? []);
1753
+ const pageRows = pagination === false || server ? sortedRows : paginateDataTableRows(sortedRows, store.state);
1754
+ const totalRows = server ? pagination.rowCount : sortedRows.length;
1755
+ return {
1756
+ columns,
1757
+ visibleColumns: columns.filter(({ id }) => store.state.columnVisibility[id] !== false),
1758
+ rows,
1759
+ filteredRows,
1760
+ sortedRows,
1761
+ pageRows,
1762
+ pageCount: Math.max(1, Math.ceil(totalRows / Math.max(1, store.state.pageSize))),
1763
+ totalRows
1764
+ };
1765
+ };
1766
+ var useTableAtom = (tableAtom) => useAtom(tableAtom);
1767
+ var changeState = (setStore, update) => {
1768
+ setStore((store) => {
1769
+ const proposed = update(store.state);
1770
+ const query = queryFromState(proposed);
1771
+ if (!sameQueryState(query, store.state)) {
1772
+ store.config.onStateChange?.(query);
1773
+ }
1774
+ const uiState = uiFromState(proposed);
1775
+ if (!sameUiState(uiState, store.state)) {
1776
+ store.config.onUiStateChange(uiState);
1777
+ }
1778
+ const state = store.controlledState ? { ...proposed, ...queryFromState(store.controlledState) } : proposed;
1779
+ if (sameDataTableState(state, store.state))
1780
+ return store;
1781
+ const next = { ...store, state };
1782
+ return { ...next, model: buildDataTableModel(next) };
1783
+ });
1784
+ };
1785
+ var deriveModel = (store) => store.model;
1786
+ var groupDataTableRows = (rows, fields, depth = 0, parentKey = "") => {
1787
+ const field = fields[0];
1788
+ if (!field)
1789
+ return [];
1790
+ const groups = new Map;
1791
+ field.getGroupIds?.().forEach((id) => groups.set(id, []));
1792
+ rows.forEach((row) => {
1793
+ const ids = field.getRowGroupIds?.(row.data) ?? [
1794
+ field.getGroupId(row.data)
1795
+ ];
1796
+ ids.forEach((id) => groups.set(id, [...groups.get(id) ?? [], row]));
1797
+ });
1798
+ return Array.from(groups, ([groupId, groupRows]) => {
1799
+ const segment = `${encodeURIComponent(field.id)}:${encodeURIComponent(groupId)}`;
1800
+ const key = `${parentKey}${parentKey ? "/" : ""}${segment}`;
1801
+ return {
1802
+ key,
1803
+ groupId,
1804
+ depth,
1805
+ field,
1806
+ rows: groupRows,
1807
+ children: groupDataTableRows(groupRows, fields.slice(1), depth + 1, key)
1808
+ };
1809
+ });
1810
+ };
1811
+ var getDataTableSelectableRows = (model, grouped, isRowSelectable) => (grouped ? model.sortedRows : model.pageRows).filter((row) => isRowSelectable?.(row.data) ?? true);
1812
+ var getActiveGrouping = (store) => {
1813
+ const grouping = store.config.features.grouping;
1814
+ if (!grouping)
1815
+ return [];
1816
+ return store.state.grouping.flatMap((id) => {
1817
+ const field = grouping.fields.find((candidate) => candidate.id === id);
1818
+ return field ? [field] : [];
1819
+ });
1820
+ };
1821
+ var canReorderRows = (store) => {
1822
+ const pagination = store.config.features.pagination;
1823
+ return !!store.config.features.reordering && !getActiveGrouping(store).length && !store.state.globalFilter && !store.state.filters?.length && !store.state.sort?.length && !(pagination && pagination.mode === "server");
1824
+ };
1825
+ var canMoveRowsToGroups = (store) => getActiveGrouping(store).some((field) => !!field.onMoveToGroup);
1826
+ var canDragRows = (store) => getActiveGrouping(store).length ? canMoveRowsToGroups(store) : canReorderRows(store);
1827
+ var hasRowActionMenu = (store) => !!store.config.features.rowActions || canReorderRows(store);
1828
+ var getSelectedRows = (store, model) => model.rows.filter((row) => store.state.rowSelection[row.id]).map((row) => row.data);
1829
+ var renderCell = (row, column, locale = "en", labels = dataTableMessages(locale)) => {
1830
+ const value = row.values.get(column.id);
1831
+ const params = {
1832
+ data: row.data,
1833
+ value,
1834
+ rowId: row.id,
1835
+ rowIndex: row.index,
1836
+ colDef: column.colDef
1837
+ };
1838
+ const CellRenderer = column.colDef.cellRenderer;
1839
+ if (CellRenderer)
1840
+ return /* @__PURE__ */ jsx15(CellRenderer, {
1841
+ ...params
1842
+ });
1843
+ const colDef = column.colDef;
1844
+ if (colDef.type === "reference") {
1845
+ if (colDef.valueFormatter)
1846
+ return colDef.valueFormatter(params);
1847
+ return /* @__PURE__ */ jsx15(DataTableReferenceCell, {
1848
+ item: colDef.typeOptions.getItem(row.data),
1849
+ emptyLabel: colDef.typeOptions.emptyLabel,
1850
+ imageVariant: colDef.typeOptions.imageVariant
1851
+ });
1852
+ }
1853
+ if (colDef.type === "number") {
1854
+ if (colDef.valueFormatter)
1855
+ return colDef.valueFormatter(params);
1856
+ const number = Option2.getOrUndefined(decodeNumberValue(value));
1857
+ return /* @__PURE__ */ jsx15("span", {
1858
+ className: "block text-left tabular-nums",
1859
+ children: number === undefined ? colDef.typeOptions?.emptyLabel ?? "—" : formatNumberValue(number, colDef.typeOptions, locale)
1860
+ });
1861
+ }
1862
+ if (colDef.type === "boolean") {
1863
+ if (colDef.valueFormatter)
1864
+ return colDef.valueFormatter(params);
1865
+ const boolean = Option2.getOrUndefined(decodeBooleanValue(value));
1866
+ if (boolean === undefined)
1867
+ return colDef.typeOptions?.emptyLabel ?? "—";
1868
+ const options = colDef.typeOptions;
1869
+ return /* @__PURE__ */ jsx15("label", {
1870
+ "data-slot": "data-table-boolean-cell",
1871
+ className: cn("focus-within:border-ring focus-within:ring-ring/50 flex min-h-16 w-full items-center justify-start border border-transparent px-2 outline-none focus-within:ring-3 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) && "hover:bg-muted/50 cursor-pointer"),
1872
+ onClick: (event) => event.stopPropagation(),
1873
+ onPointerDown: (event) => event.stopPropagation(),
1874
+ children: /* @__PURE__ */ jsx15(Checkbox, {
1875
+ "aria-label": options?.getAriaLabel?.(row.data) ?? columnLabel(column),
1876
+ className: "focus-visible:ring-0 focus-visible:outline-none",
1877
+ checked: boolean,
1878
+ readOnly: !options?.onChange,
1879
+ disabled: options?.disabled?.(row.data),
1880
+ onCheckedChange: (checked) => options?.onChange?.({ value: checked, row: row.data })
1881
+ })
1882
+ });
1883
+ }
1884
+ if (colDef.type === "date" || colDef.type === "dateTime") {
1885
+ if (colDef.valueFormatter)
1886
+ return colDef.valueFormatter(params);
1887
+ const date = resolveDate(value, colDef.type);
1888
+ return date ? /* @__PURE__ */ jsx15("time", {
1889
+ dateTime: dateIsoValue(date),
1890
+ children: formatDateValue(date, colDef, locale)
1891
+ }) : colDef.typeOptions?.emptyLabel ?? "—";
1892
+ }
1893
+ if (colDef.type === "list") {
1894
+ const config = colDef.typeOptions;
1895
+ const itemActions = config.itemActions?.map((action) => ({
1896
+ ...action,
1897
+ onClick: (item) => action.onClick({ item, row: row.data }),
1898
+ visible: (item) => action.visible?.({ item, row: row.data }) ?? true,
1899
+ disabled: (item) => action.disabled?.({ item, row: row.data }) ?? false
1900
+ }));
1901
+ if (config.getOptions) {
1902
+ return /* @__PURE__ */ jsx15(DataTableListCell, {
1903
+ ...config,
1904
+ itemActions,
1905
+ onItemClick: config.onItemClick ? (item) => config.onItemClick?.({ item, row: row.data }) : undefined,
1906
+ items: config.getItems(row.data),
1907
+ locale,
1908
+ messages: { [locale]: labels },
1909
+ options: config.getOptions(row.data),
1910
+ totalCount: config.getTotalCount?.(row.data),
1911
+ onAdd: config.onAdd ? (value) => config.onAdd?.({ value, row: row.data }) : undefined,
1912
+ onRemove: config.onRemove ? (value) => config.onRemove?.({ value, row: row.data }) : undefined
1913
+ });
1914
+ }
1915
+ return /* @__PURE__ */ jsx15(DataTableListCell, {
1916
+ ...config,
1917
+ itemActions,
1918
+ onItemClick: config.onItemClick ? (item) => config.onItemClick?.({ item, row: row.data }) : undefined,
1919
+ items: config.getItems(row.data),
1920
+ locale,
1921
+ messages: { [locale]: labels },
1922
+ totalCount: config.getTotalCount?.(row.data)
1923
+ });
1924
+ }
1925
+ return column.colDef.valueFormatter?.(params) ?? (value === null || value === undefined ? null : String(value));
1926
+ };
1927
+ var nodeText = (node) => {
1928
+ if (Schema2.is(Schema2.String)(node) || Schema2.is(Schema2.Number)(node))
1929
+ return String(node);
1930
+ if (!isValidElement(node))
1931
+ return "";
1932
+ if (Schema2.is(Schema2.String)(node.props.title))
1933
+ return node.props.title;
1934
+ return nodeText(node.props.children);
1935
+ };
1936
+ var columnLabel = (column) => nodeText(column.colDef.headerName) || column.id;
1937
+ var withExtension = (fileName, extension) => fileName.includes(".") ? fileName.replace(/\.[^/.]+$/, `.${extension}`) : `${fileName}.${extension}`;
1938
+ var downloadCsv = (headers, data, fileName = "data.csv") => {
1939
+ const content = Effect2.runSync(Stream.fromIterable([headers, ...data]).pipe(Stream.map((row) => row.map((value) => value == null ? "" : String(value))), Stream.pipeThroughChannel(Csv.encodeString({ newline: `
1940
+ ` })), Stream.runCollect, Effect2.map((parts) => parts.join("").slice(0, -1))));
1941
+ downloadBlob(content, "text/csv;charset=utf-8", withExtension(fileName, "csv"));
1942
+ };
1943
+ var downloadJson = (data, fileName = "data.json") => downloadBlob(JSON.stringify(data, null, 2), "application/json;charset=utf-8", withExtension(fileName, "json"));
1944
+ var downloadBlob = (content, type, fileName) => {
1945
+ const url = window.URL.createObjectURL(new Blob([content], { type }));
1946
+ const link = document.createElement("a");
1947
+ link.href = url;
1948
+ link.download = fileName;
1949
+ document.body.appendChild(link);
1950
+ link.click();
1951
+ link.remove();
1952
+ requestAnimationFrame(() => window.URL.revokeObjectURL(url));
1953
+ };
1954
+ var DataTableRowActions = ({
1955
+ actions,
1956
+ row,
1957
+ title
1958
+ }) => {
1959
+ const visible = actions.filter((action) => !action.visible || action.visible(row));
1960
+ if (!visible.length)
1961
+ return null;
1962
+ return /* @__PURE__ */ jsxs9(DropdownMenu, {
1963
+ children: [
1964
+ /* @__PURE__ */ jsx15(DropdownMenuTrigger, {
1965
+ onClick: (event) => event.stopPropagation(),
1966
+ render: /* @__PURE__ */ jsxs9(Button, {
1967
+ className: "size-8 focus-visible:ring-inset [&_svg:not([class*='size-'])]:size-4",
1968
+ size: "icon",
1969
+ variant: "ghost",
1970
+ children: [
1971
+ /* @__PURE__ */ jsx15("span", {
1972
+ className: "sr-only",
1973
+ children: title
1974
+ }),
1975
+ /* @__PURE__ */ jsx15(MoreHorizontal, {})
1976
+ ]
1977
+ })
1978
+ }),
1979
+ /* @__PURE__ */ jsx15(DropdownMenuContent, {
1980
+ align: "end",
1981
+ className: "w-max",
1982
+ children: /* @__PURE__ */ jsxs9(DropdownMenuGroup, {
1983
+ children: [
1984
+ /* @__PURE__ */ jsx15(DropdownMenuLabel, {
1985
+ children: title
1986
+ }),
1987
+ /* @__PURE__ */ jsx15(DropdownMenuSeparator, {}),
1988
+ visible.map((action) => /* @__PURE__ */ jsxs9(DropdownMenuItem, {
1989
+ onClick: (event) => {
1990
+ event.stopPropagation();
1991
+ action.onClick(row);
1992
+ },
1993
+ variant: action.variant ?? "default",
1994
+ children: [
1995
+ action.icon,
1996
+ action.name
1997
+ ]
1998
+ }, action.id ?? action.name))
1999
+ ]
2000
+ })
2001
+ })
2002
+ ]
2003
+ });
2004
+ };
2005
+ var DataTableRowActionMenu = ({
2006
+ tableAtom
2007
+ }) => {
2008
+ const [store] = useTableAtom(tableAtom);
2009
+ const rowId = useRequiredId(RowIdContext);
2010
+ const model = deriveModel(store);
2011
+ const row = model.sortedRows.find((candidate) => candidate.id === rowId);
2012
+ if (!row)
2013
+ return null;
2014
+ const rowActions = store.config.features.rowActions || undefined;
2015
+ const visibleRows = model.pageRows;
2016
+ const rowIndex = visibleRows.findIndex((candidate) => candidate.id === rowId);
2017
+ const reordering = store.config.features.reordering;
2018
+ const reorderActions = [];
2019
+ if (reordering && canReorderRows(store)) {
2020
+ const move = (targetIndex) => reordering.onReorder(reorderDataTableRows(model.rows, rowId, visibleRows[targetIndex].id));
2021
+ if (rowIndex > 0) {
2022
+ reorderActions.push({
2023
+ id: "data-table-move-up",
2024
+ name: store.config.labels.moveUp,
2025
+ icon: /* @__PURE__ */ jsx15(ArrowUp, {}),
2026
+ onClick: () => move(rowIndex - 1)
2027
+ });
2028
+ }
2029
+ if (rowIndex !== -1 && rowIndex < visibleRows.length - 1) {
2030
+ reorderActions.push({
2031
+ id: "data-table-move-down",
2032
+ name: store.config.labels.moveDown,
2033
+ icon: /* @__PURE__ */ jsx15(ArrowDown, {}),
2034
+ onClick: () => move(rowIndex + 1)
2035
+ });
2036
+ }
2037
+ }
2038
+ return /* @__PURE__ */ jsx15(DataTableRowActions, {
2039
+ actions: [...reorderActions, ...rowActions ? rowActions.items : []],
2040
+ row: row.data,
2041
+ title: rowActions?.label ?? store.config.labels.actions
2042
+ });
2043
+ };
2044
+ var DataTableToolbar = ({
2045
+ tableAtom
2046
+ }) => {
2047
+ const [store, setStore] = useTableAtom(tableAtom);
2048
+ const exportPending = useRef(false);
2049
+ const [exporting, setExporting] = useState(false);
2050
+ const [exportFailed, setExportFailed] = useState(false);
2051
+ const { features, labels } = store.config;
2052
+ const model = deriveModel(store);
2053
+ const selectedRows = getSelectedRows(store, model);
2054
+ const grouping = features.grouping;
2055
+ const toolbar = features.toolbar;
2056
+ const bulkActions = features.selection && features.selection.bulkActions;
2057
+ const hasToolbar = !!toolbar || features.search !== false || features.filtering !== false || features.sorting !== false || features.columnVisibility !== false || !!features.export || !!features.gallery || !!grouping || !!features.refresh || !!bulkActions && selectedRows.length > 0;
2058
+ if (!hasToolbar)
2059
+ return null;
2060
+ const update = (next) => changeState(setStore, next);
2061
+ const visibleBulkActions = bulkActions ? bulkActions.items.filter((action) => !action.visible || action.visible(selectedRows)) : [];
2062
+ const exportRows = features.export && features.export.scope === "currentPage" ? model.pageRows : model.sortedRows;
2063
+ const exportColumns = getDataTableExportColumns(model.visibleColumns);
2064
+ const exportFeature = features.export;
2065
+ const exportActions = exportFeature ? exportFeature.actions ?? [] : [];
2066
+ const builtInExport = exportFeature && exportFeature.builtIn !== false;
2067
+ const canExport = builtInExport && exportRows.length > 0 || exportActions.some((action) => !action.disabled);
2068
+ const runExport = async (action) => {
2069
+ if (exportPending.current || action.disabled)
2070
+ return;
2071
+ exportPending.current = true;
2072
+ setExporting(true);
2073
+ setExportFailed(false);
2074
+ try {
2075
+ await action.onExport();
2076
+ } catch (error) {
2077
+ setExportFailed(true);
2078
+ if (exportFeature)
2079
+ exportFeature.onError?.(error, action);
2080
+ } finally {
2081
+ exportPending.current = false;
2082
+ setExporting(false);
2083
+ }
2084
+ };
2085
+ return /* @__PURE__ */ jsxs9("div", {
2086
+ className: "flex flex-col gap-2 pb-4",
2087
+ children: [
2088
+ features.search !== false ? /* @__PURE__ */ jsxs9("div", {
2089
+ className: "relative min-w-0",
2090
+ children: [
2091
+ /* @__PURE__ */ jsx15(Search, {
2092
+ className: "text-muted-foreground pointer-events-none absolute top-1/2 left-3 size-4 -translate-y-1/2"
2093
+ }),
2094
+ /* @__PURE__ */ jsx15(Input, {
2095
+ className: "px-9",
2096
+ onChange: (event) => update((state) => ({
2097
+ ...state,
2098
+ globalFilter: event.target.value,
2099
+ page: 0
2100
+ })),
2101
+ placeholder: labels.filter,
2102
+ value: store.state.globalFilter ?? ""
2103
+ }),
2104
+ store.state.globalFilter ? /* @__PURE__ */ jsx15(Button, {
2105
+ "aria-label": labels.filter,
2106
+ className: "absolute top-1/2 right-1 size-7 -translate-y-1/2 active:not-aria-[haspopup]:-translate-y-1/2",
2107
+ onClick: () => update((state) => ({
2108
+ ...state,
2109
+ globalFilter: undefined,
2110
+ page: 0
2111
+ })),
2112
+ size: "icon",
2113
+ variant: "ghost",
2114
+ children: /* @__PURE__ */ jsx15(X, {})
2115
+ }) : null
2116
+ ]
2117
+ }) : null,
2118
+ /* @__PURE__ */ jsx15("div", {
2119
+ className: "-m-1 flex overflow-x-auto p-1",
2120
+ children: /* @__PURE__ */ jsxs9(Menubar, {
2121
+ 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",
2122
+ children: [
2123
+ visibleBulkActions.length ? /* @__PURE__ */ jsxs9(MenubarMenu, {
2124
+ children: [
2125
+ /* @__PURE__ */ jsxs9(MenubarTrigger, {
2126
+ className: "bg-primary text-primary-foreground hover:bg-primary/90 aria-expanded:bg-primary/90",
2127
+ children: [
2128
+ labels.selected,
2129
+ /* @__PURE__ */ jsx15(Badge, {
2130
+ variant: "secondary",
2131
+ children: selectedRows.length
2132
+ }),
2133
+ /* @__PURE__ */ jsx15(ChevronDown, {})
2134
+ ]
2135
+ }),
2136
+ /* @__PURE__ */ jsx15(MenubarContent, {
2137
+ align: "end",
2138
+ className: "w-max",
2139
+ children: /* @__PURE__ */ jsxs9(MenubarGroup, {
2140
+ children: [
2141
+ /* @__PURE__ */ jsx15(MenubarLabel, {
2142
+ children: bulkActions && bulkActions.label ? bulkActions.label : labels.actions
2143
+ }),
2144
+ /* @__PURE__ */ jsx15(MenubarSeparator, {}),
2145
+ visibleBulkActions.map((action) => /* @__PURE__ */ jsxs9(MenubarItem, {
2146
+ onClick: () => action.onClick(selectedRows),
2147
+ variant: action.variant ?? "default",
2148
+ children: [
2149
+ action.icon,
2150
+ action.name
2151
+ ]
2152
+ }, action.id ?? action.name))
2153
+ ]
2154
+ })
2155
+ })
2156
+ ]
2157
+ }) : null,
2158
+ toolbar && toolbar.items,
2159
+ features.filtering !== false ? /* @__PURE__ */ jsx15(FilterMenu, {
2160
+ tableAtom
2161
+ }) : null,
2162
+ grouping ? /* @__PURE__ */ jsxs9(MenubarMenu, {
2163
+ children: [
2164
+ /* @__PURE__ */ jsxs9(MenubarTrigger, {
2165
+ "aria-label": labels.groupBy,
2166
+ children: [
2167
+ /* @__PURE__ */ jsx15(Rows3, {}),
2168
+ /* @__PURE__ */ jsx15("span", {
2169
+ className: "hidden sm:inline",
2170
+ children: labels.groupBy
2171
+ })
2172
+ ]
2173
+ }),
2174
+ /* @__PURE__ */ jsx15(MenubarContent, {
2175
+ align: "end",
2176
+ children: /* @__PURE__ */ jsxs9(MenubarGroup, {
2177
+ children: [
2178
+ /* @__PURE__ */ jsx15(MenubarLabel, {
2179
+ children: labels.groupBy
2180
+ }),
2181
+ /* @__PURE__ */ jsx15(MenubarSeparator, {}),
2182
+ grouping.fields.map((field) => /* @__PURE__ */ jsx15(MenubarCheckboxItem, {
2183
+ checked: store.state.grouping.includes(field.id),
2184
+ onCheckedChange: (checked) => update((state) => ({
2185
+ ...state,
2186
+ grouping: checked ? [...state.grouping, field.id] : state.grouping.filter((id) => id !== field.id)
2187
+ })),
2188
+ children: field.label
2189
+ }, field.id))
2190
+ ]
2191
+ })
2192
+ })
2193
+ ]
2194
+ }) : null,
2195
+ features.sorting !== false ? /* @__PURE__ */ jsx15(SortMenu, {
2196
+ tableAtom
2197
+ }) : null,
2198
+ features.gallery ? /* @__PURE__ */ jsx15(ViewMenu, {
2199
+ tableAtom
2200
+ }) : null,
2201
+ features.columnVisibility !== false ? /* @__PURE__ */ jsx15(ColumnMenu, {
2202
+ tableAtom
2203
+ }) : null,
2204
+ features.refresh ? /* @__PURE__ */ jsx15(MenubarMenu, {
2205
+ children: /* @__PURE__ */ jsxs9(MenubarTrigger, {
2206
+ "aria-label": labels.refresh,
2207
+ onClick: features.refresh,
2208
+ children: [
2209
+ /* @__PURE__ */ jsx15(RefreshCw, {}),
2210
+ /* @__PURE__ */ jsx15("span", {
2211
+ className: "hidden sm:inline",
2212
+ children: labels.refresh
2213
+ })
2214
+ ]
2215
+ })
2216
+ }) : null,
2217
+ features.export ? /* @__PURE__ */ jsxs9(MenubarMenu, {
2218
+ children: [
2219
+ /* @__PURE__ */ jsxs9(MenubarTrigger, {
2220
+ "aria-label": labels.export,
2221
+ "aria-busy": exporting,
2222
+ disabled: exporting || !canExport,
2223
+ children: [
2224
+ exporting ? /* @__PURE__ */ jsx15(RefreshCw, {
2225
+ className: "animate-spin"
2226
+ }) : /* @__PURE__ */ jsx15(Download, {}),
2227
+ /* @__PURE__ */ jsx15("span", {
2228
+ className: "hidden sm:inline",
2229
+ children: exporting ? labels.loading : labels.export
2230
+ })
2231
+ ]
2232
+ }),
2233
+ /* @__PURE__ */ jsx15(MenubarContent, {
2234
+ align: "end",
2235
+ children: /* @__PURE__ */ jsxs9(MenubarGroup, {
2236
+ children: [
2237
+ /* @__PURE__ */ jsx15(MenubarLabel, {
2238
+ children: labels.export
2239
+ }),
2240
+ /* @__PURE__ */ jsx15(MenubarSeparator, {}),
2241
+ builtInExport ? /* @__PURE__ */ jsxs9(Fragment, {
2242
+ children: [
2243
+ /* @__PURE__ */ jsxs9(MenubarItem, {
2244
+ disabled: exporting || !exportRows.length,
2245
+ onClick: () => downloadCsv(exportColumns.map(columnLabel), exportRows.map((row) => exportColumns.map((column) => String(getDataTableExportValue(row, column, store.config.locale) ?? ""))), features.export ? features.export.baseName : "table"),
2246
+ children: [
2247
+ /* @__PURE__ */ jsx15(FileText, {}),
2248
+ labels.exportCsv
2249
+ ]
2250
+ }),
2251
+ /* @__PURE__ */ jsxs9(MenubarItem, {
2252
+ disabled: exporting || !exportRows.length,
2253
+ onClick: () => downloadJson(exportRows.map((row) => Object.fromEntries(exportColumns.map((column) => [
2254
+ column.id,
2255
+ getDataTableExportValue(row, column, store.config.locale)
2256
+ ]))), features.export ? features.export.baseName : "table"),
2257
+ children: [
2258
+ /* @__PURE__ */ jsx15(FileJson, {}),
2259
+ labels.exportJson
2260
+ ]
2261
+ })
2262
+ ]
2263
+ }) : null,
2264
+ builtInExport && exportActions.length ? /* @__PURE__ */ jsx15(MenubarSeparator, {}) : null,
2265
+ exportActions.map((action) => /* @__PURE__ */ jsxs9(MenubarItem, {
2266
+ disabled: exporting || action.disabled,
2267
+ onClick: () => void runExport(action),
2268
+ children: [
2269
+ action.icon,
2270
+ action.label
2271
+ ]
2272
+ }, action.id))
2273
+ ]
2274
+ })
2275
+ })
2276
+ ]
2277
+ }) : null
2278
+ ]
2279
+ })
2280
+ }),
2281
+ exportFeature && exportFailed ? /* @__PURE__ */ jsx15("p", {
2282
+ role: "alert",
2283
+ className: "text-destructive text-sm",
2284
+ children: labels.exportFailed ?? dataTableMessages(store.config.locale).exportFailed
2285
+ }) : null
2286
+ ]
2287
+ });
2288
+ };
2289
+ var withColumnFilter = (state, id, filter) => {
2290
+ const filters = (state.filters ?? []).filter((current) => current.id !== id);
2291
+ if (filter)
2292
+ filters.push(filter);
2293
+ return { ...state, page: 0, filters: filters.length ? filters : undefined };
2294
+ };
2295
+ var FilterEditor = ({
2296
+ column,
2297
+ rows,
2298
+ current,
2299
+ labels,
2300
+ onChange
2301
+ }) => {
2302
+ const inputId = useId2();
2303
+ const kind = getDataTableFilterKind(column);
2304
+ const [primary, setPrimary] = useState(current?.kind === "text" ? current.value : current?.kind === "number" ? String(current.min ?? "") : current?.kind === "date" ? current.from ?? "" : "");
2305
+ const [secondary, setSecondary] = useState(current?.kind === "number" ? String(current.max ?? "") : current?.kind === "date" ? current.to ?? "" : "");
2306
+ const [operator, setOperator] = useState(current?.kind === "text" ? current.operator : "contains");
2307
+ const operatorOptions = [
2308
+ { value: "contains", label: labels.filterContains },
2309
+ { value: "equals", label: labels.filterEquals },
2310
+ { value: "startsWith", label: labels.filterStartsWith },
2311
+ { value: "endsWith", label: labels.filterEndsWith }
2312
+ ];
2313
+ const [invalid, setInvalid] = useState(false);
2314
+ const [optionSearch, setOptionSearch] = useState("");
2315
+ const apply = (candidate) => {
2316
+ const decoded = Schema2.decodeUnknownOption(ColumnFilter)(candidate);
2317
+ if (Option2.isNone(decoded)) {
2318
+ setInvalid(true);
2319
+ return;
2320
+ }
2321
+ setInvalid(false);
2322
+ onChange(decoded.value);
2323
+ };
2324
+ if (kind === "boolean") {
2325
+ return /* @__PURE__ */ jsxs9(MenubarGroup, {
2326
+ children: [
2327
+ /* @__PURE__ */ jsxs9(MenubarRadioGroup, {
2328
+ value: current?.kind === "boolean" ? String(current.value) : "",
2329
+ onValueChange: (value) => apply({ id: column.id, kind, value: value === "true" }),
2330
+ children: [
2331
+ /* @__PURE__ */ jsx15(MenubarRadioItem, {
2332
+ value: "true",
2333
+ closeOnClick: false,
2334
+ children: column.colDef.type === "boolean" ? column.colDef.typeOptions?.trueLabel ?? labels.filterTrue : labels.filterTrue
2335
+ }),
2336
+ /* @__PURE__ */ jsx15(MenubarRadioItem, {
2337
+ value: "false",
2338
+ closeOnClick: false,
2339
+ children: column.colDef.type === "boolean" ? column.colDef.typeOptions?.falseLabel ?? labels.filterFalse : labels.filterFalse
2340
+ })
2341
+ ]
2342
+ }),
2343
+ /* @__PURE__ */ jsx15(MenubarSeparator, {}),
2344
+ /* @__PURE__ */ jsx15(MenubarItem, {
2345
+ closeOnClick: false,
2346
+ onClick: () => onChange(undefined),
2347
+ children: labels.filterClear
2348
+ })
2349
+ ]
2350
+ });
2351
+ }
2352
+ if (kind === "values") {
2353
+ const selected = current?.kind === "values" ? current.values : [];
2354
+ const options = getDataTableFilterOptions(rows, column);
2355
+ const filteredOptions = options.filter((option) => option.label.toLocaleLowerCase().includes(optionSearch.trim().toLocaleLowerCase()));
2356
+ return /* @__PURE__ */ jsxs9(MenubarGroup, {
2357
+ children: [
2358
+ options.length > 8 ? /* @__PURE__ */ jsx15("div", {
2359
+ className: "p-1",
2360
+ children: /* @__PURE__ */ jsx15(Input, {
2361
+ "aria-label": labels.filter,
2362
+ placeholder: labels.filter,
2363
+ value: optionSearch,
2364
+ onChange: (event) => setOptionSearch(event.target.value),
2365
+ onKeyDown: (event) => {
2366
+ if (event.key !== "Escape")
2367
+ event.stopPropagation();
2368
+ }
2369
+ })
2370
+ }) : null,
2371
+ filteredOptions.map((option) => /* @__PURE__ */ jsxs9(MenubarCheckboxItem, {
2372
+ checked: selected.includes(option.value),
2373
+ closeOnClick: false,
2374
+ onCheckedChange: (checked) => {
2375
+ const values = checked ? [...selected, option.value] : selected.filter((value) => value !== option.value);
2376
+ if (values.length)
2377
+ apply({ id: column.id, kind, values });
2378
+ else
2379
+ onChange(undefined);
2380
+ },
2381
+ children: [
2382
+ /* @__PURE__ */ jsx15("span", {
2383
+ className: "min-w-0 flex-1 truncate",
2384
+ children: option.label
2385
+ }),
2386
+ option.count !== undefined ? /* @__PURE__ */ jsx15(Badge, {
2387
+ variant: "secondary",
2388
+ className: "ml-auto shrink-0",
2389
+ children: option.count
2390
+ }) : null
2391
+ ]
2392
+ }, option.value)),
2393
+ !filteredOptions.length ? /* @__PURE__ */ jsx15("div", {
2394
+ className: "text-muted-foreground px-2 py-1.5 text-sm",
2395
+ children: labels.empty
2396
+ }) : null,
2397
+ /* @__PURE__ */ jsx15(MenubarSeparator, {}),
2398
+ /* @__PURE__ */ jsx15(MenubarItem, {
2399
+ closeOnClick: false,
2400
+ onClick: () => onChange(undefined),
2401
+ children: labels.filterClear
2402
+ })
2403
+ ]
2404
+ });
2405
+ }
2406
+ return /* @__PURE__ */ jsxs9("form", {
2407
+ className: "flex flex-col gap-3 p-2",
2408
+ onKeyDown: (event) => {
2409
+ if (event.key !== "Escape")
2410
+ event.stopPropagation();
2411
+ },
2412
+ onSubmit: (event) => {
2413
+ event.preventDefault();
2414
+ if (kind === "text")
2415
+ apply({ id: column.id, kind, operator, value: primary.trim() });
2416
+ else if (kind === "date")
2417
+ apply({
2418
+ id: column.id,
2419
+ kind,
2420
+ from: primary || undefined,
2421
+ to: secondary || undefined
2422
+ });
2423
+ else {
2424
+ const min = primary ? Schema2.decodeUnknownOption(Schema2.FiniteFromString)(primary) : Option2.some(undefined);
2425
+ const max = secondary ? Schema2.decodeUnknownOption(Schema2.FiniteFromString)(secondary) : Option2.some(undefined);
2426
+ if (Option2.isNone(min) || Option2.isNone(max)) {
2427
+ setInvalid(true);
2428
+ return;
2429
+ }
2430
+ apply({ id: column.id, kind, min: min.value, max: max.value });
2431
+ }
2432
+ },
2433
+ children: [
2434
+ /* @__PURE__ */ jsxs9(FieldGroup, {
2435
+ children: [
2436
+ kind === "text" ? /* @__PURE__ */ jsxs9(Field, {
2437
+ children: [
2438
+ /* @__PURE__ */ jsx15(FieldLabel, {
2439
+ htmlFor: `${inputId}-operator`,
2440
+ children: labels.filterOperator
2441
+ }),
2442
+ /* @__PURE__ */ jsxs9(Select, {
2443
+ items: operatorOptions,
2444
+ value: operator,
2445
+ onValueChange: (value) => {
2446
+ const decoded = Schema2.decodeUnknownOption(TextFilterOperator)(value);
2447
+ if (Option2.isSome(decoded))
2448
+ setOperator(decoded.value);
2449
+ },
2450
+ children: [
2451
+ /* @__PURE__ */ jsx15(SelectTrigger, {
2452
+ id: `${inputId}-operator`,
2453
+ children: /* @__PURE__ */ jsx15(SelectValue, {})
2454
+ }),
2455
+ /* @__PURE__ */ jsx15(SelectContent, {
2456
+ children: /* @__PURE__ */ jsx15(SelectGroup, {
2457
+ children: operatorOptions.map((option) => /* @__PURE__ */ jsx15(SelectItem, {
2458
+ value: option.value,
2459
+ children: option.label
2460
+ }, option.value))
2461
+ })
2462
+ })
2463
+ ]
2464
+ })
2465
+ ]
2466
+ }) : null,
2467
+ /* @__PURE__ */ jsxs9(Field, {
2468
+ "data-invalid": invalid || undefined,
2469
+ children: [
2470
+ /* @__PURE__ */ jsx15(FieldLabel, {
2471
+ htmlFor: `${inputId}-primary`,
2472
+ children: kind === "text" ? labels.filterValue : kind === "date" ? labels.filterFrom : labels.filterMin
2473
+ }),
2474
+ /* @__PURE__ */ jsx15(Input, {
2475
+ id: `${inputId}-primary`,
2476
+ type: kind === "text" ? "text" : kind === "date" ? "date" : "number",
2477
+ step: kind === "number" ? "any" : undefined,
2478
+ value: primary,
2479
+ "aria-invalid": invalid || undefined,
2480
+ onChange: (event) => {
2481
+ setPrimary(event.target.value);
2482
+ setInvalid(false);
2483
+ }
2484
+ })
2485
+ ]
2486
+ }),
2487
+ kind !== "text" ? /* @__PURE__ */ jsxs9(Field, {
2488
+ "data-invalid": invalid || undefined,
2489
+ children: [
2490
+ /* @__PURE__ */ jsx15(FieldLabel, {
2491
+ htmlFor: `${inputId}-secondary`,
2492
+ children: kind === "date" ? labels.filterTo : labels.filterMax
2493
+ }),
2494
+ /* @__PURE__ */ jsx15(Input, {
2495
+ id: `${inputId}-secondary`,
2496
+ type: kind === "date" ? "date" : "number",
2497
+ step: kind === "number" ? "any" : undefined,
2498
+ value: secondary,
2499
+ "aria-invalid": invalid || undefined,
2500
+ onChange: (event) => {
2501
+ setSecondary(event.target.value);
2502
+ setInvalid(false);
2503
+ }
2504
+ })
2505
+ ]
2506
+ }) : null
2507
+ ]
2508
+ }),
2509
+ invalid ? /* @__PURE__ */ jsx15("p", {
2510
+ role: "alert",
2511
+ className: "text-destructive text-sm",
2512
+ children: labels.filterInvalid
2513
+ }) : null,
2514
+ /* @__PURE__ */ jsxs9("div", {
2515
+ className: "flex gap-2",
2516
+ children: [
2517
+ /* @__PURE__ */ jsx15(Button, {
2518
+ type: "submit",
2519
+ size: "sm",
2520
+ children: labels.filterApply
2521
+ }),
2522
+ /* @__PURE__ */ jsx15(Button, {
2523
+ type: "button",
2524
+ size: "sm",
2525
+ variant: "outline",
2526
+ onClick: () => {
2527
+ setPrimary("");
2528
+ setSecondary("");
2529
+ setInvalid(false);
2530
+ onChange(undefined);
2531
+ },
2532
+ children: labels.filterClear
2533
+ })
2534
+ ]
2535
+ })
2536
+ ]
2537
+ });
2538
+ };
2539
+ var FilterMenu = ({
2540
+ tableAtom
2541
+ }) => {
2542
+ const [store, setStore] = useTableAtom(tableAtom);
2543
+ const model = deriveModel(store);
2544
+ const columns = model.columns.flatMap((parent) => getDataTableFilterColumns([parent]).map((column) => ({
2545
+ column,
2546
+ label: column.id === parent.id ? columnLabel(column) : `${columnLabel(parent)} / ${columnLabel(column)}`
2547
+ })));
2548
+ if (!columns.length)
2549
+ return null;
2550
+ const filters = store.state.filters ?? [];
2551
+ const update = (id, filter) => changeState(setStore, (state) => withColumnFilter(state, id, filter));
2552
+ return /* @__PURE__ */ jsxs9(MenubarMenu, {
2553
+ children: [
2554
+ /* @__PURE__ */ jsxs9(MenubarTrigger, {
2555
+ "aria-label": store.config.labels.filters,
2556
+ children: [
2557
+ /* @__PURE__ */ jsx15(ListFilter, {}),
2558
+ /* @__PURE__ */ jsx15("span", {
2559
+ children: store.config.labels.filters
2560
+ }),
2561
+ filters.length ? /* @__PURE__ */ jsx15(Badge, {
2562
+ variant: "secondary",
2563
+ children: filters.length
2564
+ }) : null
2565
+ ]
2566
+ }),
2567
+ /* @__PURE__ */ jsx15(MenubarContent, {
2568
+ align: "end",
2569
+ className: "w-80 max-w-[calc(100vw-2rem)]",
2570
+ children: /* @__PURE__ */ jsxs9(MenubarGroup, {
2571
+ children: [
2572
+ /* @__PURE__ */ jsx15(MenubarLabel, {
2573
+ children: store.config.labels.filters
2574
+ }),
2575
+ /* @__PURE__ */ jsx15(MenubarSeparator, {}),
2576
+ columns.map(({ column, label }) => /* @__PURE__ */ jsxs9(MenubarSub, {
2577
+ children: [
2578
+ /* @__PURE__ */ jsxs9(MenubarSubTrigger, {
2579
+ children: [
2580
+ /* @__PURE__ */ jsx15("span", {
2581
+ className: "min-w-0 flex-1 truncate",
2582
+ children: label
2583
+ }),
2584
+ filters.some((filter) => filter.id === column.id) ? /* @__PURE__ */ jsx15(Check, {}) : null
2585
+ ]
2586
+ }),
2587
+ /* @__PURE__ */ jsx15(MenubarSubContent, {
2588
+ className: "w-80 max-w-[calc(100vw-2rem)]",
2589
+ children: /* @__PURE__ */ jsx15(FilterEditor, {
2590
+ column,
2591
+ rows: model.rows,
2592
+ current: filters.find((filter) => filter.id === column.id),
2593
+ labels: store.config.labels,
2594
+ onChange: (filter) => update(column.id, filter)
2595
+ })
2596
+ })
2597
+ ]
2598
+ }, column.id)),
2599
+ filters.length ? /* @__PURE__ */ jsxs9(Fragment, {
2600
+ children: [
2601
+ /* @__PURE__ */ jsx15(MenubarSeparator, {}),
2602
+ /* @__PURE__ */ jsxs9(MenubarItem, {
2603
+ onClick: () => changeState(setStore, (state) => ({
2604
+ ...state,
2605
+ page: 0,
2606
+ filters: undefined
2607
+ })),
2608
+ children: [
2609
+ /* @__PURE__ */ jsx15(X, {}),
2610
+ store.config.labels.filtersClear
2611
+ ]
2612
+ })
2613
+ ]
2614
+ }) : null
2615
+ ]
2616
+ })
2617
+ })
2618
+ ]
2619
+ });
2620
+ };
2621
+ var SortMenu = ({
2622
+ tableAtom
2623
+ }) => {
2624
+ const [store, setStore] = useTableAtom(tableAtom);
2625
+ const columns = deriveModel(store).columns.flatMap((column) => getDataTableSortColumns([column]).map((field) => field.id === column.id ? field : {
2626
+ ...field,
2627
+ colDef: {
2628
+ ...field.colDef,
2629
+ headerName: `${columnLabel(column)} / ${columnLabel(field)}`
2630
+ }
2631
+ }));
2632
+ if (!columns.length)
2633
+ return null;
2634
+ const current = store.state.sort?.[0];
2635
+ const sort = (id, direction) => changeState(setStore, (state) => ({
2636
+ ...state,
2637
+ sort: [{ id, direction }],
2638
+ page: 0
2639
+ }));
2640
+ return /* @__PURE__ */ jsxs9(MenubarMenu, {
2641
+ children: [
2642
+ /* @__PURE__ */ jsxs9(MenubarTrigger, {
2643
+ "aria-label": store.config.labels.sortBy,
2644
+ children: [
2645
+ current ? current.direction === "desc" ? /* @__PURE__ */ jsx15(ArrowDown, {}) : /* @__PURE__ */ jsx15(ArrowUp, {}) : /* @__PURE__ */ jsx15(ChevronsUpDown, {}),
2646
+ /* @__PURE__ */ jsx15("span", {
2647
+ className: "hidden sm:inline",
2648
+ children: store.config.labels.sortBy
2649
+ })
2650
+ ]
2651
+ }),
2652
+ /* @__PURE__ */ jsx15(MenubarContent, {
2653
+ align: "end",
2654
+ className: "w-52",
2655
+ children: /* @__PURE__ */ jsxs9(MenubarGroup, {
2656
+ children: [
2657
+ /* @__PURE__ */ jsx15(MenubarLabel, {
2658
+ children: store.config.labels.sortBy
2659
+ }),
2660
+ /* @__PURE__ */ jsx15(MenubarSeparator, {}),
2661
+ columns.map((column) => {
2662
+ const sortState = store.state.sort?.find(({ id }) => id === column.id);
2663
+ return /* @__PURE__ */ jsxs9(MenubarSub, {
2664
+ children: [
2665
+ /* @__PURE__ */ jsxs9(MenubarSubTrigger, {
2666
+ children: [
2667
+ sortState ? sortState.direction === "desc" ? /* @__PURE__ */ jsx15(ArrowDown, {}) : /* @__PURE__ */ jsx15(ArrowUp, {}) : null,
2668
+ columnLabel(column)
2669
+ ]
2670
+ }),
2671
+ /* @__PURE__ */ jsxs9(MenubarSubContent, {
2672
+ children: [
2673
+ /* @__PURE__ */ jsxs9(MenubarItem, {
2674
+ onClick: () => sort(column.id, "asc"),
2675
+ children: [
2676
+ /* @__PURE__ */ jsx15(ArrowUp, {}),
2677
+ " ",
2678
+ store.config.labels.sortAsc
2679
+ ]
2680
+ }),
2681
+ /* @__PURE__ */ jsxs9(MenubarItem, {
2682
+ onClick: () => sort(column.id, "desc"),
2683
+ children: [
2684
+ /* @__PURE__ */ jsx15(ArrowDown, {}),
2685
+ " ",
2686
+ store.config.labels.sortDesc
2687
+ ]
2688
+ }),
2689
+ sortState ? /* @__PURE__ */ jsxs9(Fragment, {
2690
+ children: [
2691
+ /* @__PURE__ */ jsx15(MenubarSeparator, {}),
2692
+ /* @__PURE__ */ jsxs9(MenubarItem, {
2693
+ onClick: () => changeState(setStore, (state) => ({
2694
+ ...state,
2695
+ sort: state.sort?.filter(({ id }) => id !== column.id)
2696
+ })),
2697
+ children: [
2698
+ /* @__PURE__ */ jsx15(X, {}),
2699
+ " ",
2700
+ store.config.labels.sortClear
2701
+ ]
2702
+ })
2703
+ ]
2704
+ }) : null
2705
+ ]
2706
+ })
2707
+ ]
2708
+ }, column.id);
2709
+ })
2710
+ ]
2711
+ })
2712
+ })
2713
+ ]
2714
+ });
2715
+ };
2716
+ var ViewMenu = ({
2717
+ tableAtom
2718
+ }) => {
2719
+ const [store, setStore] = useTableAtom(tableAtom);
2720
+ return /* @__PURE__ */ jsxs9(MenubarMenu, {
2721
+ children: [
2722
+ /* @__PURE__ */ jsxs9(MenubarTrigger, {
2723
+ "aria-label": store.config.labels.view,
2724
+ children: [
2725
+ store.state.view === "gallery" ? /* @__PURE__ */ jsx15(LayoutGrid, {}) : /* @__PURE__ */ jsx15(Rows3, {}),
2726
+ /* @__PURE__ */ jsx15("span", {
2727
+ className: "hidden sm:inline",
2728
+ children: store.config.labels.view
2729
+ })
2730
+ ]
2731
+ }),
2732
+ /* @__PURE__ */ jsx15(MenubarContent, {
2733
+ align: "end",
2734
+ children: /* @__PURE__ */ jsxs9(MenubarGroup, {
2735
+ children: [
2736
+ /* @__PURE__ */ jsx15(MenubarLabel, {
2737
+ children: store.config.labels.view
2738
+ }),
2739
+ /* @__PURE__ */ jsx15(MenubarSeparator, {}),
2740
+ /* @__PURE__ */ jsxs9(MenubarRadioGroup, {
2741
+ onValueChange: (view) => {
2742
+ if (view === "table" || view === "gallery") {
2743
+ changeState(setStore, (state) => ({ ...state, view }));
2744
+ }
2745
+ },
2746
+ value: store.state.view,
2747
+ children: [
2748
+ /* @__PURE__ */ jsxs9(MenubarRadioItem, {
2749
+ value: "table",
2750
+ children: [
2751
+ /* @__PURE__ */ jsx15(Rows3, {}),
2752
+ " ",
2753
+ store.config.labels.tableView
2754
+ ]
2755
+ }),
2756
+ /* @__PURE__ */ jsxs9(MenubarRadioItem, {
2757
+ value: "gallery",
2758
+ children: [
2759
+ /* @__PURE__ */ jsx15(LayoutGrid, {}),
2760
+ " ",
2761
+ store.config.labels.galleryView
2762
+ ]
2763
+ })
2764
+ ]
2765
+ })
2766
+ ]
2767
+ })
2768
+ })
2769
+ ]
2770
+ });
2771
+ };
2772
+ var ColumnMenu = ({
2773
+ tableAtom
2774
+ }) => {
2775
+ const [store, setStore] = useTableAtom(tableAtom);
2776
+ const columns = deriveModel(store).columns.filter(({ colDef }) => colDef.hideable !== false);
2777
+ if (!columns.length)
2778
+ return null;
2779
+ return /* @__PURE__ */ jsxs9(MenubarMenu, {
2780
+ children: [
2781
+ /* @__PURE__ */ jsxs9(MenubarTrigger, {
2782
+ "aria-label": store.config.labels.columns,
2783
+ children: [
2784
+ /* @__PURE__ */ jsx15(Settings2, {}),
2785
+ /* @__PURE__ */ jsx15("span", {
2786
+ className: "hidden sm:inline",
2787
+ children: store.config.labels.columns
2788
+ })
2789
+ ]
2790
+ }),
2791
+ /* @__PURE__ */ jsx15(MenubarContent, {
2792
+ align: "end",
2793
+ children: /* @__PURE__ */ jsxs9(MenubarGroup, {
2794
+ children: [
2795
+ /* @__PURE__ */ jsx15(MenubarLabel, {
2796
+ children: store.config.labels.columns
2797
+ }),
2798
+ /* @__PURE__ */ jsx15(MenubarSeparator, {}),
2799
+ columns.map((column) => /* @__PURE__ */ jsx15(MenubarCheckboxItem, {
2800
+ checked: store.state.columnVisibility[column.id] !== false,
2801
+ onCheckedChange: (visible) => changeState(setStore, (state) => ({
2802
+ ...state,
2803
+ columnVisibility: {
2804
+ ...state.columnVisibility,
2805
+ [column.id]: visible
2806
+ }
2807
+ })),
2808
+ children: columnLabel(column)
2809
+ }, column.id))
2810
+ ]
2811
+ })
2812
+ })
2813
+ ]
2814
+ });
2815
+ };
2816
+ var ResizeHandle = ({
2817
+ tableAtom
2818
+ }) => {
2819
+ const [store, setStore] = useTableAtom(tableAtom);
2820
+ const columnId = useRequiredId(ColumnIdContext);
2821
+ const resizeRef = useRef(null);
2822
+ const column = deriveModel(store).columns.find(({ id }) => id === columnId);
2823
+ if (!column || column.colDef.resizable === false)
2824
+ return null;
2825
+ const resize = (width) => changeState(setStore, (state) => ({
2826
+ ...state,
2827
+ columnSizing: {
2828
+ ...state.columnSizing,
2829
+ [column.id]: clampWidth(column.colDef, width)
2830
+ }
2831
+ }));
2832
+ const onPointerDown = (event) => {
2833
+ if (event.button !== 0)
2834
+ return;
2835
+ event.preventDefault();
2836
+ event.currentTarget.setPointerCapture(event.pointerId);
2837
+ resizeRef.current = {
2838
+ pointerId: event.pointerId,
2839
+ startX: event.clientX,
2840
+ startWidth: column.width
2841
+ };
2842
+ };
2843
+ const onPointerMove = (event) => {
2844
+ const drag = resizeRef.current;
2845
+ if (!drag || drag.pointerId !== event.pointerId)
2846
+ return;
2847
+ resize(drag.startWidth + event.clientX - drag.startX);
2848
+ };
2849
+ const reset = () => {
2850
+ resizeRef.current = null;
2851
+ };
2852
+ return /* @__PURE__ */ jsx15("button", {
2853
+ "aria-label": store.config.labels.resizeColumn(columnLabel(column)),
2854
+ "aria-orientation": "vertical",
2855
+ "aria-valuemax": column.colDef.maxWidth ?? DEFAULT_MAX_WIDTH,
2856
+ "aria-valuemin": column.colDef.minWidth ?? DEFAULT_MIN_WIDTH,
2857
+ "aria-valuenow": column.width,
2858
+ 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",
2859
+ onDoubleClick: () => resize(column.colDef.width ?? DEFAULT_WIDTH),
2860
+ onKeyDown: (event) => {
2861
+ const delta = event.key === "ArrowLeft" ? -8 : event.key === "ArrowRight" ? 8 : 0;
2862
+ if (delta) {
2863
+ event.preventDefault();
2864
+ resize(column.width + delta);
2865
+ }
2866
+ },
2867
+ onPointerDown,
2868
+ onPointerMove,
2869
+ onPointerUp: reset,
2870
+ onPointerCancel: reset,
2871
+ onLostPointerCapture: reset,
2872
+ role: "separator",
2873
+ type: "button"
2874
+ });
2875
+ };
2876
+ var DragHandle = ({
2877
+ tableAtom
2878
+ }) => {
2879
+ const [store, setStore] = useTableAtom(tableAtom);
2880
+ const rowId = useRequiredId(RowIdContext);
2881
+ const dragRef = useRef(null);
2882
+ const [overlay, setOverlay] = useState(null);
2883
+ const reset = (element) => {
2884
+ clearDragPresentation(element.closest("[data-table-root]"));
2885
+ dragRef.current = null;
2886
+ setOverlay(null);
2887
+ };
2888
+ const onPointerDown = (event) => {
2889
+ event.stopPropagation();
2890
+ event.currentTarget.setPointerCapture(event.pointerId);
2891
+ const row = deriveModel(store).rows.find((candidate) => candidate.id === rowId);
2892
+ const grouping = store.config.features.grouping;
2893
+ const reordering = store.config.features.reordering;
2894
+ dragRef.current = {
2895
+ pointerId: event.pointerId,
2896
+ rowId,
2897
+ label: row && grouping && grouping.getRowLabel?.(row.data) || row && reordering && reordering.getRowLabel?.(row.data) || rowId,
2898
+ startX: event.clientX,
2899
+ startY: event.clientY,
2900
+ active: false
2901
+ };
2902
+ };
2903
+ const onPointerMove = (event) => {
2904
+ const drag = dragRef.current;
2905
+ if (!drag || drag.pointerId !== event.pointerId)
2906
+ return;
2907
+ const root = event.currentTarget.closest("[data-table-root]");
2908
+ const active = drag.active || Math.hypot(event.clientX - drag.startX, event.clientY - drag.startY) >= 8;
2909
+ drag.active = active;
2910
+ clearDragPresentation(root);
2911
+ if (!active)
2912
+ return;
2913
+ const elements = document.elementsFromPoint(event.clientX, event.clientY);
2914
+ const rowTarget = findTableDragTarget(elements, "[data-table-row]", root);
2915
+ const groupTarget = findTableDragTarget(elements, "[data-table-group]", root);
2916
+ event.currentTarget.closest("[data-table-row]")?.setAttribute("data-drag-source", "true");
2917
+ if (canMoveRowsToGroups(store)) {
2918
+ groupTarget?.setAttribute("data-drop-target", "true");
2919
+ } else if (rowTarget?.dataset.tableRow !== drag.rowId) {
2920
+ const rows = deriveModel(store).pageRows;
2921
+ const sourceIndex = rows.findIndex((row) => row.id === drag.rowId);
2922
+ const targetIndex = rows.findIndex((row) => row.id === rowTarget?.dataset.tableRow);
2923
+ if (sourceIndex !== -1 && targetIndex !== -1) {
2924
+ rowTarget?.setAttribute("data-drop-position", sourceIndex < targetIndex ? "after" : "before");
2925
+ }
2926
+ }
2927
+ setOverlay({ label: drag.label, x: event.clientX, y: event.clientY });
2928
+ };
2929
+ const finish = (event) => {
2930
+ const drag = dragRef.current;
2931
+ if (!drag || drag.pointerId !== event.pointerId)
2932
+ return;
2933
+ const root = event.currentTarget.closest("[data-table-root]");
2934
+ const elements = document.elementsFromPoint(event.clientX, event.clientY);
2935
+ const rowTarget = findTableDragTarget(elements, "[data-table-row]", root);
2936
+ const groupTarget = findTableDragTarget(elements, "[data-table-group]", root);
2937
+ setStore((current) => {
2938
+ const targetRowId = rowTarget?.dataset.tableRow;
2939
+ const targetGroupKey = groupTarget?.dataset.tableGroup;
2940
+ const model = deriveModel(current);
2941
+ const source = model.sortedRows.find((row) => row.id === drag.rowId);
2942
+ const grouping = current.config.features.grouping;
2943
+ const reordering = current.config.features.reordering;
2944
+ if (drag.active && source && targetGroupKey && grouping) {
2945
+ const target = parseGroupDropKey(targetGroupKey);
2946
+ const field = grouping.fields.find(({ id }) => id === target?.fieldId);
2947
+ if (target && field?.onMoveToGroup && field.getGroupId(source.data) !== target.groupId) {
2948
+ field.onMoveToGroup(source.data, target.groupId);
2949
+ }
2950
+ } else if (drag.active && source && targetRowId && reordering && canReorderRows(current) && source.id !== targetRowId) {
2951
+ reordering.onReorder(reorderDataTableRows(model.rows, source.id, targetRowId));
2952
+ }
2953
+ return current;
2954
+ });
2955
+ reset(event.currentTarget);
2956
+ };
2957
+ const cancel = (event) => {
2958
+ if (dragRef.current?.pointerId === event.pointerId) {
2959
+ reset(event.currentTarget);
2960
+ }
2961
+ };
2962
+ const reorderWithKeyboard = (direction) => {
2963
+ const reordering = store.config.features.reordering;
2964
+ if (!reordering || !canReorderRows(store))
2965
+ return;
2966
+ const model = deriveModel(store);
2967
+ const visibleRows = model.pageRows;
2968
+ const sourceIndex = visibleRows.findIndex((row) => row.id === rowId);
2969
+ const target = visibleRows[sourceIndex + direction];
2970
+ if (sourceIndex !== -1 && target) {
2971
+ reordering.onReorder(reorderDataTableRows(model.rows, rowId, target.id));
2972
+ }
2973
+ };
2974
+ return /* @__PURE__ */ jsxs9(Fragment, {
2975
+ children: [
2976
+ /* @__PURE__ */ jsx15(Button, {
2977
+ "aria-label": store.config.features.reordering && store.config.features.reordering.handleLabel ? store.config.features.reordering.handleLabel : store.config.labels.reorder,
2978
+ className: "size-8 cursor-grab touch-none active:cursor-grabbing",
2979
+ onClick: (event) => event.stopPropagation(),
2980
+ onKeyDown: (event) => {
2981
+ if (event.key === "ArrowUp" || event.key === "ArrowDown") {
2982
+ event.preventDefault();
2983
+ event.stopPropagation();
2984
+ reorderWithKeyboard(event.key === "ArrowUp" ? -1 : 1);
2985
+ }
2986
+ },
2987
+ onPointerCancel: cancel,
2988
+ onPointerDown,
2989
+ onLostPointerCapture: cancel,
2990
+ onPointerMove,
2991
+ onPointerUp: finish,
2992
+ size: "icon",
2993
+ variant: "ghost",
2994
+ children: /* @__PURE__ */ jsx15(GripVertical, {})
2995
+ }),
2996
+ overlay ? createPortal(/* @__PURE__ */ jsx15("div", {
2997
+ "aria-hidden": "true",
2998
+ className: "bg-background pointer-events-none fixed z-[100] rounded-md border px-3 py-2 text-sm shadow-lg",
2999
+ style: { left: overlay.x + 12, top: overlay.y + 12 },
3000
+ children: overlay.label
3001
+ }), document.body) : null
3002
+ ]
3003
+ });
3004
+ };
3005
+ var toggleRow = (store, setStore, rowId, selected) => changeState(setStore, (state) => {
3006
+ const rowSelection = { ...state.rowSelection, [rowId]: selected };
3007
+ const selection = store.config.features.selection;
3008
+ if (selection) {
3009
+ const model = deriveModel(store);
3010
+ selection.onSelectionChange?.(model.rows.filter((row) => rowSelection[row.id]).map((row) => row.data));
3011
+ }
3012
+ return { ...state, rowSelection };
3013
+ });
3014
+ var TableDataRow = ({
3015
+ tableAtom
3016
+ }) => {
3017
+ const [store, setStore] = useTableAtom(tableAtom);
3018
+ const rowId = useRequiredId(RowIdContext);
3019
+ const model = deriveModel(store);
3020
+ const row = model.sortedRows.find((candidate) => candidate.id === rowId);
3021
+ if (!row)
3022
+ return null;
3023
+ const selection = store.config.features.selection;
3024
+ const selectable = !!selection && (selection.isRowSelectable?.(row.data) ?? true);
3025
+ const draggable = canDragRows(store);
3026
+ return /* @__PURE__ */ jsxs9(TableRow, {
3027
+ className: cn("group/row data-[drop-position=before]:[&>td]:border-primary data-[drop-position=after]:[&>td]:border-primary h-16 data-[drag-source=true]:opacity-40 data-[drop-position=after]:[&>td]:border-b-2 data-[drop-position=before]:[&>td]:border-t-2", store.config.onRowClicked && "cursor-pointer"),
3028
+ "data-state": store.state.rowSelection[row.id] && "selected",
3029
+ "data-table-row": row.id,
3030
+ onClick: () => store.config.onRowClicked?.(row.data),
3031
+ onKeyDown: (event) => {
3032
+ if (event.target === event.currentTarget && store.config.onRowClicked && (event.key === "Enter" || event.key === " ")) {
3033
+ event.preventDefault();
3034
+ store.config.onRowClicked(row.data);
3035
+ }
3036
+ },
3037
+ tabIndex: store.config.onRowClicked ? 0 : undefined,
3038
+ children: [
3039
+ selection ? /* @__PURE__ */ jsx15(TableCell, {
3040
+ className: "w-10 pr-0",
3041
+ onClick: (event) => event.stopPropagation(),
3042
+ children: /* @__PURE__ */ jsx15(Checkbox, {
3043
+ "aria-label": store.config.labels.selectRow,
3044
+ checked: !!store.state.rowSelection[row.id],
3045
+ disabled: !selectable,
3046
+ onCheckedChange: (checked) => toggleRow(store, setStore, row.id, checked)
3047
+ })
3048
+ }) : null,
3049
+ draggable ? /* @__PURE__ */ jsx15(TableCell, {
3050
+ className: "w-10 pr-0",
3051
+ children: /* @__PURE__ */ jsx15(DragHandle, {
3052
+ tableAtom
3053
+ })
3054
+ }) : null,
3055
+ model.visibleColumns.map((column) => /* @__PURE__ */ jsx15(TableCell, {
3056
+ className: cn("min-w-24 overflow-hidden has-[[data-slot=data-table-boolean-cell]]:relative has-[[data-slot=data-table-boolean-cell]]:p-0 has-[[data-slot=data-table-list-cell]]:relative has-[[data-slot=data-table-list-cell]]:p-0", column.colDef.truncate ? "whitespace-nowrap" : "whitespace-normal"),
3057
+ style: { width: column.width },
3058
+ children: /* @__PURE__ */ jsx15("div", {
3059
+ className: cn("min-w-0", column.colDef.truncate && "truncate"),
3060
+ children: renderCell(row, column, store.config.locale, store.config.labels)
3061
+ })
3062
+ }, column.id)),
3063
+ hasRowActionMenu(store) ? /* @__PURE__ */ jsx15(TableCell, {
3064
+ 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))]",
3065
+ onClick: (event) => event.stopPropagation(),
3066
+ children: /* @__PURE__ */ jsx15("div", {
3067
+ className: "flex h-16 items-center justify-center",
3068
+ children: /* @__PURE__ */ jsx15(DataTableRowActionMenu, {
3069
+ tableAtom
3070
+ })
3071
+ })
3072
+ }) : null
3073
+ ]
3074
+ });
3075
+ };
3076
+ var GroupActions = ({
3077
+ actions,
3078
+ groupId,
3079
+ title
3080
+ }) => {
3081
+ const visible = actions?.filter((action) => !action.visible || action.visible(groupId));
3082
+ if (!visible?.length)
3083
+ return null;
3084
+ return /* @__PURE__ */ jsxs9(DropdownMenu, {
3085
+ children: [
3086
+ /* @__PURE__ */ jsx15(DropdownMenuTrigger, {
3087
+ onClick: (event) => event.stopPropagation(),
3088
+ render: /* @__PURE__ */ jsxs9(Button, {
3089
+ size: "icon",
3090
+ variant: "ghost",
3091
+ children: [
3092
+ /* @__PURE__ */ jsx15("span", {
3093
+ className: "sr-only",
3094
+ children: title
3095
+ }),
3096
+ /* @__PURE__ */ jsx15(MoreHorizontal, {})
3097
+ ]
3098
+ })
3099
+ }),
3100
+ /* @__PURE__ */ jsx15(DropdownMenuContent, {
3101
+ align: "end",
3102
+ children: /* @__PURE__ */ jsx15(DropdownMenuGroup, {
3103
+ children: visible.map((action) => /* @__PURE__ */ jsxs9(DropdownMenuItem, {
3104
+ onClick: () => action.onClick(groupId),
3105
+ variant: action.variant ?? "default",
3106
+ children: [
3107
+ action.icon,
3108
+ " ",
3109
+ action.name
3110
+ ]
3111
+ }, action.name))
3112
+ })
3113
+ })
3114
+ ]
3115
+ });
3116
+ };
3117
+ var GroupedTable = ({
3118
+ tableAtom,
3119
+ sections
3120
+ }) => {
3121
+ const [store, setStore] = useTableAtom(tableAtom);
3122
+ const model = deriveModel(store);
3123
+ const extra = (store.config.features.selection ? 1 : 0) + (hasRowActionMenu(store) ? 1 : 0) + (canDragRows(store) ? 1 : 0);
3124
+ const renderSections = (items) => items.flatMap((section) => {
3125
+ const collapsed = !!store.state.collapsedGroups[section.key];
3126
+ const targetKey = getGroupDropKey(section.field.id, section.groupId);
3127
+ const toggleCollapsed = () => changeState(setStore, (state) => ({
3128
+ ...state,
3129
+ collapsedGroups: {
3130
+ ...state.collapsedGroups,
3131
+ [section.key]: !collapsed
3132
+ }
3133
+ }));
3134
+ const body = /* @__PURE__ */ jsxs9(TableBody, {
3135
+ 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",
3136
+ "data-table-group": section.field.onMoveToGroup ? targetKey : undefined,
3137
+ children: [
3138
+ /* @__PURE__ */ jsx15(TableRow, {
3139
+ className: "bg-muted/40 hover:bg-accent! cursor-pointer",
3140
+ onClick: toggleCollapsed,
3141
+ children: /* @__PURE__ */ jsx15(TableCell, {
3142
+ colSpan: model.visibleColumns.length + extra,
3143
+ children: /* @__PURE__ */ jsxs9("div", {
3144
+ className: "flex items-center gap-2",
3145
+ style: { paddingLeft: section.depth * 20 },
3146
+ children: [
3147
+ /* @__PURE__ */ jsxs9("button", {
3148
+ "aria-expanded": !collapsed,
3149
+ className: "flex flex-1 cursor-pointer items-center gap-2 text-left font-medium",
3150
+ type: "button",
3151
+ children: [
3152
+ collapsed ? /* @__PURE__ */ jsx15(ChevronRight2, {
3153
+ className: "size-4"
3154
+ }) : /* @__PURE__ */ jsx15(ChevronDown, {
3155
+ className: "size-4"
3156
+ }),
3157
+ /* @__PURE__ */ jsx15("span", {
3158
+ className: "flex-1",
3159
+ children: section.field.renderGroupLabel?.(section.groupId, section.rows.map((row) => row.data)) ?? section.groupId
3160
+ })
3161
+ ]
3162
+ }),
3163
+ /* @__PURE__ */ jsx15(Badge, {
3164
+ variant: "secondary",
3165
+ children: section.rows.length
3166
+ }),
3167
+ /* @__PURE__ */ jsx15(GroupActions, {
3168
+ actions: section.field.actions,
3169
+ groupId: section.groupId,
3170
+ title: section.field.actionsLabel ?? store.config.labels.actions
3171
+ })
3172
+ ]
3173
+ })
3174
+ })
3175
+ }),
3176
+ !collapsed && !section.children.length ? section.rows.length ? section.rows.map((row) => /* @__PURE__ */ jsx15(RowIdContext.Provider, {
3177
+ value: row.id,
3178
+ children: /* @__PURE__ */ jsx15(TableDataRow, {
3179
+ tableAtom
3180
+ })
3181
+ }, `${section.key}:${row.id}`)) : [
3182
+ /* @__PURE__ */ jsx15(TableRow, {
3183
+ children: /* @__PURE__ */ jsx15(TableCell, {
3184
+ className: "text-muted-foreground h-16",
3185
+ colSpan: model.visibleColumns.length + extra,
3186
+ children: section.field.renderEmptyGroup?.(section.groupId) ?? store.config.labels.empty
3187
+ })
3188
+ }, `${section.key}:empty`)
3189
+ ] : null
3190
+ ]
3191
+ }, section.key);
3192
+ return !collapsed && section.children.length ? [body, renderSections(section.children)] : [body];
3193
+ });
3194
+ return /* @__PURE__ */ jsx15(Fragment, {
3195
+ children: renderSections(sections)
3196
+ });
3197
+ };
3198
+ var ColumnHeaderMenu = ({
3199
+ tableAtom
3200
+ }) => {
3201
+ const [store, setStore] = useTableAtom(tableAtom);
3202
+ const columnId = useRequiredId(ColumnIdContext);
3203
+ const model = deriveModel(store);
3204
+ const column = model.columns.find(({ id }) => id === columnId);
3205
+ if (!column)
3206
+ return null;
3207
+ const sortColumns = getDataTableSortColumns([column]);
3208
+ const filterColumns = getDataTableFilterColumns([column]);
3209
+ const filteringEnabled = store.config.features.filtering !== false && filterColumns.length > 0;
3210
+ const ownsFilter = (id) => id === column.id || getDataTableFieldColumns(column).some((field) => field.id === id);
3211
+ const activeFilters = (store.state.filters ?? []).filter(({ id }) => ownsFilter(id));
3212
+ const filterEditor = (field) => /* @__PURE__ */ jsx15(FilterEditor, {
3213
+ column: field,
3214
+ rows: model.rows,
3215
+ current: store.state.filters?.find((filter) => filter.id === field.id),
3216
+ labels: store.config.labels,
3217
+ onChange: (filter) => changeState(setStore, (state) => withColumnFilter(state, field.id, filter))
3218
+ });
3219
+ const sortingEnabled = store.config.features.sorting !== false && sortColumns.length > 0;
3220
+ const hidingEnabled = store.config.features.columnVisibility !== false && column.colDef.hideable !== false;
3221
+ const ownsSort = (id) => id === column.id || sortColumns.some((field) => field.id === id);
3222
+ const sort = store.state.sort?.find(({ id }) => ownsSort(id));
3223
+ const update = (next) => changeState(setStore, next);
3224
+ const setSort = (id, direction) => update((state) => ({
3225
+ ...state,
3226
+ sort: [{ id, direction }],
3227
+ page: 0
3228
+ }));
3229
+ const label = columnLabel(column);
3230
+ const sortItems = (field) => /* @__PURE__ */ jsxs9(Fragment, {
3231
+ children: [
3232
+ /* @__PURE__ */ jsxs9(DropdownMenuItem, {
3233
+ onClick: () => setSort(field.id, "asc"),
3234
+ children: [
3235
+ /* @__PURE__ */ jsx15(ArrowUp, {}),
3236
+ " ",
3237
+ store.config.labels.sortAsc
3238
+ ]
3239
+ }),
3240
+ /* @__PURE__ */ jsxs9(DropdownMenuItem, {
3241
+ onClick: () => setSort(field.id, "desc"),
3242
+ children: [
3243
+ /* @__PURE__ */ jsx15(ArrowDown, {}),
3244
+ " ",
3245
+ store.config.labels.sortDesc
3246
+ ]
3247
+ })
3248
+ ]
3249
+ });
3250
+ if (!sortingEnabled && !hidingEnabled && !filteringEnabled) {
3251
+ return /* @__PURE__ */ jsx15("div", {
3252
+ className: "truncate px-2",
3253
+ children: column.colDef.headerName
3254
+ });
3255
+ }
3256
+ return /* @__PURE__ */ jsxs9(DropdownMenu, {
3257
+ children: [
3258
+ /* @__PURE__ */ jsx15(DropdownMenuTrigger, {
3259
+ render: /* @__PURE__ */ jsxs9(Button, {
3260
+ "aria-label": label,
3261
+ "aria-description": activeFilters.length ? `${store.config.labels.filters}: ${activeFilters.length}` : undefined,
3262
+ className: "absolute inset-0 h-full w-full min-w-0 justify-start rounded-none px-2 pr-4 focus-visible:ring-inset",
3263
+ variant: "ghost",
3264
+ children: [
3265
+ /* @__PURE__ */ jsx15("span", {
3266
+ className: "truncate",
3267
+ children: column.colDef.headerName
3268
+ }),
3269
+ activeFilters.length ? /* @__PURE__ */ jsx15(ListFilter, {}) : null,
3270
+ sort ? sort.direction === "desc" ? /* @__PURE__ */ jsx15(ArrowDown, {}) : /* @__PURE__ */ jsx15(ArrowUp, {}) : null
3271
+ ]
3272
+ })
3273
+ }),
3274
+ /* @__PURE__ */ jsx15(DropdownMenuContent, {
3275
+ align: "start",
3276
+ className: "w-48",
3277
+ children: /* @__PURE__ */ jsxs9(DropdownMenuGroup, {
3278
+ children: [
3279
+ sortingEnabled ? /* @__PURE__ */ jsxs9(Fragment, {
3280
+ children: [
3281
+ column.colDef.fields?.length ? sortColumns.map((field) => /* @__PURE__ */ jsxs9(DropdownMenuSub, {
3282
+ children: [
3283
+ /* @__PURE__ */ jsx15(DropdownMenuSubTrigger, {
3284
+ children: columnLabel(field)
3285
+ }),
3286
+ /* @__PURE__ */ jsx15(DropdownMenuSubContent, {
3287
+ children: /* @__PURE__ */ jsx15(DropdownMenuGroup, {
3288
+ children: sortItems(field)
3289
+ })
3290
+ })
3291
+ ]
3292
+ }, field.id)) : sortItems(column),
3293
+ sort ? /* @__PURE__ */ jsxs9(DropdownMenuItem, {
3294
+ onClick: () => update((state) => ({
3295
+ ...state,
3296
+ sort: state.sort?.filter(({ id }) => !ownsSort(id))
3297
+ })),
3298
+ children: [
3299
+ /* @__PURE__ */ jsx15(X, {}),
3300
+ " ",
3301
+ store.config.labels.sortClear
3302
+ ]
3303
+ }) : null
3304
+ ]
3305
+ }) : null,
3306
+ sortingEnabled && filteringEnabled ? /* @__PURE__ */ jsx15(DropdownMenuSeparator, {}) : null,
3307
+ filteringEnabled ? /* @__PURE__ */ jsxs9(Fragment, {
3308
+ children: [
3309
+ /* @__PURE__ */ jsxs9(DropdownMenuSub, {
3310
+ children: [
3311
+ /* @__PURE__ */ jsxs9(DropdownMenuSubTrigger, {
3312
+ children: [
3313
+ /* @__PURE__ */ jsx15(ListFilter, {}),
3314
+ store.config.labels.filters
3315
+ ]
3316
+ }),
3317
+ /* @__PURE__ */ jsx15(DropdownMenuSubContent, {
3318
+ className: "w-80 max-w-[calc(100vw-2rem)]",
3319
+ children: column.colDef.fields?.length ? /* @__PURE__ */ jsx15(DropdownMenuGroup, {
3320
+ children: filterColumns.map((field) => /* @__PURE__ */ jsxs9(DropdownMenuSub, {
3321
+ children: [
3322
+ /* @__PURE__ */ jsxs9(DropdownMenuSubTrigger, {
3323
+ children: [
3324
+ columnLabel(field),
3325
+ activeFilters.some((filter) => filter.id === field.id) ? /* @__PURE__ */ jsx15(Check, {}) : null
3326
+ ]
3327
+ }),
3328
+ /* @__PURE__ */ jsx15(DropdownMenuSubContent, {
3329
+ className: "w-80 max-w-[calc(100vw-2rem)]",
3330
+ children: filterEditor(field)
3331
+ })
3332
+ ]
3333
+ }, field.id))
3334
+ }) : filterEditor(column)
3335
+ })
3336
+ ]
3337
+ }),
3338
+ activeFilters.length ? /* @__PURE__ */ jsxs9(DropdownMenuItem, {
3339
+ onClick: () => update((state) => {
3340
+ const filters = state.filters?.filter(({ id }) => !ownsFilter(id));
3341
+ return {
3342
+ ...state,
3343
+ page: 0,
3344
+ filters: filters?.length ? filters : undefined
3345
+ };
3346
+ }),
3347
+ children: [
3348
+ /* @__PURE__ */ jsx15(X, {}),
3349
+ store.config.labels.filterClear
3350
+ ]
3351
+ }) : null
3352
+ ]
3353
+ }) : null,
3354
+ (sortingEnabled || filteringEnabled) && hidingEnabled ? /* @__PURE__ */ jsx15(DropdownMenuSeparator, {}) : null,
3355
+ hidingEnabled ? /* @__PURE__ */ jsxs9(DropdownMenuItem, {
3356
+ onClick: () => update((state) => ({
3357
+ ...state,
3358
+ columnVisibility: {
3359
+ ...state.columnVisibility,
3360
+ [column.id]: false
3361
+ }
3362
+ })),
3363
+ children: [
3364
+ /* @__PURE__ */ jsx15(EyeOff, {}),
3365
+ " ",
3366
+ store.config.labels.hideColumn
3367
+ ]
3368
+ }) : null
3369
+ ]
3370
+ })
3371
+ })
3372
+ ]
3373
+ });
3374
+ };
3375
+ var DataTableHeader = ({
3376
+ tableAtom
3377
+ }) => {
3378
+ const [store, setStore] = useTableAtom(tableAtom);
3379
+ const model = deriveModel(store);
3380
+ const selection = store.config.features.selection;
3381
+ const grouped = getActiveGrouping(store).length > 0;
3382
+ const draggable = canDragRows(store);
3383
+ const selectableRows = getDataTableSelectableRows(model, grouped, selection ? selection.isRowSelectable : undefined);
3384
+ const allSelected = selectableRows.length > 0 && selectableRows.every((row) => store.state.rowSelection[row.id]);
3385
+ const someSelected = selectableRows.some((row) => store.state.rowSelection[row.id]);
3386
+ return /* @__PURE__ */ jsx15(TableHeader, {
3387
+ children: /* @__PURE__ */ jsxs9(TableRow, {
3388
+ children: [
3389
+ selection ? /* @__PURE__ */ jsx15(TableHead, {
3390
+ className: "w-10 pr-0",
3391
+ children: /* @__PURE__ */ jsx15(Checkbox, {
3392
+ "aria-label": store.config.labels.selectAllRows,
3393
+ checked: allSelected,
3394
+ indeterminate: someSelected && !allSelected,
3395
+ onCheckedChange: (checked) => {
3396
+ changeState(setStore, (state) => {
3397
+ const rowSelection = { ...state.rowSelection };
3398
+ selectableRows.forEach((row) => rowSelection[row.id] = checked);
3399
+ selection.onSelectionChange?.(model.rows.filter((row) => rowSelection[row.id]).map((row) => row.data));
3400
+ return { ...state, rowSelection };
3401
+ });
3402
+ }
3403
+ })
3404
+ }) : null,
3405
+ draggable ? /* @__PURE__ */ jsx15(TableHead, {
3406
+ className: "w-10"
3407
+ }) : null,
3408
+ model.visibleColumns.map((column) => {
3409
+ const direction = store.state.sort?.find(({ id }) => id === column.id)?.direction;
3410
+ return /* @__PURE__ */ jsx15(TableHead, {
3411
+ "aria-sort": direction === "asc" ? "ascending" : direction === "desc" ? "descending" : undefined,
3412
+ className: "relative h-12 p-0",
3413
+ scope: "col",
3414
+ style: { width: column.width },
3415
+ children: /* @__PURE__ */ jsxs9(ColumnIdContext.Provider, {
3416
+ value: column.id,
3417
+ children: [
3418
+ /* @__PURE__ */ jsx15(ColumnHeaderMenu, {
3419
+ tableAtom
3420
+ }),
3421
+ /* @__PURE__ */ jsx15(ResizeHandle, {
3422
+ tableAtom
3423
+ })
3424
+ ]
3425
+ })
3426
+ }, column.id);
3427
+ }),
3428
+ hasRowActionMenu(store) ? /* @__PURE__ */ jsx15(TableHead, {
3429
+ className: "w-10"
3430
+ }) : null
3431
+ ]
3432
+ })
3433
+ });
3434
+ };
3435
+ var DataTableBody = ({
3436
+ tableAtom
3437
+ }) => {
3438
+ const [store] = useTableAtom(tableAtom);
3439
+ const model = deriveModel(store);
3440
+ const fields = getActiveGrouping(store);
3441
+ const grouped = fields.length > 0;
3442
+ const rows = grouped ? model.sortedRows : model.pageRows;
3443
+ const sections = groupDataTableRows(rows, fields);
3444
+ const colSpan = model.visibleColumns.length + (store.config.features.selection ? 1 : 0) + (hasRowActionMenu(store) ? 1 : 0) + (canDragRows(store) ? 1 : 0);
3445
+ if (sections.length && (rows.length || !store.config.status.loading) && !store.config.status.error) {
3446
+ return /* @__PURE__ */ jsx15(GroupedTable, {
3447
+ tableAtom,
3448
+ sections
3449
+ });
3450
+ }
3451
+ return /* @__PURE__ */ jsx15(TableBody, {
3452
+ children: store.config.status.error || !rows.length && !store.config.status.loading ? /* @__PURE__ */ jsx15(TableRow, {
3453
+ children: /* @__PURE__ */ jsx15(TableCell, {
3454
+ className: "h-24 text-center",
3455
+ colSpan: Math.max(colSpan, 1),
3456
+ children: store.config.status.error ?? store.config.status.empty ?? store.config.labels.empty
3457
+ })
3458
+ }) : store.config.status.loading && !rows.length ? /* @__PURE__ */ jsx15(TableRow, {
3459
+ children: /* @__PURE__ */ jsx15(TableCell, {
3460
+ className: "h-24 text-center",
3461
+ colSpan: Math.max(colSpan, 1),
3462
+ children: /* @__PURE__ */ jsx15(Loading, {
3463
+ label: store.config.labels.loading
3464
+ })
3465
+ })
3466
+ }) : rows.map((row) => /* @__PURE__ */ jsx15(RowIdContext.Provider, {
3467
+ value: row.id,
3468
+ children: /* @__PURE__ */ jsx15(TableDataRow, {
3469
+ tableAtom
3470
+ })
3471
+ }, row.id))
3472
+ });
3473
+ };
3474
+ var GalleryCard = ({
3475
+ tableAtom
3476
+ }) => {
3477
+ const [store, setStore] = useTableAtom(tableAtom);
3478
+ const rowId = useRequiredId(RowIdContext);
3479
+ const model = deriveModel(store);
3480
+ const row = model.sortedRows.find((candidate) => candidate.id === rowId);
3481
+ const gallery = store.config.features.gallery;
3482
+ if (!row || !gallery)
3483
+ return null;
3484
+ const find = (id) => id ? model.visibleColumns.find((column) => column.id === id) : undefined;
3485
+ const name = find(gallery.name);
3486
+ const description = find(gallery.description);
3487
+ const tag = find(gallery.tag);
3488
+ const selection = store.config.features.selection;
3489
+ const selectable = !!selection && (selection.isRowSelectable?.(row.data) ?? true);
3490
+ const draggable = canDragRows(store);
3491
+ return /* @__PURE__ */ jsx15(Card, {
3492
+ className: cn("data-[drop-position=before]:border-t-primary data-[drop-position=after]:border-b-primary relative gap-3 data-[drag-source=true]:opacity-40 data-[drop-position=after]:border-b-2 data-[drop-position=before]:border-t-2", store.config.onRowClicked && "cursor-pointer"),
3493
+ "data-table-row": row.id,
3494
+ onClick: () => store.config.onRowClicked?.(row.data),
3495
+ onKeyDown: (event) => {
3496
+ if (event.target === event.currentTarget && store.config.onRowClicked && (event.key === "Enter" || event.key === " ")) {
3497
+ event.preventDefault();
3498
+ store.config.onRowClicked(row.data);
3499
+ }
3500
+ },
3501
+ tabIndex: store.config.onRowClicked ? 0 : undefined,
3502
+ children: /* @__PURE__ */ jsxs9(CardHeader, {
3503
+ className: "pr-12",
3504
+ children: [
3505
+ /* @__PURE__ */ jsxs9("div", {
3506
+ className: "flex items-center gap-2",
3507
+ children: [
3508
+ selection ? /* @__PURE__ */ jsx15(Checkbox, {
3509
+ "aria-label": store.config.labels.selectRow,
3510
+ checked: !!store.state.rowSelection[row.id],
3511
+ disabled: !selectable,
3512
+ onCheckedChange: (checked) => toggleRow(store, setStore, row.id, checked),
3513
+ onClick: (event) => event.stopPropagation()
3514
+ }) : null,
3515
+ draggable ? /* @__PURE__ */ jsx15(DragHandle, {
3516
+ tableAtom
3517
+ }) : null,
3518
+ tag ? /* @__PURE__ */ jsxs9(Badge, {
3519
+ variant: "secondary",
3520
+ children: [
3521
+ gallery.tagIcon,
3522
+ renderCell(row, tag, store.config.locale, store.config.labels)
3523
+ ]
3524
+ }) : null
3525
+ ]
3526
+ }),
3527
+ /* @__PURE__ */ jsx15(CardTitle, {
3528
+ children: name ? renderCell(row, name, store.config.locale, store.config.labels) : row.id
3529
+ }),
3530
+ description ? /* @__PURE__ */ jsx15("div", {
3531
+ className: "text-muted-foreground line-clamp-3 text-sm",
3532
+ children: renderCell(row, description, store.config.locale, store.config.labels)
3533
+ }) : null,
3534
+ hasRowActionMenu(store) ? /* @__PURE__ */ jsx15("div", {
3535
+ className: "absolute top-4 right-4",
3536
+ onClick: (event) => event.stopPropagation(),
3537
+ children: /* @__PURE__ */ jsx15(DataTableRowActionMenu, {
3538
+ tableAtom
3539
+ })
3540
+ }) : null
3541
+ ]
3542
+ })
3543
+ });
3544
+ };
3545
+ var DataTableGallery = ({
3546
+ tableAtom
3547
+ }) => {
3548
+ const [store, setStore] = useTableAtom(tableAtom);
3549
+ const model = deriveModel(store);
3550
+ const fields = getActiveGrouping(store);
3551
+ const rows = fields.length ? model.sortedRows : model.pageRows;
3552
+ const sections = groupDataTableRows(rows, fields);
3553
+ if (store.config.status.error) {
3554
+ return /* @__PURE__ */ jsx15("div", {
3555
+ className: "text-destructive rounded-lg border border-dashed p-10 text-center",
3556
+ children: store.config.status.error
3557
+ });
3558
+ }
3559
+ if (store.config.status.loading && !rows.length) {
3560
+ return /* @__PURE__ */ jsx15("div", {
3561
+ className: "rounded-lg border border-dashed p-10 text-center",
3562
+ children: /* @__PURE__ */ jsx15(Loading, {
3563
+ label: store.config.labels.loading
3564
+ })
3565
+ });
3566
+ }
3567
+ if (!rows.length && !sections.length) {
3568
+ return /* @__PURE__ */ jsx15("div", {
3569
+ className: "text-muted-foreground rounded-lg border border-dashed p-10 text-center",
3570
+ children: store.config.status.empty ?? store.config.labels.empty
3571
+ });
3572
+ }
3573
+ if (!fields.length) {
3574
+ return /* @__PURE__ */ jsx15("div", {
3575
+ className: "grid gap-3 sm:grid-cols-2 xl:grid-cols-3",
3576
+ children: rows.map((row) => /* @__PURE__ */ jsx15(RowIdContext.Provider, {
3577
+ value: row.id,
3578
+ children: /* @__PURE__ */ jsx15(GalleryCard, {
3579
+ tableAtom
3580
+ })
3581
+ }, row.id))
3582
+ });
3583
+ }
3584
+ const renderSections = (sections) => sections.map((section) => {
3585
+ const collapsed = !!store.state.collapsedGroups[section.key];
3586
+ const targetKey = getGroupDropKey(section.field.id, section.groupId);
3587
+ const toggleCollapsed = () => changeState(setStore, (state) => ({
3588
+ ...state,
3589
+ collapsedGroups: {
3590
+ ...state.collapsedGroups,
3591
+ [section.key]: !collapsed
3592
+ }
3593
+ }));
3594
+ return /* @__PURE__ */ jsxs9("section", {
3595
+ className: "data-[drop-target=true]:ring-primary space-y-3 rounded-lg transition-shadow data-[drop-target=true]:ring-2",
3596
+ "data-table-group": section.field.onMoveToGroup ? targetKey : undefined,
3597
+ children: [
3598
+ /* @__PURE__ */ jsxs9("div", {
3599
+ className: "hover:bg-accent flex cursor-pointer items-center gap-2 rounded-lg border p-3 transition-colors",
3600
+ onClick: toggleCollapsed,
3601
+ children: [
3602
+ /* @__PURE__ */ jsxs9("button", {
3603
+ "aria-expanded": !collapsed,
3604
+ className: "flex flex-1 cursor-pointer items-center gap-2 text-left font-medium",
3605
+ type: "button",
3606
+ children: [
3607
+ collapsed ? /* @__PURE__ */ jsx15(ChevronRight2, {
3608
+ className: "size-4"
3609
+ }) : /* @__PURE__ */ jsx15(ChevronDown, {
3610
+ className: "size-4"
3611
+ }),
3612
+ /* @__PURE__ */ jsx15("span", {
3613
+ className: "flex-1",
3614
+ children: section.field.renderGroupLabel?.(section.groupId, section.rows.map((row) => row.data)) ?? section.groupId
3615
+ }),
3616
+ /* @__PURE__ */ jsx15(Badge, {
3617
+ variant: "secondary",
3618
+ children: section.rows.length
3619
+ })
3620
+ ]
3621
+ }),
3622
+ /* @__PURE__ */ jsx15(GroupActions, {
3623
+ actions: section.field.actions,
3624
+ groupId: section.groupId,
3625
+ title: section.field.actionsLabel ?? store.config.labels.actions
3626
+ })
3627
+ ]
3628
+ }),
3629
+ !collapsed ? section.children.length ? renderSections(section.children) : section.rows.length ? /* @__PURE__ */ jsx15("div", {
3630
+ className: "grid gap-3 sm:grid-cols-2 xl:grid-cols-3",
3631
+ children: section.rows.map((row) => /* @__PURE__ */ jsx15(RowIdContext.Provider, {
3632
+ value: row.id,
3633
+ children: /* @__PURE__ */ jsx15(GalleryCard, {
3634
+ tableAtom
3635
+ })
3636
+ }, `${section.key}:${row.id}`))
3637
+ }) : /* @__PURE__ */ jsx15("div", {
3638
+ className: "text-muted-foreground rounded-lg border border-dashed p-8 text-center",
3639
+ children: section.field.renderEmptyGroup?.(section.groupId) ?? store.config.labels.empty
3640
+ }) : null
3641
+ ]
3642
+ }, section.key);
3643
+ });
3644
+ return /* @__PURE__ */ jsx15("div", {
3645
+ className: "space-y-4",
3646
+ children: renderSections(sections)
3647
+ });
3648
+ };
3649
+ var DataTablePagination = ({
3650
+ tableAtom
3651
+ }) => {
3652
+ const [store, setStore] = useTableAtom(tableAtom);
3653
+ const model = deriveModel(store);
3654
+ const pagination = store.config.features.pagination ?? { mode: "client" };
3655
+ const clientGrouping = pagination !== false && pagination.mode === "client" && getActiveGrouping(store).length > 0;
3656
+ const paginationVisible = pagination !== false && !clientGrouping;
3657
+ const pageIndex = store.state.page;
3658
+ const maxPageIndex = model.pageCount - 1;
3659
+ useLayoutEffect(() => {
3660
+ if (paginationVisible && pageIndex > maxPageIndex) {
3661
+ changeState(setStore, (state) => ({
3662
+ ...state,
3663
+ page: maxPageIndex
3664
+ }));
3665
+ }
3666
+ }, [maxPageIndex, pageIndex, paginationVisible, setStore]);
3667
+ if (!paginationVisible)
3668
+ return null;
3669
+ const selected = model.rows.filter((row) => store.state.rowSelection[row.id]).length;
3670
+ const setPagination = (next) => changeState(setStore, (state) => ({ ...state, ...next }));
3671
+ return /* @__PURE__ */ jsx15("div", {
3672
+ className: "pt-4",
3673
+ children: /* @__PURE__ */ jsx15(Pagination, {
3674
+ locale: store.config.locale,
3675
+ messages: { [store.config.locale]: store.config.labels },
3676
+ onPageChange: (page) => setPagination({ page, pageSize: store.state.pageSize }),
3677
+ onPageSizeChange: (pageSize) => setPagination({ page: 0, pageSize }),
3678
+ page: Math.min(store.state.page, model.pageCount - 1),
3679
+ pageCount: model.pageCount,
3680
+ pageSize: store.state.pageSize,
3681
+ pageSizes: pagination.pageSizes,
3682
+ selectedRows: selected,
3683
+ totalRows: model.totalRows
3684
+ })
3685
+ });
3686
+ };
3687
+ var HydratedDataTable = ({
3688
+ persistedUiState,
3689
+ setPersistedUiState,
3690
+ ...props
3691
+ }) => {
3692
+ const [initialGrouping] = useState(() => {
3693
+ const grouping = props.features?.grouping;
3694
+ return grouping && grouping.initial ? grouping.initial : [];
3695
+ });
3696
+ const [transientUiAtom] = useState(() => Atom.make(transientUiFromState(DEFAULT_UI_STATE)));
3697
+ const [transientUiState, setTransientUiState] = useAtom(transientUiAtom);
3698
+ const uiState = useMemo2(() => ({
3699
+ ...persistedUiState,
3700
+ ...transientUiState,
3701
+ grouping: persistedUiState.grouping ?? initialGrouping
3702
+ }), [persistedUiState, transientUiState, initialGrouping]);
3703
+ const setUiState = useCallback((state) => {
3704
+ setPersistedUiState(persistedUiFromState(state));
3705
+ setTransientUiState(transientUiFromState(state));
3706
+ }, [setPersistedUiState, setTransientUiState]);
3707
+ const validatedConfig = resolveConfig(props, (state) => setUiState(state));
3708
+ const [tableAtom] = useState(() => {
3709
+ const initial = {
3710
+ rowData: props.rowData,
3711
+ columnDefs: props.columnDefs,
3712
+ config: validatedConfig,
3713
+ state: initialPublicState(props, uiState),
3714
+ controlledState: props.state
3715
+ };
3716
+ return Atom.make({
3717
+ ...initial,
3718
+ model: buildDataTableModel(initial)
3719
+ });
3720
+ });
3721
+ const setStore = useAtomSet(tableAtom);
3722
+ useLayoutEffect(() => {
3723
+ setStore((store) => {
3724
+ const features = props.features ?? {};
3725
+ const selection = features.selection;
3726
+ const config = {
3727
+ getRowId: selection && selection.getRowId || props.getRowId || undefined,
3728
+ onStateChange: props.onStateChange,
3729
+ onUiStateChange: (state) => setUiState(state),
3730
+ status: props.status ?? {},
3731
+ features,
3732
+ onRowClicked: props.onRowClicked,
3733
+ labels: dataTableMessages(props.locale, props.messages),
3734
+ locale: props.locale ?? "en"
3735
+ };
3736
+ const state = {
3737
+ ...store.state,
3738
+ ...uiState,
3739
+ ...queryFromState(props.state ?? store.state)
3740
+ };
3741
+ 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;
3742
+ const next = {
3743
+ ...store,
3744
+ rowData: props.rowData,
3745
+ columnDefs: props.columnDefs,
3746
+ config,
3747
+ controlledState: props.state,
3748
+ state
3749
+ };
3750
+ return modelChanged ? { ...next, model: buildDataTableModel(next) } : next;
3751
+ });
3752
+ }, [
3753
+ props.columnDefs,
3754
+ props.features,
3755
+ props.getRowId,
3756
+ props.locale,
3757
+ props.messages,
3758
+ props.onRowClicked,
3759
+ props.onStateChange,
3760
+ props.rowData,
3761
+ props.state,
3762
+ props.status,
3763
+ setStore,
3764
+ setUiState,
3765
+ uiState
3766
+ ]);
3767
+ return /* @__PURE__ */ jsxs9("div", {
3768
+ className: "w-full max-w-full min-w-0 rounded-md",
3769
+ "data-table-root": "",
3770
+ children: [
3771
+ /* @__PURE__ */ jsx15(DataTableToolbar, {
3772
+ tableAtom
3773
+ }),
3774
+ /* @__PURE__ */ jsx15(DataTableContent, {
3775
+ tableAtom
3776
+ }),
3777
+ /* @__PURE__ */ jsx15(DataTablePagination, {
3778
+ tableAtom
3779
+ })
3780
+ ]
3781
+ });
3782
+ };
3783
+ var DataTable = (props) => {
3784
+ const locale = useKrakstackLocale3(props.locale);
3785
+ const [initialColumnVisibility] = useState(() => props.initialState?.columnVisibility ?? {});
3786
+ const [persistedUiAtom] = useState(() => {
3787
+ const pathname = globalThis.window?.location.pathname ?? "/";
3788
+ const columnIds = normalizeDataTableColumns(props.columnDefs).map(({ id }) => id).join(",");
3789
+ const viewCapability = props.features?.gallery ? "gallery" : "table";
3790
+ return Atom.kvs({
3791
+ mode: "async",
3792
+ runtime: dataTableStorageRuntime,
3793
+ key: `data-table:${pathname}:${columnIds}:${viewCapability}:ui`,
3794
+ schema: DataTablePersistedUiStateSchema,
3795
+ defaultValue: () => ({
3796
+ ...persistedUiFromState(DEFAULT_UI_STATE),
3797
+ grouping: props.features?.grouping ? props.features.grouping.initial ?? [] : []
3798
+ })
3799
+ });
3800
+ });
3801
+ const [persistedUiResult, setPersistedUiState] = useAtom(persistedUiAtom);
3802
+ const persistedUiState = useMemo2(() => AsyncResult.isSuccess(persistedUiResult) ? {
3803
+ ...persistedUiResult.value,
3804
+ columnVisibility: {
3805
+ ...initialColumnVisibility,
3806
+ ...persistedUiResult.value.columnVisibility
3807
+ }
3808
+ } : undefined, [initialColumnVisibility, persistedUiResult]);
3809
+ if (!persistedUiState || AsyncResult.isWaiting(persistedUiResult)) {
3810
+ return /* @__PURE__ */ jsx15("div", {
3811
+ "aria-busy": "true",
3812
+ className: "invisible w-full max-w-full min-w-0 rounded-md",
3813
+ "data-table-root": ""
3814
+ });
3815
+ }
3816
+ return /* @__PURE__ */ jsx15(HydratedDataTable, {
3817
+ ...props,
3818
+ locale,
3819
+ persistedUiState,
3820
+ setPersistedUiState
3821
+ });
3822
+ };
3823
+ var DataTableContent = ({
3824
+ tableAtom
3825
+ }) => {
3826
+ const [store] = useTableAtom(tableAtom);
3827
+ if (store.config.features.gallery && store.state.view === "gallery") {
3828
+ return /* @__PURE__ */ jsx15(DataTableGallery, {
3829
+ tableAtom
3830
+ });
3831
+ }
3832
+ const model = deriveModel(store);
3833
+ const width = getDataTableWidth(model.visibleColumns, (store.config.features.selection ? 1 : 0) + (hasRowActionMenu(store) ? 1 : 0) + (canDragRows(store) ? 1 : 0));
3834
+ return /* @__PURE__ */ jsxs9(ScrollArea, {
3835
+ className: "max-w-full min-w-0",
3836
+ children: [
3837
+ /* @__PURE__ */ jsxs9(Table, {
3838
+ className: "table-fixed",
3839
+ style: { width: `max(100%, ${width}px)` },
3840
+ children: [
3841
+ /* @__PURE__ */ jsx15(DataTableHeader, {
3842
+ tableAtom
3843
+ }),
3844
+ /* @__PURE__ */ jsx15(DataTableBody, {
3845
+ tableAtom
3846
+ })
3847
+ ]
3848
+ }),
3849
+ /* @__PURE__ */ jsx15(ScrollBar, {
3850
+ orientation: "horizontal"
3851
+ })
3852
+ ]
3853
+ });
3854
+ };
3855
+ var DataTableListCell = (props) => {
3856
+ const locale = useKrakstackLocale3(props.locale);
3857
+ const resolvedProps = { ...props, locale };
3858
+ if (resolvedProps.options && (resolvedProps.onAdd || resolvedProps.onRemove)) {
3859
+ return /* @__PURE__ */ jsx15(EditableDataTableListCell, {
3860
+ ...resolvedProps
3861
+ });
3862
+ }
3863
+ const { actionsLabel, itemActions, onItemClick, ...summaryProps } = resolvedProps;
3864
+ const labels = dataTableMessages(locale, resolvedProps.messages);
3865
+ const hasItems = resolvedProps.items.length > 0;
3866
+ if (!itemActions?.length && !hasItems) {
3867
+ return /* @__PURE__ */ jsx15(DataTableListSummary, {
3868
+ ...summaryProps
3869
+ });
3870
+ }
3871
+ const menuLabel = actionsLabel ?? (itemActions?.length ? labels.actions : labels.listDetails);
3872
+ return /* @__PURE__ */ jsx15("div", {
3873
+ 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",
3874
+ "data-slot": "data-table-list-cell",
3875
+ onClick: (event) => event.stopPropagation(),
3876
+ onPointerDown: (event) => event.stopPropagation(),
3877
+ children: /* @__PURE__ */ jsx15(DataTableListMenu, {
3878
+ actions: itemActions ?? [],
3879
+ display: resolvedProps.display,
3880
+ force: hasItems,
3881
+ label: menuLabel,
3882
+ items: resolvedProps.items,
3883
+ locale,
3884
+ messages: resolvedProps.messages,
3885
+ onItemClick,
3886
+ trigger: /* @__PURE__ */ jsxs9(Button, {
3887
+ "aria-label": menuLabel,
3888
+ className: "h-full w-full min-w-0 justify-between rounded-none px-2 focus-visible:ring-inset",
3889
+ variant: "ghost",
3890
+ children: [
3891
+ /* @__PURE__ */ jsx15(DataTableListSummaryContent, {
3892
+ ...summaryProps,
3893
+ showMenu: false
3894
+ }),
3895
+ /* @__PURE__ */ jsx15(ChevronDown, {})
3896
+ ]
3897
+ })
3898
+ })
3899
+ });
3900
+ };
3901
+ var EditableDataTableListCell = ({
3902
+ emptyLabel,
3903
+ manageLabel,
3904
+ onAdd,
3905
+ onRemove,
3906
+ options,
3907
+ items,
3908
+ display,
3909
+ visibleCount,
3910
+ totalCount,
3911
+ actionsLabel,
3912
+ itemActions,
3913
+ onItemClick,
3914
+ locale = "en",
3915
+ messages
3916
+ }) => {
3917
+ const [selected, setSelected] = useState([...items]);
3918
+ useLayoutEffect(() => setSelected([...items]), [items]);
3919
+ const selectedValues = new Set(selected.map((item) => item.value));
3920
+ const available = options.filter((item) => !selectedValues.has(item.value));
3921
+ const canAdd = !!onAdd && available.length > 0;
3922
+ const selectedTotal = totalCount === undefined ? selected.length : totalCount + selected.length - items.length;
3923
+ const labels = dataTableMessages(locale, messages);
3924
+ const actions = [
3925
+ ...itemActions ?? [],
3926
+ ...onRemove ? [
3927
+ {
3928
+ id: "data-table-list-remove",
3929
+ closeOnClick: false,
3930
+ name: labels.removeItem,
3931
+ icon: /* @__PURE__ */ jsx15(Trash2, {}),
3932
+ variant: "destructive",
3933
+ onClick: (item) => {
3934
+ if (item.value === undefined)
3935
+ return;
3936
+ onRemove(item.value);
3937
+ setSelected((current) => current.filter((candidate) => candidate.value !== item.value));
3938
+ }
3939
+ }
3940
+ ] : []
3941
+ ];
3942
+ return /* @__PURE__ */ jsx15("div", {
3943
+ "data-slot": "data-table-list-cell",
3944
+ 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",
3945
+ onClick: (event) => event.stopPropagation(),
3946
+ onPointerDown: (event) => event.stopPropagation(),
3947
+ children: /* @__PURE__ */ jsx15(DataTableListMenu, {
3948
+ actions,
3949
+ addEmptyLabel: emptyLabel,
3950
+ addLabel: labels.addItem,
3951
+ addOptions: canAdd ? available : undefined,
3952
+ addSearchLabel: manageLabel,
3953
+ display,
3954
+ force: true,
3955
+ items: selected,
3956
+ onItemClick,
3957
+ label: actionsLabel ?? manageLabel,
3958
+ locale,
3959
+ messages,
3960
+ onAdd: canAdd ? (item) => {
3961
+ onAdd(item.value);
3962
+ setSelected((current) => [...current, item]);
3963
+ } : undefined,
3964
+ trigger: /* @__PURE__ */ jsxs9(Button, {
3965
+ "aria-label": manageLabel,
3966
+ className: "h-full w-full min-w-0 justify-between rounded-none px-2 focus-visible:ring-inset",
3967
+ variant: "ghost",
3968
+ children: [
3969
+ /* @__PURE__ */ jsx15(DataTableListSummaryContent, {
3970
+ emptyLabel,
3971
+ items: selected,
3972
+ display,
3973
+ showMenu: false,
3974
+ visibleCount,
3975
+ totalCount: selectedTotal
3976
+ }),
3977
+ /* @__PURE__ */ jsx15(ChevronDown, {})
3978
+ ]
3979
+ })
3980
+ })
3981
+ });
3982
+ };
3983
+ var DataTableListMenu = ({
3984
+ actions,
3985
+ addEmptyLabel,
3986
+ addLabel,
3987
+ addOptions,
3988
+ addSearchLabel,
3989
+ className,
3990
+ display = "list",
3991
+ force = false,
3992
+ items,
3993
+ label,
3994
+ locale = "en",
3995
+ messages,
3996
+ onAdd,
3997
+ onItemClick,
3998
+ trigger
3999
+ }) => {
4000
+ const entries = items.map((item) => {
4001
+ const normalized = Schema2.is(Schema2.String)(item) ? { label: item } : item;
4002
+ const visibleActions = actions.filter((action) => action.visible?.(normalized) ?? true);
4003
+ return { item: normalized, visibleActions };
4004
+ });
4005
+ const hasActions = entries.some(({ visibleActions }) => visibleActions.length);
4006
+ if (!force && !hasActions && !onAdd)
4007
+ return null;
4008
+ const labels = dataTableMessages(locale, messages);
4009
+ const resolvedLabel = label ?? (hasActions ? labels.actions : labels.listDetails);
4010
+ return /* @__PURE__ */ jsxs9(DropdownMenu, {
4011
+ children: [
4012
+ /* @__PURE__ */ jsx15(DropdownMenuTrigger, {
4013
+ onClick: (event) => event.stopPropagation(),
4014
+ onPointerDown: (event) => event.stopPropagation(),
4015
+ render: trigger ?? /* @__PURE__ */ jsx15(Button, {
4016
+ "aria-label": resolvedLabel,
4017
+ className: cn("size-8 shrink-0", className),
4018
+ size: "icon",
4019
+ variant: "ghost",
4020
+ children: /* @__PURE__ */ jsx15(MoreHorizontal, {})
4021
+ })
4022
+ }),
4023
+ /* @__PURE__ */ jsx15(DropdownMenuContent, {
4024
+ align: "end",
4025
+ className: "max-h-[min(18rem,var(--available-height))] w-72 max-w-[calc(100vw-2rem)]",
4026
+ onClick: (event) => event.stopPropagation(),
4027
+ onPointerDown: (event) => event.stopPropagation(),
4028
+ children: /* @__PURE__ */ jsxs9(DropdownMenuGroup, {
4029
+ children: [
4030
+ /* @__PURE__ */ jsx15(DropdownMenuLabel, {
4031
+ children: resolvedLabel
4032
+ }),
4033
+ /* @__PURE__ */ jsx15(DropdownMenuSeparator, {}),
4034
+ entries.map(({ item, visibleActions }, index) => visibleActions.length ? /* @__PURE__ */ jsxs9(DropdownMenuSub, {
4035
+ children: [
4036
+ /* @__PURE__ */ jsx15(DropdownMenuSubTrigger, {
4037
+ children: /* @__PURE__ */ jsx15(DataTableListEntry, {
4038
+ item,
4039
+ appearance: display === "icon" ? "detail" : "list"
4040
+ })
4041
+ }),
4042
+ /* @__PURE__ */ jsx15(DropdownMenuSubContent, {
4043
+ className: "w-max",
4044
+ children: visibleActions.map((action) => /* @__PURE__ */ jsxs9(DropdownMenuItem, {
4045
+ closeOnClick: action.closeOnClick,
4046
+ disabled: action.disabled?.(item),
4047
+ onClick: (event) => {
4048
+ event.stopPropagation();
4049
+ action.onClick(item);
4050
+ },
4051
+ variant: action.variant ?? "default",
4052
+ children: [
4053
+ action.icon,
4054
+ action.name
4055
+ ]
4056
+ }, action.id ?? action.name))
4057
+ })
4058
+ ]
4059
+ }, item.value ?? `${item.label}-${index}`) : /* @__PURE__ */ jsx15(DropdownMenuItem, {
4060
+ closeOnClick: Boolean(onItemClick),
4061
+ onClick: (event) => {
4062
+ event.stopPropagation();
4063
+ onItemClick?.(item);
4064
+ },
4065
+ children: /* @__PURE__ */ jsx15(DataTableListEntry, {
4066
+ item,
4067
+ appearance: display === "icon" ? "detail" : "list"
4068
+ })
4069
+ }, item.value ?? `${item.label}-${index}`)),
4070
+ onAdd && addOptions?.length ? /* @__PURE__ */ jsxs9(Fragment, {
4071
+ children: [
4072
+ entries.length ? /* @__PURE__ */ jsx15(DropdownMenuSeparator, {}) : null,
4073
+ /* @__PURE__ */ jsx15(DataTableListAddMenu, {
4074
+ emptyLabel: addEmptyLabel,
4075
+ label: addLabel ?? labels.addItem,
4076
+ locale,
4077
+ messages,
4078
+ onAdd,
4079
+ options: addOptions,
4080
+ searchLabel: addSearchLabel ?? labels.filter,
4081
+ display
4082
+ })
4083
+ ]
4084
+ }) : null
4085
+ ]
4086
+ })
4087
+ })
4088
+ ]
4089
+ });
4090
+ };
4091
+ var DataTableListAddMenu = ({
4092
+ emptyLabel,
4093
+ display,
4094
+ label,
4095
+ locale = "en",
4096
+ messages,
4097
+ onAdd,
4098
+ options,
4099
+ searchLabel
4100
+ }) => {
4101
+ const [search, setSearch] = useState("");
4102
+ const focusSearch = useCallback((input) => {
4103
+ input?.focus({ preventScroll: true });
4104
+ }, []);
4105
+ const labels = dataTableMessages(locale, messages);
4106
+ const normalizedSearch = search.trim().toLocaleLowerCase(locale);
4107
+ const filtered = normalizedSearch ? options.filter((item) => item.label.toLocaleLowerCase(locale).includes(normalizedSearch)) : options;
4108
+ return /* @__PURE__ */ jsxs9(DropdownMenuSub, {
4109
+ onOpenChange: (open) => {
4110
+ if (!open)
4111
+ setSearch("");
4112
+ },
4113
+ children: [
4114
+ /* @__PURE__ */ jsxs9(DropdownMenuSubTrigger, {
4115
+ children: [
4116
+ /* @__PURE__ */ jsx15(Plus, {}),
4117
+ label
4118
+ ]
4119
+ }),
4120
+ /* @__PURE__ */ jsxs9(DropdownMenuSubContent, {
4121
+ className: "w-64",
4122
+ children: [
4123
+ /* @__PURE__ */ jsxs9("div", {
4124
+ className: "relative p-1",
4125
+ children: [
4126
+ /* @__PURE__ */ jsx15(Search, {
4127
+ className: "text-muted-foreground pointer-events-none absolute top-1/2 left-3 size-4 -translate-y-1/2"
4128
+ }),
4129
+ /* @__PURE__ */ jsx15(Input, {
4130
+ "aria-label": searchLabel,
4131
+ className: "h-8 pl-8",
4132
+ onChange: (event) => setSearch(event.target.value),
4133
+ onKeyDown: (event) => {
4134
+ if (event.key !== "Escape")
4135
+ event.stopPropagation();
4136
+ },
4137
+ placeholder: labels.filter,
4138
+ ref: focusSearch,
4139
+ value: search
4140
+ })
4141
+ ]
4142
+ }),
4143
+ /* @__PURE__ */ jsx15(DropdownMenuSeparator, {}),
4144
+ filtered.length ? filtered.map((item) => /* @__PURE__ */ jsx15(DropdownMenuItem, {
4145
+ closeOnClick: false,
4146
+ onClick: () => onAdd(item),
4147
+ children: /* @__PURE__ */ jsx15(DataTableListEntry, {
4148
+ item,
4149
+ appearance: display === "icon" ? "detail" : "list"
4150
+ })
4151
+ }, item.value)) : /* @__PURE__ */ jsx15("div", {
4152
+ className: "text-muted-foreground px-2 py-1.5 text-sm",
4153
+ children: emptyLabel
4154
+ })
4155
+ ]
4156
+ })
4157
+ ]
4158
+ });
4159
+ };
4160
+ var DataTableListSummaryContent = ({
4161
+ emptyLabel,
4162
+ items,
4163
+ locale,
4164
+ messages,
4165
+ totalCount = items.length,
4166
+ display = "list",
4167
+ showMenu,
4168
+ visibleCount = 3
4169
+ }) => {
4170
+ const normalized = items.map((item) => Schema2.is(Schema2.String)(item) ? { label: item } : item);
4171
+ if (!normalized.length)
4172
+ return /* @__PURE__ */ jsx15("span", {
4173
+ className: "text-muted-foreground",
4174
+ children: emptyLabel
4175
+ });
4176
+ const visible = normalized.slice(0, Math.max(0, visibleCount));
4177
+ const remaining = Math.max(totalCount - visible.length, 0);
4178
+ if (display === "icon") {
4179
+ return /* @__PURE__ */ jsx15(TooltipProvider, {
4180
+ children: /* @__PURE__ */ jsxs9("span", {
4181
+ className: "flex items-center",
4182
+ children: [
4183
+ visible.map((item, index) => /* @__PURE__ */ jsx15(DataTableListEntry, {
4184
+ item,
4185
+ appearance: "icon"
4186
+ }, item.value ?? `${item.label}-${index}`)),
4187
+ remaining ? /* @__PURE__ */ jsxs9("span", {
4188
+ className: "bg-secondary text-secondary-foreground -ml-1 flex size-8 items-center justify-center rounded-full",
4189
+ children: [
4190
+ "+",
4191
+ remaining
4192
+ ]
4193
+ }) : null,
4194
+ remaining && showMenu ? /* @__PURE__ */ jsx15(DataTableListMenu, {
4195
+ actions: [],
4196
+ display,
4197
+ force: true,
4198
+ items: normalized,
4199
+ locale,
4200
+ messages
4201
+ }) : null
4202
+ ]
4203
+ })
4204
+ });
4205
+ }
4206
+ return /* @__PURE__ */ jsxs9("span", {
4207
+ className: "inline-flex min-w-0 items-center gap-2 text-sm",
4208
+ children: [
4209
+ /* @__PURE__ */ jsxs9("span", {
4210
+ className: "truncate",
4211
+ children: [
4212
+ visible.map((item) => item.label).join(", "),
4213
+ remaining ? ` +${remaining}` : ""
4214
+ ]
4215
+ }),
4216
+ remaining && showMenu ? /* @__PURE__ */ jsx15(DataTableListMenu, {
4217
+ actions: [],
4218
+ display,
4219
+ force: true,
4220
+ items: normalized,
4221
+ locale,
4222
+ messages
4223
+ }) : null
4224
+ ]
4225
+ });
4226
+ };
4227
+ var DataTableListSummary = (props) => /* @__PURE__ */ jsx15(DataTableListSummaryContent, {
4228
+ ...props,
4229
+ showMenu: true
4230
+ });
4231
+ var DataTableListEntry = ({
4232
+ item,
4233
+ appearance
4234
+ }) => {
4235
+ const icon = /* @__PURE__ */ jsx15("span", {
4236
+ "aria-hidden": "true",
4237
+ className: "bg-secondary text-secondary-foreground flex size-8 shrink-0 items-center justify-center overflow-hidden rounded-full",
4238
+ children: item.imageSrc ? /* @__PURE__ */ jsx15("img", {
4239
+ alt: "",
4240
+ src: item.imageSrc,
4241
+ className: "size-full object-cover"
4242
+ }) : item.icon ?? item.label.slice(0, 2).toUpperCase()
4243
+ });
4244
+ if (appearance === "list") {
4245
+ return /* @__PURE__ */ jsx15("span", {
4246
+ className: "min-w-0 flex-1 truncate",
4247
+ title: item.label,
4248
+ children: item.label
4249
+ });
4250
+ }
4251
+ return appearance === "icon" ? /* @__PURE__ */ jsxs9(Tooltip, {
4252
+ children: [
4253
+ /* @__PURE__ */ jsx15(TooltipTrigger, {
4254
+ render: /* @__PURE__ */ jsx15("span", {
4255
+ className: "-ml-1 inline-flex rounded-full",
4256
+ "aria-label": item.label
4257
+ }),
4258
+ children: icon
4259
+ }),
4260
+ /* @__PURE__ */ jsx15(TooltipContent, {
4261
+ children: item.label
4262
+ })
4263
+ ]
4264
+ }) : /* @__PURE__ */ jsxs9("span", {
4265
+ className: "flex min-w-0 flex-1 items-center gap-2 text-left",
4266
+ children: [
4267
+ icon,
4268
+ /* @__PURE__ */ jsx15("span", {
4269
+ className: "truncate",
4270
+ children: item.label
4271
+ })
4272
+ ]
4273
+ });
4274
+ };
4275
+
4276
+ // ../../src/components/ui/copy-button.tsx
4277
+ import { Check as Check2, Copy, TriangleAlert } from "lucide-react";
4278
+ import { useEffect, useRef as useRef2, useState as useState2 } from "react";
4279
+ import { useKrakstackLocale as useKrakstackLocale4 } from "@krak-stack/registry/krakstack-provider";
4280
+ import { jsx as jsx16, jsxs as jsxs10 } from "react/jsx-runtime";
4281
+ var messages3 = {
4282
+ en: { copy: "Copy", copied: "Copied", copyFailed: "Copy failed" },
4283
+ fr: { copy: "Copier", copied: "Copié", copyFailed: "Échec de la copie" }
4284
+ };
4285
+ var copyButtonMessages = (locale = "en", translations) => ({
4286
+ ...locale.startsWith("fr") ? messages3.fr : messages3.en,
4287
+ ...translations?.[locale.split("-")[0] ?? locale],
4288
+ ...translations?.[locale]
4289
+ });
4290
+ function CopyButton({
4291
+ value,
4292
+ valueDescription,
4293
+ copyVariant = "default",
4294
+ locale: localeOverride,
4295
+ messages,
4296
+ onCopied,
4297
+ onCopyError,
4298
+ resetDelay = 1500,
4299
+ disabled,
4300
+ size,
4301
+ "aria-label": ariaLabel,
4302
+ ...props
4303
+ }) {
4304
+ const locale = useKrakstackLocale4(localeOverride);
4305
+ const [copyState, setCopyState] = useState2("idle");
4306
+ const copyTimeout = useRef2(undefined);
4307
+ const labels = copyButtonMessages(locale, messages);
4308
+ const accessibleLabel = ariaLabel ?? (valueDescription ? `${labels.copy} ${valueDescription}` : labels.copy);
4309
+ const isLarge = copyVariant === "large";
4310
+ const defaultSize = copyVariant === "sm" ? "icon-xs" : isLarge ? "sm" : "icon-sm";
4311
+ useEffect(() => {
4312
+ return () => {
4313
+ if (copyTimeout.current)
4314
+ clearTimeout(copyTimeout.current);
4315
+ };
4316
+ }, []);
4317
+ const resetCopyState = () => {
4318
+ if (copyTimeout.current)
4319
+ clearTimeout(copyTimeout.current);
4320
+ copyTimeout.current = setTimeout(() => setCopyState("idle"), resetDelay);
4321
+ };
4322
+ const copy = async () => {
4323
+ try {
4324
+ await navigator.clipboard.writeText(value);
4325
+ setCopyState("copied");
4326
+ onCopied?.();
4327
+ } catch (error) {
4328
+ setCopyState("failed");
4329
+ onCopyError?.(error instanceof Error ? error : new Error(labels.copyFailed, { cause: error }));
4330
+ }
4331
+ resetCopyState();
4332
+ };
4333
+ const status = copyState === "copied" ? valueDescription ? `${labels.copied}: ${valueDescription}` : labels.copied : copyState === "failed" ? valueDescription ? `${labels.copyFailed}: ${valueDescription}` : labels.copyFailed : "";
4334
+ return /* @__PURE__ */ jsxs10(Button, {
4335
+ "aria-label": accessibleLabel,
4336
+ disabled,
4337
+ onClick: copy,
4338
+ size: size ?? defaultSize,
4339
+ ...props,
4340
+ children: [
4341
+ /* @__PURE__ */ jsx16("span", {
4342
+ "aria-live": "polite",
4343
+ className: "sr-only",
4344
+ role: "status",
4345
+ children: status
4346
+ }),
4347
+ copyState === "copied" ? /* @__PURE__ */ jsx16(Check2, {
4348
+ "aria-hidden": "true"
4349
+ }) : null,
4350
+ copyState === "failed" ? /* @__PURE__ */ jsx16(TriangleAlert, {
4351
+ "aria-hidden": "true"
4352
+ }) : null,
4353
+ copyState === "idle" ? /* @__PURE__ */ jsx16(Copy, {
4354
+ "aria-hidden": "true"
4355
+ }) : null,
4356
+ isLarge ? /* @__PURE__ */ jsx16("span", {
4357
+ children: labels.copy
4358
+ }) : null
4359
+ ]
4360
+ });
4361
+ }
4362
+
4363
+ // ../../src/components/ui/code-block.tsx
4364
+ import { highlight } from "@tanstack/highlight";
4365
+ import { createThemeCss } from "@tanstack/highlight/theme";
4366
+ import { githubDarkTheme } from "@tanstack/highlight/themes/github-dark";
4367
+ import { githubLightTheme } from "@tanstack/highlight/themes/github-light";
4368
+ import { useKrakstackLocale as useKrakstackLocale5 } from "@krak-stack/registry/krakstack-provider";
4369
+ import { jsx as jsx17, jsxs as jsxs11 } from "react/jsx-runtime";
4370
+ var themeCss = `${createThemeCss({
4371
+ light: githubLightTheme,
4372
+ dark: githubDarkTheme,
4373
+ lightSelector: "[data-code-theme]",
4374
+ darkSelector: ".dark [data-code-theme]",
4375
+ codeBlockSelector: "[data-code-theme] pre.th-code",
4376
+ lineNumbersSelector: "[data-code-theme] .th-code--line-numbers"
4377
+ })}
4378
+ [data-code-theme] pre.th-code {
4379
+ margin: 0;
4380
+ overflow: visible;
4381
+ background: transparent;
4382
+ font: inherit;
4383
+ color: inherit;
4384
+ }
4385
+ [data-code-theme] pre.th-code code { font: inherit; }`;
4386
+ var messages4 = {
4387
+ en: {
4388
+ codeDescription: (language) => `${language} code`,
4389
+ copy: "Copy",
4390
+ copied: "Copied",
4391
+ copyFailed: "Copy failed"
4392
+ },
4393
+ fr: {
4394
+ codeDescription: (language) => `code ${language}`,
4395
+ copy: "Copier",
4396
+ copied: "Copié",
4397
+ copyFailed: "Échec de la copie"
4398
+ }
4399
+ };
4400
+ var codeBlockMessages = (locale = "en", translations) => ({
4401
+ ...locale.startsWith("fr") ? messages4.fr : messages4.en,
4402
+ ...translations?.[locale.split("-")[0] ?? locale],
4403
+ ...translations?.[locale]
4404
+ });
4405
+ function CodeBlock({
4406
+ code,
4407
+ language = "text",
4408
+ locale: localeOverride,
4409
+ messages
4410
+ }) {
4411
+ const locale = useKrakstackLocale5(localeOverride);
4412
+ const normalizedLanguage = language.toLowerCase() || "text";
4413
+ const highlighted = highlight(code, { lang: normalizedLanguage });
4414
+ const labels = codeBlockMessages(locale, messages);
4415
+ return /* @__PURE__ */ jsxs11("div", {
4416
+ className: "not-prose bg-muted overflow-hidden rounded-md border text-[var(--th-token)]",
4417
+ "data-code-theme": true,
4418
+ children: [
4419
+ /* @__PURE__ */ jsx17("style", {
4420
+ children: themeCss
4421
+ }),
4422
+ /* @__PURE__ */ jsxs11("div", {
4423
+ className: "bg-background border-border/60 flex items-center justify-between border-b px-3 py-2",
4424
+ children: [
4425
+ /* @__PURE__ */ jsx17("span", {
4426
+ className: "text-muted-foreground font-mono text-xs",
4427
+ children: highlighted.lang
4428
+ }),
4429
+ /* @__PURE__ */ jsx17(CopyButton, {
4430
+ value: code,
4431
+ valueDescription: labels.codeDescription(highlighted.lang),
4432
+ variant: "secondary",
4433
+ locale,
4434
+ messages: { [locale]: labels }
4435
+ })
4436
+ ]
4437
+ }),
4438
+ /* @__PURE__ */ jsx17("div", {
4439
+ className: "max-h-full overflow-auto font-mono text-[0.875rem] leading-[1.625]",
4440
+ dangerouslySetInnerHTML: { __html: highlighted.html }
4441
+ })
4442
+ ]
4443
+ });
4444
+ }
4445
+
4446
+ // ../../src/components/ui/dialog.tsx
4447
+ import { Dialog as DialogPrimitive } from "@base-ui/react/dialog";
4448
+ import { XIcon } from "lucide-react";
4449
+ import { jsx as jsx18, jsxs as jsxs12 } from "react/jsx-runtime";
4450
+ function Dialog({ ...props }) {
4451
+ return /* @__PURE__ */ jsx18(DialogPrimitive.Root, {
4452
+ "data-slot": "dialog",
4453
+ ...props
4454
+ });
4455
+ }
4456
+ function DialogPortal({ ...props }) {
4457
+ return /* @__PURE__ */ jsx18(DialogPrimitive.Portal, {
4458
+ "data-slot": "dialog-portal",
4459
+ ...props
4460
+ });
4461
+ }
4462
+ function DialogOverlay({
4463
+ className,
4464
+ ...props
4465
+ }) {
4466
+ return /* @__PURE__ */ jsx18(DialogPrimitive.Backdrop, {
4467
+ "data-slot": "dialog-overlay",
4468
+ className: cn("fixed inset-0 isolate z-50 bg-black/10 duration-100 supports-backdrop-filter:backdrop-blur-xs data-open:animate-in data-open:fade-in-0 data-closed:animate-out data-closed:fade-out-0", className),
4469
+ ...props
4470
+ });
4471
+ }
4472
+ function DialogContent({
4473
+ className,
4474
+ children,
4475
+ ...props
4476
+ }) {
4477
+ return /* @__PURE__ */ jsxs12(DialogPortal, {
4478
+ children: [
4479
+ /* @__PURE__ */ jsx18(DialogOverlay, {}),
4480
+ /* @__PURE__ */ jsxs12(DialogPrimitive.Popup, {
4481
+ "data-slot": "dialog-content",
4482
+ className: cn("fixed top-1/2 left-1/2 z-50 grid w-full max-w-[calc(100%-2rem)] -translate-x-1/2 -translate-y-1/2 gap-4 rounded-xl bg-popover p-6 text-popover-foreground ring-1 ring-foreground/10 duration-100 outline-none sm:max-w-lg 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),
4483
+ ...props,
4484
+ children: [
4485
+ children,
4486
+ /* @__PURE__ */ jsxs12(DialogPrimitive.Close, {
4487
+ className: "focus-visible:ring-ring absolute top-4 right-4 rounded-xs opacity-70 transition-opacity hover:opacity-100 focus-visible:ring-2 focus-visible:outline-none disabled:pointer-events-none",
4488
+ children: [
4489
+ /* @__PURE__ */ jsx18(XIcon, {
4490
+ className: "size-4"
4491
+ }),
4492
+ /* @__PURE__ */ jsx18("span", {
4493
+ className: "sr-only",
4494
+ children: "Close"
4495
+ })
4496
+ ]
4497
+ })
4498
+ ]
4499
+ })
4500
+ ]
4501
+ });
4502
+ }
4503
+ function DialogHeader({ className, ...props }) {
4504
+ return /* @__PURE__ */ jsx18("div", {
4505
+ "data-slot": "dialog-header",
4506
+ className: cn("grid gap-1.5", className),
4507
+ ...props
4508
+ });
4509
+ }
4510
+ function DialogTitle({
4511
+ className,
4512
+ ...props
4513
+ }) {
4514
+ return /* @__PURE__ */ jsx18(DialogPrimitive.Title, {
4515
+ "data-slot": "dialog-title",
4516
+ className: cn("text-lg font-medium", className),
4517
+ ...props
4518
+ });
4519
+ }
4520
+
4521
+ // ../../src/services/webhooks/client/delivery-table.tsx
4522
+ import { useKrakstackLocale as useKrakstackLocale6 } from "@krak-stack/registry/krakstack-provider";
4523
+ import { jsx as jsx19, jsxs as jsxs13, Fragment as Fragment2 } from "react/jsx-runtime";
4524
+ var translations = {
4525
+ en: {
4526
+ identifier: "ID",
4527
+ event: "Event",
4528
+ status: "Status",
4529
+ pending: "Pending",
4530
+ success: "Success",
4531
+ failed: "Failed",
4532
+ retries: "Retries",
4533
+ retryAt: "Next retry",
4534
+ errorUnavailable: "Error details unavailable",
4535
+ payload: "Payload",
4536
+ viewPayload: "View JSON",
4537
+ createdAt: "Created",
4538
+ completedAt: "Completed"
4539
+ },
4540
+ fr: {
4541
+ identifier: "Identifiant",
4542
+ event: "Événement",
4543
+ status: "Statut",
4544
+ pending: "En attente",
4545
+ success: "Réussite",
4546
+ failed: "Échec",
4547
+ retries: "Tentatives",
4548
+ retryAt: "Prochaine tentative",
4549
+ errorUnavailable: "Détails de l’erreur indisponibles",
4550
+ payload: "Données",
4551
+ viewPayload: "Voir le JSON",
4552
+ createdAt: "Créé",
4553
+ completedAt: "Terminé"
4554
+ }
4555
+ };
4556
+ var webhookDeliveryStatus = (delivery) => delivery.status === "pending" && delivery.retries > 0 ? "failed" : delivery.status;
4557
+ var WebhookDeliveryTable = ({
4558
+ entries,
4559
+ rowCount,
4560
+ locale: localeOverride,
4561
+ messages,
4562
+ events = [],
4563
+ linksColumn,
4564
+ state,
4565
+ onStateChange,
4566
+ status
4567
+ }) => {
4568
+ const locale = useKrakstackLocale6(localeOverride);
4569
+ const base = locale.split("-")[0];
4570
+ const labels = {
4571
+ ...translations.en,
4572
+ ...base === "fr" ? translations.fr : translations.en,
4573
+ ...messages?.[base],
4574
+ ...messages?.[locale]
4575
+ };
4576
+ const [selected, setSelected] = useState3(null);
4577
+ const dateFormatter = new Intl.DateTimeFormat(locale, {
4578
+ dateStyle: "medium",
4579
+ timeStyle: "short"
4580
+ });
4581
+ const statusLabels = {
4582
+ pending: labels.pending,
4583
+ success: labels.success,
4584
+ failed: labels.failed
4585
+ };
4586
+ const columns = [
4587
+ { field: "id", headerName: labels.identifier },
4588
+ {
4589
+ field: "event",
4590
+ headerName: labels.event,
4591
+ valueGetter: ({ data }) => events.find((event) => event.value === data.event)?.label ?? data.event,
4592
+ filterValueGetter: ({ data }) => data.event,
4593
+ filterable: events.length > 0,
4594
+ filterOptions: events
4595
+ },
4596
+ {
4597
+ field: "status",
4598
+ headerName: labels.status,
4599
+ type: "reference",
4600
+ filterValueGetter: ({ data }) => webhookDeliveryStatus(data),
4601
+ valueGetter: ({ data }) => statusLabels[webhookDeliveryStatus(data)],
4602
+ filterOptions: Object.entries(statusLabels).map(([value, label]) => ({
4603
+ value,
4604
+ label
4605
+ })),
4606
+ typeOptions: {
4607
+ imageVariant: "square",
4608
+ getItem: (delivery) => {
4609
+ const displayStatus = webhookDeliveryStatus(delivery);
4610
+ const details = displayStatus === "failed" ? [
4611
+ delivery.error ?? labels.errorUnavailable,
4612
+ `${labels.retries}: ${delivery.retries}`,
4613
+ ...delivery.status === "pending" ? [
4614
+ `${labels.retryAt}: ${dateFormatter.format(delivery.retryAt)}`
4615
+ ] : []
4616
+ ] : [];
4617
+ return {
4618
+ label: statusLabels[displayStatus],
4619
+ description: details.join(" · ") || undefined,
4620
+ icon: displayStatus === "failed" ? /* @__PURE__ */ jsx19(X2, {}) : displayStatus === "success" ? /* @__PURE__ */ jsx19(Check3, {}) : /* @__PURE__ */ jsx19(Clock, {}),
4621
+ iconClassName: displayStatus === "failed" ? "bg-destructive/10 text-destructive" : displayStatus === "success" ? "bg-success/10 text-success" : "bg-primary/10 text-primary"
4622
+ };
4623
+ }
4624
+ }
4625
+ },
4626
+ ...linksColumn ? [linksColumn] : [],
4627
+ {
4628
+ colId: "data",
4629
+ headerName: labels.payload,
4630
+ sortable: false,
4631
+ filterable: false,
4632
+ cellRenderer: ({ data }) => /* @__PURE__ */ jsxs13(Button, {
4633
+ variant: "outline",
4634
+ size: "sm",
4635
+ onClick: (event) => {
4636
+ event.stopPropagation();
4637
+ setSelected(data);
4638
+ },
4639
+ children: [
4640
+ /* @__PURE__ */ jsx19(FileJson2, {
4641
+ "data-icon": "inline-start"
4642
+ }),
4643
+ labels.viewPayload
4644
+ ]
4645
+ })
4646
+ },
4647
+ { field: "createdAt", headerName: labels.createdAt, type: "dateTime" },
4648
+ { field: "completedAt", headerName: labels.completedAt, type: "dateTime" }
4649
+ ];
4650
+ return /* @__PURE__ */ jsxs13(Fragment2, {
4651
+ children: [
4652
+ /* @__PURE__ */ jsx19(DataTable, {
4653
+ locale,
4654
+ rowData: entries,
4655
+ getRowId: (row) => row.id,
4656
+ columnDefs: columns,
4657
+ initialState: { columnVisibility: { id: false } },
4658
+ state,
4659
+ onStateChange,
4660
+ status,
4661
+ features: {
4662
+ search: true,
4663
+ export: { baseName: "webhook-deliveries" },
4664
+ pagination: { mode: "server", rowCount }
4665
+ }
4666
+ }),
4667
+ /* @__PURE__ */ jsx19(Dialog, {
4668
+ open: selected !== null,
4669
+ onOpenChange: (open) => {
4670
+ if (!open)
4671
+ setSelected(null);
4672
+ },
4673
+ children: /* @__PURE__ */ jsxs13(DialogContent, {
4674
+ className: "grid max-h-[calc(100svh-2rem)] grid-rows-[auto_minmax(0,1fr)] overflow-hidden sm:max-w-4xl",
4675
+ children: [
4676
+ /* @__PURE__ */ jsx19(DialogHeader, {
4677
+ children: /* @__PURE__ */ jsx19(DialogTitle, {
4678
+ children: labels.payload
4679
+ })
4680
+ }),
4681
+ /* @__PURE__ */ jsx19("div", {
4682
+ className: "min-h-0 overflow-auto",
4683
+ children: /* @__PURE__ */ jsx19(CodeBlock, {
4684
+ code: JSON.stringify(selected?.data ?? null, null, 2),
4685
+ language: "json",
4686
+ locale
4687
+ })
4688
+ })
4689
+ ]
4690
+ })
4691
+ })
4692
+ ]
4693
+ });
4694
+ };
4695
+ export {
4696
+ WebhookDeliveryTable,
4697
+ webhookDeliveryStatus
4698
+ };