@runlume/admin-ui 0.1.0 → 0.2.1
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.en.md +6 -13
- package/README.md +5 -11
- package/dist-package/_virtual/_rolldown/runtime.cjs +1 -0
- package/dist-package/admin-ui.cjs +1 -0
- package/dist-package/admin-ui.d.ts +41 -1
- package/dist-package/admin-ui.d.ts.map +1 -1
- package/dist-package/admin-ui.js +79 -0
- package/dist-package/components/calendar.cjs +1 -0
- package/dist-package/components/calendar.d.ts +13 -0
- package/dist-package/components/calendar.d.ts.map +1 -0
- package/dist-package/components/calendar.js +91 -0
- package/dist-package/components/cascader.cjs +1 -0
- package/dist-package/components/cascader.d.ts +19 -0
- package/dist-package/components/cascader.d.ts.map +1 -0
- package/dist-package/components/cascader.js +85 -0
- package/dist-package/components/charts.cjs +1 -0
- package/dist-package/components/charts.d.ts +80 -0
- package/dist-package/components/charts.d.ts.map +1 -0
- package/dist-package/components/charts.js +374 -0
- package/dist-package/components/code-block.cjs +1 -0
- package/dist-package/components/code-block.d.ts +7 -0
- package/dist-package/components/code-block.d.ts.map +1 -0
- package/dist-package/components/code-block.js +47 -0
- package/dist-package/components/column-chart.cjs +1 -0
- package/dist-package/components/column-chart.d.ts +18 -0
- package/dist-package/components/column-chart.d.ts.map +1 -0
- package/dist-package/components/column-chart.js +89 -0
- package/dist-package/components/combobox.cjs +1 -0
- package/dist-package/components/combobox.d.ts +24 -0
- package/dist-package/components/combobox.d.ts.map +1 -0
- package/dist-package/components/combobox.js +111 -0
- package/dist-package/components/confirm-dialog.cjs +1 -0
- package/dist-package/components/confirm-dialog.d.ts +17 -0
- package/dist-package/components/confirm-dialog.d.ts.map +1 -0
- package/dist-package/components/confirm-dialog.js +44 -0
- package/dist-package/components/count-to.cjs +1 -0
- package/dist-package/components/count-to.d.ts +13 -0
- package/dist-package/components/count-to.d.ts.map +1 -0
- package/dist-package/components/count-to.js +36 -0
- package/dist-package/components/cursor-pagination.cjs +1 -0
- package/dist-package/components/cursor-pagination.d.ts +11 -0
- package/dist-package/components/cursor-pagination.d.ts.map +1 -0
- package/dist-package/components/cursor-pagination.js +39 -0
- package/dist-package/components/data-table.cjs +1 -0
- package/dist-package/components/data-table.d.ts +69 -0
- package/dist-package/components/data-table.d.ts.map +1 -0
- package/dist-package/components/data-table.js +377 -0
- package/dist-package/components/descriptions.cjs +1 -0
- package/dist-package/components/descriptions.d.ts +16 -0
- package/dist-package/components/descriptions.d.ts.map +1 -0
- package/dist-package/components/descriptions.js +28 -0
- package/dist-package/components/editable-table.cjs +1 -0
- package/dist-package/components/editable-table.d.ts +27 -0
- package/dist-package/components/editable-table.d.ts.map +1 -0
- package/dist-package/components/editable-table.js +212 -0
- package/dist-package/components/filter-presets.cjs +1 -0
- package/dist-package/components/filter-presets.d.ts +11 -0
- package/dist-package/components/filter-presets.d.ts.map +1 -0
- package/dist-package/components/filter-presets.js +17 -0
- package/dist-package/components/fixed-bar.cjs +1 -0
- package/dist-package/components/fixed-bar.d.ts +11 -0
- package/dist-package/components/fixed-bar.d.ts.map +1 -0
- package/dist-package/components/fixed-bar.js +18 -0
- package/dist-package/components/image-preview.cjs +1 -0
- package/dist-package/components/image-preview.d.ts +14 -0
- package/dist-package/components/image-preview.d.ts.map +1 -0
- package/dist-package/components/image-preview.js +166 -0
- package/dist-package/components/layout-container.cjs +1 -0
- package/dist-package/components/layout-container.d.ts +17 -0
- package/dist-package/components/layout-container.d.ts.map +1 -0
- package/dist-package/components/layout-container.js +85 -0
- package/dist-package/components/mention.cjs +1 -0
- package/dist-package/components/mention.d.ts +20 -0
- package/dist-package/components/mention.d.ts.map +1 -0
- package/dist-package/components/mention.js +126 -0
- package/dist-package/components/multi-select.cjs +1 -0
- package/dist-package/components/multi-select.d.ts +17 -0
- package/dist-package/components/multi-select.d.ts.map +1 -0
- package/dist-package/components/multi-select.js +126 -0
- package/dist-package/components/multi-step-loader.cjs +1 -0
- package/dist-package/components/multi-step-loader.d.ts +18 -0
- package/dist-package/components/multi-step-loader.d.ts.map +1 -0
- package/dist-package/components/multi-step-loader.js +38 -0
- package/dist-package/components/page-button.cjs +1 -0
- package/dist-package/components/page-button.d.ts +6 -0
- package/dist-package/components/page-button.d.ts.map +1 -0
- package/dist-package/components/page-button.js +24 -0
- package/dist-package/components/page-pager.cjs +1 -0
- package/dist-package/components/page-pager.d.ts +11 -0
- package/dist-package/components/page-pager.d.ts.map +1 -0
- package/dist-package/components/page-pager.js +51 -0
- package/dist-package/components/page.cjs +1 -0
- package/dist-package/components/page.d.ts +34 -0
- package/dist-package/components/page.d.ts.map +1 -0
- package/dist-package/components/page.js +208 -0
- package/dist-package/components/pagination-bar.cjs +1 -0
- package/dist-package/components/pagination-bar.d.ts +8 -0
- package/dist-package/components/pagination-bar.d.ts.map +1 -0
- package/dist-package/components/pagination-bar.js +23 -0
- package/dist-package/components/password-strength.cjs +1 -0
- package/dist-package/components/password-strength.d.ts +11 -0
- package/dist-package/components/password-strength.d.ts.map +1 -0
- package/dist-package/components/password-strength.js +70 -0
- package/dist-package/components/rate.cjs +1 -0
- package/dist-package/components/rate.d.ts +13 -0
- package/dist-package/components/rate.d.ts.map +1 -0
- package/dist-package/components/rate.js +56 -0
- package/dist-package/components/resizable-panel.cjs +1 -0
- package/dist-package/components/resizable-panel.d.ts +15 -0
- package/dist-package/components/resizable-panel.d.ts.map +1 -0
- package/dist-package/components/resizable-panel.js +56 -0
- package/dist-package/components/search-filters.cjs +1 -0
- package/dist-package/components/search-filters.d.ts +31 -0
- package/dist-package/components/search-filters.d.ts.map +1 -0
- package/dist-package/components/search-filters.js +110 -0
- package/dist-package/components/sortable-list.cjs +1 -0
- package/dist-package/components/sortable-list.d.ts +14 -0
- package/dist-package/components/sortable-list.d.ts.map +1 -0
- package/dist-package/components/sortable-list.js +48 -0
- package/dist-package/components/sparkline.cjs +1 -0
- package/dist-package/components/sparkline.d.ts +11 -0
- package/dist-package/components/sparkline.d.ts.map +1 -0
- package/dist-package/components/sparkline.js +50 -0
- package/dist-package/components/status-badge.cjs +1 -0
- package/dist-package/components/status-badge.d.ts +4 -0
- package/dist-package/components/status-badge.d.ts.map +1 -0
- package/dist-package/components/status-badge.js +28 -0
- package/dist-package/components/steps.cjs +1 -0
- package/dist-package/components/steps.d.ts +15 -0
- package/dist-package/components/steps.d.ts.map +1 -0
- package/dist-package/components/steps.js +41 -0
- package/dist-package/components/storage-box.cjs +1 -0
- package/dist-package/components/storage-box.d.ts +19 -0
- package/dist-package/components/storage-box.d.ts.map +1 -0
- package/dist-package/components/storage-box.js +153 -0
- package/dist-package/components/table-cell-overflow.cjs +1 -0
- package/dist-package/components/table-cell-overflow.d.ts +5 -0
- package/dist-package/components/table-cell-overflow.d.ts.map +1 -0
- package/dist-package/components/table-cell-overflow.js +31 -0
- package/dist-package/components/table-toolbar.cjs +1 -0
- package/dist-package/components/table-toolbar.d.ts +5 -0
- package/dist-package/components/table-toolbar.d.ts.map +1 -0
- package/dist-package/components/table-toolbar.js +11 -0
- package/dist-package/components/timeline.cjs +1 -0
- package/dist-package/components/timeline.d.ts +14 -0
- package/dist-package/components/timeline.d.ts.map +1 -0
- package/dist-package/components/timeline.js +40 -0
- package/dist-package/components/transfer.cjs +1 -0
- package/dist-package/components/transfer.d.ts +18 -0
- package/dist-package/components/transfer.d.ts.map +1 -0
- package/dist-package/components/transfer.js +98 -0
- package/dist-package/components/tree-table.cjs +1 -0
- package/dist-package/components/tree-table.d.ts +23 -0
- package/dist-package/components/tree-table.d.ts.map +1 -0
- package/dist-package/components/tree-table.js +53 -0
- package/dist-package/components/tree.cjs +1 -0
- package/dist-package/components/tree.d.ts +36 -0
- package/dist-package/components/tree.d.ts.map +1 -0
- package/dist-package/components/tree.js +204 -0
- package/dist-package/components/trend.cjs +1 -0
- package/dist-package/components/trend.d.ts +19 -0
- package/dist-package/components/trend.d.ts.map +1 -0
- package/dist-package/components/trend.js +18 -0
- package/dist-package/components/ui/alert-dialog.cjs +1 -0
- package/dist-package/components/ui/alert-dialog.js +57 -0
- package/dist-package/components/ui/alert.cjs +1 -0
- package/dist-package/components/ui/alert.js +63 -0
- package/dist-package/components/ui/avatar.cjs +1 -0
- package/dist-package/components/ui/avatar.js +27 -0
- package/dist-package/components/ui/badge.cjs +1 -0
- package/dist-package/components/ui/badge.js +40 -0
- package/dist-package/components/ui/breadcrumb.cjs +1 -0
- package/dist-package/components/ui/breadcrumb.js +70 -0
- package/dist-package/components/ui/button.cjs +1 -0
- package/dist-package/components/ui/button.js +58 -0
- package/dist-package/components/ui/card.cjs +1 -0
- package/dist-package/components/ui/card.js +55 -0
- package/dist-package/components/ui/checkbox.cjs +1 -0
- package/dist-package/components/ui/checkbox.js +19 -0
- package/dist-package/components/ui/collapsible.cjs +1 -0
- package/dist-package/components/ui/collapsible.js +32 -0
- package/dist-package/components/ui/context-menu.cjs +1 -0
- package/dist-package/components/ui/context-menu.js +46 -0
- package/dist-package/components/ui/date-input.cjs +1 -0
- package/dist-package/components/ui/date-input.js +183 -0
- package/dist-package/components/ui/date-range-input.cjs +1 -0
- package/dist-package/components/ui/date-range-input.js +209 -0
- package/dist-package/components/ui/date-time-input.cjs +1 -0
- package/dist-package/components/ui/date-time-input.js +23 -0
- package/dist-package/components/ui/dialog.cjs +1 -0
- package/dist-package/components/ui/dialog.js +189 -0
- package/dist-package/components/ui/dropdown-menu.cjs +1 -0
- package/dist-package/components/ui/dropdown-menu.js +124 -0
- package/dist-package/components/ui/file-upload.cjs +1 -0
- package/dist-package/components/ui/file-upload.js +160 -0
- package/dist-package/components/ui/hover-card.cjs +1 -0
- package/dist-package/components/ui/hover-card.js +28 -0
- package/dist-package/components/ui/input-otp.cjs +1 -0
- package/dist-package/components/ui/input-otp.js +33 -0
- package/dist-package/components/ui/input.cjs +1 -0
- package/dist-package/components/ui/input.js +65 -0
- package/dist-package/components/ui/kbd.cjs +1 -0
- package/dist-package/components/ui/kbd.js +20 -0
- package/dist-package/components/ui/label.cjs +1 -0
- package/dist-package/components/ui/label.js +14 -0
- package/dist-package/components/ui/native-select.cjs +1 -0
- package/dist-package/components/ui/native-select.js +125 -0
- package/dist-package/components/ui/number-field.cjs +1 -0
- package/dist-package/components/ui/number-field.js +50 -0
- package/dist-package/components/ui/progress.cjs +1 -0
- package/dist-package/components/ui/progress.js +28 -0
- package/dist-package/components/ui/radio-group.cjs +1 -0
- package/dist-package/components/ui/radio-group.js +27 -0
- package/dist-package/components/ui/scroll-area.cjs +1 -0
- package/dist-package/components/ui/scroll-area.js +25 -0
- package/dist-package/components/ui/select.cjs +1 -0
- package/dist-package/components/ui/select.js +23 -0
- package/dist-package/components/ui/separator.cjs +1 -0
- package/dist-package/components/ui/separator.js +17 -0
- package/dist-package/components/ui/sheet.cjs +1 -0
- package/dist-package/components/ui/sheet.js +86 -0
- package/dist-package/components/ui/sidebar.cjs +1 -0
- package/dist-package/components/ui/sidebar.js +350 -0
- package/dist-package/components/ui/skeleton.cjs +1 -0
- package/dist-package/components/ui/skeleton.js +12 -0
- package/dist-package/components/ui/slider.cjs +1 -0
- package/dist-package/components/ui/slider.js +36 -0
- package/dist-package/components/ui/switch.cjs +1 -0
- package/dist-package/components/ui/switch.js +14 -0
- package/dist-package/components/ui/table.cjs +1 -0
- package/dist-package/components/ui/table.js +66 -0
- package/dist-package/components/ui/tabs.cjs +1 -0
- package/dist-package/components/ui/tabs.js +47 -0
- package/dist-package/components/ui/tag-variants.cjs +1 -0
- package/dist-package/components/ui/tag-variants.js +15 -0
- package/dist-package/components/ui/tag.cjs +1 -0
- package/dist-package/components/ui/tag.js +31 -0
- package/dist-package/components/ui/textarea.cjs +1 -0
- package/dist-package/components/ui/textarea.js +13 -0
- package/dist-package/components/ui/time-input.cjs +1 -0
- package/dist-package/components/ui/time-input.js +89 -0
- package/dist-package/components/ui/tooltip.cjs +1 -0
- package/dist-package/components/ui/tooltip.js +35 -0
- package/dist-package/hooks/use-mobile.cjs +1 -0
- package/dist-package/hooks/use-mobile.js +11 -0
- package/dist-package/lib/dialog-focus.cjs +1 -0
- package/dist-package/lib/dialog-focus.js +10 -0
- package/dist-package/lib/metrics.cjs +1 -0
- package/dist-package/lib/metrics.d.ts +18 -0
- package/dist-package/lib/metrics.d.ts.map +1 -0
- package/dist-package/lib/metrics.js +22 -0
- package/dist-package/lib/pager.cjs +1 -0
- package/dist-package/lib/pager.d.ts +8 -0
- package/dist-package/lib/pager.d.ts.map +1 -0
- package/dist-package/lib/pager.js +18 -0
- package/dist-package/lib/password.cjs +1 -0
- package/dist-package/lib/password.d.ts +14 -0
- package/dist-package/lib/password.d.ts.map +1 -0
- package/dist-package/lib/password.js +34 -0
- package/dist-package/lib/presets.cjs +1 -0
- package/dist-package/lib/presets.d.ts +25 -0
- package/dist-package/lib/presets.d.ts.map +1 -0
- package/dist-package/lib/presets.js +48 -0
- package/dist-package/lib/range.cjs +1 -0
- package/dist-package/lib/range.js +57 -0
- package/dist-package/lib/storage-key.cjs +1 -0
- package/dist-package/lib/storage-key.d.ts +2 -0
- package/dist-package/lib/storage-key.d.ts.map +1 -0
- package/dist-package/lib/storage-key.js +6 -0
- package/dist-package/lib/table-prefs.cjs +1 -0
- package/dist-package/lib/table-prefs.d.ts +17 -0
- package/dist-package/lib/table-prefs.d.ts.map +1 -0
- package/dist-package/lib/table-prefs.js +64 -0
- package/dist-package/lib/tree.cjs +1 -0
- package/dist-package/lib/tree.d.ts +37 -0
- package/dist-package/lib/tree.d.ts.map +1 -0
- package/dist-package/lib/tree.js +57 -0
- package/dist-package/lib/use-ui-translation.cjs +1 -0
- package/dist-package/lib/use-ui-translation.d.ts +15 -0
- package/dist-package/lib/use-ui-translation.d.ts.map +1 -0
- package/dist-package/lib/use-ui-translation.js +65 -0
- package/dist-package/lib/utils.cjs +1 -0
- package/dist-package/lib/utils.js +8 -0
- package/dist-package/styles.css +1 -1
- package/package.json +25 -15
- package/dist-package/index.js +0 -12212
|
@@ -0,0 +1,377 @@
|
|
|
1
|
+
import { cn as e } from "../lib/utils.js";
|
|
2
|
+
import { Button as t } from "./ui/button.js";
|
|
3
|
+
import { useUiTranslation as n } from "../lib/use-ui-translation.js";
|
|
4
|
+
import { DropdownMenu as r, DropdownMenuCheckboxItem as i, DropdownMenuContent as a, DropdownMenuItem as ee, DropdownMenuLabel as te, DropdownMenuSeparator as o, DropdownMenuTrigger as s } from "./ui/dropdown-menu.js";
|
|
5
|
+
import { Skeleton as c } from "./ui/skeleton.js";
|
|
6
|
+
import { TooltipProvider as l } from "./ui/tooltip.js";
|
|
7
|
+
import { Table as u, TableBody as d, TableCaption as f, TableCell as p, TableHead as ne, TableHeader as m, TableRow as h } from "./ui/table.js";
|
|
8
|
+
import { TableToolbar as g } from "./table-toolbar.js";
|
|
9
|
+
import { TableCellOverflow as _ } from "./table-cell-overflow.js";
|
|
10
|
+
import { readColumnOrder as v, readColumnSizes as y, registerTableReset as b, resetTableLayout as x, writeColumnOrder as re, writeColumnSizes as ie } from "../lib/table-prefs.js";
|
|
11
|
+
import { EmptyState as S } from "./page.js";
|
|
12
|
+
import { Fragment as ae, useEffect as C, useLayoutEffect as oe, useRef as w, useState as T } from "react";
|
|
13
|
+
import { ArrowDown as se, ArrowUp as ce, ArrowUpDown as le, ChevronRight as ue, Columns3 as de, GripVertical as fe, RotateCcw as pe } from "lucide-react";
|
|
14
|
+
import { jsx as E, jsxs as D } from "react/jsx-runtime";
|
|
15
|
+
import { flexRender as O, getCoreRowModel as me, getSortedRowModel as he, useReactTable as ge } from "@tanstack/react-table";
|
|
16
|
+
//#region src/components/data-table.tsx
|
|
17
|
+
var _e = "a, button, input, select, textarea, label, [role=\"menuitem\"], [role=\"checkbox\"], [role=\"switch\"], [contenteditable=\"true\"]", ve = {
|
|
18
|
+
compact: "px-4 py-2",
|
|
19
|
+
default: "px-4 py-3",
|
|
20
|
+
relaxed: "px-4 py-4"
|
|
21
|
+
};
|
|
22
|
+
function ye(e, t, n) {
|
|
23
|
+
let r = e.indexOf(t), i = e.indexOf(n);
|
|
24
|
+
if (r < 0 || i < 0 || r === i) return e;
|
|
25
|
+
let a = [...e];
|
|
26
|
+
return a.splice(r, 1), a.splice(i, 0, t), a;
|
|
27
|
+
}
|
|
28
|
+
function be({ columns: c, visibility: l, onVisibilityChange: u, order: d, onOrderChange: f, pinned: p, storageId: ne }) {
|
|
29
|
+
let { t: m } = n(), [h, g] = T(), [_, v] = T(), y = c.map((e) => e.id ?? ("accessorKey" in e ? String(e.accessorKey) : String(e.header ?? ""))).filter(Boolean), b = d?.length ? d : y, re = p?.first ? y[0] : void 0, ie = p?.last ? y[y.length - 1] : void 0, S = (e) => !!f && e !== re && e !== ie, ae = c.filter((e) => e.id !== "select" && e.id !== "actions").map((e) => ({
|
|
30
|
+
id: e.id ?? ("accessorKey" in e ? String(e.accessorKey) : String(e.header ?? "")),
|
|
31
|
+
label: typeof e.header == "string" ? e.header : e.id ?? ("accessorKey" in e ? String(e.accessorKey) : "")
|
|
32
|
+
})).sort((e, t) => b.indexOf(e.id) - b.indexOf(t.id)), C = (e) => {
|
|
33
|
+
if (!h || h === e) return;
|
|
34
|
+
let t = b.indexOf(h), n = b.indexOf(e);
|
|
35
|
+
if (!(t < 0 || n < 0)) return t < n ? "after" : "before";
|
|
36
|
+
};
|
|
37
|
+
return /* @__PURE__ */ D(r, { children: [/* @__PURE__ */ E(s, {
|
|
38
|
+
asChild: !0,
|
|
39
|
+
children: /* @__PURE__ */ D(t, {
|
|
40
|
+
variant: "outline",
|
|
41
|
+
children: [/* @__PURE__ */ E(de, { "aria-hidden": "true" }), m("columns")]
|
|
42
|
+
})
|
|
43
|
+
}), /* @__PURE__ */ D(a, {
|
|
44
|
+
align: "end",
|
|
45
|
+
className: "w-52",
|
|
46
|
+
children: [
|
|
47
|
+
/* @__PURE__ */ E(te, { children: m("columnsHint") }),
|
|
48
|
+
/* @__PURE__ */ E(o, {}),
|
|
49
|
+
ae.map((t) => /* @__PURE__ */ D(i, {
|
|
50
|
+
indicator: "trailing",
|
|
51
|
+
draggable: S(t.id),
|
|
52
|
+
className: e(h === t.id && "opacity-60", _ === t.id && C(t.id) === "before" && "shadow-[inset_0_2px_0_0_var(--primary)]", _ === t.id && C(t.id) === "after" && "shadow-[inset_0_-2px_0_0_var(--primary)]"),
|
|
53
|
+
onDragStart: (e) => {
|
|
54
|
+
if (!S(t.id)) {
|
|
55
|
+
e.preventDefault();
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
g(t.id), e.dataTransfer.effectAllowed = "move", e.dataTransfer.setData("text/plain", t.id);
|
|
59
|
+
},
|
|
60
|
+
onDragOver: (e) => {
|
|
61
|
+
h && h !== t.id && S(t.id) && (e.preventDefault(), e.dataTransfer.dropEffect = "move", v(t.id));
|
|
62
|
+
},
|
|
63
|
+
onDragLeave: () => v((e) => e === t.id ? void 0 : e),
|
|
64
|
+
onDrop: (e) => {
|
|
65
|
+
e.preventDefault();
|
|
66
|
+
let n = h ?? e.dataTransfer.getData("text/plain");
|
|
67
|
+
n && n !== t.id && f?.(ye(b, n, t.id)), g(void 0), v(void 0);
|
|
68
|
+
},
|
|
69
|
+
onDragEnd: () => {
|
|
70
|
+
g(void 0), v(void 0);
|
|
71
|
+
},
|
|
72
|
+
checked: l[t.id] !== !1,
|
|
73
|
+
onSelect: (e) => e.preventDefault(),
|
|
74
|
+
onCheckedChange: (e) => u({
|
|
75
|
+
...l,
|
|
76
|
+
[t.id]: e
|
|
77
|
+
}),
|
|
78
|
+
children: [/* @__PURE__ */ E(fe, {
|
|
79
|
+
"aria-hidden": "true",
|
|
80
|
+
className: "size-3.5 shrink-0 cursor-grab text-muted-foreground/60"
|
|
81
|
+
}), /* @__PURE__ */ E("span", {
|
|
82
|
+
className: "min-w-0 flex-1 truncate",
|
|
83
|
+
children: t.label
|
|
84
|
+
})]
|
|
85
|
+
}, t.id)),
|
|
86
|
+
/* @__PURE__ */ E(o, {}),
|
|
87
|
+
/* @__PURE__ */ D(ee, {
|
|
88
|
+
onSelect: () => {
|
|
89
|
+
u({}), x(ne);
|
|
90
|
+
},
|
|
91
|
+
children: [/* @__PURE__ */ E(pe, { "aria-hidden": "true" }), m("columnsReset")]
|
|
92
|
+
})
|
|
93
|
+
]
|
|
94
|
+
})] });
|
|
95
|
+
}
|
|
96
|
+
function k({ data: r, columns: i, caption: a, loading: ee, emptyTitle: te, emptyDescription: o, footer: s, toolbar: x, striped: de = !0, sortable: fe = !1, defaultSorting: pe = [], density: be = "default", onRowClick: k, columnVisibility: xe, onColumnVisibilityChange: Se, columnOrder: Ce, onColumnOrderChange: we, columnSizes: Te, onColumnSizesChange: Ee, pinned: De, storageId: A, expandable: j, virtual: M }) {
|
|
97
|
+
let { t: N } = n(), Oe = w(null), P = w(null), [F, ke] = T(0), [Ae, je] = T(240), [Me, Ne] = T(() => y(A)), I = Te ?? Me, L = (e) => {
|
|
98
|
+
let t = typeof e == "function" ? e(I) : e;
|
|
99
|
+
(Ee ?? Ne)(t);
|
|
100
|
+
}, [Pe, Fe] = T(() => v(A)), [R, z] = T(), [Ie, B] = T(), [V, Le] = T(() => /* @__PURE__ */ new Set()), [Re, ze] = T(0), [Be, Ve] = T();
|
|
101
|
+
C(() => {
|
|
102
|
+
ie(A, I);
|
|
103
|
+
}, [A, I]);
|
|
104
|
+
let He = Ce ?? Pe, H = we ?? Fe, Ue = i.map((e) => e.id ?? ("accessorKey" in e ? String(e.accessorKey) : "")).filter(Boolean), U = [...He.filter((e) => Ue.includes(e)), ...Ue.filter((e) => !He.includes(e))], We = U.join("|");
|
|
105
|
+
C(() => {
|
|
106
|
+
re(A, U);
|
|
107
|
+
}, [A, We]);
|
|
108
|
+
let Ge = w({
|
|
109
|
+
setSizes: L,
|
|
110
|
+
setOrder: H
|
|
111
|
+
});
|
|
112
|
+
C(() => {
|
|
113
|
+
Ge.current = {
|
|
114
|
+
setSizes: L,
|
|
115
|
+
setOrder: H
|
|
116
|
+
};
|
|
117
|
+
}), C(() => {
|
|
118
|
+
if (A) return b(A, () => {
|
|
119
|
+
Ge.current.setSizes({}), Ge.current.setOrder([]);
|
|
120
|
+
});
|
|
121
|
+
}, [A]);
|
|
122
|
+
let [Ke, qe] = T(pe), [Je, Ye] = T({}), Xe = xe ?? Je, Ze = Se ?? Ye;
|
|
123
|
+
oe(() => {
|
|
124
|
+
let e = Oe.current;
|
|
125
|
+
if (!e) return;
|
|
126
|
+
let t = () => {
|
|
127
|
+
ke(e.clientWidth);
|
|
128
|
+
let t = Array.from(e.querySelectorAll("[data-action-content]"));
|
|
129
|
+
t.length && je(Math.ceil(Math.max(...t.map((e) => e.getBoundingClientRect().width)) + 32));
|
|
130
|
+
};
|
|
131
|
+
t();
|
|
132
|
+
let n = new ResizeObserver(t);
|
|
133
|
+
return n.observe(e), e.querySelectorAll("[data-action-content]").forEach((e) => n.observe(e)), () => n.disconnect();
|
|
134
|
+
}, [r, i]);
|
|
135
|
+
let Qe = ge({
|
|
136
|
+
data: r,
|
|
137
|
+
columns: i,
|
|
138
|
+
getCoreRowModel: me(),
|
|
139
|
+
getSortedRowModel: he(),
|
|
140
|
+
enableSorting: fe,
|
|
141
|
+
enableMultiSort: fe,
|
|
142
|
+
isMultiSortEvent: (e) => typeof e == "object" && e && "shiftKey" in e ? !!e.shiftKey : !1,
|
|
143
|
+
state: {
|
|
144
|
+
sorting: Ke,
|
|
145
|
+
columnVisibility: Xe,
|
|
146
|
+
columnOrder: U
|
|
147
|
+
},
|
|
148
|
+
onSortingChange: qe,
|
|
149
|
+
onColumnOrderChange: (e) => {
|
|
150
|
+
let t = typeof e == "function" ? e(U) : e;
|
|
151
|
+
H(t);
|
|
152
|
+
},
|
|
153
|
+
onColumnVisibilityChange: (e) => {
|
|
154
|
+
let t = typeof e == "function" ? e(Xe) : e;
|
|
155
|
+
Ze(t);
|
|
156
|
+
},
|
|
157
|
+
manualPagination: !0
|
|
158
|
+
}), W = Qe.getRowModel().rows, G = !!M && !j && W.length > 40, K = M?.rowHeight ?? Be ?? 45, $e = M?.height ?? 460, et = M?.overscan ?? 6, q = G ? Math.max(0, Math.floor(Re / K) - et) : 0, tt = G ? Math.min(W.length, q + Math.ceil($e / K) + et * 2) : W.length, J = Qe.getVisibleLeafColumns(), Y = (e) => e === "actions" || e === "action", X = (e) => Y(e) ? Ae : e === "select" ? 56 : 96, nt = new Map(i.filter((e) => e.size !== void 0).map((e) => [e.id ?? ("accessorKey" in e ? String(e.accessorKey).replaceAll(".", "_") : typeof e.header == "string" ? e.header : ""), e.size])), Z = J.filter((e) => I[e.id] === void 0 && !Y(e.id) && e.id !== "select" && !nt.has(e.id)), rt = J.filter((e) => !Z.includes(e)).reduce((e, t) => e + Math.max(X(t.id), I[t.id] ?? nt.get(t.id) ?? X(t.id)), 0), Q = Object.fromEntries(J.map((e) => [e.id, Z.includes(e) ? Math.max(X(e.id), (F - rt) / Z.length) : Math.max(X(e.id), I[e.id] ?? nt.get(e.id) ?? X(e.id))])), it = Object.values(Q).reduce((e, t) => e + t, 0);
|
|
159
|
+
if (it < F) {
|
|
160
|
+
let e = J.filter((e) => !Y(e.id) && e.id !== "select"), t = e.length ? e : J;
|
|
161
|
+
for (let e of t) Q[e.id] = (Q[e.id] ?? 0) + (F - it) / t.length;
|
|
162
|
+
}
|
|
163
|
+
let at = Object.values(Q).reduce((e, t) => e + t, 0);
|
|
164
|
+
function ot(e, t, n) {
|
|
165
|
+
L((r) => ({
|
|
166
|
+
...r,
|
|
167
|
+
[e]: Math.min(n, Math.max(X(e), t))
|
|
168
|
+
}));
|
|
169
|
+
}
|
|
170
|
+
let st = i.some((e) => e.id === "select"), ct = De?.first ? i[0] : void 0, lt = De?.last ? i[i.length - 1] : void 0, ut = (e) => e.id ?? ("accessorKey" in e ? String(e.accessorKey) : void 0), dt = ct ? ut(ct) : void 0, ft = lt ? ut(lt) : void 0, pt = (e) => e === dt ? "sticky left-0 z-10 bg-card shadow-[1px_0_0_0_var(--border)]" : e === ft ? "sticky right-0 z-10 bg-card shadow-[-1px_0_0_0_var(--border)]" : void 0, $ = (e) => !Y(e) && e !== "select" && e !== dt && e !== ft, mt = (e) => {
|
|
171
|
+
if (!R || R === e) return;
|
|
172
|
+
let t = U.indexOf(R), n = U.indexOf(e);
|
|
173
|
+
if (!(t < 0 || n < 0)) return t < n ? "after" : "before";
|
|
174
|
+
};
|
|
175
|
+
return /* @__PURE__ */ D(l, {
|
|
176
|
+
delayDuration: 250,
|
|
177
|
+
children: [x && /* @__PURE__ */ E(g, { children: x }), /* @__PURE__ */ D("div", {
|
|
178
|
+
ref: Oe,
|
|
179
|
+
className: "data-table flex flex-col overflow-hidden rounded-lg border border-table-border bg-card",
|
|
180
|
+
children: [/* @__PURE__ */ E("div", {
|
|
181
|
+
"data-slot": "table-scroll",
|
|
182
|
+
className: e(G && "overflow-auto overscroll-contain", "[&_[data-slot=table-container]]:overflow-visible", "[&_[data-slot=table-header]]:sticky [&_[data-slot=table-header]]:top-0 [&_[data-slot=table-header]]:z-10", "[&_[data-slot=table-header]]:bg-table-header"),
|
|
183
|
+
style: G ? { maxHeight: $e } : void 0,
|
|
184
|
+
onScroll: (e) => {
|
|
185
|
+
G && ze(e.currentTarget.scrollTop);
|
|
186
|
+
},
|
|
187
|
+
ref: (e) => {
|
|
188
|
+
if (!e || !G || M?.rowHeight) return;
|
|
189
|
+
let t = e.querySelector("tbody tr[data-row]")?.getBoundingClientRect().height;
|
|
190
|
+
t && Math.abs(t - (Be ?? 0)) > 1 && Ve(t);
|
|
191
|
+
},
|
|
192
|
+
children: /* @__PURE__ */ D(u, {
|
|
193
|
+
"data-striped": de,
|
|
194
|
+
"aria-busy": !!ee,
|
|
195
|
+
className: "table-fixed",
|
|
196
|
+
style: { width: at },
|
|
197
|
+
children: [
|
|
198
|
+
/* @__PURE__ */ E("colgroup", { children: J.map((e) => /* @__PURE__ */ E("col", { style: { width: Q[e.id] } }, e.id)) }),
|
|
199
|
+
/* @__PURE__ */ E(f, {
|
|
200
|
+
className: "sr-only",
|
|
201
|
+
children: a
|
|
202
|
+
}),
|
|
203
|
+
/* @__PURE__ */ E(m, { children: Qe.getHeaderGroups().map((t) => /* @__PURE__ */ E(h, {
|
|
204
|
+
className: "bg-table-header hover:bg-table-header focus-within:bg-table-header",
|
|
205
|
+
children: t.headers.map((t) => /* @__PURE__ */ D(ne, {
|
|
206
|
+
draggable: $(t.column.id),
|
|
207
|
+
title: $(t.column.id) ? N("columnDragHint") : void 0,
|
|
208
|
+
onDragStart: (e) => {
|
|
209
|
+
if (!$(t.column.id) || e.target.closest("[role=\"separator\"]")) {
|
|
210
|
+
e.preventDefault();
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
z(t.column.id), e.dataTransfer.effectAllowed = "move", e.dataTransfer.setData("text/plain", t.column.id);
|
|
214
|
+
},
|
|
215
|
+
onDragOver: (e) => {
|
|
216
|
+
R && R !== t.column.id && $(t.column.id) && (e.preventDefault(), e.dataTransfer.dropEffect = "move", B(t.column.id));
|
|
217
|
+
},
|
|
218
|
+
onDragLeave: () => B((e) => e === t.column.id ? void 0 : e),
|
|
219
|
+
onDrop: (e) => {
|
|
220
|
+
e.preventDefault();
|
|
221
|
+
let n = R ?? e.dataTransfer.getData("text/plain");
|
|
222
|
+
n && $(t.column.id) && H(ye(U, n, t.column.id)), z(void 0), B(void 0);
|
|
223
|
+
},
|
|
224
|
+
onDragEnd: () => {
|
|
225
|
+
z(void 0), B(void 0);
|
|
226
|
+
},
|
|
227
|
+
className: e("relative h-10 px-4 text-sm font-medium text-muted-foreground", pt(t.column.id)?.replace("bg-card", "bg-table-header"), $(t.column.id) && "cursor-grab", R === t.column.id && "cursor-grabbing opacity-60", Ie === t.column.id && mt(t.column.id) === "before" && "bg-primary/5 shadow-[inset_2px_0_0_0_var(--primary)]", Ie === t.column.id && mt(t.column.id) === "after" && "bg-primary/5 shadow-[inset_-2px_0_0_0_var(--primary)]"),
|
|
228
|
+
colSpan: t.colSpan,
|
|
229
|
+
children: [/* @__PURE__ */ E("div", {
|
|
230
|
+
className: "truncate",
|
|
231
|
+
children: t.isPlaceholder ? null : t.column.getCanSort() ? /* @__PURE__ */ D("button", {
|
|
232
|
+
type: "button",
|
|
233
|
+
"aria-label": t.column.getIsSorted() === "asc" ? N("sortDesc") : N("sortAsc"),
|
|
234
|
+
className: "-mx-1 inline-flex items-center gap-1 rounded px-1 hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring/40 focus-visible:outline-none",
|
|
235
|
+
onClick: t.column.getToggleSortingHandler(),
|
|
236
|
+
children: [
|
|
237
|
+
O(t.column.columnDef.header, t.getContext()),
|
|
238
|
+
t.column.getIsSorted() === "asc" ? /* @__PURE__ */ E(ce, {
|
|
239
|
+
"aria-hidden": "true",
|
|
240
|
+
className: "size-3.5 text-primary"
|
|
241
|
+
}) : t.column.getIsSorted() === "desc" ? /* @__PURE__ */ E(se, {
|
|
242
|
+
"aria-hidden": "true",
|
|
243
|
+
className: "size-3.5 text-primary"
|
|
244
|
+
}) : /* @__PURE__ */ E(le, {
|
|
245
|
+
"aria-hidden": "true",
|
|
246
|
+
className: "size-3.5 opacity-40"
|
|
247
|
+
}),
|
|
248
|
+
Ke.length > 1 && t.column.getSortIndex() >= 0 && /* @__PURE__ */ E("span", {
|
|
249
|
+
className: "rounded bg-primary/15 px-1 text-[10px] tabular-nums text-primary",
|
|
250
|
+
children: t.column.getSortIndex() + 1
|
|
251
|
+
})
|
|
252
|
+
]
|
|
253
|
+
}) : O(t.column.columnDef.header, t.getContext())
|
|
254
|
+
}), !t.isPlaceholder && t.subHeaders.length === 0 && t.column.getCanResize() && t.column.id !== "select" && /* @__PURE__ */ E("div", {
|
|
255
|
+
role: "separator",
|
|
256
|
+
"aria-orientation": "vertical",
|
|
257
|
+
"aria-label": N("tableResize", { column: typeof t.column.columnDef.header == "string" ? t.column.columnDef.header : t.column.id }),
|
|
258
|
+
"aria-valuemin": X(t.column.id),
|
|
259
|
+
"aria-valuemax": Math.max(X(t.column.id), t.column.columnDef.maxSize ?? 2 ** 53 - 1),
|
|
260
|
+
"aria-valuenow": Math.round(Q[t.column.id] ?? X(t.column.id)),
|
|
261
|
+
tabIndex: 0,
|
|
262
|
+
className: "absolute right-0 top-0 h-full w-2 touch-none cursor-col-resize select-none border-r border-transparent hover:border-primary/40 hover:bg-primary/10 focus:bg-primary/10 focus:outline-none",
|
|
263
|
+
onPointerDown: (e) => {
|
|
264
|
+
e.preventDefault(), e.currentTarget.setPointerCapture(e.pointerId), P.current = {
|
|
265
|
+
id: t.column.id,
|
|
266
|
+
x: e.clientX,
|
|
267
|
+
width: Q[t.column.id] ?? X(t.column.id)
|
|
268
|
+
};
|
|
269
|
+
},
|
|
270
|
+
onPointerMove: (e) => {
|
|
271
|
+
P.current?.id === t.column.id && ot(t.column.id, P.current.width + e.clientX - P.current.x, Math.max(X(t.column.id), t.column.columnDef.maxSize ?? 2 ** 53 - 1));
|
|
272
|
+
},
|
|
273
|
+
onPointerUp: () => {
|
|
274
|
+
P.current = null;
|
|
275
|
+
},
|
|
276
|
+
onPointerCancel: () => {
|
|
277
|
+
P.current = null;
|
|
278
|
+
},
|
|
279
|
+
onDoubleClick: () => L((e) => {
|
|
280
|
+
let n = { ...e };
|
|
281
|
+
return delete n[t.column.id], n;
|
|
282
|
+
}),
|
|
283
|
+
onKeyDown: (e) => {
|
|
284
|
+
(e.key === "ArrowLeft" || e.key === "ArrowRight") && (e.preventDefault(), ot(t.column.id, (Q[t.column.id] ?? X(t.column.id)) + (e.key === "ArrowRight" ? 16 : -16), Math.max(X(t.column.id), t.column.columnDef.maxSize ?? 2 ** 53 - 1)));
|
|
285
|
+
}
|
|
286
|
+
})]
|
|
287
|
+
}, t.id))
|
|
288
|
+
}, t.id)) }),
|
|
289
|
+
/* @__PURE__ */ D(d, { children: [
|
|
290
|
+
G && q > 0 && /* @__PURE__ */ E(h, {
|
|
291
|
+
className: "border-0",
|
|
292
|
+
"aria-hidden": "true",
|
|
293
|
+
children: /* @__PURE__ */ E(p, {
|
|
294
|
+
colSpan: J.length,
|
|
295
|
+
className: "p-0",
|
|
296
|
+
style: { height: q * K }
|
|
297
|
+
})
|
|
298
|
+
}),
|
|
299
|
+
ee ? Array.from({ length: 4 }, (e, t) => /* @__PURE__ */ E(h, { children: i.map((e, t) => /* @__PURE__ */ E(p, {
|
|
300
|
+
className: "px-4 py-3",
|
|
301
|
+
children: /* @__PURE__ */ E(c, { className: "h-4 w-24" })
|
|
302
|
+
}, t)) }, t)) : W.length ? W.slice(q, tt).map((n) => /* @__PURE__ */ D(ae, { children: [/* @__PURE__ */ E(h, {
|
|
303
|
+
"data-row": "",
|
|
304
|
+
"data-clickable": k ? !0 : void 0,
|
|
305
|
+
className: e(de && n.index % 2 == 1 && "bg-table-stripe", k && "cursor-pointer"),
|
|
306
|
+
onClick: k ? (e) => {
|
|
307
|
+
e.target.closest(_e) || k(n.original);
|
|
308
|
+
} : void 0,
|
|
309
|
+
children: n.getVisibleCells().map((r, i) => /* @__PURE__ */ E(p, {
|
|
310
|
+
className: e(ve[be], pt(r.column.id)),
|
|
311
|
+
children: Y(r.column.id) ? /* @__PURE__ */ E("div", {
|
|
312
|
+
"data-action-content": !0,
|
|
313
|
+
className: "w-max",
|
|
314
|
+
children: O(r.column.columnDef.cell, r.getContext())
|
|
315
|
+
}) : r.column.id === "select" ? O(r.column.columnDef.cell, r.getContext()) : i === +!!st && j ? /* @__PURE__ */ D("div", {
|
|
316
|
+
className: "flex min-w-0 items-center gap-1.5",
|
|
317
|
+
children: [/* @__PURE__ */ E(t, {
|
|
318
|
+
type: "button",
|
|
319
|
+
variant: "ghost",
|
|
320
|
+
size: "icon-xs",
|
|
321
|
+
"aria-expanded": V.has(n.id),
|
|
322
|
+
"aria-label": N(V.has(n.id) ? "collapseRow" : "expandRow"),
|
|
323
|
+
onClick: () => {
|
|
324
|
+
Le((e) => {
|
|
325
|
+
let t = new Set(e);
|
|
326
|
+
return t.has(n.id) ? t.delete(n.id) : t.add(n.id), t;
|
|
327
|
+
});
|
|
328
|
+
},
|
|
329
|
+
children: /* @__PURE__ */ E(ue, {
|
|
330
|
+
"aria-hidden": "true",
|
|
331
|
+
className: e("size-3.5 transition-transform", V.has(n.id) && "rotate-90")
|
|
332
|
+
})
|
|
333
|
+
}), /* @__PURE__ */ E("span", {
|
|
334
|
+
className: "min-w-0 flex-1",
|
|
335
|
+
children: O(r.column.columnDef.cell, r.getContext())
|
|
336
|
+
})]
|
|
337
|
+
}) : /* @__PURE__ */ E(_, { children: O(r.column.columnDef.cell, r.getContext()) })
|
|
338
|
+
}, r.id))
|
|
339
|
+
}, n.id), j && V.has(n.id) && /* @__PURE__ */ E(h, {
|
|
340
|
+
className: "bg-muted/30 hover:bg-muted/30",
|
|
341
|
+
children: /* @__PURE__ */ E(p, {
|
|
342
|
+
colSpan: J.length,
|
|
343
|
+
className: "px-4 py-3",
|
|
344
|
+
children: j.content(n.original)
|
|
345
|
+
})
|
|
346
|
+
}, `${n.id}-detail`)] }, n.id)) : /* @__PURE__ */ E(h, {
|
|
347
|
+
className: "hover:bg-transparent focus-within:bg-transparent",
|
|
348
|
+
children: /* @__PURE__ */ E(p, {
|
|
349
|
+
colSpan: i.length,
|
|
350
|
+
className: "whitespace-normal",
|
|
351
|
+
children: /* @__PURE__ */ E(S, {
|
|
352
|
+
title: te,
|
|
353
|
+
description: o
|
|
354
|
+
})
|
|
355
|
+
})
|
|
356
|
+
}),
|
|
357
|
+
G && tt < W.length && /* @__PURE__ */ E(h, {
|
|
358
|
+
className: "border-0",
|
|
359
|
+
"aria-hidden": "true",
|
|
360
|
+
children: /* @__PURE__ */ E(p, {
|
|
361
|
+
colSpan: J.length,
|
|
362
|
+
className: "p-0",
|
|
363
|
+
style: { height: (W.length - tt) * K }
|
|
364
|
+
})
|
|
365
|
+
})
|
|
366
|
+
] })
|
|
367
|
+
]
|
|
368
|
+
})
|
|
369
|
+
}), s && /* @__PURE__ */ E("div", {
|
|
370
|
+
className: "mt-auto flex flex-wrap items-center justify-between gap-3 border-t border-table-border px-4 py-3 [&>div:only-child]:w-full [&>div:only-child]:p-0",
|
|
371
|
+
children: s
|
|
372
|
+
})]
|
|
373
|
+
})]
|
|
374
|
+
});
|
|
375
|
+
}
|
|
376
|
+
//#endregion
|
|
377
|
+
export { be as ColumnManager, k as DataTable };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const e=require("../lib/utils.cjs");let t=require("react"),n=require("react/jsx-runtime");function r({items:r,columns:i=2,bordered:a=!1,className:o}){return(0,n.jsx)(`dl`,{"data-slot":`descriptions`,className:e.cn(`grid text-sm`,i===1&&`grid-cols-1`,i===2&&`grid-cols-1 sm:grid-cols-2`,i===3&&`grid-cols-1 sm:grid-cols-2 xl:grid-cols-3`,a?`overflow-hidden rounded-lg border`:`gap-x-8 gap-y-4`,o),children:r.map(r=>(0,n.jsx)(t.Fragment,{children:(0,n.jsx)(`div`,{className:e.cn(`min-w-0`,r.span===2&&`sm:col-span-2`,r.span===3&&`sm:col-span-2 xl:col-span-3`,a&&`grid grid-cols-[7rem_minmax(0,1fr)] border-b last:border-b-0`),children:a?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(`dt`,{className:`bg-muted/40 px-4 py-3 text-muted-foreground`,children:r.label}),(0,n.jsx)(`dd`,{className:`min-w-0 px-4 py-3`,children:r.value})]}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(`dt`,{className:`text-xs text-muted-foreground`,children:r.label}),(0,n.jsx)(`dd`,{className:`mt-1 min-w-0`,children:r.value})]})})},r.key))})}exports.Descriptions=r;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type ReactNode } from 'react';
|
|
2
|
+
export type DescriptionItem = {
|
|
3
|
+
key: string;
|
|
4
|
+
label: ReactNode;
|
|
5
|
+
value: ReactNode;
|
|
6
|
+
/** 跨列展示,适合备注、地址这类长内容。 */
|
|
7
|
+
span?: 1 | 2 | 3;
|
|
8
|
+
};
|
|
9
|
+
/** 详情键值列表。 */
|
|
10
|
+
export declare function Descriptions({ items, columns, bordered, className, }: {
|
|
11
|
+
items: DescriptionItem[];
|
|
12
|
+
columns?: 1 | 2 | 3;
|
|
13
|
+
bordered?: boolean;
|
|
14
|
+
className?: string;
|
|
15
|
+
}): import("react").JSX.Element;
|
|
16
|
+
//# sourceMappingURL=descriptions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"descriptions.d.ts","sourceRoot":"","sources":["../../src/components/descriptions.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAY,KAAK,SAAS,EAAE,MAAM,OAAO,CAAA;AAGhD,MAAM,MAAM,eAAe,GAAG;IAC5B,GAAG,EAAE,MAAM,CAAA;IACX,KAAK,EAAE,SAAS,CAAA;IAChB,KAAK,EAAE,SAAS,CAAA;IAChB,yBAAyB;IACzB,IAAI,CAAC,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;CACjB,CAAA;AAED,cAAc;AACd,wBAAgB,YAAY,CAAC,EAC3B,KAAK,EACL,OAAW,EACX,QAAgB,EAChB,SAAS,GACV,EAAE;IACD,KAAK,EAAE,eAAe,EAAE,CAAA;IACxB,OAAO,CAAC,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;IACnB,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB,+BAuCA"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { cn as e } from "../lib/utils.js";
|
|
2
|
+
import { Fragment as t } from "react";
|
|
3
|
+
import { Fragment as n, jsx as r, jsxs as i } from "react/jsx-runtime";
|
|
4
|
+
//#region src/components/descriptions.tsx
|
|
5
|
+
function a({ items: a, columns: o = 2, bordered: s = !1, className: c }) {
|
|
6
|
+
return /* @__PURE__ */ r("dl", {
|
|
7
|
+
"data-slot": "descriptions",
|
|
8
|
+
className: e("grid text-sm", o === 1 && "grid-cols-1", o === 2 && "grid-cols-1 sm:grid-cols-2", o === 3 && "grid-cols-1 sm:grid-cols-2 xl:grid-cols-3", s ? "overflow-hidden rounded-lg border" : "gap-x-8 gap-y-4", c),
|
|
9
|
+
children: a.map((a) => /* @__PURE__ */ r(t, { children: /* @__PURE__ */ r("div", {
|
|
10
|
+
className: e("min-w-0", a.span === 2 && "sm:col-span-2", a.span === 3 && "sm:col-span-2 xl:col-span-3", s && "grid grid-cols-[7rem_minmax(0,1fr)] border-b last:border-b-0"),
|
|
11
|
+
children: s ? /* @__PURE__ */ i(n, { children: [/* @__PURE__ */ r("dt", {
|
|
12
|
+
className: "bg-muted/40 px-4 py-3 text-muted-foreground",
|
|
13
|
+
children: a.label
|
|
14
|
+
}), /* @__PURE__ */ r("dd", {
|
|
15
|
+
className: "min-w-0 px-4 py-3",
|
|
16
|
+
children: a.value
|
|
17
|
+
})] }) : /* @__PURE__ */ i(n, { children: [/* @__PURE__ */ r("dt", {
|
|
18
|
+
className: "text-xs text-muted-foreground",
|
|
19
|
+
children: a.label
|
|
20
|
+
}), /* @__PURE__ */ r("dd", {
|
|
21
|
+
className: "mt-1 min-w-0",
|
|
22
|
+
children: a.value
|
|
23
|
+
})] })
|
|
24
|
+
}) }, a.key))
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
//#endregion
|
|
28
|
+
export { a as Descriptions };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const e=require("../lib/utils.cjs"),t=require("./ui/button.cjs"),n=require("../lib/use-ui-translation.cjs"),r=require("./ui/input.cjs"),i=require("./ui/native-select.cjs"),a=require("./ui/switch.cjs"),o=require("./ui/table.cjs");let s=require("react"),c=require("lucide-react"),l=require("react/jsx-runtime");function u({id:e,column:t,index:o,value:s,onChange:c}){let{t:u}=n.useUiTranslation(),d=u(`editableTable.cellLabel`,{column:t.label,index:o+1});switch(t.type){case`select`:return(0,l.jsxs)(i.NativeSelect,{id:e,"aria-label":d,value:s,onChange:e=>c(e.target.value),children:[(0,l.jsx)(`option`,{value:``,children:u(`editableTable.emptyCell`)}),t.options?.map(e=>(0,l.jsx)(`option`,{value:e.value,children:e.label},e.value))]});case`switch`:return(0,l.jsx)(a.Switch,{id:e,"aria-label":d,checked:s===`true`,onCheckedChange:e=>c(e?`true`:`false`)});case`date`:case`number`:return(0,l.jsx)(r.Input,{id:e,type:t.type,className:`h-9`,"aria-label":d,placeholder:t.placeholder,value:s,onChange:e=>c(e.target.value)});default:return(0,l.jsx)(r.Input,{id:e,className:`h-9`,"aria-label":d,placeholder:t.placeholder,value:s,onChange:e=>c(e.target.value)})}}function d({column:t,value:r}){let{t:i}=n.useUiTranslation();if(t.type===`switch`)return(0,l.jsx)(`span`,{className:e.cn(`text-sm`,r!==`true`&&`text-muted-foreground`),children:i(r===`true`?`editableTable.on`:`editableTable.off`)});let a=t.type===`select`?t.options?.find(e=>e.value===r)?.label:r;return(0,l.jsx)(`span`,{className:e.cn(!a&&`text-muted-foreground`),children:a||i(`editableTable.emptyCell`)})}function f({columns:r,defaultRows:i=[],onChange:a,maxRows:f,stickyActions:p=!0,className:m}){let{t:h}=n.useUiTranslation(),[g,_]=(0,s.useState)(()=>i.map(e=>({...e,editing:!1,draft:e.values,isNew:!1}))),v=(0,s.useRef)(0),y=(0,s.useRef)(null);(0,s.useEffect)(()=>{if(!y.current)return;let e=r[0],t=e?document.getElementById(`${y.current}-${e.key}`):null;y.current=null,t instanceof HTMLInputElement&&t.focus()});function b(e){_(e),a?.(e.map(({id:e,values:t})=>({id:e,values:t})))}function x(){v.current+=1;let e=`new-${v.current}`;y.current=e,b([...g,{id:e,values:{},draft:{},editing:!0,isNew:!0}])}function S(e){b(g.map(t=>t.id===e?{...t,editing:!0,draft:t.values}:t))}function C(e){b(g.map(t=>t.id===e?{...t,editing:!1,values:t.draft,isNew:!1}:t))}function w(e){if(g.find(t=>t.id===e)?.isNew){b(g.filter(t=>t.id!==e));return}b(g.map(t=>t.id===e?{...t,editing:!1,draft:t.values}:t))}function T(e){b(g.filter(t=>t.id!==e))}function E(e,t,n){_(r=>r.map(r=>r.id===e?{...r,draft:{...r.draft,[t]:n}}:r))}return(0,l.jsx)(`div`,{className:e.cn(`data-table flex flex-col overflow-hidden rounded-lg border border-table-border bg-card`,`[&>[data-slot=table-container]]:overflow-x-auto`,`[&_[data-slot=table-header]]:sticky [&_[data-slot=table-header]]:top-0 [&_[data-slot=table-header]]:z-10`,f&&`[&>[data-slot=table-container]]:max-h-(--editable-table-max-height)`,m),style:f?{"--editable-table-max-height":`${f*45+45}px`}:void 0,children:(0,l.jsxs)(o.Table,{children:[(0,l.jsx)(o.TableHeader,{children:(0,l.jsxs)(o.TableRow,{children:[r.map(e=>(0,l.jsx)(o.TableHead,{children:e.label},e.key)),(0,l.jsx)(o.TableHead,{className:e.cn(`w-px whitespace-nowrap text-left`,p&&`sticky right-0 z-10 border-l border-table-border bg-table-header`),children:h(`sample.columnActions`)})]})}),(0,l.jsxs)(o.TableBody,{children:[g.map((n,i)=>(0,l.jsxs)(o.TableRow,{className:`group/row`,"data-editing":n.editing||void 0,children:[r.map(e=>(0,l.jsx)(o.TableCell,{className:`align-middle`,children:n.editing?(0,l.jsx)(u,{id:`${n.id}-${e.key}`,column:e,index:i,value:n.draft[e.key]??``,onChange:t=>E(n.id,e.key,t)}):(0,l.jsx)(d,{column:e,value:n.values[e.key]??``})},e.key)),(0,l.jsx)(o.TableCell,{className:e.cn(p&&`sticky right-0 z-10 border-l border-table-border bg-card group-hover/row:bg-table-hover`),children:(0,l.jsx)(`div`,{className:`flex justify-start gap-2`,children:n.editing?(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(t.Button,{type:`button`,size:`icon-sm`,onClick:()=>C(n.id),"aria-label":h(`editableTable.saveRow`,{index:i+1}),title:h(`save`),children:(0,l.jsx)(c.Check,{"aria-hidden":`true`})}),(0,l.jsx)(t.Button,{type:`button`,size:`icon-sm`,variant:`outline`,onClick:()=>w(n.id),"aria-label":h(`editableTable.cancelRow`,{index:i+1}),title:h(`cancel`),children:(0,l.jsx)(c.X,{"aria-hidden":`true`})})]}):(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(t.Button,{type:`button`,size:`icon-sm`,variant:`outline`,onClick:()=>S(n.id),"aria-label":h(`editableTable.editRow`,{index:i+1}),title:h(`editableTable.edit`),children:(0,l.jsx)(c.SquarePen,{"aria-hidden":`true`})}),(0,l.jsx)(t.Button,{type:`button`,size:`icon-sm`,variant:`outline`,className:`border-danger/25 bg-danger-soft text-danger hover:border-danger/40 hover:bg-danger/12 hover:text-danger`,onClick:()=>T(n.id),"aria-label":h(`editableTable.removeRow`,{index:i+1}),title:h(`editableTable.remove`),children:(0,l.jsx)(c.Trash2,{"aria-hidden":`true`})})]})})})]},n.id)),(0,l.jsx)(o.TableRow,{children:(0,l.jsx)(o.TableCell,{colSpan:r.length+1,className:`p-0`,children:(0,l.jsxs)(`button`,{type:`button`,onClick:x,className:`flex h-11 w-full items-center justify-center gap-2 text-sm text-muted-foreground transition-colors hover:bg-accent hover:text-foreground`,children:[(0,l.jsx)(c.Plus,{"aria-hidden":`true`,className:`size-4`}),h(`editableTable.addRow`)]})})})]})]})})}exports.EditableTable=f;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export type EditableTableColumn = {
|
|
2
|
+
key: string;
|
|
3
|
+
label: string;
|
|
4
|
+
/** 行内编辑控件:文本(默认)、数字、日期、下拉、开关。 */
|
|
5
|
+
type?: 'text' | 'number' | 'date' | 'select' | 'switch';
|
|
6
|
+
placeholder?: string;
|
|
7
|
+
/** type=select 时的选项 */
|
|
8
|
+
options?: {
|
|
9
|
+
value: string;
|
|
10
|
+
label: string;
|
|
11
|
+
}[];
|
|
12
|
+
};
|
|
13
|
+
export type EditableTableValue = {
|
|
14
|
+
id: string;
|
|
15
|
+
values: Record<string, string>;
|
|
16
|
+
};
|
|
17
|
+
export declare function EditableTable({ columns, defaultRows, onChange, maxRows, stickyActions, className, }: {
|
|
18
|
+
columns: EditableTableColumn[];
|
|
19
|
+
defaultRows?: EditableTableValue[];
|
|
20
|
+
onChange?: (rows: EditableTableValue[]) => void;
|
|
21
|
+
/** 行数超过这个值时表格内部纵向滚动(表头吸顶)。不传就不限高,不出现纵向滚动条。 */
|
|
22
|
+
maxRows?: number;
|
|
23
|
+
/** 操作列固定在右侧:列多时左侧横向滚动,操作按钮始终可见。默认开启。 */
|
|
24
|
+
stickyActions?: boolean;
|
|
25
|
+
className?: string;
|
|
26
|
+
}): import("react").JSX.Element;
|
|
27
|
+
//# sourceMappingURL=editable-table.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"editable-table.d.ts","sourceRoot":"","sources":["../../src/components/editable-table.tsx"],"names":[],"mappings":"AAiBA,MAAM,MAAM,mBAAmB,GAAG;IAChC,GAAG,EAAE,MAAM,CAAA;IACX,KAAK,EAAE,MAAM,CAAA;IACb,iCAAiC;IACjC,IAAI,CAAC,EAAE,MAAM,GAAG,QAAQ,GAAG,MAAM,GAAG,QAAQ,GAAG,QAAQ,CAAA;IACvD,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,uBAAuB;IACvB,OAAO,CAAC,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,EAAE,CAAA;CAC7C,CAAA;AAED,MAAM,MAAM,kBAAkB,GAAG;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CAAE,CAAA;AAmG/E,wBAAgB,aAAa,CAAC,EAC5B,OAAO,EACP,WAAgB,EAChB,QAAQ,EACR,OAAO,EACP,aAAoB,EACpB,SAAS,GACV,EAAE;IACD,OAAO,EAAE,mBAAmB,EAAE,CAAA;IAC9B,WAAW,CAAC,EAAE,kBAAkB,EAAE,CAAA;IAClC,QAAQ,CAAC,EAAE,CAAC,IAAI,EAAE,kBAAkB,EAAE,KAAK,IAAI,CAAA;IAC/C,8CAA8C;IAC9C,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,wCAAwC;IACxC,aAAa,CAAC,EAAE,OAAO,CAAA;IACvB,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB,+BAkMA"}
|