@tmagic/form 1.4.9 → 1.4.11
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/style.css +4 -0
- package/dist/tmagic-form.js +14 -12
- package/dist/tmagic-form.umd.cjs +14 -12
- package/package.json +3 -3
- package/src/containers/GroupList.vue +1 -0
- package/src/fields/Cascader.vue +1 -1
- package/src/fields/CheckboxGroup.vue +3 -2
- package/src/schema.ts +8 -7
- package/src/theme/container.scss +5 -0
- package/src/theme/index.scss +1 -0
- package/src/utils/form.ts +17 -12
- package/types/schema.d.ts +7 -5
- package/types/utils/form.d.ts +2 -2
package/dist/style.css
CHANGED
package/dist/tmagic-form.js
CHANGED
|
@@ -97,18 +97,18 @@ const getDefaultValue = function(mForm, { defaultValue, type, filter, multiple }
|
|
|
97
97
|
return "";
|
|
98
98
|
};
|
|
99
99
|
const filterFunction = (mForm, config, props) => {
|
|
100
|
-
if (typeof config
|
|
101
|
-
return config
|
|
100
|
+
if (typeof config === "function") {
|
|
101
|
+
return config(mForm, {
|
|
102
|
+
values: mForm?.initValues || {},
|
|
103
|
+
model: props.model,
|
|
104
|
+
parent: mForm?.parentValues || {},
|
|
105
|
+
formValue: mForm?.values || props.model,
|
|
106
|
+
prop: props.prop,
|
|
107
|
+
config: props.config,
|
|
108
|
+
index: props.index
|
|
109
|
+
});
|
|
102
110
|
}
|
|
103
|
-
return config
|
|
104
|
-
values: mForm?.initValues || {},
|
|
105
|
-
model: props.model,
|
|
106
|
-
parent: mForm?.parentValues || {},
|
|
107
|
-
formValue: mForm?.values || props.model,
|
|
108
|
-
prop: props.prop,
|
|
109
|
-
config: props.config,
|
|
110
|
-
index: props.index
|
|
111
|
-
});
|
|
111
|
+
return config;
|
|
112
112
|
};
|
|
113
113
|
const display = function(mForm, config, props) {
|
|
114
114
|
if (config === "expand") {
|
|
@@ -953,6 +953,7 @@ const _sfc_main$u = /* @__PURE__ */ defineComponent({
|
|
|
953
953
|
initValues
|
|
954
954
|
});
|
|
955
955
|
props.model[props.name].push(groupValue);
|
|
956
|
+
changeHandler();
|
|
956
957
|
};
|
|
957
958
|
const removeHandler = (index) => {
|
|
958
959
|
if (!props.name) return false;
|
|
@@ -2366,7 +2367,8 @@ const _sfc_main$l = /* @__PURE__ */ defineComponent({
|
|
|
2366
2367
|
const mForm = inject("mForm");
|
|
2367
2368
|
const options = computed(() => {
|
|
2368
2369
|
if (Array.isArray(props.config.options)) return props.config.options;
|
|
2369
|
-
if (typeof props.config.options === "function")
|
|
2370
|
+
if (typeof props.config.options === "function")
|
|
2371
|
+
return filterFunction(mForm, props.config.options, props) || [];
|
|
2370
2372
|
return [];
|
|
2371
2373
|
});
|
|
2372
2374
|
return (_ctx, _cache) => {
|
package/dist/tmagic-form.umd.cjs
CHANGED
|
@@ -96,18 +96,18 @@
|
|
|
96
96
|
return "";
|
|
97
97
|
};
|
|
98
98
|
const filterFunction = (mForm, config, props) => {
|
|
99
|
-
if (typeof config
|
|
100
|
-
return config
|
|
99
|
+
if (typeof config === "function") {
|
|
100
|
+
return config(mForm, {
|
|
101
|
+
values: mForm?.initValues || {},
|
|
102
|
+
model: props.model,
|
|
103
|
+
parent: mForm?.parentValues || {},
|
|
104
|
+
formValue: mForm?.values || props.model,
|
|
105
|
+
prop: props.prop,
|
|
106
|
+
config: props.config,
|
|
107
|
+
index: props.index
|
|
108
|
+
});
|
|
101
109
|
}
|
|
102
|
-
return config
|
|
103
|
-
values: mForm?.initValues || {},
|
|
104
|
-
model: props.model,
|
|
105
|
-
parent: mForm?.parentValues || {},
|
|
106
|
-
formValue: mForm?.values || props.model,
|
|
107
|
-
prop: props.prop,
|
|
108
|
-
config: props.config,
|
|
109
|
-
index: props.index
|
|
110
|
-
});
|
|
110
|
+
return config;
|
|
111
111
|
};
|
|
112
112
|
const display = function(mForm, config, props) {
|
|
113
113
|
if (config === "expand") {
|
|
@@ -952,6 +952,7 @@
|
|
|
952
952
|
initValues
|
|
953
953
|
});
|
|
954
954
|
props.model[props.name].push(groupValue);
|
|
955
|
+
changeHandler();
|
|
955
956
|
};
|
|
956
957
|
const removeHandler = (index) => {
|
|
957
958
|
if (!props.name) return false;
|
|
@@ -2365,7 +2366,8 @@
|
|
|
2365
2366
|
const mForm = vue.inject("mForm");
|
|
2366
2367
|
const options = vue.computed(() => {
|
|
2367
2368
|
if (Array.isArray(props.config.options)) return props.config.options;
|
|
2368
|
-
if (typeof props.config.options === "function")
|
|
2369
|
+
if (typeof props.config.options === "function")
|
|
2370
|
+
return filterFunction(mForm, props.config.options, props) || [];
|
|
2369
2371
|
return [];
|
|
2370
2372
|
});
|
|
2371
2373
|
return (_ctx, _cache) => {
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.4.
|
|
2
|
+
"version": "1.4.11",
|
|
3
3
|
"name": "@tmagic/form",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": [
|
|
@@ -54,8 +54,8 @@
|
|
|
54
54
|
"peerDependencies": {
|
|
55
55
|
"vue": "^3.4.27",
|
|
56
56
|
"typescript": "*",
|
|
57
|
-
"@tmagic/design": "1.4.
|
|
58
|
-
"@tmagic/utils": "1.4.
|
|
57
|
+
"@tmagic/design": "1.4.11",
|
|
58
|
+
"@tmagic/utils": "1.4.11"
|
|
59
59
|
},
|
|
60
60
|
"peerDependenciesMeta": {
|
|
61
61
|
"typescript": {
|
package/src/fields/Cascader.vue
CHANGED
|
@@ -49,7 +49,7 @@ const options = ref<CascaderOption[]>([]);
|
|
|
49
49
|
const remoteData = ref<any>(null);
|
|
50
50
|
|
|
51
51
|
const checkStrictly = computed(() => filterFunction(mForm, props.config.checkStrictly, props));
|
|
52
|
-
const valueSeparator = computed(() => filterFunction(mForm, props.config.valueSeparator, props));
|
|
52
|
+
const valueSeparator = computed(() => filterFunction<string>(mForm, props.config.valueSeparator, props));
|
|
53
53
|
|
|
54
54
|
const value = computed({
|
|
55
55
|
get() {
|
|
@@ -11,7 +11,7 @@ import { computed, inject } from 'vue';
|
|
|
11
11
|
|
|
12
12
|
import { TMagicCheckbox, TMagicCheckboxGroup } from '@tmagic/design';
|
|
13
13
|
|
|
14
|
-
import type { CheckboxGroupConfig, FieldProps, FormState } from '../schema';
|
|
14
|
+
import type { CheckboxGroupConfig, CheckboxGroupOption, FieldProps, FormState } from '../schema';
|
|
15
15
|
import { filterFunction } from '../utils/form';
|
|
16
16
|
import { useAddField } from '../utils/useAddField';
|
|
17
17
|
|
|
@@ -37,7 +37,8 @@ const changeHandler = (v: Array<string | number | boolean>) => {
|
|
|
37
37
|
const mForm = inject<FormState | undefined>('mForm');
|
|
38
38
|
const options = computed(() => {
|
|
39
39
|
if (Array.isArray(props.config.options)) return props.config.options;
|
|
40
|
-
if (typeof props.config.options === 'function')
|
|
40
|
+
if (typeof props.config.options === 'function')
|
|
41
|
+
return filterFunction<CheckboxGroupOption[]>(mForm, props.config.options, props) || [];
|
|
41
42
|
return [];
|
|
42
43
|
});
|
|
43
44
|
</script>
|
package/src/schema.ts
CHANGED
|
@@ -170,6 +170,7 @@ export type FilterFunction<T = boolean> = (
|
|
|
170
170
|
formValue: Record<any, any>;
|
|
171
171
|
prop: string;
|
|
172
172
|
config: any;
|
|
173
|
+
index?: number;
|
|
173
174
|
},
|
|
174
175
|
) => T;
|
|
175
176
|
|
|
@@ -433,18 +434,18 @@ export interface ColorPickConfig extends FormItem {
|
|
|
433
434
|
type: 'colorPicker';
|
|
434
435
|
}
|
|
435
436
|
|
|
437
|
+
export interface CheckboxGroupOption {
|
|
438
|
+
value: any;
|
|
439
|
+
text: string;
|
|
440
|
+
disabled?: boolean;
|
|
441
|
+
}
|
|
442
|
+
|
|
436
443
|
/**
|
|
437
444
|
* 多选框组
|
|
438
445
|
*/
|
|
439
446
|
export interface CheckboxGroupConfig extends FormItem {
|
|
440
447
|
type: 'checkbox-group';
|
|
441
|
-
options:
|
|
442
|
-
| {
|
|
443
|
-
value: any;
|
|
444
|
-
text: string;
|
|
445
|
-
disabled?: boolean;
|
|
446
|
-
}[]
|
|
447
|
-
| Function;
|
|
448
|
+
options: CheckboxGroupOption[] | FilterFunction<CheckboxGroupOption[]>;
|
|
448
449
|
}
|
|
449
450
|
|
|
450
451
|
/**
|
package/src/theme/index.scss
CHANGED
package/src/utils/form.ts
CHANGED
|
@@ -24,6 +24,7 @@ import {
|
|
|
24
24
|
ChildConfig,
|
|
25
25
|
ContainerCommonConfig,
|
|
26
26
|
DaterangeConfig,
|
|
27
|
+
FilterFunction,
|
|
27
28
|
FormConfig,
|
|
28
29
|
FormState,
|
|
29
30
|
FormValue,
|
|
@@ -181,20 +182,24 @@ const getDefaultValue = function (mForm: FormState | undefined, { defaultValue,
|
|
|
181
182
|
return '';
|
|
182
183
|
};
|
|
183
184
|
|
|
184
|
-
export const filterFunction = <T = any>(
|
|
185
|
-
|
|
186
|
-
|
|
185
|
+
export const filterFunction = <T = any>(
|
|
186
|
+
mForm: FormState | undefined,
|
|
187
|
+
config: T | FilterFunction<T> | undefined,
|
|
188
|
+
props: any,
|
|
189
|
+
) => {
|
|
190
|
+
if (typeof config === 'function') {
|
|
191
|
+
return (config as FilterFunction<T>)(mForm, {
|
|
192
|
+
values: mForm?.initValues || {},
|
|
193
|
+
model: props.model,
|
|
194
|
+
parent: mForm?.parentValues || {},
|
|
195
|
+
formValue: mForm?.values || props.model,
|
|
196
|
+
prop: props.prop,
|
|
197
|
+
config: props.config,
|
|
198
|
+
index: props.index,
|
|
199
|
+
});
|
|
187
200
|
}
|
|
188
201
|
|
|
189
|
-
return config
|
|
190
|
-
values: mForm?.initValues || {},
|
|
191
|
-
model: props.model,
|
|
192
|
-
parent: mForm?.parentValues || {},
|
|
193
|
-
formValue: mForm?.values || props.model,
|
|
194
|
-
prop: props.prop,
|
|
195
|
-
config: props.config,
|
|
196
|
-
index: props.index,
|
|
197
|
-
});
|
|
202
|
+
return config;
|
|
198
203
|
};
|
|
199
204
|
|
|
200
205
|
export const display = function (mForm: FormState | undefined, config: any, props: any) {
|
package/types/schema.d.ts
CHANGED
|
@@ -130,6 +130,7 @@ export type FilterFunction<T = boolean> = (mForm: FormState | undefined, data: {
|
|
|
130
130
|
formValue: Record<any, any>;
|
|
131
131
|
prop: string;
|
|
132
132
|
config: any;
|
|
133
|
+
index?: number;
|
|
133
134
|
}) => T;
|
|
134
135
|
type OnChangeHandler = (mForm: FormState | undefined, value: any, data: {
|
|
135
136
|
model: Record<any, any>;
|
|
@@ -346,16 +347,17 @@ export interface RadioGroupConfig extends FormItem {
|
|
|
346
347
|
export interface ColorPickConfig extends FormItem {
|
|
347
348
|
type: 'colorPicker';
|
|
348
349
|
}
|
|
350
|
+
export interface CheckboxGroupOption {
|
|
351
|
+
value: any;
|
|
352
|
+
text: string;
|
|
353
|
+
disabled?: boolean;
|
|
354
|
+
}
|
|
349
355
|
/**
|
|
350
356
|
* 多选框组
|
|
351
357
|
*/
|
|
352
358
|
export interface CheckboxGroupConfig extends FormItem {
|
|
353
359
|
type: 'checkbox-group';
|
|
354
|
-
options:
|
|
355
|
-
value: any;
|
|
356
|
-
text: string;
|
|
357
|
-
disabled?: boolean;
|
|
358
|
-
}[] | Function;
|
|
360
|
+
options: CheckboxGroupOption[] | FilterFunction<CheckboxGroupOption[]>;
|
|
359
361
|
}
|
|
360
362
|
/**
|
|
361
363
|
* 下拉选择器
|
package/types/utils/form.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { FormConfig, FormState, FormValue, Rule, TabPaneConfig } from '../schema';
|
|
1
|
+
import { FilterFunction, FormConfig, FormState, FormValue, Rule, TabPaneConfig } from '../schema';
|
|
2
2
|
export declare const createValues: (mForm: FormState | undefined, config?: FormConfig | TabPaneConfig[], initValue?: FormValue, value?: FormValue) => FormValue;
|
|
3
|
-
export declare const filterFunction: <T = any>(mForm: FormState | undefined, config: T, props: any) =>
|
|
3
|
+
export declare const filterFunction: <T = any>(mForm: FormState | undefined, config: T | FilterFunction<T> | undefined, props: any) => T | undefined;
|
|
4
4
|
export declare const display: (mForm: FormState | undefined, config: any, props: any) => any;
|
|
5
5
|
export declare const getRules: (mForm: FormState | undefined, rules: Rule | Rule[] | undefined, props: any) => Rule[];
|
|
6
6
|
export declare const initValue: (mForm: FormState | undefined, { initValues, config }: {
|