@wordrhyme/auto-crud 1.23.0 → 1.23.2
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 +152 -58
- package/dist/index.d.cts +1004 -995
- package/dist/index.d.ts +1003 -994
- package/dist/index.js +153 -59
- package/package.json +4 -4
package/dist/index.d.ts
CHANGED
|
@@ -117,942 +117,154 @@ type AutoCrudSorting = Array<{
|
|
|
117
117
|
desc: boolean;
|
|
118
118
|
}>;
|
|
119
119
|
//#endregion
|
|
120
|
-
//#region src/
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
120
|
+
//#region src/lib/registries.d.ts
|
|
121
|
+
type AutoCrudFormComponentConfig = {
|
|
122
|
+
component: React$1.ComponentType<any>;
|
|
123
|
+
decorator?: string | React$1.ComponentType<any>;
|
|
124
|
+
[key: string]: unknown;
|
|
125
|
+
};
|
|
126
|
+
type AutoCrudOption = {
|
|
127
|
+
value: string;
|
|
128
|
+
label: string;
|
|
129
|
+
searchText?: string | string[];
|
|
130
|
+
keywords?: string[];
|
|
131
|
+
count?: number;
|
|
132
|
+
color?: string;
|
|
133
|
+
disabled?: boolean;
|
|
134
|
+
};
|
|
135
|
+
type AutoCrudDataSourceContextType = 'form' | 'filter' | 'resolve';
|
|
136
|
+
type AutoCrudDataSourceResolveFields = readonly string[] | ((context: {
|
|
137
|
+
field: string;
|
|
138
|
+
}) => readonly string[]);
|
|
139
|
+
type AutoCrudDataSourceContext = {
|
|
140
|
+
field: string;
|
|
141
|
+
type: AutoCrudDataSourceContextType;
|
|
142
|
+
page?: number;
|
|
143
|
+
pageSize?: number;
|
|
144
|
+
query?: string;
|
|
145
|
+
/** @deprecated Use `query` instead. */
|
|
146
|
+
search?: string;
|
|
147
|
+
values?: Record<string, unknown> | Record<string, unknown>[];
|
|
148
|
+
signal?: AbortSignal;
|
|
149
|
+
};
|
|
150
|
+
type AutoCrudDataSourceResult = AutoCrudOption[] | {
|
|
151
|
+
hasMore?: boolean;
|
|
152
|
+
options?: AutoCrudOption[];
|
|
153
|
+
};
|
|
154
|
+
type AutoCrudDataSourceLoader = (context: AutoCrudDataSourceContext) => AutoCrudDataSourceResult | Promise<AutoCrudDataSourceResult>;
|
|
155
|
+
type AutoCrudDataSourceConfig = string;
|
|
156
|
+
type AutoCrudDataSourceRegistration = AutoCrudDataSourceLoader | {
|
|
157
|
+
dependencies?: string[];
|
|
158
|
+
reset?: boolean;
|
|
159
|
+
search?: boolean;
|
|
160
|
+
debounceMs?: number;
|
|
161
|
+
loadMore?: boolean;
|
|
162
|
+
pageSize?: number;
|
|
163
|
+
resolveFields?: AutoCrudDataSourceResolveFields;
|
|
164
|
+
load: AutoCrudDataSourceLoader;
|
|
165
|
+
};
|
|
166
|
+
type AutoCrudDataSourceEntry = {
|
|
167
|
+
dependencies: string[];
|
|
168
|
+
reset: boolean;
|
|
169
|
+
search: boolean;
|
|
170
|
+
debounceMs: number;
|
|
171
|
+
loadMore: boolean;
|
|
172
|
+
pageSize: number;
|
|
173
|
+
resolveFields?: AutoCrudDataSourceResolveFields;
|
|
174
|
+
load: AutoCrudDataSourceLoader;
|
|
175
|
+
};
|
|
176
|
+
type RegistryListener$1 = () => void;
|
|
177
|
+
declare const tablePagination: {
|
|
178
|
+
register(name: string, value: TablePaginationOptions): void;
|
|
179
|
+
unregister(name: string): void;
|
|
180
|
+
get(name: string): TablePaginationOptions | undefined;
|
|
181
|
+
all(): Record<string, TablePaginationOptions>;
|
|
182
|
+
subscribe(listener: RegistryListener$1): () => void;
|
|
183
|
+
};
|
|
184
|
+
declare const formComponents: {
|
|
185
|
+
register(name: string, value: AutoCrudFormComponentConfig): void;
|
|
186
|
+
unregister(name: string): void;
|
|
187
|
+
get(name: string): AutoCrudFormComponentConfig | undefined;
|
|
188
|
+
all(): Record<string, AutoCrudFormComponentConfig>;
|
|
189
|
+
subscribe(listener: RegistryListener$1): () => void;
|
|
190
|
+
};
|
|
191
|
+
declare const components: {
|
|
192
|
+
register(name: string, value: AutoCrudFormComponentConfig): void;
|
|
193
|
+
unregister(name: string): void;
|
|
194
|
+
get(name: string): AutoCrudFormComponentConfig | undefined;
|
|
195
|
+
all(): Record<string, AutoCrudFormComponentConfig>;
|
|
196
|
+
subscribe(listener: RegistryListener$1): () => void;
|
|
197
|
+
};
|
|
198
|
+
declare const dataSources: {
|
|
199
|
+
register(name: string, registration: AutoCrudDataSourceRegistration): void;
|
|
200
|
+
unregister: (name: string) => void;
|
|
201
|
+
get: (name: string) => AutoCrudDataSourceEntry | undefined;
|
|
202
|
+
all: () => Record<string, AutoCrudDataSourceEntry>;
|
|
203
|
+
subscribe: (listener: RegistryListener$1) => () => void;
|
|
204
|
+
};
|
|
205
|
+
declare function normalizeDataSourceConfig(config: AutoCrudDataSourceConfig | undefined): {
|
|
206
|
+
key: string;
|
|
207
|
+
} | undefined;
|
|
208
|
+
declare function normalizeOptions(result: AutoCrudDataSourceResult | undefined): AutoCrudOption[];
|
|
209
|
+
//#endregion
|
|
210
|
+
//#region src/components/auto-crud/auto-crud-provider.d.ts
|
|
211
|
+
interface ViewStorage {
|
|
212
|
+
list: (resourceId: string) => Promise<SavedView[]>;
|
|
213
|
+
create: (resourceId: string, input: ViewInput) => Promise<SavedView>;
|
|
214
|
+
update: (resourceId: string, id: string, input: ViewInput) => Promise<SavedView>;
|
|
215
|
+
remove: (resourceId: string, id: string) => Promise<void>;
|
|
216
|
+
/** Omit to use the adapter's default scope. Empty createScopes disables creation. */
|
|
217
|
+
getCapabilities?: (resourceId: string) => Promise<ViewStorageCapabilities>;
|
|
218
|
+
/** Complete permutation of permitted persisted IDs; other rows keep their slots. The selector uses local preferences. */
|
|
219
|
+
reorder?: (resourceId: string, ids: string[]) => Promise<void>;
|
|
130
220
|
}
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
search?: {
|
|
135
|
-
enabled: boolean;
|
|
136
|
-
fields: string[];
|
|
137
|
-
};
|
|
138
|
-
filters?: {
|
|
139
|
-
enabled: boolean;
|
|
140
|
-
fields: string[] | null;
|
|
141
|
-
};
|
|
142
|
-
sort?: {
|
|
143
|
-
enabled: boolean;
|
|
144
|
-
fields: string[] | null;
|
|
145
|
-
};
|
|
221
|
+
interface TagScope {
|
|
222
|
+
resourceId: string;
|
|
223
|
+
field: string;
|
|
146
224
|
}
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
type ModalVariant$1 = 'dialog' | 'sheet';
|
|
151
|
-
interface ModalState<T> {
|
|
152
|
-
createOpen: boolean;
|
|
153
|
-
editOpen: boolean;
|
|
154
|
-
deleteOpen: boolean;
|
|
155
|
-
viewOpen: boolean;
|
|
156
|
-
selected: T | null;
|
|
157
|
-
/** 复制源数据(用于复制行功能) */
|
|
158
|
-
copySource: T | null;
|
|
159
|
-
variant: ModalVariant$1;
|
|
225
|
+
interface TagInput {
|
|
226
|
+
label: string;
|
|
227
|
+
color: string;
|
|
160
228
|
}
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
* - 返回 true/false = 完全自定义,跳过默认 mutation
|
|
165
|
-
*/
|
|
166
|
-
type HookResult<T> = T | boolean;
|
|
167
|
-
/**
|
|
168
|
-
* 统一的 hooks 配置
|
|
169
|
-
*/
|
|
170
|
-
interface CrudHooks<TSchema extends z.ZodObject<z.ZodRawShape>, TListItem> {
|
|
171
|
-
/**
|
|
172
|
-
* 创建前钩子
|
|
173
|
-
* - 返回对象: 作为转换后的数据,继续执行默认创建
|
|
174
|
-
* - 返回 true: 表示已自定义处理成功,跳过默认创建
|
|
175
|
-
* - 返回 false: 表示自定义处理失败,跳过默认创建
|
|
176
|
-
*/
|
|
177
|
-
beforeCreate?: (values: z.infer<TSchema>) => HookResult<z.infer<TSchema>> | Promise<HookResult<z.infer<TSchema>>>;
|
|
178
|
-
/**
|
|
179
|
-
* 更新前钩子
|
|
180
|
-
* - 返回对象: 作为转换后的数据,继续执行默认更新
|
|
181
|
-
* - 返回 true/false: 完全自定义处理
|
|
182
|
-
*/
|
|
183
|
-
beforeUpdate?: (values: z.infer<TSchema>, original: TListItem) => HookResult<z.infer<TSchema>> | Promise<HookResult<z.infer<TSchema>>>;
|
|
184
|
-
/**
|
|
185
|
-
* 删除前钩子
|
|
186
|
-
* - 返回 true: 表示已自定义处理成功(如软删除)
|
|
187
|
-
* - 返回 false: 表示自定义处理失败
|
|
188
|
-
* - 返回 undefined/void: 继续执行默认删除
|
|
189
|
-
*/
|
|
190
|
-
beforeDelete?: (item: TListItem) => boolean | void | Promise<boolean | void>;
|
|
191
|
-
/** 操作成功回调 */
|
|
192
|
-
onSuccess?: (op: 'create' | 'update' | 'delete', payload: unknown) => void;
|
|
193
|
-
/** 操作失败回调 */
|
|
194
|
-
onError?: (op: 'create' | 'update' | 'delete', error: Error) => void;
|
|
229
|
+
interface TagOption extends TagInput {
|
|
230
|
+
disabled?: boolean;
|
|
231
|
+
value: string;
|
|
195
232
|
}
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
/** 主键字段名(默认: "id") */
|
|
201
|
-
idKey?: keyof TListItem & string;
|
|
202
|
-
/** 默认弹窗模式 */
|
|
203
|
-
defaultVariant?: ModalVariant$1;
|
|
204
|
-
/** 统一钩子配置 */
|
|
205
|
-
hooks?: CrudHooks<TSchema, TListItem>;
|
|
206
|
-
/**
|
|
207
|
-
* Toast 配置
|
|
208
|
-
* - undefined: 使用内置 sonner(默认)
|
|
209
|
-
* - false: 禁用所有通知
|
|
210
|
-
* - ToastAdapter: 注入自定义 toast 实现
|
|
211
|
-
*/
|
|
212
|
-
toast?: ToastAdapter | false;
|
|
213
|
-
/**
|
|
214
|
-
* 自定义导出数据获取函数(escape hatch)
|
|
215
|
-
*
|
|
216
|
-
* 通常不需要传此参数:
|
|
217
|
-
* - 导出选中行:纯客户端,零配置
|
|
218
|
-
* - 导出筛选结果:router 有 export procedure 时自动可用
|
|
219
|
-
*
|
|
220
|
-
* 仅当需要完全自定义导出逻辑时才使用(如队列导出、自定义接口等)
|
|
221
|
-
* 传入后优先级高于 router.export
|
|
222
|
-
*/
|
|
223
|
-
exportFetcher?: (params: any) => Promise<{
|
|
224
|
-
data: Record<string, unknown>[];
|
|
225
|
-
total: number;
|
|
233
|
+
interface TagService {
|
|
234
|
+
/** Search a page of tags; set hasMore to false on the last page. */
|
|
235
|
+
list: (input: TagScope & Pick<AutoCrudDataSourceContext, 'query' | 'page' | 'pageSize' | 'signal'>) => Promise<{
|
|
236
|
+
options: TagOption[];
|
|
226
237
|
hasMore: boolean;
|
|
227
238
|
}>;
|
|
228
|
-
/**
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
239
|
+
/** Resolve all selected IDs; missing IDs remain visible as invalid selections. */
|
|
240
|
+
resolve: (input: TagScope & {
|
|
241
|
+
ids: string[];
|
|
242
|
+
}) => Promise<TagOption[]>;
|
|
243
|
+
create?: (input: TagScope & TagInput) => Promise<TagOption>;
|
|
244
|
+
update?: (input: TagScope & TagInput & {
|
|
245
|
+
id: string;
|
|
246
|
+
}) => Promise<TagOption>;
|
|
247
|
+
remove?: (input: TagScope & {
|
|
248
|
+
id: string;
|
|
249
|
+
}) => Promise<void>;
|
|
250
|
+
/** Add/remove only the specified tags; preserve every other existing tag. */
|
|
251
|
+
assign?: (input: TagScope & {
|
|
252
|
+
entityIds: string[];
|
|
253
|
+
add: string[];
|
|
254
|
+
remove: string[];
|
|
255
|
+
}) => Promise<void>;
|
|
234
256
|
}
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
path: string[];
|
|
242
|
-
message: string;
|
|
243
|
-
params: Record<string, unknown>;
|
|
257
|
+
interface AutoCrudProviderProps {
|
|
258
|
+
/** Change with the signed-in user/tenant; remounts cached UI state. */
|
|
259
|
+
scope: string;
|
|
260
|
+
viewStorage?: ViewStorage;
|
|
261
|
+
tagService?: TagService;
|
|
262
|
+
children: ReactNode;
|
|
244
263
|
}
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
failed: Array<{
|
|
250
|
-
row: number;
|
|
251
|
-
errors: string[];
|
|
252
|
-
issues?: Array<ImportIssue | null>;
|
|
253
|
-
}>;
|
|
254
|
-
}
|
|
255
|
-
/**
|
|
256
|
-
* Hook 返回值类型
|
|
257
|
-
*/
|
|
258
|
-
interface UseAutoCrudResourceReturn<TSchema extends z.ZodObject<z.ZodRawShape>, TListItem> {
|
|
259
|
-
queryKeys?: Partial<QueryKeys>;
|
|
260
|
-
/** Page-local criteria; shared by list and export without entering the URL. */
|
|
261
|
-
batchSearch?: BatchSearchState;
|
|
262
|
-
/** Shared by all filter controls, list queries, and exports. */
|
|
263
|
-
filterState?: TableFilterState<z.output<TSchema>>;
|
|
264
|
-
/** 主键字段名(默认: "id") */
|
|
265
|
-
idKey?: keyof TListItem & string;
|
|
266
|
-
tableData: {
|
|
267
|
-
data: TListItem[];
|
|
268
|
-
pageCount: number;
|
|
269
|
-
/** Total rows matching the current search and filters. */
|
|
270
|
-
total?: number;
|
|
271
|
-
isLoading: boolean;
|
|
272
|
-
/** 是否正在获取数据(用于显示微妙的加载指示器) */
|
|
273
|
-
isFetching: boolean;
|
|
274
|
-
error?: Error | null;
|
|
275
|
-
};
|
|
276
|
-
/** Optional schema override from host metadata. */
|
|
277
|
-
schema?: z.ZodObject<z.ZodRawShape>;
|
|
278
|
-
/** Whether the initial field metadata is still loading. */
|
|
279
|
-
metadataPending?: boolean;
|
|
280
|
-
/** Optional field config override from host metadata. */
|
|
281
|
-
fields?: Fields;
|
|
282
|
-
/** Query capabilities reported by auto-crud-server metadata. */
|
|
283
|
-
capabilities?: AutoCrudQueryCapabilities;
|
|
284
|
-
/** Default sorting used by this resource's list query. */
|
|
285
|
-
defaultSort?: AutoCrudSorting;
|
|
286
|
-
modal: ModalState<TListItem>;
|
|
287
|
-
mutations: {
|
|
288
|
-
isCreating: boolean;
|
|
289
|
-
isUpdating: boolean;
|
|
290
|
-
isDeleting: boolean;
|
|
291
|
-
isImporting: boolean;
|
|
292
|
-
};
|
|
293
|
-
handlers: {
|
|
294
|
-
openCreate: () => void;
|
|
295
|
-
openEdit: (row: TListItem) => void;
|
|
296
|
-
openDelete: (row: TListItem) => void;
|
|
297
|
-
openView: (row: TListItem) => void;
|
|
298
|
-
copyRow: (row: TListItem) => void;
|
|
299
|
-
closeModals: () => void;
|
|
300
|
-
submitCreate: (values: z.infer<TSchema>) => void;
|
|
301
|
-
submitUpdate: (values: z.infer<TSchema>) => void;
|
|
302
|
-
confirmDelete: () => void;
|
|
303
|
-
deleteMany: (rows: TListItem[]) => void;
|
|
304
|
-
updateMany: (rows: TListItem[], data: Record<string, unknown>) => void;
|
|
305
|
-
setVariant: (variant: ModalVariant$1) => void;
|
|
306
|
-
/** 刷新当前列表数据 */
|
|
307
|
-
refresh?: () => Promise<unknown>;
|
|
308
|
-
/** 导入数据(router 有 import 路由时自动可用) */
|
|
309
|
-
import: ((rows: Record<string, unknown>[]) => Promise<ImportResult>) | null;
|
|
310
|
-
/** 导出筛选结果(router 有 export procedure 或传入 exportFetcher 时自动可用)。导出选中行由 AutoCrudTable 内部处理 */
|
|
311
|
-
export: (() => Promise<Record<string, unknown>[]>) | null;
|
|
312
|
-
};
|
|
313
|
-
}
|
|
314
|
-
/**
|
|
315
|
-
* tRPC Router 接口定义(宽松类型以兼容实际 tRPC router)
|
|
316
|
-
* import 为可选 — 传入 router 时自动检测是否存在
|
|
317
|
-
*/
|
|
318
|
-
interface CrudRouter {
|
|
319
|
-
list: {
|
|
320
|
-
useQuery: (input?: any, opts?: any) => any;
|
|
321
|
-
};
|
|
322
|
-
create: {
|
|
323
|
-
useMutation: (opts?: any) => any;
|
|
324
|
-
};
|
|
325
|
-
update: {
|
|
326
|
-
useMutation: (opts?: any) => any;
|
|
327
|
-
};
|
|
328
|
-
delete: {
|
|
329
|
-
useMutation: (opts?: any) => any;
|
|
330
|
-
};
|
|
331
|
-
deleteMany?: {
|
|
332
|
-
useMutation: (opts?: any) => any;
|
|
333
|
-
};
|
|
334
|
-
updateMany?: {
|
|
335
|
-
useMutation: (opts?: any) => any;
|
|
336
|
-
};
|
|
337
|
-
/** 导入路由(mutation,由 createCrudRouter 自动生成) */
|
|
338
|
-
import?: {
|
|
339
|
-
useMutation: (opts?: any) => any;
|
|
340
|
-
};
|
|
341
|
-
/** 导出路由(query,由 createCrudRouter 自动生成) */
|
|
342
|
-
export?: {
|
|
343
|
-
useQuery: (input?: any, opts?: any) => any;
|
|
344
|
-
};
|
|
345
|
-
/** 元数据路由(query,由 createCrudRouter 自动生成) */
|
|
346
|
-
meta?: {
|
|
347
|
-
useQuery: (input?: any, opts?: any) => any;
|
|
348
|
-
};
|
|
349
|
-
}
|
|
350
|
-
/**
|
|
351
|
-
* 自动生成的查询参数(由内部 URL 状态管理生成)
|
|
352
|
-
*/
|
|
353
|
-
interface AutoQueryParams {
|
|
354
|
-
page: number;
|
|
355
|
-
perPage: number;
|
|
356
|
-
sort: Array<{
|
|
357
|
-
id: string;
|
|
358
|
-
desc: boolean;
|
|
359
|
-
}>;
|
|
360
|
-
search?: string;
|
|
361
|
-
filters: any[];
|
|
362
|
-
joinOperator: 'and' | 'or';
|
|
363
|
-
}
|
|
364
|
-
/**
|
|
365
|
-
* Hook 配置参数
|
|
366
|
-
*/
|
|
367
|
-
interface UseAutoCrudResourceParams<TSchema extends z.ZodObject<z.ZodRawShape>, TListItem> {
|
|
368
|
-
/** tRPC router (如 trpc.tasks) */
|
|
369
|
-
router: CrudRouter;
|
|
370
|
-
/** URL keys shared with the table, for multiple resources on one page. */
|
|
371
|
-
queryKeys?: Partial<QueryKeys>;
|
|
372
|
-
/** Zod schema */
|
|
373
|
-
schema: TSchema;
|
|
374
|
-
/** Field filter configuration shared with AutoCrudTable. */
|
|
375
|
-
fields?: Fields;
|
|
376
|
-
/**
|
|
377
|
-
* 查询参数变换函数
|
|
378
|
-
*
|
|
379
|
-
* 默认零配置:hook 内部自动管理 URL 状态(分页、排序、筛选),
|
|
380
|
-
* 传入此函数可注入额外参数或修改自动生成的参数。
|
|
381
|
-
*
|
|
382
|
-
* @example
|
|
383
|
-
* ```tsx
|
|
384
|
-
* // 注入租户 ID
|
|
385
|
-
* query: (params) => ({ ...params, tenantId: currentTenant.id })
|
|
386
|
-
*
|
|
387
|
-
* // 覆盖默认分页
|
|
388
|
-
* query: (params) => ({ ...params, perPage: 20 })
|
|
389
|
-
* ```
|
|
390
|
-
*/
|
|
391
|
-
query?: (params: AutoQueryParams) => Record<string, unknown>;
|
|
392
|
-
/** tRPC operation context shared by list and automatic export requests. */
|
|
393
|
-
queryContext?: Record<string, unknown>;
|
|
394
|
-
/** 其他配置选项 */
|
|
395
|
-
options?: UseAutoCrudResourceOptions<TSchema, TListItem>;
|
|
396
|
-
}
|
|
397
|
-
/**
|
|
398
|
-
* Hook 主函数
|
|
399
|
-
*/
|
|
400
|
-
declare function useAutoCrudResource<TSchema extends z.ZodObject<z.ZodRawShape>, TListItem = z.output<TSchema>>({
|
|
401
|
-
router,
|
|
402
|
-
queryKeys,
|
|
403
|
-
schema,
|
|
404
|
-
query: queryTransform,
|
|
405
|
-
queryContext,
|
|
406
|
-
fields,
|
|
407
|
-
options
|
|
408
|
-
}: UseAutoCrudResourceParams<TSchema, TListItem>): UseAutoCrudResourceReturn<TSchema, TListItem>;
|
|
409
|
-
//#endregion
|
|
410
|
-
//#region src/i18n/locale.d.ts
|
|
411
|
-
/**
|
|
412
|
-
* AutoCrud 国际化接口及内置语言包
|
|
413
|
-
*
|
|
414
|
-
* 使用方式:
|
|
415
|
-
* // 内置语言
|
|
416
|
-
* <AutoCrudTable locale="en-US" ... />
|
|
417
|
-
*
|
|
418
|
-
* // 部分覆盖(以 zh-CN 为基础深合并)
|
|
419
|
-
* <AutoCrudTable locale={{ toolbar: { create: "Add" } }} ... />
|
|
420
|
-
*/
|
|
421
|
-
interface TableControlsLocale {
|
|
422
|
-
sort: {
|
|
423
|
-
label: string;
|
|
424
|
-
title: string;
|
|
425
|
-
empty: string;
|
|
426
|
-
description: string;
|
|
427
|
-
emptyDescription: string;
|
|
428
|
-
add: string;
|
|
429
|
-
reset: string;
|
|
430
|
-
searchFields: string;
|
|
431
|
-
noFields: string;
|
|
432
|
-
ascending: string;
|
|
433
|
-
descending: string;
|
|
434
|
-
direction: string;
|
|
435
|
-
remove: string;
|
|
436
|
-
move: string;
|
|
437
|
-
dragInstructions: string;
|
|
438
|
-
dragOutside: string;
|
|
439
|
-
dragStarted: (label: string, position: number, total: number) => string;
|
|
440
|
-
dragMoved: (label: string, position: number, total: number) => string;
|
|
441
|
-
dragDropped: (label: string, position: number, total: number) => string;
|
|
442
|
-
dragCancelled: (label: string) => string;
|
|
443
|
-
};
|
|
444
|
-
columns: {
|
|
445
|
-
label: string;
|
|
446
|
-
search: string;
|
|
447
|
-
empty: string;
|
|
448
|
-
};
|
|
449
|
-
}
|
|
450
|
-
interface TablePaginationLocale {
|
|
451
|
-
selected: (count: number, total: number) => string;
|
|
452
|
-
total: (count: number) => string;
|
|
453
|
-
rowsPerPage: string;
|
|
454
|
-
page: (page: number, total: number) => string;
|
|
455
|
-
pageJump: string;
|
|
456
|
-
firstPage: string;
|
|
457
|
-
previousPage: string;
|
|
458
|
-
nextPage: string;
|
|
459
|
-
lastPage: string;
|
|
460
|
-
}
|
|
461
|
-
interface TableActionBarLocale {
|
|
462
|
-
selected: (count: number) => string;
|
|
463
|
-
export: string;
|
|
464
|
-
delete: string;
|
|
465
|
-
clearSelection: string;
|
|
466
|
-
}
|
|
467
|
-
interface AutoCrudLocale {
|
|
468
|
-
/** Label shared by automatic tag assignment actions and their dialog. */
|
|
469
|
-
tagAssignment?: (fieldLabel: string) => string;
|
|
470
|
-
batchSearch?: BatchSearchLocale;
|
|
471
|
-
/** Sorting and column visibility controls. Optional for existing custom locales. */
|
|
472
|
-
tableControls?: TableControlsLocale;
|
|
473
|
-
pagination?: Partial<TablePaginationLocale>;
|
|
474
|
-
actionBar?: Partial<TableActionBarLocale>;
|
|
475
|
-
toolbar: {
|
|
476
|
-
refresh: string;
|
|
477
|
-
create: string;
|
|
478
|
-
import: string;
|
|
479
|
-
export: string;
|
|
480
|
-
exportSelected: (count: number) => string;
|
|
481
|
-
};
|
|
482
|
-
rowActions: {
|
|
483
|
-
view: string;
|
|
484
|
-
edit: string;
|
|
485
|
-
copy: string;
|
|
486
|
-
delete: string;
|
|
487
|
-
};
|
|
488
|
-
viewModal: {
|
|
489
|
-
title: string;
|
|
490
|
-
};
|
|
491
|
-
boolean: {
|
|
492
|
-
true: string;
|
|
493
|
-
false: string;
|
|
494
|
-
};
|
|
495
|
-
formModal: {
|
|
496
|
-
createTitle: string;
|
|
497
|
-
editTitle: string;
|
|
498
|
-
cancel: string;
|
|
499
|
-
create: string;
|
|
500
|
-
save: string;
|
|
501
|
-
submitting: string;
|
|
502
|
-
};
|
|
503
|
-
deleteModal: {
|
|
504
|
-
title: string;
|
|
505
|
-
description: string;
|
|
506
|
-
cancel: string;
|
|
507
|
-
confirm: string;
|
|
508
|
-
confirming: string;
|
|
509
|
-
};
|
|
510
|
-
bulkDeleteModal: {
|
|
511
|
-
title: string;
|
|
512
|
-
description: (count: number) => string;
|
|
513
|
-
cancel: string;
|
|
514
|
-
confirm: string;
|
|
515
|
-
};
|
|
516
|
-
importDialog: {
|
|
517
|
-
title: string;
|
|
518
|
-
uploadDescription: string;
|
|
519
|
-
previewDescription: (count: number) => string;
|
|
520
|
-
importingDescription: string;
|
|
521
|
-
doneDescription: string;
|
|
522
|
-
dragHint: string;
|
|
523
|
-
formatHint: string;
|
|
524
|
-
downloadTemplate: string;
|
|
525
|
-
moreColumns: (count: number) => string;
|
|
526
|
-
previewSummary: (rows: number, fields: number, format: string, previewLimit?: number) => string;
|
|
527
|
-
reselect: string;
|
|
528
|
-
confirmImport: string;
|
|
529
|
-
importingRows: (count: number) => string;
|
|
530
|
-
resultCreated: string;
|
|
531
|
-
resultUpdated: string;
|
|
532
|
-
resultSkipped: string;
|
|
533
|
-
resultFailed: string;
|
|
534
|
-
failedRowHeader: string;
|
|
535
|
-
failedErrorHeader: string;
|
|
536
|
-
close: string;
|
|
537
|
-
continueImport: string;
|
|
538
|
-
errorNoData: string;
|
|
539
|
-
errorParseFailed: string;
|
|
540
|
-
errorImportFailed: string;
|
|
541
|
-
/** Localize structured validation issues; plain string errors are preserved. */
|
|
542
|
-
validationError?: (issue: ImportIssue) => string;
|
|
543
|
-
};
|
|
544
|
-
}
|
|
545
|
-
declare const zhCN: AutoCrudLocale;
|
|
546
|
-
declare const enUS: AutoCrudLocale;
|
|
547
|
-
declare const jaJP: AutoCrudLocale;
|
|
548
|
-
declare const koKR: AutoCrudLocale;
|
|
549
|
-
declare const frFR: AutoCrudLocale;
|
|
550
|
-
declare const deDE: AutoCrudLocale;
|
|
551
|
-
declare const esES: AutoCrudLocale;
|
|
552
|
-
type DeepPartial<T> = { [P in keyof T]?: NonNullable<T[P]> extends ((...args: never[]) => unknown) ? T[P] : NonNullable<T[P]> extends object ? DeepPartial<NonNullable<T[P]>> : T[P] };
|
|
553
|
-
/** locale prop 类型:内置语言 key 或部分覆盖对象 */
|
|
554
|
-
type LocaleProp = string | DeepPartial<AutoCrudLocale>;
|
|
555
|
-
/**
|
|
556
|
-
* 解析 locale prop 为完整的 AutoCrudLocale
|
|
557
|
-
* - string → 内置语言(fallback: zh-CN)
|
|
558
|
-
* - object → 以 zh-CN 为基础深合并
|
|
559
|
-
*/
|
|
560
|
-
declare function resolveLocale(localeProp?: LocaleProp): AutoCrudLocale;
|
|
561
|
-
//#endregion
|
|
562
|
-
//#region src/config/data-table.d.ts
|
|
563
|
-
type DataTableConfig = typeof dataTableConfig;
|
|
564
|
-
declare const dataTableConfig: {
|
|
565
|
-
textOperators: ({
|
|
566
|
-
label: string;
|
|
567
|
-
value: "iLike";
|
|
568
|
-
} | {
|
|
569
|
-
label: string;
|
|
570
|
-
value: "notILike";
|
|
571
|
-
} | {
|
|
572
|
-
label: string;
|
|
573
|
-
value: "eq";
|
|
574
|
-
} | {
|
|
575
|
-
label: string;
|
|
576
|
-
value: "ne";
|
|
577
|
-
} | {
|
|
578
|
-
label: string;
|
|
579
|
-
value: "isEmpty";
|
|
580
|
-
} | {
|
|
581
|
-
label: string;
|
|
582
|
-
value: "isNotEmpty";
|
|
583
|
-
})[];
|
|
584
|
-
numericOperators: ({
|
|
585
|
-
label: string;
|
|
586
|
-
value: "eq";
|
|
587
|
-
} | {
|
|
588
|
-
label: string;
|
|
589
|
-
value: "ne";
|
|
590
|
-
} | {
|
|
591
|
-
label: string;
|
|
592
|
-
value: "lt";
|
|
593
|
-
} | {
|
|
594
|
-
label: string;
|
|
595
|
-
value: "lte";
|
|
596
|
-
} | {
|
|
597
|
-
label: string;
|
|
598
|
-
value: "gt";
|
|
599
|
-
} | {
|
|
600
|
-
label: string;
|
|
601
|
-
value: "gte";
|
|
602
|
-
} | {
|
|
603
|
-
label: string;
|
|
604
|
-
value: "isBetween";
|
|
605
|
-
} | {
|
|
606
|
-
label: string;
|
|
607
|
-
value: "isEmpty";
|
|
608
|
-
} | {
|
|
609
|
-
label: string;
|
|
610
|
-
value: "isNotEmpty";
|
|
611
|
-
})[];
|
|
612
|
-
dateOperators: ({
|
|
613
|
-
label: string;
|
|
614
|
-
value: "eq";
|
|
615
|
-
} | {
|
|
616
|
-
label: string;
|
|
617
|
-
value: "ne";
|
|
618
|
-
} | {
|
|
619
|
-
label: string;
|
|
620
|
-
value: "lt";
|
|
621
|
-
} | {
|
|
622
|
-
label: string;
|
|
623
|
-
value: "gt";
|
|
624
|
-
} | {
|
|
625
|
-
label: string;
|
|
626
|
-
value: "lte";
|
|
627
|
-
} | {
|
|
628
|
-
label: string;
|
|
629
|
-
value: "gte";
|
|
630
|
-
} | {
|
|
631
|
-
label: string;
|
|
632
|
-
value: "isBetween";
|
|
633
|
-
} | {
|
|
634
|
-
label: string;
|
|
635
|
-
value: "isRelativeToToday";
|
|
636
|
-
} | {
|
|
637
|
-
label: string;
|
|
638
|
-
value: "isEmpty";
|
|
639
|
-
} | {
|
|
640
|
-
label: string;
|
|
641
|
-
value: "isNotEmpty";
|
|
642
|
-
})[];
|
|
643
|
-
selectOperators: ({
|
|
644
|
-
label: string;
|
|
645
|
-
value: "eq";
|
|
646
|
-
} | {
|
|
647
|
-
label: string;
|
|
648
|
-
value: "ne";
|
|
649
|
-
} | {
|
|
650
|
-
label: string;
|
|
651
|
-
value: "isEmpty";
|
|
652
|
-
} | {
|
|
653
|
-
label: string;
|
|
654
|
-
value: "isNotEmpty";
|
|
655
|
-
})[];
|
|
656
|
-
multiSelectOperators: ({
|
|
657
|
-
label: string;
|
|
658
|
-
value: "inArray";
|
|
659
|
-
} | {
|
|
660
|
-
label: string;
|
|
661
|
-
value: "notInArray";
|
|
662
|
-
} | {
|
|
663
|
-
label: string;
|
|
664
|
-
value: "isEmpty";
|
|
665
|
-
} | {
|
|
666
|
-
label: string;
|
|
667
|
-
value: "isNotEmpty";
|
|
668
|
-
})[];
|
|
669
|
-
booleanOperators: ({
|
|
670
|
-
label: string;
|
|
671
|
-
value: "eq";
|
|
672
|
-
} | {
|
|
673
|
-
label: string;
|
|
674
|
-
value: "ne";
|
|
675
|
-
})[];
|
|
676
|
-
sortOrders: ({
|
|
677
|
-
label: string;
|
|
678
|
-
value: "asc";
|
|
679
|
-
} | {
|
|
680
|
-
label: string;
|
|
681
|
-
value: "desc";
|
|
682
|
-
})[];
|
|
683
|
-
filterVariants: readonly ["text", "number", "range", "date", "dateRange", "boolean", "select", "multiSelect", "tags"];
|
|
684
|
-
operators: readonly ["iLike", "notILike", "eq", "ne", "inArray", "notInArray", "isEmpty", "isNotEmpty", "lt", "lte", "gt", "gte", "isBetween", "isRelativeToToday", "matches"];
|
|
685
|
-
joinOperators: readonly ["and", "or"];
|
|
686
|
-
};
|
|
687
|
-
//#endregion
|
|
688
|
-
//#region src/types/data-table.d.ts
|
|
689
|
-
interface DataTableClassNames {
|
|
690
|
-
table?: string;
|
|
691
|
-
thead?: string;
|
|
692
|
-
tbody?: string;
|
|
693
|
-
/** 应用于表头行、正文行和空状态行 */
|
|
694
|
-
tr?: string;
|
|
695
|
-
th?: string;
|
|
696
|
-
td?: string;
|
|
697
|
-
}
|
|
698
|
-
/** Optional pagination controls. Omitted options preserve the existing layout. */
|
|
699
|
-
interface TablePaginationOptions {
|
|
700
|
-
locale?: Partial<TablePaginationLocale>;
|
|
701
|
-
/** Show first/last page buttons at every viewport width; default remains lg-only. */
|
|
702
|
-
alwaysShowFirstLast?: boolean;
|
|
703
|
-
/** Hide optional controls when their measured content does not fit the container. */
|
|
704
|
-
responsive?: boolean;
|
|
705
|
-
/** Show an input to jump to a known page; defaults to false. */
|
|
706
|
-
showPageJump?: boolean;
|
|
707
|
-
pageJumpLabel?: string;
|
|
708
|
-
}
|
|
709
|
-
declare module '@tanstack/react-table' {
|
|
710
|
-
interface TableMeta<TData extends RowData> {
|
|
711
|
-
queryKeys?: QueryKeys;
|
|
712
|
-
queryStateOptions?: UrlStateOptions;
|
|
713
|
-
filterState?: TableFilterState<TData>;
|
|
714
|
-
/** @internal Renders the batch value using the existing filter controls. */
|
|
715
|
-
renderFilterValue?: (filter: ExtendedColumnFilter<TData>, props: {
|
|
716
|
-
className?: string;
|
|
717
|
-
}) => React.ReactNode;
|
|
718
|
-
}
|
|
719
|
-
interface ColumnMeta<TData extends RowData, TValue> {
|
|
720
|
-
label?: string;
|
|
721
|
-
index?: number;
|
|
722
|
-
/** @internal Identifies the generated row expansion control, regardless of its id. */
|
|
723
|
-
autoCrudExpandColumn?: boolean;
|
|
724
|
-
/** 按元素分组的列类名,优先于全局单元格类名 */
|
|
725
|
-
classNames?: Pick<DataTableClassNames, 'th' | 'td'>;
|
|
726
|
-
placeholder?: string;
|
|
727
|
-
variant?: FilterVariant$1;
|
|
728
|
-
options?: Option[];
|
|
729
|
-
range?: [number, number];
|
|
730
|
-
/** Latest selectable calendar day (YYYY-MM-DD), or today in the Host time zone. */
|
|
731
|
-
maxDate?: string;
|
|
732
|
-
unit?: string;
|
|
733
|
-
icon?: React.FC<React.SVGProps<SVGSVGElement>>;
|
|
734
|
-
/** 控制在哪些筛选模式下显示(未设置则在所有模式显示) */
|
|
735
|
-
modes?: Array<'simple' | 'advanced' | 'command'>;
|
|
736
|
-
/** 内部:远程筛选选项搜索值 */
|
|
737
|
-
autoCrudFilterSearchValue?: string;
|
|
738
|
-
/** 内部:远程筛选选项搜索回调 */
|
|
739
|
-
autoCrudFilterOnSearch?: (value: string) => void;
|
|
740
|
-
/** 内部:是否启用本地选项过滤 */
|
|
741
|
-
autoCrudFilterShouldFilter?: boolean;
|
|
742
|
-
/** 内部:远程筛选当前弹窗选项,和稳定标签缓存分离 */
|
|
743
|
-
autoCrudFilterOptions?: Option[];
|
|
744
|
-
/** 内部:远程筛选是否还有更多选项 */
|
|
745
|
-
autoCrudFilterHasMore?: boolean;
|
|
746
|
-
/** 内部:远程筛选是否正在加载 */
|
|
747
|
-
autoCrudFilterLoading?: boolean;
|
|
748
|
-
/** 内部:远程筛选弹窗滚动回调 */
|
|
749
|
-
autoCrudFilterOnPopupScroll?: React.UIEventHandler<HTMLElement>;
|
|
750
|
-
}
|
|
751
|
-
}
|
|
752
|
-
interface QueryKeys {
|
|
753
|
-
/** Saved view slug or ID. Defaults to "view". */
|
|
754
|
-
view?: string;
|
|
755
|
-
page: string;
|
|
756
|
-
perPage: string;
|
|
757
|
-
sort: string;
|
|
758
|
-
filters: string;
|
|
759
|
-
joinOperator: string;
|
|
760
|
-
}
|
|
761
|
-
interface Option {
|
|
762
|
-
label: string;
|
|
763
|
-
value: string;
|
|
764
|
-
searchText?: string;
|
|
765
|
-
count?: number;
|
|
766
|
-
color?: string;
|
|
767
|
-
icon?: React.FC<React.SVGProps<SVGSVGElement>>;
|
|
768
|
-
}
|
|
769
|
-
type FilterOperator = DataTableConfig['operators'][number];
|
|
770
|
-
type FilterVariant$1 = DataTableConfig['filterVariants'][number];
|
|
771
|
-
type JoinOperator = DataTableConfig['joinOperators'][number];
|
|
772
|
-
interface ExtendedColumnSort<TData> extends Omit<ColumnSort, 'id'> {
|
|
773
|
-
id: Extract<keyof TData, string>;
|
|
774
|
-
}
|
|
775
|
-
type ExtendedColumnFilter<TData> = FilterItemSchema & {
|
|
776
|
-
id: Extract<keyof TData, string>;
|
|
777
|
-
};
|
|
778
|
-
interface TableFilterState<TData> {
|
|
779
|
-
filters: ExtendedColumnFilter<TData>[];
|
|
780
|
-
onFiltersChange: (updater: ExtendedColumnFilter<TData>[] | ((previous: ExtendedColumnFilter<TData>[]) => ExtendedColumnFilter<TData>[])) => void;
|
|
781
|
-
}
|
|
782
|
-
interface DataTableRowAction<TData> {
|
|
783
|
-
row: Row<TData>;
|
|
784
|
-
variant: 'update' | 'delete';
|
|
785
|
-
}
|
|
786
|
-
//#endregion
|
|
787
|
-
//#region src/lib/parsers.d.ts
|
|
788
|
-
declare const filterItemSchema: z.ZodUnion<readonly [z.ZodObject<{
|
|
789
|
-
id: z.ZodString;
|
|
790
|
-
value: z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>;
|
|
791
|
-
variant: z.ZodEnum<{
|
|
792
|
-
number: "number";
|
|
793
|
-
boolean: "boolean";
|
|
794
|
-
date: "date";
|
|
795
|
-
text: "text";
|
|
796
|
-
range: "range";
|
|
797
|
-
dateRange: "dateRange";
|
|
798
|
-
select: "select";
|
|
799
|
-
multiSelect: "multiSelect";
|
|
800
|
-
}>;
|
|
801
|
-
operator: z.ZodEnum<{
|
|
802
|
-
iLike: "iLike";
|
|
803
|
-
notILike: "notILike";
|
|
804
|
-
eq: "eq";
|
|
805
|
-
ne: "ne";
|
|
806
|
-
isEmpty: "isEmpty";
|
|
807
|
-
isNotEmpty: "isNotEmpty";
|
|
808
|
-
lt: "lt";
|
|
809
|
-
lte: "lte";
|
|
810
|
-
gt: "gt";
|
|
811
|
-
gte: "gte";
|
|
812
|
-
isBetween: "isBetween";
|
|
813
|
-
isRelativeToToday: "isRelativeToToday";
|
|
814
|
-
inArray: "inArray";
|
|
815
|
-
notInArray: "notInArray";
|
|
816
|
-
}>;
|
|
817
|
-
filterId: z.ZodString;
|
|
818
|
-
}, z.core.$strip>, z.ZodObject<{
|
|
819
|
-
id: z.ZodString;
|
|
820
|
-
filterId: z.ZodString;
|
|
821
|
-
variant: z.ZodLiteral<"tags">;
|
|
822
|
-
operator: z.ZodLiteral<"matches">;
|
|
823
|
-
value: z.ZodObject<{
|
|
824
|
-
include: z.ZodArray<z.ZodString>;
|
|
825
|
-
exclude: z.ZodArray<z.ZodString>;
|
|
826
|
-
match: z.ZodEnum<{
|
|
827
|
-
any: "any";
|
|
828
|
-
all: "all";
|
|
829
|
-
}>;
|
|
830
|
-
}, z.core.$strict>;
|
|
831
|
-
}, z.core.$strip>]>;
|
|
832
|
-
type FilterItemSchema = z.infer<typeof filterItemSchema>;
|
|
833
|
-
//#endregion
|
|
834
|
-
//#region src/lib/batch-search.d.ts
|
|
835
|
-
interface BatchSearchConfig {
|
|
836
|
-
/** Maximum unique values per query. Defaults to 2000. */
|
|
837
|
-
maxItems?: number;
|
|
838
|
-
}
|
|
839
|
-
interface BatchSearchFilter {
|
|
840
|
-
id: string;
|
|
841
|
-
value: string[];
|
|
842
|
-
variant: 'text' | 'number';
|
|
843
|
-
operator: 'inArray';
|
|
844
|
-
filterId: string;
|
|
845
|
-
}
|
|
846
|
-
interface BatchSearchState {
|
|
847
|
-
filter: BatchSearchFilter | null;
|
|
848
|
-
onFilterChange: (filter: BatchSearchFilter | null) => void;
|
|
849
|
-
}
|
|
850
|
-
interface BatchSearchField {
|
|
851
|
-
id: string;
|
|
852
|
-
label: string;
|
|
853
|
-
}
|
|
854
|
-
type BatchSearchIssue = {
|
|
855
|
-
type: 'columns' | 'invalid';
|
|
856
|
-
lines: number[];
|
|
857
|
-
} | {
|
|
858
|
-
type: 'limit';
|
|
859
|
-
maxItems: number;
|
|
860
|
-
};
|
|
861
|
-
//#endregion
|
|
862
|
-
//#region src/types/permissions.d.ts
|
|
863
|
-
/**
|
|
864
|
-
* CRUD 操作权限
|
|
865
|
-
* 控制工具栏按钮、行操作按钮、批量操作按钮的显示
|
|
866
|
-
*/
|
|
867
|
-
interface CrudOperationPermissions {
|
|
868
|
-
/** 是否允许创建(新建按钮、复制行操作) */
|
|
869
|
-
create?: boolean;
|
|
870
|
-
/** 是否允许更新(编辑按钮、批量更新) */
|
|
871
|
-
update?: boolean;
|
|
872
|
-
/** 是否允许删除(删除按钮、批量删除) */
|
|
873
|
-
delete?: boolean;
|
|
874
|
-
/** 是否允许导出 */
|
|
875
|
-
export?: boolean;
|
|
876
|
-
/** 是否允许导入 */
|
|
877
|
-
import?: boolean;
|
|
878
|
-
}
|
|
879
|
-
/**
|
|
880
|
-
* AutoCrudTable 权限配置
|
|
881
|
-
*
|
|
882
|
-
* @example
|
|
883
|
-
* ```tsx
|
|
884
|
-
* const permissions = useMemo(() => ({
|
|
885
|
-
* can: {
|
|
886
|
-
* create: user.role === 'admin',
|
|
887
|
-
* update: user.role === 'admin' || user.role === 'editor',
|
|
888
|
-
* delete: user.role === 'admin',
|
|
889
|
-
* export: true,
|
|
890
|
-
* },
|
|
891
|
-
* deny: user.role === 'user' ? ['salary', 'ssn'] : [],
|
|
892
|
-
* }), [user.role]);
|
|
893
|
-
*
|
|
894
|
-
* <AutoCrudTable
|
|
895
|
-
* schema={employeeSchema}
|
|
896
|
-
* resource={resource}
|
|
897
|
-
* permissions={permissions}
|
|
898
|
-
* />
|
|
899
|
-
* ```
|
|
900
|
-
*/
|
|
901
|
-
interface CrudPermissions {
|
|
902
|
-
/** 操作权限(默认全部为 true) */
|
|
903
|
-
can?: CrudOperationPermissions;
|
|
904
|
-
/** 禁止访问的字段列表(表格列和表单字段都会隐藏) */
|
|
905
|
-
deny?: string[];
|
|
906
|
-
}
|
|
907
|
-
//#endregion
|
|
908
|
-
//#region src/lib/registries.d.ts
|
|
909
|
-
type AutoCrudFormComponentConfig = {
|
|
910
|
-
component: React$1.ComponentType<any>;
|
|
911
|
-
decorator?: string | React$1.ComponentType<any>;
|
|
912
|
-
[key: string]: unknown;
|
|
913
|
-
};
|
|
914
|
-
type AutoCrudOption = {
|
|
915
|
-
value: string;
|
|
916
|
-
label: string;
|
|
917
|
-
searchText?: string | string[];
|
|
918
|
-
keywords?: string[];
|
|
919
|
-
count?: number;
|
|
920
|
-
color?: string;
|
|
921
|
-
disabled?: boolean;
|
|
922
|
-
};
|
|
923
|
-
type AutoCrudDataSourceContextType = 'form' | 'filter' | 'resolve';
|
|
924
|
-
type AutoCrudDataSourceResolveFields = readonly string[] | ((context: {
|
|
925
|
-
field: string;
|
|
926
|
-
}) => readonly string[]);
|
|
927
|
-
type AutoCrudDataSourceContext = {
|
|
928
|
-
field: string;
|
|
929
|
-
type: AutoCrudDataSourceContextType;
|
|
930
|
-
page?: number;
|
|
931
|
-
pageSize?: number;
|
|
932
|
-
query?: string;
|
|
933
|
-
/** @deprecated Use `query` instead. */
|
|
934
|
-
search?: string;
|
|
935
|
-
values?: Record<string, unknown> | Record<string, unknown>[];
|
|
936
|
-
signal?: AbortSignal;
|
|
937
|
-
};
|
|
938
|
-
type AutoCrudDataSourceResult = AutoCrudOption[] | {
|
|
939
|
-
hasMore?: boolean;
|
|
940
|
-
options?: AutoCrudOption[];
|
|
941
|
-
};
|
|
942
|
-
type AutoCrudDataSourceLoader = (context: AutoCrudDataSourceContext) => AutoCrudDataSourceResult | Promise<AutoCrudDataSourceResult>;
|
|
943
|
-
type AutoCrudDataSourceConfig = string;
|
|
944
|
-
type AutoCrudDataSourceRegistration = AutoCrudDataSourceLoader | {
|
|
945
|
-
dependencies?: string[];
|
|
946
|
-
reset?: boolean;
|
|
947
|
-
search?: boolean;
|
|
948
|
-
debounceMs?: number;
|
|
949
|
-
loadMore?: boolean;
|
|
950
|
-
pageSize?: number;
|
|
951
|
-
resolveFields?: AutoCrudDataSourceResolveFields;
|
|
952
|
-
load: AutoCrudDataSourceLoader;
|
|
953
|
-
};
|
|
954
|
-
type AutoCrudDataSourceEntry = {
|
|
955
|
-
dependencies: string[];
|
|
956
|
-
reset: boolean;
|
|
957
|
-
search: boolean;
|
|
958
|
-
debounceMs: number;
|
|
959
|
-
loadMore: boolean;
|
|
960
|
-
pageSize: number;
|
|
961
|
-
resolveFields?: AutoCrudDataSourceResolveFields;
|
|
962
|
-
load: AutoCrudDataSourceLoader;
|
|
963
|
-
};
|
|
964
|
-
type RegistryListener$1 = () => void;
|
|
965
|
-
declare const tablePagination: {
|
|
966
|
-
register(name: string, value: TablePaginationOptions): void;
|
|
967
|
-
unregister(name: string): void;
|
|
968
|
-
get(name: string): TablePaginationOptions | undefined;
|
|
969
|
-
all(): Record<string, TablePaginationOptions>;
|
|
970
|
-
subscribe(listener: RegistryListener$1): () => void;
|
|
971
|
-
};
|
|
972
|
-
declare const formComponents: {
|
|
973
|
-
register(name: string, value: AutoCrudFormComponentConfig): void;
|
|
974
|
-
unregister(name: string): void;
|
|
975
|
-
get(name: string): AutoCrudFormComponentConfig | undefined;
|
|
976
|
-
all(): Record<string, AutoCrudFormComponentConfig>;
|
|
977
|
-
subscribe(listener: RegistryListener$1): () => void;
|
|
978
|
-
};
|
|
979
|
-
declare const components: {
|
|
980
|
-
register(name: string, value: AutoCrudFormComponentConfig): void;
|
|
981
|
-
unregister(name: string): void;
|
|
982
|
-
get(name: string): AutoCrudFormComponentConfig | undefined;
|
|
983
|
-
all(): Record<string, AutoCrudFormComponentConfig>;
|
|
984
|
-
subscribe(listener: RegistryListener$1): () => void;
|
|
985
|
-
};
|
|
986
|
-
declare const dataSources: {
|
|
987
|
-
register(name: string, registration: AutoCrudDataSourceRegistration): void;
|
|
988
|
-
unregister: (name: string) => void;
|
|
989
|
-
get: (name: string) => AutoCrudDataSourceEntry | undefined;
|
|
990
|
-
all: () => Record<string, AutoCrudDataSourceEntry>;
|
|
991
|
-
subscribe: (listener: RegistryListener$1) => () => void;
|
|
992
|
-
};
|
|
993
|
-
declare function normalizeDataSourceConfig(config: AutoCrudDataSourceConfig | undefined): {
|
|
994
|
-
key: string;
|
|
995
|
-
} | undefined;
|
|
996
|
-
declare function normalizeOptions(result: AutoCrudDataSourceResult | undefined): AutoCrudOption[];
|
|
997
|
-
//#endregion
|
|
998
|
-
//#region src/components/auto-crud/auto-crud-provider.d.ts
|
|
999
|
-
interface ViewStorage {
|
|
1000
|
-
list: (resourceId: string) => Promise<SavedView[]>;
|
|
1001
|
-
create: (resourceId: string, input: ViewInput) => Promise<SavedView>;
|
|
1002
|
-
update: (resourceId: string, id: string, input: ViewInput) => Promise<SavedView>;
|
|
1003
|
-
remove: (resourceId: string, id: string) => Promise<void>;
|
|
1004
|
-
/** Omit to use the adapter's default scope. Empty createScopes disables creation. */
|
|
1005
|
-
getCapabilities?: (resourceId: string) => Promise<ViewStorageCapabilities>;
|
|
1006
|
-
/** Complete permutation of permitted persisted IDs; other rows keep their slots. The selector uses local preferences. */
|
|
1007
|
-
reorder?: (resourceId: string, ids: string[]) => Promise<void>;
|
|
1008
|
-
}
|
|
1009
|
-
interface TagScope {
|
|
1010
|
-
resourceId: string;
|
|
1011
|
-
field: string;
|
|
1012
|
-
}
|
|
1013
|
-
interface TagInput {
|
|
1014
|
-
label: string;
|
|
1015
|
-
color: string;
|
|
1016
|
-
}
|
|
1017
|
-
interface TagOption extends TagInput {
|
|
1018
|
-
disabled?: boolean;
|
|
1019
|
-
value: string;
|
|
1020
|
-
}
|
|
1021
|
-
interface TagService {
|
|
1022
|
-
/** Search a page of tags; set hasMore to false on the last page. */
|
|
1023
|
-
list: (input: TagScope & Pick<AutoCrudDataSourceContext, 'query' | 'page' | 'pageSize' | 'signal'>) => Promise<{
|
|
1024
|
-
options: TagOption[];
|
|
1025
|
-
hasMore: boolean;
|
|
1026
|
-
}>;
|
|
1027
|
-
/** Resolve all selected IDs; missing IDs remain visible as invalid selections. */
|
|
1028
|
-
resolve: (input: TagScope & {
|
|
1029
|
-
ids: string[];
|
|
1030
|
-
}) => Promise<TagOption[]>;
|
|
1031
|
-
create?: (input: TagScope & TagInput) => Promise<TagOption>;
|
|
1032
|
-
update?: (input: TagScope & TagInput & {
|
|
1033
|
-
id: string;
|
|
1034
|
-
}) => Promise<TagOption>;
|
|
1035
|
-
remove?: (input: TagScope & {
|
|
1036
|
-
id: string;
|
|
1037
|
-
}) => Promise<void>;
|
|
1038
|
-
/** Add/remove only the specified tags; preserve every other existing tag. */
|
|
1039
|
-
assign?: (input: TagScope & {
|
|
1040
|
-
entityIds: string[];
|
|
1041
|
-
add: string[];
|
|
1042
|
-
remove: string[];
|
|
1043
|
-
}) => Promise<void>;
|
|
1044
|
-
}
|
|
1045
|
-
interface AutoCrudProviderProps {
|
|
1046
|
-
/** Change with the signed-in user/tenant; remounts cached UI state. */
|
|
1047
|
-
scope: string;
|
|
1048
|
-
viewStorage?: ViewStorage;
|
|
1049
|
-
tagService?: TagService;
|
|
1050
|
-
children: ReactNode;
|
|
1051
|
-
}
|
|
1052
|
-
declare function AutoCrudProvider({
|
|
1053
|
-
children,
|
|
1054
|
-
...config
|
|
1055
|
-
}: AutoCrudProviderProps): react_jsx_runtime17.JSX.Element;
|
|
264
|
+
declare function AutoCrudProvider({
|
|
265
|
+
children,
|
|
266
|
+
...config
|
|
267
|
+
}: AutoCrudProviderProps): react_jsx_runtime17.JSX.Element;
|
|
1056
268
|
//#endregion
|
|
1057
269
|
//#region src/lib/saved-views.d.ts
|
|
1058
270
|
declare const viewQuerySchema: z.ZodObject<{
|
|
@@ -1306,74 +518,871 @@ declare const presetViewSchema: z.ZodObject<{
|
|
|
1306
518
|
name: z.ZodString;
|
|
1307
519
|
slug: z.ZodOptional<z.ZodString>;
|
|
1308
520
|
id: z.ZodString;
|
|
1309
|
-
}, z.core.$strict>;
|
|
1310
|
-
type ViewQuery = z.infer<typeof viewQuerySchema>;
|
|
1311
|
-
type ViewScope = z.infer<typeof viewScopeSchema>;
|
|
1312
|
-
type ViewCapabilities = z.infer<typeof viewCapabilitiesSchema>;
|
|
1313
|
-
type ViewStorageCapabilities = z.infer<typeof viewStorageCapabilitiesSchema>;
|
|
1314
|
-
type ViewInput = z.infer<typeof viewInputSchema>;
|
|
1315
|
-
type SavedView = z.infer<typeof savedViewSchema>;
|
|
1316
|
-
type PresetView = z.infer<typeof presetViewSchema>;
|
|
1317
|
-
declare const viewPreferencesSchema: z.ZodPipe<z.ZodObject<{
|
|
1318
|
-
selector: z.ZodEnum<{
|
|
1319
|
-
dropdown: "dropdown";
|
|
1320
|
-
tabs: "tabs";
|
|
521
|
+
}, z.core.$strict>;
|
|
522
|
+
type ViewQuery = z.infer<typeof viewQuerySchema>;
|
|
523
|
+
type ViewScope = z.infer<typeof viewScopeSchema>;
|
|
524
|
+
type ViewCapabilities = z.infer<typeof viewCapabilitiesSchema>;
|
|
525
|
+
type ViewStorageCapabilities = z.infer<typeof viewStorageCapabilitiesSchema>;
|
|
526
|
+
type ViewInput = z.infer<typeof viewInputSchema>;
|
|
527
|
+
type SavedView = z.infer<typeof savedViewSchema>;
|
|
528
|
+
type PresetView = z.infer<typeof presetViewSchema>;
|
|
529
|
+
declare const viewPreferencesSchema: z.ZodPipe<z.ZodObject<{
|
|
530
|
+
selector: z.ZodEnum<{
|
|
531
|
+
dropdown: "dropdown";
|
|
532
|
+
tabs: "tabs";
|
|
533
|
+
}>;
|
|
534
|
+
viewId: z.ZodNullable<z.ZodString>;
|
|
535
|
+
viewOrder: z.ZodCatch<z.ZodOptional<z.ZodArray<z.ZodString>>>;
|
|
536
|
+
hiddenViewIds: z.ZodCatch<z.ZodOptional<z.ZodArray<z.ZodString>>>;
|
|
537
|
+
hiddenPresetIds: z.ZodCatch<z.ZodOptional<z.ZodArray<z.ZodString>>>;
|
|
538
|
+
}, z.core.$strip>, z.ZodTransform<{
|
|
539
|
+
selector: "dropdown" | "tabs";
|
|
540
|
+
viewId: string | null;
|
|
541
|
+
viewOrder?: string[] | undefined;
|
|
542
|
+
hiddenViewIds?: string[] | undefined;
|
|
543
|
+
}, {
|
|
544
|
+
selector: "dropdown" | "tabs";
|
|
545
|
+
viewId: string | null;
|
|
546
|
+
viewOrder?: string[] | undefined;
|
|
547
|
+
hiddenViewIds?: string[] | undefined;
|
|
548
|
+
hiddenPresetIds?: string[] | undefined;
|
|
549
|
+
}>>;
|
|
550
|
+
type ViewPreferences = z.infer<typeof viewPreferencesSchema>;
|
|
551
|
+
/** namespace must identify both the user and tenant. No implicit browser fallback. */
|
|
552
|
+
declare function createLocalViewStorage(namespace: string): ViewStorage;
|
|
553
|
+
//#endregion
|
|
554
|
+
//#region src/components/auto-crud/saved-views.d.ts
|
|
555
|
+
interface SavedViewsConfig {
|
|
556
|
+
/** Code-defined queries; users may hide/reorder their display locally. IDs/slugs must be unique across sources. */
|
|
557
|
+
presets?: readonly PresetView[];
|
|
558
|
+
/** Page-hidden view IDs or slugs from any source. Overrides personal preferences; excluded from restore. */
|
|
559
|
+
hiddenViews?: readonly string[];
|
|
560
|
+
/** Opt into scope selection with Host-defined values and labels. Single options stay hidden. */
|
|
561
|
+
scopeOptions?: readonly {
|
|
562
|
+
value: ViewScope;
|
|
563
|
+
label: string;
|
|
564
|
+
}[];
|
|
565
|
+
/** Initial view slug or ID when the URL and local preferences do not select a view. */
|
|
566
|
+
defaultView?: string;
|
|
567
|
+
/** Wait for async fields in standalone AutoTable; AutoCrudTable derives readiness from resource metadata. */
|
|
568
|
+
fieldsReady?: boolean;
|
|
569
|
+
/** Initial display mode when no local preference exists. */
|
|
570
|
+
selector?: ViewPreferences['selector'];
|
|
571
|
+
/** Appearance of the tab selector; supplied classes override the defaults. */
|
|
572
|
+
tabs?: {
|
|
573
|
+
variant?: 'default' | 'line';
|
|
574
|
+
/** Position of the active line. Defaults to bottom; only applies to line tabs. */
|
|
575
|
+
linePosition?: 'top' | 'bottom';
|
|
576
|
+
classNames?: {
|
|
577
|
+
list?: string;
|
|
578
|
+
trigger?: string;
|
|
579
|
+
indicator?: string;
|
|
580
|
+
};
|
|
581
|
+
};
|
|
582
|
+
/** Count saved queries (including All), in batches of at most 100. Keys are opaque. */
|
|
583
|
+
counts?: (input: {
|
|
584
|
+
queries: Array<Pick<ViewQuery, 'filters' | 'joinOperator' | 'search'> & {
|
|
585
|
+
key: string;
|
|
586
|
+
}>;
|
|
587
|
+
signal: AbortSignal;
|
|
588
|
+
}) => Promise<Record<string, number>>;
|
|
589
|
+
}
|
|
590
|
+
/** Internal list state supplied by useAutoCrudResource. */
|
|
591
|
+
interface ViewCountSource {
|
|
592
|
+
navigationKey: string | null;
|
|
593
|
+
refreshVersion: number;
|
|
594
|
+
isFetching: boolean;
|
|
595
|
+
}
|
|
596
|
+
//#endregion
|
|
597
|
+
//#region src/hooks/use-auto-crud-resource.d.ts
|
|
598
|
+
/**
|
|
599
|
+
* Toast 适配器接口
|
|
600
|
+
* 用户可以注入自己的 toast 实现
|
|
601
|
+
*/
|
|
602
|
+
interface ToastAdapter {
|
|
603
|
+
success: (message: string) => void;
|
|
604
|
+
error: (message: string) => void;
|
|
605
|
+
info?: (message: string) => void;
|
|
606
|
+
warning?: (message: string) => void;
|
|
607
|
+
}
|
|
608
|
+
/** 空 toast 适配器(禁用通知) */
|
|
609
|
+
declare const noopToastAdapter: ToastAdapter;
|
|
610
|
+
interface AutoCrudQueryCapabilities {
|
|
611
|
+
search?: {
|
|
612
|
+
enabled: boolean;
|
|
613
|
+
fields: string[];
|
|
614
|
+
};
|
|
615
|
+
filters?: {
|
|
616
|
+
enabled: boolean;
|
|
617
|
+
fields: string[] | null;
|
|
618
|
+
};
|
|
619
|
+
sort?: {
|
|
620
|
+
enabled: boolean;
|
|
621
|
+
fields: string[] | null;
|
|
622
|
+
};
|
|
623
|
+
}
|
|
624
|
+
/**
|
|
625
|
+
* Modal 状态类型
|
|
626
|
+
*/
|
|
627
|
+
type ModalVariant$1 = 'dialog' | 'sheet';
|
|
628
|
+
interface ModalState<T> {
|
|
629
|
+
createOpen: boolean;
|
|
630
|
+
editOpen: boolean;
|
|
631
|
+
deleteOpen: boolean;
|
|
632
|
+
viewOpen: boolean;
|
|
633
|
+
selected: T | null;
|
|
634
|
+
/** 复制源数据(用于复制行功能) */
|
|
635
|
+
copySource: T | null;
|
|
636
|
+
variant: ModalVariant$1;
|
|
637
|
+
}
|
|
638
|
+
/**
|
|
639
|
+
* Hook 返回值类型(用于判断是数据转换还是完全自定义)
|
|
640
|
+
* - 返回对象 = 数据转换,继续执行默认 mutation
|
|
641
|
+
* - 返回 true/false = 完全自定义,跳过默认 mutation
|
|
642
|
+
*/
|
|
643
|
+
type HookResult<T> = T | boolean;
|
|
644
|
+
/**
|
|
645
|
+
* 统一的 hooks 配置
|
|
646
|
+
*/
|
|
647
|
+
interface CrudHooks<TSchema extends z.ZodObject<z.ZodRawShape>, TListItem> {
|
|
648
|
+
/**
|
|
649
|
+
* 创建前钩子
|
|
650
|
+
* - 返回对象: 作为转换后的数据,继续执行默认创建
|
|
651
|
+
* - 返回 true: 表示已自定义处理成功,跳过默认创建
|
|
652
|
+
* - 返回 false: 表示自定义处理失败,跳过默认创建
|
|
653
|
+
*/
|
|
654
|
+
beforeCreate?: (values: z.infer<TSchema>) => HookResult<z.infer<TSchema>> | Promise<HookResult<z.infer<TSchema>>>;
|
|
655
|
+
/**
|
|
656
|
+
* 更新前钩子
|
|
657
|
+
* - 返回对象: 作为转换后的数据,继续执行默认更新
|
|
658
|
+
* - 返回 true/false: 完全自定义处理
|
|
659
|
+
*/
|
|
660
|
+
beforeUpdate?: (values: z.infer<TSchema>, original: TListItem) => HookResult<z.infer<TSchema>> | Promise<HookResult<z.infer<TSchema>>>;
|
|
661
|
+
/**
|
|
662
|
+
* 删除前钩子
|
|
663
|
+
* - 返回 true: 表示已自定义处理成功(如软删除)
|
|
664
|
+
* - 返回 false: 表示自定义处理失败
|
|
665
|
+
* - 返回 undefined/void: 继续执行默认删除
|
|
666
|
+
*/
|
|
667
|
+
beforeDelete?: (item: TListItem) => boolean | void | Promise<boolean | void>;
|
|
668
|
+
/** 操作成功回调 */
|
|
669
|
+
onSuccess?: (op: 'create' | 'update' | 'delete', payload: unknown) => void;
|
|
670
|
+
/** 操作失败回调 */
|
|
671
|
+
onError?: (op: 'create' | 'update' | 'delete', error: Error) => void;
|
|
672
|
+
}
|
|
673
|
+
/**
|
|
674
|
+
* Hook 配置选项
|
|
675
|
+
*/
|
|
676
|
+
interface UseAutoCrudResourceOptions<TSchema extends z.ZodObject<z.ZodRawShape>, TListItem> {
|
|
677
|
+
/** 主键字段名(默认: "id") */
|
|
678
|
+
idKey?: keyof TListItem & string;
|
|
679
|
+
/** 默认弹窗模式 */
|
|
680
|
+
defaultVariant?: ModalVariant$1;
|
|
681
|
+
/** 统一钩子配置 */
|
|
682
|
+
hooks?: CrudHooks<TSchema, TListItem>;
|
|
683
|
+
/**
|
|
684
|
+
* Toast 配置
|
|
685
|
+
* - undefined: 使用内置 sonner(默认)
|
|
686
|
+
* - false: 禁用所有通知
|
|
687
|
+
* - ToastAdapter: 注入自定义 toast 实现
|
|
688
|
+
*/
|
|
689
|
+
toast?: ToastAdapter | false;
|
|
690
|
+
/**
|
|
691
|
+
* 自定义导出数据获取函数(escape hatch)
|
|
692
|
+
*
|
|
693
|
+
* 通常不需要传此参数:
|
|
694
|
+
* - 导出选中行:纯客户端,零配置
|
|
695
|
+
* - 导出筛选结果:router 有 export procedure 时自动可用
|
|
696
|
+
*
|
|
697
|
+
* 仅当需要完全自定义导出逻辑时才使用(如队列导出、自定义接口等)
|
|
698
|
+
* 传入后优先级高于 router.export
|
|
699
|
+
*/
|
|
700
|
+
exportFetcher?: (params: any) => Promise<{
|
|
701
|
+
data: Record<string, unknown>[];
|
|
702
|
+
total: number;
|
|
703
|
+
hasMore: boolean;
|
|
704
|
+
}>;
|
|
705
|
+
/**
|
|
706
|
+
* 默认排序。
|
|
707
|
+
* - undefined: schema 有 createdAt 时默认 createdAt desc
|
|
708
|
+
* - false: 不应用默认排序
|
|
709
|
+
*/
|
|
710
|
+
defaultSort?: AutoCrudSorting | false;
|
|
711
|
+
}
|
|
712
|
+
/**
|
|
713
|
+
* 导入结果类型(与服务端保持一致)
|
|
714
|
+
*/
|
|
715
|
+
/** Serializable validation details; excludes the submitted cell value. */
|
|
716
|
+
interface ImportIssue {
|
|
717
|
+
code: string;
|
|
718
|
+
path: string[];
|
|
719
|
+
message: string;
|
|
720
|
+
params: Record<string, unknown>;
|
|
721
|
+
}
|
|
722
|
+
interface ImportResult {
|
|
723
|
+
success: number;
|
|
724
|
+
updated: number;
|
|
725
|
+
skipped: number;
|
|
726
|
+
failed: Array<{
|
|
727
|
+
row: number;
|
|
728
|
+
errors: string[];
|
|
729
|
+
issues?: Array<ImportIssue | null>;
|
|
730
|
+
}>;
|
|
731
|
+
}
|
|
732
|
+
/**
|
|
733
|
+
* Hook 返回值类型
|
|
734
|
+
*/
|
|
735
|
+
interface UseAutoCrudResourceReturn<TSchema extends z.ZodObject<z.ZodRawShape>, TListItem> {
|
|
736
|
+
queryKeys?: Partial<QueryKeys>;
|
|
737
|
+
/** Page-local criteria; shared by list and export without entering the URL. */
|
|
738
|
+
batchSearch?: BatchSearchState;
|
|
739
|
+
/** Shared by all filter controls, list queries, and exports. */
|
|
740
|
+
filterState?: TableFilterState<z.output<TSchema>>;
|
|
741
|
+
/** 主键字段名(默认: "id") */
|
|
742
|
+
idKey?: keyof TListItem & string;
|
|
743
|
+
tableData: {
|
|
744
|
+
data: TListItem[];
|
|
745
|
+
/** @internal Used by AutoCrudTable to refresh saved-view counts. */
|
|
746
|
+
countSource?: ViewCountSource;
|
|
747
|
+
pageCount: number;
|
|
748
|
+
/** Total rows matching the current search and filters. */
|
|
749
|
+
total?: number;
|
|
750
|
+
isLoading: boolean;
|
|
751
|
+
/** 是否正在获取数据(用于显示微妙的加载指示器) */
|
|
752
|
+
isFetching: boolean;
|
|
753
|
+
error?: Error | null;
|
|
754
|
+
};
|
|
755
|
+
/** Optional schema override from host metadata. */
|
|
756
|
+
schema?: z.ZodObject<z.ZodRawShape>;
|
|
757
|
+
/** Whether the initial field metadata is still loading. */
|
|
758
|
+
metadataPending?: boolean;
|
|
759
|
+
/** Optional field config override from host metadata. */
|
|
760
|
+
fields?: Fields;
|
|
761
|
+
/** Query capabilities reported by auto-crud-server metadata. */
|
|
762
|
+
capabilities?: AutoCrudQueryCapabilities;
|
|
763
|
+
/** Default sorting used by this resource's list query. */
|
|
764
|
+
defaultSort?: AutoCrudSorting;
|
|
765
|
+
modal: ModalState<TListItem>;
|
|
766
|
+
mutations: {
|
|
767
|
+
isCreating: boolean;
|
|
768
|
+
isUpdating: boolean;
|
|
769
|
+
isDeleting: boolean;
|
|
770
|
+
isImporting: boolean;
|
|
771
|
+
};
|
|
772
|
+
handlers: {
|
|
773
|
+
openCreate: () => void;
|
|
774
|
+
openEdit: (row: TListItem) => void;
|
|
775
|
+
openDelete: (row: TListItem) => void;
|
|
776
|
+
openView: (row: TListItem) => void;
|
|
777
|
+
copyRow: (row: TListItem) => void;
|
|
778
|
+
closeModals: () => void;
|
|
779
|
+
submitCreate: (values: z.infer<TSchema>) => void;
|
|
780
|
+
submitUpdate: (values: z.infer<TSchema>) => void;
|
|
781
|
+
/** The table waits for a returned promise and ignores its resolved value. */
|
|
782
|
+
confirmDelete: () => void;
|
|
783
|
+
deleteMany: (rows: TListItem[]) => void;
|
|
784
|
+
updateMany: (rows: TListItem[], data: Record<string, unknown>) => void;
|
|
785
|
+
setVariant: (variant: ModalVariant$1) => void;
|
|
786
|
+
/** 刷新当前列表数据 */
|
|
787
|
+
refresh?: () => Promise<unknown>;
|
|
788
|
+
/** 导入数据(router 有 import 路由时自动可用) */
|
|
789
|
+
import: ((rows: Record<string, unknown>[]) => Promise<ImportResult>) | null;
|
|
790
|
+
/** 导出筛选结果(router 有 export procedure 或传入 exportFetcher 时自动可用)。导出选中行由 AutoCrudTable 内部处理 */
|
|
791
|
+
export: (() => Promise<Record<string, unknown>[]>) | null;
|
|
792
|
+
};
|
|
793
|
+
}
|
|
794
|
+
/**
|
|
795
|
+
* tRPC Router 接口定义(宽松类型以兼容实际 tRPC router)
|
|
796
|
+
* import 为可选 — 传入 router 时自动检测是否存在
|
|
797
|
+
*/
|
|
798
|
+
interface CrudRouter {
|
|
799
|
+
list: {
|
|
800
|
+
useQuery: (input?: any, opts?: any) => any;
|
|
801
|
+
};
|
|
802
|
+
create: {
|
|
803
|
+
useMutation: (opts?: any) => any;
|
|
804
|
+
};
|
|
805
|
+
update: {
|
|
806
|
+
useMutation: (opts?: any) => any;
|
|
807
|
+
};
|
|
808
|
+
delete: {
|
|
809
|
+
useMutation: (opts?: any) => any;
|
|
810
|
+
};
|
|
811
|
+
deleteMany?: {
|
|
812
|
+
useMutation: (opts?: any) => any;
|
|
813
|
+
};
|
|
814
|
+
updateMany?: {
|
|
815
|
+
useMutation: (opts?: any) => any;
|
|
816
|
+
};
|
|
817
|
+
/** 导入路由(mutation,由 createCrudRouter 自动生成) */
|
|
818
|
+
import?: {
|
|
819
|
+
useMutation: (opts?: any) => any;
|
|
820
|
+
};
|
|
821
|
+
/** 导出路由(query,由 createCrudRouter 自动生成) */
|
|
822
|
+
export?: {
|
|
823
|
+
useQuery: (input?: any, opts?: any) => any;
|
|
824
|
+
};
|
|
825
|
+
/** 元数据路由(query,由 createCrudRouter 自动生成) */
|
|
826
|
+
meta?: {
|
|
827
|
+
useQuery: (input?: any, opts?: any) => any;
|
|
828
|
+
};
|
|
829
|
+
}
|
|
830
|
+
/**
|
|
831
|
+
* 自动生成的查询参数(由内部 URL 状态管理生成)
|
|
832
|
+
*/
|
|
833
|
+
interface AutoQueryParams {
|
|
834
|
+
page: number;
|
|
835
|
+
perPage: number;
|
|
836
|
+
sort: Array<{
|
|
837
|
+
id: string;
|
|
838
|
+
desc: boolean;
|
|
839
|
+
}>;
|
|
840
|
+
search?: string;
|
|
841
|
+
filters: any[];
|
|
842
|
+
joinOperator: 'and' | 'or';
|
|
843
|
+
}
|
|
844
|
+
/**
|
|
845
|
+
* Hook 配置参数
|
|
846
|
+
*/
|
|
847
|
+
interface UseAutoCrudResourceParams<TSchema extends z.ZodObject<z.ZodRawShape>, TListItem> {
|
|
848
|
+
/** tRPC router (如 trpc.tasks) */
|
|
849
|
+
router: CrudRouter;
|
|
850
|
+
/** URL keys shared with the table, for multiple resources on one page. */
|
|
851
|
+
queryKeys?: Partial<QueryKeys>;
|
|
852
|
+
/** Zod schema */
|
|
853
|
+
schema: TSchema;
|
|
854
|
+
/** Field filter configuration shared with AutoCrudTable. */
|
|
855
|
+
fields?: Fields;
|
|
856
|
+
/**
|
|
857
|
+
* 查询参数变换函数
|
|
858
|
+
*
|
|
859
|
+
* 默认零配置:hook 内部自动管理 URL 状态(分页、排序、筛选),
|
|
860
|
+
* 传入此函数可注入额外参数或修改自动生成的参数。
|
|
861
|
+
*
|
|
862
|
+
* @example
|
|
863
|
+
* ```tsx
|
|
864
|
+
* // 注入租户 ID
|
|
865
|
+
* query: (params) => ({ ...params, tenantId: currentTenant.id })
|
|
866
|
+
*
|
|
867
|
+
* // 覆盖默认分页
|
|
868
|
+
* query: (params) => ({ ...params, perPage: 20 })
|
|
869
|
+
* ```
|
|
870
|
+
*/
|
|
871
|
+
query?: (params: AutoQueryParams) => Record<string, unknown>;
|
|
872
|
+
/** tRPC operation context shared by list and automatic export requests. */
|
|
873
|
+
queryContext?: Record<string, unknown>;
|
|
874
|
+
/** 其他配置选项 */
|
|
875
|
+
options?: UseAutoCrudResourceOptions<TSchema, TListItem>;
|
|
876
|
+
}
|
|
877
|
+
/**
|
|
878
|
+
* Hook 主函数
|
|
879
|
+
*/
|
|
880
|
+
declare function useAutoCrudResource<TSchema extends z.ZodObject<z.ZodRawShape>, TListItem = z.output<TSchema>>({
|
|
881
|
+
router,
|
|
882
|
+
queryKeys,
|
|
883
|
+
schema,
|
|
884
|
+
query: queryTransform,
|
|
885
|
+
queryContext,
|
|
886
|
+
fields,
|
|
887
|
+
options
|
|
888
|
+
}: UseAutoCrudResourceParams<TSchema, TListItem>): UseAutoCrudResourceReturn<TSchema, TListItem>;
|
|
889
|
+
//#endregion
|
|
890
|
+
//#region src/i18n/locale.d.ts
|
|
891
|
+
/**
|
|
892
|
+
* AutoCrud 国际化接口及内置语言包
|
|
893
|
+
*
|
|
894
|
+
* 使用方式:
|
|
895
|
+
* // 内置语言
|
|
896
|
+
* <AutoCrudTable locale="en-US" ... />
|
|
897
|
+
*
|
|
898
|
+
* // 部分覆盖(以 zh-CN 为基础深合并)
|
|
899
|
+
* <AutoCrudTable locale={{ toolbar: { create: "Add" } }} ... />
|
|
900
|
+
*/
|
|
901
|
+
interface TableControlsLocale {
|
|
902
|
+
sort: {
|
|
903
|
+
label: string;
|
|
904
|
+
title: string;
|
|
905
|
+
empty: string;
|
|
906
|
+
description: string;
|
|
907
|
+
emptyDescription: string;
|
|
908
|
+
add: string;
|
|
909
|
+
reset: string;
|
|
910
|
+
searchFields: string;
|
|
911
|
+
noFields: string;
|
|
912
|
+
ascending: string;
|
|
913
|
+
descending: string;
|
|
914
|
+
direction: string;
|
|
915
|
+
remove: string;
|
|
916
|
+
move: string;
|
|
917
|
+
dragInstructions: string;
|
|
918
|
+
dragOutside: string;
|
|
919
|
+
dragStarted: (label: string, position: number, total: number) => string;
|
|
920
|
+
dragMoved: (label: string, position: number, total: number) => string;
|
|
921
|
+
dragDropped: (label: string, position: number, total: number) => string;
|
|
922
|
+
dragCancelled: (label: string) => string;
|
|
923
|
+
};
|
|
924
|
+
columns: {
|
|
925
|
+
label: string;
|
|
926
|
+
search: string;
|
|
927
|
+
empty: string;
|
|
928
|
+
};
|
|
929
|
+
}
|
|
930
|
+
interface TablePaginationLocale {
|
|
931
|
+
selected: (count: number, total: number) => string;
|
|
932
|
+
total: (count: number) => string;
|
|
933
|
+
rowsPerPage: string;
|
|
934
|
+
page: (page: number, total: number) => string;
|
|
935
|
+
pageJump: string;
|
|
936
|
+
firstPage: string;
|
|
937
|
+
previousPage: string;
|
|
938
|
+
nextPage: string;
|
|
939
|
+
lastPage: string;
|
|
940
|
+
}
|
|
941
|
+
interface TableActionBarLocale {
|
|
942
|
+
selected: (count: number) => string;
|
|
943
|
+
export: string;
|
|
944
|
+
delete: string;
|
|
945
|
+
clearSelection: string;
|
|
946
|
+
}
|
|
947
|
+
interface AutoCrudLocale {
|
|
948
|
+
/** Label shared by automatic tag assignment actions and their dialog. */
|
|
949
|
+
tagAssignment?: (fieldLabel: string) => string;
|
|
950
|
+
batchSearch?: BatchSearchLocale;
|
|
951
|
+
/** Sorting and column visibility controls. Optional for existing custom locales. */
|
|
952
|
+
tableControls?: TableControlsLocale;
|
|
953
|
+
pagination?: Partial<TablePaginationLocale>;
|
|
954
|
+
actionBar?: Partial<TableActionBarLocale>;
|
|
955
|
+
toolbar: {
|
|
956
|
+
refresh: string;
|
|
957
|
+
create: string;
|
|
958
|
+
import: string;
|
|
959
|
+
export: string;
|
|
960
|
+
exportSelected: (count: number) => string;
|
|
961
|
+
};
|
|
962
|
+
rowActions: {
|
|
963
|
+
view: string;
|
|
964
|
+
edit: string;
|
|
965
|
+
copy: string;
|
|
966
|
+
delete: string;
|
|
967
|
+
};
|
|
968
|
+
viewModal: {
|
|
969
|
+
title: string;
|
|
970
|
+
};
|
|
971
|
+
boolean: {
|
|
972
|
+
true: string;
|
|
973
|
+
false: string;
|
|
974
|
+
};
|
|
975
|
+
formModal: {
|
|
976
|
+
createTitle: string;
|
|
977
|
+
editTitle: string;
|
|
978
|
+
cancel: string;
|
|
979
|
+
create: string;
|
|
980
|
+
save: string;
|
|
981
|
+
submitting: string;
|
|
982
|
+
};
|
|
983
|
+
deleteModal: {
|
|
984
|
+
title: string;
|
|
985
|
+
description: string;
|
|
986
|
+
cancel: string;
|
|
987
|
+
confirm: string;
|
|
988
|
+
confirming: string;
|
|
989
|
+
};
|
|
990
|
+
bulkDeleteModal: {
|
|
991
|
+
title: string;
|
|
992
|
+
description: (count: number) => string;
|
|
993
|
+
cancel: string;
|
|
994
|
+
confirm: string;
|
|
995
|
+
};
|
|
996
|
+
importDialog: {
|
|
997
|
+
title: string;
|
|
998
|
+
uploadDescription: string;
|
|
999
|
+
previewDescription: (count: number) => string;
|
|
1000
|
+
importingDescription: string;
|
|
1001
|
+
doneDescription: string;
|
|
1002
|
+
dragHint: string;
|
|
1003
|
+
formatHint: string;
|
|
1004
|
+
downloadTemplate: string;
|
|
1005
|
+
moreColumns: (count: number) => string;
|
|
1006
|
+
previewSummary: (rows: number, fields: number, format: string, previewLimit?: number) => string;
|
|
1007
|
+
reselect: string;
|
|
1008
|
+
confirmImport: string;
|
|
1009
|
+
importingRows: (count: number) => string;
|
|
1010
|
+
resultCreated: string;
|
|
1011
|
+
resultUpdated: string;
|
|
1012
|
+
resultSkipped: string;
|
|
1013
|
+
resultFailed: string;
|
|
1014
|
+
failedRowHeader: string;
|
|
1015
|
+
failedErrorHeader: string;
|
|
1016
|
+
close: string;
|
|
1017
|
+
continueImport: string;
|
|
1018
|
+
errorNoData: string;
|
|
1019
|
+
errorParseFailed: string;
|
|
1020
|
+
errorImportFailed: string;
|
|
1021
|
+
/** Localize structured validation issues; plain string errors are preserved. */
|
|
1022
|
+
validationError?: (issue: ImportIssue) => string;
|
|
1023
|
+
};
|
|
1024
|
+
}
|
|
1025
|
+
declare const zhCN: AutoCrudLocale;
|
|
1026
|
+
declare const enUS: AutoCrudLocale;
|
|
1027
|
+
declare const jaJP: AutoCrudLocale;
|
|
1028
|
+
declare const koKR: AutoCrudLocale;
|
|
1029
|
+
declare const frFR: AutoCrudLocale;
|
|
1030
|
+
declare const deDE: AutoCrudLocale;
|
|
1031
|
+
declare const esES: AutoCrudLocale;
|
|
1032
|
+
type DeepPartial<T> = { [P in keyof T]?: NonNullable<T[P]> extends ((...args: never[]) => unknown) ? T[P] : NonNullable<T[P]> extends object ? DeepPartial<NonNullable<T[P]>> : T[P] };
|
|
1033
|
+
/** locale prop 类型:内置语言 key 或部分覆盖对象 */
|
|
1034
|
+
type LocaleProp = string | DeepPartial<AutoCrudLocale>;
|
|
1035
|
+
/**
|
|
1036
|
+
* 解析 locale prop 为完整的 AutoCrudLocale
|
|
1037
|
+
* - string → 内置语言(fallback: zh-CN)
|
|
1038
|
+
* - object → 以 zh-CN 为基础深合并
|
|
1039
|
+
*/
|
|
1040
|
+
declare function resolveLocale(localeProp?: LocaleProp): AutoCrudLocale;
|
|
1041
|
+
//#endregion
|
|
1042
|
+
//#region src/config/data-table.d.ts
|
|
1043
|
+
type DataTableConfig = typeof dataTableConfig;
|
|
1044
|
+
declare const dataTableConfig: {
|
|
1045
|
+
textOperators: ({
|
|
1046
|
+
label: string;
|
|
1047
|
+
value: "iLike";
|
|
1048
|
+
} | {
|
|
1049
|
+
label: string;
|
|
1050
|
+
value: "notILike";
|
|
1051
|
+
} | {
|
|
1052
|
+
label: string;
|
|
1053
|
+
value: "eq";
|
|
1054
|
+
} | {
|
|
1055
|
+
label: string;
|
|
1056
|
+
value: "ne";
|
|
1057
|
+
} | {
|
|
1058
|
+
label: string;
|
|
1059
|
+
value: "isEmpty";
|
|
1060
|
+
} | {
|
|
1061
|
+
label: string;
|
|
1062
|
+
value: "isNotEmpty";
|
|
1063
|
+
})[];
|
|
1064
|
+
numericOperators: ({
|
|
1065
|
+
label: string;
|
|
1066
|
+
value: "eq";
|
|
1067
|
+
} | {
|
|
1068
|
+
label: string;
|
|
1069
|
+
value: "ne";
|
|
1070
|
+
} | {
|
|
1071
|
+
label: string;
|
|
1072
|
+
value: "lt";
|
|
1073
|
+
} | {
|
|
1074
|
+
label: string;
|
|
1075
|
+
value: "lte";
|
|
1076
|
+
} | {
|
|
1077
|
+
label: string;
|
|
1078
|
+
value: "gt";
|
|
1079
|
+
} | {
|
|
1080
|
+
label: string;
|
|
1081
|
+
value: "gte";
|
|
1082
|
+
} | {
|
|
1083
|
+
label: string;
|
|
1084
|
+
value: "isBetween";
|
|
1085
|
+
} | {
|
|
1086
|
+
label: string;
|
|
1087
|
+
value: "isEmpty";
|
|
1088
|
+
} | {
|
|
1089
|
+
label: string;
|
|
1090
|
+
value: "isNotEmpty";
|
|
1091
|
+
})[];
|
|
1092
|
+
dateOperators: ({
|
|
1093
|
+
label: string;
|
|
1094
|
+
value: "eq";
|
|
1095
|
+
} | {
|
|
1096
|
+
label: string;
|
|
1097
|
+
value: "ne";
|
|
1098
|
+
} | {
|
|
1099
|
+
label: string;
|
|
1100
|
+
value: "lt";
|
|
1101
|
+
} | {
|
|
1102
|
+
label: string;
|
|
1103
|
+
value: "gt";
|
|
1104
|
+
} | {
|
|
1105
|
+
label: string;
|
|
1106
|
+
value: "lte";
|
|
1107
|
+
} | {
|
|
1108
|
+
label: string;
|
|
1109
|
+
value: "gte";
|
|
1110
|
+
} | {
|
|
1111
|
+
label: string;
|
|
1112
|
+
value: "isBetween";
|
|
1113
|
+
} | {
|
|
1114
|
+
label: string;
|
|
1115
|
+
value: "isRelativeToToday";
|
|
1116
|
+
} | {
|
|
1117
|
+
label: string;
|
|
1118
|
+
value: "isEmpty";
|
|
1119
|
+
} | {
|
|
1120
|
+
label: string;
|
|
1121
|
+
value: "isNotEmpty";
|
|
1122
|
+
})[];
|
|
1123
|
+
selectOperators: ({
|
|
1124
|
+
label: string;
|
|
1125
|
+
value: "eq";
|
|
1126
|
+
} | {
|
|
1127
|
+
label: string;
|
|
1128
|
+
value: "ne";
|
|
1129
|
+
} | {
|
|
1130
|
+
label: string;
|
|
1131
|
+
value: "isEmpty";
|
|
1132
|
+
} | {
|
|
1133
|
+
label: string;
|
|
1134
|
+
value: "isNotEmpty";
|
|
1135
|
+
})[];
|
|
1136
|
+
multiSelectOperators: ({
|
|
1137
|
+
label: string;
|
|
1138
|
+
value: "inArray";
|
|
1139
|
+
} | {
|
|
1140
|
+
label: string;
|
|
1141
|
+
value: "notInArray";
|
|
1142
|
+
} | {
|
|
1143
|
+
label: string;
|
|
1144
|
+
value: "isEmpty";
|
|
1145
|
+
} | {
|
|
1146
|
+
label: string;
|
|
1147
|
+
value: "isNotEmpty";
|
|
1148
|
+
})[];
|
|
1149
|
+
booleanOperators: ({
|
|
1150
|
+
label: string;
|
|
1151
|
+
value: "eq";
|
|
1152
|
+
} | {
|
|
1153
|
+
label: string;
|
|
1154
|
+
value: "ne";
|
|
1155
|
+
})[];
|
|
1156
|
+
sortOrders: ({
|
|
1157
|
+
label: string;
|
|
1158
|
+
value: "asc";
|
|
1159
|
+
} | {
|
|
1160
|
+
label: string;
|
|
1161
|
+
value: "desc";
|
|
1162
|
+
})[];
|
|
1163
|
+
filterVariants: readonly ["text", "number", "range", "date", "dateRange", "boolean", "select", "multiSelect", "tags"];
|
|
1164
|
+
operators: readonly ["iLike", "notILike", "eq", "ne", "inArray", "notInArray", "isEmpty", "isNotEmpty", "lt", "lte", "gt", "gte", "isBetween", "isRelativeToToday", "matches"];
|
|
1165
|
+
joinOperators: readonly ["and", "or"];
|
|
1166
|
+
};
|
|
1167
|
+
//#endregion
|
|
1168
|
+
//#region src/types/data-table.d.ts
|
|
1169
|
+
interface DataTableClassNames {
|
|
1170
|
+
table?: string;
|
|
1171
|
+
thead?: string;
|
|
1172
|
+
tbody?: string;
|
|
1173
|
+
/** 应用于表头行、正文行和空状态行 */
|
|
1174
|
+
tr?: string;
|
|
1175
|
+
th?: string;
|
|
1176
|
+
td?: string;
|
|
1177
|
+
}
|
|
1178
|
+
/** Optional pagination controls. Omitted options preserve the existing layout. */
|
|
1179
|
+
interface TablePaginationOptions {
|
|
1180
|
+
locale?: Partial<TablePaginationLocale>;
|
|
1181
|
+
/** Show first/last page buttons at every viewport width; default remains lg-only. */
|
|
1182
|
+
alwaysShowFirstLast?: boolean;
|
|
1183
|
+
/** Hide optional controls when their measured content does not fit the container. */
|
|
1184
|
+
responsive?: boolean;
|
|
1185
|
+
/** Show an input to jump to a known page; defaults to false. */
|
|
1186
|
+
showPageJump?: boolean;
|
|
1187
|
+
pageJumpLabel?: string;
|
|
1188
|
+
}
|
|
1189
|
+
declare module '@tanstack/react-table' {
|
|
1190
|
+
interface TableMeta<TData extends RowData> {
|
|
1191
|
+
queryKeys?: QueryKeys;
|
|
1192
|
+
queryStateOptions?: UrlStateOptions;
|
|
1193
|
+
filterState?: TableFilterState<TData>;
|
|
1194
|
+
/** @internal Renders the batch value using the existing filter controls. */
|
|
1195
|
+
renderFilterValue?: (filter: ExtendedColumnFilter<TData>, props: {
|
|
1196
|
+
className?: string;
|
|
1197
|
+
}) => React.ReactNode;
|
|
1198
|
+
}
|
|
1199
|
+
interface ColumnMeta<TData extends RowData, TValue> {
|
|
1200
|
+
label?: string;
|
|
1201
|
+
index?: number;
|
|
1202
|
+
/** @internal Identifies the generated row expansion control, regardless of its id. */
|
|
1203
|
+
autoCrudExpandColumn?: boolean;
|
|
1204
|
+
/** 按元素分组的列类名,优先于全局单元格类名 */
|
|
1205
|
+
classNames?: Pick<DataTableClassNames, 'th' | 'td'>;
|
|
1206
|
+
placeholder?: string;
|
|
1207
|
+
variant?: FilterVariant$1;
|
|
1208
|
+
options?: Option[];
|
|
1209
|
+
range?: [number, number];
|
|
1210
|
+
/** Latest selectable calendar day (YYYY-MM-DD), or today in the Host time zone. */
|
|
1211
|
+
maxDate?: string;
|
|
1212
|
+
unit?: string;
|
|
1213
|
+
icon?: React.FC<React.SVGProps<SVGSVGElement>>;
|
|
1214
|
+
/** 控制在哪些筛选模式下显示(未设置则在所有模式显示) */
|
|
1215
|
+
modes?: Array<'simple' | 'advanced' | 'command'>;
|
|
1216
|
+
/** 内部:远程筛选选项搜索值 */
|
|
1217
|
+
autoCrudFilterSearchValue?: string;
|
|
1218
|
+
/** 内部:远程筛选选项搜索回调 */
|
|
1219
|
+
autoCrudFilterOnSearch?: (value: string) => void;
|
|
1220
|
+
/** 内部:是否启用本地选项过滤 */
|
|
1221
|
+
autoCrudFilterShouldFilter?: boolean;
|
|
1222
|
+
/** 内部:远程筛选当前弹窗选项,和稳定标签缓存分离 */
|
|
1223
|
+
autoCrudFilterOptions?: Option[];
|
|
1224
|
+
/** 内部:远程筛选是否还有更多选项 */
|
|
1225
|
+
autoCrudFilterHasMore?: boolean;
|
|
1226
|
+
/** 内部:远程筛选是否正在加载 */
|
|
1227
|
+
autoCrudFilterLoading?: boolean;
|
|
1228
|
+
/** 内部:远程筛选弹窗滚动回调 */
|
|
1229
|
+
autoCrudFilterOnPopupScroll?: React.UIEventHandler<HTMLElement>;
|
|
1230
|
+
}
|
|
1231
|
+
}
|
|
1232
|
+
interface QueryKeys {
|
|
1233
|
+
/** Saved view slug or ID. Defaults to "view". */
|
|
1234
|
+
view?: string;
|
|
1235
|
+
page: string;
|
|
1236
|
+
perPage: string;
|
|
1237
|
+
sort: string;
|
|
1238
|
+
filters: string;
|
|
1239
|
+
joinOperator: string;
|
|
1240
|
+
}
|
|
1241
|
+
interface Option {
|
|
1242
|
+
label: string;
|
|
1243
|
+
value: string;
|
|
1244
|
+
searchText?: string;
|
|
1245
|
+
count?: number;
|
|
1246
|
+
color?: string;
|
|
1247
|
+
icon?: React.FC<React.SVGProps<SVGSVGElement>>;
|
|
1248
|
+
}
|
|
1249
|
+
type FilterOperator = DataTableConfig['operators'][number];
|
|
1250
|
+
type FilterVariant$1 = DataTableConfig['filterVariants'][number];
|
|
1251
|
+
type JoinOperator = DataTableConfig['joinOperators'][number];
|
|
1252
|
+
interface ExtendedColumnSort<TData> extends Omit<ColumnSort, 'id'> {
|
|
1253
|
+
id: Extract<keyof TData, string>;
|
|
1254
|
+
}
|
|
1255
|
+
type ExtendedColumnFilter<TData> = FilterItemSchema & {
|
|
1256
|
+
id: Extract<keyof TData, string>;
|
|
1257
|
+
};
|
|
1258
|
+
interface TableFilterState<TData> {
|
|
1259
|
+
filters: ExtendedColumnFilter<TData>[];
|
|
1260
|
+
onFiltersChange: (updater: ExtendedColumnFilter<TData>[] | ((previous: ExtendedColumnFilter<TData>[]) => ExtendedColumnFilter<TData>[])) => void;
|
|
1261
|
+
}
|
|
1262
|
+
interface DataTableRowAction<TData> {
|
|
1263
|
+
row: Row<TData>;
|
|
1264
|
+
variant: 'update' | 'delete';
|
|
1265
|
+
}
|
|
1266
|
+
//#endregion
|
|
1267
|
+
//#region src/lib/parsers.d.ts
|
|
1268
|
+
declare const filterItemSchema: z.ZodUnion<readonly [z.ZodObject<{
|
|
1269
|
+
id: z.ZodString;
|
|
1270
|
+
value: z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>;
|
|
1271
|
+
variant: z.ZodEnum<{
|
|
1272
|
+
number: "number";
|
|
1273
|
+
boolean: "boolean";
|
|
1274
|
+
date: "date";
|
|
1275
|
+
text: "text";
|
|
1276
|
+
range: "range";
|
|
1277
|
+
dateRange: "dateRange";
|
|
1278
|
+
select: "select";
|
|
1279
|
+
multiSelect: "multiSelect";
|
|
1321
1280
|
}>;
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
}
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
value: ViewScope;
|
|
1351
|
-
label: string;
|
|
1352
|
-
}[];
|
|
1353
|
-
/** Initial view slug or ID when the URL and local preferences do not select a view. */
|
|
1354
|
-
defaultView?: string;
|
|
1355
|
-
/** Wait for async fields in standalone AutoTable; AutoCrudTable derives readiness from resource metadata. */
|
|
1356
|
-
fieldsReady?: boolean;
|
|
1357
|
-
/** Initial display mode when no local preference exists. */
|
|
1358
|
-
selector?: ViewPreferences['selector'];
|
|
1359
|
-
/** Appearance of the tab selector; supplied classes override the defaults. */
|
|
1360
|
-
tabs?: {
|
|
1361
|
-
variant?: 'default' | 'line';
|
|
1362
|
-
/** Position of the active line. Defaults to bottom; only applies to line tabs. */
|
|
1363
|
-
linePosition?: 'top' | 'bottom';
|
|
1364
|
-
classNames?: {
|
|
1365
|
-
list?: string;
|
|
1366
|
-
trigger?: string;
|
|
1367
|
-
indicator?: string;
|
|
1368
|
-
};
|
|
1369
|
-
};
|
|
1370
|
-
/** Count saved queries (including All), in batches of at most 100. Keys are opaque. */
|
|
1371
|
-
counts?: (input: {
|
|
1372
|
-
queries: Array<Pick<ViewQuery, 'filters' | 'joinOperator' | 'search'> & {
|
|
1373
|
-
key: string;
|
|
1281
|
+
operator: z.ZodEnum<{
|
|
1282
|
+
iLike: "iLike";
|
|
1283
|
+
notILike: "notILike";
|
|
1284
|
+
eq: "eq";
|
|
1285
|
+
ne: "ne";
|
|
1286
|
+
isEmpty: "isEmpty";
|
|
1287
|
+
isNotEmpty: "isNotEmpty";
|
|
1288
|
+
lt: "lt";
|
|
1289
|
+
lte: "lte";
|
|
1290
|
+
gt: "gt";
|
|
1291
|
+
gte: "gte";
|
|
1292
|
+
isBetween: "isBetween";
|
|
1293
|
+
isRelativeToToday: "isRelativeToToday";
|
|
1294
|
+
inArray: "inArray";
|
|
1295
|
+
notInArray: "notInArray";
|
|
1296
|
+
}>;
|
|
1297
|
+
filterId: z.ZodString;
|
|
1298
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
1299
|
+
id: z.ZodString;
|
|
1300
|
+
filterId: z.ZodString;
|
|
1301
|
+
variant: z.ZodLiteral<"tags">;
|
|
1302
|
+
operator: z.ZodLiteral<"matches">;
|
|
1303
|
+
value: z.ZodObject<{
|
|
1304
|
+
include: z.ZodArray<z.ZodString>;
|
|
1305
|
+
exclude: z.ZodArray<z.ZodString>;
|
|
1306
|
+
match: z.ZodEnum<{
|
|
1307
|
+
any: "any";
|
|
1308
|
+
all: "all";
|
|
1374
1309
|
}>;
|
|
1375
|
-
|
|
1376
|
-
|
|
1310
|
+
}, z.core.$strict>;
|
|
1311
|
+
}, z.core.$strip>]>;
|
|
1312
|
+
type FilterItemSchema = z.infer<typeof filterItemSchema>;
|
|
1313
|
+
//#endregion
|
|
1314
|
+
//#region src/lib/batch-search.d.ts
|
|
1315
|
+
interface BatchSearchConfig {
|
|
1316
|
+
/** Maximum unique values per query. Defaults to 2000. */
|
|
1317
|
+
maxItems?: number;
|
|
1318
|
+
}
|
|
1319
|
+
interface BatchSearchFilter {
|
|
1320
|
+
id: string;
|
|
1321
|
+
value: string[];
|
|
1322
|
+
variant: 'text' | 'number';
|
|
1323
|
+
operator: 'inArray';
|
|
1324
|
+
filterId: string;
|
|
1325
|
+
}
|
|
1326
|
+
interface BatchSearchState {
|
|
1327
|
+
filter: BatchSearchFilter | null;
|
|
1328
|
+
onFilterChange: (filter: BatchSearchFilter | null) => void;
|
|
1329
|
+
}
|
|
1330
|
+
interface BatchSearchField {
|
|
1331
|
+
id: string;
|
|
1332
|
+
label: string;
|
|
1333
|
+
}
|
|
1334
|
+
type BatchSearchIssue = {
|
|
1335
|
+
type: 'columns' | 'invalid';
|
|
1336
|
+
lines: number[];
|
|
1337
|
+
} | {
|
|
1338
|
+
type: 'limit';
|
|
1339
|
+
maxItems: number;
|
|
1340
|
+
};
|
|
1341
|
+
//#endregion
|
|
1342
|
+
//#region src/types/permissions.d.ts
|
|
1343
|
+
/**
|
|
1344
|
+
* CRUD 操作权限
|
|
1345
|
+
* 控制工具栏按钮、行操作按钮、批量操作按钮的显示
|
|
1346
|
+
*/
|
|
1347
|
+
interface CrudOperationPermissions {
|
|
1348
|
+
/** 是否允许创建(新建按钮、复制行操作) */
|
|
1349
|
+
create?: boolean;
|
|
1350
|
+
/** 是否允许更新(编辑按钮、批量更新) */
|
|
1351
|
+
update?: boolean;
|
|
1352
|
+
/** 是否允许删除(删除按钮、批量删除) */
|
|
1353
|
+
delete?: boolean;
|
|
1354
|
+
/** 是否允许导出 */
|
|
1355
|
+
export?: boolean;
|
|
1356
|
+
/** 是否允许导入 */
|
|
1357
|
+
import?: boolean;
|
|
1358
|
+
}
|
|
1359
|
+
/**
|
|
1360
|
+
* AutoCrudTable 权限配置
|
|
1361
|
+
*
|
|
1362
|
+
* @example
|
|
1363
|
+
* ```tsx
|
|
1364
|
+
* const permissions = useMemo(() => ({
|
|
1365
|
+
* can: {
|
|
1366
|
+
* create: user.role === 'admin',
|
|
1367
|
+
* update: user.role === 'admin' || user.role === 'editor',
|
|
1368
|
+
* delete: user.role === 'admin',
|
|
1369
|
+
* export: true,
|
|
1370
|
+
* },
|
|
1371
|
+
* deny: user.role === 'user' ? ['salary', 'ssn'] : [],
|
|
1372
|
+
* }), [user.role]);
|
|
1373
|
+
*
|
|
1374
|
+
* <AutoCrudTable
|
|
1375
|
+
* schema={employeeSchema}
|
|
1376
|
+
* resource={resource}
|
|
1377
|
+
* permissions={permissions}
|
|
1378
|
+
* />
|
|
1379
|
+
* ```
|
|
1380
|
+
*/
|
|
1381
|
+
interface CrudPermissions {
|
|
1382
|
+
/** 操作权限(默认全部为 true) */
|
|
1383
|
+
can?: CrudOperationPermissions;
|
|
1384
|
+
/** 禁止访问的字段列表(表格列和表单字段都会隐藏) */
|
|
1385
|
+
deny?: string[];
|
|
1377
1386
|
}
|
|
1378
1387
|
//#endregion
|
|
1379
1388
|
//#region src/components/data-table/data-table.d.ts
|