@wordrhyme/auto-crud 1.2.1 → 1.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -5235,8 +5235,12 @@ function createEditFormSchema(schema, options) {
5235
5235
  function createRegistry(label) {
5236
5236
  const entries = /* @__PURE__ */ new Map();
5237
5237
  const listeners = /* @__PURE__ */ new Set();
5238
+ let notifyScheduled = false;
5238
5239
  const notify = () => {
5240
+ if (notifyScheduled) return;
5241
+ notifyScheduled = true;
5239
5242
  queueMicrotask(() => {
5243
+ notifyScheduled = false;
5240
5244
  for (const listener of listeners) listener();
5241
5245
  });
5242
5246
  };
@@ -5266,20 +5270,32 @@ function createRegistry(label) {
5266
5270
  };
5267
5271
  }
5268
5272
  const formComponents = createRegistry("form component");
5269
- const dataSources = createRegistry("data source");
5270
- function normalizeDataSourceConfig(config) {
5271
- if (typeof config === "string") return config.length > 0 ? {
5272
- key: config,
5273
- dependsOn: [],
5274
- resetOnChange: false
5275
- } : void 0;
5276
- if (!config?.key) return void 0;
5273
+ const components = formComponents;
5274
+ function normalizeDataSourceRegistration(registration) {
5275
+ if (typeof registration === "function") return {
5276
+ dependencies: [],
5277
+ reset: false,
5278
+ load: registration
5279
+ };
5277
5280
  return {
5278
- key: config.key,
5279
- dependsOn: Array.isArray(config.dependsOn) ? config.dependsOn : [],
5280
- resetOnChange: config.resetOnChange === true
5281
+ dependencies: Array.isArray(registration.dependencies) ? registration.dependencies : [],
5282
+ reset: registration.reset === true,
5283
+ load: registration.load
5281
5284
  };
5282
5285
  }
5286
+ const dataSourceRegistry = createRegistry("data source");
5287
+ const dataSources = {
5288
+ register(name, registration) {
5289
+ dataSourceRegistry.register(name, normalizeDataSourceRegistration(registration));
5290
+ },
5291
+ unregister: dataSourceRegistry.unregister,
5292
+ get: dataSourceRegistry.get,
5293
+ all: dataSourceRegistry.all,
5294
+ subscribe: dataSourceRegistry.subscribe
5295
+ };
5296
+ function normalizeDataSourceConfig(config) {
5297
+ if (typeof config === "string") return config.length > 0 ? { key: config } : void 0;
5298
+ }
5283
5299
  function normalizeOptions(result) {
5284
5300
  const options = Array.isArray(result) ? result : result?.options;
5285
5301
  if (!Array.isArray(options)) return [];
@@ -5345,9 +5361,7 @@ function useRegistryVersion$1(subscribe) {
5345
5361
  return version;
5346
5362
  }
5347
5363
  function isDataSourceConfig(value) {
5348
- if (typeof value === "string") return value.length > 0;
5349
- if (!value || typeof value !== "object" || Array.isArray(value)) return false;
5350
- return typeof value.key === "string";
5364
+ return typeof value === "string" && value.length > 0;
5351
5365
  }
5352
5366
  function collectDataSourceConfigs(schema, result = {}) {
5353
5367
  const properties = schema.properties;
@@ -5377,17 +5391,17 @@ function useFormDataSources(form, schema) {
5377
5391
  const loadFieldOptions = async (fieldName, source) => {
5378
5392
  const version = (loadVersions.get(fieldName) ?? 0) + 1;
5379
5393
  loadVersions.set(fieldName, version);
5380
- const loader = dataSources.get(source.key);
5381
- if (!loader) {
5394
+ const entry = dataSources.get(source.key);
5395
+ if (!entry) {
5382
5396
  form.setFieldState(fieldName, (state) => {
5383
5397
  state.dataSource = [];
5384
5398
  });
5385
5399
  return;
5386
5400
  }
5387
5401
  try {
5388
- const options = normalizeOptions(await loader({
5402
+ const options = normalizeOptions(await entry.load({
5389
5403
  field: fieldName,
5390
- values: Object.fromEntries(source.dependsOn.map((dependency) => [dependency, form.getValuesIn(dependency)])),
5404
+ values: Object.fromEntries(entry.dependencies.map((dependency) => [dependency, form.getValuesIn(dependency)])),
5391
5405
  signal: controller?.signal
5392
5406
  }));
5393
5407
  if (!active || loadVersions.get(fieldName) !== version) return;
@@ -5404,10 +5418,11 @@ function useFormDataSources(form, schema) {
5404
5418
  };
5405
5419
  for (const [fieldName, source] of sourceEntries) loadFieldOptions(fieldName, source);
5406
5420
  form.addEffects(effectId, () => {
5407
- for (const dependency of new Set(sourceEntries.flatMap(([, source]) => source.dependsOn))) (0, __formily_core.onFieldValueChange)(dependency, () => {
5421
+ for (const dependency of new Set(sourceEntries.flatMap(([, source]) => dataSources.get(source.key)?.dependencies ?? []))) (0, __formily_core.onFieldValueChange)(dependency, () => {
5408
5422
  for (const [fieldName, source] of sourceEntries) {
5409
- if (!source.dependsOn.includes(dependency)) continue;
5410
- if (source.resetOnChange) form.setValuesIn(fieldName, void 0);
5423
+ const entry = dataSources.get(source.key);
5424
+ if (!entry?.dependencies.includes(dependency)) continue;
5425
+ if (entry.reset) form.setValuesIn(fieldName, void 0);
5411
5426
  loadFieldOptions(fieldName, source);
5412
5427
  }
5413
5428
  });
@@ -5446,8 +5461,8 @@ function AutoFormInner({ schema: zodSchema, initialValues, onSubmit, overrides,
5446
5461
  }, [labelAlign, labelWidth]);
5447
5462
  const fieldComponents = (0, react.useMemo)(() => ({ fields: {
5448
5463
  ...defaultFieldComponents,
5449
- ...formComponents.all()
5450
- } }), [useRegistryVersion$1(formComponents.subscribe)]);
5464
+ ...components.all()
5465
+ } }), [useRegistryVersion$1(components.subscribe)]);
5451
5466
  useFormDataSources(form, formSchema);
5452
5467
  const handleSubmit = async () => {
5453
5468
  await form.validate();
@@ -6346,10 +6361,10 @@ function useDynamicFilterOptions(fields) {
6346
6361
  let active = true;
6347
6362
  const controller = typeof AbortController === "undefined" ? void 0 : new AbortController();
6348
6363
  Promise.all(sourceEntries.map(async ({ field, source }) => {
6349
- const loader = dataSources.get(source.key);
6350
- if (!loader) return [field, []];
6364
+ const entry = dataSources.get(source.key);
6365
+ if (!entry) return [field, []];
6351
6366
  try {
6352
- return [field, normalizeOptions(await loader({
6367
+ return [field, normalizeOptions(await entry.load({
6353
6368
  field,
6354
6369
  values: {},
6355
6370
  signal: controller?.signal
@@ -6583,7 +6598,7 @@ function renderFieldValue(value, type, booleanLocale, options) {
6583
6598
  /**
6584
6599
  * ViewModal 组件 - 详情查看弹窗
6585
6600
  */
6586
- function ViewModal({ open, onOpenChange, variant, data, schema, fields: fieldConfig, denyFields, locale }) {
6601
+ function ViewModal({ open, onOpenChange, variant, data, schema, fields: fieldConfig, dynamicOptions, denyFields, locale }) {
6587
6602
  if (!data) return null;
6588
6603
  const shape = schema.shape;
6589
6604
  const denySet = new Set(denyFields ?? []);
@@ -6596,7 +6611,7 @@ function ViewModal({ open, onOpenChange, variant, data, schema, fields: fieldCon
6596
6611
  const parsed = parseZodField(fieldSchema);
6597
6612
  const label = fieldConfig?.[key]?.label ?? humanize(key);
6598
6613
  const value = data[key];
6599
- const options = normalizeFieldOptions(fieldConfig?.[key]?.enum);
6614
+ const options = normalizeFieldOptions(fieldConfig?.[key]?.enum) ?? normalizeFieldOptions(dynamicOptions?.[key]);
6600
6615
  return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
6601
6616
  className: "grid grid-cols-3 items-start gap-4",
6602
6617
  children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("dt", {
@@ -6618,6 +6633,7 @@ function ViewModal({ open, onOpenChange, variant, data, schema, fields: fieldCon
6618
6633
  open,
6619
6634
  onOpenChange,
6620
6635
  children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(__pixpilot_shadcn.DialogContent, {
6636
+ "aria-describedby": void 0,
6621
6637
  className: "max-w-2xl max-h-[80vh] overflow-y-auto",
6622
6638
  children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(__pixpilot_shadcn.DialogHeader, { children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(__pixpilot_shadcn.DialogTitle, { children: locale.viewModal.title }) }), content]
6623
6639
  })
@@ -6922,6 +6938,7 @@ function AutoCrudTable({ title, description, schema, resource, fields, table: ta
6922
6938
  data: resource.modal.selected,
6923
6939
  schema: resolvedSchema,
6924
6940
  fields: resolvedFields,
6941
+ dynamicOptions: dynamicFilterOptions,
6925
6942
  denyFields,
6926
6943
  locale
6927
6944
  }),
@@ -8327,6 +8344,7 @@ exports.MultiCombobox = MultiCombobox;
8327
8344
  exports.SchemaAdapter = SchemaAdapter;
8328
8345
  exports.cn = cn;
8329
8346
  exports.coerceRowValues = coerceRowValues;
8347
+ exports.components = components;
8330
8348
  exports.createActionsColumn = createActionsColumn;
8331
8349
  exports.createEditFormSchema = createEditFormSchema;
8332
8350
  exports.createFormSchema = createFormSchema;
package/dist/index.d.cts CHANGED
@@ -24,7 +24,7 @@ declare const noopToastAdapter: ToastAdapter;
24
24
  /**
25
25
  * Modal 状态类型
26
26
  */
27
- type ModalVariant$1 = "dialog" | "sheet";
27
+ type ModalVariant$1 = 'dialog' | 'sheet';
28
28
  interface ModalState<T> {
29
29
  createOpen: boolean;
30
30
  editOpen: boolean;
@@ -66,9 +66,9 @@ interface CrudHooks<TSchema extends z.ZodObject<z.ZodRawShape>, TListItem> {
66
66
  */
67
67
  beforeDelete?: (item: TListItem) => boolean | void | Promise<boolean | void>;
68
68
  /** 操作成功回调 */
69
- onSuccess?: (op: "create" | "update" | "delete", payload: unknown) => void;
69
+ onSuccess?: (op: 'create' | 'update' | 'delete', payload: unknown) => void;
70
70
  /** 操作失败回调 */
71
- onError?: (op: "create" | "update" | "delete", error: Error) => void;
71
+ onError?: (op: 'create' | 'update' | 'delete', error: Error) => void;
72
72
  }
73
73
  /**
74
74
  * Hook 配置选项
@@ -204,7 +204,7 @@ interface AutoQueryParams {
204
204
  }>;
205
205
  search?: string;
206
206
  filters: any[];
207
- joinOperator: "and" | "or";
207
+ joinOperator: 'and' | 'or';
208
208
  }
209
209
  /**
210
210
  * Hook 配置参数
@@ -368,11 +368,11 @@ declare function AutoTableActionBar<TData>({
368
368
  /**
369
369
  * 字段类型映射
370
370
  */
371
- type FieldType = "string" | "number" | "boolean" | "date" | "enum" | "array" | "object";
371
+ type FieldType = 'string' | 'number' | 'boolean' | 'date' | 'enum' | 'array' | 'object';
372
372
  /**
373
373
  * DataTable Filter Variant
374
374
  */
375
- type FilterVariant = "text" | "number" | "boolean" | "select" | "multiSelect" | "date" | "dateRange" | "range";
375
+ type FilterVariant = 'text' | 'number' | 'boolean' | 'select' | 'multiSelect' | 'date' | 'dateRange' | 'range';
376
376
  /**
377
377
  * 解析后的 Zod 字段信息
378
378
  */
@@ -408,10 +408,10 @@ interface CreateTableSchemaOptions<T> {
408
408
  interface CreateFormSchemaOptions {
409
409
  overrides?: FormSchemaOverrides;
410
410
  exclude?: string[];
411
- layout?: "vertical" | "horizontal" | "grid";
411
+ layout?: 'vertical' | 'horizontal' | 'grid';
412
412
  gridColumns?: number;
413
413
  /** Label 对齐方式 */
414
- labelAlign?: "left" | "top" | "right";
414
+ labelAlign?: 'left' | 'top' | 'right';
415
415
  /** Label 宽度(labelAlign 为 left 时有效) */
416
416
  labelWidth?: number | string;
417
417
  /** Label 栅格占位 */
@@ -450,7 +450,7 @@ interface ResolvedActionItem<T> {
450
450
  label: string;
451
451
  onClick: (row: T) => void;
452
452
  separator?: boolean;
453
- variant?: "default" | "destructive";
453
+ variant?: 'default' | 'destructive';
454
454
  }
455
455
  /**
456
456
  * 操作列配置(ResolvedActionItem 数组)
@@ -646,10 +646,16 @@ type AutoCrudDataSourceResult = AutoCrudOption[] | {
646
646
  options?: AutoCrudOption[];
647
647
  };
648
648
  type AutoCrudDataSourceLoader = (context: AutoCrudDataSourceContext) => AutoCrudDataSourceResult | Promise<AutoCrudDataSourceResult>;
649
- type AutoCrudDataSourceConfig = string | {
650
- key: string;
651
- dependsOn?: string[];
652
- resetOnChange?: boolean;
649
+ type AutoCrudDataSourceConfig = string;
650
+ type AutoCrudDataSourceRegistration = AutoCrudDataSourceLoader | {
651
+ dependencies?: string[];
652
+ reset?: boolean;
653
+ load: AutoCrudDataSourceLoader;
654
+ };
655
+ type AutoCrudDataSourceEntry = {
656
+ dependencies: string[];
657
+ reset: boolean;
658
+ load: AutoCrudDataSourceLoader;
653
659
  };
654
660
  type RegistryListener = () => void;
655
661
  declare const formComponents: {
@@ -659,17 +665,22 @@ declare const formComponents: {
659
665
  all(): Record<string, AutoCrudFormComponentConfig>;
660
666
  subscribe(listener: RegistryListener): () => void;
661
667
  };
662
- declare const dataSources: {
663
- register(name: string, value: AutoCrudDataSourceLoader): void;
668
+ declare const components: {
669
+ register(name: string, value: AutoCrudFormComponentConfig): void;
664
670
  unregister(name: string): void;
665
- get(name: string): AutoCrudDataSourceLoader | undefined;
666
- all(): Record<string, AutoCrudDataSourceLoader>;
671
+ get(name: string): AutoCrudFormComponentConfig | undefined;
672
+ all(): Record<string, AutoCrudFormComponentConfig>;
667
673
  subscribe(listener: RegistryListener): () => void;
668
674
  };
675
+ declare const dataSources: {
676
+ register(name: string, registration: AutoCrudDataSourceRegistration): void;
677
+ unregister: (name: string) => void;
678
+ get: (name: string) => AutoCrudDataSourceEntry | undefined;
679
+ all: () => Record<string, AutoCrudDataSourceEntry>;
680
+ subscribe: (listener: RegistryListener) => () => void;
681
+ };
669
682
  declare function normalizeDataSourceConfig(config: AutoCrudDataSourceConfig | undefined): {
670
683
  key: string;
671
- dependsOn: string[];
672
- resetOnChange: boolean;
673
684
  } | undefined;
674
685
  declare function normalizeOptions(result: AutoCrudDataSourceResult | undefined): AutoCrudOption[];
675
686
  //#endregion
@@ -1209,7 +1220,7 @@ declare const filterItemSchema: z.ZodObject<{
1209
1220
  type FilterItemSchema = z.infer<typeof filterItemSchema>;
1210
1221
  //#endregion
1211
1222
  //#region src/types/data-table.d.ts
1212
- declare module "@tanstack/react-table" {
1223
+ declare module '@tanstack/react-table' {
1213
1224
  interface TableMeta<TData extends RowData> {
1214
1225
  queryKeys?: QueryKeys;
1215
1226
  queryStateOptions?: UrlStateOptions;
@@ -1224,7 +1235,7 @@ declare module "@tanstack/react-table" {
1224
1235
  unit?: string;
1225
1236
  icon?: React.FC<React.SVGProps<SVGSVGElement>>;
1226
1237
  /** 控制在哪些筛选模式下显示(未设置则在所有模式显示) */
1227
- modes?: Array<"simple" | "advanced" | "command">;
1238
+ modes?: Array<'simple' | 'advanced' | 'command'>;
1228
1239
  }
1229
1240
  }
1230
1241
  interface QueryKeys {
@@ -1241,10 +1252,10 @@ interface Option {
1241
1252
  count?: number;
1242
1253
  icon?: React.FC<React.SVGProps<SVGSVGElement>>;
1243
1254
  }
1244
- type FilterOperator = DataTableConfig["operators"][number];
1245
- type FilterVariant$1 = DataTableConfig["filterVariants"][number];
1246
- type JoinOperator = DataTableConfig["joinOperators"][number];
1247
- interface ExtendedColumnSort<TData> extends Omit<ColumnSort, "id"> {
1255
+ type FilterOperator = DataTableConfig['operators'][number];
1256
+ type FilterVariant$1 = DataTableConfig['filterVariants'][number];
1257
+ type JoinOperator = DataTableConfig['joinOperators'][number];
1258
+ interface ExtendedColumnSort<TData> extends Omit<ColumnSort, 'id'> {
1248
1259
  id: Extract<keyof TData, string>;
1249
1260
  }
1250
1261
  interface ExtendedColumnFilter<TData> extends FilterItemSchema {
@@ -1252,7 +1263,7 @@ interface ExtendedColumnFilter<TData> extends FilterItemSchema {
1252
1263
  }
1253
1264
  interface DataTableRowAction<TData> {
1254
1265
  row: Row<TData>;
1255
- variant: "update" | "delete";
1266
+ variant: 'update' | 'delete';
1256
1267
  }
1257
1268
  //#endregion
1258
1269
  //#region src/components/auto-crud/auto-table-simple-filters.d.ts
@@ -1814,4 +1825,4 @@ declare function exportAllToCSV<T extends Record<string, unknown>>(data: T[], op
1814
1825
  */
1815
1826
  declare function downloadCSVTemplate(headers: string[], filename?: string): void;
1816
1827
  //#endregion
1817
- export { type ActionItem, type ActionsColumnConfig, type AutoCrudDataSourceConfig, type AutoCrudDataSourceContext, type AutoCrudDataSourceLoader, type AutoCrudFormComponentConfig, type AutoCrudLocale, type AutoCrudOption, AutoCrudTable, type AutoCrudTableProps, AutoForm, type AutoQueryParams, AutoTable, AutoTableActionBar, AutoTableSimpleFilters, type BatchActionConfig, type BatchActionContext, type BatchActionItem, type BatchBuiltinActionItem, type BatchBuiltinActionType, type BatchCustomActionItem, type BatchUpdateField, type ColumnOverrides, type CreateFormSchemaOptions, type CreateTableSchemaOptions, CrudFormModal, type CrudHooks, type CrudOperationPermissions, type CrudPermissions, type DataSource, DataTable, DataTableAdvancedToolbar, DataTableColumnHeader, DataTableFacetedFilter, DataTablePagination, DataTableRowAction, DataTableToolbar, DataTableViewOptions, type EnumOption, ExportDialog, type ExportDialogProps, type ExportMode, ExtendedColumnFilter, ExtendedColumnSort, type Field, type FieldOption, type FieldType, type Fields, type FilterConfig, FilterOperator, type FilterVariant, type FormSchemaOverrides, ImportDialog, type ImportDialogProps, 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, QueryKeys, SchemaAdapter, type SimpleFieldConfig, type SimpleFieldsConfig, type ToastAdapter, type ToolbarActionItem, type ToolbarBuiltinActionItem, type ToolbarCustomActionItem, type UnifiedField, type UnifiedSchema, type UrlStateOptions, type UseAutoCrudResourceOptions, type UseAutoCrudResourceParams, type UseAutoCrudResourceReturn, cn, coerceRowValues, createActionsColumn, createEditFormSchema, createFormSchema, createMemoryDataSource, createSelectColumn, createTRPCDataSource, createTableSchema, dataSources, dataToCSV, deDE, downloadCSVTemplate, enUS, esES, exportAllToCSV, exportTableToCSV, formComponents, formatDate, frFR, generateCSVTemplate, getUrlParams, humanize, jaJP, koKR, noopToastAdapter, normalizeDataSourceConfig, normalizeOptions, parseAsArrayOf, parseAsInteger, parseAsString, parseAsStringEnum, parseCSV, parseImportFile, parseJSON, parseZodField, resolveLocale, setSearchParams, useAutoCrudResource, useDataTable, useQueryState, useQueryStates, useReadableFilters, useUrlState, useUrlStates, zhCN };
1828
+ export { type ActionItem, type ActionsColumnConfig, type AutoCrudDataSourceConfig, type AutoCrudDataSourceContext, type AutoCrudDataSourceEntry, type AutoCrudDataSourceLoader, type AutoCrudDataSourceRegistration, type AutoCrudFormComponentConfig, type AutoCrudLocale, type AutoCrudOption, AutoCrudTable, type AutoCrudTableProps, AutoForm, type AutoQueryParams, AutoTable, AutoTableActionBar, AutoTableSimpleFilters, type BatchActionConfig, type BatchActionContext, type BatchActionItem, type BatchBuiltinActionItem, type BatchBuiltinActionType, type BatchCustomActionItem, type BatchUpdateField, type ColumnOverrides, type CreateFormSchemaOptions, type CreateTableSchemaOptions, CrudFormModal, type CrudHooks, type CrudOperationPermissions, type CrudPermissions, type DataSource, DataTable, DataTableAdvancedToolbar, DataTableColumnHeader, DataTableFacetedFilter, DataTablePagination, DataTableRowAction, DataTableToolbar, DataTableViewOptions, type EnumOption, ExportDialog, type ExportDialogProps, type ExportMode, ExtendedColumnFilter, ExtendedColumnSort, type Field, type FieldOption, type FieldType, type Fields, type FilterConfig, FilterOperator, type FilterVariant, type FormSchemaOverrides, ImportDialog, type ImportDialogProps, 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, QueryKeys, SchemaAdapter, type SimpleFieldConfig, type SimpleFieldsConfig, type ToastAdapter, type ToolbarActionItem, type ToolbarBuiltinActionItem, type ToolbarCustomActionItem, type UnifiedField, type UnifiedSchema, type UrlStateOptions, type UseAutoCrudResourceOptions, type UseAutoCrudResourceParams, type UseAutoCrudResourceReturn, cn, coerceRowValues, components, createActionsColumn, createEditFormSchema, createFormSchema, createMemoryDataSource, createSelectColumn, createTRPCDataSource, createTableSchema, dataSources, dataToCSV, deDE, downloadCSVTemplate, enUS, esES, exportAllToCSV, exportTableToCSV, formComponents, formatDate, frFR, generateCSVTemplate, getUrlParams, humanize, jaJP, koKR, noopToastAdapter, normalizeDataSourceConfig, normalizeOptions, parseAsArrayOf, parseAsInteger, parseAsString, parseAsStringEnum, parseCSV, parseImportFile, parseJSON, parseZodField, resolveLocale, setSearchParams, useAutoCrudResource, useDataTable, useQueryState, useQueryStates, useReadableFilters, useUrlState, useUrlStates, zhCN };
package/dist/index.d.ts CHANGED
@@ -4,7 +4,7 @@ import * as _tanstack_react_table0 from "@tanstack/react-table";
4
4
  import { Column, ColumnDef, ColumnSort, Row, RowData, Table, TableOptions, TableState } from "@tanstack/react-table";
5
5
  import { Command, DropdownMenuTrigger, PopoverContent } from "@pixpilot/shadcn";
6
6
  import { ClassValue } from "clsx";
7
- import * as react_jsx_runtime3 from "react/jsx-runtime";
7
+ import * as react_jsx_runtime2 from "react/jsx-runtime";
8
8
  import { z } from "zod";
9
9
  import { ISchema } from "@formily/json-schema";
10
10
 
@@ -24,7 +24,7 @@ declare const noopToastAdapter: ToastAdapter;
24
24
  /**
25
25
  * Modal 状态类型
26
26
  */
27
- type ModalVariant$1 = "dialog" | "sheet";
27
+ type ModalVariant$1 = 'dialog' | 'sheet';
28
28
  interface ModalState<T> {
29
29
  createOpen: boolean;
30
30
  editOpen: boolean;
@@ -66,9 +66,9 @@ interface CrudHooks<TSchema extends z.ZodObject<z.ZodRawShape>, TListItem> {
66
66
  */
67
67
  beforeDelete?: (item: TListItem) => boolean | void | Promise<boolean | void>;
68
68
  /** 操作成功回调 */
69
- onSuccess?: (op: "create" | "update" | "delete", payload: unknown) => void;
69
+ onSuccess?: (op: 'create' | 'update' | 'delete', payload: unknown) => void;
70
70
  /** 操作失败回调 */
71
- onError?: (op: "create" | "update" | "delete", error: Error) => void;
71
+ onError?: (op: 'create' | 'update' | 'delete', error: Error) => void;
72
72
  }
73
73
  /**
74
74
  * Hook 配置选项
@@ -204,7 +204,7 @@ interface AutoQueryParams {
204
204
  }>;
205
205
  search?: string;
206
206
  filters: any[];
207
- joinOperator: "and" | "or";
207
+ joinOperator: 'and' | 'or';
208
208
  }
209
209
  /**
210
210
  * Hook 配置参数
@@ -362,17 +362,17 @@ declare function AutoTableActionBar<TData>({
362
362
  enableDelete,
363
363
  extraActions,
364
364
  actions
365
- }: AutoTableActionBarProps<TData>): react_jsx_runtime3.JSX.Element;
365
+ }: AutoTableActionBarProps<TData>): react_jsx_runtime2.JSX.Element;
366
366
  //#endregion
367
367
  //#region src/lib/schema-bridge/types.d.ts
368
368
  /**
369
369
  * 字段类型映射
370
370
  */
371
- type FieldType = "string" | "number" | "boolean" | "date" | "enum" | "array" | "object";
371
+ type FieldType = 'string' | 'number' | 'boolean' | 'date' | 'enum' | 'array' | 'object';
372
372
  /**
373
373
  * DataTable Filter Variant
374
374
  */
375
- type FilterVariant = "text" | "number" | "boolean" | "select" | "multiSelect" | "date" | "dateRange" | "range";
375
+ type FilterVariant = 'text' | 'number' | 'boolean' | 'select' | 'multiSelect' | 'date' | 'dateRange' | 'range';
376
376
  /**
377
377
  * 解析后的 Zod 字段信息
378
378
  */
@@ -408,10 +408,10 @@ interface CreateTableSchemaOptions<T> {
408
408
  interface CreateFormSchemaOptions {
409
409
  overrides?: FormSchemaOverrides;
410
410
  exclude?: string[];
411
- layout?: "vertical" | "horizontal" | "grid";
411
+ layout?: 'vertical' | 'horizontal' | 'grid';
412
412
  gridColumns?: number;
413
413
  /** Label 对齐方式 */
414
- labelAlign?: "left" | "top" | "right";
414
+ labelAlign?: 'left' | 'top' | 'right';
415
415
  /** Label 宽度(labelAlign 为 left 时有效) */
416
416
  labelWidth?: number | string;
417
417
  /** Label 栅格占位 */
@@ -450,7 +450,7 @@ interface ResolvedActionItem<T> {
450
450
  label: string;
451
451
  onClick: (row: T) => void;
452
452
  separator?: boolean;
453
- variant?: "default" | "destructive";
453
+ variant?: 'default' | 'destructive';
454
454
  }
455
455
  /**
456
456
  * 操作列配置(ResolvedActionItem 数组)
@@ -530,7 +530,7 @@ declare function AutoTable<T extends z.ZodObject<z.ZodRawShape>>({
530
530
  showDefaultExport,
531
531
  onSelectedCountChange,
532
532
  getSelectedRows
533
- }: AutoTableProps<T>): react_jsx_runtime3.JSX.Element;
533
+ }: AutoTableProps<T>): react_jsx_runtime2.JSX.Element;
534
534
  //#endregion
535
535
  //#region src/i18n/locale.d.ts
536
536
  /**
@@ -646,10 +646,16 @@ type AutoCrudDataSourceResult = AutoCrudOption[] | {
646
646
  options?: AutoCrudOption[];
647
647
  };
648
648
  type AutoCrudDataSourceLoader = (context: AutoCrudDataSourceContext) => AutoCrudDataSourceResult | Promise<AutoCrudDataSourceResult>;
649
- type AutoCrudDataSourceConfig = string | {
650
- key: string;
651
- dependsOn?: string[];
652
- resetOnChange?: boolean;
649
+ type AutoCrudDataSourceConfig = string;
650
+ type AutoCrudDataSourceRegistration = AutoCrudDataSourceLoader | {
651
+ dependencies?: string[];
652
+ reset?: boolean;
653
+ load: AutoCrudDataSourceLoader;
654
+ };
655
+ type AutoCrudDataSourceEntry = {
656
+ dependencies: string[];
657
+ reset: boolean;
658
+ load: AutoCrudDataSourceLoader;
653
659
  };
654
660
  type RegistryListener = () => void;
655
661
  declare const formComponents: {
@@ -659,17 +665,22 @@ declare const formComponents: {
659
665
  all(): Record<string, AutoCrudFormComponentConfig>;
660
666
  subscribe(listener: RegistryListener): () => void;
661
667
  };
662
- declare const dataSources: {
663
- register(name: string, value: AutoCrudDataSourceLoader): void;
668
+ declare const components: {
669
+ register(name: string, value: AutoCrudFormComponentConfig): void;
664
670
  unregister(name: string): void;
665
- get(name: string): AutoCrudDataSourceLoader | undefined;
666
- all(): Record<string, AutoCrudDataSourceLoader>;
671
+ get(name: string): AutoCrudFormComponentConfig | undefined;
672
+ all(): Record<string, AutoCrudFormComponentConfig>;
667
673
  subscribe(listener: RegistryListener): () => void;
668
674
  };
675
+ declare const dataSources: {
676
+ register(name: string, registration: AutoCrudDataSourceRegistration): void;
677
+ unregister: (name: string) => void;
678
+ get: (name: string) => AutoCrudDataSourceEntry | undefined;
679
+ all: () => Record<string, AutoCrudDataSourceEntry>;
680
+ subscribe: (listener: RegistryListener) => () => void;
681
+ };
669
682
  declare function normalizeDataSourceConfig(config: AutoCrudDataSourceConfig | undefined): {
670
683
  key: string;
671
- dependsOn: string[];
672
- resetOnChange: boolean;
673
684
  } | undefined;
674
685
  declare function normalizeOptions(result: AutoCrudDataSourceResult | undefined): AutoCrudOption[];
675
686
  //#endregion
@@ -935,7 +946,7 @@ declare function AutoCrudTable<TSchema extends z.ZodObject<z.ZodRawShape>>({
935
946
  toolbarActions,
936
947
  locale: localeProp,
937
948
  onCreate
938
- }: AutoCrudTableProps<TSchema>): react_jsx_runtime3.JSX.Element;
949
+ }: AutoCrudTableProps<TSchema>): react_jsx_runtime2.JSX.Element;
939
950
  //#endregion
940
951
  //#region src/components/auto-crud/auto-form.d.ts
941
952
  interface AutoFormProps<T extends z.ZodObject<z.ZodRawShape>> {
@@ -967,7 +978,7 @@ declare function AutoFormInner<T extends z.ZodObject<z.ZodRawShape>>({
967
978
  labelAlign,
968
979
  labelWidth,
969
980
  showSubmitButton
970
- }: AutoFormProps<T>, ref: React.Ref<AutoFormRef>): react_jsx_runtime3.JSX.Element;
981
+ }: AutoFormProps<T>, ref: React.Ref<AutoFormRef>): react_jsx_runtime2.JSX.Element;
971
982
  declare const AutoForm: <T extends z.ZodObject<z.ZodRawShape>>(props: AutoFormProps<T> & {
972
983
  ref?: React.Ref<AutoFormRef>;
973
984
  }) => ReturnType<typeof AutoFormInner>;
@@ -1209,7 +1220,7 @@ declare const filterItemSchema: z.ZodObject<{
1209
1220
  type FilterItemSchema = z.infer<typeof filterItemSchema>;
1210
1221
  //#endregion
1211
1222
  //#region src/types/data-table.d.ts
1212
- declare module "@tanstack/react-table" {
1223
+ declare module '@tanstack/react-table' {
1213
1224
  interface TableMeta<TData extends RowData> {
1214
1225
  queryKeys?: QueryKeys;
1215
1226
  queryStateOptions?: UrlStateOptions;
@@ -1224,7 +1235,7 @@ declare module "@tanstack/react-table" {
1224
1235
  unit?: string;
1225
1236
  icon?: React.FC<React.SVGProps<SVGSVGElement>>;
1226
1237
  /** 控制在哪些筛选模式下显示(未设置则在所有模式显示) */
1227
- modes?: Array<"simple" | "advanced" | "command">;
1238
+ modes?: Array<'simple' | 'advanced' | 'command'>;
1228
1239
  }
1229
1240
  }
1230
1241
  interface QueryKeys {
@@ -1241,10 +1252,10 @@ interface Option {
1241
1252
  count?: number;
1242
1253
  icon?: React.FC<React.SVGProps<SVGSVGElement>>;
1243
1254
  }
1244
- type FilterOperator = DataTableConfig["operators"][number];
1245
- type FilterVariant$1 = DataTableConfig["filterVariants"][number];
1246
- type JoinOperator = DataTableConfig["joinOperators"][number];
1247
- interface ExtendedColumnSort<TData> extends Omit<ColumnSort, "id"> {
1255
+ type FilterOperator = DataTableConfig['operators'][number];
1256
+ type FilterVariant$1 = DataTableConfig['filterVariants'][number];
1257
+ type JoinOperator = DataTableConfig['joinOperators'][number];
1258
+ interface ExtendedColumnSort<TData> extends Omit<ColumnSort, 'id'> {
1248
1259
  id: Extract<keyof TData, string>;
1249
1260
  }
1250
1261
  interface ExtendedColumnFilter<TData> extends FilterItemSchema {
@@ -1252,7 +1263,7 @@ interface ExtendedColumnFilter<TData> extends FilterItemSchema {
1252
1263
  }
1253
1264
  interface DataTableRowAction<TData> {
1254
1265
  row: Row<TData>;
1255
- variant: "update" | "delete";
1266
+ variant: 'update' | 'delete';
1256
1267
  }
1257
1268
  //#endregion
1258
1269
  //#region src/components/auto-crud/auto-table-simple-filters.d.ts
@@ -1269,7 +1280,7 @@ declare function AutoTableSimpleFilters<TData>({
1269
1280
  filters: externalFilters,
1270
1281
  onFiltersChange,
1271
1282
  leading
1272
- }: AutoTableSimpleFiltersProps<TData>): react_jsx_runtime3.JSX.Element | null;
1283
+ }: AutoTableSimpleFiltersProps<TData>): react_jsx_runtime2.JSX.Element | null;
1273
1284
  //#endregion
1274
1285
  //#region src/components/auto-crud/form-modal.d.ts
1275
1286
  type ModalVariant = "dialog" | "sheet";
@@ -1311,7 +1322,7 @@ declare function CrudFormModal<T extends z.ZodObject<z.ZodRawShape>>({
1311
1322
  labelAlign,
1312
1323
  labelWidth,
1313
1324
  className
1314
- }: CrudFormModalProps<T>): react_jsx_runtime3.JSX.Element;
1325
+ }: CrudFormModalProps<T>): react_jsx_runtime2.JSX.Element;
1315
1326
  //#endregion
1316
1327
  //#region src/components/auto-crud/import-dialog.d.ts
1317
1328
  interface ImportDialogProps {
@@ -1333,7 +1344,7 @@ declare function ImportDialog({
1333
1344
  columns,
1334
1345
  title,
1335
1346
  locale
1336
- }: ImportDialogProps): react_jsx_runtime3.JSX.Element;
1347
+ }: ImportDialogProps): react_jsx_runtime2.JSX.Element;
1337
1348
  //#endregion
1338
1349
  //#region src/components/auto-crud/export-dialog.d.ts
1339
1350
  type ExportMode = "selected" | "filtered";
@@ -1353,7 +1364,7 @@ declare function ExportDialog({
1353
1364
  selectedCount,
1354
1365
  onExport,
1355
1366
  canExportFiltered
1356
- }: ExportDialogProps): react_jsx_runtime3.JSX.Element;
1367
+ }: ExportDialogProps): react_jsx_runtime2.JSX.Element;
1357
1368
  //#endregion
1358
1369
  //#region src/components/data-table/data-table.d.ts
1359
1370
  interface DataTableProps<TData> extends React$1.ComponentProps<"div"> {
@@ -1366,7 +1377,7 @@ declare function DataTable<TData>({
1366
1377
  children,
1367
1378
  className,
1368
1379
  ...props
1369
- }: DataTableProps<TData>): react_jsx_runtime3.JSX.Element;
1380
+ }: DataTableProps<TData>): react_jsx_runtime2.JSX.Element;
1370
1381
  //#endregion
1371
1382
  //#region src/components/data-table/data-table-advanced-toolbar.d.ts
1372
1383
  interface DataTableAdvancedToolbarProps<TData> extends React$1.ComponentProps<"div"> {
@@ -1377,7 +1388,7 @@ declare function DataTableAdvancedToolbar<TData>({
1377
1388
  children,
1378
1389
  className,
1379
1390
  ...props
1380
- }: DataTableAdvancedToolbarProps<TData>): react_jsx_runtime3.JSX.Element;
1391
+ }: DataTableAdvancedToolbarProps<TData>): react_jsx_runtime2.JSX.Element;
1381
1392
  //#endregion
1382
1393
  //#region src/components/data-table/data-table-column-header.d.ts
1383
1394
  interface DataTableColumnHeaderProps<TData, TValue> extends React.ComponentProps<typeof DropdownMenuTrigger> {
@@ -1389,7 +1400,7 @@ declare function DataTableColumnHeader<TData, TValue>({
1389
1400
  label,
1390
1401
  className,
1391
1402
  ...props
1392
- }: DataTableColumnHeaderProps<TData, TValue>): react_jsx_runtime3.JSX.Element;
1403
+ }: DataTableColumnHeaderProps<TData, TValue>): react_jsx_runtime2.JSX.Element;
1393
1404
  //#endregion
1394
1405
  //#region src/components/data-table/data-table-faceted-filter.d.ts
1395
1406
  interface DataTableFacetedFilterProps<TData, TValue> {
@@ -1403,7 +1414,7 @@ declare function DataTableFacetedFilter<TData, TValue>({
1403
1414
  title,
1404
1415
  options,
1405
1416
  multiple
1406
- }: DataTableFacetedFilterProps<TData, TValue>): react_jsx_runtime3.JSX.Element;
1417
+ }: DataTableFacetedFilterProps<TData, TValue>): react_jsx_runtime2.JSX.Element;
1407
1418
  //#endregion
1408
1419
  //#region src/components/data-table/data-table-pagination.d.ts
1409
1420
  interface DataTablePaginationProps<TData> extends React.ComponentProps<"div"> {
@@ -1415,7 +1426,7 @@ declare function DataTablePagination<TData>({
1415
1426
  pageSizeOptions,
1416
1427
  className,
1417
1428
  ...props
1418
- }: DataTablePaginationProps<TData>): react_jsx_runtime3.JSX.Element;
1429
+ }: DataTablePaginationProps<TData>): react_jsx_runtime2.JSX.Element;
1419
1430
  //#endregion
1420
1431
  //#region src/components/data-table/data-table-toolbar.d.ts
1421
1432
  interface DataTableToolbarProps<TData> extends React$1.ComponentProps<"div"> {
@@ -1426,7 +1437,7 @@ declare function DataTableToolbar<TData>({
1426
1437
  children,
1427
1438
  className,
1428
1439
  ...props
1429
- }: DataTableToolbarProps<TData>): react_jsx_runtime3.JSX.Element;
1440
+ }: DataTableToolbarProps<TData>): react_jsx_runtime2.JSX.Element;
1430
1441
  //#endregion
1431
1442
  //#region src/components/data-table/data-table-view-options.d.ts
1432
1443
  interface DataTableViewOptionsProps<TData> extends React$1.ComponentProps<typeof PopoverContent> {
@@ -1437,7 +1448,7 @@ declare function DataTableViewOptions<TData>({
1437
1448
  table,
1438
1449
  disabled,
1439
1450
  ...props
1440
- }: DataTableViewOptionsProps<TData>): react_jsx_runtime3.JSX.Element;
1451
+ }: DataTableViewOptionsProps<TData>): react_jsx_runtime2.JSX.Element;
1441
1452
  //#endregion
1442
1453
  //#region src/components/ui/multi-combobox.d.ts
1443
1454
  interface MultiComboboxOption {
@@ -1814,4 +1825,4 @@ declare function exportAllToCSV<T extends Record<string, unknown>>(data: T[], op
1814
1825
  */
1815
1826
  declare function downloadCSVTemplate(headers: string[], filename?: string): void;
1816
1827
  //#endregion
1817
- export { type ActionItem, type ActionsColumnConfig, type AutoCrudDataSourceConfig, type AutoCrudDataSourceContext, type AutoCrudDataSourceLoader, type AutoCrudFormComponentConfig, type AutoCrudLocale, type AutoCrudOption, AutoCrudTable, type AutoCrudTableProps, AutoForm, type AutoQueryParams, AutoTable, AutoTableActionBar, AutoTableSimpleFilters, type BatchActionConfig, type BatchActionContext, type BatchActionItem, type BatchBuiltinActionItem, type BatchBuiltinActionType, type BatchCustomActionItem, type BatchUpdateField, type ColumnOverrides, type CreateFormSchemaOptions, type CreateTableSchemaOptions, CrudFormModal, type CrudHooks, type CrudOperationPermissions, type CrudPermissions, type DataSource, DataTable, DataTableAdvancedToolbar, DataTableColumnHeader, DataTableFacetedFilter, DataTablePagination, DataTableRowAction, DataTableToolbar, DataTableViewOptions, type EnumOption, ExportDialog, type ExportDialogProps, type ExportMode, ExtendedColumnFilter, ExtendedColumnSort, type Field, type FieldOption, type FieldType, type Fields, type FilterConfig, FilterOperator, type FilterVariant, type FormSchemaOverrides, ImportDialog, type ImportDialogProps, 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, QueryKeys, SchemaAdapter, type SimpleFieldConfig, type SimpleFieldsConfig, type ToastAdapter, type ToolbarActionItem, type ToolbarBuiltinActionItem, type ToolbarCustomActionItem, type UnifiedField, type UnifiedSchema, type UrlStateOptions, type UseAutoCrudResourceOptions, type UseAutoCrudResourceParams, type UseAutoCrudResourceReturn, cn, coerceRowValues, createActionsColumn, createEditFormSchema, createFormSchema, createMemoryDataSource, createSelectColumn, createTRPCDataSource, createTableSchema, dataSources, dataToCSV, deDE, downloadCSVTemplate, enUS, esES, exportAllToCSV, exportTableToCSV, formComponents, formatDate, frFR, generateCSVTemplate, getUrlParams, humanize, jaJP, koKR, noopToastAdapter, normalizeDataSourceConfig, normalizeOptions, parseAsArrayOf, parseAsInteger, parseAsString, parseAsStringEnum, parseCSV, parseImportFile, parseJSON, parseZodField, resolveLocale, setSearchParams, useAutoCrudResource, useDataTable, useQueryState, useQueryStates, useReadableFilters, useUrlState, useUrlStates, zhCN };
1828
+ export { type ActionItem, type ActionsColumnConfig, type AutoCrudDataSourceConfig, type AutoCrudDataSourceContext, type AutoCrudDataSourceEntry, type AutoCrudDataSourceLoader, type AutoCrudDataSourceRegistration, type AutoCrudFormComponentConfig, type AutoCrudLocale, type AutoCrudOption, AutoCrudTable, type AutoCrudTableProps, AutoForm, type AutoQueryParams, AutoTable, AutoTableActionBar, AutoTableSimpleFilters, type BatchActionConfig, type BatchActionContext, type BatchActionItem, type BatchBuiltinActionItem, type BatchBuiltinActionType, type BatchCustomActionItem, type BatchUpdateField, type ColumnOverrides, type CreateFormSchemaOptions, type CreateTableSchemaOptions, CrudFormModal, type CrudHooks, type CrudOperationPermissions, type CrudPermissions, type DataSource, DataTable, DataTableAdvancedToolbar, DataTableColumnHeader, DataTableFacetedFilter, DataTablePagination, DataTableRowAction, DataTableToolbar, DataTableViewOptions, type EnumOption, ExportDialog, type ExportDialogProps, type ExportMode, ExtendedColumnFilter, ExtendedColumnSort, type Field, type FieldOption, type FieldType, type Fields, type FilterConfig, FilterOperator, type FilterVariant, type FormSchemaOverrides, ImportDialog, type ImportDialogProps, 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, QueryKeys, SchemaAdapter, type SimpleFieldConfig, type SimpleFieldsConfig, type ToastAdapter, type ToolbarActionItem, type ToolbarBuiltinActionItem, type ToolbarCustomActionItem, type UnifiedField, type UnifiedSchema, type UrlStateOptions, type UseAutoCrudResourceOptions, type UseAutoCrudResourceParams, type UseAutoCrudResourceReturn, cn, coerceRowValues, components, createActionsColumn, createEditFormSchema, createFormSchema, createMemoryDataSource, createSelectColumn, createTRPCDataSource, createTableSchema, dataSources, dataToCSV, deDE, downloadCSVTemplate, enUS, esES, exportAllToCSV, exportTableToCSV, formComponents, formatDate, frFR, generateCSVTemplate, getUrlParams, humanize, jaJP, koKR, noopToastAdapter, normalizeDataSourceConfig, normalizeOptions, parseAsArrayOf, parseAsInteger, parseAsString, parseAsStringEnum, parseCSV, parseImportFile, parseJSON, parseZodField, resolveLocale, setSearchParams, useAutoCrudResource, useDataTable, useQueryState, useQueryStates, useReadableFilters, useUrlState, useUrlStates, zhCN };
package/dist/index.js CHANGED
@@ -5192,8 +5192,12 @@ function createEditFormSchema(schema, options) {
5192
5192
  function createRegistry(label) {
5193
5193
  const entries = /* @__PURE__ */ new Map();
5194
5194
  const listeners = /* @__PURE__ */ new Set();
5195
+ let notifyScheduled = false;
5195
5196
  const notify = () => {
5197
+ if (notifyScheduled) return;
5198
+ notifyScheduled = true;
5196
5199
  queueMicrotask(() => {
5200
+ notifyScheduled = false;
5197
5201
  for (const listener of listeners) listener();
5198
5202
  });
5199
5203
  };
@@ -5223,20 +5227,32 @@ function createRegistry(label) {
5223
5227
  };
5224
5228
  }
5225
5229
  const formComponents = createRegistry("form component");
5226
- const dataSources = createRegistry("data source");
5227
- function normalizeDataSourceConfig(config) {
5228
- if (typeof config === "string") return config.length > 0 ? {
5229
- key: config,
5230
- dependsOn: [],
5231
- resetOnChange: false
5232
- } : void 0;
5233
- if (!config?.key) return void 0;
5230
+ const components = formComponents;
5231
+ function normalizeDataSourceRegistration(registration) {
5232
+ if (typeof registration === "function") return {
5233
+ dependencies: [],
5234
+ reset: false,
5235
+ load: registration
5236
+ };
5234
5237
  return {
5235
- key: config.key,
5236
- dependsOn: Array.isArray(config.dependsOn) ? config.dependsOn : [],
5237
- resetOnChange: config.resetOnChange === true
5238
+ dependencies: Array.isArray(registration.dependencies) ? registration.dependencies : [],
5239
+ reset: registration.reset === true,
5240
+ load: registration.load
5238
5241
  };
5239
5242
  }
5243
+ const dataSourceRegistry = createRegistry("data source");
5244
+ const dataSources = {
5245
+ register(name, registration) {
5246
+ dataSourceRegistry.register(name, normalizeDataSourceRegistration(registration));
5247
+ },
5248
+ unregister: dataSourceRegistry.unregister,
5249
+ get: dataSourceRegistry.get,
5250
+ all: dataSourceRegistry.all,
5251
+ subscribe: dataSourceRegistry.subscribe
5252
+ };
5253
+ function normalizeDataSourceConfig(config) {
5254
+ if (typeof config === "string") return config.length > 0 ? { key: config } : void 0;
5255
+ }
5240
5256
  function normalizeOptions(result) {
5241
5257
  const options = Array.isArray(result) ? result : result?.options;
5242
5258
  if (!Array.isArray(options)) return [];
@@ -5302,9 +5318,7 @@ function useRegistryVersion$1(subscribe) {
5302
5318
  return version;
5303
5319
  }
5304
5320
  function isDataSourceConfig(value) {
5305
- if (typeof value === "string") return value.length > 0;
5306
- if (!value || typeof value !== "object" || Array.isArray(value)) return false;
5307
- return typeof value.key === "string";
5321
+ return typeof value === "string" && value.length > 0;
5308
5322
  }
5309
5323
  function collectDataSourceConfigs(schema, result = {}) {
5310
5324
  const properties = schema.properties;
@@ -5334,17 +5348,17 @@ function useFormDataSources(form, schema) {
5334
5348
  const loadFieldOptions = async (fieldName, source) => {
5335
5349
  const version = (loadVersions.get(fieldName) ?? 0) + 1;
5336
5350
  loadVersions.set(fieldName, version);
5337
- const loader = dataSources.get(source.key);
5338
- if (!loader) {
5351
+ const entry = dataSources.get(source.key);
5352
+ if (!entry) {
5339
5353
  form.setFieldState(fieldName, (state) => {
5340
5354
  state.dataSource = [];
5341
5355
  });
5342
5356
  return;
5343
5357
  }
5344
5358
  try {
5345
- const options = normalizeOptions(await loader({
5359
+ const options = normalizeOptions(await entry.load({
5346
5360
  field: fieldName,
5347
- values: Object.fromEntries(source.dependsOn.map((dependency) => [dependency, form.getValuesIn(dependency)])),
5361
+ values: Object.fromEntries(entry.dependencies.map((dependency) => [dependency, form.getValuesIn(dependency)])),
5348
5362
  signal: controller?.signal
5349
5363
  }));
5350
5364
  if (!active || loadVersions.get(fieldName) !== version) return;
@@ -5361,10 +5375,11 @@ function useFormDataSources(form, schema) {
5361
5375
  };
5362
5376
  for (const [fieldName, source] of sourceEntries) loadFieldOptions(fieldName, source);
5363
5377
  form.addEffects(effectId, () => {
5364
- for (const dependency of new Set(sourceEntries.flatMap(([, source]) => source.dependsOn))) onFieldValueChange(dependency, () => {
5378
+ for (const dependency of new Set(sourceEntries.flatMap(([, source]) => dataSources.get(source.key)?.dependencies ?? []))) onFieldValueChange(dependency, () => {
5365
5379
  for (const [fieldName, source] of sourceEntries) {
5366
- if (!source.dependsOn.includes(dependency)) continue;
5367
- if (source.resetOnChange) form.setValuesIn(fieldName, void 0);
5380
+ const entry = dataSources.get(source.key);
5381
+ if (!entry?.dependencies.includes(dependency)) continue;
5382
+ if (entry.reset) form.setValuesIn(fieldName, void 0);
5368
5383
  loadFieldOptions(fieldName, source);
5369
5384
  }
5370
5385
  });
@@ -5403,8 +5418,8 @@ function AutoFormInner({ schema: zodSchema, initialValues, onSubmit, overrides,
5403
5418
  }, [labelAlign, labelWidth]);
5404
5419
  const fieldComponents = useMemo(() => ({ fields: {
5405
5420
  ...defaultFieldComponents,
5406
- ...formComponents.all()
5407
- } }), [useRegistryVersion$1(formComponents.subscribe)]);
5421
+ ...components.all()
5422
+ } }), [useRegistryVersion$1(components.subscribe)]);
5408
5423
  useFormDataSources(form, formSchema);
5409
5424
  const handleSubmit = async () => {
5410
5425
  await form.validate();
@@ -6303,10 +6318,10 @@ function useDynamicFilterOptions(fields) {
6303
6318
  let active = true;
6304
6319
  const controller = typeof AbortController === "undefined" ? void 0 : new AbortController();
6305
6320
  Promise.all(sourceEntries.map(async ({ field, source }) => {
6306
- const loader = dataSources.get(source.key);
6307
- if (!loader) return [field, []];
6321
+ const entry = dataSources.get(source.key);
6322
+ if (!entry) return [field, []];
6308
6323
  try {
6309
- return [field, normalizeOptions(await loader({
6324
+ return [field, normalizeOptions(await entry.load({
6310
6325
  field,
6311
6326
  values: {},
6312
6327
  signal: controller?.signal
@@ -6540,7 +6555,7 @@ function renderFieldValue(value, type, booleanLocale, options) {
6540
6555
  /**
6541
6556
  * ViewModal 组件 - 详情查看弹窗
6542
6557
  */
6543
- function ViewModal({ open, onOpenChange, variant, data, schema, fields: fieldConfig, denyFields, locale }) {
6558
+ function ViewModal({ open, onOpenChange, variant, data, schema, fields: fieldConfig, dynamicOptions, denyFields, locale }) {
6544
6559
  if (!data) return null;
6545
6560
  const shape = schema.shape;
6546
6561
  const denySet = new Set(denyFields ?? []);
@@ -6553,7 +6568,7 @@ function ViewModal({ open, onOpenChange, variant, data, schema, fields: fieldCon
6553
6568
  const parsed = parseZodField(fieldSchema);
6554
6569
  const label = fieldConfig?.[key]?.label ?? humanize(key);
6555
6570
  const value = data[key];
6556
- const options = normalizeFieldOptions(fieldConfig?.[key]?.enum);
6571
+ const options = normalizeFieldOptions(fieldConfig?.[key]?.enum) ?? normalizeFieldOptions(dynamicOptions?.[key]);
6557
6572
  return /* @__PURE__ */ jsxs("div", {
6558
6573
  className: "grid grid-cols-3 items-start gap-4",
6559
6574
  children: [/* @__PURE__ */ jsx("dt", {
@@ -6575,6 +6590,7 @@ function ViewModal({ open, onOpenChange, variant, data, schema, fields: fieldCon
6575
6590
  open,
6576
6591
  onOpenChange,
6577
6592
  children: /* @__PURE__ */ jsxs(DialogContent, {
6593
+ "aria-describedby": void 0,
6578
6594
  className: "max-w-2xl max-h-[80vh] overflow-y-auto",
6579
6595
  children: [/* @__PURE__ */ jsx(DialogHeader, { children: /* @__PURE__ */ jsx(DialogTitle, { children: locale.viewModal.title }) }), content]
6580
6596
  })
@@ -6879,6 +6895,7 @@ function AutoCrudTable({ title, description, schema, resource, fields, table: ta
6879
6895
  data: resource.modal.selected,
6880
6896
  schema: resolvedSchema,
6881
6897
  fields: resolvedFields,
6898
+ dynamicOptions: dynamicFilterOptions,
6882
6899
  denyFields,
6883
6900
  locale
6884
6901
  }),
@@ -8265,4 +8282,4 @@ function createMemoryDataSource(initialData = []) {
8265
8282
  }
8266
8283
 
8267
8284
  //#endregion
8268
- export { AutoCrudTable, AutoForm, AutoTable, AutoTableActionBar, AutoTableSimpleFilters, CrudFormModal, DataTable, DataTableAdvancedToolbar, DataTableColumnHeader, DataTableFacetedFilter, DataTablePagination, DataTableToolbar, DataTableViewOptions, ExportDialog, ImportDialog, MultiCombobox, SchemaAdapter, cn, coerceRowValues, createActionsColumn, createEditFormSchema, createFormSchema, createMemoryDataSource, createSelectColumn, createTRPCDataSource, createTableSchema, dataSources, dataToCSV, deDE, downloadCSVTemplate, enUS, esES, exportAllToCSV, exportTableToCSV, formComponents, formatDate, frFR, generateCSVTemplate, getUrlParams, humanize, jaJP, koKR, noopToastAdapter, normalizeDataSourceConfig, normalizeOptions, parseAsArrayOf, parseAsInteger, parseAsString, parseAsStringEnum, parseCSV, parseImportFile, parseJSON, parseZodField, resolveLocale, setSearchParams, useAutoCrudResource, useDataTable, useQueryState, useQueryStates, useReadableFilters, useUrlState, useUrlStates, zhCN };
8285
+ export { AutoCrudTable, AutoForm, AutoTable, AutoTableActionBar, AutoTableSimpleFilters, CrudFormModal, DataTable, DataTableAdvancedToolbar, DataTableColumnHeader, DataTableFacetedFilter, DataTablePagination, DataTableToolbar, DataTableViewOptions, ExportDialog, ImportDialog, MultiCombobox, SchemaAdapter, cn, coerceRowValues, components, createActionsColumn, createEditFormSchema, createFormSchema, createMemoryDataSource, createSelectColumn, createTRPCDataSource, createTableSchema, dataSources, dataToCSV, deDE, downloadCSVTemplate, enUS, esES, exportAllToCSV, exportTableToCSV, formComponents, formatDate, frFR, generateCSVTemplate, getUrlParams, humanize, jaJP, koKR, noopToastAdapter, normalizeDataSourceConfig, normalizeOptions, parseAsArrayOf, parseAsInteger, parseAsString, parseAsStringEnum, parseCSV, parseImportFile, parseJSON, parseZodField, resolveLocale, setSearchParams, useAutoCrudResource, useDataTable, useQueryState, useQueryStates, useReadableFilters, useUrlState, useUrlStates, zhCN };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@wordrhyme/auto-crud",
3
3
  "type": "module",
4
- "version": "1.2.1",
4
+ "version": "1.2.3",
5
5
  "description": "Schema-first CRUD components with auto-generated tables and forms",
6
6
  "author": "wordrhyme",
7
7
  "license": "MIT",
@@ -67,8 +67,8 @@
67
67
  "tailwind-merge": "^3.5.0",
68
68
  "vaul": "^1.1.2",
69
69
  "@pixpilot/formily-shadcn": "1.11.20",
70
- "@pixpilot/shadcn": "1.2.7",
71
- "@pixpilot/shadcn-ui": "1.21.1"
70
+ "@pixpilot/shadcn-ui": "1.21.1",
71
+ "@pixpilot/shadcn": "1.2.7"
72
72
  },
73
73
  "devDependencies": {
74
74
  "@tanstack/react-query": "^5.90.15",
@@ -86,11 +86,11 @@
86
86
  "tsdown": "^0.15.12",
87
87
  "typescript": "^5.9.3",
88
88
  "vitest": "^3.2.4",
89
- "@internal/tsconfig": "0.1.0",
90
- "@internal/prettier-config": "0.0.1",
91
- "@internal/vitest-config": "0.1.0",
92
89
  "@internal/eslint-config": "0.3.0",
93
- "@internal/tsdown-config": "0.1.0"
90
+ "@internal/prettier-config": "0.0.1",
91
+ "@internal/tsconfig": "0.1.0",
92
+ "@internal/tsdown-config": "0.1.0",
93
+ "@internal/vitest-config": "0.1.0"
94
94
  },
95
95
  "prettier": "@internal/prettier-config",
96
96
  "scripts": {