@avenue-ticketing/ui 0.4.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (73) hide show
  1. package/dist/react/avatar.d.ts +42 -0
  2. package/dist/react/avatar.js +159 -0
  3. package/dist/react/avatar.js.map +1 -0
  4. package/dist/react/badge.d.ts +12 -0
  5. package/dist/react/badge.js +35 -1
  6. package/dist/react/badge.js.map +1 -1
  7. package/dist/react/button.d.ts +1 -1
  8. package/dist/react/button.js +3 -3
  9. package/dist/react/button.js.map +1 -1
  10. package/dist/react/calendar.d.ts +13 -0
  11. package/dist/react/calendar.js +4639 -0
  12. package/dist/react/calendar.js.map +1 -0
  13. package/dist/react/card.d.ts +11 -0
  14. package/dist/react/card.js +113 -0
  15. package/dist/react/card.js.map +1 -0
  16. package/dist/react/checkbox.d.ts +11 -0
  17. package/dist/react/checkbox.js +131 -0
  18. package/dist/react/checkbox.js.map +1 -0
  19. package/dist/react/datetime-picker.d.ts +21 -0
  20. package/dist/react/datetime-picker.js +6124 -0
  21. package/dist/react/datetime-picker.js.map +1 -0
  22. package/dist/react/dialog.js +1 -1
  23. package/dist/react/dialog.js.map +1 -1
  24. package/dist/react/dropdown.d.ts +26 -9
  25. package/dist/react/dropdown.js +194 -96
  26. package/dist/react/dropdown.js.map +1 -1
  27. package/dist/react/input.d.ts +7 -0
  28. package/dist/react/input.js +15 -2
  29. package/dist/react/input.js.map +1 -1
  30. package/dist/react/pagination.d.ts +28 -0
  31. package/dist/react/pagination.js +262 -0
  32. package/dist/react/pagination.js.map +1 -0
  33. package/dist/react/popover.d.ts +76 -0
  34. package/dist/react/popover.js +564 -0
  35. package/dist/react/popover.js.map +1 -0
  36. package/dist/react/scroll-header.js +13 -1
  37. package/dist/react/scroll-header.js.map +1 -1
  38. package/dist/react/scroll-wheel.d.ts +45 -0
  39. package/dist/react/scroll-wheel.js +557 -0
  40. package/dist/react/scroll-wheel.js.map +1 -0
  41. package/dist/react/select.d.ts +62 -0
  42. package/dist/react/select.js +889 -0
  43. package/dist/react/select.js.map +1 -0
  44. package/dist/react/sheet.js +1 -1
  45. package/dist/react/sheet.js.map +1 -1
  46. package/dist/react/switch.d.ts +38 -0
  47. package/dist/react/switch.js +117 -0
  48. package/dist/react/switch.js.map +1 -0
  49. package/dist/react/table-pagination.d.ts +15 -0
  50. package/dist/react/table-pagination.js +1153 -0
  51. package/dist/react/table-pagination.js.map +1 -0
  52. package/dist/react/table-view/column-menu.d.ts +15 -0
  53. package/dist/react/table-view/column-menu.js +918 -0
  54. package/dist/react/table-view/column-menu.js.map +1 -0
  55. package/dist/react/table-view/index.d.ts +70 -0
  56. package/dist/react/table-view/index.js +2155 -0
  57. package/dist/react/table-view/index.js.map +1 -0
  58. package/dist/react/table.d.ts +86 -0
  59. package/dist/react/table.js +414 -0
  60. package/dist/react/table.js.map +1 -0
  61. package/dist/react/tabs.d.ts +9 -3
  62. package/dist/react/tabs.js +204 -48
  63. package/dist/react/tabs.js.map +1 -1
  64. package/dist/react/textarea.d.ts +6 -0
  65. package/dist/react/textarea.js +33 -0
  66. package/dist/react/textarea.js.map +1 -0
  67. package/dist/react/time-picker.d.ts +22 -0
  68. package/dist/react/time-picker.js +856 -0
  69. package/dist/react/time-picker.js.map +1 -0
  70. package/dist/react/tooltip.d.ts +45 -0
  71. package/dist/react/tooltip.js +540 -0
  72. package/dist/react/tooltip.js.map +1 -0
  73. package/package.json +1 -1
