@tmagic/form 1.3.0-alpha.1 → 1.3.0-alpha.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.
Files changed (73) hide show
  1. package/dist/tmagic-form.js +913 -917
  2. package/dist/tmagic-form.js.map +1 -1
  3. package/dist/tmagic-form.umd.cjs +911 -915
  4. package/dist/tmagic-form.umd.cjs.map +1 -1
  5. package/package.json +10 -11
  6. package/src/Form.vue +14 -2
  7. package/src/FormDialog.vue +5 -1
  8. package/src/containers/Col.vue +5 -1
  9. package/src/containers/Container.vue +5 -1
  10. package/src/containers/Fieldset.vue +5 -1
  11. package/src/containers/GroupList.vue +6 -2
  12. package/src/containers/GroupListItem.vue +7 -7
  13. package/src/containers/Panel.vue +5 -1
  14. package/src/containers/Row.vue +5 -1
  15. package/src/containers/Step.vue +5 -1
  16. package/src/containers/Table.vue +6 -2
  17. package/src/containers/Tabs.vue +14 -8
  18. package/src/fields/Cascader.vue +5 -1
  19. package/src/fields/Checkbox.vue +5 -1
  20. package/src/fields/CheckboxGroup.vue +6 -2
  21. package/src/fields/ColorPicker.vue +5 -1
  22. package/src/fields/Date.vue +5 -1
  23. package/src/fields/DateTime.vue +5 -1
  24. package/src/fields/Daterange.vue +5 -1
  25. package/src/fields/Display.vue +5 -1
  26. package/src/fields/DynamicField.vue +5 -1
  27. package/src/fields/Hidden.vue +5 -1
  28. package/src/fields/Link.vue +5 -1
  29. package/src/fields/Number.vue +5 -1
  30. package/src/fields/RadioGroup.vue +5 -1
  31. package/src/fields/Select.vue +26 -18
  32. package/src/fields/SelectOptionGroups.vue +7 -3
  33. package/src/fields/SelectOptions.vue +5 -1
  34. package/src/fields/Switch.vue +5 -1
  35. package/src/fields/Text.vue +5 -1
  36. package/src/fields/Textarea.vue +5 -1
  37. package/src/fields/Time.vue +5 -1
  38. package/src/index.ts +39 -37
  39. package/src/schema.ts +4 -3
  40. package/types/Form.vue.d.ts +9 -4
  41. package/types/FormDialog.vue.d.ts +83 -121
  42. package/types/containers/Col.vue.d.ts +1 -1
  43. package/types/containers/Container.vue.d.ts +6 -3
  44. package/types/containers/Fieldset.vue.d.ts +6 -3
  45. package/types/containers/GroupList.vue.d.ts +1 -1
  46. package/types/containers/GroupListItem.vue.d.ts +1 -1
  47. package/types/containers/Panel.vue.d.ts +3 -3
  48. package/types/containers/Row.vue.d.ts +1 -1
  49. package/types/containers/Step.vue.d.ts +6 -3
  50. package/types/containers/Table.vue.d.ts +9 -6
  51. package/types/containers/Tabs.vue.d.ts +6 -3
  52. package/types/fields/Cascader.vue.d.ts +1 -1
  53. package/types/fields/Checkbox.vue.d.ts +1 -1
  54. package/types/fields/CheckboxGroup.vue.d.ts +1 -1
  55. package/types/fields/ColorPicker.vue.d.ts +1 -1
  56. package/types/fields/Date.vue.d.ts +1 -1
  57. package/types/fields/DateTime.vue.d.ts +1 -1
  58. package/types/fields/Daterange.vue.d.ts +1 -1
  59. package/types/fields/Display.vue.d.ts +2 -2
  60. package/types/fields/DynamicField.vue.d.ts +1 -10
  61. package/types/fields/Hidden.vue.d.ts +2 -2
  62. package/types/fields/Link.vue.d.ts +1 -1
  63. package/types/fields/Number.vue.d.ts +1 -1
  64. package/types/fields/RadioGroup.vue.d.ts +1 -1
  65. package/types/fields/Select.vue.d.ts +1 -1
  66. package/types/fields/SelectOptionGroups.vue.d.ts +2 -2
  67. package/types/fields/SelectOptions.vue.d.ts +2 -2
  68. package/types/fields/Switch.vue.d.ts +1 -1
  69. package/types/fields/Text.vue.d.ts +1 -1
  70. package/types/fields/Textarea.vue.d.ts +1 -1
  71. package/types/fields/Time.vue.d.ts +1 -1
  72. package/types/index.d.ts +4 -1
  73. package/types/schema.d.ts +4 -3
