@krizaka/ui 3.21.0 → 3.22.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/dist/app-shell.js +1 -1
- package/dist/argument-card.js +3 -3
- package/dist/{chunk-5MH64NIL.js → chunk-2L67YTNV.js} +2 -2
- package/dist/chunk-AQSZJJAJ.js +126 -0
- package/dist/chunk-AQSZJJAJ.js.map +1 -0
- package/dist/{chunk-3GODX3D6.js → chunk-QDXV544C.js} +2 -2
- package/dist/chunk-QDXV544C.js.map +1 -0
- package/dist/chunk-R6NK6ZNY.js +1080 -0
- package/dist/chunk-R6NK6ZNY.js.map +1 -0
- package/dist/{chunk-LIPK4UCS.js → chunk-YCIBJ6OQ.js} +140 -209
- package/dist/chunk-YCIBJ6OQ.js.map +1 -0
- package/dist/comparison-table.d.ts +44 -0
- package/dist/comparison-table.js +84 -0
- package/dist/comparison-table.js.map +1 -0
- package/dist/data-table.js +19 -1066
- package/dist/data-table.js.map +1 -1
- package/dist/date-picker.js +3 -3
- package/dist/genui.d.ts +219 -0
- package/dist/genui.js +506 -0
- package/dist/genui.js.map +1 -0
- package/dist/index.d.ts +17 -24
- package/dist/index.js +1 -1
- package/dist/marketing-layout.js +1 -1
- package/dist/marketing-layout.js.map +1 -1
- package/dist/media-grid.js +43 -151
- package/dist/media-grid.js.map +1 -1
- package/dist/meta-row.d.ts +54 -0
- package/dist/meta-row.js +35 -0
- package/dist/meta-row.js.map +1 -0
- package/dist/native.d.ts +25 -16
- package/dist/native.js +493 -520
- package/dist/native.js.map +1 -1
- package/dist/nav-bar.js +2 -2
- package/dist/page-hero.js +3 -3
- package/dist/site-footer.js +2 -2
- package/dist/skip-link.js +1 -1
- package/dist/step-showcase.d.ts +62 -0
- package/dist/step-showcase.js +227 -0
- package/dist/step-showcase.js.map +1 -0
- package/package.json +61 -4
- package/registry/achievement.json +1 -1
- package/registry/action-bar.json +1 -1
- package/registry/activity-feed.json +1 -1
- package/registry/alert.json +1 -1
- package/registry/app-shell.json +1 -1
- package/registry/argument-card.json +1 -1
- package/registry/audio-player.json +1 -1
- package/registry/auth-layout.json +1 -1
- package/registry/avatar.json +1 -1
- package/registry/badge.json +1 -1
- package/registry/button.json +1 -1
- package/registry/card-grid.json +1 -1
- package/registry/card.json +1 -1
- package/registry/catalogue-page.json +1 -1
- package/registry/changelog-page.json +1 -1
- package/registry/chat.json +1 -1
- package/registry/checkbox.json +1 -1
- package/registry/chip-link.json +1 -1
- package/registry/chip.json +1 -1
- package/registry/choice-grid.json +1 -1
- package/registry/code-block.json +1 -1
- package/registry/combobox.json +1 -1
- package/registry/command.json +1 -1
- package/registry/comparison-table.json +207 -0
- package/registry/component-page.json +1 -1
- package/registry/confirm-button.json +1 -1
- package/registry/contact-page.json +1 -1
- package/registry/continue-prompt.json +1 -1
- package/registry/countdown.json +1 -1
- package/registry/cta-panel.json +1 -1
- package/registry/dashboard-layout.json +1 -1
- package/registry/data-table.json +1 -1
- package/registry/date-picker.json +1 -1
- package/registry/decision-list.json +1 -1
- package/registry/description-list.json +1 -1
- package/registry/detail-layout.json +1 -1
- package/registry/dialog.json +1 -1
- package/registry/docs-article-page.json +1 -1
- package/registry/docs-hub-page.json +1 -1
- package/registry/docs-layout.json +1 -1
- package/registry/document-viewer.json +1 -1
- package/registry/dropdown-menu.json +1 -1
- package/registry/empty-state.json +1 -1
- package/registry/error-page.json +1 -1
- package/registry/examples/comparison-table/versus.d.ts +4 -0
- package/registry/examples/comparison-table/versus.js +28 -0
- package/registry/examples/comparison-table/versus.tsx +20 -0
- package/registry/examples/dialog/native/sheet.dark.png +0 -0
- package/registry/examples/dialog/native/sheet.light.png +0 -0
- package/registry/examples/genui/streaming.d.ts +4 -0
- package/registry/examples/genui/streaming.js +18 -0
- package/registry/examples/genui/streaming.tsx +14 -0
- package/registry/examples/genui/table.d.ts +4 -0
- package/registry/examples/genui/table.js +19 -0
- package/registry/examples/genui/table.tsx +14 -0
- package/registry/examples/meta-row/native/video.d.ts +4 -0
- package/registry/examples/meta-row/native/video.dark.png +0 -0
- package/registry/examples/meta-row/native/video.js +11 -0
- package/registry/examples/meta-row/native/video.light.png +0 -0
- package/registry/examples/meta-row/native/video.tsx +5 -0
- package/registry/examples/meta-row/status.d.ts +4 -0
- package/registry/examples/meta-row/status.js +12 -0
- package/registry/examples/meta-row/status.tsx +7 -0
- package/registry/examples/meta-row/video.d.ts +4 -0
- package/registry/examples/meta-row/video.js +12 -0
- package/registry/examples/meta-row/video.tsx +7 -0
- package/registry/examples/step-showcase/desktop.d.ts +4 -0
- package/registry/examples/step-showcase/desktop.js +24 -0
- package/registry/examples/step-showcase/desktop.tsx +19 -0
- package/registry/examples/step-showcase/phone.d.ts +4 -0
- package/registry/examples/step-showcase/phone.js +24 -0
- package/registry/examples/step-showcase/phone.tsx +19 -0
- package/registry/field.json +1 -1
- package/registry/file-upload.json +1 -1
- package/registry/filter-bar.json +1 -1
- package/registry/force-update-screen.json +1 -1
- package/registry/form.json +1 -1
- package/registry/gallery-page.json +1 -1
- package/registry/genui.json +409 -0
- package/registry/glow-card.json +1 -1
- package/registry/goal-gauge.json +1 -1
- package/registry/how-it-works-page.json +1 -1
- package/registry/image-cropper.json +1 -1
- package/registry/index.json +130 -4
- package/registry/iso.json +1 -1
- package/registry/kanban.json +1 -1
- package/registry/kbd.json +1 -1
- package/registry/landing-page.json +1 -1
- package/registry/landscape.json +1 -1
- package/registry/legal-page.json +1 -1
- package/registry/link-card.json +1 -1
- package/registry/list.json +1 -1
- package/registry/loader.json +1 -1
- package/registry/longform-page.json +1 -1
- package/registry/maintenance-screen.json +1 -1
- package/registry/map.json +2 -2
- package/registry/markdown.json +1 -1
- package/registry/marketing-layout.json +1 -1
- package/registry/marquee.json +1 -1
- package/registry/mascot-quote.json +1 -1
- package/registry/mascot-state.json +1 -1
- package/registry/mascots.json +1 -1
- package/registry/match-dialog.json +1 -1
- package/registry/media-capture.json +1 -1
- package/registry/media-grid.json +1 -1
- package/registry/meta-row.json +215 -0
- package/registry/meter.json +1 -1
- package/registry/nav-bar.json +13 -13
- package/registry/number-ticker.json +1 -1
- package/registry/page-header.json +1 -1
- package/registry/page-hero.json +1 -1
- package/registry/page.json +1 -1
- package/registry/pagination.json +1 -1
- package/registry/photo-grid.json +1 -1
- package/registry/pointer-light.json +1 -1
- package/registry/popover.json +1 -1
- package/registry/pricing-page.json +1 -1
- package/registry/product-page.json +1 -1
- package/registry/profile-card.json +1 -1
- package/registry/progress.json +1 -1
- package/registry/promise-card.json +1 -1
- package/registry/radio-group.json +1 -1
- package/registry/recipes.json +1 -1
- package/registry/scroll-stage.json +1 -1
- package/registry/search-field.json +1 -1
- package/registry/section-backdrop.json +1 -1
- package/registry/separator.json +1 -1
- package/registry/settings-layout.json +1 -1
- package/registry/showcase.json +1 -1
- package/registry/site-footer.json +13 -13
- package/registry/sites.json +1 -1
- package/registry/skeleton.json +1 -1
- package/registry/skip-link.json +2 -2
- package/registry/slider.json +1 -1
- package/registry/slot.json +1 -1
- package/registry/spinner.json +1 -1
- package/registry/split-view.json +1 -1
- package/registry/stage-banner.json +1 -1
- package/registry/stat.json +1 -1
- package/registry/status-page.json +1 -1
- package/registry/step-progress.json +1 -1
- package/registry/step-showcase.json +296 -0
- package/registry/stepper.json +1 -1
- package/registry/swipe-deck.json +1 -1
- package/registry/switch.json +1 -1
- package/registry/tabs.json +1 -1
- package/registry/tag-input.json +1 -1
- package/registry/tag-selector.json +1 -1
- package/registry/terminal-replay.json +1 -1
- package/registry/theme.json +1 -1
- package/registry/toast.json +1 -1
- package/registry/toc.json +1 -1
- package/registry/tooltip.json +1 -1
- package/registry/tree-view.json +1 -1
- package/registry/update-prompt.json +1 -1
- package/registry/verified-badge.json +1 -1
- package/registry/vertical-video.json +1 -1
- package/registry/video-player.json +1 -1
- package/registry/video-trimmer.json +1 -1
- package/registry/virtual.json +1 -1
- package/dist/chunk-3GODX3D6.js.map +0 -1
- package/dist/chunk-LIPK4UCS.js.map +0 -1
- /package/dist/{chunk-5MH64NIL.js.map → chunk-2L67YTNV.js.map} +0 -0
|
@@ -0,0 +1,1080 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import {
|
|
3
|
+
Checkbox
|
|
4
|
+
} from "./chunk-7Z4KHPFC.js";
|
|
5
|
+
import {
|
|
6
|
+
Button
|
|
7
|
+
} from "./chunk-3BC4XQ6C.js";
|
|
8
|
+
import {
|
|
9
|
+
useLayoutFallbacks,
|
|
10
|
+
useVirtualizer
|
|
11
|
+
} from "./chunk-KVDB4GXV.js";
|
|
12
|
+
import {
|
|
13
|
+
DropdownMenu,
|
|
14
|
+
FilterBar,
|
|
15
|
+
FilterMenu
|
|
16
|
+
} from "./chunk-FKBHWS4N.js";
|
|
17
|
+
import {
|
|
18
|
+
cn
|
|
19
|
+
} from "./chunk-2FRWNSRO.js";
|
|
20
|
+
import {
|
|
21
|
+
SearchField
|
|
22
|
+
} from "./chunk-REPTKUJ6.js";
|
|
23
|
+
import {
|
|
24
|
+
useControllable
|
|
25
|
+
} from "./chunk-FZBWEDQI.js";
|
|
26
|
+
import {
|
|
27
|
+
ChevronGlyph,
|
|
28
|
+
SortGlyph
|
|
29
|
+
} from "./chunk-CPA5CF35.js";
|
|
30
|
+
|
|
31
|
+
// src/data-table/csv.ts
|
|
32
|
+
var FORMULA = /^[=+\-@\t\r]/;
|
|
33
|
+
function field(value) {
|
|
34
|
+
let text = value == null ? "" : value instanceof Date ? value.toISOString() : String(value);
|
|
35
|
+
if (typeof value === "string" && FORMULA.test(text)) text = `'${text}`;
|
|
36
|
+
return /[",\n\r;]/.test(text) || text !== text.trim() ? `"${text.replace(/"/g, '""')}"` : text;
|
|
37
|
+
}
|
|
38
|
+
function dataTableCsv(rows, columns, separator = ",") {
|
|
39
|
+
const lines = [columns.map((column) => field(column.header)).join(separator)];
|
|
40
|
+
for (const row of rows) {
|
|
41
|
+
lines.push(columns.map((column) => field(column.value ? column.value(row) : row[column.id])).join(separator));
|
|
42
|
+
}
|
|
43
|
+
return lines.join("\r\n");
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// src/data-table/data-table.tsx
|
|
47
|
+
import { useTable } from "@tanstack/react-table";
|
|
48
|
+
import * as React from "react";
|
|
49
|
+
import { tv as tv2 } from "tailwind-variants";
|
|
50
|
+
|
|
51
|
+
// src/pagination/pagination.tsx
|
|
52
|
+
import { tv } from "tailwind-variants";
|
|
53
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
54
|
+
var pagination = tv({
|
|
55
|
+
slots: {
|
|
56
|
+
root: "@container flex w-full flex-wrap items-center justify-between gap-3 text-sm",
|
|
57
|
+
list: "flex items-center gap-1",
|
|
58
|
+
pages: "hidden items-center gap-1 @md:flex",
|
|
59
|
+
compact: "px-2 text-xs font-semibold tabular-nums text-fg-secondary @md:hidden",
|
|
60
|
+
item: "inline-flex h-9 min-w-9 select-none items-center justify-center gap-1.5 rounded-lg px-2.5 text-sm font-semibold tabular-nums text-fg-secondary transition-colors hover:bg-surface-2 hover:text-fg focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-ring aria-[current=page]:bg-accent aria-[current=page]:text-on-accent aria-[current=page]:hover:bg-accent aria-disabled:pointer-events-none aria-disabled:opacity-40 disabled:pointer-events-none disabled:opacity-40",
|
|
61
|
+
edge: "border border-border-default bg-surface-1 px-3",
|
|
62
|
+
ellipsis: "inline-flex h-9 min-w-6 items-end justify-center pb-2 text-fg-muted",
|
|
63
|
+
status: "text-xs text-fg-secondary tabular-nums",
|
|
64
|
+
size: "flex items-center gap-2 text-xs text-fg-secondary",
|
|
65
|
+
select: "h-9 rounded-lg border border-border-default bg-surface-2 px-2 text-sm text-fg focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-ring"
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
var paginationLabels = {
|
|
69
|
+
nav: "Pagination",
|
|
70
|
+
previous: "Previous",
|
|
71
|
+
next: "Next",
|
|
72
|
+
page: (page) => `Page ${page}`,
|
|
73
|
+
compact: (page, count) => `Page ${page} of ${count}`,
|
|
74
|
+
pageSize: "Rows per page"
|
|
75
|
+
};
|
|
76
|
+
function pageRange(page, pageCount, siblings = 1, boundaries = 1) {
|
|
77
|
+
if (pageCount <= 2 * boundaries + 2 * siblings + 3) return Array.from({ length: Math.max(0, pageCount) }, (_, i) => i + 1);
|
|
78
|
+
const pages = /* @__PURE__ */ new Set();
|
|
79
|
+
for (let i = 1; i <= Math.min(boundaries, pageCount); i += 1) pages.add(i);
|
|
80
|
+
for (let i = Math.max(1, pageCount - boundaries + 1); i <= pageCount; i += 1) pages.add(i);
|
|
81
|
+
for (let i = Math.max(1, page - siblings); i <= Math.min(pageCount, page + siblings); i += 1) pages.add(i);
|
|
82
|
+
const sorted = [...pages].sort((a, b) => a - b);
|
|
83
|
+
const out = [];
|
|
84
|
+
sorted.forEach((n, i) => {
|
|
85
|
+
const prev = sorted[i - 1];
|
|
86
|
+
if (prev !== void 0 && n - prev === 2) out.push(prev + 1);
|
|
87
|
+
else if (prev !== void 0 && n - prev > 2) out.push("\u2026");
|
|
88
|
+
out.push(n);
|
|
89
|
+
});
|
|
90
|
+
return out;
|
|
91
|
+
}
|
|
92
|
+
function Item({ href, onClick, disabled, current, label, className, children }) {
|
|
93
|
+
const common = { "aria-label": label, "aria-current": current ? "page" : void 0, className };
|
|
94
|
+
if (href && !disabled) {
|
|
95
|
+
return /* @__PURE__ */ jsx("a", { href, onClick, ...common, children });
|
|
96
|
+
}
|
|
97
|
+
if (href) {
|
|
98
|
+
return /* @__PURE__ */ jsx("a", { role: "link", "aria-disabled": true, ...common, children });
|
|
99
|
+
}
|
|
100
|
+
return /* @__PURE__ */ jsx("button", { type: "button", onClick, disabled, ...common, children });
|
|
101
|
+
}
|
|
102
|
+
function Pagination({
|
|
103
|
+
page = 1,
|
|
104
|
+
pageCount,
|
|
105
|
+
onPageChange,
|
|
106
|
+
getHref,
|
|
107
|
+
hasPrevious,
|
|
108
|
+
hasNext,
|
|
109
|
+
onPrevious,
|
|
110
|
+
onNext,
|
|
111
|
+
siblings = 1,
|
|
112
|
+
boundaries = 1,
|
|
113
|
+
status,
|
|
114
|
+
pageSize,
|
|
115
|
+
pageSizeOptions,
|
|
116
|
+
onPageSizeChange,
|
|
117
|
+
disabled,
|
|
118
|
+
labels: given,
|
|
119
|
+
className,
|
|
120
|
+
...props
|
|
121
|
+
}) {
|
|
122
|
+
const s2 = pagination();
|
|
123
|
+
const labels = { ...paginationLabels, ...given };
|
|
124
|
+
const paged = pageCount !== void 0;
|
|
125
|
+
const count = Math.max(1, pageCount ?? 1);
|
|
126
|
+
const current = Math.min(Math.max(1, page), count);
|
|
127
|
+
const canPrevious = paged ? current > 1 : Boolean(hasPrevious);
|
|
128
|
+
const canNext = paged ? current < count : Boolean(hasNext);
|
|
129
|
+
const go = (target) => () => onPageChange?.(target);
|
|
130
|
+
const href = (target) => paged && getHref ? getHref(target) : void 0;
|
|
131
|
+
return /* @__PURE__ */ jsxs("nav", { "aria-label": labels.nav, className: s2.root({ className }), ...props, children: [
|
|
132
|
+
status !== void 0 || pageSizeOptions ? /* @__PURE__ */ jsxs("div", { className: "flex flex-wrap items-center gap-4", children: [
|
|
133
|
+
status !== void 0 && /* @__PURE__ */ jsx("p", { className: s2.status(), children: status }),
|
|
134
|
+
pageSizeOptions && pageSize !== void 0 && /* @__PURE__ */ jsxs("label", { className: s2.size(), children: [
|
|
135
|
+
labels.pageSize,
|
|
136
|
+
/* @__PURE__ */ jsx(
|
|
137
|
+
"select",
|
|
138
|
+
{
|
|
139
|
+
className: s2.select(),
|
|
140
|
+
value: pageSize,
|
|
141
|
+
disabled,
|
|
142
|
+
onChange: (event) => onPageSizeChange?.(Number(event.target.value)),
|
|
143
|
+
children: pageSizeOptions.map((size) => /* @__PURE__ */ jsx("option", { value: size, children: size }, size))
|
|
144
|
+
}
|
|
145
|
+
)
|
|
146
|
+
] })
|
|
147
|
+
] }) : null,
|
|
148
|
+
/* @__PURE__ */ jsxs("ul", { className: s2.list(), children: [
|
|
149
|
+
/* @__PURE__ */ jsx("li", { children: /* @__PURE__ */ jsxs(
|
|
150
|
+
Item,
|
|
151
|
+
{
|
|
152
|
+
href: href(current - 1),
|
|
153
|
+
onClick: paged ? go(current - 1) : onPrevious,
|
|
154
|
+
disabled: disabled || !canPrevious,
|
|
155
|
+
label: labels.previous,
|
|
156
|
+
className: s2.item({ className: s2.edge() }),
|
|
157
|
+
children: [
|
|
158
|
+
/* @__PURE__ */ jsx(ChevronGlyph, { direction: "left" }),
|
|
159
|
+
/* @__PURE__ */ jsx("span", { className: "hidden @lg:inline", children: labels.previous })
|
|
160
|
+
]
|
|
161
|
+
}
|
|
162
|
+
) }),
|
|
163
|
+
paged && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
164
|
+
/* @__PURE__ */ jsx("li", { className: s2.pages(), children: /* @__PURE__ */ jsx("ul", { className: "contents", children: pageRange(current, count, siblings, boundaries).map(
|
|
165
|
+
(n, i) => n === "\u2026" ? /* @__PURE__ */ jsx("li", { "aria-hidden": true, className: s2.ellipsis(), children: "\u2026" }, `gap-${i}`) : /* @__PURE__ */ jsx("li", { children: /* @__PURE__ */ jsx(Item, { href: href(n), onClick: go(n), disabled, current: n === current, label: labels.page(n), className: s2.item(), children: n }) }, n)
|
|
166
|
+
) }) }),
|
|
167
|
+
/* @__PURE__ */ jsx("li", { className: s2.compact(), children: labels.compact(current, count) })
|
|
168
|
+
] }),
|
|
169
|
+
/* @__PURE__ */ jsx("li", { children: /* @__PURE__ */ jsxs(
|
|
170
|
+
Item,
|
|
171
|
+
{
|
|
172
|
+
href: href(current + 1),
|
|
173
|
+
onClick: paged ? go(current + 1) : onNext,
|
|
174
|
+
disabled: disabled || !canNext,
|
|
175
|
+
label: labels.next,
|
|
176
|
+
className: s2.item({ className: s2.edge() }),
|
|
177
|
+
children: [
|
|
178
|
+
/* @__PURE__ */ jsx("span", { className: "hidden @lg:inline", children: labels.next }),
|
|
179
|
+
/* @__PURE__ */ jsx(ChevronGlyph, { direction: "right" })
|
|
180
|
+
]
|
|
181
|
+
}
|
|
182
|
+
) })
|
|
183
|
+
] })
|
|
184
|
+
] });
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
// src/data-table/engine.ts
|
|
188
|
+
import {
|
|
189
|
+
columnFacetingFeature,
|
|
190
|
+
columnFilteringFeature,
|
|
191
|
+
columnGroupingFeature,
|
|
192
|
+
columnPinningFeature,
|
|
193
|
+
columnResizingFeature,
|
|
194
|
+
columnSizingFeature,
|
|
195
|
+
columnVisibilityFeature,
|
|
196
|
+
createExpandedRowModel,
|
|
197
|
+
createFacetedMinMaxValues,
|
|
198
|
+
createFacetedRowModel,
|
|
199
|
+
createFacetedUniqueValues,
|
|
200
|
+
createFilteredRowModel,
|
|
201
|
+
createGroupedRowModel,
|
|
202
|
+
createPaginatedRowModel,
|
|
203
|
+
createSortedRowModel,
|
|
204
|
+
rowExpandingFeature,
|
|
205
|
+
rowPaginationFeature,
|
|
206
|
+
rowSelectionFeature,
|
|
207
|
+
rowSortingFeature,
|
|
208
|
+
tableFeatures
|
|
209
|
+
} from "@tanstack/react-table";
|
|
210
|
+
var features = tableFeatures({
|
|
211
|
+
columnFilteringFeature,
|
|
212
|
+
filteredRowModel: createFilteredRowModel(),
|
|
213
|
+
columnFacetingFeature,
|
|
214
|
+
facetedRowModel: createFacetedRowModel(),
|
|
215
|
+
facetedUniqueValues: createFacetedUniqueValues(),
|
|
216
|
+
facetedMinMaxValues: createFacetedMinMaxValues(),
|
|
217
|
+
columnGroupingFeature,
|
|
218
|
+
groupedRowModel: createGroupedRowModel(),
|
|
219
|
+
rowSortingFeature,
|
|
220
|
+
sortedRowModel: createSortedRowModel(),
|
|
221
|
+
rowExpandingFeature,
|
|
222
|
+
expandedRowModel: createExpandedRowModel(),
|
|
223
|
+
rowPaginationFeature,
|
|
224
|
+
paginatedRowModel: createPaginatedRowModel(),
|
|
225
|
+
rowSelectionFeature,
|
|
226
|
+
columnVisibilityFeature,
|
|
227
|
+
columnPinningFeature,
|
|
228
|
+
columnSizingFeature,
|
|
229
|
+
columnResizingFeature
|
|
230
|
+
});
|
|
231
|
+
var empty = (value) => value == null || value === "";
|
|
232
|
+
function compareValues(a, b) {
|
|
233
|
+
if (empty(a)) return empty(b) ? 0 : 1;
|
|
234
|
+
if (empty(b)) return -1;
|
|
235
|
+
if (a instanceof Date || b instanceof Date) return Number(a) - Number(b);
|
|
236
|
+
if (typeof a === "number" && typeof b === "number") return a - b;
|
|
237
|
+
return String(a).localeCompare(String(b), void 0, { numeric: true, sensitivity: "base" });
|
|
238
|
+
}
|
|
239
|
+
var sortByValue = (a, b, id) => compareValues(a.getValue(id), b.getValue(id));
|
|
240
|
+
var filterText = (row, id, query) => String(row.getValue(id) ?? "").normalize("NFD").toLocaleLowerCase().includes(query.normalize("NFD").toLocaleLowerCase().trim());
|
|
241
|
+
filterText.autoRemove = (value) => typeof value !== "string" || value.trim() === "";
|
|
242
|
+
var filterFacet = (row, id, chosen) => chosen.includes(String(row.getValue(id) ?? ""));
|
|
243
|
+
filterFacet.autoRemove = (value) => !Array.isArray(value) || value.length === 0;
|
|
244
|
+
var filterRange = (row, id, [min, max]) => {
|
|
245
|
+
const raw = row.getValue(id);
|
|
246
|
+
if (empty(raw)) return false;
|
|
247
|
+
const value = Number(raw);
|
|
248
|
+
return (min == null || value >= min) && (max == null || value <= max);
|
|
249
|
+
};
|
|
250
|
+
filterRange.autoRemove = (value) => !Array.isArray(value) || value[0] == null && value[1] == null;
|
|
251
|
+
var FILTERS = { text: filterText, facet: filterFacet, range: filterRange };
|
|
252
|
+
|
|
253
|
+
// src/data-table/data-table.tsx
|
|
254
|
+
import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
255
|
+
var dataTable = tv2({
|
|
256
|
+
slots: {
|
|
257
|
+
root: "@container w-full overflow-clip rounded-xl border border-border-default bg-surface-1",
|
|
258
|
+
toolbar: "border-b border-border-default p-3",
|
|
259
|
+
scroller: "w-full overflow-x-auto",
|
|
260
|
+
table: "w-full border-collapse text-left text-sm text-fg",
|
|
261
|
+
caption: "px-4 pt-4 pb-2 text-left text-sm font-semibold text-fg",
|
|
262
|
+
thead: "bg-surface-2/60",
|
|
263
|
+
headRow: "border-b border-border-default",
|
|
264
|
+
th: "relative whitespace-nowrap px-4 py-3 text-xs font-semibold text-fg-secondary",
|
|
265
|
+
sortButton: "-mx-1.5 inline-flex items-center gap-1 rounded-md px-1.5 py-1 hover:bg-surface-3 hover:text-fg focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-ring aria-[pressed=true]:text-fg",
|
|
266
|
+
resizer: "absolute top-0 right-0 h-full w-1.5 cursor-col-resize touch-none select-none bg-transparent hover:bg-border-strong focus-visible:bg-accent focus-visible:outline-hidden data-[resizing]:bg-accent",
|
|
267
|
+
tbody: "",
|
|
268
|
+
tr: "border-b border-border-subtle transition-colors last:border-b-0 hover:bg-surface-2/50 data-[state=selected]:bg-accent-soft",
|
|
269
|
+
groupRow: "bg-surface-2/40 font-semibold",
|
|
270
|
+
td: "px-4 py-3 align-middle",
|
|
271
|
+
select: "w-10",
|
|
272
|
+
expander: "w-10",
|
|
273
|
+
toggle: "inline-flex h-7 min-w-7 items-center justify-center gap-1.5 rounded-md text-fg-secondary hover:bg-surface-3 hover:text-fg focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-ring [&[aria-expanded=true]>svg]:rotate-90 [&>svg]:transition-transform motion-reduce:[&>svg]:transition-none",
|
|
274
|
+
detail: "bg-surface-0 px-4 py-4",
|
|
275
|
+
message: "px-4 py-10 text-center text-sm text-fg-secondary",
|
|
276
|
+
skeleton: "h-4 w-full max-w-40 animate-pulse rounded bg-surface-3 motion-reduce:animate-none",
|
|
277
|
+
footer: "border-t border-border-default px-4 py-3"
|
|
278
|
+
},
|
|
279
|
+
variants: {
|
|
280
|
+
layout: {
|
|
281
|
+
table: {
|
|
282
|
+
th: "data-[pin]:sticky data-[pin]:z-[2] data-[pin]:bg-surface-2 data-[pin=start]:left-(--dt-pin) data-[pin=end]:right-(--dt-pin)",
|
|
283
|
+
td: "data-[pin]:sticky data-[pin]:z-[1] data-[pin]:bg-surface-1 data-[pin=start]:left-(--dt-pin) data-[pin=end]:right-(--dt-pin)"
|
|
284
|
+
},
|
|
285
|
+
// Below 36rem of container: cards. The sortable headers stay, as a row of sort buttons above the cards.
|
|
286
|
+
auto: {
|
|
287
|
+
table: "@max-xl:block",
|
|
288
|
+
caption: "@max-xl:block",
|
|
289
|
+
thead: "@max-xl:sr-only @max-xl:bg-transparent @max-xl:has-[[data-keep]]:not-sr-only @max-xl:has-[[data-keep]]:block",
|
|
290
|
+
headRow: "@max-xl:flex @max-xl:flex-wrap @max-xl:items-center @max-xl:gap-2 @max-xl:px-3 @max-xl:py-2",
|
|
291
|
+
th: "@max-xl:sr-only @max-xl:data-[keep]:not-sr-only @max-xl:data-[keep]:block @max-xl:p-0 @xl:data-[pin]:sticky @xl:data-[pin]:z-[2] @xl:data-[pin]:bg-surface-2 @xl:data-[pin=start]:left-(--dt-pin) @xl:data-[pin=end]:right-(--dt-pin)",
|
|
292
|
+
tbody: "@max-xl:grid @max-xl:gap-3 @max-xl:p-3",
|
|
293
|
+
tr: "@max-xl:relative @max-xl:grid @max-xl:gap-1.5 @max-xl:rounded-xl @max-xl:border @max-xl:border-border-default @max-xl:bg-surface-0 @max-xl:p-4 @max-xl:last:border-b",
|
|
294
|
+
td: "@max-xl:flex @max-xl:items-baseline @max-xl:justify-between @max-xl:gap-4 @max-xl:p-0 @max-xl:text-right @max-xl:before:shrink-0 @max-xl:before:text-xs @max-xl:before:font-semibold @max-xl:before:text-fg-secondary @max-xl:before:content-[attr(data-label)] @max-xl:data-[card=title]:order-first @max-xl:data-[card=title]:pr-8 @max-xl:data-[card=title]:text-left @max-xl:data-[card=title]:text-base @max-xl:data-[card=title]:font-semibold @max-xl:data-[card=title]:before:content-none @max-xl:data-[card=hidden]:hidden @max-xl:data-[card=message]:block @max-xl:data-[card=message]:text-center @max-xl:data-[card=message]:before:content-none @xl:data-[pin]:sticky @xl:data-[pin]:z-[1] @xl:data-[pin]:bg-surface-1 @xl:data-[pin=start]:left-(--dt-pin) @xl:data-[pin=end]:right-(--dt-pin)",
|
|
295
|
+
select: "@max-xl:absolute @max-xl:right-3 @max-xl:top-3 @max-xl:w-auto @max-xl:before:content-none",
|
|
296
|
+
expander: "@max-xl:before:content-none"
|
|
297
|
+
},
|
|
298
|
+
cards: {
|
|
299
|
+
table: "block",
|
|
300
|
+
caption: "block",
|
|
301
|
+
thead: "sr-only bg-transparent has-[[data-keep]]:not-sr-only has-[[data-keep]]:block",
|
|
302
|
+
headRow: "flex flex-wrap items-center gap-2 px-3 py-2",
|
|
303
|
+
th: "sr-only p-0 data-[keep]:not-sr-only data-[keep]:block",
|
|
304
|
+
tbody: "grid gap-3 p-3",
|
|
305
|
+
tr: "relative grid gap-1.5 rounded-xl border border-border-default bg-surface-0 p-4 last:border-b",
|
|
306
|
+
td: "flex items-baseline justify-between gap-4 p-0 text-right before:shrink-0 before:text-xs before:font-semibold before:text-fg-secondary before:content-[attr(data-label)] data-[card=title]:order-first data-[card=title]:pr-8 data-[card=title]:text-left data-[card=title]:text-base data-[card=title]:font-semibold data-[card=title]:before:content-none data-[card=hidden]:hidden data-[card=message]:block data-[card=message]:text-center data-[card=message]:before:content-none",
|
|
307
|
+
select: "absolute right-3 top-3 w-auto before:content-none",
|
|
308
|
+
expander: "before:content-none"
|
|
309
|
+
}
|
|
310
|
+
},
|
|
311
|
+
density: {
|
|
312
|
+
comfortable: {},
|
|
313
|
+
compact: { th: "py-2", td: "py-1.5" }
|
|
314
|
+
},
|
|
315
|
+
// The header stays in view while the page scrolls (table layouts only; `--dt-top` clears a fixed bar).
|
|
316
|
+
sticky: { true: {}, false: {} },
|
|
317
|
+
// Zebra rows (the table layouts); the cards keep their frame.
|
|
318
|
+
striped: { true: {}, false: {} },
|
|
319
|
+
// Typed columns: one height per row (`typed`); untyped tables keep the height of their content.
|
|
320
|
+
typed: { true: {}, false: {} }
|
|
321
|
+
},
|
|
322
|
+
compoundVariants: [
|
|
323
|
+
{ layout: "table", sticky: true, class: { th: "sticky top-(--dt-top,0px) z-[3] bg-surface-2" } },
|
|
324
|
+
{ layout: "auto", sticky: true, class: { th: "@xl:sticky @xl:top-(--dt-top,0px) @xl:z-[3] @xl:bg-surface-2" } },
|
|
325
|
+
{ layout: "table", striped: true, class: { tr: "even:bg-surface-2/40" } },
|
|
326
|
+
{ layout: "auto", striped: true, class: { tr: "@xl:even:bg-surface-2/40" } },
|
|
327
|
+
// One row height per density (a two-line row — a name and its id — is the tallest).
|
|
328
|
+
{ layout: "table", density: "comfortable", typed: true, class: { td: "h-15" } },
|
|
329
|
+
{ layout: "auto", density: "comfortable", typed: true, class: { td: "@xl:h-15" } },
|
|
330
|
+
{ layout: "table", density: "compact", typed: true, class: { td: "h-12" } },
|
|
331
|
+
{ layout: "auto", density: "compact", typed: true, class: { td: "@xl:h-12" } }
|
|
332
|
+
],
|
|
333
|
+
defaultVariants: { layout: "auto", density: "comfortable", sticky: false, striped: false, typed: false }
|
|
334
|
+
});
|
|
335
|
+
var NO_CLASS = { 2: "", 3: "", 4: "", 5: "", 6: "", 7: "" };
|
|
336
|
+
var LEAVES = {
|
|
337
|
+
auto: { 2: "@xl:@max-2xl:hidden!", 3: "@max-3xl:hidden!", 4: "@max-4xl:hidden!", 5: "@max-5xl:hidden!", 6: "@max-6xl:hidden!", 7: "@max-7xl:hidden!" },
|
|
338
|
+
table: { 2: "@max-2xl:hidden!", 3: "@max-3xl:hidden!", 4: "@max-4xl:hidden!", 5: "@max-5xl:hidden!", 6: "@max-6xl:hidden!", 7: "@max-7xl:hidden!" },
|
|
339
|
+
cards: { 2: "", 3: "hidden!", 4: "hidden!", 5: "hidden!", 6: "hidden!", 7: "hidden!" }
|
|
340
|
+
};
|
|
341
|
+
var LEAVES_HEAD = {
|
|
342
|
+
auto: { 2: "@xl:@max-2xl:hidden!", 3: "@xl:@max-3xl:hidden!", 4: "@xl:@max-4xl:hidden!", 5: "@xl:@max-5xl:hidden!", 6: "@xl:@max-6xl:hidden!", 7: "@xl:@max-7xl:hidden!" },
|
|
343
|
+
table: LEAVES.table,
|
|
344
|
+
cards: NO_CLASS
|
|
345
|
+
};
|
|
346
|
+
var IN_DETAIL = {
|
|
347
|
+
auto: { 2: "hidden @xl:@max-2xl:grid", 3: "hidden @max-3xl:grid", 4: "hidden @max-4xl:grid", 5: "hidden @max-5xl:grid", 6: "hidden @max-6xl:grid", 7: "hidden @max-7xl:grid" },
|
|
348
|
+
table: { 2: "hidden @max-2xl:grid", 3: "hidden @max-3xl:grid", 4: "hidden @max-4xl:grid", 5: "hidden @max-5xl:grid", 6: "hidden @max-6xl:grid", 7: "hidden @max-7xl:grid" },
|
|
349
|
+
cards: { 2: "hidden", 3: "grid", 4: "grid", 5: "grid", 6: "grid", 7: "grid" }
|
|
350
|
+
};
|
|
351
|
+
var TOGGLE = {
|
|
352
|
+
auto: { 2: "hidden @xl:@max-2xl:inline-flex", 3: "hidden @max-3xl:inline-flex", 4: "hidden @max-4xl:inline-flex", 5: "hidden @max-5xl:inline-flex", 6: "hidden @max-6xl:inline-flex", 7: "hidden @max-7xl:inline-flex" },
|
|
353
|
+
table: { 2: "hidden @max-2xl:inline-flex", 3: "hidden @max-3xl:inline-flex", 4: "hidden @max-4xl:inline-flex", 5: "hidden @max-5xl:inline-flex", 6: "hidden @max-6xl:inline-flex", 7: "hidden @max-7xl:inline-flex" },
|
|
354
|
+
cards: { 2: "hidden", 3: "inline-flex", 4: "inline-flex", 5: "inline-flex", 6: "inline-flex", 7: "inline-flex" }
|
|
355
|
+
};
|
|
356
|
+
var PANEL = {
|
|
357
|
+
auto: { 2: "hidden @xl:@max-2xl:block", 3: "hidden @max-3xl:block", 4: "hidden @max-4xl:block", 5: "hidden @max-5xl:block", 6: "hidden @max-6xl:block", 7: "hidden @max-7xl:block" },
|
|
358
|
+
table: { 2: "hidden @max-2xl:block", 3: "hidden @max-3xl:block", 4: "hidden @max-4xl:block", 5: "hidden @max-5xl:block", 6: "hidden @max-6xl:block", 7: "hidden @max-7xl:block" },
|
|
359
|
+
cards: { 2: "hidden", 3: "block", 4: "block", 5: "block", 6: "block", 7: "block" }
|
|
360
|
+
};
|
|
361
|
+
var TYPE_CELL = {
|
|
362
|
+
title: { auto: "@xl:w-full @xl:max-w-0 @xl:min-w-44", table: "w-full max-w-0 min-w-44", cards: "" },
|
|
363
|
+
badge: { auto: "@xl:w-px", table: "w-px", cards: "" },
|
|
364
|
+
status: { auto: "@xl:w-px @xl:whitespace-nowrap", table: "w-px whitespace-nowrap", cards: "" },
|
|
365
|
+
number: { auto: "@xl:w-px @xl:whitespace-nowrap tabular-nums", table: "w-px whitespace-nowrap tabular-nums", cards: "tabular-nums" },
|
|
366
|
+
date: { auto: "@xl:w-px @xl:whitespace-nowrap tabular-nums", table: "w-px whitespace-nowrap tabular-nums", cards: "tabular-nums" },
|
|
367
|
+
link: { auto: "@xl:min-w-28 @xl:max-w-56", table: "min-w-28 max-w-56", cards: "" },
|
|
368
|
+
text: { auto: "@xl:min-w-36", table: "min-w-36", cards: "" }
|
|
369
|
+
};
|
|
370
|
+
var CLAMP = { 1: "line-clamp-1", 2: "line-clamp-2", 3: "line-clamp-3" };
|
|
371
|
+
var dataTableLabels = {
|
|
372
|
+
selectAll: "Select all rows",
|
|
373
|
+
selectRow: (name) => `Select ${name}`,
|
|
374
|
+
loading: "Loading",
|
|
375
|
+
empty: "Nothing to show",
|
|
376
|
+
details: "Details",
|
|
377
|
+
expandRow: (name) => `Show details of ${name}`,
|
|
378
|
+
group: (value, count) => `${value}, ${count} ${count === 1 ? "row" : "rows"}`,
|
|
379
|
+
resize: (header) => `Resize ${header}`,
|
|
380
|
+
results: (count) => `${count.toLocaleString("en")} ${count === 1 ? "row" : "rows"}`,
|
|
381
|
+
filters: "Filter the table",
|
|
382
|
+
clearFilters: "Clear filters",
|
|
383
|
+
removeFilter: (label) => `Remove ${label}`,
|
|
384
|
+
activeFilter: (header, value) => `${header}: ${value}`,
|
|
385
|
+
search: (header) => `Search ${header.toLocaleLowerCase()}`,
|
|
386
|
+
rangeFrom: (header) => `${header} from`,
|
|
387
|
+
rangeTo: (header) => `${header} to`,
|
|
388
|
+
columns: "Columns",
|
|
389
|
+
showMore: (name) => `Show more about ${name}`,
|
|
390
|
+
export: "Export CSV"
|
|
391
|
+
};
|
|
392
|
+
var DataTableContext = React.createContext(null);
|
|
393
|
+
function useDataTable() {
|
|
394
|
+
const context = React.useContext(DataTableContext);
|
|
395
|
+
if (!context) throw new Error("useDataTable: call it inside a DataTable (its `toolbar`, `footer` or a cell)");
|
|
396
|
+
return context;
|
|
397
|
+
}
|
|
398
|
+
var TRUNCATE = { auto: "@xl:truncate", table: "truncate", cards: "" };
|
|
399
|
+
var MIN = { auto: "@xl:min-w-(--dt-min)!", table: "min-w-(--dt-min)!", cards: "" };
|
|
400
|
+
var MAX = { auto: "@xl:max-w-(--dt-max)!", table: "max-w-(--dt-max)!", cards: "" };
|
|
401
|
+
var SHADOWS = "[background:linear-gradient(to_right,var(--kz-surface-1),transparent)_left/24px_100%_no-repeat_local,linear-gradient(to_left,var(--kz-surface-1),transparent)_right/24px_100%_no-repeat_local,linear-gradient(to_right,rgb(0_0_0/0.18),transparent)_left/10px_100%_no-repeat_scroll,linear-gradient(to_left,rgb(0_0_0/0.18),transparent)_right/10px_100%_no-repeat_scroll]";
|
|
402
|
+
var ALIGN = { start: "text-left", center: "text-center", end: "text-right" };
|
|
403
|
+
var NONE = [];
|
|
404
|
+
var NO_RECORD = {};
|
|
405
|
+
var apply = (updater, old) => typeof updater === "function" ? updater(old) : updater;
|
|
406
|
+
var valueOf = (column, row) => column.value ? column.value(row) : row[column.id];
|
|
407
|
+
var display = (value) => value instanceof Date ? value.toISOString() : String(value ?? "");
|
|
408
|
+
function DataTable({
|
|
409
|
+
rows,
|
|
410
|
+
columns,
|
|
411
|
+
getRowId,
|
|
412
|
+
caption,
|
|
413
|
+
showCaption,
|
|
414
|
+
sort: sortProp,
|
|
415
|
+
defaultSort = null,
|
|
416
|
+
onSortChange,
|
|
417
|
+
filters: filtersProp,
|
|
418
|
+
defaultFilters = NO_RECORD,
|
|
419
|
+
onFiltersChange,
|
|
420
|
+
selectable,
|
|
421
|
+
selected: selectedProp,
|
|
422
|
+
defaultSelected = NONE,
|
|
423
|
+
onSelectedChange,
|
|
424
|
+
rowLabel,
|
|
425
|
+
groupBy: groupByProp,
|
|
426
|
+
defaultGroupBy = NONE,
|
|
427
|
+
onGroupByChange,
|
|
428
|
+
columnVisibility: visibilityProp,
|
|
429
|
+
defaultColumnVisibility = NO_RECORD,
|
|
430
|
+
onColumnVisibilityChange,
|
|
431
|
+
pinning,
|
|
432
|
+
resizing,
|
|
433
|
+
getSubRows,
|
|
434
|
+
renderDetail,
|
|
435
|
+
expanded: expandedProp,
|
|
436
|
+
defaultExpanded = NO_RECORD,
|
|
437
|
+
onExpandedChange,
|
|
438
|
+
pageSize: pageSizeProp,
|
|
439
|
+
defaultPageSize,
|
|
440
|
+
onPageSizeChange,
|
|
441
|
+
pageSizeOptions,
|
|
442
|
+
page: pageProp,
|
|
443
|
+
defaultPage = 1,
|
|
444
|
+
onPageChange,
|
|
445
|
+
manual,
|
|
446
|
+
rowCount,
|
|
447
|
+
onStateChange,
|
|
448
|
+
loading,
|
|
449
|
+
loadingRows = 5,
|
|
450
|
+
error,
|
|
451
|
+
empty: empty2,
|
|
452
|
+
layout = "auto",
|
|
453
|
+
density,
|
|
454
|
+
stickyHeader,
|
|
455
|
+
striped,
|
|
456
|
+
scroll,
|
|
457
|
+
stickyFirstColumn,
|
|
458
|
+
virtualized,
|
|
459
|
+
toolbar,
|
|
460
|
+
footer,
|
|
461
|
+
labels: given,
|
|
462
|
+
className
|
|
463
|
+
}) {
|
|
464
|
+
const labels = { ...dataTableLabels, ...given };
|
|
465
|
+
const effectiveLayout = virtualized ? "table" : layout;
|
|
466
|
+
const L = effectiveLayout;
|
|
467
|
+
const typed = columns.some((c) => c.type || c.priority);
|
|
468
|
+
const s2 = dataTable({ layout: L, density, sticky: Boolean(stickyHeader), striped: Boolean(striped), typed });
|
|
469
|
+
const [sort, setSort] = useControllable(sortProp, defaultSort, onSortChange);
|
|
470
|
+
const [filters, setFiltersState] = useControllable(filtersProp, defaultFilters, onFiltersChange);
|
|
471
|
+
const [selected, setSelected] = useControllable(selectedProp, defaultSelected, onSelectedChange);
|
|
472
|
+
const [groupBy, setGroupBy] = useControllable(groupByProp, defaultGroupBy, onGroupByChange);
|
|
473
|
+
const [visibility, setVisibility] = useControllable(visibilityProp, defaultColumnVisibility, onColumnVisibilityChange);
|
|
474
|
+
const [expanded, setExpanded] = useControllable(expandedProp, defaultExpanded, onExpandedChange);
|
|
475
|
+
const paginated = pageSizeProp !== void 0 || defaultPageSize !== void 0;
|
|
476
|
+
const [pageSize, setPageSize] = useControllable(pageSizeProp, defaultPageSize ?? Number.POSITIVE_INFINITY, onPageSizeChange);
|
|
477
|
+
const [page, setPage] = useControllable(pageProp, defaultPage, onPageChange);
|
|
478
|
+
const [sizing, setSizing] = React.useState({});
|
|
479
|
+
const [resizeState, setResizeState] = React.useState(void 0);
|
|
480
|
+
const announce = (next) => onStateChange?.({ sort, filters, page: paginated ? page : 1, pageSize: paginated ? pageSize : Number.POSITIVE_INFINITY, ...next });
|
|
481
|
+
const changeSort = (next) => {
|
|
482
|
+
setSort(next);
|
|
483
|
+
if (paginated && page !== 1) setPage(1);
|
|
484
|
+
announce({ sort: next, page: 1 });
|
|
485
|
+
};
|
|
486
|
+
const changeFilters = (next) => {
|
|
487
|
+
setFiltersState(next);
|
|
488
|
+
if (paginated && page !== 1) setPage(1);
|
|
489
|
+
announce({ filters: next, page: 1 });
|
|
490
|
+
};
|
|
491
|
+
const changePage = (next) => {
|
|
492
|
+
setPage(next);
|
|
493
|
+
announce({ page: next });
|
|
494
|
+
};
|
|
495
|
+
const changePageSize = (next) => {
|
|
496
|
+
setPageSize(next);
|
|
497
|
+
setPage(1);
|
|
498
|
+
announce({ pageSize: next, page: 1 });
|
|
499
|
+
};
|
|
500
|
+
const hasExpander = Boolean(renderDetail || getSubRows);
|
|
501
|
+
const priorityOf = (column) => column.priority && column.priority > 1 ? column.priority : 1;
|
|
502
|
+
const maxPriority = columns.reduce((max, column) => priorityOf(column) > max ? priorityOf(column) : max, 1);
|
|
503
|
+
const inlineToggle = maxPriority > 1 && !hasExpander;
|
|
504
|
+
const detailed = Boolean(renderDetail) || inlineToggle;
|
|
505
|
+
const defs = React.useMemo(
|
|
506
|
+
() => columns.map((column) => ({
|
|
507
|
+
id: column.id,
|
|
508
|
+
accessorFn: (row) => valueOf(column, row),
|
|
509
|
+
header: column.header,
|
|
510
|
+
enableSorting: Boolean(column.sortable),
|
|
511
|
+
sortFn: sortByValue,
|
|
512
|
+
sortUndefined: "last",
|
|
513
|
+
enableColumnFilter: Boolean(column.filter),
|
|
514
|
+
filterFn: column.filter ? FILTERS[column.filter] : FILTERS.text,
|
|
515
|
+
enableGrouping: Boolean(column.groupable),
|
|
516
|
+
enableHiding: column.hideable !== false,
|
|
517
|
+
enableResizing: Boolean(resizing),
|
|
518
|
+
...column.width ? { size: column.width } : {},
|
|
519
|
+
minSize: column.minWidth ?? 64
|
|
520
|
+
})),
|
|
521
|
+
[columns, resizing]
|
|
522
|
+
);
|
|
523
|
+
const firstId = columns[0]?.id;
|
|
524
|
+
const pinned = stickyFirstColumn && firstId && !pinning?.start?.length ? { ...pinning, start: [firstId] } : pinning;
|
|
525
|
+
const pageIndex = Math.max(0, page - 1);
|
|
526
|
+
const table = useTable({
|
|
527
|
+
features,
|
|
528
|
+
columns: defs,
|
|
529
|
+
data: rows,
|
|
530
|
+
getRowId: (row) => getRowId(row),
|
|
531
|
+
getSubRows: getSubRows ? (row) => getSubRows(row) : void 0,
|
|
532
|
+
getRowCanExpand: detailed ? () => true : void 0,
|
|
533
|
+
state: {
|
|
534
|
+
sorting: sort ? [{ id: sort.column, desc: sort.direction === "descending" }] : [],
|
|
535
|
+
columnFilters: Object.entries(filters).map(([id, value]) => ({ id, value })),
|
|
536
|
+
rowSelection: Object.fromEntries(selected.map((id) => [id, true])),
|
|
537
|
+
grouping: [...groupBy],
|
|
538
|
+
columnVisibility: { ...visibility },
|
|
539
|
+
expanded: { ...expanded },
|
|
540
|
+
pagination: { pageIndex, pageSize: paginated ? pageSize : Math.max(1, rows.length) },
|
|
541
|
+
columnPinning: { start: [...pinned?.start ?? []], end: [...pinned?.end ?? []] },
|
|
542
|
+
columnSizing: sizing,
|
|
543
|
+
...resizeState ? { columnResizing: resizeState } : {}
|
|
544
|
+
},
|
|
545
|
+
onSortingChange: (updater) => {
|
|
546
|
+
const [first] = apply(updater, sort ? [{ id: sort.column, desc: sort.direction === "descending" }] : []);
|
|
547
|
+
changeSort(first ? { column: first.id, direction: first.desc ? "descending" : "ascending" } : null);
|
|
548
|
+
},
|
|
549
|
+
onColumnFiltersChange: (updater) => {
|
|
550
|
+
const next = apply(updater, Object.entries(filters).map(([id, value]) => ({ id, value })));
|
|
551
|
+
changeFilters(Object.fromEntries(next.map((f) => [f.id, f.value])));
|
|
552
|
+
},
|
|
553
|
+
onRowSelectionChange: (updater) => {
|
|
554
|
+
const next = apply(updater, Object.fromEntries(selected.map((id) => [id, true])));
|
|
555
|
+
setSelected(Object.keys(next).filter((id) => next[id]));
|
|
556
|
+
},
|
|
557
|
+
onGroupingChange: (updater) => setGroupBy(apply(updater, [...groupBy])),
|
|
558
|
+
onColumnVisibilityChange: (updater) => setVisibility(apply(updater, { ...visibility })),
|
|
559
|
+
onExpandedChange: (updater) => {
|
|
560
|
+
const next = apply(updater, { ...expanded });
|
|
561
|
+
setExpanded(next === true ? Object.fromEntries(table.getRowModel().rows.map((r) => [r.id, true])) : next);
|
|
562
|
+
},
|
|
563
|
+
onColumnSizingChange: (updater) => setSizing((old) => apply(updater, old)),
|
|
564
|
+
onColumnResizingChange: (updater) => setResizeState((old) => apply(updater, old)),
|
|
565
|
+
enableSortingRemoval: true,
|
|
566
|
+
sortDescFirst: false,
|
|
567
|
+
manualSorting: manual?.sorting,
|
|
568
|
+
manualFiltering: manual?.filtering,
|
|
569
|
+
manualPagination: manual?.pagination || !paginated,
|
|
570
|
+
rowCount: manual?.pagination ? rowCount : void 0,
|
|
571
|
+
autoResetPageIndex: false,
|
|
572
|
+
autoResetExpanded: false,
|
|
573
|
+
groupedColumnMode: false,
|
|
574
|
+
columnResizeMode: "onChange",
|
|
575
|
+
enableRowSelection: (row) => !row.getIsGrouped()
|
|
576
|
+
});
|
|
577
|
+
const visibleColumns = table.getVisibleLeafColumns();
|
|
578
|
+
const byId = new Map(columns.map((c) => [c.id, c]));
|
|
579
|
+
const pageRows = table.getRowModel().rows;
|
|
580
|
+
const leafCount = (manual?.pagination || manual?.filtering) && rowCount !== void 0 ? rowCount : table.getFilteredRowModel().rows.length;
|
|
581
|
+
const pageCount = paginated ? Math.max(1, manual?.pagination ? Math.ceil((rowCount ?? rows.length) / pageSize) : table.getPageCount()) : 1;
|
|
582
|
+
React.useEffect(() => {
|
|
583
|
+
if (paginated && !loading && page > pageCount) changePage(pageCount);
|
|
584
|
+
}, [pageCount]);
|
|
585
|
+
const selectableIds = pageRows.filter((r) => !r.getIsGrouped()).map((r) => r.id);
|
|
586
|
+
const chosen = new Set(selected);
|
|
587
|
+
const allChosen = selectableIds.length > 0 && selectableIds.every((id) => chosen.has(id));
|
|
588
|
+
const someChosen = selectableIds.some((id) => chosen.has(id));
|
|
589
|
+
const toggleAll = () => setSelected(allChosen ? selected.filter((id) => !selectableIds.includes(id)) : [.../* @__PURE__ */ new Set([...selected, ...selectableIds])]);
|
|
590
|
+
const span = visibleColumns.length + (selectable ? 1 : 0) + (hasExpander ? 1 : 0);
|
|
591
|
+
const fixedLayout = Boolean(resizing || pinned?.start?.length || pinned?.end?.length);
|
|
592
|
+
const sideways = scroll ?? (!typed && !stickyHeader);
|
|
593
|
+
const nameOf = (row) => rowLabel ? rowLabel(row.original) : row.id;
|
|
594
|
+
const scroller = React.useRef(null);
|
|
595
|
+
const fallbacks = useLayoutFallbacks(virtualized?.height ?? 0, virtualized?.estimateRowHeight ?? 44);
|
|
596
|
+
const virtualizer = useVirtualizer({
|
|
597
|
+
...fallbacks,
|
|
598
|
+
count: pageRows.length,
|
|
599
|
+
getScrollElement: () => scroller.current,
|
|
600
|
+
estimateSize: () => virtualized?.estimateRowHeight ?? 44,
|
|
601
|
+
overscan: virtualized?.overscan ?? 6,
|
|
602
|
+
initialRect: { width: 0, height: virtualized?.height ?? 0 },
|
|
603
|
+
getItemKey: (index) => pageRows[index]?.id ?? index,
|
|
604
|
+
enabled: Boolean(virtualized) && !loading
|
|
605
|
+
});
|
|
606
|
+
const windowItems = virtualized && !loading ? virtualizer.getVirtualItems() : null;
|
|
607
|
+
const before = windowItems?.[0]?.start ?? 0;
|
|
608
|
+
const after = windowItems && windowItems.length > 0 ? virtualizer.getTotalSize() - (windowItems.at(-1)?.end ?? 0) : 0;
|
|
609
|
+
const pin = (column) => {
|
|
610
|
+
const position = column.getIsPinned();
|
|
611
|
+
if (!position) return {};
|
|
612
|
+
const offset = position === "start" ? column.getStart("start") : column.getAfter("end");
|
|
613
|
+
return { "data-pin": position, style: { ["--dt-pin"]: `${offset}px` } };
|
|
614
|
+
};
|
|
615
|
+
const width = (column) => fixedLayout || byId.get(column.id)?.width ? { width: column.getSize() } : void 0;
|
|
616
|
+
const message = (content, alert) => /* @__PURE__ */ jsx2("tr", { role: "row", className: s2.tr({ className: "hover:bg-transparent" }), children: /* @__PURE__ */ jsx2("td", { role: "cell", colSpan: span, "data-card": "message", className: s2.td({ className: s2.message() }), children: alert ? /* @__PURE__ */ jsx2("div", { role: "alert", children: content }) : content }) });
|
|
617
|
+
const cardOf = (column) => column?.card === "title" || column && !column.card && column.type === "title" ? "title" : column?.card === "hidden" ? "hidden" : void 0;
|
|
618
|
+
const contentOf = (column, original) => {
|
|
619
|
+
if (column.cell) return column.cell(original);
|
|
620
|
+
const value = valueOf(column, original);
|
|
621
|
+
const text = column.type === "date" && value instanceof Date ? value.toISOString().slice(0, 10) : display(value);
|
|
622
|
+
const cut = TRUNCATE[L];
|
|
623
|
+
switch (column.type) {
|
|
624
|
+
case "title": {
|
|
625
|
+
const sub = column.subtitle?.(original);
|
|
626
|
+
return /* @__PURE__ */ jsxs2("span", { className: "block min-w-0", children: [
|
|
627
|
+
/* @__PURE__ */ jsx2("span", { className: cn("block font-semibold text-fg", cut), title: text, children: text }),
|
|
628
|
+
sub ? /* @__PURE__ */ jsx2("span", { className: cn("block font-mono text-xs text-fg-tertiary", cut), children: sub }) : null
|
|
629
|
+
] });
|
|
630
|
+
}
|
|
631
|
+
case "number":
|
|
632
|
+
return /* @__PURE__ */ jsxs2("span", { children: [
|
|
633
|
+
typeof value === "number" ? value.toLocaleString("en") : text,
|
|
634
|
+
column.unit ? /* @__PURE__ */ jsx2("span", { className: "ms-1 text-fg-secondary", children: column.unit }) : null
|
|
635
|
+
] });
|
|
636
|
+
case "link": {
|
|
637
|
+
const href = column.href?.(original);
|
|
638
|
+
return href ? /* @__PURE__ */ jsx2("a", { href, title: text, className: cn("block text-fg-accent underline-offset-2 hover:underline", cut), children: text }) : /* @__PURE__ */ jsx2("span", { className: cn("block", cut), title: text, children: text });
|
|
639
|
+
}
|
|
640
|
+
default: {
|
|
641
|
+
const lines = column.clamp ?? (column.type === "text" ? 2 : void 0);
|
|
642
|
+
if (!column.nowrap && !lines) return text;
|
|
643
|
+
return /* @__PURE__ */ jsx2("span", { className: column.nowrap ? cn("block", cut || "truncate") : CLAMP[lines], title: text, children: text });
|
|
644
|
+
}
|
|
645
|
+
}
|
|
646
|
+
};
|
|
647
|
+
const dataCell = (row, cell, first) => {
|
|
648
|
+
const column = byId.get(cell.column.id);
|
|
649
|
+
if (!column) return null;
|
|
650
|
+
const { style, ...pinnedProps } = pin(cell.column);
|
|
651
|
+
let content;
|
|
652
|
+
if (row.getIsGrouped()) {
|
|
653
|
+
const leaves = row.getLeafRows().filter((r) => !r.getIsGrouped()).map((r) => r.original);
|
|
654
|
+
if (cell.column.id === row.groupingColumnId) {
|
|
655
|
+
const value = display(row.groupingValue);
|
|
656
|
+
content = /* @__PURE__ */ jsxs2("button", { type: "button", className: s2.toggle({ className: "px-1.5 font-semibold text-fg" }), "aria-expanded": row.getIsExpanded(), onClick: row.getToggleExpandedHandler(), children: [
|
|
657
|
+
/* @__PURE__ */ jsx2(ChevronGlyph, { direction: "right", className: "h-4 w-4" }),
|
|
658
|
+
labels.group(value, leaves.length)
|
|
659
|
+
] });
|
|
660
|
+
} else content = column.aggregate ? column.aggregate(leaves) : null;
|
|
661
|
+
} else {
|
|
662
|
+
content = contentOf(column, row.original);
|
|
663
|
+
if (first && inlineToggle) {
|
|
664
|
+
content = /* @__PURE__ */ jsxs2("span", { className: "flex min-w-0 items-center gap-1", children: [
|
|
665
|
+
/* @__PURE__ */ jsx2(
|
|
666
|
+
"button",
|
|
667
|
+
{
|
|
668
|
+
type: "button",
|
|
669
|
+
className: s2.toggle({ className: TOGGLE[L][maxPriority] }),
|
|
670
|
+
"aria-expanded": row.getIsExpanded(),
|
|
671
|
+
"aria-label": labels.showMore(nameOf(row)),
|
|
672
|
+
onClick: row.getToggleExpandedHandler(),
|
|
673
|
+
children: /* @__PURE__ */ jsx2(ChevronGlyph, { direction: "right", className: "h-4 w-4" })
|
|
674
|
+
}
|
|
675
|
+
),
|
|
676
|
+
/* @__PURE__ */ jsx2("span", { className: "min-w-0 flex-1", children: content })
|
|
677
|
+
] });
|
|
678
|
+
}
|
|
679
|
+
}
|
|
680
|
+
const level = priorityOf(column);
|
|
681
|
+
const type = column.type;
|
|
682
|
+
const cellClass = [
|
|
683
|
+
ALIGN[column.align ?? (type === "number" ? "end" : "start")],
|
|
684
|
+
type ? TYPE_CELL[type][L] : "",
|
|
685
|
+
level > 1 ? LEAVES[L][level] : "",
|
|
686
|
+
(type || column.priority) && column.minWidth !== void 0 ? MIN[L] : "",
|
|
687
|
+
column.maxWidth !== void 0 ? MAX[L] : ""
|
|
688
|
+
].join(" ");
|
|
689
|
+
return /* @__PURE__ */ jsx2(
|
|
690
|
+
"td",
|
|
691
|
+
{
|
|
692
|
+
role: "cell",
|
|
693
|
+
"data-label": column.header,
|
|
694
|
+
"data-card": row.getIsGrouped() ? cell.column.id === row.groupingColumnId ? "title" : column.aggregate ? void 0 : "hidden" : cardOf(column),
|
|
695
|
+
...pinnedProps,
|
|
696
|
+
className: s2.td({ className: cellClass }),
|
|
697
|
+
style: {
|
|
698
|
+
...style,
|
|
699
|
+
...column.minWidth !== void 0 ? { ["--dt-min"]: `${column.minWidth}px` } : {},
|
|
700
|
+
...column.maxWidth !== void 0 ? { ["--dt-max"]: `${column.maxWidth}px` } : {},
|
|
701
|
+
...first && row.depth > 0 && !row.getIsGrouped() ? { paddingInlineStart: `${1 + row.depth * 1.25}rem` } : {}
|
|
702
|
+
},
|
|
703
|
+
children: content
|
|
704
|
+
},
|
|
705
|
+
cell.id
|
|
706
|
+
);
|
|
707
|
+
};
|
|
708
|
+
const renderRow = (row, index) => {
|
|
709
|
+
const isChosen = chosen.has(row.id);
|
|
710
|
+
const grouped = row.getIsGrouped();
|
|
711
|
+
const canExpand = !grouped && (renderDetail ? true : row.getCanExpand());
|
|
712
|
+
const showDetail = detailed && !grouped && row.getIsExpanded() && !virtualized;
|
|
713
|
+
const cells = row.getVisibleCells();
|
|
714
|
+
const main = /* @__PURE__ */ jsxs2(
|
|
715
|
+
"tr",
|
|
716
|
+
{
|
|
717
|
+
role: "row",
|
|
718
|
+
"data-index": windowItems ? index : void 0,
|
|
719
|
+
ref: windowItems ? virtualizer.measureElement : void 0,
|
|
720
|
+
"aria-rowindex": virtualized ? index + 2 : void 0,
|
|
721
|
+
"data-state": isChosen ? "selected" : void 0,
|
|
722
|
+
"data-group": grouped ? "" : void 0,
|
|
723
|
+
className: s2.tr({ className: grouped ? s2.groupRow() : void 0 }),
|
|
724
|
+
children: [
|
|
725
|
+
selectable && /* @__PURE__ */ jsx2("td", { role: "cell", className: s2.td({ className: s2.select() }), children: grouped ? null : /* @__PURE__ */ jsx2(Checkbox, { checked: isChosen, onCheckedChange: () => row.toggleSelected(), "aria-label": labels.selectRow(nameOf(row)) }) }),
|
|
726
|
+
hasExpander && /* @__PURE__ */ jsx2("td", { role: "cell", className: s2.td({ className: s2.expander() }), children: canExpand ? /* @__PURE__ */ jsx2("button", { type: "button", className: s2.toggle(), "aria-expanded": row.getIsExpanded(), "aria-label": labels.expandRow(nameOf(row)), onClick: row.getToggleExpandedHandler(), children: /* @__PURE__ */ jsx2(ChevronGlyph, { direction: "right", className: "h-4 w-4" }) }) : null }),
|
|
727
|
+
cells.map((cell, i) => dataCell(row, cell, i === 0))
|
|
728
|
+
]
|
|
729
|
+
}
|
|
730
|
+
);
|
|
731
|
+
if (!showDetail) return /* @__PURE__ */ jsx2(React.Fragment, { children: main }, row.id);
|
|
732
|
+
const left = visibleColumns.filter((c) => priorityOf(byId.get(c.id)) > 1);
|
|
733
|
+
return /* @__PURE__ */ jsxs2(React.Fragment, { children: [
|
|
734
|
+
main,
|
|
735
|
+
/* @__PURE__ */ jsx2("tr", { role: "row", className: s2.tr({ className: "hover:bg-transparent" }), children: /* @__PURE__ */ jsxs2("td", { role: "cell", colSpan: span, "data-card": "message", className: s2.td({ className: renderDetail ? s2.detail() : "bg-surface-0 p-0 text-left" }), children: [
|
|
736
|
+
left.length > 0 ? /* @__PURE__ */ jsx2("dl", { className: cn("m-0 grid gap-3 text-left", renderDetail ? "mb-4" : cn("px-4 py-4", PANEL[L][maxPriority])), children: left.map((c) => {
|
|
737
|
+
const column = byId.get(c.id);
|
|
738
|
+
return /* @__PURE__ */ jsxs2("div", { className: cn(IN_DETAIL[L][priorityOf(column)], "grid-cols-[minmax(5rem,8rem)_minmax(0,1fr)] items-baseline gap-3"), children: [
|
|
739
|
+
/* @__PURE__ */ jsx2("dt", { className: "text-xs font-semibold text-fg-secondary", children: column.header }),
|
|
740
|
+
/* @__PURE__ */ jsx2("dd", { className: "m-0 min-w-0 text-sm text-fg", children: contentOf(column, row.original) })
|
|
741
|
+
] }, c.id);
|
|
742
|
+
}) }) : null,
|
|
743
|
+
renderDetail ? renderDetail(row.original) : null
|
|
744
|
+
] }) })
|
|
745
|
+
] }, row.id);
|
|
746
|
+
};
|
|
747
|
+
let body;
|
|
748
|
+
if (loading) {
|
|
749
|
+
body = Array.from({ length: loadingRows }, (_, i) => /* @__PURE__ */ jsxs2("tr", { role: "row", "aria-hidden": true, className: s2.tr(), children: [
|
|
750
|
+
selectable && /* @__PURE__ */ jsx2("td", { role: "cell", className: s2.td({ className: s2.select() }) }),
|
|
751
|
+
hasExpander && /* @__PURE__ */ jsx2("td", { role: "cell", className: s2.td({ className: s2.expander() }) }),
|
|
752
|
+
visibleColumns.map((column) => /* @__PURE__ */ jsx2("td", { role: "cell", "data-card": cardOf(byId.get(column.id)), className: s2.td(), children: /* @__PURE__ */ jsx2("div", { className: s2.skeleton() }) }, column.id))
|
|
753
|
+
] }, `loading-${i}`));
|
|
754
|
+
} else if (error) body = message(error, true);
|
|
755
|
+
else if (pageRows.length === 0) body = message(empty2 ?? labels.empty);
|
|
756
|
+
else if (windowItems) body = windowItems.map((item) => renderRow(pageRows[item.index], item.index));
|
|
757
|
+
else body = pageRows.map((row, i) => renderRow(row, i));
|
|
758
|
+
const headers = table.getHeaderGroups().at(-1)?.headers ?? [];
|
|
759
|
+
const tableElement = /* @__PURE__ */ jsxs2(
|
|
760
|
+
"table",
|
|
761
|
+
{
|
|
762
|
+
role: "table",
|
|
763
|
+
"aria-busy": loading || void 0,
|
|
764
|
+
"aria-rowcount": virtualized ? pageRows.length + 1 : void 0,
|
|
765
|
+
className: s2.table({ className: fixedLayout ? "table-fixed" : void 0 }),
|
|
766
|
+
style: fixedLayout ? { minWidth: table.getTotalSize() + (selectable ? 40 : 0) + (hasExpander ? 40 : 0) } : void 0,
|
|
767
|
+
children: [
|
|
768
|
+
/* @__PURE__ */ jsxs2("caption", { className: showCaption ? s2.caption() : "sr-only", children: [
|
|
769
|
+
caption,
|
|
770
|
+
loading ? /* @__PURE__ */ jsx2("span", { className: "sr-only", children: ` \u2014 ${labels.loading}` }) : null
|
|
771
|
+
] }),
|
|
772
|
+
/* @__PURE__ */ jsx2("thead", { role: "rowgroup", className: s2.thead({ className: virtualized ? "sticky top-0 z-10 bg-surface-2" : void 0 }), children: /* @__PURE__ */ jsxs2("tr", { role: "row", "aria-rowindex": virtualized ? 1 : void 0, className: s2.headRow(), children: [
|
|
773
|
+
selectable && /* @__PURE__ */ jsx2("th", { role: "columnheader", scope: "col", "data-keep": "", className: s2.th({ className: s2.select() }), children: /* @__PURE__ */ jsx2(
|
|
774
|
+
Checkbox,
|
|
775
|
+
{
|
|
776
|
+
checked: allChosen ? true : someChosen ? "indeterminate" : false,
|
|
777
|
+
onCheckedChange: toggleAll,
|
|
778
|
+
disabled: loading || selectableIds.length === 0,
|
|
779
|
+
"aria-label": labels.selectAll
|
|
780
|
+
}
|
|
781
|
+
) }),
|
|
782
|
+
hasExpander && /* @__PURE__ */ jsx2("th", { role: "columnheader", scope: "col", className: s2.th({ className: s2.expander() }), children: /* @__PURE__ */ jsx2("span", { className: "sr-only", children: labels.details }) }),
|
|
783
|
+
headers.map((header) => {
|
|
784
|
+
const column = byId.get(header.column.id);
|
|
785
|
+
if (!column) return null;
|
|
786
|
+
const sorted = header.column.getIsSorted();
|
|
787
|
+
const direction = sorted === "asc" ? "ascending" : sorted === "desc" ? "descending" : void 0;
|
|
788
|
+
const { style, ...pinnedProps } = pin(header.column);
|
|
789
|
+
const level = priorityOf(column);
|
|
790
|
+
return /* @__PURE__ */ jsxs2(
|
|
791
|
+
"th",
|
|
792
|
+
{
|
|
793
|
+
role: "columnheader",
|
|
794
|
+
scope: "col",
|
|
795
|
+
"aria-sort": column.sortable ? direction ?? "none" : void 0,
|
|
796
|
+
"data-keep": column.sortable ? "" : void 0,
|
|
797
|
+
...pinnedProps,
|
|
798
|
+
className: s2.th({ className: cn(ALIGN[column.align ?? (column.type === "number" ? "end" : "start")], level > 1 && LEAVES_HEAD[L][level]) }),
|
|
799
|
+
style: { ...style, ...typeof stickyHeader === "number" ? { ["--dt-top"]: `${stickyHeader}px` } : {}, ...width(header.column) },
|
|
800
|
+
children: [
|
|
801
|
+
column.sortable ? /* @__PURE__ */ jsxs2("button", { type: "button", "aria-pressed": Boolean(direction), className: s2.sortButton(), onClick: () => header.column.toggleSorting(void 0, false), children: [
|
|
802
|
+
column.header,
|
|
803
|
+
/* @__PURE__ */ jsx2(SortGlyph, { direction, className: "h-3.5 w-3.5" })
|
|
804
|
+
] }) : column.headerHidden ? /* @__PURE__ */ jsx2("span", { className: "sr-only", children: column.header }) : column.header,
|
|
805
|
+
resizing && header.column.getCanResize() ? /* @__PURE__ */ jsx2(
|
|
806
|
+
ResizeHandle,
|
|
807
|
+
{
|
|
808
|
+
label: labels.resize(column.header),
|
|
809
|
+
size: header.column.getSize(),
|
|
810
|
+
min: column.minWidth ?? 64,
|
|
811
|
+
resizing: header.column.getIsResizing(),
|
|
812
|
+
className: s2.resizer(),
|
|
813
|
+
onPointerStart: header.getResizeHandler(),
|
|
814
|
+
onSize: (size) => setSizing((old) => ({ ...old, [header.column.id]: size }))
|
|
815
|
+
}
|
|
816
|
+
) : null
|
|
817
|
+
]
|
|
818
|
+
},
|
|
819
|
+
header.id
|
|
820
|
+
);
|
|
821
|
+
})
|
|
822
|
+
] }) }),
|
|
823
|
+
/* @__PURE__ */ jsxs2("tbody", { role: "rowgroup", className: s2.tbody(), children: [
|
|
824
|
+
before > 0 && /* @__PURE__ */ jsx2("tr", { "aria-hidden": true, style: { height: before }, children: /* @__PURE__ */ jsx2("td", { colSpan: span }) }),
|
|
825
|
+
body,
|
|
826
|
+
after > 0 && /* @__PURE__ */ jsx2("tr", { "aria-hidden": true, style: { height: after }, children: /* @__PURE__ */ jsx2("td", { colSpan: span }) })
|
|
827
|
+
] })
|
|
828
|
+
]
|
|
829
|
+
}
|
|
830
|
+
);
|
|
831
|
+
const context = {
|
|
832
|
+
table,
|
|
833
|
+
columns,
|
|
834
|
+
labels,
|
|
835
|
+
filters,
|
|
836
|
+
setFilters: changeFilters,
|
|
837
|
+
resultCount: leafCount,
|
|
838
|
+
exportRows: () => table.getSortedRowModel().flatRows.filter((r) => !r.getIsGrouped()).map((r) => r.original),
|
|
839
|
+
manualFiltering: Boolean(manual?.filtering)
|
|
840
|
+
};
|
|
841
|
+
const pagination2 = paginated ? /* @__PURE__ */ jsx2(
|
|
842
|
+
Pagination,
|
|
843
|
+
{
|
|
844
|
+
page: Math.min(page, pageCount),
|
|
845
|
+
pageCount,
|
|
846
|
+
onPageChange: changePage,
|
|
847
|
+
pageSize: pageSizeOptions ? pageSize : void 0,
|
|
848
|
+
pageSizeOptions,
|
|
849
|
+
onPageSizeChange: pageSizeOptions ? changePageSize : void 0,
|
|
850
|
+
disabled: loading,
|
|
851
|
+
labels: labels.pagination
|
|
852
|
+
}
|
|
853
|
+
) : null;
|
|
854
|
+
return /* @__PURE__ */ jsx2(DataTableContext.Provider, { value: context, children: /* @__PURE__ */ jsxs2("div", { className: s2.root({ className }), children: [
|
|
855
|
+
toolbar ? /* @__PURE__ */ jsx2("div", { className: s2.toolbar(), children: toolbar }) : null,
|
|
856
|
+
virtualized ? (
|
|
857
|
+
// A scrolling region the keyboard can reach: Tab lands on it, the arrows scroll it.
|
|
858
|
+
/* @__PURE__ */ jsx2(
|
|
859
|
+
"div",
|
|
860
|
+
{
|
|
861
|
+
ref: scroller,
|
|
862
|
+
tabIndex: 0,
|
|
863
|
+
role: "region",
|
|
864
|
+
"aria-label": caption,
|
|
865
|
+
className: s2.scroller({ className: "overflow-y-auto focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-ring" }),
|
|
866
|
+
style: { height: virtualized.height },
|
|
867
|
+
children: tableElement
|
|
868
|
+
}
|
|
869
|
+
)
|
|
870
|
+
) : /* @__PURE__ */ jsx2("div", { className: s2.scroller({ className: sideways ? scroll ? SHADOWS : void 0 : "overflow-x-clip" }), children: tableElement }),
|
|
871
|
+
pagination2 || footer ? /* @__PURE__ */ jsxs2("div", { className: s2.footer({ className: "flex flex-col gap-3" }), children: [
|
|
872
|
+
pagination2,
|
|
873
|
+
footer
|
|
874
|
+
] }) : null
|
|
875
|
+
] }) });
|
|
876
|
+
}
|
|
877
|
+
function ResizeHandle({
|
|
878
|
+
label,
|
|
879
|
+
size,
|
|
880
|
+
min,
|
|
881
|
+
resizing,
|
|
882
|
+
className,
|
|
883
|
+
onPointerStart,
|
|
884
|
+
onSize
|
|
885
|
+
}) {
|
|
886
|
+
return (
|
|
887
|
+
// A focusable separator is interactive (WAI-ARIA "window splitter"): its value is the width, the arrows change it.
|
|
888
|
+
/* @__PURE__ */ jsx2(
|
|
889
|
+
"div",
|
|
890
|
+
{
|
|
891
|
+
role: "separator",
|
|
892
|
+
"aria-orientation": "vertical",
|
|
893
|
+
"aria-label": label,
|
|
894
|
+
"aria-valuenow": Math.round(size),
|
|
895
|
+
"aria-valuemin": min,
|
|
896
|
+
tabIndex: 0,
|
|
897
|
+
"data-resizing": resizing ? "" : void 0,
|
|
898
|
+
className,
|
|
899
|
+
onMouseDown: onPointerStart,
|
|
900
|
+
onTouchStart: onPointerStart,
|
|
901
|
+
onClick: (event) => event.stopPropagation(),
|
|
902
|
+
onKeyDown: (event) => {
|
|
903
|
+
const step = event.shiftKey ? 48 : 16;
|
|
904
|
+
if (event.key === "ArrowLeft") onSize(Math.max(min, size - step));
|
|
905
|
+
else if (event.key === "ArrowRight") onSize(size + step);
|
|
906
|
+
else return;
|
|
907
|
+
event.preventDefault();
|
|
908
|
+
}
|
|
909
|
+
}
|
|
910
|
+
)
|
|
911
|
+
);
|
|
912
|
+
}
|
|
913
|
+
|
|
914
|
+
// src/field/field.tsx
|
|
915
|
+
import { tv as tv3 } from "tailwind-variants";
|
|
916
|
+
import { jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
917
|
+
var field2 = tv3({
|
|
918
|
+
slots: {
|
|
919
|
+
root: "flex flex-col gap-1.5",
|
|
920
|
+
label: "text-xs font-semibold text-fg-secondary",
|
|
921
|
+
control: "flex h-11 w-full rounded-lg border border-border-default bg-surface-2 px-3 text-sm text-fg placeholder:text-fg-muted transition-[border-color,box-shadow] focus-visible:border-accent focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:border-danger aria-invalid:ring-danger/30",
|
|
922
|
+
hint: "text-xs text-fg-secondary",
|
|
923
|
+
// The message reads in the danger text role (≥ 4.5:1 on every surface, both themes); the dot is the danger fill.
|
|
924
|
+
error: "flex items-center gap-1.5 text-xs font-medium text-fg-danger before:h-1.5 before:w-1.5 before:shrink-0 before:rounded-full before:bg-danger",
|
|
925
|
+
selectWrap: "relative flex w-full",
|
|
926
|
+
chevron: "pointer-events-none absolute right-3 top-1/2 h-4 w-4 -translate-y-1/2 text-fg-secondary"
|
|
927
|
+
}
|
|
928
|
+
});
|
|
929
|
+
var s = field2();
|
|
930
|
+
var invalidProps = (invalid) => invalid ? { "aria-invalid": true, "data-invalid": "" } : {};
|
|
931
|
+
function Input({ invalid, className, ...props }) {
|
|
932
|
+
return /* @__PURE__ */ jsx3("input", { ...invalidProps(invalid), className: s.control({ className }), ...props });
|
|
933
|
+
}
|
|
934
|
+
|
|
935
|
+
// src/data-table/toolbar.tsx
|
|
936
|
+
import { jsx as jsx4, jsxs as jsxs4 } from "react/jsx-runtime";
|
|
937
|
+
var asRange = (value) => Array.isArray(value) && value.length === 2 && (typeof value[0] !== "string" || typeof value[1] !== "string") ? [value[0], value[1]] : [null, null];
|
|
938
|
+
var asList = (value) => Array.isArray(value) ? value : [];
|
|
939
|
+
var number = (text) => text.trim() === "" || Number.isNaN(Number(text)) ? null : Number(text);
|
|
940
|
+
function DataTableFilters({ debounce = 250, children, className }) {
|
|
941
|
+
const { table, columns, labels, filters, setFilters, resultCount, manualFiltering } = useDataTable();
|
|
942
|
+
const set = (id, value) => {
|
|
943
|
+
const next = { ...filters };
|
|
944
|
+
if (value === null || value === "" || Array.isArray(value) && (value.length === 0 || value.length === 2 && value[0] == null && value[1] == null)) delete next[id];
|
|
945
|
+
else next[id] = value;
|
|
946
|
+
setFilters(next);
|
|
947
|
+
};
|
|
948
|
+
const filterable = columns.filter((column) => column.filter);
|
|
949
|
+
const optionsOf = (column) => {
|
|
950
|
+
if (column.options) return column.options;
|
|
951
|
+
const facets = manualFiltering ? /* @__PURE__ */ new Map() : table.getColumn(column.id)?.getFacetedUniqueValues() ?? /* @__PURE__ */ new Map();
|
|
952
|
+
return [...facets.entries()].filter(([value]) => value != null && value !== "").map(([value, count]) => ({ value: String(value), label: String(value), count })).sort((a, b) => a.label.localeCompare(b.label, void 0, { numeric: true }));
|
|
953
|
+
};
|
|
954
|
+
const active = filterable.flatMap((column) => {
|
|
955
|
+
const value = filters[column.id];
|
|
956
|
+
if (value === void 0) return [];
|
|
957
|
+
let text;
|
|
958
|
+
if (column.filter === "facet") {
|
|
959
|
+
const options = optionsOf(column);
|
|
960
|
+
text = asList(value).map((v) => options.find((o) => o.value === v)?.label ?? v).join(", ");
|
|
961
|
+
} else if (column.filter === "range") {
|
|
962
|
+
const [min, max] = asRange(value);
|
|
963
|
+
text = `${min ?? "\u2026"}\u2013${max ?? "\u2026"}`;
|
|
964
|
+
} else text = String(value);
|
|
965
|
+
const label = labels.activeFilter(column.header, text);
|
|
966
|
+
return [{ id: column.id, label, onRemove: () => set(column.id, null) }];
|
|
967
|
+
});
|
|
968
|
+
return /* @__PURE__ */ jsxs4(
|
|
969
|
+
FilterBar,
|
|
970
|
+
{
|
|
971
|
+
label: labels.filters,
|
|
972
|
+
active,
|
|
973
|
+
onClearAll: () => setFilters({}),
|
|
974
|
+
clearLabel: labels.clearFilters,
|
|
975
|
+
removeLabel: labels.removeFilter,
|
|
976
|
+
results: labels.results(resultCount),
|
|
977
|
+
className,
|
|
978
|
+
children: [
|
|
979
|
+
filterable.map((column) => {
|
|
980
|
+
if (column.filter === "text")
|
|
981
|
+
return /* @__PURE__ */ jsx4(
|
|
982
|
+
SearchField,
|
|
983
|
+
{
|
|
984
|
+
label: labels.search(column.header),
|
|
985
|
+
placeholder: labels.search(column.header),
|
|
986
|
+
value: typeof filters[column.id] === "string" ? void 0 : "",
|
|
987
|
+
defaultValue: typeof filters[column.id] === "string" ? filters[column.id] : void 0,
|
|
988
|
+
debounce,
|
|
989
|
+
onSearch: (query) => set(column.id, query),
|
|
990
|
+
landmark: false,
|
|
991
|
+
size: "sm",
|
|
992
|
+
className: "min-w-48 flex-1"
|
|
993
|
+
},
|
|
994
|
+
column.id
|
|
995
|
+
);
|
|
996
|
+
if (column.filter === "facet")
|
|
997
|
+
return /* @__PURE__ */ jsx4(FilterMenu, { label: column.header, options: optionsOf(column), value: asList(filters[column.id]), onValueChange: (value) => set(column.id, value) }, column.id);
|
|
998
|
+
const [min, max] = asRange(filters[column.id]);
|
|
999
|
+
const bounds = manualFiltering ? void 0 : table.getColumn(column.id)?.getFacetedMinMaxValues();
|
|
1000
|
+
return /* @__PURE__ */ jsxs4("span", { className: "inline-flex items-center gap-1.5", children: [
|
|
1001
|
+
/* @__PURE__ */ jsx4(
|
|
1002
|
+
Input,
|
|
1003
|
+
{
|
|
1004
|
+
type: "number",
|
|
1005
|
+
inputMode: "decimal",
|
|
1006
|
+
"aria-label": labels.rangeFrom(column.header),
|
|
1007
|
+
placeholder: bounds ? String(bounds[0]) : labels.rangeFrom(column.header),
|
|
1008
|
+
value: min ?? "",
|
|
1009
|
+
onChange: (event) => set(column.id, [number(event.currentTarget.value), max]),
|
|
1010
|
+
className: "h-11 w-28"
|
|
1011
|
+
}
|
|
1012
|
+
),
|
|
1013
|
+
/* @__PURE__ */ jsx4("span", { "aria-hidden": true, className: "text-fg-secondary", children: "\u2013" }),
|
|
1014
|
+
/* @__PURE__ */ jsx4(
|
|
1015
|
+
Input,
|
|
1016
|
+
{
|
|
1017
|
+
type: "number",
|
|
1018
|
+
inputMode: "decimal",
|
|
1019
|
+
"aria-label": labels.rangeTo(column.header),
|
|
1020
|
+
placeholder: bounds ? String(bounds[1]) : labels.rangeTo(column.header),
|
|
1021
|
+
value: max ?? "",
|
|
1022
|
+
onChange: (event) => set(column.id, [min, number(event.currentTarget.value)]),
|
|
1023
|
+
className: "h-11 w-28"
|
|
1024
|
+
}
|
|
1025
|
+
)
|
|
1026
|
+
] }, column.id);
|
|
1027
|
+
}),
|
|
1028
|
+
children
|
|
1029
|
+
]
|
|
1030
|
+
}
|
|
1031
|
+
);
|
|
1032
|
+
}
|
|
1033
|
+
function DataTableColumnsMenu({ defaultOpen, className }) {
|
|
1034
|
+
const { table, columns, labels } = useDataTable();
|
|
1035
|
+
return /* @__PURE__ */ jsxs4(DropdownMenu.Root, { defaultOpen, modal: false, children: [
|
|
1036
|
+
/* @__PURE__ */ jsx4(DropdownMenu.Trigger, { asChild: true, children: /* @__PURE__ */ jsxs4(Button, { variant: "outline", size: "sm", className, children: [
|
|
1037
|
+
labels.columns,
|
|
1038
|
+
/* @__PURE__ */ jsx4(ChevronGlyph, { className: "h-4 w-4" })
|
|
1039
|
+
] }) }),
|
|
1040
|
+
/* @__PURE__ */ jsx4(DropdownMenu.Content, { align: "end", "aria-label": labels.columns, children: columns.filter((column) => column.hideable !== false).map((column) => {
|
|
1041
|
+
const instance = table.getColumn(column.id);
|
|
1042
|
+
return /* @__PURE__ */ jsx4(
|
|
1043
|
+
DropdownMenu.CheckboxItem,
|
|
1044
|
+
{
|
|
1045
|
+
checked: instance?.getIsVisible() ?? true,
|
|
1046
|
+
onSelect: (event) => event.preventDefault(),
|
|
1047
|
+
onCheckedChange: (checked) => instance?.toggleVisibility(Boolean(checked)),
|
|
1048
|
+
children: column.header
|
|
1049
|
+
},
|
|
1050
|
+
column.id
|
|
1051
|
+
);
|
|
1052
|
+
}) })
|
|
1053
|
+
] });
|
|
1054
|
+
}
|
|
1055
|
+
function DataTableExport({ filename = "export.csv", onExport, className }) {
|
|
1056
|
+
const { table, columns, labels, exportRows } = useDataTable();
|
|
1057
|
+
const run = () => {
|
|
1058
|
+
const visible = columns.filter((column) => table.getColumn(column.id)?.getIsVisible() !== false);
|
|
1059
|
+
const csv = dataTableCsv(exportRows(), visible);
|
|
1060
|
+
if (onExport) return onExport(csv);
|
|
1061
|
+
const url = URL.createObjectURL(new Blob(["\uFEFF", csv], { type: "text/csv;charset=utf-8" }));
|
|
1062
|
+
const link = Object.assign(document.createElement("a"), { href: url, download: filename });
|
|
1063
|
+
link.click();
|
|
1064
|
+
setTimeout(() => URL.revokeObjectURL(url), 0);
|
|
1065
|
+
};
|
|
1066
|
+
return /* @__PURE__ */ jsx4(Button, { variant: "outline", size: "sm", className, onClick: run, children: labels.export });
|
|
1067
|
+
}
|
|
1068
|
+
|
|
1069
|
+
export {
|
|
1070
|
+
dataTableCsv,
|
|
1071
|
+
compareValues,
|
|
1072
|
+
dataTable,
|
|
1073
|
+
dataTableLabels,
|
|
1074
|
+
useDataTable,
|
|
1075
|
+
DataTable,
|
|
1076
|
+
DataTableFilters,
|
|
1077
|
+
DataTableColumnsMenu,
|
|
1078
|
+
DataTableExport
|
|
1079
|
+
};
|
|
1080
|
+
//# sourceMappingURL=chunk-R6NK6ZNY.js.map
|