@movk/nuxt 1.8.2 → 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 +21 -24
- 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 +9 -13
- 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 -12
- package/dist/runtime/domains/api/interceptors/response.js +34 -20
- 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 +12 -0
- package/dist/runtime/domains/api/session.js +9 -0
- 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.C7xx2FPO.mjs → nuxt.CbmfnBRt.mjs} +92 -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 +40 -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 -49
- package/dist/runtime/domains/api/transfer.d.ts +0 -69
- package/dist/runtime/domains/api/transfer.js +0 -82
- 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
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
function isEmpty(value) {
|
|
2
|
+
return value === void 0 || value === null || typeof value === "string" && value.trim() === "";
|
|
3
|
+
}
|
|
4
|
+
export function cleanSearchPayload(data) {
|
|
5
|
+
return Object.fromEntries(
|
|
6
|
+
Object.entries(data).filter(([, value]) => !isEmpty(value)).map(([key, value]) => [key, typeof value === "string" ? value.trim() : value])
|
|
7
|
+
);
|
|
8
|
+
}
|
|
9
|
+
export function serializeSearchQuery(state) {
|
|
10
|
+
return Object.fromEntries(
|
|
11
|
+
Object.entries(state).filter(([, value]) => !isEmpty(value)).map(([key, value]) => {
|
|
12
|
+
if (Array.isArray(value)) return [key, value.map(String)];
|
|
13
|
+
if (typeof value === "object") return [key, JSON.stringify(value)];
|
|
14
|
+
return [key, String(value)];
|
|
15
|
+
})
|
|
16
|
+
);
|
|
17
|
+
}
|
|
18
|
+
function coreType(schema) {
|
|
19
|
+
let current = schema;
|
|
20
|
+
while (current?._zod?.def?.innerType) current = current._zod.def.innerType;
|
|
21
|
+
return current?._zod?.def?.type;
|
|
22
|
+
}
|
|
23
|
+
function parseValue(raw, type) {
|
|
24
|
+
const values = (Array.isArray(raw) ? raw : [raw]).filter((v) => v !== null);
|
|
25
|
+
const first = values[0];
|
|
26
|
+
if (first === void 0) return void 0;
|
|
27
|
+
switch (type) {
|
|
28
|
+
case "array":
|
|
29
|
+
return values;
|
|
30
|
+
case "number": {
|
|
31
|
+
const number = Number(first);
|
|
32
|
+
return Number.isNaN(number) ? void 0 : number;
|
|
33
|
+
}
|
|
34
|
+
case "boolean":
|
|
35
|
+
return first === "true" ? true : first === "false" ? false : void 0;
|
|
36
|
+
case "string":
|
|
37
|
+
case "enum":
|
|
38
|
+
return first;
|
|
39
|
+
default:
|
|
40
|
+
try {
|
|
41
|
+
return JSON.parse(first);
|
|
42
|
+
} catch {
|
|
43
|
+
return type === void 0 ? first : void 0;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
export function parseSearchQuery(query, schema) {
|
|
48
|
+
const shape = schema.shape;
|
|
49
|
+
return Object.fromEntries(
|
|
50
|
+
Object.entries(query).flatMap(([key, raw]) => {
|
|
51
|
+
const fieldSchema = shape[key];
|
|
52
|
+
if (!fieldSchema || raw === void 0) return [];
|
|
53
|
+
const value = parseValue(raw, coreType(fieldSchema));
|
|
54
|
+
return value === void 0 ? [] : [[key, value]];
|
|
55
|
+
})
|
|
56
|
+
);
|
|
57
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type { ComputedRef, Ref } from 'vue';
|
|
2
|
+
import type { ButtonProps } from '@nuxt/ui';
|
|
3
|
+
import type { z } from 'zod';
|
|
4
|
+
import type { AutoFormControls, AutoFormField } from '../../types/auto-form';
|
|
5
|
+
import type { ZodAutoFormFieldMeta } from '../../types/zod';
|
|
6
|
+
type FormState = Record<string, any>;
|
|
7
|
+
export interface AutoFormCoreOptions {
|
|
8
|
+
schema: () => z.ZodObject | undefined;
|
|
9
|
+
controls: () => AutoFormControls | undefined;
|
|
10
|
+
globalMeta: () => ZodAutoFormFieldMeta | undefined;
|
|
11
|
+
/** 字段被 `if` 隐藏时如何处理其值 */
|
|
12
|
+
hiddenValue: () => 'keep' | 'clear' | undefined;
|
|
13
|
+
model: Ref<FormState>;
|
|
14
|
+
slots: Record<string, any>;
|
|
15
|
+
addButtonProps?: () => ButtonProps | undefined;
|
|
16
|
+
}
|
|
17
|
+
/** AutoForm 与 SearchForm 共用的字段解析、可见性、校验 schema、基线与 reset/clear 语义 */
|
|
18
|
+
export declare function useAutoFormCore(options: AutoFormCoreOptions): {
|
|
19
|
+
provider: {
|
|
20
|
+
addButtonProps: ComputedRef<ButtonProps | undefined>;
|
|
21
|
+
isFieldVisible: (field: AutoFormField) => boolean;
|
|
22
|
+
createFieldContext: (field: AutoFormField, extraProps?: Record<string, any>) => import("../../types").ResolvedAutoFormFieldContext;
|
|
23
|
+
createSlotProps: (field: AutoFormField, extraProps?: Record<string, any>) => import("../../types").ResolvedAutoFormFieldContext;
|
|
24
|
+
resolveFieldProp: {
|
|
25
|
+
<K extends keyof import("../../types").AutoFormMergeMeta>(field: AutoFormField, prop: K, defaultValue?: NonNullable<import("../../types").AutoFormMergeMeta[K]> extends infer T ? T extends NonNullable<import("../../types").AutoFormMergeMeta[K]> ? T extends import("vue").MaybeRefOrGetter<infer V> | ((ctx: any) => infer V) ? V : T : never : never, extraProps?: Record<string, any>): (NonNullable<import("../../types").AutoFormMergeMeta[K]> extends infer T_1 ? T_1 extends NonNullable<import("../../types").AutoFormMergeMeta[K]> ? T_1 extends import("vue").MaybeRefOrGetter<infer V> | ((ctx: any) => infer V) ? V : T_1 : never : never) | undefined;
|
|
26
|
+
<T>(field: AutoFormField, prop: keyof import("../../types").AutoFormMergeMeta, defaultValue?: T, extraProps?: Record<string, any>): T | undefined;
|
|
27
|
+
};
|
|
28
|
+
renderFieldSlot: (fn?: (props?: any) => any, slotProps?: any) => any;
|
|
29
|
+
getResolvedFieldSlots: (field: AutoFormField, extraProps?: Record<string, any>) => Record<string, ((props?: any) => any) | undefined> | undefined;
|
|
30
|
+
renderControl: (field: AutoFormField, extraProps?: Record<string, any>, overrides?: Record<string, unknown>) => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
|
|
31
|
+
[key: string]: any;
|
|
32
|
+
}> | null;
|
|
33
|
+
createSlotResolver: (field: AutoFormField, extraProps?: Record<string, any>) => {
|
|
34
|
+
hasSlot(name: string): boolean;
|
|
35
|
+
renderSlot(name: string, slotProps: any): any;
|
|
36
|
+
};
|
|
37
|
+
createFormFieldSlots: (field: AutoFormField, slotResolver: ReturnType<(field: AutoFormField, extraProps?: Record<string, any>) => {
|
|
38
|
+
hasSlot(name: string): boolean;
|
|
39
|
+
renderSlot(name: string, slotProps: any): any;
|
|
40
|
+
}>, extraProps?: Record<string, any>) => Record<string, any>;
|
|
41
|
+
createCollapsibleEnhancer: (fieldSource: import("vue").MaybeRefOrGetter<AutoFormField>, extraPropsSource?: import("vue").MaybeRefOrGetter<Record<string, any> | undefined>) => {
|
|
42
|
+
collapsibleConfig: ComputedRef<import("../../types").AutoFormNestedCollapsible | undefined>;
|
|
43
|
+
shouldShowCollapsible: ComputedRef<boolean>;
|
|
44
|
+
isHidden: ComputedRef<boolean | undefined>;
|
|
45
|
+
enhancedField: ComputedRef<AutoFormField>;
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
fields: ComputedRef<AutoFormField[]>;
|
|
49
|
+
visibleFields: ComputedRef<AutoFormField[]>;
|
|
50
|
+
isFieldVisible: (field: AutoFormField) => boolean;
|
|
51
|
+
pureSchema: ComputedRef<z.ZodObject<any, any> | undefined>;
|
|
52
|
+
validationSchema: ComputedRef<z.ZodObject<any, any> | undefined>;
|
|
53
|
+
resolvedButtonSize: ComputedRef<"xs" | "sm" | "md" | "lg" | "xl" | undefined>;
|
|
54
|
+
setBaseline: (value?: FormState) => void;
|
|
55
|
+
reset: () => FormState;
|
|
56
|
+
clear: () => FormState;
|
|
57
|
+
dirtyFields: ComputedRef<string[]>;
|
|
58
|
+
isDirty: ComputedRef<boolean>;
|
|
59
|
+
getFieldValue: (path: string) => unknown;
|
|
60
|
+
setFieldValue: (path: string, value: unknown) => void;
|
|
61
|
+
};
|
|
62
|
+
export {};
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { computed, onMounted, shallowRef, toRaw, unref, watch } from "vue";
|
|
2
|
+
import { deepClone, getPath, isDeepEqual, isFunction, setPath } from "@movk/core";
|
|
3
|
+
import { useAutoFormProvider } from "./provider.js";
|
|
4
|
+
import { applyFieldDefaults, isLeafField } from "./fields.js";
|
|
5
|
+
import { extractPureSchema, introspectSchema, omitPaths } from "./schema.js";
|
|
6
|
+
import { DEFAULT_CONTROLS } from "./controls.js";
|
|
7
|
+
import { AUTOFORM_META } from "./constants.js";
|
|
8
|
+
import { useZodFormSchema } from "../zod/sync.js";
|
|
9
|
+
function collectHiddenPaths(fields, isVisible) {
|
|
10
|
+
return fields.flatMap((field) => {
|
|
11
|
+
const isLayout = field.meta?.type === AUTOFORM_META.LAYOUT_KEY;
|
|
12
|
+
if (!isVisible(field)) {
|
|
13
|
+
return isLayout ? (field.children ?? []).map((child) => child.path) : [field.path];
|
|
14
|
+
}
|
|
15
|
+
return field.children ? collectHiddenPaths(field.children, isVisible) : [];
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
function collectValuePaths(fields) {
|
|
19
|
+
return fields.flatMap((field) => {
|
|
20
|
+
const isContainer = field.meta?.type === AUTOFORM_META.LAYOUT_KEY || !isLeafField(field) && field.meta?.type !== "array";
|
|
21
|
+
return isContainer && field.children ? collectValuePaths(field.children) : [field.path];
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
export function useAutoFormCore(options) {
|
|
25
|
+
const { model, slots } = options;
|
|
26
|
+
const provider = useAutoFormProvider(model, slots, { addButtonProps: options.addButtonProps });
|
|
27
|
+
const { resolveFieldProp, isFieldVisible } = provider;
|
|
28
|
+
const controlsMapping = computed(() => ({ ...DEFAULT_CONTROLS, ...options.controls() }));
|
|
29
|
+
const fields = computed(() => {
|
|
30
|
+
const schema = options.schema();
|
|
31
|
+
return schema ? introspectSchema(schema, controlsMapping.value, "", options.globalMeta()) : [];
|
|
32
|
+
});
|
|
33
|
+
const visibleFields = computed(() => fields.value.filter(isFieldVisible));
|
|
34
|
+
const hiddenPaths = computed(() => collectHiddenPaths(fields.value, isFieldVisible));
|
|
35
|
+
const pureSchema = computed(() => {
|
|
36
|
+
const schema = options.schema();
|
|
37
|
+
return schema ? extractPureSchema(schema) : void 0;
|
|
38
|
+
});
|
|
39
|
+
const validationSchema = useZodFormSchema(() => pureSchema.value && omitPaths(pureSchema.value, hiddenPaths.value));
|
|
40
|
+
const resolvedButtonSize = computed(() => {
|
|
41
|
+
const size = options.globalMeta()?.size;
|
|
42
|
+
if (size === void 0 || isFunction(size)) return void 0;
|
|
43
|
+
return unref(size);
|
|
44
|
+
});
|
|
45
|
+
const baseline = shallowRef(deepClone(toRaw(model.value ?? {})));
|
|
46
|
+
function setBaseline(value = model.value) {
|
|
47
|
+
baseline.value = deepClone(toRaw(value));
|
|
48
|
+
}
|
|
49
|
+
function withDefaults(state) {
|
|
50
|
+
const next = deepClone(state);
|
|
51
|
+
applyFieldDefaults(fields.value, next);
|
|
52
|
+
return next;
|
|
53
|
+
}
|
|
54
|
+
function replaceState(next) {
|
|
55
|
+
const target = model.value;
|
|
56
|
+
for (const key of Object.keys(target)) Reflect.deleteProperty(target, key);
|
|
57
|
+
Object.assign(target, next);
|
|
58
|
+
return deepClone(next);
|
|
59
|
+
}
|
|
60
|
+
const reset = () => replaceState(withDefaults(baseline.value));
|
|
61
|
+
const clear = () => replaceState(withDefaults({}));
|
|
62
|
+
const valuePaths = computed(() => collectValuePaths(fields.value));
|
|
63
|
+
const dirtyFields = computed(() => valuePaths.value.filter(
|
|
64
|
+
(path) => !isDeepEqual(getPath(model.value, path), getPath(baseline.value, path))
|
|
65
|
+
));
|
|
66
|
+
const isDirty = computed(() => dirtyFields.value.length > 0);
|
|
67
|
+
watch(hiddenPaths, (paths, previous = []) => {
|
|
68
|
+
const added = paths.filter((path) => !previous.includes(path));
|
|
69
|
+
if (!added.length) return;
|
|
70
|
+
for (const path of added) {
|
|
71
|
+
const field = findField(fields.value, path);
|
|
72
|
+
const policy = (field && resolveFieldProp(field, "hiddenValue")) ?? options.hiddenValue() ?? "keep";
|
|
73
|
+
if (policy === "clear" && getPath(model.value, path) !== void 0) setPath(model.value, path, void 0);
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
watch(fields, (value) => applyFieldDefaults(value, model.value), { flush: "post" });
|
|
77
|
+
onMounted(() => {
|
|
78
|
+
applyFieldDefaults(fields.value, model.value);
|
|
79
|
+
setBaseline();
|
|
80
|
+
});
|
|
81
|
+
const getFieldValue = (path) => getPath(model.value, path);
|
|
82
|
+
const setFieldValue = (path, value) => {
|
|
83
|
+
setPath(model.value, path, value);
|
|
84
|
+
};
|
|
85
|
+
return {
|
|
86
|
+
provider,
|
|
87
|
+
fields,
|
|
88
|
+
visibleFields,
|
|
89
|
+
isFieldVisible,
|
|
90
|
+
pureSchema,
|
|
91
|
+
validationSchema,
|
|
92
|
+
resolvedButtonSize,
|
|
93
|
+
setBaseline,
|
|
94
|
+
reset,
|
|
95
|
+
clear,
|
|
96
|
+
dirtyFields,
|
|
97
|
+
isDirty,
|
|
98
|
+
getFieldValue,
|
|
99
|
+
setFieldValue
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
function findField(fields, path) {
|
|
103
|
+
for (const field of fields) {
|
|
104
|
+
if (field.path === path) return field;
|
|
105
|
+
const found = field.children && findField(field.children, path);
|
|
106
|
+
if (found) return found;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { InferInput } from '@nuxt/ui';
|
|
2
|
+
import type { z } from 'zod';
|
|
3
|
+
import type { SearchFormQuerySync } from '../../types/auto-form/search-form';
|
|
4
|
+
interface SearchQueryOptions<S extends z.ZodObject> {
|
|
5
|
+
sync: () => boolean | SearchFormQuerySync<S>;
|
|
6
|
+
schema: () => z.ZodObject | undefined;
|
|
7
|
+
state: () => Partial<InferInput<S>>;
|
|
8
|
+
onRestore: (state: Partial<InferInput<S>>) => void;
|
|
9
|
+
}
|
|
10
|
+
export declare function useSearchQuerySync<S extends z.ZodObject>(options: SearchQueryOptions<S>): (state: Partial<InferInput<S>>) => Promise<void>;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { deepClone, isDeepEqual } from "@movk/core";
|
|
2
|
+
import { onMounted, toRaw, watch } from "vue";
|
|
3
|
+
import { useRouter } from "#imports";
|
|
4
|
+
import { supportsSearchQuery } from "#build/movk-router";
|
|
5
|
+
import { cleanSearchPayload, parseSearchQuery, serializeSearchQuery } from "./search-query.js";
|
|
6
|
+
function pickQuery(query, keys) {
|
|
7
|
+
return Object.fromEntries(Object.entries(query).filter(([key, value]) => keys.has(key) && value !== void 0));
|
|
8
|
+
}
|
|
9
|
+
export function useSearchQuerySync(options) {
|
|
10
|
+
const router = supportsSearchQuery ? useRouter() : void 0;
|
|
11
|
+
const pending = /* @__PURE__ */ new Set();
|
|
12
|
+
const getSync = () => options.sync() || void 0;
|
|
13
|
+
onMounted(() => {
|
|
14
|
+
if (!router) {
|
|
15
|
+
if (import.meta.dev) {
|
|
16
|
+
watch(getSync, (enabled) => {
|
|
17
|
+
if (enabled) console.warn("[SearchForm] syncQuery requires Nuxt routing or Vue Router.");
|
|
18
|
+
}, { immediate: true });
|
|
19
|
+
}
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
const baseline = deepClone(toRaw(options.state()));
|
|
23
|
+
let previous;
|
|
24
|
+
watch([getSync, options.schema, () => router.currentRoute.value.query], ([sync, schema, query]) => {
|
|
25
|
+
if (!sync || !schema) {
|
|
26
|
+
previous = void 0;
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
const keys = new Set(Object.keys(schema.shape));
|
|
30
|
+
const owned = pickQuery(query, keys);
|
|
31
|
+
if (isDeepEqual(previous, owned)) return;
|
|
32
|
+
const initial = previous === void 0;
|
|
33
|
+
previous = owned;
|
|
34
|
+
if ([...pending].some((expected) => isDeepEqual(expected, owned))) return;
|
|
35
|
+
const parsed = sync !== true && sync.parse ? sync.parse(owned) : parseSearchQuery(owned, schema);
|
|
36
|
+
if (initial && !Object.keys(parsed).length) return;
|
|
37
|
+
const state = options.state();
|
|
38
|
+
for (const key of keys) {
|
|
39
|
+
if (Object.hasOwn(parsed, key)) state[key] = parsed[key];
|
|
40
|
+
else if (Object.hasOwn(baseline, key)) state[key] = deepClone(baseline[key]);
|
|
41
|
+
else Reflect.deleteProperty(state, key);
|
|
42
|
+
}
|
|
43
|
+
options.onRestore(Object.fromEntries([...keys].map((key) => [key, state[key]])));
|
|
44
|
+
}, { immediate: true, flush: "sync" });
|
|
45
|
+
});
|
|
46
|
+
return async (state) => {
|
|
47
|
+
const sync = getSync();
|
|
48
|
+
const schema = options.schema();
|
|
49
|
+
if (!router || !sync || !schema) return;
|
|
50
|
+
const keys = new Set(Object.keys(schema.shape));
|
|
51
|
+
const current = router.currentRoute.value;
|
|
52
|
+
const others = Object.fromEntries(Object.entries(current.query).filter(([key]) => !keys.has(key)));
|
|
53
|
+
const serialize = sync !== true && sync.serialize ? sync.serialize : serializeSearchQuery;
|
|
54
|
+
const owned = pickQuery(serialize(cleanSearchPayload(state)), keys);
|
|
55
|
+
const expected = pickQuery(router.resolve({ query: owned }).query, keys);
|
|
56
|
+
pending.add(expected);
|
|
57
|
+
try {
|
|
58
|
+
const method = sync !== true && sync.replace === false ? "push" : "replace";
|
|
59
|
+
await router[method]({ query: { ...others, ...owned }, hash: current.hash });
|
|
60
|
+
} finally {
|
|
61
|
+
pending.delete(expected);
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { MovkTranslator } from '../../../composables/useMovkLocale';
|
|
1
2
|
import type { ColumnDef, ColumnMeta, ColumnPinningState, ColumnSizingState, HeaderContext, VisibilityState } from '@tanstack/vue-table';
|
|
2
3
|
import type { VNode } from 'vue';
|
|
3
4
|
import type { DataTableDensityPreset, DataTableSizePreset, DataTableTreeSelectionStrategy } from '../../../types/data-table';
|
|
@@ -52,4 +53,5 @@ export interface ResolveContext<T> {
|
|
|
52
53
|
subRowSelection?: boolean;
|
|
53
54
|
nextGroupId: () => number;
|
|
54
55
|
allColumnIds: string[];
|
|
56
|
+
t: MovkTranslator;
|
|
55
57
|
}
|
|
@@ -15,5 +15,5 @@ export const SPECIAL_COLUMN_DEFAULTS = {
|
|
|
15
15
|
"index": { id: "__index", size: 60, align: "center", header: "#", tdClass: "text-muted" },
|
|
16
16
|
"expand": { id: "__expand", size: 60, align: "center" },
|
|
17
17
|
"row-pinning": { id: "__row_pinning", size: 60, align: "center" },
|
|
18
|
-
"actions": { id: "__actions", size: 60,
|
|
18
|
+
"actions": { id: "__actions", size: 60, align: "center" }
|
|
19
19
|
};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
+
import type { MovkTranslator } from '../../../composables/useMovkLocale';
|
|
1
2
|
import type { DataTableColumn } from '../../../types/data-table';
|
|
2
3
|
import type { HeaderSlotMap, ResolvedColumnState } from './constants';
|
|
3
4
|
import type { DataTableProps } from '../../../types/data-table/component';
|
|
4
|
-
export declare function resolveColumns<T>(columns: DataTableColumn<T>[], options: DataTableProps<T>, headerSlots?: HeaderSlotMap<T>): ResolvedColumnState<T>;
|
|
5
|
+
export declare function resolveColumns<T>(columns: DataTableColumn<T>[], options: DataTableProps<T>, t: MovkTranslator, headerSlots?: HeaderSlotMap<T>): ResolvedColumnState<T>;
|
|
@@ -29,7 +29,7 @@ function resolveColumn(col, ctx, inheritedFixed) {
|
|
|
29
29
|
}
|
|
30
30
|
return col;
|
|
31
31
|
}
|
|
32
|
-
export function resolveColumns(columns, options, headerSlots) {
|
|
32
|
+
export function resolveColumns(columns, options, t, headerSlots) {
|
|
33
33
|
let groupCounter = 0;
|
|
34
34
|
const ctx = {
|
|
35
35
|
options,
|
|
@@ -40,7 +40,8 @@ export function resolveColumns(columns, options, headerSlots) {
|
|
|
40
40
|
sizing: {},
|
|
41
41
|
flags: { hasPinning: false, hasResizing: false, hasSort: false, hasExpand: false },
|
|
42
42
|
nextGroupId: () => groupCounter++,
|
|
43
|
-
allColumnIds: []
|
|
43
|
+
allColumnIds: [],
|
|
44
|
+
t
|
|
44
45
|
};
|
|
45
46
|
const columnDefs = columns.map((col) => resolveColumn(col, ctx));
|
|
46
47
|
return {
|
|
@@ -2,8 +2,13 @@ import type { ColumnDef, HeaderContext } from '@tanstack/vue-table';
|
|
|
2
2
|
import type { VNode } from 'vue';
|
|
3
3
|
import type { DataTableDataColumn } from '../../../types/data-table';
|
|
4
4
|
import type { ResolveContext } from './constants';
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
interface HeaderActionFlags {
|
|
6
|
+
sortable: boolean;
|
|
7
|
+
pinable: boolean;
|
|
8
|
+
resizable: boolean;
|
|
9
|
+
}
|
|
10
|
+
export declare function renderHeaderActions<T>(ctx: HeaderContext<T, unknown>, col: Pick<DataTableDataColumn<T>, 'pinButtonProps' | 'sortButtonProps'>, resolveCtx: Pick<ResolveContext<T>, 'options' | 't'>, label: unknown, { sortable, pinable, resizable }: HeaderActionFlags): VNode<import("vue").RendererNode, import("vue").RendererElement, {
|
|
7
11
|
[key: string]: any;
|
|
8
12
|
}>;
|
|
9
13
|
export declare function resolveDataColumn<T>(col: DataTableDataColumn<T>, ctx: ResolveContext<T>, inheritedFixed?: 'left' | 'right'): ColumnDef<T, unknown>;
|
|
14
|
+
export {};
|
|
@@ -68,7 +68,7 @@ function buildSortAction(col, options) {
|
|
|
68
68
|
}
|
|
69
69
|
};
|
|
70
70
|
}
|
|
71
|
-
function buildPinAction(col, options) {
|
|
71
|
+
function buildPinAction(col, options, t) {
|
|
72
72
|
return {
|
|
73
73
|
id: "pin",
|
|
74
74
|
position: "leading",
|
|
@@ -81,7 +81,7 @@ function buildPinAction(col, options) {
|
|
|
81
81
|
"color": pinned ? "primary" : "neutral",
|
|
82
82
|
"class": pinned ? "opacity-100" : "opacity-60 group-hover:opacity-100",
|
|
83
83
|
"icon": pinned ? "i-lucide-pin-off" : "i-lucide-pin",
|
|
84
|
-
"aria-label": pinned ? "
|
|
84
|
+
"aria-label": pinned ? t("dataTable.unpinColumn") : t("dataTable.pinColumn"),
|
|
85
85
|
"onClick": (event) => {
|
|
86
86
|
event.stopPropagation();
|
|
87
87
|
if (pinned === "left") {
|
|
@@ -105,9 +105,10 @@ function buildPinAction(col, options) {
|
|
|
105
105
|
}
|
|
106
106
|
};
|
|
107
107
|
}
|
|
108
|
-
export function renderHeaderActions(ctx, col,
|
|
108
|
+
export function renderHeaderActions(ctx, col, resolveCtx, label, { sortable, pinable, resizable }) {
|
|
109
|
+
const { options, t } = resolveCtx;
|
|
109
110
|
const actions = [];
|
|
110
|
-
if (pinable) actions.push(buildPinAction(col, options));
|
|
111
|
+
if (pinable) actions.push(buildPinAction(col, options, t));
|
|
111
112
|
if (sortable) actions.push(buildSortAction(col, options));
|
|
112
113
|
const leading = actions.filter((a) => a.position === "leading").map((a) => a.render(ctx));
|
|
113
114
|
const trailing = actions.filter((a) => a.position === "trailing").map((a) => a.render(ctx));
|
|
@@ -136,7 +137,11 @@ export function resolveDataColumn(col, ctx, inheritedFixed) {
|
|
|
136
137
|
const headerSlot = ctx.headerSlots?.[`${id}-header`];
|
|
137
138
|
const def = {
|
|
138
139
|
accessorKey: id,
|
|
139
|
-
header: effectiveSortable || effectivePinable || effectiveResizable ? (hctx) => renderHeaderActions(hctx, col,
|
|
140
|
+
header: effectiveSortable || effectivePinable || effectiveResizable ? (hctx) => renderHeaderActions(hctx, col, ctx, headerSlot ? headerSlot(hctx) : col.header ?? id, {
|
|
141
|
+
sortable: effectiveSortable,
|
|
142
|
+
pinable: effectivePinable,
|
|
143
|
+
resizable: effectiveResizable
|
|
144
|
+
}) : headerSlot ? (hctx) => headerSlot(hctx) : col.header ?? id,
|
|
140
145
|
...col.minSize != null && { minSize: col.minSize },
|
|
141
146
|
...col.maxSize != null && { maxSize: col.maxSize },
|
|
142
147
|
...resolvedSize != null && { size: resolvedSize },
|
|
@@ -45,7 +45,11 @@ function buildSpecialColumnDef(col, type, ctx, render) {
|
|
|
45
45
|
const headerSlot = ctx.headerSlots?.[`${id}-header`];
|
|
46
46
|
const resolvedHeader = effectivePinable || effectiveResizable ? (hctx) => {
|
|
47
47
|
const label = headerSlot ? headerSlot(hctx) : isFunction(render.header) ? render.header(hctx) : render.header ?? "";
|
|
48
|
-
return renderHeaderActions(hctx, col,
|
|
48
|
+
return renderHeaderActions(hctx, col, ctx, label, {
|
|
49
|
+
sortable: false,
|
|
50
|
+
pinable: effectivePinable,
|
|
51
|
+
resizable: effectiveResizable
|
|
52
|
+
});
|
|
49
53
|
} : headerSlot ? (hctx) => headerSlot(hctx) : render.header;
|
|
50
54
|
const classMeta = buildClassMeta(density, alignClass, effectiveResizable, defaults.tdClass);
|
|
51
55
|
const checkboxClass = type === "selection" ? {
|
|
@@ -88,7 +92,7 @@ export function resolveSelectionColumn(col, ctx) {
|
|
|
88
92
|
isIndeterminate
|
|
89
93
|
};
|
|
90
94
|
return h(UCheckbox, {
|
|
91
|
-
"aria-label": "
|
|
95
|
+
"aria-label": ctx.t("dataTable.selectAll"),
|
|
92
96
|
"class": "inline-flex",
|
|
93
97
|
"modelValue": isIndeterminate ? "indeterminate" : isAllSelected,
|
|
94
98
|
"onUpdate:modelValue": (value) => hctx.table.toggleAllPageRowsSelected(!!value),
|
|
@@ -106,7 +110,7 @@ export function resolveSelectionColumn(col, ctx) {
|
|
|
106
110
|
isLeafAggregate: true
|
|
107
111
|
};
|
|
108
112
|
return h(UCheckbox, {
|
|
109
|
-
"aria-label": "
|
|
113
|
+
"aria-label": ctx.t("dataTable.selectParentRow"),
|
|
110
114
|
"class": "inline-flex",
|
|
111
115
|
"disabled": true,
|
|
112
116
|
"modelValue": all ? true : some ? "indeterminate" : false,
|
|
@@ -124,7 +128,7 @@ export function resolveSelectionColumn(col, ctx) {
|
|
|
124
128
|
isLeafAggregate: false
|
|
125
129
|
};
|
|
126
130
|
return h(UCheckbox, {
|
|
127
|
-
"aria-label": "
|
|
131
|
+
"aria-label": ctx.t("dataTable.selectRow"),
|
|
128
132
|
"class": "inline-flex",
|
|
129
133
|
"modelValue": isSelected ? true : isIndeterminate ? "indeterminate" : false,
|
|
130
134
|
"onUpdate:modelValue": (value) => cellCtx.row.toggleSelected(!!value),
|
|
@@ -156,7 +160,7 @@ export function resolveExpandColumn(col, ctx) {
|
|
|
156
160
|
"variant": "outline",
|
|
157
161
|
"size": "xs",
|
|
158
162
|
"color": "neutral",
|
|
159
|
-
"aria-label": isAllExpanded ? "
|
|
163
|
+
"aria-label": isAllExpanded ? ctx.t("dataTable.collapseAll") : ctx.t("dataTable.expandAll"),
|
|
160
164
|
"icon": isAllExpanded ? "i-lucide-minus" : "i-lucide-plus",
|
|
161
165
|
"ui": {
|
|
162
166
|
base: "p-0.5 rounded-sm",
|
|
@@ -212,7 +216,7 @@ export function resolveRowPinningColumn(col, ctx) {
|
|
|
212
216
|
"size": "xs",
|
|
213
217
|
"color": pinned ? "primary" : "neutral",
|
|
214
218
|
"icon": "i-lucide-star",
|
|
215
|
-
"aria-label": pinned ? "
|
|
219
|
+
"aria-label": pinned ? ctx.t("dataTable.unpinRow") : ctx.t("dataTable.pinRow"),
|
|
216
220
|
"onClick": (event) => {
|
|
217
221
|
event.stopPropagation();
|
|
218
222
|
if (pinned) {
|
|
@@ -228,7 +232,9 @@ export function resolveRowPinningColumn(col, ctx) {
|
|
|
228
232
|
}
|
|
229
233
|
export function resolveActionsColumn(col, ctx) {
|
|
230
234
|
return buildSpecialColumnDef(col, "actions", ctx, {
|
|
231
|
-
header: col.header ??
|
|
232
|
-
|
|
235
|
+
header: col.header ?? ctx.t("dataTable.actions"),
|
|
236
|
+
// FlexRender 以无 .props 的函数式组件调用 cell,同一 row-key 更新时 Vue 会原地复用 attrs 作为 cellCtx;
|
|
237
|
+
// 浅拷贝打破引用复用,确保 ActionsCell 在行数据更新时重新渲染而非停留在旧行快照。
|
|
238
|
+
cell: (cellCtx) => h(DataTableActionsCell, { col, cellCtx: { ...cellCtx }, options: ctx.options })
|
|
233
239
|
});
|
|
234
240
|
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export interface ColumnSettingsItem {
|
|
2
|
+
id: string;
|
|
3
|
+
label: string;
|
|
4
|
+
visible: boolean;
|
|
5
|
+
hideable: boolean;
|
|
6
|
+
}
|
|
7
|
+
type __VLS_Props = {
|
|
8
|
+
items: ColumnSettingsItem[];
|
|
9
|
+
};
|
|
10
|
+
declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
|
|
11
|
+
reset: () => any;
|
|
12
|
+
toggle: (id: string, visible: boolean) => any;
|
|
13
|
+
move: (from: number, to: number) => any;
|
|
14
|
+
}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{
|
|
15
|
+
onReset?: (() => any) | undefined;
|
|
16
|
+
onToggle?: ((id: string, visible: boolean) => any) | undefined;
|
|
17
|
+
onMove?: ((from: number, to: number) => any) | undefined;
|
|
18
|
+
}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
19
|
+
declare const _default: typeof __VLS_export;
|
|
20
|
+
export default _default;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
<script setup>
|
|
2
|
+
import { ref } from "vue";
|
|
3
|
+
import { UButton, UCheckbox, UIcon, UPopover } from "#components";
|
|
4
|
+
import { useMovkLocale } from "../../../composables/useMovkLocale";
|
|
5
|
+
defineProps({
|
|
6
|
+
items: { type: Array, required: true }
|
|
7
|
+
});
|
|
8
|
+
const emit = defineEmits(["toggle", "move", "reset"]);
|
|
9
|
+
const { t } = useMovkLocale();
|
|
10
|
+
const dragIndex = ref();
|
|
11
|
+
function onDrop(index) {
|
|
12
|
+
if (dragIndex.value !== void 0 && dragIndex.value !== index) emit("move", dragIndex.value, index);
|
|
13
|
+
dragIndex.value = void 0;
|
|
14
|
+
}
|
|
15
|
+
</script>
|
|
16
|
+
|
|
17
|
+
<template>
|
|
18
|
+
<UPopover :content="{ align: 'end' }">
|
|
19
|
+
<UButton
|
|
20
|
+
icon="i-lucide-settings-2"
|
|
21
|
+
color="neutral"
|
|
22
|
+
variant="outline"
|
|
23
|
+
size="sm"
|
|
24
|
+
:aria-label="t('dataTable.columnSettings')"
|
|
25
|
+
/>
|
|
26
|
+
|
|
27
|
+
<template #content>
|
|
28
|
+
<div class="flex flex-col gap-1 p-2 min-w-48" data-slot="column-settings">
|
|
29
|
+
<ul class="flex flex-col">
|
|
30
|
+
<li
|
|
31
|
+
v-for="(item, index) in items"
|
|
32
|
+
:key="item.id"
|
|
33
|
+
draggable="true"
|
|
34
|
+
class="flex items-center gap-2 rounded-md px-1.5 py-1 hover:bg-elevated/50"
|
|
35
|
+
:class="{ 'opacity-50': dragIndex === index }"
|
|
36
|
+
@dragstart="dragIndex = index"
|
|
37
|
+
@dragover.prevent
|
|
38
|
+
@drop="onDrop(index)"
|
|
39
|
+
@dragend="dragIndex = void 0"
|
|
40
|
+
>
|
|
41
|
+
<UIcon name="i-lucide-grip-vertical" class="size-4 shrink-0 cursor-grab text-dimmed" />
|
|
42
|
+
<UCheckbox
|
|
43
|
+
:model-value="item.visible"
|
|
44
|
+
:disabled="!item.hideable"
|
|
45
|
+
:label="item.label"
|
|
46
|
+
class="flex-1"
|
|
47
|
+
@update:model-value="emit('toggle', item.id, $event === true)"
|
|
48
|
+
/>
|
|
49
|
+
</li>
|
|
50
|
+
</ul>
|
|
51
|
+
<UButton
|
|
52
|
+
:label="t('dataTable.resetColumns')"
|
|
53
|
+
icon="i-lucide-rotate-ccw"
|
|
54
|
+
color="neutral"
|
|
55
|
+
variant="ghost"
|
|
56
|
+
size="xs"
|
|
57
|
+
block
|
|
58
|
+
@click="emit('reset')"
|
|
59
|
+
/>
|
|
60
|
+
</div>
|
|
61
|
+
</template>
|
|
62
|
+
</UPopover>
|
|
63
|
+
</template>
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export interface ColumnSettingsItem {
|
|
2
|
+
id: string;
|
|
3
|
+
label: string;
|
|
4
|
+
visible: boolean;
|
|
5
|
+
hideable: boolean;
|
|
6
|
+
}
|
|
7
|
+
type __VLS_Props = {
|
|
8
|
+
items: ColumnSettingsItem[];
|
|
9
|
+
};
|
|
10
|
+
declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
|
|
11
|
+
reset: () => any;
|
|
12
|
+
toggle: (id: string, visible: boolean) => any;
|
|
13
|
+
move: (from: number, to: number) => any;
|
|
14
|
+
}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{
|
|
15
|
+
onReset?: (() => any) | undefined;
|
|
16
|
+
onToggle?: ((id: string, visible: boolean) => any) | undefined;
|
|
17
|
+
onMove?: ((from: number, to: number) => any) | undefined;
|
|
18
|
+
}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
19
|
+
declare const _default: typeof __VLS_export;
|
|
20
|
+
export default _default;
|
|
@@ -1,13 +1,7 @@
|
|
|
1
1
|
import type { TableData } from '@nuxt/ui';
|
|
2
|
-
import type { DataTablePaginationProps, DataTablePaginationSlots
|
|
2
|
+
import type { DataTablePaginationProps, DataTablePaginationSlots } from '../../../types/data-table/pagination';
|
|
3
3
|
declare const __VLS_export: <T extends TableData>(__VLS_props: NonNullable<Awaited<typeof __VLS_setup>>["props"], __VLS_ctx?: __VLS_PrettifyLocal<Pick<NonNullable<Awaited<typeof __VLS_setup>>, "attrs" | "emit" | "slots">>, __VLS_exposed?: NonNullable<Awaited<typeof __VLS_setup>>["expose"], __VLS_setup?: Promise<{
|
|
4
|
-
props: import("vue").PublicProps & __VLS_PrettifyLocal<DataTablePaginationProps<T
|
|
5
|
-
uiConfig?: DataTablePaginationUi & {
|
|
6
|
-
ui?: {
|
|
7
|
-
[x: string]: import("@nuxt/ui").SlotClass;
|
|
8
|
-
};
|
|
9
|
-
};
|
|
10
|
-
}> & (typeof globalThis extends {
|
|
4
|
+
props: import("vue").PublicProps & __VLS_PrettifyLocal<DataTablePaginationProps<T>> & (typeof globalThis extends {
|
|
11
5
|
__VLS_PROPS_FALLBACK: infer P;
|
|
12
6
|
} ? P : {});
|
|
13
7
|
expose: (exposed: {}) => void;
|