@@ -0,0 +1,2155 @@
1
+ import * as React5 from 'react';
2
+ import React5__default, { useState, useCallback, forwardRef, useImperativeHandle, memo, useRef, useLayoutEffect, useMemo, useEffect, startTransition } from 'react';
3
+ import { clsx } from 'clsx';
4
+ import { twMerge } from 'tailwind-merge';
5
+ import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
6
+ import { X, MoreVertical, ArrowLeft, ArrowRight, ChevronUp, ChevronDown, Pin, PinOff, EyeOff, GripVertical, ArrowDown, ArrowUp } from 'lucide-react';
7
+ import { createPortal } from 'react-dom';
8
+
9
+ // src/react/table-view/meta.ts
10
+ function getTableViewColumnDisableReorder(column) {
11
+ return Boolean(column.columnDef.meta?.tableView?.disableColumnReorder);
12
+ }
13
+ function flexRender(Comp, props) {
14
+ return !Comp ? null : isReactComponent(Comp) ? /* @__PURE__ */ React5.createElement(Comp, props) : Comp;
15
+ }
16
+ function isReactComponent(component) {
17
+ return isClassComponent(component) || typeof component === "function" || isExoticComponent(component);
18
+ }
19
+ function isClassComponent(component) {
20
+ return typeof component === "function" && (() => {
21
+ const proto = Object.getPrototypeOf(component);
22
+ return proto.prototype && proto.prototype.isReactComponent;
23
+ })();
24
+ }
25
+ function isExoticComponent(component) {
26
+ return typeof component === "object" && typeof component.$$typeof === "symbol" && ["react.memo", "react.forward_ref"].includes(component.$$typeof.description);
27
+ }
28
+ function cn(...inputs) {
29
+ return twMerge(clsx(inputs));
30
+ }
31
+ var CHECKBOX_TICK_DELAY_MS = 60;
32
+ var CHECKBOX_TICK_DRAW_MS = 100;
33
+ function CheckboxAnimatedCheckMark() {
34
+ const lineRef = useRef(null);
35
+ useLayoutEffect(() => {
36
+ const poly = lineRef.current;
37
+ if (!poly || typeof poly.getTotalLength !== "function") return;
38
+ const len = poly.getTotalLength();
39
+ if (len <= 0) return;
40
+ poly.style.strokeDasharray = `${len}`;
41
+ poly.style.strokeDashoffset = `${len}`;
42
+ if (typeof poly.animate !== "function") {
43
+ poly.style.strokeDashoffset = "0";
44
+ return;
45
+ }
46
+ const anim = poly.animate(
47
+ [{ strokeDashoffset: len }, { strokeDashoffset: 0 }],
48
+ {
49
+ duration: CHECKBOX_TICK_DRAW_MS,
50
+ delay: CHECKBOX_TICK_DELAY_MS,
51
+ easing: "cubic-bezier(0.45, 0, 0.2, 1)",
52
+ fill: "forwards"
53
+ }
54
+ );
55
+ return () => anim.cancel();
56
+ }, []);
57
+ return /* @__PURE__ */ jsx(
58
+ "svg",
59
+ {
60
+ className: "size-4 shrink-0 overflow-visible",
61
+ viewBox: "0 0 24 24",
62
+ "aria-hidden": true,
63
+ children: /* @__PURE__ */ jsx(
64
+ "polyline",
65
+ {
66
+ ref: lineRef,
67
+ points: "4 12 9 17 20 6",
68
+ fill: "none",
69
+ stroke: "currentColor",
70
+ strokeWidth: "3",
71
+ strokeLinecap: "round",
72
+ strokeLinejoin: "round"
73
+ }
74
+ )
75
+ }
76
+ );
77
+ }
78
+ var Checkbox = React5.forwardRef(
79
+ ({
80
+ checked: checkedProp,
81
+ defaultChecked = false,
82
+ onCheckedChange,
83
+ indeterminate = false,
84
+ disabled = false,
85
+ className,
86
+ onClick,
87
+ ...rest
88
+ }, ref) => {
89
+ const isControlled = checkedProp !== void 0;
90
+ const [uncontrolledChecked, setUncontrolledChecked] = useState(
91
+ defaultChecked
92
+ );
93
+ const checked = isControlled ? checkedProp : uncontrolledChecked;
94
+ const ariaChecked = indeterminate ? "mixed" : checked ? true : false;
95
+ return /* @__PURE__ */ jsx(
96
+ "button",
97
+ {
98
+ ref,
99
+ type: "button",
100
+ role: "checkbox",
101
+ "data-slot": "checkbox",
102
+ "data-state": indeterminate ? "indeterminate" : checked ? "checked" : "unchecked",
103
+ disabled,
104
+ "aria-checked": ariaChecked,
105
+ className: cn(
106
+ "ring-offset-background focus-visible:ring-primary/40 inline-flex shrink-0 items-center justify-center rounded-md border border-transparent p-0 outline-none select-none",
107
+ "focus-visible:ring-2 focus-visible:ring-offset-2",
108
+ "disabled:cursor-not-allowed",
109
+ className
110
+ ),
111
+ onClick: (e) => {
112
+ onClick?.(e);
113
+ if (e.defaultPrevented) return;
114
+ if (disabled) return;
115
+ if (isControlled) {
116
+ onCheckedChange?.(!checked);
117
+ return;
118
+ }
119
+ setUncontrolledChecked((prev) => {
120
+ const next = !prev;
121
+ onCheckedChange?.(next);
122
+ return next;
123
+ });
124
+ },
125
+ ...rest,
126
+ children: /* @__PURE__ */ jsx("span", { className: "pointer-events-none", children: /* @__PURE__ */ jsx(
127
+ "span",
128
+ {
129
+ "aria-hidden": true,
130
+ className: cn(
131
+ "flex size-5 shrink-0 items-center justify-center rounded-[4px] border",
132
+ !disabled && (indeterminate ? "border-primary bg-primary text-background" : checked ? "border-primary bg-primary text-background" : "border-primary/20 bg-background"),
133
+ disabled && (indeterminate ? "border-primary/40 bg-primary/45 text-primary-foreground" : checked ? "border-primary/40 bg-primary/45 text-primary-foreground" : "border-primary/10 bg-muted/25")
134
+ ),
135
+ children: indeterminate ? /* @__PURE__ */ jsx(
136
+ "span",
137
+ {
138
+ className: "size-2.5 shrink-0 rounded-[2px] border border-primary/20 bg-background",
139
+ "aria-hidden": true
140
+ }
141
+ ) : checked ? /* @__PURE__ */ jsx(CheckboxAnimatedCheckMark, {}) : null
142
+ }
143
+ ) })
144
+ }
145
+ );
146
+ }
147
+ );
148
+ Checkbox.displayName = "Checkbox";
149
+ var sizeClass = {
150
+ xs: "h-8 min-h-8 gap-2 px-4 text-sm has-[>svg]:px-3 [&_svg:not([class*='size-'])]:size-3",
151
+ default: "h-10 min-h-10 gap-2 px-5 text-sm has-[>svg]:px-4 [&_svg:not([class*='size-'])]:size-4",
152
+ lg: "h-11 min-h-11 gap-2 px-6 text-base has-[>svg]:px-5 [&_svg:not([class*='size-'])]:size-5"
153
+ };
154
+ var iconOnlySizeClass = {
155
+ xs: "size-8 min-h-8 min-w-8 gap-0 p-0 [&_svg:not([class*='size-'])]:size-3",
156
+ default: "size-10 min-h-10 min-w-10 gap-0 p-0 [&_svg:not([class*='size-'])]:size-4",
157
+ lg: "size-11 min-h-11 min-w-11 gap-0 p-0 [&_svg:not([class*='size-'])]:size-5"
158
+ };
159
+ var roundedClass = {
160
+ full: "rounded-full",
161
+ lg: "rounded-lg",
162
+ md: "rounded-md"
163
+ };
164
+ var variantClass = {
165
+ primary: "bg-primary text-background border border-transparent hover:bg-primary/90 active:bg-primary/85",
166
+ secondary: "bg-background text-primary border border-primary/10 hover:bg-primary/5",
167
+ destructive: "bg-background text-red-500 border border-red-500/25 hover:bg-red-500/5",
168
+ success: "bg-background text-green-500 border border-green-500/25 hover:bg-green-500/5"
169
+ };
170
+ var Button = React5.forwardRef(
171
+ ({
172
+ className,
173
+ type = "button",
174
+ variant = "secondary",
175
+ rounded: roundedProp,
176
+ size = "default",
177
+ iconOnly = false,
178
+ disabled,
179
+ ...props
180
+ }, ref) => {
181
+ const rounded = roundedProp ?? (iconOnly ? "md" : "full");
182
+ return /* @__PURE__ */ jsx(
183
+ "button",
184
+ {
185
+ type,
186
+ disabled,
187
+ "data-slot": "button",
188
+ "data-icon-only": iconOnly ? "" : void 0,
189
+ className: cn(
190
+ "inline-flex shrink-0 cursor-pointer items-center justify-center whitespace-nowrap outline-none scale-100 transition-[color,background-color,box-shadow,transform] duration-150 ease-out active:scale-[0.98] active:duration-100 active:ease-linear [&_svg]:pointer-events-none [&_svg]:shrink-0",
191
+ "disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50",
192
+ "focus-visible:border-ring font-medium lg:tracking-wide focus-visible:ring-ring/50 focus-visible:ring-[3px]",
193
+ iconOnly ? iconOnlySizeClass[size] : sizeClass[size],
194
+ roundedClass[rounded],
195
+ variantClass[variant],
196
+ className
197
+ ),
198
+ ref,
199
+ ...props
200
+ }
201
+ );
202
+ }
203
+ );
204
+ Button.displayName = "Button";
205
+ var DROPDOWN_PANEL_OPEN_EASING = "cubic-bezier(0,0.55,0.45,1)";
206
+ var DROPDOWN_PANEL_CLOSE_EASING = "cubic-bezier(0.55,0,1,0.45)";
207
+ var DROPDOWN_MENU_MIN_WIDTH_PX = 192;
208
+ var DROPDOWN_MOBILE_SHEET_MAX_PX = 1024;
209
+ var DROPDOWN_MOBILE_SHEET_MOTION_MS = 175;
210
+ var DROPDOWN_MOBILE_SHEET_ENTRY_EASING = "cubic-bezier(0.85, 0, 0.15, 1)";
211
+ var DROPDOWN_MOBILE_SHEET_EXIT_EASING = "cubic-bezier(0.85, 0, 1, 0.15)";
212
+ var DROPDOWN_MOBILE_SHEET_SLIDE_ENTRANCE_OFFSET_DEFAULT_PX = 120;
213
+ function resolveDropdownMobileSheet(mobileOptions) {
214
+ return {
215
+ sheet: mobileOptions?.sheet ?? true,
216
+ title: mobileOptions?.title,
217
+ sheetExtraClassName: mobileOptions?.className,
218
+ contentClassName: mobileOptions?.contentClassName
219
+ };
220
+ }
221
+ var DROPDOWN_SUB_CONTENT_ATTR = "data-dropdown-sub-content";
222
+ var DROPDOWN_SHEET_MENU_TEXT = "max-[1024px]:text-base";
223
+ var DROPDOWN_SHEET_MENU_SHORTCUT = "max-[1024px]:text-sm";
224
+ var DROPDOWN_CONTENT_ORIGIN = {
225
+ bottom: "top center",
226
+ top: "bottom center",
227
+ left: "right center",
228
+ right: "left center"
229
+ };
230
+ var DROPDOWN_CONTENT_HIDDEN = {
231
+ bottom: "translateY(-4px) scale(0.97)",
232
+ top: "translateY(4px) scale(0.97)",
233
+ left: "translateX(4px) scale(0.97)",
234
+ right: "translateX(-4px) scale(0.97)"
235
+ };
236
+ function computePos(trigger, menu, side, align, offset, pad) {
237
+ const tr = trigger.getBoundingClientRect();
238
+ const mr = menu.getBoundingClientRect();
239
+ const vw = window.innerWidth;
240
+ const vh = window.innerHeight;
241
+ const sx = window.scrollX;
242
+ const sy = window.scrollY;
243
+ let top = 0;
244
+ let left = 0;
245
+ let effectiveSide = side;
246
+ const calc = (s) => {
247
+ switch (s) {
248
+ case "bottom":
249
+ top = tr.bottom + sy + offset;
250
+ if (align === "start") left = tr.left + sx;
251
+ else if (align === "end") left = tr.right + sx - mr.width;
252
+ else left = tr.left + sx + tr.width / 2 - mr.width / 2;
253
+ break;
254
+ case "top":
255
+ top = tr.top + sy - mr.height - offset;
256
+ if (align === "start") left = tr.left + sx;
257
+ else if (align === "end") left = tr.right + sx - mr.width;
258
+ else left = tr.left + sx + tr.width / 2 - mr.width / 2;
259
+ break;
260
+ case "right":
261
+ left = tr.right + sx + offset;
262
+ if (align === "start") top = tr.top + sy;
263
+ else if (align === "end") top = tr.bottom + sy - mr.height;
264
+ else top = tr.top + sy + tr.height / 2 - mr.height / 2;
265
+ break;
266
+ case "left":
267
+ left = tr.left + sx - mr.width - offset;
268
+ if (align === "start") top = tr.top + sy;
269
+ else if (align === "end") top = tr.bottom + sy - mr.height;
270
+ else top = tr.top + sy + tr.height / 2 - mr.height / 2;
271
+ break;
272
+ }
273
+ };
274
+ calc(side);
275
+ if (side === "bottom" && top + mr.height > vh + sy - pad) {
276
+ const ft = tr.top + sy - mr.height - offset;
277
+ if (ft >= sy + pad) {
278
+ effectiveSide = "top";
279
+ top = ft;
280
+ }
281
+ } else if (side === "top" && top < sy + pad) {
282
+ const ft = tr.bottom + sy + offset;
283
+ if (ft + mr.height <= vh + sy - pad) {
284
+ effectiveSide = "bottom";
285
+ top = ft;
286
+ }
287
+ } else if (side === "right" && left + mr.width > vw + sx - pad) {
288
+ const fl = tr.left + sx - mr.width - offset;
289
+ if (fl >= sx + pad) {
290
+ effectiveSide = "left";
291
+ left = fl;
292
+ }
293
+ } else if (side === "left" && left < sx + pad) {
294
+ const fl = tr.right + sx + offset;
295
+ if (fl + mr.width <= vw + sx - pad) {
296
+ effectiveSide = "right";
297
+ left = fl;
298
+ }
299
+ }
300
+ left = Math.max(sx + pad, Math.min(left, vw + sx - mr.width - pad));
301
+ top = Math.max(sy + pad, Math.min(top, vh + sy - mr.height - pad));
302
+ return { top, left, side: effectiveSide };
303
+ }
304
+ function useIsMobile(breakpoint = 1025) {
305
+ const [isMobile, setIsMobile] = useState(false);
306
+ useEffect(() => {
307
+ const mq = window.matchMedia(`(max-width: ${breakpoint - 1}px)`);
308
+ setIsMobile(mq.matches);
309
+ const handler = (e) => setIsMobile(e.matches);
310
+ mq.addEventListener("change", handler);
311
+ return () => mq.removeEventListener("change", handler);
312
+ }, [breakpoint]);
313
+ return isMobile;
314
+ }
315
+ var DropdownContext = React5__default.createContext(void 0);
316
+ function useDropdown() {
317
+ const ctx = React5__default.useContext(DropdownContext);
318
+ if (!ctx)
319
+ throw new Error("Dropdown components must be used within <Dropdown />");
320
+ return ctx;
321
+ }
322
+ React5__default.createContext(void 0);
323
+ var Dropdown = ({
324
+ children,
325
+ open: controlledOpen,
326
+ onOpenChange
327
+ }) => {
328
+ const [internalOpen, setInternalOpen] = useState(false);
329
+ const isControlled = controlledOpen !== void 0;
330
+ const open = isControlled ? controlledOpen : internalOpen;
331
+ const triggerRef = useRef(null);
332
+ const [radioValues, setRadioValues] = useState({});
333
+ const setOpen = useCallback(
334
+ (v) => {
335
+ if (!isControlled) setInternalOpen(v);
336
+ onOpenChange?.(v);
337
+ },
338
+ [isControlled, onOpenChange]
339
+ );
340
+ const setRadioValue = useCallback((group, value) => {
341
+ setRadioValues((prev) => ({ ...prev, [group]: value }));
342
+ }, []);
343
+ const ctx = useMemo(
344
+ () => ({ open, setOpen, triggerRef, radioValues, setRadioValue }),
345
+ [open, setOpen, radioValues, setRadioValue]
346
+ );
347
+ return /* @__PURE__ */ jsx(DropdownContext.Provider, { value: ctx, children });
348
+ };
349
+ function mergeTriggerRef(triggerRef, node, childRef) {
350
+ triggerRef.current = node;
351
+ if (typeof childRef === "function") childRef(node);
352
+ else if (childRef && typeof childRef === "object")
353
+ childRef.current = node;
354
+ }
355
+ var DropdownTrigger = React5__default.forwardRef(
356
+ ({
357
+ children,
358
+ asChild,
359
+ className,
360
+ onClick: onClickProp,
361
+ disabled,
362
+ ...buttonProps
363
+ }, ref) => {
364
+ const { open, setOpen, triggerRef } = useDropdown();
365
+ const handleClick = useCallback(
366
+ (e) => {
367
+ onClickProp?.(e);
368
+ e.stopPropagation();
369
+ if (disabled) return;
370
+ setOpen(!open);
371
+ },
372
+ [disabled, onClickProp, open, setOpen]
373
+ );
374
+ const setButtonRef = useCallback(
375
+ (el) => {
376
+ triggerRef.current = el;
377
+ if (typeof ref === "function") ref(el);
378
+ else if (ref) ref.current = el;
379
+ },
380
+ [ref, triggerRef]
381
+ );
382
+ if (asChild && React5__default.isValidElement(children)) {
383
+ const child = children;
384
+ return React5__default.cloneElement(child, {
385
+ ref: (node) => {
386
+ mergeTriggerRef(
387
+ triggerRef,
388
+ node,
389
+ child.ref
390
+ );
391
+ },
392
+ className: cn("group", child.props.className),
393
+ onClick: (e) => {
394
+ child.props.onClick?.(e);
395
+ handleClick(e);
396
+ },
397
+ "aria-expanded": open,
398
+ "aria-haspopup": "menu",
399
+ "data-state": open ? "open" : "closed",
400
+ ...disabled !== void 0 ? {
401
+ disabled
402
+ } : {}
403
+ });
404
+ }
405
+ return /* @__PURE__ */ jsx(
406
+ Button,
407
+ {
408
+ ref: setButtonRef,
409
+ type: "button",
410
+ ...buttonProps,
411
+ disabled,
412
+ className: cn("group", className),
413
+ "aria-expanded": open,
414
+ "aria-haspopup": "menu",
415
+ "data-state": open ? "open" : "closed",
416
+ onClick: handleClick,
417
+ children
418
+ }
419
+ );
420
+ }
421
+ );
422
+ DropdownTrigger.displayName = "DropdownTrigger";
423
+ var DropdownMobileClose = React5__default.forwardRef(({ className, type = "button", ...props }, ref) => {
424
+ return /* @__PURE__ */ jsxs(
425
+ "button",
426
+ {
427
+ ref,
428
+ type,
429
+ className: cn(
430
+ "z-100 flex size-12 shrink-0 cursor-pointer items-center justify-center rounded-full transition-all hover:bg-secondary-background active:scale-[0.96]",
431
+ className
432
+ ),
433
+ ...props,
434
+ children: [
435
+ /* @__PURE__ */ jsx(X, { className: "size-5.5" }),
436
+ /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Close" })
437
+ ]
438
+ }
439
+ );
440
+ });
441
+ DropdownMobileClose.displayName = "DropdownMobileClose";
442
+ function DropdownMobileBottomSheetPortal({
443
+ open,
444
+ isAnimating,
445
+ slideEntrance,
446
+ slideOffsetPx,
447
+ sheetTitle,
448
+ sheetExtraClassName,
449
+ contentClassName,
450
+ onRequestClose,
451
+ menuRef,
452
+ portalZClassName = "z-50",
453
+ children,
454
+ className,
455
+ style,
456
+ ...panelProps
457
+ }) {
458
+ const sheetMotion = open ? DROPDOWN_MOBILE_SHEET_ENTRY_EASING : DROPDOWN_MOBILE_SHEET_EXIT_EASING;
459
+ const sheetHiddenTransform = slideEntrance ? `translateY(${slideOffsetPx}px)` : "translateY(100%)";
460
+ return createPortal(
461
+ /* @__PURE__ */ jsxs(
462
+ "div",
463
+ {
464
+ className: cn(
465
+ "fixed inset-0 flex items-end justify-center p-0",
466
+ portalZClassName
467
+ ),
468
+ children: [
469
+ /* @__PURE__ */ jsx(
470
+ "div",
471
+ {
472
+ className: cn(
473
+ "fixed inset-0 bg-black/40 dark:bg-black/60",
474
+ isAnimating ? "opacity-100" : "opacity-0"
475
+ ),
476
+ style: {
477
+ transitionProperty: "opacity",
478
+ transitionDuration: `${DROPDOWN_MOBILE_SHEET_MOTION_MS}ms`,
479
+ transitionTimingFunction: sheetMotion
480
+ },
481
+ onClick: onRequestClose
482
+ }
483
+ ),
484
+ /* @__PURE__ */ jsxs(
485
+ "div",
486
+ {
487
+ ...panelProps,
488
+ ref: menuRef,
489
+ className: cn(
490
+ "bg-background border-primary/10 relative z-10 flex w-full max-h-[min(90dvh,calc(100dvh-env(safe-area-inset-bottom,0px)))] flex-col overflow-hidden shadow-2xl outline-none",
491
+ "rounded-t-2xl rounded-b-none border-x-0 border-b-0 border-t",
492
+ sheetExtraClassName,
493
+ className
494
+ ),
495
+ style: {
496
+ transform: isAnimating ? "translateY(0)" : sheetHiddenTransform,
497
+ opacity: isAnimating ? 1 : 0,
498
+ transitionProperty: "transform, opacity",
499
+ transitionDuration: `${DROPDOWN_MOBILE_SHEET_MOTION_MS}ms`,
500
+ transitionTimingFunction: sheetMotion,
501
+ ...style
502
+ },
503
+ children: [
504
+ /* @__PURE__ */ jsxs(
505
+ "div",
506
+ {
507
+ className: cn(
508
+ "flex w-full shrink-0 items-center py-2 pl-4 pr-2",
509
+ sheetTitle ? "justify-between gap-3" : "justify-end"
510
+ ),
511
+ children: [
512
+ sheetTitle ? /* @__PURE__ */ jsx("p", { className: "text-foreground min-w-0 flex-1 truncate text-base font-semibold", children: sheetTitle }) : null,
513
+ /* @__PURE__ */ jsx(
514
+ DropdownMobileClose,
515
+ {
516
+ onClick: (e) => {
517
+ e.stopPropagation();
518
+ onRequestClose();
519
+ }
520
+ }
521
+ )
522
+ ]
523
+ }
524
+ ),
525
+ /* @__PURE__ */ jsx(
526
+ "div",
527
+ {
528
+ className: cn(
529
+ "min-h-0 flex-1 overflow-y-auto pb-[calc(5rem+env(safe-area-inset-bottom,0px))]",
530
+ contentClassName
531
+ ),
532
+ children
533
+ }
534
+ )
535
+ ]
536
+ }
537
+ )
538
+ ]
539
+ }
540
+ ),
541
+ document.body
542
+ );
543
+ }
544
+ var DropdownContent = ({
545
+ children,
546
+ side = "bottom",
547
+ align = "start",
548
+ offset = 10,
549
+ duration = 80,
550
+ viewportPadding = 8,
551
+ closeOnEscape = true,
552
+ minWidth = "trigger",
553
+ loop = true,
554
+ mobileOptions,
555
+ slideEntrance = true,
556
+ slideEntranceOffsetPx: slideEntranceOffsetPxProp,
557
+ className,
558
+ style,
559
+ ...props
560
+ }) => {
561
+ const isMobile = useIsMobile(DROPDOWN_MOBILE_SHEET_MAX_PX + 1);
562
+ const { open, setOpen, triggerRef } = useDropdown();
563
+ const [shouldRender, setShouldRender] = useState(false);
564
+ const [isAnimating, setIsAnimating] = useState(false);
565
+ const [pos, setPos] = useState({ top: -9999, left: -9999, side });
566
+ const [triggerW, setTriggerW] = useState(0);
567
+ const menuRef = useRef(null);
568
+ const resolvedMobile = useMemo(
569
+ () => resolveDropdownMobileSheet(mobileOptions),
570
+ [mobileOptions]
571
+ );
572
+ const slideOffsetPx = useMemo(
573
+ () => slideEntranceOffsetPxProp ?? DROPDOWN_MOBILE_SHEET_SLIDE_ENTRANCE_OFFSET_DEFAULT_PX,
574
+ [slideEntranceOffsetPxProp]
575
+ );
576
+ const closeDuration = isMobile && resolvedMobile.sheet ? DROPDOWN_MOBILE_SHEET_MOTION_MS : duration;
577
+ const closeMenu = useCallback(() => setOpen(false), [setOpen]);
578
+ useEffect(() => {
579
+ if (open) {
580
+ setShouldRender(true);
581
+ } else {
582
+ setIsAnimating(false);
583
+ const timer = setTimeout(() => setShouldRender(false), closeDuration);
584
+ return () => clearTimeout(timer);
585
+ }
586
+ }, [open, closeDuration]);
587
+ useEffect(() => {
588
+ if (!shouldRender || !open) return;
589
+ let raf2 = 0;
590
+ const raf1 = requestAnimationFrame(() => {
591
+ raf2 = requestAnimationFrame(() => setIsAnimating(true));
592
+ });
593
+ return () => {
594
+ cancelAnimationFrame(raf1);
595
+ if (raf2) cancelAnimationFrame(raf2);
596
+ };
597
+ }, [shouldRender, open]);
598
+ useLayoutEffect(() => {
599
+ if (!shouldRender || !triggerRef.current || !menuRef.current) return;
600
+ const update = () => {
601
+ if (!triggerRef.current || !menuRef.current) return;
602
+ setTriggerW(triggerRef.current.getBoundingClientRect().width);
603
+ setPos(
604
+ computePos(
605
+ triggerRef.current,
606
+ menuRef.current,
607
+ side,
608
+ align,
609
+ offset,
610
+ viewportPadding
611
+ )
612
+ );
613
+ };
614
+ update();
615
+ window.addEventListener("resize", update);
616
+ window.addEventListener("scroll", update, true);
617
+ return () => {
618
+ window.removeEventListener("resize", update);
619
+ window.removeEventListener("scroll", update, true);
620
+ };
621
+ }, [shouldRender, side, align, offset, viewportPadding]);
622
+ useEffect(() => {
623
+ if (isAnimating && menuRef.current) {
624
+ menuRef.current.focus();
625
+ }
626
+ }, [isAnimating]);
627
+ useEffect(() => {
628
+ if (!open) return;
629
+ const handler = (e) => {
630
+ const t = e.target;
631
+ if (menuRef.current?.contains(t) || triggerRef.current?.contains(t))
632
+ return;
633
+ const el = e.target instanceof Element ? e.target : null;
634
+ if (el?.closest?.(`[${DROPDOWN_SUB_CONTENT_ATTR}]`)) return;
635
+ setOpen(false);
636
+ };
637
+ document.addEventListener("mousedown", handler);
638
+ return () => document.removeEventListener("mousedown", handler);
639
+ }, [open, setOpen, triggerRef]);
640
+ useEffect(() => {
641
+ if (!open) return;
642
+ const handler = (e) => {
643
+ const menu = menuRef.current;
644
+ if (!menu) return;
645
+ const focusedEl = document.activeElement;
646
+ if (focusedEl && !menu.contains(focusedEl)) return;
647
+ const items = getItems(menu);
648
+ const idx = items.indexOf(focusedEl);
649
+ switch (e.key) {
650
+ case "Escape":
651
+ if (closeOnEscape) {
652
+ e.preventDefault();
653
+ setOpen(false);
654
+ triggerRef.current?.focus();
655
+ }
656
+ break;
657
+ case "ArrowDown":
658
+ e.preventDefault();
659
+ if (items.length === 0) break;
660
+ if (idx === -1 || idx === items.length - 1 && loop)
661
+ items[0]?.focus();
662
+ else if (idx < items.length - 1) items[idx + 1]?.focus();
663
+ break;
664
+ case "ArrowUp":
665
+ e.preventDefault();
666
+ if (items.length === 0) break;
667
+ if (idx <= 0 && loop) items[items.length - 1]?.focus();
668
+ else if (idx > 0) items[idx - 1]?.focus();
669
+ break;
670
+ case "Home":
671
+ e.preventDefault();
672
+ items[0]?.focus();
673
+ break;
674
+ case "End":
675
+ e.preventDefault();
676
+ items[items.length - 1]?.focus();
677
+ break;
678
+ case "Tab":
679
+ setOpen(false);
680
+ break;
681
+ }
682
+ };
683
+ window.addEventListener("keydown", handler);
684
+ return () => window.removeEventListener("keydown", handler);
685
+ }, [open, closeOnEscape, loop, setOpen, triggerRef]);
686
+ useEffect(() => {
687
+ if (open && isMobile && resolvedMobile.sheet) {
688
+ document.body.style.overflow = "hidden";
689
+ }
690
+ return () => {
691
+ document.body.style.overflow = "";
692
+ };
693
+ }, [open, isMobile, resolvedMobile.sheet]);
694
+ if (!shouldRender || typeof document === "undefined") return null;
695
+ if (isMobile && resolvedMobile.sheet) {
696
+ return /* @__PURE__ */ jsx(
697
+ DropdownMobileBottomSheetPortal,
698
+ {
699
+ ...props,
700
+ open,
701
+ isAnimating,
702
+ slideEntrance,
703
+ slideOffsetPx,
704
+ sheetTitle: resolvedMobile.title,
705
+ sheetExtraClassName: resolvedMobile.sheetExtraClassName,
706
+ contentClassName: resolvedMobile.contentClassName,
707
+ onRequestClose: closeMenu,
708
+ menuRef,
709
+ portalZClassName: "z-50",
710
+ className,
711
+ style,
712
+ role: "menu",
713
+ "aria-orientation": "vertical",
714
+ tabIndex: -1,
715
+ children
716
+ }
717
+ );
718
+ }
719
+ const resolvedMinW = minWidth === "trigger" ? Math.max(triggerW, DROPDOWN_MENU_MIN_WIDTH_PX) : minWidth;
720
+ return createPortal(
721
+ /* @__PURE__ */ jsx(
722
+ "div",
723
+ {
724
+ ...props,
725
+ ref: menuRef,
726
+ role: "menu",
727
+ "aria-orientation": "vertical",
728
+ tabIndex: -1,
729
+ className: cn(
730
+ "bg-background border-primary/10 absolute z-50 overflow-hidden rounded-xl border py-1.5 shadow-xl outline-none",
731
+ className
732
+ ),
733
+ style: {
734
+ position: "absolute",
735
+ top: pos.top,
736
+ left: pos.left,
737
+ minWidth: resolvedMinW,
738
+ transformOrigin: DROPDOWN_CONTENT_ORIGIN[pos.side],
739
+ transform: isAnimating ? "none" : DROPDOWN_CONTENT_HIDDEN[pos.side],
740
+ opacity: isAnimating ? 1 : 0,
741
+ transitionProperty: "opacity, transform",
742
+ transitionDuration: `${duration}ms`,
743
+ transitionTimingFunction: isAnimating ? DROPDOWN_PANEL_OPEN_EASING : DROPDOWN_PANEL_CLOSE_EASING,
744
+ ...style
745
+ },
746
+ children
747
+ }
748
+ ),
749
+ document.body
750
+ );
751
+ };
752
+ function getItems(menu) {
753
+ return Array.from(
754
+ menu.querySelectorAll(
755
+ '[role="menuitem"]:not([aria-disabled="true"]),[role="menuitemcheckbox"]:not([aria-disabled="true"]),[role="menuitemradio"]:not([aria-disabled="true"])'
756
+ )
757
+ );
758
+ }
759
+ var DropdownItem = ({
760
+ children,
761
+ disabled = false,
762
+ destructive = false,
763
+ icon,
764
+ shortcut,
765
+ closeOnSelect = true,
766
+ inset = false,
767
+ className,
768
+ onClick,
769
+ ...props
770
+ }) => {
771
+ const { setOpen } = useDropdown();
772
+ const handleClick = (e) => {
773
+ if (disabled) return;
774
+ onClick?.(e);
775
+ if (closeOnSelect) setOpen(false);
776
+ };
777
+ const handleKeyDown = (e) => {
778
+ if (e.key === "Enter" || e.key === " ") {
779
+ e.preventDefault();
780
+ handleClick(e);
781
+ }
782
+ };
783
+ return /* @__PURE__ */ jsxs(
784
+ "div",
785
+ {
786
+ ...props,
787
+ role: "menuitem",
788
+ tabIndex: disabled ? void 0 : -1,
789
+ "aria-disabled": disabled,
790
+ onClick: handleClick,
791
+ onKeyDown: handleKeyDown,
792
+ className: cn(
793
+ "relative mx-1.5 flex items-center gap-2 rounded-md px-3 py-2 text-sm transition-colors duration-0 outline-none select-none",
794
+ DROPDOWN_SHEET_MENU_TEXT,
795
+ inset && "pl-9",
796
+ !disabled && "cursor-pointer",
797
+ disabled && "lg:cursor-not-allowed",
798
+ !disabled && !destructive && "text-foreground hover:bg-primary/8 focus-visible:bg-primary/8 dark:hover:bg-primary/4 dark:focus-visible:bg-primary/4",
799
+ !disabled && destructive && "text-destructive hover:bg-destructive/10 focus-visible:bg-destructive/10 dark:text-destructive-foreground dark:hover:bg-destructive-foreground/18 dark:focus-visible:bg-destructive-foreground/18",
800
+ disabled && !destructive && "text-foreground/45 dark:text-foreground/50",
801
+ disabled && destructive && "bg-destructive/5 text-destructive/75 dark:bg-destructive-foreground/12 dark:text-destructive-foreground/78",
802
+ className
803
+ ),
804
+ children: [
805
+ icon && /* @__PURE__ */ jsx("span", { className: "flex size-4 shrink-0 items-center justify-center", children: icon }),
806
+ /* @__PURE__ */ jsx("span", { className: "flex-1", children }),
807
+ shortcut ? /* @__PURE__ */ jsx(
808
+ "span",
809
+ {
810
+ className: cn(
811
+ "ml-auto text-xs tracking-widest",
812
+ DROPDOWN_SHEET_MENU_SHORTCUT,
813
+ destructive ? "text-destructive/70 dark:text-destructive-foreground/80" : "opacity-40"
814
+ ),
815
+ children: shortcut
816
+ }
817
+ ) : null
818
+ ]
819
+ }
820
+ );
821
+ };
822
+ var DropdownSeparator = ({ className, ...props }) => /* @__PURE__ */ jsx(
823
+ "div",
824
+ {
825
+ role: "separator",
826
+ className: cn("border-primary/10 my-1.5 border-t", className),
827
+ ...props
828
+ }
829
+ );
830
+ React5__default.createContext(
831
+ void 0
832
+ );
833
+
834
+ // src/react/table-view/helpers.ts
835
+ function getSelectedRowIds(table) {
836
+ return table.getSelectedRowModel().rows.map((r) => r.id);
837
+ }
838
+ function moveColumnInOrder(order, sourceId, targetId) {
839
+ const from = order.indexOf(sourceId);
840
+ const to = order.indexOf(targetId);
841
+ if (from < 0 || to < 0 || from === to) return order;
842
+ const next = [...order];
843
+ const [moved] = next.splice(from, 1);
844
+ if (moved) next.splice(to, 0, moved);
845
+ return next;
846
+ }
847
+ function getColumnHeaderLabel(header) {
848
+ const h = header.column.columnDef.header;
849
+ if (typeof h === "string") return h;
850
+ return header.column.id;
851
+ }
852
+ function getTableLeafColumnOrderList(table) {
853
+ const o = table.getState().columnOrder;
854
+ if (o && o.length > 0) return [...o];
855
+ return table.getVisibleLeafColumns().map((c) => c.id);
856
+ }
857
+ function moveTableColumnOneStep(table, columnId, direction) {
858
+ const list = getTableLeafColumnOrderList(table);
859
+ const i = list.indexOf(columnId);
860
+ if (i < 0) return;
861
+ const next = [...list];
862
+ if (direction === "left" && i > 0) {
863
+ [next[i - 1], next[i]] = [next[i], next[i - 1]];
864
+ } else if (direction === "right" && i < next.length - 1) {
865
+ [next[i + 1], next[i]] = [next[i], next[i + 1]];
866
+ } else {
867
+ return;
868
+ }
869
+ table.setColumnOrder(next);
870
+ }
871
+ function getColumnPinningStyle(column) {
872
+ const pin = column.getIsPinned();
873
+ if (!pin) return {};
874
+ const left = pin === "left" ? column.getStart("left") : void 0;
875
+ const right = pin === "right" ? column.getAfter("right") : void 0;
876
+ const zi = 20 + (column.getPinnedIndex() >= 0 ? column.getPinnedIndex() : 0);
877
+ return {
878
+ position: "sticky",
879
+ left: left == null ? void 0 : `${left}px`,
880
+ right: right == null ? void 0 : `${right}px`,
881
+ zIndex: zi
882
+ };
883
+ }
884
+ function getColumnPinningClassName(column) {
885
+ return column.getIsPinned() ? "bg-background" : void 0;
886
+ }
887
+ var ColumnHeaderMenuInner = forwardRef(function ColumnHeaderMenuInner2({ table, header, columnSort, columnReorder }, ref) {
888
+ const [open, setOpen] = useState(false);
889
+ useImperativeHandle(
890
+ ref,
891
+ () => ({
892
+ open: () => {
893
+ setOpen(true);
894
+ }
895
+ }),
896
+ []
897
+ );
898
+ const col = header.column;
899
+ const id = col.id;
900
+ const canPin = col.getCanPin();
901
+ const pin = col.getIsPinned();
902
+ const list = getTableLeafColumnOrderList(table);
903
+ const idx = list.indexOf(id);
904
+ const reorderLocked = getTableViewColumnDisableReorder(col);
905
+ const canMoveLeft = columnReorder && !reorderLocked && idx > 0;
906
+ const canMoveRight = columnReorder && !reorderLocked && idx >= 0 && idx < list.length - 1;
907
+ const canSort = columnSort && col.getCanSort();
908
+ const hasMoveSection = canMoveLeft || canMoveRight;
909
+ const hasSortSection = !!canSort;
910
+ const hasPinSection = canPin;
911
+ const hasHideSection = col.getCanHide();
912
+ if (!hasMoveSection && !hasSortSection && !hasPinSection && !hasHideSection) {
913
+ return null;
914
+ }
915
+ const showSepBeforeHide = hasHideSection && (hasMoveSection || hasSortSection || hasPinSection);
916
+ return /* @__PURE__ */ jsx(
917
+ "div",
918
+ {
919
+ className: cn(
920
+ "flex shrink-0 self-stretch items-center",
921
+ "opacity-0 transition-opacity duration-150 group-hover:opacity-100 group-focus-within:opacity-100 has-[[data-state=open]]:opacity-100"
922
+ ),
923
+ onClick: (e) => e.stopPropagation(),
924
+ children: /* @__PURE__ */ jsxs(Dropdown, { open, onOpenChange: setOpen, children: [
925
+ /* @__PURE__ */ jsx(DropdownTrigger, { asChild: true, children: /* @__PURE__ */ jsx(
926
+ Button,
927
+ {
928
+ type: "button",
929
+ size: "xs",
930
+ iconOnly: true,
931
+ rounded: "full",
932
+ className: "touch-manipulation border-none bg-transparent shadow-none",
933
+ "aria-label": "Column options",
934
+ children: /* @__PURE__ */ jsx(MoreVertical, { className: "size-3.5", strokeWidth: 2.25, "aria-hidden": true })
935
+ }
936
+ ) }),
937
+ /* @__PURE__ */ jsxs(DropdownContent, { align: "end", side: "bottom", offset: 4, children: [
938
+ hasMoveSection ? /* @__PURE__ */ jsxs(Fragment, { children: [
939
+ /* @__PURE__ */ jsx(
940
+ DropdownItem,
941
+ {
942
+ disabled: !canMoveLeft,
943
+ icon: /* @__PURE__ */ jsx(
944
+ ArrowLeft,
945
+ {
946
+ className: "size-3.5",
947
+ strokeWidth: 2.25,
948
+ "aria-hidden": true
949
+ }
950
+ ),
951
+ onClick: () => {
952
+ if (canMoveLeft) moveTableColumnOneStep(table, id, "left");
953
+ },
954
+ children: "Move to the left"
955
+ }
956
+ ),
957
+ /* @__PURE__ */ jsx(
958
+ DropdownItem,
959
+ {
960
+ disabled: !canMoveRight,
961
+ icon: /* @__PURE__ */ jsx(
962
+ ArrowRight,
963
+ {
964
+ className: "size-3.5",
965
+ strokeWidth: 2.25,
966
+ "aria-hidden": true
967
+ }
968
+ ),
969
+ onClick: () => {
970
+ if (canMoveRight) moveTableColumnOneStep(table, id, "right");
971
+ },
972
+ children: "Move to the right"
973
+ }
974
+ )
975
+ ] }) : null,
976
+ hasMoveSection && (hasSortSection || hasPinSection) ? /* @__PURE__ */ jsx(DropdownSeparator, {}) : null,
977
+ hasSortSection ? /* @__PURE__ */ jsxs(Fragment, { children: [
978
+ /* @__PURE__ */ jsx(
979
+ DropdownItem,
980
+ {
981
+ icon: /* @__PURE__ */ jsx(
982
+ ChevronUp,
983
+ {
984
+ className: "size-3.5",
985
+ strokeWidth: 2.25,
986
+ "aria-hidden": true
987
+ }
988
+ ),
989
+ onClick: () => {
990
+ col.toggleSorting(false);
991
+ },
992
+ children: "Sort ascending"
993
+ }
994
+ ),
995
+ /* @__PURE__ */ jsx(
996
+ DropdownItem,
997
+ {
998
+ icon: /* @__PURE__ */ jsx(
999
+ ChevronDown,
1000
+ {
1001
+ className: "size-3.5",
1002
+ strokeWidth: 2.25,
1003
+ "aria-hidden": true
1004
+ }
1005
+ ),
1006
+ onClick: () => {
1007
+ col.toggleSorting(true);
1008
+ },
1009
+ children: "Sort descending"
1010
+ }
1011
+ )
1012
+ ] }) : null,
1013
+ hasSortSection && hasPinSection ? /* @__PURE__ */ jsx(DropdownSeparator, {}) : null,
1014
+ hasPinSection ? /* @__PURE__ */ jsxs(Fragment, { children: [
1015
+ pin !== "left" ? /* @__PURE__ */ jsx(
1016
+ DropdownItem,
1017
+ {
1018
+ icon: /* @__PURE__ */ jsx(Pin, { className: "size-3.5", strokeWidth: 2.25, "aria-hidden": true }),
1019
+ onClick: () => {
1020
+ col.pin("left");
1021
+ },
1022
+ children: "Pin to the left"
1023
+ }
1024
+ ) : null,
1025
+ pin !== "right" ? /* @__PURE__ */ jsx(
1026
+ DropdownItem,
1027
+ {
1028
+ icon: /* @__PURE__ */ jsx(
1029
+ Pin,
1030
+ {
1031
+ className: "size-3.5 -scale-x-100",
1032
+ strokeWidth: 2.25,
1033
+ "aria-hidden": true
1034
+ }
1035
+ ),
1036
+ onClick: () => {
1037
+ col.pin("right");
1038
+ },
1039
+ children: "Pin to the right"
1040
+ }
1041
+ ) : null,
1042
+ pin ? /* @__PURE__ */ jsx(
1043
+ DropdownItem,
1044
+ {
1045
+ icon: /* @__PURE__ */ jsx(
1046
+ PinOff,
1047
+ {
1048
+ className: "size-3.5",
1049
+ strokeWidth: 2.25,
1050
+ "aria-hidden": true
1051
+ }
1052
+ ),
1053
+ onClick: () => {
1054
+ col.pin(false);
1055
+ },
1056
+ children: "Unpin column"
1057
+ }
1058
+ ) : null
1059
+ ] }) : null,
1060
+ showSepBeforeHide ? /* @__PURE__ */ jsx(DropdownSeparator, {}) : null,
1061
+ hasHideSection ? /* @__PURE__ */ jsx(
1062
+ DropdownItem,
1063
+ {
1064
+ icon: /* @__PURE__ */ jsx(EyeOff, { className: "size-3.5", strokeWidth: 2.25, "aria-hidden": true }),
1065
+ onClick: () => {
1066
+ col.toggleVisibility(false);
1067
+ setOpen(false);
1068
+ },
1069
+ children: "Hide column"
1070
+ }
1071
+ ) : null
1072
+ ] })
1073
+ ] })
1074
+ }
1075
+ );
1076
+ });
1077
+ ColumnHeaderMenuInner.displayName = "ColumnHeaderMenuInner";
1078
+ var ColumnHeaderMenu = memo(ColumnHeaderMenuInner);
1079
+ ColumnHeaderMenu.displayName = "ColumnHeaderMenu";
1080
+ var TABLE_VIEW_PERSIST_STORAGE_KEY = "@avenueticket/ui/table-view";
1081
+ var TABLE_VIEW_PERSIST_DEBOUNCE_MS = 200;
1082
+ function emptyRoot() {
1083
+ return { tables: {} };
1084
+ }
1085
+ function readRoot() {
1086
+ if (typeof window === "undefined") return emptyRoot();
1087
+ try {
1088
+ const raw = localStorage.getItem(TABLE_VIEW_PERSIST_STORAGE_KEY);
1089
+ if (!raw) return emptyRoot();
1090
+ const parsed = JSON.parse(raw);
1091
+ if (!parsed || typeof parsed !== "object") return emptyRoot();
1092
+ const tables = parsed.tables;
1093
+ if (!tables || typeof tables !== "object") return emptyRoot();
1094
+ const out = {};
1095
+ for (const [k, v] of Object.entries(tables)) {
1096
+ if (v && typeof v === "object" && v.v === 1) {
1097
+ out[k] = v;
1098
+ }
1099
+ }
1100
+ return { tables: out };
1101
+ } catch {
1102
+ return emptyRoot();
1103
+ }
1104
+ }
1105
+ function writeRoot(root) {
1106
+ if (typeof window === "undefined") return;
1107
+ try {
1108
+ localStorage.setItem(TABLE_VIEW_PERSIST_STORAGE_KEY, JSON.stringify(root));
1109
+ } catch {
1110
+ }
1111
+ }
1112
+ function readSnapshot(persistKey) {
1113
+ const row = readRoot().tables[persistKey];
1114
+ return row?.v === 1 ? row : null;
1115
+ }
1116
+ function writeSnapshot(persistKey, snapshot) {
1117
+ const root = readRoot();
1118
+ root.tables[persistKey] = snapshot;
1119
+ writeRoot(root);
1120
+ }
1121
+ function mergePersistedColumnOrder(persisted, defaultOrder) {
1122
+ if (!persisted?.length) return defaultOrder;
1123
+ const allowed = new Set(defaultOrder);
1124
+ const seen = /* @__PURE__ */ new Set();
1125
+ const next = [];
1126
+ for (const id of persisted) {
1127
+ if (allowed.has(id) && !seen.has(id)) {
1128
+ next.push(id);
1129
+ seen.add(id);
1130
+ }
1131
+ }
1132
+ for (const id of defaultOrder) {
1133
+ if (!seen.has(id)) {
1134
+ next.push(id);
1135
+ seen.add(id);
1136
+ }
1137
+ }
1138
+ return next;
1139
+ }
1140
+ function filterColumnSizingForIds(sizing, allowed) {
1141
+ if (!sizing) return {};
1142
+ const next = {};
1143
+ for (const [id, w] of Object.entries(sizing)) {
1144
+ if (allowed.has(id) && typeof w === "number" && Number.isFinite(w)) {
1145
+ next[id] = w;
1146
+ }
1147
+ }
1148
+ return next;
1149
+ }
1150
+ function normalizePersistedPinning(raw, allowed) {
1151
+ return {
1152
+ left: (raw?.left ?? []).filter((id) => allowed.has(id)),
1153
+ right: (raw?.right ?? []).filter((id) => allowed.has(id))
1154
+ };
1155
+ }
1156
+ function filterColumnVisibilityForIds(visibility, allowed) {
1157
+ if (!visibility) return {};
1158
+ const next = {};
1159
+ for (const [id, vis] of Object.entries(visibility)) {
1160
+ if (allowed.has(id) && vis === false) {
1161
+ next[id] = false;
1162
+ }
1163
+ }
1164
+ return next;
1165
+ }
1166
+ function shallowEqualColumnOrder(a, b) {
1167
+ if (a.length !== b.length) return false;
1168
+ return a.every((id, i) => id === b[i]);
1169
+ }
1170
+ function useTableViewPersistence(table, persistKey, opts) {
1171
+ const { columnResize, columnHeaderMenu } = opts;
1172
+ const hydratedRef = useRef(false);
1173
+ const skipNextSaveRef = useRef(false);
1174
+ const prevPersistKeyRef = useRef(void 0);
1175
+ const prevLeafIdsKeyRef = useRef("");
1176
+ const prevGatesKeyRef = useRef("");
1177
+ const leafIdsKey = useMemo(
1178
+ () => table.getAllLeafColumns().map((c) => c.id).join("\0"),
1179
+ [table]
1180
+ );
1181
+ const gatesKey = `${columnResize}\0${columnHeaderMenu}`;
1182
+ useLayoutEffect(() => {
1183
+ if (!persistKey) {
1184
+ hydratedRef.current = true;
1185
+ prevPersistKeyRef.current = void 0;
1186
+ return;
1187
+ }
1188
+ const persistChanged = prevPersistKeyRef.current !== persistKey;
1189
+ const leafChanged = prevLeafIdsKeyRef.current !== leafIdsKey;
1190
+ const gatesChanged = prevGatesKeyRef.current !== gatesKey;
1191
+ if (!persistChanged && !leafChanged && !gatesChanged && hydratedRef.current) {
1192
+ return;
1193
+ }
1194
+ prevPersistKeyRef.current = persistKey;
1195
+ prevLeafIdsKeyRef.current = leafIdsKey;
1196
+ prevGatesKeyRef.current = gatesKey;
1197
+ skipNextSaveRef.current = true;
1198
+ const allowed = new Set(table.getAllLeafColumns().map((c) => c.id));
1199
+ if (allowed.size === 0) {
1200
+ hydratedRef.current = true;
1201
+ return;
1202
+ }
1203
+ const saved = readSnapshot(persistKey);
1204
+ const defaultOrder = table.getAllLeafColumns().map((c) => c.id);
1205
+ const cur = table.getState();
1206
+ const curPin = cur.columnPinning ?? { left: [], right: [] };
1207
+ if (saved) {
1208
+ const nextOrder = mergePersistedColumnOrder(
1209
+ saved.columnOrder,
1210
+ defaultOrder
1211
+ );
1212
+ if (!shallowEqualColumnOrder(nextOrder, cur.columnOrder)) {
1213
+ table.setColumnOrder(nextOrder);
1214
+ }
1215
+ if (columnHeaderMenu && saved.columnPinning) {
1216
+ const nextPin = normalizePersistedPinning(saved.columnPinning, allowed);
1217
+ const pinEq = shallowEqualColumnOrder(nextPin.left ?? [], curPin.left ?? []) && shallowEqualColumnOrder(nextPin.right ?? [], curPin.right ?? []);
1218
+ if (!pinEq) {
1219
+ table.setColumnPinning(nextPin);
1220
+ }
1221
+ }
1222
+ if (columnResize && saved.columnSizing) {
1223
+ const nextSizing = filterColumnSizingForIds(
1224
+ saved.columnSizing,
1225
+ allowed
1226
+ );
1227
+ if (JSON.stringify(nextSizing) !== JSON.stringify(cur.columnSizing)) {
1228
+ table.setColumnSizing(nextSizing);
1229
+ }
1230
+ }
1231
+ if (columnHeaderMenu && saved.columnVisibility != null) {
1232
+ const nextVis = filterColumnVisibilityForIds(
1233
+ saved.columnVisibility,
1234
+ allowed
1235
+ );
1236
+ const curVis = cur.columnVisibility ?? {};
1237
+ if (JSON.stringify(nextVis) !== JSON.stringify(curVis)) {
1238
+ table.setColumnVisibility(nextVis);
1239
+ }
1240
+ }
1241
+ }
1242
+ hydratedRef.current = true;
1243
+ }, [
1244
+ persistKey,
1245
+ table,
1246
+ leafIdsKey,
1247
+ gatesKey,
1248
+ columnResize,
1249
+ columnHeaderMenu
1250
+ ]);
1251
+ const s = table.getState();
1252
+ const persistSerial = persistKey == null ? "" : JSON.stringify({
1253
+ columnOrder: s.columnOrder,
1254
+ columnSizing: columnResize ? s.columnSizing : null,
1255
+ columnPinning: columnHeaderMenu ? s.columnPinning : null,
1256
+ columnVisibility: columnHeaderMenu ? s.columnVisibility : null
1257
+ });
1258
+ useEffect(() => {
1259
+ if (!persistKey || !hydratedRef.current) return;
1260
+ if (skipNextSaveRef.current) {
1261
+ skipNextSaveRef.current = false;
1262
+ return;
1263
+ }
1264
+ const id = window.setTimeout(() => {
1265
+ const st = table.getState();
1266
+ writeSnapshot(persistKey, {
1267
+ v: 1,
1268
+ columnOrder: st.columnOrder,
1269
+ ...columnResize ? { columnSizing: st.columnSizing } : {},
1270
+ ...columnHeaderMenu ? {
1271
+ columnPinning: st.columnPinning,
1272
+ columnVisibility: st.columnVisibility
1273
+ } : {}
1274
+ });
1275
+ }, TABLE_VIEW_PERSIST_DEBOUNCE_MS);
1276
+ return () => window.clearTimeout(id);
1277
+ }, [
1278
+ persistKey,
1279
+ persistSerial,
1280
+ table,
1281
+ columnResize,
1282
+ columnHeaderMenu
1283
+ ]);
1284
+ }
1285
+ var defaultTableConfig = {
1286
+ sortableColumnIds: /* @__PURE__ */ new Set(),
1287
+ enableColumnSort: true,
1288
+ enableColumnReorder: false,
1289
+ enableColumnResize: false,
1290
+ columnDragState: null
1291
+ };
1292
+ var TableConfigContext = React5.createContext(null);
1293
+ TableConfigContext.displayName = "TableConfigContext";
1294
+ function setColumnDragPreview(e, options) {
1295
+ if (!e.dataTransfer) return;
1296
+ e.dataTransfer.effectAllowed = "move";
1297
+ const width = options.width ?? 80;
1298
+ const height = options.height ?? 100;
1299
+ const el = document.createElement("div");
1300
+ el.setAttribute("data-table-drag-preview", "");
1301
+ const dark = typeof window !== "undefined" && window.matchMedia && window.matchMedia("(prefers-color-scheme: dark)").matches;
1302
+ const bg = dark ? "rgba(24,24,26,0.95)" : "rgba(255,255,255,0.96)";
1303
+ const fg = dark ? "rgba(250,250,250,0.95)" : "rgba(10,10,10,0.92)";
1304
+ const border = dark ? "1px solid rgba(255,255,255,0.12)" : "1px solid rgba(0,0,0,0.1)";
1305
+ const shadow = "0 12px 32px rgba(0,0,0,0.2),0 0 0 1px rgba(0,0,0,0.04)";
1306
+ el.style.cssText = [
1307
+ "position:fixed",
1308
+ "left:0",
1309
+ "top:0",
1310
+ "z-index:100000",
1311
+ "pointer-events:none",
1312
+ "box-sizing:border-box",
1313
+ `width:${width}px`,
1314
+ `min-height:${height}px`,
1315
+ "display:flex",
1316
+ "flex-direction:column",
1317
+ "align-items:center",
1318
+ "justify-content:flex-start",
1319
+ "gap:8px",
1320
+ `padding:10px 8px 12px`,
1321
+ `color:${fg}`,
1322
+ `background:${bg}`,
1323
+ `border:${border}`,
1324
+ "border-radius:8px",
1325
+ `box-shadow:${shadow}`
1326
+ ].join(";");
1327
+ const bar = document.createElement("div");
1328
+ bar.style.cssText = `width:3px;flex:1;min-height:32px;border-radius:2px;background:${dark ? "rgba(80,200,150,0.4)" : "rgba(20,80,200,0.2)"};align-self:stretch;`;
1329
+ const t = document.createElement("div");
1330
+ t.textContent = options.title;
1331
+ t.style.cssText = "font:600 11px/1.2 system-ui,-apple-system,sans-serif;text-align:center;word-break:break-word;max-width:100%;";
1332
+ el.appendChild(t);
1333
+ el.appendChild(bar);
1334
+ el.style.minHeight = `${height}px`;
1335
+ document.body.appendChild(el);
1336
+ void el.offsetWidth;
1337
+ e.dataTransfer.setDragImage(
1338
+ el,
1339
+ options.hotspotX ?? width / 2,
1340
+ options.hotspotY ?? 28
1341
+ );
1342
+ requestAnimationFrame(() => {
1343
+ if (el.parentNode) el.parentNode.removeChild(el);
1344
+ });
1345
+ }
1346
+ var COLUMN_DRAG_TH_STRIP = "relative z-20 box-border overflow-hidden rounded-t-lg border border-primary/20 bg-primary/8 opacity-70 shadow-sm";
1347
+ var COLUMN_DRAG_TD_STRIP = "overflow-hidden border-x border-primary/15 bg-primary/5 opacity-70";
1348
+ var columnDragThClasses = (config, columnId) => {
1349
+ if (!config.enableColumnReorder || !config.columnDragState) return void 0;
1350
+ const d = config.columnDragState;
1351
+ const isSource = d.draggingId === columnId;
1352
+ const isDrop = d.dropTargetId === columnId && d.draggingId != null && d.draggingId !== columnId;
1353
+ if (isSource || isDrop) {
1354
+ return COLUMN_DRAG_TH_STRIP;
1355
+ }
1356
+ return void 0;
1357
+ };
1358
+ var columnDragTdClasses = (config, columnId) => {
1359
+ if (!config.enableColumnReorder || !config.columnDragState) return void 0;
1360
+ const d = config.columnDragState;
1361
+ const isSource = d.draggingId === columnId;
1362
+ const isDrop = d.dropTargetId === columnId && d.draggingId != null && d.draggingId !== columnId;
1363
+ if (isSource || isDrop) {
1364
+ return COLUMN_DRAG_TD_STRIP;
1365
+ }
1366
+ return void 0;
1367
+ };
1368
+ var Table = React5.forwardRef(
1369
+ ({
1370
+ className,
1371
+ containerClassName,
1372
+ sortableColumns,
1373
+ enableColumnSort: enableColumnSortFromProps,
1374
+ enableColumnReorder: enableColumnReorderFromProps,
1375
+ enableColumnResize: enableColumnResizeFromProps,
1376
+ columnDragState: columnDragStateFromProps,
1377
+ ...props
1378
+ }, ref) => {
1379
+ const config = React5.useMemo(() => {
1380
+ const sortableColumnIds = new Set(sortableColumns ?? []);
1381
+ return {
1382
+ sortableColumnIds,
1383
+ enableColumnSort: enableColumnSortFromProps ?? true,
1384
+ enableColumnReorder: enableColumnReorderFromProps ?? false,
1385
+ enableColumnResize: enableColumnResizeFromProps ?? false,
1386
+ columnDragState: columnDragStateFromProps ?? null
1387
+ };
1388
+ }, [
1389
+ sortableColumns,
1390
+ enableColumnSortFromProps,
1391
+ enableColumnReorderFromProps,
1392
+ enableColumnResizeFromProps,
1393
+ columnDragStateFromProps
1394
+ ]);
1395
+ return /* @__PURE__ */ jsx(
1396
+ "div",
1397
+ {
1398
+ "data-slot": "table-container",
1399
+ "data-table-sort": config.enableColumnSort ? "on" : "off",
1400
+ "data-table-reorder": config.enableColumnReorder ? "on" : "off",
1401
+ "data-table-resize": config.enableColumnResize ? "on" : "off",
1402
+ className: cn("relative w-full overflow-x-auto", containerClassName),
1403
+ children: /* @__PURE__ */ jsx(TableConfigContext.Provider, { value: config, children: /* @__PURE__ */ jsx(
1404
+ "table",
1405
+ {
1406
+ ref,
1407
+ "data-slot": "table",
1408
+ className: cn(
1409
+ "min-w-full w-max caption-bottom text-sm",
1410
+ className
1411
+ ),
1412
+ ...props
1413
+ }
1414
+ ) })
1415
+ }
1416
+ );
1417
+ }
1418
+ );
1419
+ Table.displayName = "Table";
1420
+ var TableHeader = React5.forwardRef(({ className, ...props }, ref) => {
1421
+ const config = React5.useContext(TableConfigContext) ?? defaultTableConfig;
1422
+ const hasSortableColumns = config.enableColumnSort && config.sortableColumnIds.size > 0;
1423
+ return /* @__PURE__ */ jsx(
1424
+ "thead",
1425
+ {
1426
+ ref,
1427
+ "data-slot": "table-header",
1428
+ className: cn(
1429
+ hasSortableColumns && "[&_tr:hover]:bg-transparent!",
1430
+ className
1431
+ ),
1432
+ ...props
1433
+ }
1434
+ );
1435
+ });
1436
+ TableHeader.displayName = "TableHeader";
1437
+ var TableBody = React5.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsx(
1438
+ "tbody",
1439
+ {
1440
+ ref,
1441
+ "data-slot": "table-body",
1442
+ className: cn(
1443
+ "[&>tr:last-child>td:not([data-table-column-drag-strip])]:border-b-0",
1444
+ className
1445
+ ),
1446
+ ...props
1447
+ }
1448
+ ));
1449
+ TableBody.displayName = "TableBody";
1450
+ var TableFooter = React5.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsx(
1451
+ "tfoot",
1452
+ {
1453
+ ref,
1454
+ "data-slot": "table-footer",
1455
+ className: cn(
1456
+ "border-t border-primary/10 bg-primary/5 font-medium",
1457
+ className
1458
+ ),
1459
+ ...props
1460
+ }
1461
+ ));
1462
+ TableFooter.displayName = "TableFooter";
1463
+ var TableRow = React5.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsx(
1464
+ "tr",
1465
+ {
1466
+ ref,
1467
+ "data-slot": "table-row",
1468
+ className: cn(
1469
+ "transition-colors duration-0 hover:bg-primary/3 data-[state=selected]:bg-primary/10",
1470
+ className
1471
+ ),
1472
+ ...props
1473
+ }
1474
+ ));
1475
+ TableRow.displayName = "TableRow";
1476
+ var columnDragHandleIconClass = cn(
1477
+ "text-primary/55 hover:text-primary/80",
1478
+ "cursor-grab active:cursor-grabbing touch-none",
1479
+ "shrink-0"
1480
+ );
1481
+ var TableColumnDragHandle = React5.forwardRef(function TableColumnDragHandle2({ columnId, previewLabel, className, onDragStart, onDragEnd, title, ...rest }, ref) {
1482
+ return /* @__PURE__ */ jsx(
1483
+ "span",
1484
+ {
1485
+ ref,
1486
+ className: cn(
1487
+ "inline-flex select-none items-center justify-center",
1488
+ columnDragHandleIconClass,
1489
+ className
1490
+ ),
1491
+ title: title ?? "Drag to reorder this column",
1492
+ tabIndex: -1,
1493
+ "aria-label": "Drag to reorder this column",
1494
+ draggable: true,
1495
+ onDragStart: (e) => {
1496
+ e.dataTransfer.setData("text/plain", columnId);
1497
+ setColumnDragPreview(e, { title: previewLabel ?? "Column" });
1498
+ onDragStart?.(e);
1499
+ },
1500
+ onDragEnd,
1501
+ onClick: (ev) => ev.stopPropagation(),
1502
+ onKeyDown: (ev) => {
1503
+ if (ev.key === " " || ev.key === "Enter") {
1504
+ ev.preventDefault();
1505
+ }
1506
+ ev.stopPropagation();
1507
+ },
1508
+ "data-slot": "table-column-drag-handle",
1509
+ ...rest,
1510
+ children: /* @__PURE__ */ jsx(
1511
+ GripVertical,
1512
+ {
1513
+ className: "size-4 pointer-events-none",
1514
+ strokeWidth: 2.25,
1515
+ "aria-hidden": true
1516
+ }
1517
+ )
1518
+ }
1519
+ );
1520
+ });
1521
+ TableColumnDragHandle.displayName = "TableColumnDragHandle";
1522
+ function TableHeaderSortControl({
1523
+ activeSort,
1524
+ onRequest,
1525
+ className
1526
+ }) {
1527
+ const isActiveSort = activeSort === "asc" || activeSort === "desc";
1528
+ return /* @__PURE__ */ jsx(
1529
+ "span",
1530
+ {
1531
+ className: cn("inline-flex shrink-0 items-stretch pl-0", className),
1532
+ children: onRequest ? /* @__PURE__ */ jsx("span", { className: "flex shrink-0 items-stretch", children: /* @__PURE__ */ jsx(
1533
+ "button",
1534
+ {
1535
+ type: "button",
1536
+ className: "text-primary/90 hover:text-primary/95 inline-flex min-h-10 w-8 min-w-8 touch-manipulation items-center justify-center self-center rounded p-0 md:min-h-12",
1537
+ onClick: (e) => {
1538
+ e.stopPropagation();
1539
+ onRequest(e);
1540
+ },
1541
+ title: "Change sort",
1542
+ "aria-label": "Change sort order",
1543
+ children: isActiveSort ? activeSort === "desc" ? /* @__PURE__ */ jsx(
1544
+ ArrowDown,
1545
+ {
1546
+ className: "size-3.5 shrink-0",
1547
+ strokeWidth: 2.25,
1548
+ "aria-hidden": true
1549
+ }
1550
+ ) : /* @__PURE__ */ jsx(
1551
+ ArrowUp,
1552
+ {
1553
+ className: "size-3.5 shrink-0",
1554
+ strokeWidth: 2.25,
1555
+ "aria-hidden": true
1556
+ }
1557
+ ) : /* @__PURE__ */ jsx(
1558
+ ArrowUp,
1559
+ {
1560
+ className: "text-primary/85 size-3.5 shrink-0 opacity-0 transition-opacity duration-150 group-hover:opacity-100 group-focus-within:opacity-100",
1561
+ strokeWidth: 2.25,
1562
+ "aria-hidden": true
1563
+ }
1564
+ )
1565
+ }
1566
+ ) }) : isActiveSort ? /* @__PURE__ */ jsx("span", { className: "inline-flex shrink-0 items-center", children: activeSort === "desc" ? /* @__PURE__ */ jsx(
1567
+ ArrowDown,
1568
+ {
1569
+ className: "size-3.5 shrink-0 self-center text-primary/90",
1570
+ strokeWidth: 2.25,
1571
+ "aria-hidden": true
1572
+ }
1573
+ ) : /* @__PURE__ */ jsx(
1574
+ ArrowUp,
1575
+ {
1576
+ className: "size-3.5 shrink-0 self-center text-primary/90",
1577
+ strokeWidth: 2.25,
1578
+ "aria-hidden": true
1579
+ }
1580
+ ) }) : /* @__PURE__ */ jsx("span", { className: "inline-flex shrink-0 items-center", children: /* @__PURE__ */ jsx(
1581
+ ArrowUp,
1582
+ {
1583
+ className: "text-primary/85 size-3.5 shrink-0 self-center opacity-0 transition-opacity duration-150 group-hover:opacity-100 group-focus-within:opacity-100",
1584
+ strokeWidth: 2.25,
1585
+ "aria-hidden": true
1586
+ }
1587
+ ) })
1588
+ }
1589
+ );
1590
+ }
1591
+ var TableHead = React5.forwardRef(
1592
+ ({
1593
+ className,
1594
+ columnId,
1595
+ children,
1596
+ activeSort,
1597
+ onColumnResizeStart,
1598
+ isColumnResizing,
1599
+ style,
1600
+ headerEnd,
1601
+ ...props
1602
+ }, ref) => {
1603
+ const config = React5.useContext(TableConfigContext) ?? defaultTableConfig;
1604
+ const showSortUI = config.enableColumnSort && columnId !== void 0 && config.sortableColumnIds.has(columnId);
1605
+ const isActiveSort = showSortUI && (activeSort === "asc" || activeSort === "desc");
1606
+ const hasHeaderEnd = headerEnd != null && headerEnd !== false;
1607
+ const showResizer = config.enableColumnResize && typeof onColumnResizeStart === "function";
1608
+ const drag = columnId ? columnDragThClasses(config, columnId) : void 0;
1609
+ return /* @__PURE__ */ jsxs(
1610
+ "th",
1611
+ {
1612
+ ref,
1613
+ "data-resizing": isColumnResizing ? 1 : void 0,
1614
+ "data-slot": "table-head",
1615
+ "data-column-id": columnId,
1616
+ "data-sortable": showSortUI ? "true" : void 0,
1617
+ "data-sorted": isActiveSort ? activeSort ?? void 0 : void 0,
1618
+ "aria-sort": isActiveSort && activeSort ? activeSort === "desc" ? "descending" : "ascending" : showSortUI ? "none" : void 0,
1619
+ className: cn(
1620
+ "h-10 min-w-0 px-3 text-left align-middle text-sm font-bold text-primary transition-colors duration-0 md:h-12 md:px-4 [&:has([role=checkbox])]:pr-0",
1621
+ !drag && "border-b border-primary/10",
1622
+ showResizer && "relative",
1623
+ // th cursor-pointer is often overridden by child button default cursor
1624
+ (showSortUI || hasHeaderEnd) && "group hover:bg-primary/5 [&_button]:cursor-pointer",
1625
+ drag,
1626
+ isColumnResizing && "opacity-100",
1627
+ className
1628
+ ),
1629
+ style,
1630
+ ...props,
1631
+ children: [
1632
+ showSortUI ? /* @__PURE__ */ jsxs("span", { className: "inline-flex h-full w-full min-h-0 min-w-0 max-w-full items-center justify-start gap-0.5", children: [
1633
+ /* @__PURE__ */ jsx("span", { className: "min-h-0 min-w-0 flex-1 text-left [&_[data-slot=table-column-drag-handle]]:cursor-grab [&_[data-slot=table-column-drag-handle]]:active:cursor-grabbing", children }),
1634
+ hasHeaderEnd ? /* @__PURE__ */ jsx("span", { className: "inline-flex min-h-0 min-w-0 shrink-0 items-center", children: headerEnd }) : null
1635
+ ] }) : hasHeaderEnd ? /* @__PURE__ */ jsxs("span", { className: "inline-flex h-full w-full min-h-0 min-w-0 max-w-full items-center justify-start gap-0.5", children: [
1636
+ /* @__PURE__ */ jsx("span", { className: "min-h-0 min-w-0 flex-1 text-left [&_[data-slot=table-column-drag-handle]]:cursor-grab [&_[data-slot=table-column-drag-handle]]:active:cursor-grabbing", children }),
1637
+ /* @__PURE__ */ jsx("span", { className: "inline-flex min-h-0 min-w-0 shrink-0 items-center", children: headerEnd })
1638
+ ] }) : children,
1639
+ showResizer && /* @__PURE__ */ jsx(
1640
+ "div",
1641
+ {
1642
+ role: "separator",
1643
+ title: "Drag to resize",
1644
+ onMouseDown: onColumnResizeStart,
1645
+ onTouchStart: onColumnResizeStart,
1646
+ className: cn(
1647
+ // keep handle inside this th — negative right overlapped the next cell (bad with sticky/pinned columns)
1648
+ "absolute top-0 right-0 z-1 h-full w-2.5 min-w-2.5 max-w-2.5 touch-none",
1649
+ "cursor-col-resize select-none",
1650
+ isColumnResizing ? "bg-primary/35" : "bg-primary/0 hover:bg-primary/25"
1651
+ ),
1652
+ "data-slot": "table-column-resize-handle",
1653
+ "aria-hidden": true
1654
+ }
1655
+ )
1656
+ ]
1657
+ }
1658
+ );
1659
+ }
1660
+ );
1661
+ TableHead.displayName = "TableHead";
1662
+ var TableCell = React5.forwardRef(
1663
+ ({ className, style, columnId, ...props }, ref) => {
1664
+ const config = React5.useContext(TableConfigContext) ?? defaultTableConfig;
1665
+ const drag = columnId ? columnDragTdClasses(config, columnId) : void 0;
1666
+ const columnDragStrip = Boolean(drag);
1667
+ return /* @__PURE__ */ jsx(
1668
+ "td",
1669
+ {
1670
+ ref,
1671
+ "data-slot": "table-cell",
1672
+ "data-table-column-drag-strip": columnDragStrip ? "" : void 0,
1673
+ className: cn(
1674
+ "min-w-0 border-b border-primary/10 p-3 align-middle text-sm text-primary/90 md:p-4 [&:has([role=checkbox])]:pr-0",
1675
+ drag,
1676
+ className
1677
+ ),
1678
+ style,
1679
+ "data-column-id": columnId,
1680
+ ...props
1681
+ }
1682
+ );
1683
+ }
1684
+ );
1685
+ TableCell.displayName = "TableCell";
1686
+ function sizingUpdaterToFn(updater) {
1687
+ return typeof updater === "function" ? updater : () => updater;
1688
+ }
1689
+ function useRafBatchedColumnSizing(setColumnSizing) {
1690
+ const rafRef = useRef(null);
1691
+ const queueRef = useRef(
1692
+ []
1693
+ );
1694
+ useEffect(
1695
+ () => () => {
1696
+ if (rafRef.current != null) {
1697
+ cancelAnimationFrame(rafRef.current);
1698
+ rafRef.current = null;
1699
+ }
1700
+ },
1701
+ []
1702
+ );
1703
+ return useCallback(
1704
+ (updater) => {
1705
+ queueRef.current.push(sizingUpdaterToFn(updater));
1706
+ if (rafRef.current != null) return;
1707
+ rafRef.current = requestAnimationFrame(() => {
1708
+ rafRef.current = null;
1709
+ const fns = queueRef.current;
1710
+ queueRef.current = [];
1711
+ if (fns.length === 0) return;
1712
+ setColumnSizing((prev) => fns.reduce((acc, f) => f(acc), prev));
1713
+ });
1714
+ },
1715
+ [setColumnSizing]
1716
+ );
1717
+ }
1718
+ function useTransitionColumnSizing(setColumnSizing) {
1719
+ return useCallback(
1720
+ (updater) => {
1721
+ startTransition(() => {
1722
+ setColumnSizing(updater);
1723
+ });
1724
+ },
1725
+ [setColumnSizing]
1726
+ );
1727
+ }
1728
+ var EMPTY_STRING_ARRAY = [];
1729
+ var tableViewColumnRoundTop = "overflow-hidden rounded-t-lg";
1730
+ var tableViewColumnRoundBottom = "overflow-hidden rounded-b-lg";
1731
+ var TableViewColumnHead = React5.memo(
1732
+ function TableViewColumnHead2(props) {
1733
+ const {
1734
+ header,
1735
+ table,
1736
+ options,
1737
+ getColumnMinClassName,
1738
+ onHeaderCellDragOver,
1739
+ onHeaderCellDrop,
1740
+ onHeaderContextMenu,
1741
+ setDraggedId,
1742
+ setDropTargetId,
1743
+ endColumnDrag,
1744
+ registerColumnMenu
1745
+ } = props;
1746
+ const id = header.column.id;
1747
+ const canSort = header.column.getCanSort() && options.columnSort;
1748
+ const isSorted = header.column.getIsSorted();
1749
+ const hSize = header.getSize();
1750
+ const canResize = options.columnResize && header.column.getCanResize();
1751
+ const resizer = header.getResizeHandler();
1752
+ const onSort = header.column.getToggleSortingHandler();
1753
+ const runSort = useCallback(
1754
+ (e) => {
1755
+ onSort?.(e);
1756
+ },
1757
+ [onSort]
1758
+ );
1759
+ const setMenuRef = useCallback(
1760
+ (h) => {
1761
+ registerColumnMenu(id, h);
1762
+ },
1763
+ [id, registerColumnMenu]
1764
+ );
1765
+ const onDragStartReorder = useCallback(() => {
1766
+ setDraggedId(id);
1767
+ setDropTargetId(null);
1768
+ }, [id, setDraggedId, setDropTargetId]);
1769
+ const disableColumnReorder = getTableViewColumnDisableReorder(
1770
+ header.column
1771
+ );
1772
+ const showReorderHandle = options.columnReorder && !disableColumnReorder;
1773
+ const headerInnerGap = showReorderHandle ? "gap-2" : "gap-1.5";
1774
+ const pinStyle = getColumnPinningStyle(header.column);
1775
+ const sizeStyle = options.columnResize ? {
1776
+ width: hSize,
1777
+ minWidth: header.column.columnDef.minSize,
1778
+ maxWidth: header.column.columnDef.maxSize
1779
+ } : void 0;
1780
+ return /* @__PURE__ */ jsx(
1781
+ TableHead,
1782
+ {
1783
+ colSpan: header.colSpan,
1784
+ className: cn(
1785
+ tableViewColumnRoundTop,
1786
+ !options.columnResize && getColumnMinClassName?.(id),
1787
+ getColumnPinningClassName(header.column),
1788
+ header.column.getIsPinned() && "hover:bg-[color-mix(in_oklab,var(--color-primary)_5%,var(--color-background))]",
1789
+ options.columnHeaderMenu && !header.isPlaceholder && "group"
1790
+ ),
1791
+ style: { ...pinStyle, ...sizeStyle },
1792
+ columnId: id,
1793
+ activeSort: canSort ? isSorted === "asc" || isSorted === "desc" ? isSorted : null : null,
1794
+ onColumnResizeStart: canResize ? resizer : void 0,
1795
+ isColumnResizing: header.column.getIsResizing(),
1796
+ headerEnd: options.columnHeaderMenu && !header.isPlaceholder ? /* @__PURE__ */ jsx(
1797
+ ColumnHeaderMenu,
1798
+ {
1799
+ ref: setMenuRef,
1800
+ table,
1801
+ header,
1802
+ columnSort: options.columnSort,
1803
+ columnReorder: options.columnReorder
1804
+ }
1805
+ ) : void 0,
1806
+ onContextMenu: options.columnHeaderMenu && !header.isPlaceholder ? onHeaderContextMenu : void 0,
1807
+ onDragOver: onHeaderCellDragOver,
1808
+ onDrop: options.columnReorder ? onHeaderCellDrop : void 0,
1809
+ children: /* @__PURE__ */ jsxs(
1810
+ "span",
1811
+ {
1812
+ className: cn(
1813
+ "box-border flex h-full min-h-0 w-full min-w-0 max-w-full flex-1 items-center",
1814
+ headerInnerGap
1815
+ ),
1816
+ children: [
1817
+ showReorderHandle ? /* @__PURE__ */ jsx(
1818
+ TableColumnDragHandle,
1819
+ {
1820
+ className: "shrink-0 self-center",
1821
+ columnId: id,
1822
+ previewLabel: getColumnHeaderLabel(header),
1823
+ onDragStart: onDragStartReorder,
1824
+ onDragEnd: endColumnDrag
1825
+ }
1826
+ ) : null,
1827
+ header.isPlaceholder ? null : canSort ? /* @__PURE__ */ jsxs(Fragment, { children: [
1828
+ /* @__PURE__ */ jsxs("span", { className: "inline-flex w-max min-w-0 max-w-full shrink-0 items-center gap-1", children: [
1829
+ /* @__PURE__ */ jsx(
1830
+ "button",
1831
+ {
1832
+ type: "button",
1833
+ className: "text-primary hover:text-primary/90 m-0 min-h-10 min-w-0 max-w-full cursor-pointer truncate border-0 bg-transparent py-0 pr-0 pl-0 text-left text-sm font-bold leading-snug md:min-h-12",
1834
+ onClick: runSort,
1835
+ children: flexRender(
1836
+ header.column.columnDef.header,
1837
+ header.getContext()
1838
+ )
1839
+ }
1840
+ ),
1841
+ /* @__PURE__ */ jsx(
1842
+ TableHeaderSortControl,
1843
+ {
1844
+ activeSort: isSorted === "asc" || isSorted === "desc" ? isSorted : null,
1845
+ onRequest: runSort
1846
+ }
1847
+ )
1848
+ ] }),
1849
+ /* @__PURE__ */ jsx(
1850
+ "button",
1851
+ {
1852
+ type: "button",
1853
+ className: "m-0 min-h-10 min-w-0 flex-1 cursor-pointer self-stretch border-0 bg-transparent p-0 shadow-none md:min-h-12 focus-visible:ring-2 focus-visible:ring-primary/20 focus-visible:ring-offset-0",
1854
+ "aria-label": "Change sort",
1855
+ title: "Change sort",
1856
+ onClick: runSort
1857
+ }
1858
+ )
1859
+ ] }) : /* @__PURE__ */ jsx("span", { className: "min-w-0 flex-1 self-center text-left", children: flexRender(header.column.columnDef.header, header.getContext()) })
1860
+ ]
1861
+ }
1862
+ )
1863
+ }
1864
+ );
1865
+ },
1866
+ (prev, next) => {
1867
+ if (prev.header.id !== next.header.id) return false;
1868
+ if (prev.header.column.getIsResizing() !== next.header.column.getIsResizing()) {
1869
+ return false;
1870
+ }
1871
+ if (prev.header.column.getIsSorted() !== next.header.column.getIsSorted()) {
1872
+ return false;
1873
+ }
1874
+ if (prev.header.getSize() !== next.header.getSize()) return false;
1875
+ if (prev.header.column.getIsPinned() !== next.header.column.getIsPinned()) {
1876
+ return false;
1877
+ }
1878
+ if (prev.header.isPlaceholder !== next.header.isPlaceholder) return false;
1879
+ if (getTableViewColumnDisableReorder(prev.header.column) !== getTableViewColumnDisableReorder(next.header.column)) {
1880
+ return false;
1881
+ }
1882
+ if (prev.options.columnSort !== next.options.columnSort) return false;
1883
+ if (prev.options.columnReorder !== next.options.columnReorder) return false;
1884
+ if (prev.options.columnResize !== next.options.columnResize) return false;
1885
+ if (prev.options.columnHeaderMenu !== next.options.columnHeaderMenu) {
1886
+ return false;
1887
+ }
1888
+ if (prev.getColumnMinClassName !== next.getColumnMinClassName) {
1889
+ return false;
1890
+ }
1891
+ if (prev.draggedId !== next.draggedId) {
1892
+ return false;
1893
+ }
1894
+ if (prev.table !== next.table) return false;
1895
+ if (prev.onHeaderCellDragOver !== next.onHeaderCellDragOver) return false;
1896
+ if (prev.onHeaderCellDrop !== next.onHeaderCellDrop) return false;
1897
+ if (prev.onHeaderContextMenu !== next.onHeaderContextMenu) return false;
1898
+ if (prev.setDraggedId !== next.setDraggedId) return false;
1899
+ if (prev.setDropTargetId !== next.setDropTargetId) return false;
1900
+ if (prev.endColumnDrag !== next.endColumnDrag) return false;
1901
+ if (prev.registerColumnMenu !== next.registerColumnMenu) return false;
1902
+ return true;
1903
+ }
1904
+ );
1905
+ var TableViewDataRow = React5.memo(function TableViewDataRow2({
1906
+ row,
1907
+ getColumnMinClassName,
1908
+ options,
1909
+ isLastRow
1910
+ }) {
1911
+ return /* @__PURE__ */ jsxs(
1912
+ TableRow,
1913
+ {
1914
+ className: "relative isolate",
1915
+ "data-state": row.getIsSelected() ? "selected" : void 0,
1916
+ children: [
1917
+ options.rowSelection ? /* @__PURE__ */ jsx(
1918
+ TableCell,
1919
+ {
1920
+ className: cn(
1921
+ "w-10 min-w-10 max-w-12 shrink-0 !px-2 !py-3 text-center align-middle md:!px-2.5 md:!py-4",
1922
+ isLastRow && tableViewColumnRoundBottom
1923
+ ),
1924
+ onClick: (e) => e.stopPropagation(),
1925
+ children: /* @__PURE__ */ jsx("span", { className: "inline-flex w-full items-center justify-center", children: /* @__PURE__ */ jsx(
1926
+ Checkbox,
1927
+ {
1928
+ className: "scale-90",
1929
+ checked: row.getIsSelected(),
1930
+ disabled: !row.getCanSelect(),
1931
+ onCheckedChange: (next) => {
1932
+ if (!row.getCanSelect()) return;
1933
+ row.toggleSelected(!!next);
1934
+ },
1935
+ "aria-label": "Select this row"
1936
+ }
1937
+ ) })
1938
+ }
1939
+ ) : null,
1940
+ row.getVisibleCells().map((cell) => {
1941
+ const cid = cell.column.id;
1942
+ const cSize = cell.column.getSize();
1943
+ const cellPin = getColumnPinningStyle(cell.column);
1944
+ const cellSize = options.columnResize ? {
1945
+ width: cSize,
1946
+ minWidth: cell.column.columnDef.minSize,
1947
+ maxWidth: cell.column.columnDef.maxSize
1948
+ } : {};
1949
+ return /* @__PURE__ */ jsx(
1950
+ TableCell,
1951
+ {
1952
+ columnId: cid,
1953
+ className: cn(
1954
+ !options.columnResize ? getColumnMinClassName?.(cid) : void 0,
1955
+ getColumnPinningClassName(cell.column),
1956
+ isLastRow && tableViewColumnRoundBottom
1957
+ ),
1958
+ style: { ...cellPin, ...cellSize },
1959
+ children: flexRender(cell.column.columnDef.cell, cell.getContext())
1960
+ },
1961
+ cell.id
1962
+ );
1963
+ })
1964
+ ]
1965
+ }
1966
+ );
1967
+ });
1968
+ function TableView({
1969
+ table,
1970
+ sortableColumnIds: sortableColumns,
1971
+ options: optionsProp,
1972
+ getColumnMinClassName,
1973
+ containerClassName,
1974
+ persistKey
1975
+ }) {
1976
+ const options = useMemo(
1977
+ () => ({
1978
+ columnSort: optionsProp?.columnSort ?? true,
1979
+ columnReorder: optionsProp?.columnReorder ?? false,
1980
+ columnResize: optionsProp?.columnResize ?? false,
1981
+ rowSelection: optionsProp?.rowSelection ?? false,
1982
+ columnHeaderMenu: optionsProp?.columnHeaderMenu ?? false
1983
+ }),
1984
+ [
1985
+ optionsProp?.columnSort,
1986
+ optionsProp?.columnReorder,
1987
+ optionsProp?.columnResize,
1988
+ optionsProp?.rowSelection,
1989
+ optionsProp?.columnHeaderMenu
1990
+ ]
1991
+ );
1992
+ useTableViewPersistence(table, persistKey, {
1993
+ columnResize: options.columnResize,
1994
+ columnHeaderMenu: options.columnHeaderMenu
1995
+ });
1996
+ const [draggedId, setDraggedId] = useState(null);
1997
+ const [dropTargetId, setDropTargetId] = useState(null);
1998
+ const columnMenuByIdRef = useRef({});
1999
+ const tableForMenu = table;
2000
+ const endColumnDrag = useCallback(() => {
2001
+ setDraggedId(null);
2002
+ setDropTargetId(null);
2003
+ }, []);
2004
+ const onDragOverCell = useCallback(
2005
+ (e) => e.preventDefault(),
2006
+ []
2007
+ );
2008
+ const onHeaderContextMenu = useCallback(
2009
+ (e) => {
2010
+ const t = e.currentTarget;
2011
+ const colId = t.getAttribute("data-column-id");
2012
+ if (!colId) return;
2013
+ e.preventDefault();
2014
+ e.stopPropagation();
2015
+ columnMenuByIdRef.current[colId]?.open();
2016
+ },
2017
+ []
2018
+ );
2019
+ const onHeaderCellDrop = useCallback(
2020
+ (e) => {
2021
+ e.preventDefault();
2022
+ const toId = e.currentTarget.getAttribute("data-column-id");
2023
+ if (!toId) return;
2024
+ const from = e.dataTransfer.getData("text/plain");
2025
+ if (!from || from === toId) return;
2026
+ table.setColumnOrder((o) => moveColumnInOrder([...o], from, toId));
2027
+ endColumnDrag();
2028
+ },
2029
+ [table, endColumnDrag]
2030
+ );
2031
+ const onHeaderCellDragOver = useCallback(
2032
+ (e) => {
2033
+ onDragOverCell(e);
2034
+ if (!options.columnReorder || !draggedId) return;
2035
+ const colId = e.currentTarget.getAttribute("data-column-id");
2036
+ if (colId) setDropTargetId(colId);
2037
+ },
2038
+ [onDragOverCell, options.columnReorder, draggedId, setDropTargetId]
2039
+ );
2040
+ const registerColumnMenu = useCallback(
2041
+ (columnId, h) => {
2042
+ if (h) columnMenuByIdRef.current[columnId] = h;
2043
+ else delete columnMenuByIdRef.current[columnId];
2044
+ },
2045
+ []
2046
+ );
2047
+ const sortableForTable = useMemo(
2048
+ () => options.columnSort ? sortableColumns : EMPTY_STRING_ARRAY,
2049
+ [options.columnSort, sortableColumns]
2050
+ );
2051
+ const columnDragState = useMemo(
2052
+ () => options.columnReorder ? { draggingId: draggedId, dropTargetId } : null,
2053
+ [options.columnReorder, draggedId, dropTargetId]
2054
+ );
2055
+ const pageRows = table.getRowModel().rows;
2056
+ const dataRowOptions = useMemo(
2057
+ () => ({
2058
+ columnResize: options.columnResize,
2059
+ rowSelection: options.rowSelection
2060
+ }),
2061
+ [options.columnResize, options.rowSelection]
2062
+ );
2063
+ return /* @__PURE__ */ jsxs(
2064
+ Table,
2065
+ {
2066
+ className: "border-separate border-spacing-0",
2067
+ sortableColumns: sortableForTable,
2068
+ enableColumnSort: options.columnSort,
2069
+ enableColumnReorder: options.columnReorder,
2070
+ enableColumnResize: options.columnResize,
2071
+ columnDragState,
2072
+ containerClassName: containerClassName ?? "min-w-0",
2073
+ children: [
2074
+ /* @__PURE__ */ jsx(TableHeader, { children: table.getHeaderGroups().map((headerGroup) => {
2075
+ const allPageSelected = table.getIsAllPageRowsSelected();
2076
+ const somePageSelected = table.getIsSomePageRowsSelected();
2077
+ return /* @__PURE__ */ jsxs(TableRow, { className: "relative isolate", children: [
2078
+ options.rowSelection ? /* @__PURE__ */ jsx(
2079
+ TableHead,
2080
+ {
2081
+ className: cn(
2082
+ "w-10 min-w-10 max-w-12 shrink-0 !px-2 text-center align-middle md:!px-2.5",
2083
+ tableViewColumnRoundTop
2084
+ ),
2085
+ onDragOver: onDragOverCell,
2086
+ scope: "col",
2087
+ children: /* @__PURE__ */ jsx("span", { className: "inline-flex w-full items-center justify-center", children: /* @__PURE__ */ jsx(
2088
+ Checkbox,
2089
+ {
2090
+ className: "scale-90",
2091
+ checked: allPageSelected,
2092
+ indeterminate: !allPageSelected && somePageSelected,
2093
+ onClick: (e) => {
2094
+ e.stopPropagation();
2095
+ table.getToggleAllPageRowsSelectedHandler()(e);
2096
+ e.preventDefault();
2097
+ },
2098
+ title: "Select all on this page",
2099
+ "aria-label": "Select all rows on this page"
2100
+ }
2101
+ ) })
2102
+ }
2103
+ ) : null,
2104
+ headerGroup.headers.map((header) => /* @__PURE__ */ jsx(
2105
+ TableViewColumnHead,
2106
+ {
2107
+ table: tableForMenu,
2108
+ header,
2109
+ options,
2110
+ getColumnMinClassName,
2111
+ draggedId,
2112
+ onHeaderCellDragOver,
2113
+ onHeaderCellDrop,
2114
+ onHeaderContextMenu,
2115
+ setDraggedId,
2116
+ setDropTargetId,
2117
+ endColumnDrag,
2118
+ registerColumnMenu
2119
+ },
2120
+ header.id
2121
+ ))
2122
+ ] }, headerGroup.id);
2123
+ }) }),
2124
+ /* @__PURE__ */ jsx(TableBody, { children: pageRows.map((row, rowIndex) => /* @__PURE__ */ jsx(
2125
+ TableViewDataRow,
2126
+ {
2127
+ row,
2128
+ getColumnMinClassName,
2129
+ options: dataRowOptions,
2130
+ isLastRow: rowIndex === pageRows.length - 1
2131
+ },
2132
+ row.id
2133
+ )) })
2134
+ ]
2135
+ }
2136
+ );
2137
+ }
2138
+ /*! Bundled license information:
2139
+
2140
+ @tanstack/react-table/build/lib/index.mjs:
2141
+ (**
2142
+ * react-table
2143
+ *
2144
+ * Copyright (c) TanStack
2145
+ *
2146
+ * This source code is licensed under the MIT license found in the
2147
+ * LICENSE.md file in the root directory of this source tree.
2148
+ *
2149
+ * @license MIT
2150
+ *)
2151
+ */
2152
+
2153
+ export { TABLE_VIEW_PERSIST_STORAGE_KEY, TableView, getColumnHeaderLabel, getSelectedRowIds, moveColumnInOrder, useRafBatchedColumnSizing, useTransitionColumnSizing };
2154
+ //# sourceMappingURL=index.js.map
2155
+ //# sourceMappingURL=index.js.map