@wordrhyme/auto-crud 1.23.2 → 1.24.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 +6 -0
- package/dist/index.cjs +357 -185
- package/dist/index.d.cts +24 -1
- package/dist/index.d.ts +24 -1
- package/dist/index.js +358 -186
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { i as positionActions, n as compareOrder, r as matchesPosition, t as actionPositionSchema } from "./position--p6kJnYA.js";
|
|
2
2
|
import * as React from "react";
|
|
3
|
-
import { Fragment, createContext, createElement, forwardRef, useCallback, useContext, useEffect, useId, useImperativeHandle, useMemo, useReducer, useRef, useState, useSyncExternalStore } from "react";
|
|
3
|
+
import { Fragment, createContext, createElement, forwardRef, useCallback, useContext, useEffect, useId, useImperativeHandle, useLayoutEffect, useMemo, useReducer, useRef, useState, useSyncExternalStore } from "react";
|
|
4
4
|
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
5
|
-
import { hashKey, keepPreviousData, useInfiniteQuery, useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
|
5
|
+
import { hashKey, keepPreviousData, replaceEqualDeep, useInfiniteQuery, useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
|
6
6
|
import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, Badge, Button, Calendar, Checkbox, Command, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList, Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, DropdownMenu, DropdownMenuCheckboxItem, DropdownMenuContent, DropdownMenuItem, DropdownMenuLabel, DropdownMenuRadioGroup, DropdownMenuRadioItem, DropdownMenuSeparator, DropdownMenuSub, DropdownMenuSubContent, DropdownMenuSubTrigger, DropdownMenuTrigger, Input, InputGroup, InputGroupAddon, InputGroupButton, InputGroupInput, Label, Popover, PopoverContent, PopoverTrigger, RadioGroup, RadioGroupItem, Select as Select$1, SelectContent, SelectItem, SelectTrigger, SelectValue, Separator, Slider, Switch, Table, TableBody, TableCell, TableHead, TableHeader, TableRow, Textarea, ToggleGroup, ToggleGroupItem, cn as cn$1 } from "@wordrhyme/shadcn";
|
|
7
7
|
import { AppWindow, ArrowDownUp, BadgeCheck, CalendarIcon, Check, CheckCircle2, ChevronDown, ChevronLeft, ChevronRight, ChevronRightIcon, ChevronUp, ChevronsLeft, ChevronsRight, ChevronsRightIcon, ChevronsUpDown, CommandIcon, Copy, Download, Ellipsis, Eye, EyeOff, FileDown, FileSpreadsheetIcon, GripVertical, Info, Layers, List, ListFilter, ListFilterIcon, Loader2, PanelsTopLeft, Pencil, Plus, PlusCircle, RefreshCw, Search, Settings, Settings2, Text, Trash2, Upload, X, XCircle } from "lucide-react";
|
|
8
8
|
import { z } from "zod";
|
|
9
9
|
import { clsx } from "clsx";
|
|
10
10
|
import { twMerge } from "tailwind-merge";
|
|
11
|
+
import { flexRender, getCoreRowModel, getExpandedRowModel, getFacetedMinMaxValues, getFacetedRowModel, getFacetedUniqueValues, getFilteredRowModel, getPaginationRowModel, getSortedRowModel, useReactTable } from "@tanstack/react-table";
|
|
11
12
|
import { ActionBar, ActionBarClose, ActionBarGroup, ActionBarItem, ActionBarSelection, ActionBarSeparator, Faceted, FacetedBadgeList, FacetedContent, FacetedEmpty, FacetedGroup, FacetedInput, FacetedItem, FacetedList, FacetedTrigger, MultiCombobox, Select, Select as Select$2, Sortable, SortableContent, SortableItem, SortableItemHandle, SortableOverlay } from "@wordrhyme/shadcn-ui";
|
|
12
13
|
import { customAlphabet } from "nanoid";
|
|
13
|
-
import { flexRender, getCoreRowModel, getExpandedRowModel, getFacetedMinMaxValues, getFacetedRowModel, getFacetedUniqueValues, getFilteredRowModel, getPaginationRowModel, getSortedRowModel, useReactTable } from "@tanstack/react-table";
|
|
14
14
|
import { AlertDialog as AlertDialog$1, AlertDialogAction as AlertDialogAction$1, AlertDialogCancel as AlertDialogCancel$1, AlertDialogContent as AlertDialogContent$1, AlertDialogDescription as AlertDialogDescription$1, AlertDialogFooter as AlertDialogFooter$1, AlertDialogHeader as AlertDialogHeader$1, AlertDialogTitle as AlertDialogTitle$1, Button as Button$1, Calendar as Calendar$1, Dialog as Dialog$1, DialogContent as DialogContent$1, DialogDescription as DialogDescription$1, DialogHeader as DialogHeader$1, DialogTitle as DialogTitle$1, DropdownMenu as DropdownMenu$1, DropdownMenuContent as DropdownMenuContent$1, DropdownMenuItem as DropdownMenuItem$1, DropdownMenuSeparator as DropdownMenuSeparator$1, DropdownMenuTrigger as DropdownMenuTrigger$1, Popover as Popover$1, PopoverContent as PopoverContent$1, PopoverTrigger as PopoverTrigger$1, Sheet, SheetContent, SheetDescription, SheetHeader, SheetTitle } from "@wordrhyme/ui";
|
|
15
15
|
import { DatePicker, Form, JsonSchemaField, connect, defaultComponentRegistry, mapProps } from "@wordrhyme/formily-shadcn";
|
|
16
16
|
import { createForm } from "@formily/core";
|
|
@@ -236,6 +236,34 @@ const dataTableConfig = {
|
|
|
236
236
|
|
|
237
237
|
//#endregion
|
|
238
238
|
//#region src/lib/data-table.ts
|
|
239
|
+
function readRowId(row, idKey) {
|
|
240
|
+
const value = row[idKey];
|
|
241
|
+
return value === null || value === void 0 ? void 0 : String(value);
|
|
242
|
+
}
|
|
243
|
+
function getSelectedTableRows(table) {
|
|
244
|
+
return table.options.meta?.selectedRows ?? table.getFilteredSelectedRowModel().rows;
|
|
245
|
+
}
|
|
246
|
+
function createRowSelectionScope() {
|
|
247
|
+
const listeners$1 = /* @__PURE__ */ new Set();
|
|
248
|
+
return {
|
|
249
|
+
onDelete(listener) {
|
|
250
|
+
listeners$1.add(listener);
|
|
251
|
+
return () => {
|
|
252
|
+
listeners$1.delete(listener);
|
|
253
|
+
};
|
|
254
|
+
},
|
|
255
|
+
notifyDeleted(row) {
|
|
256
|
+
listeners$1.forEach((listener) => listener(row));
|
|
257
|
+
}
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
/** Infer a total only when the loaded page accounts for the whole result. */
|
|
261
|
+
function getSelectionTotal(table, loadedPageIndex = table.getState().pagination.pageIndex) {
|
|
262
|
+
if (table.options.rowCount !== void 0 || !table.options.manualPagination) return table.getRowCount();
|
|
263
|
+
const pages = table.getPageCount();
|
|
264
|
+
if (pages === 0) return 0;
|
|
265
|
+
if (pages === 1 && loadedPageIndex === 0) return table.getFilteredRowModel().rows.length;
|
|
266
|
+
}
|
|
239
267
|
function getColumnPinningStyle({ column, withBorder = false }) {
|
|
240
268
|
const isPinned = column.getIsPinned();
|
|
241
269
|
const isLastLeftPinnedColumn = isPinned === "left" && column.getIsLastColumn("left");
|
|
@@ -2082,175 +2110,183 @@ function ViewMenu({ resourceId, table, fieldsReady = true, defaultView, presets,
|
|
|
2082
2110
|
className: cn("pointer-events-none absolute inset-x-0 h-1 bg-primary", linePosition === "top" ? "top-0" : "bottom-0", tabs?.classNames?.indicator)
|
|
2083
2111
|
}) : null;
|
|
2084
2112
|
const triggerLabel = display === "tabs" ? "视图设置" : selected === null ? "切换视图" : void 0;
|
|
2113
|
+
const viewActions = selected && /* @__PURE__ */ jsxs(Fragment$1, { children: [canUpdate ? /* @__PURE__ */ jsx(Button, {
|
|
2114
|
+
type: "button",
|
|
2115
|
+
size: "sm",
|
|
2116
|
+
disabled: mutation.isPending,
|
|
2117
|
+
onClick: () => mutation.mutate({
|
|
2118
|
+
operation: "update",
|
|
2119
|
+
input: {
|
|
2120
|
+
name: selected.name,
|
|
2121
|
+
slug: selected.slug,
|
|
2122
|
+
scope: selected.source === "saved" ? selected.scope : void 0,
|
|
2123
|
+
query: current
|
|
2124
|
+
}
|
|
2125
|
+
}),
|
|
2126
|
+
children: "保存修改"
|
|
2127
|
+
}) : canCreate && /* @__PURE__ */ jsx(Button, {
|
|
2128
|
+
type: "button",
|
|
2129
|
+
size: "sm",
|
|
2130
|
+
disabled: mutation.isPending,
|
|
2131
|
+
onClick: () => open("create"),
|
|
2132
|
+
children: "另存为新视图"
|
|
2133
|
+
}), /* @__PURE__ */ jsx(Button, {
|
|
2134
|
+
type: "button",
|
|
2135
|
+
size: "sm",
|
|
2136
|
+
variant: "ghost",
|
|
2137
|
+
disabled: mutation.isPending,
|
|
2138
|
+
onClick: () => select(selected),
|
|
2139
|
+
children: "还原"
|
|
2140
|
+
})] });
|
|
2085
2141
|
return /* @__PURE__ */ jsxs(Fragment$1, { children: [children(/* @__PURE__ */ jsxs("div", {
|
|
2086
2142
|
className: "flex min-w-0 flex-wrap items-center gap-2",
|
|
2087
2143
|
children: [
|
|
2088
2144
|
/* @__PURE__ */ jsxs("div", {
|
|
2089
|
-
className: cn("flex min-w-0 max-w-full items-center gap-1", display === "tabs" && lineTabs && ["relative
|
|
2090
|
-
children: [
|
|
2091
|
-
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
|
|
2097
|
-
onValueChange: selectValue,
|
|
2098
|
-
disabled: !fieldsReady || views.isPending || mutation.isPending,
|
|
2099
|
-
"aria-label": "已保存的视图",
|
|
2100
|
-
className: cn(lineTabs ? "min-w-full justify-start gap-0 rounded-none bg-transparent p-0" : "rounded-lg bg-muted p-1", tabs?.classNames?.list),
|
|
2101
|
-
children: [/* @__PURE__ */ jsxs(ToggleGroupItem, {
|
|
2102
|
-
value: "all",
|
|
2103
|
-
className: tabClassName,
|
|
2104
|
-
children: [
|
|
2105
|
-
"全部",
|
|
2106
|
-
renderCount("all"),
|
|
2107
|
-
renderIndicator(selected === null)
|
|
2108
|
-
]
|
|
2109
|
-
}), viewItems.map((view, index$1) => /* @__PURE__ */ jsxs(ToggleGroupItem, {
|
|
2110
|
-
value: `view:${view.id}`,
|
|
2111
|
-
title: view.source === "preset" ? `${view.name}(预设视图)` : view.name,
|
|
2112
|
-
className: tabClassName,
|
|
2113
|
-
children: [
|
|
2114
|
-
view.name,
|
|
2115
|
-
renderCount(`view:${index$1}`),
|
|
2116
|
-
renderIndicator(selected?.id === view.id),
|
|
2117
|
-
selected?.id === view.id && dirty && /* @__PURE__ */ jsx("span", {
|
|
2118
|
-
"aria-label": "有未保存修改",
|
|
2119
|
-
className: "size-1.5 rounded-full bg-current"
|
|
2120
|
-
})
|
|
2121
|
-
]
|
|
2122
|
-
}, view.id))]
|
|
2123
|
-
})
|
|
2124
|
-
}), /* @__PURE__ */ jsxs(DropdownMenu, { children: [/* @__PURE__ */ jsx(DropdownMenuTrigger, {
|
|
2125
|
-
asChild: true,
|
|
2126
|
-
children: /* @__PURE__ */ jsx(Button, {
|
|
2127
|
-
type: "button",
|
|
2128
|
-
variant: display === "tabs" ? "ghost" : "outline",
|
|
2129
|
-
size: display === "tabs" || selected === null ? "icon-sm" : "sm",
|
|
2130
|
-
className: cn("relative shrink-0", display === "dropdown" && selected === null && counts && "w-auto px-2"),
|
|
2131
|
-
"aria-label": triggerLabel,
|
|
2132
|
-
title: triggerLabel,
|
|
2133
|
-
disabled: !fieldsReady || views.isPending || mutation.isPending,
|
|
2134
|
-
children: display === "tabs" ? /* @__PURE__ */ jsx(Settings, { className: "size-4" }) : /* @__PURE__ */ jsxs(Fragment$1, { children: [
|
|
2135
|
-
selected ? selected.name : /* @__PURE__ */ jsx(Layers, {
|
|
2136
|
-
"aria-hidden": "true",
|
|
2137
|
-
className: "size-4"
|
|
2138
|
-
}),
|
|
2139
|
-
renderCount(selected ? `view:${viewItems.findIndex((view) => view.id === selected.id)}` : "all"),
|
|
2140
|
-
dirty && /* @__PURE__ */ jsx("span", {
|
|
2141
|
-
"aria-label": "有未保存修改",
|
|
2142
|
-
className: cn("size-1.5 rounded-full bg-current", selected === null && "absolute right-1 top-1")
|
|
2143
|
-
}),
|
|
2144
|
-
selected && /* @__PURE__ */ jsx(ChevronDown, { className: "size-4" })
|
|
2145
|
-
] })
|
|
2146
|
-
})
|
|
2147
|
-
}), /* @__PURE__ */ jsxs(DropdownMenuContent, {
|
|
2148
|
-
align: "start",
|
|
2149
|
-
children: [
|
|
2150
|
-
display === "dropdown" && /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsxs(DropdownMenuRadioGroup, {
|
|
2145
|
+
className: cn("flex min-w-0 max-w-full items-center gap-1", display === "tabs" && "w-full", display === "tabs" && lineTabs && ["relative before:pointer-events-none before:absolute before:inset-x-0 before:h-px before:bg-border", linePosition === "top" ? "before:top-0" : "before:bottom-0"]),
|
|
2146
|
+
children: [
|
|
2147
|
+
display === "tabs" && /* @__PURE__ */ jsx("div", {
|
|
2148
|
+
className: "min-w-0 flex-1 overflow-x-auto",
|
|
2149
|
+
children: /* @__PURE__ */ jsxs(ToggleGroup, {
|
|
2150
|
+
type: "single",
|
|
2151
|
+
size: "sm",
|
|
2152
|
+
spacing: 1,
|
|
2151
2153
|
value: selected ? `view:${selected.id}` : "all",
|
|
2152
2154
|
onValueChange: selectValue,
|
|
2153
|
-
|
|
2155
|
+
disabled: !fieldsReady || views.isPending || mutation.isPending,
|
|
2156
|
+
"aria-label": "已保存的视图",
|
|
2157
|
+
className: cn(lineTabs ? "min-w-full justify-start gap-0 rounded-none bg-transparent p-0" : "rounded-lg bg-muted p-1", tabs?.classNames?.list),
|
|
2158
|
+
children: [/* @__PURE__ */ jsxs(ToggleGroupItem, {
|
|
2154
2159
|
value: "all",
|
|
2155
|
-
|
|
2156
|
-
|
|
2160
|
+
className: tabClassName,
|
|
2161
|
+
children: [
|
|
2162
|
+
"全部",
|
|
2163
|
+
renderCount("all"),
|
|
2164
|
+
renderIndicator(selected === null)
|
|
2165
|
+
]
|
|
2166
|
+
}), viewItems.map((view, index$1) => /* @__PURE__ */ jsxs(ToggleGroupItem, {
|
|
2157
2167
|
value: `view:${view.id}`,
|
|
2158
|
-
|
|
2168
|
+
title: view.source === "preset" ? `${view.name}(预设视图)` : view.name,
|
|
2169
|
+
className: tabClassName,
|
|
2170
|
+
children: [
|
|
2171
|
+
view.name,
|
|
2172
|
+
renderCount(`view:${index$1}`),
|
|
2173
|
+
renderIndicator(selected?.id === view.id),
|
|
2174
|
+
selected?.id === view.id && /* @__PURE__ */ jsx("span", {
|
|
2175
|
+
"aria-label": dirty ? "有未保存修改" : void 0,
|
|
2176
|
+
className: cn("size-1.5 rounded-full bg-current", !dirty && "invisible")
|
|
2177
|
+
})
|
|
2178
|
+
]
|
|
2159
2179
|
}, view.id))]
|
|
2160
|
-
})
|
|
2161
|
-
|
|
2162
|
-
|
|
2163
|
-
|
|
2164
|
-
|
|
2165
|
-
|
|
2166
|
-
|
|
2167
|
-
|
|
2168
|
-
|
|
2169
|
-
|
|
2170
|
-
|
|
2171
|
-
|
|
2180
|
+
})
|
|
2181
|
+
}),
|
|
2182
|
+
display === "tabs" && viewActions && /* @__PURE__ */ jsx("div", {
|
|
2183
|
+
className: cn("flex shrink-0 items-center gap-1", !dirty && "invisible"),
|
|
2184
|
+
children: viewActions
|
|
2185
|
+
}),
|
|
2186
|
+
/* @__PURE__ */ jsxs(DropdownMenu, { children: [/* @__PURE__ */ jsx(DropdownMenuTrigger, {
|
|
2187
|
+
asChild: true,
|
|
2188
|
+
children: /* @__PURE__ */ jsx(Button, {
|
|
2189
|
+
type: "button",
|
|
2190
|
+
variant: display === "tabs" ? "ghost" : "outline",
|
|
2191
|
+
size: display === "tabs" || selected === null ? "icon-sm" : "sm",
|
|
2192
|
+
className: cn("relative shrink-0", display === "dropdown" && selected === null && counts && "w-auto px-2"),
|
|
2193
|
+
"aria-label": triggerLabel,
|
|
2194
|
+
title: triggerLabel,
|
|
2195
|
+
disabled: !fieldsReady || views.isPending || mutation.isPending,
|
|
2196
|
+
children: display === "tabs" ? /* @__PURE__ */ jsx(Settings, { className: "size-4" }) : /* @__PURE__ */ jsxs(Fragment$1, { children: [
|
|
2197
|
+
selected ? selected.name : /* @__PURE__ */ jsx(Layers, {
|
|
2198
|
+
"aria-hidden": "true",
|
|
2199
|
+
className: "size-4"
|
|
2200
|
+
}),
|
|
2201
|
+
renderCount(selected ? `view:${viewItems.findIndex((view) => view.id === selected.id)}` : "all"),
|
|
2202
|
+
dirty && /* @__PURE__ */ jsx("span", {
|
|
2203
|
+
"aria-label": "有未保存修改",
|
|
2204
|
+
className: cn("size-1.5 rounded-full bg-current", selected === null && "absolute right-1 top-1")
|
|
2205
|
+
}),
|
|
2206
|
+
selected && /* @__PURE__ */ jsx(ChevronDown, { className: "size-4" })
|
|
2207
|
+
] })
|
|
2208
|
+
})
|
|
2209
|
+
}), /* @__PURE__ */ jsxs(DropdownMenuContent, {
|
|
2210
|
+
align: "start",
|
|
2211
|
+
children: [
|
|
2212
|
+
display === "dropdown" && /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsxs(DropdownMenuRadioGroup, {
|
|
2213
|
+
value: selected ? `view:${selected.id}` : "all",
|
|
2214
|
+
onValueChange: selectValue,
|
|
2215
|
+
children: [/* @__PURE__ */ jsxs(DropdownMenuRadioItem, {
|
|
2216
|
+
value: "all",
|
|
2217
|
+
children: ["全部", renderCount("all")]
|
|
2218
|
+
}), viewItems.map((view, index$1) => /* @__PURE__ */ jsxs(DropdownMenuRadioItem, {
|
|
2219
|
+
value: `view:${view.id}`,
|
|
2220
|
+
children: [view.name, renderCount(`view:${index$1}`)]
|
|
2221
|
+
}, view.id))]
|
|
2222
|
+
}), /* @__PURE__ */ jsx(DropdownMenuSeparator, {})] }),
|
|
2223
|
+
/* @__PURE__ */ jsx(DropdownMenuLabel, { children: "视图设置" }),
|
|
2172
2224
|
/* @__PURE__ */ jsxs(DropdownMenuItem, {
|
|
2173
2225
|
disabled: !ready || !canCreate,
|
|
2174
|
-
onSelect: () => open("
|
|
2175
|
-
children: [/* @__PURE__ */ jsx(
|
|
2176
|
-
}),
|
|
2177
|
-
canDelete && /* @__PURE__ */ jsxs(DropdownMenuItem, {
|
|
2178
|
-
onSelect: () => open("delete"),
|
|
2179
|
-
children: [/* @__PURE__ */ jsx(Trash2, { className: "size-4" }), "删除视图"]
|
|
2226
|
+
onSelect: () => open("create"),
|
|
2227
|
+
children: [/* @__PURE__ */ jsx(Plus, { className: "size-4" }), "另存为新视图"]
|
|
2180
2228
|
}),
|
|
2229
|
+
selected && /* @__PURE__ */ jsxs(Fragment$1, { children: [
|
|
2230
|
+
canUpdate && /* @__PURE__ */ jsxs(DropdownMenuItem, {
|
|
2231
|
+
onSelect: () => open("rename"),
|
|
2232
|
+
children: [/* @__PURE__ */ jsx(Pencil, { className: "size-4" }), "重命名视图"]
|
|
2233
|
+
}),
|
|
2234
|
+
/* @__PURE__ */ jsxs(DropdownMenuItem, {
|
|
2235
|
+
disabled: !ready || !canCreate,
|
|
2236
|
+
onSelect: () => open("duplicate"),
|
|
2237
|
+
children: [/* @__PURE__ */ jsx(Copy, { className: "size-4" }), "复制视图"]
|
|
2238
|
+
}),
|
|
2239
|
+
canDelete && /* @__PURE__ */ jsxs(DropdownMenuItem, {
|
|
2240
|
+
onSelect: () => open("delete"),
|
|
2241
|
+
children: [/* @__PURE__ */ jsx(Trash2, { className: "size-4" }), "删除视图"]
|
|
2242
|
+
}),
|
|
2243
|
+
/* @__PURE__ */ jsxs(DropdownMenuItem, {
|
|
2244
|
+
disabled: !ready,
|
|
2245
|
+
onSelect: hideView,
|
|
2246
|
+
children: [/* @__PURE__ */ jsx(EyeOff, { className: "size-4" }), "隐藏视图"]
|
|
2247
|
+
})
|
|
2248
|
+
] }),
|
|
2249
|
+
selected && /* @__PURE__ */ jsx(DropdownMenuSeparator, {}),
|
|
2181
2250
|
/* @__PURE__ */ jsxs(DropdownMenuItem, {
|
|
2251
|
+
disabled: !ready || viewItems.length < 2,
|
|
2252
|
+
onSelect: () => open("reorder"),
|
|
2253
|
+
children: [/* @__PURE__ */ jsx(ArrowDownUp, { className: "size-4" }), "调整顺序"]
|
|
2254
|
+
}),
|
|
2255
|
+
restorableViews.length > 0 && /* @__PURE__ */ jsxs(DropdownMenuSub, { children: [/* @__PURE__ */ jsxs(DropdownMenuSubTrigger, {
|
|
2182
2256
|
disabled: !ready,
|
|
2183
|
-
|
|
2184
|
-
|
|
2185
|
-
|
|
2186
|
-
|
|
2187
|
-
|
|
2188
|
-
|
|
2189
|
-
|
|
2190
|
-
|
|
2191
|
-
|
|
2192
|
-
|
|
2193
|
-
|
|
2194
|
-
|
|
2195
|
-
|
|
2196
|
-
|
|
2197
|
-
|
|
2198
|
-
|
|
2199
|
-
|
|
2200
|
-
|
|
2201
|
-
|
|
2202
|
-
|
|
2203
|
-
|
|
2204
|
-
|
|
2205
|
-
|
|
2206
|
-
|
|
2207
|
-
|
|
2208
|
-
|
|
2209
|
-
|
|
2210
|
-
|
|
2211
|
-
|
|
2212
|
-
|
|
2213
|
-
|
|
2214
|
-
},
|
|
2215
|
-
children: [/* @__PURE__ */ jsxs(DropdownMenuRadioItem, {
|
|
2216
|
-
value: "dropdown",
|
|
2217
|
-
children: [/* @__PURE__ */ jsx(ChevronDown, { className: "size-4" }), "下拉"]
|
|
2218
|
-
}), /* @__PURE__ */ jsxs(DropdownMenuRadioItem, {
|
|
2219
|
-
value: "tabs",
|
|
2220
|
-
children: [/* @__PURE__ */ jsx(AppWindow, { className: "size-4" }), "Tab"]
|
|
2221
|
-
})]
|
|
2222
|
-
}) })] })
|
|
2223
|
-
]
|
|
2224
|
-
})] })]
|
|
2257
|
+
children: [/* @__PURE__ */ jsx(Eye, { className: "size-4" }), "恢复隐藏视图"]
|
|
2258
|
+
}), /* @__PURE__ */ jsx(DropdownMenuSubContent, { children: restorableViews.map((view) => /* @__PURE__ */ jsxs(DropdownMenuItem, {
|
|
2259
|
+
onSelect: () => {
|
|
2260
|
+
preferencesRestored.current = false;
|
|
2261
|
+
savePreferences({ hiddenViewIds: preferencesRef.current?.hiddenViewIds?.filter((id) => id !== view.id) });
|
|
2262
|
+
setError(null);
|
|
2263
|
+
},
|
|
2264
|
+
children: [/* @__PURE__ */ jsx(Eye, { className: "size-4" }), view.name]
|
|
2265
|
+
}, view.id)) })] }),
|
|
2266
|
+
/* @__PURE__ */ jsxs(DropdownMenuSub, { children: [/* @__PURE__ */ jsxs(DropdownMenuSubTrigger, { children: [/* @__PURE__ */ jsx(PanelsTopLeft, { className: "size-4" }), "展示方式"] }), /* @__PURE__ */ jsx(DropdownMenuSubContent, { children: /* @__PURE__ */ jsxs(DropdownMenuRadioGroup, {
|
|
2267
|
+
value: display,
|
|
2268
|
+
onValueChange: (value) => {
|
|
2269
|
+
if (value === "dropdown" || value === "tabs") {
|
|
2270
|
+
setDisplay(value);
|
|
2271
|
+
savePreferences({
|
|
2272
|
+
selector: value,
|
|
2273
|
+
viewId: selected?.id ?? null
|
|
2274
|
+
});
|
|
2275
|
+
}
|
|
2276
|
+
},
|
|
2277
|
+
children: [/* @__PURE__ */ jsxs(DropdownMenuRadioItem, {
|
|
2278
|
+
value: "dropdown",
|
|
2279
|
+
children: [/* @__PURE__ */ jsx(ChevronDown, { className: "size-4" }), "下拉"]
|
|
2280
|
+
}), /* @__PURE__ */ jsxs(DropdownMenuRadioItem, {
|
|
2281
|
+
value: "tabs",
|
|
2282
|
+
children: [/* @__PURE__ */ jsx(AppWindow, { className: "size-4" }), "Tab"]
|
|
2283
|
+
})]
|
|
2284
|
+
}) })] })
|
|
2285
|
+
]
|
|
2286
|
+
})] })
|
|
2287
|
+
]
|
|
2225
2288
|
}),
|
|
2226
|
-
|
|
2227
|
-
type: "button",
|
|
2228
|
-
size: "sm",
|
|
2229
|
-
disabled: mutation.isPending,
|
|
2230
|
-
onClick: () => mutation.mutate({
|
|
2231
|
-
operation: "update",
|
|
2232
|
-
input: {
|
|
2233
|
-
name: selected.name,
|
|
2234
|
-
slug: selected.slug,
|
|
2235
|
-
scope: selected.source === "saved" ? selected.scope : void 0,
|
|
2236
|
-
query: current
|
|
2237
|
-
}
|
|
2238
|
-
}),
|
|
2239
|
-
children: "保存修改"
|
|
2240
|
-
}) : canCreate && /* @__PURE__ */ jsx(Button, {
|
|
2241
|
-
type: "button",
|
|
2242
|
-
size: "sm",
|
|
2243
|
-
disabled: mutation.isPending,
|
|
2244
|
-
onClick: () => open("create"),
|
|
2245
|
-
children: "另存为新视图"
|
|
2246
|
-
}), /* @__PURE__ */ jsx(Button, {
|
|
2247
|
-
type: "button",
|
|
2248
|
-
size: "sm",
|
|
2249
|
-
variant: "ghost",
|
|
2250
|
-
disabled: mutation.isPending,
|
|
2251
|
-
onClick: () => select(selected),
|
|
2252
|
-
children: "还原"
|
|
2253
|
-
})] }),
|
|
2289
|
+
display === "dropdown" && dirty && viewActions,
|
|
2254
2290
|
(error !== null || views.error !== null || collection.error !== null) && /* @__PURE__ */ jsxs("span", {
|
|
2255
2291
|
role: "alert",
|
|
2256
2292
|
className: "text-sm text-destructive",
|
|
@@ -3422,6 +3458,8 @@ function DataTablePagination({ table, pageSizeOptions = [
|
|
|
3422
3458
|
const canJump = Number.isFinite(pageCount) && pageCount > 0;
|
|
3423
3459
|
const canGoNext = table.getCanNextPage() && (knownPageCount || table.options.data.length >= pageSize);
|
|
3424
3460
|
const total = table.options.rowCount ?? (table.options.manualPagination ? void 0 : table.getRowCount());
|
|
3461
|
+
const selectedCount = getSelectedTableRows(table).length;
|
|
3462
|
+
const selectionTotal = table.options.meta?.selectedRows !== void 0 ? getSelectionTotal(table) : table.getFilteredRowModel().rows.length;
|
|
3425
3463
|
useEffect(() => {
|
|
3426
3464
|
if (!responsive || !container.current || !summary.current || !controls.current || !navigation.current) return;
|
|
3427
3465
|
if (typeof ResizeObserver === "undefined") return;
|
|
@@ -3470,7 +3508,7 @@ function DataTablePagination({ table, pageSizeOptions = [
|
|
|
3470
3508
|
children: [/* @__PURE__ */ jsxs("div", {
|
|
3471
3509
|
ref: summary,
|
|
3472
3510
|
className: "flex flex-1 items-center gap-6 whitespace-nowrap text-muted-foreground text-sm",
|
|
3473
|
-
children: [/* @__PURE__ */ jsx("span", { children: locale.selected(
|
|
3511
|
+
children: [/* @__PURE__ */ jsx("span", { children: selectionTotal === void 0 || selectedCount > selectionTotal ? (locale.selectedCount ?? enUSActionBar.selected)(selectedCount) : locale.selected(selectedCount, selectionTotal) }), total !== void 0 && /* @__PURE__ */ jsx("span", { children: locale.total(total) })]
|
|
3474
3512
|
}), /* @__PURE__ */ jsxs("div", {
|
|
3475
3513
|
ref: controls,
|
|
3476
3514
|
className: cn("flex items-center gap-4 sm:gap-6 lg:gap-8", responsive ? "flex-row flex-wrap justify-center whitespace-nowrap [&>*]:shrink-0" : "flex-col-reverse sm:flex-row"),
|
|
@@ -3787,7 +3825,7 @@ function DataTable({ table, actionBar, pagination, expandedRow, rowFooter, child
|
|
|
3787
3825
|
children: [/* @__PURE__ */ jsx(DataTablePagination, {
|
|
3788
3826
|
table,
|
|
3789
3827
|
...pagination
|
|
3790
|
-
}), actionBar && table
|
|
3828
|
+
}), actionBar && getSelectedTableRows(table).length > 0 && actionBar]
|
|
3791
3829
|
})
|
|
3792
3830
|
]
|
|
3793
3831
|
});
|
|
@@ -5969,12 +6007,14 @@ function createSelectColumn() {
|
|
|
5969
6007
|
id: "select",
|
|
5970
6008
|
header: ({ table }) => /* @__PURE__ */ jsx(Checkbox, {
|
|
5971
6009
|
"aria-label": "Select all",
|
|
6010
|
+
disabled: !table.getPaginationRowModel().flatRows.some((row) => row.getCanSelect()),
|
|
5972
6011
|
className: "translate-y-0.5",
|
|
5973
6012
|
checked: table.getIsAllPageRowsSelected() || table.getIsSomePageRowsSelected() && "indeterminate",
|
|
5974
6013
|
onCheckedChange: (value) => table.toggleAllPageRowsSelected(!!value)
|
|
5975
6014
|
}),
|
|
5976
6015
|
cell: ({ row }) => /* @__PURE__ */ jsx(Checkbox, {
|
|
5977
6016
|
"aria-label": "Select row",
|
|
6017
|
+
disabled: !row.getCanSelect(),
|
|
5978
6018
|
className: "translate-y-0.5",
|
|
5979
6019
|
checked: row.getIsSelected(),
|
|
5980
6020
|
onCheckedChange: (value) => row.toggleSelected(!!value)
|
|
@@ -7316,7 +7356,7 @@ function getExportColumnIds(table) {
|
|
|
7316
7356
|
function exportTableToCSV(table, opts = {}) {
|
|
7317
7357
|
const { filename = "table", excludeColumns = [], onlySelected = false } = opts;
|
|
7318
7358
|
const headers = getExportColumnIds(table).filter((id) => !excludeColumns.includes(id));
|
|
7319
|
-
downloadCSV([headers.join(","), ...(onlySelected ? table
|
|
7359
|
+
downloadCSV([headers.join(","), ...(onlySelected ? getSelectedTableRows(table) : table.getRowModel().rows).map((row) => headers.map((header) => {
|
|
7320
7360
|
const cellValue = row.getValue(header);
|
|
7321
7361
|
return typeof cellValue === "string" ? `"${cellValue.replace(/"/g, "\"\"")}"` : cellValue;
|
|
7322
7362
|
}).join(","))].join("\n"), filename);
|
|
@@ -7365,14 +7405,14 @@ function AutoTableActionBar({ table, locale: localeProp, onDeleteSelected, onUpd
|
|
|
7365
7405
|
...enUSActionBar,
|
|
7366
7406
|
...localeProp
|
|
7367
7407
|
}), [localeProp]);
|
|
7368
|
-
const rows = table
|
|
7408
|
+
const rows = getSelectedTableRows(table);
|
|
7369
7409
|
const selectedRows = React.useMemo(() => rows.map((row) => row.original), [rows]);
|
|
7370
7410
|
const [deleteDialogOpen, setDeleteDialogOpen] = React.useState(false);
|
|
7371
7411
|
React.useEffect(() => {
|
|
7372
7412
|
if (selectedRows.length === 0) setDeleteDialogOpen(false);
|
|
7373
7413
|
}, [selectedRows.length]);
|
|
7374
7414
|
const clearSelection = React.useCallback(() => {
|
|
7375
|
-
table.
|
|
7415
|
+
table.resetRowSelection(true);
|
|
7376
7416
|
}, [table]);
|
|
7377
7417
|
const actionContext = React.useMemo(() => ({
|
|
7378
7418
|
rows: selectedRows,
|
|
@@ -7779,7 +7819,7 @@ const filterModeConfig = {
|
|
|
7779
7819
|
tooltip: "Linear-style command filters"
|
|
7780
7820
|
}
|
|
7781
7821
|
};
|
|
7782
|
-
function AutoTable({ resourceId, views, schema, data, getRowId, expandedRow, rowFooter, defaultExpanded = false, pageCount = 1, pagination, total, overrides, classNames, enableRowSelection = true, queryKeys, initialColumnVisibility, exclude, filterOnly, actions, pinnedColumns, filterMode, search = false, batchSearch, filterState, toolbarExtra, locale = enUSTableControls, onDeleteSelected, onUpdateSelected, batchUpdateFields, actionBarExtra, actionBarLocale, actionBarActions, deleteConfirmation, initialSorting, enableExport = true, showDefaultExport = true, onSelectedCountChange, onSelectedRowsChange, getSelectedRows, exportTableRef }) {
|
|
7822
|
+
function AutoTable({ resourceId, views, schema, data, getRowId, idKey = "id", selectionScope, pagePending = false, expandedRow, rowFooter, defaultExpanded = false, pageCount = 1, pagination, total, overrides, classNames, enableRowSelection = true, queryKeys, initialColumnVisibility, exclude, filterOnly, actions, pinnedColumns, filterMode, search = false, batchSearch, filterState, toolbarExtra, locale = enUSTableControls, onDeleteSelected, onUpdateSelected, batchUpdateFields, actionBarExtra, actionBarLocale, actionBarActions, deleteConfirmation, initialSorting, enableExport = true, showDefaultExport = true, onSelectedCountChange, onSelectedRowsChange, getSelectedRows, exportTableRef }) {
|
|
7783
7823
|
const inheritedResourceId = useContext(CrudResourceContext);
|
|
7784
7824
|
const activeResourceId = resourceId ?? inheritedResourceId;
|
|
7785
7825
|
const viewsEnabled = views ?? false;
|
|
@@ -7900,12 +7940,28 @@ function AutoTable({ resourceId, views, schema, data, getRowId, expandedRow, row
|
|
|
7900
7940
|
actions
|
|
7901
7941
|
]);
|
|
7902
7942
|
const expandedRowModel = useMemo(() => getExpandedRowModel(), []);
|
|
7943
|
+
const resolveRowId = useMemo(() => {
|
|
7944
|
+
if (getRowId) return getRowId;
|
|
7945
|
+
const anonymousRows = /* @__PURE__ */ new WeakMap();
|
|
7946
|
+
let nextId = 0;
|
|
7947
|
+
return (record) => {
|
|
7948
|
+
const key = readRowId(record, idKey);
|
|
7949
|
+
if (key !== void 0) return `key:${key}`;
|
|
7950
|
+
let id = anonymousRows.get(record);
|
|
7951
|
+
if (id === void 0) {
|
|
7952
|
+
id = `local:${nextId++}`;
|
|
7953
|
+
anonymousRows.set(record, id);
|
|
7954
|
+
}
|
|
7955
|
+
return id;
|
|
7956
|
+
};
|
|
7957
|
+
}, [getRowId, idKey]);
|
|
7958
|
+
const keyedData = useMemo(() => data.slice(), [data, idKey]);
|
|
7903
7959
|
const { table, shallow, debounceMs, throttleMs } = useDataTable({
|
|
7904
|
-
data,
|
|
7960
|
+
data: keyedData,
|
|
7905
7961
|
columns,
|
|
7906
7962
|
queryKeys,
|
|
7907
|
-
enableRowSelection,
|
|
7908
|
-
getRowId,
|
|
7963
|
+
enableRowSelection: enableRowSelection && !pagePending,
|
|
7964
|
+
getRowId: resolveRowId,
|
|
7909
7965
|
getRowCanExpand: () => enableExpansion,
|
|
7910
7966
|
getExpandedRowModel: enableExpansion ? expandedRowModel : void 0,
|
|
7911
7967
|
autoResetExpanded: defaultExpanded ? false : void 0,
|
|
@@ -7937,14 +7993,95 @@ function AutoTable({ resourceId, views, schema, data, getRowId, expandedRow, row
|
|
|
7937
7993
|
exportTableRef.current = null;
|
|
7938
7994
|
};
|
|
7939
7995
|
}, [table, exportTableRef]);
|
|
7940
|
-
const
|
|
7941
|
-
const
|
|
7942
|
-
const
|
|
7996
|
+
const [filters] = useReadableFilters(columns, { state: filterState });
|
|
7997
|
+
const [query] = useQueryState("search", parseAsString.withDefault(""));
|
|
7998
|
+
const [join] = useQueryState(queryKeys?.joinOperator ?? "joinOperator", parseAsString.withDefault("and"));
|
|
7999
|
+
const resultSet = useMemo(() => selectionScope ?? JSON.stringify([
|
|
8000
|
+
query.trim(),
|
|
8001
|
+
join,
|
|
8002
|
+
filterSignature(filters),
|
|
8003
|
+
batchSearch?.filter
|
|
8004
|
+
]), [
|
|
8005
|
+
selectionScope,
|
|
8006
|
+
query,
|
|
8007
|
+
join,
|
|
8008
|
+
filters,
|
|
8009
|
+
batchSearch?.filter
|
|
8010
|
+
]);
|
|
8011
|
+
const scope = useMemo(() => ({
|
|
8012
|
+
activeResourceId,
|
|
8013
|
+
idKey,
|
|
8014
|
+
enableRowSelection,
|
|
8015
|
+
resultSet
|
|
8016
|
+
}), [
|
|
8017
|
+
activeResourceId,
|
|
8018
|
+
idKey,
|
|
8019
|
+
enableRowSelection,
|
|
8020
|
+
resultSet
|
|
8021
|
+
]);
|
|
8022
|
+
const [previousScope, setPreviousScope] = useState(scope);
|
|
8023
|
+
if (previousScope !== scope) {
|
|
8024
|
+
setPreviousScope(scope);
|
|
8025
|
+
table.resetRowSelection(true);
|
|
8026
|
+
}
|
|
8027
|
+
const { rowSelection, pagination: { pageIndex } } = table.getState();
|
|
8028
|
+
const pageSelection = table.getFilteredSelectedRowModel().rows;
|
|
8029
|
+
const retained = useRef([]);
|
|
8030
|
+
const loadedPage = useRef(null);
|
|
8031
|
+
const loadedIndex = loadedPage.current?.data === data ? loadedPage.current.index : pageIndex;
|
|
8032
|
+
const allRowsLoaded = !pagePending && getSelectionTotal(table, loadedIndex) === data.length;
|
|
8033
|
+
const selectedTableRows = useMemo(() => {
|
|
8034
|
+
if (pagePending) return retained.current.filter((row) => rowSelection[row.id]);
|
|
8035
|
+
if (allRowsLoaded || pageSelection.length === Object.keys(rowSelection).length) return pageSelection;
|
|
8036
|
+
const rows = /* @__PURE__ */ new Map();
|
|
8037
|
+
for (const row of retained.current) if (rowSelection[row.id] && (getRowId || row.original[idKey] != null)) rows.set(row.id, row);
|
|
8038
|
+
for (const row of pageSelection) rows.set(row.id, row);
|
|
8039
|
+
return Array.from(rows.values());
|
|
8040
|
+
}, [
|
|
8041
|
+
allRowsLoaded,
|
|
8042
|
+
pagePending,
|
|
8043
|
+
pageSelection,
|
|
8044
|
+
rowSelection,
|
|
8045
|
+
getRowId,
|
|
8046
|
+
idKey
|
|
8047
|
+
]);
|
|
8048
|
+
table.setOptions((options) => ({
|
|
8049
|
+
...options,
|
|
8050
|
+
meta: {
|
|
8051
|
+
...options.meta,
|
|
8052
|
+
selectedRows: selectedTableRows
|
|
8053
|
+
}
|
|
8054
|
+
}));
|
|
8055
|
+
useLayoutEffect(() => {
|
|
8056
|
+
loadedPage.current = pagePending ? null : {
|
|
8057
|
+
data,
|
|
8058
|
+
index: loadedIndex
|
|
8059
|
+
};
|
|
8060
|
+
retained.current = selectedTableRows;
|
|
8061
|
+
if (!pagePending && Object.keys(rowSelection).length > selectedTableRows.length) table.setRowSelection(Object.fromEntries(selectedTableRows.map((row) => [row.id, true])));
|
|
8062
|
+
}, [
|
|
7943
8063
|
table,
|
|
7944
8064
|
rowSelection,
|
|
7945
|
-
|
|
7946
|
-
|
|
8065
|
+
selectedTableRows,
|
|
8066
|
+
pagePending,
|
|
8067
|
+
data,
|
|
8068
|
+
loadedIndex
|
|
7947
8069
|
]);
|
|
8070
|
+
useLayoutEffect(() => selectionScope?.onDelete((deleted) => {
|
|
8071
|
+
const id = readRowId(deleted, idKey);
|
|
8072
|
+
const rows = retained.current.filter((row) => row.original === deleted || id !== void 0 && readRowId(row.original, idKey) === id);
|
|
8073
|
+
if (!rows.length) return;
|
|
8074
|
+
table.setRowSelection((current) => {
|
|
8075
|
+
const next = { ...current };
|
|
8076
|
+
for (const row of rows) delete next[row.id];
|
|
8077
|
+
return next;
|
|
8078
|
+
});
|
|
8079
|
+
}), [
|
|
8080
|
+
selectionScope,
|
|
8081
|
+
table,
|
|
8082
|
+
idKey
|
|
8083
|
+
]);
|
|
8084
|
+
const selectedRows = useMemo(() => selectedTableRows.map((row) => row.original), [selectedTableRows]);
|
|
7948
8085
|
const getSelectedRowsFn = useCallback(() => selectedRows, [selectedRows]);
|
|
7949
8086
|
useEffect(() => {
|
|
7950
8087
|
if (getSelectedRows) getSelectedRows.current = getSelectedRowsFn;
|
|
@@ -8061,20 +8198,28 @@ function AutoTable({ resourceId, views, schema, data, getRowId, expandedRow, row
|
|
|
8061
8198
|
});
|
|
8062
8199
|
const state = table.getState();
|
|
8063
8200
|
const tableContent = useMemo(() => /* @__PURE__ */ jsx(DataTable, {
|
|
8064
|
-
pagination
|
|
8201
|
+
pagination: {
|
|
8202
|
+
...pagination,
|
|
8203
|
+
locale: {
|
|
8204
|
+
selectedCount: actionBarLocale?.selected,
|
|
8205
|
+
...pagination?.locale
|
|
8206
|
+
}
|
|
8207
|
+
},
|
|
8065
8208
|
table,
|
|
8066
8209
|
classNames,
|
|
8067
8210
|
expandedRow,
|
|
8068
8211
|
rowFooter
|
|
8069
8212
|
}), [
|
|
8070
8213
|
table,
|
|
8071
|
-
|
|
8214
|
+
keyedData,
|
|
8215
|
+
pagePending,
|
|
8072
8216
|
columns,
|
|
8073
8217
|
getRowId,
|
|
8074
8218
|
pageCount,
|
|
8075
8219
|
total,
|
|
8076
8220
|
stableInitialState,
|
|
8077
8221
|
pagination,
|
|
8222
|
+
actionBarLocale?.selected,
|
|
8078
8223
|
classNames,
|
|
8079
8224
|
expandedRow,
|
|
8080
8225
|
rowFooter,
|
|
@@ -9641,10 +9786,6 @@ function resolveOwnerBatchActions(actions) {
|
|
|
9641
9786
|
function isUnifiedActionsConfig(actions) {
|
|
9642
9787
|
return typeof actions === "object" && actions !== null && !Array.isArray(actions);
|
|
9643
9788
|
}
|
|
9644
|
-
function readRowId(row, idKey) {
|
|
9645
|
-
const value = row[idKey];
|
|
9646
|
-
return value === null || value === void 0 ? void 0 : String(value);
|
|
9647
|
-
}
|
|
9648
9789
|
function readRowIds(rows, idKey) {
|
|
9649
9790
|
return rows.flatMap((row) => {
|
|
9650
9791
|
const value = readRowId(row, idKey);
|
|
@@ -10837,7 +10978,7 @@ function AutoCrudTable({ id, title, description, schema, resource, fields, table
|
|
|
10837
10978
|
...action$1,
|
|
10838
10979
|
onClick: (_rows, { table }) => {
|
|
10839
10980
|
const headers = getExportColumnIds(table).filter((key) => key !== "select" && key !== "actions" && !denyFields?.includes(key));
|
|
10840
|
-
exportAllToCSV(table
|
|
10981
|
+
exportAllToCSV(getSelectedTableRows(table).map((row) => formatExportRow(row.original, resolvedFields, Object.fromEntries(headers.map((key) => [key, row.getValue(key)])))), {
|
|
10841
10982
|
filename: "table",
|
|
10842
10983
|
headers
|
|
10843
10984
|
});
|
|
@@ -11149,6 +11290,9 @@ function AutoCrudTable({ id, title, description, schema, resource, fields, table
|
|
|
11149
11290
|
enableRowSelection: tableConfig?.enableRowSelection,
|
|
11150
11291
|
initialColumnVisibility: tableConfig?.initialColumnVisibility,
|
|
11151
11292
|
getRowId: tableConfig?.getRowId,
|
|
11293
|
+
idKey: resourceIdKey,
|
|
11294
|
+
selectionScope: resource.tableData.selectionScope,
|
|
11295
|
+
pagePending: resource.tableData.isLoading || resource.tableData.isPlaceholderData || Boolean(resource.tableData.error) && resource.tableData.data.length === 0,
|
|
11152
11296
|
expandedRow: tableConfig?.expandedRow,
|
|
11153
11297
|
rowFooter: tableConfig?.rowFooter,
|
|
11154
11298
|
defaultExpanded: tableConfig?.defaultExpanded,
|
|
@@ -12093,25 +12237,49 @@ function useAutoCrudResource({ router, queryKeys, schema, query: queryTransform,
|
|
|
12093
12237
|
const [filtersReady, setFiltersReady] = useState(!metadataPending);
|
|
12094
12238
|
useEffect(() => setFiltersReady(!metadataPending), [metadataPending]);
|
|
12095
12239
|
const listReady = !metadataPending && filtersReady;
|
|
12240
|
+
const firstPageParams = useMemo(() => ({
|
|
12241
|
+
page: 1,
|
|
12242
|
+
perPage: 10,
|
|
12243
|
+
sort: defaultSorting,
|
|
12244
|
+
filters,
|
|
12245
|
+
joinOperator,
|
|
12246
|
+
...search.trim() ? { search: search.trim() } : {}
|
|
12247
|
+
}), [
|
|
12248
|
+
defaultSorting,
|
|
12249
|
+
filters,
|
|
12250
|
+
joinOperator,
|
|
12251
|
+
search
|
|
12252
|
+
]);
|
|
12253
|
+
const firstPageInput = useMemo(() => queryTransform ? queryTransform({ ...firstPageParams }) : firstPageParams, [queryTransform, firstPageParams]);
|
|
12096
12254
|
const queryInput = useMemo(() => {
|
|
12255
|
+
if (page === firstPageParams.page && perPage === firstPageParams.perPage && sort === firstPageParams.sort) return firstPageInput;
|
|
12097
12256
|
const autoParams = {
|
|
12257
|
+
...firstPageParams,
|
|
12098
12258
|
page,
|
|
12099
12259
|
perPage,
|
|
12100
|
-
sort
|
|
12101
|
-
filters,
|
|
12102
|
-
joinOperator,
|
|
12103
|
-
...search.trim() ? { search: search.trim() } : {}
|
|
12260
|
+
sort
|
|
12104
12261
|
};
|
|
12105
12262
|
return queryTransform ? queryTransform(autoParams) : autoParams;
|
|
12106
12263
|
}, [
|
|
12107
12264
|
page,
|
|
12108
12265
|
perPage,
|
|
12109
12266
|
sort,
|
|
12110
|
-
|
|
12111
|
-
|
|
12112
|
-
search,
|
|
12267
|
+
firstPageParams,
|
|
12268
|
+
firstPageInput,
|
|
12113
12269
|
queryTransform
|
|
12114
12270
|
]);
|
|
12271
|
+
const previousCriteria = useRef(void 0);
|
|
12272
|
+
const selectionCriteria = useMemo(() => {
|
|
12273
|
+
const criteria = firstPageInput?.filters === filters ? {
|
|
12274
|
+
...firstPageInput,
|
|
12275
|
+
filters: filterSignature(filters)
|
|
12276
|
+
} : firstPageInput;
|
|
12277
|
+
return replaceEqualDeep(previousCriteria.current, criteria);
|
|
12278
|
+
}, [firstPageInput, filters]);
|
|
12279
|
+
useEffect(() => {
|
|
12280
|
+
previousCriteria.current = selectionCriteria;
|
|
12281
|
+
}, [selectionCriteria]);
|
|
12282
|
+
const selectionScope = useMemo(() => createRowSelectionScope(), [router.list, selectionCriteria]);
|
|
12115
12283
|
const hasReadyListData = useRef(false);
|
|
12116
12284
|
const listQuery = router.list.useQuery(queryInput, {
|
|
12117
12285
|
...queryContext !== void 0 ? { trpc: { context: queryContext } } : {},
|
|
@@ -12294,6 +12462,7 @@ function useAutoCrudResource({ router, queryKeys, schema, query: queryTransform,
|
|
|
12294
12462
|
return;
|
|
12295
12463
|
}
|
|
12296
12464
|
toast$1.success("删除成功");
|
|
12465
|
+
selectionScope.notifyDeleted(modal.selected);
|
|
12297
12466
|
dispatch({
|
|
12298
12467
|
type: "DELETE_SUCCEEDED",
|
|
12299
12468
|
payload: modal.selected
|
|
@@ -12305,7 +12474,8 @@ function useAutoCrudResource({ router, queryKeys, schema, query: queryTransform,
|
|
|
12305
12474
|
idKey,
|
|
12306
12475
|
deleteMutation,
|
|
12307
12476
|
refreshResource,
|
|
12308
|
-
toast$1
|
|
12477
|
+
toast$1,
|
|
12478
|
+
selectionScope
|
|
12309
12479
|
]);
|
|
12310
12480
|
const deleteMany = useCallback((rows) => {
|
|
12311
12481
|
const currentHooks = hooksRef.current;
|
|
@@ -12408,6 +12578,8 @@ function useAutoCrudResource({ router, queryKeys, schema, query: queryTransform,
|
|
|
12408
12578
|
filterState,
|
|
12409
12579
|
tableData: {
|
|
12410
12580
|
data: tableRows,
|
|
12581
|
+
selectionScope,
|
|
12582
|
+
isPlaceholderData: Boolean(listQuery.isPlaceholderData),
|
|
12411
12583
|
countSource: {
|
|
12412
12584
|
navigationKey: listData && !listQuery.isPlaceholderData ? navigationKey : null,
|
|
12413
12585
|
refreshVersion,
|