@krak-stack/registry 0.1.60 → 0.2.0

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