@wordrhyme/auto-crud 1.23.1 → 1.23.3
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 -1
- package/dist/index.cjs +229 -180
- package/dist/index.d.cts +1004 -996
- package/dist/index.d.ts +1021 -1013
- package/dist/index.js +230 -181
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -2204,7 +2204,7 @@ const loadViewCounts: NonNullable<SavedViewsConfig['counts']> = async ({
|
|
|
2204
2204
|
|
|
2205
2205
|
回调返回以传入 `query.key` 为键的数量对象,键由组件生成,直接原样返回即可。每批最多 100 个查询,更多视图自动分批。使用 `auto-crud-server` 时开启 `counts: true`,数据库适配器须支持受权限和租户范围约束的 `$counts`;其他后端可自行实现相同的回调。
|
|
2206
2206
|
|
|
2207
|
-
首次加载显示 `…`,零结果显示 `0`,缺失或无效数量显示
|
|
2207
|
+
首次加载显示 `…`,零结果显示 `0`,缺失或无效数量显示 `—`,请求失败显示 `—` 和重试入口。保存视图条件或更换 `counts` 回调会重新统计。配合 `useAutoCrudResource` 时,翻页、排序和切换视图复用已有数量。成功写入、显式刷新资源或当前列表的行数据更新后,角标会刷新。独立 `AutoTable` 使用 `views={{ selector: 'tabs', counts: loadViewCounts }}`,行数组引用变化时刷新。数量保存在查询缓存中。
|
|
2208
2208
|
|
|
2209
2209
|
Storybook 的 **Auto CRUD / Saved views and tags / Tabs With Counts** 与其他视图示例共用本地视图存储,模拟 300ms 统计请求延迟;首次加载预置数量为 3、2、1、0 的视图。列表和数量共用筛选逻辑,修改客户标签后会重新计算。视图与排列顺序刷新后保留,客户标签刷新后重置。
|
|
2210
2210
|
|
package/dist/index.cjs
CHANGED
|
@@ -1634,7 +1634,7 @@ function SavedViews(props) {
|
|
|
1634
1634
|
key: `${config.cacheKey}:${props.resourceId}`
|
|
1635
1635
|
});
|
|
1636
1636
|
}
|
|
1637
|
-
function ViewMenu({ resourceId, table, fieldsReady = true, defaultView, presets, hiddenViews, scopeOptions, selector = "dropdown", tabs, counts, onApply, children }) {
|
|
1637
|
+
function ViewMenu({ resourceId, table, fieldsReady = true, defaultView, presets, hiddenViews, scopeOptions, selector = "dropdown", tabs, counts, countSource, onApply, children }) {
|
|
1638
1638
|
const config = useAutoCrudConfig();
|
|
1639
1639
|
const storage = config.viewStorage;
|
|
1640
1640
|
const client = (0, __tanstack_react_query.useQueryClient)();
|
|
@@ -1743,25 +1743,39 @@ function ViewMenu({ resourceId, table, fieldsReady = true, defaultView, presets,
|
|
|
1743
1743
|
enabled: Boolean(counts) && ready && fieldsReady
|
|
1744
1744
|
});
|
|
1745
1745
|
const data = table.options.data;
|
|
1746
|
+
const navigationKey = countSource?.navigationKey;
|
|
1747
|
+
const refreshVersion = countSource?.refreshVersion;
|
|
1748
|
+
const listFetching = countSource?.isFetching;
|
|
1746
1749
|
const previousSource = (0, react.useRef)({
|
|
1747
1750
|
data,
|
|
1748
|
-
counts
|
|
1751
|
+
counts,
|
|
1752
|
+
navigationKey
|
|
1749
1753
|
});
|
|
1754
|
+
const countedVersion = (0, react.useRef)(refreshVersion);
|
|
1750
1755
|
const refreshPending = (0, react.useRef)(false);
|
|
1751
1756
|
const refetchCounts = totals.refetch;
|
|
1752
1757
|
(0, react.useEffect)(() => {
|
|
1753
1758
|
const previous = previousSource.current;
|
|
1754
|
-
previousSource.current = {
|
|
1755
|
-
|
|
1759
|
+
previousSource.current = navigationKey === null ? {
|
|
1760
|
+
...previous,
|
|
1756
1761
|
counts
|
|
1762
|
+
} : {
|
|
1763
|
+
data,
|
|
1764
|
+
counts,
|
|
1765
|
+
navigationKey
|
|
1757
1766
|
};
|
|
1758
|
-
if (previous.data !== data || previous.counts !== counts) refreshPending.current = true;
|
|
1759
|
-
|
|
1767
|
+
if (navigationKey !== null && previous.navigationKey === navigationKey && previous.data !== data || previous.counts !== counts) refreshPending.current = true;
|
|
1768
|
+
const resourceRefresh = countedVersion.current !== refreshVersion;
|
|
1769
|
+
if (!counts || !ready || !fieldsReady || totals.fetchStatus !== "idle" || resourceRefresh && listFetching || !refreshPending.current && !resourceRefresh) return;
|
|
1760
1770
|
refreshPending.current = false;
|
|
1771
|
+
countedVersion.current = refreshVersion;
|
|
1761
1772
|
refetchCounts({ cancelRefetch: false });
|
|
1762
1773
|
}, [
|
|
1763
1774
|
data,
|
|
1764
1775
|
counts,
|
|
1776
|
+
navigationKey,
|
|
1777
|
+
refreshVersion,
|
|
1778
|
+
listFetching,
|
|
1765
1779
|
ready,
|
|
1766
1780
|
fieldsReady,
|
|
1767
1781
|
totals.fetchStatus,
|
|
@@ -2084,175 +2098,183 @@ function ViewMenu({ resourceId, table, fieldsReady = true, defaultView, presets,
|
|
|
2084
2098
|
className: cn("pointer-events-none absolute inset-x-0 h-1 bg-primary", linePosition === "top" ? "top-0" : "bottom-0", tabs?.classNames?.indicator)
|
|
2085
2099
|
}) : null;
|
|
2086
2100
|
const triggerLabel = display === "tabs" ? "视图设置" : selected === null ? "切换视图" : void 0;
|
|
2101
|
+
const viewActions = selected && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [canUpdate ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(__wordrhyme_shadcn.Button, {
|
|
2102
|
+
type: "button",
|
|
2103
|
+
size: "sm",
|
|
2104
|
+
disabled: mutation.isPending,
|
|
2105
|
+
onClick: () => mutation.mutate({
|
|
2106
|
+
operation: "update",
|
|
2107
|
+
input: {
|
|
2108
|
+
name: selected.name,
|
|
2109
|
+
slug: selected.slug,
|
|
2110
|
+
scope: selected.source === "saved" ? selected.scope : void 0,
|
|
2111
|
+
query: current
|
|
2112
|
+
}
|
|
2113
|
+
}),
|
|
2114
|
+
children: "保存修改"
|
|
2115
|
+
}) : canCreate && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(__wordrhyme_shadcn.Button, {
|
|
2116
|
+
type: "button",
|
|
2117
|
+
size: "sm",
|
|
2118
|
+
disabled: mutation.isPending,
|
|
2119
|
+
onClick: () => open("create"),
|
|
2120
|
+
children: "另存为新视图"
|
|
2121
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(__wordrhyme_shadcn.Button, {
|
|
2122
|
+
type: "button",
|
|
2123
|
+
size: "sm",
|
|
2124
|
+
variant: "ghost",
|
|
2125
|
+
disabled: mutation.isPending,
|
|
2126
|
+
onClick: () => select(selected),
|
|
2127
|
+
children: "还原"
|
|
2128
|
+
})] });
|
|
2087
2129
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [children(/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
2088
2130
|
className: "flex min-w-0 flex-wrap items-center gap-2",
|
|
2089
2131
|
children: [
|
|
2090
2132
|
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
2091
|
-
className: cn("flex min-w-0 max-w-full items-center gap-1", display === "tabs" && lineTabs && ["relative
|
|
2092
|
-
children: [
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
|
|
2097
|
-
|
|
2098
|
-
|
|
2099
|
-
onValueChange: selectValue,
|
|
2100
|
-
disabled: !fieldsReady || views.isPending || mutation.isPending,
|
|
2101
|
-
"aria-label": "已保存的视图",
|
|
2102
|
-
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),
|
|
2103
|
-
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)(__wordrhyme_shadcn.ToggleGroupItem, {
|
|
2104
|
-
value: "all",
|
|
2105
|
-
className: tabClassName,
|
|
2106
|
-
children: [
|
|
2107
|
-
"全部",
|
|
2108
|
-
renderCount("all"),
|
|
2109
|
-
renderIndicator(selected === null)
|
|
2110
|
-
]
|
|
2111
|
-
}), viewItems.map((view, index$1) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(__wordrhyme_shadcn.ToggleGroupItem, {
|
|
2112
|
-
value: `view:${view.id}`,
|
|
2113
|
-
title: view.source === "preset" ? `${view.name}(预设视图)` : view.name,
|
|
2114
|
-
className: tabClassName,
|
|
2115
|
-
children: [
|
|
2116
|
-
view.name,
|
|
2117
|
-
renderCount(`view:${index$1}`),
|
|
2118
|
-
renderIndicator(selected?.id === view.id),
|
|
2119
|
-
selected?.id === view.id && dirty && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
2120
|
-
"aria-label": "有未保存修改",
|
|
2121
|
-
className: "size-1.5 rounded-full bg-current"
|
|
2122
|
-
})
|
|
2123
|
-
]
|
|
2124
|
-
}, view.id))]
|
|
2125
|
-
})
|
|
2126
|
-
}), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(__wordrhyme_shadcn.DropdownMenu, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(__wordrhyme_shadcn.DropdownMenuTrigger, {
|
|
2127
|
-
asChild: true,
|
|
2128
|
-
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(__wordrhyme_shadcn.Button, {
|
|
2129
|
-
type: "button",
|
|
2130
|
-
variant: display === "tabs" ? "ghost" : "outline",
|
|
2131
|
-
size: display === "tabs" || selected === null ? "icon-sm" : "sm",
|
|
2132
|
-
className: cn("relative shrink-0", display === "dropdown" && selected === null && counts && "w-auto px-2"),
|
|
2133
|
-
"aria-label": triggerLabel,
|
|
2134
|
-
title: triggerLabel,
|
|
2135
|
-
disabled: !fieldsReady || views.isPending || mutation.isPending,
|
|
2136
|
-
children: display === "tabs" ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.Settings, { className: "size-4" }) : /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
|
|
2137
|
-
selected ? selected.name : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.Layers, {
|
|
2138
|
-
"aria-hidden": "true",
|
|
2139
|
-
className: "size-4"
|
|
2140
|
-
}),
|
|
2141
|
-
renderCount(selected ? `view:${viewItems.findIndex((view) => view.id === selected.id)}` : "all"),
|
|
2142
|
-
dirty && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
2143
|
-
"aria-label": "有未保存修改",
|
|
2144
|
-
className: cn("size-1.5 rounded-full bg-current", selected === null && "absolute right-1 top-1")
|
|
2145
|
-
}),
|
|
2146
|
-
selected && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.ChevronDown, { className: "size-4" })
|
|
2147
|
-
] })
|
|
2148
|
-
})
|
|
2149
|
-
}), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(__wordrhyme_shadcn.DropdownMenuContent, {
|
|
2150
|
-
align: "start",
|
|
2151
|
-
children: [
|
|
2152
|
-
display === "dropdown" && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)(__wordrhyme_shadcn.DropdownMenuRadioGroup, {
|
|
2133
|
+
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"]),
|
|
2134
|
+
children: [
|
|
2135
|
+
display === "tabs" && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
2136
|
+
className: "min-w-0 flex-1 overflow-x-auto",
|
|
2137
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(__wordrhyme_shadcn.ToggleGroup, {
|
|
2138
|
+
type: "single",
|
|
2139
|
+
size: "sm",
|
|
2140
|
+
spacing: 1,
|
|
2153
2141
|
value: selected ? `view:${selected.id}` : "all",
|
|
2154
2142
|
onValueChange: selectValue,
|
|
2155
|
-
|
|
2143
|
+
disabled: !fieldsReady || views.isPending || mutation.isPending,
|
|
2144
|
+
"aria-label": "已保存的视图",
|
|
2145
|
+
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),
|
|
2146
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)(__wordrhyme_shadcn.ToggleGroupItem, {
|
|
2156
2147
|
value: "all",
|
|
2157
|
-
|
|
2158
|
-
|
|
2148
|
+
className: tabClassName,
|
|
2149
|
+
children: [
|
|
2150
|
+
"全部",
|
|
2151
|
+
renderCount("all"),
|
|
2152
|
+
renderIndicator(selected === null)
|
|
2153
|
+
]
|
|
2154
|
+
}), viewItems.map((view, index$1) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(__wordrhyme_shadcn.ToggleGroupItem, {
|
|
2159
2155
|
value: `view:${view.id}`,
|
|
2160
|
-
|
|
2156
|
+
title: view.source === "preset" ? `${view.name}(预设视图)` : view.name,
|
|
2157
|
+
className: tabClassName,
|
|
2158
|
+
children: [
|
|
2159
|
+
view.name,
|
|
2160
|
+
renderCount(`view:${index$1}`),
|
|
2161
|
+
renderIndicator(selected?.id === view.id),
|
|
2162
|
+
selected?.id === view.id && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
2163
|
+
"aria-label": dirty ? "有未保存修改" : void 0,
|
|
2164
|
+
className: cn("size-1.5 rounded-full bg-current", !dirty && "invisible")
|
|
2165
|
+
})
|
|
2166
|
+
]
|
|
2161
2167
|
}, view.id))]
|
|
2162
|
-
})
|
|
2163
|
-
|
|
2164
|
-
|
|
2165
|
-
|
|
2166
|
-
|
|
2167
|
-
|
|
2168
|
-
|
|
2169
|
-
|
|
2170
|
-
|
|
2171
|
-
|
|
2172
|
-
|
|
2173
|
-
|
|
2168
|
+
})
|
|
2169
|
+
}),
|
|
2170
|
+
display === "tabs" && viewActions && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
2171
|
+
className: cn("flex shrink-0 items-center gap-1", !dirty && "invisible"),
|
|
2172
|
+
children: viewActions
|
|
2173
|
+
}),
|
|
2174
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)(__wordrhyme_shadcn.DropdownMenu, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(__wordrhyme_shadcn.DropdownMenuTrigger, {
|
|
2175
|
+
asChild: true,
|
|
2176
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(__wordrhyme_shadcn.Button, {
|
|
2177
|
+
type: "button",
|
|
2178
|
+
variant: display === "tabs" ? "ghost" : "outline",
|
|
2179
|
+
size: display === "tabs" || selected === null ? "icon-sm" : "sm",
|
|
2180
|
+
className: cn("relative shrink-0", display === "dropdown" && selected === null && counts && "w-auto px-2"),
|
|
2181
|
+
"aria-label": triggerLabel,
|
|
2182
|
+
title: triggerLabel,
|
|
2183
|
+
disabled: !fieldsReady || views.isPending || mutation.isPending,
|
|
2184
|
+
children: display === "tabs" ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.Settings, { className: "size-4" }) : /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
|
|
2185
|
+
selected ? selected.name : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.Layers, {
|
|
2186
|
+
"aria-hidden": "true",
|
|
2187
|
+
className: "size-4"
|
|
2188
|
+
}),
|
|
2189
|
+
renderCount(selected ? `view:${viewItems.findIndex((view) => view.id === selected.id)}` : "all"),
|
|
2190
|
+
dirty && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
2191
|
+
"aria-label": "有未保存修改",
|
|
2192
|
+
className: cn("size-1.5 rounded-full bg-current", selected === null && "absolute right-1 top-1")
|
|
2193
|
+
}),
|
|
2194
|
+
selected && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.ChevronDown, { className: "size-4" })
|
|
2195
|
+
] })
|
|
2196
|
+
})
|
|
2197
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(__wordrhyme_shadcn.DropdownMenuContent, {
|
|
2198
|
+
align: "start",
|
|
2199
|
+
children: [
|
|
2200
|
+
display === "dropdown" && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)(__wordrhyme_shadcn.DropdownMenuRadioGroup, {
|
|
2201
|
+
value: selected ? `view:${selected.id}` : "all",
|
|
2202
|
+
onValueChange: selectValue,
|
|
2203
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)(__wordrhyme_shadcn.DropdownMenuRadioItem, {
|
|
2204
|
+
value: "all",
|
|
2205
|
+
children: ["全部", renderCount("all")]
|
|
2206
|
+
}), viewItems.map((view, index$1) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(__wordrhyme_shadcn.DropdownMenuRadioItem, {
|
|
2207
|
+
value: `view:${view.id}`,
|
|
2208
|
+
children: [view.name, renderCount(`view:${index$1}`)]
|
|
2209
|
+
}, view.id))]
|
|
2210
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(__wordrhyme_shadcn.DropdownMenuSeparator, {})] }),
|
|
2211
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(__wordrhyme_shadcn.DropdownMenuLabel, { children: "视图设置" }),
|
|
2174
2212
|
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)(__wordrhyme_shadcn.DropdownMenuItem, {
|
|
2175
2213
|
disabled: !ready || !canCreate,
|
|
2176
|
-
onSelect: () => open("
|
|
2177
|
-
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.
|
|
2178
|
-
}),
|
|
2179
|
-
canDelete && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(__wordrhyme_shadcn.DropdownMenuItem, {
|
|
2180
|
-
onSelect: () => open("delete"),
|
|
2181
|
-
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.Trash2, { className: "size-4" }), "删除视图"]
|
|
2214
|
+
onSelect: () => open("create"),
|
|
2215
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.Plus, { className: "size-4" }), "另存为新视图"]
|
|
2182
2216
|
}),
|
|
2217
|
+
selected && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
|
|
2218
|
+
canUpdate && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(__wordrhyme_shadcn.DropdownMenuItem, {
|
|
2219
|
+
onSelect: () => open("rename"),
|
|
2220
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.Pencil, { className: "size-4" }), "重命名视图"]
|
|
2221
|
+
}),
|
|
2222
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)(__wordrhyme_shadcn.DropdownMenuItem, {
|
|
2223
|
+
disabled: !ready || !canCreate,
|
|
2224
|
+
onSelect: () => open("duplicate"),
|
|
2225
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.Copy, { className: "size-4" }), "复制视图"]
|
|
2226
|
+
}),
|
|
2227
|
+
canDelete && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(__wordrhyme_shadcn.DropdownMenuItem, {
|
|
2228
|
+
onSelect: () => open("delete"),
|
|
2229
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.Trash2, { className: "size-4" }), "删除视图"]
|
|
2230
|
+
}),
|
|
2231
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)(__wordrhyme_shadcn.DropdownMenuItem, {
|
|
2232
|
+
disabled: !ready,
|
|
2233
|
+
onSelect: hideView,
|
|
2234
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.EyeOff, { className: "size-4" }), "隐藏视图"]
|
|
2235
|
+
})
|
|
2236
|
+
] }),
|
|
2237
|
+
selected && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(__wordrhyme_shadcn.DropdownMenuSeparator, {}),
|
|
2183
2238
|
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)(__wordrhyme_shadcn.DropdownMenuItem, {
|
|
2239
|
+
disabled: !ready || viewItems.length < 2,
|
|
2240
|
+
onSelect: () => open("reorder"),
|
|
2241
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.ArrowDownUp, { className: "size-4" }), "调整顺序"]
|
|
2242
|
+
}),
|
|
2243
|
+
restorableViews.length > 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(__wordrhyme_shadcn.DropdownMenuSub, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)(__wordrhyme_shadcn.DropdownMenuSubTrigger, {
|
|
2184
2244
|
disabled: !ready,
|
|
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
|
-
|
|
2216
|
-
},
|
|
2217
|
-
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)(__wordrhyme_shadcn.DropdownMenuRadioItem, {
|
|
2218
|
-
value: "dropdown",
|
|
2219
|
-
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.ChevronDown, { className: "size-4" }), "下拉"]
|
|
2220
|
-
}), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(__wordrhyme_shadcn.DropdownMenuRadioItem, {
|
|
2221
|
-
value: "tabs",
|
|
2222
|
-
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.AppWindow, { className: "size-4" }), "Tab"]
|
|
2223
|
-
})]
|
|
2224
|
-
}) })] })
|
|
2225
|
-
]
|
|
2226
|
-
})] })]
|
|
2245
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.Eye, { className: "size-4" }), "恢复隐藏视图"]
|
|
2246
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(__wordrhyme_shadcn.DropdownMenuSubContent, { children: restorableViews.map((view) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(__wordrhyme_shadcn.DropdownMenuItem, {
|
|
2247
|
+
onSelect: () => {
|
|
2248
|
+
preferencesRestored.current = false;
|
|
2249
|
+
savePreferences({ hiddenViewIds: preferencesRef.current?.hiddenViewIds?.filter((id) => id !== view.id) });
|
|
2250
|
+
setError(null);
|
|
2251
|
+
},
|
|
2252
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.Eye, { className: "size-4" }), view.name]
|
|
2253
|
+
}, view.id)) })] }),
|
|
2254
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)(__wordrhyme_shadcn.DropdownMenuSub, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)(__wordrhyme_shadcn.DropdownMenuSubTrigger, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.PanelsTopLeft, { className: "size-4" }), "展示方式"] }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(__wordrhyme_shadcn.DropdownMenuSubContent, { children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(__wordrhyme_shadcn.DropdownMenuRadioGroup, {
|
|
2255
|
+
value: display,
|
|
2256
|
+
onValueChange: (value) => {
|
|
2257
|
+
if (value === "dropdown" || value === "tabs") {
|
|
2258
|
+
setDisplay(value);
|
|
2259
|
+
savePreferences({
|
|
2260
|
+
selector: value,
|
|
2261
|
+
viewId: selected?.id ?? null
|
|
2262
|
+
});
|
|
2263
|
+
}
|
|
2264
|
+
},
|
|
2265
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)(__wordrhyme_shadcn.DropdownMenuRadioItem, {
|
|
2266
|
+
value: "dropdown",
|
|
2267
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.ChevronDown, { className: "size-4" }), "下拉"]
|
|
2268
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(__wordrhyme_shadcn.DropdownMenuRadioItem, {
|
|
2269
|
+
value: "tabs",
|
|
2270
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.AppWindow, { className: "size-4" }), "Tab"]
|
|
2271
|
+
})]
|
|
2272
|
+
}) })] })
|
|
2273
|
+
]
|
|
2274
|
+
})] })
|
|
2275
|
+
]
|
|
2227
2276
|
}),
|
|
2228
|
-
|
|
2229
|
-
type: "button",
|
|
2230
|
-
size: "sm",
|
|
2231
|
-
disabled: mutation.isPending,
|
|
2232
|
-
onClick: () => mutation.mutate({
|
|
2233
|
-
operation: "update",
|
|
2234
|
-
input: {
|
|
2235
|
-
name: selected.name,
|
|
2236
|
-
slug: selected.slug,
|
|
2237
|
-
scope: selected.source === "saved" ? selected.scope : void 0,
|
|
2238
|
-
query: current
|
|
2239
|
-
}
|
|
2240
|
-
}),
|
|
2241
|
-
children: "保存修改"
|
|
2242
|
-
}) : canCreate && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(__wordrhyme_shadcn.Button, {
|
|
2243
|
-
type: "button",
|
|
2244
|
-
size: "sm",
|
|
2245
|
-
disabled: mutation.isPending,
|
|
2246
|
-
onClick: () => open("create"),
|
|
2247
|
-
children: "另存为新视图"
|
|
2248
|
-
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(__wordrhyme_shadcn.Button, {
|
|
2249
|
-
type: "button",
|
|
2250
|
-
size: "sm",
|
|
2251
|
-
variant: "ghost",
|
|
2252
|
-
disabled: mutation.isPending,
|
|
2253
|
-
onClick: () => select(selected),
|
|
2254
|
-
children: "还原"
|
|
2255
|
-
})] }),
|
|
2277
|
+
display === "dropdown" && dirty && viewActions,
|
|
2256
2278
|
(error !== null || views.error !== null || collection.error !== null) && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
|
|
2257
2279
|
role: "alert",
|
|
2258
2280
|
className: "text-sm text-destructive",
|
|
@@ -11112,6 +11134,11 @@ function AutoCrudTable({ id, title, description, schema, resource, fields, table
|
|
|
11112
11134
|
};
|
|
11113
11135
|
const toolbarNodes = normalizedToolbarActions.filter((action$1) => action$1.type !== "refresh").map(renderToolbarAction).filter((node) => node !== null);
|
|
11114
11136
|
const refreshNodes = normalizedToolbarActions.filter((action$1) => action$1.type === "refresh").map(renderToolbarAction);
|
|
11137
|
+
const views = viewsEnabled ? {
|
|
11138
|
+
...typeof viewsEnabled === "object" ? viewsEnabled : {},
|
|
11139
|
+
countSource: resource.tableData.countSource,
|
|
11140
|
+
fieldsReady: !resource.metadataPending && (typeof viewsEnabled !== "object" || viewsEnabled.fieldsReady !== false)
|
|
11141
|
+
} : false;
|
|
11115
11142
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CrudResourceContext.Provider, {
|
|
11116
11143
|
value: id,
|
|
11117
11144
|
children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
@@ -11136,10 +11163,7 @@ function AutoCrudTable({ id, title, description, schema, resource, fields, table
|
|
|
11136
11163
|
}),
|
|
11137
11164
|
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(AutoTable, {
|
|
11138
11165
|
resourceId: id,
|
|
11139
|
-
views
|
|
11140
|
-
...typeof viewsEnabled === "object" ? viewsEnabled : {},
|
|
11141
|
-
fieldsReady: !resource.metadataPending && (typeof viewsEnabled !== "object" || viewsEnabled.fieldsReady !== false)
|
|
11142
|
-
} : false,
|
|
11166
|
+
views,
|
|
11143
11167
|
data: resource.tableData.data,
|
|
11144
11168
|
schema: resolvedSchema,
|
|
11145
11169
|
pageCount: resource.tableData.pageCount,
|
|
@@ -12124,6 +12148,26 @@ function useAutoCrudResource({ router, queryKeys, schema, query: queryTransform,
|
|
|
12124
12148
|
}, [listReady, listQuery.data]);
|
|
12125
12149
|
const listData = listReady ? listQuery.data : void 0;
|
|
12126
12150
|
const tableRows = listData?.data ?? EMPTY_ROWS;
|
|
12151
|
+
const navigationKey = (0, react.useMemo)(() => (0, __tanstack_react_query.hashKey)([
|
|
12152
|
+
page,
|
|
12153
|
+
perPage,
|
|
12154
|
+
sort,
|
|
12155
|
+
filters,
|
|
12156
|
+
joinOperator,
|
|
12157
|
+
search.trim()
|
|
12158
|
+
]), [
|
|
12159
|
+
page,
|
|
12160
|
+
perPage,
|
|
12161
|
+
sort,
|
|
12162
|
+
filters,
|
|
12163
|
+
joinOperator,
|
|
12164
|
+
search
|
|
12165
|
+
]);
|
|
12166
|
+
const [refreshVersion, requestCountsRefresh] = (0, react.useReducer)((version$1) => version$1 + 1, 0);
|
|
12167
|
+
const refreshResource = (0, react.useCallback)(() => {
|
|
12168
|
+
requestCountsRefresh();
|
|
12169
|
+
return listQuery.refetch();
|
|
12170
|
+
}, [listQuery]);
|
|
12127
12171
|
const createMutation = router.create.useMutation();
|
|
12128
12172
|
const updateMutation = router.update.useMutation();
|
|
12129
12173
|
const deleteMutation = router.delete.useMutation();
|
|
@@ -12175,7 +12219,7 @@ function useAutoCrudResource({ router, queryKeys, schema, query: queryTransform,
|
|
|
12175
12219
|
if (result) {
|
|
12176
12220
|
toast$1.success("创建成功");
|
|
12177
12221
|
closeModals();
|
|
12178
|
-
|
|
12222
|
+
refreshResource();
|
|
12179
12223
|
currentHooks?.onSuccess?.("create", values);
|
|
12180
12224
|
}
|
|
12181
12225
|
return;
|
|
@@ -12186,7 +12230,7 @@ function useAutoCrudResource({ router, queryKeys, schema, query: queryTransform,
|
|
|
12186
12230
|
onSuccess: (data) => {
|
|
12187
12231
|
toast$1.success("创建成功");
|
|
12188
12232
|
closeModals();
|
|
12189
|
-
|
|
12233
|
+
refreshResource();
|
|
12190
12234
|
currentHooks?.onSuccess?.("create", data);
|
|
12191
12235
|
},
|
|
12192
12236
|
onError: (error) => {
|
|
@@ -12203,7 +12247,7 @@ function useAutoCrudResource({ router, queryKeys, schema, query: queryTransform,
|
|
|
12203
12247
|
}, [
|
|
12204
12248
|
createMutation,
|
|
12205
12249
|
closeModals,
|
|
12206
|
-
|
|
12250
|
+
refreshResource
|
|
12207
12251
|
]);
|
|
12208
12252
|
const submitUpdate = (0, react.useCallback)(async (values) => {
|
|
12209
12253
|
const currentHooks = hooksRef.current;
|
|
@@ -12215,7 +12259,7 @@ function useAutoCrudResource({ router, queryKeys, schema, query: queryTransform,
|
|
|
12215
12259
|
if (result) {
|
|
12216
12260
|
toast$1.success("更新成功");
|
|
12217
12261
|
closeModals();
|
|
12218
|
-
|
|
12262
|
+
refreshResource();
|
|
12219
12263
|
currentHooks?.onSuccess?.("update", values);
|
|
12220
12264
|
}
|
|
12221
12265
|
return;
|
|
@@ -12230,7 +12274,7 @@ function useAutoCrudResource({ router, queryKeys, schema, query: queryTransform,
|
|
|
12230
12274
|
onSuccess: (data) => {
|
|
12231
12275
|
toast$1.success("更新成功");
|
|
12232
12276
|
closeModals();
|
|
12233
|
-
|
|
12277
|
+
refreshResource();
|
|
12234
12278
|
currentHooks?.onSuccess?.("update", data);
|
|
12235
12279
|
},
|
|
12236
12280
|
onError: (error) => {
|
|
@@ -12249,7 +12293,7 @@ function useAutoCrudResource({ router, queryKeys, schema, query: queryTransform,
|
|
|
12249
12293
|
idKey,
|
|
12250
12294
|
updateMutation,
|
|
12251
12295
|
closeModals,
|
|
12252
|
-
|
|
12296
|
+
refreshResource
|
|
12253
12297
|
]);
|
|
12254
12298
|
const confirmDelete = (0, react.useCallback)(async () => {
|
|
12255
12299
|
const currentHooks = hooksRef.current;
|
|
@@ -12278,13 +12322,13 @@ function useAutoCrudResource({ router, queryKeys, schema, query: queryTransform,
|
|
|
12278
12322
|
type: "DELETE_SUCCEEDED",
|
|
12279
12323
|
payload: modal.selected
|
|
12280
12324
|
});
|
|
12281
|
-
|
|
12325
|
+
refreshResource();
|
|
12282
12326
|
currentHooks?.onSuccess?.("delete", data);
|
|
12283
12327
|
}, [
|
|
12284
12328
|
modal.selected,
|
|
12285
12329
|
idKey,
|
|
12286
12330
|
deleteMutation,
|
|
12287
|
-
|
|
12331
|
+
refreshResource,
|
|
12288
12332
|
toast$1
|
|
12289
12333
|
]);
|
|
12290
12334
|
const deleteMany = (0, react.useCallback)((rows) => {
|
|
@@ -12297,7 +12341,7 @@ function useAutoCrudResource({ router, queryKeys, schema, query: queryTransform,
|
|
|
12297
12341
|
deleteManyMutation.mutate(ids, {
|
|
12298
12342
|
onSuccess: (data) => {
|
|
12299
12343
|
toast$1.success(`成功删除 ${ids.length} 条记录`);
|
|
12300
|
-
|
|
12344
|
+
refreshResource();
|
|
12301
12345
|
currentHooks?.onSuccess?.("delete", data);
|
|
12302
12346
|
},
|
|
12303
12347
|
onError: (error) => {
|
|
@@ -12309,7 +12353,7 @@ function useAutoCrudResource({ router, queryKeys, schema, query: queryTransform,
|
|
|
12309
12353
|
}, [
|
|
12310
12354
|
deleteManyMutation,
|
|
12311
12355
|
idKey,
|
|
12312
|
-
|
|
12356
|
+
refreshResource
|
|
12313
12357
|
]);
|
|
12314
12358
|
const updateMany = (0, react.useCallback)((rows, data) => {
|
|
12315
12359
|
const currentHooks = hooksRef.current;
|
|
@@ -12324,7 +12368,7 @@ function useAutoCrudResource({ router, queryKeys, schema, query: queryTransform,
|
|
|
12324
12368
|
}, {
|
|
12325
12369
|
onSuccess: (result) => {
|
|
12326
12370
|
toast$1.success(`成功更新 ${ids.length} 条记录`);
|
|
12327
|
-
|
|
12371
|
+
refreshResource();
|
|
12328
12372
|
currentHooks?.onSuccess?.("update", result);
|
|
12329
12373
|
},
|
|
12330
12374
|
onError: (error) => {
|
|
@@ -12336,7 +12380,7 @@ function useAutoCrudResource({ router, queryKeys, schema, query: queryTransform,
|
|
|
12336
12380
|
}, [
|
|
12337
12381
|
updateManyMutation,
|
|
12338
12382
|
idKey,
|
|
12339
|
-
|
|
12383
|
+
refreshResource
|
|
12340
12384
|
]);
|
|
12341
12385
|
const copyRow = (0, react.useCallback)((row) => {
|
|
12342
12386
|
dispatch({
|
|
@@ -12351,11 +12395,11 @@ function useAutoCrudResource({ router, queryKeys, schema, query: queryTransform,
|
|
|
12351
12395
|
rows: coercedRows,
|
|
12352
12396
|
onConflict: "upsert"
|
|
12353
12397
|
});
|
|
12354
|
-
|
|
12398
|
+
refreshResource();
|
|
12355
12399
|
return result;
|
|
12356
12400
|
}, [
|
|
12357
12401
|
importMutation,
|
|
12358
|
-
|
|
12402
|
+
refreshResource,
|
|
12359
12403
|
schema
|
|
12360
12404
|
]);
|
|
12361
12405
|
const handleExport = (0, react.useCallback)(async () => {
|
|
@@ -12379,8 +12423,8 @@ function useAutoCrudResource({ router, queryKeys, schema, query: queryTransform,
|
|
|
12379
12423
|
const canExport = !!(exportFetcher || exportQuery);
|
|
12380
12424
|
const refresh = (0, react.useCallback)(async () => {
|
|
12381
12425
|
if (!listReady) return;
|
|
12382
|
-
return
|
|
12383
|
-
}, [
|
|
12426
|
+
return refreshResource();
|
|
12427
|
+
}, [refreshResource, listReady]);
|
|
12384
12428
|
return {
|
|
12385
12429
|
idKey,
|
|
12386
12430
|
queryKeys,
|
|
@@ -12388,6 +12432,11 @@ function useAutoCrudResource({ router, queryKeys, schema, query: queryTransform,
|
|
|
12388
12432
|
filterState,
|
|
12389
12433
|
tableData: {
|
|
12390
12434
|
data: tableRows,
|
|
12435
|
+
countSource: {
|
|
12436
|
+
navigationKey: listData && !listQuery.isPlaceholderData ? navigationKey : null,
|
|
12437
|
+
refreshVersion,
|
|
12438
|
+
isFetching: listQuery.isFetching
|
|
12439
|
+
},
|
|
12391
12440
|
pageCount: listData?.pageCount ?? 0,
|
|
12392
12441
|
...typeof listData?.total === "number" ? { total: listData.total } : {},
|
|
12393
12442
|
isLoading: !listReady || listQuery.isLoading,
|