@movk/nuxt 1.8.3 → 2.0.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.en.md +16 -6
- package/README.md +16 -6
- package/dist/module.d.mts +6 -0
- package/dist/module.json +3 -3
- package/dist/module.mjs +15 -22
- package/dist/runtime/components/AutoForm.d.vue.ts +15 -1
- package/dist/runtime/components/AutoForm.vue +48 -50
- package/dist/runtime/components/AutoForm.vue.d.ts +15 -1
- package/dist/runtime/components/DataTable.d.vue.ts +4 -2
- package/dist/runtime/components/DataTable.vue +166 -174
- package/dist/runtime/components/DataTable.vue.d.ts +4 -2
- package/dist/runtime/components/DatePicker.d.vue.ts +6 -5
- package/dist/runtime/components/DatePicker.vue +96 -43
- package/dist/runtime/components/DatePicker.vue.d.ts +6 -5
- package/dist/runtime/components/MessageBox.d.vue.ts +1 -5
- package/dist/runtime/components/MessageBox.vue +9 -7
- package/dist/runtime/components/MessageBox.vue.d.ts +1 -5
- package/dist/runtime/components/SearchForm.d.vue.ts +12 -4
- package/dist/runtime/components/SearchForm.vue +130 -120
- package/dist/runtime/components/SearchForm.vue.d.ts +12 -4
- package/dist/runtime/components/Tree.d.vue.ts +3 -1
- package/dist/runtime/components/Tree.vue +102 -140
- package/dist/runtime/components/Tree.vue.d.ts +3 -1
- package/dist/runtime/components/theme-picker/ThemePicker.vue +5 -3
- package/dist/runtime/components/theme-picker/ThemePickerButton.vue +15 -6
- package/dist/runtime/composables/index.d.ts +1 -0
- package/dist/runtime/composables/index.js +1 -0
- package/dist/runtime/composables/useApiFetch.d.ts +7 -7
- package/dist/runtime/composables/useApiFetch.js +5 -23
- package/dist/runtime/composables/useAutoForm.js +2 -2
- package/dist/runtime/composables/useClientApiFetch.d.ts +5 -5
- package/dist/runtime/composables/useDateFormatter.d.ts +32 -34
- package/dist/runtime/composables/useDateFormatter.js +75 -232
- package/dist/runtime/composables/useDownloadWithProgress.d.ts +11 -8
- package/dist/runtime/composables/useDownloadWithProgress.js +49 -132
- package/dist/runtime/composables/useMessageBox.js +3 -2
- package/dist/runtime/composables/useMovkLocale.d.ts +16 -0
- package/dist/runtime/composables/useMovkLocale.js +20 -0
- package/dist/runtime/composables/useTheme.js +8 -18
- package/dist/runtime/composables/useUploadWithProgress.d.ts +9 -6
- package/dist/runtime/composables/useUploadWithProgress.js +50 -84
- package/dist/runtime/domains/ai/chat-transport.js +1 -0
- package/dist/runtime/domains/api/adapters/xhr.d.ts +17 -0
- package/dist/runtime/domains/api/adapters/xhr.js +55 -0
- package/dist/runtime/domains/api/auth.d.ts +4 -1
- package/dist/runtime/domains/api/auth.js +6 -7
- package/dist/runtime/domains/api/client.d.ts +13 -0
- package/dist/runtime/domains/api/client.js +35 -0
- package/dist/runtime/domains/api/download.d.ts +10 -0
- package/dist/runtime/domains/api/download.js +28 -0
- package/dist/runtime/domains/api/errors.d.ts +20 -2
- package/dist/runtime/domains/api/errors.js +61 -8
- package/dist/runtime/domains/api/fetch-key.d.ts +2 -2
- package/dist/runtime/domains/api/fetch-key.js +4 -4
- package/dist/runtime/domains/api/interceptors/request.d.ts +2 -6
- package/dist/runtime/domains/api/interceptors/request.js +3 -2
- package/dist/runtime/domains/api/interceptors/response.d.ts +8 -14
- package/dist/runtime/domains/api/interceptors/response.js +34 -25
- package/dist/runtime/domains/api/report.d.ts +25 -0
- package/dist/runtime/domains/api/report.js +51 -0
- package/dist/runtime/domains/api/response.d.ts +29 -4
- package/dist/runtime/domains/api/response.js +27 -6
- package/dist/runtime/domains/api/session.d.ts +1 -1
- package/dist/runtime/domains/api/session.js +1 -1
- package/dist/runtime/domains/api/stream.d.ts +2 -1
- package/dist/runtime/domains/api/stream.js +2 -1
- package/dist/runtime/domains/api/toast.d.ts +6 -3
- package/dist/runtime/domains/api/toast.js +7 -7
- package/dist/runtime/domains/auto-form/actions.d.ts +2 -1
- package/dist/runtime/domains/auto-form/actions.js +6 -4
- package/dist/runtime/domains/auto-form/array-ops.d.ts +3 -0
- package/dist/runtime/domains/auto-form/array-ops.js +9 -0
- package/dist/runtime/domains/auto-form/async-items.d.ts +10 -0
- package/dist/runtime/domains/auto-form/async-items.js +42 -0
- package/dist/runtime/domains/auto-form/components/Array.d.vue.ts +0 -4
- package/dist/runtime/domains/auto-form/components/Array.vue +81 -73
- package/dist/runtime/domains/auto-form/components/Array.vue.d.ts +0 -4
- package/dist/runtime/domains/auto-form/components/Children.d.vue.ts +0 -2
- package/dist/runtime/domains/auto-form/components/Children.vue +0 -5
- package/dist/runtime/domains/auto-form/components/Children.vue.d.ts +0 -2
- package/dist/runtime/domains/auto-form/components/Field.d.vue.ts +0 -2
- package/dist/runtime/domains/auto-form/components/Field.vue +9 -2
- package/dist/runtime/domains/auto-form/components/Field.vue.d.ts +0 -2
- package/dist/runtime/domains/auto-form/components/Layout.d.vue.ts +0 -2
- package/dist/runtime/domains/auto-form/components/Layout.vue +3 -6
- package/dist/runtime/domains/auto-form/components/Layout.vue.d.ts +0 -2
- package/dist/runtime/domains/auto-form/components/Nested.d.vue.ts +0 -2
- package/dist/runtime/domains/auto-form/components/Nested.vue +5 -9
- package/dist/runtime/domains/auto-form/components/Nested.vue.d.ts +0 -2
- package/dist/runtime/domains/auto-form/controls.d.ts +5 -572
- package/dist/runtime/domains/auto-form/controls.js +7 -20
- package/dist/runtime/domains/auto-form/fields.d.ts +21 -4
- package/dist/runtime/domains/auto-form/fields.js +52 -40
- package/dist/runtime/domains/auto-form/provider.d.ts +15 -6
- package/dist/runtime/domains/auto-form/provider.js +24 -10
- package/dist/runtime/domains/auto-form/schema.d.ts +9 -4
- package/dist/runtime/domains/auto-form/schema.js +91 -50
- package/dist/runtime/domains/auto-form/search-query.d.ts +10 -0
- package/dist/runtime/domains/auto-form/search-query.js +57 -0
- package/dist/runtime/domains/auto-form/useAutoFormCore.d.ts +62 -0
- package/dist/runtime/domains/auto-form/useAutoFormCore.js +108 -0
- package/dist/runtime/domains/auto-form/useSearchQuerySync.d.ts +11 -0
- package/dist/runtime/domains/auto-form/useSearchQuerySync.js +64 -0
- package/dist/runtime/domains/data-table/columns/constants.d.ts +2 -0
- package/dist/runtime/domains/data-table/columns/constants.js +1 -1
- package/dist/runtime/domains/data-table/columns/resolve-columns.d.ts +2 -1
- package/dist/runtime/domains/data-table/columns/resolve-columns.js +3 -2
- package/dist/runtime/domains/data-table/columns/resolve-data-column.d.ts +7 -2
- package/dist/runtime/domains/data-table/columns/resolve-data-column.js +10 -5
- package/dist/runtime/domains/data-table/columns/resolve-special-columns.js +14 -8
- package/dist/runtime/domains/data-table/components/ColumnSettings.d.vue.ts +20 -0
- package/dist/runtime/domains/data-table/components/ColumnSettings.vue +63 -0
- package/dist/runtime/domains/data-table/components/ColumnSettings.vue.d.ts +20 -0
- package/dist/runtime/domains/data-table/components/Pagination.d.vue.ts +2 -8
- package/dist/runtime/domains/data-table/components/Pagination.vue +34 -36
- package/dist/runtime/domains/data-table/components/Pagination.vue.d.ts +2 -8
- package/dist/runtime/domains/data-table/export.d.ts +23 -0
- package/dist/runtime/domains/data-table/export.js +43 -0
- package/dist/runtime/domains/data-table/load-more.d.ts +8 -0
- package/dist/runtime/domains/data-table/load-more.js +14 -0
- package/dist/runtime/domains/data-table/pagination.d.ts +29 -0
- package/dist/runtime/domains/data-table/pagination.js +42 -0
- package/dist/runtime/domains/data-table/persist.d.ts +12 -0
- package/dist/runtime/domains/data-table/persist.js +41 -0
- package/dist/runtime/domains/data-table/state/keys.d.ts +11 -0
- package/dist/runtime/domains/data-table/state/keys.js +44 -0
- package/dist/runtime/domains/data-table/state/models.d.ts +5 -0
- package/dist/runtime/domains/data-table/state/models.js +38 -0
- package/dist/runtime/domains/data-table/tree-layout.d.ts +13 -0
- package/dist/runtime/domains/data-table/tree-layout.js +30 -0
- package/dist/runtime/domains/theme/theme-color.d.ts +3 -0
- package/dist/runtime/domains/theme/theme-color.js +16 -0
- package/dist/runtime/domains/theme/theme-fouc.d.ts +5 -0
- package/dist/runtime/domains/theme/theme-fouc.js +43 -0
- package/dist/runtime/domains/tree/components/TreeToolbar.d.vue.ts +7 -5
- package/dist/runtime/domains/tree/components/TreeToolbar.vue +6 -4
- package/dist/runtime/domains/tree/components/TreeToolbar.vue.d.ts +7 -5
- package/dist/runtime/domains/tree/tree-disabled.d.ts +5 -0
- package/dist/runtime/domains/tree/tree-disabled.js +15 -0
- package/dist/runtime/domains/tree/tree-lazy.d.ts +8 -0
- package/dist/runtime/domains/tree/tree-lazy.js +19 -1
- package/dist/runtime/domains/tree/tree-search.d.ts +3 -1
- package/dist/runtime/domains/tree/tree-search.js +4 -0
- package/dist/runtime/domains/tree/useTreeLazy.d.ts +22 -0
- package/dist/runtime/domains/tree/useTreeLazy.js +57 -0
- package/dist/runtime/domains/tree/useTreeSearch.d.ts +27 -0
- package/dist/runtime/domains/tree/useTreeSearch.js +59 -0
- package/dist/runtime/domains/tree/useTreeSelection.d.ts +31 -0
- package/dist/runtime/domains/tree/useTreeSelection.js +89 -0
- package/dist/runtime/domains/zod/apply.d.ts +23 -0
- package/dist/runtime/domains/zod/apply.js +26 -0
- package/dist/runtime/domains/zod/error-map.d.ts +13 -0
- package/dist/runtime/domains/zod/error-map.js +19 -0
- package/dist/runtime/domains/zod/locale-map.d.ts +5 -0
- package/dist/runtime/domains/zod/locale-map.js +17 -0
- package/dist/runtime/domains/zod/sync.d.ts +12 -0
- package/dist/runtime/domains/zod/sync.js +30 -0
- package/dist/runtime/locale/en.d.ts +74 -0
- package/dist/runtime/locale/en.js +73 -0
- package/dist/runtime/locale/index.d.ts +8 -0
- package/dist/runtime/locale/index.js +15 -0
- package/dist/runtime/locale/zh_cn.d.ts +74 -0
- package/dist/runtime/locale/zh_cn.js +73 -0
- package/dist/runtime/plugins/api.factory.js +5 -22
- package/dist/runtime/plugins/theme.js +4 -42
- package/dist/runtime/plugins/zod.d.ts +2 -0
- package/dist/runtime/plugins/zod.js +16 -0
- package/dist/runtime/types/api/config.d.ts +12 -0
- package/dist/runtime/types/api/fetch.d.ts +3 -16
- package/dist/runtime/types/api/index.d.ts +1 -1
- package/dist/runtime/types/api/response.d.ts +33 -19
- package/dist/runtime/types/api/stream.d.ts +2 -3
- package/dist/runtime/types/api/transfer.d.ts +3 -7
- package/dist/runtime/types/auto-form/base.d.ts +9 -1
- package/dist/runtime/types/auto-form/component.d.ts +31 -3
- package/dist/runtime/types/auto-form/fields.d.ts +15 -1
- package/dist/runtime/types/auto-form/index.d.ts +3 -3
- package/dist/runtime/types/auto-form/search-form.d.ts +26 -12
- package/dist/runtime/types/auto-form/zod-factory.d.ts +2 -2
- package/dist/runtime/types/components/date-picker.d.ts +14 -3
- package/dist/runtime/types/components/index.d.ts +1 -6
- package/dist/runtime/types/components/message-box.d.ts +5 -18
- package/dist/runtime/types/components/tree.d.ts +17 -14
- package/dist/runtime/types/data-table/columns.d.ts +6 -14
- package/dist/runtime/types/data-table/component.d.ts +42 -1
- package/dist/runtime/types/data-table/index.d.ts +1 -1
- package/dist/runtime/types/data-table/pagination.d.ts +7 -8
- package/dist/runtime/types/index.d.ts +2 -0
- package/dist/runtime/types/locale.d.ts +82 -0
- package/dist/runtime/types/shared.d.ts +13 -0
- package/dist/runtime/types/zod-config.d.ts +38 -0
- package/dist/runtime/types/zod.d.ts +9 -1
- package/dist/runtime/utils/date/convert.d.ts +29 -0
- package/dist/runtime/utils/date/convert.js +93 -0
- package/dist/runtime/utils/date/guards.d.ts +10 -0
- package/dist/runtime/utils/date/guards.js +18 -0
- package/dist/runtime/utils/extend-theme.js +2 -1
- package/dist/runtime/utils/form-control.d.ts +0 -12
- package/dist/runtime/utils/form-control.js +3 -39
- package/dist/runtime/utils/interpolate.d.ts +2 -0
- package/dist/runtime/utils/interpolate.js +4 -0
- package/dist/runtime/utils/theme-defaults.d.ts +10 -0
- package/dist/runtime/utils/theme-defaults.js +9 -0
- package/dist/runtime/utils/tree-selection.d.ts +2 -15
- package/dist/runtime/utils/tv.d.ts +1 -1
- package/dist/runtime/vue/plugins/zod.d.ts +7 -0
- package/dist/runtime/vue/plugins/zod.js +12 -0
- package/dist/shared/{nuxt.DfVF6ZZv.mjs → nuxt.CbmfnBRt.mjs} +82 -236
- package/dist/unplugin.d.mts +3 -2
- package/dist/unplugin.mjs +22 -22
- package/dist/vite.d.mts +1 -0
- package/dist/vite.mjs +2 -1
- package/package.json +39 -34
- package/vue-plugin.d.ts +7 -1
- package/dist/runtime/components/ColorChooser.d.vue.ts +0 -36
- package/dist/runtime/components/ColorChooser.vue +0 -328
- package/dist/runtime/components/ColorChooser.vue.d.ts +0 -36
- package/dist/runtime/components/PillGroup.d.vue.ts +0 -33
- package/dist/runtime/components/PillGroup.vue +0 -291
- package/dist/runtime/components/PillGroup.vue.d.ts +0 -33
- package/dist/runtime/components/Popconfirm.d.vue.ts +0 -30
- package/dist/runtime/components/Popconfirm.vue +0 -143
- package/dist/runtime/components/Popconfirm.vue.d.ts +0 -30
- package/dist/runtime/components/SlideVerify.d.vue.ts +0 -41
- package/dist/runtime/components/SlideVerify.vue +0 -174
- package/dist/runtime/components/SlideVerify.vue.d.ts +0 -41
- package/dist/runtime/components/input/AsPhoneNumberInput.d.vue.ts +0 -32
- package/dist/runtime/components/input/AsPhoneNumberInput.vue +0 -48
- package/dist/runtime/components/input/AsPhoneNumberInput.vue.d.ts +0 -32
- package/dist/runtime/components/input/WithCharacterLimit.d.vue.ts +0 -32
- package/dist/runtime/components/input/WithCharacterLimit.vue +0 -54
- package/dist/runtime/components/input/WithCharacterLimit.vue.d.ts +0 -32
- package/dist/runtime/components/input/WithClear.d.vue.ts +0 -33
- package/dist/runtime/components/input/WithClear.vue +0 -60
- package/dist/runtime/components/input/WithClear.vue.d.ts +0 -33
- package/dist/runtime/components/input/WithCopy.d.vue.ts +0 -33
- package/dist/runtime/components/input/WithCopy.vue +0 -66
- package/dist/runtime/components/input/WithCopy.vue.d.ts +0 -33
- package/dist/runtime/components/input/WithFloatingLabel.d.vue.ts +0 -33
- package/dist/runtime/components/input/WithFloatingLabel.vue +0 -75
- package/dist/runtime/components/input/WithFloatingLabel.vue.d.ts +0 -33
- package/dist/runtime/components/input/WithPasswordToggle.d.vue.ts +0 -32
- package/dist/runtime/components/input/WithPasswordToggle.vue +0 -61
- package/dist/runtime/components/input/WithPasswordToggle.vue.d.ts +0 -32
- package/dist/runtime/domains/api/interceptors/compose.d.ts +0 -24
- package/dist/runtime/domains/api/interceptors/compose.js +0 -18
- package/dist/runtime/domains/api/interceptors/error.d.ts +0 -13
- package/dist/runtime/domains/api/interceptors/error.js +0 -26
- package/dist/runtime/domains/api/interceptors/unauthorized.d.ts +0 -12
- package/dist/runtime/domains/api/interceptors/unauthorized.js +0 -34
- package/dist/runtime/domains/api/transfer.d.ts +0 -69
- package/dist/runtime/domains/api/transfer.js +0 -87
- package/dist/runtime/types/components/color-chooser.d.ts +0 -109
- package/dist/runtime/types/components/input/as-phone-number-input.d.ts +0 -17
- package/dist/runtime/types/components/input/index.d.ts +0 -6
- package/dist/runtime/types/components/input/index.js +0 -0
- package/dist/runtime/types/components/input/with-character-limit.d.ts +0 -11
- package/dist/runtime/types/components/input/with-character-limit.js +0 -0
- package/dist/runtime/types/components/input/with-clear.d.ts +0 -10
- package/dist/runtime/types/components/input/with-clear.js +0 -0
- package/dist/runtime/types/components/input/with-copy.d.ts +0 -11
- package/dist/runtime/types/components/input/with-copy.js +0 -0
- package/dist/runtime/types/components/input/with-floating-label.d.ts +0 -12
- package/dist/runtime/types/components/input/with-floating-label.js +0 -0
- package/dist/runtime/types/components/input/with-password-toggle.d.ts +0 -7
- package/dist/runtime/types/components/input/with-password-toggle.js +0 -0
- package/dist/runtime/types/components/pill-group.d.ts +0 -103
- package/dist/runtime/types/components/pill-group.js +0 -0
- package/dist/runtime/types/components/popconfirm.d.ts +0 -74
- package/dist/runtime/types/components/popconfirm.js +0 -0
- package/dist/runtime/types/components/slide-verify.d.ts +0 -54
- package/dist/runtime/types/components/slide-verify.js +0 -0
- /package/dist/runtime/types/{components/color-chooser.js → locale.js} +0 -0
- /package/dist/runtime/types/{components/input/as-phone-number-input.js → zod-config.js} +0 -0
|
@@ -1,18 +1,10 @@
|
|
|
1
|
-
import
|
|
2
|
-
import WithPasswordToggle from "../../components/input/WithPasswordToggle.vue";
|
|
3
|
-
import WithCopy from "../../components/input/WithCopy.vue";
|
|
4
|
-
import WithCharacterLimit from "../../components/input/WithCharacterLimit.vue";
|
|
5
|
-
import AsPhoneNumberInput from "../../components/input/AsPhoneNumberInput.vue";
|
|
6
|
-
import WithFloatingLabel from "../../components/input/WithFloatingLabel.vue";
|
|
7
|
-
import DatePicker from "../../components/DatePicker.vue";
|
|
8
|
-
import ColorChooser from "../../components/ColorChooser.vue";
|
|
9
|
-
import SlideVerify from "../../components/SlideVerify.vue";
|
|
10
|
-
import PillGroup from "../../components/PillGroup.vue";
|
|
1
|
+
import { defineAsyncComponent } from "vue";
|
|
11
2
|
import {
|
|
12
3
|
UInput,
|
|
13
4
|
UInputNumber,
|
|
14
5
|
UCheckbox,
|
|
15
6
|
USwitch,
|
|
7
|
+
UToggle,
|
|
16
8
|
UTextarea,
|
|
17
9
|
USlider,
|
|
18
10
|
UPinInput,
|
|
@@ -23,11 +15,13 @@ import {
|
|
|
23
15
|
UInputMenu,
|
|
24
16
|
UCheckboxGroup,
|
|
25
17
|
URadioGroup,
|
|
18
|
+
UToggleGroup,
|
|
26
19
|
UInputDate,
|
|
27
20
|
UInputTime,
|
|
28
21
|
UListbox
|
|
29
22
|
} from "#components";
|
|
30
23
|
const DEFAULT_CONTROL_PROPS = { class: "w-full" };
|
|
24
|
+
const DatePicker = defineAsyncComponent(() => import("../../components/DatePicker.vue"));
|
|
31
25
|
export function defineControl(e) {
|
|
32
26
|
return e;
|
|
33
27
|
}
|
|
@@ -49,24 +43,17 @@ const DEFAULT_CONTROL_COMPONENTS = {
|
|
|
49
43
|
calendarDate: DatePicker,
|
|
50
44
|
inputDate: UInputDate,
|
|
51
45
|
inputTime: UInputTime,
|
|
52
|
-
withClear: WithClear,
|
|
53
|
-
withPasswordToggle: WithPasswordToggle,
|
|
54
|
-
withCopy: WithCopy,
|
|
55
|
-
withCharacterLimit: WithCharacterLimit,
|
|
56
|
-
withFloatingLabel: WithFloatingLabel,
|
|
57
|
-
asPhoneNumberInput: AsPhoneNumberInput,
|
|
58
46
|
textarea: UTextarea,
|
|
59
47
|
switch: USwitch,
|
|
48
|
+
toggle: UToggle,
|
|
60
49
|
slider: USlider,
|
|
61
50
|
selectMenu: USelectMenu,
|
|
62
51
|
inputMenu: UInputMenu,
|
|
63
52
|
checkboxGroup: UCheckboxGroup,
|
|
64
53
|
radioGroup: URadioGroup,
|
|
54
|
+
toggleGroup: UToggleGroup,
|
|
65
55
|
inputTags: UInputTags,
|
|
66
56
|
pinInput: UPinInput,
|
|
67
|
-
listbox: UListbox
|
|
68
|
-
colorChooser: ColorChooser,
|
|
69
|
-
slideVerify: SlideVerify,
|
|
70
|
-
pillGroup: PillGroup
|
|
57
|
+
listbox: UListbox
|
|
71
58
|
};
|
|
72
59
|
export const DEFAULT_CONTROLS = createControlMap(DEFAULT_CONTROL_COMPONENTS);
|
|
@@ -11,10 +11,27 @@ export declare function classifyFields(fields: AutoFormField[]): {
|
|
|
11
11
|
hasComplexFields: boolean;
|
|
12
12
|
};
|
|
13
13
|
export declare function isLeafField(field: AutoFormField): boolean;
|
|
14
|
-
|
|
14
|
+
/** 按路径段把字段树中以 `from` 开头的路径替换为 `to`,递归处理 children 与 arrayElement,不修改原字段 */
|
|
15
|
+
export declare function remapFieldPath(field: AutoFormField, from: string, to: string): AutoFormField;
|
|
15
16
|
/** 递归收集字段的默认值,object 类型返回嵌套结构,叶子类型直接返回值 */
|
|
16
|
-
export declare function collectFieldDefaults(field: AutoFormField):
|
|
17
|
+
export declare function collectFieldDefaults(field: AutoFormField): unknown;
|
|
17
18
|
/** 从 items 选项中提取枚举值,支持对象格式(取 valueKey/value/label)和原始值 */
|
|
18
19
|
export declare function extractEnumValuesFromItems(items: any, valueKey?: string): string[];
|
|
19
|
-
|
|
20
|
-
|
|
20
|
+
export interface ArrayItemActions {
|
|
21
|
+
remove: (index: number) => void;
|
|
22
|
+
/** 提供时渲染上移 / 下移按钮 */
|
|
23
|
+
move?: (index: number, offset: -1 | 1) => void;
|
|
24
|
+
/** 提供时渲染复制按钮 */
|
|
25
|
+
duplicate?: (index: number) => void;
|
|
26
|
+
canRemove: () => boolean;
|
|
27
|
+
canAdd: () => boolean;
|
|
28
|
+
length: () => number;
|
|
29
|
+
labels: {
|
|
30
|
+
moveUp: string;
|
|
31
|
+
moveDown: string;
|
|
32
|
+
duplicate: string;
|
|
33
|
+
remove: string;
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
/** 创建数组项的 hint 插槽渲染函数:项根节点渲染操作按钮(对象项另加折叠图标),嵌套对象只渲染折叠图标 */
|
|
37
|
+
export declare function createHintSlotFactory(actions: ArrayItemActions): (field: AutoFormField, isItemRoot: boolean, open?: boolean, count?: number) => VNode | undefined;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { UButton, UIcon } from "#components";
|
|
2
2
|
import { h } from "vue";
|
|
3
|
-
import { getPath, setPath } from "@movk/core";
|
|
3
|
+
import { getPath, joinPath, setPath, toPath } from "@movk/core";
|
|
4
4
|
import { AUTOFORM_META } from "./constants.js";
|
|
5
5
|
export function applyFieldDefaults(fields, target) {
|
|
6
6
|
if (!fields.length) return;
|
|
@@ -45,26 +45,34 @@ export function classifyFields(fields) {
|
|
|
45
45
|
export function isLeafField(field) {
|
|
46
46
|
return field.meta.type !== "object" && field.meta.type !== "array";
|
|
47
47
|
}
|
|
48
|
-
|
|
49
|
-
|
|
48
|
+
function relativeSegments(path, base) {
|
|
49
|
+
const segments = toPath(path);
|
|
50
|
+
const baseSegments = toPath(base);
|
|
51
|
+
const matches = baseSegments.every((segment, index) => String(segments[index]) === String(segment));
|
|
52
|
+
return matches ? segments.slice(baseSegments.length) : void 0;
|
|
53
|
+
}
|
|
54
|
+
export function remapFieldPath(field, from, to) {
|
|
55
|
+
const rest = relativeSegments(field.path, from);
|
|
56
|
+
const path = rest ? joinPath([...toPath(to), ...rest]) : field.path;
|
|
57
|
+
return {
|
|
58
|
+
...field,
|
|
59
|
+
path,
|
|
60
|
+
...field.children && { children: field.children.map((child) => remapFieldPath(child, from, to)) },
|
|
61
|
+
...field.arrayElement && { arrayElement: remapFieldPath(field.arrayElement, from, to) }
|
|
62
|
+
};
|
|
50
63
|
}
|
|
51
64
|
export function collectFieldDefaults(field) {
|
|
52
|
-
if (field.meta?.type
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
}
|
|
61
|
-
};
|
|
62
|
-
const result = {};
|
|
63
|
-
const basePath = field.path;
|
|
64
|
-
collect(field);
|
|
65
|
-
return result;
|
|
65
|
+
if (field.meta?.type !== "object") return field.decorators?.defaultValue;
|
|
66
|
+
const result = {};
|
|
67
|
+
function collect(currentField) {
|
|
68
|
+
const rest = relativeSegments(currentField.path, field.path);
|
|
69
|
+
if (currentField.decorators?.defaultValue !== void 0 && rest?.length) {
|
|
70
|
+
setPath(result, joinPath(rest), currentField.decorators.defaultValue);
|
|
71
|
+
}
|
|
72
|
+
currentField.children?.forEach(collect);
|
|
66
73
|
}
|
|
67
|
-
|
|
74
|
+
collect(field);
|
|
75
|
+
return result;
|
|
68
76
|
}
|
|
69
77
|
export function extractEnumValuesFromItems(items, valueKey) {
|
|
70
78
|
if (!items || !Array.isArray(items)) {
|
|
@@ -92,36 +100,40 @@ export function extractEnumValuesFromItems(items, valueKey) {
|
|
|
92
100
|
return item;
|
|
93
101
|
}).filter((value) => value !== void 0 && value !== null);
|
|
94
102
|
}
|
|
95
|
-
|
|
96
|
-
return (
|
|
97
|
-
|
|
103
|
+
function itemButton(icon, label, onClick, options = {}) {
|
|
104
|
+
return h(UButton, {
|
|
105
|
+
"icon": icon,
|
|
106
|
+
"color": options.color ?? "neutral",
|
|
107
|
+
"variant": "ghost",
|
|
108
|
+
"size": "xs",
|
|
109
|
+
"aria-label": label,
|
|
110
|
+
"disabled": options.disabled,
|
|
111
|
+
"onClick": (event) => {
|
|
112
|
+
event?.stopPropagation();
|
|
113
|
+
onClick();
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
export function createHintSlotFactory(actions) {
|
|
118
|
+
return (field, isItemRoot, open, count) => {
|
|
98
119
|
const isObject = field.meta?.type === "object";
|
|
99
|
-
if (
|
|
120
|
+
if (!isItemRoot && !isObject) {
|
|
100
121
|
return void 0;
|
|
101
122
|
}
|
|
102
123
|
const chevronIcon = h(UIcon, {
|
|
103
124
|
name: open ? "i-lucide-chevron-down" : "i-lucide-chevron-right",
|
|
104
125
|
class: "shrink-0 size-5 transition-transform duration-200"
|
|
105
126
|
});
|
|
106
|
-
if (
|
|
127
|
+
if (!isItemRoot || count === void 0) {
|
|
107
128
|
return chevronIcon;
|
|
108
129
|
}
|
|
109
|
-
const
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
}
|
|
118
|
-
});
|
|
119
|
-
if (!isObject) {
|
|
120
|
-
return deleteButton;
|
|
121
|
-
}
|
|
122
|
-
return h("div", { class: "flex items-center gap-1.5" }, [
|
|
123
|
-
deleteButton,
|
|
124
|
-
chevronIcon
|
|
125
|
-
]);
|
|
130
|
+
const { labels, move, duplicate } = actions;
|
|
131
|
+
const buttons = [
|
|
132
|
+
move && itemButton("i-lucide-arrow-up", labels.moveUp, () => move(count, -1), { disabled: count === 0 }),
|
|
133
|
+
move && itemButton("i-lucide-arrow-down", labels.moveDown, () => move(count, 1), { disabled: count >= actions.length() - 1 }),
|
|
134
|
+
duplicate && itemButton("i-lucide-copy", labels.duplicate, () => duplicate(count), { disabled: !actions.canAdd() }),
|
|
135
|
+
itemButton("i-lucide-trash-2", labels.remove, () => actions.remove(count), { color: "error", disabled: !actions.canRemove() })
|
|
136
|
+
].filter((node) => !!node);
|
|
137
|
+
return h("div", { class: "flex items-center gap-0.5" }, isObject ? [...buttons, chevronIcon] : buttons);
|
|
126
138
|
};
|
|
127
139
|
}
|
|
@@ -1,10 +1,17 @@
|
|
|
1
|
-
import type { Ref } from 'vue';
|
|
1
|
+
import type { MaybeRefOrGetter, Ref } from 'vue';
|
|
2
2
|
import type { ReactiveValue } from '@movk/core';
|
|
3
|
+
import type { ButtonProps } from '@nuxt/ui';
|
|
3
4
|
import type { AutoFormField, AutoFormMergeMeta, ResolvedAutoFormFieldContext } from '../../types/auto-form';
|
|
4
5
|
type _ResolveReactive<T> = T extends ReactiveValue<infer V, any> ? V : T;
|
|
5
6
|
type ResolvedMetaValue<K extends keyof AutoFormMergeMeta> = _ResolveReactive<NonNullable<AutoFormMergeMeta[K]>>;
|
|
6
7
|
/** 初始化表单上下文工厂并通过 provide 注入给所有子渲染器 */
|
|
7
|
-
export
|
|
8
|
+
export interface AutoFormProviderOptions {
|
|
9
|
+
/** 数组字段添加按钮属性 */
|
|
10
|
+
addButtonProps?: () => ButtonProps | undefined;
|
|
11
|
+
}
|
|
12
|
+
export declare function useAutoFormProvider(state: Ref<any>, slots: Record<string, any>, options?: AutoFormProviderOptions): {
|
|
13
|
+
addButtonProps: import("vue").ComputedRef<ButtonProps | undefined>;
|
|
14
|
+
isFieldVisible: (field: AutoFormField) => boolean;
|
|
8
15
|
createFieldContext: (field: AutoFormField, extraProps?: Record<string, any>) => ResolvedAutoFormFieldContext;
|
|
9
16
|
createSlotProps: (field: AutoFormField, extraProps?: Record<string, any>) => ResolvedAutoFormFieldContext;
|
|
10
17
|
resolveFieldProp: {
|
|
@@ -13,7 +20,7 @@ export declare function useAutoFormProvider(state: Ref<any>, slots: Record<strin
|
|
|
13
20
|
};
|
|
14
21
|
renderFieldSlot: (fn?: (props?: any) => any, slotProps?: any) => any;
|
|
15
22
|
getResolvedFieldSlots: (field: AutoFormField, extraProps?: Record<string, any>) => Record<string, ((props?: any) => any) | undefined> | undefined;
|
|
16
|
-
renderControl: (field: AutoFormField, extraProps?: Record<string, any>) => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
|
|
23
|
+
renderControl: (field: AutoFormField, extraProps?: Record<string, any>, overrides?: Record<string, unknown>) => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
|
|
17
24
|
[key: string]: any;
|
|
18
25
|
}> | null;
|
|
19
26
|
createSlotResolver: (field: AutoFormField, extraProps?: Record<string, any>) => {
|
|
@@ -24,7 +31,7 @@ export declare function useAutoFormProvider(state: Ref<any>, slots: Record<strin
|
|
|
24
31
|
hasSlot(name: string): boolean;
|
|
25
32
|
renderSlot(name: string, slotProps: any): any;
|
|
26
33
|
}>, extraProps?: Record<string, any>) => Record<string, any>;
|
|
27
|
-
createCollapsibleEnhancer: (
|
|
34
|
+
createCollapsibleEnhancer: (fieldSource: MaybeRefOrGetter<AutoFormField>, extraPropsSource?: MaybeRefOrGetter<Record<string, any> | undefined>) => {
|
|
28
35
|
collapsibleConfig: import("vue").ComputedRef<import("../../types").AutoFormNestedCollapsible | undefined>;
|
|
29
36
|
shouldShowCollapsible: import("vue").ComputedRef<boolean>;
|
|
30
37
|
isHidden: import("vue").ComputedRef<boolean | undefined>;
|
|
@@ -33,6 +40,8 @@ export declare function useAutoFormProvider(state: Ref<any>, slots: Record<strin
|
|
|
33
40
|
};
|
|
34
41
|
/** 注入表单上下文,必须在 AutoForm 子渲染器中调用 */
|
|
35
42
|
export declare function useAutoFormInjector(): {
|
|
43
|
+
addButtonProps: import("vue").ComputedRef<ButtonProps | undefined>;
|
|
44
|
+
isFieldVisible: (field: AutoFormField) => boolean;
|
|
36
45
|
createFieldContext: (field: AutoFormField, extraProps?: Record<string, any>) => ResolvedAutoFormFieldContext;
|
|
37
46
|
createSlotProps: (field: AutoFormField, extraProps?: Record<string, any>) => ResolvedAutoFormFieldContext;
|
|
38
47
|
resolveFieldProp: {
|
|
@@ -41,7 +50,7 @@ export declare function useAutoFormInjector(): {
|
|
|
41
50
|
};
|
|
42
51
|
renderFieldSlot: (fn?: (props?: any) => any, slotProps?: any) => any;
|
|
43
52
|
getResolvedFieldSlots: (field: AutoFormField, extraProps?: Record<string, any>) => Record<string, ((props?: any) => any) | undefined> | undefined;
|
|
44
|
-
renderControl: (field: AutoFormField, extraProps?: Record<string, any>) => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
|
|
53
|
+
renderControl: (field: AutoFormField, extraProps?: Record<string, any>, overrides?: Record<string, unknown>) => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
|
|
45
54
|
[key: string]: any;
|
|
46
55
|
}> | null;
|
|
47
56
|
createSlotResolver: (field: AutoFormField, extraProps?: Record<string, any>) => {
|
|
@@ -52,7 +61,7 @@ export declare function useAutoFormInjector(): {
|
|
|
52
61
|
hasSlot(name: string): boolean;
|
|
53
62
|
renderSlot(name: string, slotProps: any): any;
|
|
54
63
|
}>, extraProps?: Record<string, any>) => Record<string, any>;
|
|
55
|
-
createCollapsibleEnhancer: (
|
|
64
|
+
createCollapsibleEnhancer: (fieldSource: MaybeRefOrGetter<AutoFormField>, extraPropsSource?: MaybeRefOrGetter<Record<string, any> | undefined>) => {
|
|
56
65
|
collapsibleConfig: import("vue").ComputedRef<import("../../types").AutoFormNestedCollapsible | undefined>;
|
|
57
66
|
shouldShowCollapsible: import("vue").ComputedRef<boolean>;
|
|
58
67
|
isHidden: import("vue").ComputedRef<boolean | undefined>;
|
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
import { UIcon } from "#components";
|
|
2
|
-
import
|
|
3
|
-
import { computed, h, inject, isVNode, provide, resolveDynamicComponent, unref } from "vue";
|
|
2
|
+
import { createDefu } from "defu";
|
|
3
|
+
import { computed, h, inject, isVNode, provide, resolveDynamicComponent, toValue, unref } from "vue";
|
|
4
4
|
import { getPath, setPath } from "@movk/core";
|
|
5
5
|
import { enhanceEventProps, resolveReactiveValue } from "./reactive.js";
|
|
6
6
|
const AUTO_FORM_CONTEXT_KEY = Symbol("AUTO_FORM_CONTEXT_KEY");
|
|
7
|
-
|
|
7
|
+
const defu = createDefu((obj, key, value) => {
|
|
8
|
+
if (Array.isArray(obj[key]) || Array.isArray(value)) {
|
|
9
|
+
obj[key] = value;
|
|
10
|
+
return true;
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
export function useAutoFormProvider(state, slots, options = {}) {
|
|
8
14
|
function createFieldContext(field, extraProps) {
|
|
9
15
|
const path = field.path;
|
|
10
16
|
const context = {
|
|
@@ -15,8 +21,9 @@ export function useAutoFormProvider(state, slots) {
|
|
|
15
21
|
get value() {
|
|
16
22
|
return getPath(state.value, path);
|
|
17
23
|
},
|
|
18
|
-
setValue: (
|
|
19
|
-
|
|
24
|
+
setValue: (...args) => {
|
|
25
|
+
const [pathOrValue, value] = args;
|
|
26
|
+
if (args.length === 1) {
|
|
20
27
|
const nextValue = typeof pathOrValue === "function" ? pathOrValue(getPath(state.value, path)) : pathOrValue;
|
|
21
28
|
setPath(state.value, path, nextValue);
|
|
22
29
|
} else {
|
|
@@ -57,6 +64,9 @@ export function useAutoFormProvider(state, slots) {
|
|
|
57
64
|
const result = resolveReactiveValue(value, context);
|
|
58
65
|
return result ?? defaultValue;
|
|
59
66
|
}
|
|
67
|
+
function isFieldVisible(field) {
|
|
68
|
+
return field.meta?.if === void 0 || resolveFieldProp(field, "if") === true;
|
|
69
|
+
}
|
|
60
70
|
function renderFieldSlot(fn, slotProps) {
|
|
61
71
|
return fn ? fn(slotProps) : null;
|
|
62
72
|
}
|
|
@@ -65,13 +75,13 @@ export function useAutoFormProvider(state, slots) {
|
|
|
65
75
|
return void 0;
|
|
66
76
|
return resolveFieldProp(field, "fieldSlots", void 0, extraProps);
|
|
67
77
|
}
|
|
68
|
-
function renderControl(field, extraProps) {
|
|
78
|
+
function renderControl(field, extraProps, overrides) {
|
|
69
79
|
const controlMeta = field?.meta;
|
|
70
80
|
const comp = controlMeta?.component;
|
|
71
81
|
if (field.meta.type === "object" || field.meta.type === "array")
|
|
72
82
|
return null;
|
|
73
83
|
if (!comp) {
|
|
74
|
-
return h("div", { class: "text-red-500" }, `[AutoForm]
|
|
84
|
+
return h("div", { class: "text-red-500" }, `[AutoForm] No control mapped for "${field?.path ?? ""}" (type: ${field?.meta?.type ?? "unknown"})`);
|
|
75
85
|
}
|
|
76
86
|
if (isVNode(comp))
|
|
77
87
|
return comp;
|
|
@@ -81,6 +91,7 @@ export function useAutoFormProvider(state, slots) {
|
|
|
81
91
|
const isReadonly = field.decorators?.isReadonly;
|
|
82
92
|
const resolvedSize = resolveFieldProp(field, "size", void 0, extraProps);
|
|
83
93
|
const finalProps = defu(
|
|
94
|
+
overrides ?? {},
|
|
84
95
|
resolvedControlProps,
|
|
85
96
|
isReadonly ? { disabled: true } : {},
|
|
86
97
|
controlMeta?.mapped?.controlProps || {},
|
|
@@ -164,14 +175,15 @@ export function useAutoFormProvider(state, slots) {
|
|
|
164
175
|
}
|
|
165
176
|
return slots2;
|
|
166
177
|
}
|
|
167
|
-
function createCollapsibleEnhancer(
|
|
168
|
-
const collapsibleConfig = computed(() => resolveFieldProp(
|
|
178
|
+
function createCollapsibleEnhancer(fieldSource, extraPropsSource) {
|
|
179
|
+
const collapsibleConfig = computed(() => resolveFieldProp(toValue(fieldSource), "collapsible", void 0, toValue(extraPropsSource)));
|
|
169
180
|
const shouldShowCollapsible = computed(() => {
|
|
170
181
|
const config = collapsibleConfig.value;
|
|
171
182
|
return !config || config.enabled !== false;
|
|
172
183
|
});
|
|
173
|
-
const isHidden = computed(() => resolveFieldProp(
|
|
184
|
+
const isHidden = computed(() => resolveFieldProp(toValue(fieldSource), "hidden", void 0, toValue(extraPropsSource)));
|
|
174
185
|
const enhancedField = computed(() => {
|
|
186
|
+
const field = toValue(fieldSource);
|
|
175
187
|
if (!shouldShowCollapsible.value || field.meta.hint !== void 0) {
|
|
176
188
|
return field;
|
|
177
189
|
}
|
|
@@ -194,6 +206,8 @@ export function useAutoFormProvider(state, slots) {
|
|
|
194
206
|
};
|
|
195
207
|
}
|
|
196
208
|
const contextFactory = {
|
|
209
|
+
addButtonProps: computed(() => options.addButtonProps?.()),
|
|
210
|
+
isFieldVisible,
|
|
197
211
|
createFieldContext,
|
|
198
212
|
createSlotProps,
|
|
199
213
|
resolveFieldProp,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { z } from 'zod';
|
|
2
2
|
import type { AutoFormControls, AutoFormField } from '../../types/auto-form';
|
|
3
3
|
import type { ZodAutoFormFieldMeta } from '../../types/zod';
|
|
4
4
|
/** 将 Zod schema 递归解析为 AutoFormField 列表(schema 遍历的核心入口) */
|
|
@@ -6,7 +6,12 @@ export declare function introspectSchema(schema: z.ZodType, mapping: AutoFormCon
|
|
|
6
6
|
/** 将含布局标记的 schema 还原为纯字段 schema,用于 Zod 表单校验 */
|
|
7
7
|
export declare function extractPureSchema<T extends z.ZodObject<any, any>>(schema: T): z.ZodObject<any, any>;
|
|
8
8
|
/**
|
|
9
|
-
* 从校验 schema
|
|
10
|
-
* 用于让 meta.if
|
|
9
|
+
* 从校验 schema 中剔除指定路径(支持嵌套,如 `profile.phone`),
|
|
10
|
+
* 用于让 meta.if 隐藏的字段不参与校验。refinement 保留,并以完整数据执行。
|
|
11
11
|
*/
|
|
12
|
-
export declare function
|
|
12
|
+
export declare function omitPaths<T extends z.ZodType>(schema: T, paths: string[]): T;
|
|
13
|
+
/** 读取数组 schema 上的 `.min()` / `.max()` / `.length()` 约束 */
|
|
14
|
+
export declare function getArrayLengthBounds(schema: z.ZodType): {
|
|
15
|
+
min: number;
|
|
16
|
+
max: number;
|
|
17
|
+
};
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { markRaw, toRaw } from "vue";
|
|
3
3
|
import { joinPath, startCase, toPath, isFunction, isObject } from "@movk/core";
|
|
4
4
|
import { getAutoFormMetadata } from "./metadata.js";
|
|
5
|
+
import { DEFAULT_CONTROLS } from "./controls.js";
|
|
5
6
|
import { AUTOFORM_LIMITS, AUTOFORM_META } from "./constants.js";
|
|
6
7
|
function getUnwrappedSchema(schema) {
|
|
7
8
|
const def = schema?.def || schema?._def;
|
|
@@ -70,14 +71,6 @@ function selectComponent(mergedMeta, finalType, mapping) {
|
|
|
70
71
|
}
|
|
71
72
|
return { chosenComponent, mapped };
|
|
72
73
|
}
|
|
73
|
-
function createField(path, coreSchema, decorators, mergedMeta) {
|
|
74
|
-
return {
|
|
75
|
-
path,
|
|
76
|
-
schema: coreSchema,
|
|
77
|
-
decorators,
|
|
78
|
-
meta: mergedMeta
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
74
|
function extractEnumValues(schema) {
|
|
82
75
|
if (schema.enum && typeof schema.enum === "object") {
|
|
83
76
|
return Object.values(schema.enum);
|
|
@@ -94,7 +87,7 @@ function handleArrayField(params) {
|
|
|
94
87
|
if (!elementSchema) {
|
|
95
88
|
return [];
|
|
96
89
|
}
|
|
97
|
-
const field =
|
|
90
|
+
const field = { path, schema, decorators, meta: { ...meta, type: "array" } };
|
|
98
91
|
const [arrayElement] = introspectSchema(elementSchema, mapping, path, globalMeta);
|
|
99
92
|
if (arrayElement) {
|
|
100
93
|
field.arrayElement = arrayElement;
|
|
@@ -116,7 +109,7 @@ function handleObjectField(params) {
|
|
|
116
109
|
(key) => introspectSchema(shape[key], mapping, key, globalMeta)
|
|
117
110
|
);
|
|
118
111
|
}
|
|
119
|
-
const field =
|
|
112
|
+
const field = { path, schema, decorators, meta };
|
|
120
113
|
field.children = shapeKeys.flatMap((key) => {
|
|
121
114
|
const childPath = joinPath([...toPath(path), key]);
|
|
122
115
|
return introspectSchema(shape[key], mapping, childPath, globalMeta);
|
|
@@ -131,7 +124,7 @@ function handleLayoutField(params) {
|
|
|
131
124
|
}
|
|
132
125
|
const pathSegments = toPath(path);
|
|
133
126
|
const actualParentPath = pathSegments.slice(0, -1).join(".");
|
|
134
|
-
const layoutField =
|
|
127
|
+
const layoutField = { path, schema, decorators: {}, meta };
|
|
135
128
|
layoutField.children = Object.keys(shape).flatMap((key) => {
|
|
136
129
|
const childSchema = shape[key];
|
|
137
130
|
if (!childSchema) return [];
|
|
@@ -141,6 +134,7 @@ function handleLayoutField(params) {
|
|
|
141
134
|
return [layoutField];
|
|
142
135
|
}
|
|
143
136
|
export function introspectSchema(schema, mapping, path, globalMeta = {}) {
|
|
137
|
+
if (toPath(path).length > AUTOFORM_LIMITS.MAX_RECURSION_DEPTH) return [];
|
|
144
138
|
const fieldName = path.split(".").pop();
|
|
145
139
|
const autoGeneratedLabel = fieldName ? startCase(fieldName) : "";
|
|
146
140
|
const { decorators, mergedMeta, coreSchema } = extractSchemaInfo(schema, globalMeta, autoGeneratedLabel);
|
|
@@ -157,11 +151,18 @@ export function introspectSchema(schema, mapping, path, globalMeta = {}) {
|
|
|
157
151
|
if (fieldType === "object") {
|
|
158
152
|
return handleObjectField({ schema: coreSchema, path, decorators, meta: mergedMeta, mapping, globalMeta });
|
|
159
153
|
}
|
|
160
|
-
const field =
|
|
154
|
+
const field = { path, schema: coreSchema, decorators, meta: mergedMeta };
|
|
161
155
|
const { chosenComponent, mapped } = selectComponent(mergedMeta, fieldType, mapping);
|
|
162
156
|
field.meta.component = chosenComponent;
|
|
163
157
|
field.meta.mapped = mapped;
|
|
164
|
-
if (
|
|
158
|
+
if (mapped && toRaw(mapped) === DEFAULT_CONTROLS.toggleGroup && coreSchema instanceof z.ZodEnum) {
|
|
159
|
+
field.meta.mapped = {
|
|
160
|
+
...mapped,
|
|
161
|
+
controlProps: Object.assign({
|
|
162
|
+
items: coreSchema.options.map((value) => ({ label: String(value), value }))
|
|
163
|
+
}, mapped.controlProps)
|
|
164
|
+
};
|
|
165
|
+
} else if (coreSchema.type === "enum" && mapped) {
|
|
165
166
|
const enumValues = extractEnumValues(coreSchema);
|
|
166
167
|
if (enumValues && enumValues.length > 0) {
|
|
167
168
|
field.meta.controlProps = {
|
|
@@ -176,45 +177,85 @@ function isLayoutMarker(schema) {
|
|
|
176
177
|
const meta = getAutoFormMetadata(schema);
|
|
177
178
|
return meta?.type === AUTOFORM_META.LAYOUT_KEY;
|
|
178
179
|
}
|
|
179
|
-
function
|
|
180
|
-
|
|
181
|
-
|
|
180
|
+
function defOf(schema) {
|
|
181
|
+
return schema._zod.def;
|
|
182
|
+
}
|
|
183
|
+
function mapObjectShape(schema, mapShape) {
|
|
184
|
+
const def = defOf(schema);
|
|
185
|
+
const cloneable = schema;
|
|
186
|
+
if (def.type === "object" && def.shape) {
|
|
187
|
+
const shape = mapShape(def.shape);
|
|
188
|
+
return shape ? cloneable.clone({ ...def, shape }) : schema;
|
|
189
|
+
}
|
|
190
|
+
if (def.innerType) {
|
|
191
|
+
const inner = mapObjectShape(def.innerType, mapShape);
|
|
192
|
+
return inner === def.innerType ? schema : cloneable.clone({ ...def, innerType: inner });
|
|
193
|
+
}
|
|
194
|
+
if (def.type === "pipe" && def.in) {
|
|
195
|
+
const input = mapObjectShape(def.in, mapShape);
|
|
196
|
+
return input === def.in ? schema : cloneable.clone({ ...def, in: input });
|
|
197
|
+
}
|
|
198
|
+
return schema;
|
|
199
|
+
}
|
|
200
|
+
function expandLayoutShape(shape) {
|
|
201
|
+
let changed = false;
|
|
202
|
+
const entries = Object.entries(shape).flatMap(([key, fieldSchema]) => {
|
|
182
203
|
if (isLayoutMarker(fieldSchema)) {
|
|
183
|
-
|
|
184
|
-
const layoutFields =
|
|
185
|
-
if (layoutFields
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
} else {
|
|
189
|
-
resultShape[key] = fieldSchema;
|
|
204
|
+
changed = true;
|
|
205
|
+
const layoutFields = getAutoFormMetadata(fieldSchema)?.layout?.fields;
|
|
206
|
+
if (!layoutFields || !isObject(layoutFields)) return [];
|
|
207
|
+
const expanded = expandLayoutShape(layoutFields) ?? layoutFields;
|
|
208
|
+
return Object.entries(expanded);
|
|
190
209
|
}
|
|
191
|
-
|
|
192
|
-
|
|
210
|
+
const next = mapObjectShape(fieldSchema, expandLayoutShape);
|
|
211
|
+
if (next !== fieldSchema) changed = true;
|
|
212
|
+
return [[key, next]];
|
|
213
|
+
});
|
|
214
|
+
return changed ? Object.fromEntries(entries) : void 0;
|
|
193
215
|
}
|
|
194
216
|
export function extractPureSchema(schema) {
|
|
195
|
-
|
|
196
|
-
if (!shape || typeof shape !== "object") {
|
|
197
|
-
return schema;
|
|
198
|
-
}
|
|
199
|
-
const hasLayoutMarker = Object.values(shape).some(
|
|
200
|
-
(fieldSchema) => isLayoutMarker(fieldSchema)
|
|
201
|
-
);
|
|
202
|
-
if (!hasLayoutMarker) {
|
|
203
|
-
return schema;
|
|
204
|
-
}
|
|
205
|
-
const pureShape = processLayoutShape(shape);
|
|
206
|
-
return zod.object(pureShape);
|
|
217
|
+
return mapObjectShape(schema, expandLayoutShape);
|
|
207
218
|
}
|
|
208
|
-
|
|
209
|
-
const
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
219
|
+
function buildPathTree(paths) {
|
|
220
|
+
const root = /* @__PURE__ */ new Map();
|
|
221
|
+
for (const path of paths) {
|
|
222
|
+
const segments = toPath(path).map(String);
|
|
223
|
+
let node = root;
|
|
224
|
+
segments.forEach((segment, index) => {
|
|
225
|
+
if (index === segments.length - 1) {
|
|
226
|
+
node.set(segment, true);
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
const child = node.get(segment);
|
|
230
|
+
if (child === true) return;
|
|
231
|
+
const next = child ?? /* @__PURE__ */ new Map();
|
|
232
|
+
node.set(segment, next);
|
|
233
|
+
node = next;
|
|
234
|
+
});
|
|
216
235
|
}
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
236
|
+
return root;
|
|
237
|
+
}
|
|
238
|
+
function omitByTree(schema, tree) {
|
|
239
|
+
return mapObjectShape(schema, (shape) => {
|
|
240
|
+
const keys = Object.keys(shape);
|
|
241
|
+
if (!keys.some((key) => tree.has(key))) return void 0;
|
|
242
|
+
return Object.fromEntries(keys.flatMap((key) => {
|
|
243
|
+
const node = tree.get(key);
|
|
244
|
+
if (node === true) return [];
|
|
245
|
+
return [[key, node ? omitByTree(shape[key], node) : shape[key]]];
|
|
246
|
+
}));
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
export function omitPaths(schema, paths) {
|
|
250
|
+
if (!paths.length) return schema;
|
|
251
|
+
return omitByTree(schema, buildPathTree(paths));
|
|
252
|
+
}
|
|
253
|
+
export function getArrayLengthBounds(schema) {
|
|
254
|
+
const checks = defOf(schema).checks ?? [];
|
|
255
|
+
return checks.reduce((bounds, { _zod: { def } }) => {
|
|
256
|
+
if (def.check === "min_length") return { ...bounds, min: def.minimum ?? bounds.min };
|
|
257
|
+
if (def.check === "max_length") return { ...bounds, max: def.maximum ?? bounds.max };
|
|
258
|
+
if (def.check === "length_equals") return { min: def.length ?? bounds.min, max: def.length ?? bounds.max };
|
|
259
|
+
return bounds;
|
|
260
|
+
}, { min: 0, max: Infinity });
|
|
220
261
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { z } from 'zod';
|
|
2
|
+
type SearchState = Record<string, unknown>;
|
|
3
|
+
export type SearchQuery = Record<string, string | null | Array<string | null> | undefined>;
|
|
4
|
+
/** 默认的搜索载荷清洗:字符串去首尾空白,剔除空字符串、`undefined` 与 `null` */
|
|
5
|
+
export declare function cleanSearchPayload<T extends SearchState>(data: T): Partial<T>;
|
|
6
|
+
/** 将搜索状态写成 URL query:数组保留为多值,对象以 JSON 编码,空值跳过 */
|
|
7
|
+
export declare function serializeSearchQuery(state: SearchState): SearchQuery;
|
|
8
|
+
/** 按 schema 字段类型把 URL query 还原为搜索状态,忽略 schema 外的键与无法解析的值 */
|
|
9
|
+
export declare function parseSearchQuery(query: SearchQuery, schema: z.ZodObject): SearchState;
|
|
10
|
+
export {};
|