@tmagic/form 1.3.0-alpha.2 → 1.3.0-alpha.20
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 +21 -0
- package/dist/tmagic-form.js +1400 -1187
- package/dist/tmagic-form.js.map +1 -1
- package/dist/tmagic-form.umd.cjs +1425 -1210
- package/dist/tmagic-form.umd.cjs.map +1 -1
- package/package.json +10 -11
- package/src/Form.vue +14 -2
- package/src/FormDialog.vue +20 -6
- package/src/FormDrawer.vue +134 -0
- package/src/containers/Col.vue +5 -1
- package/src/containers/Container.vue +16 -11
- package/src/containers/Fieldset.vue +5 -1
- package/src/containers/GroupList.vue +7 -2
- package/src/containers/GroupListItem.vue +15 -9
- package/src/containers/Panel.vue +5 -1
- package/src/containers/Row.vue +5 -1
- package/src/containers/Step.vue +5 -1
- package/src/containers/Table.vue +153 -151
- package/src/containers/Tabs.vue +14 -8
- package/src/fields/Cascader.vue +7 -13
- package/src/fields/Checkbox.vue +7 -13
- package/src/fields/CheckboxGroup.vue +9 -15
- package/src/fields/ColorPicker.vue +10 -14
- package/src/fields/Date.vue +11 -15
- package/src/fields/DateTime.vue +12 -16
- package/src/fields/Daterange.vue +7 -13
- package/src/fields/Display.vue +7 -11
- package/src/fields/DynamicField.vue +8 -14
- package/src/fields/Hidden.vue +7 -11
- package/src/fields/Link.vue +7 -13
- package/src/fields/Number.vue +12 -15
- package/src/fields/NumberRange.vue +50 -0
- package/src/fields/RadioGroup.vue +7 -13
- package/src/fields/Select.vue +28 -30
- package/src/fields/SelectOptionGroups.vue +7 -3
- package/src/fields/SelectOptions.vue +5 -1
- package/src/fields/Switch.vue +11 -15
- package/src/fields/Text.vue +12 -15
- package/src/fields/Textarea.vue +12 -15
- package/src/fields/Time.vue +10 -14
- package/src/index.ts +43 -37
- package/src/schema.ts +27 -5
- package/src/theme/form-drawer.scss +11 -0
- package/src/theme/index.scss +2 -0
- package/src/theme/number-range.scss +8 -0
- package/src/theme/panel.scss +6 -0
- package/src/utils/config.ts +1 -1
- package/src/utils/form.ts +2 -1
- package/types/Form.vue.d.ts +11 -6
- package/types/FormDialog.vue.d.ts +89 -125
- package/types/FormDrawer.vue.d.ts +338 -0
- package/types/containers/Col.vue.d.ts +1 -1
- package/types/containers/Container.vue.d.ts +6 -3
- package/types/containers/Fieldset.vue.d.ts +6 -3
- package/types/containers/GroupList.vue.d.ts +1 -1
- package/types/containers/GroupListItem.vue.d.ts +1 -1
- package/types/containers/Panel.vue.d.ts +3 -3
- package/types/containers/Row.vue.d.ts +1 -1
- package/types/containers/Step.vue.d.ts +6 -3
- package/types/containers/Table.vue.d.ts +9 -6
- package/types/containers/Tabs.vue.d.ts +6 -3
- package/types/fields/Cascader.vue.d.ts +3 -23
- package/types/fields/Checkbox.vue.d.ts +3 -23
- package/types/fields/CheckboxGroup.vue.d.ts +3 -23
- package/types/fields/ColorPicker.vue.d.ts +2 -24
- package/types/fields/Date.vue.d.ts +2 -24
- package/types/fields/DateTime.vue.d.ts +2 -24
- package/types/fields/Daterange.vue.d.ts +3 -23
- package/types/fields/Display.vue.d.ts +2 -18
- package/types/fields/DynamicField.vue.d.ts +3 -32
- package/types/fields/Hidden.vue.d.ts +2 -18
- package/types/fields/Link.vue.d.ts +3 -23
- package/types/fields/Number.vue.d.ts +2 -25
- package/types/fields/NumberRange.vue.d.ts +12 -0
- package/types/fields/RadioGroup.vue.d.ts +3 -23
- package/types/fields/Select.vue.d.ts +3 -23
- package/types/fields/SelectOptionGroups.vue.d.ts +2 -2
- package/types/fields/SelectOptions.vue.d.ts +2 -2
- package/types/fields/Switch.vue.d.ts +2 -24
- package/types/fields/Text.vue.d.ts +2 -25
- package/types/fields/Textarea.vue.d.ts +2 -25
- package/types/fields/Time.vue.d.ts +2 -24
- package/types/index.d.ts +6 -1
- package/types/schema.d.ts +25 -5
- package/types/utils/config.d.ts +1 -1
package/src/index.ts
CHANGED
|
@@ -38,6 +38,7 @@ import DynamicField from './fields/DynamicField.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
42
|
import RadioGroup from './fields/RadioGroup.vue';
|
|
42
43
|
import Select from './fields/Select.vue';
|
|
43
44
|
import Switch from './fields/Switch.vue';
|
|
@@ -56,6 +57,7 @@ export * from './utils/useAddField';
|
|
|
56
57
|
|
|
57
58
|
export { default as MForm } from './Form.vue';
|
|
58
59
|
export { default as MFormDialog } from './FormDialog.vue';
|
|
60
|
+
export { default as MFormDrawer } from './FormDrawer.vue';
|
|
59
61
|
export { default as MContainer } from './containers/Container.vue';
|
|
60
62
|
export { default as MFieldset } from './containers/Fieldset.vue';
|
|
61
63
|
export { default as MPanel } from './containers/Panel.vue';
|
|
@@ -65,6 +67,7 @@ export { default as MTable } from './containers/Table.vue';
|
|
|
65
67
|
export { default as MGroupList } from './containers/GroupList.vue';
|
|
66
68
|
export { default as MText } from './fields/Text.vue';
|
|
67
69
|
export { default as MNumber } from './fields/Number.vue';
|
|
70
|
+
export { default as MNumberRange } from './fields/NumberRange.vue';
|
|
68
71
|
export { default as MTextarea } from './fields/Textarea.vue';
|
|
69
72
|
export { default as MHidden } from './fields/Hidden.vue';
|
|
70
73
|
export { default as MDate } from './fields/Date.vue';
|
|
@@ -82,45 +85,48 @@ export { default as MSelect } from './fields/Select.vue';
|
|
|
82
85
|
export { default as MCascader } from './fields/Cascader.vue';
|
|
83
86
|
export { default as MDynamicField } from './fields/DynamicField.vue';
|
|
84
87
|
|
|
85
|
-
|
|
88
|
+
export interface InstallOptions {
|
|
89
|
+
[key: string]: any;
|
|
90
|
+
}
|
|
86
91
|
|
|
87
|
-
const
|
|
88
|
-
const option = Object.assign(defaultInstallOpt, opt);
|
|
92
|
+
const defaultInstallOpt: InstallOptions = {};
|
|
89
93
|
|
|
90
|
-
|
|
91
|
-
app
|
|
92
|
-
|
|
94
|
+
export default {
|
|
95
|
+
install(app: App, opt: InstallOptions = {}) {
|
|
96
|
+
const option = Object.assign(defaultInstallOpt, opt);
|
|
93
97
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
app.component('m-form-fieldset', Fieldset);
|
|
98
|
-
app.component('m-form-group-list', GroupList);
|
|
99
|
-
app.component('m-form-panel', Panel);
|
|
100
|
-
app.component('m-form-row', Row);
|
|
101
|
-
app.component('m-form-step', MStep);
|
|
102
|
-
app.component('m-form-table', Table);
|
|
103
|
-
app.component('m-form-tab', Tabs);
|
|
104
|
-
app.component('m-fields-text', Text);
|
|
105
|
-
app.component('m-fields-number', Number);
|
|
106
|
-
app.component('m-fields-textarea', Textarea);
|
|
107
|
-
app.component('m-fields-hidden', Hidden);
|
|
108
|
-
app.component('m-fields-date', Date);
|
|
109
|
-
app.component('m-fields-datetime', DateTime);
|
|
110
|
-
app.component('m-fields-daterange', Daterange);
|
|
111
|
-
app.component('m-fields-time', Time);
|
|
112
|
-
app.component('m-fields-checkbox', Checkbox);
|
|
113
|
-
app.component('m-fields-switch', Switch);
|
|
114
|
-
app.component('m-fields-color-picker', ColorPicker);
|
|
115
|
-
app.component('m-fields-checkbox-group', CheckboxGroup);
|
|
116
|
-
app.component('m-fields-radio-group', RadioGroup);
|
|
117
|
-
app.component('m-fields-display', Display);
|
|
118
|
-
app.component('m-fields-link', Link);
|
|
119
|
-
app.component('m-fields-select', Select);
|
|
120
|
-
app.component('m-fields-cascader', Cascader);
|
|
121
|
-
app.component('m-fields-dynamic-field', DynamicField);
|
|
122
|
-
};
|
|
98
|
+
// eslint-disable-next-line no-param-reassign
|
|
99
|
+
app.config.globalProperties.$MAGIC_FORM = option;
|
|
100
|
+
setConfig(option);
|
|
123
101
|
|
|
124
|
-
|
|
125
|
-
|
|
102
|
+
app.component('m-form', Form);
|
|
103
|
+
app.component('m-form-dialog', FormDialog);
|
|
104
|
+
app.component('m-form-container', Container);
|
|
105
|
+
app.component('m-form-fieldset', Fieldset);
|
|
106
|
+
app.component('m-form-group-list', GroupList);
|
|
107
|
+
app.component('m-form-panel', Panel);
|
|
108
|
+
app.component('m-form-row', Row);
|
|
109
|
+
app.component('m-form-step', MStep);
|
|
110
|
+
app.component('m-form-table', Table);
|
|
111
|
+
app.component('m-form-tab', Tabs);
|
|
112
|
+
app.component('m-fields-text', Text);
|
|
113
|
+
app.component('m-fields-number', Number);
|
|
114
|
+
app.component('m-fields-number-range', NumberRange);
|
|
115
|
+
app.component('m-fields-textarea', Textarea);
|
|
116
|
+
app.component('m-fields-hidden', Hidden);
|
|
117
|
+
app.component('m-fields-date', Date);
|
|
118
|
+
app.component('m-fields-datetime', DateTime);
|
|
119
|
+
app.component('m-fields-daterange', Daterange);
|
|
120
|
+
app.component('m-fields-time', Time);
|
|
121
|
+
app.component('m-fields-checkbox', Checkbox);
|
|
122
|
+
app.component('m-fields-switch', Switch);
|
|
123
|
+
app.component('m-fields-color-picker', ColorPicker);
|
|
124
|
+
app.component('m-fields-checkbox-group', CheckboxGroup);
|
|
125
|
+
app.component('m-fields-radio-group', RadioGroup);
|
|
126
|
+
app.component('m-fields-display', Display);
|
|
127
|
+
app.component('m-fields-link', Link);
|
|
128
|
+
app.component('m-fields-select', Select);
|
|
129
|
+
app.component('m-fields-cascader', Cascader);
|
|
130
|
+
app.component('m-fields-dynamic-field', DynamicField);
|
|
131
|
+
},
|
|
126
132
|
};
|
package/src/schema.ts
CHANGED
|
@@ -21,6 +21,18 @@ export interface ValidateError {
|
|
|
21
21
|
field: string;
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
+
export interface FieldProps<T = any> {
|
|
25
|
+
config: T;
|
|
26
|
+
model: any;
|
|
27
|
+
initValues?: any;
|
|
28
|
+
values?: any;
|
|
29
|
+
name: string;
|
|
30
|
+
prop: string;
|
|
31
|
+
disabled?: boolean;
|
|
32
|
+
size?: 'large' | 'default' | 'small';
|
|
33
|
+
lastValues?: Record<string, any>;
|
|
34
|
+
}
|
|
35
|
+
|
|
24
36
|
/**
|
|
25
37
|
* 整个表单的数据,会注入到各个组件中去
|
|
26
38
|
*/
|
|
@@ -72,7 +84,7 @@ export interface FormItem {
|
|
|
72
84
|
/** 值发生改变时调用的方法 */
|
|
73
85
|
onChange?: OnChangeHandler;
|
|
74
86
|
/** label 标签的文本 */
|
|
75
|
-
text?: string;
|
|
87
|
+
text?: string | FilterFunction;
|
|
76
88
|
/** 右侧感叹号 */
|
|
77
89
|
tip?: string;
|
|
78
90
|
|
|
@@ -146,7 +158,7 @@ export type TypeFunction = (
|
|
|
146
158
|
},
|
|
147
159
|
) => string;
|
|
148
160
|
|
|
149
|
-
type FilterFunction = (
|
|
161
|
+
export type FilterFunction = (
|
|
150
162
|
mForm: FormState | undefined,
|
|
151
163
|
data: {
|
|
152
164
|
model: Record<any, any>;
|
|
@@ -339,6 +351,13 @@ export interface NumberConfig extends FormItem {
|
|
|
339
351
|
placeholder?: string;
|
|
340
352
|
}
|
|
341
353
|
|
|
354
|
+
/**
|
|
355
|
+
* 数值范围
|
|
356
|
+
*/
|
|
357
|
+
export interface NumberRangeConfig extends FormItem {
|
|
358
|
+
type?: 'number-range';
|
|
359
|
+
}
|
|
360
|
+
|
|
342
361
|
/**
|
|
343
362
|
* 隐藏域
|
|
344
363
|
*/
|
|
@@ -435,9 +454,9 @@ export interface SelectConfig extends FormItem, Input {
|
|
|
435
454
|
allowCreate?: boolean;
|
|
436
455
|
filterable?: boolean;
|
|
437
456
|
group?: boolean;
|
|
438
|
-
options
|
|
439
|
-
remote
|
|
440
|
-
option
|
|
457
|
+
options?: SelectConfigOption[] | SelectConfigGroupOption[] | SelectOptionFunction;
|
|
458
|
+
remote?: true;
|
|
459
|
+
option?: {
|
|
441
460
|
url: string | ((mForm: FormState | undefined, data: { model: any; formValue: any }) => string);
|
|
442
461
|
initUrl?: string | ((mForm: FormState | undefined, data: { model: any; formValue: any }) => string);
|
|
443
462
|
method?: 'jsonp' | string;
|
|
@@ -661,7 +680,10 @@ export interface GroupListConfig extends FormItem {
|
|
|
661
680
|
groupItems?: FormConfig;
|
|
662
681
|
tableItems?: FormConfig;
|
|
663
682
|
titleKey?: string;
|
|
683
|
+
titlePrefix?: string;
|
|
684
|
+
title?: string | FilterFunction;
|
|
664
685
|
itemExtra?: string | FilterFunction;
|
|
686
|
+
expandAll?: boolean;
|
|
665
687
|
addable?: (mForm: FormState | undefined, data: any) => boolean | 'undefined' | boolean;
|
|
666
688
|
defaultAdd?: (mForm: FormState | undefined, data: any) => any;
|
|
667
689
|
delete?: (model: any, index: number | string | symbol, values: any) => boolean | boolean;
|
package/src/theme/index.scss
CHANGED
package/src/theme/panel.scss
CHANGED
package/src/utils/config.ts
CHANGED
package/src/utils/form.ts
CHANGED
|
@@ -174,7 +174,7 @@ const getDefaultValue = function (mForm: FormState | undefined, { defaultValue,
|
|
|
174
174
|
return false;
|
|
175
175
|
}
|
|
176
176
|
|
|
177
|
-
if (multiple) {
|
|
177
|
+
if (multiple || type === 'number-range') {
|
|
178
178
|
return [];
|
|
179
179
|
}
|
|
180
180
|
|
|
@@ -193,6 +193,7 @@ export const filterFunction = (mForm: FormState | undefined, config: any, props:
|
|
|
193
193
|
formValue: mForm?.values || props.model,
|
|
194
194
|
prop: props.prop,
|
|
195
195
|
config: props.config,
|
|
196
|
+
index: props.index,
|
|
196
197
|
});
|
|
197
198
|
};
|
|
198
199
|
|
package/types/Form.vue.d.ts
CHANGED
|
@@ -13,11 +13,12 @@ declare const _default: import("vue").DefineComponent<__VLS_WithDefaults<__VLS_T
|
|
|
13
13
|
disabled?: boolean | undefined;
|
|
14
14
|
height?: string | undefined;
|
|
15
15
|
stepActive?: string | number | undefined;
|
|
16
|
-
size?: "
|
|
16
|
+
size?: "large" | "default" | "small" | undefined;
|
|
17
17
|
inline?: boolean | undefined;
|
|
18
18
|
labelPosition?: string | undefined;
|
|
19
19
|
keyProp?: string | undefined;
|
|
20
20
|
popperClass?: string | undefined;
|
|
21
|
+
extendState?: ((state: FormState) => Record<string, any> | Promise<Record<string, any>>) | undefined;
|
|
21
22
|
}>, {
|
|
22
23
|
config: () => never[];
|
|
23
24
|
initValues: () => {};
|
|
@@ -38,7 +39,7 @@ declare const _default: import("vue").DefineComponent<__VLS_WithDefaults<__VLS_T
|
|
|
38
39
|
initialized: import("vue").Ref<boolean>;
|
|
39
40
|
changeHandler: () => void;
|
|
40
41
|
resetForm: () => any;
|
|
41
|
-
submitForm: (native?: boolean) => Promise<any>;
|
|
42
|
+
submitForm: (native?: boolean | undefined) => Promise<any>;
|
|
42
43
|
}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, ("change" | "field-input" | "field-change")[], "change" | "field-input" | "field-change", import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<__VLS_WithDefaults<__VLS_TypePropsToRuntimeProps<{
|
|
43
44
|
/** 表单配置 */
|
|
44
45
|
config: FormConfig;
|
|
@@ -53,11 +54,12 @@ declare const _default: import("vue").DefineComponent<__VLS_WithDefaults<__VLS_T
|
|
|
53
54
|
disabled?: boolean | undefined;
|
|
54
55
|
height?: string | undefined;
|
|
55
56
|
stepActive?: string | number | undefined;
|
|
56
|
-
size?: "
|
|
57
|
+
size?: "large" | "default" | "small" | undefined;
|
|
57
58
|
inline?: boolean | undefined;
|
|
58
59
|
labelPosition?: string | undefined;
|
|
59
60
|
keyProp?: string | undefined;
|
|
60
61
|
popperClass?: string | undefined;
|
|
62
|
+
extendState?: ((state: FormState) => Record<string, any> | Promise<Record<string, any>>) | undefined;
|
|
61
63
|
}>, {
|
|
62
64
|
config: () => never[];
|
|
63
65
|
initValues: () => {};
|
|
@@ -88,7 +90,7 @@ declare const _default: import("vue").DefineComponent<__VLS_WithDefaults<__VLS_T
|
|
|
88
90
|
height: string;
|
|
89
91
|
inline: boolean;
|
|
90
92
|
labelPosition: string;
|
|
91
|
-
}>;
|
|
93
|
+
}, {}>;
|
|
92
94
|
export default _default;
|
|
93
95
|
type __VLS_NonUndefinedable<T> = T extends undefined ? never : T;
|
|
94
96
|
type __VLS_TypePropsToRuntimeProps<T> = {
|
|
@@ -100,7 +102,10 @@ type __VLS_TypePropsToRuntimeProps<T> = {
|
|
|
100
102
|
};
|
|
101
103
|
};
|
|
102
104
|
type __VLS_WithDefaults<P, D> = {
|
|
103
|
-
[K in keyof Pick<P, keyof P>]: K extends keyof D ? P[K] & {
|
|
105
|
+
[K in keyof Pick<P, keyof P>]: K extends keyof D ? __VLS_Prettify<P[K] & {
|
|
104
106
|
default: D[K];
|
|
105
|
-
} : P[K];
|
|
107
|
+
}> : P[K];
|
|
106
108
|
};
|
|
109
|
+
type __VLS_Prettify<T> = {
|
|
110
|
+
[K in keyof T]: T[K];
|
|
111
|
+
} & {};
|