@@ -25,10 +25,11 @@
25
25
  </TMagicSelect>
26
26
  </template>
27
27
 
28
- <script lang="ts" setup name="MFormSelect">
28
+ <script lang="ts" setup>
29
29
  import { inject, onBeforeMount, Ref, ref, watch, watchEffect } from 'vue';
30
30
 
31
31
  import { TMagicSelect } from '@tmagic/design';
32
+ import { getValueByKeyPath } from '@tmagic/utils';
32
33
 
33
34
  import { FormState, SelectConfig, SelectGroupOption, SelectOption } from '../schema';
34
35
  import { getConfig } from '../utils/config';
@@ -37,6 +38,10 @@ import { useAddField } from '../utils/useAddField';
37
38
  import SelectOptionGroups from './SelectOptionGroups.vue';
38
39
  import SelectOptions from './SelectOptions.vue';
39
40
 
41
+ defineOptions({
42
+ name: 'MFormSelect',
43
+ });
44
+
40
45
  const props = defineProps<{
41
46
  config: SelectConfig;
42
47
  model: any;
@@ -77,13 +82,17 @@ const equalValue = (value: any, v: any): boolean => {
77
82
  };
78
83
 
79
84
  const mapOptions = (data: any[]) => {
80
- const { option } = props.config;
81
- const { text } = option;
82
- const { value } = option;
85
+ const {
86
+ option = {
87
+ text: 'text',
88
+ value: 'value',
89
+ },
90
+ } = props.config;
91
+ const { text = 'text', value = 'value' } = option;
83
92
 
84
93
  return data.map((item) => ({
85
- text: typeof text === 'function' ? text(item) : item[text || 'text'],
86
- value: typeof value === 'function' ? value(item) : item[value || 'value'],
94
+ text: typeof text === 'function' ? text(item) : item[text],
95
+ value: typeof value === 'function' ? value(item) : item[value],
87
96
  }));
88
97
  };
89
98
 
@@ -98,8 +107,10 @@ const getOptions = async () => {
98
107
 
99
108
  let items: SelectOption[] | SelectGroupOption[] = [];
100
109
 
101
- const { config } = props;
102
- const { option } = config;
110
+ const { option } = props.config;
111
+
112
+ if (!option) return [];
113
+
103
114
  const { root = '', totalKey = 'total' } = option;
104
115
  let { body = {}, url } = option;
105
116
 
@@ -157,12 +168,9 @@ const getOptions = async () => {
157
168
  });
158
169
  }
159
170
 
160
- const optionsData = root.split('.').reduce((accumulator, currentValue: any) => accumulator[currentValue], res);
171
+ const optionsData = getValueByKeyPath(root, res);
161
172
 
162
- const resTotal = globalThis.parseInt(
163
- totalKey.split('.').reduce((accumulator, currentValue: any) => accumulator[currentValue], res),
164
- 10,
165
- );
173
+ const resTotal = globalThis.parseInt(getValueByKeyPath(totalKey, res), 10);
166
174
  if (resTotal > 0) {
167
175
  total.value = resTotal;
168
176
  }
@@ -222,8 +230,10 @@ const getInitLocalOption = async () => {
222
230
  const getInitOption = async () => {
223
231
  if (!props.model) return [];
224
232
 
225
- const { config } = props;
226
- const { option } = config;
233
+ const { option } = props.config;
234
+
235
+ if (!option) return [];
236
+
227
237
  const { root = '', initRoot = '' } = option;
228
238
  let { initBody = {} } = option;
229
239
 
@@ -283,9 +293,7 @@ const getInitOption = async () => {
283
293
  });
284
294
  }
285
295
 
