@tmagic/form 1.2.0-beta.2 → 1.2.0-beta.21

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 (83) hide show
  1. package/dist/style.css +1 -1
  2. package/dist/tmagic-form.js +3673 -0
  3. package/dist/tmagic-form.js.map +1 -0
  4. package/dist/tmagic-form.umd.cjs +3713 -0
  5. package/dist/tmagic-form.umd.cjs.map +1 -0
  6. package/package.json +10 -9
  7. package/src/Form.vue +124 -159
  8. package/src/FormDialog.vue +108 -126
  9. package/src/containers/Col.vue +24 -38
  10. package/src/containers/Container.vue +143 -171
  11. package/src/containers/Fieldset.vue +15 -8
  12. package/src/containers/GroupList.vue +86 -116
  13. package/src/containers/GroupListItem.vue +91 -125
  14. package/src/containers/Panel.vue +29 -49
  15. package/src/containers/Row.vue +20 -40
  16. package/src/containers/Step.vue +38 -48
  17. package/src/containers/Table.vue +466 -481
  18. package/src/containers/Tabs.vue +94 -118
  19. package/src/fields/Cascader.vue +88 -136
  20. package/src/fields/Checkbox.vue +46 -50
  21. package/src/fields/CheckboxGroup.vue +39 -35
  22. package/src/fields/ColorPicker.vue +5 -3
  23. package/src/fields/Date.vue +21 -27
  24. package/src/fields/DateTime.vue +31 -39
  25. package/src/fields/Daterange.vue +4 -3
  26. package/src/fields/Display.vue +1 -1
  27. package/src/fields/DynamicField.vue +63 -77
  28. package/src/fields/Hidden.vue +1 -1
  29. package/src/fields/Link.vue +65 -86
  30. package/src/fields/Number.vue +32 -34
  31. package/src/fields/RadioGroup.vue +23 -23
  32. package/src/fields/Select.vue +294 -310
  33. package/src/fields/SelectOptionGroups.vue +11 -6
  34. package/src/fields/SelectOptions.vue +5 -3
  35. package/src/fields/Switch.vue +46 -49
  36. package/src/fields/Text.vue +99 -107
  37. package/src/fields/Textarea.vue +32 -44
  38. package/src/fields/Time.vue +21 -30
  39. package/src/index.ts +22 -23
  40. package/src/schema.ts +50 -12
  41. package/src/theme/form.scss +1 -1
  42. package/src/utils/form.ts +9 -5
  43. package/types/Form.vue.d.ts +211 -111
  44. package/types/FormDialog.vue.d.ts +813 -154
  45. package/types/containers/Col.vue.d.ts +96 -40
  46. package/types/containers/Container.vue.d.ts +126 -65
  47. package/types/containers/Fieldset.vue.d.ts +5 -3
  48. package/types/containers/GroupList.vue.d.ts +90 -53
  49. package/types/containers/GroupListItem.vue.d.ts +101 -67
  50. package/types/containers/Panel.vue.d.ts +96 -39
  51. package/types/containers/Row.vue.d.ts +96 -39
  52. package/types/containers/Step.vue.d.ts +106 -42
  53. package/types/containers/Table.vue.d.ts +161 -130
  54. package/types/containers/Tabs.vue.d.ts +97 -50
  55. package/types/fields/Cascader.vue.d.ts +95 -71
  56. package/types/fields/Checkbox.vue.d.ts +95 -56
  57. package/types/fields/CheckboxGroup.vue.d.ts +95 -53
  58. package/types/fields/ColorPicker.vue.d.ts +1 -3
  59. package/types/fields/Date.vue.d.ts +95 -54
  60. package/types/fields/DateTime.vue.d.ts +95 -54
  61. package/types/fields/Daterange.vue.d.ts +1 -3
  62. package/types/fields/Display.vue.d.ts +1 -3
  63. package/types/fields/DynamicField.vue.d.ts +95 -64
  64. package/types/fields/Hidden.vue.d.ts +1 -3
  65. package/types/fields/Link.vue.d.ts +60 -657
  66. package/types/fields/Number.vue.d.ts +99 -56
  67. package/types/fields/RadioGroup.vue.d.ts +96 -52
  68. package/types/fields/Select.vue.d.ts +97 -65
  69. package/types/fields/SelectOptionGroups.vue.d.ts +1 -3
  70. package/types/fields/SelectOptions.vue.d.ts +1 -3
  71. package/types/fields/Switch.vue.d.ts +95 -56
  72. package/types/fields/Text.vue.d.ts +98 -57
  73. package/types/fields/Textarea.vue.d.ts +100 -60
  74. package/types/fields/Time.vue.d.ts +95 -55
  75. package/types/index.d.ts +0 -1
  76. package/types/schema.d.ts +42 -9
  77. package/types/utils/form.d.ts +2 -1
  78. package/dist/tmagic-form.mjs +0 -3925
  79. package/dist/tmagic-form.mjs.map +0 -1
  80. package/dist/tmagic-form.umd.js +0 -3965
  81. package/dist/tmagic-form.umd.js.map +0 -1
  82. package/src/utils/fieldProps.ts +0 -39
  83. package/types/utils/fieldProps.d.ts +0 -21
