@wordrhyme/auto-crud 1.2.0 → 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 +63 -47
- package/dist/index.d.cts +55 -44
- package/dist/index.d.ts +55 -44
- package/dist/index.js +61 -47
- package/package.json +7 -3
package/dist/index.cjs
CHANGED
|
@@ -61,6 +61,8 @@ let __formily_react = require("@formily/react");
|
|
|
61
61
|
__formily_react = __toESM(__formily_react);
|
|
62
62
|
let sonner = require("sonner");
|
|
63
63
|
sonner = __toESM(sonner);
|
|
64
|
+
let __tanstack_react_query = require("@tanstack/react-query");
|
|
65
|
+
__tanstack_react_query = __toESM(__tanstack_react_query);
|
|
64
66
|
|
|
65
67
|
//#region src/lib/utils.ts
|
|
66
68
|
function cn(...inputs) {
|
|
@@ -5173,12 +5175,8 @@ function getComponentProps(type, parsed) {
|
|
|
5173
5175
|
function createFormSchema(schema, options) {
|
|
5174
5176
|
const shape = schema.shape;
|
|
5175
5177
|
const properties = {};
|
|
5176
|
-
const { overrides, exclude = [], layout = "vertical", gridColumns = 1
|
|
5178
|
+
const { overrides, exclude = [], layout = "vertical", gridColumns = 1 } = options ?? {};
|
|
5177
5179
|
const decoratorProps = { className: "space-y-2" };
|
|
5178
|
-
if (labelAlign) decoratorProps.labelAlign = labelAlign;
|
|
5179
|
-
if (labelWidth) decoratorProps.labelWidth = labelWidth;
|
|
5180
|
-
if (labelCol) decoratorProps.labelCol = labelCol;
|
|
5181
|
-
if (wrapperCol) decoratorProps.wrapperCol = wrapperCol;
|
|
5182
5180
|
for (const [key, fieldSchema] of Object.entries(shape)) {
|
|
5183
5181
|
if (exclude.includes(key)) continue;
|
|
5184
5182
|
const parsed = parseZodField(fieldSchema);
|
|
@@ -5237,8 +5235,12 @@ function createEditFormSchema(schema, options) {
|
|
|
5237
5235
|
function createRegistry(label) {
|
|
5238
5236
|
const entries = /* @__PURE__ */ new Map();
|
|
5239
5237
|
const listeners = /* @__PURE__ */ new Set();
|
|
5238
|
+
let notifyScheduled = false;
|
|
5240
5239
|
const notify = () => {
|
|
5240
|
+
if (notifyScheduled) return;
|
|
5241
|
+
notifyScheduled = true;
|
|
5241
5242
|
queueMicrotask(() => {
|
|
5243
|
+
notifyScheduled = false;
|
|
5242
5244
|
for (const listener of listeners) listener();
|
|
5243
5245
|
});
|
|
5244
5246
|
};
|
|
@@ -5268,20 +5270,32 @@ function createRegistry(label) {
|
|
|
5268
5270
|
};
|
|
5269
5271
|
}
|
|
5270
5272
|
const formComponents = createRegistry("form component");
|
|
5271
|
-
const
|
|
5272
|
-
function
|
|
5273
|
-
if (typeof
|
|
5274
|
-
|
|
5275
|
-
|
|
5276
|
-
|
|
5277
|
-
}
|
|
5278
|
-
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
|
+
};
|
|
5279
5280
|
return {
|
|
5280
|
-
|
|
5281
|
-
|
|
5282
|
-
|
|
5281
|
+
dependencies: Array.isArray(registration.dependencies) ? registration.dependencies : [],
|
|
5282
|
+
reset: registration.reset === true,
|
|
5283
|
+
load: registration.load
|
|
5283
5284
|
};
|
|
5284
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
|
+
}
|
|
5285
5299
|
function normalizeOptions(result) {
|
|
5286
5300
|
const options = Array.isArray(result) ? result : result?.options;
|
|
5287
5301
|
if (!Array.isArray(options)) return [];
|
|
@@ -5347,9 +5361,7 @@ function useRegistryVersion$1(subscribe) {
|
|
|
5347
5361
|
return version;
|
|
5348
5362
|
}
|
|
5349
5363
|
function isDataSourceConfig(value) {
|
|
5350
|
-
|
|
5351
|
-
if (!value || typeof value !== "object" || Array.isArray(value)) return false;
|
|
5352
|
-
return typeof value.key === "string";
|
|
5364
|
+
return typeof value === "string" && value.length > 0;
|
|
5353
5365
|
}
|
|
5354
5366
|
function collectDataSourceConfigs(schema, result = {}) {
|
|
5355
5367
|
const properties = schema.properties;
|
|
@@ -5379,17 +5391,17 @@ function useFormDataSources(form, schema) {
|
|
|
5379
5391
|
const loadFieldOptions = async (fieldName, source) => {
|
|
5380
5392
|
const version = (loadVersions.get(fieldName) ?? 0) + 1;
|
|
5381
5393
|
loadVersions.set(fieldName, version);
|
|
5382
|
-
const
|
|
5383
|
-
if (!
|
|
5394
|
+
const entry = dataSources.get(source.key);
|
|
5395
|
+
if (!entry) {
|
|
5384
5396
|
form.setFieldState(fieldName, (state) => {
|
|
5385
5397
|
state.dataSource = [];
|
|
5386
5398
|
});
|
|
5387
5399
|
return;
|
|
5388
5400
|
}
|
|
5389
5401
|
try {
|
|
5390
|
-
const options = normalizeOptions(await
|
|
5402
|
+
const options = normalizeOptions(await entry.load({
|
|
5391
5403
|
field: fieldName,
|
|
5392
|
-
values: Object.fromEntries(
|
|
5404
|
+
values: Object.fromEntries(entry.dependencies.map((dependency) => [dependency, form.getValuesIn(dependency)])),
|
|
5393
5405
|
signal: controller?.signal
|
|
5394
5406
|
}));
|
|
5395
5407
|
if (!active || loadVersions.get(fieldName) !== version) return;
|
|
@@ -5406,10 +5418,11 @@ function useFormDataSources(form, schema) {
|
|
|
5406
5418
|
};
|
|
5407
5419
|
for (const [fieldName, source] of sourceEntries) loadFieldOptions(fieldName, source);
|
|
5408
5420
|
form.addEffects(effectId, () => {
|
|
5409
|
-
for (const dependency of new Set(sourceEntries.flatMap(([, source]) => source.
|
|
5421
|
+
for (const dependency of new Set(sourceEntries.flatMap(([, source]) => dataSources.get(source.key)?.dependencies ?? []))) (0, __formily_core.onFieldValueChange)(dependency, () => {
|
|
5410
5422
|
for (const [fieldName, source] of sourceEntries) {
|
|
5411
|
-
|
|
5412
|
-
if (
|
|
5423
|
+
const entry = dataSources.get(source.key);
|
|
5424
|
+
if (!entry?.dependencies.includes(dependency)) continue;
|
|
5425
|
+
if (entry.reset) form.setValuesIn(fieldName, void 0);
|
|
5413
5426
|
loadFieldOptions(fieldName, source);
|
|
5414
5427
|
}
|
|
5415
5428
|
});
|
|
@@ -5430,20 +5443,26 @@ function AutoFormInner({ schema: zodSchema, initialValues, onSubmit, overrides,
|
|
|
5430
5443
|
const formSchema = (0, react.useMemo)(() => createEditFormSchema(zodSchema, {
|
|
5431
5444
|
overrides,
|
|
5432
5445
|
layout: "grid",
|
|
5433
|
-
gridColumns
|
|
5434
|
-
labelAlign,
|
|
5435
|
-
labelWidth
|
|
5446
|
+
gridColumns
|
|
5436
5447
|
}), [
|
|
5437
5448
|
zodSchema,
|
|
5438
5449
|
overrides,
|
|
5439
|
-
gridColumns
|
|
5440
|
-
labelAlign,
|
|
5441
|
-
labelWidth
|
|
5450
|
+
gridColumns
|
|
5442
5451
|
]);
|
|
5452
|
+
const formLayout = (0, react.useMemo)(() => {
|
|
5453
|
+
const inlineLabel = labelAlign === "left" || labelAlign === "right";
|
|
5454
|
+
return {
|
|
5455
|
+
labelPlacement: inlineLabel ? "start" : "top",
|
|
5456
|
+
itemProps: inlineLabel ? { label: {
|
|
5457
|
+
className: labelAlign === "right" ? "text-right" : void 0,
|
|
5458
|
+
style: labelWidth != null ? { width: labelWidth } : void 0
|
|
5459
|
+
} } : void 0
|
|
5460
|
+
};
|
|
5461
|
+
}, [labelAlign, labelWidth]);
|
|
5443
5462
|
const fieldComponents = (0, react.useMemo)(() => ({ fields: {
|
|
5444
5463
|
...defaultFieldComponents,
|
|
5445
|
-
...
|
|
5446
|
-
} }), [useRegistryVersion$1(
|
|
5464
|
+
...components.all()
|
|
5465
|
+
} }), [useRegistryVersion$1(components.subscribe)]);
|
|
5447
5466
|
useFormDataSources(form, formSchema);
|
|
5448
5467
|
const handleSubmit = async () => {
|
|
5449
5468
|
await form.validate();
|
|
@@ -5452,6 +5471,7 @@ function AutoFormInner({ schema: zodSchema, initialValues, onSubmit, overrides,
|
|
|
5452
5471
|
(0, react.useImperativeHandle)(ref, () => ({ submit: handleSubmit }));
|
|
5453
5472
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(__pixpilot_formily_shadcn.Form, {
|
|
5454
5473
|
form,
|
|
5474
|
+
layout: formLayout,
|
|
5455
5475
|
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(__pixpilot_formily_shadcn.JsonSchemaField, {
|
|
5456
5476
|
schema: formSchema,
|
|
5457
5477
|
components: fieldComponents
|
|
@@ -6341,10 +6361,10 @@ function useDynamicFilterOptions(fields) {
|
|
|
6341
6361
|
let active = true;
|
|
6342
6362
|
const controller = typeof AbortController === "undefined" ? void 0 : new AbortController();
|
|
6343
6363
|
Promise.all(sourceEntries.map(async ({ field, source }) => {
|
|
6344
|
-
const
|
|
6345
|
-
if (!
|
|
6364
|
+
const entry = dataSources.get(source.key);
|
|
6365
|
+
if (!entry) return [field, []];
|
|
6346
6366
|
try {
|
|
6347
|
-
return [field, normalizeOptions(await
|
|
6367
|
+
return [field, normalizeOptions(await entry.load({
|
|
6348
6368
|
field,
|
|
6349
6369
|
values: {},
|
|
6350
6370
|
signal: controller?.signal
|
|
@@ -6578,7 +6598,7 @@ function renderFieldValue(value, type, booleanLocale, options) {
|
|
|
6578
6598
|
/**
|
|
6579
6599
|
* ViewModal 组件 - 详情查看弹窗
|
|
6580
6600
|
*/
|
|
6581
|
-
function ViewModal({ open, onOpenChange, variant, data, schema, fields: fieldConfig, denyFields, locale }) {
|
|
6601
|
+
function ViewModal({ open, onOpenChange, variant, data, schema, fields: fieldConfig, dynamicOptions, denyFields, locale }) {
|
|
6582
6602
|
if (!data) return null;
|
|
6583
6603
|
const shape = schema.shape;
|
|
6584
6604
|
const denySet = new Set(denyFields ?? []);
|
|
@@ -6591,7 +6611,7 @@ function ViewModal({ open, onOpenChange, variant, data, schema, fields: fieldCon
|
|
|
6591
6611
|
const parsed = parseZodField(fieldSchema);
|
|
6592
6612
|
const label = fieldConfig?.[key]?.label ?? humanize(key);
|
|
6593
6613
|
const value = data[key];
|
|
6594
|
-
const options = normalizeFieldOptions(fieldConfig?.[key]?.enum);
|
|
6614
|
+
const options = normalizeFieldOptions(fieldConfig?.[key]?.enum) ?? normalizeFieldOptions(dynamicOptions?.[key]);
|
|
6595
6615
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
6596
6616
|
className: "grid grid-cols-3 items-start gap-4",
|
|
6597
6617
|
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("dt", {
|
|
@@ -6613,6 +6633,7 @@ function ViewModal({ open, onOpenChange, variant, data, schema, fields: fieldCon
|
|
|
6613
6633
|
open,
|
|
6614
6634
|
onOpenChange,
|
|
6615
6635
|
children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(__pixpilot_shadcn.DialogContent, {
|
|
6636
|
+
"aria-describedby": void 0,
|
|
6616
6637
|
className: "max-w-2xl max-h-[80vh] overflow-y-auto",
|
|
6617
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]
|
|
6618
6639
|
})
|
|
@@ -6917,6 +6938,7 @@ function AutoCrudTable({ title, description, schema, resource, fields, table: ta
|
|
|
6917
6938
|
data: resource.modal.selected,
|
|
6918
6939
|
schema: resolvedSchema,
|
|
6919
6940
|
fields: resolvedFields,
|
|
6941
|
+
dynamicOptions: dynamicFilterOptions,
|
|
6920
6942
|
denyFields,
|
|
6921
6943
|
locale
|
|
6922
6944
|
}),
|
|
@@ -7560,13 +7582,6 @@ function DataTableToolbarFilter({ column }) {
|
|
|
7560
7582
|
}
|
|
7561
7583
|
}
|
|
7562
7584
|
|
|
7563
|
-
//#endregion
|
|
7564
|
-
//#region ../../node_modules/.pnpm/@tanstack+query-core@5.90.20/node_modules/@tanstack/query-core/build/modern/utils.js
|
|
7565
|
-
var isServer = typeof window === "undefined" || "Deno" in globalThis;
|
|
7566
|
-
function keepPreviousData(previousData) {
|
|
7567
|
-
return previousData;
|
|
7568
|
-
}
|
|
7569
|
-
|
|
7570
7585
|
//#endregion
|
|
7571
7586
|
//#region src/hooks/use-auto-crud-resource.ts
|
|
7572
7587
|
/** 默认 toast 适配器(使用 sonner) */
|
|
@@ -7716,7 +7731,7 @@ function useAutoCrudResource({ router, schema, query: queryTransform, options =
|
|
|
7716
7731
|
queryTransform
|
|
7717
7732
|
]);
|
|
7718
7733
|
const listQuery = router.list.useQuery(queryInput, {
|
|
7719
|
-
placeholderData: keepPreviousData,
|
|
7734
|
+
placeholderData: __tanstack_react_query.keepPreviousData,
|
|
7720
7735
|
staleTime: 0
|
|
7721
7736
|
});
|
|
7722
7737
|
const tableRows = listQuery.data?.data ?? [];
|
|
@@ -8329,6 +8344,7 @@ exports.MultiCombobox = MultiCombobox;
|
|
|
8329
8344
|
exports.SchemaAdapter = SchemaAdapter;
|
|
8330
8345
|
exports.cn = cn;
|
|
8331
8346
|
exports.coerceRowValues = coerceRowValues;
|
|
8347
|
+
exports.components = components;
|
|
8332
8348
|
exports.createActionsColumn = createActionsColumn;
|
|
8333
8349
|
exports.createEditFormSchema = createEditFormSchema;
|
|
8334
8350
|
exports.createFormSchema = createFormSchema;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as react_jsx_runtime3 from "react/jsx-runtime";
|
|
2
2
|
import { z } from "zod";
|
|
3
3
|
import * as _tanstack_react_table0 from "@tanstack/react-table";
|
|
4
4
|
import { Column, ColumnDef, ColumnSort, Row, RowData, Table, TableOptions, TableState } from "@tanstack/react-table";
|
|
@@ -24,7 +24,7 @@ declare const noopToastAdapter: ToastAdapter;
|
|
|
24
24
|
/**
|
|
25
25
|
* Modal 状态类型
|
|
26
26
|
*/
|
|
27
|
-
type ModalVariant$1 =
|
|
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:
|
|
69
|
+
onSuccess?: (op: 'create' | 'update' | 'delete', payload: unknown) => void;
|
|
70
70
|
/** 操作失败回调 */
|
|
71
|
-
onError?: (op:
|
|
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:
|
|
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>):
|
|
365
|
+
}: AutoTableActionBarProps<TData>): react_jsx_runtime3.JSX.Element;
|
|
366
366
|
//#endregion
|
|
367
367
|
//#region src/lib/schema-bridge/types.d.ts
|
|
368
368
|
/**
|
|
369
369
|
* 字段类型映射
|
|
370
370
|
*/
|
|
371
|
-
type FieldType =
|
|
371
|
+
type FieldType = 'string' | 'number' | 'boolean' | 'date' | 'enum' | 'array' | 'object';
|
|
372
372
|
/**
|
|
373
373
|
* DataTable Filter Variant
|
|
374
374
|
*/
|
|
375
|
-
type FilterVariant =
|
|
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?:
|
|
411
|
+
layout?: 'vertical' | 'horizontal' | 'grid';
|
|
412
412
|
gridColumns?: number;
|
|
413
413
|
/** Label 对齐方式 */
|
|
414
|
-
labelAlign?:
|
|
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?:
|
|
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>):
|
|
533
|
+
}: AutoTableProps<T>): react_jsx_runtime3.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
|
-
|
|
651
|
-
|
|
652
|
-
|
|
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
|
|
663
|
-
register(name: string, value:
|
|
668
|
+
declare const components: {
|
|
669
|
+
register(name: string, value: AutoCrudFormComponentConfig): void;
|
|
664
670
|
unregister(name: string): void;
|
|
665
|
-
get(name: string):
|
|
666
|
-
all(): Record<string,
|
|
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>):
|
|
949
|
+
}: AutoCrudTableProps<TSchema>): react_jsx_runtime3.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>):
|
|
981
|
+
}: AutoFormProps<T>, ref: React.Ref<AutoFormRef>): react_jsx_runtime3.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
|
|
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<
|
|
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[
|
|
1245
|
-
type FilterVariant$1 = DataTableConfig[
|
|
1246
|
-
type JoinOperator = DataTableConfig[
|
|
1247
|
-
interface ExtendedColumnSort<TData> extends Omit<ColumnSort,
|
|
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:
|
|
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>):
|
|
1283
|
+
}: AutoTableSimpleFiltersProps<TData>): react_jsx_runtime3.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>):
|
|
1325
|
+
}: CrudFormModalProps<T>): react_jsx_runtime3.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):
|
|
1347
|
+
}: ImportDialogProps): react_jsx_runtime3.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):
|
|
1367
|
+
}: ExportDialogProps): react_jsx_runtime3.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>):
|
|
1380
|
+
}: DataTableProps<TData>): react_jsx_runtime3.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>):
|
|
1391
|
+
}: DataTableAdvancedToolbarProps<TData>): react_jsx_runtime3.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>):
|
|
1403
|
+
}: DataTableColumnHeaderProps<TData, TValue>): react_jsx_runtime3.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>):
|
|
1417
|
+
}: DataTableFacetedFilterProps<TData, TValue>): react_jsx_runtime3.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>):
|
|
1429
|
+
}: DataTablePaginationProps<TData>): react_jsx_runtime3.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>):
|
|
1440
|
+
}: DataTableToolbarProps<TData>): react_jsx_runtime3.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>):
|
|
1451
|
+
}: DataTableViewOptionsProps<TData>): react_jsx_runtime3.JSX.Element;
|
|
1441
1452
|
//#endregion
|
|
1442
1453
|
//#region src/components/ui/multi-combobox.d.ts
|
|
1443
1454
|
interface MultiComboboxOption {
|
|
@@ -1523,7 +1534,7 @@ declare function createFormSchema<T extends z.ZodObject<z.ZodRawShape>>(schema:
|
|
|
1523
1534
|
/**
|
|
1524
1535
|
* 为编辑模式创建 Form Schema(排除 id, createdAt, updatedAt)
|
|
1525
1536
|
*/
|
|
1526
|
-
declare function createEditFormSchema<T extends z.ZodObject<z.ZodRawShape>>(schema: T, options?: Omit<CreateFormSchemaOptions,
|
|
1537
|
+
declare function createEditFormSchema<T extends z.ZodObject<z.ZodRawShape>>(schema: T, options?: Omit<CreateFormSchemaOptions, 'exclude'>): ISchema;
|
|
1527
1538
|
//#endregion
|
|
1528
1539
|
//#region src/lib/schema-bridge/schema-adapter.d.ts
|
|
1529
1540
|
/**
|
|
@@ -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
|
|
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 =
|
|
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:
|
|
69
|
+
onSuccess?: (op: 'create' | 'update' | 'delete', payload: unknown) => void;
|
|
70
70
|
/** 操作失败回调 */
|
|
71
|
-
onError?: (op:
|
|
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:
|
|
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>):
|
|
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 =
|
|
371
|
+
type FieldType = 'string' | 'number' | 'boolean' | 'date' | 'enum' | 'array' | 'object';
|
|
372
372
|
/**
|
|
373
373
|
* DataTable Filter Variant
|
|
374
374
|
*/
|
|
375
|
-
type FilterVariant =
|
|
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?:
|
|
411
|
+
layout?: 'vertical' | 'horizontal' | 'grid';
|
|
412
412
|
gridColumns?: number;
|
|
413
413
|
/** Label 对齐方式 */
|
|
414
|
-
labelAlign?:
|
|
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?:
|
|
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>):
|
|
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
|
-
|
|
651
|
-
|
|
652
|
-
|
|
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
|
|
663
|
-
register(name: string, value:
|
|
668
|
+
declare const components: {
|
|
669
|
+
register(name: string, value: AutoCrudFormComponentConfig): void;
|
|
664
670
|
unregister(name: string): void;
|
|
665
|
-
get(name: string):
|
|
666
|
-
all(): Record<string,
|
|
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>):
|
|
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>):
|
|
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
|
|
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<
|
|
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[
|
|
1245
|
-
type FilterVariant$1 = DataTableConfig[
|
|
1246
|
-
type JoinOperator = DataTableConfig[
|
|
1247
|
-
interface ExtendedColumnSort<TData> extends Omit<ColumnSort,
|
|
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:
|
|
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>):
|
|
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>):
|
|
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):
|
|
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):
|
|
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>):
|
|
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>):
|
|
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>):
|
|
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>):
|
|
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>):
|
|
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>):
|
|
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>):
|
|
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 {
|
|
@@ -1523,7 +1534,7 @@ declare function createFormSchema<T extends z.ZodObject<z.ZodRawShape>>(schema:
|
|
|
1523
1534
|
/**
|
|
1524
1535
|
* 为编辑模式创建 Form Schema(排除 id, createdAt, updatedAt)
|
|
1525
1536
|
*/
|
|
1526
|
-
declare function createEditFormSchema<T extends z.ZodObject<z.ZodRawShape>>(schema: T, options?: Omit<CreateFormSchemaOptions,
|
|
1537
|
+
declare function createEditFormSchema<T extends z.ZodObject<z.ZodRawShape>>(schema: T, options?: Omit<CreateFormSchemaOptions, 'exclude'>): ISchema;
|
|
1527
1538
|
//#endregion
|
|
1528
1539
|
//#region src/lib/schema-bridge/schema-adapter.d.ts
|
|
1529
1540
|
/**
|
|
@@ -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
|
@@ -19,6 +19,7 @@ import { createForm, onFieldValueChange } from "@formily/core";
|
|
|
19
19
|
import { Form, JsonSchemaField } from "@pixpilot/formily-shadcn";
|
|
20
20
|
import { connect, mapProps } from "@formily/react";
|
|
21
21
|
import { toast } from "sonner";
|
|
22
|
+
import { keepPreviousData } from "@tanstack/react-query";
|
|
22
23
|
|
|
23
24
|
//#region src/lib/utils.ts
|
|
24
25
|
function cn(...inputs) {
|
|
@@ -5131,12 +5132,8 @@ function getComponentProps(type, parsed) {
|
|
|
5131
5132
|
function createFormSchema(schema, options) {
|
|
5132
5133
|
const shape = schema.shape;
|
|
5133
5134
|
const properties = {};
|
|
5134
|
-
const { overrides, exclude = [], layout = "vertical", gridColumns = 1
|
|
5135
|
+
const { overrides, exclude = [], layout = "vertical", gridColumns = 1 } = options ?? {};
|
|
5135
5136
|
const decoratorProps = { className: "space-y-2" };
|
|
5136
|
-
if (labelAlign) decoratorProps.labelAlign = labelAlign;
|
|
5137
|
-
if (labelWidth) decoratorProps.labelWidth = labelWidth;
|
|
5138
|
-
if (labelCol) decoratorProps.labelCol = labelCol;
|
|
5139
|
-
if (wrapperCol) decoratorProps.wrapperCol = wrapperCol;
|
|
5140
5137
|
for (const [key, fieldSchema] of Object.entries(shape)) {
|
|
5141
5138
|
if (exclude.includes(key)) continue;
|
|
5142
5139
|
const parsed = parseZodField(fieldSchema);
|
|
@@ -5195,8 +5192,12 @@ function createEditFormSchema(schema, options) {
|
|
|
5195
5192
|
function createRegistry(label) {
|
|
5196
5193
|
const entries = /* @__PURE__ */ new Map();
|
|
5197
5194
|
const listeners = /* @__PURE__ */ new Set();
|
|
5195
|
+
let notifyScheduled = false;
|
|
5198
5196
|
const notify = () => {
|
|
5197
|
+
if (notifyScheduled) return;
|
|
5198
|
+
notifyScheduled = true;
|
|
5199
5199
|
queueMicrotask(() => {
|
|
5200
|
+
notifyScheduled = false;
|
|
5200
5201
|
for (const listener of listeners) listener();
|
|
5201
5202
|
});
|
|
5202
5203
|
};
|
|
@@ -5226,20 +5227,32 @@ function createRegistry(label) {
|
|
|
5226
5227
|
};
|
|
5227
5228
|
}
|
|
5228
5229
|
const formComponents = createRegistry("form component");
|
|
5229
|
-
const
|
|
5230
|
-
function
|
|
5231
|
-
if (typeof
|
|
5232
|
-
|
|
5233
|
-
|
|
5234
|
-
|
|
5235
|
-
}
|
|
5236
|
-
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
|
+
};
|
|
5237
5237
|
return {
|
|
5238
|
-
|
|
5239
|
-
|
|
5240
|
-
|
|
5238
|
+
dependencies: Array.isArray(registration.dependencies) ? registration.dependencies : [],
|
|
5239
|
+
reset: registration.reset === true,
|
|
5240
|
+
load: registration.load
|
|
5241
5241
|
};
|
|
5242
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
|
+
}
|
|
5243
5256
|
function normalizeOptions(result) {
|
|
5244
5257
|
const options = Array.isArray(result) ? result : result?.options;
|
|
5245
5258
|
if (!Array.isArray(options)) return [];
|
|
@@ -5305,9 +5318,7 @@ function useRegistryVersion$1(subscribe) {
|
|
|
5305
5318
|
return version;
|
|
5306
5319
|
}
|
|
5307
5320
|
function isDataSourceConfig(value) {
|
|
5308
|
-
|
|
5309
|
-
if (!value || typeof value !== "object" || Array.isArray(value)) return false;
|
|
5310
|
-
return typeof value.key === "string";
|
|
5321
|
+
return typeof value === "string" && value.length > 0;
|
|
5311
5322
|
}
|
|
5312
5323
|
function collectDataSourceConfigs(schema, result = {}) {
|
|
5313
5324
|
const properties = schema.properties;
|
|
@@ -5337,17 +5348,17 @@ function useFormDataSources(form, schema) {
|
|
|
5337
5348
|
const loadFieldOptions = async (fieldName, source) => {
|
|
5338
5349
|
const version = (loadVersions.get(fieldName) ?? 0) + 1;
|
|
5339
5350
|
loadVersions.set(fieldName, version);
|
|
5340
|
-
const
|
|
5341
|
-
if (!
|
|
5351
|
+
const entry = dataSources.get(source.key);
|
|
5352
|
+
if (!entry) {
|
|
5342
5353
|
form.setFieldState(fieldName, (state) => {
|
|
5343
5354
|
state.dataSource = [];
|
|
5344
5355
|
});
|
|
5345
5356
|
return;
|
|
5346
5357
|
}
|
|
5347
5358
|
try {
|
|
5348
|
-
const options = normalizeOptions(await
|
|
5359
|
+
const options = normalizeOptions(await entry.load({
|
|
5349
5360
|
field: fieldName,
|
|
5350
|
-
values: Object.fromEntries(
|
|
5361
|
+
values: Object.fromEntries(entry.dependencies.map((dependency) => [dependency, form.getValuesIn(dependency)])),
|
|
5351
5362
|
signal: controller?.signal
|
|
5352
5363
|
}));
|
|
5353
5364
|
if (!active || loadVersions.get(fieldName) !== version) return;
|
|
@@ -5364,10 +5375,11 @@ function useFormDataSources(form, schema) {
|
|
|
5364
5375
|
};
|
|
5365
5376
|
for (const [fieldName, source] of sourceEntries) loadFieldOptions(fieldName, source);
|
|
5366
5377
|
form.addEffects(effectId, () => {
|
|
5367
|
-
for (const dependency of new Set(sourceEntries.flatMap(([, source]) => source.
|
|
5378
|
+
for (const dependency of new Set(sourceEntries.flatMap(([, source]) => dataSources.get(source.key)?.dependencies ?? []))) onFieldValueChange(dependency, () => {
|
|
5368
5379
|
for (const [fieldName, source] of sourceEntries) {
|
|
5369
|
-
|
|
5370
|
-
if (
|
|
5380
|
+
const entry = dataSources.get(source.key);
|
|
5381
|
+
if (!entry?.dependencies.includes(dependency)) continue;
|
|
5382
|
+
if (entry.reset) form.setValuesIn(fieldName, void 0);
|
|
5371
5383
|
loadFieldOptions(fieldName, source);
|
|
5372
5384
|
}
|
|
5373
5385
|
});
|
|
@@ -5388,20 +5400,26 @@ function AutoFormInner({ schema: zodSchema, initialValues, onSubmit, overrides,
|
|
|
5388
5400
|
const formSchema = useMemo(() => createEditFormSchema(zodSchema, {
|
|
5389
5401
|
overrides,
|
|
5390
5402
|
layout: "grid",
|
|
5391
|
-
gridColumns
|
|
5392
|
-
labelAlign,
|
|
5393
|
-
labelWidth
|
|
5403
|
+
gridColumns
|
|
5394
5404
|
}), [
|
|
5395
5405
|
zodSchema,
|
|
5396
5406
|
overrides,
|
|
5397
|
-
gridColumns
|
|
5398
|
-
labelAlign,
|
|
5399
|
-
labelWidth
|
|
5407
|
+
gridColumns
|
|
5400
5408
|
]);
|
|
5409
|
+
const formLayout = useMemo(() => {
|
|
5410
|
+
const inlineLabel = labelAlign === "left" || labelAlign === "right";
|
|
5411
|
+
return {
|
|
5412
|
+
labelPlacement: inlineLabel ? "start" : "top",
|
|
5413
|
+
itemProps: inlineLabel ? { label: {
|
|
5414
|
+
className: labelAlign === "right" ? "text-right" : void 0,
|
|
5415
|
+
style: labelWidth != null ? { width: labelWidth } : void 0
|
|
5416
|
+
} } : void 0
|
|
5417
|
+
};
|
|
5418
|
+
}, [labelAlign, labelWidth]);
|
|
5401
5419
|
const fieldComponents = useMemo(() => ({ fields: {
|
|
5402
5420
|
...defaultFieldComponents,
|
|
5403
|
-
...
|
|
5404
|
-
} }), [useRegistryVersion$1(
|
|
5421
|
+
...components.all()
|
|
5422
|
+
} }), [useRegistryVersion$1(components.subscribe)]);
|
|
5405
5423
|
useFormDataSources(form, formSchema);
|
|
5406
5424
|
const handleSubmit = async () => {
|
|
5407
5425
|
await form.validate();
|
|
@@ -5410,6 +5428,7 @@ function AutoFormInner({ schema: zodSchema, initialValues, onSubmit, overrides,
|
|
|
5410
5428
|
useImperativeHandle(ref, () => ({ submit: handleSubmit }));
|
|
5411
5429
|
return /* @__PURE__ */ jsxs(Form, {
|
|
5412
5430
|
form,
|
|
5431
|
+
layout: formLayout,
|
|
5413
5432
|
children: [/* @__PURE__ */ jsx(JsonSchemaField, {
|
|
5414
5433
|
schema: formSchema,
|
|
5415
5434
|
components: fieldComponents
|
|
@@ -6299,10 +6318,10 @@ function useDynamicFilterOptions(fields) {
|
|
|
6299
6318
|
let active = true;
|
|
6300
6319
|
const controller = typeof AbortController === "undefined" ? void 0 : new AbortController();
|
|
6301
6320
|
Promise.all(sourceEntries.map(async ({ field, source }) => {
|
|
6302
|
-
const
|
|
6303
|
-
if (!
|
|
6321
|
+
const entry = dataSources.get(source.key);
|
|
6322
|
+
if (!entry) return [field, []];
|
|
6304
6323
|
try {
|
|
6305
|
-
return [field, normalizeOptions(await
|
|
6324
|
+
return [field, normalizeOptions(await entry.load({
|
|
6306
6325
|
field,
|
|
6307
6326
|
values: {},
|
|
6308
6327
|
signal: controller?.signal
|
|
@@ -6536,7 +6555,7 @@ function renderFieldValue(value, type, booleanLocale, options) {
|
|
|
6536
6555
|
/**
|
|
6537
6556
|
* ViewModal 组件 - 详情查看弹窗
|
|
6538
6557
|
*/
|
|
6539
|
-
function ViewModal({ open, onOpenChange, variant, data, schema, fields: fieldConfig, denyFields, locale }) {
|
|
6558
|
+
function ViewModal({ open, onOpenChange, variant, data, schema, fields: fieldConfig, dynamicOptions, denyFields, locale }) {
|
|
6540
6559
|
if (!data) return null;
|
|
6541
6560
|
const shape = schema.shape;
|
|
6542
6561
|
const denySet = new Set(denyFields ?? []);
|
|
@@ -6549,7 +6568,7 @@ function ViewModal({ open, onOpenChange, variant, data, schema, fields: fieldCon
|
|
|
6549
6568
|
const parsed = parseZodField(fieldSchema);
|
|
6550
6569
|
const label = fieldConfig?.[key]?.label ?? humanize(key);
|
|
6551
6570
|
const value = data[key];
|
|
6552
|
-
const options = normalizeFieldOptions(fieldConfig?.[key]?.enum);
|
|
6571
|
+
const options = normalizeFieldOptions(fieldConfig?.[key]?.enum) ?? normalizeFieldOptions(dynamicOptions?.[key]);
|
|
6553
6572
|
return /* @__PURE__ */ jsxs("div", {
|
|
6554
6573
|
className: "grid grid-cols-3 items-start gap-4",
|
|
6555
6574
|
children: [/* @__PURE__ */ jsx("dt", {
|
|
@@ -6571,6 +6590,7 @@ function ViewModal({ open, onOpenChange, variant, data, schema, fields: fieldCon
|
|
|
6571
6590
|
open,
|
|
6572
6591
|
onOpenChange,
|
|
6573
6592
|
children: /* @__PURE__ */ jsxs(DialogContent, {
|
|
6593
|
+
"aria-describedby": void 0,
|
|
6574
6594
|
className: "max-w-2xl max-h-[80vh] overflow-y-auto",
|
|
6575
6595
|
children: [/* @__PURE__ */ jsx(DialogHeader, { children: /* @__PURE__ */ jsx(DialogTitle, { children: locale.viewModal.title }) }), content]
|
|
6576
6596
|
})
|
|
@@ -6875,6 +6895,7 @@ function AutoCrudTable({ title, description, schema, resource, fields, table: ta
|
|
|
6875
6895
|
data: resource.modal.selected,
|
|
6876
6896
|
schema: resolvedSchema,
|
|
6877
6897
|
fields: resolvedFields,
|
|
6898
|
+
dynamicOptions: dynamicFilterOptions,
|
|
6878
6899
|
denyFields,
|
|
6879
6900
|
locale
|
|
6880
6901
|
}),
|
|
@@ -7518,13 +7539,6 @@ function DataTableToolbarFilter({ column }) {
|
|
|
7518
7539
|
}
|
|
7519
7540
|
}
|
|
7520
7541
|
|
|
7521
|
-
//#endregion
|
|
7522
|
-
//#region ../../node_modules/.pnpm/@tanstack+query-core@5.90.20/node_modules/@tanstack/query-core/build/modern/utils.js
|
|
7523
|
-
var isServer = typeof window === "undefined" || "Deno" in globalThis;
|
|
7524
|
-
function keepPreviousData(previousData) {
|
|
7525
|
-
return previousData;
|
|
7526
|
-
}
|
|
7527
|
-
|
|
7528
7542
|
//#endregion
|
|
7529
7543
|
//#region src/hooks/use-auto-crud-resource.ts
|
|
7530
7544
|
/** 默认 toast 适配器(使用 sonner) */
|
|
@@ -8268,4 +8282,4 @@ function createMemoryDataSource(initialData = []) {
|
|
|
8268
8282
|
}
|
|
8269
8283
|
|
|
8270
8284
|
//#endregion
|
|
8271
|
-
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.
|
|
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",
|
|
@@ -27,6 +27,7 @@
|
|
|
27
27
|
"access": "public"
|
|
28
28
|
},
|
|
29
29
|
"peerDependencies": {
|
|
30
|
+
"@tanstack/react-query": "^5.0.0",
|
|
30
31
|
"react": "^18.0.0 || ^19.0.0",
|
|
31
32
|
"react-dom": "^18.0.0 || ^19.0.0",
|
|
32
33
|
"sonner": "^2.0.0",
|
|
@@ -71,6 +72,7 @@
|
|
|
71
72
|
},
|
|
72
73
|
"devDependencies": {
|
|
73
74
|
"@tanstack/react-query": "^5.90.15",
|
|
75
|
+
"@testing-library/jest-dom": "^6.9.1",
|
|
74
76
|
"@testing-library/react": "^16.3.2",
|
|
75
77
|
"@trpc/server": "^11.0.0",
|
|
76
78
|
"@types/node": "^22.19.17",
|
|
@@ -78,15 +80,17 @@
|
|
|
78
80
|
"@types/react-dom": "^19.2.3",
|
|
79
81
|
"drizzle-orm": "1.0.0-beta.15-859cf75",
|
|
80
82
|
"eslint": "^9.39.4",
|
|
83
|
+
"jsdom": "^27.4.0",
|
|
81
84
|
"react": "19.2.4",
|
|
82
85
|
"react-dom": "19.2.4",
|
|
83
86
|
"tsdown": "^0.15.12",
|
|
84
87
|
"typescript": "^5.9.3",
|
|
88
|
+
"vitest": "^3.2.4",
|
|
85
89
|
"@internal/eslint-config": "0.3.0",
|
|
86
90
|
"@internal/prettier-config": "0.0.1",
|
|
91
|
+
"@internal/tsconfig": "0.1.0",
|
|
87
92
|
"@internal/tsdown-config": "0.1.0",
|
|
88
|
-
"@internal/vitest-config": "0.1.0"
|
|
89
|
-
"@internal/tsconfig": "0.1.0"
|
|
93
|
+
"@internal/vitest-config": "0.1.0"
|
|
90
94
|
},
|
|
91
95
|
"prettier": "@internal/prettier-config",
|
|
92
96
|
"scripts": {
|