@krak-stack/registry 0.1.19 → 0.1.21

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 (50) hide show
  1. package/dist/components/ui/code-block.d.ts +1 -3
  2. package/dist/components/ui/code-block.js +32 -60
  3. package/dist/components/ui/data-table.d.ts +211 -273
  4. package/dist/components/ui/data-table.js +1894 -2012
  5. package/dist/components/ui/effect-form.js +169 -170
  6. package/dist/components/ui/form.js +112 -113
  7. package/dist/components/ui/icon-input.js +40 -43
  8. package/dist/components/ui/menubar.d.ts +29 -0
  9. package/dist/components/ui/pagination.js +2 -2
  10. package/dist/components/ui/sidebar-layout.js +67 -72
  11. package/dist/components/ui/theme-switcher.js +3 -3
  12. package/dist/components/ui/virtualized-combobox.js +31 -34
  13. package/dist/lib/{docs-core.d.ts → docs.d.ts} +135 -144
  14. package/dist/lib/{docs-core.js → docs.js} +597 -440
  15. package/dist/lib/documentation-toolkit.d.ts +19 -1
  16. package/dist/lib/documentation-toolkit.js +164 -66
  17. package/dist/lib/httpapi-cli.d.ts +5 -4
  18. package/dist/lib/httpapi-cli.js +256 -34
  19. package/dist/lib/httpapi-client.js +3 -3
  20. package/dist/lib/httpapi-helpers.d.ts +8 -6
  21. package/dist/lib/httpapi-helpers.js +12 -12
  22. package/dist/lib/httpapi-mcp.js +3 -3
  23. package/dist/lib/httpapi-toolkit.js +3 -3
  24. package/dist/lib/markdown/content.d.ts +13 -0
  25. package/dist/lib/markdown/server.d.ts +19 -0
  26. package/dist/lib/query.d.ts +3 -2
  27. package/dist/lib/query.js +10 -8
  28. package/dist/lib/seo.js +2 -2
  29. package/dist/lib/webfetch-toolkit.js +6 -6
  30. package/dist/services/agent/client/atom.d.ts +7 -0
  31. package/dist/services/agent/client/index.js +481 -304
  32. package/dist/services/agent/index.d.ts +16 -0
  33. package/dist/services/agent/index.js +102 -1
  34. package/dist/services/agent/schema.d.ts +28 -0
  35. package/dist/services/agent/schema.js +15 -4
  36. package/dist/services/file-extraction/index.js +4 -4
  37. package/dist/services/file-extraction/schema.js +2 -2
  38. package/dist/services/health/index.js +9 -9
  39. package/dist/services/notification/channels/ses/index.js +2 -2
  40. package/dist/services/notification/channels/ses/schema.js +2 -2
  41. package/dist/services/notification/client/index.js +5 -5
  42. package/dist/services/notification/index.js +2 -2
  43. package/dist/services/notification/persistence/drizzle.js +2 -2
  44. package/dist/services/notification/persistence/index.js +15 -15
  45. package/dist/services/notification/persistence/schema.js +12 -12
  46. package/dist/services/notification/public.js +7 -7
  47. package/dist/services/notification/schema.js +2 -2
  48. package/dist/services/s3/index.js +2 -2
  49. package/dist/services/s3/schema.js +2 -2
  50. package/package.json +6 -38
@@ -1,3 +1,36 @@
1
+ // ../../src/components/ui/data-table.tsx
2
+ import { useAtom, useAtomSet } from "@effect/atom-react";
3
+ import { Schema as Schema2 } from "effect";
4
+ import { Atom } from "effect/unstable/reactivity";
5
+ import {
6
+ ArrowDown,
7
+ ArrowUp,
8
+ ChevronDown,
9
+ ChevronRight as ChevronRight2,
10
+ ChevronsUpDown as ChevronsUpDown2,
11
+ Download,
12
+ EyeOff,
13
+ FileJson,
14
+ FileText,
15
+ GripVertical,
16
+ LayoutGrid,
17
+ MoreHorizontal,
18
+ RefreshCw,
19
+ Rows3,
20
+ Search,
21
+ Settings2,
22
+ X as X2
23
+ } from "lucide-react";
24
+ import {
25
+ createContext,
26
+ isValidElement,
27
+ useContext,
28
+ useLayoutEffect,
29
+ useRef as useRef2,
30
+ useState
31
+ } from "react";
32
+ import { createPortal } from "react-dom";
33
+
1
34
  // ../../src/components/ui/badge.tsx
2
35
  import { mergeProps } from "@base-ui/react/merge-props";
3
36
  import { useRender } from "@base-ui/react/use-render";
@@ -88,32 +121,14 @@ function Button({
88
121
  });
89
122
  }
90
123
 
91
- // ../../src/components/ui/checkbox.tsx
92
- import { Checkbox as CheckboxPrimitive } from "@base-ui/react/checkbox";
93
- import { CheckIcon } from "lucide-react";
94
- import { jsx as jsx2 } from "react/jsx-runtime";
95
- "use client";
96
- function Checkbox({ className, ...props }) {
97
- return /* @__PURE__ */ jsx2(CheckboxPrimitive.Root, {
98
- "data-slot": "checkbox",
99
- 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),
100
- ...props,
101
- children: /* @__PURE__ */ jsx2(CheckboxPrimitive.Indicator, {
102
- "data-slot": "checkbox-indicator",
103
- className: "grid place-content-center text-current transition-none [&>svg]:size-3.5",
104
- children: /* @__PURE__ */ jsx2(CheckIcon, {})
105
- })
106
- });
107
- }
108
-
109
124
  // ../../src/components/ui/card.tsx
