@tmagic/form 1.4.7 → 1.4.8

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 (60) hide show
  1. package/dist/tmagic-form.js +54 -108
  2. package/dist/tmagic-form.umd.cjs +54 -108
  3. package/package.json +9 -5
  4. package/src/Form.vue +0 -201
  5. package/src/FormBox.vue +0 -120
  6. package/src/FormDialog.vue +0 -173
  7. package/src/FormDrawer.vue +0 -159
  8. package/src/containers/Col.vue +0 -52
  9. package/src/containers/Container.vue +0 -408
  10. package/src/containers/Fieldset.vue +0 -124
  11. package/src/containers/GroupList.vue +0 -139
  12. package/src/containers/GroupListItem.vue +0 -135
  13. package/src/containers/Panel.vue +0 -99
  14. package/src/containers/Row.vue +0 -54
  15. package/src/containers/Step.vue +0 -82
  16. package/src/containers/Table.vue +0 -648
  17. package/src/containers/Tabs.vue +0 -226
  18. package/src/fields/Cascader.vue +0 -131
  19. package/src/fields/Checkbox.vue +0 -58
  20. package/src/fields/CheckboxGroup.vue +0 -43
  21. package/src/fields/ColorPicker.vue +0 -30
  22. package/src/fields/Date.vue +0 -38
  23. package/src/fields/DateTime.vue +0 -47
  24. package/src/fields/Daterange.vue +0 -99
  25. package/src/fields/Display.vue +0 -21
  26. package/src/fields/DynamicField.vue +0 -90
  27. package/src/fields/Hidden.vue +0 -16
  28. package/src/fields/Link.vue +0 -86
  29. package/src/fields/Number.vue +0 -49
  30. package/src/fields/NumberRange.vue +0 -50
  31. package/src/fields/RadioGroup.vue +0 -28
  32. package/src/fields/Select.vue +0 -449
  33. package/src/fields/Switch.vue +0 -59
  34. package/src/fields/Text.vue +0 -170
  35. package/src/fields/Textarea.vue +0 -46
  36. package/src/fields/Time.vue +0 -34
  37. package/src/fields/Timerange.vue +0 -76
  38. package/src/index.ts +0 -139
  39. package/src/schema.ts +0 -757
  40. package/src/shims-vue.d.ts +0 -6
  41. package/src/theme/date-time.scss +0 -7
  42. package/src/theme/fieldset.scss +0 -28
  43. package/src/theme/form-box.scss +0 -13
  44. package/src/theme/form-dialog.scss +0 -13
  45. package/src/theme/form-drawer.scss +0 -11
  46. package/src/theme/form.scss +0 -43
  47. package/src/theme/group-list.scss +0 -23
  48. package/src/theme/index.scss +0 -14
  49. package/src/theme/link.scss +0 -3
  50. package/src/theme/number-range.scss +0 -8
  51. package/src/theme/panel.scss +0 -24
  52. package/src/theme/select.scss +0 -3
  53. package/src/theme/table.scss +0 -70
  54. package/src/theme/tabs.scss +0 -27
  55. package/src/theme/text.scss +0 -6
  56. package/src/utils/config.ts +0 -27
  57. package/src/utils/containerProps.ts +0 -50
  58. package/src/utils/form.ts +0 -268
  59. package/src/utils/useAddField.ts +0 -40
  60. package/tsconfig.build.json +0 -13
