@wordrhyme/auto-crud 1.23.1 → 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/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { a as positionActions, i as matchesPosition, n as actionPositionSchema, r as compareOrder, t as ActionPosition } from "./position-mYekVBBH.js";
2
2
  import * as React$1 from "react";
3
3
  import { ComponentProps, ReactNode } from "react";
4
- import * as react_jsx_runtime20 from "react/jsx-runtime";
4
+ import * as react_jsx_runtime17 from "react/jsx-runtime";
5
5
  import { DropdownMenuTrigger, PopoverContentProps } from "@wordrhyme/shadcn";
6
6
  import { z } from "zod";
7
7
  import { ClassValue } from "clsx";
@@ -117,943 +117,154 @@ type AutoCrudSorting = Array<{
117
117
  desc: boolean;
118
118
  }>;
119
119
  //#endregion
120
- //#region src/hooks/use-auto-crud-resource.d.ts
121
- /**
122
- * Toast 适配器接口
123
- * 用户可以注入自己的 toast 实现
124
- */
125
- interface ToastAdapter {
126
- success: (message: string) => void;
127
- error: (message: string) => void;
128
- info?: (message: string) => void;
129
- warning?: (message: string) => void;
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
- /** 空 toast 适配器(禁用通知) */
132
- declare const noopToastAdapter: ToastAdapter;
133
- interface AutoCrudQueryCapabilities {
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
- * Modal 状态类型
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
- * Hook 返回值类型(用于判断是数据转换还是完全自定义)
163
- * - 返回对象 = 数据转换,继续执行默认 mutation
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
- * Hook 配置选项
198
- */
199
- interface UseAutoCrudResourceOptions<TSchema extends z.ZodObject<z.ZodRawShape>, TListItem> {
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
- * - undefined: schema 有 createdAt 时默认 createdAt desc
231
- * - false: 不应用默认排序
232
- */
233
- defaultSort?: AutoCrudSorting | false;
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
- /** Serializable validation details; excludes the submitted cell value. */
239
- interface ImportIssue {
240
- code: string;
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
- interface ImportResult {
246
- success: number;
247
- updated: number;
248
- skipped: number;
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
- /** The table waits for a returned promise and ignores its resolved value. */
303
- confirmDelete: () => void;
304
- deleteMany: (rows: TListItem[]) => void;
305
- updateMany: (rows: TListItem[], data: Record<string, unknown>) => void;
306
- setVariant: (variant: ModalVariant$1) => void;
307
- /** 刷新当前列表数据 */
308
- refresh?: () => Promise<unknown>;
309
- /** 导入数据(router 有 import 路由时自动可用) */
310
- import: ((rows: Record<string, unknown>[]) => Promise<ImportResult>) | null;
311
- /** 导出筛选结果(router 有 export procedure 或传入 exportFetcher 时自动可用)。导出选中行由 AutoCrudTable 内部处理 */
312
- export: (() => Promise<Record<string, unknown>[]>) | null;
313
- };
314
- }
315
- /**
316
- * tRPC Router 接口定义(宽松类型以兼容实际 tRPC router)
317
- * import 为可选 — 传入 router 时自动检测是否存在
318
- */
319
- interface CrudRouter {
320
- list: {
321
- useQuery: (input?: any, opts?: any) => any;
322
- };
323
- create: {
324
- useMutation: (opts?: any) => any;
325
- };
326
- update: {
327
- useMutation: (opts?: any) => any;
328
- };
329
- delete: {
330
- useMutation: (opts?: any) => any;
331
- };
332
- deleteMany?: {
333
- useMutation: (opts?: any) => any;
334
- };
335
- updateMany?: {
336
- useMutation: (opts?: any) => any;
337
- };
338
- /** 导入路由(mutation,由 createCrudRouter 自动生成) */
339
- import?: {
340
- useMutation: (opts?: any) => any;
341
- };
342
- /** 导出路由(query,由 createCrudRouter 自动生成) */
343
- export?: {
344
- useQuery: (input?: any, opts?: any) => any;
345
- };
346
- /** 元数据路由(query,由 createCrudRouter 自动生成) */
347
- meta?: {
348
- useQuery: (input?: any, opts?: any) => any;
349
- };
350
- }
351
- /**
352
- * 自动生成的查询参数(由内部 URL 状态管理生成)
353
- */
354
- interface AutoQueryParams {
355
- page: number;
356
- perPage: number;
357
- sort: Array<{
358
- id: string;
359
- desc: boolean;
360
- }>;
361
- search?: string;
362
- filters: any[];
363
- joinOperator: 'and' | 'or';
364
- }
365
- /**
366
- * Hook 配置参数
367
- */
368
- interface UseAutoCrudResourceParams<TSchema extends z.ZodObject<z.ZodRawShape>, TListItem> {
369
- /** tRPC router (如 trpc.tasks) */
370
- router: CrudRouter;
371
- /** URL keys shared with the table, for multiple resources on one page. */
372
- queryKeys?: Partial<QueryKeys>;
373
- /** Zod schema */
374
- schema: TSchema;
375
- /** Field filter configuration shared with AutoCrudTable. */
376
- fields?: Fields;
377
- /**
378
- * 查询参数变换函数
379
- *
380
- * 默认零配置:hook 内部自动管理 URL 状态(分页、排序、筛选),
381
- * 传入此函数可注入额外参数或修改自动生成的参数。
382
- *
383
- * @example
384
- * ```tsx
385
- * // 注入租户 ID
386
- * query: (params) => ({ ...params, tenantId: currentTenant.id })
387
- *
388
- * // 覆盖默认分页
389
- * query: (params) => ({ ...params, perPage: 20 })
390
- * ```
391
- */
392
- query?: (params: AutoQueryParams) => Record<string, unknown>;
393
- /** tRPC operation context shared by list and automatic export requests. */
394
- queryContext?: Record<string, unknown>;
395
- /** 其他配置选项 */
396
- options?: UseAutoCrudResourceOptions<TSchema, TListItem>;
397
- }
398
- /**
399
- * Hook 主函数
400
- */
401
- declare function useAutoCrudResource<TSchema extends z.ZodObject<z.ZodRawShape>, TListItem = z.output<TSchema>>({
402
- router,
403
- queryKeys,
404
- schema,
405
- query: queryTransform,
406
- queryContext,
407
- fields,
408
- options
409
- }: UseAutoCrudResourceParams<TSchema, TListItem>): UseAutoCrudResourceReturn<TSchema, TListItem>;
410
- //#endregion
411
- //#region src/i18n/locale.d.ts
412
- /**
413
- * AutoCrud 国际化接口及内置语言包
414
- *
415
- * 使用方式:
416
- * // 内置语言
417
- * <AutoCrudTable locale="en-US" ... />
418
- *
419
- * // 部分覆盖(以 zh-CN 为基础深合并)
420
- * <AutoCrudTable locale={{ toolbar: { create: "Add" } }} ... />
421
- */
422
- interface TableControlsLocale {
423
- sort: {
424
- label: string;
425
- title: string;
426
- empty: string;
427
- description: string;
428
- emptyDescription: string;
429
- add: string;
430
- reset: string;
431
- searchFields: string;
432
- noFields: string;
433
- ascending: string;
434
- descending: string;
435
- direction: string;
436
- remove: string;
437
- move: string;
438
- dragInstructions: string;
439
- dragOutside: string;
440
- dragStarted: (label: string, position: number, total: number) => string;
441
- dragMoved: (label: string, position: number, total: number) => string;
442
- dragDropped: (label: string, position: number, total: number) => string;
443
- dragCancelled: (label: string) => string;
444
- };
445
- columns: {
446
- label: string;
447
- search: string;
448
- empty: string;
449
- };
450
- }
451
- interface TablePaginationLocale {
452
- selected: (count: number, total: number) => string;
453
- total: (count: number) => string;
454
- rowsPerPage: string;
455
- page: (page: number, total: number) => string;
456
- pageJump: string;
457
- firstPage: string;
458
- previousPage: string;
459
- nextPage: string;
460
- lastPage: string;
461
- }
462
- interface TableActionBarLocale {
463
- selected: (count: number) => string;
464
- export: string;
465
- delete: string;
466
- clearSelection: string;
467
- }
468
- interface AutoCrudLocale {
469
- /** Label shared by automatic tag assignment actions and their dialog. */
470
- tagAssignment?: (fieldLabel: string) => string;
471
- batchSearch?: BatchSearchLocale;
472
- /** Sorting and column visibility controls. Optional for existing custom locales. */
473
- tableControls?: TableControlsLocale;
474
- pagination?: Partial<TablePaginationLocale>;
475
- actionBar?: Partial<TableActionBarLocale>;
476
- toolbar: {
477
- refresh: string;
478
- create: string;
479
- import: string;
480
- export: string;
481
- exportSelected: (count: number) => string;
482
- };
483
- rowActions: {
484
- view: string;
485
- edit: string;
486
- copy: string;
487
- delete: string;
488
- };
489
- viewModal: {
490
- title: string;
491
- };
492
- boolean: {
493
- true: string;
494
- false: string;
495
- };
496
- formModal: {
497
- createTitle: string;
498
- editTitle: string;
499
- cancel: string;
500
- create: string;
501
- save: string;
502
- submitting: string;
503
- };
504
- deleteModal: {
505
- title: string;
506
- description: string;
507
- cancel: string;
508
- confirm: string;
509
- confirming: string;
510
- };
511
- bulkDeleteModal: {
512
- title: string;
513
- description: (count: number) => string;
514
- cancel: string;
515
- confirm: string;
516
- };
517
- importDialog: {
518
- title: string;
519
- uploadDescription: string;
520
- previewDescription: (count: number) => string;
521
- importingDescription: string;
522
- doneDescription: string;
523
- dragHint: string;
524
- formatHint: string;
525
- downloadTemplate: string;
526
- moreColumns: (count: number) => string;
527
- previewSummary: (rows: number, fields: number, format: string, previewLimit?: number) => string;
528
- reselect: string;
529
- confirmImport: string;
530
- importingRows: (count: number) => string;
531
- resultCreated: string;
532
- resultUpdated: string;
533
- resultSkipped: string;
534
- resultFailed: string;
535
- failedRowHeader: string;
536
- failedErrorHeader: string;
537
- close: string;
538
- continueImport: string;
539
- errorNoData: string;
540
- errorParseFailed: string;
541
- errorImportFailed: string;
542
- /** Localize structured validation issues; plain string errors are preserved. */
543
- validationError?: (issue: ImportIssue) => string;
544
- };
545
- }
546
- declare const zhCN: AutoCrudLocale;
547
- declare const enUS: AutoCrudLocale;
548
- declare const jaJP: AutoCrudLocale;
549
- declare const koKR: AutoCrudLocale;
550
- declare const frFR: AutoCrudLocale;
551
- declare const deDE: AutoCrudLocale;
552
- declare const esES: AutoCrudLocale;
553
- 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] };
554
- /** locale prop 类型:内置语言 key 或部分覆盖对象 */
555
- type LocaleProp = string | DeepPartial<AutoCrudLocale>;
556
- /**
557
- * 解析 locale prop 为完整的 AutoCrudLocale
558
- * - string → 内置语言(fallback: zh-CN)
559
- * - object → 以 zh-CN 为基础深合并
560
- */
561
- declare function resolveLocale(localeProp?: LocaleProp): AutoCrudLocale;
562
- //#endregion
563
- //#region src/config/data-table.d.ts
564
- type DataTableConfig = typeof dataTableConfig;
565
- declare const dataTableConfig: {
566
- textOperators: ({
567
- label: string;
568
- value: "iLike";
569
- } | {
570
- label: string;
571
- value: "notILike";
572
- } | {
573
- label: string;
574
- value: "eq";
575
- } | {
576
- label: string;
577
- value: "ne";
578
- } | {
579
- label: string;
580
- value: "isEmpty";
581
- } | {
582
- label: string;
583
- value: "isNotEmpty";
584
- })[];
585
- numericOperators: ({
586
- label: string;
587
- value: "eq";
588
- } | {
589
- label: string;
590
- value: "ne";
591
- } | {
592
- label: string;
593
- value: "lt";
594
- } | {
595
- label: string;
596
- value: "lte";
597
- } | {
598
- label: string;
599
- value: "gt";
600
- } | {
601
- label: string;
602
- value: "gte";
603
- } | {
604
- label: string;
605
- value: "isBetween";
606
- } | {
607
- label: string;
608
- value: "isEmpty";
609
- } | {
610
- label: string;
611
- value: "isNotEmpty";
612
- })[];
613
- dateOperators: ({
614
- label: string;
615
- value: "eq";
616
- } | {
617
- label: string;
618
- value: "ne";
619
- } | {
620
- label: string;
621
- value: "lt";
622
- } | {
623
- label: string;
624
- value: "gt";
625
- } | {
626
- label: string;
627
- value: "lte";
628
- } | {
629
- label: string;
630
- value: "gte";
631
- } | {
632
- label: string;
633
- value: "isBetween";
634
- } | {
635
- label: string;
636
- value: "isRelativeToToday";
637
- } | {
638
- label: string;
639
- value: "isEmpty";
640
- } | {
641
- label: string;
642
- value: "isNotEmpty";
643
- })[];
644
- selectOperators: ({
645
- label: string;
646
- value: "eq";
647
- } | {
648
- label: string;
649
- value: "ne";
650
- } | {
651
- label: string;
652
- value: "isEmpty";
653
- } | {
654
- label: string;
655
- value: "isNotEmpty";
656
- })[];
657
- multiSelectOperators: ({
658
- label: string;
659
- value: "inArray";
660
- } | {
661
- label: string;
662
- value: "notInArray";
663
- } | {
664
- label: string;
665
- value: "isEmpty";
666
- } | {
667
- label: string;
668
- value: "isNotEmpty";
669
- })[];
670
- booleanOperators: ({
671
- label: string;
672
- value: "eq";
673
- } | {
674
- label: string;
675
- value: "ne";
676
- })[];
677
- sortOrders: ({
678
- label: string;
679
- value: "asc";
680
- } | {
681
- label: string;
682
- value: "desc";
683
- })[];
684
- filterVariants: readonly ["text", "number", "range", "date", "dateRange", "boolean", "select", "multiSelect", "tags"];
685
- operators: readonly ["iLike", "notILike", "eq", "ne", "inArray", "notInArray", "isEmpty", "isNotEmpty", "lt", "lte", "gt", "gte", "isBetween", "isRelativeToToday", "matches"];
686
- joinOperators: readonly ["and", "or"];
687
- };
688
- //#endregion
689
- //#region src/types/data-table.d.ts
690
- interface DataTableClassNames {
691
- table?: string;
692
- thead?: string;
693
- tbody?: string;
694
- /** 应用于表头行、正文行和空状态行 */
695
- tr?: string;
696
- th?: string;
697
- td?: string;
698
- }
699
- /** Optional pagination controls. Omitted options preserve the existing layout. */
700
- interface TablePaginationOptions {
701
- locale?: Partial<TablePaginationLocale>;
702
- /** Show first/last page buttons at every viewport width; default remains lg-only. */
703
- alwaysShowFirstLast?: boolean;
704
- /** Hide optional controls when their measured content does not fit the container. */
705
- responsive?: boolean;
706
- /** Show an input to jump to a known page; defaults to false. */
707
- showPageJump?: boolean;
708
- pageJumpLabel?: string;
709
- }
710
- declare module '@tanstack/react-table' {
711
- interface TableMeta<TData extends RowData> {
712
- queryKeys?: QueryKeys;
713
- queryStateOptions?: UrlStateOptions;
714
- filterState?: TableFilterState<TData>;
715
- /** @internal Renders the batch value using the existing filter controls. */
716
- renderFilterValue?: (filter: ExtendedColumnFilter<TData>, props: {
717
- className?: string;
718
- }) => React.ReactNode;
719
- }
720
- interface ColumnMeta<TData extends RowData, TValue> {
721
- label?: string;
722
- index?: number;
723
- /** @internal Identifies the generated row expansion control, regardless of its id. */
724
- autoCrudExpandColumn?: boolean;
725
- /** 按元素分组的列类名,优先于全局单元格类名 */
726
- classNames?: Pick<DataTableClassNames, 'th' | 'td'>;
727
- placeholder?: string;
728
- variant?: FilterVariant$1;
729
- options?: Option[];
730
- range?: [number, number];
731
- /** Latest selectable calendar day (YYYY-MM-DD), or today in the Host time zone. */
732
- maxDate?: string;
733
- unit?: string;
734
- icon?: React.FC<React.SVGProps<SVGSVGElement>>;
735
- /** 控制在哪些筛选模式下显示(未设置则在所有模式显示) */
736
- modes?: Array<'simple' | 'advanced' | 'command'>;
737
- /** 内部:远程筛选选项搜索值 */
738
- autoCrudFilterSearchValue?: string;
739
- /** 内部:远程筛选选项搜索回调 */
740
- autoCrudFilterOnSearch?: (value: string) => void;
741
- /** 内部:是否启用本地选项过滤 */
742
- autoCrudFilterShouldFilter?: boolean;
743
- /** 内部:远程筛选当前弹窗选项,和稳定标签缓存分离 */
744
- autoCrudFilterOptions?: Option[];
745
- /** 内部:远程筛选是否还有更多选项 */
746
- autoCrudFilterHasMore?: boolean;
747
- /** 内部:远程筛选是否正在加载 */
748
- autoCrudFilterLoading?: boolean;
749
- /** 内部:远程筛选弹窗滚动回调 */
750
- autoCrudFilterOnPopupScroll?: React.UIEventHandler<HTMLElement>;
751
- }
752
- }
753
- interface QueryKeys {
754
- /** Saved view slug or ID. Defaults to "view". */
755
- view?: string;
756
- page: string;
757
- perPage: string;
758
- sort: string;
759
- filters: string;
760
- joinOperator: string;
761
- }
762
- interface Option {
763
- label: string;
764
- value: string;
765
- searchText?: string;
766
- count?: number;
767
- color?: string;
768
- icon?: React.FC<React.SVGProps<SVGSVGElement>>;
769
- }
770
- type FilterOperator = DataTableConfig['operators'][number];
771
- type FilterVariant$1 = DataTableConfig['filterVariants'][number];
772
- type JoinOperator = DataTableConfig['joinOperators'][number];
773
- interface ExtendedColumnSort<TData> extends Omit<ColumnSort, 'id'> {
774
- id: Extract<keyof TData, string>;
775
- }
776
- type ExtendedColumnFilter<TData> = FilterItemSchema & {
777
- id: Extract<keyof TData, string>;
778
- };
779
- interface TableFilterState<TData> {
780
- filters: ExtendedColumnFilter<TData>[];
781
- onFiltersChange: (updater: ExtendedColumnFilter<TData>[] | ((previous: ExtendedColumnFilter<TData>[]) => ExtendedColumnFilter<TData>[])) => void;
782
- }
783
- interface DataTableRowAction<TData> {
784
- row: Row<TData>;
785
- variant: 'update' | 'delete';
786
- }
787
- //#endregion
788
- //#region src/lib/parsers.d.ts
789
- declare const filterItemSchema: z.ZodUnion<readonly [z.ZodObject<{
790
- id: z.ZodString;
791
- value: z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>;
792
- variant: z.ZodEnum<{
793
- number: "number";
794
- boolean: "boolean";
795
- date: "date";
796
- text: "text";
797
- range: "range";
798
- dateRange: "dateRange";
799
- select: "select";
800
- multiSelect: "multiSelect";
801
- }>;
802
- operator: z.ZodEnum<{
803
- iLike: "iLike";
804
- notILike: "notILike";
805
- eq: "eq";
806
- ne: "ne";
807
- isEmpty: "isEmpty";
808
- isNotEmpty: "isNotEmpty";
809
- lt: "lt";
810
- lte: "lte";
811
- gt: "gt";
812
- gte: "gte";
813
- isBetween: "isBetween";
814
- isRelativeToToday: "isRelativeToToday";
815
- inArray: "inArray";
816
- notInArray: "notInArray";
817
- }>;
818
- filterId: z.ZodString;
819
- }, z.core.$strip>, z.ZodObject<{
820
- id: z.ZodString;
821
- filterId: z.ZodString;
822
- variant: z.ZodLiteral<"tags">;
823
- operator: z.ZodLiteral<"matches">;
824
- value: z.ZodObject<{
825
- include: z.ZodArray<z.ZodString>;
826
- exclude: z.ZodArray<z.ZodString>;
827
- match: z.ZodEnum<{
828
- any: "any";
829
- all: "all";
830
- }>;
831
- }, z.core.$strict>;
832
- }, z.core.$strip>]>;
833
- type FilterItemSchema = z.infer<typeof filterItemSchema>;
834
- //#endregion
835
- //#region src/lib/batch-search.d.ts
836
- interface BatchSearchConfig {
837
- /** Maximum unique values per query. Defaults to 2000. */
838
- maxItems?: number;
839
- }
840
- interface BatchSearchFilter {
841
- id: string;
842
- value: string[];
843
- variant: 'text' | 'number';
844
- operator: 'inArray';
845
- filterId: string;
846
- }
847
- interface BatchSearchState {
848
- filter: BatchSearchFilter | null;
849
- onFilterChange: (filter: BatchSearchFilter | null) => void;
850
- }
851
- interface BatchSearchField {
852
- id: string;
853
- label: string;
854
- }
855
- type BatchSearchIssue = {
856
- type: 'columns' | 'invalid';
857
- lines: number[];
858
- } | {
859
- type: 'limit';
860
- maxItems: number;
861
- };
862
- //#endregion
863
- //#region src/types/permissions.d.ts
864
- /**
865
- * CRUD 操作权限
866
- * 控制工具栏按钮、行操作按钮、批量操作按钮的显示
867
- */
868
- interface CrudOperationPermissions {
869
- /** 是否允许创建(新建按钮、复制行操作) */
870
- create?: boolean;
871
- /** 是否允许更新(编辑按钮、批量更新) */
872
- update?: boolean;
873
- /** 是否允许删除(删除按钮、批量删除) */
874
- delete?: boolean;
875
- /** 是否允许导出 */
876
- export?: boolean;
877
- /** 是否允许导入 */
878
- import?: boolean;
879
- }
880
- /**
881
- * AutoCrudTable 权限配置
882
- *
883
- * @example
884
- * ```tsx
885
- * const permissions = useMemo(() => ({
886
- * can: {
887
- * create: user.role === 'admin',
888
- * update: user.role === 'admin' || user.role === 'editor',
889
- * delete: user.role === 'admin',
890
- * export: true,
891
- * },
892
- * deny: user.role === 'user' ? ['salary', 'ssn'] : [],
893
- * }), [user.role]);
894
- *
895
- * <AutoCrudTable
896
- * schema={employeeSchema}
897
- * resource={resource}
898
- * permissions={permissions}
899
- * />
900
- * ```
901
- */
902
- interface CrudPermissions {
903
- /** 操作权限(默认全部为 true) */
904
- can?: CrudOperationPermissions;
905
- /** 禁止访问的字段列表(表格列和表单字段都会隐藏) */
906
- deny?: string[];
907
- }
908
- //#endregion
909
- //#region src/lib/registries.d.ts
910
- type AutoCrudFormComponentConfig = {
911
- component: React$1.ComponentType<any>;
912
- decorator?: string | React$1.ComponentType<any>;
913
- [key: string]: unknown;
914
- };
915
- type AutoCrudOption = {
916
- value: string;
917
- label: string;
918
- searchText?: string | string[];
919
- keywords?: string[];
920
- count?: number;
921
- color?: string;
922
- disabled?: boolean;
923
- };
924
- type AutoCrudDataSourceContextType = 'form' | 'filter' | 'resolve';
925
- type AutoCrudDataSourceResolveFields = readonly string[] | ((context: {
926
- field: string;
927
- }) => readonly string[]);
928
- type AutoCrudDataSourceContext = {
929
- field: string;
930
- type: AutoCrudDataSourceContextType;
931
- page?: number;
932
- pageSize?: number;
933
- query?: string;
934
- /** @deprecated Use `query` instead. */
935
- search?: string;
936
- values?: Record<string, unknown> | Record<string, unknown>[];
937
- signal?: AbortSignal;
938
- };
939
- type AutoCrudDataSourceResult = AutoCrudOption[] | {
940
- hasMore?: boolean;
941
- options?: AutoCrudOption[];
942
- };
943
- type AutoCrudDataSourceLoader = (context: AutoCrudDataSourceContext) => AutoCrudDataSourceResult | Promise<AutoCrudDataSourceResult>;
944
- type AutoCrudDataSourceConfig = string;
945
- type AutoCrudDataSourceRegistration = AutoCrudDataSourceLoader | {
946
- dependencies?: string[];
947
- reset?: boolean;
948
- search?: boolean;
949
- debounceMs?: number;
950
- loadMore?: boolean;
951
- pageSize?: number;
952
- resolveFields?: AutoCrudDataSourceResolveFields;
953
- load: AutoCrudDataSourceLoader;
954
- };
955
- type AutoCrudDataSourceEntry = {
956
- dependencies: string[];
957
- reset: boolean;
958
- search: boolean;
959
- debounceMs: number;
960
- loadMore: boolean;
961
- pageSize: number;
962
- resolveFields?: AutoCrudDataSourceResolveFields;
963
- load: AutoCrudDataSourceLoader;
964
- };
965
- type RegistryListener$1 = () => void;
966
- declare const tablePagination: {
967
- register(name: string, value: TablePaginationOptions): void;
968
- unregister(name: string): void;
969
- get(name: string): TablePaginationOptions | undefined;
970
- all(): Record<string, TablePaginationOptions>;
971
- subscribe(listener: RegistryListener$1): () => void;
972
- };
973
- declare const formComponents: {
974
- register(name: string, value: AutoCrudFormComponentConfig): void;
975
- unregister(name: string): void;
976
- get(name: string): AutoCrudFormComponentConfig | undefined;
977
- all(): Record<string, AutoCrudFormComponentConfig>;
978
- subscribe(listener: RegistryListener$1): () => void;
979
- };
980
- declare const components: {
981
- register(name: string, value: AutoCrudFormComponentConfig): void;
982
- unregister(name: string): void;
983
- get(name: string): AutoCrudFormComponentConfig | undefined;
984
- all(): Record<string, AutoCrudFormComponentConfig>;
985
- subscribe(listener: RegistryListener$1): () => void;
986
- };
987
- declare const dataSources: {
988
- register(name: string, registration: AutoCrudDataSourceRegistration): void;
989
- unregister: (name: string) => void;
990
- get: (name: string) => AutoCrudDataSourceEntry | undefined;
991
- all: () => Record<string, AutoCrudDataSourceEntry>;
992
- subscribe: (listener: RegistryListener$1) => () => void;
993
- };
994
- declare function normalizeDataSourceConfig(config: AutoCrudDataSourceConfig | undefined): {
995
- key: string;
996
- } | undefined;
997
- declare function normalizeOptions(result: AutoCrudDataSourceResult | undefined): AutoCrudOption[];
998
- //#endregion
999
- //#region src/components/auto-crud/auto-crud-provider.d.ts
1000
- interface ViewStorage {
1001
- list: (resourceId: string) => Promise<SavedView[]>;
1002
- create: (resourceId: string, input: ViewInput) => Promise<SavedView>;
1003
- update: (resourceId: string, id: string, input: ViewInput) => Promise<SavedView>;
1004
- remove: (resourceId: string, id: string) => Promise<void>;
1005
- /** Omit to use the adapter's default scope. Empty createScopes disables creation. */
1006
- getCapabilities?: (resourceId: string) => Promise<ViewStorageCapabilities>;
1007
- /** Complete permutation of permitted persisted IDs; other rows keep their slots. The selector uses local preferences. */
1008
- reorder?: (resourceId: string, ids: string[]) => Promise<void>;
1009
- }
1010
- interface TagScope {
1011
- resourceId: string;
1012
- field: string;
1013
- }
1014
- interface TagInput {
1015
- label: string;
1016
- color: string;
1017
- }
1018
- interface TagOption extends TagInput {
1019
- disabled?: boolean;
1020
- value: string;
1021
- }
1022
- interface TagService {
1023
- /** Search a page of tags; set hasMore to false on the last page. */
1024
- list: (input: TagScope & Pick<AutoCrudDataSourceContext, 'query' | 'page' | 'pageSize' | 'signal'>) => Promise<{
1025
- options: TagOption[];
1026
- hasMore: boolean;
1027
- }>;
1028
- /** Resolve all selected IDs; missing IDs remain visible as invalid selections. */
1029
- resolve: (input: TagScope & {
1030
- ids: string[];
1031
- }) => Promise<TagOption[]>;
1032
- create?: (input: TagScope & TagInput) => Promise<TagOption>;
1033
- update?: (input: TagScope & TagInput & {
1034
- id: string;
1035
- }) => Promise<TagOption>;
1036
- remove?: (input: TagScope & {
1037
- id: string;
1038
- }) => Promise<void>;
1039
- /** Add/remove only the specified tags; preserve every other existing tag. */
1040
- assign?: (input: TagScope & {
1041
- entityIds: string[];
1042
- add: string[];
1043
- remove: string[];
1044
- }) => Promise<void>;
1045
- }
1046
- interface AutoCrudProviderProps {
1047
- /** Change with the signed-in user/tenant; remounts cached UI state. */
1048
- scope: string;
1049
- viewStorage?: ViewStorage;
1050
- tagService?: TagService;
1051
- children: ReactNode;
1052
- }
1053
- declare function AutoCrudProvider({
1054
- children,
1055
- ...config
1056
- }: AutoCrudProviderProps): react_jsx_runtime20.JSX.Element;
264
+ declare function AutoCrudProvider({
265
+ children,
266
+ ...config
267
+ }: AutoCrudProviderProps): react_jsx_runtime17.JSX.Element;
1057
268
  //#endregion
1058
269
  //#region src/lib/saved-views.d.ts
1059
270
  declare const viewQuerySchema: z.ZodObject<{
@@ -1307,74 +518,871 @@ declare const presetViewSchema: z.ZodObject<{
1307
518
  name: z.ZodString;
1308
519
  slug: z.ZodOptional<z.ZodString>;
1309
520
  id: z.ZodString;
1310
- }, z.core.$strict>;
1311
- type ViewQuery = z.infer<typeof viewQuerySchema>;
1312
- type ViewScope = z.infer<typeof viewScopeSchema>;
1313
- type ViewCapabilities = z.infer<typeof viewCapabilitiesSchema>;
1314
- type ViewStorageCapabilities = z.infer<typeof viewStorageCapabilitiesSchema>;
1315
- type ViewInput = z.infer<typeof viewInputSchema>;
1316
- type SavedView = z.infer<typeof savedViewSchema>;
1317
- type PresetView = z.infer<typeof presetViewSchema>;
1318
- declare const viewPreferencesSchema: z.ZodPipe<z.ZodObject<{
1319
- selector: z.ZodEnum<{
1320
- dropdown: "dropdown";
1321
- 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";
1322
1280
  }>;
1323
- viewId: z.ZodNullable<z.ZodString>;
1324
- viewOrder: z.ZodCatch<z.ZodOptional<z.ZodArray<z.ZodString>>>;
1325
- hiddenViewIds: z.ZodCatch<z.ZodOptional<z.ZodArray<z.ZodString>>>;
1326
- hiddenPresetIds: z.ZodCatch<z.ZodOptional<z.ZodArray<z.ZodString>>>;
1327
- }, z.core.$strip>, z.ZodTransform<{
1328
- selector: "dropdown" | "tabs";
1329
- viewId: string | null;
1330
- viewOrder?: string[] | undefined;
1331
- hiddenViewIds?: string[] | undefined;
1332
- }, {
1333
- selector: "dropdown" | "tabs";
1334
- viewId: string | null;
1335
- viewOrder?: string[] | undefined;
1336
- hiddenViewIds?: string[] | undefined;
1337
- hiddenPresetIds?: string[] | undefined;
1338
- }>>;
1339
- type ViewPreferences = z.infer<typeof viewPreferencesSchema>;
1340
- /** namespace must identify both the user and tenant. No implicit browser fallback. */
1341
- declare function createLocalViewStorage(namespace: string): ViewStorage;
1342
- //#endregion
1343
- //#region src/components/auto-crud/saved-views.d.ts
1344
- interface SavedViewsConfig {
1345
- /** Code-defined queries; users may hide/reorder their display locally. IDs/slugs must be unique across sources. */
1346
- presets?: readonly PresetView[];
1347
- /** Page-hidden view IDs or slugs from any source. Overrides personal preferences; excluded from restore. */
1348
- hiddenViews?: readonly string[];
1349
- /** Opt into scope selection with Host-defined values and labels. Single options stay hidden. */
1350
- scopeOptions?: readonly {
1351
- value: ViewScope;
1352
- label: string;
1353
- }[];
1354
- /** Initial view slug or ID when the URL and local preferences do not select a view. */
1355
- defaultView?: string;
1356
- /** Wait for async fields in standalone AutoTable; AutoCrudTable derives readiness from resource metadata. */
1357
- fieldsReady?: boolean;
1358
- /** Initial display mode when no local preference exists. */
1359
- selector?: ViewPreferences['selector'];
1360
- /** Appearance of the tab selector; supplied classes override the defaults. */
1361
- tabs?: {
1362
- variant?: 'default' | 'line';
1363
- /** Position of the active line. Defaults to bottom; only applies to line tabs. */
1364
- linePosition?: 'top' | 'bottom';
1365
- classNames?: {
1366
- list?: string;
1367
- trigger?: string;
1368
- indicator?: string;
1369
- };
1370
- };
1371
- /** Count saved queries (including All), in batches of at most 100. Keys are opaque. */
1372
- counts?: (input: {
1373
- queries: Array<Pick<ViewQuery, 'filters' | 'joinOperator' | 'search'> & {
1374
- 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";
1375
1309
  }>;
1376
- signal: AbortSignal;
1377
- }) => Promise<Record<string, number>>;
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[];
1378
1386
  }
1379
1387
  //#endregion
1380
1388
  //#region src/components/data-table/data-table.d.ts
@@ -1398,7 +1406,7 @@ declare function DataTable<TData>({
1398
1406
  className,
1399
1407
  classNames,
1400
1408
  ...props
1401
- }: DataTableProps<TData>): react_jsx_runtime20.JSX.Element;
1409
+ }: DataTableProps<TData>): react_jsx_runtime17.JSX.Element;
1402
1410
  //#endregion
