@tmagic/form 1.7.7 → 1.7.8-beta.2

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 (108) hide show
  1. package/LICENSE +235 -164
  2. package/dist/es/Form.js +5 -0
  3. package/dist/es/Form.vue_vue_type_script_setup_true_lang.js +234 -0
  4. package/dist/es/FormBox.js +5 -0
  5. package/dist/es/FormBox.vue_vue_type_script_setup_true_lang.js +117 -0
  6. package/dist/es/FormDialog.js +5 -0
  7. package/dist/es/FormDialog.vue_vue_type_script_setup_true_lang.js +222 -0
  8. package/dist/es/FormDrawer.js +5 -0
  9. package/dist/es/FormDrawer.vue_vue_type_script_setup_true_lang.js +176 -0
  10. package/dist/es/_virtual/_rolldown/runtime.js +27 -0
  11. package/dist/es/containers/Col.js +5 -0
  12. package/dist/es/containers/Col.vue_vue_type_script_setup_true_lang.js +60 -0
  13. package/dist/es/containers/Container.js +5 -0
  14. package/dist/es/containers/Container.vue_vue_type_script_setup_true_lang.js +438 -0
  15. package/dist/es/containers/Fieldset.js +5 -0
  16. package/dist/es/containers/Fieldset.vue_vue_type_script_setup_true_lang.js +153 -0
  17. package/dist/es/containers/FlexLayout.js +5 -0
  18. package/dist/es/containers/FlexLayout.vue_vue_type_script_setup_true_lang.js +64 -0
  19. package/dist/es/containers/FormLabel.js +5 -0
  20. package/dist/es/containers/FormLabel.vue_vue_type_script_setup_true_lang.js +51 -0
  21. package/dist/es/containers/GroupList.js +5 -0
  22. package/dist/es/containers/GroupList.vue_vue_type_script_setup_true_lang.js +164 -0
  23. package/dist/es/containers/GroupListItem.js +5 -0
  24. package/dist/es/containers/GroupListItem.vue_vue_type_script_setup_true_lang.js +221 -0
  25. package/dist/es/containers/Panel.js +5 -0
  26. package/dist/es/containers/Panel.vue_vue_type_script_setup_true_lang.js +130 -0
  27. package/dist/es/containers/Row.js +5 -0
  28. package/dist/es/containers/Row.vue_vue_type_script_setup_true_lang.js +65 -0
  29. package/dist/es/containers/Step.js +5 -0
  30. package/dist/es/containers/Step.vue_vue_type_script_setup_true_lang.js +85 -0
  31. package/dist/es/containers/Tabs.js +5 -0
  32. package/dist/es/containers/Tabs.vue_vue_type_script_setup_true_lang.js +194 -0
  33. package/dist/es/fields/Cascader.js +5 -0
  34. package/dist/es/fields/Cascader.vue_vue_type_script_setup_true_lang.js +123 -0
  35. package/dist/es/fields/Checkbox.js +5 -0
  36. package/dist/es/fields/Checkbox.vue_vue_type_script_setup_true_lang.js +61 -0
  37. package/dist/es/fields/CheckboxGroup.js +5 -0
  38. package/dist/es/fields/CheckboxGroup.vue_vue_type_script_setup_true_lang.js +63 -0
  39. package/dist/es/fields/ColorPicker.js +5 -0
  40. package/dist/es/fields/ColorPicker.vue_vue_type_script_setup_true_lang.js +42 -0
  41. package/dist/es/fields/Date.js +5 -0
  42. package/dist/es/fields/Date.vue_vue_type_script_setup_true_lang.js +52 -0
  43. package/dist/es/fields/DateTime.js +5 -0
  44. package/dist/es/fields/DateTime.vue_vue_type_script_setup_true_lang.js +57 -0
  45. package/dist/es/fields/Daterange.js +5 -0
  46. package/dist/es/fields/Daterange.vue_vue_type_script_setup_true_lang.js +99 -0
  47. package/dist/es/fields/Display.js +5 -0
  48. package/dist/es/fields/Display.vue_vue_type_script_setup_true_lang.js +36 -0
  49. package/dist/es/fields/DynamicField.js +5 -0
  50. package/dist/es/fields/DynamicField.vue_vue_type_script_setup_true_lang.js +91 -0
  51. package/dist/es/fields/Hidden.js +5 -0
  52. package/dist/es/fields/Hidden.vue_vue_type_script_setup_true_lang.js +24 -0
  53. package/dist/es/fields/Link.js +5 -0
  54. package/dist/es/fields/Link.vue_vue_type_script_setup_true_lang.js +104 -0
  55. package/dist/es/fields/Number.js +5 -0
  56. package/dist/es/fields/Number.vue_vue_type_script_setup_true_lang.js +65 -0
  57. package/dist/es/fields/NumberRange.js +5 -0
  58. package/dist/es/fields/NumberRange.vue_vue_type_script_setup_true_lang.js +76 -0
  59. package/dist/es/fields/RadioGroup.js +5 -0
  60. package/dist/es/fields/RadioGroup.vue_vue_type_script_setup_true_lang.js +75 -0
  61. package/dist/es/fields/Select.js +5 -0
  62. package/dist/es/fields/Select.vue_vue_type_script_setup_true_lang.js +337 -0
  63. package/dist/es/fields/Switch.js +5 -0
  64. package/dist/es/fields/Switch.vue_vue_type_script_setup_true_lang.js +59 -0
  65. package/dist/es/fields/Text.js +5 -0
  66. package/dist/es/fields/Text.vue_vue_type_script_setup_true_lang.js +215 -0
  67. package/dist/es/fields/Textarea.js +5 -0
  68. package/dist/es/fields/Textarea.vue_vue_type_script_setup_true_lang.js +60 -0
  69. package/dist/es/fields/Time.js +5 -0
  70. package/dist/es/fields/Time.vue_vue_type_script_setup_true_lang.js +49 -0
  71. package/dist/es/fields/Timerange.js +5 -0
  72. package/dist/es/fields/Timerange.vue_vue_type_script_setup_true_lang.js +100 -0
  73. package/dist/es/index.js +41 -0
  74. package/dist/es/plugin.js +74 -0
  75. package/dist/es/schema.js +2 -0
  76. package/dist/es/style.css +325 -0
  77. package/dist/es/table/ActionsColumn.js +5 -0
  78. package/dist/es/table/ActionsColumn.vue_vue_type_script_setup_true_lang.js +107 -0
  79. package/dist/es/table/SortColumn.js +5 -0
  80. package/dist/es/table/SortColumn.vue_vue_type_script_setup_true_lang.js +88 -0
  81. package/dist/es/table/Table.js +5 -0
  82. package/dist/es/table/Table.vue_vue_type_script_setup_true_lang.js +232 -0
  83. package/dist/es/table/useAdd.js +71 -0
  84. package/dist/es/table/useFullscreen.js +15 -0
  85. package/dist/es/table/useImport.js +46 -0
  86. package/dist/es/table/usePagination.js +26 -0
  87. package/dist/es/table/useSelection.js +26 -0
  88. package/dist/es/table/useSortable.js +39 -0
  89. package/dist/es/table/useTableColumns.js +160 -0
  90. package/dist/es/utils/config.js +15 -0
  91. package/dist/es/utils/form.js +174 -0
  92. package/dist/es/utils/useAddField.js +13 -0
  93. package/dist/style.css +1 -1
  94. package/dist/tmagic-form.umd.cjs +7696 -8924
  95. package/package.json +7 -6
  96. package/src/Form.vue +2 -2
  97. package/src/containers/Container.vue +25 -20
  98. package/src/containers/GroupListItem.vue +3 -1
  99. package/src/fields/Hidden.vue +6 -2
  100. package/src/fields/RadioGroup.vue +1 -1
  101. package/src/fields/Timerange.vue +2 -2
  102. package/src/index.ts +8 -82
  103. package/src/plugin.ts +102 -0
  104. package/src/table/useSortable.ts +8 -4
  105. package/src/utils/config.ts +16 -1
  106. package/src/utils/form.ts +10 -7
  107. package/types/index.d.ts +1265 -1227
  108. package/dist/tmagic-form.js +0 -5940