110
- import { jsx as jsx3 } from "react/jsx-runtime";
125
+ import { jsx as jsx2 } from "react/jsx-runtime";
111
126
  function Card({
112
127
  className,
113
128
  size = "default",
114
129
  ...props
115
130
  }) {
116
- return /* @__PURE__ */ jsx3("div", {
131
+ return /* @__PURE__ */ jsx2("div", {
117
132
  "data-slot": "card",
118
133
  "data-size": size,
119
134
  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),
@@ -121,38 +136,35 @@ function Card({
121
136
  });
122
137
  }
123
138
  function CardHeader({ className, ...props }) {
124
- return /* @__PURE__ */ jsx3("div", {
139
+ return /* @__PURE__ */ jsx2("div", {
125
140
  "data-slot": "card-header",
126
141
  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),
127
142
  ...props
128
143
  });
129
144
  }
130
145
  function CardTitle({ className, ...props }) {
131
- return /* @__PURE__ */ jsx3("div", {
146
+ return /* @__PURE__ */ jsx2("div", {
132
147
  "data-slot": "card-title",
133
148
  className: cn("text-base leading-normal font-medium group-data-[size=sm]/card:text-sm", className),
134
149
  ...props
135
150
  });
136
151
  }
137
- function CardDescription({ className, ...props }) {
138
- return /* @__PURE__ */ jsx3("div", {
139
- "data-slot": "card-description",
140
- className: cn("text-sm text-muted-foreground", className),
141
- ...props
142
- });
143
- }
144
- function CardAction({ className, ...props }) {
145
- return /* @__PURE__ */ jsx3("div", {
146
- "data-slot": "card-action",
147
- className: cn("col-start-2 row-span-2 row-start-1 self-start justify-self-end", className),
148
- ...props
149
- });
150
- }
151
- function CardContent({ className, ...props }) {
152
- return /* @__PURE__ */ jsx3("div", {
153
- "data-slot": "card-content",
154
- className: cn("px-(--card-spacing)", className),
155
- ...props
152
+
153
+ // ../../src/components/ui/checkbox.tsx
154
+ import { Checkbox as CheckboxPrimitive } from "@base-ui/react/checkbox";
155
+ import { CheckIcon } from "lucide-react";
156
+ import { jsx as jsx3 } from "react/jsx-runtime";
157
+ "use client";
158
+ function Checkbox({ className, ...props }) {
159
+ return /* @__PURE__ */ jsx3(CheckboxPrimitive.Root, {
160
+ "data-slot": "checkbox",
161
+ 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),
162
+ ...props,
163
+ children: /* @__PURE__ */ jsx3(CheckboxPrimitive.Indicator, {
164
+ "data-slot": "checkbox-indicator",
165
+ className: "grid place-content-center text-current transition-none [&>svg]:size-3.5",
166
+ children: /* @__PURE__ */ jsx3(CheckIcon, {})
167
+ })
156
168
  });
157
169
  }
158
170
 
@@ -270,60 +282,12 @@ function DropdownMenuSubContent({
270
282
  ...props
271
283
  });
272
284
  }
273
- function DropdownMenuCheckboxItem({
274
- className,
275
- children,
276
- checked,
277
- inset,
278
- ...props
279
- }) {
280
- return /* @__PURE__ */ jsxs(MenuPrimitive.CheckboxItem, {
281
- "data-slot": "dropdown-menu-checkbox-item",
282
- "data-inset": inset,
283
- className: cn("relative flex 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 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),
284
- checked,
285
- ...props,
286
- children: [
287
- /* @__PURE__ */ jsx4("span", {
288
- className: "pointer-events-none absolute right-2 flex items-center justify-center",
289
- "data-slot": "dropdown-menu-checkbox-item-indicator",
290
- children: /* @__PURE__ */ jsx4(MenuPrimitive.CheckboxItemIndicator, {
291
- children: /* @__PURE__ */ jsx4(CheckIcon2, {})
292
- })
293
- }),
294
- children
295
- ]
296
- });
297
- }
298
285
  function DropdownMenuRadioGroup({ ...props }) {
299
286
  return /* @__PURE__ */ jsx4(MenuPrimitive.RadioGroup, {
300
287
  "data-slot": "dropdown-menu-radio-group",
301
288
  ...props
302
289
  });
303
290
  }
304
- function DropdownMenuRadioItem({
305
- className,
306
- children,
307
- inset,
308
- ...props
309
- }) {
310
- return /* @__PURE__ */ jsxs(MenuPrimitive.RadioItem, {
311
- "data-slot": "dropdown-menu-radio-item",
312
- "data-inset": inset,
313
- className: cn("relative flex 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 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),
314
- ...props,
315
- children: [
316
- /* @__PURE__ */ jsx4("span", {
317
- className: "pointer-events-none absolute right-2 flex items-center justify-center",
318
- "data-slot": "dropdown-menu-radio-item-indicator",
319
- children: /* @__PURE__ */ jsx4(MenuPrimitive.RadioItemIndicator, {
320
- children: /* @__PURE__ */ jsx4(CheckIcon2, {})
321
- })
322
- }),
323
- children
324
- ]
325
- });
326
- }
327
291
  function DropdownMenuSeparator({
328
292
  className,
329
293
  ...props
@@ -813,6 +777,180 @@ function Loading({
813
777
  });
814
778
  }
815
779
 
780
+ // ../../src/components/ui/menubar.tsx
781
+ import { Menu as MenuPrimitive2 } from "@base-ui/react/menu";
782
+ import { Menubar as MenubarPrimitive } from "@base-ui/react/menubar";
783
+ import { CheckIcon as CheckIcon3 } from "lucide-react";
784
+ import { jsx as jsx7, jsxs as jsxs3 } from "react/jsx-runtime";
785
+ "use client";
786
+ function Menubar({ className, ...props }) {
787
+ return /* @__PURE__ */ jsx7(MenubarPrimitive, {
788
+ "data-slot": "menubar",
789
+ className: cn("flex h-9 items-center gap-1 rounded-md border p-1 shadow-xs", className),
790
+ ...props
791
+ });
792
+ }
793
+ function MenubarMenu({ ...props }) {
794
+ return /* @__PURE__ */ jsx7(DropdownMenu, {
795
+ "data-slot": "menubar-menu",
796
+ ...props
797
+ });
798
+ }
799
+ function MenubarGroup({
800
+ ...props
801
+ }) {
802
+ return /* @__PURE__ */ jsx7(DropdownMenuGroup, {
803
+ "data-slot": "menubar-group",
804
+ ...props
805
+ });
806
+ }
807
+ function MenubarTrigger({
808
+ className,
809
+ ...props
810
+ }) {
811
+ return /* @__PURE__ */ jsx7(DropdownMenuTrigger, {
812
+ "data-slot": "menubar-trigger",
813
+ 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),
814
+ ...props
815
+ });
816
+ }
817
+ function MenubarContent({
818
+ className,
819
+ align = "start",
820
+ alignOffset = -4,
821
+ sideOffset = 8,
822
+ ...props
823
+ }) {
824
+ return /* @__PURE__ */ jsx7(DropdownMenuContent, {
825
+ "data-slot": "menubar-content",
826
+ align,
827
+ alignOffset,
828
+ sideOffset,
829
+ 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),
830
+ ...props
831
+ });
832
+ }
833
+ function MenubarItem({
834
+ className,
835
+ inset,
836
+ variant = "default",
837
+ ...props
838
+ }) {
839
+ return /* @__PURE__ */ jsx7(DropdownMenuItem, {
840
+ "data-slot": "menubar-item",
841
+ "data-inset": inset,
842
+ "data-variant": variant,
843
+ 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),
844
+ ...props
845
+ });
846
+ }
847
+ function MenubarCheckboxItem({
848
+ className,
849
+ children,
850
+ checked,
851
+ inset,
852
+ ...props
853
+ }) {
854
+ return /* @__PURE__ */ jsxs3(MenuPrimitive2.CheckboxItem, {
855
+ "data-slot": "menubar-checkbox-item",
856
+ "data-inset": inset,
857
+ 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),
858
+ checked,
859
+ ...props,
860
+ children: [
861
+ /* @__PURE__ */ jsx7("span", {
862
+ className: "pointer-events-none absolute left-2 flex size-4 items-center justify-center [&_svg:not([class*='size-'])]:size-4",
863
+ children: /* @__PURE__ */ jsx7(MenuPrimitive2.CheckboxItemIndicator, {
864
+ children: /* @__PURE__ */ jsx7(CheckIcon3, {})
865
+ })
866
+ }),
867
+ children
868
+ ]
869
+ });
870
+ }
871
+ function MenubarRadioGroup({
872
+ ...props
873
+ }) {
874
+ return /* @__PURE__ */ jsx7(DropdownMenuRadioGroup, {
875
+ "data-slot": "menubar-radio-group",
876
+ ...props
877
+ });
878
+ }
879
+ function MenubarRadioItem({
880
+ className,
881
+ children,
882
+ inset,
883
+ ...props
884
+ }) {
885
+ return /* @__PURE__ */ jsxs3(MenuPrimitive2.RadioItem, {
886
+ "data-slot": "menubar-radio-item",
887
+ "data-inset": inset,
888
+ 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),
889
+ ...props,
890
+ children: [
891
+ /* @__PURE__ */ jsx7("span", {
892
+ className: "pointer-events-none absolute left-2 flex size-4 items-center justify-center [&_svg:not([class*='size-'])]:size-4",
893
+ children: /* @__PURE__ */ jsx7(MenuPrimitive2.RadioItemIndicator, {
894
+ children: /* @__PURE__ */ jsx7(CheckIcon3, {})
895
+ })
896
+ }),
897
+ children
898
+ ]
899
+ });
900
+ }
901
+ function MenubarLabel({
902
+ className,
903
+ inset,
904
+ ...props
905
+ }) {
906
+ return /* @__PURE__ */ jsx7(DropdownMenuLabel, {
907
+ "data-slot": "menubar-label",
908
+ "data-inset": inset,
909
+ className: cn("px-2 py-1.5 text-sm font-medium data-inset:pl-8", className),
910
+ ...props
911
+ });
912
+ }
913
+ function MenubarSeparator({
914
+ className,
915
+ ...props
916
+ }) {
917
+ return /* @__PURE__ */ jsx7(DropdownMenuSeparator, {
918
+ "data-slot": "menubar-separator",
919
+ className: cn("-mx-1 my-1 h-px bg-border", className),
920
+ ...props
921
+ });
922
+ }
923
+ function MenubarSub({
924
+ ...props
925
+ }) {
926
+ return /* @__PURE__ */ jsx7(DropdownMenuSub, {
927
+ "data-slot": "menubar-sub",
928
+ ...props
929
+ });
930
+ }
931
+ function MenubarSubTrigger({
932
+ className,
933
+ inset,
934
+ ...props
935
+ }) {
936
+ return /* @__PURE__ */ jsx7(DropdownMenuSubTrigger, {
937
+ "data-slot": "menubar-sub-trigger",
938
+ "data-inset": inset,
939
+ 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),
940
+ ...props
941
+ });
942
+ }
943
+ function MenubarSubContent({
944
+ className,
945
+ ...props
946
+ }) {
947
+ return /* @__PURE__ */ jsx7(DropdownMenuSubContent, {
948
+ "data-slot": "menubar-sub-content",
949
+ 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),
950
+ ...props
951
+ });
952
+ }
953
+
816
954
  // ../../src/components/ui/pagination.tsx
817
955
  import {
818
956
  ChevronLeft,
@@ -823,10 +961,10 @@ import {
823
961
  import { useId } from "react";
824
962
 
825
963
  // ../../src/components/ui/label.tsx
826
- import { jsx as jsx7 } from "react/jsx-runtime";
964
+ import { jsx as jsx8 } from "react/jsx-runtime";
827
965
  "use client";
828
966
  function Label({ className, ...props }) {
829
- return /* @__PURE__ */ jsx7("label", {
967
+ return /* @__PURE__ */ jsx8("label", {
830
968
  "data-slot": "label",
831
969
  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),
832
970
  ...props
@@ -835,12 +973,12 @@ function Label({ className, ...props }) {
835
973
 
836
974
  // ../../src/components/ui/select.tsx
837
975
  import { Select as SelectPrimitive } from "@base-ui/react/select";
838
- import { ChevronDownIcon, CheckIcon as CheckIcon3, ChevronUpIcon } from "lucide-react";
839
- import { jsx as jsx8, jsxs as jsxs3 } from "react/jsx-runtime";
976
+ import { ChevronDownIcon, CheckIcon as CheckIcon4, ChevronUpIcon } from "lucide-react";
977
+ import { jsx as jsx9, jsxs as jsxs4 } from "react/jsx-runtime";
840
978
  "use client";
841
979
  var Select = SelectPrimitive.Root;
842
980
  function SelectValue({ className, ...props }) {
843
- return /* @__PURE__ */ jsx8(SelectPrimitive.Value, {
981
+ return /* @__PURE__ */ jsx9(SelectPrimitive.Value, {
844
982
  "data-slot": "select-value",
845
983
  className: cn("flex flex-1 text-left", className),
846
984
  ...props
@@ -852,15 +990,15 @@ function SelectTrigger({
852
990
  children,
853
991
  ...props
854
992
  }) {
855
- return /* @__PURE__ */ jsxs3(SelectPrimitive.Trigger, {
993
+ return /* @__PURE__ */ jsxs4(SelectPrimitive.Trigger, {
856
994
  "data-slot": "select-trigger",
857
995
  "data-size": size,
858
996
  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),
859
997
  ...props,
860
998
  children: [
861
999
  children,
862
- /* @__PURE__ */ jsx8(SelectPrimitive.Icon, {
863
- render: /* @__PURE__ */ jsx8(ChevronDownIcon, {
1000
+ /* @__PURE__ */ jsx9(SelectPrimitive.Icon, {
1001
+ render: /* @__PURE__ */ jsx9(ChevronDownIcon, {
864
1002
  className: "text-muted-foreground pointer-events-none size-4"
865
1003
  })
866
1004
  })
@@ -877,25 +1015,25 @@ function SelectContent({
877
1015
  alignItemWithTrigger = true,
878
1016
  ...props
879
1017
  }) {
880
- return /* @__PURE__ */ jsx8(SelectPrimitive.Portal, {
881
- children: /* @__PURE__ */ jsx8(SelectPrimitive.Positioner, {
1018
+ return /* @__PURE__ */ jsx9(SelectPrimitive.Portal, {
1019
+ children: /* @__PURE__ */ jsx9(SelectPrimitive.Positioner, {
882
1020
  side,
883
1021
  sideOffset,
884
1022
  align,
885
1023
  alignOffset,
886
1024
  alignItemWithTrigger,
887
1025
  className: "isolate z-50",
888
- children: /* @__PURE__ */ jsxs3(SelectPrimitive.Popup, {
1026
+ children: /* @__PURE__ */ jsxs4(SelectPrimitive.Popup, {
889
1027
  "data-slot": "select-content",
890
1028
  "data-align-trigger": alignItemWithTrigger,
891
1029
  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),
892
1030
  ...props,
893
1031
  children: [
894
- /* @__PURE__ */ jsx8(SelectScrollUpButton, {}),
895
- /* @__PURE__ */ jsx8(SelectPrimitive.List, {
1032
+ /* @__PURE__ */ jsx9(SelectScrollUpButton, {}),
1033
+ /* @__PURE__ */ jsx9(SelectPrimitive.List, {
896
1034
  children
897
1035
  }),
898
- /* @__PURE__ */ jsx8(SelectScrollDownButton, {})
1036
+ /* @__PURE__ */ jsx9(SelectScrollDownButton, {})
899
1037
  ]
900
1038
  })
901
1039
  })
@@ -906,20 +1044,20 @@ function SelectItem({
906
1044
  children,
907
1045
  ...props
908
1046
  }) {
909
- return /* @__PURE__ */ jsxs3(SelectPrimitive.Item, {
1047
+ return /* @__PURE__ */ jsxs4(SelectPrimitive.Item, {
910
1048
  "data-slot": "select-item",
911
1049
  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),
912
1050
  ...props,
913
1051
  children: [
914
- /* @__PURE__ */ jsx8(SelectPrimitive.ItemText, {
1052
+ /* @__PURE__ */ jsx9(SelectPrimitive.ItemText, {
915
1053
  className: "flex flex-1 shrink-0 gap-2 whitespace-nowrap",
916
1054
  children
917
1055
  }),
918
- /* @__PURE__ */ jsx8(SelectPrimitive.ItemIndicator, {
919
- render: /* @__PURE__ */ jsx8("span", {
1056
+ /* @__PURE__ */ jsx9(SelectPrimitive.ItemIndicator, {
1057
+ render: /* @__PURE__ */ jsx9("span", {
920
1058
  className: "pointer-events-none absolute right-2 flex size-4 items-center justify-center"
921
1059
  }),
922
- children: /* @__PURE__ */ jsx8(CheckIcon3, {
1060
+ children: /* @__PURE__ */ jsx9(CheckIcon4, {
923
1061
  className: "pointer-events-none"
924
1062
  })
925
1063
  })
@@ -930,27 +1068,27 @@ function SelectScrollUpButton({
930
1068
  className,
931
1069
  ...props
932
1070
  }) {
933
- return /* @__PURE__ */ jsx8(SelectPrimitive.ScrollUpArrow, {
1071
+ return /* @__PURE__ */ jsx9(SelectPrimitive.ScrollUpArrow, {
934
1072
  "data-slot": "select-scroll-up-button",
935
1073
  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),
936
1074
  ...props,
937
- children: /* @__PURE__ */ jsx8(ChevronUpIcon, {})
1075
+ children: /* @__PURE__ */ jsx9(ChevronUpIcon, {})
938
1076
  });
939
1077
  }
940
1078
  function SelectScrollDownButton({
941
1079
  className,
942
1080
  ...props
943
1081
  }) {
944
- return /* @__PURE__ */ jsx8(SelectPrimitive.ScrollDownArrow, {
1082
+ return /* @__PURE__ */ jsx9(SelectPrimitive.ScrollDownArrow, {
945
1083
  "data-slot": "select-scroll-down-button",
946
1084
  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),
947
1085
  ...props,
948
- children: /* @__PURE__ */ jsx8(ChevronDownIcon, {})
1086
+ children: /* @__PURE__ */ jsx9(ChevronDownIcon, {})
949
1087
  });
950
1088
  }
951
1089
 
952
1090
  // ../../src/components/ui/pagination.tsx
953
- import { jsx as jsx9, jsxs as jsxs4 } from "react/jsx-runtime";
1091
+ import { jsx as jsx10, jsxs as jsxs5 } from "react/jsx-runtime";
954
1092
  var messages = {
955
1093
  en: {
956
1094
  pageSize: "Page size",
@@ -994,32 +1132,32 @@ function Pagination({
994
1132
  const pageSizeId = useId();
995
1133
  const canGoBack = page > 0;
996
1134
  const canGoForward = page + 1 < pageCount;
997
- return /* @__PURE__ */ jsxs4("div", {
1135
+ return /* @__PURE__ */ jsxs5("div", {
998
1136
  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"),
999
1137
  children: [
1000
- showResults ? /* @__PURE__ */ jsxs4("div", {
1138
+ showResults ? /* @__PURE__ */ jsxs5("div", {
1001
1139
  className: "text-muted-foreground flex flex-wrap items-center gap-x-3 gap-y-1 text-sm",
1002
1140
  children: [
1003
- /* @__PURE__ */ jsx9("span", {
1141
+ /* @__PURE__ */ jsx10("span", {
1004
1142
  children: labels2.results(totalRows)
1005
1143
  }),
1006
- selectedRows > 0 ? /* @__PURE__ */ jsx9("span", {
1144
+ selectedRows > 0 ? /* @__PURE__ */ jsx10("span", {
1007
1145
  children: labels2.selectedOf(selectedRows, totalRows)
1008
1146
  }) : null
1009
1147
  ]
1010
1148
  }) : null,
1011
- /* @__PURE__ */ jsxs4("div", {
1149
+ /* @__PURE__ */ jsxs5("div", {
1012
1150
  className: cn("flex items-center gap-4 sm:justify-end", compact && "flex-wrap justify-between gap-2 sm:justify-between"),
1013
1151
  children: [
1014
- /* @__PURE__ */ jsxs4("div", {
1152
+ /* @__PURE__ */ jsxs5("div", {
1015
1153
  className: "flex items-center gap-2",
1016
1154
  children: [
1017
- /* @__PURE__ */ jsx9(Label, {
1155
+ /* @__PURE__ */ jsx10(Label, {
1018
1156
  htmlFor: pageSizeId,
1019
1157
  className: cn("hidden text-sm sm:block", compact && "block"),
1020
1158
  children: labels2.pageSize
1021
1159
  }),
1022
- /* @__PURE__ */ jsxs4(Select, {
1160
+ /* @__PURE__ */ jsxs5(Select, {
1023
1161
  items: pageSizes.map((size) => ({
1024
1162
  label: size.toString(),
1025
1163
  value: size.toString()
@@ -1027,16 +1165,16 @@ function Pagination({
1027
1165
  value: `${pageSize}`,
1028
1166
  onValueChange: (value) => onPageSizeChange(Number(value)),
1029
1167
  children: [
1030
- /* @__PURE__ */ jsx9(SelectTrigger, {
1168
+ /* @__PURE__ */ jsx10(SelectTrigger, {
1031
1169
  className: "h-8 w-[70px]",
1032
1170
  id: pageSizeId,
1033
- children: /* @__PURE__ */ jsx9(SelectValue, {
1171
+ children: /* @__PURE__ */ jsx10(SelectValue, {
1034
1172
  placeholder: pageSize
1035
1173
  })
1036
1174
  }),
1037
- /* @__PURE__ */ jsx9(SelectContent, {
1175
+ /* @__PURE__ */ jsx10(SelectContent, {
1038
1176
  side: "top",
1039
- children: pageSizes.map((size) => /* @__PURE__ */ jsx9(SelectItem, {
1177
+ children: pageSizes.map((size) => /* @__PURE__ */ jsx10(SelectItem, {
1040
1178
  value: `${size}`,
1041
1179
  children: size
1042
1180
  }, size))
@@ -1045,66 +1183,66 @@ function Pagination({
1045
1183
  })
1046
1184
  ]
1047
1185
  }),
1048
- /* @__PURE__ */ jsxs4("div", {
1186
+ /* @__PURE__ */ jsxs5("div", {
1049
1187
  className: "flex items-center gap-2",
1050
1188
  children: [
1051
- /* @__PURE__ */ jsx9("div", {
1189
+ /* @__PURE__ */ jsx10("div", {
1052
1190
  className: "flex items-center justify-center text-sm font-medium sm:block",
1053
1191
  children: labels2.pageOf(page + 1, pageCount)
1054
1192
  }),
1055
- /* @__PURE__ */ jsxs4("div", {
1193
+ /* @__PURE__ */ jsxs5("div", {
1056
1194
  className: "flex items-center gap-1",
1057
1195
  children: [
1058
- /* @__PURE__ */ jsxs4(Button, {
1196
+ /* @__PURE__ */ jsxs5(Button, {
1059
1197
  className: cn("hidden h-8 w-8 p-0 lg:flex", compact && "!hidden"),
1060
1198
  disabled: !canGoBack,
1061
1199
  onClick: () => onPageChange(0),
1062
1200
  type: "button",
1063
1201
  children: [
1064
- /* @__PURE__ */ jsx9("span", {
1202
+ /* @__PURE__ */ jsx10("span", {
1065
1203
  className: "sr-only",
1066
1204
  children: labels2.goToFirstPage
1067
1205
  }),
1068
- /* @__PURE__ */ jsx9(ChevronsLeft, {})
1206
+ /* @__PURE__ */ jsx10(ChevronsLeft, {})
1069
1207
  ]
1070
1208
  }),
1071
- /* @__PURE__ */ jsxs4(Button, {
1209
+ /* @__PURE__ */ jsxs5(Button, {
1072
1210
  className: "h-8 w-8 p-0",
1073
1211
  disabled: !canGoBack,
1074
1212
  onClick: () => onPageChange(page - 1),
1075
1213
  type: "button",
1076
1214
  children: [
1077
- /* @__PURE__ */ jsx9("span", {
1215
+ /* @__PURE__ */ jsx10("span", {
1078
1216
  className: "sr-only",
1079
1217
  children: labels2.goToPreviousPage
1080
1218
  }),
1081
- /* @__PURE__ */ jsx9(ChevronLeft, {})
1219
+ /* @__PURE__ */ jsx10(ChevronLeft, {})
1082
1220
  ]
1083
1221
  }),
1084
- /* @__PURE__ */ jsxs4(Button, {
1222
+ /* @__PURE__ */ jsxs5(Button, {
1085
1223
  className: "h-8 w-8 p-0",
1086
1224
  disabled: !canGoForward,
1087
1225
  onClick: () => onPageChange(page + 1),
1088
1226
  type: "button",
1089
1227
  children: [
1090
- /* @__PURE__ */ jsx9("span", {
1228
+ /* @__PURE__ */ jsx10("span", {
1091
1229
  className: "sr-only",
1092
1230
  children: labels2.goToNextPage
1093
1231
  }),
1094
- /* @__PURE__ */ jsx9(ChevronRight, {})
1232
+ /* @__PURE__ */ jsx10(ChevronRight, {})
1095
1233
  ]
1096
1234
  }),
1097
- /* @__PURE__ */ jsxs4(Button, {
1235
+ /* @__PURE__ */ jsxs5(Button, {
1098
1236
  className: cn("hidden h-8 w-8 p-0 lg:flex", compact && "!hidden"),
1099
1237
  disabled: !canGoForward,
1100
1238
  onClick: () => onPageChange(pageCount - 1),
1101
1239
  type: "button",
1102
1240
  children: [
1103
- /* @__PURE__ */ jsx9("span", {
1241
+ /* @__PURE__ */ jsx10("span", {
1104
1242
  className: "sr-only",
1105
1243
  children: labels2.goToLastPage
1106
1244
  }),
1107
- /* @__PURE__ */ jsx9(ChevronsRight, {})
1245
+ /* @__PURE__ */ jsx10(ChevronsRight, {})
1108
1246
  ]
1109
1247
  })
1110
1248
  ]
@@ -1119,15 +1257,15 @@ function Pagination({
1119
1257
 
1120
1258
  // ../../src/components/ui/popover.tsx
1121
1259
  import { Popover as PopoverPrimitive } from "@base-ui/react/popover";
1122
- import { jsx as jsx10 } from "react/jsx-runtime";
1260
+ import { jsx as jsx11 } from "react/jsx-runtime";
1123
1261
  function Popover({ ...props }) {
1124
- return /* @__PURE__ */ jsx10(PopoverPrimitive.Root, {
1262
+ return /* @__PURE__ */ jsx11(PopoverPrimitive.Root, {
1125
1263
  "data-slot": "popover",
1126
1264
  ...props
1127
1265
  });
1128
1266
  }
1129
1267
  function PopoverTrigger({ ...props }) {
1130
- return /* @__PURE__ */ jsx10(PopoverPrimitive.Trigger, {
1268
+ return /* @__PURE__ */ jsx11(PopoverPrimitive.Trigger, {
1131
1269
  "data-slot": "popover-trigger",
1132
1270
  ...props
1133
1271
  });
@@ -1140,14 +1278,14 @@ function PopoverContent({
1140
1278
  sideOffset = 4,
1141
1279
  ...props
1142
1280
  }) {
1143
- return /* @__PURE__ */ jsx10(PopoverPrimitive.Portal, {
1144
- children: /* @__PURE__ */ jsx10(PopoverPrimitive.Positioner, {
1281
+ return /* @__PURE__ */ jsx11(PopoverPrimitive.Portal, {
1282
+ children: /* @__PURE__ */ jsx11(PopoverPrimitive.Positioner, {
1145
1283
  align,
1146
1284
  alignOffset,
1147
1285
  side,
1148
1286
  sideOffset,
1149
1287
  className: "isolate z-50",
1150
- children: /* @__PURE__ */ jsx10(PopoverPrimitive.Popup, {
1288
+ children: /* @__PURE__ */ jsx11(PopoverPrimitive.Popup, {
1151
1289
  "data-slot": "popover-content",
1152
1290
  className: cn("z-50 flex w-72 origin-(--transform-origin) flex-col gap-4 rounded-md bg-popover p-4 text-sm text-popover-foreground shadow-md ring-1 ring-foreground/10 outline-hidden 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 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95", className),
1153
1291
  ...props
@@ -1158,24 +1296,24 @@ function PopoverContent({
1158
1296
 
1159
1297
  // ../../src/components/ui/scroll-area.tsx
1160
1298
  import { ScrollArea as ScrollAreaPrimitive } from "@base-ui/react/scroll-area";
1161
- import { jsx as jsx11, jsxs as jsxs5 } from "react/jsx-runtime";
1299
+ import { jsx as jsx12, jsxs as jsxs6 } from "react/jsx-runtime";
1162
1300
  function ScrollArea({
1163
1301
  className,
1164
1302
  children,
1165
1303
  ...props
1166
1304
  }) {
1167
- return /* @__PURE__ */ jsxs5(ScrollAreaPrimitive.Root, {
1305
+ return /* @__PURE__ */ jsxs6(ScrollAreaPrimitive.Root, {
1168
1306
  "data-slot": "scroll-area",
1169
1307
  className: cn("relative", className),
1170
1308
  ...props,
1171
1309
  children: [
1172
- /* @__PURE__ */ jsx11(ScrollAreaPrimitive.Viewport, {
1310
+ /* @__PURE__ */ jsx12(ScrollAreaPrimitive.Viewport, {
1173
1311
  "data-slot": "scroll-area-viewport",
1174
1312
  className: "focus-visible:ring-ring/50 size-full rounded-[inherit] transition-[color,box-shadow] outline-none focus-visible:ring-[3px] focus-visible:outline-1",
1175
1313
  children
1176
1314
  }),
1177
- /* @__PURE__ */ jsx11(ScrollBar, {}),
1178
- /* @__PURE__ */ jsx11(ScrollAreaPrimitive.Corner, {})
1315
+ /* @__PURE__ */ jsx12(ScrollBar, {}),
1316
+ /* @__PURE__ */ jsx12(ScrollAreaPrimitive.Corner, {})
1179
1317
  ]
1180
1318
  });
1181
1319
  }
@@ -1184,13 +1322,13 @@ function ScrollBar({
1184
1322
  orientation = "vertical",
1185
1323
  ...props
1186
1324
  }) {
1187
- return /* @__PURE__ */ jsx11(ScrollAreaPrimitive.Scrollbar, {
1325
+ return /* @__PURE__ */ jsx12(ScrollAreaPrimitive.Scrollbar, {
1188
1326
  "data-slot": "scroll-area-scrollbar",
1189
1327
  "data-orientation": orientation,
1190
1328
  orientation,
1191
1329
  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),
1192
1330
  ...props,
1193
- children: /* @__PURE__ */ jsx11(ScrollAreaPrimitive.Thumb, {
1331
+ children: /* @__PURE__ */ jsx12(ScrollAreaPrimitive.Thumb, {
1194
1332
  "data-slot": "scroll-area-thumb",
1195
1333
  className: "bg-border relative flex-1 rounded-full"
1196
1334
  })
@@ -1198,12 +1336,12 @@ function ScrollBar({
1198
1336
  }
1199
1337
 
1200
1338
  // ../../src/components/ui/table.tsx
1201
- import { jsx as jsx12 } from "react/jsx-runtime";
1339
+ import { jsx as jsx13 } from "react/jsx-runtime";
1202
1340
  function Table({ className, ...props }) {
1203
- return /* @__PURE__ */ jsx12("div", {
1341
+ return /* @__PURE__ */ jsx13("div", {
1204
1342
  "data-slot": "table-container",
1205
1343
  className: "relative w-full overflow-x-auto",
1206
- children: /* @__PURE__ */ jsx12("table", {
1344
+ children: /* @__PURE__ */ jsx13("table", {
1207
1345
  "data-slot": "table",
1208
1346
  className: cn("w-full caption-bottom text-sm", className),
1209
1347
  ...props
@@ -1211,35 +1349,35 @@ function Table({ className, ...props }) {
1211
1349
  });
1212
1350
  }
1213
1351
  function TableHeader({ className, ...props }) {
1214
- return /* @__PURE__ */ jsx12("thead", {
1352
+ return /* @__PURE__ */ jsx13("thead", {
1215
1353
  "data-slot": "table-header",
1216
1354
  className: cn("[&_tr]:border-b", className),
1217
1355
  ...props
1218
1356
  });
1219
1357
  }
1220
1358
  function TableBody({ className, ...props }) {
1221
- return /* @__PURE__ */ jsx12("tbody", {
1359
+ return /* @__PURE__ */ jsx13("tbody", {
1222
1360
  "data-slot": "table-body",
1223
1361
  className: cn("[&_tr:last-child]:border-0", className),
1224
1362
  ...props
1225
1363
  });
1226
1364
  }
1227
1365
  function TableRow({ className, ...props }) {
1228
- return /* @__PURE__ */ jsx12("tr", {
1366
+ return /* @__PURE__ */ jsx13("tr", {
1229
1367
  "data-slot": "table-row",
1230
1368
  className: cn("border-b transition-colors hover:bg-muted/50 has-aria-expanded:bg-muted/50 data-[state=selected]:bg-muted", className),
1231
1369
  ...props
1232
1370
  });
1233
1371
  }
1234
1372
  function TableHead({ className, ...props }) {
1235
- return /* @__PURE__ */ jsx12("th", {
1373
+ return /* @__PURE__ */ jsx13("th", {
1236
1374
  "data-slot": "table-head",
1237
1375
  className: cn("h-10 px-2 text-left align-middle font-medium whitespace-nowrap text-foreground [&:has([role=checkbox])]:pr-0", className),
1238
1376
  ...props
1239
1377
  });
1240
1378
  }
1241
1379
  function TableCell({ className, ...props }) {
1242
- return /* @__PURE__ */ jsx12("td", {
1380
+ return /* @__PURE__ */ jsx13("td", {
1243
1381
  "data-slot": "table-cell",
1244
1382
  className: cn("p-2 align-middle whitespace-nowrap [&:has([role=checkbox])]:pr-0", className),
1245
1383
  ...props
@@ -1248,26 +1386,26 @@ function TableCell({ className, ...props }) {
1248
1386
 
1249
1387
  // ../../src/components/ui/tooltip.tsx
1250
1388
  import { Tooltip as TooltipPrimitive } from "@base-ui/react/tooltip";
1251
- import { jsx as jsx13, jsxs as jsxs6 } from "react/jsx-runtime";
1389
+ import { jsx as jsx14, jsxs as jsxs7 } from "react/jsx-runtime";
1252
1390
  "use client";
1253
1391
  function TooltipProvider({
1254
1392
  delay = 0,
1255
1393
  ...props
1256
1394
  }) {
1257
- return /* @__PURE__ */ jsx13(TooltipPrimitive.Provider, {
1395
+ return /* @__PURE__ */ jsx14(TooltipPrimitive.Provider, {
1258
1396
  "data-slot": "tooltip-provider",
1259
1397
  delay,
1260
1398
  ...props
1261
1399
  });
1262
1400
  }
1263
1401
  function Tooltip({ ...props }) {
1264
- return /* @__PURE__ */ jsx13(TooltipPrimitive.Root, {
1402
+ return /* @__PURE__ */ jsx14(TooltipPrimitive.Root, {
1265
1403
  "data-slot": "tooltip",
1266
1404
  ...props
1267
1405
  });
1268
1406
  }
1269
1407
  function TooltipTrigger({ ...props }) {
1270
- return /* @__PURE__ */ jsx13(TooltipPrimitive.Trigger, {
1408
+ return /* @__PURE__ */ jsx14(TooltipPrimitive.Trigger, {
1271
1409
  "data-slot": "tooltip-trigger",
1272
1410
  ...props
1273
1411
  });
@@ -1281,20 +1419,20 @@ function TooltipContent({
1281
1419
  children,
1282
1420
  ...props
1283
1421
  }) {
1284
- return /* @__PURE__ */ jsx13(TooltipPrimitive.Portal, {
1285
- children: /* @__PURE__ */ jsx13(TooltipPrimitive.Positioner, {
1422
+ return /* @__PURE__ */ jsx14(TooltipPrimitive.Portal, {
1423
+ children: /* @__PURE__ */ jsx14(TooltipPrimitive.Positioner, {
1286
1424
  align,
1287
1425
  alignOffset,
1288
1426
  side,
1289
1427
  sideOffset,
1290
1428
  className: "isolate z-50",
1291
- children: /* @__PURE__ */ jsxs6(TooltipPrimitive.Popup, {
1429
+ children: /* @__PURE__ */ jsxs7(TooltipPrimitive.Popup, {
1292
1430
  "data-slot": "tooltip-content",
1293
1431
  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),
1294
1432
  ...props,
1295
1433
  children: [
1296
1434
  children,
1297
- /* @__PURE__ */ jsx13(TooltipPrimitive.Arrow, {
1435
+ /* @__PURE__ */ jsx14(TooltipPrimitive.Arrow, {
1298
1436
  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"
1299
1437
  })
1300
1438
  ]
@@ -1316,11 +1454,6 @@ import {
1316
1454
 
1317
1455
  // ../../src/components/ui/input-group.tsx
1318
1456
  import { cva as cva3 } from "class-variance-authority";
1319
-
1320
- // ../../src/components/ui/textarea.tsx
1321
- import { jsx as jsx14 } from "react/jsx-runtime";
1322
-
1323
- // ../../src/components/ui/input-group.tsx
1324
1457
  import { jsx as jsx15 } from "react/jsx-runtime";
1325
1458
  function InputGroup({ className, ...props }) {
1326
1459
  return /* @__PURE__ */ jsx15("div", {
@@ -1364,7 +1497,7 @@ function InputGroupInput({
1364
1497
  }
1365
1498
 
1366
1499
  // ../../src/components/ui/virtualized-combobox.tsx
1367
- import { jsx as jsx16, jsxs as jsxs7 } from "react/jsx-runtime";
1500
+ import { jsx as jsx16, jsxs as jsxs8 } from "react/jsx-runtime";
1368
1501
  "use client";
1369
1502
  var messages2 = {
1370
1503
  en: {
@@ -1476,7 +1609,7 @@ var VirtualizedComboboxList = ({
1476
1609
  })
1477
1610
  }, entry.key);
1478
1611
  }
1479
- return /* @__PURE__ */ jsxs7(ComboboxPrimitive.Item, {
1612
+ return /* @__PURE__ */ jsxs8(ComboboxPrimitive.Item, {
1480
1613
  "aria-posinset": entry.index + 1,
1481
1614
  "aria-setsize": filteredItems.length,
1482
1615
  className: "data-highlighted:bg-accent data-highlighted:text-accent-foreground absolute top-0 left-0 flex w-full cursor-default items-center gap-2 rounded-sm py-1.5 pr-8 pl-2 text-sm outline-hidden select-none data-disabled:pointer-events-none data-disabled:opacity-50",
@@ -1517,7 +1650,7 @@ var VirtualizedComboboxContent = ({
1517
1650
  className: "isolate z-50",
1518
1651
  side: "bottom",
1519
1652
  sideOffset: 6,
1520
- children: /* @__PURE__ */ jsxs7(ComboboxPrimitive.Popup, {
1653
+ children: /* @__PURE__ */ jsxs8(ComboboxPrimitive.Popup, {
1521
1654
  className: cn("relative max-h-(--available-height) w-(--anchor-width) max-w-(--available-width) min-w-0 origin-(--transform-origin) overflow-hidden rounded-md bg-popover text-popover-foreground shadow-md ring-1 ring-foreground/10 duration-100 data-[side=bottom]:slide-in-from-top-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-in-95", contentClassName),
1522
1655
  children: [
1523
1656
  /* @__PURE__ */ jsx16("div", {
@@ -1544,7 +1677,7 @@ var VirtualizedComboboxContent = ({
1544
1677
  })
1545
1678
  });
1546
1679
  };
1547
- var defaultTrigger = (ariaLabel, ariaInvalid, disabled, label, triggerId) => /* @__PURE__ */ jsxs7(Button, {
1680
+ var defaultTrigger = (ariaLabel, ariaInvalid, disabled, label, triggerId) => /* @__PURE__ */ jsxs8(Button, {
1548
1681
  "aria-label": ariaLabel,
1549
1682
  "aria-invalid": ariaInvalid,
1550
1683
  className: "w-full max-w-full min-w-0 justify-between overflow-hidden",
@@ -1584,7 +1717,7 @@ var VirtualizedComboboxSingle = (props) => {
1584
1717
  const virtualizerRef = useComboboxVirtualizerRef(props.virtualizerRef);
1585
1718
  const itemIndexRef = useRef(new Map);
1586
1719
  const labels2 = virtualizedComboboxMessages(props.messages);
1587
- return /* @__PURE__ */ jsxs7(ComboboxPrimitive.Root, {
1720
+ return /* @__PURE__ */ jsxs8(ComboboxPrimitive.Root, {
1588
1721
  disabled: props.disabled,
1589
1722
  inputValue: props.searchValue,
1590
1723
  items: [...props.items],
@@ -1602,7 +1735,7 @@ var VirtualizedComboboxSingle = (props) => {
1602
1735
  value: props.value,
1603
1736
  virtualized: true,
1604
1737
  children: [
1605
- /* @__PURE__ */ jsxs7("div", {
1738
+ /* @__PURE__ */ jsxs8("div", {
1606
1739
  className: "relative",
1607
1740
  children: [
1608
1741
  /* @__PURE__ */ jsx16(ComboboxPrimitive.Trigger, {
@@ -1625,7 +1758,7 @@ var VirtualizedComboboxMultiple = (props) => {
1625
1758
  const virtualizerRef = useComboboxVirtualizerRef(props.virtualizerRef);
1626
1759
  const itemIndexRef = useRef(new Map);
1627
1760
  const labels2 = virtualizedComboboxMessages(props.messages);
1628
- return /* @__PURE__ */ jsxs7(ComboboxPrimitive.Root, {
1761
+ return /* @__PURE__ */ jsxs8(ComboboxPrimitive.Root, {
1629
1762
  disabled: props.disabled,
1630
1763
  inputValue: props.searchValue,
1631
1764
  items: [...props.items],
@@ -1644,7 +1777,7 @@ var VirtualizedComboboxMultiple = (props) => {
1644
1777
  value: [...props.value],
1645
1778
  virtualized: true,
1646
1779
  children: [
1647
- /* @__PURE__ */ jsxs7("div", {
1780
+ /* @__PURE__ */ jsxs8("div", {
1648
1781
  className: "relative",
1649
1782
  children: [
1650
1783
  /* @__PURE__ */ jsx16(ComboboxPrimitive.Trigger, {
@@ -1758,8 +1891,8 @@ var SortParamSearch = SortParamsFromString.pipe(Schema.decodeTo(Schema.String, S
1758
1891
  examples: ["-name,age"]
1759
1892
  }));
1760
1893
  var Query = Schema.Struct({
1761
- page: Schema.Int.check(Schema.isGreaterThanOrEqualTo(0)),
1762
- pageSize: Schema.Int.check(Schema.isBetween({ minimum: 1, maximum: 100 })),
1894
+ page: Schema.Int.check(Schema.isGreaterThanOrEqualTo(0)).pipe(Schema.withDecodingDefaultKey(Effect.succeed(0))),
1895
+ pageSize: Schema.Int.check(Schema.isBetween({ minimum: 1, maximum: 100 })).pipe(Schema.withDecodingDefaultKey(Effect.succeed(10))),
1763
1896
  globalFilter: Schema.optional(Schema.String),
1764
1897
  sort: Schema.optional(SortParamSearch)
1765
1898
  }).annotate({
@@ -1775,6 +1908,7 @@ var Query = Schema.Struct({
1775
1908
  }
1776
1909
  ]
1777
1910
  });
1911
+ var QueryStandard = Schema.toStandardSchemaV1(Query);
1778
1912
  var PaginationMeta = Schema.Struct({
1779
1913
  page: Schema.Int,
1780
1914
  pageSize: Schema.Int,
@@ -1788,158 +1922,7 @@ var PaginationMeta = Schema.Struct({
1788
1922
  }));
1789
1923
 
1790
1924
  // ../../src/components/ui/data-table.tsx
1791
- import { useAtom } from "@effect/atom-react";
1792
- import { BrowserKeyValueStore } from "@effect/platform-browser";
1793
- import {
1794
- DndContext,
1795
- DragOverlay,
1796
- PointerSensor,
1797
- useDraggable,
1798
- useDroppable,
1799
- useSensor,
1800
- useSensors
1801
- } from "@dnd-kit/core";
1802
- import {
1803
- arrayMove,
1804
- SortableContext,
1805
- useSortable,
1806
- verticalListSortingStrategy
1807
- } from "@dnd-kit/sortable";
1808
- import { CSS } from "@dnd-kit/utilities";
1809
- import { Effect as Effect2, Layer, Option as Option2, Schema as Schema2 } from "effect";
1810
- import { KeyValueStore } from "effect/unstable/persistence";
1811
- import { Atom } from "effect/unstable/reactivity";
1812
- import {
1813
- ArrowDown,
1814
- ArrowUp,
1815
- ChevronDown,
1816
- ChevronRight as ChevronRight2,
1817
- ChevronsUpDown as ChevronsUpDown2,
1818
- Download,
1819
- EyeOff,
1820
- FileJson,
1821
- FileText,
1822
- GripVertical,
1823
- LayoutGrid,
1824
- MoreHorizontal,
1825
- RefreshCw,
1826
- Rows3,
1827
- Search,
1828
- Settings2,
1829
- X as X2
1830
- } from "lucide-react";
1831
- import {
1832
- isValidElement,
1833
- useEffect as useEffect2,
1834
- useMemo,
1835
- useState
1836
- } from "react";
1837
- import {
1838
- useNavigate,
1839
- useRouterState
1840
- } from "@tanstack/react-router";
1841
- import {
1842
- columnFilteringFeature,
1843
- columnResizingFeature,
1844
- columnSizingFeature,
1845
- columnVisibilityFeature,
1846
- createFilteredRowModel,
1847
- createPaginatedRowModel,
1848
- createSortedRowModel,
1849
- createTableHook,
1850
- globalFilteringFeature,
1851
- rowPaginationFeature,
1852
- rowSelectionFeature,
1853
- rowSortingFeature,
1854
- tableFeatures,
1855
- flexRender
1856
- } from "@tanstack/react-table";
1857
- import { jsx as jsx17, jsxs as jsxs8, Fragment } from "react/jsx-runtime";
1858
- var DEFAULT_COLUMN_MIN_SIZE = 128;
1859
- var DEFAULT_COLUMN_SIZE = 224;
1860
- var DEFAULT_COLUMN_MAX_SIZE = 640;
1861
- var COLUMN_RESIZE_STEP = 8;
1862
- var dataTableColumnMeta = {};
1863
- var dataTableFeatures = tableFeatures({
1864
- columnFilteringFeature,
1865
- columnResizingFeature,
1866
- columnSizingFeature,
1867
- columnVisibilityFeature,
1868
- globalFilteringFeature,
1869
- rowPaginationFeature,
1870
- rowSelectionFeature,
1871
- rowSortingFeature,
1872
- filteredRowModel: createFilteredRowModel(),
1873
- paginatedRowModel: createPaginatedRowModel(),
1874
- sortedRowModel: createSortedRowModel(),
1875
- columnMeta: dataTableColumnMeta
1876
- });
1877
- var {
1878
- createAppColumnHelper: createDataTableColumnHelper,
1879
- useAppTable: useDataTable,
1880
- useCellContext: useDataTableCellContext,
1881
- useHeaderContext: useDataTableHeaderContext,
1882
- useTableContext: useDataTableContext
1883
- } = createTableHook({
1884
- features: dataTableFeatures,
1885
- defaultColumn: {
1886
- minSize: DEFAULT_COLUMN_MIN_SIZE,
1887
- size: DEFAULT_COLUMN_SIZE,
1888
- maxSize: DEFAULT_COLUMN_MAX_SIZE
1889
- },
1890
- columnResizeMode: "onChange",
1891
- enableColumnResizing: true,
1892
- tableComponents: {},
1893
- cellComponents: {},
1894
- headerComponents: {}
1895
- });
1896
- var TableSearchSchema = Schema2.Struct({
1897
- page: Schema2.optional(Query.fields.page),
1898
- pageSize: Schema2.optional(Query.fields.pageSize),
1899
- globalFilter: Query.fields.globalFilter,
1900
- sort: Query.fields.sort,
1901
- grouping: Schema2.optional(Schema2.Array(Schema2.String))
1902
- }).annotate({ identifier: "TableSearch" });
1903
- var TableSearchSchemaStandard = Schema2.toStandardSchemaV1(TableSearchSchema);
1904
- var compactDataTableStorage = Layer.effect(KeyValueStore.KeyValueStore, Effect2.map(KeyValueStore.KeyValueStore, (store) => KeyValueStore.make({
1905
- clear: store.clear,
1906
- get: (key) => Effect2.flatMap(store.get(key), (value) => value === "{}" ? Effect2.as(store.remove(key), undefined) : Effect2.succeed(value)),
1907
- getUint8Array: store.getUint8Array,
1908
- remove: store.remove,
1909
- set: (key, value) => value === "{}" ? store.remove(key) : store.set(key, value),
1910
- size: store.size
1911
- }))).pipe(Layer.provide(BrowserKeyValueStore.layerLocalStorage));
1912
- var dataTableStorageRuntime = Atom.runtime(compactDataTableStorage);
1913
- var DataTableViewSchema = Schema2.Union([
1914
- Schema2.Literal("table"),
1915
- Schema2.Literal("gallery")
1916
- ]).annotate({ identifier: "DataTableView" });
1917
- var ColumnVisibilitySchema = Schema2.Record(Schema2.String, Schema2.Boolean).annotate({ identifier: "DataTableColumnVisibility" });
1918
- var ColumnSizingSchema = Schema2.Record(Schema2.String, Schema2.Number).annotate({
1919
- identifier: "DataTableColumnSizing"
1920
- });
1921
- var RowDragDataSchema = Schema2.Struct({
1922
- type: Schema2.Literal("row"),
1923
- label: Schema2.optional(Schema2.String),
1924
- rowId: Schema2.String
1925
- }).annotate({ identifier: "DataTableRowDragData" });
1926
- var RowReorderDragDataSchema = Schema2.Struct({
1927
- type: Schema2.Literal("row-reorder")
1928
- }).annotate({ identifier: "DataTableRowReorderDragData" });
1929
- var GroupDropDataSchema = Schema2.Struct({
1930
- type: Schema2.Literal("group-target"),
1931
- fieldId: Schema2.String,
1932
- groupId: Schema2.String
1933
- }).annotate({ identifier: "DataTableGroupDropData" });
1934
- var decodeTableSearch = Schema2.decodeUnknownOption(TableSearchSchema);
1935
- var decodeDataTableView = Schema2.decodeUnknownOption(DataTableViewSchema);
1936
- var decodeRowDragData = Schema2.decodeUnknownOption(RowDragDataSchema);
1937
- var decodeRowReorderDragData = Schema2.decodeUnknownOption(RowReorderDragDataSchema);
1938
- var decodeGroupDropData = Schema2.decodeUnknownOption(GroupDropDataSchema);
1939
- var validateTableSearchUpdate = (search) => ({
1940
- ...search,
1941
- ...Schema2.decodeUnknownSync(TableSearchSchema)(search)
1942
- });
1925
+ import { jsx as jsx17, jsxs as jsxs9, Fragment } from "react/jsx-runtime";
1943
1926
  var messages3 = {
1944
1927
  en: {
1945
1928
  ...paginationMessages("en"),
@@ -1956,12 +1939,14 @@ var messages3 = {
1956
1939
  galleryView: "Gallery",
1957
1940
  columns: "Columns",
1958
1941
  groupBy: "Group by",
1959
- sortAsc: "Asc",
1960
- sortDesc: "Desc",
1961
- sortHide: "Hide",
1962
- sortClear: "Clear",
1942
+ sortAsc: "Ascending",
1943
+ sortDesc: "Descending",
1944
+ sortClear: "Clear sorting",
1963
1945
  sortBy: "Sort by",
1946
+ hideColumn: "Hide column",
1964
1947
  reorder: "Drag to reorder",
1948
+ moveUp: "Move up",
1949
+ moveDown: "Move down",
1965
1950
  resizeColumn: (column) => `Resize ${column} column`,
1966
1951
  listOthers: (count) => count === 1 ? "and 1 other" : `and ${count} others`,
1967
1952
  selectAllRows: "Select all rows on this page",
@@ -1985,10 +1970,12 @@ var messages3 = {
1985
1970
  groupBy: "Grouper par",
1986
1971
  sortAsc: "Croissant",
1987
1972
  sortDesc: "Décroissant",
1988
- sortHide: "Cacher",
1989
- sortClear: "Effacer",
1973
+ sortClear: "Effacer le tri",
1990
1974
  sortBy: "Trier par",
1975
+ hideColumn: "Masquer la colonne",
1991
1976
  reorder: "Glisser pour réordonner",
1977
+ moveUp: "Déplacer vers le haut",
1978
+ moveDown: "Déplacer vers le bas",
1992
1979
  resizeColumn: (column) => `Redimensionner la colonne ${column}`,
1993
1980
  listOthers: (count) => count === 1 ? "et 1 autre" : `et ${count} autres`,
1994
1981
  selectAllRows: "Sélectionner toutes les lignes de cette page",
@@ -2000,300 +1987,341 @@ var dataTableMessages = (overrides) => ({
2000
1987
  ...getLocale().startsWith("fr") ? messages3.fr : messages3.en,
2001
1988
  ...overrides
2002
1989
  });
2003
- var GROUP_INDENT_PX = 20;
2004
- var GROUP_ROW_INDENT_OFFSET_PX = 44;
2005
- var snapDragOverlayVerticalCenterToCursor = ({
2006
- activatorEvent,
2007
- activeNodeRect,
2008
- overlayNodeRect,
2009
- transform
2010
- }) => {
2011
- if (!globalThis.window || !(activatorEvent instanceof globalThis.window.MouseEvent) || !activeNodeRect || !overlayNodeRect) {
2012
- return transform;
2013
- }
2014
- return {
2015
- ...transform,
2016
- y: transform.y + activatorEvent.clientY - activeNodeRect.top - overlayNodeRect.height / 2
2017
- };
1990
+ var DEFAULT_MIN_WIDTH = 96;
1991
+ var DEFAULT_WIDTH = 208;
1992
+ var DEFAULT_MAX_WIDTH = 640;
1993
+ var DEFAULT_STATE = {
1994
+ globalFilter: "",
1995
+ sorting: [],
1996
+ pagination: { pageIndex: 0, pageSize: 10 },
1997
+ columnVisibility: {},
1998
+ columnSizing: {},
1999
+ rowSelection: {},
2000
+ grouping: [],
2001
+ collapsedGroups: {},
2002
+ view: "table"
2018
2003
  };
2019
- var getDefaultGrouping = (grouping) => {
2020
- if (!grouping) {
2021
- return [];
2022
- }
2023
- const validInitial = grouping.initial?.filter((id) => grouping.fields.some((field) => field.id === id));
2024
- if (validInitial?.length) {
2025
- return validInitial;
2026
- }
2027
- return grouping.fields[0] ? [grouping.fields[0].id] : [];
2004
+ var clampWidth = (column, width) => Math.min(column.maxWidth ?? DEFAULT_MAX_WIDTH, Math.max(column.minWidth ?? DEFAULT_MIN_WIDTH, width));
2005
+ var normalizeDataTableColumns = (columnDefs, columnSizing = {}) => {
2006
+ const ids = new Set;
2007
+ return columnDefs.map((colDef) => {
2008
+ const id = colDef.field ?? colDef.colId;
2009
+ if (!id) {
2010
+ throw new Error("DataTable columns require a field or colId");
2011
+ }
2012
+ if (ids.has(id)) {
2013
+ throw new Error(`DataTable column IDs must be unique: ${id}`);
2014
+ }
2015
+ ids.add(id);
2016
+ return {
2017
+ id,
2018
+ colDef,
2019
+ width: clampWidth(colDef, columnSizing[id] ?? colDef.width ?? DEFAULT_WIDTH)
2020
+ };
2021
+ });
2028
2022
  };
2029
- var getGroupTargetDropId = (key) => `group-target:${key}`;
2030
- var getRowDragId = (rowId) => `row:${rowId}`;
2031
- var getSortableRowId = (rowId) => `sortable-row:${rowId}`;
2032
- var getGroupLabels = (section) => {
2033
- const rows = section.rows.map((row) => row.original);
2034
- const label = section.field.getGroupLabel?.(section.groupId, rows) ?? section.groupId;
2035
- return section.field.renderGroupLabel?.(section.groupId, rows) ?? label;
2023
+ var getDataTableWidth = (columns, utilityColumns = 0) => columns.reduce((total, column) => total + column.width, 0) + utilityColumns * 40;
2024
+ var buildDataTableRows = (rowData, columns, getRowId) => {
2025
+ const ids = new Set;
2026
+ return rowData.map((data, index) => {
2027
+ const id = getRowId?.(data) ?? String(index);
2028
+ if (ids.has(id))
2029
+ throw new Error(`DataTable row IDs must be unique: ${id}`);
2030
+ ids.add(id);
2031
+ return {
2032
+ id,
2033
+ data,
2034
+ index,
2035
+ values: new Map(columns.map((column) => {
2036
+ const { colDef } = column;
2037
+ const value = colDef.valueGetter ? colDef.valueGetter({ data, rowId: id, rowIndex: index, colDef }) : colDef.field ? data[colDef.field] : undefined;
2038
+ return [column.id, value];
2039
+ }))
2040
+ };
2041
+ });
2036
2042
  };
2037
- var DataTableRowActions = ({
2038
- actions,
2039
- contentClassName,
2040
- row,
2041
- title
2042
- }) => {
2043
- const resolvedTitle = title ?? dataTableMessages().actions;
2044
- const visibleActions = actions.filter((action) => !action.visible || action.visible(row));
2045
- if (visibleActions.length === 0) {
2043
+ var filterDataTableRows = (rows, columns, globalFilter) => {
2044
+ const query = globalFilter.trim().toLocaleLowerCase();
2045
+ if (!query)
2046
+ return [...rows];
2047
+ const searchable = columns.filter(({ colDef }) => colDef.searchable !== false);
2048
+ return rows.filter((row) => searchable.some((column) => String(row.values.get(column.id) ?? "").toLocaleLowerCase().includes(query)));
2049
+ };
2050
+ var sortDataTableRows = (rows, columns, sorting) => {
2051
+ const byId = new Map(columns.map((column) => [column.id, column]));
2052
+ return rows.map((row, stableIndex) => ({ row, stableIndex })).sort((left, right) => {
2053
+ for (const sort of sorting) {
2054
+ const column = byId.get(sort.id);
2055
+ if (!column)
2056
+ continue;
2057
+ const leftValue = left.row.values.get(sort.id);
2058
+ const rightValue = right.row.values.get(sort.id);
2059
+ const comparison = column.colDef.comparator ? column.colDef.comparator(leftValue, rightValue, left.row.data, right.row.data) : Object.is(leftValue, rightValue) ? 0 : leftValue === null || leftValue === undefined ? 1 : rightValue === null || rightValue === undefined ? -1 : Schema2.is(Schema2.Number)(leftValue) && Schema2.is(Schema2.Number)(rightValue) ? leftValue - rightValue : String(leftValue).localeCompare(String(rightValue), undefined, { numeric: true, sensitivity: "base" });
2060
+ if (comparison !== 0)
2061
+ return sort.desc ? -comparison : comparison;
2062
+ }
2063
+ return left.stableIndex - right.stableIndex;
2064
+ }).map(({ row }) => row);
2065
+ };
2066
+ var paginateDataTableRows = (rows, pagination) => {
2067
+ const pageSize = Math.max(1, pagination.pageSize);
2068
+ const lastPageIndex = Math.max(0, Math.ceil(rows.length / pageSize) - 1);
2069
+ const pageIndex = Math.min(lastPageIndex, Math.max(0, pagination.pageIndex));
2070
+ const start = pageIndex * pageSize;
2071
+ return rows.slice(start, start + pageSize);
2072
+ };
2073
+ var mergeDataTableState = (state, controlledState = {}) => ({
2074
+ globalFilter: controlledState.globalFilter ?? state.globalFilter,
2075
+ sorting: controlledState.sorting ?? state.sorting,
2076
+ pagination: controlledState.pagination ?? state.pagination,
2077
+ columnVisibility: controlledState.columnVisibility ?? state.columnVisibility,
2078
+ columnSizing: controlledState.columnSizing ?? state.columnSizing,
2079
+ rowSelection: controlledState.rowSelection ?? state.rowSelection,
2080
+ grouping: controlledState.grouping ?? state.grouping,
2081
+ collapsedGroups: controlledState.collapsedGroups ?? state.collapsedGroups,
2082
+ view: controlledState.view ?? state.view
2083
+ });
2084
+ var sameDataTableState = (left, right) => left.globalFilter === right.globalFilter && left.sorting === right.sorting && left.pagination === right.pagination && left.columnVisibility === right.columnVisibility && left.columnSizing === right.columnSizing && left.rowSelection === right.rowSelection && left.grouping === right.grouping && left.collapsedGroups === right.collapsedGroups && left.view === right.view;
2085
+ var reorderDataTableRows = (rows, sourceRowId, targetRowId) => {
2086
+ const sourceIndex = rows.findIndex((row) => row.id === sourceRowId);
2087
+ const targetIndex = rows.findIndex((row) => row.id === targetRowId);
2088
+ const reordered = rows.map((row) => row.data);
2089
+ if (sourceIndex === -1 || targetIndex === -1 || sourceIndex === targetIndex) {
2090
+ return reordered;
2091
+ }
2092
+ const [source] = reordered.splice(sourceIndex, 1);
2093
+ if (source)
2094
+ reordered.splice(targetIndex, 0, source);
2095
+ return reordered;
2096
+ };
2097
+ var RowIdContext = createContext(null);
2098
+ var ColumnIdContext = createContext(null);
2099
+ var useRequiredId = (context) => {
2100
+ const id = useContext(context);
2101
+ if (!id)
2102
+ throw new Error("DataTable internal ID context is missing");
2103
+ return id;
2104
+ };
2105
+ var getGroupDropKey = (fieldId, groupId) => `${encodeURIComponent(fieldId)}:${encodeURIComponent(groupId)}`;
2106
+ var parseGroupDropKey = (key) => {
2107
+ const separator = key.indexOf(":");
2108
+ if (separator === -1)
2046
2109
  return null;
2110
+ return {
2111
+ fieldId: decodeURIComponent(key.slice(0, separator)),
2112
+ groupId: decodeURIComponent(key.slice(separator + 1))
2113
+ };
2114
+ };
2115
+ var findTableDragTarget = (elements, selector, root) => {
2116
+ for (const element of elements) {
2117
+ const target = element.closest(selector);
2118
+ if (target instanceof HTMLElement && root?.contains(target))
2119
+ return target;
2047
2120
  }
2048
- return /* @__PURE__ */ jsxs8(DropdownMenu, {
2049
- children: [
2050
- /* @__PURE__ */ jsx17(DropdownMenuTrigger, {
2051
- onClick: (event) => event.stopPropagation(),
2052
- render: /* @__PURE__ */ jsxs8(Button, {
2053
- className: "size-8 focus-visible:ring-inset [&_svg:not([class*='size-'])]:size-4",
2054
- variant: "ghost",
2055
- size: "icon",
2056
- children: [
2057
- /* @__PURE__ */ jsx17("span", {
2058
- className: "sr-only",
2059
- children: resolvedTitle
2060
- }),
2061
- /* @__PURE__ */ jsx17(MoreHorizontal, {})
2062
- ]
2063
- })
2064
- }),
2065
- /* @__PURE__ */ jsx17(DropdownMenuContent, {
2066
- align: "end",
2067
- className: cn("w-max", contentClassName),
2068
- children: /* @__PURE__ */ jsxs8(DropdownMenuGroup, {
2069
- children: [
2070
- /* @__PURE__ */ jsx17(DropdownMenuLabel, {
2071
- children: resolvedTitle
2072
- }),
2073
- /* @__PURE__ */ jsx17(DropdownMenuSeparator, {}),
2074
- visibleActions.map((action) => /* @__PURE__ */ jsxs8(DropdownMenuItem, {
2075
- className: "whitespace-nowrap",
2076
- onClick: (event) => {
2077
- event.stopPropagation();
2078
- action.onClick(row);
2079
- },
2080
- ...action.variant ? { variant: action.variant } : {},
2081
- children: [
2082
- action.icon,
2083
- action.name
2084
- ]
2085
- }, action.id ?? action.name))
2086
- ]
2087
- })
2088
- })
2089
- ]
2121
+ return null;
2122
+ };
2123
+ var clearDragPresentation = (root) => {
2124
+ root?.querySelectorAll("[data-drag-source], [data-drop-target], [data-drop-position]").forEach((element) => {
2125
+ element.removeAttribute("data-drag-source");
2126
+ element.removeAttribute("data-drop-target");
2127
+ element.removeAttribute("data-drop-position");
2090
2128
  });
2091
2129
  };
2092
- var DataTableBulkActions = ({
2093
- actions,
2094
- label,
2095
- selectedLabel: selectedLabel2,
2096
- rows
2097
- }) => {
2098
- const visibleActions = actions.filter((action) => !action.visible || action.visible(rows));
2099
- if (visibleActions.length === 0)
2100
- return null;
2101
- return /* @__PURE__ */ jsxs8(DropdownMenu, {
2102
- children: [
2103
- /* @__PURE__ */ jsx17(DropdownMenuTrigger, {
2104
- render: /* @__PURE__ */ jsxs8(Button, {
2105
- className: "h-9",
2106
- size: "sm",
2107
- variant: "default",
2108
- children: [
2109
- selectedLabel2,
2110
- /* @__PURE__ */ jsx17(Badge, {
2111
- className: "bg-primary-foreground/15 text-primary-foreground min-w-5 justify-center rounded-full border-0 px-1.5 tabular-nums",
2112
- variant: "secondary",
2113
- children: rows.length
2114
- }),
2115
- /* @__PURE__ */ jsx17(ChevronRight2, {
2116
- className: "rotate-90"
2117
- })
2118
- ]
2119
- })
2120
- }),
2121
- /* @__PURE__ */ jsx17(DropdownMenuContent, {
2122
- align: "start",
2123
- className: "w-max max-w-56",
2124
- children: /* @__PURE__ */ jsxs8(DropdownMenuGroup, {
2125
- children: [
2126
- /* @__PURE__ */ jsx17(DropdownMenuLabel, {
2127
- children: label
2128
- }),
2129
- /* @__PURE__ */ jsx17(DropdownMenuSeparator, {}),
2130
- visibleActions.map((action) => /* @__PURE__ */ jsxs8(DropdownMenuItem, {
2131
- className: "whitespace-nowrap",
2132
- onClick: () => action.onClick(rows),
2133
- ...action.variant ? { variant: action.variant } : {},
2134
- children: [
2135
- action.icon,
2136
- action.name
2137
- ]
2138
- }, action.id ?? action.name))
2139
- ]
2140
- })
2141
- })
2142
- ]
2130
+ var resolveConfig = (props) => {
2131
+ const features = props.features ?? {};
2132
+ const selection = features.selection;
2133
+ const getRowId = selection && selection.getRowId || props.getRowId || undefined;
2134
+ if ((selection || features.reordering) && !getRowId) {
2135
+ throw new Error("DataTable requires getRowId when selection or reordering is enabled");
2136
+ }
2137
+ return {
2138
+ getRowId,
2139
+ onQueryChange: props.onQueryChange,
2140
+ onStateChange: props.onStateChange,
2141
+ status: props.status ?? {},
2142
+ features,
2143
+ onRowClicked: props.onRowClicked,
2144
+ labels: dataTableMessages(props.messages)
2145
+ };
2146
+ };
2147
+ var dataTableStateFromQuery = (query) => query ? {
2148
+ globalFilter: query.globalFilter ?? "",
2149
+ sorting: query.sort ? Schema2.decodeSync(SortParamsFromString)(query.sort).map(({ id, direction }) => ({
2150
+ id,
2151
+ desc: direction === "desc"
2152
+ })) : [],
2153
+ pagination: { pageIndex: query.page, pageSize: query.pageSize }
2154
+ } : {};
2155
+ var queryFromDataTableState = (state) => ({
2156
+ page: state.pagination.pageIndex,
2157
+ pageSize: state.pagination.pageSize,
2158
+ globalFilter: state.globalFilter || undefined,
2159
+ sort: state.sorting.length ? Schema2.encodeSync(SortParamsFromString)(state.sorting.map(({ id, desc }) => ({
2160
+ id,
2161
+ direction: desc ? "desc" : "asc"
2162
+ }))) : undefined
2163
+ });
2164
+ var sameQuery = (left, right) => left.page === right.page && left.pageSize === right.pageSize && left.globalFilter === right.globalFilter && left.sort === right.sort;
2165
+ var controlledStateFromProps = (query, state) => ({
2166
+ ...dataTableStateFromQuery(query),
2167
+ ...state
2168
+ });
2169
+ var initialPublicState = (props) => {
2170
+ const grouping = props.features?.grouping;
2171
+ const groupingInitial = grouping && grouping.initial ? grouping.initial : [];
2172
+ return {
2173
+ ...DEFAULT_STATE,
2174
+ grouping: groupingInitial,
2175
+ ...props.initialState,
2176
+ ...controlledStateFromProps(props.query, props.state)
2177
+ };
2178
+ };
2179
+ var buildDataTableModel = (store) => {
2180
+ const columns = normalizeDataTableColumns(store.columnDefs, store.state.columnSizing);
2181
+ const selection = store.config.features.selection;
2182
+ const rowId = selection && selection.getRowId || store.config.getRowId || undefined;
2183
+ const rows = buildDataTableRows(store.rowData, columns, rowId);
2184
+ const pagination = store.config.features.pagination ?? { mode: "client" };
2185
+ const server = pagination !== false && pagination.mode === "server";
2186
+ const filteredRows = server ? [...rows] : filterDataTableRows(rows, columns, store.state.globalFilter);
2187
+ const sortedRows = server ? filteredRows : sortDataTableRows(filteredRows, columns, store.state.sorting);
2188
+ const pageRows = pagination === false || server ? sortedRows : paginateDataTableRows(sortedRows, store.state.pagination);
2189
+ const totalRows = server ? pagination.rowCount : sortedRows.length;
2190
+ return {
2191
+ columns,
2192
+ visibleColumns: columns.filter(({ id }) => store.state.columnVisibility[id] !== false),
2193
+ rows,
2194
+ filteredRows,
2195
+ sortedRows,
2196
+ pageRows,
2197
+ pageCount: Math.max(1, Math.ceil(totalRows / Math.max(1, store.state.pagination.pageSize))),
2198
+ totalRows
2199
+ };
2200
+ };
2201
+ var useTableAtom = (tableAtom) => useAtom(tableAtom);
2202
+ var changeState = (setStore, update) => {
2203
+ setStore((store) => {
2204
+ const proposed = update(store.state);
2205
+ const previousQuery = queryFromDataTableState(store.state);
2206
+ const nextQuery = queryFromDataTableState(proposed);
2207
+ if (!sameQuery(previousQuery, nextQuery)) {
2208
+ store.config.onQueryChange?.(nextQuery);
2209
+ }
2210
+ store.config.onStateChange?.(proposed);
2211
+ const state = mergeDataTableState(proposed, store.controlledState);
2212
+ if (sameDataTableState(state, store.state))
2213
+ return store;
2214
+ const next = { ...store, state };
2215
+ return { ...next, model: buildDataTableModel(next) };
2143
2216
  });
2144
2217
  };
2145
- var buildGroupedSections = (rows, fields, depth = 0, parentKey = "") => {
2146
- if (fields.length === 0) {
2218
+ var deriveModel = (store) => store.model;
2219
+ var groupDataTableRows = (rows, fields, depth = 0, parentKey = "") => {
2220
+ const field = fields[0];
2221
+ if (!field)
2147
2222
  return [];
2148
- }
2149
- const [field, ...remainingFields] = fields;
2150
2223
  const groups = new Map;
2151
- field.getGroupIds?.().forEach((groupId) => {
2152
- groups.set(groupId, []);
2153
- });
2224
+ field.getGroupIds?.().forEach((id) => groups.set(id, []));
2154
2225
  rows.forEach((row) => {
2155
- const groupIds = field.getRowGroupIds?.(row.original) ?? [
2156
- field.getGroupId(row.original)
2226
+ const ids = field.getRowGroupIds?.(row.data) ?? [
2227
+ field.getGroupId(row.data)
2157
2228
  ];
2158
- for (const groupId of groupIds) {
2159
- const currentRows = groups.get(groupId) ?? [];
2160
- currentRows.push(row);
2161
- groups.set(groupId, currentRows);
2162
- }
2229
+ ids.forEach((id) => groups.set(id, [...groups.get(id) ?? [], row]));
2163
2230
  });
2164
- return Array.from(groups.entries()).map(([groupId, groupRows]) => {
2165
- const key = parentKey ? `${parentKey}::${field.id}:${groupId}` : `${field.id}:${groupId}`;
2231
+ return Array.from(groups, ([groupId, groupRows]) => {
2232
+ const segment = `${encodeURIComponent(field.id)}:${encodeURIComponent(groupId)}`;
2233
+ const key = `${parentKey}${parentKey ? "/" : ""}${segment}`;
2166
2234
  return {
2167
2235
  key,
2168
2236
  groupId,
2169
2237
  depth,
2170
2238
  field,
2171
2239
  rows: groupRows,
2172
- children: groupRows.length > 0 ? buildGroupedSections(groupRows, remainingFields, depth + 1, key) : []
2240
+ children: groupDataTableRows(groupRows, fields.slice(1), depth + 1, key)
2173
2241
  };
2174
2242
  });
2175
2243
  };
2176
- var GroupHeaderRow = ({
2177
- collapsed,
2178
- colSpan,
2179
- onToggle,
2180
- section
2181
- }) => {
2182
- return /* @__PURE__ */ jsx17(TableRow, {
2183
- children: /* @__PURE__ */ jsx17(TableCell, {
2184
- className: "relative p-0",
2185
- colSpan,
2186
- onClick: onToggle,
2187
- children: /* @__PURE__ */ jsxs8("div", {
2188
- className: "flex cursor-pointer items-center gap-3 px-2 py-2 font-medium transition-colors",
2189
- style: {
2190
- paddingLeft: `calc(0.5rem + ${section.depth * GROUP_INDENT_PX}px)`
2191
- },
2192
- children: [
2193
- collapsed ? /* @__PURE__ */ jsx17(ChevronRight2, {
2194
- className: "size-4"
2195
- }) : /* @__PURE__ */ jsx17(ChevronDown, {
2196
- className: "size-4"
2197
- }),
2198
- /* @__PURE__ */ jsx17("div", {
2199
- className: "min-w-0 flex-1 text-left",
2200
- children: getGroupLabels(section)
2201
- }),
2202
- /* @__PURE__ */ jsx17(Badge, {
2203
- variant: "secondary",
2204
- className: "ml-auto",
2205
- children: section.rows.length
2206
- }),
2207
- /* @__PURE__ */ jsx17(DataTableGroupActions, {
2208
- actions: section.field.actions,
2209
- groupId: section.groupId,
2210
- title: section.field.actionsTitle
2211
- })
2212
- ]
2213
- })
2214
- })
2244
+ var getDataTableSelectableRows = (model, grouped, isRowSelectable) => (grouped ? model.sortedRows : model.pageRows).filter((row) => isRowSelectable?.(row.data) ?? true);
2245
+ var getActiveGrouping = (store) => {
2246
+ const grouping = store.config.features.grouping;
2247
+ if (!grouping)
2248
+ return [];
2249
+ return store.state.grouping.flatMap((id) => {
2250
+ const field = grouping.fields.find((candidate) => candidate.id === id);
2251
+ return field ? [field] : [];
2215
2252
  });
2216
2253
  };
2217
- var GroupTableSection = ({
2218
- children,
2219
- section
2220
- }) => {
2221
- const { isOver, setNodeRef } = useDroppable({
2222
- id: getGroupTargetDropId(section.key),
2223
- disabled: !section.field.onMoveToGroup,
2224
- data: {
2225
- type: "group-target",
2226
- fieldId: section.field.id,
2227
- groupId: section.groupId
2228
- }
2229
- });
2230
- return /* @__PURE__ */ jsx17(TableBody, {
2231
- className: cn("relative px-2", isOver && "ring-primary ring-1 ring-inset"),
2232
- ref: setNodeRef,
2233
- children
2234
- });
2254
+ var canReorderRows = (store) => {
2255
+ const pagination = store.config.features.pagination;
2256
+ return !!store.config.features.reordering && !getActiveGrouping(store).length && !store.state.globalFilter && !store.state.sorting.length && !(pagination && pagination.mode === "server");
2235
2257
  };
2236
- var GroupHeaderCard = ({
2237
- collapsed,
2238
- onToggle,
2239
- section
2240
- }) => {
2241
- const { isOver, setNodeRef } = useDroppable({
2242
- id: getGroupTargetDropId(section.key),
2243
- disabled: !section.field.onMoveToGroup,
2244
- data: {
2245
- type: "group-target",
2246
- fieldId: section.field.id,
2247
- groupId: section.groupId
2248
- }
2249
- });
2250
- return /* @__PURE__ */ jsxs8("div", {
2251
- className: cn("flex w-full items-center gap-3 rounded-lg border px-3 py-2 text-left font-medium transition-colors", isOver && "outline outline-primary"),
2252
- ref: setNodeRef,
2253
- children: [
2254
- /* @__PURE__ */ jsxs8("button", {
2255
- className: "flex min-w-0 flex-1 items-center gap-3 text-left",
2256
- onClick: onToggle,
2257
- type: "button",
2258
- children: [
2259
- collapsed ? /* @__PURE__ */ jsx17(ChevronRight2, {
2260
- className: "size-4"
2261
- }) : /* @__PURE__ */ jsx17(ChevronDown, {
2262
- className: "size-4"
2263
- }),
2264
- /* @__PURE__ */ jsx17("div", {
2265
- className: "min-w-0 flex-1",
2266
- children: getGroupLabels(section)
2267
- }),
2268
- /* @__PURE__ */ jsx17(Badge, {
2269
- variant: "secondary",
2270
- className: "ml-auto",
2271
- children: section.rows.length
2272
- })
2273
- ]
2274
- }),
2275
- /* @__PURE__ */ jsx17(DataTableGroupActions, {
2276
- actions: section.field.actions,
2277
- groupId: section.groupId,
2278
- title: section.field.actionsTitle
2279
- })
2280
- ]
2281
- });
2258
+ var canMoveRowsToGroups = (store) => getActiveGrouping(store).some((field) => !!field.onMoveToGroup);
2259
+ var canDragRows = (store) => getActiveGrouping(store).length ? canMoveRowsToGroups(store) : canReorderRows(store);
2260
+ var hasRowActionMenu = (store) => !!store.config.features.rowActions || canReorderRows(store);
2261
+ var getSelectedRows = (store, model) => model.rows.filter((row) => store.state.rowSelection[row.id]).map((row) => row.data);
2262
+ var renderCell = (row, column) => {
2263
+ const value = row.values.get(column.id);
2264
+ const params = {
2265
+ data: row.data,
2266
+ value,
2267
+ rowId: row.id,
2268
+ rowIndex: row.index,
2269
+ colDef: column.colDef
2270
+ };
2271
+ const CellRenderer = column.colDef.cellRenderer;
2272
+ if (CellRenderer)
2273
+ return /* @__PURE__ */ jsx17(CellRenderer, {
2274
+ ...params
2275
+ });
2276
+ return column.colDef.valueFormatter?.(params) ?? (value === null || value === undefined ? null : String(value));
2277
+ };
2278
+ var nodeText = (node) => {
2279
+ if (Schema2.is(Schema2.String)(node) || Schema2.is(Schema2.Number)(node))
2280
+ return String(node);
2281
+ if (!isValidElement(node))
2282
+ return "";
2283
+ if (Schema2.is(Schema2.String)(node.props.title))
2284
+ return node.props.title;
2285
+ return nodeText(node.props.children);
2286
+ };
2287
+ var columnLabel = (column) => nodeText(column.colDef.headerName) || column.id;
2288
+ var withExtension = (fileName, extension) => fileName.includes(".") ? fileName.replace(/\.[^/.]+$/, `.${extension}`) : `${fileName}.${extension}`;
2289
+ var escapeCsvValue = (value) => {
2290
+ if (value === null || value === undefined)
2291
+ return "";
2292
+ const text = String(value);
2293
+ return /[",\n]/.test(text) ? `"${text.replace(/"/g, '""')}"` : text;
2294
+ };
2295
+ var downloadCsv = (headers, data, fileName = "data.csv") => {
2296
+ const content = [headers, ...data].map((row) => row.map(escapeCsvValue).join(",")).join(`
2297
+ `);
2298
+ downloadBlob(content, "text/csv;charset=utf-8", withExtension(fileName, "csv"));
2299
+ };
2300
+ var downloadJson = (data, fileName = "data.json") => downloadBlob(JSON.stringify(data, null, 2), "application/json;charset=utf-8", withExtension(fileName, "json"));
2301
+ var downloadBlob = (content, type, fileName) => {
2302
+ const url = window.URL.createObjectURL(new Blob([content], { type }));
2303
+ const link = document.createElement("a");
2304
+ link.href = url;
2305
+ link.download = fileName;
2306
+ document.body.appendChild(link);
2307
+ link.click();
2308
+ link.remove();
2309
+ requestAnimationFrame(() => window.URL.revokeObjectURL(url));
2282
2310
  };
2283
- var DataTableGroupActions = ({
2311
+ var DataTableRowActions = ({
2284
2312
  actions,
2285
- groupId,
2313
+ row,
2286
2314
  title
2287
2315
  }) => {
2288
- const visibleActions = actions?.filter((action) => !action.visible || action.visible(groupId));
2289
- if (!visibleActions?.length)
2316
+ const visible = actions.filter((action) => !action.visible || action.visible(row));
2317
+ if (!visible.length)
2290
2318
  return null;
2291
- return /* @__PURE__ */ jsxs8(DropdownMenu, {
2319
+ return /* @__PURE__ */ jsxs9(DropdownMenu, {
2292
2320
  children: [
2293
2321
  /* @__PURE__ */ jsx17(DropdownMenuTrigger, {
2294
2322
  onClick: (event) => event.stopPropagation(),
2295
- render: /* @__PURE__ */ jsxs8(Button, {
2296
- className: "size-7 shadow-md [&_svg:not([class*='size-'])]:size-3.5",
2323
+ render: /* @__PURE__ */ jsxs9(Button, {
2324
+ className: "size-8 focus-visible:ring-inset [&_svg:not([class*='size-'])]:size-4",
2297
2325
  size: "icon",
2298
2326
  variant: "ghost",
2299
2327
  children: [
@@ -2308,569 +2336,244 @@ var DataTableGroupActions = ({
2308
2336
  /* @__PURE__ */ jsx17(DropdownMenuContent, {
2309
2337
  align: "end",
2310
2338
  className: "w-max",
2311
- children: /* @__PURE__ */ jsxs8(DropdownMenuGroup, {
2339
+ children: /* @__PURE__ */ jsxs9(DropdownMenuGroup, {
2312
2340
  children: [
2313
2341
  /* @__PURE__ */ jsx17(DropdownMenuLabel, {
2314
2342
  children: title
2315
2343
  }),
2316
2344
  /* @__PURE__ */ jsx17(DropdownMenuSeparator, {}),
2317
- visibleActions.map((action) => /* @__PURE__ */ jsxs8(DropdownMenuItem, {
2318
- className: "whitespace-nowrap",
2345
+ visible.map((action) => /* @__PURE__ */ jsxs9(DropdownMenuItem, {
2319
2346
  onClick: (event) => {
2320
2347
  event.stopPropagation();
2321
- action.onClick(groupId);
2348
+ action.onClick(row);
2322
2349
  },
2323
- ...action.variant ? { variant: action.variant } : {},
2350
+ variant: action.variant,
2324
2351
  children: [
2325
2352
  action.icon,
2326
2353
  action.name
2327
2354
  ]
2328
- }, action.name))
2355
+ }, action.id ?? action.name))
2329
2356
  ]
2330
2357
  })
2331
2358
  })
2332
2359
  ]
2333
2360
  });
2334
2361
  };
2335
- var DataTableRow = ({
2336
- canDrag,
2337
- canReorder,
2338
- dragLabel,
2339
- indentDepth = 0,
2340
- reorderHandleLabel,
2341
- onRowClick,
2342
- row,
2343
- rowActions,
2344
- rowActionsLabel,
2345
- selectRowLabel,
2346
- selectable,
2347
- table
2362
+ var DataTableRowActionMenu = ({
2363
+ tableAtom
2348
2364
  }) => {
2349
- const sortable = useSortable({
2350
- id: getSortableRowId(row.id),
2351
- disabled: !canReorder,
2352
- data: {
2353
- type: "row-reorder",
2354
- row: row.original,
2355
- label: dragLabel
2365
+ const [store] = useTableAtom(tableAtom);
2366
+ const rowId = useRequiredId(RowIdContext);
2367
+ const model = deriveModel(store);
2368
+ const row = model.sortedRows.find((candidate) => candidate.id === rowId);
2369
+ if (!row)
2370
+ return null;
2371
+ const rowActions = store.config.features.rowActions || undefined;
2372
+ const visibleRows = model.pageRows;
2373
+ const rowIndex = visibleRows.findIndex((candidate) => candidate.id === rowId);
2374
+ const reordering = store.config.features.reordering;
2375
+ const reorderActions = [];
2376
+ if (reordering && canReorderRows(store)) {
2377
+ const move = (targetIndex) => reordering.onReorder(reorderDataTableRows(model.rows, rowId, visibleRows[targetIndex].id));
2378
+ if (rowIndex > 0) {
2379
+ reorderActions.push({
2380
+ id: "data-table-move-up",
2381
+ name: store.config.labels.moveUp,
2382
+ icon: /* @__PURE__ */ jsx17(ArrowUp, {}),
2383
+ onClick: () => move(rowIndex - 1)
2384
+ });
2356
2385
  }
2357
- });
2358
- const draggable = useDraggable({
2359
- id: getRowDragId(row.id),
2360
- disabled: !canDrag || canReorder,
2361
- data: {
2362
- type: "row",
2363
- rowId: row.id,
2364
- label: dragLabel
2386
+ if (rowIndex !== -1 && rowIndex < visibleRows.length - 1) {
2387
+ reorderActions.push({
2388
+ id: "data-table-move-down",
2389
+ name: store.config.labels.moveDown,
2390
+ icon: /* @__PURE__ */ jsx17(ArrowDown, {}),
2391
+ onClick: () => move(rowIndex + 1)
2392
+ });
2365
2393
  }
2394
+ }
2395
+ return /* @__PURE__ */ jsx17(DataTableRowActions, {
2396
+ actions: [...reorderActions, ...rowActions ? rowActions.items : []],
2397
+ row: row.data,
2398
+ title: rowActions?.label ?? store.config.labels.actions
2366
2399
  });
2367
- const attributes = canReorder ? sortable.attributes : draggable.attributes;
2368
- const listeners = canReorder ? sortable.listeners : draggable.listeners;
2369
- const isDragging = canReorder ? sortable.isDragging : draggable.isDragging;
2370
- const setRowNodeRef = canReorder ? sortable.setNodeRef : draggable.setNodeRef;
2371
- const transform = canReorder ? CSS.Transform.toString(sortable.transform) : undefined;
2372
- const firstCellIndent = indentDepth > 0 ? `calc(0.5rem + ${(indentDepth - 1) * GROUP_INDENT_PX + GROUP_ROW_INDENT_OFFSET_PX}px)` : undefined;
2373
- const rowAttributes = canReorder ? onRowClick ? { role: "button", tabIndex: 0 } : {} : onRowClick ? { ...attributes, role: "button", tabIndex: 0 } : attributes;
2374
- const visibleCells = row.getVisibleCells();
2375
- return /* @__PURE__ */ jsxs8(TableRow, {
2376
- className: cn("group/row h-16 focus-visible:outline-ring focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-solid", onRowClick && "cursor-pointer", isDragging && "opacity-50"),
2377
- "data-state": row.getIsSelected() && "selected",
2378
- onClick: () => {
2379
- if (onRowClick) {
2380
- onRowClick(row.original);
2381
- }
2382
- },
2383
- onKeyDown: (event) => {
2384
- if (!onRowClick || event.key !== "Enter" && event.key !== " ") {
2385
- return;
2386
- }
2387
- event.preventDefault();
2388
- onRowClick(row.original);
2389
- },
2390
- ref: setRowNodeRef,
2391
- style: {
2392
- transform,
2393
- transition: sortable.transition
2394
- },
2395
- ...rowAttributes,
2396
- ...!canReorder ? listeners : {},
2400
+ };
2401
+ var DataTableToolbar = ({
2402
+ tableAtom
2403
+ }) => {
2404
+ const [store, setStore] = useTableAtom(tableAtom);
2405
+ const { features, labels: labels2 } = store.config;
2406
+ const model = deriveModel(store);
2407
+ const selectedRows = getSelectedRows(store, model);
2408
+ const grouping = features.grouping;
2409
+ const bulkActions = features.selection && features.selection.bulkActions;
2410
+ const hasToolbar = features.search !== false || features.sorting !== false || features.columnVisibility !== false || !!features.export || !!features.gallery || !!grouping || !!features.refresh || !!bulkActions && selectedRows.length > 0;
2411
+ if (!hasToolbar)
2412
+ return null;
2413
+ const update = (next) => changeState(setStore, next);
2414
+ const visibleBulkActions = bulkActions ? bulkActions.items.filter((action) => !action.visible || action.visible(selectedRows)) : [];
2415
+ const exportRows = features.export && features.export.scope === "filteredRows" ? model.filteredRows : model.pageRows;
2416
+ return /* @__PURE__ */ jsxs9("div", {
2417
+ className: "flex flex-col gap-2 pb-4",
2397
2418
  children: [
2398
- selectable ? /* @__PURE__ */ jsx17(TableCell, {
2399
- className: "w-10 min-w-10 cursor-default pr-0",
2400
- onClick: (event) => event.stopPropagation(),
2401
- children: /* @__PURE__ */ jsx17(Checkbox, {
2402
- "aria-label": selectRowLabel,
2403
- checked: row.getIsSelected(),
2404
- disabled: !row.getCanSelect(),
2405
- onCheckedChange: (checked, eventDetails) => row.getToggleSelectedHandler()({
2406
- nativeEvent: eventDetails.event,
2407
- target: { checked }
2419
+ features.search !== false ? /* @__PURE__ */ jsxs9("div", {
2420
+ className: "relative min-w-0",
2421
+ children: [
2422
+ /* @__PURE__ */ jsx17(Search, {
2423
+ className: "text-muted-foreground pointer-events-none absolute top-1/2 left-3 size-4 -translate-y-1/2"
2408
2424
  }),
2409
- onClick: (event) => event.stopPropagation()
2410
- })
2411
- }) : null,
2412
- canReorder ? /* @__PURE__ */ jsx17(TableCell, {
2413
- className: "w-10 min-w-10 pr-0",
2414
- children: /* @__PURE__ */ jsx17(Button, {
2415
- "aria-label": reorderHandleLabel,
2416
- className: "size-8 cursor-grab active:cursor-grabbing",
2417
- onClick: (event) => event.stopPropagation(),
2418
- size: "icon",
2419
- type: "button",
2420
- variant: "ghost",
2421
- ...attributes,
2422
- ...listeners,
2423
- children: /* @__PURE__ */ jsx17(GripVertical, {})
2424
- })
2425
+ /* @__PURE__ */ jsx17(Input, {
2426
+ className: "px-9",
2427
+ onChange: (event) => update((state) => ({
2428
+ ...state,
2429
+ globalFilter: event.target.value,
2430
+ pagination: { ...state.pagination, pageIndex: 0 }
2431
+ })),
2432
+ placeholder: labels2.filter,
2433
+ value: store.state.globalFilter
2434
+ }),
2435
+ store.state.globalFilter ? /* @__PURE__ */ jsx17(Button, {
2436
+ "aria-label": labels2.filter,
2437
+ className: "absolute top-1/2 right-1 size-7 -translate-y-1/2",
2438
+ onClick: () => update((state) => ({
2439
+ ...state,
2440
+ globalFilter: "",
2441
+ pagination: { ...state.pagination, pageIndex: 0 }
2442
+ })),
2443
+ size: "icon",
2444
+ variant: "ghost",
2445
+ children: /* @__PURE__ */ jsx17(X2, {})
2446
+ }) : null
2447
+ ]
2425
2448
  }) : null,
2426
- visibleCells.map((cell, index) => {
2427
- return /* @__PURE__ */ jsx17(table.AppCell, {
2428
- cell,
2429
- children: (appCell) => /* @__PURE__ */ jsx17(TableCell, {
2430
- className: cn("align-center min-w-32 overflow-hidden [&:has([data-slot=relationship-cell])]:relative [&:has([data-slot=relationship-cell])]:p-0 [&:has([data-slot=relationship-cell])>div]:absolute [&:has([data-slot=relationship-cell])>div]:inset-0", cell.column.columnDef.meta?.truncate ? "whitespace-nowrap" : "whitespace-normal"),
2431
- style: index === 0 && firstCellIndent ? {
2432
- paddingLeft: firstCellIndent,
2433
- width: cell.column.getSize()
2434
- } : { width: cell.column.getSize() },
2435
- children: /* @__PURE__ */ jsx17("div", {
2436
- className: cn("w-full max-w-full min-w-0 overflow-hidden break-words [&:has([data-slot=list-summary])]:line-clamp-none", cell.column.columnDef.meta?.truncate ? "truncate" : "line-clamp-3"),
2437
- children: /* @__PURE__ */ jsx17(appCell.FlexRender, {})
2438
- })
2439
- })
2440
- }, cell.id);
2441
- }),
2442
- rowActions ? /* @__PURE__ */ jsx17(TableCell, {
2443
- 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))]",
2444
- onClick: (event) => event.stopPropagation(),
2445
- children: /* @__PURE__ */ jsx17("div", {
2446
- className: "flex h-16 items-center justify-center",
2447
- children: /* @__PURE__ */ jsx17(DataTableRowActions, {
2448
- actions: rowActions,
2449
- row: row.original,
2450
- title: rowActionsLabel
2451
- })
2452
- })
2453
- }) : null
2454
- ]
2455
- }, row.id);
2456
- };
2457
- var DataTableGalleryCard = ({
2458
- canDrag,
2459
- dragLabel,
2460
- gallery,
2461
- onRowClick,
2462
- row,
2463
- rowActions,
2464
- rowActionsLabel,
2465
- selectRowLabel,
2466
- selectable,
2467
- table
2468
- }) => {
2469
- const { attributes, listeners, setNodeRef, isDragging } = useDraggable({
2470
- id: getRowDragId(row.id),
2471
- disabled: !canDrag,
2472
- data: {
2473
- type: "row",
2474
- rowId: row.id,
2475
- label: dragLabel
2476
- }
2477
- });
2478
- const nameCell = gallery ? row.getVisibleCells().find((cell) => cell.column.id === gallery.name) : null;
2479
- const descriptionCell = gallery?.description ? row.getVisibleCells().find((cell) => cell.column.id === gallery.description) : null;
2480
- const tagCell = gallery?.tag ? row.getVisibleCells().find((cell) => cell.column.id === gallery.tag) : null;
2481
- if (gallery) {
2482
- const tagValue = gallery.tag ? row.getValue(gallery.tag) : null;
2483
- const tagLabel = tagValue === null || tagValue === undefined ? null : String(tagValue);
2484
- return /* @__PURE__ */ jsxs8(Card, {
2485
- className: cn("relative mx-auto w-full max-w-sm transition-colors", onRowClick && "cursor-pointer hover:bg-accent/20", isDragging && "opacity-50"),
2486
- "data-state": row.getIsSelected() && "selected",
2487
- onClick: () => {
2488
- if (onRowClick) {
2489
- onRowClick(row.original);
2490
- }
2491
- },
2492
- ref: setNodeRef,
2493
- ...attributes,
2494
- ...listeners,
2495
- children: [
2496
- selectable ? /* @__PURE__ */ jsx17("div", {
2497
- className: "absolute top-4 left-4 z-10",
2498
- onClick: (event) => event.stopPropagation(),
2499
- children: /* @__PURE__ */ jsx17(Checkbox, {
2500
- "aria-label": selectRowLabel,
2501
- checked: row.getIsSelected(),
2502
- disabled: !row.getCanSelect(),
2503
- onCheckedChange: (checked, eventDetails) => row.getToggleSelectedHandler()({
2504
- nativeEvent: eventDetails.event,
2505
- target: { checked }
2506
- })
2507
- })
2508
- }) : null,
2509
- rowActions ? /* @__PURE__ */ jsx17("div", {
2510
- className: "absolute top-4 right-4 z-10",
2511
- onClick: (event) => event.stopPropagation(),
2512
- children: /* @__PURE__ */ jsx17(DataTableRowActions, {
2513
- actions: rowActions,
2514
- row: row.original,
2515
- title: rowActionsLabel
2516
- })
2517
- }) : null,
2518
- /* @__PURE__ */ jsxs8(CardHeader, {
2519
- className: cn(rowActions && "pr-14", selectable && "pl-12"),
2449
+ /* @__PURE__ */ jsx17("div", {
2450
+ className: "-m-1 flex w-full overflow-x-auto p-1",
2451
+ children: /* @__PURE__ */ jsxs9(Menubar, {
2452
+ 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",
2520
2453
  children: [
2521
- tagCell && tagLabel ? /* @__PURE__ */ jsxs8(Badge, {
2522
- variant: "secondary",
2523
- className: "mb-1 w-fit gap-1",
2454
+ visibleBulkActions.length ? /* @__PURE__ */ jsxs9(MenubarMenu, {
2524
2455
  children: [
2525
- gallery.tagIcon,
2526
- tagLabel
2456
+ /* @__PURE__ */ jsxs9(MenubarTrigger, {
2457
+ className: "bg-primary text-primary-foreground hover:bg-primary/90 aria-expanded:bg-primary/90",
2458
+ children: [
2459
+ labels2.selected,
2460
+ /* @__PURE__ */ jsx17(Badge, {
2461
+ variant: "secondary",
2462
+ children: selectedRows.length
2463
+ }),
2464
+ /* @__PURE__ */ jsx17(ChevronDown, {})
2465
+ ]
2466
+ }),
2467
+ /* @__PURE__ */ jsx17(MenubarContent, {
2468
+ align: "end",
2469
+ className: "w-max",
2470
+ children: /* @__PURE__ */ jsxs9(MenubarGroup, {
2471
+ children: [
2472
+ /* @__PURE__ */ jsx17(MenubarLabel, {
2473
+ children: bulkActions && bulkActions.label ? bulkActions.label : labels2.actions
2474
+ }),
2475
+ /* @__PURE__ */ jsx17(MenubarSeparator, {}),
2476
+ visibleBulkActions.map((action) => /* @__PURE__ */ jsxs9(MenubarItem, {
2477
+ onClick: () => action.onClick(selectedRows),
2478
+ variant: action.variant,
2479
+ children: [
2480
+ action.icon,
2481
+ action.name
2482
+ ]
2483
+ }, action.id ?? action.name))
2484
+ ]
2485
+ })
2486
+ })
2527
2487
  ]
2528
2488
  }) : null,
2529
- nameCell ? /* @__PURE__ */ jsx17(CardTitle, {
2530
- className: "min-w-0 text-base",
2531
- children: flexRender(nameCell.column.columnDef.cell, nameCell.getContext())
2489
+ grouping ? /* @__PURE__ */ jsxs9(MenubarMenu, {
2490
+ children: [
2491
+ /* @__PURE__ */ jsxs9(MenubarTrigger, {
2492
+ "aria-label": labels2.groupBy,
2493
+ children: [
2494
+ /* @__PURE__ */ jsx17(Rows3, {}),
2495
+ /* @__PURE__ */ jsx17("span", {
2496
+ className: "hidden sm:inline",
2497
+ children: labels2.groupBy
2498
+ })
2499
+ ]
2500
+ }),
2501
+ /* @__PURE__ */ jsx17(MenubarContent, {
2502
+ align: "end",
2503
+ children: /* @__PURE__ */ jsxs9(MenubarGroup, {
2504
+ children: [
2505
+ /* @__PURE__ */ jsx17(MenubarLabel, {
2506
+ children: labels2.groupBy
2507
+ }),
2508
+ /* @__PURE__ */ jsx17(MenubarSeparator, {}),
2509
+ grouping.fields.map((field) => /* @__PURE__ */ jsx17(MenubarCheckboxItem, {
2510
+ checked: store.state.grouping.includes(field.id),
2511
+ onCheckedChange: (checked) => update((state) => ({
2512
+ ...state,
2513
+ grouping: checked ? [...state.grouping, field.id] : state.grouping.filter((id) => id !== field.id)
2514
+ })),
2515
+ children: field.label
2516
+ }, field.id))
2517
+ ]
2518
+ })
2519
+ })
2520
+ ]
2532
2521
  }) : null,
2533
- descriptionCell ? /* @__PURE__ */ jsx17(CardDescription, {
2534
- className: "line-clamp-2 min-w-0",
2535
- children: flexRender(descriptionCell.column.columnDef.cell, descriptionCell.getContext())
2536
- }) : null
2537
- ]
2538
- })
2539
- ]
2540
- });
2541
- }
2542
- const contentCells = row.getVisibleCells();
2543
- return /* @__PURE__ */ jsxs8(Card, {
2544
- className: cn("relative gap-3 transition-colors", onRowClick && "cursor-pointer hover:bg-accent/20", isDragging && "opacity-50"),
2545
- "data-state": row.getIsSelected() && "selected",
2546
- onClick: () => {
2547
- if (onRowClick) {
2548
- onRowClick(row.original);
2549
- }
2550
- },
2551
- ref: setNodeRef,
2552
- ...attributes,
2553
- ...listeners,
2554
- children: [
2555
- selectable ? /* @__PURE__ */ jsx17("div", {
2556
- className: "absolute top-4 left-4 z-10",
2557
- onClick: (event) => event.stopPropagation(),
2558
- children: /* @__PURE__ */ jsx17(Checkbox, {
2559
- "aria-label": selectRowLabel,
2560
- checked: row.getIsSelected(),
2561
- disabled: !row.getCanSelect(),
2562
- onCheckedChange: (checked, eventDetails) => row.getToggleSelectedHandler()({
2563
- nativeEvent: eventDetails.event,
2564
- target: { checked }
2565
- })
2566
- })
2567
- }) : null,
2568
- /* @__PURE__ */ jsxs8(CardHeader, {
2569
- children: [
2570
- rowActions ? /* @__PURE__ */ jsx17(CardAction, {
2571
- onClick: (event) => event.stopPropagation(),
2572
- children: /* @__PURE__ */ jsx17(DataTableRowActions, {
2573
- actions: rowActions,
2574
- row: row.original,
2575
- title: rowActionsLabel
2576
- })
2577
- }) : null,
2578
- contentCells.length > 0 && /* @__PURE__ */ jsxs8("div", {
2579
- className: "grid min-w-0 gap-3",
2580
- children: [
2581
- /* @__PURE__ */ jsx17(CardDescription, {
2582
- className: "text-muted-foreground text-xs font-medium tracking-wide uppercase",
2583
- children: getColumnDisplayName(table, contentCells[0].column.id)
2584
- }),
2585
- /* @__PURE__ */ jsx17(CardTitle, {
2586
- className: "text-base",
2587
- children: flexRender(contentCells[0].column.columnDef.cell, contentCells[0].getContext())
2588
- })
2589
- ]
2590
- })
2591
- ]
2592
- }),
2593
- contentCells.length > 1 && /* @__PURE__ */ jsx17(CardContent, {
2594
- className: "grid gap-3",
2595
- children: contentCells.slice(1).map((cell) => /* @__PURE__ */ jsxs8("div", {
2596
- className: "grid gap-1",
2597
- children: [
2598
- /* @__PURE__ */ jsx17("div", {
2599
- className: "text-muted-foreground text-xs font-medium tracking-wide uppercase",
2600
- children: getColumnDisplayName(table, cell.column.id)
2601
- }),
2602
- /* @__PURE__ */ jsx17("div", {
2603
- className: "min-w-0 text-sm",
2604
- children: flexRender(cell.column.columnDef.cell, cell.getContext())
2605
- })
2606
- ]
2607
- }, cell.id))
2608
- })
2609
- ]
2610
- });
2611
- };
2612
- var extractTextFromElement = (element) => {
2613
- if (Schema2.is(Schema2.String)(element))
2614
- return element;
2615
- if (Schema2.is(Schema2.Number)(element))
2616
- return String(element);
2617
- if (!isValidElement(element)) {
2618
- return null;
2619
- }
2620
- const { props } = element;
2621
- if (Schema2.is(Schema2.String)(props.title))
2622
- return props.title;
2623
- return extractTextFromElement(props.children);
2624
- };
2625
- var getColumnLabels = (table) => new Map(table.getFlatHeaders().map((header) => [header.column.id, getHeaderName(header)]));
2626
- var getHeaderName = (header) => {
2627
- const columnDef = header.column.columnDef;
2628
- if (columnDef.header instanceof Function) {
2629
- const headerContext = columnDef.header(header.getContext());
2630
- if (Schema2.is(Schema2.String)(headerContext)) {
2631
- return headerContext;
2632
- }
2633
- return extractTextFromElement(headerContext) ?? header.id;
2634
- }
2635
- return String(columnDef.header ?? header.id);
2636
- };
2637
- var getHeaderNames = (headers) => headers.map((header) => getHeaderName(header));
2638
- var getColumnDisplayName = (table, columnId) => {
2639
- const header = table.getFlatHeaders().find((currentHeader) => currentHeader.column.id === columnId);
2640
- return header ? getHeaderName(header) : columnId;
2641
- };
2642
- var withFileExtension = (fileName, extension) => {
2643
- const normalizedExtension = extension.startsWith(".") ? extension : `.${extension}`;
2644
- return fileName.includes(".") ? fileName.replace(/\.[^/.]+$/, normalizedExtension) : `${fileName}${normalizedExtension}`;
2645
- };
2646
- var escapeCsvValue = (value) => {
2647
- if (value === null || value === undefined)
2648
- return "";
2649
- const stringValue = String(value);
2650
- if (stringValue.includes(",") || stringValue.includes('"') || stringValue.includes(`
2651
- `)) {
2652
- return `"${stringValue.replace(/"/g, '""')}"`;
2653
- }
2654
- return stringValue;
2655
- };
2656
- var downloadCsv = (headers, data, fileName = "data.csv") => {
2657
- const csvContent = [headers, ...data].map((row) => row.map(escapeCsvValue).join(",")).join(`
2658
- `);
2659
- const blob = new Blob([csvContent], { type: "text/csv;charset=utf-8;" });
2660
- const link = document.createElement("a");
2661
- const url = window.URL.createObjectURL(blob);
2662
- link.href = url;
2663
- link.setAttribute("download", withFileExtension(fileName, "csv"));
2664
- document.body.appendChild(link);
2665
- link.click();
2666
- link.remove();
2667
- requestAnimationFrame(() => window.URL.revokeObjectURL(url));
2668
- };
2669
- var downloadJson = (data, fileName = "data.json") => {
2670
- const jsonContent = JSON.stringify(data, null, 2);
2671
- const blob = new Blob([jsonContent], {
2672
- type: "application/json;charset=utf-8;"
2673
- });
2674
- const link = document.createElement("a");
2675
- const url = window.URL.createObjectURL(blob);
2676
- link.href = url;
2677
- link.setAttribute("download", withFileExtension(fileName, "json"));
2678
- document.body.appendChild(link);
2679
- link.click();
2680
- link.remove();
2681
- requestAnimationFrame(() => window.URL.revokeObjectURL(url));
2682
- };
2683
- var exportTableToCsv = (table, rows, fileName = "data.csv") => {
2684
- const exportableColumns = table.getVisibleLeafColumns();
2685
- const headerNames = exportableColumns.map((column) => getColumnDisplayName(table, column.id));
2686
- const data = rows.map((row) => exportableColumns.map((column) => {
2687
- const value = row.getValue(column.id);
2688
- return value === null || value === undefined ? "" : String(value);
2689
- }));
2690
- downloadCsv(headerNames, data, fileName);
2691
- };
2692
- var exportTableToJson = (table, rows, fileName = "data.json") => {
2693
- const exportableColumns = table.getVisibleLeafColumns();
2694
- const data = rows.map((row) => Object.fromEntries(exportableColumns.map((column) => [column.id, row.getValue(column.id)])));
2695
- downloadJson(data, fileName);
2696
- };
2697
- var DataTableToolbar = ({
2698
- activeGrouping,
2699
- bulkActions,
2700
- exportBaseName,
2701
- exportRows,
2702
- grouping,
2703
- labels: labels2,
2704
- onRefresh,
2705
- onToggleGrouping,
2706
- onViewChange,
2707
- selectedRows,
2708
- showColumnVisibility,
2709
- showExport,
2710
- showGallery,
2711
- showSearch,
2712
- showSorting,
2713
- table,
2714
- view
2715
- }) => {
2716
- const [refreshSpinCount, setRefreshSpinCount] = useState(0);
2717
- const [searchInput, setSearchInput] = useState(table.state.globalFilter);
2718
- const hasToolbar = Boolean(showSearch || grouping?.fields.length || showSorting || showGallery || showColumnVisibility || onRefresh || showExport || selectedRows.length > 0 && bulkActions?.items.length);
2719
- useEffect2(() => {
2720
- setSearchInput(table.state.globalFilter);
2721
- }, [table.state.globalFilter]);
2722
- if (!hasToolbar)
2723
- return null;
2724
- return /* @__PURE__ */ jsx17("div", {
2725
- className: "flex flex-col gap-3 pb-4",
2726
- children: /* @__PURE__ */ jsxs8("div", {
2727
- className: "flex flex-col gap-2 sm:flex-row sm:flex-wrap sm:items-center sm:justify-between",
2728
- children: [
2729
- showSearch ? /* @__PURE__ */ jsxs8("div", {
2730
- className: "relative w-full min-w-0 flex-1 sm:min-w-sm",
2731
- children: [
2732
- /* @__PURE__ */ jsx17(Search, {
2733
- className: "text-muted-foreground pointer-events-none absolute top-1/2 left-3 size-4 -translate-y-1/2"
2734
- }),
2735
- /* @__PURE__ */ jsx17(Input, {
2736
- className: "px-9",
2737
- onChange: (event) => {
2738
- setSearchInput(event.target.value);
2739
- table.setGlobalFilter(event.target.value);
2740
- },
2741
- placeholder: labels2.filter,
2742
- value: searchInput
2743
- }),
2744
- searchInput ? /* @__PURE__ */ jsx17(Button, {
2745
- "aria-label": labels2.filter,
2746
- className: "text-muted-foreground hover:text-foreground absolute top-1/2 right-1 size-7 -translate-y-1/2 active:!-translate-y-1/2",
2747
- onClick: () => {
2748
- setSearchInput("");
2749
- table.setGlobalFilter("");
2750
- },
2751
- size: "icon",
2752
- type: "button",
2753
- variant: "ghost",
2754
- children: /* @__PURE__ */ jsx17(X2, {
2755
- className: "size-4"
2756
- })
2757
- }) : null
2758
- ]
2759
- }) : /* @__PURE__ */ jsx17("div", {}),
2760
- /* @__PURE__ */ jsxs8("div", {
2761
- className: "-m-1 flex items-center gap-2 overflow-x-auto p-1",
2762
- children: [
2763
- bulkActions && selectedRows.length > 0 ? /* @__PURE__ */ jsx17(DataTableBulkActions, {
2764
- actions: bulkActions.items,
2765
- label: bulkActions.label ?? labels2.actions,
2766
- rows: selectedRows,
2767
- selectedLabel: labels2.selected
2522
+ features.sorting !== false ? /* @__PURE__ */ jsx17(SortMenu, {
2523
+ tableAtom
2768
2524
  }) : null,
2769
- grouping?.fields.length ? /* @__PURE__ */ jsxs8(DropdownMenu, {
2770
- children: [
2771
- /* @__PURE__ */ jsx17(DropdownMenuTrigger, {
2772
- render: /* @__PURE__ */ jsxs8(Button, {
2773
- "aria-label": labels2.groupBy,
2774
- className: "h-9",
2775
- size: "sm",
2776
- variant: "outline",
2777
- children: [
2778
- /* @__PURE__ */ jsx17(Rows3, {}),
2779
- /* @__PURE__ */ jsx17("span", {
2780
- className: "hidden sm:inline",
2781
- children: labels2.groupBy
2782
- })
2783
- ]
2784
- })
2785
- }),
2786
- /* @__PURE__ */ jsx17(DropdownMenuContent, {
2787
- align: "end",
2788
- className: "w-[200px]",
2789
- children: /* @__PURE__ */ jsxs8(DropdownMenuGroup, {
2790
- children: [
2791
- /* @__PURE__ */ jsx17(DropdownMenuLabel, {
2792
- children: labels2.groupBy
2793
- }),
2794
- /* @__PURE__ */ jsx17(DropdownMenuSeparator, {}),
2795
- grouping.fields.map((field) => /* @__PURE__ */ jsx17(DropdownMenuCheckboxItem, {
2796
- checked: activeGrouping.includes(field.id),
2797
- onCheckedChange: (value) => onToggleGrouping(field.id, !!value),
2798
- children: field.label
2799
- }, field.id))
2800
- ]
2801
- })
2802
- })
2803
- ]
2804
- }) : null,
2805
- showSorting ? /* @__PURE__ */ jsx17(DataTableSortDropdown, {
2806
- messages: labels2,
2807
- table
2525
+ features.gallery ? /* @__PURE__ */ jsx17(ViewMenu, {
2526
+ tableAtom
2808
2527
  }) : null,
2809
- showGallery ? /* @__PURE__ */ jsx17(DataTableDisplayModeSwitch, {
2810
- messages: labels2,
2811
- onChange: onViewChange,
2812
- value: view
2528
+ features.columnVisibility !== false ? /* @__PURE__ */ jsx17(ColumnMenu, {
2529
+ tableAtom
2813
2530
  }) : null,
2814
- showColumnVisibility ? /* @__PURE__ */ jsx17(DataTableViewOptions, {
2815
- messages: labels2,
2816
- table
2817
- }) : null,
2818
- onRefresh ? /* @__PURE__ */ jsxs8(Button, {
2819
- "aria-label": labels2.refresh,
2820
- className: "h-9",
2821
- onClick: () => {
2822
- setRefreshSpinCount((count) => count + 1);
2823
- onRefresh();
2824
- },
2825
- size: "sm",
2826
- type: "button",
2827
- variant: "outline",
2828
- children: [
2829
- /* @__PURE__ */ jsx17(RefreshCw, {
2830
- className: cn(refreshSpinCount > 0 && "animate-[spin_500ms_ease-in-out_1]")
2831
- }, refreshSpinCount),
2832
- /* @__PURE__ */ jsx17("span", {
2833
- className: "hidden sm:inline",
2834
- children: labels2.refresh
2835
- })
2836
- ]
2531
+ features.refresh ? /* @__PURE__ */ jsx17(MenubarMenu, {
2532
+ children: /* @__PURE__ */ jsxs9(MenubarTrigger, {
2533
+ "aria-label": labels2.refresh,
2534
+ onClick: features.refresh,
2535
+ children: [
2536
+ /* @__PURE__ */ jsx17(RefreshCw, {}),
2537
+ /* @__PURE__ */ jsx17("span", {
2538
+ className: "hidden sm:inline",
2539
+ children: labels2.refresh
2540
+ })
2541
+ ]
2542
+ })
2837
2543
  }) : null,
2838
- showExport ? /* @__PURE__ */ jsxs8(DropdownMenu, {
2544
+ features.export ? /* @__PURE__ */ jsxs9(MenubarMenu, {
2839
2545
  children: [
2840
- /* @__PURE__ */ jsx17(DropdownMenuTrigger, {
2841
- render: /* @__PURE__ */ jsxs8(Button, {
2842
- "aria-label": labels2.export,
2843
- className: "h-9",
2844
- disabled: exportRows.length === 0,
2845
- size: "sm",
2846
- variant: "outline",
2847
- children: [
2848
- /* @__PURE__ */ jsx17(Download, {}),
2849
- /* @__PURE__ */ jsx17("span", {
2850
- className: "hidden sm:inline",
2851
- children: labels2.export
2852
- })
2853
- ]
2854
- })
2546
+ /* @__PURE__ */ jsxs9(MenubarTrigger, {
2547
+ "aria-label": labels2.export,
2548
+ disabled: !exportRows.length,
2549
+ children: [
2550
+ /* @__PURE__ */ jsx17(Download, {}),
2551
+ /* @__PURE__ */ jsx17("span", {
2552
+ className: "hidden sm:inline",
2553
+ children: labels2.export
2554
+ })
2555
+ ]
2855
2556
  }),
2856
- /* @__PURE__ */ jsx17(DropdownMenuContent, {
2557
+ /* @__PURE__ */ jsx17(MenubarContent, {
2857
2558
  align: "end",
2858
- className: "w-[180px]",
2859
- children: /* @__PURE__ */ jsxs8(DropdownMenuGroup, {
2559
+ children: /* @__PURE__ */ jsxs9(MenubarGroup, {
2860
2560
  children: [
2861
- /* @__PURE__ */ jsx17(DropdownMenuLabel, {
2561
+ /* @__PURE__ */ jsx17(MenubarLabel, {
2862
2562
  children: labels2.export
2863
2563
  }),
2864
- /* @__PURE__ */ jsx17(DropdownMenuSeparator, {}),
2865
- /* @__PURE__ */ jsxs8(DropdownMenuItem, {
2866
- onClick: () => exportTableToCsv(table, exportRows, exportBaseName),
2564
+ /* @__PURE__ */ jsx17(MenubarSeparator, {}),
2565
+ /* @__PURE__ */ jsxs9(MenubarItem, {
2566
+ onClick: () => downloadCsv(model.visibleColumns.map(columnLabel), exportRows.map((row) => model.visibleColumns.map((column) => String(row.values.get(column.id) ?? ""))), features.export ? features.export.baseName : "table"),
2867
2567
  children: [
2868
2568
  /* @__PURE__ */ jsx17(FileText, {}),
2869
2569
  labels2.exportCsv
2870
2570
  ]
2871
2571
  }),
2872
- /* @__PURE__ */ jsxs8(DropdownMenuItem, {
2873
- onClick: () => exportTableToJson(table, exportRows, exportBaseName),
2572
+ /* @__PURE__ */ jsxs9(MenubarItem, {
2573
+ onClick: () => downloadJson(exportRows.map((row) => Object.fromEntries(model.visibleColumns.map((column) => [
2574
+ column.id,
2575
+ row.values.get(column.id)
2576
+ ]))), features.export ? features.export.baseName : "table"),
2874
2577
  children: [
2875
2578
  /* @__PURE__ */ jsx17(FileJson, {}),
2876
2579
  labels2.exportJson
@@ -2883,815 +2586,1101 @@ var DataTableToolbar = ({
2883
2586
  }) : null
2884
2587
  ]
2885
2588
  })
2886
- ]
2887
- })
2589
+ })
2590
+ ]
2888
2591
  });
2889
2592
  };
2890
- function DataTable({
2891
- columns,
2892
- data,
2893
- state,
2894
- search: controlledSearch,
2895
- onSearchChange,
2896
- searchState = "url",
2897
- emptyLabel,
2898
- messages: messages4,
2899
- exportFileName,
2900
- isLoading: legacyIsLoading,
2901
- onRefresh,
2902
- onRowClick,
2903
- from,
2904
- routeFrom,
2905
- grouping,
2906
- gallery,
2907
- rowActions: legacyRowActions,
2908
- reordering,
2909
- serverPagination,
2910
- features
2911
- }) {
2912
- const labels2 = dataTableMessages(messages4);
2913
- const isLoading = state?.loading ?? legacyIsLoading ?? false;
2914
- const emptyContent = state?.error ?? state?.empty ?? emptyLabel ?? labels2.empty;
2915
- const paginationFeature = features?.pagination ?? (serverPagination ? { mode: "server", rowCount: serverPagination.rowCount } : { mode: "client" });
2916
- const exportFeature = features?.export ?? (exportFileName ? { baseName: exportFileName, scope: "currentPage" } : false);
2917
- const exportBaseName = exportFeature ? exportFeature.baseName : "table";
2918
- const galleryConfig = features?.gallery === false ? undefined : features?.gallery ?? gallery;
2919
- const rowActionsFeature = features?.rowActions === false ? undefined : features?.rowActions ?? (legacyRowActions?.length ? {
2920
- items: legacyRowActions.map((action) => ({
2921
- ...action,
2922
- id: action.id ?? action.name
2923
- }))
2924
- } : undefined);
2925
- const rowActions = rowActionsFeature?.items.length ? rowActionsFeature.items : undefined;
2926
- const rowActionsLabel = rowActionsFeature?.label ?? labels2.actions;
2927
- const showPagination = paginationFeature !== false;
2928
- const pageSizes = paginationFeature ? paginationFeature.pageSizes : undefined;
2929
- const showSearch = features?.search ?? true;
2930
- const showExport = exportFeature !== false;
2931
- const columnVisibilityFeature2 = features?.columnVisibility ?? true;
2932
- const showColumnVisibility = columnVisibilityFeature2 !== false;
2933
- const defaultColumnVisibility = Schema2.is(Schema2.Struct({ default: ColumnVisibilitySchema }))(columnVisibilityFeature2) ? columnVisibilityFeature2.default : undefined;
2934
- const showGallery = !!galleryConfig;
2935
- const showSorting = features?.sorting ?? true;
2936
- const selectionFeature = features?.selection === false ? undefined : features?.selection;
2937
- const selectable = !!selectionFeature;
2938
- const bulkActions = selectionFeature?.bulkActions === false ? undefined : selectionFeature?.bulkActions;
2939
- const isServerMode = paginationFeature !== false && paginationFeature.mode === "server";
2940
- const serverRowCount = isServerMode ? paginationFeature.rowCount : undefined;
2941
- const location = useRouterState({
2942
- select: (state2) => state2.location
2943
- });
2944
- const search = Option2.getOrUndefined(decodeTableSearch(location.search));
2945
- const pathname = location.pathname;
2946
- const resolvedRouteFrom = routeFrom ?? from;
2947
- const [storagePath] = useState(() => resolvedRouteFrom ?? pathname);
2948
- const navigate = useNavigate(resolvedRouteFrom ? { from: resolvedRouteFrom } : undefined);
2949
- const [localSearch, setLocalSearch] = useState({
2950
- globalFilter: ""
2951
- });
2952
- const tableSearch = controlledSearch ?? (searchState === "local" ? localSearch : search);
2953
- const {
2954
- page = 0,
2955
- pageSize = 10,
2956
- sort,
2957
- globalFilter = "",
2958
- grouping: urlGrouping
2959
- } = tableSearch ?? {};
2960
- const pagination = { pageIndex: page, pageSize };
2961
- const decodedSort = sort ? Schema2.decodeSync(SortParamsFromString)(sort) : [];
2962
- const sorting = decodedSort.map((sortParam) => ({
2963
- id: sortParam.id,
2964
- desc: sortParam.direction === "desc"
2593
+ var SortMenu = ({
2594
+ tableAtom
2595
+ }) => {
2596
+ const [store, setStore] = useTableAtom(tableAtom);
2597
+ const columns = deriveModel(store).columns.filter(({ colDef }) => colDef.sortable !== false);
2598
+ if (!columns.length)
2599
+ return null;
2600
+ const current = store.state.sorting[0];
2601
+ const sort = (id, desc) => changeState(setStore, (state) => ({
2602
+ ...state,
2603
+ sorting: [{ id, desc }],
2604
+ pagination: { ...state.pagination, pageIndex: 0 }
2965
2605
  }));
2966
- const tableStorageId = useMemo(() => {
2967
- const columnIds = columns.map((column, index) => {
2968
- if ("id" in column && Schema2.is(Schema2.String)(column.id)) {
2969
- return column.id;
2970
- }
2971
- if ("accessorKey" in column && Schema2.is(Schema2.String)(column.accessorKey)) {
2972
- return column.accessorKey;
2973
- }
2974
- return String(index);
2975
- }).join(",");
2976
- return `${storagePath}:${columnIds}`;
2977
- }, [columns, storagePath]);
2978
- const columnVisibilityAtom = useMemo(() => Atom.kvs({
2979
- runtime: dataTableStorageRuntime,
2980
- key: `data-table:column-visibility:${tableStorageId}`,
2981
- schema: ColumnVisibilitySchema,
2982
- defaultValue: () => defaultColumnVisibility ?? {}
2983
- }), [defaultColumnVisibility, tableStorageId]);
2984
- const columnSizingAtom = useMemo(() => Atom.kvs({
2985
- runtime: dataTableStorageRuntime,
2986
- key: `data-table:column-sizing:${tableStorageId}`,
2987
- schema: ColumnSizingSchema,
2988
- defaultValue: () => ({})
2989
- }), [tableStorageId]);
2990
- const viewAtom = useMemo(() => Atom.kvs({
2991
- runtime: dataTableStorageRuntime,
2992
- key: `data-table:view:${tableStorageId}`,
2993
- schema: DataTableViewSchema,
2994
- defaultValue: () => "table"
2995
- }), [tableStorageId]);
2996
- const [columnVisibility, setColumnVisibility] = useAtom(columnVisibilityAtom);
2997
- const [columnSizing, setColumnSizing] = useAtom(columnSizingAtom);
2998
- const [storedView, setStoredView] = useAtom(viewAtom);
2999
- const currentView = showGallery ? storedView : "table";
3000
- const isGalleryView = currentView === "gallery";
3001
- const [rowSelection, setRowSelection] = useState({});
3002
- const [collapsedGroups, setCollapsedGroups] = useState({});
3003
- const [activeDragLabel, setActiveDragLabel] = useState(null);
3004
- const availableGroupFieldIds = grouping?.fields.map((field) => field.id) ?? [];
3005
- const activeGrouping = urlGrouping?.filter((groupId) => availableGroupFieldIds.includes(groupId)) ?? getDefaultGrouping(grouping);
3006
- const sensors = useSensors(useSensor(PointerSensor, {
3007
- activationConstraint: {
3008
- distance: 8
2606
+ return /* @__PURE__ */ jsxs9(MenubarMenu, {
2607
+ children: [
2608
+ /* @__PURE__ */ jsxs9(MenubarTrigger, {
2609
+ "aria-label": store.config.labels.sortBy,
2610
+ children: [
2611
+ current ? current.desc ? /* @__PURE__ */ jsx17(ArrowDown, {}) : /* @__PURE__ */ jsx17(ArrowUp, {}) : /* @__PURE__ */ jsx17(ChevronsUpDown2, {}),
2612
+ /* @__PURE__ */ jsx17("span", {
2613
+ className: "hidden sm:inline",
2614
+ children: store.config.labels.sortBy
2615
+ })
2616
+ ]
2617
+ }),
2618
+ /* @__PURE__ */ jsx17(MenubarContent, {
2619
+ align: "end",
2620
+ className: "w-52",
2621
+ children: columns.map((column) => {
2622
+ const sortState = store.state.sorting.find(({ id }) => id === column.id);
2623
+ return /* @__PURE__ */ jsxs9(MenubarSub, {
2624
+ children: [
2625
+ /* @__PURE__ */ jsxs9(MenubarSubTrigger, {
2626
+ children: [
2627
+ sortState ? sortState.desc ? /* @__PURE__ */ jsx17(ArrowDown, {}) : /* @__PURE__ */ jsx17(ArrowUp, {}) : null,
2628
+ columnLabel(column)
2629
+ ]
2630
+ }),
2631
+ /* @__PURE__ */ jsxs9(MenubarSubContent, {
2632
+ children: [
2633
+ /* @__PURE__ */ jsxs9(MenubarItem, {
2634
+ onClick: () => sort(column.id, false),
2635
+ children: [
2636
+ /* @__PURE__ */ jsx17(ArrowUp, {}),
2637
+ " ",
2638
+ store.config.labels.sortAsc
2639
+ ]
2640
+ }),
2641
+ /* @__PURE__ */ jsxs9(MenubarItem, {
2642
+ onClick: () => sort(column.id, true),
2643
+ children: [
2644
+ /* @__PURE__ */ jsx17(ArrowDown, {}),
2645
+ " ",
2646
+ store.config.labels.sortDesc
2647
+ ]
2648
+ }),
2649
+ sortState ? /* @__PURE__ */ jsxs9(Fragment, {
2650
+ children: [
2651
+ /* @__PURE__ */ jsx17(MenubarSeparator, {}),
2652
+ /* @__PURE__ */ jsxs9(MenubarItem, {
2653
+ onClick: () => changeState(setStore, (state) => ({
2654
+ ...state,
2655
+ sorting: state.sorting.filter(({ id }) => id !== column.id)
2656
+ })),
2657
+ children: [
2658
+ /* @__PURE__ */ jsx17(X2, {}),
2659
+ " ",
2660
+ store.config.labels.sortClear
2661
+ ]
2662
+ })
2663
+ ]
2664
+ }) : null
2665
+ ]
2666
+ })
2667
+ ]
2668
+ }, column.id);
2669
+ })
2670
+ })
2671
+ ]
2672
+ });
2673
+ };
2674
+ var ViewMenu = ({
2675
+ tableAtom
2676
+ }) => {
2677
+ const [store, setStore] = useTableAtom(tableAtom);
2678
+ return /* @__PURE__ */ jsxs9(MenubarMenu, {
2679
+ children: [
2680
+ /* @__PURE__ */ jsxs9(MenubarTrigger, {
2681
+ "aria-label": store.config.labels.view,
2682
+ children: [
2683
+ store.state.view === "gallery" ? /* @__PURE__ */ jsx17(LayoutGrid, {}) : /* @__PURE__ */ jsx17(Rows3, {}),
2684
+ /* @__PURE__ */ jsx17("span", {
2685
+ className: "hidden sm:inline",
2686
+ children: store.config.labels.view
2687
+ })
2688
+ ]
2689
+ }),
2690
+ /* @__PURE__ */ jsx17(MenubarContent, {
2691
+ align: "end",
2692
+ children: /* @__PURE__ */ jsxs9(MenubarRadioGroup, {
2693
+ onValueChange: (view) => {
2694
+ if (view === "table" || view === "gallery") {
2695
+ changeState(setStore, (state) => ({ ...state, view }));
2696
+ }
2697
+ },
2698
+ value: store.state.view,
2699
+ children: [
2700
+ /* @__PURE__ */ jsxs9(MenubarRadioItem, {
2701
+ value: "table",
2702
+ children: [
2703
+ /* @__PURE__ */ jsx17(Rows3, {}),
2704
+ " ",
2705
+ store.config.labels.tableView
2706
+ ]
2707
+ }),
2708
+ /* @__PURE__ */ jsxs9(MenubarRadioItem, {
2709
+ value: "gallery",
2710
+ children: [
2711
+ /* @__PURE__ */ jsx17(LayoutGrid, {}),
2712
+ " ",
2713
+ store.config.labels.galleryView
2714
+ ]
2715
+ })
2716
+ ]
2717
+ })
2718
+ })
2719
+ ]
2720
+ });
2721
+ };
2722
+ var ColumnMenu = ({
2723
+ tableAtom
2724
+ }) => {
2725
+ const [store, setStore] = useTableAtom(tableAtom);
2726
+ const columns = deriveModel(store).columns.filter(({ colDef }) => colDef.hideable !== false);
2727
+ if (!columns.length)
2728
+ return null;
2729
+ return /* @__PURE__ */ jsxs9(MenubarMenu, {
2730
+ children: [
2731
+ /* @__PURE__ */ jsxs9(MenubarTrigger, {
2732
+ "aria-label": store.config.labels.columns,
2733
+ children: [
2734
+ /* @__PURE__ */ jsx17(Settings2, {}),
2735
+ /* @__PURE__ */ jsx17("span", {
2736
+ className: "hidden sm:inline",
2737
+ children: store.config.labels.columns
2738
+ })
2739
+ ]
2740
+ }),
2741
+ /* @__PURE__ */ jsx17(MenubarContent, {
2742
+ align: "end",
2743
+ children: /* @__PURE__ */ jsxs9(MenubarGroup, {
2744
+ children: [
2745
+ /* @__PURE__ */ jsx17(MenubarLabel, {
2746
+ children: store.config.labels.columns
2747
+ }),
2748
+ /* @__PURE__ */ jsx17(MenubarSeparator, {}),
2749
+ columns.map((column) => /* @__PURE__ */ jsx17(MenubarCheckboxItem, {
2750
+ checked: store.state.columnVisibility[column.id] !== false,
2751
+ onCheckedChange: (visible) => changeState(setStore, (state) => ({
2752
+ ...state,
2753
+ columnVisibility: {
2754
+ ...state.columnVisibility,
2755
+ [column.id]: visible
2756
+ }
2757
+ })),
2758
+ children: columnLabel(column)
2759
+ }, column.id))
2760
+ ]
2761
+ })
2762
+ })
2763
+ ]
2764
+ });
2765
+ };
2766
+ var ResizeHandle = ({
2767
+ tableAtom
2768
+ }) => {
2769
+ const [store, setStore] = useTableAtom(tableAtom);
2770
+ const columnId = useRequiredId(ColumnIdContext);
2771
+ const column = deriveModel(store).columns.find(({ id }) => id === columnId);
2772
+ if (!column || column.colDef.resizable === false)
2773
+ return null;
2774
+ const resize = (width) => changeState(setStore, (state) => ({
2775
+ ...state,
2776
+ columnSizing: {
2777
+ ...state.columnSizing,
2778
+ [column.id]: clampWidth(column.colDef, width)
3009
2779
  }
3010
2780
  }));
3011
- const updateTableSearch = (updater, options) => {
3012
- if (controlledSearch || onSearchChange || searchState === "local") {
3013
- const nextSearch = Schema2.decodeUnknownSync(TableSearchSchema)(updater(controlledSearch ?? localSearch));
3014
- if (onSearchChange) {
3015
- onSearchChange(nextSearch);
3016
- } else {
3017
- setLocalSearch(nextSearch);
3018
- }
2781
+ const onPointerDown = (event) => {
2782
+ event.preventDefault();
2783
+ event.currentTarget.setPointerCapture(event.pointerId);
2784
+ event.currentTarget.dataset.startX = String(event.clientX);
2785
+ event.currentTarget.dataset.startWidth = String(column.width);
2786
+ };
2787
+ const onPointerMove = (event) => {
2788
+ if (!event.currentTarget.hasPointerCapture(event.pointerId))
3019
2789
  return;
3020
- }
3021
- navigate({
3022
- to: ".",
3023
- replace: options?.replace ?? false,
3024
- resetScroll: false,
3025
- search: (current) => validateTableSearchUpdate(updater(current))
3026
- });
2790
+ const startX = Number(event.currentTarget.dataset.startX);
2791
+ const startWidth = Number(event.currentTarget.dataset.startWidth);
2792
+ resize(startWidth + event.clientX - startX);
3027
2793
  };
3028
- const table = useDataTable({
3029
- key: tableStorageId,
3030
- data,
3031
- columns,
3032
- onColumnSizingChange: (updater) => {
3033
- const nextColumnSizing = updater instanceof Function ? updater(columnSizing) : updater;
3034
- setColumnSizing(nextColumnSizing);
3035
- },
3036
- ...selectionFeature ? { getRowId: selectionFeature.getRowId } : reordering ? { getRowId: reordering.getRowId } : {},
3037
- enableRowSelection: selectionFeature?.isRowSelectable ? (row) => selectionFeature.isRowSelectable?.(row.original) ?? true : selectable,
3038
- enableMultiRowSelection: selectable,
3039
- onPaginationChange: (updater) => {
3040
- const newPagination = updater instanceof Function ? updater(pagination) : updater;
3041
- if (pagination.pageIndex === newPagination.pageIndex && pagination.pageSize === newPagination.pageSize) {
3042
- return;
3043
- }
3044
- updateTableSearch((current) => ({
3045
- ...current,
3046
- page: newPagination.pageIndex,
3047
- pageSize: newPagination.pageSize
3048
- }));
3049
- },
3050
- onSortingChange: (updater) => {
3051
- const newSorting = updater instanceof Function ? updater([...sorting]) : updater;
3052
- if (sorting.length === newSorting.length && sorting.every((sortState, i) => sortState.id === newSorting[i]?.id && sortState.desc === newSorting[i]?.desc)) {
3053
- return;
3054
- }
3055
- const nextSort = newSorting.length ? Schema2.encodeSync(SortParamsFromString)(newSorting.map((sortState) => ({
3056
- id: sortState.id,
3057
- direction: sortState.desc ? "desc" : "asc"
3058
- }))) : undefined;
3059
- updateTableSearch((current) => ({
3060
- ...current,
3061
- sort: nextSort,
3062
- page: 0
3063
- }));
3064
- },
3065
- onGlobalFilterChange: (updater) => {
3066
- const newGlobalFilter = updater instanceof Function ? updater(globalFilter) : updater;
3067
- if (globalFilter === newGlobalFilter) {
3068
- return;
2794
+ return /* @__PURE__ */ jsx17("button", {
2795
+ "aria-label": store.config.labels.resizeColumn(columnLabel(column)),
2796
+ "aria-orientation": "vertical",
2797
+ "aria-valuemax": column.colDef.maxWidth ?? DEFAULT_MAX_WIDTH,
2798
+ "aria-valuemin": column.colDef.minWidth ?? DEFAULT_MIN_WIDTH,
2799
+ "aria-valuenow": column.width,
2800
+ className: "hover:bg-primary/60 absolute inset-y-0 right-0 z-10 w-1 cursor-col-resize touch-none",
2801
+ onDoubleClick: () => resize(column.colDef.width ?? DEFAULT_WIDTH),
2802
+ onKeyDown: (event) => {
2803
+ const delta = event.key === "ArrowLeft" ? -8 : event.key === "ArrowRight" ? 8 : 0;
2804
+ if (delta) {
2805
+ event.preventDefault();
2806
+ resize(column.width + delta);
3069
2807
  }
3070
- updateTableSearch((current) => ({
3071
- ...current,
3072
- page: 0,
3073
- globalFilter: newGlobalFilter
3074
- }), { replace: true });
3075
- },
3076
- manualSorting: isServerMode || undefined,
3077
- manualFiltering: isServerMode || undefined,
3078
- ...paginationFeature !== false && paginationFeature.mode === "server" ? { manualPagination: true, rowCount: paginationFeature.rowCount } : paginationFeature === false ? { manualPagination: true } : {},
3079
- autoResetPageIndex: false,
3080
- onColumnVisibilityChange: (updater) => {
3081
- const nextColumnVisibility = updater instanceof Function ? updater(columnVisibility) : updater;
3082
- setColumnVisibility(nextColumnVisibility);
3083
- },
3084
- onRowSelectionChange: (updater) => {
3085
- setRowSelection((current) => {
3086
- const next = updater instanceof Function ? updater(current) : updater;
3087
- selectionFeature?.onSelectionChange?.(data.filter((row) => next[selectionFeature.getRowId(row)]));
3088
- return next;
3089
- });
3090
2808
  },
3091
- state: {
3092
- sorting,
3093
- pagination,
3094
- globalFilter,
3095
- columnVisibility,
3096
- columnSizing,
3097
- rowSelection
3098
- }
2809
+ onPointerDown,
2810
+ onPointerMove,
2811
+ role: "separator",
2812
+ type: "button"
3099
2813
  });
3100
- const activeGroupingFields = useMemo(() => activeGrouping.map((groupId) => grouping?.fields.find((field) => field.id === groupId)).filter((field) => !!field), [activeGrouping, grouping]);
3101
- const hasActiveGrouping = activeGroupingFields.length > 0;
3102
- const filteredRows = table.getPrePaginatedRowModel().rows;
3103
- const selectedRows = selectionFeature ? data.filter((row) => rowSelection[selectionFeature.getRowId(row)]) : [];
3104
- const exportRows = exportFeature && exportFeature.scope === "filteredRows" ? filteredRows : table.getRowModel().rows;
3105
- const bodyRows = hasActiveGrouping ? filteredRows : table.getRowModel().rows;
3106
- const sortableRowIds = bodyRows.map((row) => getSortableRowId(row.id));
3107
- const groupedSections = useMemo(() => buildGroupedSections(bodyRows, activeGroupingFields), [activeGroupingFields, bodyRows]);
3108
- const canReorderRows = Boolean(reordering) && !hasActiveGrouping;
3109
- const colSpan = Math.max(table.getVisibleLeafColumns().length, 1) + (rowActions ? 1 : 0) + (selectable ? 1 : 0) + (canReorderRows ? 1 : 0);
3110
- const canDragRows = activeGroupingFields.some((field) => !!field.onMoveToGroup);
3111
- const addGroupingField = (fieldId) => {
3112
- if (activeGrouping.includes(fieldId))
3113
- return;
3114
- updateTableSearch((current) => ({
3115
- ...current,
3116
- grouping: [...activeGrouping, fieldId]
3117
- }));
2814
+ };
2815
+ var DragHandle = ({
2816
+ tableAtom
2817
+ }) => {
2818
+ const [store, setStore] = useTableAtom(tableAtom);
2819
+ const rowId = useRequiredId(RowIdContext);
2820
+ const dragRef = useRef2(null);
2821
+ const [overlay, setOverlay] = useState(null);
2822
+ const reset = (element) => {
2823
+ clearDragPresentation(element.closest("[data-table-root]"));
2824
+ dragRef.current = null;
2825
+ setOverlay(null);
3118
2826
  };
3119
- const removeGroupingField = (fieldId) => {
3120
- updateTableSearch((current) => ({
3121
- ...current,
3122
- grouping: activeGrouping.filter((currentId) => currentId !== fieldId)
3123
- }));
2827
+ const onPointerDown = (event) => {
2828
+ event.stopPropagation();
2829
+ event.currentTarget.setPointerCapture(event.pointerId);
2830
+ const row = deriveModel(store).rows.find((candidate) => candidate.id === rowId);
2831
+ const grouping = store.config.features.grouping;
2832
+ const reordering = store.config.features.reordering;
2833
+ dragRef.current = {
2834
+ pointerId: event.pointerId,
2835
+ rowId,
2836
+ label: row && grouping && grouping.getRowLabel?.(row.data) || row && reordering && reordering.getRowLabel?.(row.data) || rowId,
2837
+ startX: event.clientX,
2838
+ startY: event.clientY,
2839
+ active: false
2840
+ };
3124
2841
  };
3125
- const toggleGroupingField = (fieldId, enabled) => {
3126
- if (enabled) {
3127
- addGroupingField(fieldId);
2842
+ const onPointerMove = (event) => {
2843
+ const drag = dragRef.current;
2844
+ if (!drag || drag.pointerId !== event.pointerId)
2845
+ return;
2846
+ const root = event.currentTarget.closest("[data-table-root]");
2847
+ const active = drag.active || Math.hypot(event.clientX - drag.startX, event.clientY - drag.startY) >= 8;
2848
+ drag.active = active;
2849
+ clearDragPresentation(root);
2850
+ if (!active)
3128
2851
  return;
2852
+ const elements = document.elementsFromPoint(event.clientX, event.clientY);
2853
+ const rowTarget = findTableDragTarget(elements, "[data-table-row]", root);
2854
+ const groupTarget = findTableDragTarget(elements, "[data-table-group]", root);
2855
+ event.currentTarget.closest("[data-table-row]")?.setAttribute("data-drag-source", "true");
2856
+ if (canMoveRowsToGroups(store)) {
2857
+ groupTarget?.setAttribute("data-drop-target", "true");
2858
+ } else if (rowTarget?.dataset.tableRow !== drag.rowId) {
2859
+ const rows = deriveModel(store).pageRows;
2860
+ const sourceIndex = rows.findIndex((row) => row.id === drag.rowId);
2861
+ const targetIndex = rows.findIndex((row) => row.id === rowTarget?.dataset.tableRow);
2862
+ if (sourceIndex !== -1 && targetIndex !== -1) {
2863
+ rowTarget?.setAttribute("data-drop-position", sourceIndex < targetIndex ? "after" : "before");
2864
+ }
3129
2865
  }
3130
- removeGroupingField(fieldId);
2866
+ setOverlay({ label: drag.label, x: event.clientX, y: event.clientY });
3131
2867
  };
3132
- const toggleGroup = (groupKey) => {
3133
- setCollapsedGroups((current) => ({
3134
- ...current,
3135
- [groupKey]: !current[groupKey]
3136
- }));
2868
+ const finish = (event) => {
2869
+ const drag = dragRef.current;
2870
+ if (!drag || drag.pointerId !== event.pointerId)
2871
+ return;
2872
+ const root = event.currentTarget.closest("[data-table-root]");
2873
+ const elements = document.elementsFromPoint(event.clientX, event.clientY);
2874
+ const rowTarget = findTableDragTarget(elements, "[data-table-row]", root);
2875
+ const groupTarget = findTableDragTarget(elements, "[data-table-group]", root);
2876
+ setStore((current) => {
2877
+ const targetRowId = rowTarget?.dataset.tableRow;
2878
+ const targetGroupKey = groupTarget?.dataset.tableGroup;
2879
+ const model = deriveModel(current);
2880
+ const source = model.sortedRows.find((row) => row.id === drag.rowId);
2881
+ const grouping = current.config.features.grouping;
2882
+ const reordering = current.config.features.reordering;
2883
+ if (drag.active && source && targetGroupKey && grouping) {
2884
+ const target = parseGroupDropKey(targetGroupKey);
2885
+ const field = grouping.fields.find(({ id }) => id === target?.fieldId);
2886
+ if (target && field?.onMoveToGroup && field.getGroupId(source.data) !== target.groupId) {
2887
+ field.onMoveToGroup(source.data, target.groupId);
2888
+ }
2889
+ } else if (drag.active && source && targetRowId && reordering && canReorderRows(current) && source.id !== targetRowId) {
2890
+ reordering.onReorder(reorderDataTableRows(model.rows, source.id, targetRowId));
2891
+ }
2892
+ return current;
2893
+ });
2894
+ reset(event.currentTarget);
2895
+ };
2896
+ const cancel = (event) => {
2897
+ if (dragRef.current?.pointerId === event.pointerId) {
2898
+ reset(event.currentTarget);
2899
+ }
3137
2900
  };
3138
- const setView = (nextView) => {
3139
- if (nextView === currentView) {
2901
+ const reorderWithKeyboard = (direction) => {
2902
+ const reordering = store.config.features.reordering;
2903
+ if (!reordering || !canReorderRows(store))
3140
2904
  return;
2905
+ const model = deriveModel(store);
2906
+ const visibleRows = model.pageRows;
2907
+ const sourceIndex = visibleRows.findIndex((row) => row.id === rowId);
2908
+ const target = visibleRows[sourceIndex + direction];
2909
+ if (sourceIndex !== -1 && target) {
2910
+ reordering.onReorder(reorderDataTableRows(model.rows, rowId, target.id));
3141
2911
  }
3142
- setStoredView(nextView);
3143
2912
  };
3144
- const renderLoadingState = () => /* @__PURE__ */ jsx17(Loading, {
3145
- label: labels2.loading
3146
- });
3147
- const renderEmptyContent = () => state?.error ?? (isLoading ? renderLoadingState() : emptyContent);
3148
- const renderTableEmptyState = () => /* @__PURE__ */ jsx17(TableRow, {
3149
- children: /* @__PURE__ */ jsx17(TableCell, {
3150
- className: "h-24 text-center",
3151
- colSpan,
3152
- children: renderEmptyContent()
3153
- })
2913
+ return /* @__PURE__ */ jsxs9(Fragment, {
2914
+ children: [
2915
+ /* @__PURE__ */ jsx17(Button, {
2916
+ "aria-label": store.config.features.reordering && store.config.features.reordering.handleLabel ? store.config.features.reordering.handleLabel : store.config.labels.reorder,
2917
+ className: "size-8 cursor-grab touch-none active:cursor-grabbing",
2918
+ onClick: (event) => event.stopPropagation(),
2919
+ onKeyDown: (event) => {
2920
+ if (event.key === "ArrowUp" || event.key === "ArrowDown") {
2921
+ event.preventDefault();
2922
+ event.stopPropagation();
2923
+ reorderWithKeyboard(event.key === "ArrowUp" ? -1 : 1);
2924
+ }
2925
+ },
2926
+ onPointerCancel: cancel,
2927
+ onPointerDown,
2928
+ onLostPointerCapture: cancel,
2929
+ onPointerMove,
2930
+ onPointerUp: finish,
2931
+ size: "icon",
2932
+ variant: "ghost",
2933
+ children: /* @__PURE__ */ jsx17(GripVertical, {})
2934
+ }),
2935
+ overlay ? createPortal(/* @__PURE__ */ jsx17("div", {
2936
+ "aria-hidden": "true",
2937
+ className: "bg-background pointer-events-none fixed z-[100] rounded-md border px-3 py-2 text-sm shadow-lg",
2938
+ style: { left: overlay.x + 12, top: overlay.y + 12 },
2939
+ children: overlay.label
2940
+ }), document.body) : null
2941
+ ]
3154
2942
  });
3155
- const renderGalleryEmptyState = (message) => /* @__PURE__ */ jsx17("div", {
3156
- className: "text-muted-foreground rounded-xl border border-dashed px-4 py-10 text-center text-sm",
3157
- children: message ?? renderEmptyContent()
3158
- });
3159
- const renderGalleryRows = (rows, canDrag) => /* @__PURE__ */ jsx17("div", {
3160
- className: "grid gap-3 sm:grid-cols-2 xl:grid-cols-3",
3161
- children: rows.map((row) => /* @__PURE__ */ jsx17(DataTableGalleryCard, {
3162
- canDrag,
3163
- dragLabel: grouping?.getRowLabel?.(row.original),
3164
- gallery: galleryConfig,
3165
- onRowClick,
3166
- row,
3167
- rowActions,
3168
- rowActionsLabel,
3169
- selectRowLabel: labels2.selectRow,
3170
- selectable,
3171
- table
3172
- }, row.id))
2943
+ };
2944
+ var toggleRow = (store, setStore, rowId, selected) => changeState(setStore, (state) => {
2945
+ const rowSelection = { ...state.rowSelection, [rowId]: selected };
2946
+ const selection = store.config.features.selection;
2947
+ if (selection) {
2948
+ const model = deriveModel(store);
2949
+ selection.onSelectionChange?.(model.rows.filter((row) => rowSelection[row.id]).map((row) => row.data));
2950
+ }
2951
+ return { ...state, rowSelection };
2952
+ });
2953
+ var TableDataRow = ({
2954
+ tableAtom
2955
+ }) => {
2956
+ const [store, setStore] = useTableAtom(tableAtom);
2957
+ const rowId = useRequiredId(RowIdContext);
2958
+ const model = deriveModel(store);
2959
+ const row = model.sortedRows.find((candidate) => candidate.id === rowId);
2960
+ if (!row)
2961
+ return null;
2962
+ const selection = store.config.features.selection;
2963
+ const selectable = !!selection && (selection.isRowSelectable?.(row.data) ?? true);
2964
+ const draggable = canDragRows(store);
2965
+ return /* @__PURE__ */ jsxs9(TableRow, {
2966
+ className: cn("group/row h-16 data-[drag-source=true]:opacity-40 data-[drop-position=before]:[&>td]:border-t-2 data-[drop-position=before]:[&>td]:border-primary data-[drop-position=after]:[&>td]:border-b-2 data-[drop-position=after]:[&>td]:border-primary", store.config.onRowClicked && "cursor-pointer"),
2967
+ "data-state": store.state.rowSelection[row.id] && "selected",
2968
+ "data-table-row": row.id,
2969
+ onClick: () => store.config.onRowClicked?.(row.data),
2970
+ onKeyDown: (event) => {
2971
+ if (event.target === event.currentTarget && store.config.onRowClicked && (event.key === "Enter" || event.key === " ")) {
2972
+ event.preventDefault();
2973
+ store.config.onRowClicked(row.data);
2974
+ }
2975
+ },
2976
+ tabIndex: store.config.onRowClicked ? 0 : undefined,
2977
+ children: [
2978
+ selection ? /* @__PURE__ */ jsx17(TableCell, {
2979
+ className: "w-10 pr-0",
2980
+ onClick: (event) => event.stopPropagation(),
2981
+ children: /* @__PURE__ */ jsx17(Checkbox, {
2982
+ "aria-label": store.config.labels.selectRow,
2983
+ checked: !!store.state.rowSelection[row.id],
2984
+ disabled: !selectable,
2985
+ onCheckedChange: (checked) => toggleRow(store, setStore, row.id, checked)
2986
+ })
2987
+ }) : null,
2988
+ draggable ? /* @__PURE__ */ jsx17(TableCell, {
2989
+ className: "w-10 pr-0",
2990
+ children: /* @__PURE__ */ jsx17(DragHandle, {
2991
+ tableAtom
2992
+ })
2993
+ }) : null,
2994
+ model.visibleColumns.map((column) => /* @__PURE__ */ jsx17(TableCell, {
2995
+ className: cn("min-w-24 overflow-hidden", column.colDef.truncate ? "whitespace-nowrap" : "whitespace-normal"),
2996
+ style: { width: column.width },
2997
+ children: /* @__PURE__ */ jsx17("div", {
2998
+ className: cn("min-w-0", column.colDef.truncate && "truncate"),
2999
+ children: renderCell(row, column)
3000
+ })
3001
+ }, column.id)),
3002
+ hasRowActionMenu(store) ? /* @__PURE__ */ jsx17(TableCell, {
3003
+ 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))]",
3004
+ onClick: (event) => event.stopPropagation(),
3005
+ children: /* @__PURE__ */ jsx17("div", {
3006
+ className: "flex h-16 items-center justify-center",
3007
+ children: /* @__PURE__ */ jsx17(DataTableRowActionMenu, {
3008
+ tableAtom
3009
+ })
3010
+ })
3011
+ }) : null
3012
+ ]
3173
3013
  });
3174
- const renderGroupedTableSections = (sections) => sections.flatMap((section) => {
3175
- const isCollapsed = collapsedGroups[section.key] ?? false;
3176
- const hasChildren = section.children.length > 0;
3177
- const sectionBody = /* @__PURE__ */ jsxs8(GroupTableSection, {
3178
- section,
3014
+ };
3015
+ var GroupActions = ({
3016
+ actions,
3017
+ groupId,
3018
+ title
3019
+ }) => {
3020
+ const visible = actions?.filter((action) => !action.visible || action.visible(groupId));
3021
+ if (!visible?.length)
3022
+ return null;
3023
+ return /* @__PURE__ */ jsxs9(DropdownMenu, {
3024
+ children: [
3025
+ /* @__PURE__ */ jsx17(DropdownMenuTrigger, {
3026
+ onClick: (event) => event.stopPropagation(),
3027
+ render: /* @__PURE__ */ jsxs9(Button, {
3028
+ size: "icon",
3029
+ variant: "ghost",
3030
+ children: [
3031
+ /* @__PURE__ */ jsx17("span", {
3032
+ className: "sr-only",
3033
+ children: title
3034
+ }),
3035
+ /* @__PURE__ */ jsx17(MoreHorizontal, {})
3036
+ ]
3037
+ })
3038
+ }),
3039
+ /* @__PURE__ */ jsx17(DropdownMenuContent, {
3040
+ align: "end",
3041
+ children: /* @__PURE__ */ jsx17(DropdownMenuGroup, {
3042
+ children: visible.map((action) => /* @__PURE__ */ jsxs9(DropdownMenuItem, {
3043
+ onClick: () => action.onClick(groupId),
3044
+ variant: action.variant,
3045
+ children: [
3046
+ action.icon,
3047
+ " ",
3048
+ action.name
3049
+ ]
3050
+ }, action.name))
3051
+ })
3052
+ })
3053
+ ]
3054
+ });
3055
+ };
3056
+ var GroupedTable = ({
3057
+ tableAtom
3058
+ }) => {
3059
+ const [store, setStore] = useTableAtom(tableAtom);
3060
+ const model = deriveModel(store);
3061
+ const sections = groupDataTableRows(model.sortedRows, getActiveGrouping(store));
3062
+ const extra = (store.config.features.selection ? 1 : 0) + (hasRowActionMenu(store) ? 1 : 0) + (canDragRows(store) ? 1 : 0);
3063
+ const renderSections = (items) => items.flatMap((section) => {
3064
+ const collapsed = !!store.state.collapsedGroups[section.key];
3065
+ const targetKey = getGroupDropKey(section.field.id, section.groupId);
3066
+ const body = /* @__PURE__ */ jsxs9(TableBody, {
3067
+ 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",
3068
+ "data-table-group": section.field.onMoveToGroup ? targetKey : undefined,
3179
3069
  children: [
3180
- /* @__PURE__ */ jsx17(GroupHeaderRow, {
3181
- collapsed: isCollapsed,
3182
- colSpan,
3183
- onToggle: () => toggleGroup(section.key),
3184
- section
3185
- }),
3186
- !isCollapsed && !hasChildren && (section.rows.length > 0 ? section.rows.map((row) => /* @__PURE__ */ jsx17(DataTableRow, {
3187
- canDrag: canDragRows,
3188
- canReorder: false,
3189
- dragLabel: grouping?.getRowLabel?.(row.original),
3190
- indentDepth: section.depth + 1,
3191
- onRowClick,
3192
- row,
3193
- rowActions,
3194
- rowActionsLabel,
3195
- selectRowLabel: labels2.selectRow,
3196
- selectable,
3197
- table
3198
- }, row.id)) : /* @__PURE__ */ jsx17(TableRow, {
3070
+ /* @__PURE__ */ jsx17(TableRow, {
3071
+ className: "bg-muted/40",
3199
3072
  children: /* @__PURE__ */ jsx17(TableCell, {
3200
- className: "text-muted-foreground h-16",
3201
- colSpan,
3202
- style: {
3203
- paddingLeft: `calc(0.5rem + ${section.depth * GROUP_INDENT_PX + GROUP_ROW_INDENT_OFFSET_PX}px)`
3204
- },
3205
- children: isLoading ? renderLoadingState() : section.field.renderEmptyGroup?.(section.groupId) ?? labels2.empty
3073
+ colSpan: model.visibleColumns.length + extra,
3074
+ children: /* @__PURE__ */ jsxs9("div", {
3075
+ className: "flex items-center gap-2",
3076
+ style: { paddingLeft: section.depth * 20 },
3077
+ children: [
3078
+ /* @__PURE__ */ jsxs9("button", {
3079
+ "aria-expanded": !collapsed,
3080
+ className: "flex flex-1 items-center gap-2 text-left",
3081
+ onClick: () => changeState(setStore, (state) => ({
3082
+ ...state,
3083
+ collapsedGroups: {
3084
+ ...state.collapsedGroups,
3085
+ [section.key]: !collapsed
3086
+ }
3087
+ })),
3088
+ type: "button",
3089
+ children: [
3090
+ collapsed ? /* @__PURE__ */ jsx17(ChevronRight2, {
3091
+ className: "size-4"
3092
+ }) : /* @__PURE__ */ jsx17(ChevronDown, {
3093
+ className: "size-4"
3094
+ }),
3095
+ /* @__PURE__ */ jsx17("span", {
3096
+ className: "flex-1",
3097
+ children: section.field.renderGroupLabel?.(section.groupId, section.rows.map((row) => row.data)) ?? section.groupId
3098
+ })
3099
+ ]
3100
+ }),
3101
+ /* @__PURE__ */ jsx17(Badge, {
3102
+ variant: "secondary",
3103
+ children: section.rows.length
3104
+ }),
3105
+ /* @__PURE__ */ jsx17(GroupActions, {
3106
+ actions: section.field.actions,
3107
+ groupId: section.groupId,
3108
+ title: section.field.actionsLabel ?? store.config.labels.actions
3109
+ })
3110
+ ]
3111
+ })
3206
3112
  })
3207
- }))
3208
- ]
3209
- }, section.key);
3210
- return !isCollapsed && hasChildren ? [sectionBody, renderGroupedTableSections(section.children)] : [sectionBody];
3211
- });
3212
- const renderGroupedGallerySections = (sections) => sections.map((section) => {
3213
- const isCollapsed = collapsedGroups[section.key] ?? false;
3214
- const hasChildren = section.children.length > 0;
3215
- return /* @__PURE__ */ jsxs8("div", {
3216
- className: "space-y-3",
3217
- children: [
3218
- /* @__PURE__ */ jsx17(GroupHeaderCard, {
3219
- collapsed: isCollapsed,
3220
- onToggle: () => toggleGroup(section.key),
3221
- section
3222
3113
  }),
3223
- !isCollapsed && (hasChildren ? renderGroupedGallerySections(section.children) : section.rows.length > 0 ? renderGalleryRows(section.rows, canDragRows) : renderGalleryEmptyState(isLoading ? renderLoadingState() : section.field.renderEmptyGroup?.(section.groupId) ?? labels2.empty))
3114
+ !collapsed && !section.children.length ? section.rows.length ? section.rows.map((row) => /* @__PURE__ */ jsx17(RowIdContext.Provider, {
3115
+ value: row.id,
3116
+ children: /* @__PURE__ */ jsx17(TableDataRow, {
3117
+ tableAtom
3118
+ })
3119
+ }, `${section.key}:${row.id}`)) : [
3120
+ /* @__PURE__ */ jsx17(TableRow, {
3121
+ children: /* @__PURE__ */ jsx17(TableCell, {
3122
+ className: "text-muted-foreground h-16",
3123
+ colSpan: model.visibleColumns.length + extra,
3124
+ children: section.field.renderEmptyGroup?.(section.groupId) ?? store.config.labels.empty
3125
+ })
3126
+ }, `${section.key}:empty`)
3127
+ ] : null
3224
3128
  ]
3225
3129
  }, section.key);
3130
+ return !collapsed && section.children.length ? [body, renderSections(section.children)] : [body];
3226
3131
  });
3227
- const handleDragEnd = ({ active, over }) => {
3228
- setActiveDragLabel(null);
3229
- if (!over)
3230
- return;
3231
- const reorderData = decodeRowReorderDragData(active.data.current);
3232
- if (Option2.isSome(reorderData) && reordering && canReorderRows) {
3233
- const sourceRowId = String(active.id).replace(/^sortable-row:/, "");
3234
- const targetRowId = String(over.id).replace(/^sortable-row:/, "");
3235
- const currentIndex = bodyRows.findIndex((row2) => row2.id === sourceRowId);
3236
- const nextIndex = bodyRows.findIndex((row2) => row2.id === targetRowId);
3237
- if (currentIndex !== -1 && nextIndex !== -1 && currentIndex !== nextIndex) {
3238
- reordering.onReorder(arrayMove(bodyRows.map((row2) => row2.original), currentIndex, nextIndex));
3239
- }
3240
- return;
3241
- }
3242
- const rowData = decodeRowDragData(active.data.current);
3243
- const groupData = decodeGroupDropData(over.data.current);
3244
- if (Option2.isNone(rowData) || Option2.isNone(groupData))
3245
- return;
3246
- const row = bodyRows.find(({ id }) => id === rowData.value.rowId)?.original;
3247
- const field = grouping?.fields.find((currentField) => currentField.id === groupData.value.fieldId);
3248
- const nextGroupId = groupData.value.groupId;
3249
- if (row && field?.onMoveToGroup && field.getGroupId(row) !== nextGroupId) {
3250
- field.onMoveToGroup(row, nextGroupId);
3251
- }
3252
- };
3253
- const handleDragStart = ({ active }) => {
3254
- const rowData = decodeRowDragData(active.data.current);
3255
- setActiveDragLabel(Option2.isSome(rowData) ? rowData.value.label ?? null : null);
3256
- };
3257
- return /* @__PURE__ */ jsxs8("div", {
3258
- className: "w-full max-w-full min-w-0 rounded-md",
3132
+ return /* @__PURE__ */ jsx17(Fragment, {
3133
+ children: renderSections(sections)
3134
+ });
3135
+ };
3136
+ var ColumnHeaderMenu = ({
3137
+ tableAtom
3138
+ }) => {
3139
+ const [store, setStore] = useTableAtom(tableAtom);
3140
+ const columnId = useRequiredId(ColumnIdContext);
3141
+ const column = deriveModel(store).columns.find(({ id }) => id === columnId);
3142
+ if (!column)
3143
+ return null;
3144
+ const sortingEnabled = store.config.features.sorting !== false && column.colDef.sortable !== false;
3145
+ const hidingEnabled = store.config.features.columnVisibility !== false && column.colDef.hideable !== false;
3146
+ const sort = store.state.sorting.find(({ id }) => id === column.id);
3147
+ const update = (next) => changeState(setStore, next);
3148
+ const setSort = (desc) => update((state) => ({
3149
+ ...state,
3150
+ sorting: [{ id: column.id, desc }],
3151
+ pagination: { ...state.pagination, pageIndex: 0 }
3152
+ }));
3153
+ const label = columnLabel(column);
3154
+ if (!sortingEnabled && !hidingEnabled) {
3155
+ return /* @__PURE__ */ jsx17("div", {
3156
+ className: "truncate",
3157
+ children: column.colDef.headerName
3158
+ });
3159
+ }
3160
+ return /* @__PURE__ */ jsxs9(DropdownMenu, {
3259
3161
  children: [
3260
- /* @__PURE__ */ jsx17(DataTableToolbar, {
3261
- activeGrouping,
3262
- bulkActions,
3263
- exportBaseName,
3264
- exportRows,
3265
- grouping,
3266
- labels: labels2,
3267
- onRefresh,
3268
- onToggleGrouping: toggleGroupingField,
3269
- onViewChange: setView,
3270
- selectedRows,
3271
- showColumnVisibility,
3272
- showExport,
3273
- showGallery,
3274
- showSearch,
3275
- showSorting,
3276
- table,
3277
- view: currentView
3162
+ /* @__PURE__ */ jsx17(DropdownMenuTrigger, {
3163
+ render: /* @__PURE__ */ jsxs9(Button, {
3164
+ "aria-label": label,
3165
+ className: "h-8 max-w-full justify-start px-2",
3166
+ size: "sm",
3167
+ variant: "ghost",
3168
+ children: [
3169
+ /* @__PURE__ */ jsx17("span", {
3170
+ className: "truncate",
3171
+ children: column.colDef.headerName
3172
+ }),
3173
+ sort ? sort.desc ? /* @__PURE__ */ jsx17(ArrowDown, {}) : /* @__PURE__ */ jsx17(ArrowUp, {}) : sortingEnabled ? /* @__PURE__ */ jsx17(ChevronsUpDown2, {}) : null
3174
+ ]
3175
+ })
3278
3176
  }),
3279
- /* @__PURE__ */ jsx17(DndContext, {
3280
- onDragCancel: () => setActiveDragLabel(null),
3281
- onDragEnd: handleDragEnd,
3282
- onDragStart: handleDragStart,
3283
- sensors,
3284
- children: /* @__PURE__ */ jsxs8(table.AppTable, {
3177
+ /* @__PURE__ */ jsx17(DropdownMenuContent, {
3178
+ align: "start",
3179
+ className: "w-48",
3180
+ children: /* @__PURE__ */ jsxs9(DropdownMenuGroup, {
3285
3181
  children: [
3286
- isGalleryView ? hasActiveGrouping ? groupedSections.length > 0 ? /* @__PURE__ */ jsx17("div", {
3287
- className: "space-y-4",
3288
- children: renderGroupedGallerySections(groupedSections)
3289
- }) : renderGalleryEmptyState() : bodyRows.length > 0 ? renderGalleryRows(bodyRows, false) : renderGalleryEmptyState() : /* @__PURE__ */ jsxs8(ScrollArea, {
3290
- className: "-m-1 max-w-full min-w-0",
3182
+ sortingEnabled ? /* @__PURE__ */ jsxs9(Fragment, {
3183
+ children: [
3184
+ /* @__PURE__ */ jsxs9(DropdownMenuItem, {
3185
+ onClick: () => setSort(false),
3186
+ children: [
3187
+ /* @__PURE__ */ jsx17(ArrowUp, {}),
3188
+ " ",
3189
+ store.config.labels.sortAsc
3190
+ ]
3191
+ }),
3192
+ /* @__PURE__ */ jsxs9(DropdownMenuItem, {
3193
+ onClick: () => setSort(true),
3194
+ children: [
3195
+ /* @__PURE__ */ jsx17(ArrowDown, {}),
3196
+ " ",
3197
+ store.config.labels.sortDesc
3198
+ ]
3199
+ }),
3200
+ sort ? /* @__PURE__ */ jsxs9(DropdownMenuItem, {
3201
+ onClick: () => update((state) => ({
3202
+ ...state,
3203
+ sorting: state.sorting.filter(({ id }) => id !== column.id)
3204
+ })),
3205
+ children: [
3206
+ /* @__PURE__ */ jsx17(X2, {}),
3207
+ " ",
3208
+ store.config.labels.sortClear
3209
+ ]
3210
+ }) : null
3211
+ ]
3212
+ }) : null,
3213
+ sortingEnabled && hidingEnabled ? /* @__PURE__ */ jsx17(DropdownMenuSeparator, {}) : null,
3214
+ hidingEnabled ? /* @__PURE__ */ jsxs9(DropdownMenuItem, {
3215
+ onClick: () => update((state) => ({
3216
+ ...state,
3217
+ columnVisibility: {
3218
+ ...state.columnVisibility,
3219
+ [column.id]: false
3220
+ }
3221
+ })),
3222
+ children: [
3223
+ /* @__PURE__ */ jsx17(EyeOff, {}),
3224
+ " ",
3225
+ store.config.labels.hideColumn
3226
+ ]
3227
+ }) : null
3228
+ ]
3229
+ })
3230
+ })
3231
+ ]
3232
+ });
3233
+ };
3234
+ var DataTableHeader = ({
3235
+ tableAtom
3236
+ }) => {
3237
+ const [store, setStore] = useTableAtom(tableAtom);
3238
+ const model = deriveModel(store);
3239
+ const selection = store.config.features.selection;
3240
+ const grouped = getActiveGrouping(store).length > 0;
3241
+ const draggable = canDragRows(store);
3242
+ const selectableRows = getDataTableSelectableRows(model, grouped, selection ? selection.isRowSelectable : undefined);
3243
+ const allSelected = selectableRows.length > 0 && selectableRows.every((row) => store.state.rowSelection[row.id]);
3244
+ const someSelected = selectableRows.some((row) => store.state.rowSelection[row.id]);
3245
+ return /* @__PURE__ */ jsx17(TableHeader, {
3246
+ children: /* @__PURE__ */ jsxs9(TableRow, {
3247
+ children: [
3248
+ selection ? /* @__PURE__ */ jsx17(TableHead, {
3249
+ className: "w-10 pr-0",
3250
+ children: /* @__PURE__ */ jsx17(Checkbox, {
3251
+ "aria-label": store.config.labels.selectAllRows,
3252
+ checked: allSelected,
3253
+ indeterminate: someSelected && !allSelected,
3254
+ onCheckedChange: (checked) => {
3255
+ changeState(setStore, (state) => {
3256
+ const rowSelection = { ...state.rowSelection };
3257
+ selectableRows.forEach((row) => rowSelection[row.id] = checked);
3258
+ selection.onSelectionChange?.(model.rows.filter((row) => rowSelection[row.id]).map((row) => row.data));
3259
+ return { ...state, rowSelection };
3260
+ });
3261
+ }
3262
+ })
3263
+ }) : null,
3264
+ draggable ? /* @__PURE__ */ jsx17(TableHead, {
3265
+ className: "w-10"
3266
+ }) : null,
3267
+ model.visibleColumns.map((column) => {
3268
+ return /* @__PURE__ */ jsx17(TableHead, {
3269
+ className: "relative h-12",
3270
+ style: { width: column.width },
3271
+ children: /* @__PURE__ */ jsxs9(ColumnIdContext.Provider, {
3272
+ value: column.id,
3291
3273
  children: [
3292
- /* @__PURE__ */ jsx17("div", {
3293
- className: "max-w-full min-w-0 p-1",
3294
- children: /* @__PURE__ */ jsxs8(Table, {
3295
- className: "table-fixed",
3296
- style: {
3297
- width: `max(100%, ${table.getTotalSize() + (canReorderRows ? 40 : 0) + (selectable ? 40 : 0) + (rowActions ? 40 : 0)}px)`
3298
- },
3299
- children: [
3300
- /* @__PURE__ */ jsx17(TableHeader, {
3301
- children: table.getHeaderGroups().map((headerGroup) => /* @__PURE__ */ jsxs8(TableRow, {
3302
- className: "p-4",
3303
- children: [
3304
- selectable ? /* @__PURE__ */ jsx17(TableHead, {
3305
- className: "w-10 min-w-10 pr-0",
3306
- children: /* @__PURE__ */ jsx17(Checkbox, {
3307
- "aria-label": labels2.selectAllRows,
3308
- checked: table.getIsAllPageRowsSelected(),
3309
- indeterminate: table.getIsSomePageRowsSelected() && !table.getIsAllPageRowsSelected(),
3310
- onCheckedChange: (checked) => table.toggleAllPageRowsSelected(checked)
3311
- })
3312
- }) : null,
3313
- canReorderRows ? /* @__PURE__ */ jsx17(TableHead, {
3314
- className: "w-10 min-w-10 p-0"
3315
- }) : null,
3316
- headerGroup.headers.map((header) => /* @__PURE__ */ jsx17(table.AppHeader, {
3317
- header,
3318
- children: (appHeader) => /* @__PURE__ */ jsxs8(TableHead, {
3319
- className: "relative h-12 min-w-32 p-0",
3320
- style: { width: header.getSize() },
3321
- children: [
3322
- header.isPlaceholder ? null : /* @__PURE__ */ jsx17(appHeader.FlexRender, {}),
3323
- header.column.getCanResize() ? /* @__PURE__ */ jsx17("button", {
3324
- "aria-label": labels2.resizeColumn(getHeaderName(header)),
3325
- "aria-orientation": "vertical",
3326
- "aria-valuemax": header.column.columnDef.maxSize ?? DEFAULT_COLUMN_MAX_SIZE,
3327
- "aria-valuemin": header.column.columnDef.minSize ?? DEFAULT_COLUMN_MIN_SIZE,
3328
- "aria-valuenow": header.column.getSize(),
3329
- className: cn("hover:bg-primary/60 absolute inset-y-0 right-0 z-10 w-1 cursor-col-resize touch-none bg-transparent p-0 select-none", header.column.getIsResizing() && "bg-primary"),
3330
- onKeyDown: (event) => {
3331
- const minSize = header.column.columnDef.minSize ?? DEFAULT_COLUMN_MIN_SIZE;
3332
- const maxSize = header.column.columnDef.maxSize ?? DEFAULT_COLUMN_MAX_SIZE;
3333
- const currentSize = header.column.getSize();
3334
- const nextSize = event.key === "ArrowLeft" ? currentSize - COLUMN_RESIZE_STEP : event.key === "ArrowRight" ? currentSize + COLUMN_RESIZE_STEP : event.key === "Home" ? minSize : event.key === "End" ? maxSize : undefined;
3335
- if (nextSize === undefined)
3336
- return;
3337
- event.preventDefault();
3338
- table.setColumnSizing((current) => ({
3339
- ...current,
3340
- [header.column.id]: Math.min(maxSize, Math.max(minSize, nextSize))
3341
- }));
3342
- },
3343
- role: "separator",
3344
- type: "button",
3345
- onDoubleClick: () => header.column.resetSize(),
3346
- onMouseDown: header.getResizeHandler(),
3347
- onTouchStart: header.getResizeHandler()
3348
- }) : null
3349
- ]
3350
- })
3351
- }, header.id)),
3352
- rowActions ? /* @__PURE__ */ jsx17(TableHead, {
3353
- className: "w-10 min-w-10 p-0"
3354
- }) : null
3355
- ]
3356
- }, headerGroup.id))
3357
- }),
3358
- hasActiveGrouping ? groupedSections.length > 0 ? renderGroupedTableSections(groupedSections) : /* @__PURE__ */ jsx17(TableBody, {
3359
- className: "px-2",
3360
- children: renderTableEmptyState()
3361
- }) : /* @__PURE__ */ jsx17(TableBody, {
3362
- className: "px-2",
3363
- children: bodyRows.length > 0 ? canReorderRows ? /* @__PURE__ */ jsx17(SortableContext, {
3364
- items: sortableRowIds,
3365
- strategy: verticalListSortingStrategy,
3366
- children: bodyRows.map((row) => /* @__PURE__ */ jsx17(DataTableRow, {
3367
- canDrag: false,
3368
- canReorder: true,
3369
- dragLabel: reordering?.getRowLabel?.(row.original),
3370
- onRowClick,
3371
- reorderHandleLabel: reordering?.handleLabel ?? labels2.reorder,
3372
- row,
3373
- rowActions,
3374
- rowActionsLabel,
3375
- selectRowLabel: labels2.selectRow,
3376
- selectable,
3377
- table
3378
- }, row.id))
3379
- }) : bodyRows.map((row) => /* @__PURE__ */ jsx17(DataTableRow, {
3380
- canDrag: false,
3381
- canReorder: false,
3382
- onRowClick,
3383
- row,
3384
- rowActions,
3385
- rowActionsLabel,
3386
- selectRowLabel: labels2.selectRow,
3387
- selectable,
3388
- table
3389
- }, row.id)) : renderTableEmptyState()
3390
- })
3391
- ]
3392
- })
3274
+ /* @__PURE__ */ jsx17(ColumnHeaderMenu, {
3275
+ tableAtom
3393
3276
  }),
3394
- /* @__PURE__ */ jsx17(ScrollBar, {
3395
- orientation: "horizontal"
3277
+ /* @__PURE__ */ jsx17(ResizeHandle, {
3278
+ tableAtom
3396
3279
  })
3397
3280
  ]
3398
- }),
3399
- /* @__PURE__ */ jsx17(DragOverlay, {
3400
- modifiers: [snapDragOverlayVerticalCenterToCursor],
3401
- children: activeDragLabel ? /* @__PURE__ */ jsx17("div", {
3402
- className: "bg-background rounded-md border px-3 py-2 text-sm shadow-sm",
3403
- children: activeDragLabel
3404
- }) : null
3405
3281
  })
3406
- ]
3407
- })
3408
- }),
3409
- showPagination && !hasActiveGrouping && /* @__PURE__ */ jsx17("div", {
3410
- className: "p-2",
3411
- children: /* @__PURE__ */ jsx17(DataTablePagination, {
3412
- messages: labels2,
3413
- pageSizes,
3414
- rowCount: serverRowCount,
3415
- table
3282
+ }, column.id);
3283
+ }),
3284
+ hasRowActionMenu(store) ? /* @__PURE__ */ jsx17(TableHead, {
3285
+ className: "w-10"
3286
+ }) : null
3287
+ ]
3288
+ })
3289
+ });
3290
+ };
3291
+ var DataTableBody = ({
3292
+ tableAtom
3293
+ }) => {
3294
+ const [store] = useTableAtom(tableAtom);
3295
+ const model = deriveModel(store);
3296
+ const grouped = getActiveGrouping(store).length > 0;
3297
+ const rows = grouped ? model.sortedRows : model.pageRows;
3298
+ const colSpan = model.visibleColumns.length + (store.config.features.selection ? 1 : 0) + (hasRowActionMenu(store) ? 1 : 0) + (canDragRows(store) ? 1 : 0);
3299
+ if (grouped && rows.length && !store.config.status.error) {
3300
+ return /* @__PURE__ */ jsx17(GroupedTable, {
3301
+ tableAtom
3302
+ });
3303
+ }
3304
+ return /* @__PURE__ */ jsx17(TableBody, {
3305
+ children: store.config.status.error || !rows.length && !store.config.status.loading ? /* @__PURE__ */ jsx17(TableRow, {
3306
+ children: /* @__PURE__ */ jsx17(TableCell, {
3307
+ className: "h-24 text-center",
3308
+ colSpan: Math.max(colSpan, 1),
3309
+ children: store.config.status.error ?? store.config.status.empty ?? store.config.labels.empty
3310
+ })
3311
+ }) : store.config.status.loading && !rows.length ? /* @__PURE__ */ jsx17(TableRow, {
3312
+ children: /* @__PURE__ */ jsx17(TableCell, {
3313
+ className: "h-24 text-center",
3314
+ colSpan: Math.max(colSpan, 1),
3315
+ children: /* @__PURE__ */ jsx17(Loading, {
3316
+ label: store.config.labels.loading
3416
3317
  })
3417
3318
  })
3418
- ]
3319
+ }) : rows.map((row) => /* @__PURE__ */ jsx17(RowIdContext.Provider, {
3320
+ value: row.id,
3321
+ children: /* @__PURE__ */ jsx17(TableDataRow, {
3322
+ tableAtom
3323
+ })
3324
+ }, row.id))
3419
3325
  });
3420
- }
3421
- function DataTableDisplayModeSwitch({
3422
- messages: messages4,
3423
- value,
3424
- onChange
3425
- }) {
3426
- return /* @__PURE__ */ jsxs8(DropdownMenu, {
3427
- children: [
3428
- /* @__PURE__ */ jsx17(DropdownMenuTrigger, {
3429
- render: /* @__PURE__ */ jsxs8(Button, {
3430
- "aria-label": messages4.view,
3431
- className: "h-9",
3432
- size: "sm",
3433
- variant: "outline",
3326
+ };
3327
+ var GalleryCard = ({
3328
+ tableAtom
3329
+ }) => {
3330
+ const [store, setStore] = useTableAtom(tableAtom);
3331
+ const rowId = useRequiredId(RowIdContext);
3332
+ const model = deriveModel(store);
3333
+ const row = model.sortedRows.find((candidate) => candidate.id === rowId);
3334
+ const gallery = store.config.features.gallery;
3335
+ if (!row || !gallery)
3336
+ return null;
3337
+ const find = (id) => id ? model.visibleColumns.find((column) => column.id === id) : undefined;
3338
+ const name = find(gallery.name);
3339
+ const description = find(gallery.description);
3340
+ const tag = find(gallery.tag);
3341
+ const selection = store.config.features.selection;
3342
+ const selectable = !!selection && (selection.isRowSelectable?.(row.data) ?? true);
3343
+ const draggable = canDragRows(store);
3344
+ return /* @__PURE__ */ jsx17(Card, {
3345
+ className: cn("relative gap-3 data-[drag-source=true]:opacity-40 data-[drop-position=before]:border-t-2 data-[drop-position=before]:border-t-primary data-[drop-position=after]:border-b-2 data-[drop-position=after]:border-b-primary", store.config.onRowClicked && "cursor-pointer"),
3346
+ "data-table-row": row.id,
3347
+ onClick: () => store.config.onRowClicked?.(row.data),
3348
+ onKeyDown: (event) => {
3349
+ if (event.target === event.currentTarget && store.config.onRowClicked && (event.key === "Enter" || event.key === " ")) {
3350
+ event.preventDefault();
3351
+ store.config.onRowClicked(row.data);
3352
+ }
3353
+ },
3354
+ tabIndex: store.config.onRowClicked ? 0 : undefined,
3355
+ children: /* @__PURE__ */ jsxs9(CardHeader, {
3356
+ className: "pr-12",
3357
+ children: [
3358
+ /* @__PURE__ */ jsxs9("div", {
3359
+ className: "flex items-center gap-2",
3434
3360
  children: [
3435
- value === "gallery" ? /* @__PURE__ */ jsx17(LayoutGrid, {}) : /* @__PURE__ */ jsx17(Rows3, {}),
3436
- /* @__PURE__ */ jsx17("span", {
3437
- className: "hidden sm:inline",
3438
- children: messages4.view
3439
- })
3361
+ selection ? /* @__PURE__ */ jsx17(Checkbox, {
3362
+ "aria-label": store.config.labels.selectRow,
3363
+ checked: !!store.state.rowSelection[row.id],
3364
+ disabled: !selectable,
3365
+ onCheckedChange: (checked) => toggleRow(store, setStore, row.id, checked),
3366
+ onClick: (event) => event.stopPropagation()
3367
+ }) : null,
3368
+ draggable ? /* @__PURE__ */ jsx17(DragHandle, {
3369
+ tableAtom
3370
+ }) : null,
3371
+ tag ? /* @__PURE__ */ jsxs9(Badge, {
3372
+ variant: "secondary",
3373
+ children: [
3374
+ gallery.tagIcon,
3375
+ renderCell(row, tag)
3376
+ ]
3377
+ }) : null
3440
3378
  ]
3379
+ }),
3380
+ /* @__PURE__ */ jsx17(CardTitle, {
3381
+ children: name ? renderCell(row, name) : row.id
3382
+ }),
3383
+ description ? /* @__PURE__ */ jsx17("div", {
3384
+ className: "text-muted-foreground line-clamp-3 text-sm",
3385
+ children: renderCell(row, description)
3386
+ }) : null,
3387
+ hasRowActionMenu(store) ? /* @__PURE__ */ jsx17("div", {
3388
+ className: "absolute top-4 right-4",
3389
+ onClick: (event) => event.stopPropagation(),
3390
+ children: /* @__PURE__ */ jsx17(DataTableRowActionMenu, {
3391
+ tableAtom
3392
+ })
3393
+ }) : null
3394
+ ]
3395
+ })
3396
+ });
3397
+ };
3398
+ var DataTableGallery = ({
3399
+ tableAtom
3400
+ }) => {
3401
+ const [store, setStore] = useTableAtom(tableAtom);
3402
+ const model = deriveModel(store);
3403
+ const fields = getActiveGrouping(store);
3404
+ const rows = fields.length ? model.sortedRows : model.pageRows;
3405
+ if (store.config.status.error) {
3406
+ return /* @__PURE__ */ jsx17("div", {
3407
+ className: "text-destructive rounded-lg border border-dashed p-10 text-center",
3408
+ children: store.config.status.error
3409
+ });
3410
+ }
3411
+ if (store.config.status.loading && !rows.length) {
3412
+ return /* @__PURE__ */ jsx17("div", {
3413
+ className: "rounded-lg border border-dashed p-10 text-center",
3414
+ children: /* @__PURE__ */ jsx17(Loading, {
3415
+ label: store.config.labels.loading
3416
+ })
3417
+ });
3418
+ }
3419
+ if (!rows.length) {
3420
+ return /* @__PURE__ */ jsx17("div", {
3421
+ className: "text-muted-foreground rounded-lg border border-dashed p-10 text-center",
3422
+ children: store.config.status.empty ?? store.config.labels.empty
3423
+ });
3424
+ }
3425
+ if (!fields.length) {
3426
+ return /* @__PURE__ */ jsx17("div", {
3427
+ className: "grid gap-3 sm:grid-cols-2 xl:grid-cols-3",
3428
+ children: rows.map((row) => /* @__PURE__ */ jsx17(RowIdContext.Provider, {
3429
+ value: row.id,
3430
+ children: /* @__PURE__ */ jsx17(GalleryCard, {
3431
+ tableAtom
3441
3432
  })
3442
- }),
3443
- /* @__PURE__ */ jsx17(DropdownMenuContent, {
3444
- align: "end",
3445
- className: "w-[160px]",
3446
- children: /* @__PURE__ */ jsxs8(DropdownMenuRadioGroup, {
3447
- value,
3448
- onValueChange: (nextValue) => {
3449
- const view = decodeDataTableView(nextValue);
3450
- if (Option2.isSome(view))
3451
- onChange(view.value);
3452
- },
3433
+ }, row.id))
3434
+ });
3435
+ }
3436
+ const renderSections = (sections) => sections.map((section) => {
3437
+ const collapsed = !!store.state.collapsedGroups[section.key];
3438
+ const targetKey = getGroupDropKey(section.field.id, section.groupId);
3439
+ return /* @__PURE__ */ jsxs9("section", {
3440
+ className: "data-[drop-target=true]:ring-primary space-y-3 rounded-lg transition-shadow data-[drop-target=true]:ring-2",
3441
+ "data-table-group": section.field.onMoveToGroup ? targetKey : undefined,
3442
+ children: [
3443
+ /* @__PURE__ */ jsxs9("div", {
3444
+ className: "flex items-center gap-2 rounded-lg border p-3",
3453
3445
  children: [
3454
- /* @__PURE__ */ jsxs8(DropdownMenuRadioItem, {
3455
- value: "table",
3446
+ /* @__PURE__ */ jsxs9("button", {
3447
+ "aria-expanded": !collapsed,
3448
+ className: "flex flex-1 items-center gap-2 text-left",
3449
+ onClick: () => changeState(setStore, (state) => ({
3450
+ ...state,
3451
+ collapsedGroups: {
3452
+ ...state.collapsedGroups,
3453
+ [section.key]: !collapsed
3454
+ }
3455
+ })),
3456
+ type: "button",
3456
3457
  children: [
3457
- /* @__PURE__ */ jsx17(Rows3, {}),
3458
- messages4.tableView
3458
+ collapsed ? /* @__PURE__ */ jsx17(ChevronRight2, {
3459
+ className: "size-4"
3460
+ }) : /* @__PURE__ */ jsx17(ChevronDown, {
3461
+ className: "size-4"
3462
+ }),
3463
+ /* @__PURE__ */ jsx17("span", {
3464
+ className: "flex-1",
3465
+ children: section.field.renderGroupLabel?.(section.groupId, section.rows.map((row) => row.data)) ?? section.groupId
3466
+ }),
3467
+ /* @__PURE__ */ jsx17(Badge, {
3468
+ variant: "secondary",
3469
+ children: section.rows.length
3470
+ })
3459
3471
  ]
3460
3472
  }),
3461
- /* @__PURE__ */ jsxs8(DropdownMenuRadioItem, {
3462
- value: "gallery",
3463
- children: [
3464
- /* @__PURE__ */ jsx17(LayoutGrid, {}),
3465
- messages4.galleryView
3466
- ]
3473
+ /* @__PURE__ */ jsx17(GroupActions, {
3474
+ actions: section.field.actions,
3475
+ groupId: section.groupId,
3476
+ title: section.field.actionsLabel ?? store.config.labels.actions
3467
3477
  })
3468
3478
  ]
3469
- })
3470
- })
3471
- ]
3479
+ }),
3480
+ !collapsed ? section.children.length ? renderSections(section.children) : section.rows.length ? /* @__PURE__ */ jsx17("div", {
3481
+ className: "grid gap-3 sm:grid-cols-2 xl:grid-cols-3",
3482
+ children: section.rows.map((row) => /* @__PURE__ */ jsx17(RowIdContext.Provider, {
3483
+ value: row.id,
3484
+ children: /* @__PURE__ */ jsx17(GalleryCard, {
3485
+ tableAtom
3486
+ })
3487
+ }, `${section.key}:${row.id}`))
3488
+ }) : /* @__PURE__ */ jsx17("div", {
3489
+ className: "text-muted-foreground rounded-lg border border-dashed p-8 text-center",
3490
+ children: section.field.renderEmptyGroup?.(section.groupId) ?? store.config.labels.empty
3491
+ }) : null
3492
+ ]
3493
+ }, section.key);
3472
3494
  });
3473
- }
3474
- function DataTableSortDropdown({
3475
- messages: messages4,
3476
- table
3477
- }) {
3478
- const sorting = table.state.sorting;
3479
- const sortableColumns = table.getAllColumns().filter((column) => column.getCanSort());
3480
- const columnLabels = getColumnLabels(table);
3481
- if (sortableColumns.length === 0) {
3495
+ return /* @__PURE__ */ jsx17("div", {
3496
+ className: "space-y-4",
3497
+ children: renderSections(groupDataTableRows(rows, fields))
3498
+ });
3499
+ };
3500
+ var DataTablePagination = ({
3501
+ tableAtom
3502
+ }) => {
3503
+ const [store, setStore] = useTableAtom(tableAtom);
3504
+ const model = deriveModel(store);
3505
+ const pagination = store.config.features.pagination ?? { mode: "client" };
3506
+ const clientGrouping = pagination !== false && pagination.mode === "client" && getActiveGrouping(store).length > 0;
3507
+ const paginationVisible = pagination !== false && !clientGrouping;
3508
+ const pageIndex = store.state.pagination.pageIndex;
3509
+ const maxPageIndex = model.pageCount - 1;
3510
+ useLayoutEffect(() => {
3511
+ if (paginationVisible && pageIndex > maxPageIndex) {
3512
+ changeState(setStore, (state) => ({
3513
+ ...state,
3514
+ pagination: { ...state.pagination, pageIndex: maxPageIndex }
3515
+ }));
3516
+ }
3517
+ }, [maxPageIndex, pageIndex, paginationVisible, setStore]);
3518
+ if (!paginationVisible)
3482
3519
  return null;
3520
+ const selected = model.rows.filter((row) => store.state.rowSelection[row.id]).length;
3521
+ const setPagination = (next) => changeState(setStore, (state) => ({ ...state, pagination: next }));
3522
+ return /* @__PURE__ */ jsx17("div", {
3523
+ className: "pt-4",
3524
+ children: /* @__PURE__ */ jsx17(Pagination, {
3525
+ messages: store.config.labels,
3526
+ onPageChange: (pageIndex2) => setPagination({ ...store.state.pagination, pageIndex: pageIndex2 }),
3527
+ onPageSizeChange: (pageSize) => setPagination({ pageIndex: 0, pageSize }),
3528
+ page: Math.min(store.state.pagination.pageIndex, model.pageCount - 1),
3529
+ pageCount: model.pageCount,
3530
+ pageSize: store.state.pagination.pageSize,
3531
+ pageSizes: pagination.pageSizes,
3532
+ selectedRows: selected,
3533
+ totalRows: model.totalRows
3534
+ })
3535
+ });
3536
+ };
3537
+ var DataTable = (props) => {
3538
+ const validatedConfig = resolveConfig(props);
3539
+ const atomRef = useRef2(null);
3540
+ if (!atomRef.current) {
3541
+ const initial = {
3542
+ rowData: props.rowData,
3543
+ columnDefs: props.columnDefs,
3544
+ config: validatedConfig,
3545
+ state: initialPublicState(props),
3546
+ controlledState: controlledStateFromProps(props.query, props.state)
3547
+ };
3548
+ atomRef.current = Atom.make({
3549
+ ...initial,
3550
+ model: buildDataTableModel(initial)
3551
+ });
3483
3552
  }
3484
- const activeSortColumn = sorting.length > 0 ? sorting[0] : null;
3485
- return /* @__PURE__ */ jsxs8(DropdownMenu, {
3553
+ const tableAtom = atomRef.current;
3554
+ const setStore = useAtomSet(tableAtom);
3555
+ useLayoutEffect(() => {
3556
+ setStore((store) => {
3557
+ const features = props.features ?? {};
3558
+ const selection = features.selection;
3559
+ const config = {
3560
+ getRowId: selection && selection.getRowId || props.getRowId || undefined,
3561
+ onQueryChange: props.onQueryChange,
3562
+ onStateChange: props.onStateChange,
3563
+ status: props.status ?? {},
3564
+ features,
3565
+ onRowClicked: props.onRowClicked,
3566
+ labels: dataTableMessages(props.messages)
3567
+ };
3568
+ const controlledState = controlledStateFromProps(props.query, props.state);
3569
+ const state = mergeDataTableState(store.state, controlledState);
3570
+ 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;
3571
+ const next = {
3572
+ ...store,
3573
+ rowData: props.rowData,
3574
+ columnDefs: props.columnDefs,
3575
+ config,
3576
+ controlledState,
3577
+ state
3578
+ };
3579
+ return modelChanged ? { ...next, model: buildDataTableModel(next) } : next;
3580
+ });
3581
+ }, [
3582
+ props.columnDefs,
3583
+ props.features,
3584
+ props.getRowId,
3585
+ props.messages,
3586
+ props.onRowClicked,
3587
+ props.onQueryChange,
3588
+ props.onStateChange,
3589
+ props.query,
3590
+ props.rowData,
3591
+ props.state,
3592
+ props.status,
3593
+ setStore
3594
+ ]);
3595
+ return /* @__PURE__ */ jsxs9("div", {
3596
+ className: "w-full max-w-full min-w-0 rounded-md",
3597
+ "data-table-root": "",
3486
3598
  children: [
3487
- /* @__PURE__ */ jsx17(DropdownMenuTrigger, {
3488
- render: /* @__PURE__ */ jsxs8(Button, {
3489
- "aria-label": messages4.sortBy,
3490
- className: "h-9",
3491
- size: "sm",
3492
- variant: "outline",
3493
- children: [
3494
- activeSortColumn ? activeSortColumn.desc ? /* @__PURE__ */ jsx17(ArrowDown, {}) : /* @__PURE__ */ jsx17(ArrowUp, {}) : /* @__PURE__ */ jsx17(ChevronsUpDown2, {}),
3495
- /* @__PURE__ */ jsx17("span", {
3496
- className: "hidden sm:inline",
3497
- children: messages4.sortBy
3498
- })
3499
- ]
3500
- })
3599
+ /* @__PURE__ */ jsx17(DataTableToolbar, {
3600
+ tableAtom
3501
3601
  }),
3502
- /* @__PURE__ */ jsx17(DropdownMenuContent, {
3503
- align: "end",
3504
- className: "w-[200px]",
3505
- children: /* @__PURE__ */ jsxs8(DropdownMenuGroup, {
3506
- children: [
3507
- /* @__PURE__ */ jsx17(DropdownMenuLabel, {
3508
- children: messages4.sortBy
3509
- }),
3510
- /* @__PURE__ */ jsx17(DropdownMenuSeparator, {}),
3511
- sortableColumns.map((column) => {
3512
- const sortState = sorting.find((s) => s.id === column.id);
3513
- const label = columnLabels.get(column.id) ?? column.id;
3514
- return /* @__PURE__ */ jsxs8(DropdownMenuSub, {
3515
- children: [
3516
- /* @__PURE__ */ jsxs8(DropdownMenuSubTrigger, {
3517
- inset: !!sortState,
3518
- children: [
3519
- sortState ? /* @__PURE__ */ jsx17("span", {
3520
- className: "pointer-events-none absolute left-3 flex size-4 items-center justify-center",
3521
- children: sortState.desc ? /* @__PURE__ */ jsx17(ArrowDown, {}) : /* @__PURE__ */ jsx17(ArrowUp, {})
3522
- }) : null,
3523
- label
3524
- ]
3525
- }),
3526
- /* @__PURE__ */ jsxs8(DropdownMenuSubContent, {
3527
- children: [
3528
- /* @__PURE__ */ jsxs8(DropdownMenuItem, {
3529
- onClick: () => column.toggleSorting(false),
3530
- children: [
3531
- /* @__PURE__ */ jsx17(ArrowUp, {}),
3532
- messages4.sortAsc
3533
- ]
3534
- }),
3535
- /* @__PURE__ */ jsxs8(DropdownMenuItem, {
3536
- onClick: () => column.toggleSorting(true),
3537
- children: [
3538
- /* @__PURE__ */ jsx17(ArrowDown, {}),
3539
- messages4.sortDesc
3540
- ]
3541
- }),
3542
- sortState && /* @__PURE__ */ jsxs8(Fragment, {
3543
- children: [
3544
- /* @__PURE__ */ jsx17(DropdownMenuSeparator, {}),
3545
- /* @__PURE__ */ jsx17(DropdownMenuItem, {
3546
- onClick: () => column.clearSorting(),
3547
- children: messages4.sortClear
3548
- })
3549
- ]
3550
- })
3551
- ]
3552
- })
3553
- ]
3554
- }, column.id);
3555
- })
3556
- ]
3557
- })
3602
+ /* @__PURE__ */ jsx17(DataTableContent, {
3603
+ tableAtom
3604
+ }),
3605
+ /* @__PURE__ */ jsx17(DataTablePagination, {
3606
+ tableAtom
3558
3607
  })
3559
3608
  ]
3560
3609
  });
3561
- }
3562
- function DataTableViewOptions({
3563
- messages: messages4,
3564
- table
3565
- }) {
3566
- const columnLabels = getColumnLabels(table);
3567
- const columns = table.getAllColumns().filter((column) => column.accessorFn !== undefined && column.getCanHide());
3568
- if (columns.length === 0) {
3569
- return null;
3610
+ };
3611
+ var DataTableContent = ({
3612
+ tableAtom
3613
+ }) => {
3614
+ const [store] = useTableAtom(tableAtom);
3615
+ if (store.config.features.gallery && store.state.view === "gallery") {
3616
+ return /* @__PURE__ */ jsx17(DataTableGallery, {
3617
+ tableAtom
3618
+ });
3570
3619
  }
3571
- return /* @__PURE__ */ jsxs8(DropdownMenu, {
3620
+ const model = deriveModel(store);
3621
+ const width = getDataTableWidth(model.visibleColumns, (store.config.features.selection ? 1 : 0) + (hasRowActionMenu(store) ? 1 : 0) + (canDragRows(store) ? 1 : 0));
3622
+ return /* @__PURE__ */ jsxs9(ScrollArea, {
3623
+ className: "max-w-full min-w-0",
3572
3624
  children: [
3573
- /* @__PURE__ */ jsx17(DropdownMenuTrigger, {
3574
- render: /* @__PURE__ */ jsxs8(Button, {
3575
- "aria-label": messages4.columns,
3576
- className: "h-9",
3577
- size: "sm",
3578
- variant: "outline",
3579
- children: [
3580
- /* @__PURE__ */ jsx17(Settings2, {}),
3581
- /* @__PURE__ */ jsx17("span", {
3582
- className: "hidden sm:inline",
3583
- children: messages4.columns
3584
- })
3585
- ]
3586
- })
3625
+ /* @__PURE__ */ jsxs9(Table, {
3626
+ className: "table-fixed",
3627
+ style: { width: `max(100%, ${width}px)` },
3628
+ children: [
3629
+ /* @__PURE__ */ jsx17(DataTableHeader, {
3630
+ tableAtom
3631
+ }),
3632
+ /* @__PURE__ */ jsx17(DataTableBody, {
3633
+ tableAtom
3634
+ })
3635
+ ]
3587
3636
  }),
3588
- /* @__PURE__ */ jsx17(DropdownMenuContent, {
3589
- align: "end",
3590
- className: "w-[180px]",
3591
- children: /* @__PURE__ */ jsxs8(DropdownMenuGroup, {
3592
- children: [
3593
- /* @__PURE__ */ jsx17(DropdownMenuLabel, {
3594
- children: messages4.columns
3595
- }),
3596
- /* @__PURE__ */ jsx17(DropdownMenuSeparator, {}),
3597
- columns.map((column) => /* @__PURE__ */ jsx17(DropdownMenuCheckboxItem, {
3598
- checked: column.getIsVisible(),
3599
- className: "capitalize",
3600
- onCheckedChange: (value) => column.toggleVisibility(!!value),
3601
- children: columnLabels.get(column.id) ?? column.id
3602
- }, column.id))
3603
- ]
3604
- })
3637
+ /* @__PURE__ */ jsx17(ScrollBar, {
3638
+ orientation: "horizontal"
3605
3639
  })
3606
3640
  ]
3607
3641
  });
3608
- }
3609
- function DataTablePagination({
3610
- messages: messages4,
3611
- pageSizes = [10, 20, 30, 40, 50],
3612
- rowCount,
3613
- table
3614
- }) {
3615
- const labels2 = dataTableMessages(messages4);
3616
- const selectedRows = table.getFilteredSelectedRowModel().rows.length;
3617
- const filteredRows = table.getFilteredRowModel().rows.length;
3618
- const totalRows = rowCount ?? filteredRows;
3619
- return /* @__PURE__ */ jsx17(Pagination, {
3620
- messages: {
3621
- pageSize: labels2.pageSize,
3622
- results: labels2.results,
3623
- selectedOf: labels2.selectedOf,
3624
- pageOf: labels2.pageOf,
3625
- goToFirstPage: labels2.goToFirstPage,
3626
- goToPreviousPage: labels2.goToPreviousPage,
3627
- goToNextPage: labels2.goToNextPage,
3628
- goToLastPage: labels2.goToLastPage
3629
- },
3630
- onPageChange: (page) => table.setPageIndex(page),
3631
- onPageSizeChange: (pageSize) => table.setPageSize(pageSize),
3632
- page: table.state.pagination.pageIndex,
3633
- pageCount: table.getPageCount(),
3634
- pageSize: table.state.pagination.pageSize,
3635
- pageSizes,
3636
- selectedRows,
3637
- totalRows
3638
- });
3639
- }
3640
- function DataTableRelationshipCell({
3642
+ };
3643
+ var DataTableRelationshipCell = ({
3641
3644
  emptyLabel,
3642
3645
  manageLabel,
3643
3646
  onAdd,
3644
3647
  onRemove,
3645
3648
  options,
3646
3649
  value
3647
- }) {
3648
- const [selectedOptions, setSelectedOptions] = useState(() => [...value]);
3649
- const selectedValues = new Set(selectedOptions.map(({ value: value2 }) => value2));
3650
- const orderedOptions = [...options].sort((a, b) => Number(selectedValues.has(b.value)) - Number(selectedValues.has(a.value)));
3651
- useEffect2(() => {
3652
- setSelectedOptions([...value]);
3653
- }, [value]);
3650
+ }) => {
3651
+ const [selected, setSelected] = useState([...value]);
3652
+ useLayoutEffect(() => setSelected([...value]), [value]);
3653
+ const selectedValues = new Set(selected.map((item) => item.value));
3654
3654
  return /* @__PURE__ */ jsx17(VirtualizedCombobox, {
3655
3655
  ariaLabel: manageLabel,
3656
3656
  emptyLabel,
3657
- items: orderedOptions,
3657
+ items: [...options].sort((left, right) => Number(selectedValues.has(right.value)) - Number(selectedValues.has(left.value))),
3658
3658
  messages: { search: manageLabel },
3659
3659
  multiple: true,
3660
- onValueChange: (nextOptions) => {
3661
- const nextValues = new Set(nextOptions.map(({ value: value2 }) => value2));
3662
- for (const option of selectedOptions) {
3663
- if (!nextValues.has(option.value))
3664
- onRemove?.(option.value);
3665
- }
3666
- for (const option of nextOptions) {
3667
- if (!selectedValues.has(option.value))
3668
- onAdd?.(option.value);
3669
- }
3670
- setSelectedOptions(nextOptions);
3660
+ onValueChange: (next) => {
3661
+ const nextValues = new Set(next.map((item) => item.value));
3662
+ selected.forEach((item) => !nextValues.has(item.value) && onRemove?.(item.value));
3663
+ next.forEach((item) => !selectedValues.has(item.value) && onAdd?.(item.value));
3664
+ setSelected(next);
3671
3665
  },
3672
3666
  placeholder: emptyLabel,
3673
- trigger: /* @__PURE__ */ jsxs8(Button, {
3674
- "aria-label": manageLabel,
3675
- className: "h-full min-h-16 w-full min-w-0 justify-between gap-2 overflow-hidden rounded-none px-2 py-2 text-left font-normal",
3676
- "data-slot": "relationship-cell",
3677
- type: "button",
3667
+ trigger: /* @__PURE__ */ jsxs9(Button, {
3668
+ className: "h-full min-h-16 w-full justify-between rounded-none",
3678
3669
  variant: "ghost",
3679
3670
  children: [
3680
3671
  /* @__PURE__ */ jsx17(DataTableListSummary, {
3681
3672
  emptyLabel,
3682
3673
  expandable: false,
3683
- items: selectedOptions,
3684
- variant: selectedOptions.some(({ icon }) => icon) ? "icon" : "text"
3674
+ items: selected,
3675
+ variant: selected.some((item) => item.icon) ? "icon" : "text"
3685
3676
  }),
3686
- /* @__PURE__ */ jsx17(ChevronDown, {
3687
- className: "text-muted-foreground size-4 shrink-0"
3688
- })
3677
+ /* @__PURE__ */ jsx17(ChevronDown, {})
3689
3678
  ]
3690
3679
  }),
3691
- value: selectedOptions
3680
+ value: selected
3692
3681
  });
3693
- }
3694
- function DataTableListSummary({
3682
+ };
3683
+ var DataTableListSummary = ({
3695
3684
  emptyLabel,
3696
3685
  expandable = true,
3697
3686
  items,
@@ -3699,52 +3688,38 @@ function DataTableListSummary({
3699
3688
  totalCount = items.length,
3700
3689
  variant = "text",
3701
3690
  visibleCount = 3
3702
- }) {
3691
+ }) => {
3703
3692
  const labels2 = dataTableMessages();
3704
- const normalizedItems = items.map((item) => Schema2.is(Schema2.String)(item) ? { label: item } : item);
3705
- const visibleItems = normalizedItems.slice(0, visibleCount);
3706
- const visibleLabels = visibleItems.map(({ label }) => label).join(", ");
3707
- const remaining = Math.max(totalCount - visibleItems.length, 0);
3708
- const remainingLabel = overflowLabel?.(remaining) ?? labels2.listOthers(remaining);
3709
- const expandedItems = /* @__PURE__ */ jsx17(PopoverContent, {
3710
- align: "start",
3711
- className: "max-h-72 w-72 overflow-y-auto p-2",
3712
- onClick: (event) => event.stopPropagation(),
3713
- children: /* @__PURE__ */ jsx17("ul", {
3714
- className: "grid gap-1",
3715
- children: normalizedItems.map((item, index) => /* @__PURE__ */ jsxs8("li", {
3716
- className: "flex items-center gap-2 rounded-sm px-2 py-1.5 break-words",
3717
- children: [
3718
- item.icon ? /* @__PURE__ */ jsx17("span", {
3719
- className: "bg-muted flex size-6 shrink-0 items-center justify-center overflow-hidden rounded-full text-[9px] font-semibold",
3720
- children: item.icon
3721
- }) : null,
3722
- /* @__PURE__ */ jsx17("span", {
3723
- className: "min-w-0",
3724
- children: item.label
3725
- })
3726
- ]
3727
- }, item.value ?? `${item.label}-${index}`))
3728
- })
3729
- });
3730
- if (normalizedItems.length === 0) {
3693
+ const normalized = items.map((item) => Schema2.is(Schema2.String)(item) ? { label: item } : item);
3694
+ if (!normalized.length)
3731
3695
  return /* @__PURE__ */ jsx17("span", {
3732
- className: "text-muted-foreground text-sm",
3696
+ className: "text-muted-foreground",
3733
3697
  children: emptyLabel
3734
3698
  });
3735
- }
3699
+ const visible = normalized.slice(0, visibleCount);
3700
+ const remaining = Math.max(totalCount - visible.length, 0);
3701
+ const details = /* @__PURE__ */ jsx17(PopoverContent, {
3702
+ align: "start",
3703
+ className: "max-h-72 w-72 overflow-y-auto p-2",
3704
+ children: normalized.map((item, index) => /* @__PURE__ */ jsxs9("div", {
3705
+ className: "flex items-center gap-2 p-2",
3706
+ children: [
3707
+ item.icon,
3708
+ item.label
3709
+ ]
3710
+ }, item.value ?? `${item.label}-${index}`))
3711
+ });
3736
3712
  if (variant === "icon") {
3737
3713
  return /* @__PURE__ */ jsx17(TooltipProvider, {
3738
- children: /* @__PURE__ */ jsxs8("span", {
3739
- className: "flex min-w-0 items-center pl-2",
3714
+ children: /* @__PURE__ */ jsxs9("span", {
3715
+ className: "flex items-center",
3740
3716
  children: [
3741
- visibleItems.map((item, index) => /* @__PURE__ */ jsxs8(Tooltip, {
3717
+ visible.map((item) => /* @__PURE__ */ jsxs9(Tooltip, {
3742
3718
  children: [
3743
3719
  /* @__PURE__ */ jsx17(TooltipTrigger, {
3744
3720
  render: /* @__PURE__ */ jsx17("span", {
3745
3721
  "aria-label": item.label,
3746
- className: "bg-muted border-background relative flex size-8 shrink-0 items-center justify-center overflow-hidden rounded-full border-2 text-[10px] font-semibold",
3747
- style: { marginLeft: index ? -8 : 0 },
3722
+ className: "bg-muted -ml-1 flex size-8 items-center justify-center rounded-full",
3748
3723
  children: item.icon ?? item.label.slice(0, 2).toUpperCase()
3749
3724
  })
3750
3725
  }),
@@ -3753,14 +3728,12 @@ function DataTableListSummary({
3753
3728
  })
3754
3729
  ]
3755
3730
  }, item.value ?? item.label)),
3756
- remaining ? expandable ? /* @__PURE__ */ jsxs8(Popover, {
3731
+ remaining && expandable ? /* @__PURE__ */ jsxs9(Popover, {
3757
3732
  children: [
3758
3733
  /* @__PURE__ */ jsx17(PopoverTrigger, {
3759
- render: /* @__PURE__ */ jsxs8("button", {
3734
+ render: /* @__PURE__ */ jsxs9("button", {
3760
3735
  "aria-label": labels2.listOthers(remaining),
3761
- className: "bg-muted border-background relative -ml-2 flex size-8 shrink-0 items-center justify-center rounded-full border-2 text-[10px] font-semibold tabular-nums",
3762
- onClick: (event) => event.stopPropagation(),
3763
- onPointerDown: (event) => event.stopPropagation(),
3736
+ className: "bg-muted -ml-1 flex size-8 items-center justify-center rounded-full",
3764
3737
  type: "button",
3765
3738
  children: [
3766
3739
  "+",
@@ -3768,10 +3741,10 @@ function DataTableListSummary({
3768
3741
  ]
3769
3742
  })
3770
3743
  }),
3771
- expandedItems
3744
+ details
3772
3745
  ]
3773
- }) : /* @__PURE__ */ jsxs8("span", {
3774
- className: "bg-muted border-background relative -ml-2 flex size-8 shrink-0 items-center justify-center rounded-full border-2 text-[10px] font-semibold tabular-nums",
3746
+ }) : remaining ? /* @__PURE__ */ jsxs9("span", {
3747
+ className: "bg-muted -ml-1 flex size-8 items-center justify-center rounded-full",
3775
3748
  children: [
3776
3749
  "+",
3777
3750
  remaining
@@ -3781,135 +3754,44 @@ function DataTableListSummary({
3781
3754
  })
3782
3755
  });
3783
3756
  }
3784
- return remaining > 0 ? /* @__PURE__ */ jsxs8("span", {
3785
- className: "block min-w-0 text-sm whitespace-normal",
3786
- "data-slot": "list-summary",
3757
+ const summary = /* @__PURE__ */ jsxs9(Fragment, {
3787
3758
  children: [
3788
- /* @__PURE__ */ jsx17("span", {
3789
- children: visibleLabels
3790
- }),
3791
- " ",
3792
- /* @__PURE__ */ jsx17("span", {
3793
- className: "inline-block whitespace-nowrap",
3794
- children: expandable ? /* @__PURE__ */ jsxs8(Popover, {
3795
- children: [
3796
- /* @__PURE__ */ jsx17(PopoverTrigger, {
3797
- render: /* @__PURE__ */ jsx17("button", {
3798
- className: "text-muted-foreground hover:text-foreground underline decoration-dotted underline-offset-2",
3799
- onClick: (event) => event.stopPropagation(),
3800
- onPointerDown: (event) => event.stopPropagation(),
3801
- type: "button",
3802
- children: remainingLabel
3803
- })
3804
- }),
3805
- expandedItems
3806
- ]
3807
- }) : remainingLabel
3808
- })
3759
+ visible.map((item) => item.label).join(", "),
3760
+ remaining ? ` ${overflowLabel?.(remaining) ?? labels2.listOthers(remaining)}` : ""
3809
3761
  ]
3810
- }) : /* @__PURE__ */ jsx17("span", {
3811
- className: "block min-w-0 text-sm",
3812
- "data-slot": "list-summary",
3813
- children: visibleLabels
3814
3762
  });
3815
- }
3816
- function DataTableColumnHeader({
3817
- column,
3818
- messages: messages4,
3819
- title,
3820
- className
3821
- }) {
3822
- const labels2 = dataTableMessages(messages4);
3823
- const sortDirection = column.getIsSorted();
3824
- if (!column.getCanSort()) {
3825
- return /* @__PURE__ */ jsx17("div", {
3826
- className: cn("flex h-12 items-center truncate px-2 text-sm", className),
3827
- children: title
3828
- });
3829
- }
3830
- return /* @__PURE__ */ jsx17("div", {
3831
- className: cn("flex h-12 items-center", className),
3832
- children: /* @__PURE__ */ jsxs8(DropdownMenu, {
3833
- children: [
3834
- /* @__PURE__ */ jsx17(DropdownMenuTrigger, {
3835
- render: /* @__PURE__ */ jsxs8(Button, {
3836
- variant: "ghost",
3837
- size: "sm",
3838
- className: "data-[state=open]:bg-accent h-8 max-w-full justify-start px-2",
3839
- children: [
3840
- /* @__PURE__ */ jsx17("span", {
3841
- className: "min-w-0 truncate text-sm",
3842
- children: title
3843
- }),
3844
- sortDirection === "desc" ? /* @__PURE__ */ jsx17(ArrowDown, {}) : sortDirection === "asc" ? /* @__PURE__ */ jsx17(ArrowUp, {}) : /* @__PURE__ */ jsx17(ChevronsUpDown2, {})
3845
- ]
3846
- })
3847
- }),
3848
- /* @__PURE__ */ jsx17(DropdownMenuContent, {
3849
- align: "start",
3850
- className: "max-w-56",
3851
- children: /* @__PURE__ */ jsxs8(DropdownMenuGroup, {
3852
- children: [
3853
- /* @__PURE__ */ jsxs8(DropdownMenuItem, {
3854
- onClick: () => column.toggleSorting(false),
3855
- children: [
3856
- /* @__PURE__ */ jsx17(ArrowUp, {
3857
- className: "text-muted-foreground/70 h-3.5 w-3.5"
3858
- }),
3859
- labels2.sortAsc
3860
- ]
3861
- }),
3862
- /* @__PURE__ */ jsxs8(DropdownMenuItem, {
3863
- onClick: () => column.toggleSorting(true),
3864
- children: [
3865
- /* @__PURE__ */ jsx17(ArrowDown, {
3866
- className: "text-muted-foreground/70 h-3.5 w-3.5"
3867
- }),
3868
- labels2.sortDesc
3869
- ]
3870
- }),
3871
- sortDirection ? /* @__PURE__ */ jsxs8(DropdownMenuItem, {
3872
- onClick: () => column.clearSorting(),
3873
- children: [
3874
- /* @__PURE__ */ jsx17(X2, {
3875
- className: "text-muted-foreground/70 h-3.5 w-3.5"
3876
- }),
3877
- labels2.sortClear
3878
- ]
3879
- }) : null,
3880
- /* @__PURE__ */ jsx17(DropdownMenuSeparator, {}),
3881
- /* @__PURE__ */ jsxs8(DropdownMenuItem, {
3882
- onClick: () => column.toggleVisibility(false),
3883
- children: [
3884
- /* @__PURE__ */ jsx17(EyeOff, {
3885
- className: "text-muted-foreground/70 h-3.5 w-3.5"
3886
- }),
3887
- labels2.sortHide
3888
- ]
3889
- })
3890
- ]
3891
- })
3763
+ return remaining && expandable ? /* @__PURE__ */ jsxs9(Popover, {
3764
+ children: [
3765
+ /* @__PURE__ */ jsx17(PopoverTrigger, {
3766
+ render: /* @__PURE__ */ jsx17("button", {
3767
+ className: "text-left text-sm",
3768
+ type: "button",
3769
+ children: summary
3892
3770
  })
3893
- ]
3894
- })
3771
+ }),
3772
+ details
3773
+ ]
3774
+ }) : /* @__PURE__ */ jsx17("span", {
3775
+ className: "text-sm",
3776
+ children: summary
3895
3777
  });
3896
- }
3778
+ };
3897
3779
  export {
3898
- useDataTableHeaderContext,
3899
- useDataTableContext,
3900
- useDataTableCellContext,
3901
- useDataTable,
3902
- getHeaderNames,
3903
- downloadJson,
3904
- downloadCsv,
3905
- dataTableMessages,
3906
- createDataTableColumnHelper,
3907
- TableSearchSchemaStandard,
3908
- TableSearchSchema,
3909
- DataTableRowActions,
3910
- DataTableRelationshipCell,
3911
- DataTablePagination,
3780
+ DataTable,
3912
3781
  DataTableListSummary,
3913
- DataTableColumnHeader,
3914
- DataTable
3782
+ DataTableRelationshipCell,
3783
+ DataTableRowActions,
3784
+ buildDataTableRows,
3785
+ dataTableMessages,
3786
+ downloadCsv,
3787
+ downloadJson,
3788
+ filterDataTableRows,
3789
+ getDataTableSelectableRows,
3790
+ getDataTableWidth,
3791
+ groupDataTableRows,
3792
+ mergeDataTableState,
3793
+ normalizeDataTableColumns,
3794
+ paginateDataTableRows,
3795
+ reorderDataTableRows,
3796
+ sortDataTableRows
3915
3797
  };