@movk/nuxt 1.1.2 → 1.3.0
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/.nuxt/movk-ui.css +3 -0
- package/README.md +75 -104
- package/dist/module.d.mts +59 -1
- package/dist/module.json +2 -2
- package/dist/module.mjs +136 -56
- package/dist/runtime/components/AutoForm.d.vue.ts +10 -31
- package/dist/runtime/components/AutoForm.vue +114 -148
- package/dist/runtime/components/AutoForm.vue.d.ts +10 -31
- package/dist/runtime/components/ColorChooser.d.vue.ts +20 -17
- package/dist/runtime/components/ColorChooser.vue +305 -31
- package/dist/runtime/components/ColorChooser.vue.d.ts +20 -17
- package/dist/runtime/components/DataTable.d.vue.ts +57 -0
- package/dist/runtime/components/DataTable.vue +584 -0
- package/dist/runtime/components/DataTable.vue.d.ts +57 -0
- package/dist/runtime/components/DatePicker.d.vue.ts +15 -22
- package/dist/runtime/components/DatePicker.vue +173 -65
- package/dist/runtime/components/DatePicker.vue.d.ts +15 -22
- package/dist/runtime/components/MessageBox.d.vue.ts +36 -0
- package/dist/runtime/components/MessageBox.vue +113 -0
- package/dist/runtime/components/MessageBox.vue.d.ts +36 -0
- package/dist/runtime/components/PillGroup.d.vue.ts +33 -0
- package/dist/runtime/components/PillGroup.vue +291 -0
- package/dist/runtime/components/PillGroup.vue.d.ts +33 -0
- package/dist/runtime/components/Popconfirm.d.vue.ts +30 -0
- package/dist/runtime/components/Popconfirm.vue +143 -0
- package/dist/runtime/components/Popconfirm.vue.d.ts +30 -0
- package/dist/runtime/components/SearchForm.d.vue.ts +43 -0
- package/dist/runtime/components/SearchForm.vue +274 -0
- package/dist/runtime/components/SearchForm.vue.d.ts +43 -0
- package/dist/runtime/components/SlideVerify.d.vue.ts +13 -79
- package/dist/runtime/components/SlideVerify.vue +117 -90
- package/dist/runtime/components/SlideVerify.vue.d.ts +13 -79
- package/dist/runtime/components/StarRating.d.vue.ts +25 -82
- package/dist/runtime/components/StarRating.vue +128 -99
- package/dist/runtime/components/StarRating.vue.d.ts +25 -82
- package/dist/runtime/components/input/AsPhoneNumberInput.d.vue.ts +32 -0
- package/dist/runtime/components/input/AsPhoneNumberInput.vue +48 -0
- package/dist/runtime/components/input/AsPhoneNumberInput.vue.d.ts +32 -0
- package/dist/runtime/components/input/WithCharacterLimit.d.vue.ts +13 -7
- package/dist/runtime/components/input/WithCharacterLimit.vue +27 -15
- package/dist/runtime/components/input/WithCharacterLimit.vue.d.ts +13 -7
- package/dist/runtime/components/input/WithClear.d.vue.ts +11 -5
- package/dist/runtime/components/input/WithClear.vue +29 -10
- package/dist/runtime/components/input/WithClear.vue.d.ts +11 -5
- package/dist/runtime/components/input/WithCopy.d.vue.ts +13 -7
- package/dist/runtime/components/input/WithCopy.vue +28 -11
- package/dist/runtime/components/input/WithCopy.vue.d.ts +13 -7
- package/dist/runtime/components/input/WithFloatingLabel.d.vue.ts +33 -0
- package/dist/runtime/components/input/WithFloatingLabel.vue +75 -0
- package/dist/runtime/components/input/WithFloatingLabel.vue.d.ts +33 -0
- package/dist/runtime/components/input/WithPasswordToggle.d.vue.ts +13 -7
- package/dist/runtime/components/input/WithPasswordToggle.vue +27 -10
- package/dist/runtime/components/input/WithPasswordToggle.vue.d.ts +13 -7
- package/dist/runtime/components/theme-picker/ThemePicker.d.vue.ts +8 -1
- package/dist/runtime/components/theme-picker/ThemePicker.vue +37 -28
- package/dist/runtime/components/theme-picker/ThemePicker.vue.d.ts +8 -1
- package/dist/runtime/components/theme-picker/ThemePickerButton.d.vue.ts +5 -6
- package/dist/runtime/components/theme-picker/ThemePickerButton.vue +4 -0
- package/dist/runtime/components/theme-picker/ThemePickerButton.vue.d.ts +5 -6
- package/dist/runtime/composables/index.d.ts +9 -8
- package/dist/runtime/composables/index.js +2 -1
- package/dist/runtime/composables/useApiFetch.d.ts +23 -15
- package/dist/runtime/composables/useApiFetch.js +21 -28
- package/dist/runtime/composables/useAutoForm.d.ts +14 -98
- package/dist/runtime/composables/useAutoForm.js +55 -161
- package/dist/runtime/composables/useClientApiFetch.d.ts +7 -7
- package/dist/runtime/composables/useDateFormatter.d.ts +16 -3
- package/dist/runtime/composables/useDateFormatter.js +89 -30
- package/dist/runtime/composables/useDownloadWithProgress.d.ts +26 -27
- package/dist/runtime/composables/useDownloadWithProgress.js +143 -42
- package/dist/runtime/composables/useLazyApiFetch.d.ts +19 -0
- package/dist/runtime/composables/useLazyApiFetch.js +4 -0
- package/dist/runtime/composables/useMessageBox.d.ts +6 -0
- package/dist/runtime/composables/useMessageBox.js +16 -0
- package/dist/runtime/composables/useTheme.d.ts +21 -8
- package/dist/runtime/composables/useTheme.js +109 -86
- package/dist/runtime/composables/useUploadWithProgress.d.ts +22 -28
- package/dist/runtime/composables/useUploadWithProgress.js +79 -68
- package/dist/runtime/domains/api/auth.d.ts +2 -0
- package/dist/runtime/domains/api/auth.js +31 -0
- package/dist/runtime/domains/api/endpoint-config.d.ts +11 -0
- package/dist/runtime/domains/api/endpoint-config.js +17 -0
- package/dist/runtime/domains/api/errors.d.ts +2 -0
- package/dist/runtime/domains/api/errors.js +10 -0
- package/dist/runtime/domains/api/fetch-key.d.ts +20 -0
- package/dist/runtime/domains/api/fetch-key.js +23 -0
- package/dist/runtime/domains/api/interceptors/error.d.ts +13 -0
- package/dist/runtime/domains/api/interceptors/error.js +49 -0
- package/dist/runtime/domains/api/interceptors/request.d.ts +12 -0
- package/dist/runtime/domains/api/interceptors/request.js +46 -0
- package/dist/runtime/domains/api/interceptors/response.d.ts +17 -0
- package/dist/runtime/domains/api/interceptors/response.js +27 -0
- package/dist/runtime/domains/api/response.d.ts +4 -0
- package/dist/runtime/domains/api/response.js +14 -0
- package/dist/runtime/domains/api/toast.d.ts +15 -0
- package/dist/runtime/domains/api/toast.js +46 -0
- package/dist/runtime/domains/api/transfer.d.ts +69 -0
- package/dist/runtime/domains/api/transfer.js +81 -0
- package/dist/runtime/domains/auto-form/actions.d.ts +2 -0
- package/dist/runtime/domains/auto-form/actions.js +4 -0
- package/dist/runtime/domains/auto-form/components/Array.d.vue.ts +13 -0
- package/dist/runtime/{components/auto-form-renderer/AutoFormRendererArray.vue → domains/auto-form/components/Array.vue} +37 -48
- package/dist/runtime/domains/auto-form/components/Array.vue.d.ts +13 -0
- package/dist/runtime/domains/auto-form/components/Children.d.vue.ts +11 -0
- package/dist/runtime/domains/auto-form/components/Children.vue +50 -0
- package/dist/runtime/domains/auto-form/components/Children.vue.d.ts +11 -0
- package/dist/runtime/domains/auto-form/components/Field.d.vue.ts +11 -0
- package/dist/runtime/domains/auto-form/components/Field.vue +56 -0
- package/dist/runtime/domains/auto-form/components/Field.vue.d.ts +11 -0
- package/dist/runtime/domains/auto-form/components/Layout.d.vue.ts +11 -0
- package/dist/runtime/domains/auto-form/components/Layout.vue +89 -0
- package/dist/runtime/domains/auto-form/components/Layout.vue.d.ts +11 -0
- package/dist/runtime/domains/auto-form/components/Nested.d.vue.ts +11 -0
- package/dist/runtime/domains/auto-form/components/Nested.vue +47 -0
- package/dist/runtime/domains/auto-form/components/Nested.vue.d.ts +11 -0
- package/dist/runtime/{constants/auto-form.d.ts → domains/auto-form/constants.d.ts} +0 -2
- package/dist/runtime/{constants/auto-form.js → domains/auto-form/constants.js} +0 -25
- package/dist/runtime/domains/auto-form/controls.d.ts +41 -0
- package/dist/runtime/domains/auto-form/controls.js +73 -0
- package/dist/runtime/{utils/field-utils.d.ts → domains/auto-form/fields.d.ts} +7 -21
- package/dist/runtime/{utils/field-utils.js → domains/auto-form/fields.js} +19 -4
- package/dist/runtime/domains/auto-form/metadata.d.ts +22 -0
- package/dist/runtime/domains/auto-form/metadata.js +53 -0
- package/dist/runtime/domains/auto-form/provider.d.ts +62 -0
- package/dist/runtime/{internal/useAutoFormProvider.js → domains/auto-form/provider.js} +6 -3
- package/dist/runtime/domains/auto-form/reactive.d.ts +12 -0
- package/dist/runtime/{utils/reactive-utils.js → domains/auto-form/reactive.js} +1 -1
- package/dist/runtime/domains/auto-form/schema.d.ts +7 -0
- package/dist/runtime/{utils/schema-introspector.js → domains/auto-form/schema.js} +12 -10
- package/dist/runtime/domains/data-table/columns/constants.d.ts +50 -0
- package/dist/runtime/domains/data-table/columns/constants.js +19 -0
- package/dist/runtime/domains/data-table/columns/resolve-columns.d.ts +4 -0
- package/dist/runtime/domains/data-table/columns/resolve-columns.js +59 -0
- package/dist/runtime/domains/data-table/columns/resolve-data-column.d.ts +9 -0
- package/dist/runtime/domains/data-table/columns/resolve-data-column.js +164 -0
- package/dist/runtime/domains/data-table/columns/resolve-group-column.d.ts +4 -0
- package/dist/runtime/domains/data-table/columns/resolve-group-column.js +19 -0
- package/dist/runtime/domains/data-table/columns/resolve-special-columns.d.ts +8 -0
- package/dist/runtime/domains/data-table/columns/resolve-special-columns.js +232 -0
- package/dist/runtime/domains/data-table/columns/style.d.ts +11 -0
- package/dist/runtime/domains/data-table/columns/style.js +67 -0
- package/dist/runtime/domains/data-table/columns/utils.d.ts +6 -0
- package/dist/runtime/domains/data-table/columns/utils.js +16 -0
- package/dist/runtime/domains/data-table/components/ActionConfirm.d.vue.ts +10 -0
- package/dist/runtime/domains/data-table/components/ActionConfirm.vue +39 -0
- package/dist/runtime/domains/data-table/components/ActionConfirm.vue.d.ts +10 -0
- package/dist/runtime/domains/data-table/components/ActionsCell.d.vue.ts +11 -0
- package/dist/runtime/domains/data-table/components/ActionsCell.vue +91 -0
- package/dist/runtime/domains/data-table/components/ActionsCell.vue.d.ts +11 -0
- package/dist/runtime/domains/data-table/components/CellTooltip.d.vue.ts +9 -0
- package/dist/runtime/domains/data-table/components/CellTooltip.vue +40 -0
- package/dist/runtime/domains/data-table/components/CellTooltip.vue.d.ts +9 -0
- package/dist/runtime/domains/data-table/components/Pagination.d.vue.ts +26 -0
- package/dist/runtime/domains/data-table/components/Pagination.vue +132 -0
- package/dist/runtime/domains/data-table/components/Pagination.vue.d.ts +26 -0
- package/dist/runtime/domains/data-table/indent.d.ts +8 -0
- package/dist/runtime/domains/data-table/indent.js +19 -0
- package/dist/runtime/domains/data-table/tree-selection.d.ts +9 -0
- package/dist/runtime/domains/data-table/tree-selection.js +76 -0
- package/dist/runtime/{utils/theme.d.ts → domains/theme/theme-icons.d.ts} +0 -1
- package/dist/runtime/index.css +1 -0
- package/dist/runtime/plugins/api.factory.js +28 -171
- package/dist/runtime/plugins/theme.js +72 -70
- package/dist/runtime/types/api/config.d.ts +127 -0
- package/dist/runtime/types/api/fetch.d.ts +50 -0
- package/dist/runtime/types/api/index.d.ts +5 -0
- package/dist/runtime/types/api/module.d.ts +94 -0
- package/dist/runtime/types/api/response.d.ts +62 -0
- package/dist/runtime/types/api/transfer.d.ts +32 -0
- package/dist/runtime/types/api/transfer.js +0 -0
- package/dist/runtime/types/app.config.d.ts +6 -0
- package/dist/runtime/types/auto-form/base.d.ts +26 -0
- package/dist/runtime/types/auto-form/base.js +0 -0
- package/dist/runtime/types/auto-form/component.d.ts +28 -0
- package/dist/runtime/types/auto-form/component.js +0 -0
- package/dist/runtime/types/auto-form/controls.d.ts +45 -0
- package/dist/runtime/types/auto-form/controls.js +0 -0
- package/dist/runtime/types/auto-form/fields.d.ts +68 -0
- package/dist/runtime/types/auto-form/fields.js +0 -0
- package/dist/runtime/types/auto-form/index.d.ts +7 -0
- package/dist/runtime/types/auto-form/index.js +0 -0
- package/dist/runtime/types/auto-form/search-form.d.ts +84 -0
- package/dist/runtime/types/auto-form/search-form.js +0 -0
- package/dist/runtime/types/auto-form/slots.d.ts +85 -0
- package/dist/runtime/types/auto-form/slots.js +0 -0
- package/dist/runtime/types/auto-form/zod-factory.d.ts +127 -0
- package/dist/runtime/types/auto-form/zod-factory.js +0 -0
- package/dist/runtime/types/components/color-chooser.d.ts +109 -0
- package/dist/runtime/types/components/color-chooser.js +0 -0
- package/dist/runtime/types/components/date-picker.d.ts +41 -0
- package/dist/runtime/types/components/date-picker.js +0 -0
- package/dist/runtime/types/components/index.d.ts +8 -0
- package/dist/runtime/types/components/index.js +0 -0
- package/dist/runtime/types/components/input/as-phone-number-input.d.ts +17 -0
- package/dist/runtime/types/components/input/as-phone-number-input.js +0 -0
- package/dist/runtime/types/components/input/index.d.ts +6 -0
- package/dist/runtime/types/components/input/index.js +0 -0
- package/dist/runtime/types/components/input/with-character-limit.d.ts +11 -0
- package/dist/runtime/types/components/input/with-character-limit.js +0 -0
- package/dist/runtime/types/components/input/with-clear.d.ts +10 -0
- package/dist/runtime/types/components/input/with-clear.js +0 -0
- package/dist/runtime/types/components/input/with-copy.d.ts +11 -0
- package/dist/runtime/types/components/input/with-copy.js +0 -0
- package/dist/runtime/types/components/input/with-floating-label.d.ts +12 -0
- package/dist/runtime/types/components/input/with-floating-label.js +0 -0
- package/dist/runtime/types/components/input/with-password-toggle.d.ts +7 -0
- package/dist/runtime/types/components/input/with-password-toggle.js +0 -0
- package/dist/runtime/types/components/message-box.d.ts +69 -0
- package/dist/runtime/types/components/message-box.js +0 -0
- package/dist/runtime/types/components/pill-group.d.ts +103 -0
- package/dist/runtime/types/components/pill-group.js +0 -0
- package/dist/runtime/types/components/popconfirm.d.ts +74 -0
- package/dist/runtime/types/components/popconfirm.js +0 -0
- package/dist/runtime/types/components/slide-verify.d.ts +54 -0
- package/dist/runtime/types/components/slide-verify.js +0 -0
- package/dist/runtime/types/components/star-rating.d.ts +55 -0
- package/dist/runtime/types/components/star-rating.js +0 -0
- package/dist/runtime/types/data-table/columns.d.ts +236 -0
- package/dist/runtime/types/data-table/columns.js +6 -0
- package/dist/runtime/types/data-table/component.d.ts +190 -0
- package/dist/runtime/types/data-table/component.js +0 -0
- package/dist/runtime/types/data-table/contexts.d.ts +44 -0
- package/dist/runtime/types/data-table/contexts.js +0 -0
- package/dist/runtime/types/data-table/index.d.ts +6 -0
- package/dist/runtime/types/data-table/index.js +1 -0
- package/dist/runtime/types/data-table/pagination.d.ts +87 -0
- package/dist/runtime/types/data-table/pagination.js +0 -0
- package/dist/runtime/types/index.d.ts +6 -5
- package/dist/runtime/types/index.js +5 -5
- package/dist/runtime/types/shared.d.ts +5 -0
- package/dist/runtime/types/shared.js +0 -0
- package/dist/runtime/types/zod.d.ts +19 -17
- package/dist/runtime/utils/extend-theme.d.ts +19 -0
- package/dist/runtime/utils/extend-theme.js +44 -0
- package/dist/runtime/utils/form-control.d.ts +33 -0
- package/dist/runtime/utils/form-control.js +54 -0
- package/dist/runtime/utils/meta.d.ts +4 -0
- package/dist/runtime/utils/meta.js +14 -0
- package/dist/runtime/utils/theme-defaults.d.ts +27 -0
- package/dist/runtime/utils/theme-defaults.js +28 -0
- package/dist/runtime/utils/tv.d.ts +1 -0
- package/dist/runtime/utils/tv.js +4 -0
- package/dist/runtime/vue/composables/useSiteConfig.d.ts +13 -0
- package/dist/runtime/vue/composables/useSiteConfig.js +11 -0
- package/dist/runtime/vue/plugins/theme.d.ts +6 -0
- package/dist/runtime/vue/plugins/theme.js +14 -0
- package/dist/runtime/vue/stubs/base.d.ts +2 -0
- package/dist/runtime/vue/stubs/base.js +2 -0
- package/dist/runtime/vue/stubs/inertia.d.ts +2 -0
- package/dist/runtime/vue/stubs/inertia.js +2 -0
- package/dist/runtime/vue/stubs/movk-extra.d.ts +2 -0
- package/dist/runtime/vue/stubs/movk-extra.js +2 -0
- package/dist/runtime/vue/stubs/none.d.ts +2 -0
- package/dist/runtime/vue/stubs/none.js +2 -0
- package/dist/runtime/vue/stubs/vue-router.d.ts +2 -0
- package/dist/runtime/vue/stubs/vue-router.js +2 -0
- package/dist/shared/nuxt.DfBEyjld.mjs +667 -0
- package/dist/types.d.mts +2 -6
- package/dist/unplugin.d.mts +28 -0
- package/dist/unplugin.mjs +292 -0
- package/dist/vite.d.mts +12 -0
- package/dist/vite.mjs +20 -0
- package/package.json +82 -42
- package/vue-plugin.d.ts +5 -0
- package/dist/runtime/components/auto-form-renderer/AutoFormRendererArray.d.vue.ts +0 -20
- package/dist/runtime/components/auto-form-renderer/AutoFormRendererArray.vue.d.ts +0 -20
- package/dist/runtime/components/auto-form-renderer/AutoFormRendererField.d.vue.ts +0 -20
- package/dist/runtime/components/auto-form-renderer/AutoFormRendererField.vue +0 -55
- package/dist/runtime/components/auto-form-renderer/AutoFormRendererField.vue.d.ts +0 -20
- package/dist/runtime/components/auto-form-renderer/AutoFormRendererLayout.d.vue.ts +0 -20
- package/dist/runtime/components/auto-form-renderer/AutoFormRendererLayout.vue +0 -125
- package/dist/runtime/components/auto-form-renderer/AutoFormRendererLayout.vue.d.ts +0 -20
- package/dist/runtime/components/auto-form-renderer/AutoFormRendererNested.d.vue.ts +0 -20
- package/dist/runtime/components/auto-form-renderer/AutoFormRendererNested.vue +0 -105
- package/dist/runtime/components/auto-form-renderer/AutoFormRendererNested.vue.d.ts +0 -20
- package/dist/runtime/composables/useApiAuth.d.ts +0 -47
- package/dist/runtime/composables/useApiAuth.js +0 -66
- package/dist/runtime/internal/useAutoFormProvider.d.ts +0 -50
- package/dist/runtime/schemas/api.d.ts +0 -590
- package/dist/runtime/schemas/api.js +0 -228
- package/dist/runtime/server/api/_movk/session.post.d.ts +0 -10
- package/dist/runtime/server/api/_movk/session.post.js +0 -18
- package/dist/runtime/style.css +0 -1
- package/dist/runtime/types/api.d.ts +0 -218
- package/dist/runtime/types/auth.d.ts +0 -34
- package/dist/runtime/types/auto-form-renderer.d.ts +0 -22
- package/dist/runtime/types/auto-form.d.ts +0 -548
- package/dist/runtime/types/components.d.ts +0 -43
- package/dist/runtime/types/module.d.ts +0 -39
- package/dist/runtime/utils/api-utils.d.ts +0 -79
- package/dist/runtime/utils/api-utils.js +0 -127
- package/dist/runtime/utils/auto-form.d.ts +0 -3
- package/dist/runtime/utils/auto-form.js +0 -18
- package/dist/runtime/utils/reactive-utils.d.ts +0 -30
- package/dist/runtime/utils/schema-introspector.d.ts +0 -13
- /package/dist/runtime/{utils/theme.js → domains/theme/theme-icons.js} +0 -0
- /package/dist/runtime/types/{api.js → api/config.js} +0 -0
- /package/dist/runtime/types/{auto-form-renderer.js → api/fetch.js} +0 -0
- /package/dist/runtime/types/{auto-form.js → api/index.js} +0 -0
- /package/dist/runtime/types/{module.js → api/module.js} +0 -0
- /package/dist/runtime/types/{components.js → api/response.js} +0 -0
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import type { FetchContext, FetchOptions } from 'ofetch';
|
|
2
|
+
import type { ApiResponse, MovkApiPublicConfig, RequestToastOptions, TransferRequestOptions, TransferResult } from '../../types/api';
|
|
3
|
+
import type { ResolvedEndpointConfig } from '../../types/api/module';
|
|
4
|
+
import type { useNuxtApp } from '#imports';
|
|
5
|
+
type NuxtApp = ReturnType<typeof useNuxtApp>;
|
|
6
|
+
/**
|
|
7
|
+
* 预备传输上下文
|
|
8
|
+
*/
|
|
9
|
+
export interface PreparedTransfer {
|
|
10
|
+
fullUrl: string;
|
|
11
|
+
headers: Record<string, string>;
|
|
12
|
+
config: ResolvedEndpointConfig;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* 解析端点 + 拼装 URL + 合并 headers(auth 在前、用户在后,用户优先)
|
|
16
|
+
*/
|
|
17
|
+
export declare function prepareTransfer(publicConfig: MovkApiPublicConfig, url: string, options: TransferRequestOptions): PreparedTransfer;
|
|
18
|
+
/**
|
|
19
|
+
* 解析下载文件名
|
|
20
|
+
* @description 优先级:override > content-disposition > URL pathname 末段 > 'download'
|
|
21
|
+
*/
|
|
22
|
+
export declare function resolveFilename(headers: Headers, url: string, override?: string): string;
|
|
23
|
+
/**
|
|
24
|
+
* 安全解析 JSON 响应
|
|
25
|
+
* @description content-type 含 application/json 时尝试 JSON.parse;失败或非 JSON 返回 null
|
|
26
|
+
*/
|
|
27
|
+
export declare function tryParseJsonResponse(headers: Headers, text: string): ApiResponse | null;
|
|
28
|
+
/**
|
|
29
|
+
* 把 XHR 的 getAllResponseHeaders() 字符串解析为标准 Headers
|
|
30
|
+
*/
|
|
31
|
+
export declare function parseXhrHeaders(raw: string): Headers;
|
|
32
|
+
/**
|
|
33
|
+
* finalizeTransfer 入参
|
|
34
|
+
*/
|
|
35
|
+
export interface FinalizeTransferContext<T> {
|
|
36
|
+
/** JSON 响应体;纯二进制成功时为 null */
|
|
37
|
+
raw: ApiResponse | null;
|
|
38
|
+
/** 无 JSON 时由调用方提供成功/失败判定与默认数据 */
|
|
39
|
+
fallback?: {
|
|
40
|
+
isSuccess: boolean;
|
|
41
|
+
data: T | null;
|
|
42
|
+
message?: string;
|
|
43
|
+
};
|
|
44
|
+
config: ResolvedEndpointConfig;
|
|
45
|
+
publicConfig: MovkApiPublicConfig;
|
|
46
|
+
/** 单次请求 toast 覆盖;false 整体禁用 */
|
|
47
|
+
requestToast: RequestToastOptions | false | undefined;
|
|
48
|
+
skipBusinessCheck?: boolean;
|
|
49
|
+
/** 合成的 FetchContext,用于派发 movk:api:* hook */
|
|
50
|
+
fetchContext: FetchContext;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* 统一处理传输结果:业务校验 → 派发 hook → 触发 toast → 构造 TransferResult
|
|
54
|
+
*
|
|
55
|
+
* @description 本函数**不抛异常**,所有错误以 result.error 形式返回,由 composable 自行决定是否 throw。
|
|
56
|
+
* 中止场景应由调用方在调用本函数前短路,不要进入此函数。
|
|
57
|
+
*/
|
|
58
|
+
export declare function finalizeTransfer<T>(nuxtApp: NuxtApp, ctx: FinalizeTransferContext<T>): Promise<TransferResult<T>>;
|
|
59
|
+
/**
|
|
60
|
+
* 合成一个最小可用的 FetchContext,供 hook 订阅者使用
|
|
61
|
+
*
|
|
62
|
+
* @description 由于上传/下载基于 XHR / fetch,不经 ofetch;此处提供必要字段以与 $api 的 hook 契约对齐。
|
|
63
|
+
*/
|
|
64
|
+
export declare function buildFetchContext(request: string, options: FetchOptions, response?: {
|
|
65
|
+
status: number;
|
|
66
|
+
headers: Headers;
|
|
67
|
+
_data?: unknown;
|
|
68
|
+
}): FetchContext;
|
|
69
|
+
export {};
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { extractFilename } from "@movk/core";
|
|
2
|
+
import { getAuthHeaders } from "./auth.js";
|
|
3
|
+
import { resolveEndpointConfig } from "./endpoint-config.js";
|
|
4
|
+
import { createApiError } from "./errors.js";
|
|
5
|
+
import { extractData, extractMessage, isBusinessSuccess } from "./response.js";
|
|
6
|
+
import { showToast } from "./toast.js";
|
|
7
|
+
export function prepareTransfer(publicConfig, url, options) {
|
|
8
|
+
const config = resolveEndpointConfig(publicConfig, options.endpoint);
|
|
9
|
+
const fullUrl = `${config.baseURL || ""}${url}`;
|
|
10
|
+
const authHeaders = getAuthHeaders(config.auth);
|
|
11
|
+
const headers = { ...authHeaders, ...options.headers || {} };
|
|
12
|
+
return { fullUrl, headers, config };
|
|
13
|
+
}
|
|
14
|
+
export function resolveFilename(headers, url, override) {
|
|
15
|
+
if (override) return override;
|
|
16
|
+
const fromHeader = extractFilename(headers, "");
|
|
17
|
+
if (fromHeader) return fromHeader;
|
|
18
|
+
try {
|
|
19
|
+
const base = typeof location !== "undefined" ? location.origin : "http://localhost";
|
|
20
|
+
const pathname = new URL(url, base).pathname;
|
|
21
|
+
const last = pathname.split("/").filter(Boolean).pop();
|
|
22
|
+
if (last) return last;
|
|
23
|
+
} catch {
|
|
24
|
+
}
|
|
25
|
+
return "download";
|
|
26
|
+
}
|
|
27
|
+
export function tryParseJsonResponse(headers, text) {
|
|
28
|
+
const contentType = headers.get("content-type") || "";
|
|
29
|
+
if (!contentType.toLowerCase().includes("application/json")) return null;
|
|
30
|
+
try {
|
|
31
|
+
return JSON.parse(text);
|
|
32
|
+
} catch {
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
export function parseXhrHeaders(raw) {
|
|
37
|
+
const headers = new Headers();
|
|
38
|
+
if (!raw) return headers;
|
|
39
|
+
for (const line of raw.trim().split(/\r?\n/)) {
|
|
40
|
+
const idx = line.indexOf(":");
|
|
41
|
+
if (idx <= 0) continue;
|
|
42
|
+
const name = line.slice(0, idx).trim();
|
|
43
|
+
const value = line.slice(idx + 1).trim();
|
|
44
|
+
if (name) headers.append(name, value);
|
|
45
|
+
}
|
|
46
|
+
return headers;
|
|
47
|
+
}
|
|
48
|
+
export async function finalizeTransfer(nuxtApp, ctx) {
|
|
49
|
+
const { raw, fallback, config, publicConfig, requestToast, skipBusinessCheck, fetchContext } = ctx;
|
|
50
|
+
const { response: responseConfig, toast: toastConfig } = config;
|
|
51
|
+
if (publicConfig.debug) {
|
|
52
|
+
console.info("[@movk/nuxt] Transfer response:", raw ?? fallback);
|
|
53
|
+
}
|
|
54
|
+
const hasRaw = raw !== null;
|
|
55
|
+
const isSuccess = hasRaw ? skipBusinessCheck || isBusinessSuccess(raw, responseConfig) : fallback?.isSuccess ?? false;
|
|
56
|
+
if (isSuccess) {
|
|
57
|
+
const data = hasRaw ? skipBusinessCheck ? raw : extractData(raw, responseConfig) : fallback?.data ?? null;
|
|
58
|
+
if (fetchContext.response) {
|
|
59
|
+
fetchContext.response._data = data;
|
|
60
|
+
}
|
|
61
|
+
await nuxtApp.callHook("movk:api:response", fetchContext);
|
|
62
|
+
showToast("success", raw ?? fallback?.message, requestToast, toastConfig, responseConfig);
|
|
63
|
+
return { data, error: null, aborted: false };
|
|
64
|
+
}
|
|
65
|
+
const message = hasRaw ? extractMessage(raw, responseConfig) || fallback?.message : fallback?.message;
|
|
66
|
+
const apiError = hasRaw ? createApiError(raw, message) : Object.assign(new Error(message || "\u8BF7\u6C42\u5931\u8D25"), { isBusinessError: false });
|
|
67
|
+
if (fetchContext.response) {
|
|
68
|
+
fetchContext.response._data = raw ?? void 0;
|
|
69
|
+
}
|
|
70
|
+
fetchContext.error = apiError;
|
|
71
|
+
await nuxtApp.callHook("movk:api:error", fetchContext);
|
|
72
|
+
showToast("error", raw ?? message, requestToast, toastConfig, responseConfig);
|
|
73
|
+
return { data: null, error: apiError, aborted: false };
|
|
74
|
+
}
|
|
75
|
+
export function buildFetchContext(request, options, response) {
|
|
76
|
+
return {
|
|
77
|
+
request,
|
|
78
|
+
options,
|
|
79
|
+
response
|
|
80
|
+
};
|
|
81
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { z } from 'zod';
|
|
2
|
+
import type { ButtonProps } from '@nuxt/ui';
|
|
3
|
+
import type { AutoFormField } from '../../../types/auto-form';
|
|
4
|
+
import type { AnyObject } from '@movk/core';
|
|
5
|
+
interface AutoFormRendererArrayProps {
|
|
6
|
+
schema: z.ZodObject;
|
|
7
|
+
field: AutoFormField;
|
|
8
|
+
extraProps?: AnyObject;
|
|
9
|
+
addButtonProps?: Partial<ButtonProps>;
|
|
10
|
+
}
|
|
11
|
+
declare const __VLS_export: import("vue").DefineComponent<AutoFormRendererArrayProps, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<AutoFormRendererArrayProps> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
12
|
+
declare const _default: typeof __VLS_export;
|
|
13
|
+
export default _default;
|
|
@@ -1,42 +1,34 @@
|
|
|
1
1
|
<script setup>
|
|
2
2
|
import { UButton, UCollapsible } from "#components";
|
|
3
|
-
import { computed, ref
|
|
4
|
-
import { useAutoFormInjector } from "
|
|
3
|
+
import { computed, ref } from "vue";
|
|
4
|
+
import { useAutoFormInjector } from "../provider";
|
|
5
5
|
import { joinPath } from "@movk/core";
|
|
6
|
-
import { collectFieldDefaults, createHintSlotFactory
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
schema,
|
|
13
|
-
addButtonProps: customAddButtonProps
|
|
14
|
-
} = defineProps({
|
|
6
|
+
import { collectFieldDefaults, createHintSlotFactory } from "../fields";
|
|
7
|
+
import { VNodeRender } from "../reactive";
|
|
8
|
+
import AutoFormRendererField from "./Field.vue";
|
|
9
|
+
import AutoFormRendererNested from "./Nested.vue";
|
|
10
|
+
const props = defineProps({
|
|
11
|
+
schema: { type: null, required: true },
|
|
15
12
|
field: { type: Object, required: true },
|
|
16
13
|
extraProps: { type: Object, required: false },
|
|
17
|
-
addButtonProps: { type: Object, required: false }
|
|
18
|
-
schema: { type: null, required: false }
|
|
19
|
-
});
|
|
20
|
-
const { createCollapsibleEnhancer, createFieldContext, createSlotResolver, createSlotProps } = useAutoFormInjector();
|
|
21
|
-
const context = createFieldContext(field);
|
|
22
|
-
const slotResolver = computed(() => createSlotResolver(field, extraProps));
|
|
23
|
-
const slotProps = computed(() => createSlotProps(field, extraProps));
|
|
24
|
-
const elementTemplate = computed(() => field.arrayElement);
|
|
25
|
-
const isObjectElement = computed(() => {
|
|
26
|
-
if (!elementTemplate.value)
|
|
27
|
-
return false;
|
|
28
|
-
return elementTemplate.value.meta.type === "object";
|
|
14
|
+
addButtonProps: { type: Object, required: false }
|
|
29
15
|
});
|
|
16
|
+
const { createCollapsibleEnhancer, createFieldContext, createSlotResolver, createSlotProps, resolveFieldProp } = useAutoFormInjector();
|
|
17
|
+
const context = createFieldContext(props.field);
|
|
18
|
+
const slotResolver = computed(() => createSlotResolver(props.field, props.extraProps));
|
|
19
|
+
const slotProps = computed(() => createSlotProps(props.field, props.extraProps));
|
|
20
|
+
const elementTemplate = computed(() => props.field.arrayElement);
|
|
21
|
+
const isObjectElement = computed(() => elementTemplate.value?.meta.type === "object");
|
|
30
22
|
const arrayValue = computed(() => {
|
|
31
23
|
const value = context.value;
|
|
32
24
|
return Array.isArray(value) ? value : [];
|
|
33
25
|
});
|
|
34
26
|
const itemIds = ref([]);
|
|
35
|
-
|
|
27
|
+
const idCounter = ref(0);
|
|
36
28
|
function ensureItemIds() {
|
|
37
29
|
const arr = arrayValue.value;
|
|
38
30
|
while (itemIds.value.length < arr.length) {
|
|
39
|
-
itemIds.value.push(`${field.path}-${idCounter++}`);
|
|
31
|
+
itemIds.value.push(`${props.field.path}-${idCounter.value++}`);
|
|
40
32
|
}
|
|
41
33
|
}
|
|
42
34
|
function getItemId(_item, index) {
|
|
@@ -55,7 +47,7 @@ function updateFieldPaths(template, oldBasePath, newBasePath, hintSlotFactory) {
|
|
|
55
47
|
fieldSlots: isNested && !isObject ? {
|
|
56
48
|
...template.meta?.fieldSlots
|
|
57
49
|
} : {
|
|
58
|
-
hint: (
|
|
50
|
+
hint: (props2) => hintSlotFactory(template, props2.path, props2.open, props2.count),
|
|
59
51
|
...template.meta?.fieldSlots
|
|
60
52
|
}
|
|
61
53
|
}
|
|
@@ -68,23 +60,22 @@ function updateFieldPaths(template, oldBasePath, newBasePath, hintSlotFactory) {
|
|
|
68
60
|
return updatedField;
|
|
69
61
|
}
|
|
70
62
|
const arrayItemFields = computed(() => {
|
|
71
|
-
const template =
|
|
63
|
+
const template = elementTemplate.value;
|
|
72
64
|
const arr = arrayValue.value;
|
|
73
65
|
if (!template || !arr.length)
|
|
74
66
|
return [];
|
|
75
67
|
const factory = createHintSlotFactory(removeItem);
|
|
76
68
|
return arr.map((_, index) => {
|
|
77
|
-
const newBasePath = joinPath([field.path, index]);
|
|
78
|
-
return updateFieldPaths(template, field.path, newBasePath, factory);
|
|
69
|
+
const newBasePath = joinPath([props.field.path, index]);
|
|
70
|
+
return updateFieldPaths(template, props.field.path, newBasePath, factory);
|
|
79
71
|
});
|
|
80
72
|
});
|
|
81
73
|
function createDefaultValue() {
|
|
82
|
-
const template =
|
|
74
|
+
const template = elementTemplate.value;
|
|
83
75
|
return template ? collectFieldDefaults(template) : void 0;
|
|
84
76
|
}
|
|
85
77
|
function addItem() {
|
|
86
|
-
|
|
87
|
-
if (!template)
|
|
78
|
+
if (!elementTemplate.value)
|
|
88
79
|
return;
|
|
89
80
|
const newArray = [...arrayValue.value, createDefaultValue()];
|
|
90
81
|
context.setValue(newArray);
|
|
@@ -97,37 +88,36 @@ function removeItem(count) {
|
|
|
97
88
|
itemIds.value = [...itemIds.value.slice(0, count), ...itemIds.value.slice(count + 1)];
|
|
98
89
|
context.setValue(newArray);
|
|
99
90
|
}
|
|
100
|
-
const { collapsibleConfig, shouldShowCollapsible, isHidden, enhancedField } = createCollapsibleEnhancer(field, extraProps);
|
|
91
|
+
const { collapsibleConfig, shouldShowCollapsible, isHidden, enhancedField } = createCollapsibleEnhancer(props.field, props.extraProps);
|
|
101
92
|
const DEFAULT_ADD_BUTTON_PROPS = {
|
|
102
93
|
icon: "i-lucide-plus",
|
|
103
|
-
color: "
|
|
104
|
-
variant: "
|
|
105
|
-
block: true,
|
|
94
|
+
color: "info",
|
|
95
|
+
variant: "soft",
|
|
106
96
|
size: "sm"
|
|
107
97
|
};
|
|
108
98
|
const addButtonProps = computed(() => ({
|
|
109
99
|
...DEFAULT_ADD_BUTTON_PROPS,
|
|
110
|
-
|
|
100
|
+
size: resolveFieldProp(props.field, "size", "sm", props.extraProps),
|
|
101
|
+
...props.addButtonProps
|
|
111
102
|
}));
|
|
112
103
|
</script>
|
|
113
104
|
|
|
114
105
|
<template>
|
|
115
106
|
<UCollapsible v-if="shouldShowCollapsible" v-show="!isHidden" v-bind="collapsibleConfig || {}">
|
|
116
107
|
<template #default="{ open }">
|
|
117
|
-
<AutoFormRendererField :field="enhancedField" :schema="schema" :extra-props="{ ...extraProps, open }" />
|
|
108
|
+
<AutoFormRendererField :field="enhancedField" :schema="props.schema" :extra-props="{ ...props.extraProps, open }" />
|
|
118
109
|
</template>
|
|
119
110
|
|
|
120
111
|
<template v-if="elementTemplate" #content>
|
|
121
112
|
<VNodeRender v-if="slotResolver.hasSlot('before')" :node="slotResolver.renderSlot('before', slotProps)" />
|
|
122
113
|
<VNodeRender v-if="slotResolver.hasSlot('content')" :node="slotResolver.renderSlot('content', slotProps)" />
|
|
123
114
|
<template v-else>
|
|
124
|
-
<template v-for="(
|
|
115
|
+
<template v-for="(itemField, count) in arrayItemFields" :key="getItemId(arrayValue[count], count)">
|
|
125
116
|
<component
|
|
126
117
|
:is="isObjectElement ? AutoFormRendererNested : AutoFormRendererField"
|
|
127
|
-
|
|
128
|
-
:
|
|
129
|
-
:
|
|
130
|
-
:extra-props="{ ...extraProps, count }"
|
|
118
|
+
:field="itemField"
|
|
119
|
+
:schema="props.schema"
|
|
120
|
+
:extra-props="{ ...props.extraProps, count }"
|
|
131
121
|
/>
|
|
132
122
|
</template>
|
|
133
123
|
</template>
|
|
@@ -139,13 +129,12 @@ const addButtonProps = computed(() => ({
|
|
|
139
129
|
</UCollapsible>
|
|
140
130
|
|
|
141
131
|
<template v-else-if="elementTemplate">
|
|
142
|
-
<template v-for="(
|
|
132
|
+
<template v-for="(itemField, count) in arrayItemFields" :key="getItemId(arrayValue[count], count)">
|
|
143
133
|
<component
|
|
144
134
|
:is="isObjectElement ? AutoFormRendererNested : AutoFormRendererField"
|
|
145
|
-
|
|
146
|
-
:
|
|
147
|
-
:
|
|
148
|
-
:extra-props="{ ...extraProps, count }"
|
|
135
|
+
:field="itemField"
|
|
136
|
+
:schema="props.schema"
|
|
137
|
+
:extra-props="{ ...props.extraProps, count }"
|
|
149
138
|
/>
|
|
150
139
|
</template>
|
|
151
140
|
<UButton v-bind="addButtonProps" @click="addItem">
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { z } from 'zod';
|
|
2
|
+
import type { ButtonProps } from '@nuxt/ui';
|
|
3
|
+
import type { AutoFormField } from '../../../types/auto-form';
|
|
4
|
+
import type { AnyObject } from '@movk/core';
|
|
5
|
+
interface AutoFormRendererArrayProps {
|
|
6
|
+
schema: z.ZodObject;
|
|
7
|
+
field: AutoFormField;
|
|
8
|
+
extraProps?: AnyObject;
|
|
9
|
+
addButtonProps?: Partial<ButtonProps>;
|
|
10
|
+
}
|
|
11
|
+
declare const __VLS_export: import("vue").DefineComponent<AutoFormRendererArrayProps, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<AutoFormRendererArrayProps> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
12
|
+
declare const _default: typeof __VLS_export;
|
|
13
|
+
export default _default;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { z } from 'zod';
|
|
2
|
+
import type { AutoFormField } from '../../../types/auto-form';
|
|
3
|
+
import type { AnyObject } from '@movk/core';
|
|
4
|
+
interface AutoFormRendererChildrenProps {
|
|
5
|
+
schema: z.ZodObject;
|
|
6
|
+
fields: AutoFormField[];
|
|
7
|
+
extraProps?: AnyObject;
|
|
8
|
+
}
|
|
9
|
+
declare const __VLS_export: import("vue").DefineComponent<AutoFormRendererChildrenProps, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<AutoFormRendererChildrenProps> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
10
|
+
declare const _default: typeof __VLS_export;
|
|
11
|
+
export default _default;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
<script setup>
|
|
2
|
+
import { computed } from "vue";
|
|
3
|
+
import { classifyFields } from "../fields";
|
|
4
|
+
import AutoFormRendererField from "./Field.vue";
|
|
5
|
+
import AutoFormRendererArray from "./Array.vue";
|
|
6
|
+
import AutoFormRendererLayout from "./Layout.vue";
|
|
7
|
+
import AutoFormRendererNested from "./Nested.vue";
|
|
8
|
+
const props = defineProps({
|
|
9
|
+
schema: { type: null, required: true },
|
|
10
|
+
fields: { type: Array, required: true },
|
|
11
|
+
extraProps: { type: Object, required: false }
|
|
12
|
+
});
|
|
13
|
+
const fieldTypeMap = computed(() => {
|
|
14
|
+
const { leafFields, arrayFields, layoutFields } = classifyFields(props.fields);
|
|
15
|
+
const map = /* @__PURE__ */ new Map();
|
|
16
|
+
for (const f of leafFields) map.set(f, "leaf");
|
|
17
|
+
for (const f of arrayFields) map.set(f, "array");
|
|
18
|
+
for (const f of layoutFields) map.set(f, "layout");
|
|
19
|
+
return map;
|
|
20
|
+
});
|
|
21
|
+
</script>
|
|
22
|
+
|
|
23
|
+
<template>
|
|
24
|
+
<template v-for="childField in props.fields" :key="childField.path">
|
|
25
|
+
<AutoFormRendererField
|
|
26
|
+
v-if="fieldTypeMap.get(childField) === 'leaf'"
|
|
27
|
+
:field="childField"
|
|
28
|
+
:schema="props.schema"
|
|
29
|
+
:extra-props="props.extraProps"
|
|
30
|
+
/>
|
|
31
|
+
<AutoFormRendererArray
|
|
32
|
+
v-else-if="fieldTypeMap.get(childField) === 'array'"
|
|
33
|
+
:field="childField"
|
|
34
|
+
:schema="props.schema"
|
|
35
|
+
:extra-props="props.extraProps"
|
|
36
|
+
/>
|
|
37
|
+
<AutoFormRendererLayout
|
|
38
|
+
v-else-if="fieldTypeMap.get(childField) === 'layout'"
|
|
39
|
+
:field="childField"
|
|
40
|
+
:schema="props.schema"
|
|
41
|
+
:extra-props="props.extraProps"
|
|
42
|
+
/>
|
|
43
|
+
<AutoFormRendererNested
|
|
44
|
+
v-else
|
|
45
|
+
:field="childField"
|
|
46
|
+
:schema="props.schema"
|
|
47
|
+
:extra-props="props.extraProps"
|
|
48
|
+
/>
|
|
49
|
+
</template>
|
|
50
|
+
</template>
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { z } from 'zod';
|
|
2
|
+
import type { AutoFormField } from '../../../types/auto-form';
|
|
3
|
+
import type { AnyObject } from '@movk/core';
|
|
4
|
+
interface AutoFormRendererChildrenProps {
|
|
5
|
+
schema: z.ZodObject;
|
|
6
|
+
fields: AutoFormField[];
|
|
7
|
+
extraProps?: AnyObject;
|
|
8
|
+
}
|
|
9
|
+
declare const __VLS_export: import("vue").DefineComponent<AutoFormRendererChildrenProps, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<AutoFormRendererChildrenProps> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
10
|
+
declare const _default: typeof __VLS_export;
|
|
11
|
+
export default _default;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { z } from 'zod';
|
|
2
|
+
import type { AnyObject } from '@movk/core';
|
|
3
|
+
import type { AutoFormField } from '../../../types';
|
|
4
|
+
interface AutoFormFieldProps {
|
|
5
|
+
schema: z.ZodObject;
|
|
6
|
+
field: AutoFormField;
|
|
7
|
+
extraProps?: AnyObject;
|
|
8
|
+
}
|
|
9
|
+
declare const __VLS_export: import("vue").DefineComponent<AutoFormFieldProps, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<AutoFormFieldProps> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
10
|
+
declare const _default: typeof __VLS_export;
|
|
11
|
+
export default _default;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
<script setup>
|
|
2
|
+
import { UFormField } from "#components";
|
|
3
|
+
import { computed } from "vue";
|
|
4
|
+
import { useAutoFormInjector } from "../provider";
|
|
5
|
+
import { VNodeRender } from "../reactive";
|
|
6
|
+
const props = defineProps({
|
|
7
|
+
schema: { type: null, required: true },
|
|
8
|
+
field: { type: Object, required: true },
|
|
9
|
+
extraProps: { type: Object, required: false }
|
|
10
|
+
});
|
|
11
|
+
const {
|
|
12
|
+
resolveFieldProp,
|
|
13
|
+
renderControl,
|
|
14
|
+
createSlotResolver,
|
|
15
|
+
createFormFieldSlots,
|
|
16
|
+
createSlotProps
|
|
17
|
+
} = useAutoFormInjector();
|
|
18
|
+
const slotResolver = computed(() => createSlotResolver(props.field, props.extraProps));
|
|
19
|
+
const fieldProps = computed(() => ({
|
|
20
|
+
hidden: resolveFieldProp(props.field, "hidden", void 0, props.extraProps),
|
|
21
|
+
as: resolveFieldProp(props.field, "as", void 0, props.extraProps),
|
|
22
|
+
name: resolveFieldProp(props.field, "name", props.field.path, props.extraProps),
|
|
23
|
+
errorPattern: resolveFieldProp(props.field, "errorPattern", void 0, props.extraProps),
|
|
24
|
+
label: resolveFieldProp(props.field, "label", void 0, props.extraProps),
|
|
25
|
+
description: resolveFieldProp(props.field, "description", void 0, props.extraProps),
|
|
26
|
+
help: resolveFieldProp(props.field, "help", void 0, props.extraProps),
|
|
27
|
+
error: resolveFieldProp(props.field, "error", void 0, props.extraProps),
|
|
28
|
+
hint: resolveFieldProp(props.field, "hint", void 0, props.extraProps),
|
|
29
|
+
size: resolveFieldProp(props.field, "size", void 0, props.extraProps),
|
|
30
|
+
required: resolveFieldProp(props.field, "required", void 0, props.extraProps),
|
|
31
|
+
eagerValidation: resolveFieldProp(props.field, "eagerValidation", void 0, props.extraProps),
|
|
32
|
+
validateOnInputDelay: resolveFieldProp(props.field, "validateOnInputDelay", void 0, props.extraProps),
|
|
33
|
+
orientation: resolveFieldProp(props.field, "orientation", void 0, props.extraProps),
|
|
34
|
+
class: resolveFieldProp(props.field, "class", void 0, props.extraProps),
|
|
35
|
+
ui: resolveFieldProp(props.field, "ui", void 0, props.extraProps)
|
|
36
|
+
}));
|
|
37
|
+
const formFieldSlots = computed(() => createFormFieldSlots(props.field, slotResolver.value, props.extraProps));
|
|
38
|
+
const renderedControl = computed(() => renderControl(props.field, props.extraProps));
|
|
39
|
+
const defaultSlotProps = computed(() => createSlotProps(props.field, props.extraProps));
|
|
40
|
+
</script>
|
|
41
|
+
|
|
42
|
+
<template>
|
|
43
|
+
<UFormField v-show="!fieldProps.hidden" v-bind="fieldProps">
|
|
44
|
+
<template v-for="(slotComponent, slotName) in formFieldSlots" :key="slotName" #[slotName]="slotData">
|
|
45
|
+
<VNodeRender :node="slotComponent(slotData)" />
|
|
46
|
+
</template>
|
|
47
|
+
|
|
48
|
+
<template #default="{ error }">
|
|
49
|
+
<VNodeRender
|
|
50
|
+
v-if="slotResolver.hasSlot('default')"
|
|
51
|
+
:node="slotResolver.renderSlot('default', { ...defaultSlotProps, error })"
|
|
52
|
+
/>
|
|
53
|
+
<VNodeRender v-else :node="renderedControl" />
|
|
54
|
+
</template>
|
|
55
|
+
</UFormField>
|
|
56
|
+
</template>
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { z } from 'zod';
|
|
2
|
+
import type { AnyObject } from '@movk/core';
|
|
3
|
+
import type { AutoFormField } from '../../../types';
|
|
4
|
+
interface AutoFormFieldProps {
|
|
5
|
+
schema: z.ZodObject;
|
|
6
|
+
field: AutoFormField;
|
|
7
|
+
extraProps?: AnyObject;
|
|
8
|
+
}
|
|
9
|
+
declare const __VLS_export: import("vue").DefineComponent<AutoFormFieldProps, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<AutoFormFieldProps> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
10
|
+
declare const _default: typeof __VLS_export;
|
|
11
|
+
export default _default;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { z } from 'zod';
|
|
2
|
+
import type { AutoFormField } from '../../../types/auto-form';
|
|
3
|
+
import type { AnyObject } from '@movk/core';
|
|
4
|
+
interface AutoFormRendererLayoutProps {
|
|
5
|
+
schema: z.ZodObject;
|
|
6
|
+
field: AutoFormField;
|
|
7
|
+
extraProps?: AnyObject;
|
|
8
|
+
}
|
|
9
|
+
declare const _default: typeof __VLS_export;
|
|
10
|
+
export default _default;
|
|
11
|
+
declare const __VLS_export: import("vue").DefineComponent<AutoFormRendererLayoutProps, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<AutoFormRendererLayoutProps> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
|
|
3
|
+
</script>
|
|
4
|
+
|
|
5
|
+
<script setup>
|
|
6
|
+
import { computed, resolveDynamicComponent } from "vue";
|
|
7
|
+
import { resolveReactiveValue } from "../reactive";
|
|
8
|
+
import { useAutoFormInjector } from "../provider";
|
|
9
|
+
import AutoFormRendererChildren from "./Children.vue";
|
|
10
|
+
const props = defineProps({
|
|
11
|
+
schema: { type: null, required: true },
|
|
12
|
+
field: { type: Object, required: true },
|
|
13
|
+
extraProps: { type: Object, required: false }
|
|
14
|
+
});
|
|
15
|
+
const { createFieldContext, resolveFieldProp } = useAutoFormInjector();
|
|
16
|
+
function getFieldName(f) {
|
|
17
|
+
return f.path.split(".").pop() || f.path;
|
|
18
|
+
}
|
|
19
|
+
const visibleFields = computed(() => {
|
|
20
|
+
if (!props.field.children?.length) return [];
|
|
21
|
+
return props.field.children.filter(
|
|
22
|
+
(f) => f && (f.meta?.if === void 0 || resolveFieldProp(f, "if") === true)
|
|
23
|
+
);
|
|
24
|
+
});
|
|
25
|
+
const layoutComponent = computed(() => {
|
|
26
|
+
if (!props.field.meta?.layout?.component) {
|
|
27
|
+
return "div";
|
|
28
|
+
}
|
|
29
|
+
return resolveDynamicComponent(props.field.meta.layout.component);
|
|
30
|
+
});
|
|
31
|
+
const layoutProps = computed(() => {
|
|
32
|
+
const config = props.field.meta.layout;
|
|
33
|
+
if (!config) return {};
|
|
34
|
+
const context = createFieldContext(props.field);
|
|
35
|
+
return {
|
|
36
|
+
...resolveReactiveValue(config.props, context),
|
|
37
|
+
...config.class && { class: resolveReactiveValue(config.class, context) }
|
|
38
|
+
};
|
|
39
|
+
});
|
|
40
|
+
const layoutSlots = computed(() => {
|
|
41
|
+
const config = props.field.meta.layout;
|
|
42
|
+
if (!config?.slots) return {};
|
|
43
|
+
const context = createFieldContext(props.field);
|
|
44
|
+
const resolvedSlots = resolveReactiveValue(config.slots, context);
|
|
45
|
+
return Object.entries(resolvedSlots).reduce((acc, [name, fn]) => {
|
|
46
|
+
if (typeof fn === "function") acc[name] = fn;
|
|
47
|
+
return acc;
|
|
48
|
+
}, {});
|
|
49
|
+
});
|
|
50
|
+
const fieldsBySlot = computed(() => {
|
|
51
|
+
const config = props.field.meta.layout;
|
|
52
|
+
if (!config || !visibleFields.value.length) return /* @__PURE__ */ new Map();
|
|
53
|
+
const context = createFieldContext(props.field);
|
|
54
|
+
let slotMapping;
|
|
55
|
+
if (config.fieldSlots) {
|
|
56
|
+
const resolved = resolveReactiveValue(config.fieldSlots, context);
|
|
57
|
+
slotMapping = /* @__PURE__ */ new Map();
|
|
58
|
+
for (const [name, slot] of Object.entries(resolved)) {
|
|
59
|
+
if (slot && typeof slot === "string") slotMapping.set(name, slot);
|
|
60
|
+
}
|
|
61
|
+
} else if (config.fieldSlot) {
|
|
62
|
+
const slot = resolveReactiveValue(config.fieldSlot, context);
|
|
63
|
+
if (slot && typeof slot === "string") {
|
|
64
|
+
slotMapping = /* @__PURE__ */ new Map();
|
|
65
|
+
for (const f of visibleFields.value) {
|
|
66
|
+
slotMapping.set(getFieldName(f), slot);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return visibleFields.value.reduce((map, f) => {
|
|
71
|
+
const slot = slotMapping?.get(getFieldName(f)) || "default";
|
|
72
|
+
if (!map.has(slot)) map.set(slot, []);
|
|
73
|
+
map.get(slot).push(f);
|
|
74
|
+
return map;
|
|
75
|
+
}, /* @__PURE__ */ new Map());
|
|
76
|
+
});
|
|
77
|
+
</script>
|
|
78
|
+
|
|
79
|
+
<template>
|
|
80
|
+
<component :is="layoutComponent" v-bind="layoutProps" v-if="visibleFields.length">
|
|
81
|
+
<template v-for="(slotFn, slotName) in layoutSlots" :key="`slot-${slotName}`" #[slotName]>
|
|
82
|
+
<component :is="slotFn" />
|
|
83
|
+
</template>
|
|
84
|
+
|
|
85
|
+
<template v-for="[slotName, fields] in fieldsBySlot.entries()" :key="`fields-${slotName}`" #[slotName]>
|
|
86
|
+
<AutoFormRendererChildren :fields="fields" :schema="props.schema" :extra-props="props.extraProps" />
|
|
87
|
+
</template>
|
|
88
|
+
</component>
|
|
89
|
+
</template>
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { z } from 'zod';
|
|
2
|
+
import type { AutoFormField } from '../../../types/auto-form';
|
|
3
|
+
import type { AnyObject } from '@movk/core';
|
|
4
|
+
interface AutoFormRendererLayoutProps {
|
|
5
|
+
schema: z.ZodObject;
|
|
6
|
+
field: AutoFormField;
|
|
7
|
+
extraProps?: AnyObject;
|
|
8
|
+
}
|
|
9
|
+
declare const _default: typeof __VLS_export;
|
|
10
|
+
export default _default;
|
|
11
|
+
declare const __VLS_export: import("vue").DefineComponent<AutoFormRendererLayoutProps, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<AutoFormRendererLayoutProps> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { z } from 'zod';
|
|
2
|
+
import type { AutoFormField } from '../../../types';
|
|
3
|
+
import type { AnyObject } from '@movk/core';
|
|
4
|
+
interface AutoFormRendererNestedProps {
|
|
5
|
+
schema: z.ZodObject;
|
|
6
|
+
field: AutoFormField;
|
|
7
|
+
extraProps?: AnyObject;
|
|
8
|
+
}
|
|
9
|
+
declare const __VLS_export: import("vue").DefineComponent<AutoFormRendererNestedProps, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<AutoFormRendererNestedProps> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
10
|
+
declare const _default: typeof __VLS_export;
|
|
11
|
+
export default _default;
|