@tmagic/editor 1.3.0-alpha.19 → 1.3.0-alpha.20
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/dist/tmagic-editor.js +3717 -3646
- package/dist/tmagic-editor.js.map +1 -1
- package/dist/tmagic-editor.umd.cjs +3715 -3642
- package/dist/tmagic-editor.umd.cjs.map +1 -1
- package/package.json +10 -10
- package/src/components/CodeParams.vue +2 -1
- package/src/editorProps.ts +30 -3
- package/src/fields/DataSourceInput.vue +8 -45
- package/src/initService.ts +33 -0
- package/src/layouts/sidebar/data-source/DataSourceConfigPanel.vue +11 -1
- package/src/services/dataSource.ts +15 -2
- package/src/services/editor.ts +2 -2
- package/src/services/props.ts +2 -2
- package/src/type.ts +6 -1
- package/src/utils/data-source/formConfigs/base.ts +35 -30
- package/src/utils/data-source/index.ts +64 -6
- package/src/utils/index.ts +1 -0
- package/src/utils/undo-redo.ts +1 -1
- package/types/Editor.vue.d.ts +30 -3
- package/types/editorProps.d.ts +19 -3
- package/types/initService.d.ts +1 -1
- package/types/services/dataSource.d.ts +6 -1
- package/types/services/props.d.ts +2 -2
- package/types/type.d.ts +5 -1
- package/types/utils/data-source/formConfigs/base.d.ts +2 -2
- package/types/utils/data-source/index.d.ts +7 -1
- package/types/utils/index.d.ts +1 -0
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.3.0-alpha.
|
|
2
|
+
"version": "1.3.0-alpha.20",
|
|
3
3
|
"name": "@tmagic/editor",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": [
|
|
@@ -46,13 +46,13 @@
|
|
|
46
46
|
"dependencies": {
|
|
47
47
|
"@babel/core": "^7.18.0",
|
|
48
48
|
"@element-plus/icons-vue": "^2.0.9",
|
|
49
|
-
"@tmagic/core": "1.3.0-alpha.
|
|
50
|
-
"@tmagic/design": "1.3.0-alpha.
|
|
51
|
-
"@tmagic/form": "1.3.0-alpha.
|
|
52
|
-
"@tmagic/schema": "1.3.0-alpha.
|
|
53
|
-
"@tmagic/stage": "1.3.0-alpha.
|
|
54
|
-
"@tmagic/table": "1.3.0-alpha.
|
|
55
|
-
"@tmagic/utils": "1.3.0-alpha.
|
|
49
|
+
"@tmagic/core": "1.3.0-alpha.20",
|
|
50
|
+
"@tmagic/design": "1.3.0-alpha.20",
|
|
51
|
+
"@tmagic/form": "1.3.0-alpha.20",
|
|
52
|
+
"@tmagic/schema": "1.3.0-alpha.20",
|
|
53
|
+
"@tmagic/stage": "1.3.0-alpha.20",
|
|
54
|
+
"@tmagic/table": "1.3.0-alpha.20",
|
|
55
|
+
"@tmagic/utils": "1.3.0-alpha.20",
|
|
56
56
|
"buffer": "^6.0.3",
|
|
57
57
|
"color": "^3.1.3",
|
|
58
58
|
"events": "^3.3.0",
|
|
@@ -64,8 +64,8 @@
|
|
|
64
64
|
"vue": "^3.3.4"
|
|
65
65
|
},
|
|
66
66
|
"peerDependencies": {
|
|
67
|
-
"@tmagic/design": "1.3.0-alpha.
|
|
68
|
-
"@tmagic/form": "1.3.0-alpha.
|
|
67
|
+
"@tmagic/design": "1.3.0-alpha.20",
|
|
68
|
+
"@tmagic/form": "1.3.0-alpha.20",
|
|
69
69
|
"monaco-editor": "^0.41.0",
|
|
70
70
|
"vue": "^3.3.4"
|
|
71
71
|
},
|
|
@@ -16,6 +16,7 @@ import { computed, ref } from 'vue';
|
|
|
16
16
|
import { FormConfig, MForm } from '@tmagic/form';
|
|
17
17
|
|
|
18
18
|
import type { CodeParamStatement } from '@editor/type';
|
|
19
|
+
import { error } from '@editor/utils';
|
|
19
20
|
|
|
20
21
|
defineOptions({
|
|
21
22
|
name: 'MEditorCodeParams',
|
|
@@ -53,7 +54,7 @@ const onParamsChangeHandler = async () => {
|
|
|
53
54
|
const value = await form.value?.submitForm(true);
|
|
54
55
|
emit('change', value);
|
|
55
56
|
} catch (e) {
|
|
56
|
-
|
|
57
|
+
error(e);
|
|
57
58
|
}
|
|
58
59
|
};
|
|
59
60
|
</script>
|
package/src/editorProps.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type { PropType } from 'vue';
|
|
|
2
2
|
|
|
3
3
|
import type { EventOption } from '@tmagic/core';
|
|
4
4
|
import type { FormConfig, FormState } from '@tmagic/form';
|
|
5
|
-
import type { MApp, MNode } from '@tmagic/schema';
|
|
5
|
+
import type { DataSourceSchema, MApp, MNode } from '@tmagic/schema';
|
|
6
6
|
import StageCore, {
|
|
7
7
|
CONTAINER_HIGHLIGHT_CLASS_NAME,
|
|
8
8
|
ContainerHighlightType,
|
|
@@ -11,7 +11,15 @@ import StageCore, {
|
|
|
11
11
|
UpdateDragEl,
|
|
12
12
|
} from '@tmagic/stage';
|
|
13
13
|
|
|
14
|
-
import type {
|
|
14
|
+
import type {
|
|
15
|
+
ComponentGroup,
|
|
16
|
+
DatasourceTypeOption,
|
|
17
|
+
MenuBarData,
|
|
18
|
+
MenuButton,
|
|
19
|
+
MenuComponent,
|
|
20
|
+
SideBarData,
|
|
21
|
+
StageRect,
|
|
22
|
+
} from './type';
|
|
15
23
|
|
|
16
24
|
export default {
|
|
17
25
|
/** 页面初始值 */
|
|
@@ -27,6 +35,12 @@ export default {
|
|
|
27
35
|
default: () => [],
|
|
28
36
|
},
|
|
29
37
|
|
|
38
|
+
/** 左侧面板中的组件列表 */
|
|
39
|
+
datasourceList: {
|
|
40
|
+
type: Array as PropType<DatasourceTypeOption[]>,
|
|
41
|
+
default: () => [],
|
|
42
|
+
},
|
|
43
|
+
|
|
30
44
|
/** 左侧面板配置 */
|
|
31
45
|
sidebar: {
|
|
32
46
|
type: Object as PropType<SideBarData>,
|
|
@@ -69,7 +83,7 @@ export default {
|
|
|
69
83
|
|
|
70
84
|
/** 添加组件时的默认值 */
|
|
71
85
|
propsValues: {
|
|
72
|
-
type: Object as PropType<Record<string, MNode
|
|
86
|
+
type: Object as PropType<Record<string, Partial<MNode>>>,
|
|
73
87
|
default: () => ({}),
|
|
74
88
|
},
|
|
75
89
|
|
|
@@ -79,6 +93,19 @@ export default {
|
|
|
79
93
|
default: () => ({}),
|
|
80
94
|
},
|
|
81
95
|
|
|
96
|
+
/** 组件的属性配置表单的dsl */
|
|
97
|
+
datasourceConfigs: {
|
|
98
|
+
type: Object as PropType<Record<string, FormConfig>>,
|
|
99
|
+
default: () => ({}),
|
|
100
|
+
},
|
|
101
|
+
|
|
102
|
+
/** 添加数据源时的默认值 */
|
|
103
|
+
datasourceValues: {
|
|
104
|
+
type: Object as PropType<Record<string, Partial<DataSourceSchema>>>,
|
|
105
|
+
default: () => ({}),
|
|
106
|
+
},
|
|
107
|
+
|
|
108
|
+
/** 数据源的属性配置表单的dsl */
|
|
82
109
|
dataScourceConfigs: {
|
|
83
110
|
type: Object as PropType<Record<string, FormConfig>>,
|
|
84
111
|
default: () => ({}),
|
|
@@ -54,6 +54,7 @@ import type { DataSchema, DataSourceSchema } from '@tmagic/schema';
|
|
|
54
54
|
|
|
55
55
|
import Icon from '@editor/components/Icon.vue';
|
|
56
56
|
import type { Services } from '@editor/type';
|
|
57
|
+
import { getDisplayField } from '@editor/utils/data-source';
|
|
57
58
|
|
|
58
59
|
defineOptions({
|
|
59
60
|
name: 'MEditorDataSourceInput',
|
|
@@ -87,49 +88,7 @@ const input = computed<HTMLInputElement>(() => autocomplete.value?.inputRef?.inp
|
|
|
87
88
|
const dataSources = computed(() => dataSourceService?.get('dataSources') || []);
|
|
88
89
|
|
|
89
90
|
const setDisplayState = () => {
|
|
90
|
-
displayState.value =
|
|
91
|
-
|
|
92
|
-
const matches = state.value.matchAll(/\$\{([\s\S]+?)\}/g);
|
|
93
|
-
let index = 0;
|
|
94
|
-
for (const match of matches) {
|
|
95
|
-
if (typeof match.index === 'undefined') break;
|
|
96
|
-
|
|
97
|
-
displayState.value.push({
|
|
98
|
-
type: 'text',
|
|
99
|
-
value: state.value.substring(index, match.index),
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
let dsText = '';
|
|
103
|
-
let ds: DataSourceSchema | undefined;
|
|
104
|
-
let fields: DataSchema[] | undefined;
|
|
105
|
-
|
|
106
|
-
match[1].split('.').forEach((item, index) => {
|
|
107
|
-
if (index === 0) {
|
|
108
|
-
ds = dataSources.value.find((ds) => ds.id === item);
|
|
109
|
-
dsText += ds?.title || item;
|
|
110
|
-
fields = ds?.fields;
|
|
111
|
-
return;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
const field = fields?.find((field) => field.name === item);
|
|
115
|
-
fields = field?.fields;
|
|
116
|
-
dsText += `.${field?.title || item}`;
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
displayState.value.push({
|
|
120
|
-
type: 'var',
|
|
121
|
-
value: dsText,
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
index = match.index + match[0].length;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
if (index < state.value.length) {
|
|
128
|
-
displayState.value.push({
|
|
129
|
-
type: 'text',
|
|
130
|
-
value: state.value.substring(index),
|
|
131
|
-
});
|
|
132
|
-
}
|
|
91
|
+
displayState.value = getDisplayField(dataSources.value, state.value);
|
|
133
92
|
};
|
|
134
93
|
|
|
135
94
|
watch(
|
|
@@ -243,17 +202,21 @@ const fieldQuerySearch = (
|
|
|
243
202
|
let result: DataSchema[] = [];
|
|
244
203
|
|
|
245
204
|
const dsKey = queryString.substring(leftAngleIndex + 1, dotIndex);
|
|
205
|
+
|
|
246
206
|
// 可能是xx.xx.xx,存在链式调用
|
|
247
207
|
const keys = dsKey.split('.');
|
|
208
|
+
|
|
248
209
|
// 最前的是数据源id
|
|
249
|
-
const
|
|
210
|
+
const dsId = keys.shift();
|
|
211
|
+
const ds = dataSources.value.find((ds) => ds.id === dsId);
|
|
250
212
|
if (!ds) {
|
|
213
|
+
cb([]);
|
|
251
214
|
return;
|
|
252
215
|
}
|
|
253
216
|
|
|
254
217
|
let fields = ds.fields || [];
|
|
255
218
|
|
|
256
|
-
//
|
|
219
|
+
// 后面这些是字段
|
|
257
220
|
let key = keys.shift();
|
|
258
221
|
while (key) {
|
|
259
222
|
for (const field of fields) {
|
package/src/initService.ts
CHANGED
|
@@ -31,6 +31,7 @@ export const initServiceState = (
|
|
|
31
31
|
uiService,
|
|
32
32
|
codeBlockService,
|
|
33
33
|
keybindingService,
|
|
34
|
+
dataSourceService,
|
|
34
35
|
}: Services,
|
|
35
36
|
) => {
|
|
36
37
|
// 初始值变化,重新设置节点信息
|
|
@@ -52,6 +53,14 @@ export const initServiceState = (
|
|
|
52
53
|
},
|
|
53
54
|
);
|
|
54
55
|
|
|
56
|
+
watch(
|
|
57
|
+
() => props.datasourceList,
|
|
58
|
+
(datasourceList) => dataSourceService.set('datasourceTypeList', datasourceList),
|
|
59
|
+
{
|
|
60
|
+
immediate: true,
|
|
61
|
+
},
|
|
62
|
+
);
|
|
63
|
+
|
|
55
64
|
watch(
|
|
56
65
|
() => props.propsConfigs,
|
|
57
66
|
(configs) => propsService.setPropsConfigs(configs),
|
|
@@ -87,6 +96,30 @@ export const initServiceState = (
|
|
|
87
96
|
},
|
|
88
97
|
);
|
|
89
98
|
|
|
99
|
+
watch(
|
|
100
|
+
() => props.datasourceConfigs,
|
|
101
|
+
(configs) => {
|
|
102
|
+
Object.entries(configs).forEach(([key, value]) => {
|
|
103
|
+
dataSourceService.setFormConfig(key, value);
|
|
104
|
+
});
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
immediate: true,
|
|
108
|
+
},
|
|
109
|
+
);
|
|
110
|
+
|
|
111
|
+
watch(
|
|
112
|
+
() => props.datasourceValues,
|
|
113
|
+
(values) => {
|
|
114
|
+
Object.entries(values).forEach(([key, value]) => {
|
|
115
|
+
dataSourceService.setFormValue(key, value);
|
|
116
|
+
});
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
immediate: true,
|
|
120
|
+
},
|
|
121
|
+
);
|
|
122
|
+
|
|
90
123
|
watch(
|
|
91
124
|
() => props.defaultSelected,
|
|
92
125
|
(defaultSelected) => defaultSelected && editorService.select(defaultSelected),
|
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
|
|
17
17
|
<script setup lang="ts">
|
|
18
18
|
import { computed, inject, ref, watchEffect } from 'vue';
|
|
19
|
+
import { cloneDeep, mergeWith } from 'lodash-es';
|
|
19
20
|
|
|
20
21
|
import { tMagicMessage } from '@tmagic/design';
|
|
21
22
|
import { MFormDrawer } from '@tmagic/form';
|
|
@@ -56,7 +57,16 @@ const changeHandler = (value: Record<string, any>) => {
|
|
|
56
57
|
return;
|
|
57
58
|
}
|
|
58
59
|
type.value = value.type || 'base';
|
|
59
|
-
|
|
60
|
+
|
|
61
|
+
initValues.value = mergeWith(
|
|
62
|
+
cloneDeep(value),
|
|
63
|
+
services?.dataSourceService.getFormValue(type.value) || {},
|
|
64
|
+
(objValue, srcValue) => {
|
|
65
|
+
if (Array.isArray(srcValue)) {
|
|
66
|
+
return srcValue;
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
);
|
|
60
70
|
};
|
|
61
71
|
|
|
62
72
|
const submitHandler = (values: any) => {
|
|
@@ -2,25 +2,30 @@ import { reactive } from 'vue';
|
|
|
2
2
|
import { cloneDeep } from 'lodash-es';
|
|
3
3
|
|
|
4
4
|
import type { FormConfig } from '@tmagic/form';
|
|
5
|
-
import { DataSourceSchema } from '@tmagic/schema';
|
|
5
|
+
import type { DataSourceSchema } from '@tmagic/schema';
|
|
6
6
|
import { guid } from '@tmagic/utils';
|
|
7
7
|
|
|
8
|
+
import type { DatasourceTypeOption } from '@editor/type';
|
|
8
9
|
import { getFormConfig } from '@editor/utils/data-source';
|
|
9
10
|
|
|
10
11
|
import BaseService from './BaseService';
|
|
11
12
|
|
|
12
13
|
interface State {
|
|
14
|
+
datasourceTypeList: DatasourceTypeOption[];
|
|
13
15
|
dataSources: DataSourceSchema[];
|
|
14
16
|
editable: boolean;
|
|
15
17
|
configs: Record<string, FormConfig>;
|
|
18
|
+
values: Record<string, Partial<DataSourceSchema>>;
|
|
16
19
|
}
|
|
17
20
|
|
|
18
21
|
type StateKey = keyof State;
|
|
19
22
|
class DataSource extends BaseService {
|
|
20
23
|
private state = reactive<State>({
|
|
24
|
+
datasourceTypeList: [],
|
|
21
25
|
dataSources: [],
|
|
22
26
|
editable: true,
|
|
23
27
|
configs: {},
|
|
28
|
+
values: {},
|
|
24
29
|
});
|
|
25
30
|
|
|
26
31
|
public set<K extends StateKey, T extends State[K]>(name: K, value: T) {
|
|
@@ -32,13 +37,21 @@ class DataSource extends BaseService {
|
|
|
32
37
|
}
|
|
33
38
|
|
|
34
39
|
public getFormConfig(type = 'base') {
|
|
35
|
-
return getFormConfig(type, this.get('configs'));
|
|
40
|
+
return getFormConfig(type, this.get('datasourceTypeList'), this.get('configs'));
|
|
36
41
|
}
|
|
37
42
|
|
|
38
43
|
public setFormConfig(type: string, config: FormConfig) {
|
|
39
44
|
this.get('configs')[type] = config;
|
|
40
45
|
}
|
|
41
46
|
|
|
47
|
+
public getFormValue(type = 'base') {
|
|
48
|
+
return this.get('values')[type];
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
public setFormValue(type: string, value: Partial<DataSourceSchema>) {
|
|
52
|
+
this.get('values')[type] = value;
|
|
53
|
+
}
|
|
54
|
+
|
|
42
55
|
public add(config: DataSourceSchema) {
|
|
43
56
|
const newConfig = {
|
|
44
57
|
...config,
|
package/src/services/editor.ts
CHANGED
|
@@ -705,9 +705,9 @@ class Editor extends BaseService {
|
|
|
705
705
|
brothers.splice(index, 1);
|
|
706
706
|
|
|
707
707
|
if (offset === LayerOffset.TOP) {
|
|
708
|
-
brothers.splice(isRelative ? 0 : brothers.length
|
|
708
|
+
brothers.splice(isRelative ? 0 : brothers.length, 0, node);
|
|
709
709
|
} else if (offset === LayerOffset.BOTTOM) {
|
|
710
|
-
brothers.splice(isRelative ? brothers.length
|
|
710
|
+
brothers.splice(isRelative ? brothers.length : 0, 0, node);
|
|
711
711
|
} else {
|
|
712
712
|
brothers.splice(index + (isRelative ? -offset : offset), 0, node);
|
|
713
713
|
}
|
package/src/services/props.ts
CHANGED
|
@@ -80,7 +80,7 @@ class Props extends BaseService {
|
|
|
80
80
|
return cloneDeep(this.state.propsConfigMap[type] || (await this.fillConfig([])));
|
|
81
81
|
}
|
|
82
82
|
|
|
83
|
-
public setPropsValues(values: Record<string, MNode
|
|
83
|
+
public setPropsValues(values: Record<string, Partial<MNode>>) {
|
|
84
84
|
Object.keys(values).forEach((type: string) => {
|
|
85
85
|
this.setPropsValue(toLine(type), values[type]);
|
|
86
86
|
});
|
|
@@ -91,7 +91,7 @@ class Props extends BaseService {
|
|
|
91
91
|
* @param type 组件类型
|
|
92
92
|
* @param value 组件初始值
|
|
93
93
|
*/
|
|
94
|
-
public async setPropsValue(type: string, value: MNode) {
|
|
94
|
+
public async setPropsValue(type: string, value: Partial<MNode>) {
|
|
95
95
|
this.state.propsValueMap[type] = value;
|
|
96
96
|
}
|
|
97
97
|
|
package/src/type.ts
CHANGED
|
@@ -93,7 +93,7 @@ export type StoreStateKey = keyof StoreState;
|
|
|
93
93
|
|
|
94
94
|
export interface PropsState {
|
|
95
95
|
propsConfigMap: Record<string, FormConfig>;
|
|
96
|
-
propsValueMap: Record<string, MNode
|
|
96
|
+
propsValueMap: Record<string, Partial<MNode>>;
|
|
97
97
|
}
|
|
98
98
|
|
|
99
99
|
export interface ComponentGroupState {
|
|
@@ -520,3 +520,8 @@ export enum DepTargetType {
|
|
|
520
520
|
/** 数据源条件 */
|
|
521
521
|
DATA_SOURCE_COND = 'data-source-cond',
|
|
522
522
|
}
|
|
523
|
+
|
|
524
|
+
export interface DatasourceTypeOption {
|
|
525
|
+
type: string;
|
|
526
|
+
text: string;
|
|
527
|
+
}
|
|
@@ -1,32 +1,37 @@
|
|
|
1
1
|
import type { FormConfig } from '@tmagic/form';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
3
|
+
import type { DatasourceTypeOption } from '@editor/type';
|
|
4
|
+
|
|
5
|
+
export default function (datasourceTypeList: DatasourceTypeOption[] = []): FormConfig {
|
|
6
|
+
return [
|
|
7
|
+
{
|
|
8
|
+
name: 'id',
|
|
9
|
+
type: 'hidden',
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
name: 'type',
|
|
13
|
+
text: '类型',
|
|
14
|
+
type: 'select',
|
|
15
|
+
options: [
|
|
16
|
+
{ text: '基础', value: 'base' },
|
|
17
|
+
{ text: 'HTTP', value: 'http' },
|
|
18
|
+
...datasourceTypeList.map((item) => ({ text: item.text, value: item.type })),
|
|
19
|
+
],
|
|
20
|
+
defaultValue: 'base',
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
name: 'title',
|
|
24
|
+
text: '名称',
|
|
25
|
+
rules: [
|
|
26
|
+
{
|
|
27
|
+
required: true,
|
|
28
|
+
message: '请输入名称',
|
|
29
|
+
},
|
|
30
|
+
],
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
name: 'description',
|
|
34
|
+
text: '描述',
|
|
35
|
+
},
|
|
36
|
+
];
|
|
37
|
+
}
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import { FormConfig } from '@tmagic/form';
|
|
2
|
+
import { DataSchema, DataSourceSchema } from '@tmagic/schema';
|
|
3
|
+
|
|
4
|
+
import { DatasourceTypeOption } from '@editor/type';
|
|
2
5
|
|
|
3
6
|
import BaseFormConfig from './formConfigs/base';
|
|
4
7
|
import HttpFormConfig from './formConfigs/http';
|
|
5
8
|
|
|
6
|
-
const fillConfig = (config: FormConfig): FormConfig => [
|
|
7
|
-
...BaseFormConfig,
|
|
9
|
+
const fillConfig = (config: FormConfig, datasourceTypeList: DatasourceTypeOption[]): FormConfig => [
|
|
10
|
+
...BaseFormConfig(datasourceTypeList),
|
|
8
11
|
...config,
|
|
9
12
|
{
|
|
10
13
|
type: 'panel',
|
|
@@ -30,13 +33,68 @@ const fillConfig = (config: FormConfig): FormConfig => [
|
|
|
30
33
|
},
|
|
31
34
|
];
|
|
32
35
|
|
|
33
|
-
export const getFormConfig = (
|
|
36
|
+
export const getFormConfig = (
|
|
37
|
+
type: string,
|
|
38
|
+
datasourceTypeList: DatasourceTypeOption[],
|
|
39
|
+
configs: Record<string, FormConfig>,
|
|
40
|
+
): FormConfig => {
|
|
34
41
|
switch (type) {
|
|
35
42
|
case 'base':
|
|
36
|
-
return fillConfig([]);
|
|
43
|
+
return fillConfig([], datasourceTypeList);
|
|
37
44
|
case 'http':
|
|
38
|
-
return fillConfig(HttpFormConfig);
|
|
45
|
+
return fillConfig(HttpFormConfig, datasourceTypeList);
|
|
39
46
|
default:
|
|
40
|
-
return fillConfig(configs[type] || []);
|
|
47
|
+
return fillConfig(configs[type] || [], datasourceTypeList);
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
export const getDisplayField = (dataSources: DataSourceSchema[], key: string) => {
|
|
52
|
+
const displayState: { value: string; type: 'var' | 'text' }[] = [];
|
|
53
|
+
|
|
54
|
+
// 匹配es6字符串模块
|
|
55
|
+
const matches = key.matchAll(/\$\{([\s\S]+?)\}/g);
|
|
56
|
+
let index = 0;
|
|
57
|
+
for (const match of matches) {
|
|
58
|
+
if (typeof match.index === 'undefined') break;
|
|
59
|
+
|
|
60
|
+
// 字符串常量
|
|
61
|
+
displayState.push({
|
|
62
|
+
type: 'text',
|
|
63
|
+
value: key.substring(index, match.index),
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
let dsText = '';
|
|
67
|
+
let ds: DataSourceSchema | undefined;
|
|
68
|
+
let fields: DataSchema[] | undefined;
|
|
69
|
+
|
|
70
|
+
// 将模块解析成数据源对应的值
|
|
71
|
+
match[1].split('.').forEach((item, index) => {
|
|
72
|
+
if (index === 0) {
|
|
73
|
+
ds = dataSources.find((ds) => ds.id === item);
|
|
74
|
+
dsText += ds?.title || item;
|
|
75
|
+
fields = ds?.fields;
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const field = fields?.find((field) => field.name === item);
|
|
80
|
+
fields = field?.fields;
|
|
81
|
+
dsText += `.${field?.title || item}`;
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
displayState.push({
|
|
85
|
+
type: 'var',
|
|
86
|
+
value: dsText,
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
index = match.index + match[0].length;
|
|
41
90
|
}
|
|
91
|
+
|
|
92
|
+
if (index < key.length) {
|
|
93
|
+
displayState.push({
|
|
94
|
+
type: 'text',
|
|
95
|
+
value: key.substring(index),
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
return displayState;
|
|
42
100
|
};
|
package/src/utils/index.ts
CHANGED
package/src/utils/undo-redo.ts
CHANGED
package/types/Editor.vue.d.ts
CHANGED
|
@@ -9,6 +9,10 @@ declare const _default: import("vue").DefineComponent<{
|
|
|
9
9
|
type: import("vue").PropType<import("./type").ComponentGroup[]>;
|
|
10
10
|
default: () => never[];
|
|
11
11
|
};
|
|
12
|
+
datasourceList: {
|
|
13
|
+
type: import("vue").PropType<import("./type").DatasourceTypeOption[]>;
|
|
14
|
+
default: () => never[];
|
|
15
|
+
};
|
|
12
16
|
sidebar: {
|
|
13
17
|
type: import("vue").PropType<import("./type").SideBarData>;
|
|
14
18
|
};
|
|
@@ -37,7 +41,7 @@ declare const _default: import("vue").DefineComponent<{
|
|
|
37
41
|
default: () => {};
|
|
38
42
|
};
|
|
39
43
|
propsValues: {
|
|
40
|
-
type: import("vue").PropType<Record<string, import("@tmagic/schema").MNode
|
|
44
|
+
type: import("vue").PropType<Record<string, Partial<import("@tmagic/schema").MNode>>>;
|
|
41
45
|
default: () => {};
|
|
42
46
|
};
|
|
43
47
|
eventMethodList: {
|
|
@@ -47,6 +51,14 @@ declare const _default: import("vue").DefineComponent<{
|
|
|
47
51
|
}>>;
|
|
48
52
|
default: () => {};
|
|
49
53
|
};
|
|
54
|
+
datasourceConfigs: {
|
|
55
|
+
type: import("vue").PropType<Record<string, import("@tmagic/form").FormConfig>>;
|
|
56
|
+
default: () => {};
|
|
57
|
+
};
|
|
58
|
+
datasourceValues: {
|
|
59
|
+
type: import("vue").PropType<Record<string, Partial<import("@tmagic/schema").DataSourceSchema>>>;
|
|
60
|
+
default: () => {};
|
|
61
|
+
};
|
|
50
62
|
dataScourceConfigs: {
|
|
51
63
|
type: import("vue").PropType<Record<string, import("@tmagic/form").FormConfig>>;
|
|
52
64
|
default: () => {};
|
|
@@ -103,6 +115,10 @@ declare const _default: import("vue").DefineComponent<{
|
|
|
103
115
|
type: import("vue").PropType<import("./type").ComponentGroup[]>;
|
|
104
116
|
default: () => never[];
|
|
105
117
|
};
|
|
118
|
+
datasourceList: {
|
|
119
|
+
type: import("vue").PropType<import("./type").DatasourceTypeOption[]>;
|
|
120
|
+
default: () => never[];
|
|
121
|
+
};
|
|
106
122
|
sidebar: {
|
|
107
123
|
type: import("vue").PropType<import("./type").SideBarData>;
|
|
108
124
|
};
|
|
@@ -131,7 +147,7 @@ declare const _default: import("vue").DefineComponent<{
|
|
|
131
147
|
default: () => {};
|
|
132
148
|
};
|
|
133
149
|
propsValues: {
|
|
134
|
-
type: import("vue").PropType<Record<string, import("@tmagic/schema").MNode
|
|
150
|
+
type: import("vue").PropType<Record<string, Partial<import("@tmagic/schema").MNode>>>;
|
|
135
151
|
default: () => {};
|
|
136
152
|
};
|
|
137
153
|
eventMethodList: {
|
|
@@ -141,6 +157,14 @@ declare const _default: import("vue").DefineComponent<{
|
|
|
141
157
|
}>>;
|
|
142
158
|
default: () => {};
|
|
143
159
|
};
|
|
160
|
+
datasourceConfigs: {
|
|
161
|
+
type: import("vue").PropType<Record<string, import("@tmagic/form").FormConfig>>;
|
|
162
|
+
default: () => {};
|
|
163
|
+
};
|
|
164
|
+
datasourceValues: {
|
|
165
|
+
type: import("vue").PropType<Record<string, Partial<import("@tmagic/schema").DataSourceSchema>>>;
|
|
166
|
+
default: () => {};
|
|
167
|
+
};
|
|
144
168
|
dataScourceConfigs: {
|
|
145
169
|
type: import("vue").PropType<Record<string, import("@tmagic/form").FormConfig>>;
|
|
146
170
|
default: () => {};
|
|
@@ -198,12 +222,15 @@ declare const _default: import("vue").DefineComponent<{
|
|
|
198
222
|
layerContentMenu: (import("./type").MenuButton | import("./type").MenuComponent)[];
|
|
199
223
|
stageContentMenu: (import("./type").MenuButton | import("./type").MenuComponent)[];
|
|
200
224
|
componentGroupList: import("./type").ComponentGroup[];
|
|
225
|
+
datasourceList: import("./type").DatasourceTypeOption[];
|
|
201
226
|
propsConfigs: Record<string, import("@tmagic/form").FormConfig>;
|
|
202
|
-
propsValues: Record<string, import("@tmagic/schema").MNode
|
|
227
|
+
propsValues: Record<string, Partial<import("@tmagic/schema").MNode>>;
|
|
203
228
|
eventMethodList: Record<string, {
|
|
204
229
|
events: import("@tmagic/core").EventOption[];
|
|
205
230
|
methods: import("@tmagic/core").EventOption[];
|
|
206
231
|
}>;
|
|
232
|
+
datasourceConfigs: Record<string, import("@tmagic/form").FormConfig>;
|
|
233
|
+
datasourceValues: Record<string, Partial<import("@tmagic/schema").DataSourceSchema>>;
|
|
207
234
|
dataScourceConfigs: Record<string, import("@tmagic/form").FormConfig>;
|
|
208
235
|
canSelect: (el: HTMLElement) => boolean | Promise<boolean>;
|
|
209
236
|
isContainer: (el: HTMLElement) => boolean | Promise<boolean>;
|