@tmagic/form 1.8.0-beta.25 → 1.8.0-beta.27
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/es/Form.vue_vue_type_script_setup_true_lang.js +47 -120
- package/dist/es/FormBox.vue_vue_type_script_setup_true_lang.js +3 -3
- package/dist/es/FormDialog.vue_vue_type_script_setup_true_lang.js +3 -3
- package/dist/es/FormDrawer.vue_vue_type_script_setup_true_lang.js +3 -3
- package/dist/es/containers/Col.vue_vue_type_script_setup_true_lang.js +3 -0
- package/dist/es/containers/Container.vue_vue_type_script_setup_true_lang.js +36 -51
- package/dist/es/containers/Fieldset.vue_vue_type_script_setup_true_lang.js +6 -0
- package/dist/es/containers/FlexLayout.vue_vue_type_script_setup_true_lang.js +4 -1
- package/dist/es/containers/GroupList.vue_vue_type_script_setup_true_lang.js +37 -15
- package/dist/es/containers/GroupListItem.vue_vue_type_script_setup_true_lang.js +109 -97
- package/dist/es/containers/Panel.vue_vue_type_script_setup_true_lang.js +7 -2
- package/dist/es/containers/Row.vue_vue_type_script_setup_true_lang.js +3 -0
- package/dist/es/containers/Step.vue_vue_type_script_setup_true_lang.js +4 -1
- package/dist/es/containers/Tabs.vue_vue_type_script_setup_true_lang.js +7 -0
- package/dist/es/containers/table/Table.vue_vue_type_script_setup_true_lang.js +7 -5
- package/dist/es/containers/table/useTableColumns.js +5 -13
- package/dist/es/containers/table-group-list/TableGroupList.vue_vue_type_script_setup_true_lang.js +71 -78
- package/dist/es/containers/table-group-list/useAdd.js +26 -16
- package/dist/es/containers/table-group-list/useScrollLastItemIntoView.js +72 -0
- package/dist/es/fields/Cascader.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/es/fields/CheckboxGroup/Index.js +5 -0
- package/dist/es/fields/{CheckboxGroup.vue_vue_type_script_setup_true_lang.js → CheckboxGroup/Index.vue_vue_type_script_setup_true_lang.js} +6 -7
- package/dist/es/fields/CheckboxGroup/effect.js +8 -0
- package/dist/es/fields/Date/Index.js +5 -0
- package/dist/es/fields/{Date.vue_vue_type_script_setup_true_lang.js → Date/Index.vue_vue_type_script_setup_true_lang.js} +5 -7
- package/dist/es/fields/Date/effect.js +10 -0
- package/dist/es/fields/DateTime/Index.js +5 -0
- package/dist/es/fields/{DateTime.vue_vue_type_script_setup_true_lang.js → DateTime/Index.vue_vue_type_script_setup_true_lang.js} +5 -9
- package/dist/es/fields/DateTime/effect.js +15 -0
- package/dist/es/fields/Display/Index.js +5 -0
- package/dist/es/fields/{Display.vue_vue_type_script_setup_true_lang.js → Display/Index.vue_vue_type_script_setup_true_lang.js} +6 -7
- package/dist/es/fields/Display/effect.js +8 -0
- package/dist/es/fields/DynamicField/Index.js +5 -0
- package/dist/es/fields/{DynamicField.vue_vue_type_script_setup_true_lang.js → DynamicField/Index.vue_vue_type_script_setup_true_lang.js} +11 -15
- package/dist/es/fields/DynamicField/effect.js +40 -0
- package/dist/es/fields/Link.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/es/fields/Number.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/es/fields/NumberRange/Index.js +5 -0
- package/dist/es/fields/{NumberRange.vue_vue_type_script_setup_true_lang.js → NumberRange/Index.vue_vue_type_script_setup_true_lang.js} +5 -6
- package/dist/es/fields/NumberRange/effect.js +8 -0
- package/dist/es/fields/Select.vue_vue_type_script_setup_true_lang.js +13 -6
- package/dist/es/fields/Text.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/es/headless.js +13 -0
- package/dist/es/index.js +17 -12
- package/dist/es/plugin.js +57 -41
- package/dist/es/schema.js +6 -8
- package/dist/es/style.css +81 -1
- package/dist/es/submitForm.js +44 -194
- package/dist/es/utils/builtInFields.js +49 -0
- package/dist/es/utils/collectFields.js +407 -0
- package/dist/es/utils/config.js +1 -8
- package/dist/es/utils/fieldInnerConfig.js +42 -0
- package/dist/es/utils/fieldValueEffects.js +80 -0
- package/dist/es/utils/form.js +96 -43
- package/dist/es/utils/formStateProxy.js +111 -0
- package/dist/es/utils/registerField.js +158 -0
- package/dist/es/utils/submitHeadless.js +54 -0
- package/dist/es/utils/tableGroupList.js +85 -0
- package/dist/es/utils/typeMatch.js +17 -19
- package/dist/es/utils/validateError.js +57 -0
- package/dist/es/utils/validateValues.js +115 -0
- package/dist/style.css +81 -1
- package/dist/themes/magic-admin.css +83 -7
- package/dist/tmagic-form-headless.umd.cjs +4080 -0
- package/dist/tmagic-form.umd.cjs +2020 -876
- package/package.json +10 -4
- package/src/Form.vue +49 -149
- package/src/FormBox.vue +5 -4
- package/src/FormDialog.vue +5 -5
- package/src/FormDrawer.vue +5 -5
- package/src/containers/Col.vue +2 -0
- package/src/containers/Container.vue +86 -157
- package/src/containers/Fieldset.vue +5 -0
- package/src/containers/FlexLayout.vue +2 -0
- package/src/containers/GroupList.vue +41 -11
- package/src/containers/GroupListItem.vue +83 -80
- package/src/containers/Panel.vue +3 -0
- package/src/containers/Row.vue +2 -0
- package/src/containers/Step.vue +2 -0
- package/src/containers/Tabs.vue +13 -0
- package/src/containers/table/ActionsColumn.vue +1 -1
- package/src/containers/table/Table.vue +4 -3
- package/src/containers/table/usePagination.ts +1 -1
- package/src/containers/table/useSortable.ts +1 -1
- package/src/containers/table/useTableColumns.ts +9 -19
- package/src/containers/table-group-list/TableGroupList.vue +43 -71
- package/src/containers/table-group-list/useAdd.ts +40 -25
- package/src/containers/table-group-list/useScrollLastItemIntoView.ts +94 -0
- package/src/fields/{CheckboxGroup.vue → CheckboxGroup/Index.vue} +3 -8
- package/src/fields/CheckboxGroup/effect.ts +27 -0
- package/src/fields/{Date.vue → Date/Index.vue} +2 -5
- package/src/fields/Date/effect.ts +29 -0
- package/src/fields/{DateTime.vue → DateTime/Index.vue} +2 -16
- package/src/fields/DateTime/effect.ts +36 -0
- package/src/fields/{Display.vue → Display/Index.vue} +3 -7
- package/src/fields/Display/effect.ts +28 -0
- package/src/fields/{DynamicField.vue → DynamicField/Index.vue} +11 -11
- package/src/fields/DynamicField/effect.ts +74 -0
- package/src/fields/{NumberRange.vue → NumberRange/Index.vue} +2 -6
- package/src/fields/NumberRange/effect.ts +27 -0
- package/src/fields/Select.vue +13 -4
- package/src/headless.ts +78 -0
- package/src/index.ts +32 -15
- package/src/plugin.ts +63 -42
- package/src/schema.ts +6 -8
- package/src/submitForm.ts +81 -409
- package/src/theme/group-list.scss +107 -1
- package/src/theme/themes/magic-admin/index.scss +2 -8
- package/src/utils/builtInFields.ts +69 -0
- package/src/utils/collectFields.ts +561 -0
- package/src/utils/config.ts +1 -15
- package/src/utils/fieldInnerConfig.ts +127 -0
- package/src/utils/fieldValueEffects.ts +140 -0
- package/src/utils/form.ts +141 -75
- package/src/utils/formStateProxy.ts +149 -0
- package/src/utils/registerField.ts +308 -0
- package/src/utils/submitHeadless.ts +206 -0
- package/src/utils/tableGroupList.ts +120 -0
- package/src/utils/typeMatch.ts +19 -15
- package/src/utils/validateError.ts +92 -0
- package/src/utils/validateValues.ts +177 -0
- package/types/headless.d.ts +682 -0
- package/types/index.d.ts +631 -272
- package/dist/es/fields/CheckboxGroup.js +0 -5
- package/dist/es/fields/Date.js +0 -5
- package/dist/es/fields/DateTime.js +0 -5
- package/dist/es/fields/Display.js +0 -5
- package/dist/es/fields/DynamicField.js +0 -5
- package/dist/es/fields/NumberRange.js +0 -5
- package/dist/es/utils/silentLeafFieldTypes.js +0 -49
- package/src/utils/silentLeafFieldTypes.ts +0 -71
package/src/headless.ts
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Tencent is pleased to support the open source community by making TMagicEditor available.
|
|
3
|
+
*
|
|
4
|
+
* Copyright (C) 2025 Tencent. All rights reserved.
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* @fileoverview `@tmagic/form/headless`:无渲染校验入口,不加载 Vue 组件与样式。
|
|
21
|
+
*
|
|
22
|
+
* 纯 Node / CI 请从这里引入 `submitForm` / `validateForm` / `registerField`。
|
|
23
|
+
* `dialog: true` 需要 DOM,请改从 `@tmagic/form` 引入。
|
|
24
|
+
*
|
|
25
|
+
* ESM 下本入口与 `@tmagic/form` 共用同一批模块文件,字段注册表是同一份。
|
|
26
|
+
* CJS(`require`)下两者是各自独立的 UMD bundle,注册表不共享,同一进程里不要
|
|
27
|
+
* 同时 `require('@tmagic/form')` 和 `require('@tmagic/form/headless')`。
|
|
28
|
+
*
|
|
29
|
+
* @module @tmagic/form/headless
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
export * from './schema';
|
|
33
|
+
export * from './utils/form';
|
|
34
|
+
export { builtInFields } from './utils/builtInFields';
|
|
35
|
+
|
|
36
|
+
export {
|
|
37
|
+
clearFields,
|
|
38
|
+
getField as getFormField,
|
|
39
|
+
mergeFieldOptions,
|
|
40
|
+
registerBuiltInFields,
|
|
41
|
+
registerField,
|
|
42
|
+
registerFields,
|
|
43
|
+
unregisterField,
|
|
44
|
+
} from './utils/registerField';
|
|
45
|
+
export type { FieldOptions, HeadlessFieldOptions } from './utils/registerField';
|
|
46
|
+
|
|
47
|
+
export type { FieldInnerConfig, FieldInnerConfigContext, FieldInnerConfigResult } from './utils/fieldInnerConfig';
|
|
48
|
+
|
|
49
|
+
export { isLeafFieldType } from './utils/fieldValueEffects';
|
|
50
|
+
export type { FieldMountValueEffect, FieldMountValueEffectContext } from './utils/fieldValueEffects';
|
|
51
|
+
|
|
52
|
+
export {
|
|
53
|
+
applyMountValueEffects,
|
|
54
|
+
collectValidatableFields,
|
|
55
|
+
FieldInnerConfigError,
|
|
56
|
+
isFieldInnerConfigError,
|
|
57
|
+
} from './utils/collectFields';
|
|
58
|
+
export type { CollectedField } from './utils/collectFields';
|
|
59
|
+
|
|
60
|
+
export { createHeadlessFormState, validateValues } from './utils/validateValues';
|
|
61
|
+
export type { HeadlessFormStateOptions, ValidateValuesOptions, ValidateValuesResult } from './utils/validateValues';
|
|
62
|
+
|
|
63
|
+
export { formatValidateError, getTextByName } from './utils/validateError';
|
|
64
|
+
|
|
65
|
+
export {
|
|
66
|
+
clearTypeMatchRules,
|
|
67
|
+
deleteTypeMatchRule,
|
|
68
|
+
getTypeMatchRule,
|
|
69
|
+
MAX_SUGGESTION_OPTIONS,
|
|
70
|
+
optionSuggestion,
|
|
71
|
+
stringifyExampleValue,
|
|
72
|
+
validateTypeMatch,
|
|
73
|
+
} from './utils/typeMatch';
|
|
74
|
+
|
|
75
|
+
export type { TypeMatchValidateContext, TypeMatchValidator } from './utils/typeMatch';
|
|
76
|
+
|
|
77
|
+
export { submitForm, validateForm } from './utils/submitHeadless';
|
|
78
|
+
export type { SubmitFormOptions, SubmitFormResult, ValidateFormOptions } from './utils/submitHeadless';
|
package/src/index.ts
CHANGED
|
@@ -38,36 +38,55 @@ export { default as MGroupList } from './containers/table-group-list/TableGroupL
|
|
|
38
38
|
export { default as MTableGroupList } from './containers/table-group-list/TableGroupList.vue';
|
|
39
39
|
export { default as MText } from './fields/Text.vue';
|
|
40
40
|
export { default as MNumber } from './fields/Number.vue';
|
|
41
|
-
export { default as MNumberRange } from './fields/NumberRange.vue';
|
|
41
|
+
export { default as MNumberRange } from './fields/NumberRange/Index.vue';
|
|
42
42
|
export { default as MTextarea } from './fields/Textarea.vue';
|
|
43
43
|
export { default as MHidden } from './fields/Hidden.vue';
|
|
44
|
-
export { default as MDate } from './fields/Date.vue';
|
|
45
|
-
export { default as MDateTime } from './fields/DateTime.vue';
|
|
44
|
+
export { default as MDate } from './fields/Date/Index.vue';
|
|
45
|
+
export { default as MDateTime } from './fields/DateTime/Index.vue';
|
|
46
46
|
export { default as MTime } from './fields/Time.vue';
|
|
47
47
|
export { default as MCheckbox } from './fields/Checkbox.vue';
|
|
48
48
|
export { default as MSwitch } from './fields/Switch.vue';
|
|
49
49
|
export { default as MDaterange } from './fields/Daterange.vue';
|
|
50
50
|
export { default as MTimerange } from './fields/Timerange.vue';
|
|
51
51
|
export { default as MColorPicker } from './fields/ColorPicker.vue';
|
|
52
|
-
export { default as MCheckboxGroup } from './fields/CheckboxGroup.vue';
|
|
52
|
+
export { default as MCheckboxGroup } from './fields/CheckboxGroup/Index.vue';
|
|
53
53
|
export { default as MRadioGroup } from './fields/RadioGroup.vue';
|
|
54
|
-
export { default as MDisplay } from './fields/Display.vue';
|
|
54
|
+
export { default as MDisplay } from './fields/Display/Index.vue';
|
|
55
55
|
export { default as MLink } from './fields/Link.vue';
|
|
56
56
|
export { default as MSelect } from './fields/Select.vue';
|
|
57
57
|
export { default as MCascader } from './fields/Cascader.vue';
|
|
58
|
-
export { default as MDynamicField } from './fields/DynamicField.vue';
|
|
58
|
+
export { default as MDynamicField } from './fields/DynamicField/Index.vue';
|
|
59
|
+
|
|
60
|
+
export { builtInFields } from './utils/builtInFields';
|
|
59
61
|
|
|
60
62
|
export {
|
|
61
|
-
|
|
63
|
+
clearFields,
|
|
62
64
|
getField as getFormField,
|
|
63
|
-
|
|
64
|
-
|
|
65
|
+
mergeFieldOptions,
|
|
66
|
+
registerBuiltInFields,
|
|
67
|
+
registerField,
|
|
68
|
+
registerFields,
|
|
69
|
+
unregisterField,
|
|
70
|
+
} from './utils/registerField';
|
|
71
|
+
export type { FieldOptions, HeadlessFieldOptions } from './utils/registerField';
|
|
72
|
+
|
|
73
|
+
export type { FieldInnerConfig, FieldInnerConfigContext, FieldInnerConfigResult } from './utils/fieldInnerConfig';
|
|
74
|
+
|
|
75
|
+
export { isLeafFieldType } from './utils/fieldValueEffects';
|
|
76
|
+
export type { FieldMountValueEffect, FieldMountValueEffectContext } from './utils/fieldValueEffects';
|
|
65
77
|
|
|
66
78
|
export {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
79
|
+
applyMountValueEffects,
|
|
80
|
+
collectValidatableFields,
|
|
81
|
+
FieldInnerConfigError,
|
|
82
|
+
isFieldInnerConfigError,
|
|
83
|
+
} from './utils/collectFields';
|
|
84
|
+
export type { CollectedField } from './utils/collectFields';
|
|
85
|
+
|
|
86
|
+
export { createHeadlessFormState, validateValues } from './utils/validateValues';
|
|
87
|
+
export type { HeadlessFormStateOptions, ValidateValuesOptions, ValidateValuesResult } from './utils/validateValues';
|
|
88
|
+
|
|
89
|
+
export { formatValidateError, getTextByName } from './utils/validateError';
|
|
71
90
|
|
|
72
91
|
export {
|
|
73
92
|
clearTypeMatchRules,
|
|
@@ -75,8 +94,6 @@ export {
|
|
|
75
94
|
getTypeMatchRule,
|
|
76
95
|
MAX_SUGGESTION_OPTIONS,
|
|
77
96
|
optionSuggestion,
|
|
78
|
-
registerTypeMatchRule,
|
|
79
|
-
registerTypeMatchRules,
|
|
80
97
|
stringifyExampleValue,
|
|
81
98
|
validateTypeMatch,
|
|
82
99
|
} from './utils/typeMatch';
|
package/src/plugin.ts
CHANGED
|
@@ -28,17 +28,17 @@ import TableGroupList from './containers/table-group-list/TableGroupList.vue';
|
|
|
28
28
|
import Tabs from './containers/Tabs.vue';
|
|
29
29
|
import Cascader from './fields/Cascader.vue';
|
|
30
30
|
import Checkbox from './fields/Checkbox.vue';
|
|
31
|
-
import CheckboxGroup from './fields/CheckboxGroup.vue';
|
|
31
|
+
import CheckboxGroup from './fields/CheckboxGroup/Index.vue';
|
|
32
32
|
import ColorPicker from './fields/ColorPicker.vue';
|
|
33
|
-
import Date from './fields/Date.vue';
|
|
33
|
+
import Date from './fields/Date/Index.vue';
|
|
34
34
|
import Daterange from './fields/Daterange.vue';
|
|
35
|
-
import DateTime from './fields/DateTime.vue';
|
|
36
|
-
import Display from './fields/Display.vue';
|
|
37
|
-
import DynamicField from './fields/DynamicField.vue';
|
|
35
|
+
import DateTime from './fields/DateTime/Index.vue';
|
|
36
|
+
import Display from './fields/Display/Index.vue';
|
|
37
|
+
import DynamicField from './fields/DynamicField/Index.vue';
|
|
38
38
|
import Hidden from './fields/Hidden.vue';
|
|
39
39
|
import Link from './fields/Link.vue';
|
|
40
40
|
import Number from './fields/Number.vue';
|
|
41
|
-
import NumberRange from './fields/NumberRange.vue';
|
|
41
|
+
import NumberRange from './fields/NumberRange/Index.vue';
|
|
42
42
|
import RadioGroup from './fields/RadioGroup.vue';
|
|
43
43
|
import Select from './fields/Select.vue';
|
|
44
44
|
import Switch from './fields/Switch.vue';
|
|
@@ -46,8 +46,9 @@ import Text from './fields/Text.vue';
|
|
|
46
46
|
import Textarea from './fields/Textarea.vue';
|
|
47
47
|
import Time from './fields/Time.vue';
|
|
48
48
|
import Timerange from './fields/Timerange.vue';
|
|
49
|
+
import { builtInFields } from './utils/builtInFields';
|
|
49
50
|
import { setConfig } from './utils/config';
|
|
50
|
-
import {
|
|
51
|
+
import { type FieldOptions, registerBuiltInFields, registerFields } from './utils/registerField';
|
|
51
52
|
import Form from './Form.vue';
|
|
52
53
|
import FormDialog from './FormDialog.vue';
|
|
53
54
|
import FormDrawer from './FormDrawer.vue';
|
|
@@ -55,59 +56,79 @@ import FormDrawer from './FormDrawer.vue';
|
|
|
55
56
|
import './theme/index.scss';
|
|
56
57
|
|
|
57
58
|
// #region FormInstallOptions
|
|
59
|
+
/**
|
|
60
|
+
* `@tmagic/form` 插件安装选项。
|
|
61
|
+
*/
|
|
58
62
|
export interface FormInstallOptions {
|
|
63
|
+
/** 是否启用全局 flat 模式。 */
|
|
59
64
|
flat?: boolean;
|
|
60
|
-
/**
|
|
61
|
-
|
|
65
|
+
/**
|
|
66
|
+
* 自定义字段 type 的登记(叶子 / innerConfig / walk / typeMatch / component / container)。
|
|
67
|
+
* 与 `registerFields` 相同。
|
|
68
|
+
*/
|
|
69
|
+
fields?: Record<string, FieldOptions>;
|
|
62
70
|
[key: string]: any;
|
|
63
71
|
}
|
|
64
72
|
// #endregion FormInstallOptions
|
|
65
73
|
|
|
74
|
+
const builtInFieldVue: Record<string, Pick<FieldOptions, 'component' | 'container'>> = {
|
|
75
|
+
text: { component: Text },
|
|
76
|
+
'img-upload': { component: Text },
|
|
77
|
+
number: { component: Number },
|
|
78
|
+
'number-range': { component: NumberRange },
|
|
79
|
+
textarea: { component: Textarea },
|
|
80
|
+
hidden: { component: Hidden },
|
|
81
|
+
date: { component: Date },
|
|
82
|
+
datetime: { component: DateTime },
|
|
83
|
+
daterange: { component: Daterange },
|
|
84
|
+
timerange: { component: Timerange },
|
|
85
|
+
time: { component: Time },
|
|
86
|
+
checkbox: { component: Checkbox },
|
|
87
|
+
switch: { component: Switch },
|
|
88
|
+
'color-picker': { component: ColorPicker },
|
|
89
|
+
'checkbox-group': { component: CheckboxGroup },
|
|
90
|
+
'radio-group': { component: RadioGroup },
|
|
91
|
+
display: { component: Display },
|
|
92
|
+
link: { component: Link },
|
|
93
|
+
select: { component: Select },
|
|
94
|
+
cascader: { component: Cascader },
|
|
95
|
+
'dynamic-field': { component: DynamicField },
|
|
96
|
+
container: { container: Container },
|
|
97
|
+
tab: { container: Tabs },
|
|
98
|
+
row: { container: Row },
|
|
99
|
+
'flex-layout': { container: FlexLayout },
|
|
100
|
+
fieldset: { container: Fieldset },
|
|
101
|
+
panel: { container: Panel },
|
|
102
|
+
step: { container: MStep },
|
|
103
|
+
table: { container: TableGroupList },
|
|
104
|
+
'group-list': { container: TableGroupList },
|
|
105
|
+
'table-group-list': { container: TableGroupList },
|
|
106
|
+
};
|
|
107
|
+
|
|
66
108
|
const defaultInstallOpt: FormInstallOptions = {};
|
|
67
109
|
|
|
68
110
|
export default {
|
|
111
|
+
/**
|
|
112
|
+
* 安装 `@tmagic/form`:登记内置字段、挂载 `m-form` / `m-form-dialog` / `m-form-drawer`。
|
|
113
|
+
*
|
|
114
|
+
* @param app - Vue 应用
|
|
115
|
+
* @param [opt] - 安装选项
|
|
116
|
+
*/
|
|
69
117
|
install(app: App, opt: FormInstallOptions = {}) {
|
|
70
|
-
const option =
|
|
118
|
+
const option = { ...defaultInstallOpt, ...opt };
|
|
71
119
|
|
|
72
120
|
app.config.globalProperties.$MAGIC_FORM = option;
|
|
73
121
|
setConfig(option);
|
|
74
122
|
|
|
75
|
-
|
|
76
|
-
|
|
123
|
+
registerBuiltInFields(builtInFields);
|
|
124
|
+
registerBuiltInFields(builtInFieldVue, app);
|
|
125
|
+
|
|
126
|
+
if (option.fields) {
|
|
127
|
+
registerFields(option.fields, app);
|
|
77
128
|
}
|
|
78
129
|
|
|
79
130
|
app.component('m-form', Form);
|
|
80
131
|
app.component('m-form-dialog', FormDialog);
|
|
81
132
|
app.component('m-form-drawer', FormDrawer);
|
|
82
|
-
app.component('m-form-container', Container);
|
|
83
|
-
app.component('m-form-fieldset', Fieldset);
|
|
84
|
-
app.component('m-form-group-list', TableGroupList);
|
|
85
|
-
app.component('m-form-panel', Panel);
|
|
86
|
-
app.component('m-form-row', Row);
|
|
87
|
-
app.component('m-form-step', MStep);
|
|
88
|
-
app.component('m-form-table', TableGroupList);
|
|
89
|
-
app.component('m-form-tab', Tabs);
|
|
90
|
-
app.component('m-form-flex-layout', FlexLayout);
|
|
91
|
-
app.component('m-fields-text', Text);
|
|
92
|
-
app.component('m-fields-img-upload', Text);
|
|
93
|
-
app.component('m-fields-number', Number);
|
|
94
|
-
app.component('m-fields-number-range', NumberRange);
|
|
95
|
-
app.component('m-fields-textarea', Textarea);
|
|
96
|
-
app.component('m-fields-hidden', Hidden);
|
|
97
|
-
app.component('m-fields-date', Date);
|
|
98
|
-
app.component('m-fields-datetime', DateTime);
|
|
99
|
-
app.component('m-fields-daterange', Daterange);
|
|
100
|
-
app.component('m-fields-timerange', Timerange);
|
|
101
|
-
app.component('m-fields-time', Time);
|
|
102
|
-
app.component('m-fields-checkbox', Checkbox);
|
|
103
|
-
app.component('m-fields-switch', Switch);
|
|
104
|
-
app.component('m-fields-color-picker', ColorPicker);
|
|
105
|
-
app.component('m-fields-checkbox-group', CheckboxGroup);
|
|
106
|
-
app.component('m-fields-radio-group', RadioGroup);
|
|
107
|
-
app.component('m-fields-display', Display);
|
|
108
|
-
app.component('m-fields-link', Link);
|
|
109
|
-
app.component('m-fields-select', Select);
|
|
110
|
-
app.component('m-fields-cascader', Cascader);
|
|
111
|
-
app.component('m-fields-dynamic-field', DynamicField);
|
|
112
133
|
},
|
|
113
134
|
};
|
package/src/schema.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ComputedRef, InjectionKey } from 'vue';
|
|
2
2
|
|
|
3
|
-
import type { FormItemConfig } from '@tmagic/form-schema';
|
|
3
|
+
import type { FormContext, FormItemConfig } from '@tmagic/form-schema';
|
|
4
4
|
|
|
5
5
|
export * from '@tmagic/form-schema';
|
|
6
6
|
|
|
@@ -30,16 +30,14 @@ export const FORM_DIFF_CONFIG_KEY: InjectionKey<FormDiffConfig> = Symbol('mFormD
|
|
|
30
30
|
export const FORM_TYPE_MATCH_VALID_KEY: InjectionKey<ComputedRef<boolean>> = Symbol('mFormTypeMatchValid');
|
|
31
31
|
|
|
32
32
|
/**
|
|
33
|
-
*
|
|
33
|
+
* 宿主业务上下文,由 `MForm`(或更外层的 Editor)通过 `provide` 下发。
|
|
34
34
|
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
* 重型字段组件(如 vs-code)也可 inject 该标记跳过自身渲染,省去无谓的实例化开销。
|
|
35
|
+
* 嵌套表单(Link 子表单、FormBox、临时校验表单等)会自动继承最近祖先的 context,
|
|
36
|
+
* 无需层层透传。
|
|
38
37
|
*
|
|
39
|
-
*
|
|
40
|
-
* 字段组件可以安全跳过,接入前需逐一审计;业务扩展请使用 `registerSilentLeafFieldTypes`。
|
|
38
|
+
* 配置回调统一通过 `mForm.xxx` 读取,由 formState 的读穿 Proxy 落到这里。
|
|
41
39
|
*/
|
|
42
|
-
export const
|
|
40
|
+
export const FORM_CONTEXT_KEY: InjectionKey<ComputedRef<FormContext>> = Symbol('mFormContext');
|
|
43
41
|
|
|
44
42
|
export interface ValidateError {
|
|
45
43
|
message: string;
|