@platned/ui 0.9.2 → 0.9.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,3463 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/data-table.tsx
31
+ var data_table_exports = {};
32
+ __export(data_table_exports, {
33
+ DataTable: () => DataTable,
34
+ DataTableColumnHeader: () => DataTableColumnHeader,
35
+ DataTablePagination: () => DataTablePagination,
36
+ DataTableViewOptions: () => DataTableViewOptions,
37
+ SELECT_COLUMN_ID: () => SELECT_COLUMN_ID,
38
+ TableCellBadge: () => TableCellBadge,
39
+ TableCellLeadText: () => TableCellLeadText,
40
+ TableCellProgress: () => TableCellProgress,
41
+ TableCellText: () => TableCellText,
42
+ createColumnHelper: () => import_react_table2.createColumnHelper,
43
+ createSelectColumn: () => createSelectColumn
44
+ });
45
+ module.exports = __toCommonJS(data_table_exports);
46
+
47
+ // src/components/lists/data-table.tsx
48
+ var import_react24 = require("react");
49
+ var import_clsx18 = __toESM(require("clsx"), 1);
50
+ var import_react_table = require("@tanstack/react-table");
51
+
52
+ // src/lib/cn.ts
53
+ var import_clsx = require("clsx");
54
+ var import_tailwind_merge = require("tailwind-merge");
55
+ var FONT_SIZES = [
56
+ "body-micro",
57
+ "body-tiny",
58
+ "body-xs",
59
+ "body-sm",
60
+ "body",
61
+ "body-lg",
62
+ "heading-sm",
63
+ "heading",
64
+ "heading-lg",
65
+ "subheading-sm",
66
+ "subheading",
67
+ "subheading-lg",
68
+ "subtitle-sm",
69
+ "subtitle",
70
+ "subtitle-lg",
71
+ "title-sm",
72
+ "title",
73
+ "title-lg",
74
+ "title-hero",
75
+ "scale-01",
76
+ "scale-02",
77
+ "scale-03",
78
+ "scale-04",
79
+ "scale-05",
80
+ "scale-06",
81
+ "scale-07",
82
+ "scale-08",
83
+ "scale-09",
84
+ "scale-10",
85
+ "scale-12"
86
+ ];
87
+ var twMerge = (0, import_tailwind_merge.extendTailwindMerge)({
88
+ extend: {
89
+ classGroups: {
90
+ "font-size": [{ text: [...FONT_SIZES] }]
91
+ }
92
+ }
93
+ });
94
+ function cn(...inputs) {
95
+ return twMerge((0, import_clsx.clsx)(inputs));
96
+ }
97
+
98
+ // src/lib/dev-warn.ts
99
+ var seen = /* @__PURE__ */ new Set();
100
+ function devWarn(message) {
101
+ const env = globalThis.process?.env?.NODE_ENV;
102
+ if (env === "production" || seen.has(message)) return;
103
+ seen.add(message);
104
+ console.warn(`[@platned/ui] ${message}`);
105
+ }
106
+
107
+ // src/lib/focus-ring.ts
108
+ var FOCUS_RING = "focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-brand focus-visible:ring-offset-1 focus-visible:ring-offset-default";
109
+ var FOCUS_RING_INSET = "focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-brand";
110
+
111
+ // src/lib/scrollbar.ts
112
+ var import_clsx2 = __toESM(require("clsx"), 1);
113
+ var SCROLLBAR_CLASSES = (0, import_clsx2.default)(
114
+ // Firefox and the standard property.
115
+ "[scrollbar-color:var(--color-background-default-tertiary)_transparent] [scrollbar-width:thin]",
116
+ // WebKit/Blink.
117
+ "[&::-webkit-scrollbar]:size-2",
118
+ "[&::-webkit-scrollbar-track]:bg-transparent",
119
+ "[&::-webkit-scrollbar-thumb]:rounded-full [&::-webkit-scrollbar-thumb]:bg-default-tertiary",
120
+ "[&::-webkit-scrollbar-thumb:hover]:bg-neutral-secondary",
121
+ "[&::-webkit-scrollbar-corner]:bg-transparent"
122
+ );
123
+
124
+ // src/lib/use-element-width.ts
125
+ var import_react = require("react");
126
+ var useIsomorphicLayoutEffect = typeof window === "undefined" ? import_react.useEffect : import_react.useLayoutEffect;
127
+ function useElementWidth() {
128
+ const [node, setNode] = (0, import_react.useState)(null);
129
+ const [width, setWidth] = (0, import_react.useState)(void 0);
130
+ useIsomorphicLayoutEffect(() => {
131
+ if (!node) return;
132
+ const apply = (next) => {
133
+ if (next <= 0) return;
134
+ setWidth((prev) => prev !== void 0 && Math.abs(prev - next) < 1 ? prev : next);
135
+ };
136
+ apply(node.getBoundingClientRect().width);
137
+ if (typeof ResizeObserver === "undefined") return;
138
+ const observer = new ResizeObserver((entries) => {
139
+ const entry = entries[0];
140
+ if (entry) apply(entry.contentRect.width);
141
+ });
142
+ observer.observe(node);
143
+ return () => observer.disconnect();
144
+ }, [node]);
145
+ return [setNode, width];
146
+ }
147
+
148
+ // src/components/feedback/empty-state.tsx
149
+ var import_clsx3 = __toESM(require("clsx"), 1);
150
+ var import_jsx_runtime = require("react/jsx-runtime");
151
+ var SIZES = {
152
+ sm: "py-8",
153
+ md: "py-12",
154
+ lg: "py-16"
155
+ };
156
+ var TONES = {
157
+ empty: "text-default-secondary",
158
+ loading: "text-default-secondary",
159
+ error: "text-danger"
160
+ };
161
+ function EmptyState({
162
+ message,
163
+ variant = "empty",
164
+ size: size2 = "sm",
165
+ icon,
166
+ action,
167
+ className
168
+ }) {
169
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
170
+ "div",
171
+ {
172
+ "data-variant": variant,
173
+ className: (0, import_clsx3.default)(
174
+ "flex flex-col items-center justify-center gap-2 px-4 text-center text-body-sm",
175
+ SIZES[size2],
176
+ TONES[variant],
177
+ className
178
+ ),
179
+ "aria-live": variant === "empty" ? void 0 : "polite",
180
+ children: [
181
+ icon && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "text-default-tertiary", children: icon }),
182
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { children: message }),
183
+ action
184
+ ]
185
+ }
186
+ );
187
+ }
188
+
189
+ // src/components/feedback/skeleton.tsx
190
+ var import_react2 = require("react");
191
+ var import_clsx4 = __toESM(require("clsx"), 1);
192
+ var import_jsx_runtime2 = require("react/jsx-runtime");
193
+ var SHAPE = {
194
+ line: "h-4 rounded",
195
+ block: "h-full w-full rounded-lg",
196
+ circle: "aspect-square rounded-full"
197
+ };
198
+ var Skeleton = (0, import_react2.forwardRef)(function Skeleton2({ shape = "line", lines = 1, className, ...rest }, ref) {
199
+ if (shape === "line" && lines > 1) {
200
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { ref, "aria-hidden": true, "data-slot": "skeleton-group", className: "flex flex-col gap-2", ...rest, children: Array.from({ length: lines }, (_, index) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
201
+ "div",
202
+ {
203
+ className: (0, import_clsx4.default)(
204
+ "motion-safe:animate-pulse bg-default-tertiary",
205
+ SHAPE.line,
206
+ // A ragged last line reads as a paragraph rather than a solid slab.
207
+ index === lines - 1 ? "w-3/5" : "w-full",
208
+ className
209
+ )
210
+ },
211
+ index
212
+ )) });
213
+ }
214
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
215
+ "div",
216
+ {
217
+ ref,
218
+ "aria-hidden": true,
219
+ "data-slot": "skeleton",
220
+ className: (0, import_clsx4.default)("motion-safe:animate-pulse bg-default-tertiary", SHAPE[shape], className),
221
+ ...rest
222
+ }
223
+ );
224
+ });
225
+
226
+ // src/components/forms/button.tsx
227
+ var import_react6 = require("react");
228
+ var import_clsx7 = __toESM(require("clsx"), 1);
229
+
230
+ // src/lib/slot.tsx
231
+ var import_react3 = require("react");
232
+ var import_clsx5 = __toESM(require("clsx"), 1);
233
+ var Slot = (0, import_react3.forwardRef)(function Slot2({ children, wrapChildren, ...slotProps }, forwardedRef) {
234
+ if (!(0, import_react3.isValidElement)(children)) return null;
235
+ const child = children;
236
+ const merged = {
237
+ ...mergeProps(slotProps, child.props),
238
+ ref: composeRefs(forwardedRef, getElementRef(child))
239
+ };
240
+ return wrapChildren ? (0, import_react3.cloneElement)(child, merged, wrapChildren(child.props.children)) : (0, import_react3.cloneElement)(child, merged);
241
+ });
242
+ function mergeProps(slotProps, childProps) {
243
+ const merged = { ...slotProps };
244
+ for (const key in childProps) {
245
+ const slotValue = slotProps[key];
246
+ const childValue = childProps[key];
247
+ if (/^on[A-Z]/.test(key)) {
248
+ if (typeof slotValue === "function" && typeof childValue === "function") {
249
+ merged[key] = (...args) => {
250
+ slotValue(...args);
251
+ childValue(...args);
252
+ };
253
+ } else {
254
+ merged[key] = childValue ?? slotValue;
255
+ }
256
+ } else if (key === "className") {
257
+ merged[key] = (0, import_clsx5.default)(slotValue, childValue);
258
+ } else if (key === "style") {
259
+ merged[key] = { ...slotValue, ...childValue };
260
+ } else {
261
+ merged[key] = childValue;
262
+ }
263
+ }
264
+ return merged;
265
+ }
266
+ function getElementRef(element) {
267
+ const asRecord = element;
268
+ return asRecord.props?.ref ?? asRecord.ref;
269
+ }
270
+ function composeRefs(...refs) {
271
+ return (node) => {
272
+ for (const ref of refs) {
273
+ if (!ref) continue;
274
+ if (typeof ref === "function") {
275
+ ref(node);
276
+ } else {
277
+ ref.current = node;
278
+ }
279
+ }
280
+ };
281
+ }
282
+
283
+ // src/components/feedback/spinner.tsx
284
+ var import_react4 = require("react");
285
+ var import_clsx6 = __toESM(require("clsx"), 1);
286
+ var import_jsx_runtime3 = require("react/jsx-runtime");
287
+ var SIZE = {
288
+ xs: "size-3 border",
289
+ sm: "size-4 border-[1.5px]",
290
+ md: "size-5 border-2",
291
+ lg: "size-8 border-2"
292
+ };
293
+ var Spinner = (0, import_react4.forwardRef)(function Spinner2({ size: size2 = "sm", label, className, ...rest }, ref) {
294
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
295
+ "span",
296
+ {
297
+ ref,
298
+ role: label ? "status" : void 0,
299
+ "aria-label": label,
300
+ "aria-hidden": label ? void 0 : true,
301
+ className: (0, import_clsx6.default)(
302
+ "inline-block shrink-0 rounded-full motion-safe:animate-spin motion-reduce:animate-pulse",
303
+ "border-current border-t-transparent",
304
+ SIZE[size2],
305
+ className
306
+ ),
307
+ ...rest
308
+ }
309
+ );
310
+ });
311
+
312
+ // src/components/forms/control-size.tsx
313
+ var import_react5 = require("react");
314
+ var import_jsx_runtime4 = require("react/jsx-runtime");
315
+ var ControlSizeContext = (0, import_react5.createContext)(null);
316
+ function useControlSize(explicit) {
317
+ const inherited = (0, import_react5.useContext)(ControlSizeContext);
318
+ return explicit ?? inherited ?? "md";
319
+ }
320
+
321
+ // src/components/forms/button.tsx
322
+ var import_jsx_runtime5 = require("react/jsx-runtime");
323
+ var variantStyles = {
324
+ primary: (0, import_clsx7.default)(
325
+ "bg-brand border border-brand text-brand-on-brand",
326
+ "hover:bg-brand-hover",
327
+ "disabled:bg-disabled disabled:border-disabled disabled:text-disabled-on-disabled",
328
+ "aria-disabled:bg-disabled aria-disabled:border-disabled aria-disabled:text-disabled-on-disabled"
329
+ ),
330
+ neutral: (0, import_clsx7.default)(
331
+ "bg-default border border-default text-default",
332
+ "hover:bg-default-hover hover:text-brand",
333
+ "disabled:bg-disabled disabled:border-disabled disabled:text-disabled-on-disabled",
334
+ "aria-disabled:bg-disabled aria-disabled:border-disabled aria-disabled:text-disabled-on-disabled"
335
+ ),
336
+ subtle: (0, import_clsx7.default)(
337
+ // border-transparent holds space so hover border doesn't shift layout
338
+ "bg-transparent border border-transparent text-neutral",
339
+ "hover:border-default hover:text-brand",
340
+ "disabled:bg-disabled disabled:border-disabled disabled:text-disabled-on-disabled",
341
+ "aria-disabled:bg-disabled aria-disabled:border-disabled aria-disabled:text-disabled-on-disabled"
342
+ ),
343
+ danger: (0, import_clsx7.default)(
344
+ "bg-danger border border-danger-secondary text-danger-on-danger",
345
+ // border shifts from danger-secondary → danger-default on hover (Figma spec)
346
+ "hover:bg-danger-hover hover:border-danger",
347
+ "disabled:bg-disabled disabled:border-disabled disabled:text-disabled-on-disabled",
348
+ "aria-disabled:bg-disabled aria-disabled:border-disabled aria-disabled:text-disabled-on-disabled"
349
+ ),
350
+ "danger-subtle": (0, import_clsx7.default)(
351
+ // border-transparent base avoids layout shift when hover border appears
352
+ "bg-transparent border border-transparent text-danger",
353
+ "hover:bg-danger-tertiary-hover hover:border-danger",
354
+ "disabled:bg-disabled disabled:border-disabled disabled:text-disabled-on-disabled",
355
+ "aria-disabled:bg-disabled aria-disabled:border-disabled aria-disabled:text-disabled-on-disabled"
356
+ )
357
+ };
358
+ var sizeStyles = {
359
+ lg: "h-12 px-3 gap-1 rounded-2xl text-body font-semibold [&_svg]:size-5",
360
+ md: "h-9 px-2 gap-0.5 rounded-lg text-body-sm font-semibold [&_svg]:size-5",
361
+ sm: "h-6 px-1.5 pt-0.5 gap-0 rounded-full text-body-tiny font-semibold [&_svg]:size-4"
362
+ };
363
+ var SPINNER_SIZE = {
364
+ lg: "md",
365
+ md: "sm",
366
+ sm: "sm"
367
+ };
368
+ var Button = (0, import_react6.forwardRef)(function Button2({
369
+ variant = "primary",
370
+ size: sizeProp,
371
+ leadingIcon,
372
+ trailingIcon,
373
+ asChild = false,
374
+ loading = false,
375
+ loadingLabel,
376
+ disabled,
377
+ type,
378
+ children,
379
+ className,
380
+ onClick,
381
+ ...props
382
+ }, ref) {
383
+ const size2 = useControlSize(sizeProp);
384
+ const softDisabled = loading || asChild && Boolean(disabled);
385
+ const handleClick = (event) => {
386
+ if (softDisabled) {
387
+ event.preventDefault();
388
+ event.stopPropagation();
389
+ return;
390
+ }
391
+ onClick?.(event);
392
+ };
393
+ const decorate = (content) => /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(import_jsx_runtime5.Fragment, { children: [
394
+ loading ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Spinner, { size: SPINNER_SIZE[size2], label: loadingLabel }) : leadingIcon,
395
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "px-1", children: content }),
396
+ trailingIcon
397
+ ] });
398
+ const rootProps = {
399
+ // `cn`, so a caller's `className` (say `rounded-full`) beats the size's radius.
400
+ className: cn(
401
+ "inline-flex items-center justify-center whitespace-nowrap transition-colors",
402
+ FOCUS_RING,
403
+ "disabled:cursor-not-allowed aria-disabled:cursor-not-allowed",
404
+ variantStyles[variant],
405
+ sizeStyles[size2],
406
+ className
407
+ ),
408
+ "aria-busy": loading || void 0,
409
+ "data-variant": variant,
410
+ "data-size": size2,
411
+ "aria-disabled": softDisabled || void 0,
412
+ onClick: handleClick,
413
+ ...props
414
+ };
415
+ if (asChild) {
416
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
417
+ Slot,
418
+ {
419
+ ref,
420
+ wrapChildren: decorate,
421
+ tabIndex: disabled ? -1 : void 0,
422
+ ...rootProps,
423
+ children
424
+ }
425
+ );
426
+ }
427
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
428
+ "button",
429
+ {
430
+ ref,
431
+ type: type ?? "button",
432
+ disabled,
433
+ ...rootProps,
434
+ children: decorate(children)
435
+ }
436
+ );
437
+ });
438
+
439
+ // src/components/forms/input-group.tsx
440
+ var import_react8 = require("react");
441
+ var import_clsx8 = __toESM(require("clsx"), 1);
442
+ var import_lucide_react = require("lucide-react");
443
+
444
+ // src/components/forms/field.tsx
445
+ var import_react7 = require("react");
446
+ var import_jsx_runtime6 = require("react/jsx-runtime");
447
+ var FieldContext = (0, import_react7.createContext)(null);
448
+ function useFieldContext() {
449
+ return (0, import_react7.useContext)(FieldContext);
450
+ }
451
+ function useFieldControl() {
452
+ const field = useFieldContext();
453
+ if (!field) {
454
+ return {
455
+ id: void 0,
456
+ "aria-describedby": void 0,
457
+ "aria-invalid": void 0,
458
+ "aria-required": void 0,
459
+ disabled: void 0
460
+ };
461
+ }
462
+ const describedBy = [
463
+ field.hasDescription && field.descriptionId,
464
+ field.hasError && field.errorId,
465
+ field.hasHint && !field.hasError && field.hintId
466
+ ].filter(Boolean).join(" ");
467
+ return {
468
+ id: field.controlId,
469
+ "aria-describedby": describedBy || void 0,
470
+ "aria-invalid": field.invalid || void 0,
471
+ "aria-required": field.required || void 0,
472
+ disabled: field.disabled || void 0
473
+ };
474
+ }
475
+ var GAP = {
476
+ lg: "gap-2",
477
+ md: "gap-1",
478
+ sm: "gap-0.5"
479
+ };
480
+ function Field({
481
+ children,
482
+ id,
483
+ size: size2 = "md",
484
+ invalid = false,
485
+ required = false,
486
+ disabled = false,
487
+ orientation = "vertical",
488
+ hasDescription = false,
489
+ hasError = false,
490
+ hasHint = false,
491
+ className,
492
+ ...rest
493
+ }) {
494
+ const generated = (0, import_react7.useId)();
495
+ const controlId = id ?? generated;
496
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
497
+ FieldContext.Provider,
498
+ {
499
+ value: {
500
+ controlId,
501
+ labelId: `${controlId}-label`,
502
+ descriptionId: `${controlId}-description`,
503
+ errorId: `${controlId}-error`,
504
+ hintId: `${controlId}-hint`,
505
+ hasDescription,
506
+ hasError,
507
+ hasHint,
508
+ invalid: invalid || hasError,
509
+ required,
510
+ disabled,
511
+ size: size2
512
+ },
513
+ children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
514
+ "div",
515
+ {
516
+ role: orientation === "horizontal" ? "group" : void 0,
517
+ "data-slot": "field",
518
+ "data-invalid": invalid || hasError || void 0,
519
+ "data-disabled": disabled || void 0,
520
+ className: cn(
521
+ orientation === "horizontal" ? "flex flex-row items-center justify-between gap-3" : cn("flex flex-col", GAP[size2]),
522
+ className
523
+ ),
524
+ ...rest,
525
+ children
526
+ }
527
+ )
528
+ }
529
+ );
530
+ }
531
+ var LABEL_TEXT = {
532
+ lg: "text-body",
533
+ md: "text-body-sm",
534
+ sm: "text-body-tiny"
535
+ };
536
+ function FieldLabel({ children, className, htmlFor, ...rest }) {
537
+ const field = useFieldContext();
538
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
539
+ "label",
540
+ {
541
+ id: field?.labelId,
542
+ htmlFor: htmlFor ?? field?.controlId,
543
+ "data-slot": "field-label",
544
+ className: cn(
545
+ LABEL_TEXT[field?.size ?? "md"],
546
+ field?.disabled ? "text-disabled" : "text-default",
547
+ // The required marker is CSS generated content, not a child element. An
548
+ // `<span aria-hidden>*</span>` would be correct for accessible-name computation
549
+ // (which skips aria-hidden) but it still lands in `textContent`, so every
550
+ // `getByLabelText('Name')` — ours and every consumer's — would have to become
551
+ // `/Name/`. Generated content is in neither, and the real signal is
552
+ // `aria-required` on the control regardless.
553
+ field?.required && "after:ml-0.5 after:text-danger after:content-['*']",
554
+ className
555
+ ),
556
+ ...rest,
557
+ children
558
+ }
559
+ );
560
+ }
561
+ function FieldDescription({ children, className, ...rest }) {
562
+ const field = useFieldContext();
563
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
564
+ "p",
565
+ {
566
+ id: field?.descriptionId,
567
+ "data-slot": "field-description",
568
+ className: cn(
569
+ LABEL_TEXT[field?.size ?? "md"],
570
+ field?.disabled ? "text-disabled" : "text-default-secondary",
571
+ className
572
+ ),
573
+ ...rest,
574
+ children
575
+ }
576
+ );
577
+ }
578
+ function FieldError({ children, className, ...rest }) {
579
+ const field = useFieldContext();
580
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
581
+ "p",
582
+ {
583
+ id: field?.errorId,
584
+ role: "alert",
585
+ "data-slot": "field-error",
586
+ className: cn(LABEL_TEXT[field?.size ?? "md"], "text-danger", className),
587
+ ...rest,
588
+ children
589
+ }
590
+ );
591
+ }
592
+ function FieldHint({ children, className, ...rest }) {
593
+ const field = useFieldContext();
594
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
595
+ "p",
596
+ {
597
+ id: field?.hintId,
598
+ "data-slot": "field-hint",
599
+ className: cn(LABEL_TEXT[field?.size ?? "md"], "text-default-secondary", className),
600
+ ...rest,
601
+ children
602
+ }
603
+ );
604
+ }
605
+ var FieldSet = (0, import_react7.forwardRef)(function FieldSet2({ children, className, ...rest }, ref) {
606
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
607
+ "fieldset",
608
+ {
609
+ ref,
610
+ "data-slot": "field-set",
611
+ className: cn("flex flex-col gap-3 border-0 p-0", className),
612
+ ...rest,
613
+ children
614
+ }
615
+ );
616
+ });
617
+
618
+ // src/components/forms/input-group.tsx
619
+ var import_jsx_runtime7 = require("react/jsx-runtime");
620
+ var HEIGHT = {
621
+ lg: "h-12 text-body",
622
+ md: "h-9 text-body-sm",
623
+ sm: "h-6 text-body-tiny"
624
+ };
625
+ var PAD = {
626
+ lg: "px-4 gap-2",
627
+ md: "px-3 gap-1.5",
628
+ sm: "px-2 gap-1"
629
+ };
630
+ var InputGroup = (0, import_react8.forwardRef)(function InputGroup2({ children, size: sizeProp, invalid = false, disabled = false, className, ...rest }, ref) {
631
+ const size2 = useControlSize(sizeProp);
632
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
633
+ "div",
634
+ {
635
+ ref,
636
+ "data-slot": "input-group",
637
+ "data-size": size2,
638
+ className: (0, import_clsx8.default)(
639
+ "flex w-full items-center rounded-lg border transition-colors",
640
+ "bg-default text-default",
641
+ HEIGHT[size2],
642
+ PAD[size2],
643
+ // `focus-within`, because the focused element is the nested input while the ring
644
+ // belongs to the shell.
645
+ "focus-within:ring-2 focus-within:ring-offset-1 focus-within:ring-offset-default",
646
+ disabled ? "cursor-not-allowed border-disabled bg-disabled text-disabled" : invalid ? "border-danger-secondary focus-within:border-danger focus-within:ring-danger" : "border-default focus-within:border-brand focus-within:ring-brand",
647
+ className
648
+ ),
649
+ ...rest,
650
+ children
651
+ }
652
+ );
653
+ });
654
+ var InputGroupInput = (0, import_react8.forwardRef)(
655
+ function InputGroupInput2({ className, ...props }, ref) {
656
+ const field = useFieldControl();
657
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
658
+ "input",
659
+ {
660
+ ref,
661
+ ...field,
662
+ className: (0, import_clsx8.default)(
663
+ "min-w-0 flex-1 bg-transparent outline-none",
664
+ "placeholder:text-default-tertiary",
665
+ "disabled:cursor-not-allowed disabled:text-disabled disabled:placeholder:text-disabled",
666
+ className
667
+ ),
668
+ ...props
669
+ }
670
+ );
671
+ }
672
+ );
673
+ var InputGroupAddon = (0, import_react8.forwardRef)(
674
+ function InputGroupAddon2({ children, align = "inline-start", decorative = true, className, ...rest }, ref) {
675
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
676
+ "span",
677
+ {
678
+ ref,
679
+ "aria-hidden": decorative || void 0,
680
+ "data-slot": "input-group-addon",
681
+ "data-align": align,
682
+ className: (0, import_clsx8.default)(
683
+ "flex shrink-0 items-center text-icon-default-secondary",
684
+ decorative && "pointer-events-none",
685
+ align === "inline-end" && "order-last",
686
+ className
687
+ ),
688
+ ...rest,
689
+ children
690
+ }
691
+ );
692
+ }
693
+ );
694
+ var InputGroupText = (0, import_react8.forwardRef)(
695
+ function InputGroupText2({ children, className, ...rest }, ref) {
696
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
697
+ "span",
698
+ {
699
+ ref,
700
+ className: (0, import_clsx8.default)("shrink-0 whitespace-nowrap text-default-secondary", className),
701
+ ...rest,
702
+ children
703
+ }
704
+ );
705
+ }
706
+ );
707
+ var SearchInput = (0, import_react8.forwardRef)(function SearchInput2({ size: sizeProp, onClear, label = "Search", disabled, value, className, ...props }, ref) {
708
+ const size2 = useControlSize(sizeProp);
709
+ const hasValue = value !== void 0 && value !== "";
710
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(InputGroup, { size: size2, disabled, className, children: [
711
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(InputGroupAddon, { children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_lucide_react.SearchIcon, { className: size2 === "sm" ? "size-3" : "size-4" }) }),
712
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
713
+ InputGroupInput,
714
+ {
715
+ ref,
716
+ type: "search",
717
+ "aria-label": label,
718
+ disabled,
719
+ value,
720
+ className: "[&::-webkit-search-cancel-button]:appearance-none",
721
+ ...props
722
+ }
723
+ ),
724
+ onClear && hasValue && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(InputGroupAddon, { align: "inline-end", decorative: false, children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
725
+ "button",
726
+ {
727
+ type: "button",
728
+ "aria-label": "Clear search",
729
+ onClick: onClear,
730
+ disabled,
731
+ className: "flex items-center justify-center rounded transition-colors hover:text-default focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-brand",
732
+ children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_lucide_react.XIcon, { "aria-hidden": true, className: size2 === "sm" ? "size-3" : "size-4" })
733
+ }
734
+ ) })
735
+ ] });
736
+ });
737
+
738
+ // src/components/lists/data-table-layout.ts
739
+ var DEFAULT_CARD_BREAKPOINT_PX = 560;
740
+ var LAYOUT_HYSTERESIS_PX = 24;
741
+ var FALLBACK_COLUMN_WIDTH_PX = 160;
742
+ function widthToPx(width) {
743
+ if (!width) return FALLBACK_COLUMN_WIDTH_PX;
744
+ const px = /^(\d+(?:\.\d+)?)px$/.exec(width);
745
+ if (px) return Number(px[1]);
746
+ const rem = /^(\d+(?:\.\d+)?)rem$/.exec(width);
747
+ if (rem) return Number(rem[1]) * 16;
748
+ return FALLBACK_COLUMN_WIDTH_PX;
749
+ }
750
+ function nextLayoutMode(current, widthPx, breakpointPx = DEFAULT_CARD_BREAKPOINT_PX) {
751
+ if (widthPx === void 0 || !Number.isFinite(widthPx) || widthPx <= 0) return current;
752
+ if (breakpointPx <= 0) return "table";
753
+ if (current === "table") return widthPx < breakpointPx - LAYOUT_HYSTERESIS_PX ? "cards" : "table";
754
+ return widthPx >= breakpointPx + LAYOUT_HYSTERESIS_PX ? "table" : "cards";
755
+ }
756
+ function cardSlots(columns) {
757
+ const title = columns.find((c) => c.mobile === "title") ?? columns[0];
758
+ const status = columns.find((c) => c.mobile === "status" && c !== title);
759
+ const actions = columns.find((c) => c.mobile === "actions" && c !== title);
760
+ const fields = columns.filter(
761
+ (c) => c !== title && c !== status && c !== actions && c.mobile !== "hidden"
762
+ );
763
+ return { title, status, actions, fields };
764
+ }
765
+
766
+ // src/components/lists/data-table-parts.tsx
767
+ var import_lucide_react7 = require("lucide-react");
768
+
769
+ // src/components/forms/checkbox.tsx
770
+ var import_react10 = require("react");
771
+ var import_clsx10 = __toESM(require("clsx"), 1);
772
+
773
+ // src/lib/use-controllable-state.ts
774
+ var import_react9 = require("react");
775
+ function useControllableState({
776
+ value,
777
+ defaultValue,
778
+ onChange
779
+ }) {
780
+ const [internal, setInternal] = (0, import_react9.useState)(defaultValue);
781
+ const isControlled = value !== void 0;
782
+ const current = isControlled ? value : internal;
783
+ const onChangeRef = (0, import_react9.useRef)(onChange);
784
+ onChangeRef.current = onChange;
785
+ const currentRef = (0, import_react9.useRef)(current);
786
+ currentRef.current = current;
787
+ const isControlledRef = (0, import_react9.useRef)(isControlled);
788
+ isControlledRef.current = isControlled;
789
+ const setValue = (0, import_react9.useCallback)((next) => {
790
+ const resolved = typeof next === "function" ? next(currentRef.current) : next;
791
+ if (resolved === currentRef.current) return;
792
+ if (!isControlledRef.current) setInternal(resolved);
793
+ onChangeRef.current?.(resolved);
794
+ }, []);
795
+ return [current, setValue];
796
+ }
797
+
798
+ // src/components/forms/check-control.tsx
799
+ var import_clsx9 = __toESM(require("clsx"), 1);
800
+ var import_lucide_react2 = require("lucide-react");
801
+ var import_jsx_runtime8 = require("react/jsx-runtime");
802
+ var CHECK_SIZE = {
803
+ sm: { box: "size-4", glyph: "size-2.5", dot: "size-1.5" },
804
+ md: { box: "size-[18px]", glyph: "size-3", dot: "size-2" }
805
+ };
806
+ function CheckControl({
807
+ type,
808
+ checked,
809
+ indeterminate = false,
810
+ disabled = false,
811
+ invalid = false,
812
+ size: size2 = "md"
813
+ }) {
814
+ const s = CHECK_SIZE[size2];
815
+ const on = checked || indeterminate;
816
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
817
+ "span",
818
+ {
819
+ "aria-hidden": true,
820
+ className: (0, import_clsx9.default)(
821
+ "mt-px flex shrink-0 items-center justify-center border-[1.5px] transition-colors",
822
+ s.box,
823
+ type === "radio" ? "rounded-full" : "rounded-[4px]",
824
+ // Ring is drawn from the peer input's focus state, so the visual box tracks real
825
+ // focus rather than hover.
826
+ "peer-focus-visible:ring-2 peer-focus-visible:ring-brand peer-focus-visible:ring-offset-1 peer-focus-visible:ring-offset-default",
827
+ disabled ? on ? "border-disabled bg-disabled text-disabled-on-disabled" : "border-disabled bg-disabled" : on ? "border-brand-emphasis bg-brand text-brand-on-brand" : invalid ? "border-danger bg-default" : "border-default-secondary bg-default"
828
+ ),
829
+ children: type === "checkbox" ? indeterminate ? /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_lucide_react2.MinusIcon, { className: s.glyph, strokeWidth: 3 }) : checked ? /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_lucide_react2.CheckIcon, { className: s.glyph, strokeWidth: 3 }) : null : checked ? /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: (0, import_clsx9.default)("rounded-full bg-current", s.dot) }) : null
830
+ }
831
+ );
832
+ }
833
+
834
+ // src/components/forms/checkbox.tsx
835
+ var import_jsx_runtime9 = require("react/jsx-runtime");
836
+ var LABEL_TEXT2 = {
837
+ sm: "text-body-tiny",
838
+ md: "text-body-xs"
839
+ };
840
+ var Checkbox = (0, import_react10.forwardRef)(function Checkbox2({
841
+ checked: checkedProp,
842
+ defaultChecked = false,
843
+ onCheckedChange,
844
+ label,
845
+ description,
846
+ size: size2 = "md",
847
+ indeterminate = false,
848
+ invalid = false,
849
+ disabled = false,
850
+ id,
851
+ className,
852
+ ...props
853
+ }, ref) {
854
+ const [checked, setChecked] = useControllableState({
855
+ value: checkedProp,
856
+ defaultValue: defaultChecked,
857
+ onChange: onCheckedChange
858
+ });
859
+ const inputRef = (0, import_react10.useRef)(null);
860
+ const generatedId = (0, import_react10.useId)();
861
+ const controlId = id ?? generatedId;
862
+ const descriptionId = `${controlId}-description`;
863
+ (0, import_react10.useEffect)(() => {
864
+ if (inputRef.current) inputRef.current.indeterminate = indeterminate;
865
+ }, [indeterminate]);
866
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("div", { className: (0, import_clsx10.default)("flex flex-col", className), children: [
867
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(
868
+ "label",
869
+ {
870
+ htmlFor: controlId,
871
+ className: (0, import_clsx10.default)(
872
+ // relative: the hidden input is absolutely positioned (sr-only). Without a positioned
873
+ // ancestor here its box lands far up the page, and focusing it on click scrolled a
874
+ // scrolling container to that spot, away from the control.
875
+ "group relative inline-flex items-start gap-2.5",
876
+ disabled ? "cursor-not-allowed opacity-60" : "cursor-pointer"
877
+ ),
878
+ children: [
879
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
880
+ "input",
881
+ {
882
+ ref: composeRefs(inputRef, ref),
883
+ id: controlId,
884
+ type: "checkbox",
885
+ checked,
886
+ disabled,
887
+ "aria-invalid": invalid || void 0,
888
+ "aria-describedby": description ? descriptionId : void 0,
889
+ onChange: (event) => setChecked(event.target.checked),
890
+ className: "peer sr-only",
891
+ ...props
892
+ }
893
+ ),
894
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
895
+ CheckControl,
896
+ {
897
+ type: "checkbox",
898
+ checked,
899
+ indeterminate,
900
+ disabled,
901
+ invalid,
902
+ size: size2
903
+ }
904
+ ),
905
+ label && /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("span", { className: (0, import_clsx10.default)(LABEL_TEXT2[size2], "min-w-0 text-default [overflow-wrap:anywhere]"), children: label })
906
+ ]
907
+ }
908
+ ),
909
+ description && /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
910
+ "span",
911
+ {
912
+ id: descriptionId,
913
+ className: (0, import_clsx10.default)(
914
+ "mt-0.5 pl-[26px] [overflow-wrap:anywhere]",
915
+ LABEL_TEXT2[size2],
916
+ disabled ? "text-disabled" : "text-default-secondary"
917
+ ),
918
+ children: description
919
+ }
920
+ )
921
+ ] });
922
+ });
923
+
924
+ // src/components/chrome/pagination.tsx
925
+ var import_react18 = require("react");
926
+ var import_clsx13 = __toESM(require("clsx"), 1);
927
+ var import_lucide_react4 = require("lucide-react");
928
+
929
+ // src/components/forms/select.tsx
930
+ var import_react17 = require("react");
931
+ var import_clsx12 = __toESM(require("clsx"), 1);
932
+ var import_lucide_react3 = require("lucide-react");
933
+
934
+ // src/lib/use-roving-focus.ts
935
+ var import_react11 = require("react");
936
+ function useRovingFocus({
937
+ orientation = "horizontal",
938
+ loop = true,
939
+ typeahead = false,
940
+ defaultIndex = 0,
941
+ onEscape
942
+ } = {}) {
943
+ const [activeIndex, setActiveIndex] = (0, import_react11.useState)(defaultIndex);
944
+ const items = (0, import_react11.useRef)([]);
945
+ const meta = (0, import_react11.useRef)([]);
946
+ const search = (0, import_react11.useRef)("");
947
+ const searchTimer = (0, import_react11.useRef)(null);
948
+ (0, import_react11.useEffect)(
949
+ () => () => {
950
+ if (searchTimer.current) clearTimeout(searchTimer.current);
951
+ },
952
+ []
953
+ );
954
+ const focusIndex = (0, import_react11.useCallback)((index) => {
955
+ const node = items.current[index];
956
+ if (!node) return;
957
+ setActiveIndex(index);
958
+ node.focus();
959
+ }, []);
960
+ const move = (0, import_react11.useCallback)(
961
+ (start, step) => {
962
+ const total = items.current.length;
963
+ if (total === 0) return;
964
+ for (let i = 1; i <= total; i++) {
965
+ let next = start + step * i;
966
+ if (loop) {
967
+ next = (next % total + total) % total;
968
+ } else if (next < 0 || next >= total) {
969
+ return;
970
+ }
971
+ if (items.current[next] && !meta.current[next]?.disabled) {
972
+ focusIndex(next);
973
+ return;
974
+ }
975
+ }
976
+ },
977
+ [loop, focusIndex]
978
+ );
979
+ const moveToEdge = (0, import_react11.useCallback)(
980
+ (from) => {
981
+ const total = items.current.length;
982
+ if (total === 0) return;
983
+ move(from === "start" ? -1 : total, from === "start" ? 1 : -1);
984
+ },
985
+ [move]
986
+ );
987
+ const runTypeahead = (0, import_react11.useCallback)(
988
+ (char) => {
989
+ if (searchTimer.current) clearTimeout(searchTimer.current);
990
+ search.current += char.toLowerCase();
991
+ searchTimer.current = setTimeout(() => {
992
+ search.current = "";
993
+ }, 500);
994
+ const total = items.current.length;
995
+ const query = search.current;
996
+ for (let i = 1; i <= total; i++) {
997
+ const index = (activeIndex + i) % total;
998
+ if (meta.current[index]?.disabled) continue;
999
+ const label = meta.current[index]?.label?.toLowerCase();
1000
+ if (label?.startsWith(query)) {
1001
+ focusIndex(index);
1002
+ return;
1003
+ }
1004
+ }
1005
+ },
1006
+ [activeIndex, focusIndex]
1007
+ );
1008
+ const onKeyDown = (0, import_react11.useCallback)(
1009
+ (event) => {
1010
+ const { key } = event;
1011
+ const vertical = orientation === "vertical" || orientation === "both";
1012
+ const horizontal = orientation === "horizontal" || orientation === "both";
1013
+ const next = vertical && key === "ArrowDown" || horizontal && key === "ArrowRight";
1014
+ const prev = vertical && key === "ArrowUp" || horizontal && key === "ArrowLeft";
1015
+ if (next || prev) {
1016
+ event.preventDefault();
1017
+ move(activeIndex, next ? 1 : -1);
1018
+ return;
1019
+ }
1020
+ if (key === "Home") {
1021
+ event.preventDefault();
1022
+ moveToEdge("start");
1023
+ return;
1024
+ }
1025
+ if (key === "End") {
1026
+ event.preventDefault();
1027
+ moveToEdge("end");
1028
+ return;
1029
+ }
1030
+ if (key === "Escape" && onEscape) {
1031
+ onEscape();
1032
+ return;
1033
+ }
1034
+ if (typeahead && key.length === 1 && key !== " " && !event.ctrlKey && !event.metaKey && !event.altKey) {
1035
+ event.preventDefault();
1036
+ runTypeahead(key);
1037
+ }
1038
+ },
1039
+ [orientation, activeIndex, move, moveToEdge, onEscape, typeahead, runTypeahead]
1040
+ );
1041
+ const itemProps = (0, import_react11.useCallback)(
1042
+ (index, options = {}) => {
1043
+ meta.current[index] = options;
1044
+ return {
1045
+ ref: (node) => {
1046
+ items.current[index] = node;
1047
+ },
1048
+ // The roving part: exactly one item is in the tab sequence, so Tab enters the
1049
+ // composite once and Tab again leaves it.
1050
+ tabIndex: index === activeIndex ? 0 : -1,
1051
+ onFocus: () => setActiveIndex(index),
1052
+ "data-roving-index": index
1053
+ };
1054
+ },
1055
+ [activeIndex]
1056
+ );
1057
+ return {
1058
+ activeIndex,
1059
+ setActiveIndex,
1060
+ focusIndex,
1061
+ moveToEdge,
1062
+ itemProps,
1063
+ containerProps: { onKeyDown }
1064
+ };
1065
+ }
1066
+
1067
+ // src/components/overlays/floating.tsx
1068
+ var import_react12 = require("react");
1069
+ var import_react13 = require("@floating-ui/react");
1070
+ function useFloatingPanel({
1071
+ open,
1072
+ onOpenChange,
1073
+ side = "bottom",
1074
+ align = "center",
1075
+ sideOffset = 6,
1076
+ alignOffset = 0,
1077
+ collisionPadding = 8,
1078
+ withArrow = false,
1079
+ matchAnchorWidth = false
1080
+ }) {
1081
+ const arrowRef = (0, import_react12.useRef)(null);
1082
+ const placement = align === "center" ? side : `${side}-${align}`;
1083
+ const floating = (0, import_react13.useFloating)({
1084
+ open,
1085
+ onOpenChange,
1086
+ placement,
1087
+ // `fixed`, not the default `absolute`: inside a Modal these panels portal into the
1088
+ // dialog's scrolling content (see `PortalContainerProvider`), and an absolutely
1089
+ // positioned panel there would be clipped by its overflow. Radix's Popper does the same.
1090
+ strategy: "fixed",
1091
+ // Only track while the panel is actually on screen. `autoUpdate` attaches scroll and
1092
+ // resize listeners plus a ResizeObserver, so leaving it running on a closed panel
1093
+ // would cost every consumer a listener per menu on the page.
1094
+ whileElementsMounted: import_react13.autoUpdate,
1095
+ middleware: [
1096
+ (0, import_react13.offset)({ mainAxis: sideOffset, crossAxis: alignOffset }),
1097
+ // `flip` before `shift`: try the opposite edge first, and only slide along the
1098
+ // current one if neither edge fits. The reverse order produces panels that cling to
1099
+ // the viewport edge when they had room to simply flip.
1100
+ (0, import_react13.flip)({ padding: collisionPadding }),
1101
+ (0, import_react13.shift)({ padding: collisionPadding }),
1102
+ matchAnchorWidth && (0, import_react13.size)({
1103
+ padding: collisionPadding,
1104
+ apply({ rects, elements, availableHeight }) {
1105
+ elements.floating.style.setProperty(
1106
+ "--panel-anchor-width",
1107
+ `${rects.reference.width}px`
1108
+ );
1109
+ elements.floating.style.setProperty(
1110
+ "--panel-available-height",
1111
+ `${availableHeight}px`
1112
+ );
1113
+ }
1114
+ }),
1115
+ withArrow && (0, import_react13.arrow)({ element: arrowRef, padding: 4 })
1116
+ ].filter(Boolean)
1117
+ });
1118
+ return { ...floating, arrowRef };
1119
+ }
1120
+
1121
+ // src/components/overlays/menu-styles.ts
1122
+ var import_clsx11 = __toESM(require("clsx"), 1);
1123
+ var OVERLAY_PANEL = "rounded-lg border border-default bg-default p-1 shadow-300";
1124
+ var OVERLAY_PANEL_MENU = (0, import_clsx11.default)(OVERLAY_PANEL, "min-w-[168px]");
1125
+ var OVERLAY_PANEL_SCROLL = (0, import_clsx11.default)(
1126
+ "max-h-[min(16rem,var(--panel-available-height,16rem))] overflow-y-auto",
1127
+ // A floating panel is already its own scroll container and keeps focus on the input or a
1128
+ // roving option, so it needs the scrollbar styling but not `ScrollArea`'s tab stop.
1129
+ SCROLLBAR_CLASSES
1130
+ );
1131
+ var OVERLAY_ITEM_BASE = "flex w-full cursor-pointer select-none items-start gap-2 rounded-md text-left outline-none transition-colors";
1132
+ var OVERLAY_ITEM_SIZE = {
1133
+ lg: "px-3 py-2.5 text-body",
1134
+ md: "px-2.5 py-2 text-body-sm",
1135
+ sm: "px-2 py-1.5 text-body-tiny"
1136
+ };
1137
+ function overlayItemTone(tone, disabled) {
1138
+ if (disabled) return "cursor-not-allowed text-disabled";
1139
+ return tone === "danger" ? "text-danger hover:bg-danger-tertiary focus:bg-danger-tertiary" : "text-default hover:bg-default-secondary focus:bg-default-secondary";
1140
+ }
1141
+ var OVERLAY_HEADING = "px-2.5 py-1.5 text-body-tiny font-semibold uppercase tracking-wide text-default-tertiary";
1142
+ var OVERLAY_SEPARATOR = "-mx-1 my-1 h-px bg-divider";
1143
+
1144
+ // src/components/overlays/overlay.ts
1145
+ var import_react15 = require("react");
1146
+ var import_tabbable = require("tabbable");
1147
+
1148
+ // src/components/overlays/overlay-stack.ts
1149
+ var import_react14 = require("react");
1150
+ var layers = [];
1151
+ var listeners = /* @__PURE__ */ new Set();
1152
+ function notify() {
1153
+ for (const listener of listeners) listener();
1154
+ }
1155
+ function topmost() {
1156
+ return layers[layers.length - 1]?.id;
1157
+ }
1158
+ var deferredEscapes = /* @__PURE__ */ new WeakSet();
1159
+ function isEscapeDeferred(event) {
1160
+ return deferredEscapes.has(event);
1161
+ }
1162
+ var scrollLocks = 0;
1163
+ var restoreBody = null;
1164
+ function lockScroll() {
1165
+ scrollLocks += 1;
1166
+ if (scrollLocks > 1 || typeof document === "undefined") return;
1167
+ const { body, documentElement } = document;
1168
+ const previousOverflow = body.style.overflow;
1169
+ const previousPaddingRight = body.style.paddingRight;
1170
+ const scrollbarWidth = window.innerWidth - documentElement.clientWidth;
1171
+ if (scrollbarWidth > 0) {
1172
+ const current = parseFloat(window.getComputedStyle(body).paddingRight) || 0;
1173
+ body.style.paddingRight = `${current + scrollbarWidth}px`;
1174
+ }
1175
+ body.style.overflow = "hidden";
1176
+ restoreBody = () => {
1177
+ body.style.overflow = previousOverflow;
1178
+ body.style.paddingRight = previousPaddingRight;
1179
+ };
1180
+ }
1181
+ function unlockScroll() {
1182
+ scrollLocks = Math.max(0, scrollLocks - 1);
1183
+ if (scrollLocks === 0 && restoreBody) {
1184
+ restoreBody();
1185
+ restoreBody = null;
1186
+ }
1187
+ }
1188
+ var inerted = /* @__PURE__ */ new Set();
1189
+ function applyInert(node) {
1190
+ if (typeof document === "undefined" || !node) return;
1191
+ let root = node;
1192
+ while (root.parentElement && root.parentElement !== document.body) {
1193
+ root = root.parentElement;
1194
+ }
1195
+ for (const child of Array.from(document.body.children)) {
1196
+ if (child === root || !(child instanceof HTMLElement)) continue;
1197
+ if (child.hasAttribute("inert")) continue;
1198
+ child.setAttribute("inert", "");
1199
+ inerted.add(child);
1200
+ }
1201
+ }
1202
+ function releaseInert() {
1203
+ for (const el of inerted) el.removeAttribute("inert");
1204
+ inerted.clear();
1205
+ }
1206
+ function useOverlayLayer(active, {
1207
+ lockScroll: shouldLockScroll = true,
1208
+ inertBackground = true,
1209
+ panelRef
1210
+ } = {}) {
1211
+ const id = (0, import_react14.useRef)();
1212
+ if (!id.current) id.current = /* @__PURE__ */ Symbol("overlay-layer");
1213
+ const [isTopmost, setIsTopmost] = (0, import_react14.useState)(false);
1214
+ (0, import_react14.useEffect)(() => {
1215
+ if (!active) return;
1216
+ const self = id.current;
1217
+ layers.push({ id: self });
1218
+ const sync = () => setIsTopmost(topmost() === self);
1219
+ listeners.add(sync);
1220
+ sync();
1221
+ notify();
1222
+ if (shouldLockScroll) lockScroll();
1223
+ return () => {
1224
+ const index = layers.findIndex((layer) => layer.id === self);
1225
+ if (index !== -1) layers.splice(index, 1);
1226
+ listeners.delete(sync);
1227
+ notify();
1228
+ if (shouldLockScroll) unlockScroll();
1229
+ };
1230
+ }, [active, shouldLockScroll]);
1231
+ (0, import_react14.useEffect)(() => {
1232
+ if (!active || !inertBackground) return;
1233
+ if (inerted.size === 0) applyInert(panelRef?.current ?? null);
1234
+ return () => {
1235
+ if (layers.length <= 1) releaseInert();
1236
+ };
1237
+ }, [active, inertBackground, panelRef]);
1238
+ return { isTopmost };
1239
+ }
1240
+
1241
+ // src/components/overlays/overlay.ts
1242
+ function useOverlayDismiss({
1243
+ onDismiss,
1244
+ panelRef,
1245
+ active = true,
1246
+ closeOnEscape = true,
1247
+ closeOnOutsidePress = true,
1248
+ trapFocus = true,
1249
+ lockScroll: lockScroll2 = true,
1250
+ inertBackground = true,
1251
+ autoFocus = true,
1252
+ initialFocus,
1253
+ returnFocus,
1254
+ onEscapeKeyDown,
1255
+ onInteractOutside
1256
+ }) {
1257
+ const { isTopmost } = useOverlayLayer(active, {
1258
+ lockScroll: lockScroll2,
1259
+ inertBackground,
1260
+ panelRef
1261
+ });
1262
+ const handlers = (0, import_react15.useRef)({ onDismiss, onEscapeKeyDown, onInteractOutside });
1263
+ handlers.current = { onDismiss, onEscapeKeyDown, onInteractOutside };
1264
+ const isTopmostRef = (0, import_react15.useRef)(isTopmost);
1265
+ isTopmostRef.current = isTopmost;
1266
+ (0, import_react15.useEffect)(() => {
1267
+ if (!active || !closeOnEscape) return;
1268
+ function onKeyDown(event) {
1269
+ if (event.key !== "Escape") return;
1270
+ if (!isTopmostRef.current) return;
1271
+ if (isEscapeDeferred(event)) {
1272
+ let vetoed = false;
1273
+ handlers.current.onEscapeKeyDown?.(vetoable(event, () => vetoed = true));
1274
+ if (vetoed) return;
1275
+ } else {
1276
+ handlers.current.onEscapeKeyDown?.(event);
1277
+ if (event.defaultPrevented) return;
1278
+ }
1279
+ handlers.current.onDismiss();
1280
+ }
1281
+ document.addEventListener("keydown", onKeyDown);
1282
+ return () => document.removeEventListener("keydown", onKeyDown);
1283
+ }, [active, closeOnEscape]);
1284
+ (0, import_react15.useEffect)(() => {
1285
+ if (!active || !closeOnOutsidePress) return;
1286
+ function onPointerDown(event) {
1287
+ if (!isTopmostRef.current) return;
1288
+ const panel = panelRef.current;
1289
+ if (!panel || panel.contains(event.target)) return;
1290
+ handlers.current.onInteractOutside?.(event);
1291
+ if (event.defaultPrevented) return;
1292
+ handlers.current.onDismiss();
1293
+ }
1294
+ document.addEventListener("pointerdown", onPointerDown);
1295
+ return () => document.removeEventListener("pointerdown", onPointerDown);
1296
+ }, [active, closeOnOutsidePress, panelRef]);
1297
+ (0, import_react15.useEffect)(() => {
1298
+ if (!active || !trapFocus) return;
1299
+ function onKeyDown(event) {
1300
+ if (event.key !== "Tab" || !isTopmostRef.current) return;
1301
+ const panel = panelRef.current;
1302
+ if (!panel) return;
1303
+ const items = (0, import_tabbable.tabbable)(panel);
1304
+ if (items.length === 0) {
1305
+ event.preventDefault();
1306
+ panel.focus({ preventScroll: true });
1307
+ return;
1308
+ }
1309
+ const first = items[0];
1310
+ const last = items[items.length - 1];
1311
+ const activeElement = document.activeElement;
1312
+ const inside = panel.contains(activeElement);
1313
+ if (event.shiftKey && (activeElement === first || !inside)) {
1314
+ event.preventDefault();
1315
+ last.focus();
1316
+ } else if (!event.shiftKey && (activeElement === last || !inside)) {
1317
+ event.preventDefault();
1318
+ first.focus();
1319
+ }
1320
+ }
1321
+ function onFocusIn(event) {
1322
+ if (!isTopmostRef.current) return;
1323
+ const panel = panelRef.current;
1324
+ if (!panel) return;
1325
+ if (panel.contains(event.target)) return;
1326
+ const items = (0, import_tabbable.tabbable)(panel);
1327
+ (items[0] ?? panel).focus({ preventScroll: true });
1328
+ }
1329
+ document.addEventListener("keydown", onKeyDown);
1330
+ document.addEventListener("focusin", onFocusIn);
1331
+ return () => {
1332
+ document.removeEventListener("keydown", onKeyDown);
1333
+ document.removeEventListener("focusin", onFocusIn);
1334
+ };
1335
+ }, [active, trapFocus, panelRef]);
1336
+ (0, import_react15.useEffect)(() => {
1337
+ if (!active) return;
1338
+ const previouslyFocused = document.activeElement;
1339
+ const panel = panelRef.current;
1340
+ let observer = null;
1341
+ if (panel && autoFocus) {
1342
+ if (!panel.hasAttribute("tabindex")) panel.setAttribute("tabindex", "-1");
1343
+ const focusTarget = () => {
1344
+ const explicit = initialFocus?.current;
1345
+ if (explicit) {
1346
+ explicit.focus({ preventScroll: true });
1347
+ return true;
1348
+ }
1349
+ const items = (0, import_tabbable.tabbable)(panel);
1350
+ if (items.length > 0) {
1351
+ items[0].focus({ preventScroll: true });
1352
+ return true;
1353
+ }
1354
+ return false;
1355
+ };
1356
+ if (!focusTarget()) {
1357
+ panel.focus({ preventScroll: true });
1358
+ observer = new MutationObserver(() => {
1359
+ if (focusTarget()) {
1360
+ observer?.disconnect();
1361
+ observer = null;
1362
+ }
1363
+ });
1364
+ observer.observe(panel, { childList: true, subtree: true });
1365
+ }
1366
+ }
1367
+ return () => {
1368
+ observer?.disconnect();
1369
+ const target = returnFocus ? returnFocus.current : previouslyFocused;
1370
+ if (target?.isConnected) target.focus({ preventScroll: true });
1371
+ };
1372
+ }, [active, panelRef, initialFocus, returnFocus, autoFocus]);
1373
+ }
1374
+ function vetoable(event, onVeto) {
1375
+ let vetoed = false;
1376
+ return new Proxy(event, {
1377
+ get(target, key) {
1378
+ if (key === "preventDefault") {
1379
+ return () => {
1380
+ vetoed = true;
1381
+ onVeto();
1382
+ };
1383
+ }
1384
+ if (key === "defaultPrevented") return vetoed;
1385
+ const value = Reflect.get(target, key, target);
1386
+ return typeof value === "function" ? value.bind(target) : value;
1387
+ }
1388
+ });
1389
+ }
1390
+
1391
+ // src/components/overlays/portal.tsx
1392
+ var import_react16 = require("react");
1393
+ var import_react_dom = require("react-dom");
1394
+ var import_jsx_runtime10 = require("react/jsx-runtime");
1395
+ var PortalContainerContext = (0, import_react16.createContext)(null);
1396
+ function usePortalContainer() {
1397
+ return (0, import_react16.useContext)(PortalContainerContext);
1398
+ }
1399
+ function Portal({ children, container }) {
1400
+ const [mounted, setMounted] = (0, import_react16.useState)(false);
1401
+ const contextContainer = (0, import_react16.useContext)(PortalContainerContext);
1402
+ (0, import_react16.useEffect)(() => setMounted(true), []);
1403
+ if (!mounted) return null;
1404
+ const target = container ?? contextContainer ?? (typeof document === "undefined" ? null : document.body);
1405
+ if (!target) return null;
1406
+ return (0, import_react_dom.createPortal)(children, target);
1407
+ }
1408
+
1409
+ // src/components/forms/select.tsx
1410
+ var import_jsx_runtime11 = require("react/jsx-runtime");
1411
+ var selectBase = {
1412
+ lg: "h-12 pl-4 pr-9 text-body",
1413
+ // right-4 (16) + size-5 (20) = 36px
1414
+ md: "h-9 pl-3 pr-7 text-body-sm",
1415
+ // right-3 (12) + size-4 (16) = 28px
1416
+ sm: "h-6 pl-2 pr-5 text-body-tiny"
1417
+ // right-2 (8) + size-3 (12) = 20px
1418
+ };
1419
+ var chevronPos = {
1420
+ lg: { right: "right-4", size: "size-5" },
1421
+ md: { right: "right-3", size: "size-4" },
1422
+ sm: { right: "right-2", size: "size-3" }
1423
+ };
1424
+ function isGroup(entry) {
1425
+ return "options" in entry;
1426
+ }
1427
+ function flatten(entries) {
1428
+ return entries.flatMap((entry) => isGroup(entry) ? entry.options : [entry]);
1429
+ }
1430
+ var SelectControl = (0, import_react17.forwardRef)(
1431
+ function SelectControl2({
1432
+ options,
1433
+ value: valueProp,
1434
+ defaultValue = null,
1435
+ onValueChange,
1436
+ name,
1437
+ size: sizeProp,
1438
+ invalid = false,
1439
+ placeholder = "Select\u2026",
1440
+ className,
1441
+ onKeyDown,
1442
+ ...props
1443
+ }, ref) {
1444
+ const size2 = useControlSize(sizeProp);
1445
+ const field = useFieldControl();
1446
+ const fieldContext = useFieldContext();
1447
+ const [value, setValue] = useControllableState({
1448
+ value: valueProp,
1449
+ defaultValue,
1450
+ onChange: onValueChange
1451
+ });
1452
+ const [open, setOpen] = (0, import_react17.useState)(false);
1453
+ const baseId = (0, import_react17.useId)();
1454
+ const listboxId = `${baseId}-listbox`;
1455
+ const valueId = `${baseId}-value`;
1456
+ const optionId = (index) => `${baseId}-option-${index}`;
1457
+ const triggerRef = (0, import_react17.useRef)(null);
1458
+ const panelRef = (0, import_react17.useRef)(null);
1459
+ const [panelNode, setPanelNode] = (0, import_react17.useState)(null);
1460
+ const pendingEdge = (0, import_react17.useRef)("start");
1461
+ const flat = flatten(options);
1462
+ const selected = flat.find((option) => option.value === value) ?? null;
1463
+ const isInvalid = invalid || !!field["aria-invalid"];
1464
+ const isDisabled = props.disabled ?? field.disabled;
1465
+ const isRequired = Boolean(field["aria-required"]) || Boolean(props["aria-required"]);
1466
+ if (!fieldContext && !props["aria-label"] && !props["aria-labelledby"]) {
1467
+ devWarn(
1468
+ "SelectControl outside a Field needs aria-label or aria-labelledby; otherwise it is named only by its value."
1469
+ );
1470
+ }
1471
+ const roving = useRovingFocus({ orientation: "vertical", loop: true, typeahead: true });
1472
+ const { refs, floatingStyles } = useFloatingPanel({
1473
+ open,
1474
+ onOpenChange: setOpen,
1475
+ side: "bottom",
1476
+ align: "start",
1477
+ sideOffset: 4,
1478
+ matchAnchorWidth: true
1479
+ });
1480
+ (0, import_react17.useEffect)(() => {
1481
+ refs.setReference(triggerRef.current);
1482
+ }, [refs, open]);
1483
+ useOverlayDismiss({
1484
+ onDismiss: () => setOpen(false),
1485
+ panelRef,
1486
+ active: open,
1487
+ // Not modal: the page behind stays readable and interactive. Only Escape,
1488
+ // outside-press and focus restore — the same four falses as DropdownMenu.
1489
+ trapFocus: false,
1490
+ lockScroll: false,
1491
+ inertBackground: false,
1492
+ // The listbox owns its initial focus below; a "first tabbable element" scan would
1493
+ // fight the roving tabindex, which exposes exactly one option at a time.
1494
+ autoFocus: false
1495
+ });
1496
+ const wasOpen = (0, import_react17.useRef)(false);
1497
+ (0, import_react17.useEffect)(() => {
1498
+ if (open && panelNode && !wasOpen.current) {
1499
+ const index = selected ? flat.indexOf(selected) : -1;
1500
+ if (index >= 0 && pendingEdge.current === "start") roving.focusIndex(index);
1501
+ else roving.moveToEdge(pendingEdge.current);
1502
+ pendingEdge.current = "start";
1503
+ wasOpen.current = true;
1504
+ }
1505
+ if (!open) wasOpen.current = false;
1506
+ }, [open, panelNode, roving]);
1507
+ const commit = (option) => {
1508
+ if (option.disabled) return;
1509
+ setValue(option.value);
1510
+ setOpen(false);
1511
+ };
1512
+ const triggerKeyDown = (event) => {
1513
+ onKeyDown?.(event);
1514
+ if (event.defaultPrevented || open) return;
1515
+ if (event.key === "ArrowDown" || event.key === "ArrowUp") {
1516
+ event.preventDefault();
1517
+ pendingEdge.current = event.key === "ArrowUp" ? "end" : "start";
1518
+ setOpen(true);
1519
+ }
1520
+ };
1521
+ let cursor = 0;
1522
+ const renderOption = (option, index) => {
1523
+ const isSelected = option.value === value;
1524
+ const itemProps = roving.itemProps(index, {
1525
+ disabled: option.disabled,
1526
+ label: option.label
1527
+ });
1528
+ return /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(
1529
+ "div",
1530
+ {
1531
+ role: "option",
1532
+ id: optionId(index),
1533
+ "aria-selected": isSelected,
1534
+ "aria-disabled": option.disabled || void 0,
1535
+ ...itemProps,
1536
+ tabIndex: itemProps.tabIndex,
1537
+ onClick: () => commit(option),
1538
+ onKeyDown: (event) => {
1539
+ if (event.key === "Enter" || event.key === " ") {
1540
+ event.preventDefault();
1541
+ commit(option);
1542
+ }
1543
+ },
1544
+ className: (0, import_clsx12.default)(
1545
+ OVERLAY_ITEM_BASE,
1546
+ OVERLAY_ITEM_SIZE[size2],
1547
+ "items-center",
1548
+ overlayItemTone("default", !!option.disabled),
1549
+ // The tint is shared with hover, so the ring is what marks the keyboard position.
1550
+ FOCUS_RING_INSET
1551
+ ),
1552
+ children: [
1553
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("span", { className: "min-w-0 flex-1 truncate", children: option.label }),
1554
+ isSelected && /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_lucide_react3.CheckIcon, { className: "size-3.5 shrink-0", strokeWidth: 3, "aria-hidden": true })
1555
+ ]
1556
+ },
1557
+ option.value
1558
+ );
1559
+ };
1560
+ const cp = chevronPos[size2];
1561
+ return /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_jsx_runtime11.Fragment, { children: [
1562
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { className: "relative flex items-center", children: [
1563
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
1564
+ "button",
1565
+ {
1566
+ ref: composeRefs(triggerRef, ref),
1567
+ type: "button",
1568
+ role: "combobox",
1569
+ "aria-haspopup": "listbox",
1570
+ "aria-expanded": open,
1571
+ "aria-controls": open ? listboxId : void 0,
1572
+ "aria-labelledby": fieldContext ? `${fieldContext.labelId} ${valueId}` : void 0,
1573
+ "data-size": size2,
1574
+ ...field,
1575
+ disabled: isDisabled,
1576
+ onClick: () => setOpen(!open),
1577
+ onKeyDown: triggerKeyDown,
1578
+ className: (0, import_clsx12.default)(
1579
+ "w-full appearance-none rounded-lg border text-left outline-none transition-colors",
1580
+ "bg-default text-default",
1581
+ "focus-visible:ring-2 focus-visible:ring-offset-1 focus-visible:ring-offset-default",
1582
+ selectBase[size2],
1583
+ isDisabled ? "cursor-not-allowed border-disabled bg-disabled text-disabled" : isInvalid ? "border-danger-secondary focus-visible:border-danger focus-visible:ring-danger" : "border-default focus-visible:border-brand focus-visible:ring-brand",
1584
+ className
1585
+ ),
1586
+ ...props,
1587
+ children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
1588
+ "span",
1589
+ {
1590
+ id: valueId,
1591
+ className: (0, import_clsx12.default)("block truncate", !selected && "text-default-tertiary"),
1592
+ children: selected?.label ?? placeholder
1593
+ }
1594
+ )
1595
+ }
1596
+ ),
1597
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
1598
+ "span",
1599
+ {
1600
+ "aria-hidden": true,
1601
+ className: (0, import_clsx12.default)(
1602
+ "pointer-events-none absolute",
1603
+ cp.right,
1604
+ cp.size,
1605
+ "flex items-center justify-center",
1606
+ isDisabled ? "text-icon-disabled" : "text-icon-default-secondary"
1607
+ ),
1608
+ children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_lucide_react3.ChevronDownIcon, { className: "size-full" })
1609
+ }
1610
+ ),
1611
+ name && !isRequired && /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("input", { type: "hidden", name, value: value ?? "" }),
1612
+ name && isRequired && /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
1613
+ "input",
1614
+ {
1615
+ "aria-hidden": true,
1616
+ tabIndex: -1,
1617
+ name,
1618
+ value: value ?? "",
1619
+ required: true,
1620
+ disabled: isDisabled,
1621
+ onChange: () => {
1622
+ },
1623
+ onFocus: () => triggerRef.current?.focus(),
1624
+ className: "pointer-events-none absolute inset-x-0 bottom-0 h-px w-full opacity-0"
1625
+ }
1626
+ )
1627
+ ] }),
1628
+ open && /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(Portal, { children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
1629
+ "div",
1630
+ {
1631
+ ref: composeRefs(panelRef, setPanelNode, refs.setFloating),
1632
+ id: listboxId,
1633
+ role: "listbox",
1634
+ tabIndex: -1,
1635
+ "aria-orientation": "vertical",
1636
+ "aria-labelledby": fieldContext?.labelId,
1637
+ "aria-required": field["aria-required"],
1638
+ "aria-invalid": field["aria-invalid"],
1639
+ style: { ...floatingStyles, width: "var(--panel-anchor-width)" },
1640
+ className: (0, import_clsx12.default)("z-popover", OVERLAY_PANEL, OVERLAY_PANEL_SCROLL),
1641
+ ...roving.containerProps,
1642
+ onKeyDown: (event) => {
1643
+ roving.containerProps.onKeyDown(event);
1644
+ if (event.key === "Tab") setOpen(false);
1645
+ },
1646
+ children: options.map((entry, entryIndex) => {
1647
+ if (!isGroup(entry)) return renderOption(entry, cursor++);
1648
+ const headingId = `${baseId}-group-${entryIndex}`;
1649
+ return /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { role: "group", "aria-labelledby": headingId, children: [
1650
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("div", { id: headingId, className: OVERLAY_HEADING, children: entry.label }),
1651
+ entry.options.map((option) => renderOption(option, cursor++))
1652
+ ] }, `group-${entryIndex}`);
1653
+ })
1654
+ }
1655
+ ) })
1656
+ ] });
1657
+ }
1658
+ );
1659
+ var Select = (0, import_react17.forwardRef)(function Select2({
1660
+ label,
1661
+ description,
1662
+ error,
1663
+ hint,
1664
+ size: sizeProp,
1665
+ className,
1666
+ disabled,
1667
+ required,
1668
+ id,
1669
+ ...props
1670
+ }, ref) {
1671
+ const size2 = useControlSize(sizeProp);
1672
+ const hasError = !!error;
1673
+ return /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(
1674
+ Field,
1675
+ {
1676
+ id,
1677
+ size: size2,
1678
+ disabled,
1679
+ required,
1680
+ hasDescription: !!description,
1681
+ hasError,
1682
+ hasHint: !!hint,
1683
+ className,
1684
+ children: [
1685
+ label && /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(FieldLabel, { children: label }),
1686
+ description && /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(FieldDescription, { children: description }),
1687
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(SelectControl, { ref, size: size2, invalid: hasError, disabled, ...props }),
1688
+ hasError && /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(FieldError, { children: error }),
1689
+ !hasError && hint && /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(FieldHint, { children: hint })
1690
+ ]
1691
+ }
1692
+ );
1693
+ });
1694
+
1695
+ // src/components/chrome/pagination.tsx
1696
+ var import_jsx_runtime12 = require("react/jsx-runtime");
1697
+ var GAP2 = "\u2026";
1698
+ function paginationRange(page, pageCount, siblingCount = 1) {
1699
+ const totalSlots = siblingCount * 2 + 5;
1700
+ if (pageCount <= totalSlots) {
1701
+ return Array.from({ length: pageCount }, (_, i) => i + 1);
1702
+ }
1703
+ const left = Math.max(page - siblingCount, 1);
1704
+ const right = Math.min(page + siblingCount, pageCount);
1705
+ const showLeftGap = left > 3;
1706
+ const showRightGap = right < pageCount - 2;
1707
+ if (!showLeftGap && showRightGap) {
1708
+ const count = siblingCount * 2 + 3;
1709
+ return [...Array.from({ length: count }, (_, i) => i + 1), GAP2, pageCount];
1710
+ }
1711
+ if (showLeftGap && !showRightGap) {
1712
+ const count = siblingCount * 2 + 3;
1713
+ return [1, GAP2, ...Array.from({ length: count }, (_, i) => pageCount - count + 1 + i)];
1714
+ }
1715
+ return [
1716
+ 1,
1717
+ GAP2,
1718
+ ...Array.from({ length: right - left + 1 }, (_, i) => left + i),
1719
+ GAP2,
1720
+ pageCount
1721
+ ];
1722
+ }
1723
+ var ARROW_BASE = (0, import_clsx13.default)(
1724
+ "inline-flex size-9 shrink-0 items-center justify-center rounded-lg border transition-colors",
1725
+ "focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-brand focus-visible:ring-offset-1 focus-visible:ring-offset-default",
1726
+ "disabled:cursor-not-allowed disabled:border-disabled disabled:bg-disabled disabled:text-disabled",
1727
+ "border-default bg-default text-default hover:bg-default-secondary hover:text-brand"
1728
+ );
1729
+ var Pagination = (0, import_react18.forwardRef)(function Pagination2({
1730
+ page,
1731
+ pageCount,
1732
+ onPageChange,
1733
+ type = "default",
1734
+ siblingCount = 1,
1735
+ label = "Pagination",
1736
+ className,
1737
+ ...rest
1738
+ }, ref) {
1739
+ if (pageCount < 1) return null;
1740
+ const go = (next) => {
1741
+ const clamped = Math.min(Math.max(next, 1), pageCount);
1742
+ if (clamped !== page) onPageChange(clamped);
1743
+ };
1744
+ return /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(
1745
+ "nav",
1746
+ {
1747
+ ref,
1748
+ "aria-label": label,
1749
+ "data-slot": "pagination",
1750
+ className: (0, import_clsx13.default)("flex items-center gap-1.5", className),
1751
+ ...rest,
1752
+ children: [
1753
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
1754
+ "button",
1755
+ {
1756
+ type: "button",
1757
+ "aria-label": "Previous page",
1758
+ disabled: page <= 1,
1759
+ onClick: () => go(page - 1),
1760
+ className: ARROW_BASE,
1761
+ children: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_lucide_react4.ChevronLeftIcon, { "aria-hidden": true, className: "size-4" })
1762
+ }
1763
+ ),
1764
+ type === "dots" ? (
1765
+ // The dots form has no room for numbers, so the list itself is the only place the
1766
+ // position can be stated — hence the live-region-free but explicitly named group.
1767
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
1768
+ "span",
1769
+ {
1770
+ role: "group",
1771
+ "aria-label": `Page ${page} of ${pageCount}`,
1772
+ className: "flex items-center gap-2 px-2",
1773
+ children: Array.from({ length: pageCount }, (_, i) => i + 1).map((n) => /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
1774
+ "button",
1775
+ {
1776
+ type: "button",
1777
+ "aria-label": `Page ${n}`,
1778
+ "aria-current": n === page ? "page" : void 0,
1779
+ onClick: () => go(n),
1780
+ className: (0, import_clsx13.default)(
1781
+ "size-2 rounded-full transition-colors",
1782
+ "focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-brand focus-visible:ring-offset-2 focus-visible:ring-offset-default",
1783
+ n === page ? "bg-brand" : "bg-default-tertiary hover:bg-neutral-secondary"
1784
+ )
1785
+ },
1786
+ n
1787
+ ))
1788
+ }
1789
+ )
1790
+ ) : paginationRange(page, pageCount, siblingCount).map(
1791
+ (entry, index) => entry === GAP2 ? /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
1792
+ "span",
1793
+ {
1794
+ "aria-hidden": true,
1795
+ className: "inline-flex size-9 items-center justify-center text-body-sm text-default-tertiary",
1796
+ children: GAP2
1797
+ },
1798
+ `gap-${index}`
1799
+ ) : /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
1800
+ "button",
1801
+ {
1802
+ type: "button",
1803
+ "aria-label": `Page ${entry}`,
1804
+ "aria-current": entry === page ? "page" : void 0,
1805
+ onClick: () => go(entry),
1806
+ className: (0, import_clsx13.default)(
1807
+ "inline-flex size-9 shrink-0 items-center justify-center rounded-lg border text-body-sm tabular-nums transition-colors",
1808
+ "focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-brand focus-visible:ring-offset-1 focus-visible:ring-offset-default",
1809
+ entry === page ? "border-brand bg-brand font-semibold text-brand-on-brand" : "border-default bg-default text-default hover:bg-default-secondary hover:text-brand"
1810
+ ),
1811
+ children: entry
1812
+ },
1813
+ entry
1814
+ )
1815
+ ),
1816
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
1817
+ "button",
1818
+ {
1819
+ type: "button",
1820
+ "aria-label": "Next page",
1821
+ disabled: page >= pageCount,
1822
+ onClick: () => go(page + 1),
1823
+ className: ARROW_BASE,
1824
+ children: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_lucide_react4.ChevronRightIcon, { "aria-hidden": true, className: "size-4" })
1825
+ }
1826
+ )
1827
+ ]
1828
+ }
1829
+ );
1830
+ });
1831
+ function PaginationBar({
1832
+ page,
1833
+ pageSize,
1834
+ total,
1835
+ onPageChange,
1836
+ onPageSizeChange,
1837
+ pageSizeOptions = [10, 20, 50],
1838
+ summary,
1839
+ label = "Pages",
1840
+ className
1841
+ }) {
1842
+ const pageCount = Math.max(1, Math.ceil(total / pageSize));
1843
+ const from = total === 0 ? 0 : (page - 1) * pageSize + 1;
1844
+ const to = Math.min(total, page * pageSize);
1845
+ const showSize = Boolean(onPageSizeChange) && pageSizeOptions.length > 0;
1846
+ const options = pageSizeOptions.includes(pageSize) ? pageSizeOptions : [...pageSizeOptions, pageSize].sort((a, b) => a - b);
1847
+ return /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(
1848
+ "div",
1849
+ {
1850
+ "data-slot": "pagination-bar",
1851
+ className: (0, import_clsx13.default)("flex flex-wrap items-center justify-between gap-x-4 gap-y-3", className),
1852
+ children: [
1853
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("p", { className: "text-body-xs text-default-secondary", children: summary ?? /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(import_jsx_runtime12.Fragment, { children: [
1854
+ "Showing ",
1855
+ from,
1856
+ "\u2013",
1857
+ to,
1858
+ " of ",
1859
+ total
1860
+ ] }) }),
1861
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)("div", { className: "flex flex-wrap items-center gap-x-4 gap-y-3", children: [
1862
+ showSize && /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)("div", { className: "flex items-center gap-2", children: [
1863
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("span", { "aria-hidden": true, className: "text-body-xs text-default-secondary", children: "Rows per page" }),
1864
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
1865
+ SelectControl,
1866
+ {
1867
+ "aria-label": "Rows per page",
1868
+ size: "md",
1869
+ className: "w-20",
1870
+ value: String(pageSize),
1871
+ options: options.map((size2) => ({ value: String(size2), label: String(size2) })),
1872
+ onValueChange: (value) => onPageSizeChange?.(Number(value))
1873
+ }
1874
+ )
1875
+ ] }),
1876
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(Pagination, { page, pageCount, onPageChange, label })
1877
+ ] })
1878
+ ]
1879
+ }
1880
+ );
1881
+ }
1882
+
1883
+ // src/components/overlays/dropdown-menu.tsx
1884
+ var import_react21 = require("react");
1885
+ var import_radix_ui = require("radix-ui");
1886
+ var import_lucide_react6 = require("lucide-react");
1887
+
1888
+ // src/lib/compose-event-handlers.ts
1889
+ function composeEventHandlers(theirs, ours) {
1890
+ return (event) => {
1891
+ theirs?.(event);
1892
+ if (!event.defaultPrevented) ours(event);
1893
+ };
1894
+ }
1895
+
1896
+ // src/components/forms/icon-button.tsx
1897
+ var import_react19 = require("react");
1898
+ var import_clsx14 = __toESM(require("clsx"), 1);
1899
+ var import_jsx_runtime13 = require("react/jsx-runtime");
1900
+ var variantStyles2 = {
1901
+ primary: (0, import_clsx14.default)(
1902
+ "bg-brand border border-brand text-brand-on-brand",
1903
+ "hover:bg-brand-hover",
1904
+ "disabled:bg-disabled disabled:border-disabled disabled:text-disabled-on-disabled",
1905
+ "aria-disabled:bg-disabled aria-disabled:border-disabled aria-disabled:text-disabled-on-disabled"
1906
+ ),
1907
+ // Neutral uses secondary background (light gray) for visual weight without a text label
1908
+ neutral: (0, import_clsx14.default)(
1909
+ "bg-default-secondary border border-default text-default",
1910
+ // icon turns brand blue on hover (Figma spec)
1911
+ "hover:bg-default-secondary-hover hover:text-brand",
1912
+ "disabled:bg-disabled disabled:border-disabled disabled:text-disabled-on-disabled",
1913
+ "aria-disabled:bg-disabled aria-disabled:border-disabled aria-disabled:text-disabled-on-disabled"
1914
+ ),
1915
+ subtle: (0, import_clsx14.default)(
1916
+ "bg-transparent text-neutral",
1917
+ // hover uses background-default-default-hover (#f5f5f5), icon turns brand blue (Figma spec)
1918
+ "hover:bg-default-hover hover:text-brand",
1919
+ // disabled needs explicit border since there is no base border
1920
+ "disabled:bg-disabled disabled:border disabled:border-disabled disabled:text-disabled-on-disabled",
1921
+ "aria-disabled:bg-disabled aria-disabled:border aria-disabled:border-disabled aria-disabled:text-disabled-on-disabled"
1922
+ )
1923
+ };
1924
+ var sizeStyles2 = {
1925
+ lg: "size-12 rounded-2xl [&_svg]:size-5",
1926
+ md: "size-9 rounded-lg [&_svg]:size-5",
1927
+ sm: "size-6 rounded-full [&_svg]:size-4"
1928
+ };
1929
+ var IconButton = (0, import_react19.forwardRef)(function IconButton2({
1930
+ variant = "primary",
1931
+ size: sizeProp,
1932
+ asChild = false,
1933
+ type,
1934
+ disabled,
1935
+ onClick,
1936
+ children,
1937
+ className,
1938
+ ...props
1939
+ }, ref) {
1940
+ const size2 = useControlSize(sizeProp);
1941
+ const softDisabled = asChild && Boolean(disabled);
1942
+ const handleClick = (event) => {
1943
+ if (softDisabled) {
1944
+ event.preventDefault();
1945
+ event.stopPropagation();
1946
+ return;
1947
+ }
1948
+ onClick?.(event);
1949
+ };
1950
+ const rootProps = {
1951
+ // `cn`, so a caller's `className` beats the size's radius and the variant's colours.
1952
+ className: cn(
1953
+ "inline-flex shrink-0 items-center justify-center transition-colors",
1954
+ FOCUS_RING,
1955
+ "disabled:cursor-not-allowed aria-disabled:cursor-not-allowed",
1956
+ variantStyles2[variant],
1957
+ sizeStyles2[size2],
1958
+ className
1959
+ ),
1960
+ "data-variant": variant,
1961
+ "data-size": size2,
1962
+ "aria-disabled": softDisabled || void 0,
1963
+ onClick: handleClick,
1964
+ ...props
1965
+ };
1966
+ if (asChild) {
1967
+ return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(Slot, { ref, tabIndex: disabled ? -1 : void 0, ...rootProps, children });
1968
+ }
1969
+ return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
1970
+ "button",
1971
+ {
1972
+ ref,
1973
+ type: type ?? "button",
1974
+ disabled,
1975
+ ...rootProps,
1976
+ children
1977
+ }
1978
+ );
1979
+ });
1980
+
1981
+ // src/components/overlays/menu-core.tsx
1982
+ var import_react20 = require("react");
1983
+ var import_clsx15 = __toESM(require("clsx"), 1);
1984
+ var import_lucide_react5 = require("lucide-react");
1985
+ var import_jsx_runtime14 = require("react/jsx-runtime");
1986
+ var MENU_PANEL_CLASSES = cn("z-popover", OVERLAY_PANEL_MENU, "focus:outline-none");
1987
+ var ITEM_BASE = (0, import_clsx15.default)(
1988
+ OVERLAY_ITEM_BASE,
1989
+ OVERLAY_ITEM_SIZE.md,
1990
+ // Highlight follows Radix's `data-highlighted`, which tracks pointer and keyboard alike.
1991
+ // The ring marks the keyboard position on top of it: the tint alone, shared with hover,
1992
+ // cannot tell a keyboard user which of two tinted items has focus.
1993
+ FOCUS_RING_INSET,
1994
+ "data-[disabled]:cursor-not-allowed data-[disabled]:text-disabled"
1995
+ );
1996
+ var ITEM_TONE = {
1997
+ default: "text-default data-[highlighted]:bg-default-secondary",
1998
+ danger: "text-danger data-[highlighted]:bg-danger-tertiary"
1999
+ };
2000
+ function stopToAncestors(event) {
2001
+ event.stopPropagation();
2002
+ }
2003
+ function focusMenuEdge(event, edge) {
2004
+ if (event.target !== event.currentTarget) return;
2005
+ const panel = event.currentTarget;
2006
+ queueMicrotask(() => {
2007
+ const items = panel.querySelectorAll('[role^="menuitem"]:not([data-disabled])');
2008
+ if (edge === "end") items[items.length - 1]?.focus();
2009
+ else if (document.activeElement === panel) items[0]?.focus();
2010
+ });
2011
+ }
2012
+ function visibleMenuItems(items) {
2013
+ const kept = items.filter((item) => {
2014
+ if (item.hidden) return false;
2015
+ if (item.type === "group" || item.type === "submenu") return visibleMenuItems(item.items).length > 0;
2016
+ return true;
2017
+ });
2018
+ return kept.filter((item, i) => {
2019
+ if (item.type !== "separator") return true;
2020
+ const prev = kept[i - 1];
2021
+ return i > 0 && i < kept.length - 1 && prev.type !== "separator";
2022
+ });
2023
+ }
2024
+ function createMenuParts(P) {
2025
+ const Item = (0, import_react20.forwardRef)(function MenuItem({ children, onSelect, tone = "default", disabled = false, icon, description, shortcut, textValue, className, ...rest }, ref) {
2026
+ const descriptionId = (0, import_react20.useId)();
2027
+ return /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(
2028
+ P.Item,
2029
+ {
2030
+ ref,
2031
+ disabled,
2032
+ textValue,
2033
+ onSelect,
2034
+ "data-tone": tone,
2035
+ "aria-describedby": description ? descriptionId : void 0,
2036
+ className: cn(ITEM_BASE, ITEM_TONE[tone], className),
2037
+ ...rest,
2038
+ children: [
2039
+ icon && /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("span", { "aria-hidden": true, className: "mt-0.5 flex size-4 shrink-0 items-center justify-center", children: icon }),
2040
+ /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)("span", { className: "min-w-0 flex-1", children: [
2041
+ /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("span", { className: "block truncate", children }),
2042
+ description && /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("span", { id: descriptionId, className: "mt-0.5 block text-body-tiny text-default-secondary", children: description })
2043
+ ] }),
2044
+ shortcut && /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("span", { className: "ml-auto shrink-0 pl-4 text-body-tiny text-default-tertiary", children: shortcut })
2045
+ ]
2046
+ }
2047
+ );
2048
+ });
2049
+ const CheckboxItem = (0, import_react20.forwardRef)(function MenuCheckboxItem({ children, checked, onCheckedChange, disabled = false, tone = "default", shortcut, textValue, className, ...rest }, ref) {
2050
+ return /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(
2051
+ P.CheckboxItem,
2052
+ {
2053
+ ref,
2054
+ checked,
2055
+ onCheckedChange: (next) => onCheckedChange?.(next === true),
2056
+ onSelect: (event) => event.preventDefault(),
2057
+ disabled,
2058
+ textValue,
2059
+ "data-tone": tone,
2060
+ className: cn(ITEM_BASE, "items-center", ITEM_TONE[tone], className),
2061
+ ...rest,
2062
+ children: [
2063
+ /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("span", { "aria-hidden": true, className: "flex size-4 shrink-0 items-center justify-center", children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(P.ItemIndicator, { children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_lucide_react5.CheckIcon, { className: "size-3.5", strokeWidth: 3 }) }) }),
2064
+ /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("span", { className: "min-w-0 flex-1 truncate", children }),
2065
+ shortcut && /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("span", { className: "ml-auto shrink-0 pl-4 text-body-tiny text-default-tertiary", children: shortcut })
2066
+ ]
2067
+ }
2068
+ );
2069
+ });
2070
+ function RadioGroup({ children, value, onValueChange }) {
2071
+ return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(P.RadioGroup, { value, onValueChange, children });
2072
+ }
2073
+ const RadioItem = (0, import_react20.forwardRef)(function MenuRadioItem({ children, value, disabled = false, tone = "default", textValue, className, ...rest }, ref) {
2074
+ return /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(
2075
+ P.RadioItem,
2076
+ {
2077
+ ref,
2078
+ value,
2079
+ disabled,
2080
+ textValue,
2081
+ "data-tone": tone,
2082
+ className: cn(ITEM_BASE, "items-center", ITEM_TONE[tone], className),
2083
+ ...rest,
2084
+ children: [
2085
+ /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("span", { "aria-hidden": true, className: "flex size-4 shrink-0 items-center justify-center", children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(P.ItemIndicator, { children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("span", { className: "block size-1.5 rounded-full bg-current" }) }) }),
2086
+ /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("span", { className: "min-w-0 flex-1 truncate", children })
2087
+ ]
2088
+ }
2089
+ );
2090
+ });
2091
+ const Group = (0, import_react20.forwardRef)(function MenuGroup({ children, label, className, ...rest }, ref) {
2092
+ const labelId = (0, import_react20.useId)();
2093
+ return /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(P.Group, { ref, "aria-labelledby": label ? labelId : void 0, className, ...rest, children: [
2094
+ label && /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("div", { id: labelId, className: OVERLAY_HEADING, children: label }),
2095
+ children
2096
+ ] });
2097
+ });
2098
+ const Label = (0, import_react20.forwardRef)(function MenuLabel({ className, ...rest }, ref) {
2099
+ return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(P.Label, { ref, className: cn(OVERLAY_HEADING, className), ...rest });
2100
+ });
2101
+ const Separator = (0, import_react20.forwardRef)(function MenuSeparator({ className, ...rest }, ref) {
2102
+ return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(P.Separator, { ref, className: cn(OVERLAY_SEPARATOR, className), ...rest });
2103
+ });
2104
+ const Shortcut = (0, import_react20.forwardRef)(function MenuShortcut({ className, ...rest }, ref) {
2105
+ return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("span", { ref, className: cn("ml-auto pl-4 text-body-tiny text-default-tertiary", className), ...rest });
2106
+ });
2107
+ function Sub({ children, open, defaultOpen, onOpenChange }) {
2108
+ return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(P.Sub, { open, defaultOpen, onOpenChange, children });
2109
+ }
2110
+ const SubTrigger = (0, import_react20.forwardRef)(function MenuSubTrigger({ children, icon, disabled = false, textValue, className, ...rest }, ref) {
2111
+ return /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(
2112
+ P.SubTrigger,
2113
+ {
2114
+ ref,
2115
+ disabled,
2116
+ textValue,
2117
+ className: cn(
2118
+ ITEM_BASE,
2119
+ "items-center",
2120
+ ITEM_TONE.default,
2121
+ "data-[state=open]:bg-default-secondary",
2122
+ className
2123
+ ),
2124
+ ...rest,
2125
+ children: [
2126
+ icon && /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("span", { "aria-hidden": true, className: "flex size-4 shrink-0 items-center justify-center", children: icon }),
2127
+ /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("span", { className: "min-w-0 flex-1 truncate", children }),
2128
+ /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_lucide_react5.ChevronRightIcon, { "aria-hidden": true, className: "ml-auto size-4 shrink-0 text-default-tertiary" })
2129
+ ]
2130
+ }
2131
+ );
2132
+ });
2133
+ const SubContent = (0, import_react20.forwardRef)(function MenuSubContent({ className, onClick, onKeyDown, ...rest }, ref) {
2134
+ const container = usePortalContainer();
2135
+ return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(P.Portal, { container: container ?? void 0, children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
2136
+ P.SubContent,
2137
+ {
2138
+ ref,
2139
+ sideOffset: 4,
2140
+ collisionPadding: 8,
2141
+ className: cn(MENU_PANEL_CLASSES, className),
2142
+ onClick: (event) => {
2143
+ onClick?.(event);
2144
+ stopToAncestors(event);
2145
+ },
2146
+ onKeyDown: (event) => {
2147
+ onKeyDown?.(event);
2148
+ stopToAncestors(event);
2149
+ },
2150
+ ...rest
2151
+ }
2152
+ ) });
2153
+ });
2154
+ function Items({ items }) {
2155
+ return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_jsx_runtime14.Fragment, { children: visibleMenuItems(items).map(renderItem) });
2156
+ }
2157
+ function renderItem(item) {
2158
+ switch (item.type) {
2159
+ case "checkbox":
2160
+ return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
2161
+ CheckboxItem,
2162
+ {
2163
+ checked: item.checked,
2164
+ onCheckedChange: item.onCheckedChange,
2165
+ disabled: item.disabled,
2166
+ shortcut: item.shortcut,
2167
+ textValue: item.textValue,
2168
+ children: item.label
2169
+ },
2170
+ item.id
2171
+ );
2172
+ case "radio":
2173
+ return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(RadioGroup, { value: item.value, onValueChange: item.onValueChange, children: item.options.map((option) => /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(RadioItem, { value: option.value, disabled: option.disabled, children: option.label }, option.value)) }, item.id);
2174
+ case "group":
2175
+ return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(Group, { label: item.label, children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(Items, { items: item.items }) }, item.id);
2176
+ case "submenu":
2177
+ return /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(Sub, { children: [
2178
+ /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(SubTrigger, { icon: item.icon, disabled: item.disabled, children: item.label }),
2179
+ /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(SubContent, { children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(Items, { items: item.items }) })
2180
+ ] }, item.id);
2181
+ case "label":
2182
+ return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(Label, { children: item.label }, item.id);
2183
+ case "separator":
2184
+ return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(Separator, {}, item.id);
2185
+ case "custom":
2186
+ return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_react20.Fragment, { children: item.render() }, item.id);
2187
+ default:
2188
+ return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
2189
+ Item,
2190
+ {
2191
+ onSelect: item.onSelect,
2192
+ tone: item.tone,
2193
+ disabled: item.disabled,
2194
+ icon: item.icon,
2195
+ description: item.description,
2196
+ shortcut: item.shortcut,
2197
+ textValue: item.textValue,
2198
+ children: item.label
2199
+ },
2200
+ item.id
2201
+ );
2202
+ }
2203
+ }
2204
+ return {
2205
+ Items,
2206
+ Item,
2207
+ CheckboxItem,
2208
+ RadioGroup,
2209
+ RadioItem,
2210
+ Group,
2211
+ Label,
2212
+ Separator,
2213
+ Shortcut,
2214
+ Sub,
2215
+ SubTrigger,
2216
+ SubContent
2217
+ };
2218
+ }
2219
+
2220
+ // src/components/overlays/dropdown-menu.tsx
2221
+ var import_jsx_runtime15 = require("react/jsx-runtime");
2222
+ var DropdownMenuStateContext = (0, import_react21.createContext)(null);
2223
+ function useDropdownMenuState(part) {
2224
+ const value = (0, import_react21.useContext)(DropdownMenuStateContext);
2225
+ if (!value) throw new Error(`<${part}> must be used inside <DropdownMenu>`);
2226
+ return value;
2227
+ }
2228
+ function DropdownMenu({
2229
+ children,
2230
+ items,
2231
+ trigger,
2232
+ label,
2233
+ side,
2234
+ align,
2235
+ open: openProp,
2236
+ defaultOpen = false,
2237
+ onOpenChange,
2238
+ modal = false
2239
+ }) {
2240
+ const [open, setOpen] = useControllableState({
2241
+ value: openProp,
2242
+ defaultValue: defaultOpen,
2243
+ onChange: onOpenChange
2244
+ });
2245
+ const pendingEdge = (0, import_react21.useRef)("start");
2246
+ const state = (0, import_react21.useMemo)(() => ({ setOpen, pendingEdge }), [setOpen]);
2247
+ return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(import_radix_ui.DropdownMenu.Root, { open, onOpenChange: setOpen, modal, children: /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(DropdownMenuStateContext.Provider, { value: state, children: items ? /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)(import_jsx_runtime15.Fragment, { children: [
2248
+ /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(DropdownMenuTrigger, { asChild: trigger != null, label, children: trigger }),
2249
+ /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(DropdownMenuContent, { side, align, children: /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(DropdownMenuItems, { items }) })
2250
+ ] }) : children }) });
2251
+ }
2252
+ var DropdownMenuTrigger = (0, import_react21.forwardRef)(
2253
+ function DropdownMenuTrigger2({ children, asChild = false, label = "Open menu", onClick, onPointerDown, onMouseDown, onKeyDown, ...rest }, ref) {
2254
+ const state = useDropdownMenuState("DropdownMenuTrigger");
2255
+ const handlers = {
2256
+ onClick: (event) => {
2257
+ onClick?.(event);
2258
+ stopToAncestors(event);
2259
+ },
2260
+ onPointerDown: (event) => {
2261
+ onPointerDown?.(event);
2262
+ event.stopPropagation();
2263
+ },
2264
+ onMouseDown: (event) => {
2265
+ onMouseDown?.(event);
2266
+ stopToAncestors(event);
2267
+ },
2268
+ onKeyDown: (event) => {
2269
+ onKeyDown?.(event);
2270
+ if (event.defaultPrevented) return;
2271
+ if (event.key === "ArrowUp") {
2272
+ event.preventDefault();
2273
+ state.pendingEdge.current = "end";
2274
+ state.setOpen(true);
2275
+ }
2276
+ if (event.key === "Enter" || event.key === " ") stopToAncestors(event);
2277
+ }
2278
+ };
2279
+ if (asChild) {
2280
+ return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(import_radix_ui.DropdownMenu.Trigger, { ref, asChild: true, ...rest, ...handlers, children });
2281
+ }
2282
+ return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(import_radix_ui.DropdownMenu.Trigger, { ref, asChild: true, ...rest, ...handlers, children: /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(IconButton, { variant: "neutral", size: "sm", "aria-label": label, children: children ?? /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(import_lucide_react6.EllipsisIcon, { className: "size-4", "aria-hidden": true }) }) });
2283
+ }
2284
+ );
2285
+ var DropdownMenuContent = (0, import_react21.forwardRef)(
2286
+ function DropdownMenuContent2({
2287
+ children,
2288
+ side = "bottom",
2289
+ align = "end",
2290
+ sideOffset = 6,
2291
+ container,
2292
+ className,
2293
+ onClick,
2294
+ onKeyDown,
2295
+ onFocus,
2296
+ onCloseAutoFocus,
2297
+ ...rest
2298
+ }, ref) {
2299
+ const state = useDropdownMenuState("DropdownMenuContent");
2300
+ const inherited = usePortalContainer();
2301
+ return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(import_radix_ui.DropdownMenu.Portal, { container: container ?? inherited ?? void 0, children: /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
2302
+ import_radix_ui.DropdownMenu.Content,
2303
+ {
2304
+ ref,
2305
+ side,
2306
+ align,
2307
+ sideOffset,
2308
+ collisionPadding: 8,
2309
+ loop: true,
2310
+ className: cn(MENU_PANEL_CLASSES, className),
2311
+ onCloseAutoFocus: composeEventHandlers(onCloseAutoFocus, () => {
2312
+ state.pendingEdge.current = "start";
2313
+ }),
2314
+ onFocus: composeEventHandlers(onFocus, (event) => {
2315
+ const edge = state.pendingEdge.current;
2316
+ state.pendingEdge.current = "start";
2317
+ focusMenuEdge(event, edge);
2318
+ }),
2319
+ onClick: (event) => {
2320
+ onClick?.(event);
2321
+ stopToAncestors(event);
2322
+ },
2323
+ onKeyDown: (event) => {
2324
+ onKeyDown?.(event);
2325
+ stopToAncestors(event);
2326
+ if (event.key === "Tab") state.setOpen(false);
2327
+ },
2328
+ ...rest,
2329
+ children
2330
+ }
2331
+ ) });
2332
+ }
2333
+ );
2334
+ var parts = createMenuParts(import_radix_ui.DropdownMenu);
2335
+ var DropdownMenuItems = parts.Items;
2336
+ var DropdownMenuItem = parts.Item;
2337
+ var DropdownMenuCheckboxItem = parts.CheckboxItem;
2338
+ var DropdownMenuRadioGroup = parts.RadioGroup;
2339
+ var DropdownMenuRadioItem = parts.RadioItem;
2340
+ var DropdownMenuGroup = parts.Group;
2341
+ var DropdownMenuLabel = parts.Label;
2342
+ var DropdownMenuSeparator = parts.Separator;
2343
+ var DropdownMenuShortcut = parts.Shortcut;
2344
+ var DropdownMenuSub = parts.Sub;
2345
+ var DropdownMenuSubTrigger = parts.SubTrigger;
2346
+ var DropdownMenuSubContent = parts.SubContent;
2347
+
2348
+ // src/components/lists/data-table-parts.tsx
2349
+ var import_jsx_runtime16 = require("react/jsx-runtime");
2350
+ var SELECT_COLUMN_ID = "select";
2351
+ function columnLabel(column) {
2352
+ const meta = column.columnDef.meta;
2353
+ if (meta?.label) return meta.label;
2354
+ const header = column.columnDef.header;
2355
+ return typeof header === "string" ? header : column.id;
2356
+ }
2357
+ function DataTableColumnHeader({
2358
+ column,
2359
+ title,
2360
+ className
2361
+ }) {
2362
+ const text = title ?? columnLabel(column);
2363
+ const hidden = column.columnDef.meta?.hideHeader;
2364
+ if (!column.getCanSort()) {
2365
+ return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)("span", { className: cn(hidden ? "sr-only" : "inline-block w-max whitespace-nowrap", className), children: text });
2366
+ }
2367
+ const sorted = column.getIsSorted();
2368
+ const Icon = sorted === "asc" ? import_lucide_react7.ChevronUpIcon : sorted === "desc" ? import_lucide_react7.ChevronDownIcon : import_lucide_react7.ChevronsUpDownIcon;
2369
+ return /* @__PURE__ */ (0, import_jsx_runtime16.jsxs)(
2370
+ "button",
2371
+ {
2372
+ type: "button",
2373
+ onClick: column.getToggleSortingHandler(),
2374
+ "data-sorted": sorted || void 0,
2375
+ className: cn(
2376
+ // w-max + nowrap: a header is never truncated; its column widens to fit it instead.
2377
+ "inline-flex w-max items-center gap-1 whitespace-nowrap rounded-sm transition-colors hover:text-default",
2378
+ "data-[sorted]:text-default",
2379
+ FOCUS_RING,
2380
+ className
2381
+ ),
2382
+ children: [
2383
+ /* @__PURE__ */ (0, import_jsx_runtime16.jsx)("span", { className: cn(hidden && "sr-only"), children: text }),
2384
+ /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
2385
+ Icon,
2386
+ {
2387
+ "aria-hidden": true,
2388
+ "data-sorted": sorted || void 0,
2389
+ className: "size-3.5 shrink-0 text-icon-default-secondary data-[sorted]:text-icon-brand"
2390
+ }
2391
+ )
2392
+ ]
2393
+ }
2394
+ );
2395
+ }
2396
+ function createSelectColumn(options = {}) {
2397
+ const { getRowLabel, selectAllLabel = "Select all rows on this page" } = options;
2398
+ return {
2399
+ id: SELECT_COLUMN_ID,
2400
+ header: ({ table }) => /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
2401
+ Checkbox,
2402
+ {
2403
+ "aria-label": selectAllLabel,
2404
+ checked: table.getIsAllPageRowsSelected(),
2405
+ indeterminate: table.getIsSomePageRowsSelected() && !table.getIsAllPageRowsSelected(),
2406
+ onCheckedChange: (checked) => table.toggleAllPageRowsSelected(checked)
2407
+ }
2408
+ ),
2409
+ cell: ({ row }) => /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
2410
+ Checkbox,
2411
+ {
2412
+ "aria-label": getRowLabel ? getRowLabel(row.original) : "Select row",
2413
+ checked: row.getIsSelected(),
2414
+ disabled: !row.getCanSelect(),
2415
+ onCheckedChange: (checked) => row.toggleSelected(checked)
2416
+ }
2417
+ ),
2418
+ enableSorting: false,
2419
+ enableHiding: false,
2420
+ enableGlobalFilter: false,
2421
+ meta: { width: "48px", interactive: true, mobile: "hidden", label: "Select" }
2422
+ };
2423
+ }
2424
+ function DataTableViewOptions({ table, label = "Columns" }) {
2425
+ const columns = table.getAllLeafColumns().filter((column) => column.getCanHide());
2426
+ if (columns.length === 0) return null;
2427
+ return /* @__PURE__ */ (0, import_jsx_runtime16.jsxs)(DropdownMenu, { children: [
2428
+ /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(DropdownMenuTrigger, { asChild: true, children: /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(Button, { variant: "neutral", size: "md", leadingIcon: /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(import_lucide_react7.Columns3Icon, { "aria-hidden": true }), children: label }) }),
2429
+ /* @__PURE__ */ (0, import_jsx_runtime16.jsxs)(DropdownMenuContent, { align: "end", children: [
2430
+ /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(DropdownMenuLabel, { children: "Show columns" }),
2431
+ columns.map((column) => /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
2432
+ DropdownMenuCheckboxItem,
2433
+ {
2434
+ checked: column.getIsVisible(),
2435
+ onCheckedChange: (visible) => column.toggleVisibility(visible),
2436
+ children: columnLabel(column)
2437
+ },
2438
+ column.id
2439
+ ))
2440
+ ] })
2441
+ ] });
2442
+ }
2443
+ function DataTablePagination({
2444
+ table,
2445
+ pageSizeOptions = [10, 20, 50],
2446
+ summary
2447
+ }) {
2448
+ const { pageIndex, pageSize } = table.getState().pagination;
2449
+ return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
2450
+ PaginationBar,
2451
+ {
2452
+ page: pageIndex + 1,
2453
+ pageSize,
2454
+ total: table.getRowCount(),
2455
+ onPageChange: (page) => table.setPageIndex(page - 1),
2456
+ onPageSizeChange: (size2) => table.setPageSize(size2),
2457
+ pageSizeOptions,
2458
+ summary,
2459
+ label: "Table pages"
2460
+ }
2461
+ );
2462
+ }
2463
+
2464
+ // src/components/lists/table.tsx
2465
+ var import_react22 = require("react");
2466
+ var import_clsx16 = __toESM(require("clsx"), 1);
2467
+ var import_lucide_react8 = require("lucide-react");
2468
+ var import_jsx_runtime17 = require("react/jsx-runtime");
2469
+ var Table = (0, import_react22.forwardRef)(function Table2({ label, density = "default", fixed = false, maxHeight, className, children, ...rest }, ref) {
2470
+ return (
2471
+ // The scroll container is separate from the table so the header stays inside the
2472
+ // scrolling region — a table that is its own scroll container cannot have a sticky
2473
+ // header.
2474
+ // The scroll wrapper is required for a <table>, which cannot itself scroll, so this
2475
+ // takes the scrollbar styling rather than ScrollArea.
2476
+ /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
2477
+ "div",
2478
+ {
2479
+ className: (0, import_clsx16.default)(
2480
+ "w-full",
2481
+ maxHeight ? (0, import_clsx16.default)("overflow-auto overscroll-contain", FOCUS_RING_INSET) : "overflow-x-auto",
2482
+ SCROLLBAR_CLASSES
2483
+ ),
2484
+ style: maxHeight ? { maxHeight } : void 0,
2485
+ ...maxHeight ? { role: "region", tabIndex: 0, "aria-label": label ? `${label} (scrolls)` : "Table (scrolls)" } : {},
2486
+ children: /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
2487
+ "table",
2488
+ {
2489
+ ref,
2490
+ "aria-label": label,
2491
+ "data-slot": "table",
2492
+ "data-density": density,
2493
+ className: cn("w-full border-collapse", fixed && "table-fixed", className),
2494
+ ...rest,
2495
+ children
2496
+ }
2497
+ )
2498
+ }
2499
+ )
2500
+ );
2501
+ });
2502
+ var TableCaption = (0, import_react22.forwardRef)(
2503
+ function TableCaption2({ className, ...rest }, ref) {
2504
+ return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
2505
+ "caption",
2506
+ {
2507
+ ref,
2508
+ className: cn("px-4 py-3 text-left text-body-sm text-default-secondary", className),
2509
+ ...rest
2510
+ }
2511
+ );
2512
+ }
2513
+ );
2514
+ var TableHeader = (0, import_react22.forwardRef)(
2515
+ function TableHeader2({ className, ...rest }, ref) {
2516
+ return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("thead", { ref, className: cn("border-b border-default", className), ...rest });
2517
+ }
2518
+ );
2519
+ var TableBody = (0, import_react22.forwardRef)(
2520
+ function TableBody2({ className, ...rest }, ref) {
2521
+ return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("tbody", { ref, className, ...rest });
2522
+ }
2523
+ );
2524
+ var TableFooter = (0, import_react22.forwardRef)(
2525
+ function TableFooter2({ className, ...rest }, ref) {
2526
+ return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
2527
+ "tfoot",
2528
+ {
2529
+ ref,
2530
+ className: cn("border-t border-default bg-default-secondary font-medium", className),
2531
+ ...rest
2532
+ }
2533
+ );
2534
+ }
2535
+ );
2536
+ var ROW_TONE = (0, import_clsx16.default)(
2537
+ "data-[tone=muted]:bg-default-secondary",
2538
+ "data-[tone=brand]:bg-brand-tertiary",
2539
+ "data-[tone=positive]:bg-positive-tertiary",
2540
+ "data-[tone=warning]:bg-warning-tertiary",
2541
+ "data-[tone=danger]:bg-danger-tertiary"
2542
+ );
2543
+ var TableRow = (0, import_react22.forwardRef)(function TableRow2({ selected, tone = "default", dimmed = false, className, ...rest }, ref) {
2544
+ return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
2545
+ "tr",
2546
+ {
2547
+ ref,
2548
+ "aria-selected": selected,
2549
+ "data-state": selected ? "selected" : void 0,
2550
+ "data-tone": tone === "default" ? void 0 : tone,
2551
+ "data-dimmed": dimmed || void 0,
2552
+ className: cn(
2553
+ "border-b border-default last:border-b-0 transition-colors",
2554
+ "hover:bg-default-secondary/50",
2555
+ ROW_TONE,
2556
+ "data-[dimmed]:opacity-60",
2557
+ "data-[state=selected]:bg-brand-tertiary",
2558
+ className
2559
+ ),
2560
+ ...rest
2561
+ }
2562
+ );
2563
+ });
2564
+ var ALIGN = { left: "text-left", center: "text-center", right: "text-right" };
2565
+ var TableHead = (0, import_react22.forwardRef)(function TableHead2({ sort, onSort, align = "left", sticky = false, className, children, ...rest }, ref) {
2566
+ const sortable = sort !== void 0 && onSort !== void 0;
2567
+ return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
2568
+ "th",
2569
+ {
2570
+ ref,
2571
+ scope: "col",
2572
+ "aria-sort": sort === void 0 ? void 0 : sort === false ? "none" : sort,
2573
+ className: cn(
2574
+ "px-4 py-3 text-body-xs font-semibold text-default-secondary",
2575
+ ALIGN[align],
2576
+ sticky && "sticky top-0 z-raised bg-default",
2577
+ className
2578
+ ),
2579
+ ...rest,
2580
+ children: sortable ? /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)(
2581
+ "button",
2582
+ {
2583
+ type: "button",
2584
+ onClick: onSort,
2585
+ className: (0, import_clsx16.default)(
2586
+ "inline-flex items-center gap-1.5 rounded transition-colors hover:text-default",
2587
+ "focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-brand focus-visible:ring-offset-1 focus-visible:ring-offset-default"
2588
+ ),
2589
+ children: [
2590
+ children,
2591
+ sort === false ? /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(import_lucide_react8.ChevronsUpDownIcon, { "aria-hidden": true, className: "size-3.5 opacity-50" }) : sort === "ascending" ? /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(import_lucide_react8.ChevronUpIcon, { "aria-hidden": true, className: "size-3.5" }) : /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(import_lucide_react8.ChevronDownIcon, { "aria-hidden": true, className: "size-3.5" })
2592
+ ]
2593
+ }
2594
+ ) : children
2595
+ }
2596
+ );
2597
+ });
2598
+ var TableCell = (0, import_react22.forwardRef)(function TableCell2({ align = "left", density = "default", header = false, className, ...rest }, ref) {
2599
+ const Tag = header ? "th" : "td";
2600
+ return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
2601
+ Tag,
2602
+ {
2603
+ ref,
2604
+ scope: header ? "row" : void 0,
2605
+ className: cn(
2606
+ density === "compact" ? "px-4 py-2" : "px-4 py-3",
2607
+ "text-body-sm text-default",
2608
+ header && "font-medium",
2609
+ ALIGN[align],
2610
+ className
2611
+ ),
2612
+ ...rest
2613
+ }
2614
+ );
2615
+ });
2616
+
2617
+ // src/components/lists/data-table-cells.tsx
2618
+ var import_clsx17 = __toESM(require("clsx"), 1);
2619
+
2620
+ // src/components/feedback/progress-bar.tsx
2621
+ var import_react23 = require("react");
2622
+ var import_jsx_runtime18 = require("react/jsx-runtime");
2623
+ var SIZE2 = {
2624
+ xs: "h-1",
2625
+ sm: "h-1.5",
2626
+ md: "h-2",
2627
+ lg: "h-3"
2628
+ };
2629
+ var FILL = {
2630
+ brand: "bg-brand",
2631
+ positive: "bg-positive",
2632
+ warning: "bg-warning",
2633
+ danger: "bg-danger",
2634
+ neutral: "bg-neutral"
2635
+ };
2636
+ function ProgressBar({
2637
+ value,
2638
+ tone = "brand",
2639
+ size: size2 = "sm",
2640
+ label,
2641
+ showValue = false,
2642
+ radius,
2643
+ "aria-label": ariaLabel,
2644
+ segments,
2645
+ valueText,
2646
+ className
2647
+ }) {
2648
+ const clamped = Math.min(100, Math.max(0, value));
2649
+ const rounded = radius ? void 0 : "rounded-full";
2650
+ const labelId = (0, import_react23.useId)();
2651
+ const filledSegments = segments ? Math.round(clamped / 100 * segments) : 0;
2652
+ const track = segments ? /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(
2653
+ "div",
2654
+ {
2655
+ role: "progressbar",
2656
+ "aria-valuenow": clamped,
2657
+ "aria-valuemin": 0,
2658
+ "aria-valuemax": 100,
2659
+ "aria-valuetext": valueText,
2660
+ "aria-labelledby": label ? labelId : void 0,
2661
+ "aria-label": label ? void 0 : ariaLabel,
2662
+ "data-tone": tone,
2663
+ className: cn("flex w-full gap-1", className),
2664
+ children: Array.from({ length: segments }, (_, index) => /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(
2665
+ "span",
2666
+ {
2667
+ "data-filled": index < filledSegments || void 0,
2668
+ className: cn("flex-1 bg-default-tertiary transition-colors", SIZE2[size2], rounded, index < filledSegments && FILL[tone]),
2669
+ style: radius ? { borderRadius: radius } : void 0
2670
+ },
2671
+ index
2672
+ ))
2673
+ }
2674
+ ) : /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(
2675
+ "div",
2676
+ {
2677
+ role: "progressbar",
2678
+ "aria-valuenow": clamped,
2679
+ "aria-valuemin": 0,
2680
+ "aria-valuemax": 100,
2681
+ "aria-valuetext": valueText,
2682
+ "data-tone": tone,
2683
+ "aria-labelledby": label ? labelId : void 0,
2684
+ "aria-label": label ? void 0 : ariaLabel,
2685
+ className: cn("w-full overflow-hidden bg-default-tertiary", SIZE2[size2], rounded, className),
2686
+ style: radius ? { borderRadius: radius } : void 0,
2687
+ children: /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(
2688
+ "div",
2689
+ {
2690
+ className: cn("h-full transition-all motion-reduce:transition-none", rounded, FILL[tone]),
2691
+ style: { width: `${clamped}%`, ...radius ? { borderRadius: radius } : void 0 }
2692
+ }
2693
+ )
2694
+ }
2695
+ );
2696
+ if (!label && !showValue) return track;
2697
+ return /* @__PURE__ */ (0, import_jsx_runtime18.jsxs)("div", { children: [
2698
+ /* @__PURE__ */ (0, import_jsx_runtime18.jsxs)("div", { className: "mb-1.5 flex items-center justify-between gap-2", children: [
2699
+ label && /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("span", { id: labelId, className: "text-body-xs text-default-secondary", children: label }),
2700
+ showValue && /* @__PURE__ */ (0, import_jsx_runtime18.jsxs)("span", { className: "ml-auto text-body-xs font-medium tabular-nums text-default", children: [
2701
+ Math.round(clamped),
2702
+ "%"
2703
+ ] })
2704
+ ] }),
2705
+ track
2706
+ ] });
2707
+ }
2708
+
2709
+ // src/components/lists/data-table-cells.tsx
2710
+ var import_jsx_runtime19 = require("react/jsx-runtime");
2711
+ function textFromNode(node) {
2712
+ if (typeof node === "string") return node;
2713
+ if (typeof node === "number") return String(node);
2714
+ if (Array.isArray(node)) {
2715
+ const parts2 = node.map(textFromNode);
2716
+ return parts2.every((part) => part !== void 0) ? parts2.join("") : void 0;
2717
+ }
2718
+ return void 0;
2719
+ }
2720
+ function TableCellLeadText({ primary, secondary, size: size2 = "md", className }) {
2721
+ return /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)("div", { className: (0, import_clsx17.default)("flex min-w-0 flex-col gap-0.5", className), children: [
2722
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
2723
+ "span",
2724
+ {
2725
+ title: primary,
2726
+ className: (0, import_clsx17.default)(
2727
+ "block truncate font-medium leading-snug text-default",
2728
+ size2 === "sm" ? "text-body-xs" : "text-body-sm"
2729
+ ),
2730
+ children: primary
2731
+ }
2732
+ ),
2733
+ secondary && (typeof secondary === "string" || typeof secondary === "number" ? /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
2734
+ "span",
2735
+ {
2736
+ title: String(secondary),
2737
+ className: (0, import_clsx17.default)(
2738
+ "block truncate font-normal leading-tight text-default-secondary",
2739
+ size2 === "sm" ? "text-body-tiny" : "text-body-xs"
2740
+ ),
2741
+ children: secondary
2742
+ }
2743
+ ) : (
2744
+ // An element brings its own overflow handling, so it gets no `truncate` here,
2745
+ // which a card layout's touch un-truncation would otherwise turn into wrapping.
2746
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
2747
+ "span",
2748
+ {
2749
+ className: (0, import_clsx17.default)(
2750
+ "block min-w-0 font-normal leading-tight text-default-secondary",
2751
+ size2 === "sm" ? "text-body-tiny" : "text-body-xs"
2752
+ ),
2753
+ children: secondary
2754
+ }
2755
+ )
2756
+ ))
2757
+ ] });
2758
+ }
2759
+ function TableCellText({
2760
+ children,
2761
+ muted = true,
2762
+ size: size2 = "md",
2763
+ truncate = true,
2764
+ className
2765
+ }) {
2766
+ return /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
2767
+ "span",
2768
+ {
2769
+ title: truncate ? textFromNode(children) : void 0,
2770
+ className: (0, import_clsx17.default)(
2771
+ "font-normal leading-snug",
2772
+ size2 === "sm" ? "text-body-tiny" : "text-body-xs",
2773
+ truncate ? "block min-w-0 truncate" : "whitespace-nowrap",
2774
+ muted ? "text-default-secondary" : "text-default",
2775
+ className
2776
+ ),
2777
+ children
2778
+ }
2779
+ );
2780
+ }
2781
+ function TableCellBadge({ label, className }) {
2782
+ return /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
2783
+ "span",
2784
+ {
2785
+ title: label,
2786
+ className: (0, import_clsx17.default)(
2787
+ "inline-flex max-w-full items-center rounded-md border border-default bg-default-secondary px-2 py-0.5 text-body-tiny font-medium text-default-secondary",
2788
+ className
2789
+ ),
2790
+ children: /* @__PURE__ */ (0, import_jsx_runtime19.jsx)("span", { className: "truncate", children: label })
2791
+ }
2792
+ );
2793
+ }
2794
+ function TableCellProgress({
2795
+ percent,
2796
+ tone = "brand",
2797
+ size: size2 = "md",
2798
+ label,
2799
+ className
2800
+ }) {
2801
+ const clamped = Math.round(Math.min(100, Math.max(0, percent)));
2802
+ return /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)("div", { className: (0, import_clsx17.default)("flex w-full min-w-0 items-center gap-2", className), children: [
2803
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
2804
+ ProgressBar,
2805
+ {
2806
+ value: clamped,
2807
+ tone,
2808
+ size: size2 === "sm" ? "xs" : "sm",
2809
+ className: "min-w-12 flex-1",
2810
+ "aria-label": label ?? `${clamped}%`
2811
+ }
2812
+ ),
2813
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)("span", { className: "shrink-0 text-body-tiny leading-none tabular-nums text-default-secondary", children: [
2814
+ clamped,
2815
+ "%"
2816
+ ] })
2817
+ ] });
2818
+ }
2819
+
2820
+ // src/components/lists/data-table.tsx
2821
+ var import_jsx_runtime20 = (
2822
+ // eslint-disable-next-line jsx-a11y/click-events-have-key-events, jsx-a11y/no-static-element-interactions
2823
+ require("react/jsx-runtime")
2824
+ );
2825
+ var DENSITY = {
2826
+ default: {
2827
+ headerCell: "px-4 py-3",
2828
+ headerText: "text-body-xs font-medium text-default-secondary",
2829
+ bodyCell: "px-4 py-[14px]"
2830
+ },
2831
+ compact: {
2832
+ headerCell: "px-3 py-2",
2833
+ headerText: "text-body-tiny font-semibold uppercase tracking-[0.4px] text-default-secondary",
2834
+ bodyCell: "px-3 py-2 text-body-xs text-default"
2835
+ }
2836
+ };
2837
+ var VERTICAL = {
2838
+ center: "align-middle",
2839
+ top: "align-top"
2840
+ };
2841
+ var TEXT_ALIGN = {
2842
+ start: "text-left",
2843
+ center: "text-center",
2844
+ end: "text-right"
2845
+ };
2846
+ var ROW_LINK_ATTR = "data-row-link";
2847
+ function resolve(updater, previous) {
2848
+ return typeof updater === "function" ? updater(previous) : updater;
2849
+ }
2850
+ function useTableState(controlled, initial, onChange) {
2851
+ const [inner, setInner] = (0, import_react24.useState)(initial);
2852
+ const value = controlled ?? inner;
2853
+ const latest = (0, import_react24.useRef)(value);
2854
+ latest.current = value;
2855
+ const isControlled = controlled !== void 0;
2856
+ const onChangeRef = (0, import_react24.useRef)(onChange);
2857
+ onChangeRef.current = onChange;
2858
+ const set = (0, import_react24.useCallback)(
2859
+ (updater) => {
2860
+ const next = resolve(updater, latest.current);
2861
+ if (!isControlled) setInner(next);
2862
+ onChangeRef.current?.(next);
2863
+ },
2864
+ [isControlled]
2865
+ );
2866
+ return [value, set];
2867
+ }
2868
+ function CellInteractionGuard({ children }) {
2869
+ return /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
2870
+ "div",
2871
+ {
2872
+ className: "contents",
2873
+ onClick: (event) => event.stopPropagation(),
2874
+ onKeyDown: (event) => event.stopPropagation(),
2875
+ onKeyUp: (event) => event.stopPropagation(),
2876
+ children
2877
+ }
2878
+ );
2879
+ }
2880
+ var HEADER_PADDING_PX = { default: 32, compact: 24 };
2881
+ function useHeaderWidths(padding, deps) {
2882
+ const nodes = (0, import_react24.useRef)(/* @__PURE__ */ new Map());
2883
+ const [widths, setWidths] = (0, import_react24.useState)({});
2884
+ const measure = (0, import_react24.useCallback)(() => {
2885
+ const next = {};
2886
+ nodes.current.forEach((node, id) => {
2887
+ next[id] = Math.ceil(node.getBoundingClientRect().width) + padding;
2888
+ });
2889
+ setWidths((previous) => {
2890
+ const keys = Object.keys(next);
2891
+ const same = keys.length === Object.keys(previous).length && keys.every((key) => previous[key] === next[key]);
2892
+ return same ? previous : next;
2893
+ });
2894
+ }, [padding]);
2895
+ (0, import_react24.useLayoutEffect)(measure, [measure, deps]);
2896
+ (0, import_react24.useLayoutEffect)(() => {
2897
+ let live = true;
2898
+ void document.fonts?.ready.then(() => live && measure());
2899
+ return () => {
2900
+ live = false;
2901
+ };
2902
+ }, [measure]);
2903
+ const register = (0, import_react24.useCallback)(
2904
+ (id) => (node) => {
2905
+ if (node) nodes.current.set(id, node);
2906
+ else nodes.current.delete(id);
2907
+ },
2908
+ []
2909
+ );
2910
+ return { widths, register };
2911
+ }
2912
+ function useScrollEdges() {
2913
+ const [node, setNode] = (0, import_react24.useState)(null);
2914
+ const [edges, setEdges] = (0, import_react24.useState)({ overflowing: false, atStart: true, atEnd: true, overflowingY: false, atTop: true });
2915
+ const measure = (0, import_react24.useCallback)(() => {
2916
+ if (!node) return;
2917
+ const { scrollLeft, scrollWidth, clientWidth, scrollTop, scrollHeight, clientHeight } = node;
2918
+ const next = {
2919
+ overflowing: scrollWidth > clientWidth + 1,
2920
+ atStart: scrollLeft <= 1,
2921
+ atEnd: scrollLeft + clientWidth >= scrollWidth - 1,
2922
+ overflowingY: scrollHeight > clientHeight + 1,
2923
+ atTop: scrollTop <= 1
2924
+ };
2925
+ setEdges(
2926
+ (previous) => previous.overflowing === next.overflowing && previous.atStart === next.atStart && previous.atEnd === next.atEnd && previous.overflowingY === next.overflowingY && previous.atTop === next.atTop ? previous : next
2927
+ );
2928
+ }, [node]);
2929
+ (0, import_react24.useLayoutEffect)(() => {
2930
+ if (!node) return;
2931
+ measure();
2932
+ if (typeof ResizeObserver === "undefined") return;
2933
+ const observer = new ResizeObserver(measure);
2934
+ observer.observe(node);
2935
+ if (node.firstElementChild) observer.observe(node.firstElementChild);
2936
+ return () => observer.disconnect();
2937
+ }, [node, measure]);
2938
+ return { ref: setNode, onScroll: measure, ...edges };
2939
+ }
2940
+ var serverSortedValue = () => void 0;
2941
+ function defaultRowLink({ children, ...props }) {
2942
+ return /* @__PURE__ */ (0, import_jsx_runtime20.jsx)("a", { ...props, children });
2943
+ }
2944
+ function DataTable({
2945
+ columns,
2946
+ data,
2947
+ getRowId,
2948
+ label,
2949
+ caption,
2950
+ searchable = false,
2951
+ columnVisibility: showColumnMenu = false,
2952
+ pagination: paginated = true,
2953
+ pageSize = 10,
2954
+ pageSizeOptions = [10, 20, 50],
2955
+ enableRowSelection,
2956
+ onSelectionChange,
2957
+ getRowLabel,
2958
+ onRowClick,
2959
+ getRowHref,
2960
+ renderRowLink = defaultRowLink,
2961
+ getRowTone,
2962
+ getRowDimmed,
2963
+ loading = false,
2964
+ loadingRows = 5,
2965
+ error,
2966
+ onRetry,
2967
+ empty = "No results found.",
2968
+ toolbar,
2969
+ footer,
2970
+ density = "default",
2971
+ align = "center",
2972
+ responsive = true,
2973
+ maxHeight,
2974
+ manual = {},
2975
+ state = {},
2976
+ onSortingChange,
2977
+ onGlobalFilterChange,
2978
+ onColumnFiltersChange,
2979
+ onPaginationChange,
2980
+ onColumnVisibilityChange,
2981
+ onRowSelectionChange,
2982
+ tableOptions,
2983
+ className
2984
+ }) {
2985
+ if (!label && !caption) {
2986
+ devWarn('DataTable needs `label` or `caption`: an unnamed table is announced as just "table".');
2987
+ }
2988
+ if (manual.pagination && manual.rowCount === void 0) {
2989
+ devWarn("DataTable `manual.pagination` needs `manual.rowCount` to know how many pages there are.");
2990
+ }
2991
+ const [sorting, setSorting] = useTableState(state.sorting, [], onSortingChange);
2992
+ const [globalFilter, setGlobalFilter] = useTableState(state.globalFilter, "", onGlobalFilterChange);
2993
+ const [columnFilters, setColumnFilters] = useTableState(state.columnFilters, [], onColumnFiltersChange);
2994
+ const [pagination, setPagination] = useTableState(
2995
+ state.pagination,
2996
+ { pageIndex: 0, pageSize },
2997
+ onPaginationChange
2998
+ );
2999
+ const [columnVisibility, setColumnVisibility] = useTableState(
3000
+ state.columnVisibility,
3001
+ {},
3002
+ onColumnVisibilityChange
3003
+ );
3004
+ const [rowSelection, setRowSelection] = useTableState(state.rowSelection, {}, onRowSelectionChange);
3005
+ const allColumns = (0, import_react24.useMemo)(() => {
3006
+ let cols = columns;
3007
+ if (manual.sorting) {
3008
+ cols = cols.map(
3009
+ (column) => column.enableSorting === true && !("accessorFn" in column) && !("accessorKey" in column) ? { ...column, accessorFn: serverSortedValue } : column
3010
+ );
3011
+ }
3012
+ if (!enableRowSelection || cols.some((column) => column.id === SELECT_COLUMN_ID)) return cols;
3013
+ return [createSelectColumn({ getRowLabel: getRowLabel && ((row) => `Select ${getRowLabel(row)}`) }), ...cols];
3014
+ }, [columns, enableRowSelection, getRowLabel, manual.sorting]);
3015
+ const table = (0, import_react_table.useReactTable)({
3016
+ data,
3017
+ columns: allColumns,
3018
+ getRowId,
3019
+ state: { sorting, globalFilter, columnFilters, pagination, columnVisibility, rowSelection },
3020
+ onSortingChange: setSorting,
3021
+ onGlobalFilterChange: setGlobalFilter,
3022
+ onColumnFiltersChange: setColumnFilters,
3023
+ onPaginationChange: setPagination,
3024
+ onColumnVisibilityChange: setColumnVisibility,
3025
+ onRowSelectionChange: setRowSelection,
3026
+ enableRowSelection: typeof enableRowSelection === "function" ? (row) => enableRowSelection(row.original) : Boolean(enableRowSelection),
3027
+ getCoreRowModel: (0, import_react_table.getCoreRowModel)(),
3028
+ getSortedRowModel: manual.sorting ? void 0 : (0, import_react_table.getSortedRowModel)(),
3029
+ getFilteredRowModel: manual.filtering ? void 0 : (0, import_react_table.getFilteredRowModel)(),
3030
+ getPaginationRowModel: paginated && !manual.pagination ? (0, import_react_table.getPaginationRowModel)() : void 0,
3031
+ manualSorting: manual.sorting,
3032
+ manualFiltering: manual.filtering,
3033
+ manualPagination: !paginated || manual.pagination,
3034
+ rowCount: manual.rowCount,
3035
+ // Two states from 0.9.4: a third click no longer clears the sort. "Off" is not a direction a
3036
+ // person can see or ask for, and it silently reverted to an order nobody chose. Pass
3037
+ // `tableOptions={{ enableSortingRemoval: true }}` for the three-state cycle.
3038
+ enableSortingRemoval: false,
3039
+ ...tableOptions
3040
+ });
3041
+ const selectionReported = (0, import_react24.useRef)(false);
3042
+ (0, import_react24.useEffect)(() => {
3043
+ if (!onSelectionChange) return;
3044
+ if (!selectionReported.current) {
3045
+ selectionReported.current = true;
3046
+ return;
3047
+ }
3048
+ onSelectionChange(table.getSelectedRowModel().rows.map((row) => row.original));
3049
+ }, [rowSelection]);
3050
+ const [wrapRef, containerWidth] = useElementWidth();
3051
+ const breakpoint = responsive === false ? 0 : typeof responsive === "object" ? responsive.breakpoint ?? DEFAULT_CARD_BREAKPOINT_PX : DEFAULT_CARD_BREAKPOINT_PX;
3052
+ const modeRef = (0, import_react24.useRef)("table");
3053
+ const mode = nextLayoutMode(modeRef.current, containerWidth, breakpoint);
3054
+ modeRef.current = mode;
3055
+ const search = searchable === true ? {} : searchable || void 0;
3056
+ const searchColumn = search?.columnId ? table.getColumn(search.columnId) : void 0;
3057
+ const searchValue = searchColumn ? String(searchColumn.getFilterValue() ?? "") : globalFilter;
3058
+ const setSearchValue = (value) => {
3059
+ if (searchColumn) searchColumn.setFilterValue(value || void 0);
3060
+ else table.setGlobalFilter(value);
3061
+ };
3062
+ const filtering = Boolean(globalFilter) || columnFilters.length > 0;
3063
+ const rows = table.getRowModel().rows;
3064
+ const isEmpty = !loading && !error && rows.length === 0;
3065
+ const placeholder = error ? /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
3066
+ EmptyState,
3067
+ {
3068
+ message: typeof error === "string" ? error : "Something went wrong loading this data.",
3069
+ variant: "error",
3070
+ size: "md",
3071
+ action: onRetry ? /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(Button, { variant: "neutral", size: "sm", onClick: onRetry, children: "Retry" }) : void 0,
3072
+ className: "mx-auto max-w-[520px]"
3073
+ }
3074
+ ) : isEmpty ? typeof empty === "string" ? /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(EmptyState, { message: empty, size: "md", className: "mx-auto max-w-[520px]" }) : empty : null;
3075
+ const resultCount = manual.filtering ? table.getRowCount() : table.getFilteredRowModel().rows.length;
3076
+ const showToolbar = Boolean(search || toolbar || showColumnMenu);
3077
+ const showPager = paginated && !error && table.getRowCount() > 0;
3078
+ const view = {
3079
+ table,
3080
+ label,
3081
+ caption,
3082
+ density,
3083
+ align,
3084
+ loading,
3085
+ loadingRows,
3086
+ placeholder,
3087
+ onRowClick,
3088
+ getRowHref,
3089
+ renderRowLink,
3090
+ getRowTone,
3091
+ getRowDimmed,
3092
+ getRowLabel,
3093
+ maxHeight
3094
+ };
3095
+ return /* @__PURE__ */ (0, import_jsx_runtime20.jsxs)("div", { "data-slot": "data-table", className: cn("relative flex flex-col gap-3", className), children: [
3096
+ showToolbar && /* @__PURE__ */ (0, import_jsx_runtime20.jsxs)("div", { className: "flex flex-wrap items-center gap-2", children: [
3097
+ search && /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
3098
+ SearchInput,
3099
+ {
3100
+ size: "md",
3101
+ label: search.label ?? "Search",
3102
+ placeholder: search.placeholder ?? "Search\u2026",
3103
+ value: searchValue,
3104
+ onChange: (event) => setSearchValue(event.target.value),
3105
+ onClear: () => setSearchValue(""),
3106
+ className: "w-full max-w-[280px]"
3107
+ }
3108
+ ),
3109
+ toolbar,
3110
+ showColumnMenu && /* @__PURE__ */ (0, import_jsx_runtime20.jsx)("div", { className: "ml-auto", children: /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(DataTableViewOptions, { table }) })
3111
+ ] }),
3112
+ /* @__PURE__ */ (0, import_jsx_runtime20.jsx)("p", { role: "status", "aria-live": "polite", className: "sr-only", children: filtering && !loading ? `${resultCount} ${resultCount === 1 ? "result" : "results"}` : "" }),
3113
+ /* @__PURE__ */ (0, import_jsx_runtime20.jsxs)("div", { ref: wrapRef, className: "overflow-hidden rounded-xl border border-default bg-default", children: [
3114
+ mode === "cards" ? maxHeight ? /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(CardScroll, { label, maxHeight, children: /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(CardList, { ...view }) }) : /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(CardList, { ...view }) : /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(TableView, { ...view }),
3115
+ showPager && /* @__PURE__ */ (0, import_jsx_runtime20.jsx)("div", { className: "border-t border-default px-4 py-3", children: /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(DataTablePagination, { table, pageSizeOptions }) }),
3116
+ footer && /* @__PURE__ */ (0, import_jsx_runtime20.jsx)("div", { className: "border-t border-default px-4 py-3", children: footer })
3117
+ ] })
3118
+ ] });
3119
+ }
3120
+ function titleColumnId(columns) {
3121
+ const content = columns.filter((column) => column.id !== SELECT_COLUMN_ID);
3122
+ return (content.find((column) => column.columnDef.meta?.mobile === "title") ?? content[0])?.id;
3123
+ }
3124
+ function TableView({
3125
+ table,
3126
+ label,
3127
+ caption,
3128
+ density,
3129
+ align,
3130
+ loading,
3131
+ loadingRows,
3132
+ placeholder,
3133
+ onRowClick,
3134
+ getRowHref,
3135
+ renderRowLink,
3136
+ getRowTone,
3137
+ getRowDimmed,
3138
+ maxHeight
3139
+ }) {
3140
+ const d = DENSITY[density];
3141
+ const columns = table.getVisibleLeafColumns();
3142
+ const scroll = useScrollEdges();
3143
+ const headers = useHeaderWidths(HEADER_PADDING_PX[density], columns.map((column) => column.id).join());
3144
+ const columnPx = (column) => Math.max(widthToPx(column.columnDef.meta?.width), headers.widths[column.id] ?? 0);
3145
+ const minWidth = columns.reduce((sum, column) => sum + columnPx(column), 0);
3146
+ const showPlaceholder = loading || placeholder !== null;
3147
+ const first = columns[0];
3148
+ const last = columns[columns.length - 1];
3149
+ const stickyStart = scroll.overflowing && first?.columnDef.meta?.sticky === "start" ? first.id : void 0;
3150
+ const stickyEnd = scroll.overflowing && last?.columnDef.meta?.sticky === "end" && last !== first ? last.id : void 0;
3151
+ const hasSticky = Boolean(stickyStart || stickyEnd);
3152
+ const titleId = titleColumnId(columns);
3153
+ const rowAction = getRowHref ? "link" : onRowClick ? "click" : null;
3154
+ const stickyClass = (id, header) => (0, import_clsx18.default)(
3155
+ id === stickyStart && [
3156
+ "sticky left-0 z-raised",
3157
+ // A hairline where content slides under the pinned column, once it has scrolled.
3158
+ !scroll.atStart && "shadow-[inset_-1px_0_0_var(--color-border-default-default)]"
3159
+ ],
3160
+ id === stickyEnd && [
3161
+ "sticky right-0 z-raised",
3162
+ !scroll.atEnd && "shadow-[inset_1px_0_0_var(--color-border-default-default)]"
3163
+ ],
3164
+ (id === stickyStart || id === stickyEnd) && (header ? "bg-default-secondary" : ["bg-default", rowAction && "group-hover:bg-default-secondary"])
3165
+ );
3166
+ const scrolls = scroll.overflowing || Boolean(maxHeight) && scroll.overflowingY;
3167
+ const direction = scroll.overflowing && maxHeight && scroll.overflowingY ? "scrolls" : scroll.overflowing ? "scrolls horizontally" : "scrolls vertically";
3168
+ const regionLabel = `${label ?? "Table"} (${direction})`;
3169
+ const pinnedHeader = maxHeight ? (0, import_clsx18.default)("sticky top-0 z-sticky bg-default-secondary", !scroll.atTop && "shadow-[inset_0_-1px_0_var(--color-border-default-default)]") : void 0;
3170
+ return /* @__PURE__ */ (0, import_jsx_runtime20.jsxs)("div", { className: "relative", children: [
3171
+ /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
3172
+ "div",
3173
+ {
3174
+ ref: scroll.ref,
3175
+ onScroll: scroll.onScroll,
3176
+ className: cn(
3177
+ maxHeight ? "overflow-auto overscroll-contain" : "overflow-x-auto overscroll-x-contain",
3178
+ SCROLLBAR_CLASSES,
3179
+ scrolls && FOCUS_RING_INSET
3180
+ ),
3181
+ style: maxHeight ? { maxHeight } : void 0,
3182
+ ...scrolls ? { role: "region", tabIndex: 0, "aria-label": regionLabel } : {},
3183
+ children: /* @__PURE__ */ (0, import_jsx_runtime20.jsxs)(
3184
+ "table",
3185
+ {
3186
+ className: "w-full table-fixed border-collapse text-left",
3187
+ style: showPlaceholder ? void 0 : { minWidth },
3188
+ "aria-busy": loading || void 0,
3189
+ children: [
3190
+ caption ? /* @__PURE__ */ (0, import_jsx_runtime20.jsx)("caption", { className: "px-4 pt-3 text-left text-body-sm text-default-secondary", children: caption }) : label && /* @__PURE__ */ (0, import_jsx_runtime20.jsx)("caption", { className: "sr-only", children: label }),
3191
+ /* @__PURE__ */ (0, import_jsx_runtime20.jsx)("colgroup", { children: columns.map((column) => {
3192
+ const meta = column.columnDef.meta;
3193
+ const floor = headers.widths[column.id] ?? 0;
3194
+ return /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
3195
+ "col",
3196
+ {
3197
+ style: meta?.grow || !meta?.width ? void 0 : { width: floor > widthToPx(meta.width) ? floor : meta.width }
3198
+ },
3199
+ column.id
3200
+ );
3201
+ }) }),
3202
+ /* @__PURE__ */ (0, import_jsx_runtime20.jsx)("thead", { children: table.getHeaderGroups().map((group) => /* @__PURE__ */ (0, import_jsx_runtime20.jsx)("tr", { className: "bg-default-secondary", children: group.headers.map((header) => {
3203
+ const meta = header.column.columnDef.meta;
3204
+ const sortable = header.column.getCanSort();
3205
+ const sorted = header.column.getIsSorted();
3206
+ const definition = header.column.columnDef.header;
3207
+ return /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
3208
+ "th",
3209
+ {
3210
+ scope: "col",
3211
+ colSpan: header.colSpan,
3212
+ "aria-sort": sortable ? sorted === "asc" ? "ascending" : sorted === "desc" ? "descending" : "none" : void 0,
3213
+ className: cn(
3214
+ d.headerCell,
3215
+ d.headerText,
3216
+ TEXT_ALIGN[meta?.align ?? "start"],
3217
+ !meta?.interactive && "overflow-hidden",
3218
+ stickyClass(header.column.id, true),
3219
+ pinnedHeader,
3220
+ meta?.headerClassName
3221
+ ),
3222
+ children: header.isPlaceholder ? null : typeof definition === "string" || definition === void 0 ? /* @__PURE__ */ (0, import_jsx_runtime20.jsx)("span", { ref: meta?.hideHeader ? void 0 : headers.register(header.column.id), className: "inline-block", children: /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(DataTableColumnHeader, { column: header.column }) }) : (0, import_react_table.flexRender)(definition, header.getContext())
3223
+ },
3224
+ header.id
3225
+ );
3226
+ }) }, group.id)) }),
3227
+ /* @__PURE__ */ (0, import_jsx_runtime20.jsx)("tbody", { children: loading && !placeholder ? Array.from({ length: loadingRows }, (_, index) => /* @__PURE__ */ (0, import_jsx_runtime20.jsx)("tr", { className: (0, import_clsx18.default)(index > 0 && "border-t border-default"), children: columns.map((column) => /* @__PURE__ */ (0, import_jsx_runtime20.jsx)("td", { className: (0, import_clsx18.default)(d.bodyCell, "align-middle"), children: /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(Skeleton, { className: column.columnDef.meta?.grow ? "w-[70%]" : "w-[55%]" }) }, column.id)) }, `skeleton-${index}`)) : placeholder ? /* @__PURE__ */ (0, import_jsx_runtime20.jsx)("tr", { children: /* @__PURE__ */ (0, import_jsx_runtime20.jsx)("td", { colSpan: columns.length, className: "px-4", children: placeholder }) }) : table.getRowModel().rows.map((row) => /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
3228
+ BodyRow,
3229
+ {
3230
+ row,
3231
+ density,
3232
+ align,
3233
+ titleId,
3234
+ rowAction,
3235
+ hasSticky,
3236
+ stickyClass,
3237
+ onRowClick,
3238
+ getRowHref,
3239
+ renderRowLink,
3240
+ getRowTone,
3241
+ getRowDimmed
3242
+ },
3243
+ row.id
3244
+ )) })
3245
+ ]
3246
+ }
3247
+ )
3248
+ }
3249
+ ),
3250
+ scroll.overflowing && !scroll.atStart && !stickyStart && /* @__PURE__ */ (0, import_jsx_runtime20.jsx)("span", { "aria-hidden": true, className: "pointer-events-none absolute inset-y-0 left-0 w-6 bg-gradient-to-r from-default-secondary to-transparent" }),
3251
+ scroll.overflowing && !scroll.atEnd && !stickyEnd && /* @__PURE__ */ (0, import_jsx_runtime20.jsx)("span", { "aria-hidden": true, className: "pointer-events-none absolute inset-y-0 right-0 w-6 bg-gradient-to-l from-default-secondary to-transparent" })
3252
+ ] });
3253
+ }
3254
+ function BodyRow({
3255
+ row,
3256
+ density,
3257
+ align,
3258
+ titleId,
3259
+ rowAction,
3260
+ hasSticky,
3261
+ stickyClass,
3262
+ onRowClick,
3263
+ getRowHref,
3264
+ renderRowLink,
3265
+ getRowTone,
3266
+ getRowDimmed
3267
+ }) {
3268
+ const d = DENSITY[density];
3269
+ const href = getRowHref?.(row.original);
3270
+ return /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
3271
+ TableRow,
3272
+ {
3273
+ selected: row.getIsSelected() || void 0,
3274
+ tone: getRowTone?.(row.original),
3275
+ dimmed: getRowDimmed?.(row.original),
3276
+ className: cn(
3277
+ "group",
3278
+ rowAction && ["cursor-pointer", hasSticky && "hover:bg-default-secondary"],
3279
+ // outline, not ring: `ring-*` is box-shadow, which browsers do not paint on a <tr>
3280
+ // under border-collapse.
3281
+ rowAction === "click" && "outline-none focus-visible:outline focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-brand"
3282
+ ),
3283
+ tabIndex: rowAction === "click" ? 0 : void 0,
3284
+ onClick: rowAction === "link" ? (event) => {
3285
+ if (event.target.closest("a")) return;
3286
+ event.currentTarget.querySelector(`[${ROW_LINK_ATTR}]`)?.click();
3287
+ } : rowAction === "click" ? () => onRowClick(row.original) : void 0,
3288
+ onKeyDown: rowAction === "click" ? (event) => {
3289
+ if (event.target !== event.currentTarget) return;
3290
+ if (event.key === "Enter" || event.key === " ") {
3291
+ event.preventDefault();
3292
+ onRowClick(row.original);
3293
+ }
3294
+ } : void 0,
3295
+ children: row.getVisibleCells().map((cell) => /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
3296
+ BodyCell,
3297
+ {
3298
+ cell,
3299
+ className: cn(d.bodyCell, VERTICAL[align], stickyClass(cell.column.id, false)),
3300
+ link: href && cell.column.id === titleId ? href : void 0,
3301
+ renderRowLink
3302
+ },
3303
+ cell.id
3304
+ ))
3305
+ }
3306
+ );
3307
+ }
3308
+ function BodyCell({
3309
+ cell,
3310
+ className,
3311
+ link,
3312
+ renderRowLink
3313
+ }) {
3314
+ const meta = cell.column.columnDef.meta;
3315
+ let content = (0, import_react_table.flexRender)(cell.column.columnDef.cell, cell.getContext());
3316
+ if (link) {
3317
+ content = renderRowLink({
3318
+ href: link,
3319
+ [ROW_LINK_ATTR]: "",
3320
+ className: cn("block min-w-0 rounded-sm", FOCUS_RING_INSET),
3321
+ children: content
3322
+ }, cell.row.original);
3323
+ }
3324
+ return /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
3325
+ "td",
3326
+ {
3327
+ className: cn(
3328
+ className,
3329
+ TEXT_ALIGN[meta?.align ?? "start"],
3330
+ // Guards against a bespoke cell bleeding into the next column. Interactive cells opt
3331
+ // out so focus rings are not clipped.
3332
+ !meta?.interactive && "overflow-hidden",
3333
+ meta?.cellClassName
3334
+ ),
3335
+ children: meta?.interactive ? /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(CellInteractionGuard, { children: content }) : content
3336
+ }
3337
+ );
3338
+ }
3339
+ function CardScroll({ label, maxHeight, children }) {
3340
+ const scroll = useScrollEdges();
3341
+ return /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
3342
+ "div",
3343
+ {
3344
+ ref: scroll.ref,
3345
+ onScroll: scroll.onScroll,
3346
+ style: { maxHeight },
3347
+ className: cn("overflow-y-auto overscroll-contain", SCROLLBAR_CLASSES, scroll.overflowingY && FOCUS_RING_INSET),
3348
+ ...scroll.overflowingY ? { role: "region", tabIndex: 0, "aria-label": `${label ?? "Table"} (scrolls vertically)` } : {},
3349
+ children
3350
+ }
3351
+ );
3352
+ }
3353
+ function CardList({
3354
+ table,
3355
+ label,
3356
+ loading,
3357
+ loadingRows,
3358
+ placeholder,
3359
+ onRowClick,
3360
+ getRowHref,
3361
+ renderRowLink,
3362
+ getRowTone,
3363
+ getRowDimmed,
3364
+ getRowLabel
3365
+ }) {
3366
+ if (placeholder) return /* @__PURE__ */ (0, import_jsx_runtime20.jsx)("div", { className: "px-4", children: placeholder });
3367
+ if (loading) {
3368
+ return /* @__PURE__ */ (0, import_jsx_runtime20.jsx)("ul", { "aria-label": label, "aria-busy": "true", className: "divide-y divide-default", children: Array.from({ length: loadingRows }, (_, index) => /* @__PURE__ */ (0, import_jsx_runtime20.jsxs)("li", { className: "flex flex-col gap-3 p-4", children: [
3369
+ /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(Skeleton, { className: "w-2/3" }),
3370
+ /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(Skeleton, { className: "w-1/2" }),
3371
+ /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(Skeleton, { className: "w-5/6" })
3372
+ ] }, index)) });
3373
+ }
3374
+ const columns = table.getVisibleLeafColumns();
3375
+ const selectable = columns.some((column) => column.id === SELECT_COLUMN_ID);
3376
+ const slots = cardSlots(
3377
+ columns.filter((column) => column.id !== SELECT_COLUMN_ID).map((column) => ({ id: column.id, mobile: column.columnDef.meta?.mobile, column }))
3378
+ );
3379
+ const trigger = (0, import_clsx18.default)(
3380
+ "block w-full min-w-0 text-left focus-visible:outline-none",
3381
+ "after:absolute after:inset-0 after:content-['']",
3382
+ "focus-visible:after:ring-2 focus-visible:after:ring-inset focus-visible:after:ring-brand"
3383
+ );
3384
+ return (
3385
+ // Card mode un-truncates: on touch there is no hover tooltip, so a clipped value would be
3386
+ // unreadable. `.truncate` cell renderers wrap here instead.
3387
+ /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
3388
+ "ul",
3389
+ {
3390
+ "aria-label": label,
3391
+ className: "divide-y divide-default [&_.truncate]:whitespace-normal [&_.truncate]:[overflow-wrap:anywhere]",
3392
+ children: table.getRowModel().rows.map((row) => {
3393
+ const cells = new Map(row.getVisibleCells().map((cell) => [cell.column.id, cell]));
3394
+ const render = (id) => {
3395
+ const cell = id ? cells.get(id) : void 0;
3396
+ return cell ? (0, import_react_table.flexRender)(cell.column.columnDef.cell, cell.getContext()) : null;
3397
+ };
3398
+ const href = getRowHref?.(row.original);
3399
+ const titleContent = render(slots.title?.id);
3400
+ const tone = getRowTone?.(row.original);
3401
+ return /* @__PURE__ */ (0, import_jsx_runtime20.jsxs)(
3402
+ "li",
3403
+ {
3404
+ "data-state": row.getIsSelected() ? "selected" : void 0,
3405
+ "data-tone": tone && tone !== "default" ? tone : void 0,
3406
+ "data-dimmed": getRowDimmed?.(row.original) || void 0,
3407
+ className: cn(
3408
+ "relative flex flex-col gap-3 p-4 transition-colors",
3409
+ (href || onRowClick) && "hover:bg-default-secondary/50",
3410
+ "data-[tone=muted]:bg-default-secondary data-[tone=brand]:bg-brand-tertiary",
3411
+ "data-[tone=positive]:bg-positive-tertiary data-[tone=warning]:bg-warning-tertiary",
3412
+ "data-[tone=danger]:bg-danger-tertiary data-[dimmed]:opacity-60",
3413
+ "data-[state=selected]:bg-brand-tertiary"
3414
+ ),
3415
+ children: [
3416
+ /* @__PURE__ */ (0, import_jsx_runtime20.jsxs)("div", { className: "flex items-start gap-3", children: [
3417
+ selectable && /* @__PURE__ */ (0, import_jsx_runtime20.jsx)("div", { className: "relative z-raised shrink-0 pt-0.5", children: render(SELECT_COLUMN_ID) }),
3418
+ /* @__PURE__ */ (0, import_jsx_runtime20.jsx)("div", { className: "min-w-0 flex-1", children: href ? renderRowLink({ href, [ROW_LINK_ATTR]: "", className: trigger, children: titleContent }, row.original) : onRowClick ? /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
3419
+ "button",
3420
+ {
3421
+ type: "button",
3422
+ className: trigger,
3423
+ "aria-label": getRowLabel?.(row.original),
3424
+ onClick: () => onRowClick(row.original),
3425
+ children: titleContent
3426
+ }
3427
+ ) : titleContent }),
3428
+ slots.status && // A status pill is `nowrap`, so a long label would spill off the card. Let it
3429
+ // wrap inside the cap instead.
3430
+ /* @__PURE__ */ (0, import_jsx_runtime20.jsx)("div", { className: "flex max-w-[45%] shrink-0 justify-end [&_.whitespace-nowrap]:whitespace-normal", children: render(slots.status.id) }),
3431
+ slots.actions && /* @__PURE__ */ (0, import_jsx_runtime20.jsx)("div", { className: "relative z-raised shrink-0", children: /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(CellInteractionGuard, { children: render(slots.actions.id) }) })
3432
+ ] }),
3433
+ slots.fields.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime20.jsx)("dl", { className: "grid grid-cols-[repeat(auto-fit,minmax(min(100%,8.5rem),1fr))] gap-x-4 gap-y-2.5", children: slots.fields.map(({ id, column }) => /* @__PURE__ */ (0, import_jsx_runtime20.jsxs)("div", { className: (0, import_clsx18.default)("min-w-0", column.columnDef.meta?.interactive && "relative z-raised"), children: [
3434
+ /* @__PURE__ */ (0, import_jsx_runtime20.jsx)("dt", { className: "text-body-tiny text-default-secondary", children: columnLabel(column) }),
3435
+ /* @__PURE__ */ (0, import_jsx_runtime20.jsx)("dd", { className: "mt-0.5 min-w-0 text-body-xs text-default", children: column.columnDef.meta?.interactive ? /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(CellInteractionGuard, { children: render(id) }) : render(id) })
3436
+ ] }, id)) })
3437
+ ]
3438
+ },
3439
+ row.id
3440
+ );
3441
+ })
3442
+ }
3443
+ )
3444
+ );
3445
+ }
3446
+
3447
+ // src/data-table.tsx
3448
+ var import_react_table2 = require("@tanstack/react-table");
3449
+ // Annotate the CommonJS export names for ESM import in node:
3450
+ 0 && (module.exports = {
3451
+ DataTable,
3452
+ DataTableColumnHeader,
3453
+ DataTablePagination,
3454
+ DataTableViewOptions,
3455
+ SELECT_COLUMN_ID,
3456
+ TableCellBadge,
3457
+ TableCellLeadText,
3458
+ TableCellProgress,
3459
+ TableCellText,
3460
+ createColumnHelper,
3461
+ createSelectColumn
3462
+ });
3463
+ //# sourceMappingURL=data-table.cjs.map