@wordrhyme/auto-crud 0.2.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/LICENSE +21 -0
- package/README.md +724 -0
- package/dist/index.cjs +6065 -0
- package/dist/index.d.cts +1165 -0
- package/dist/index.d.ts +1165 -0
- package/dist/index.js +5985 -0
- package/package.json +104 -0
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,1165 @@
|
|
|
1
|
+
import * as react_jsx_runtime8 from "react/jsx-runtime";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import * as _tanstack_react_table0 from "@tanstack/react-table";
|
|
4
|
+
import { Column, ColumnDef, ColumnSort, Row, RowData, Table, TableOptions, TableState } from "@tanstack/react-table";
|
|
5
|
+
import * as React$1 from "react";
|
|
6
|
+
import { ISchema } from "@formily/json-schema";
|
|
7
|
+
import { DropdownMenuTrigger, PopoverContent } from "@pixpilot/shadcn";
|
|
8
|
+
import { ClassValue } from "clsx";
|
|
9
|
+
|
|
10
|
+
//#region src/hooks/use-auto-crud-resource.d.ts
|
|
11
|
+
/**
|
|
12
|
+
* Toast 适配器接口
|
|
13
|
+
* 用户可以注入自己的 toast 实现
|
|
14
|
+
*/
|
|
15
|
+
interface ToastAdapter {
|
|
16
|
+
success: (message: string) => void;
|
|
17
|
+
error: (message: string) => void;
|
|
18
|
+
info?: (message: string) => void;
|
|
19
|
+
warning?: (message: string) => void;
|
|
20
|
+
}
|
|
21
|
+
/** 空 toast 适配器(禁用通知) */
|
|
22
|
+
declare const noopToastAdapter: ToastAdapter;
|
|
23
|
+
/**
|
|
24
|
+
* Modal 状态类型
|
|
25
|
+
*/
|
|
26
|
+
type ModalVariant$1 = "dialog" | "sheet";
|
|
27
|
+
interface ModalState<T> {
|
|
28
|
+
createOpen: boolean;
|
|
29
|
+
editOpen: boolean;
|
|
30
|
+
deleteOpen: boolean;
|
|
31
|
+
viewOpen: boolean;
|
|
32
|
+
selected: T | null;
|
|
33
|
+
/** 复制源数据(用于复制行功能) */
|
|
34
|
+
copySource: T | null;
|
|
35
|
+
variant: ModalVariant$1;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Hook 返回值类型(用于判断是数据转换还是完全自定义)
|
|
39
|
+
* - 返回对象 = 数据转换,继续执行默认 mutation
|
|
40
|
+
* - 返回 true/false = 完全自定义,跳过默认 mutation
|
|
41
|
+
*/
|
|
42
|
+
type HookResult<T> = T | boolean;
|
|
43
|
+
/**
|
|
44
|
+
* 统一的 hooks 配置
|
|
45
|
+
*/
|
|
46
|
+
interface CrudHooks<TSchema extends z.ZodObject<z.ZodRawShape>, TListItem> {
|
|
47
|
+
/**
|
|
48
|
+
* 创建前钩子
|
|
49
|
+
* - 返回对象: 作为转换后的数据,继续执行默认创建
|
|
50
|
+
* - 返回 true: 表示已自定义处理成功,跳过默认创建
|
|
51
|
+
* - 返回 false: 表示自定义处理失败,跳过默认创建
|
|
52
|
+
*/
|
|
53
|
+
beforeCreate?: (values: z.infer<TSchema>) => HookResult<z.infer<TSchema>> | Promise<HookResult<z.infer<TSchema>>>;
|
|
54
|
+
/**
|
|
55
|
+
* 更新前钩子
|
|
56
|
+
* - 返回对象: 作为转换后的数据,继续执行默认更新
|
|
57
|
+
* - 返回 true/false: 完全自定义处理
|
|
58
|
+
*/
|
|
59
|
+
beforeUpdate?: (values: z.infer<TSchema>, original: TListItem) => HookResult<z.infer<TSchema>> | Promise<HookResult<z.infer<TSchema>>>;
|
|
60
|
+
/**
|
|
61
|
+
* 删除前钩子
|
|
62
|
+
* - 返回 true: 表示已自定义处理成功(如软删除)
|
|
63
|
+
* - 返回 false: 表示自定义处理失败
|
|
64
|
+
* - 返回 undefined/void: 继续执行默认删除
|
|
65
|
+
*/
|
|
66
|
+
beforeDelete?: (item: TListItem) => boolean | void | Promise<boolean | void>;
|
|
67
|
+
/** 操作成功回调 */
|
|
68
|
+
onSuccess?: (op: "create" | "update" | "delete", payload: unknown) => void;
|
|
69
|
+
/** 操作失败回调 */
|
|
70
|
+
onError?: (op: "create" | "update" | "delete", error: Error) => void;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Hook 配置选项
|
|
74
|
+
*/
|
|
75
|
+
interface UseAutoCrudResourceOptions<TSchema extends z.ZodObject<z.ZodRawShape>, TListItem> {
|
|
76
|
+
/** 主键字段名(默认: "id") */
|
|
77
|
+
idKey?: keyof TListItem & string;
|
|
78
|
+
/** 默认弹窗模式 */
|
|
79
|
+
defaultVariant?: ModalVariant$1;
|
|
80
|
+
/** 统一钩子配置 */
|
|
81
|
+
hooks?: CrudHooks<TSchema, TListItem>;
|
|
82
|
+
/**
|
|
83
|
+
* Toast 配置
|
|
84
|
+
* - undefined: 使用内置 sonner(默认)
|
|
85
|
+
* - false: 禁用所有通知
|
|
86
|
+
* - ToastAdapter: 注入自定义 toast 实现
|
|
87
|
+
*/
|
|
88
|
+
toast?: ToastAdapter | false;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Hook 返回值类型
|
|
92
|
+
*/
|
|
93
|
+
interface UseAutoCrudResourceReturn<TSchema extends z.ZodObject<z.ZodRawShape>, TListItem> {
|
|
94
|
+
tableData: {
|
|
95
|
+
data: TListItem[];
|
|
96
|
+
pageCount: number;
|
|
97
|
+
isLoading: boolean;
|
|
98
|
+
/** 是否正在获取数据(用于显示微妙的加载指示器) */
|
|
99
|
+
isFetching: boolean;
|
|
100
|
+
};
|
|
101
|
+
modal: ModalState<TListItem>;
|
|
102
|
+
mutations: {
|
|
103
|
+
isCreating: boolean;
|
|
104
|
+
isUpdating: boolean;
|
|
105
|
+
isDeleting: boolean;
|
|
106
|
+
};
|
|
107
|
+
handlers: {
|
|
108
|
+
openCreate: () => void;
|
|
109
|
+
openEdit: (row: TListItem) => void;
|
|
110
|
+
openDelete: (row: TListItem) => void;
|
|
111
|
+
openView: (row: TListItem) => void;
|
|
112
|
+
copyRow: (row: TListItem) => void;
|
|
113
|
+
closeModals: () => void;
|
|
114
|
+
submitCreate: (values: z.infer<TSchema>) => void;
|
|
115
|
+
submitUpdate: (values: z.infer<TSchema>) => void;
|
|
116
|
+
confirmDelete: () => void;
|
|
117
|
+
deleteMany: (rows: TListItem[]) => void;
|
|
118
|
+
updateMany: (rows: TListItem[], data: Record<string, unknown>) => void;
|
|
119
|
+
setVariant: (variant: ModalVariant$1) => void;
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* tRPC Router 接口定义(宽松类型以兼容实际 tRPC router)
|
|
124
|
+
*/
|
|
125
|
+
interface CrudRouter {
|
|
126
|
+
list: {
|
|
127
|
+
useQuery: (input?: any, opts?: any) => any;
|
|
128
|
+
};
|
|
129
|
+
create: {
|
|
130
|
+
useMutation: (opts?: any) => any;
|
|
131
|
+
};
|
|
132
|
+
update: {
|
|
133
|
+
useMutation: (opts?: any) => any;
|
|
134
|
+
};
|
|
135
|
+
delete: {
|
|
136
|
+
useMutation: (opts?: any) => any;
|
|
137
|
+
};
|
|
138
|
+
deleteMany?: {
|
|
139
|
+
useMutation: (opts?: any) => any;
|
|
140
|
+
};
|
|
141
|
+
updateMany?: {
|
|
142
|
+
useMutation: (opts?: any) => any;
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Hook 配置参数
|
|
147
|
+
*/
|
|
148
|
+
interface UseAutoCrudResourceParams<TSchema extends z.ZodObject<z.ZodRawShape>, TListItem> {
|
|
149
|
+
/** tRPC router (如 trpc.tasks) */
|
|
150
|
+
router: CrudRouter;
|
|
151
|
+
/** 列表查询参数 */
|
|
152
|
+
queryInput?: any;
|
|
153
|
+
/** Zod schema */
|
|
154
|
+
schema: TSchema;
|
|
155
|
+
/** 其他配置选项 */
|
|
156
|
+
options?: UseAutoCrudResourceOptions<TSchema, TListItem>;
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Hook 主函数
|
|
160
|
+
*/
|
|
161
|
+
declare function useAutoCrudResource<TSchema extends z.ZodObject<z.ZodRawShape>, TListItem = z.output<TSchema>>({
|
|
162
|
+
router,
|
|
163
|
+
queryInput,
|
|
164
|
+
options
|
|
165
|
+
}: UseAutoCrudResourceParams<TSchema, TListItem>): UseAutoCrudResourceReturn<TSchema, TListItem>;
|
|
166
|
+
//#endregion
|
|
167
|
+
//#region src/components/auto-crud/auto-table-action-bar.d.ts
|
|
168
|
+
/** 批量更新字段配置 */
|
|
169
|
+
interface BatchUpdateField {
|
|
170
|
+
/** 字段名 */
|
|
171
|
+
field: string;
|
|
172
|
+
/** 显示标签 */
|
|
173
|
+
label: string;
|
|
174
|
+
/** 可选值 */
|
|
175
|
+
options: Array<{
|
|
176
|
+
label: string;
|
|
177
|
+
value: string;
|
|
178
|
+
}>;
|
|
179
|
+
}
|
|
180
|
+
interface AutoTableActionBarProps<TData> {
|
|
181
|
+
table: Table<TData>;
|
|
182
|
+
onDeleteSelected?: (rows: TData[]) => void;
|
|
183
|
+
/** 批量更新回调 */
|
|
184
|
+
onUpdateSelected?: (rows: TData[], data: Record<string, unknown>) => void;
|
|
185
|
+
/** 批量更新字段配置 */
|
|
186
|
+
batchUpdateFields?: BatchUpdateField[];
|
|
187
|
+
/** 是否启用导出功能 */
|
|
188
|
+
enableExport?: boolean;
|
|
189
|
+
/** 是否启用删除功能 */
|
|
190
|
+
enableDelete?: boolean;
|
|
191
|
+
/** 额外的操作按钮 */
|
|
192
|
+
extraActions?: React$1.ReactNode;
|
|
193
|
+
}
|
|
194
|
+
declare function AutoTableActionBar<TData>({
|
|
195
|
+
table,
|
|
196
|
+
onDeleteSelected,
|
|
197
|
+
onUpdateSelected,
|
|
198
|
+
batchUpdateFields,
|
|
199
|
+
enableExport,
|
|
200
|
+
enableDelete,
|
|
201
|
+
extraActions
|
|
202
|
+
}: AutoTableActionBarProps<TData>): react_jsx_runtime8.JSX.Element;
|
|
203
|
+
//#endregion
|
|
204
|
+
//#region src/lib/schema-bridge/types.d.ts
|
|
205
|
+
/**
|
|
206
|
+
* 字段类型映射
|
|
207
|
+
*/
|
|
208
|
+
type FieldType = "string" | "number" | "boolean" | "date" | "enum" | "array" | "object";
|
|
209
|
+
/**
|
|
210
|
+
* DataTable Filter Variant
|
|
211
|
+
*/
|
|
212
|
+
type FilterVariant = "text" | "number" | "boolean" | "select" | "multiSelect" | "date" | "dateRange" | "range";
|
|
213
|
+
/**
|
|
214
|
+
* 解析后的 Zod 字段信息
|
|
215
|
+
*/
|
|
216
|
+
interface ParsedZodField {
|
|
217
|
+
type: FieldType;
|
|
218
|
+
required: boolean;
|
|
219
|
+
enumValues?: string[];
|
|
220
|
+
description?: string;
|
|
221
|
+
defaultValue?: unknown;
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* 列定义覆盖选项
|
|
225
|
+
*/
|
|
226
|
+
type ColumnOverrides<T> = Partial<{ [K in keyof T]: Partial<ColumnDef<T, unknown>> & {
|
|
227
|
+
hidden?: boolean;
|
|
228
|
+
label?: string;
|
|
229
|
+
} }>;
|
|
230
|
+
/**
|
|
231
|
+
* Formily Schema 覆盖选项
|
|
232
|
+
*/
|
|
233
|
+
type FormSchemaOverrides = Record<string, Partial<ISchema>>;
|
|
234
|
+
/**
|
|
235
|
+
* createColumns 选项
|
|
236
|
+
*/
|
|
237
|
+
interface CreateColumnsOptions<T> {
|
|
238
|
+
overrides?: ColumnOverrides<T>;
|
|
239
|
+
exclude?: (keyof T)[];
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* createFormSchema 选项
|
|
243
|
+
*/
|
|
244
|
+
interface CreateFormSchemaOptions {
|
|
245
|
+
overrides?: FormSchemaOverrides;
|
|
246
|
+
exclude?: string[];
|
|
247
|
+
layout?: "vertical" | "horizontal" | "grid";
|
|
248
|
+
gridColumns?: number;
|
|
249
|
+
/** Label 对齐方式 */
|
|
250
|
+
labelAlign?: "left" | "top" | "right";
|
|
251
|
+
/** Label 宽度(labelAlign 为 left 时有效) */
|
|
252
|
+
labelWidth?: number | string;
|
|
253
|
+
/** Label 栅格占位 */
|
|
254
|
+
labelCol?: number;
|
|
255
|
+
/** 输入框栅格占位 */
|
|
256
|
+
wrapperCol?: number;
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Enum 选项类型
|
|
260
|
+
*/
|
|
261
|
+
interface EnumOption {
|
|
262
|
+
label: string;
|
|
263
|
+
value: string;
|
|
264
|
+
}
|
|
265
|
+
//#endregion
|
|
266
|
+
//#region src/lib/schema-bridge/zod-to-columns.d.ts
|
|
267
|
+
/**
|
|
268
|
+
* 解析 Zod 字段类型
|
|
269
|
+
*/
|
|
270
|
+
declare function parseZodField(schema: z.ZodType): ParsedZodField;
|
|
271
|
+
/**
|
|
272
|
+
* 从 Zod Schema 创建 ColumnDef 数组
|
|
273
|
+
*/
|
|
274
|
+
declare function createColumns<T extends z.ZodObject<z.ZodRawShape>>(schema: T, options?: CreateColumnsOptions<z.infer<T>>): ColumnDef<z.infer<T>>[];
|
|
275
|
+
/**
|
|
276
|
+
* 创建选择列
|
|
277
|
+
*/
|
|
278
|
+
declare function createSelectColumn<T>(): ColumnDef<T>;
|
|
279
|
+
/**
|
|
280
|
+
* 操作列配置
|
|
281
|
+
*/
|
|
282
|
+
interface ActionsColumnConfig<T> {
|
|
283
|
+
onEdit?: (row: T) => void;
|
|
284
|
+
onDelete?: (row: T) => void;
|
|
285
|
+
onView?: (row: T) => void;
|
|
286
|
+
onCopy?: (row: T) => void;
|
|
287
|
+
}
|
|
288
|
+
/**
|
|
289
|
+
* 创建操作列
|
|
290
|
+
*/
|
|
291
|
+
declare function createActionsColumn<T>(config: ActionsColumnConfig<T>): ColumnDef<T>;
|
|
292
|
+
//#endregion
|
|
293
|
+
//#region src/components/auto-crud/auto-table.d.ts
|
|
294
|
+
/** 过滤模式类型 */
|
|
295
|
+
type FilterMode = "simple" | "advanced" | "command";
|
|
296
|
+
interface AutoTableProps<T extends z.ZodObject<z.ZodRawShape>> {
|
|
297
|
+
schema: T;
|
|
298
|
+
data: z.infer<T>[];
|
|
299
|
+
pageCount?: number;
|
|
300
|
+
overrides?: ColumnOverrides<z.infer<T>>;
|
|
301
|
+
enableRowSelection?: boolean;
|
|
302
|
+
exclude?: (keyof z.infer<T>)[];
|
|
303
|
+
actions?: ActionsColumnConfig<z.infer<T>>;
|
|
304
|
+
/** 自定义固定列配置 */
|
|
305
|
+
pinnedColumns?: {
|
|
306
|
+
left?: string[];
|
|
307
|
+
right?: string[];
|
|
308
|
+
};
|
|
309
|
+
/**
|
|
310
|
+
* 过滤模式配置
|
|
311
|
+
* - 单个值: 只使用该模式,不显示切换按钮
|
|
312
|
+
* - 数组: 第一个为默认值,显示切换按钮
|
|
313
|
+
* 默认: ["simple", "advanced", "command"] (全部显示)
|
|
314
|
+
*/
|
|
315
|
+
filterMode?: FilterMode | FilterMode[];
|
|
316
|
+
/** 批量删除回调 */
|
|
317
|
+
onDeleteSelected?: (rows: z.infer<T>[]) => void;
|
|
318
|
+
/** 批量更新回调 */
|
|
319
|
+
onUpdateSelected?: (rows: z.infer<T>[], data: Record<string, unknown>) => void;
|
|
320
|
+
/** 批量更新字段配置 */
|
|
321
|
+
batchUpdateFields?: BatchUpdateField[];
|
|
322
|
+
/** 批量操作栏额外按钮 */
|
|
323
|
+
actionBarExtra?: React.ReactNode;
|
|
324
|
+
/** 初始排序 */
|
|
325
|
+
initialSorting?: any[];
|
|
326
|
+
}
|
|
327
|
+
declare function AutoTable<T extends z.ZodObject<z.ZodRawShape>>({
|
|
328
|
+
schema,
|
|
329
|
+
data,
|
|
330
|
+
pageCount,
|
|
331
|
+
overrides,
|
|
332
|
+
enableRowSelection,
|
|
333
|
+
exclude,
|
|
334
|
+
actions,
|
|
335
|
+
pinnedColumns,
|
|
336
|
+
filterMode,
|
|
337
|
+
onDeleteSelected,
|
|
338
|
+
onUpdateSelected,
|
|
339
|
+
batchUpdateFields,
|
|
340
|
+
actionBarExtra,
|
|
341
|
+
initialSorting
|
|
342
|
+
}: AutoTableProps<T>): react_jsx_runtime8.JSX.Element;
|
|
343
|
+
//#endregion
|
|
344
|
+
//#region src/components/auto-crud/auto-crud-table.d.ts
|
|
345
|
+
/**
|
|
346
|
+
* 统一字段配置
|
|
347
|
+
* 支持共用配置 + 表格/表单特定配置
|
|
348
|
+
*/
|
|
349
|
+
interface Field {
|
|
350
|
+
/** 字段标签(表格和表单共用) */
|
|
351
|
+
label?: string;
|
|
352
|
+
/** 是否隐藏(表格和表单都隐藏) */
|
|
353
|
+
hidden?: boolean;
|
|
354
|
+
/** 表格特定配置 */
|
|
355
|
+
table?: {
|
|
356
|
+
/** 是否在表格中隐藏 */
|
|
357
|
+
hidden?: boolean;
|
|
358
|
+
/** 筛选器配置 */
|
|
359
|
+
meta?: Record<string, unknown>;
|
|
360
|
+
/** 其他列配置 */
|
|
361
|
+
[key: string]: unknown;
|
|
362
|
+
};
|
|
363
|
+
/** 表单特定配置 */
|
|
364
|
+
form?: {
|
|
365
|
+
/** 是否在表单中隐藏 */
|
|
366
|
+
"x-hidden"?: boolean;
|
|
367
|
+
/** 组件类型 */
|
|
368
|
+
"x-component"?: string;
|
|
369
|
+
/** 组件属性 */
|
|
370
|
+
"x-component-props"?: Record<string, unknown>;
|
|
371
|
+
/** 其他表单配置 */
|
|
372
|
+
[key: string]: unknown;
|
|
373
|
+
};
|
|
374
|
+
}
|
|
375
|
+
type Fields = Record<string, Field>;
|
|
376
|
+
/**
|
|
377
|
+
* AutoCrudTable Props 接口
|
|
378
|
+
*/
|
|
379
|
+
interface AutoCrudTableProps<TSchema extends z.ZodObject<z.ZodRawShape>> {
|
|
380
|
+
/** 页面标题 */
|
|
381
|
+
title?: string;
|
|
382
|
+
/** 页面描述 */
|
|
383
|
+
description?: string;
|
|
384
|
+
/** Zod schema */
|
|
385
|
+
schema: TSchema;
|
|
386
|
+
/** useAutoCrudResource hook 返回值 */
|
|
387
|
+
resource: UseAutoCrudResourceReturn<TSchema, z.output<TSchema>>;
|
|
388
|
+
/**
|
|
389
|
+
* 统一字段配置
|
|
390
|
+
* 支持共用配置(label, hidden)+ 表格/表单特定配置
|
|
391
|
+
*/
|
|
392
|
+
fields?: Fields;
|
|
393
|
+
/** 表格配置 */
|
|
394
|
+
table?: {
|
|
395
|
+
/** 隐藏的列 */
|
|
396
|
+
hidden?: string[];
|
|
397
|
+
/** 列覆盖配置 */
|
|
398
|
+
overrides?: Record<string, any>;
|
|
399
|
+
/**
|
|
400
|
+
* 过滤模式配置
|
|
401
|
+
* - 单个值: 只使用该模式,不显示切换按钮
|
|
402
|
+
* - 数组: 第一个为默认值,显示切换按钮
|
|
403
|
+
*/
|
|
404
|
+
filterModes?: FilterMode | FilterMode[];
|
|
405
|
+
/**
|
|
406
|
+
* 批量更新字段配置
|
|
407
|
+
* - 只需传字段名数组,options 自动从 schema enum 推导
|
|
408
|
+
* - 也可以传完整配置覆盖 label 或 options
|
|
409
|
+
*/
|
|
410
|
+
batchFields?: (string | BatchUpdateField)[];
|
|
411
|
+
/** 默认排序 */
|
|
412
|
+
defaultSort?: any[];
|
|
413
|
+
};
|
|
414
|
+
/** 表单配置 */
|
|
415
|
+
form?: {
|
|
416
|
+
/** 表单覆盖配置 */
|
|
417
|
+
overrides?: Record<string, any>;
|
|
418
|
+
/** 表单列数 */
|
|
419
|
+
columns?: number;
|
|
420
|
+
};
|
|
421
|
+
/** 扩展点 */
|
|
422
|
+
slots?: {
|
|
423
|
+
/** 工具栏左侧插槽 */
|
|
424
|
+
toolbarStart?: React.ReactNode;
|
|
425
|
+
/** 工具栏右侧插槽 */
|
|
426
|
+
toolbarEnd?: React.ReactNode;
|
|
427
|
+
/** 自定义行操作 */
|
|
428
|
+
rowActions?: (row: z.output<TSchema>) => Array<{
|
|
429
|
+
label: string;
|
|
430
|
+
onClick: () => void;
|
|
431
|
+
}>;
|
|
432
|
+
};
|
|
433
|
+
}
|
|
434
|
+
/**
|
|
435
|
+
* AutoCrudTable 组件
|
|
436
|
+
*
|
|
437
|
+
* 高级 CRUD 表格组件,封装了完整的增删改查流程
|
|
438
|
+
*/
|
|
439
|
+
declare function AutoCrudTable<TSchema extends z.ZodObject<z.ZodRawShape>>({
|
|
440
|
+
title,
|
|
441
|
+
description,
|
|
442
|
+
schema,
|
|
443
|
+
resource,
|
|
444
|
+
fields,
|
|
445
|
+
table: tableConfig,
|
|
446
|
+
form: formConfig,
|
|
447
|
+
slots
|
|
448
|
+
}: AutoCrudTableProps<TSchema>): react_jsx_runtime8.JSX.Element;
|
|
449
|
+
//#endregion
|
|
450
|
+
//#region src/components/auto-crud/auto-form.d.ts
|
|
451
|
+
interface AutoFormProps<T extends z.ZodObject<z.ZodRawShape>> {
|
|
452
|
+
schema: T;
|
|
453
|
+
initialValues?: Partial<z.infer<T>>;
|
|
454
|
+
onSubmit: (values: z.infer<T>) => void | Promise<void>;
|
|
455
|
+
overrides?: FormSchemaOverrides;
|
|
456
|
+
mode?: "create" | "edit";
|
|
457
|
+
loading?: boolean;
|
|
458
|
+
gridColumns?: number;
|
|
459
|
+
/** Label 对齐方式 */
|
|
460
|
+
labelAlign?: "left" | "top" | "right";
|
|
461
|
+
/** Label 宽度(labelAlign 为 left 时有效) */
|
|
462
|
+
labelWidth?: number | string;
|
|
463
|
+
/** 是否显示提交按钮(默认 true) */
|
|
464
|
+
showSubmitButton?: boolean;
|
|
465
|
+
}
|
|
466
|
+
interface AutoFormRef {
|
|
467
|
+
submit: () => Promise<void>;
|
|
468
|
+
}
|
|
469
|
+
declare function AutoFormInner<T extends z.ZodObject<z.ZodRawShape>>({
|
|
470
|
+
schema: zodSchema,
|
|
471
|
+
initialValues,
|
|
472
|
+
onSubmit,
|
|
473
|
+
overrides,
|
|
474
|
+
mode,
|
|
475
|
+
loading,
|
|
476
|
+
gridColumns,
|
|
477
|
+
labelAlign,
|
|
478
|
+
labelWidth,
|
|
479
|
+
showSubmitButton
|
|
480
|
+
}: AutoFormProps<T>, ref: React.Ref<AutoFormRef>): react_jsx_runtime8.JSX.Element;
|
|
481
|
+
declare const AutoForm: <T extends z.ZodObject<z.ZodRawShape>>(props: AutoFormProps<T> & {
|
|
482
|
+
ref?: React.Ref<AutoFormRef>;
|
|
483
|
+
}) => ReturnType<typeof AutoFormInner>;
|
|
484
|
+
//#endregion
|
|
485
|
+
//#region src/config/data-table.d.ts
|
|
486
|
+
type DataTableConfig = typeof dataTableConfig;
|
|
487
|
+
declare const dataTableConfig: {
|
|
488
|
+
textOperators: ({
|
|
489
|
+
label: string;
|
|
490
|
+
value: "iLike";
|
|
491
|
+
} | {
|
|
492
|
+
label: string;
|
|
493
|
+
value: "notILike";
|
|
494
|
+
} | {
|
|
495
|
+
label: string;
|
|
496
|
+
value: "eq";
|
|
497
|
+
} | {
|
|
498
|
+
label: string;
|
|
499
|
+
value: "ne";
|
|
500
|
+
} | {
|
|
501
|
+
label: string;
|
|
502
|
+
value: "isEmpty";
|
|
503
|
+
} | {
|
|
504
|
+
label: string;
|
|
505
|
+
value: "isNotEmpty";
|
|
506
|
+
})[];
|
|
507
|
+
numericOperators: ({
|
|
508
|
+
label: string;
|
|
509
|
+
value: "eq";
|
|
510
|
+
} | {
|
|
511
|
+
label: string;
|
|
512
|
+
value: "ne";
|
|
513
|
+
} | {
|
|
514
|
+
label: string;
|
|
515
|
+
value: "lt";
|
|
516
|
+
} | {
|
|
517
|
+
label: string;
|
|
518
|
+
value: "lte";
|
|
519
|
+
} | {
|
|
520
|
+
label: string;
|
|
521
|
+
value: "gt";
|
|
522
|
+
} | {
|
|
523
|
+
label: string;
|
|
524
|
+
value: "gte";
|
|
525
|
+
} | {
|
|
526
|
+
label: string;
|
|
527
|
+
value: "isBetween";
|
|
528
|
+
} | {
|
|
529
|
+
label: string;
|
|
530
|
+
value: "isEmpty";
|
|
531
|
+
} | {
|
|
532
|
+
label: string;
|
|
533
|
+
value: "isNotEmpty";
|
|
534
|
+
})[];
|
|
535
|
+
dateOperators: ({
|
|
536
|
+
label: string;
|
|
537
|
+
value: "eq";
|
|
538
|
+
} | {
|
|
539
|
+
label: string;
|
|
540
|
+
value: "ne";
|
|
541
|
+
} | {
|
|
542
|
+
label: string;
|
|
543
|
+
value: "lt";
|
|
544
|
+
} | {
|
|
545
|
+
label: string;
|
|
546
|
+
value: "gt";
|
|
547
|
+
} | {
|
|
548
|
+
label: string;
|
|
549
|
+
value: "lte";
|
|
550
|
+
} | {
|
|
551
|
+
label: string;
|
|
552
|
+
value: "gte";
|
|
553
|
+
} | {
|
|
554
|
+
label: string;
|
|
555
|
+
value: "isBetween";
|
|
556
|
+
} | {
|
|
557
|
+
label: string;
|
|
558
|
+
value: "isRelativeToToday";
|
|
559
|
+
} | {
|
|
560
|
+
label: string;
|
|
561
|
+
value: "isEmpty";
|
|
562
|
+
} | {
|
|
563
|
+
label: string;
|
|
564
|
+
value: "isNotEmpty";
|
|
565
|
+
})[];
|
|
566
|
+
selectOperators: ({
|
|
567
|
+
label: string;
|
|
568
|
+
value: "eq";
|
|
569
|
+
} | {
|
|
570
|
+
label: string;
|
|
571
|
+
value: "ne";
|
|
572
|
+
} | {
|
|
573
|
+
label: string;
|
|
574
|
+
value: "isEmpty";
|
|
575
|
+
} | {
|
|
576
|
+
label: string;
|
|
577
|
+
value: "isNotEmpty";
|
|
578
|
+
})[];
|
|
579
|
+
multiSelectOperators: ({
|
|
580
|
+
label: string;
|
|
581
|
+
value: "inArray";
|
|
582
|
+
} | {
|
|
583
|
+
label: string;
|
|
584
|
+
value: "notInArray";
|
|
585
|
+
} | {
|
|
586
|
+
label: string;
|
|
587
|
+
value: "isEmpty";
|
|
588
|
+
} | {
|
|
589
|
+
label: string;
|
|
590
|
+
value: "isNotEmpty";
|
|
591
|
+
})[];
|
|
592
|
+
booleanOperators: ({
|
|
593
|
+
label: string;
|
|
594
|
+
value: "eq";
|
|
595
|
+
} | {
|
|
596
|
+
label: string;
|
|
597
|
+
value: "ne";
|
|
598
|
+
})[];
|
|
599
|
+
sortOrders: ({
|
|
600
|
+
label: string;
|
|
601
|
+
value: "asc";
|
|
602
|
+
} | {
|
|
603
|
+
label: string;
|
|
604
|
+
value: "desc";
|
|
605
|
+
})[];
|
|
606
|
+
filterVariants: readonly ["text", "number", "range", "date", "dateRange", "boolean", "select", "multiSelect"];
|
|
607
|
+
operators: readonly ["iLike", "notILike", "eq", "ne", "inArray", "notInArray", "isEmpty", "isNotEmpty", "lt", "lte", "gt", "gte", "isBetween", "isRelativeToToday"];
|
|
608
|
+
joinOperators: readonly ["and", "or"];
|
|
609
|
+
};
|
|
610
|
+
//#endregion
|
|
611
|
+
//#region src/hooks/use-url-state.d.ts
|
|
612
|
+
/**
|
|
613
|
+
* URL 状态管理 Hook - 替代 nuqs
|
|
614
|
+
* 将 React 状态同步到 URL query string
|
|
615
|
+
*
|
|
616
|
+
* 架构说明:
|
|
617
|
+
* - 使用 queueMicrotask 延迟 URL 更新,确保在渲染完成后执行
|
|
618
|
+
* - 符合 React 渲染规则,不会触发 "Cannot update a component while rendering" 错误
|
|
619
|
+
*/
|
|
620
|
+
interface UrlStateOptions {
|
|
621
|
+
/** 历史记录模式: push 添加新记录, replace 替换当前记录 */
|
|
622
|
+
history?: "push" | "replace";
|
|
623
|
+
/** 是否浅层更新(不触发页面刷新) */
|
|
624
|
+
shallow?: boolean;
|
|
625
|
+
/** 节流时间(毫秒) */
|
|
626
|
+
throttleMs?: number;
|
|
627
|
+
/** 防抖时间(毫秒) */
|
|
628
|
+
debounceMs?: number;
|
|
629
|
+
/** 当值等于默认值时是否清除 URL 参数 */
|
|
630
|
+
clearOnDefault?: boolean;
|
|
631
|
+
/** 滚动到顶部 */
|
|
632
|
+
scroll?: boolean;
|
|
633
|
+
/** React transition */
|
|
634
|
+
startTransition?: React$1.TransitionStartFunction;
|
|
635
|
+
}
|
|
636
|
+
interface Parser<T> {
|
|
637
|
+
parse: (value: string) => T;
|
|
638
|
+
serialize: (value: T) => string;
|
|
639
|
+
}
|
|
640
|
+
declare const parseAsInteger: Parser<number> & {
|
|
641
|
+
withDefault: (defaultValue: number) => Parser<number> & {
|
|
642
|
+
defaultValue: number;
|
|
643
|
+
};
|
|
644
|
+
};
|
|
645
|
+
declare const parseAsString: Parser<string> & {
|
|
646
|
+
withDefault: (defaultValue: string) => Parser<string> & {
|
|
647
|
+
defaultValue: string;
|
|
648
|
+
};
|
|
649
|
+
};
|
|
650
|
+
declare function parseAsStringEnum<T extends string>(validValues: readonly T[]): Parser<T | null> & {
|
|
651
|
+
withDefault: (defaultValue: T) => Parser<T> & {
|
|
652
|
+
defaultValue: T;
|
|
653
|
+
};
|
|
654
|
+
};
|
|
655
|
+
declare function parseAsArrayOf<T>(itemParser: Parser<T>, separator?: string): Parser<T[]> & {
|
|
656
|
+
withDefault: (defaultValue: T[]) => Parser<T[]> & {
|
|
657
|
+
defaultValue: T[];
|
|
658
|
+
};
|
|
659
|
+
};
|
|
660
|
+
declare function getUrlParams(): URLSearchParams;
|
|
661
|
+
declare function setSearchParams(params: URLSearchParams, options?: Pick<UrlStateOptions, "history" | "scroll">): void;
|
|
662
|
+
/**
|
|
663
|
+
* 单个 URL 状态参数
|
|
664
|
+
*/
|
|
665
|
+
declare function useUrlState<T>(key: string, parser: Parser<T> & {
|
|
666
|
+
defaultValue?: T;
|
|
667
|
+
}, options?: UrlStateOptions): [T, (value: T | ((prev: T) => T)) => void];
|
|
668
|
+
/**
|
|
669
|
+
* 多个 URL 状态参数
|
|
670
|
+
*/
|
|
671
|
+
declare function useUrlStates<T extends Record<string, unknown>>(parsers: { [K in keyof T]: Parser<T[K]> & {
|
|
672
|
+
defaultValue?: T[K];
|
|
673
|
+
} }, options?: UrlStateOptions): [T, (values: Partial<T>) => void];
|
|
674
|
+
/**
|
|
675
|
+
* nuqs 兼容层 - useQueryState
|
|
676
|
+
*/
|
|
677
|
+
declare function useQueryState<T>(key: string, parser: Parser<T> & {
|
|
678
|
+
defaultValue?: T;
|
|
679
|
+
}, options?: UrlStateOptions): [T, (value: T | ((prev: T) => T)) => Promise<URLSearchParams>];
|
|
680
|
+
/**
|
|
681
|
+
* nuqs 兼容层 - useQueryStates
|
|
682
|
+
*/
|
|
683
|
+
declare function useQueryStates<T extends Record<string, unknown>>(parsers: { [K in keyof T]: Parser<T[K]> & {
|
|
684
|
+
defaultValue?: T[K];
|
|
685
|
+
} }, options?: UrlStateOptions): [T, (values: Partial<T>) => Promise<URLSearchParams>];
|
|
686
|
+
//#endregion
|
|
687
|
+
//#region src/lib/parsers.d.ts
|
|
688
|
+
declare const filterItemSchema: z.ZodObject<{
|
|
689
|
+
id: z.ZodString;
|
|
690
|
+
value: z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>;
|
|
691
|
+
variant: z.ZodEnum<{
|
|
692
|
+
number: "number";
|
|
693
|
+
boolean: "boolean";
|
|
694
|
+
text: "text";
|
|
695
|
+
range: "range";
|
|
696
|
+
date: "date";
|
|
697
|
+
dateRange: "dateRange";
|
|
698
|
+
select: "select";
|
|
699
|
+
multiSelect: "multiSelect";
|
|
700
|
+
}>;
|
|
701
|
+
operator: z.ZodEnum<{
|
|
702
|
+
iLike: "iLike";
|
|
703
|
+
notILike: "notILike";
|
|
704
|
+
eq: "eq";
|
|
705
|
+
ne: "ne";
|
|
706
|
+
isEmpty: "isEmpty";
|
|
707
|
+
isNotEmpty: "isNotEmpty";
|
|
708
|
+
lt: "lt";
|
|
709
|
+
lte: "lte";
|
|
710
|
+
gt: "gt";
|
|
711
|
+
gte: "gte";
|
|
712
|
+
isBetween: "isBetween";
|
|
713
|
+
isRelativeToToday: "isRelativeToToday";
|
|
714
|
+
inArray: "inArray";
|
|
715
|
+
notInArray: "notInArray";
|
|
716
|
+
}>;
|
|
717
|
+
filterId: z.ZodString;
|
|
718
|
+
}, z.core.$strip>;
|
|
719
|
+
type FilterItemSchema = z.infer<typeof filterItemSchema>;
|
|
720
|
+
//#endregion
|
|
721
|
+
//#region src/types/data-table.d.ts
|
|
722
|
+
declare module "@tanstack/react-table" {
|
|
723
|
+
interface TableMeta<TData extends RowData> {
|
|
724
|
+
queryKeys?: QueryKeys;
|
|
725
|
+
}
|
|
726
|
+
interface ColumnMeta<TData extends RowData, TValue> {
|
|
727
|
+
label?: string;
|
|
728
|
+
placeholder?: string;
|
|
729
|
+
variant?: FilterVariant$1;
|
|
730
|
+
options?: Option[];
|
|
731
|
+
range?: [number, number];
|
|
732
|
+
unit?: string;
|
|
733
|
+
icon?: React.FC<React.SVGProps<SVGSVGElement>>;
|
|
734
|
+
}
|
|
735
|
+
}
|
|
736
|
+
interface QueryKeys {
|
|
737
|
+
page: string;
|
|
738
|
+
perPage: string;
|
|
739
|
+
sort: string;
|
|
740
|
+
filters: string;
|
|
741
|
+
joinOperator: string;
|
|
742
|
+
}
|
|
743
|
+
interface Option {
|
|
744
|
+
label: string;
|
|
745
|
+
value: string;
|
|
746
|
+
count?: number;
|
|
747
|
+
icon?: React.FC<React.SVGProps<SVGSVGElement>>;
|
|
748
|
+
}
|
|
749
|
+
type FilterOperator = DataTableConfig["operators"][number];
|
|
750
|
+
type FilterVariant$1 = DataTableConfig["filterVariants"][number];
|
|
751
|
+
type JoinOperator = DataTableConfig["joinOperators"][number];
|
|
752
|
+
interface ExtendedColumnSort<TData> extends Omit<ColumnSort, "id"> {
|
|
753
|
+
id: Extract<keyof TData, string>;
|
|
754
|
+
}
|
|
755
|
+
interface ExtendedColumnFilter<TData> extends FilterItemSchema {
|
|
756
|
+
id: Extract<keyof TData, string>;
|
|
757
|
+
}
|
|
758
|
+
interface DataTableRowAction<TData> {
|
|
759
|
+
row: Row<TData>;
|
|
760
|
+
variant: "update" | "delete";
|
|
761
|
+
}
|
|
762
|
+
//#endregion
|
|
763
|
+
//#region src/components/auto-crud/auto-table-simple-filters.d.ts
|
|
764
|
+
interface AutoTableSimpleFiltersProps<TData> {
|
|
765
|
+
table: Table<TData>;
|
|
766
|
+
shallow?: boolean;
|
|
767
|
+
filters?: ExtendedColumnFilter<TData>[];
|
|
768
|
+
onFiltersChange?: (filters: ExtendedColumnFilter<TData>[]) => void;
|
|
769
|
+
}
|
|
770
|
+
declare function AutoTableSimpleFilters<TData>({
|
|
771
|
+
table,
|
|
772
|
+
shallow,
|
|
773
|
+
filters: externalFilters,
|
|
774
|
+
onFiltersChange
|
|
775
|
+
}: AutoTableSimpleFiltersProps<TData>): react_jsx_runtime8.JSX.Element | null;
|
|
776
|
+
//#endregion
|
|
777
|
+
//#region src/components/auto-crud/form-modal.d.ts
|
|
778
|
+
type ModalVariant = "dialog" | "sheet";
|
|
779
|
+
//#endregion
|
|
780
|
+
//#region src/components/auto-crud/crud-form-modal.d.ts
|
|
781
|
+
interface CrudFormModalProps<T extends z.ZodObject<z.ZodRawShape>> {
|
|
782
|
+
open: boolean;
|
|
783
|
+
onOpenChange: (open: boolean) => void;
|
|
784
|
+
mode: "create" | "edit";
|
|
785
|
+
schema: T;
|
|
786
|
+
initialValues?: Partial<z.infer<T>>;
|
|
787
|
+
onSubmit: (values: z.infer<T>) => void | Promise<void>;
|
|
788
|
+
loading?: boolean;
|
|
789
|
+
variant?: ModalVariant;
|
|
790
|
+
overrides?: FormSchemaOverrides;
|
|
791
|
+
title?: string;
|
|
792
|
+
/** Label 对齐方式 */
|
|
793
|
+
labelAlign?: "left" | "top" | "right";
|
|
794
|
+
/** Label 宽度(labelAlign 为 left 时有效) */
|
|
795
|
+
labelWidth?: number | string;
|
|
796
|
+
}
|
|
797
|
+
declare function CrudFormModal<T extends z.ZodObject<z.ZodRawShape>>({
|
|
798
|
+
open,
|
|
799
|
+
onOpenChange,
|
|
800
|
+
mode,
|
|
801
|
+
schema,
|
|
802
|
+
initialValues,
|
|
803
|
+
onSubmit,
|
|
804
|
+
loading,
|
|
805
|
+
variant,
|
|
806
|
+
overrides,
|
|
807
|
+
title,
|
|
808
|
+
labelAlign,
|
|
809
|
+
labelWidth
|
|
810
|
+
}: CrudFormModalProps<T>): react_jsx_runtime8.JSX.Element;
|
|
811
|
+
//#endregion
|
|
812
|
+
//#region src/components/data-table/data-table.d.ts
|
|
813
|
+
interface DataTableProps<TData> extends React$1.ComponentProps<"div"> {
|
|
814
|
+
table: Table<TData>;
|
|
815
|
+
actionBar?: React$1.ReactNode;
|
|
816
|
+
}
|
|
817
|
+
declare function DataTable<TData>({
|
|
818
|
+
table,
|
|
819
|
+
actionBar,
|
|
820
|
+
children,
|
|
821
|
+
className,
|
|
822
|
+
...props
|
|
823
|
+
}: DataTableProps<TData>): react_jsx_runtime8.JSX.Element;
|
|
824
|
+
//#endregion
|
|
825
|
+
//#region src/components/data-table/data-table-advanced-toolbar.d.ts
|
|
826
|
+
interface DataTableAdvancedToolbarProps<TData> extends React$1.ComponentProps<"div"> {
|
|
827
|
+
table: Table<TData>;
|
|
828
|
+
}
|
|
829
|
+
declare function DataTableAdvancedToolbar<TData>({
|
|
830
|
+
table,
|
|
831
|
+
children,
|
|
832
|
+
className,
|
|
833
|
+
...props
|
|
834
|
+
}: DataTableAdvancedToolbarProps<TData>): react_jsx_runtime8.JSX.Element;
|
|
835
|
+
//#endregion
|
|
836
|
+
//#region src/components/data-table/data-table-column-header.d.ts
|
|
837
|
+
interface DataTableColumnHeaderProps<TData, TValue> extends React.ComponentProps<typeof DropdownMenuTrigger> {
|
|
838
|
+
column: Column<TData, TValue>;
|
|
839
|
+
label: string;
|
|
840
|
+
}
|
|
841
|
+
declare function DataTableColumnHeader<TData, TValue>({
|
|
842
|
+
column,
|
|
843
|
+
label,
|
|
844
|
+
className,
|
|
845
|
+
...props
|
|
846
|
+
}: DataTableColumnHeaderProps<TData, TValue>): react_jsx_runtime8.JSX.Element;
|
|
847
|
+
//#endregion
|
|
848
|
+
//#region src/components/data-table/data-table-faceted-filter.d.ts
|
|
849
|
+
interface DataTableFacetedFilterProps<TData, TValue> {
|
|
850
|
+
column?: Column<TData, TValue>;
|
|
851
|
+
title?: string;
|
|
852
|
+
options: Option[];
|
|
853
|
+
multiple?: boolean;
|
|
854
|
+
}
|
|
855
|
+
declare function DataTableFacetedFilter<TData, TValue>({
|
|
856
|
+
column,
|
|
857
|
+
title,
|
|
858
|
+
options,
|
|
859
|
+
multiple
|
|
860
|
+
}: DataTableFacetedFilterProps<TData, TValue>): react_jsx_runtime8.JSX.Element;
|
|
861
|
+
//#endregion
|
|
862
|
+
//#region src/components/data-table/data-table-pagination.d.ts
|
|
863
|
+
interface DataTablePaginationProps<TData> extends React.ComponentProps<"div"> {
|
|
864
|
+
table: Table<TData>;
|
|
865
|
+
pageSizeOptions?: number[];
|
|
866
|
+
}
|
|
867
|
+
declare function DataTablePagination<TData>({
|
|
868
|
+
table,
|
|
869
|
+
pageSizeOptions,
|
|
870
|
+
className,
|
|
871
|
+
...props
|
|
872
|
+
}: DataTablePaginationProps<TData>): react_jsx_runtime8.JSX.Element;
|
|
873
|
+
//#endregion
|
|
874
|
+
//#region src/components/data-table/data-table-toolbar.d.ts
|
|
875
|
+
interface DataTableToolbarProps<TData> extends React$1.ComponentProps<"div"> {
|
|
876
|
+
table: Table<TData>;
|
|
877
|
+
}
|
|
878
|
+
declare function DataTableToolbar<TData>({
|
|
879
|
+
table,
|
|
880
|
+
children,
|
|
881
|
+
className,
|
|
882
|
+
...props
|
|
883
|
+
}: DataTableToolbarProps<TData>): react_jsx_runtime8.JSX.Element;
|
|
884
|
+
//#endregion
|
|
885
|
+
//#region src/components/data-table/data-table-view-options.d.ts
|
|
886
|
+
interface DataTableViewOptionsProps<TData> extends React$1.ComponentProps<typeof PopoverContent> {
|
|
887
|
+
table: Table<TData>;
|
|
888
|
+
disabled?: boolean;
|
|
889
|
+
}
|
|
890
|
+
declare function DataTableViewOptions<TData>({
|
|
891
|
+
table,
|
|
892
|
+
disabled,
|
|
893
|
+
...props
|
|
894
|
+
}: DataTableViewOptionsProps<TData>): react_jsx_runtime8.JSX.Element;
|
|
895
|
+
//#endregion
|
|
896
|
+
//#region src/hooks/use-data-table.d.ts
|
|
897
|
+
interface UseDataTableProps<TData> extends Omit<TableOptions<TData>, "state" | "pageCount" | "getCoreRowModel" | "manualFiltering" | "manualPagination" | "manualSorting">, Required<Pick<TableOptions<TData>, "pageCount">> {
|
|
898
|
+
initialState?: Omit<Partial<TableState>, "sorting"> & {
|
|
899
|
+
sorting?: ExtendedColumnSort<TData>[];
|
|
900
|
+
};
|
|
901
|
+
queryKeys?: Partial<QueryKeys>;
|
|
902
|
+
history?: "push" | "replace";
|
|
903
|
+
debounceMs?: number;
|
|
904
|
+
throttleMs?: number;
|
|
905
|
+
clearOnDefault?: boolean;
|
|
906
|
+
enableAdvancedFilter?: boolean;
|
|
907
|
+
scroll?: boolean;
|
|
908
|
+
shallow?: boolean;
|
|
909
|
+
startTransition?: React$1.TransitionStartFunction;
|
|
910
|
+
}
|
|
911
|
+
declare function useDataTable<TData>(props: UseDataTableProps<TData>): {
|
|
912
|
+
table: _tanstack_react_table0.Table<TData>;
|
|
913
|
+
shallow: boolean;
|
|
914
|
+
debounceMs: number;
|
|
915
|
+
throttleMs: number;
|
|
916
|
+
};
|
|
917
|
+
//#endregion
|
|
918
|
+
//#region src/hooks/use-readable-filters.d.ts
|
|
919
|
+
type ColumnLike<TData> = Column<TData> | ColumnDef<TData, unknown> | {
|
|
920
|
+
id?: string;
|
|
921
|
+
accessorKey?: string;
|
|
922
|
+
meta?: {
|
|
923
|
+
variant?: FilterVariant$1;
|
|
924
|
+
};
|
|
925
|
+
};
|
|
926
|
+
interface UseReadableFiltersOptions extends UrlStateOptions {
|
|
927
|
+
debounceMs?: number;
|
|
928
|
+
}
|
|
929
|
+
declare function useReadableFilters<TData>(columns: ColumnLike<TData>[], options?: UseReadableFiltersOptions): [ExtendedColumnFilter<TData>[], (value: ExtendedColumnFilter<TData>[] | ((prev: ExtendedColumnFilter<TData>[]) => ExtendedColumnFilter<TData>[])) => void];
|
|
930
|
+
//#endregion
|
|
931
|
+
//#region src/lib/schema-bridge/zod-to-formily.d.ts
|
|
932
|
+
/**
|
|
933
|
+
* 从 Zod Schema 创建 Formily Schema
|
|
934
|
+
*/
|
|
935
|
+
declare function createFormSchema<T extends z.ZodObject<z.ZodRawShape>>(schema: T, options?: CreateFormSchemaOptions): ISchema;
|
|
936
|
+
/**
|
|
937
|
+
* 为编辑模式创建 Form Schema(排除 id, createdAt, updatedAt)
|
|
938
|
+
*/
|
|
939
|
+
declare function createEditFormSchema<T extends z.ZodObject<z.ZodRawShape>>(schema: T, options?: Omit<CreateFormSchemaOptions, "exclude">): ISchema;
|
|
940
|
+
//#endregion
|
|
941
|
+
//#region src/lib/schema-bridge/schema-adapter.d.ts
|
|
942
|
+
/**
|
|
943
|
+
* 统一的 Schema 类型
|
|
944
|
+
*/
|
|
945
|
+
type UnifiedSchema = z.ZodObject<any> | JSONSchema | SimpleFieldsConfig;
|
|
946
|
+
/**
|
|
947
|
+
* JSON Schema 类型
|
|
948
|
+
*/
|
|
949
|
+
interface JSONSchema {
|
|
950
|
+
type: "object";
|
|
951
|
+
properties: Record<string, JSONSchemaProperty>;
|
|
952
|
+
required?: string[];
|
|
953
|
+
}
|
|
954
|
+
interface JSONSchemaProperty {
|
|
955
|
+
type: "string" | "number" | "boolean" | "array" | "object";
|
|
956
|
+
title?: string;
|
|
957
|
+
description?: string;
|
|
958
|
+
enum?: any[];
|
|
959
|
+
format?: string;
|
|
960
|
+
default?: any;
|
|
961
|
+
minimum?: number;
|
|
962
|
+
maximum?: number;
|
|
963
|
+
minLength?: number;
|
|
964
|
+
maxLength?: number;
|
|
965
|
+
pattern?: string;
|
|
966
|
+
}
|
|
967
|
+
/**
|
|
968
|
+
* 简化字段配置
|
|
969
|
+
*/
|
|
970
|
+
interface SimpleFieldsConfig {
|
|
971
|
+
[key: string]: SimpleFieldConfig;
|
|
972
|
+
}
|
|
973
|
+
interface SimpleFieldConfig {
|
|
974
|
+
type: "string" | "number" | "boolean" | "select" | "multiselect" | "date" | "datetime" | "textarea" | "email" | "url";
|
|
975
|
+
label?: string;
|
|
976
|
+
description?: string;
|
|
977
|
+
required?: boolean;
|
|
978
|
+
default?: any;
|
|
979
|
+
options?: Array<string | {
|
|
980
|
+
label: string;
|
|
981
|
+
value: any;
|
|
982
|
+
}>;
|
|
983
|
+
placeholder?: string;
|
|
984
|
+
min?: number;
|
|
985
|
+
max?: number;
|
|
986
|
+
minLength?: number;
|
|
987
|
+
maxLength?: number;
|
|
988
|
+
pattern?: RegExp;
|
|
989
|
+
}
|
|
990
|
+
/**
|
|
991
|
+
* 内部统一的字段定义
|
|
992
|
+
*/
|
|
993
|
+
interface UnifiedField {
|
|
994
|
+
name: string;
|
|
995
|
+
type: string;
|
|
996
|
+
label?: string;
|
|
997
|
+
description?: string;
|
|
998
|
+
required?: boolean;
|
|
999
|
+
default?: any;
|
|
1000
|
+
validation?: any;
|
|
1001
|
+
options?: Array<{
|
|
1002
|
+
label: string;
|
|
1003
|
+
value: any;
|
|
1004
|
+
}>;
|
|
1005
|
+
component?: string;
|
|
1006
|
+
componentProps?: Record<string, any>;
|
|
1007
|
+
}
|
|
1008
|
+
/**
|
|
1009
|
+
* Schema 适配器 - 将各种格式转换为统一格式
|
|
1010
|
+
*/
|
|
1011
|
+
declare class SchemaAdapter {
|
|
1012
|
+
/**
|
|
1013
|
+
* 检测 Schema 类型
|
|
1014
|
+
*/
|
|
1015
|
+
static detectType(schema: UnifiedSchema): "zod" | "json" | "simple";
|
|
1016
|
+
/**
|
|
1017
|
+
* 转换为统一格式
|
|
1018
|
+
*/
|
|
1019
|
+
static toUnified(schema: UnifiedSchema): UnifiedField[];
|
|
1020
|
+
/**
|
|
1021
|
+
* 从 Zod Schema 转换
|
|
1022
|
+
*/
|
|
1023
|
+
private static fromZod;
|
|
1024
|
+
/**
|
|
1025
|
+
* 从 JSON Schema 转换
|
|
1026
|
+
*/
|
|
1027
|
+
private static fromJSON;
|
|
1028
|
+
/**
|
|
1029
|
+
* 从简化配置转换
|
|
1030
|
+
*/
|
|
1031
|
+
private static fromSimple;
|
|
1032
|
+
/**
|
|
1033
|
+
* 解析 Zod 字段(简化版,复用现有逻辑)
|
|
1034
|
+
*/
|
|
1035
|
+
private static parseZodField;
|
|
1036
|
+
/**
|
|
1037
|
+
* 标准化选项格式
|
|
1038
|
+
*/
|
|
1039
|
+
private static normalizeOptions;
|
|
1040
|
+
/**
|
|
1041
|
+
* 转换为 Formily Schema
|
|
1042
|
+
*/
|
|
1043
|
+
static toFormily(fields: UnifiedField[]): ISchema;
|
|
1044
|
+
}
|
|
1045
|
+
//#endregion
|
|
1046
|
+
//#region src/lib/data-source.d.ts
|
|
1047
|
+
/**
|
|
1048
|
+
* 数据源抽象接口
|
|
1049
|
+
* 支持任意后端实现(REST API, tRPC, GraphQL 等)
|
|
1050
|
+
*/
|
|
1051
|
+
/**
|
|
1052
|
+
* 列表查询参数
|
|
1053
|
+
*/
|
|
1054
|
+
interface ListParams {
|
|
1055
|
+
page: number;
|
|
1056
|
+
perPage: number;
|
|
1057
|
+
sort?: Array<{
|
|
1058
|
+
id: string;
|
|
1059
|
+
desc: boolean;
|
|
1060
|
+
}>;
|
|
1061
|
+
filters?: Array<{
|
|
1062
|
+
id: string;
|
|
1063
|
+
value: any;
|
|
1064
|
+
operator?: string;
|
|
1065
|
+
}>;
|
|
1066
|
+
}
|
|
1067
|
+
/**
|
|
1068
|
+
* 列表查询结果
|
|
1069
|
+
*/
|
|
1070
|
+
interface ListResult<T> {
|
|
1071
|
+
data: T[];
|
|
1072
|
+
total: number;
|
|
1073
|
+
page: number;
|
|
1074
|
+
perPage: number;
|
|
1075
|
+
}
|
|
1076
|
+
/**
|
|
1077
|
+
* 数据源接口
|
|
1078
|
+
*
|
|
1079
|
+
* @example
|
|
1080
|
+
* ```typescript
|
|
1081
|
+
* // 使用自己项目的请求封装
|
|
1082
|
+
* const taskDataSource: DataSource<Task> = {
|
|
1083
|
+
* list: (params) => request.post("/api/tasks/list", params),
|
|
1084
|
+
* get: (id) => request.get(`/api/tasks/${id}`),
|
|
1085
|
+
* create: (data) => request.post("/api/tasks", data),
|
|
1086
|
+
* update: (id, data) => request.put(`/api/tasks/${id}`, data),
|
|
1087
|
+
* delete: (id) => request.delete(`/api/tasks/${id}`),
|
|
1088
|
+
* };
|
|
1089
|
+
* ```
|
|
1090
|
+
*/
|
|
1091
|
+
interface DataSource<T = any> {
|
|
1092
|
+
/**
|
|
1093
|
+
* 列表查询(分页、排序、过滤)
|
|
1094
|
+
*/
|
|
1095
|
+
list(params: ListParams): Promise<ListResult<T>>;
|
|
1096
|
+
/**
|
|
1097
|
+
* 获取单条记录
|
|
1098
|
+
*/
|
|
1099
|
+
get(id: string | number): Promise<T>;
|
|
1100
|
+
/**
|
|
1101
|
+
* 创建记录
|
|
1102
|
+
*/
|
|
1103
|
+
create(data: Partial<T>): Promise<T>;
|
|
1104
|
+
/**
|
|
1105
|
+
* 更新记录
|
|
1106
|
+
*/
|
|
1107
|
+
update(id: string | number, data: Partial<T>): Promise<T>;
|
|
1108
|
+
/**
|
|
1109
|
+
* 删除记录
|
|
1110
|
+
*/
|
|
1111
|
+
delete(id: string | number): Promise<void>;
|
|
1112
|
+
/**
|
|
1113
|
+
* 批量删除(可选)
|
|
1114
|
+
*/
|
|
1115
|
+
deleteMany?(ids: Array<string | number>): Promise<void>;
|
|
1116
|
+
}
|
|
1117
|
+
/**
|
|
1118
|
+
* tRPC 路由适配器
|
|
1119
|
+
* 将 tRPC 路由转换为 DataSource 接口
|
|
1120
|
+
*
|
|
1121
|
+
* @example
|
|
1122
|
+
* ```typescript
|
|
1123
|
+
* import { createTRPCDataSource } from "@wordrhyme/auto-crud";
|
|
1124
|
+
*
|
|
1125
|
+
* const taskDataSource = createTRPCDataSource(trpc.tasks);
|
|
1126
|
+
*
|
|
1127
|
+
* <AutoCrudTable schema={schema} dataSource={taskDataSource} />
|
|
1128
|
+
* ```
|
|
1129
|
+
*/
|
|
1130
|
+
declare function createTRPCDataSource<T = any>(router: any): DataSource<T>;
|
|
1131
|
+
/**
|
|
1132
|
+
* 内存数据源(用于测试/演示)
|
|
1133
|
+
*
|
|
1134
|
+
* @example
|
|
1135
|
+
* ```typescript
|
|
1136
|
+
* const mockDataSource = createMemoryDataSource([
|
|
1137
|
+
* { id: 1, title: "Task 1", status: "todo" },
|
|
1138
|
+
* { id: 2, title: "Task 2", status: "done" },
|
|
1139
|
+
* ]);
|
|
1140
|
+
*
|
|
1141
|
+
* <AutoCrudTable schema={schema} dataSource={mockDataSource} />
|
|
1142
|
+
* ```
|
|
1143
|
+
*/
|
|
1144
|
+
declare function createMemoryDataSource<T extends {
|
|
1145
|
+
id: string | number;
|
|
1146
|
+
}>(initialData?: T[]): DataSource<T>;
|
|
1147
|
+
//#endregion
|
|
1148
|
+
//#region src/lib/utils.d.ts
|
|
1149
|
+
declare function cn(...inputs: ClassValue[]): string;
|
|
1150
|
+
//#endregion
|
|
1151
|
+
//#region src/lib/format.d.ts
|
|
1152
|
+
declare function formatDate(date: Date | string | number | undefined, opts?: Intl.DateTimeFormatOptions): string;
|
|
1153
|
+
//#endregion
|
|
1154
|
+
//#region src/lib/humanize.d.ts
|
|
1155
|
+
/**
|
|
1156
|
+
* 将字符串转为人类可读格式
|
|
1157
|
+
*
|
|
1158
|
+
* @example
|
|
1159
|
+
* humanize("createdAt") // "Created At"
|
|
1160
|
+
* humanize("user_name") // "User Name"
|
|
1161
|
+
* humanize("firstName") // "First Name"
|
|
1162
|
+
*/
|
|
1163
|
+
declare function humanize(str: string): string;
|
|
1164
|
+
//#endregion
|
|
1165
|
+
export { type ActionsColumnConfig, AutoCrudTable, type AutoCrudTableProps, AutoForm, AutoTable, AutoTableActionBar, AutoTableSimpleFilters, type ColumnOverrides, type CreateColumnsOptions, type CreateFormSchemaOptions, CrudFormModal, type CrudHooks, type DataSource, DataTable, DataTableAdvancedToolbar, DataTableColumnHeader, DataTableFacetedFilter, DataTablePagination, DataTableRowAction, DataTableToolbar, DataTableViewOptions, type EnumOption, ExtendedColumnFilter, ExtendedColumnSort, type Field, type FieldType, type Fields, FilterOperator, type FilterVariant, type FormSchemaOverrides, type JSONSchema, type JSONSchemaProperty, JoinOperator, type ListParams, type ListResult, Option, type ParsedZodField, type Parser, QueryKeys, SchemaAdapter, type SimpleFieldConfig, type SimpleFieldsConfig, type ToastAdapter, type UnifiedField, type UnifiedSchema, type UrlStateOptions, type UseAutoCrudResourceOptions, cn, createActionsColumn, createColumns, createEditFormSchema, createFormSchema, createMemoryDataSource, createSelectColumn, createTRPCDataSource, formatDate, getUrlParams, humanize, noopToastAdapter, parseAsArrayOf, parseAsInteger, parseAsString, parseAsStringEnum, parseZodField, setSearchParams, useAutoCrudResource, useDataTable, useQueryState, useQueryStates, useReadableFilters, useUrlState, useUrlStates };
|