1403
1411
  //#region src/components/auto-crud/auto-table-action-bar.d.ts
1404
1412
  /** 批量更新字段配置 */
@@ -1489,7 +1497,7 @@ declare function AutoTableActionBar<TData>({
1489
1497
  extraActions,
1490
1498
  actions,
1491
1499
  deleteConfirmation
1492
- }: AutoTableActionBarProps<TData>): react_jsx_runtime20.JSX.Element;
1500
+ }: AutoTableActionBarProps<TData>): react_jsx_runtime17.JSX.Element;
1493
1501
  //#endregion
1494
1502
  //#region src/lib/schema-bridge/types.d.ts
1495
1503
  /**
@@ -1743,7 +1751,7 @@ declare function AutoTable<T extends z.ZodObject<z.ZodRawShape>>({
1743
1751
  onSelectedRowsChange,
1744
1752
  getSelectedRows,
1745
1753
  exportTableRef
1746
- }: AutoTableProps<T>): react_jsx_runtime20.JSX.Element;
1754
+ }: AutoTableProps<T>): react_jsx_runtime17.JSX.Element;
1747
1755
  //#endregion
1748
1756
  //#region src/components/auto-crud/auto-form.d.ts
1749
1757
  type AutoFormProps<T extends z.ZodObject<z.ZodRawShape>> = {
@@ -1786,7 +1794,7 @@ declare function AutoFormInner<T extends z.ZodObject<z.ZodRawShape>>({
1786
1794
  labelAlign,
1787
1795
  labelWidth,
1788
1796
  showSubmitButton
1789
- }: AutoFormProps<T>, ref: React.Ref<AutoFormRef>): react_jsx_runtime20.JSX.Element;
1797
+ }: AutoFormProps<T>, ref: React.Ref<AutoFormRef>): react_jsx_runtime17.JSX.Element;
1790
1798
  declare const AutoForm: <T extends z.ZodObject<z.ZodRawShape>>(props: AutoFormProps<T> & {
1791
1799
  ref?: React.Ref<AutoFormRef>;
1792
1800
  }) => ReturnType<typeof AutoFormInner>;
@@ -2173,7 +2181,7 @@ declare function AutoCrudTable<TSchema extends z.ZodObject<z.ZodRawShape>>({
2173
2181
  locale: localeProp,
2174
2182
  onCreate,
2175
2183
  onExport
2176
- }: AutoCrudTableProps<TSchema>): react_jsx_runtime20.JSX.Element;
2184
+ }: AutoCrudTableProps<TSchema>): react_jsx_runtime17.JSX.Element;
2177
2185
  //#endregion
2178
2186
  //#region src/components/auto-crud/auto-table-simple-filters.d.ts
2179
2187
  interface AutoTableSimpleFiltersProps<TData> {
@@ -2189,7 +2197,7 @@ declare function AutoTableSimpleFilters<TData>({
2189
2197
  filters: externalFilters,
2190
2198
  onFiltersChange,
2191
2199
  leading
2192
- }: AutoTableSimpleFiltersProps<TData>): react_jsx_runtime20.JSX.Element | null;
2200
+ }: AutoTableSimpleFiltersProps<TData>): react_jsx_runtime17.JSX.Element | null;
2193
2201
  //#endregion
2194
2202
  //#region src/components/auto-crud/form-modal.d.ts
2195
2203
  type ModalVariant = 'dialog' | 'sheet';
@@ -2238,7 +2246,7 @@ declare function CrudFormModal<T extends z.ZodObject<z.ZodRawShape>>({
2238
2246
  labelAlign,
2239
2247
  labelWidth,
2240
2248
  className
2241
- }: CrudFormModalProps<T> & CrudFormModalMode<T>): react_jsx_runtime20.JSX.Element;
2249
+ }: CrudFormModalProps<T> & CrudFormModalMode<T>): react_jsx_runtime17.JSX.Element;
2242
2250
  //#endregion
2243
2251
  //#region src/components/auto-crud/import-dialog.d.ts
2244
2252
  interface ImportDialogProps {
@@ -2263,7 +2271,7 @@ declare function ImportDialog({
2263
2271
  fields,
2264
2272
  title,
2265
2273
  locale
2266
- }: ImportDialogProps): react_jsx_runtime20.JSX.Element;
2274
+ }: ImportDialogProps): react_jsx_runtime17.JSX.Element;
2267
2275
  //#endregion
2268
2276
  //#region src/components/auto-crud/export-dialog.d.ts
2269
2277
  type ExportMode = 'selected' | 'filtered';
@@ -2283,7 +2291,7 @@ declare function ExportDialog({
2283
2291
  selectedCount,
2284
2292
  onExport,
2285
2293
  canExportFiltered
2286
- }: ExportDialogProps): react_jsx_runtime20.JSX.Element;
2294
+ }: ExportDialogProps): react_jsx_runtime17.JSX.Element;
2287
2295
  //#endregion
2288
2296
  //#region src/components/data-table/data-table-advanced-toolbar.d.ts
2289
2297
  interface DataTableAdvancedToolbarProps<TData> extends React$1.ComponentProps<'div'> {
@@ -2294,7 +2302,7 @@ declare function DataTableAdvancedToolbar<TData>({
2294
2302
  children,
2295
2303
  className,
2296
2304
  ...props
2297
- }: DataTableAdvancedToolbarProps<TData>): react_jsx_runtime20.JSX.Element;
2305
+ }: DataTableAdvancedToolbarProps<TData>): react_jsx_runtime17.JSX.Element;
2298
2306
  //#endregion
2299
2307
  //#region src/components/data-table/data-table-column-header.d.ts
2300
2308
  interface DataTableColumnHeaderProps<TData, TValue> extends React.ComponentProps<typeof DropdownMenuTrigger> {
@@ -2306,7 +2314,7 @@ declare function DataTableColumnHeader<TData, TValue>({
2306
2314
  label,
2307
2315
  className,
2308
2316
  ...props
2309
- }: DataTableColumnHeaderProps<TData, TValue>): react_jsx_runtime20.JSX.Element;
2317
+ }: DataTableColumnHeaderProps<TData, TValue>): react_jsx_runtime17.JSX.Element;
2310
2318
  //#endregion
2311
2319
  //#region src/components/data-table/data-table-faceted-filter.d.ts
2312
2320
  interface DataTableFacetedFilterProps<TData, TValue> {
@@ -2320,7 +2328,7 @@ declare function DataTableFacetedFilter<TData, TValue>({
2320
2328
  title,
2321
2329
  options,
2322
2330
  multiple
2323
- }: DataTableFacetedFilterProps<TData, TValue>): react_jsx_runtime20.JSX.Element;
2331
+ }: DataTableFacetedFilterProps<TData, TValue>): react_jsx_runtime17.JSX.Element;
2324
2332
  //#endregion
2325
2333
  //#region src/components/data-table/data-table-pagination.d.ts
2326
2334
  interface DataTablePaginationProps<TData> extends React.ComponentProps<'div'>, TablePaginationOptions {
@@ -2337,7 +2345,7 @@ declare function DataTablePagination<TData>({
2337
2345
  pageJumpLabel,
2338
2346
  className,
2339
2347
  ...props
2340
- }: DataTablePaginationProps<TData>): react_jsx_runtime20.JSX.Element;
2348
+ }: DataTablePaginationProps<TData>): react_jsx_runtime17.JSX.Element;
2341
2349
  //#endregion
2342
2350
  //#region src/components/data-table/data-table-toolbar.d.ts
2343
2351
  interface DataTableToolbarProps<TData> extends React$1.ComponentProps<'div'> {
@@ -2348,7 +2356,7 @@ declare function DataTableToolbar<TData>({
2348
2356
  children,
2349
2357
  className,
2350
2358
  ...props
2351
- }: DataTableToolbarProps<TData>): react_jsx_runtime20.JSX.Element;
2359
+ }: DataTableToolbarProps<TData>): react_jsx_runtime17.JSX.Element;
2352
2360
  //#endregion
2353
2361
  //#region src/components/data-table/data-table-view-options.d.ts
2354
2362
  interface DataTableViewOptionsProps<TData> extends PopoverContentProps {
@@ -2361,7 +2369,7 @@ declare function DataTableViewOptions<TData>({
2361
2369
  disabled,
2362
2370
  locale,
2363
2371
  ...props
2364
- }: DataTableViewOptionsProps<TData>): react_jsx_runtime20.JSX.Element;
2372
+ }: DataTableViewOptionsProps<TData>): react_jsx_runtime17.JSX.Element;
2365
2373
  //#endregion
2366
2374
  //#region src/lib/crud-actions.d.ts
2367
2375
  type CrudActionZone = 'toolbar' | 'row' | 'batch';
@@ -2803,7 +2811,7 @@ declare function TagFilter({
2803
2811
  resourceId: resourceIdProp,
2804
2812
  field,
2805
2813
  ...props
2806
- }: TagFilterProps): react_jsx_runtime20.JSX.Element;
2814
+ }: TagFilterProps): react_jsx_runtime17.JSX.Element;
2807
2815
  interface TagAssignmentProps extends TagScope, Pick<RowActionDialogProps, 'open' | 'onOpenChange'> {
2808
2816
  title: string;
2809
2817
  /** Current record tags, snapshotted when the editor opens. */