@@ -1,6 +0,0 @@
1
- declare module '*.vue' {
2
- import { DefineComponent } from 'vue';
3
-
4
- const component: DefineComponent<{}, {}, any>;
5
- export default component;
6
- }
@@ -1,7 +0,0 @@
1
- .magic-datetime-picker-popper {
2
- .el-picker-panel__footer {
3
- button:first-child {
4
- display: none;
5
- }
6
- }
7
- }
@@ -1,28 +0,0 @@
1
- fieldset.m-fieldset {
2
- position: relative;
3
- border: 1px solid rgb(229, 229, 229);
4
- margin-top: 10px;
5
- margin-bottom: 10px;
6
- min-inline-size: auto;
7
-
8
- .el-checkbox {
9
- height: 22px;
10
- }
11
-
12
- legend {
13
- font-size: 14px;
14
- position: absolute;
15
- border: 0;
16
- top: -10px;
17
- left: 20px;
18
- background: rgb(255, 255, 255);
19
- width: auto;
20
- padding: 0px 3px;
21
- font-weight: bold;
22
- line-height: 20px;
23
- }
24
-
25
- .m-form-tip {
26
- margin-left: 5px;
27
- }
28
- }
@@ -1,13 +0,0 @@
1
- .m-form-box {
2
- display: flex;
3
- flex-direction: column;
4
- .el-box__header {
5
- margin: 0;
6
- }
7
-
8
- .dialog-footer {
9
- display: flex;
10
- align-items: center;
11
- justify-content: space-between;
12
- }
13
- }
@@ -1,13 +0,0 @@
1
- .m-form-dialog {
2
- .el-dialog__body {
3
- padding: 0 !important;
4
- }
5
-
6
- .m-dialog-body {
7
- padding: 0 20px;
8
- }
9
-
10
- .el-table .m-form-item .el-form-item {
11
- margin-bottom: 0;
12
- }
13
- }
@@ -1,11 +0,0 @@
1
- .m-form-drawer {
2
- .el-drawer__header {
3
- margin: 0;
4
- }
5
-
6
- .m-drawer-body {
7
- height: 100%;
8
- overflow-y: auto;
9
- overflow-x: hidden;
10
- }
11
- }
@@ -1,43 +0,0 @@
1
- .fade-enter-active,
2
- .fade-leave-active {
3
- transition: opacity 0.5s;
4
- }
5
-
6
- .fade-enter, .fade-leave-to /* .fade-leave-active below version 2.1.8 */ {
7
- opacity: 0;
8
- }
9
-
10
- .m-form {
11
- .m-form-tip {
12
- color: rgba(0, 0, 0, 0.45);
13
- font-size: 12px;
14
- transition: color 0.3s cubic-bezier(0.215, 0.61, 0.355, 1);
15
- }
16
-
17
- .m-form-schematic {
18
- max-width: 50%;
19
- height: 100%;
20
- }
21
-
22
- .el-table {
23
- .cell > div.m-form-container {
24
- display: block;
25
- }
26
- }
27
-
28
- .el-tabs {
29
- margin-bottom: 10px;
30
- }
31
-
32
- .el-form-item.hidden {
33
- > .el-form-item__label {
34
- display: none;
35
- }
36
- }
37
-
38
- .t-form__item.hidden {
39
- > .t-form__label {
40
- display: none;
41
- }
42
- }
43
- }
@@ -1,23 +0,0 @@
1
- .m-fields-group-list {
2
- .el-button--text {
3
- padding: 0;
4
- margin-bottom: 7px;
5
- }
6
-
7
- .el-tree-node__expand-icon {
8
- padding: 0;
9
- margin-bottom: 7px;
10
- &.expand {
11
- transform: rotate(90deg);
12
- }
13
- }
14
-
15
- .m-fields-group-list-item {
16
- border-bottom: 1px solid #ebeef5;
17
- margin-bottom: 7px;
18
-
19
- &:last-of-type {
20
- border-bottom: 0;
21
- }
22
- }
23
- }
@@ -1,14 +0,0 @@
1
- @use "./form-dialog.scss";
2
- @use "./form-drawer.scss";
3
- @use "./form.scss";
4
- @use "./date-time.scss";
5
- @use "./text.scss";
6
- @use "./link.scss";
7
- @use "./fieldset.scss";
8
- @use "./group-list.scss";
9
- @use "./panel.scss";
10
- @use "./table.scss";
11
- @use "./select.scss";
12
- @use "./tabs.scss";
13
- @use "./number-range.scss";
14
- @use "./form-box.scss";
@@ -1,3 +0,0 @@
1
- div.m-fields-link {
2
- width: fit-content;
3
- }
@@ -1,8 +0,0 @@
1
- .m-fields-number-range {
2
- display: flex;
3
- align-items: center;
4
-
5
- .split-tag {
6
- margin: 0 5px;
7
- }
8
- }
@@ -1,24 +0,0 @@
1
- .m-form-panel {
2
- .el-card__header {
3
- &:hover {
4
- background: #f2f6fc;
5
- }
6
- a {
7
- color: #409eff;
8
- }
9
- }
10
-
11
- .el-card__body {
12
- padding: 10px;
13
- }
14
-
15
- .m-form-tip {
16
- margin-left: 5px;
17
- }
18
- }
19
-
20
- .m-container-panel {
21
- &:not(:last-of-type) {
22
- margin-bottom: 20px;
23
- }
24
- }
@@ -1,3 +0,0 @@
1
- .m-select {
2
- width: 100%;
3
- }
@@ -1,70 +0,0 @@
1
- .m-fields-table-wrap {
2
- width: 100%;
3
- }
4
-
5
- .m-fields-table {
6
- width: 100%;
7
- &.fixed {
8
- position: fixed;
9
- height: 100%;
10
- overflow: auto;
11
- top: 0;
12
- right: 0;
13
- left: 0;
14
- bottom: 0;
15
- z-index: 100;
16
- background: rgba(0, 0, 0, 0.5);
17
-
18
- & > .el-form-item__content {
19
- z-index: 101;
20
- position: relative;
21
- margin: 10vh auto;
22
- max-width: fit-content;
23
- }
24
- table {
25
- width: 95vw !important;
26
- }
27
- }
28
-
29
- th {
30
- background-color: #f2f2f2 !important;
31
- color: #333 !important;
32
- }
33
-
34
- .el-table {
35
- th {
36
- padding: 0 !important;
37
- }
38
- }
39
-
40
- .el-table__column--dropable {
41
- cursor: move;
42
- }
43
-
44
- .el-form-item__content {
45
- .el-input-group {
46
- vertical-align: middle;
47
- }
48
- }
49
-
50
- &.m-fields-table-item-extra {
51
- tr.expanded td {
52
- border-bottom: 0;
53
- }
54
- }
55
-
56
- .el-table__expanded-cell {
57
- .m-form-tip {
58
- margin-left: 80px;
59
- }
60
- }
61
-
62
- .el-form-item {
63
- margin-bottom: 0;
64
- }
65
-
66
- .m-table-delete-icon {
67
- color: #f56c6c;
68
- cursor: pointer;
69
- }
70
- }
@@ -1,27 +0,0 @@
1
- .magic-form-dynamic-tab {
2
- .el-tabs__header.is-top {
3
- padding-right: 8px;
4
- .el-tabs__new-tab {
5
- margin-right: auto;
6
- min-width: 50px;
7
- outline: none;
8
- border-color: #409eff;
9
- color: #409eff;
10
- width: 10px;
11
- &::before {
12
- content: "添加";
13
- }
14
- .el-icon-plus {
15
- display: none;
16
- }
17
- }
18
- }
19
- }
20
-
21
- .magic-form-tab {
22
- margin-bottom: 10px;
23
- }
24
-
25
- .diff-count-badge {
26
- top: -10px;
27
- }
@@ -1,6 +0,0 @@
1
- .m-form-validate__warning {
2
- color: var(--el-color-warning);
3
- font-size: 12px;
4
- width: 100%;
5
- line-height: 1.4;
6
- }
@@ -1,27 +0,0 @@
1
- /*
2
- * Tencent is pleased to support the open source community by making TMagicEditor available.
3
- *
4
- * Copyright (C) 2023 THL A29 Limited, a Tencent company. 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
- let $MAGIC_FORM = {} as any;
20
-
21
- const setConfig = (option: any): void => {
22
- $MAGIC_FORM = option;
23
- };
24
-
25
- const getConfig = <T = unknown>(key: string): T => $MAGIC_FORM[key];
26
-
27
- export { getConfig, setConfig };
@@ -1,50 +0,0 @@
1
- /*
2
- * Tencent is pleased to support the open source community by making TMagicEditor available.
3
- *
4
- * Copyright (C) 2023 THL A29 Limited, a Tencent company. 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 { PropType } from 'vue';
20
-
21
- import { ChildConfig, FormValue } from '../schema';
22
-
23
- export default {
24
- labelWidth: String,
25
- expandMore: Boolean,
26
-
27
- model: {
28
- type: [Object, Array] as PropType<FormValue>,
29
- required: true,
30
- },
31
-
32
- config: {
33
- type: Object as PropType<ChildConfig>,
34
- required: true,
35
- },
36
-
37
- prop: {
38
- type: String,
39
- default: () => '',
40
- },
41
-
42
- stepActive: {
43
- type: [String, Number],
44
- },
45
-
46
- size: {
47
- type: String,
48
- default: 'small',
49
- },
50
- };
package/src/utils/form.ts DELETED
@@ -1,268 +0,0 @@
1
- /*
2
- * Tencent is pleased to support the open source community by making TMagicEditor available.
3
- *
4
- * Copyright (C) 2023 THL A29 Limited, a Tencent company. 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
- /* eslint-disable no-param-reassign */
20
- import { toRaw } from 'vue';
21
- import { cloneDeep } from 'lodash-es';
22
-
23
- import {
24
- ChildConfig,
25
- ContainerCommonConfig,
26
- DaterangeConfig,
27
- FormConfig,
28
- FormState,
29
- FormValue,
30
- HtmlField,
31
- Rule,
32
- TabPaneConfig,
33
- TypeFunction,
34
- } from '../schema';
35
-
36
- interface DefaultItem {
37
- defaultValue: any;
38
- type: string;
39
- filter: string;
40
- multiple: boolean;
41
- }
42
-
43
- const isTableSelect = (type?: string | TypeFunction) =>
44
- typeof type === 'string' && ['table-select', 'tableSelect'].includes(type);
45
-
46
- const asyncLoadConfig = (value: FormValue, initValue: FormValue, { asyncLoad, name, type }: HtmlField) => {
47
- // 富文本配置了异步加载
48
- if (type === 'html' && typeof asyncLoad === 'object' && typeof name !== 'undefined') {
49
- asyncLoad.name = name;
50
- value.asyncLoad = typeof initValue.asyncLoad === 'object' ? initValue.asyncLoad : asyncLoad;
51
- }
52
- };
53
-
54
- const isMultipleValue = (type?: string | TypeFunction) =>
55
- typeof type === 'string' &&
56
- ['checkbox-group', 'checkboxGroup', 'table', 'cascader', 'group-list', 'groupList'].includes(type);
57
-
58
- const initItemsValue = (
59
- mForm: FormState | undefined,
60
- value: FormValue,
61
- initValue: FormValue,
62
- { items, name, extensible }: any,
63
- ) => {
64
- if (Array.isArray(initValue[name])) {
65
- value[name] = initValue[name].map((v: any, index: number) => createValues(mForm, items, v, value[name]?.[index]));
66
- } else {
67
- value[name] = createValues(mForm, items, initValue[name], value[name]);
68
- if (extensible) {
69
- value[name] = Object.assign({}, initValue[name], value[name]);
70
- }
71
- }
72
- };
73
-
74
- const setValue = (mForm: FormState | undefined, value: FormValue, initValue: FormValue, item: any) => {
75
- const { items, name, type, checkbox } = item;
76
- // 值是数组, 有可能也有items配置,所以不能放到getDefaultValue里赋值
77
- if (isMultipleValue(type) || (type === 'tab' && item.dynamic)) {
78
- value[name] = initValue[name] || [];
79
- }
80
-
81
- // 有子项继续递归,没有的话有初始值用初始值,没有初始值用默认值
82
- if (items) {
83
- initItemsValue(mForm, value, initValue, item);
84
- } else {
85
- value[name] = getDefaultValue(mForm, item as DefaultItem);
86
- }
87
-
88
- // 如果fieldset配置checkbox,checkbox的值保存在value中
89
- if (type === 'fieldset' && checkbox) {
90
- if (typeof value[name] === 'object') {
91
- value[name].value = typeof initValue[name] === 'object' ? initValue[name].value || 0 : 0;
92
- }
93
- }
94
- };
95
-
96
- const initValueItem = function (
97
- mForm: FormState | undefined,
98
- item: ChildConfig | TabPaneConfig,
99
- initValue: FormValue,
100
- value: FormValue,
101
- ) {
102
- const { items } = item as ContainerCommonConfig;
103
- const { names } = item as DaterangeConfig;
104
- const { type, name } = item as ChildConfig;
105
-
106
- if (isTableSelect(type) && name) {
107
- value[name] = initValue[name] || '';
108
- return value;
109
- }
110
-
111
- asyncLoadConfig(value, initValue, item as HtmlField);
112
-
113
- // 这种情况比较多,提前结束
114
- if (name && !items && typeof initValue[name] !== 'undefined') {
115
- if (typeof value[name] === 'undefined') {
116
- if (type === 'number') {
117
- value[name] = Number(initValue[name]);
118
- } else {
119
- value[name] = typeof initValue[name] === 'object' ? cloneDeep(initValue[name]) : initValue[name];
120
- }
121
- }
122
-
123
- return value;
124
- }
125
-
126
- if (names) {
127
- return names.forEach((n: string) => (value[n] = initValue[n] || ''));
128
- }
129
-
130
- if (!name) {
131
- // 没有配置name,直接跳过
132
- return createValues(mForm, items, initValue, value);
133
- }
134
-
135
- setValue(mForm, value, initValue, item);
136
-
137
- return value;
138
- };
139
-
140
- export const createValues = function (
141
- mForm: FormState | undefined,
142
- config: FormConfig | TabPaneConfig[] = [],
143
- initValue: FormValue = {},
144
- value: FormValue = {},
145
- ) {
146
- if (Array.isArray(config)) {
147
- config.forEach((item: ChildConfig | TabPaneConfig) => {
148
- initValueItem(mForm, item, initValue, value);
149
- });
150
- }
151
-
152
- return value;
153
- };
154
-
155
- const getDefaultValue = function (mForm: FormState | undefined, { defaultValue, type, filter, multiple }: DefaultItem) {
156
- if (typeof defaultValue === 'function') {
157
- return defaultValue(mForm);
158
- }
159
-
160
- // 如果直接设置为undefined,在解析成js对象时会丢失这个配置,所以用'undefined'代替
161
- if (defaultValue === 'undefined') {
162
- return undefined;
163
- }
164
-
165
- if (typeof defaultValue !== 'undefined') {
166
- return defaultValue;
167
- }
168
-
169
- if (type === 'number' || filter === 'number') {
170
- return 0;
171
- }
172
-
173
- if (['switch', 'checkbox'].includes(type)) {
174
- return false;
175
- }
176
-
177
- if (multiple || type === 'number-range') {
178
- return [];
179
- }
180
-
181
- return '';
182
- };
183
-
184
- export const filterFunction = <T = any>(mForm: FormState | undefined, config: T, props: any) => {
185
- if (typeof config !== 'function') {
186
- return config;
187
- }
188
-
189
- return config(mForm, {
190
- values: mForm?.initValues || {},
191
- model: props.model,
192
- parent: mForm?.parentValues || {},
193
- formValue: mForm?.values || props.model,
194
- prop: props.prop,
195
- config: props.config,
196
- index: props.index,
197
- });
198
- };
199
-
200
- export const display = function (mForm: FormState | undefined, config: any, props: any) {
201
- if (config === 'expand') {
202
- return config;
203
- }
204
-
205
- if (typeof config === 'function') {
206
- return filterFunction(mForm, config, props);
207
- }
208
-
209
- if (config === false) {
210
- return false;
211
- }
212
-
213
- return true;
214
- };
215
-
216
- export const getRules = function (mForm: FormState | undefined, rules: Rule[] | Rule = [], props: any) {
217
- rules = cloneDeep(rules);
218
-
219
- if (typeof rules === 'object' && !Array.isArray(rules)) {
220
- rules = [rules];
221
- }
222
-
223
- return rules.map((item) => {
224
- if (typeof item.validator === 'function') {
225
- const fnc = item.validator;
226
-
227
- (item as any).validator = (rule: any, value: any, callback: Function, source: any, options: any) =>
228
- fnc(
229
- {
230
- rule,
231
- value: props.config.names ? props.model : value,
232
- callback,
233
- source,
234
- options,
235
- },
236
- {
237
- values: mForm?.initValues || {},
238
- model: props.model,
239
- parent: mForm?.parentValues || {},
240
- formValue: mForm?.values || props.model,
241
- prop: props.prop,
242
- config: props.config,
243
- },
244
- mForm,
245
- );
246
- }
247
- return item;
248
- });
249
- };
250
-
251
- export const initValue = async (
252
- mForm: FormState | undefined,
253
- { initValues, config }: { initValues: FormValue; config: FormConfig },
254
- ) => {
255
- if (!Array.isArray(config)) throw new Error('config应该为数组');
256
-
257
- let valuesTmp = createValues(mForm, config, toRaw(initValues), {});
258
-
259
- const [firstForm] = config as [ContainerCommonConfig];
260
- if (firstForm && typeof firstForm.onInitValue === 'function') {
261
- valuesTmp = await firstForm.onInitValue(mForm, {
262
- formValue: valuesTmp,
263
- initValue: initValues,
264
- });
265
- }
266
-
267
- return valuesTmp || {};
268
- };