286
- let initData = (initRoot || root)
287
- .split('.')
288
- .reduce((accumulator, currentValue: any) => accumulator[currentValue], res);
296
+ let initData = getValueByKeyPath(initRoot || root, res);
289
297
  if (initData) {
290
298
  if (!Array.isArray(initData)) {
291
299
  initData = [initData];
@@ -2,7 +2,7 @@
2
2
  <TMagicOptionGroup v-for="(group, index) in options" :key="index" :label="group.label" :disabled="group.disabled">
3
3
  <component
4
4
  v-for="(item, index) in group.options"
5
- :is="uiComponent.component"
5
+ :is="uiComponent"
6
6
  :key="index"
7
7
  :label="item.label || item.text"
8
8
  :value="item.value"
@@ -12,14 +12,18 @@
12
12
  </TMagicOptionGroup>
13
13
  </template>
14
14
 
15
- <script lang="ts" setup name="MFormSelectOptionGroups">
15
+ <script lang="ts" setup>
16
16
  import { getConfig, TMagicOptionGroup } from '@tmagic/design';
17
17
 
18
18
  import { SelectGroupOption } from '../schema';
19
19
 
20
+ defineOptions({
21
+ name: 'MFormSelectOptionGroups',
22
+ });
23
+
20
24
  defineProps<{
21
25
  options: SelectGroupOption[];
22
26
  }>();
23
27
 
24
- const uiComponent = getConfig('components').option;
28
+ const uiComponent = getConfig('components')?.option.component || 'el-option';
25
29
  </script>
@@ -8,11 +8,15 @@
8
8
  ></TMagicOption>
9
9
  </template>
10
10
 
11
- <script lang="ts" setup name="MFormSelectOptions">
11
+ <script lang="ts" setup>
12
12
  import { TMagicOption } from '@tmagic/design';
13
13
 
14
14
  import { SelectOption } from '../schema';
15
15
 
16
+ defineOptions({
17
+ name: 'MFormSelectOptions',
18
+ });
19
+
16
20
  defineProps<{
17
21
  options: SelectOption[];
18
22
  valueKey?: string;
@@ -9,7 +9,7 @@
9
9
  ></TMagicSwitch>
10
10
  </template>
11
11
 
12
- <script lang="ts" setup name="MFormSwitch">
12
+ <script lang="ts" setup>
13
13
  import { computed } from 'vue';
14
14
 
15
15
  import { TMagicSwitch } from '@tmagic/design';
@@ -17,6 +17,10 @@ import { TMagicSwitch } from '@tmagic/design';
17
17
  import { SwitchConfig } from '../schema';
18
18
  import { useAddField } from '../utils/useAddField';
19
19
 
20
+ defineOptions({
21
+ name: 'MFormSwitch',
22
+ });
23
+
20
24
  const props = defineProps<{
21
25
  config: SwitchConfig;
22
26
  model: any;
@@ -23,7 +23,7 @@
23
23
  </TMagicInput>
24
24
  </template>
25
25
 
26
- <script lang="ts" setup name="MFormText">
26
+ <script lang="ts" setup>
27
27
  import { inject } from 'vue';
28
28
 
29
29
  import { TMagicButton, TMagicInput } from '@tmagic/design';
@@ -32,6 +32,10 @@ import { isNumber } from '@tmagic/utils';
32
32
  import { FormState, TextConfig } from '../schema';
33
33
  import { useAddField } from '../utils/useAddField';
34
34
 
35
+ defineOptions({
36
+ name: 'MFormText',
37
+ });
38
+
35
39
  const props = defineProps<{
36
40
  config: TextConfig;
37
41
  model: any;
@@ -12,7 +12,7 @@
12
12
  </TMagicInput>
13
13
  </template>
14
14
 
15
- <script lang="ts" setup name="MFormTextarea">
15
+ <script lang="ts" setup>
16
16
  import { inject } from 'vue';
17
17
 
18
18
  import { TMagicInput } from '@tmagic/design';
@@ -20,6 +20,10 @@ import { TMagicInput } from '@tmagic/design';
20
20
  import { FormState, TextareaConfig } from '../schema';
21
21
  import { useAddField } from '../utils/useAddField';
22
22
 
23
+ defineOptions({
24
+ name: 'MFormTextarea',
25
+ });
26
+
23
27
  const props = defineProps<{
24
28
  config: TextareaConfig;
25
29
  model: any;
@@ -10,12 +10,16 @@
10
10
  ></TMagicTimePicker>
11
11
  </template>
12
12
 
13
- <script lang="ts" setup name="MFormTime">
13
+ <script lang="ts" setup>
14
14
  import { TMagicTimePicker } from '@tmagic/design';
15
15
 
16
16
  import { TimeConfig } from '../schema';
17
17
  import { useAddField } from '../utils/useAddField';
18
18
 
19
+ defineOptions({
20
+ name: 'MFormTime',
21
+ });
22
+
19
23
  const props = defineProps<{
20
24
  config: TimeConfig;
21
25
  model: any;
package/src/index.ts CHANGED
@@ -82,45 +82,47 @@ export { default as MSelect } from './fields/Select.vue';
82
82
  export { default as MCascader } from './fields/Cascader.vue';
83
83
  export { default as MDynamicField } from './fields/DynamicField.vue';
84
84
 
85
- const defaultInstallOpt = {};
85
+ export interface InstallOptions {
86
+ [key: string]: any;
87
+ }
86
88
 
87
- const install = (app: App, opt: any) => {
88
- const option = Object.assign(defaultInstallOpt, opt);
89
+ const defaultInstallOpt: InstallOptions = {};
89
90
 
90
- // eslint-disable-next-line no-param-reassign
91
- app.config.globalProperties.$MAGIC_FORM = option;
92
- setConfig(option);
91
+ export default {
92
+ install(app: App, opt: InstallOptions = {}) {
93
+ const option = Object.assign(defaultInstallOpt, opt);
93
94
 
94
- app.component('m-form', Form);
95
- app.component('m-form-dialog', FormDialog);
96
- app.component('m-form-container', Container);
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
- };
95
+ // eslint-disable-next-line no-param-reassign
96
+ app.config.globalProperties.$MAGIC_FORM = option;
97
+ setConfig(option);
123
98
 
124
- export default {
125
- install,
99
+ app.component('m-form', Form);
100
+ app.component('m-form-dialog', FormDialog);
101
+ app.component('m-form-container', Container);
102
+ app.component('m-form-fieldset', Fieldset);
103
+ app.component('m-form-group-list', GroupList);
104
+ app.component('m-form-panel', Panel);
105
+ app.component('m-form-row', Row);
106
+ app.component('m-form-step', MStep);
107
+ app.component('m-form-table', Table);
108
+ app.component('m-form-tab', Tabs);
109
+ app.component('m-fields-text', Text);
110
+ app.component('m-fields-number', Number);
111
+ app.component('m-fields-textarea', Textarea);
112
+ app.component('m-fields-hidden', Hidden);
113
+ app.component('m-fields-date', Date);
114
+ app.component('m-fields-datetime', DateTime);
115
+ app.component('m-fields-daterange', Daterange);
116
+ app.component('m-fields-time', Time);
117
+ app.component('m-fields-checkbox', Checkbox);
118
+ app.component('m-fields-switch', Switch);
119
+ app.component('m-fields-color-picker', ColorPicker);
120
+ app.component('m-fields-checkbox-group', CheckboxGroup);
121
+ app.component('m-fields-radio-group', RadioGroup);
122
+ app.component('m-fields-display', Display);
123
+ app.component('m-fields-link', Link);
124
+ app.component('m-fields-select', Select);
125
+ app.component('m-fields-cascader', Cascader);
126
+ app.component('m-fields-dynamic-field', DynamicField);
127
+ },
126
128
  };
package/src/schema.ts CHANGED
@@ -435,9 +435,9 @@ export interface SelectConfig extends FormItem, Input {
435
435
  allowCreate?: boolean;
436
436
  filterable?: boolean;
437
437
  group?: boolean;
438
- options: SelectConfigOption[] | SelectConfigGroupOption[] | SelectOptionFunction;
439
- remote: true;
440
- option: {
438
+ options?: SelectConfigOption[] | SelectConfigGroupOption[] | SelectOptionFunction;
439
+ remote?: true;
440
+ option?: {
441
441
  url: string | ((mForm: FormState | undefined, data: { model: any; formValue: any }) => string);
442
442
  initUrl?: string | ((mForm: FormState | undefined, data: { model: any; formValue: any }) => string);
443
443
  method?: 'jsonp' | string;
@@ -662,6 +662,7 @@ export interface GroupListConfig extends FormItem {
662
662
  tableItems?: FormConfig;
663
663
  titleKey?: string;
664
664
  itemExtra?: string | FilterFunction;
665
+ expandAll?: boolean;
665
666
  addable?: (mForm: FormState | undefined, data: any) => boolean | 'undefined' | boolean;
666
667
  defaultAdd?: (mForm: FormState | undefined, data: any) => any;
667
668
  delete?: (model: any, index: number | string | symbol, values: any) => boolean | boolean;
@@ -18,6 +18,7 @@ declare const _default: import("vue").DefineComponent<__VLS_WithDefaults<__VLS_T
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;
@@ -58,6 +59,7 @@ declare const _default: import("vue").DefineComponent<__VLS_WithDefaults<__VLS_T
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
+ } & {};