@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.
- package/LICENSE +235 -164
- package/dist/es/Form.js +5 -0
- package/dist/es/Form.vue_vue_type_script_setup_true_lang.js +234 -0
- package/dist/es/FormBox.js +5 -0
- package/dist/es/FormBox.vue_vue_type_script_setup_true_lang.js +117 -0
- package/dist/es/FormDialog.js +5 -0
- package/dist/es/FormDialog.vue_vue_type_script_setup_true_lang.js +222 -0
- package/dist/es/FormDrawer.js +5 -0
- package/dist/es/FormDrawer.vue_vue_type_script_setup_true_lang.js +176 -0
- package/dist/es/_virtual/_rolldown/runtime.js +27 -0
- package/dist/es/containers/Col.js +5 -0
- package/dist/es/containers/Col.vue_vue_type_script_setup_true_lang.js +60 -0
- package/dist/es/containers/Container.js +5 -0
- package/dist/es/containers/Container.vue_vue_type_script_setup_true_lang.js +438 -0
- package/dist/es/containers/Fieldset.js +5 -0
- package/dist/es/containers/Fieldset.vue_vue_type_script_setup_true_lang.js +153 -0
- package/dist/es/containers/FlexLayout.js +5 -0
- package/dist/es/containers/FlexLayout.vue_vue_type_script_setup_true_lang.js +64 -0
- package/dist/es/containers/FormLabel.js +5 -0
- package/dist/es/containers/FormLabel.vue_vue_type_script_setup_true_lang.js +51 -0
- package/dist/es/containers/GroupList.js +5 -0
- package/dist/es/containers/GroupList.vue_vue_type_script_setup_true_lang.js +164 -0
- package/dist/es/containers/GroupListItem.js +5 -0
- package/dist/es/containers/GroupListItem.vue_vue_type_script_setup_true_lang.js +221 -0
- package/dist/es/containers/Panel.js +5 -0
- package/dist/es/containers/Panel.vue_vue_type_script_setup_true_lang.js +130 -0
- package/dist/es/containers/Row.js +5 -0
- package/dist/es/containers/Row.vue_vue_type_script_setup_true_lang.js +65 -0
- package/dist/es/containers/Step.js +5 -0
- package/dist/es/containers/Step.vue_vue_type_script_setup_true_lang.js +85 -0
- package/dist/es/containers/Tabs.js +5 -0
- package/dist/es/containers/Tabs.vue_vue_type_script_setup_true_lang.js +194 -0
- package/dist/es/fields/Cascader.js +5 -0
- package/dist/es/fields/Cascader.vue_vue_type_script_setup_true_lang.js +123 -0
- package/dist/es/fields/Checkbox.js +5 -0
- package/dist/es/fields/Checkbox.vue_vue_type_script_setup_true_lang.js +61 -0
- package/dist/es/fields/CheckboxGroup.js +5 -0
- package/dist/es/fields/CheckboxGroup.vue_vue_type_script_setup_true_lang.js +63 -0
- package/dist/es/fields/ColorPicker.js +5 -0
- package/dist/es/fields/ColorPicker.vue_vue_type_script_setup_true_lang.js +42 -0
- package/dist/es/fields/Date.js +5 -0
- package/dist/es/fields/Date.vue_vue_type_script_setup_true_lang.js +52 -0
- package/dist/es/fields/DateTime.js +5 -0
- package/dist/es/fields/DateTime.vue_vue_type_script_setup_true_lang.js +57 -0
- package/dist/es/fields/Daterange.js +5 -0
- package/dist/es/fields/Daterange.vue_vue_type_script_setup_true_lang.js +99 -0
- package/dist/es/fields/Display.js +5 -0
- package/dist/es/fields/Display.vue_vue_type_script_setup_true_lang.js +36 -0
- package/dist/es/fields/DynamicField.js +5 -0
- package/dist/es/fields/DynamicField.vue_vue_type_script_setup_true_lang.js +91 -0
- package/dist/es/fields/Hidden.js +5 -0
- package/dist/es/fields/Hidden.vue_vue_type_script_setup_true_lang.js +24 -0
- package/dist/es/fields/Link.js +5 -0
- package/dist/es/fields/Link.vue_vue_type_script_setup_true_lang.js +104 -0
- package/dist/es/fields/Number.js +5 -0
- package/dist/es/fields/Number.vue_vue_type_script_setup_true_lang.js +65 -0
- package/dist/es/fields/NumberRange.js +5 -0
- package/dist/es/fields/NumberRange.vue_vue_type_script_setup_true_lang.js +76 -0
- package/dist/es/fields/RadioGroup.js +5 -0
- package/dist/es/fields/RadioGroup.vue_vue_type_script_setup_true_lang.js +75 -0
- package/dist/es/fields/Select.js +5 -0
- package/dist/es/fields/Select.vue_vue_type_script_setup_true_lang.js +337 -0
- package/dist/es/fields/Switch.js +5 -0
- package/dist/es/fields/Switch.vue_vue_type_script_setup_true_lang.js +59 -0
- package/dist/es/fields/Text.js +5 -0
- package/dist/es/fields/Text.vue_vue_type_script_setup_true_lang.js +215 -0
- package/dist/es/fields/Textarea.js +5 -0
- package/dist/es/fields/Textarea.vue_vue_type_script_setup_true_lang.js +60 -0
- package/dist/es/fields/Time.js +5 -0
- package/dist/es/fields/Time.vue_vue_type_script_setup_true_lang.js +49 -0
- package/dist/es/fields/Timerange.js +5 -0
- package/dist/es/fields/Timerange.vue_vue_type_script_setup_true_lang.js +100 -0
- package/dist/es/index.js +41 -0
- package/dist/es/plugin.js +74 -0
- package/dist/es/schema.js +2 -0
- package/dist/es/style.css +325 -0
- package/dist/es/table/ActionsColumn.js +5 -0
- package/dist/es/table/ActionsColumn.vue_vue_type_script_setup_true_lang.js +107 -0
- package/dist/es/table/SortColumn.js +5 -0
- package/dist/es/table/SortColumn.vue_vue_type_script_setup_true_lang.js +88 -0
- package/dist/es/table/Table.js +5 -0
- package/dist/es/table/Table.vue_vue_type_script_setup_true_lang.js +232 -0
- package/dist/es/table/useAdd.js +71 -0
- package/dist/es/table/useFullscreen.js +15 -0
- package/dist/es/table/useImport.js +46 -0
- package/dist/es/table/usePagination.js +26 -0
- package/dist/es/table/useSelection.js +26 -0
- package/dist/es/table/useSortable.js +39 -0
- package/dist/es/table/useTableColumns.js +160 -0
- package/dist/es/utils/config.js +15 -0
- package/dist/es/utils/form.js +174 -0
- package/dist/es/utils/useAddField.js +13 -0
- package/dist/style.css +1 -1
- package/dist/tmagic-form.umd.cjs +7696 -8924
- package/package.json +7 -6
- package/src/Form.vue +2 -2
- package/src/containers/Container.vue +25 -20
- package/src/containers/GroupListItem.vue +3 -1
- package/src/fields/Hidden.vue +6 -2
- package/src/fields/RadioGroup.vue +1 -1
- package/src/fields/Timerange.vue +2 -2
- package/src/index.ts +8 -82
- package/src/plugin.ts +102 -0
- package/src/table/useSortable.ts +8 -4
- package/src/utils/config.ts +16 -1
- package/src/utils/form.ts +10 -7
- package/types/index.d.ts +1265 -1227
- package/dist/tmagic-form.js +0 -5940
package/package.json
CHANGED
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.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/
|
|
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/
|
|
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/
|
|
55
|
-
"@tmagic/
|
|
56
|
-
"@tmagic/form-schema": "1.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 (
|
|
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 (
|
|
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
|
-
<
|
|
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
|
-
|
|
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(
|
|
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(() => {
|
package/src/fields/Hidden.vue
CHANGED
|
@@ -3,14 +3,18 @@
|
|
|
3
3
|
</template>
|
|
4
4
|
|
|
5
5
|
<script setup lang="ts">
|
|
6
|
-
import type {
|
|
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<
|
|
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>
|
package/src/fields/Timerange.vue
CHANGED
|
@@ -21,7 +21,7 @@ import dayjs from 'dayjs';
|
|
|
21
21
|
|
|
22
22
|
import { TMagicTimePicker } from '@tmagic/design';
|
|
23
23
|
|
|
24
|
-
import type { ChangeRecord,
|
|
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<
|
|
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
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
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
|
|
103
|
-
install(app: App, opt: FormInstallOptions = {}) {
|
|
104
|
-
const option = Object.assign(defaultInstallOpt, opt);
|
|
64
|
+
export type { FormInstallOptions } from './plugin';
|
|
105
65
|
|
|
106
|
-
|
|
107
|
-
setConfig(option);
|
|
66
|
+
export const createForm = <T extends [] = []>(config: FormConfig | T) => config;
|
|
108
67
|
|
|
109
|
-
|
|
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
|
+
};
|
package/src/table/useSortable.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { inject, nextTick, type Ref, type ShallowRef, watchEffect } from 'vue';
|
|
2
|
-
import
|
|
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:
|
|
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
|
-
|
|
31
|
+
|
|
32
|
+
sortable = (await loadSortable()).create(tBodyEl, {
|
|
29
33
|
draggable: '.tmagic-design-table-row',
|
|
30
34
|
filter: 'input', // 表单组件选字操作和触发拖拽会冲突,优先保证选字操作
|
|
31
35
|
preventOnFilter: false, // 允许选字
|
package/src/utils/config.ts
CHANGED
|
@@ -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
|
-
|
|
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
|
|
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
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
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 (
|
|
158
|
-
value[name].sort((a: any, b: any) => b[
|
|
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
|
|