@@ -1,20 +1,25 @@
1
1
  <template>
2
- <el-option-group v-for="(group, index) in options" :key="index" :label="group.label" :disabled="group.disabled">
3
- <el-option
2
+ <TMagicOptionGroup v-for="(group, index) in options" :key="index" :label="group.label" :disabled="group.disabled">
3
+ <component
4
4
  v-for="(item, index) in group.options"
5
+ :is="uiComponent.component"
5
6
  :key="index"
6
- :label="item.label"
7
+ :label="item.label || item.text"
7
8
  :value="item.value"
8
9
  :disabled="item.disabled"
9
10
  >
10
- </el-option>
11
- </el-option-group>
11
+ </component>
12
+ </TMagicOptionGroup>
12
13
  </template>
13
14
 
14
- <script lang="ts" setup>
15
+ <script lang="ts" setup name="MFormSelectOptionGroups">
16
+ import { getConfig, TMagicOptionGroup } from '@tmagic/design';
17
+
15
18
  import { SelectGroupOption } from '../schema';
16
19
 
17
20
  defineProps<{
18
21
  options: SelectGroupOption[];
19
22
  }>();
23
+
24
+ const uiComponent = getConfig('components').option;
20
25
  </script>
@@ -1,14 +1,16 @@
1
1
  <template>
2
- <el-option
2
+ <TMagicOption
3
3
  v-for="option in options"
4
4
  :label="option.text"
5
5
  :value="option.value"
6
6
  :key="valueKey ? option.value[valueKey] : option.value"
7
7
  :disabled="option.disabled"
8
- ></el-option>
8
+ ></TMagicOption>
9
9
  </template>
10
10
 
11
- <script lang="ts" setup>
11
+ <script lang="ts" setup name="MFormSelectOptions">
12
+ import { TMagicOption } from '@tmagic/design';
13
+
12
14
  import { SelectOption } from '../schema';
13
15
 