package/package.json CHANGED
@@ -1,19 +1,20 @@
1
1
  {
2
- "version": "1.7.7",
2
+ "version": "1.7.8-beta.2",
3
3
  "name": "@tmagic/form",
4
4
  "type": "module",
5
5
  "sideEffects": [
6
6
  "dist/style.css",
7
+ "dist/es/style.css",
7
8
  "src/theme/*"
8
9
  ],
9
10
  "main": "dist/tmagic-form.umd.cjs",
10
- "module": "dist/tmagic-form.js",
11
+ "module": "dist/es/index.js",
11
12
  "style": "dist/style.css",
12
13
  "types": "types/index.d.ts",
13
14
  "exports": {
14
15
  ".": {
15
16
  "types": "./types/index.d.ts",
16
- "import": "./dist/tmagic-form.js",
17
+ "import": "./dist/es/index.js",
17
18
  "require": "./dist/tmagic-form.umd.cjs"
18
19
  },
19
20
  "./dist/style.css": {
@@ -51,9 +52,9 @@
51
52
  "peerDependencies": {
52
53
  "vue": "^3.5.24",
53
54
  "typescript": "^5.9.3",
54
- "@tmagic/utils": "1.7.7",
55
- "@tmagic/design": "1.7.7",
56
- "@tmagic/form-schema": "1.7.7"
55
+ "@tmagic/design": "1.7.8-beta.2",
56
+ "@tmagic/utils": "1.7.8-beta.2",
57
+ "@tmagic/form-schema": "1.7.8-beta.2"
57
58
  },
58
59
  "peerDependenciesMeta": {
59
60
  "typescript": {
package/src/Form.vue CHANGED
@@ -218,13 +218,13 @@ const getTextByName = (name: string, config: FormConfig = props.config): string
218
218
  return typeof item.text === 'string' ? item.text : undefined;
219
219
  }
220
220
 
221
- if (item.items && Array.isArray(item.items)) {
221
+ if ('items' in item && Array.isArray(item.items)) {
222
222
  const result = findInConfig(item.items, remainingParts);
223
223
  if (result !== undefined) return result;
224
224
  }
225
225
  }
226
226
 
227
- if (item.items && Array.isArray(item.items)) {
227
+ if ('items' in item && Array.isArray(item.items)) {
228
228
  const result = findInConfig(item.items, parts);
229
229
  if (result !== undefined) return result;
230
230
  }
@@ -1,11 +1,11 @@
1
1
  <template>
2
2
  <div
3
- :data-tmagic-id="config.id"
3
+ :data-tmagic-id="(config as Record<string, any>).id"
4
4
  :data-tmagic-form-item-prop="itemProp"
5
5
  :class="`m-form-container m-container-${type || ''} ${config.className || ''}${config.tip ? ' has-tip' : ''}`"
6
6
  :style="config.style"
7
7
  >
8
- <m-fields-hidden v-if="type === 'hidden'" v-bind="fieldsProps" :model="model"></m-fields-hidden>
8
+ <MHidden v-if="type === 'hidden'" :name="`${name}`" :prop="itemProp" :model="model"></MHidden>
9
9
 
10
10
  <component
11
11
  v-else-if="items && !text && type && display"
@@ -28,7 +28,7 @@
28
28
  <FormLabel
29
29
  :tip="config.tip"
30
30
  :type="type"
31
- :use-label="config.useLabel"
31
+ :use-label="(config as CheckboxConfig).useLabel"
32
32
  :label-title="config.labelTitle"
33
33
  :text="text"
34
34
  ></FormLabel>
@@ -61,7 +61,7 @@
61
61
  ></component>
62
62
  </TMagicFormItem>
63
63
 
64
- <TMagicTooltip v-if="config.tip && type === 'checkbox' && !config.useLabel" placement="top">
64
+ <TMagicTooltip v-if="config.tip && type === 'checkbox' && !(config as CheckboxConfig).useLabel" placement="top">
65
65
  <TMagicIcon style="line-height: 40px; margin-left: 5px"><warning-filled /></TMagicIcon>
66
66
  <template #content>
67
67
  <div v-html="config.tip"></div>
@@ -80,7 +80,7 @@
80
80
  <FormLabel
81
81
  :tip="config.tip"
82
82
  :type="type"
83
- :use-label="config.useLabel"
83
+ :use-label="(config as CheckboxConfig).useLabel"
84
84
  :label-title="config.labelTitle"
85
85
  :text="text"
86
86
  ></FormLabel>
@@ -95,7 +95,7 @@
95
95
  <component v-else v-bind="fieldsProps" :is="tagName" :model="lastValues" @change="onChangeHandler"></component>
96
96
  </TMagicFormItem>
97
97
 
98
- <TMagicTooltip v-if="config.tip && type === 'checkbox' && !config.useLabel" placement="top">
98
+ <TMagicTooltip v-if="config.tip && type === 'checkbox' && !(config as CheckboxConfig).useLabel" placement="top">
99
99
  <TMagicIcon style="line-height: 40px; margin-left: 5px"><warning-filled /></TMagicIcon>
100
100
  <template #content>
101
101
  <div v-html="config.tip"></div>
@@ -112,7 +112,7 @@
112
112
  <FormLabel
113
113
  :tip="config.tip"
114
114
  :type="type"
115
- :use-label="config.useLabel"
115
+ :use-label="(config as CheckboxConfig).useLabel"
116
116
  :label-title="config.labelTitle"
117
117
  :text="text"
118
118
  ></FormLabel>
@@ -127,7 +127,7 @@
127
127
  <component v-else v-bind="fieldsProps" :is="tagName" :model="model" @change="onChangeHandler"></component>
128
128
  </TMagicFormItem>
129
129
 
130
- <TMagicTooltip v-if="config.tip && type === 'checkbox' && !config.useLabel" placement="top">
130
+ <TMagicTooltip v-if="config.tip && type === 'checkbox' && !(config as CheckboxConfig).useLabel" placement="top">
131
131
  <TMagicIcon style="line-height: 40px; margin-left: 5px"><warning-filled /></TMagicIcon>
132
132
  <template #content>
133
133
  <div v-html="config.tip"></div>
@@ -172,14 +172,18 @@ import { isEqual } from 'lodash-es';
172
172
  import { TMagicButton, TMagicFormItem, TMagicIcon, TMagicTooltip } from '@tmagic/design';
173
173
  import { getValueByKeyPath } from '@tmagic/utils';
174
174
 
175
+ import MHidden from '../fields/Hidden.vue';
175
176
  import type {
177
+ CheckboxConfig,
176
178
  ChildConfig,
179
+ ComponentConfig,
177
180
  ContainerChangeEventData,
178
181
  ContainerCommonConfig,
179
182
  FormState,
180
183
  FormValue,
181
184
  ToolTipConfigType,
182
185
  } from '../schema';
186
+ import { getField } from '../utils/config';
183
187
  import { createObjectProp, display as displayFunction, filterFunction, getRules } from '../utils/form';
184
188
 
185
189
  import FormLabel from './FormLabel.vue';
@@ -248,11 +252,20 @@ const itemProp = computed(() => {
248
252
  return `${n}`;
249
253
  });
250
254
 
255
+ const type = computed((): string => {
256
+ let { type } = props.config;
257
+ type = type && filterFunction<string>(mForm, type, props);
258
+ if (type === 'form') return '';
259
+ if (type === 'container') return '';
260
+ return type?.replace(/([A-Z])/g, '-$1').toLowerCase() || (items.value ? '' : 'text');
261
+ });
262
+
251
263
  const tagName = computed(() => {
252
- if (type.value === 'component' && props.config.component) {
253
- return props.config.component;
264
+ if (type.value === 'component' && (props.config as ComponentConfig).component) {
265
+ return (props.config as ComponentConfig).component;
254
266
  }
255
- return `m-${items.value ? 'form' : 'fields'}-${type.value}`;
267
+
268
+ return getField(type.value || 'container') || `m-${items.value ? 'form' : 'fields'}-${type.value}`;
256
269
  });
257
270
 
258
271
  const disabled = computed(() => props.disabled || filterFunction(mForm, props.config.disabled, props));
@@ -276,14 +289,6 @@ const tooltip = computed(() => {
276
289
 
277
290
  const rule = computed(() => getRules(mForm, props.config.rules, props));
278
291
 
279
- const type = computed((): string => {
280
- let { type } = props.config;
281
- type = type && filterFunction<string>(mForm, type, props);
282
- if (type === 'form') return '';
283
- if (type === 'container') return '';
284
- return type?.replace(/([A-Z])/g, '-$1').toLowerCase() || (items.value ? '' : 'text');
285
- });
286
-
287
292
  const display = computed((): boolean => {
288
293
  const value = displayFunction(mForm, props.config.display, props);
289
294
 
@@ -299,7 +304,7 @@ const fieldsProps = computed(() => ({
299
304
  name: name.value,
300
305
  disabled: disabled.value,
301
306
  prop: itemProp.value,
302
- key: props.config[mForm?.keyProps],
307
+ key: (props.config as Record<string, any>)[mForm?.keyProps],
303
308
  style: props.config.fieldStyle,
304
309
  }));
305
310
 
@@ -144,7 +144,9 @@ const rowConfig = computed(() => ({
144
144
  span: props.config.span || 24,
145
145
  items: props.config.items,
146
146
  labelWidth: props.config.labelWidth,
147
- [mForm?.keyProp || '__key']: `${props.config[mForm?.keyProp || '__key']}${String(props.index)}`,
147
+ [mForm?.keyProp || '__key']: `${(props.config as Record<string, any>)[mForm?.keyProp || '__key']}${String(
148
+ props.index,
149
+ )}`,
148
150
  }));
149
151
 
150
152
  const title = computed(() => {
@@ -3,14 +3,18 @@
3
3
  </template>
4
4
 
5
5
  <script setup lang="ts">
6
- import type { FieldProps, HiddenConfig } from '../schema';
6
+ import type { FormValue } from '../schema';
7
7
  import { useAddField } from '../utils/useAddField';
8
8
 
9
9
  defineOptions({
10
10
  name: 'MFormHidden',
11
11
  });
12
12
 
13
- const props = defineProps<FieldProps<HiddenConfig>>();
13
+ const props = defineProps<{
14
+ model: FormValue;
15
+ name: string;
16
+ prop: string;
17
+ }>();
14
18
 
15
19
  useAddField(props.prop);
16
20
  </script>
@@ -10,7 +10,7 @@
10
10
  <TMagicTooltip :disabled="!Boolean(option.tooltip)" placement="top-start" :content="option.tooltip">
11
11
  <div>
12
12
  <TMagicIcon v-if="option.icon" :size="iconSize"><component :is="option.icon"></component></TMagicIcon>
13
- <span>{{ option.text }}</span>
13
+ <span v-if="option.text">{{ option.text }}</span>
14
14
  </div>
15
15
  </TMagicTooltip>
16
16
  </component>
@@ -21,7 +21,7 @@ import dayjs from 'dayjs';
21
21
 
22
22
  import { TMagicTimePicker } from '@tmagic/design';
23
23
 
24
- import type { ChangeRecord, DaterangeConfig, FieldProps } from '../schema';
24
+ import type { ChangeRecord, FieldProps, TimerangeConfig } from '../schema';
25
25
  import { datetimeFormatter } from '../utils/form';
26
26
  import { useAddField } from '../utils/useAddField';
27
27
 
@@ -29,7 +29,7 @@ defineOptions({
29
29
  name: 'MFormTimeRange',
30
30
  });
31
31
 
32
- const props = defineProps<FieldProps<DaterangeConfig>>();
32
+ const props = defineProps<FieldProps<TimerangeConfig>>();
33
33
 
34
34
  const emit = defineEmits(['change']);
35
35
 
package/src/index.ts CHANGED
@@ -16,44 +16,8 @@
16
16
  * limitations under the License.
17
17
  */
18
18
 
19
- import type { App } from 'vue';
20
-
21
- import Container from './containers/Container.vue';
22
- import Fieldset from './containers/Fieldset.vue';
23
- import FlexLayout from './containers/FlexLayout.vue';
24
- import GroupList from './containers/GroupList.vue';
25
- import Panel from './containers/Panel.vue';
26
- import Row from './containers/Row.vue';
27
- import MStep from './containers/Step.vue';
28
- import Tabs from './containers/Tabs.vue';
29
- import Cascader from './fields/Cascader.vue';
30
- import Checkbox from './fields/Checkbox.vue';
31
- import CheckboxGroup from './fields/CheckboxGroup.vue';
32
- import ColorPicker from './fields/ColorPicker.vue';
33
- import Date from './fields/Date.vue';
34
- import Daterange from './fields/Daterange.vue';
35
- import DateTime from './fields/DateTime.vue';
36
- import Display from './fields/Display.vue';
37
- import DynamicField from './fields/DynamicField.vue';
38
- import Hidden from './fields/Hidden.vue';
39
- import Link from './fields/Link.vue';
40
- import Number from './fields/Number.vue';
41
- import NumberRange from './fields/NumberRange.vue';
42
- import RadioGroup from './fields/RadioGroup.vue';
43
- import Select from './fields/Select.vue';
44
- import Switch from './fields/Switch.vue';
45
- import Text from './fields/Text.vue';
46
- import Textarea from './fields/Textarea.vue';
47
- import Time from './fields/Time.vue';
48
- import Timerange from './fields/Timerange.vue';
49
- import Table from './table/Table.vue';
50
- import { setConfig } from './utils/config';
51
- import Form from './Form.vue';
52
- import FormDialog from './FormDialog.vue';
53
19
  import type { FormConfig } from './schema';
54
20
 
55
- import './theme/index.scss';
56
-
57
21
  export * from './schema';
58
22
  export * from './utils/form';
59
23
  export * from './utils/useAddField';
@@ -91,52 +55,14 @@ export { default as MSelect } from './fields/Select.vue';
91
55
  export { default as MCascader } from './fields/Cascader.vue';
92
56
  export { default as MDynamicField } from './fields/DynamicField.vue';
93
57
 
94
- export const createForm = <T extends [] = []>(config: FormConfig | T) => config;
95
-
96
- export interface FormInstallOptions {
97
- [key: string]: any;
98
- }
99
-
100
- const defaultInstallOpt: FormInstallOptions = {};
58
+ export {
59
+ deleteField as deleteFormField,
60
+ getField as getFormField,
61
+ registerField as registerFormField,
62
+ } from './utils/config';
101
63
 
102
- export default {
103
- install(app: App, opt: FormInstallOptions = {}) {
104
- const option = Object.assign(defaultInstallOpt, opt);
64
+ export type { FormInstallOptions } from './plugin';
105
65
 
106
- app.config.globalProperties.$MAGIC_FORM = option;
107
- setConfig(option);
66
+ export const createForm = <T extends [] = []>(config: FormConfig | T) => config;
108
67
 
109
- app.component('m-form', Form);
110
- app.component('m-form-dialog', FormDialog);
111
- app.component('m-form-container', Container);
112
- app.component('m-form-fieldset', Fieldset);
113
- app.component('m-form-group-list', GroupList);
114
- app.component('m-form-panel', Panel);
115
- app.component('m-form-row', Row);
116
- app.component('m-form-step', MStep);
117
- app.component('m-form-table', Table);
118
- app.component('m-form-tab', Tabs);
119
- app.component('m-form-flex-layout', FlexLayout);
120
- app.component('m-fields-text', Text);
121
- app.component('m-fields-img-upload', Text);
122
- app.component('m-fields-number', Number);
123
- app.component('m-fields-number-range', NumberRange);
124
- app.component('m-fields-textarea', Textarea);
125
- app.component('m-fields-hidden', Hidden);
126
- app.component('m-fields-date', Date);
127
- app.component('m-fields-datetime', DateTime);
128
- app.component('m-fields-daterange', Daterange);
129
- app.component('m-fields-timerange', Timerange);
130
- app.component('m-fields-time', Time);
131
- app.component('m-fields-checkbox', Checkbox);
132
- app.component('m-fields-switch', Switch);
133
- app.component('m-fields-color-picker', ColorPicker);
134
- app.component('m-fields-checkbox-group', CheckboxGroup);
135
- app.component('m-fields-radio-group', RadioGroup);
136
- app.component('m-fields-display', Display);
137
- app.component('m-fields-link', Link);
138
- app.component('m-fields-select', Select);
139
- app.component('m-fields-cascader', Cascader);
140
- app.component('m-fields-dynamic-field', DynamicField);
141
- },
142
- };
68
+ export { default } from './plugin';
package/src/plugin.ts ADDED
@@ -0,0 +1,102 @@
1
+ /*
2
+ * Tencent is pleased to support the open source community by making TMagicEditor available.
3
+ *
4
+ * Copyright (C) 2025 Tencent. All rights reserved.
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ */
18
+
19
+ import { type App } from 'vue';
20
+
21
+ import Container from './containers/Container.vue';
22
+ import Fieldset from './containers/Fieldset.vue';
23
+ import FlexLayout from './containers/FlexLayout.vue';
24
+ import GroupList from './containers/GroupList.vue';
25
+ import Panel from './containers/Panel.vue';
26
+ import Row from './containers/Row.vue';
27
+ import MStep from './containers/Step.vue';
28
+ import Tabs from './containers/Tabs.vue';
29
+ import Cascader from './fields/Cascader.vue';
30
+ import Checkbox from './fields/Checkbox.vue';
31
+ import CheckboxGroup from './fields/CheckboxGroup.vue';
32
+ import ColorPicker from './fields/ColorPicker.vue';
33
+ import Date from './fields/Date.vue';
34
+ import Daterange from './fields/Daterange.vue';
35
+ import DateTime from './fields/DateTime.vue';
36
+ import Display from './fields/Display.vue';
37
+ import DynamicField from './fields/DynamicField.vue';
38
+ import Hidden from './fields/Hidden.vue';
39
+ import Link from './fields/Link.vue';
40
+ import Number from './fields/Number.vue';
41
+ import NumberRange from './fields/NumberRange.vue';
42
+ import RadioGroup from './fields/RadioGroup.vue';
43
+ import Select from './fields/Select.vue';
44
+ import Switch from './fields/Switch.vue';
45
+ import Text from './fields/Text.vue';
46
+ import Textarea from './fields/Textarea.vue';
47
+ import Time from './fields/Time.vue';
48
+ import Timerange from './fields/Timerange.vue';
49
+ import Table from './table/Table.vue';
50
+ import { setConfig } from './utils/config';
51
+ import Form from './Form.vue';
52
+ import FormDialog from './FormDialog.vue';
53
+
54
+ import './theme/index.scss';
55
+
56
+ export interface FormInstallOptions {
57
+ [key: string]: any;
58
+ }
59
+
60
+ const defaultInstallOpt: FormInstallOptions = {};
61
+
62
+ export default {
63
+ install(app: App, opt: FormInstallOptions = {}) {
64
+ const option = Object.assign(defaultInstallOpt, opt);
65
+
66
+ app.config.globalProperties.$MAGIC_FORM = option;
67
+ setConfig(option);
68
+
69
+ app.component('m-form', Form);
70
+ app.component('m-form-dialog', FormDialog);
71
+ app.component('m-form-container', Container);
72
+ app.component('m-form-fieldset', Fieldset);
73
+ app.component('m-form-group-list', GroupList);
74
+ app.component('m-form-panel', Panel);
75
+ app.component('m-form-row', Row);
76
+ app.component('m-form-step', MStep);
77
+ app.component('m-form-table', Table);
78
+ app.component('m-form-tab', Tabs);
79
+ app.component('m-form-flex-layout', FlexLayout);
80
+ app.component('m-fields-text', Text);
81
+ app.component('m-fields-img-upload', Text);
82
+ app.component('m-fields-number', Number);
83
+ app.component('m-fields-number-range', NumberRange);
84
+ app.component('m-fields-textarea', Textarea);
85
+ app.component('m-fields-hidden', Hidden);
86
+ app.component('m-fields-date', Date);
87
+ app.component('m-fields-datetime', DateTime);
88
+ app.component('m-fields-daterange', Daterange);
89
+ app.component('m-fields-timerange', Timerange);
90
+ app.component('m-fields-time', Time);
91
+ app.component('m-fields-checkbox', Checkbox);
92
+ app.component('m-fields-switch', Switch);
93
+ app.component('m-fields-color-picker', ColorPicker);
94
+ app.component('m-fields-checkbox-group', CheckboxGroup);
95
+ app.component('m-fields-radio-group', RadioGroup);
96
+ app.component('m-fields-display', Display);
97
+ app.component('m-fields-link', Link);
98
+ app.component('m-fields-select', Select);
99
+ app.component('m-fields-cascader', Cascader);
100
+ app.component('m-fields-dynamic-field', DynamicField);
101
+ },
102
+ };
@@ -1,5 +1,5 @@
1
1
  import { inject, nextTick, type Ref, type ShallowRef, watchEffect } from 'vue';
2
- import Sortable, { type SortableEvent } from 'sortablejs';
2
+ import type { default as SortableType, SortableEvent } from 'sortablejs';
3
3
 
4
4
  import { type TMagicTable } from '@tmagic/design';
5
5
  import type { FormState } from '@tmagic/form-schema';
@@ -8,6 +8,9 @@ import { sortArray } from '../utils/form';
8
8
 
9
9
  import type { TableProps } from './type';
10
10
 
11
+ let SortablePromise: Promise<typeof SortableType> | undefined;
12
+ const loadSortable = () => (SortablePromise ??= import('sortablejs').then((m) => m.default));
13
+
11
14
  export const useSortable = (
12
15
  props: TableProps,
13
16
  emit: (event: 'select' | 'change' | 'addDiffCount', ...args: any[]) => void,
@@ -17,15 +20,16 @@ export const useSortable = (
17
20
  ) => {
18
21
  const mForm = inject<FormState | undefined>('mForm');
19
22
 
20
- let sortable: Sortable | undefined;
21
- const rowDrop = () => {
23
+ let sortable: SortableType | undefined;
24
+ const rowDrop = async () => {
22
25
  sortable?.destroy();
23
26
  const tableEl = tMagicTableRef.value?.getEl();
24
27
  const tBodyEl = tableEl?.querySelector('.el-table__body > tbody') || tableEl?.querySelector('.t-table__body');
25
28
  if (!tBodyEl) {
26
29
  return;
27
30
  }
28
- sortable = Sortable.create(tBodyEl, {
31
+
32
+ sortable = (await loadSortable()).create(tBodyEl, {
29
33
  draggable: '.tmagic-design-table-row',
30
34
  filter: 'input', // 表单组件选字操作和触发拖拽会冲突,优先保证选字操作
31
35
  preventOnFilter: false, // 允许选字
@@ -16,6 +16,8 @@
16
16
  * limitations under the License.
17
17
  */
18
18
 
19
+ import type { Component } from 'vue';
20
+
19
21
  let $MAGIC_FORM = {} as any;
20
22
 
21
23
  const setConfig = (option: any): void => {
@@ -24,4 +26,17 @@ const setConfig = (option: any): void => {
24
26
 
25
27
  const getConfig = <T = unknown>(key: string): T => $MAGIC_FORM[key];
26
28
 
27
- export { getConfig, setConfig };
29
+ const fieldRegistry = new Map<string, Component>();
30
+
31
+ const registerField = (tagName: string, component: Component): void => {
32
+ if (fieldRegistry.has(tagName)) {
33
+ return;
34
+ }
35
+ fieldRegistry.set(tagName, component);
36
+ };
37
+
38
+ const getField = (tagName: string): Component | undefined => fieldRegistry.get(tagName);
39
+
40
+ const deleteField = (tagName: string): boolean => fieldRegistry.delete(tagName);
41
+
42
+ export { deleteField, getConfig, getField, registerField, setConfig };
package/src/utils/form.ts CHANGED
@@ -29,11 +29,13 @@ import {
29
29
  DaterangeConfig,
30
30
  FilterFunction,
31
31
  FormConfig,
32
+ FormItem,
32
33
  FormState,
33
34
  FormValue,
34
35
  HtmlField,
35
36
  Rule,
36
37
  SortProp,
38
+ TableConfig,
37
39
  TabPaneConfig,
38
40
  TypeFunction,
39
41
  } from '../schema';
@@ -118,7 +120,7 @@ const initValueItem = function (
118
120
  ) {
119
121
  const { items } = item as ContainerCommonConfig;
120
122
  const { names } = item as DaterangeConfig;
121
- const { type, name } = item as ChildConfig;
123
+ const { type, name } = item as FormItem;
122
124
 
123
125
  if (isTableSelect(type) && name) {
124
126
  value[name] = initValue[name] ?? '';
@@ -148,14 +150,15 @@ const initValueItem = function (
148
150
  setValue(mForm, value, initValue, item);
149
151
 
150
152
  if (type === 'table') {
151
- if (item.defautSort) {
152
- sortChange(value[name], item.defautSort);
153
- } else if (item.defaultSort) {
154
- sortChange(value[name], item.defaultSort);
153
+ const tableConfig = item as TableConfig;
154
+ if (tableConfig.defautSort) {
155
+ sortChange(value[name], tableConfig.defautSort);
156
+ } else if (tableConfig.defaultSort) {
157
+ sortChange(value[name], tableConfig.defaultSort);
155
158
  }
156
159
 
157
- if (item.sort && item.sortKey) {
158
- value[name].sort((a: any, b: any) => b[item.sortKey] - a[item.sortKey]);
160
+ if (tableConfig.sort && tableConfig.sortKey) {
161
+ value[name].sort((a: any, b: any) => b[tableConfig.sortKey!] - a[tableConfig.sortKey!]);
159
162
  }
160
163
  }
161
164