@@ -2814,6 +2822,6 @@ interface TagAssignmentProps extends TagScope, Pick<RowActionDialogProps, 'open'
2814
2822
  onSaved?: () => unknown | Promise<unknown>;
2815
2823
  }
2816
2824
  /** Controlled dialog. Callers own the trigger, its appearance and its placement. */
2817
- declare function TagAssignment(props: TagAssignmentProps): react_jsx_runtime20.JSX.Element | null;
2825
+ declare function TagAssignment(props: TagAssignmentProps): react_jsx_runtime17.JSX.Element | null;
2818
2826
  //#endregion
2819
2827
  export { type ActionConfig, type ActionItem, type ActionPosition, type ActionsColumnConfig, type AutoCrudActionConfig, type AutoCrudActionsConfig, type AutoCrudDataSourceConfig, type AutoCrudDataSourceContext, type AutoCrudDataSourceEntry, type AutoCrudDataSourceLoader, type AutoCrudDataSourceRegistration, type AutoCrudExportContext, type AutoCrudFormComponentConfig, type AutoCrudLocale, type AutoCrudOption, AutoCrudProvider, type AutoCrudProviderProps, type AutoCrudQueryCapabilities, type AutoCrudRowActionContext, type AutoCrudRowOpenOptions, AutoCrudTable, type AutoCrudTableProps, type AutoCrudToolbarContext, type AutoCrudToolbarResolver, AutoForm, type AutoFormProps, type AutoQueryParams, AutoTable, AutoTableActionBar, type AutoTableProps, AutoTableSimpleFilters, type BatchActionConfig, type BatchActionContext, type BatchActionItem, type BatchBuiltinActionItem, type BatchBuiltinActionType, type BatchCustomActionItem, type BatchSearchConfig, type BatchSearchField, type BatchSearchFilter, type BatchSearchLocale, type BatchSearchState, type BatchUpdateField, type ColumnOverrides, type CreateFormSchemaOptions, type CreateTableSchemaOptions, type CrudActionBase, type CrudActionEntry, type CrudActionRegistration, type CrudActionZone, CrudFormModal, type CrudHooks, type CrudOperationPermissions, type CrudPermissions, type DataSource, DataTable, DataTableAdvancedToolbar, DataTableClassNames, DataTableColumnHeader, DataTableFacetedFilter, DataTablePagination, type DataTableProps, DataTableRowAction, DataTableToolbar, DataTableViewOptions, type DataTableViewOptionsProps, type DateFormatPreset, type DateFormatter, type DateLocaleOptions, type EnumOption, ExportDialog, type ExportDialogProps, type ExportMode, ExtendedColumnFilter, ExtendedColumnSort, type Field, type FieldOption, type FieldTableDisplay, type FieldType, type Fields, type FilterConfig, FilterOperator, type FilterVariant, type FormSchemaOverrides, ImportDialog, type ImportDialogProps, type ImportIssue, type ImportResult, type JSONSchema, type JSONSchemaProperty, JoinOperator, type ListParams, type ListResult, type LocaleProp, MultiCombobox, type MultiComboboxOption, type MultiComboboxProps, type MultiComboboxTriggerRenderProps, Option, type ParsedImportData, type ParsedZodField, type Parser, type PresetView, QueryKeys, type RowActionConfig, type RowActionDialogProps, type RowActionItem, type RowBuiltinActionItem, type RowBuiltinActionType, type RowCustomActionItem, type SavedView, type SavedViewsConfig, SchemaAdapter, Select, type SelectMode, type SelectOption, type SelectProps, type SelectSearchableDynamicProps, type SelectSearchableMultipleProps, type SelectSearchableProps, type SelectSearchableSingleProps, type SelectSimpleProps, type SelectTriggerRenderProps, type SimpleFieldConfig, type SimpleFieldsConfig, type TableActionBarLocale, type TableBatchSearchConfig, type TableControlsLocale, type TableFilterState, type TablePaginationLocale, type TablePaginationOptions, type TableSearchConfig, type TableSearchProps, TagAssignment, type TagAssignmentProps, TagFilter, type TagFilterProps, type TagFilterValue, type TagInput, type TagOption, type TagScope, type TagService, type ToastAdapter, type ToolbarActionConfig, type ToolbarActionItem, type ToolbarBuiltinActionItem, type ToolbarBuiltinActionType, type ToolbarCustomActionItem, type UnifiedField, type UnifiedSchema, type UrlStateOptions, type UseAutoCrudResourceOptions, type UseAutoCrudResourceParams, type UseAutoCrudResourceReturn, type ViewCapabilities, type ViewInput, type ViewQuery, type ViewScope, type ViewStorage, type ViewStorageCapabilities, type WorkbookSheet, actionPositionSchema, cn, coerceRowValues, compareOrder, components, createActionsColumn, createEditFormSchema, createFormSchema, createLocalViewStorage, createMemoryDataSource, createSelectColumn, createTRPCDataSource, createTableSchema, crudActions, dataSources, dataToCSV, deDE, downloadCSVTemplate, enUS, esES, exportAllToCSV, exportTableToCSV, exportWorkbook, formComponents, formatDate, frFR, generateCSVTemplate, getUrlParams, humanize, jaJP, koKR, matchesPosition, noopToastAdapter, normalizeDataSourceConfig, normalizeOptions, parseAsArrayOf, parseAsInteger, parseAsString, parseAsStringEnum, parseCSV, parseImportFile, parseJSON, parseZodField, positionActions, presetViewSchema, resolveLocale, savedViewSchema, setDateFormatter, setSearchParams, setToolbarResolver, tablePagination, tagFilterValueSchema, useAutoCrudResource, useDataTable, useQueryState, useQueryStates, useReadableFilters, useUrlState, useUrlStates, viewCapabilitiesSchema, viewInputSchema, viewQuerySchema, viewScopeSchema, viewStorageCapabilitiesSchema, zhCN };