14
16
  defineProps<{
@@ -1,65 +1,62 @@
1
1
  <template>
2
- <el-switch
3
- v-if="model"
4
- v-model="model[n]"
2
+ <TMagicSwitch
3
+ v-model="model[name]"
5
4
  :size="size"
6
5
  :activeValue="activeValue"
7
6
  :inactiveValue="inactiveValue"
8
7
  :disabled="disabled"
9
8
  @change="changeHandler"
10
- ></el-switch>
9
+ ></TMagicSwitch>
11
10
  </template>
12
11
 
13
- <script lang="ts">
14
- import { computed, defineComponent, PropType } from 'vue';
12
+ <script lang="ts" setup name="MFormSwitch">
13
+ import { computed } from 'vue';
14
+
15
+ import { TMagicSwitch } from '@tmagic/design';
15
16
 
16
17
  import { SwitchConfig } from '../schema';
17
- import fieldProps from '../utils/fieldProps';
18
18
  import { useAddField } from '../utils/useAddField';
19
- export default defineComponent({
20
- name: 'm-fields-switch',
21
-
22
- props: {
23
- ...fieldProps,
24
- config: {
25
- type: Object as PropType<SwitchConfig>,
26
- required: true,
27
- },
28
- },
29
-
30
- emits: ['change'],
31
19
 
32
- setup(props, { emit }) {
33
- useAddField(props.prop);
34
-
35
- return {
36
- n: computed(() => props.name || props.config.name || ''),
37
- activeValue: computed(() => {
38
- if (typeof props.config.activeValue === 'undefined') {
39
- if (props.config.filter === 'number') {
40
- return 1;
41
- }
42
- } else {
43
- return props.config.activeValue;
44
- }
20
+ const props = defineProps<{
21
+ config: SwitchConfig;
22
+ model: any;
23
+ initValues?: any;
24
+ values?: any;
25
+ name: string;
26
+ prop: string;
27
+ disabled?: boolean;
28
+ size: 'mini' | 'small' | 'medium';
29
+ }>();
30
+
31
+ const emit = defineEmits(['change']);
32
+
33
+ useAddField(props.prop);
34
+
35
+ const changeHandler = (value: number) => {
36
+ emit('change', value);
37
+ };
38
+
39
+ const activeValue = computed(() => {
40
+ if (typeof props.config.activeValue === 'undefined') {
41
+ if (props.config.filter === 'number') {
42
+ return 1;
43
+ }
44
+ } else {
45
+ return props.config.activeValue;
46
+ }
47
+
48
+ return true;
49
+ });
45
50
 
46
- return true;
47
- }),
48
- inactiveValue: computed(() => {
49
- if (typeof props.config.inactiveValue === 'undefined') {
50
- if (props.config.filter === 'number') {
51
- return 0;
52
- }
53
- } else {
54
- return props.config.inactiveValue;
55
- }
51
+ const inactiveValue = computed(() => {
52
+ if (typeof props.config.inactiveValue === 'undefined') {
53
+ if (props.config.filter === 'number') {
54
+ return 0;
55
+ }
56
+ } else {
57
+ return props.config.inactiveValue;
58
+ }
56
59
 
57
- return false;
58
- }),
59
- changeHandler: (v: boolean | number | string) => {
60
- emit('change', v);
61
- },
62
- };
63
- },
60
+ return false;
64
61
  });
65
62
  </script>
@@ -1,6 +1,6 @@
1
1
  <template>
2
- <el-input
3
- v-model="model[modelName]"
2
+ <TMagicInput
3
+ v-model="model[name]"
4
4
  clearable
5
5
  :size="size"
6
6
  :placeholder="config.placeholder"
@@ -20,117 +20,109 @@
20
20
  {{ config.append.text }}
21
21
  </el-button>
22
22
  </template>
23
- </el-input>
23
+ </TMagicInput>
24
24
  </template>
25
25
 
26
- <script lang="ts">
27
- import { computed, defineComponent, inject, PropType } from 'vue';
26
+ <script lang="ts" setup name="MFormText">
27
+ import { inject } from 'vue';
28
28
 
29
+ import { TMagicInput } from '@tmagic/design';
29
30
  import { isNumber } from '@tmagic/utils';
30
31
 
31
32
  import { FormState, TextConfig } from '../schema';
32
- import fieldProps from '../utils/fieldProps';
33
33
  import { useAddField } from '../utils/useAddField';
34
34
 
35
- export default defineComponent({
36
- name: 'm-fields-text',
37
-
38
- props: {
39
- ...fieldProps,
40
- config: {
41
- type: Object as PropType<TextConfig>,
42
- required: true,
43
- },
44
- },
45
-
46
- emits: ['change', 'input'],
47
-
48
- setup(props, { emit }) {
49
- const mForm = inject<FormState | undefined>('mForm');
50
-
51
- useAddField(props.prop);
52
-
53
- const modelName = computed(() => props.name || props.config.name || '');
54
- return {
55
- modelName,
56
-
57
- changeHandler(v: string | number) {
58
- emit('change', v);
59
- },
60
-
61
- inputHandler(v: string | number) {
62
- emit('input', v);
63
- mForm?.$emit('field-input', props.prop, v);
64
- },
65
-
66
- buttonClickHandler() {
67
- if (typeof props.config.append === 'string') return;
68
-
69
- if (props.config.append?.handler) {
70
- props.config.append.handler(mForm, {
71
- model: props.model,
72
- values: mForm?.values,
73
- });
74
- }
75
- },
76
-
77
- keyUpHandler($event: KeyboardEvent) {
78
- if (!props.model) return;
79
- if (!modelName.value) return;
80
-
81
- const arrowUp = $event.key === 'ArrowUp';
82
- const arrowDown = $event.key === 'ArrowDown';
83
-
84
- if (!arrowUp && !arrowDown) {
85
- return;
86
- }
87
-
88
- const value = props.model[modelName.value];
89
- let num;
90
- let unit;
91
- if (isNumber(value)) {
92
- num = +value;
93
- } else {
94
- value.replace(/^([0-9.]+)([a-z%]+)$/, ($0: string, $1: string, $2: string) => {
95
- num = +$1;
96
- unit = $2;
97
- });
98
- }
99
-
100
- if (num === undefined) {
101
- return;
102
- }
103
-
104
- const ctrl = navigator.platform.match('Mac') ? $event.metaKey : $event.ctrlKey;
105
- const shift = $event.shiftKey;
106
- const alt = $event.altKey;
107
-
108
- if (arrowUp) {
109
- if (ctrl) {
110
- num += 100;
111
- } else if (alt) {
112
- num = (num * 10000 + 1000) / 10000;
113
- } else if (shift) {
114
- num = num + 10;
115
- } else {
116
- num += 1;
117
- }
118
- } else if (arrowDown) {
119
- if (ctrl) {
120
- num -= 100;
121
- } else if (alt) {
122
- num = (num * 10000 - 1000) / 10000;
123
- } else if (shift) {
124
- num -= 10;
125
- } else {
126
- num -= 1;
127
- }
128
- }
129
-
130
- props.model[modelName.value] = `${num}${unit || ''}`;
131
- emit('change', props.model[modelName.value]);
132
- },
133
- };
134
- },
135
- });
35
+ const props = defineProps<{
36
+ config: TextConfig;
37
+ model: any;
38
+ initValues?: any;
39
+ values?: any;
40
+ name: string;
41
+ prop: string;
42
+ disabled?: boolean;
43
+ size: 'mini' | 'small' | 'medium';
44
+ }>();
45
+
46
+ const emit = defineEmits(['change', 'input']);
47
+
48
+ useAddField(props.prop);
49
+
50
+ const mForm = inject<FormState | undefined>('mForm');
51
+
52
+ const changeHandler = (value: number) => {
53
+ emit('change', value);
54
+ };
55
+
56
+ const inputHandler = (v: string) => {
57
+ emit('input', v);
58
+ mForm?.$emit('field-input', props.prop, v);
59
+ };
60
+
61
+ const buttonClickHandler = () => {
62
+ if (typeof props.config.append === 'string') return;
63
+
64
+ if (props.config.append?.handler) {
65
+ props.config.append.handler(mForm, {
66
+ model: props.model,
67
+ values: mForm?.values,
68
+ });
69
+ }
70
+ };
71
+
72
+ const keyUpHandler = ($event: KeyboardEvent) => {
73
+ if (!props.model) return;
74
+ if (!props.name) return;
75
+
76
+ const arrowUp = $event.key === 'ArrowUp';
77
+ const arrowDown = $event.key === 'ArrowDown';
78
+
79
+ if (!arrowUp && !arrowDown) {
80
+ return;
81
+ }
82
+
83
+ const value = props.model[props.name];
84
+ let num;
85
+ let unit;
86
+ if (isNumber(value)) {
87
+ num = +value;
88
+ } else {
89
+ value.replace(/^([0-9.]+)([a-z%]+)$/, ($0: string, $1: string, $2: string) => {
90
+ num = +$1;
91
+ unit = $2;
92
+ });
93
+ }
94
+
95
+ if (num === undefined) {
96
+ return;
97
+ }
98
+
99
+ const ctrl = navigator.platform.match('Mac') ? $event.metaKey : $event.ctrlKey;
100
+ const shift = $event.shiftKey;
101
+ const alt = $event.altKey;
102
+
103
+ if (arrowUp) {
104
+ if (ctrl) {
105
+ num += 100;
106
+ } else if (alt) {
107
+ num = (num * 10000 + 1000) / 10000;
108
+ } else if (shift) {
109
+ num = num + 10;
110
+ } else {
111
+ num += 1;
112
+ }
113
+ } else if (arrowDown) {
114
+ if (ctrl) {
115
+ num -= 100;
116
+ } else if (alt) {
117
+ num = (num * 10000 - 1000) / 10000;
118
+ } else if (shift) {
119
+ num -= 10;
120
+ } else {
121
+ num -= 1;
122
+ }
123
+ }
124
+
125
+ props.model[props.name] = `${num}${unit || ''}`;
126
+ emit('change', props.model[props.name]);
127
+ };
136
128
  </script>
@@ -1,5 +1,5 @@
1
1
  <template>
2
- <el-input
2
+ <TMagicInput
3
3
  v-model="model[name]"
4
4
  type="textarea"
5
5
  :size="size"
@@ -9,52 +9,40 @@
9
9
  @change="changeHandler"
10
10
  @input="inputHandler"
11
11
  >
12
- </el-input>
12
+ </TMagicInput>
13
13
  </template>
14
14
 
15
- <script lang="ts">
16
- import { defineComponent, inject, PropType } from 'vue';
15
+ <script lang="ts" setup name="MFormTextarea">
16
+ import { inject } from 'vue';
17
+
18
+ import { TMagicInput } from '@tmagic/design';
17
19
 
18
20
  import { FormState, TextareaConfig } from '../schema';
19
- import fieldProps from '../utils/fieldProps';
20
21
  import { useAddField } from '../utils/useAddField';
21
- export default defineComponent({
22
- name: 'm-fields-textarea',
23
-
24
- props: {
25
- ...fieldProps,
26
- config: {
27
- type: Object as PropType<TextareaConfig>,
28
- required: true,
29
- },
30
- },
31
-
32
- emits: {
33
- change(values: string | number) {
34
- return values;
35
- },
36
-
37
- input(values: string | number) {
38
- return values;
39
- },
40
- },
41
-
42
- setup(props, { emit }) {
43
- useAddField(props.prop);
44
-
45
- const mForm = inject<FormState | null>('mForm');
46
-
47
- return {
48
- mForm,
49
- changeHandler: (v: string) => {
50
- emit('change', v);
51
- },
52
-
53
- inputHandler: (v: string) => {
54
- emit('input', v);
55
- mForm?.$emit('field-input', props.prop, v);
56
- },
57
- };
58
- },
59
- });
22
+
23
+ const props = defineProps<{
24
+ config: TextareaConfig;
25
+ model: any;
26
+ initValues?: any;
27
+ values?: any;
28
+ name: string;
29
+ prop: string;
30
+ disabled?: boolean;
31
+ size: 'mini' | 'small' | 'medium';
32
+ }>();
33
+
34
+ const emit = defineEmits(['change', 'input']);
35
+
36
+ useAddField(props.prop);
37
+
38
+ const mForm = inject<FormState | null>('mForm');
39
+
40
+ const changeHandler = (value: number) => {
41
+ emit('change', value);
42
+ };
43
+
44
+ const inputHandler = (v: string) => {
45
+ emit('input', v);
46
+ mForm?.$emit('field-input', props.prop, v);
47
+ };
60
48
  </script>
@@ -1,46 +1,37 @@
1
1
  <template>
2
- <el-time-picker
2
+ <TMagicTimePicker
3
3
  v-model="model[name]"
4
+ :value-format="config.valueFormat || 'HH:mm:ss'"
5
+ :format="config.format || 'HH:mm:ss'"
4
6
  :size="size"
5
- value-format="HH:mm:ss"
6
7
  :placeholder="config.placeholder"
7
8
  :disabled="disabled"
8
9
  @change="changeHandler"
9
- ></el-time-picker>
10
+ ></TMagicTimePicker>
10
11
  </template>
11
12
 
12
- <script lang="ts">
13
- import { defineComponent, PropType } from 'vue';
13
+ <script lang="ts" setup name="MFormTime">
14
+ import { TMagicTimePicker } from '@tmagic/design';
14
15
 
15
16
  import { TimeConfig } from '../schema';
16
- import fieldProps from '../utils/fieldProps';
17
17
  import { useAddField } from '../utils/useAddField';
18
18
 
19
- export default defineComponent({
20
- name: 'm-fields-time',
19
+ const props = defineProps<{
20
+ config: TimeConfig;
21
+ model: any;
22
+ initValues?: any;
23
+ values?: any;
24
+ name: string;
25
+ prop: string;
26
+ disabled?: boolean;
27
+ size: 'mini' | 'small' | 'medium';
28
+ }>();
21
29
 
22
- props: {
23
- ...fieldProps,
24
- config: {
25
- type: Object as PropType<TimeConfig>,
26
- required: true,
27
- },
28
- },
30
+ const emit = defineEmits(['change']);
29
31
 
30
- emits: {
31
- change(values: Date) {
32
- return values;
33
- },
34
- },
32
+ useAddField(props.prop);
35
33
 
36
- setup(props, { emit }) {
37
- useAddField(props.prop);
38
-
39
- return {
40
- changeHandler: (v: Date) => {
41
- emit('change', v);
42
- },
43
- };
44
- },
45
- });
34
+ const changeHandler = (v: string) => {
35
+ emit('change', v);
36
+ };
46
37
  </script>
package/src/index.ts CHANGED
@@ -53,7 +53,6 @@ import './theme/index.scss';
53
53
  export * from './schema';
54
54
  export * from './utils/form';
55
55
  export * from './utils/useAddField';
56
- export { default as fieldProps } from './utils/fieldProps';
57
56
 
58
57
  export { default as MForm } from './Form.vue';
59
58
  export { default as MFormDialog } from './FormDialog.vue';
@@ -92,34 +91,34 @@ const install = (app: App, opt: any) => {
92
91
  app.config.globalProperties.$MAGIC_FORM = option;
93
92
  setConfig(option);
94
93
 
95
- app.component(Form.name, Form);
96
- app.component(FormDialog.name, FormDialog);
97
- app.component(Container.name, Container);
94
+ app.component('m-form', Form);
95
+ app.component('m-form-dialog', FormDialog);
96
+ app.component('m-form-container', Container);
98
97
  app.component('m-form-fieldset', Fieldset);
99
- app.component(GroupList.name, GroupList);
100
- app.component(Panel.name, Panel);
101
- app.component(Row.name, Row);
102
- app.component(MStep.name, MStep);
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);
103
102
  app.component('m-form-table', Table);
104
- app.component(Tabs.name, Tabs);
105
- app.component(Text.name, Text);
106
- app.component(Number.name, Number);
107
- app.component(Textarea.name, Textarea);
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);
108
107
  app.component('m-fields-hidden', Hidden);
109
- app.component(Date.name, Date);
110
- app.component(DateTime.name, DateTime);
111
- app.component(Time.name, Time);
112
- app.component(Checkbox.name, Checkbox);
113
- app.component(Switch.name, Switch);
108
+ app.component('m-fields-date', Date);
109
+ app.component('m-fields-datetime', DateTime);
114
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);
115
114
  app.component('m-fields-color-picker', ColorPicker);
116
- app.component(CheckboxGroup.name, CheckboxGroup);
117
- app.component(RadioGroup.name, RadioGroup);
115
+ app.component('m-fields-checkbox-group', CheckboxGroup);
116
+ app.component('m-fields-radio-group', RadioGroup);
118
117
  app.component('m-fields-display', Display);
119
- app.component(Link.name, Link);
120
- app.component(Select.name, Select);
121
- app.component(Cascader.name, Cascader);
122
- app.component(DynamicField.name, DynamicField);
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);
123
122
  };
124
123
 
125
124
  export default {