@tmagic/form 1.8.0-beta.14 → 1.8.0-beta.15
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/containers/Col.vue_vue_type_script_setup_true_lang.js +2 -1
- package/dist/es/containers/Container.vue_vue_type_script_setup_true_lang.js +4 -2
- package/dist/es/index.js +2 -2
- package/dist/es/schema.js +11 -1
- package/dist/es/submitForm.js +11 -3
- package/dist/es/utils/typeMatch.js +2 -0
- package/dist/tmagic-form.umd.cjs +27 -4
- package/package.json +4 -4
- package/src/containers/Col.vue +1 -0
- package/src/containers/Container.vue +5 -1
- package/src/schema.ts +11 -0
- package/src/submitForm.ts +28 -3
- package/src/utils/typeMatch.ts +10 -1
- package/types/index.d.ts +15 -4
|
@@ -40,7 +40,8 @@ var Col_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defineCompon
|
|
|
40
40
|
size: __props.size,
|
|
41
41
|
disabled: __props.disabled,
|
|
42
42
|
onChange: changeHandler,
|
|
43
|
-
onAddDiffCount
|
|
43
|
+
onAddDiffCount,
|
|
44
|
+
"is-in-row": true
|
|
44
45
|
}, null, 8, [
|
|
45
46
|
"model",
|
|
46
47
|
"lastValues",
|
|
@@ -3,7 +3,7 @@ import { createObjectProp, display, filterFunction, getRules } from "../utils/fo
|
|
|
3
3
|
import Hidden_default from "../fields/Hidden.js";
|
|
4
4
|
import { getField } from "../utils/config.js";
|
|
5
5
|
import FormLabel_default from "./FormLabel.js";
|
|
6
|
-
import { Fragment, computed, createBlock, createCommentVNode, createElementBlock, createElementVNode, createSlots, createTextVNode, createVNode, defineComponent, inject, mergeProps, normalizeClass, normalizeStyle, openBlock, readonly, ref, renderList, renderSlot, resolveComponent, resolveDynamicComponent, toDisplayString, toRaw, unref, watch, watchEffect, withCtx } from "vue";
|
|
6
|
+
import { Fragment, computed, createBlock, createCommentVNode, createElementBlock, createElementVNode, createSlots, createTextVNode, createVNode, defineComponent, inject, mergeProps, normalizeClass, normalizeStyle, openBlock, provide, readonly, ref, renderList, renderSlot, resolveComponent, resolveDynamicComponent, toDisplayString, toRaw, unref, watch, watchEffect, withCtx } from "vue";
|
|
7
7
|
import { isEqual } from "lodash-es";
|
|
8
8
|
import { TMagicButton, TMagicFormItem, TMagicIcon, TMagicTooltip } from "@tmagic/design";
|
|
9
9
|
import { getValueByKeyPath } from "@tmagic/utils";
|
|
@@ -44,7 +44,8 @@ var Container_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ define
|
|
|
44
44
|
isCompare: {
|
|
45
45
|
type: Boolean,
|
|
46
46
|
default: false
|
|
47
|
-
}
|
|
47
|
+
},
|
|
48
|
+
isInRow: { type: Boolean }
|
|
48
49
|
},
|
|
49
50
|
emits: ["change", "addDiffCount"],
|
|
50
51
|
setup(__props, { emit: __emit }) {
|
|
@@ -161,6 +162,7 @@ var Container_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ define
|
|
|
161
162
|
if (items.value && !text.value && type.value && display$1.value) return;
|
|
162
163
|
if (display$1.value && showDiff && type.value) emit("addDiffCount");
|
|
163
164
|
}, { immediate: true });
|
|
165
|
+
provide("isInRow", props.isInRow ?? false);
|
|
164
166
|
const expandHandler = () => expand.value = !expand.value;
|
|
165
167
|
const key = (config) => config[mForm?.keyProps];
|
|
166
168
|
const filterHandler = (filter, value) => {
|
package/dist/es/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import "./_virtual/_rolldown/runtime.js";
|
|
2
|
-
import { FORM_DIFF_CONFIG_KEY, FORM_TYPE_MATCH_VALID_KEY } from "./schema.js";
|
|
2
|
+
import { FORM_DIFF_CONFIG_KEY, FORM_SILENT_MODE_KEY, FORM_TYPE_MATCH_VALID_KEY } from "./schema.js";
|
|
3
3
|
import { clearTypeMatchRules, deleteTypeMatchRule, getTypeMatchRule, registerTypeMatchRule, registerTypeMatchRules, validateTypeMatch } from "./utils/typeMatch.js";
|
|
4
4
|
import { adaptFormValidator, applyExtendState, createObjectProp, createValues, datetimeFormatter, display, filterFunction, getDataByPage, getRules, initValue, sortArray, sortChange } from "./utils/form.js";
|
|
5
5
|
import { useAddField } from "./utils/useAddField.js";
|
|
@@ -40,4 +40,4 @@ import plugin_default from "./plugin.js";
|
|
|
40
40
|
export * from "@tmagic/form-schema";
|
|
41
41
|
var createForm = (config) => config;
|
|
42
42
|
//#endregion
|
|
43
|
-
export { FORM_DIFF_CONFIG_KEY, FORM_TYPE_MATCH_VALID_KEY, Cascader_default as MCascader, Checkbox_default as MCheckbox, CheckboxGroup_default as MCheckboxGroup, ColorPicker_default as MColorPicker, Container_default as MContainer, Date_default as MDate, DateTime_default as MDateTime, Daterange_default as MDaterange, Display_default as MDisplay, DynamicField_default as MDynamicField, Fieldset_default as MFieldset, FlexLayout_default as MFlexLayout, Form_default as MForm, FormBox_default as MFormBox, FormDialog_default as MFormDialog, FormDrawer_default as MFormDrawer, TableGroupList_default as MGroupList, Hidden_default as MHidden, Link_default as MLink, Number_default as MNumber, NumberRange_default as MNumberRange, Panel_default as MPanel, RadioGroup_default as MRadioGroup, Row_default as MRow, Select_default as MSelect, Switch_default as MSwitch, TableGroupList_default as MTable, TableGroupList_default as MTableGroupList, Tabs_default as MTabs, Text_default as MText, Textarea_default as MTextarea, Time_default as MTime, Timerange_default as MTimerange, adaptFormValidator, applyExtendState, clearTypeMatchRules, createForm, createObjectProp, createValues, datetimeFormatter, plugin_default as default, deleteField as deleteFormField, deleteTypeMatchRule, display, filterFunction, getDataByPage, getField as getFormField, getRules, getTypeMatchRule, initValue, registerField as registerFormField, registerTypeMatchRule, registerTypeMatchRules, sortArray, sortChange, stripTabItemsLazy, submitForm, useAddField, validateForm, validateTypeMatch };
|
|
43
|
+
export { FORM_DIFF_CONFIG_KEY, FORM_SILENT_MODE_KEY, FORM_TYPE_MATCH_VALID_KEY, Cascader_default as MCascader, Checkbox_default as MCheckbox, CheckboxGroup_default as MCheckboxGroup, ColorPicker_default as MColorPicker, Container_default as MContainer, Date_default as MDate, DateTime_default as MDateTime, Daterange_default as MDaterange, Display_default as MDisplay, DynamicField_default as MDynamicField, Fieldset_default as MFieldset, FlexLayout_default as MFlexLayout, Form_default as MForm, FormBox_default as MFormBox, FormDialog_default as MFormDialog, FormDrawer_default as MFormDrawer, TableGroupList_default as MGroupList, Hidden_default as MHidden, Link_default as MLink, Number_default as MNumber, NumberRange_default as MNumberRange, Panel_default as MPanel, RadioGroup_default as MRadioGroup, Row_default as MRow, Select_default as MSelect, Switch_default as MSwitch, TableGroupList_default as MTable, TableGroupList_default as MTableGroupList, Tabs_default as MTabs, Text_default as MText, Textarea_default as MTextarea, Time_default as MTime, Timerange_default as MTimerange, adaptFormValidator, applyExtendState, clearTypeMatchRules, createForm, createObjectProp, createValues, datetimeFormatter, plugin_default as default, deleteField as deleteFormField, deleteTypeMatchRule, display, filterFunction, getDataByPage, getField as getFormField, getRules, getTypeMatchRule, initValue, registerField as registerFormField, registerTypeMatchRule, registerTypeMatchRules, sortArray, sortChange, stripTabItemsLazy, submitForm, useAddField, validateForm, validateTypeMatch };
|
package/dist/es/schema.js
CHANGED
|
@@ -3,5 +3,15 @@ export * from "@tmagic/form-schema";
|
|
|
3
3
|
//#region packages/form/src/schema.ts
|
|
4
4
|
var FORM_DIFF_CONFIG_KEY = Symbol("mFormDiffConfig");
|
|
5
5
|
var FORM_TYPE_MATCH_VALID_KEY = Symbol("mFormTypeMatchValid");
|
|
6
|
+
/**
|
|
7
|
+
* 静默模式标记,由 `submitForm` / `validateForm` 以隐藏方式挂载临时表单时 provide(debug 弹层模式不提供)。
|
|
8
|
+
*
|
|
9
|
+
* 重型字段组件(如 vs-code)可 inject 该标记并跳过自身渲染:字段校验由 FormItem 基于 model 值完成,
|
|
10
|
+
* 与叶子 UI 组件实例无关,跳过可省去无谓的实例化开销(如 monaco worker / model 的创建)。
|
|
11
|
+
*
|
|
12
|
+
* 注意:仅「挂载无值副作用」(不在 onMounted/watch immediate 中 emit change、不依赖 DOM 计算值)的
|
|
13
|
+
* 字段组件可以安全跳过,接入前需逐一审计。
|
|
14
|
+
*/
|
|
15
|
+
var FORM_SILENT_MODE_KEY = Symbol("mFormSilentMode");
|
|
6
16
|
//#endregion
|
|
7
|
-
export { FORM_DIFF_CONFIG_KEY, FORM_TYPE_MATCH_VALID_KEY };
|
|
17
|
+
export { FORM_DIFF_CONFIG_KEY, FORM_SILENT_MODE_KEY, FORM_TYPE_MATCH_VALID_KEY };
|
package/dist/es/submitForm.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import { FORM_SILENT_MODE_KEY } from "./schema.js";
|
|
1
2
|
import { applyExtendState } from "./utils/form.js";
|
|
2
3
|
import Form_default from "./Form.js";
|
|
3
|
-
import { createApp, defineComponent, h, nextTick, ref, watch } from "vue";
|
|
4
|
+
import { createApp, defineComponent, h, nextTick, provide, ref, watch } from "vue";
|
|
4
5
|
//#region packages/form/src/submitForm.ts
|
|
5
6
|
/**
|
|
6
7
|
* submitForm / validateForm 的公共脚手架:
|
|
@@ -41,7 +42,7 @@ var mountFormInstance = (options) => {
|
|
|
41
42
|
resolve,
|
|
42
43
|
reject
|
|
43
44
|
});
|
|
44
|
-
const
|
|
45
|
+
const wrapperComponent = typeof extendState === "function" ? defineComponent({
|
|
45
46
|
name: "MFormExtendStateInjector",
|
|
46
47
|
setup() {
|
|
47
48
|
watch(() => formRef.value, (form) => {
|
|
@@ -62,7 +63,14 @@ var mountFormInstance = (options) => {
|
|
|
62
63
|
});
|
|
63
64
|
return () => h(userWrapper);
|
|
64
65
|
}
|
|
65
|
-
}) : userWrapper
|
|
66
|
+
}) : userWrapper;
|
|
67
|
+
const app = createApp(hidden ? defineComponent({
|
|
68
|
+
name: "MFormSilentProvider",
|
|
69
|
+
setup() {
|
|
70
|
+
provide(FORM_SILENT_MODE_KEY, true);
|
|
71
|
+
return () => h(wrapperComponent);
|
|
72
|
+
}
|
|
73
|
+
}) : wrapperComponent);
|
|
66
74
|
instance.app = app;
|
|
67
75
|
if (appContext) Object.assign(app._context, appContext);
|
|
68
76
|
if (timeout > 0 && !skipTimeout) timer = setTimeout(() => {
|
|
@@ -313,6 +313,7 @@ var validateBuiltinTypeMatch = (value, fieldType, mForm, props, message) => {
|
|
|
313
313
|
return;
|
|
314
314
|
}
|
|
315
315
|
if (typeof config.filter === "function") return;
|
|
316
|
+
if (fieldType === "text" && isNumberValue(value)) return;
|
|
316
317
|
if (typeof value !== "string") return defaultMessage(message, `${value} 类型应为字符串`, typeExampleSuggestion(mForm, props, "\"文本内容\"", isStringValue));
|
|
317
318
|
return;
|
|
318
319
|
}
|
|
@@ -362,6 +363,7 @@ var validateBuiltinTypeMatch = (value, fieldType, mForm, props, message) => {
|
|
|
362
363
|
};
|
|
363
364
|
var validateTypeMatch = (value, mForm, props, message) => {
|
|
364
365
|
if (isEmptyValue(value) || isEmptyArray(value)) return;
|
|
366
|
+
if (!props.config?.name) return;
|
|
365
367
|
const rawFieldType = "type" in (props.config || {}) ? props.config.type : "";
|
|
366
368
|
if (typeof rawFieldType !== "string" || !rawFieldType) return;
|
|
367
369
|
const fieldType = toLine(rawFieldType);
|
package/dist/tmagic-form.umd.cjs
CHANGED
|
@@ -43,6 +43,16 @@
|
|
|
43
43
|
//#region packages/form/src/schema.ts
|
|
44
44
|
var FORM_DIFF_CONFIG_KEY = Symbol("mFormDiffConfig");
|
|
45
45
|
var FORM_TYPE_MATCH_VALID_KEY = Symbol("mFormTypeMatchValid");
|
|
46
|
+
/**
|
|
47
|
+
* 静默模式标记,由 `submitForm` / `validateForm` 以隐藏方式挂载临时表单时 provide(debug 弹层模式不提供)。
|
|
48
|
+
*
|
|
49
|
+
* 重型字段组件(如 vs-code)可 inject 该标记并跳过自身渲染:字段校验由 FormItem 基于 model 值完成,
|
|
50
|
+
* 与叶子 UI 组件实例无关,跳过可省去无谓的实例化开销(如 monaco worker / model 的创建)。
|
|
51
|
+
*
|
|
52
|
+
* 注意:仅「挂载无值副作用」(不在 onMounted/watch immediate 中 emit change、不依赖 DOM 计算值)的
|
|
53
|
+
* 字段组件可以安全跳过,接入前需逐一审计。
|
|
54
|
+
*/
|
|
55
|
+
var FORM_SILENT_MODE_KEY = Symbol("mFormSilentMode");
|
|
46
56
|
//#endregion
|
|
47
57
|
//#region node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/_freeGlobal.js
|
|
48
58
|
/** Detect free variable `global` from Node.js. */
|
|
@@ -3030,6 +3040,7 @@
|
|
|
3030
3040
|
return;
|
|
3031
3041
|
}
|
|
3032
3042
|
if (typeof config.filter === "function") return;
|
|
3043
|
+
if (fieldType === "text" && isNumberValue(value)) return;
|
|
3033
3044
|
if (typeof value !== "string") return defaultMessage(message, `${value} 类型应为字符串`, typeExampleSuggestion(mForm, props, "\"文本内容\"", isStringValue));
|
|
3034
3045
|
return;
|
|
3035
3046
|
}
|
|
@@ -3079,6 +3090,7 @@
|
|
|
3079
3090
|
};
|
|
3080
3091
|
var validateTypeMatch = (value, mForm, props, message) => {
|
|
3081
3092
|
if (isEmptyValue(value) || isEmptyArray(value)) return;
|
|
3093
|
+
if (!props.config?.name) return;
|
|
3082
3094
|
const rawFieldType = "type" in (props.config || {}) ? props.config.type : "";
|
|
3083
3095
|
if (typeof rawFieldType !== "string" || !rawFieldType) return;
|
|
3084
3096
|
const fieldType = (0, _tmagic_utils.toLine)(rawFieldType);
|
|
@@ -3494,7 +3506,8 @@
|
|
|
3494
3506
|
isCompare: {
|
|
3495
3507
|
type: Boolean,
|
|
3496
3508
|
default: false
|
|
3497
|
-
}
|
|
3509
|
+
},
|
|
3510
|
+
isInRow: { type: Boolean }
|
|
3498
3511
|
},
|
|
3499
3512
|
emits: ["change", "addDiffCount"],
|
|
3500
3513
|
setup(__props, { emit: __emit }) {
|
|
@@ -3611,6 +3624,7 @@
|
|
|
3611
3624
|
if (items.value && !text.value && type.value && display$3.value) return;
|
|
3612
3625
|
if (display$3.value && showDiff && type.value) emit("addDiffCount");
|
|
3613
3626
|
}, { immediate: true });
|
|
3627
|
+
(0, vue.provide)("isInRow", props.isInRow ?? false);
|
|
3614
3628
|
const expandHandler = () => expand.value = !expand.value;
|
|
3615
3629
|
const key = (config) => config[mForm?.keyProps];
|
|
3616
3630
|
const filterHandler = (filter, value) => {
|
|
@@ -4430,7 +4444,7 @@
|
|
|
4430
4444
|
resolve,
|
|
4431
4445
|
reject
|
|
4432
4446
|
});
|
|
4433
|
-
const
|
|
4447
|
+
const wrapperComponent = typeof extendState === "function" ? (0, vue.defineComponent)({
|
|
4434
4448
|
name: "MFormExtendStateInjector",
|
|
4435
4449
|
setup() {
|
|
4436
4450
|
(0, vue.watch)(() => formRef.value, (form) => {
|
|
@@ -4451,7 +4465,14 @@
|
|
|
4451
4465
|
});
|
|
4452
4466
|
return () => (0, vue.h)(userWrapper);
|
|
4453
4467
|
}
|
|
4454
|
-
}) : userWrapper
|
|
4468
|
+
}) : userWrapper;
|
|
4469
|
+
const app = (0, vue.createApp)(hidden ? (0, vue.defineComponent)({
|
|
4470
|
+
name: "MFormSilentProvider",
|
|
4471
|
+
setup() {
|
|
4472
|
+
(0, vue.provide)(FORM_SILENT_MODE_KEY, true);
|
|
4473
|
+
return () => (0, vue.h)(wrapperComponent);
|
|
4474
|
+
}
|
|
4475
|
+
}) : wrapperComponent);
|
|
4455
4476
|
instance.app = app;
|
|
4456
4477
|
if (appContext) Object.assign(app._context, appContext);
|
|
4457
4478
|
if (timeout > 0 && !skipTimeout) timer = setTimeout(() => {
|
|
@@ -5766,7 +5787,8 @@
|
|
|
5766
5787
|
size: __props.size,
|
|
5767
5788
|
disabled: __props.disabled,
|
|
5768
5789
|
onChange: changeHandler,
|
|
5769
|
-
onAddDiffCount
|
|
5790
|
+
onAddDiffCount,
|
|
5791
|
+
"is-in-row": true
|
|
5770
5792
|
}, null, 8, [
|
|
5771
5793
|
"model",
|
|
5772
5794
|
"lastValues",
|
|
@@ -9204,6 +9226,7 @@
|
|
|
9204
9226
|
var createForm = (config) => config;
|
|
9205
9227
|
//#endregion
|
|
9206
9228
|
exports.FORM_DIFF_CONFIG_KEY = FORM_DIFF_CONFIG_KEY;
|
|
9229
|
+
exports.FORM_SILENT_MODE_KEY = FORM_SILENT_MODE_KEY;
|
|
9207
9230
|
exports.FORM_TYPE_MATCH_VALID_KEY = FORM_TYPE_MATCH_VALID_KEY;
|
|
9208
9231
|
exports.MCascader = Cascader_default;
|
|
9209
9232
|
exports.MCheckbox = Checkbox_default;
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.8.0-beta.
|
|
2
|
+
"version": "1.8.0-beta.15",
|
|
3
3
|
"name": "@tmagic/form",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": [
|
|
@@ -52,9 +52,9 @@
|
|
|
52
52
|
"peerDependencies": {
|
|
53
53
|
"vue": "^3.5.40",
|
|
54
54
|
"typescript": "^6.0.3",
|
|
55
|
-
"@tmagic/
|
|
56
|
-
"@tmagic/
|
|
57
|
-
"@tmagic/
|
|
55
|
+
"@tmagic/design": "1.8.0-beta.15",
|
|
56
|
+
"@tmagic/form-schema": "1.8.0-beta.15",
|
|
57
|
+
"@tmagic/utils": "1.8.0-beta.15"
|
|
58
58
|
},
|
|
59
59
|
"peerDependenciesMeta": {
|
|
60
60
|
"typescript": {
|
package/src/containers/Col.vue
CHANGED
|
@@ -240,7 +240,7 @@
|
|
|
240
240
|
</template>
|
|
241
241
|
|
|
242
242
|
<script setup lang="ts">
|
|
243
|
-
import { computed, inject, readonly, ref, toRaw, watch, watchEffect } from 'vue';
|
|
243
|
+
import { computed, inject, provide, readonly, ref, toRaw, watch, watchEffect } from 'vue';
|
|
244
244
|
import { ArrowDown, ArrowUp, WarningFilled } from '@element-plus/icons-vue';
|
|
245
245
|
import { isEqual } from 'lodash-es';
|
|
246
246
|
|
|
@@ -287,6 +287,8 @@ const props = withDefaults(
|
|
|
287
287
|
size?: string;
|
|
288
288
|
/** 是否开启对比模式 */
|
|
289
289
|
isCompare?: boolean;
|
|
290
|
+
/** 是否在行容器中 */
|
|
291
|
+
isInRow?: boolean;
|
|
290
292
|
}>(),
|
|
291
293
|
{
|
|
292
294
|
prop: '',
|
|
@@ -476,6 +478,8 @@ watch(
|
|
|
476
478
|
},
|
|
477
479
|
);
|
|
478
480
|
|
|
481
|
+
provide('isInRow', props.isInRow ?? false);
|
|
482
|
+
|
|
479
483
|
const expandHandler = () => (expand.value = !expand.value);
|
|
480
484
|
|
|
481
485
|
const key = (config: any) => config[mForm?.keyProps];
|
package/src/schema.ts
CHANGED
|
@@ -29,6 +29,17 @@ export interface FormDiffConfig {
|
|
|
29
29
|
export const FORM_DIFF_CONFIG_KEY: InjectionKey<FormDiffConfig> = Symbol('mFormDiffConfig');
|
|
30
30
|
export const FORM_TYPE_MATCH_VALID_KEY: InjectionKey<ComputedRef<boolean>> = Symbol('mFormTypeMatchValid');
|
|
31
31
|
|
|
32
|
+
/**
|
|
33
|
+
* 静默模式标记,由 `submitForm` / `validateForm` 以隐藏方式挂载临时表单时 provide(debug 弹层模式不提供)。
|
|
34
|
+
*
|
|
35
|
+
* 重型字段组件(如 vs-code)可 inject 该标记并跳过自身渲染:字段校验由 FormItem 基于 model 值完成,
|
|
36
|
+
* 与叶子 UI 组件实例无关,跳过可省去无谓的实例化开销(如 monaco worker / model 的创建)。
|
|
37
|
+
*
|
|
38
|
+
* 注意:仅「挂载无值副作用」(不在 onMounted/watch immediate 中 emit change、不依赖 DOM 计算值)的
|
|
39
|
+
* 字段组件可以安全跳过,接入前需逐一审计。
|
|
40
|
+
*/
|
|
41
|
+
export const FORM_SILENT_MODE_KEY: InjectionKey<boolean> = Symbol('mFormSilentMode');
|
|
42
|
+
|
|
32
43
|
export interface ValidateError {
|
|
33
44
|
message: string;
|
|
34
45
|
field: string;
|
package/src/submitForm.ts
CHANGED
|
@@ -16,11 +16,22 @@
|
|
|
16
16
|
* limitations under the License.
|
|
17
17
|
*/
|
|
18
18
|
|
|
19
|
-
import {
|
|
19
|
+
import {
|
|
20
|
+
type AppContext,
|
|
21
|
+
type Component,
|
|
22
|
+
createApp,
|
|
23
|
+
defineComponent,
|
|
24
|
+
h,
|
|
25
|
+
nextTick,
|
|
26
|
+
provide,
|
|
27
|
+
type Ref,
|
|
28
|
+
ref,
|
|
29
|
+
watch,
|
|
30
|
+
} from 'vue';
|
|
20
31
|
|
|
21
32
|
import { applyExtendState } from './utils/form';
|
|
22
33
|
import Form from './Form.vue';
|
|
23
|
-
import type
|
|
34
|
+
import { type ChangeRecord, FORM_SILENT_MODE_KEY, type FormConfig, type FormState } from './schema';
|
|
24
35
|
|
|
25
36
|
// #region SubmitFormOptions
|
|
26
37
|
/**
|
|
@@ -210,7 +221,21 @@ const mountFormInstance = <T>(options: MountFormInstanceOptions<T>): Promise<T>
|
|
|
210
221
|
})
|
|
211
222
|
: userWrapper;
|
|
212
223
|
|
|
213
|
-
|
|
224
|
+
// 静默(隐藏挂载)模式下注入静默标记:vs-code 等重型字段组件可据此跳过自身渲染,
|
|
225
|
+
// 校验/取值依赖 FormItem 与 model 值,与叶子 UI 组件无关(见 FORM_SILENT_MODE_KEY 注释)。
|
|
226
|
+
// 用组件级 provide 而非 app.provide:appContext 合并后 app._context.provides 与父级应用
|
|
227
|
+
// 共享引用,app.provide 会把标记泄漏到父级应用。
|
|
228
|
+
const rootComponent = hidden
|
|
229
|
+
? defineComponent({
|
|
230
|
+
name: 'MFormSilentProvider',
|
|
231
|
+
setup() {
|
|
232
|
+
provide(FORM_SILENT_MODE_KEY, true);
|
|
233
|
+
return () => h(wrapperComponent);
|
|
234
|
+
},
|
|
235
|
+
})
|
|
236
|
+
: wrapperComponent;
|
|
237
|
+
|
|
238
|
+
const app = createApp(rootComponent);
|
|
214
239
|
instance.app = app;
|
|
215
240
|
|
|
216
241
|
// 继承父级应用上下文(components / directives / provides / config 等)
|
package/src/utils/typeMatch.ts
CHANGED
|
@@ -558,6 +558,11 @@ const validateBuiltinTypeMatch = (
|
|
|
558
558
|
return undefined;
|
|
559
559
|
}
|
|
560
560
|
|
|
561
|
+
// text 常与数字(如 id、数量)绑定,值允许为数字;错误建议仍按字符串给出
|
|
562
|
+
if (fieldType === 'text' && isNumberValue(value)) {
|
|
563
|
+
return undefined;
|
|
564
|
+
}
|
|
565
|
+
|
|
561
566
|
if (typeof value !== 'string') {
|
|
562
567
|
return defaultMessage(
|
|
563
568
|
message,
|
|
@@ -697,9 +702,13 @@ export const validateTypeMatch = (
|
|
|
697
702
|
return undefined;
|
|
698
703
|
}
|
|
699
704
|
|
|
705
|
+
if (!props.config?.name) {
|
|
706
|
+
return undefined;
|
|
707
|
+
}
|
|
708
|
+
|
|
700
709
|
const rawFieldType = 'type' in (props.config || {}) ? props.config.type : '';
|
|
701
710
|
if (typeof rawFieldType !== 'string' || !rawFieldType) {
|
|
702
|
-
return;
|
|
711
|
+
return undefined;
|
|
703
712
|
}
|
|
704
713
|
|
|
705
714
|
// 统一将驼峰形式(如 radioGroup)归一化为连字符形式(radio-group),与内置规则的 key 保持一致
|
package/types/index.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ export * from "@tmagic/form-schema";
|
|
|
4
4
|
|
|
5
5
|
//#region \0rolldown/runtime.js
|
|
6
6
|
declare namespace schema_d_exports {
|
|
7
|
-
export { ChangeRecord, ContainerChangeEventData, FORM_DIFF_CONFIG_KEY, FORM_TYPE_MATCH_VALID_KEY, FormDiffConfig, FormLabelSlotProps, FormSlots, ValidateError };
|
|
7
|
+
export { ChangeRecord, ContainerChangeEventData, FORM_DIFF_CONFIG_KEY, FORM_SILENT_MODE_KEY, FORM_TYPE_MATCH_VALID_KEY, FormDiffConfig, FormLabelSlotProps, FormSlots, ValidateError };
|
|
8
8
|
}
|
|
9
9
|
import * as import__tmagic_form_schema from "@tmagic/form-schema";
|
|
10
10
|
/**
|
|
@@ -34,6 +34,16 @@ interface FormDiffConfig {
|
|
|
34
34
|
}
|
|
35
35
|
declare const FORM_DIFF_CONFIG_KEY: InjectionKey<FormDiffConfig>;
|
|
36
36
|
declare const FORM_TYPE_MATCH_VALID_KEY: InjectionKey<ComputedRef<boolean>>;
|
|
37
|
+
/**
|
|
38
|
+
* 静默模式标记,由 `submitForm` / `validateForm` 以隐藏方式挂载临时表单时 provide(debug 弹层模式不提供)。
|
|
39
|
+
*
|
|
40
|
+
* 重型字段组件(如 vs-code)可 inject 该标记并跳过自身渲染:字段校验由 FormItem 基于 model 值完成,
|
|
41
|
+
* 与叶子 UI 组件实例无关,跳过可省去无谓的实例化开销(如 monaco worker / model 的创建)。
|
|
42
|
+
*
|
|
43
|
+
* 注意:仅「挂载无值副作用」(不在 onMounted/watch immediate 中 emit change、不依赖 DOM 计算值)的
|
|
44
|
+
* 字段组件可以安全跳过,接入前需逐一审计。
|
|
45
|
+
*/
|
|
46
|
+
declare const FORM_SILENT_MODE_KEY: InjectionKey<boolean>;
|
|
37
47
|
interface ValidateError {
|
|
38
48
|
message: string;
|
|
39
49
|
field: string;
|
|
@@ -1773,7 +1783,8 @@ type __VLS_Props$26 = {
|
|
|
1773
1783
|
expandMore?: boolean;
|
|
1774
1784
|
stepActive?: string | number;
|
|
1775
1785
|
size?: string; /** 是否开启对比模式 */
|
|
1776
|
-
isCompare?: boolean;
|
|
1786
|
+
isCompare?: boolean; /** 是否在行容器中 */
|
|
1787
|
+
isInRow?: boolean;
|
|
1777
1788
|
};
|
|
1778
1789
|
declare const __VLS_base$1: import("@vue/runtime-core").DefineComponent<__VLS_Props$26, {}, {}, {}, {}, import("@vue/runtime-core").ComponentOptionsMixin, import("@vue/runtime-core").ComponentOptionsMixin, {
|
|
1779
1790
|
change: (v: any, eventData: ContainerChangeEventData) => any;
|
|
@@ -2207,8 +2218,8 @@ declare const _default$31: {
|
|
|
2207
2218
|
install(app: App, opt?: FormInstallOptions): void;
|
|
2208
2219
|
};
|
|
2209
2220
|
declare namespace index_d_exports {
|
|
2210
|
-
export { ChangeRecord, ContainerChangeEventData, FORM_DIFF_CONFIG_KEY, FORM_TYPE_MATCH_VALID_KEY, FormDiffConfig, FormInstallOptions, FormLabelSlotProps, FormSlots, _default as MCascader, _default$1 as MCheckbox, _default$2 as MCheckboxGroup, _default$3 as MColorPicker, _default$4 as MContainer, _default$5 as MDate, _default$6 as MDateTime, _default$7 as MDaterange, _default$8 as MDisplay, _default$9 as MDynamicField, _default$10 as MFieldset, _default$11 as MFlexLayout, _default$12 as MForm, _default$13 as MFormBox, _default$14 as MFormDialog, _default$15 as MFormDrawer, _default$16 as MGroupList, _default$17 as MHidden, _default$18 as MLink, _default$19 as MNumber, _default$20 as MNumberRange, _default$21 as MPanel, _default$22 as MRadioGroup, _default$23 as MRow, _default$24 as MSelect, _default$25 as MSwitch, _default$16 as MTable, _default$16 as MTableGroupList, _default$26 as MTabs, _default$27 as MText, _default$28 as MTextarea, _default$29 as MTime, _default$30 as MTimerange, SubmitFormOptions, SubmitFormResult, TypeMatchValidateContext, TypeMatchValidator, ValidateError, ValidateFormOptions, adaptFormValidator, applyExtendState, clearTypeMatchRules, createForm, createObjectProp, createValues, datetimeFormatter, _default$31 as default, deleteField as deleteFormField, deleteTypeMatchRule, display, filterFunction, getDataByPage, getField as getFormField, getRules, getTypeMatchRule, initValue, registerField as registerFormField, registerTypeMatchRule, registerTypeMatchRules, sortArray, sortChange, stripTabItemsLazy, submitForm, useAddField, validateForm, validateTypeMatch };
|
|
2221
|
+
export { ChangeRecord, ContainerChangeEventData, FORM_DIFF_CONFIG_KEY, FORM_SILENT_MODE_KEY, FORM_TYPE_MATCH_VALID_KEY, FormDiffConfig, FormInstallOptions, FormLabelSlotProps, FormSlots, _default as MCascader, _default$1 as MCheckbox, _default$2 as MCheckboxGroup, _default$3 as MColorPicker, _default$4 as MContainer, _default$5 as MDate, _default$6 as MDateTime, _default$7 as MDaterange, _default$8 as MDisplay, _default$9 as MDynamicField, _default$10 as MFieldset, _default$11 as MFlexLayout, _default$12 as MForm, _default$13 as MFormBox, _default$14 as MFormDialog, _default$15 as MFormDrawer, _default$16 as MGroupList, _default$17 as MHidden, _default$18 as MLink, _default$19 as MNumber, _default$20 as MNumberRange, _default$21 as MPanel, _default$22 as MRadioGroup, _default$23 as MRow, _default$24 as MSelect, _default$25 as MSwitch, _default$16 as MTable, _default$16 as MTableGroupList, _default$26 as MTabs, _default$27 as MText, _default$28 as MTextarea, _default$29 as MTime, _default$30 as MTimerange, SubmitFormOptions, SubmitFormResult, TypeMatchValidateContext, TypeMatchValidator, ValidateError, ValidateFormOptions, adaptFormValidator, applyExtendState, clearTypeMatchRules, createForm, createObjectProp, createValues, datetimeFormatter, _default$31 as default, deleteField as deleteFormField, deleteTypeMatchRule, display, filterFunction, getDataByPage, getField as getFormField, getRules, getTypeMatchRule, initValue, registerField as registerFormField, registerTypeMatchRule, registerTypeMatchRules, sortArray, sortChange, stripTabItemsLazy, submitForm, useAddField, validateForm, validateTypeMatch };
|
|
2211
2222
|
}
|
|
2212
2223
|
declare const createForm: <T extends [] = []>(config: schema_d_exports.FormConfig | T) => schema_d_exports.FormConfig | T;
|
|
2213
2224
|
//#endregion
|
|
2214
|
-
export { ChangeRecord, ContainerChangeEventData, FORM_DIFF_CONFIG_KEY, FORM_TYPE_MATCH_VALID_KEY, FormDiffConfig, type FormInstallOptions, FormLabelSlotProps, FormSlots, _default as MCascader, _default$1 as MCheckbox, _default$2 as MCheckboxGroup, _default$3 as MColorPicker, _default$4 as MContainer, _default$5 as MDate, _default$6 as MDateTime, _default$7 as MDaterange, _default$8 as MDisplay, _default$9 as MDynamicField, _default$10 as MFieldset, _default$11 as MFlexLayout, _default$12 as MForm, _default$13 as MFormBox, _default$14 as MFormDialog, _default$15 as MFormDrawer, _default$16 as MGroupList, _default$16 as MTable, _default$16 as MTableGroupList, _default$17 as MHidden, _default$18 as MLink, _default$19 as MNumber, _default$20 as MNumberRange, _default$21 as MPanel, _default$22 as MRadioGroup, _default$23 as MRow, _default$24 as MSelect, _default$25 as MSwitch, _default$26 as MTabs, _default$27 as MText, _default$28 as MTextarea, _default$29 as MTime, _default$30 as MTimerange, SubmitFormOptions, SubmitFormResult, type TypeMatchValidateContext, type TypeMatchValidator, ValidateError, ValidateFormOptions, adaptFormValidator, applyExtendState, clearTypeMatchRules, createForm, createObjectProp, createValues, datetimeFormatter, _default$31 as default, deleteField as deleteFormField, deleteTypeMatchRule, display, filterFunction, getDataByPage, getField as getFormField, getRules, getTypeMatchRule, initValue, registerField as registerFormField, registerTypeMatchRule, registerTypeMatchRules, sortArray, sortChange, stripTabItemsLazy, submitForm, useAddField, validateForm, validateTypeMatch };
|
|
2225
|
+
export { ChangeRecord, ContainerChangeEventData, FORM_DIFF_CONFIG_KEY, FORM_SILENT_MODE_KEY, FORM_TYPE_MATCH_VALID_KEY, FormDiffConfig, type FormInstallOptions, FormLabelSlotProps, FormSlots, _default as MCascader, _default$1 as MCheckbox, _default$2 as MCheckboxGroup, _default$3 as MColorPicker, _default$4 as MContainer, _default$5 as MDate, _default$6 as MDateTime, _default$7 as MDaterange, _default$8 as MDisplay, _default$9 as MDynamicField, _default$10 as MFieldset, _default$11 as MFlexLayout, _default$12 as MForm, _default$13 as MFormBox, _default$14 as MFormDialog, _default$15 as MFormDrawer, _default$16 as MGroupList, _default$16 as MTable, _default$16 as MTableGroupList, _default$17 as MHidden, _default$18 as MLink, _default$19 as MNumber, _default$20 as MNumberRange, _default$21 as MPanel, _default$22 as MRadioGroup, _default$23 as MRow, _default$24 as MSelect, _default$25 as MSwitch, _default$26 as MTabs, _default$27 as MText, _default$28 as MTextarea, _default$29 as MTime, _default$30 as MTimerange, SubmitFormOptions, SubmitFormResult, type TypeMatchValidateContext, type TypeMatchValidator, ValidateError, ValidateFormOptions, adaptFormValidator, applyExtendState, clearTypeMatchRules, createForm, createObjectProp, createValues, datetimeFormatter, _default$31 as default, deleteField as deleteFormField, deleteTypeMatchRule, display, filterFunction, getDataByPage, getField as getFormField, getRules, getTypeMatchRule, initValue, registerField as registerFormField, registerTypeMatchRule, registerTypeMatchRules, sortArray, sortChange, stripTabItemsLazy, submitForm, useAddField, validateForm, validateTypeMatch };
|