@tmagic/editor 1.3.0-alpha.13 → 1.3.0-alpha.14
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/style.css +41 -113
- package/dist/tmagic-editor.js +1307 -1197
- package/dist/tmagic-editor.js.map +1 -1
- package/dist/tmagic-editor.umd.cjs +1318 -1204
- package/dist/tmagic-editor.umd.cjs.map +1 -1
- package/package.json +11 -11
- package/src/Editor.vue +0 -4
- package/src/components/CodeBlockEditor.vue +155 -0
- package/src/components/CodeParams.vue +59 -0
- package/src/fields/Code.vue +27 -19
- package/src/fields/CodeSelect.vue +7 -1
- package/src/fields/CodeSelectCol.vue +65 -74
- package/src/fields/DataSourceFields.vue +7 -9
- package/src/fields/DataSourceMethodSelect.vue +147 -0
- package/src/fields/DataSourceMethods.vue +103 -0
- package/src/fields/EventSelect.vue +33 -7
- package/src/icons/CodeIcon.vue +0 -2
- package/src/index.ts +8 -0
- package/src/layouts/CodeEditor.vue +32 -1
- package/src/layouts/Framework.vue +7 -3
- package/src/layouts/sidebar/Sidebar.vue +2 -10
- package/src/layouts/sidebar/code-block/CodeBlockList.vue +73 -124
- package/src/layouts/sidebar/code-block/CodeBlockListPanel.vue +64 -0
- package/src/layouts/sidebar/data-source/DataSourceConfigPanel.vue +23 -33
- package/src/layouts/sidebar/data-source/DataSourceList.vue +111 -0
- package/src/layouts/sidebar/data-source/DataSourceListPanel.vue +13 -81
- package/src/services/codeBlock.ts +17 -70
- package/src/services/dataSource.ts +2 -0
- package/src/theme/code-block.scss +0 -122
- package/src/theme/code-editor.scss +27 -2
- package/src/theme/data-source-methods.scss +13 -0
- package/src/theme/event.scss +15 -12
- package/src/theme/theme.scss +1 -0
- package/src/type.ts +21 -6
- package/src/utils/data-source/index.ts +11 -0
- package/src/utils/use-code-block-edit.ts +84 -0
- package/src/utils/use-data-source-method.ts +101 -0
- package/types/components/CodeBlockEditor.vue.d.ts +21 -0
- package/types/components/CodeParams.vue.d.ts +26 -0
- package/types/components/ContentMenu.vue.d.ts +2 -2
- package/types/fields/Code.vue.d.ts +26 -6
- package/types/fields/CodeSelectCol.vue.d.ts +16 -5
- package/types/fields/DataSourceFields.vue.d.ts +2 -0
- package/types/fields/DataSourceMethodSelect.vue.d.ts +44 -0
- package/types/fields/DataSourceMethods.vue.d.ts +45 -0
- package/types/index.d.ts +4 -0
- package/types/layouts/CodeEditor.vue.d.ts +2 -0
- package/types/layouts/PropsPanel.vue.d.ts +8 -8
- package/types/layouts/sidebar/Sidebar.vue.d.ts +0 -3
- package/types/layouts/sidebar/code-block/CodeBlockList.vue.d.ts +4 -9
- package/types/layouts/sidebar/code-block/{CodeBlockEditor.vue.d.ts → CodeBlockListPanel.vue.d.ts} +5 -6
- package/types/layouts/sidebar/data-source/DataSourceConfigPanel.vue.d.ts +3 -1
- package/types/layouts/sidebar/data-source/DataSourceList.vue.d.ts +14 -0
- package/types/layouts/sidebar/data-source/DataSourceListPanel.vue.d.ts +1 -11
- package/types/services/codeBlock.d.ts +5 -36
- package/types/services/dataSource.d.ts +1 -0
- package/types/type.d.ts +19 -6
- package/types/{components/FunctionEditor.vue.d.ts → utils/use-code-block-edit.d.ts} +26 -123
- package/types/utils/use-data-source-method.d.ts +116 -0
- package/src/components/CodeDraftEditor.vue +0 -148
- package/src/components/FunctionEditor.vue +0 -197
- package/src/layouts/sidebar/code-block/CodeBlockEditor.vue +0 -100
- package/types/components/CodeDraftEditor.vue.d.ts +0 -61
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div class="m-fields-data-source-method-select">
|
|
3
|
+
<div class="data-source-method-select-container">
|
|
4
|
+
<m-form-container
|
|
5
|
+
class="select"
|
|
6
|
+
:config="cascaderConfig"
|
|
7
|
+
:model="model"
|
|
8
|
+
@change="onChangeHandler"
|
|
9
|
+
></m-form-container>
|
|
10
|
+
<Icon v-if="model[name]" class="icon" :icon="!disabled ? Edit : View" @click="editCodeHandler"></Icon>
|
|
11
|
+
</div>
|
|
12
|
+
|
|
13
|
+
<CodeParams
|
|
14
|
+
v-if="paramsConfig.length"
|
|
15
|
+
name="params"
|
|
16
|
+
:model="model"
|
|
17
|
+
:size="size"
|
|
18
|
+
:disabled="disabled"
|
|
19
|
+
:params-config="paramsConfig"
|
|
20
|
+
@change="onChangeHandler"
|
|
21
|
+
></CodeParams>
|
|
22
|
+
|
|
23
|
+
<CodeBlockEditor
|
|
24
|
+
ref="codeBlockEditor"
|
|
25
|
+
v-if="codeConfig"
|
|
26
|
+
:disabled="disabled"
|
|
27
|
+
:content="codeConfig"
|
|
28
|
+
@submit="submitCodeBlockHandler"
|
|
29
|
+
></CodeBlockEditor>
|
|
30
|
+
</div>
|
|
31
|
+
</template>
|
|
32
|
+
|
|
33
|
+
<script lang="ts" setup name="">
|
|
34
|
+
import { computed, inject, ref } from 'vue';
|
|
35
|
+
import { Edit, View } from '@element-plus/icons-vue';
|
|
36
|
+
|
|
37
|
+
import { createValues } from '@tmagic/form';
|
|
38
|
+
import type { CodeBlockContent, Id } from '@tmagic/schema';
|
|
39
|
+
|
|
40
|
+
import CodeBlockEditor from '@editor/components/CodeBlockEditor.vue';
|
|
41
|
+
import CodeParams from '@editor/components/CodeParams.vue';
|
|
42
|
+
import Icon from '@editor/components/Icon.vue';
|
|
43
|
+
import type { CodeParamStatement, DataSourceMethodSelectConfig, Services } from '@editor/type';
|
|
44
|
+
import { useDataSourceMethod } from '@editor/utils/use-data-source-method';
|
|
45
|
+
|
|
46
|
+
defineOptions({
|
|
47
|
+
name: 'MEditorDataSourceMethodSelect',
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
const services = inject<Services>('services');
|
|
51
|
+
const emit = defineEmits(['change']);
|
|
52
|
+
|
|
53
|
+
const props = withDefaults(
|
|
54
|
+
defineProps<{
|
|
55
|
+
config: DataSourceMethodSelectConfig;
|
|
56
|
+
model: any;
|
|
57
|
+
lastValues?: any;
|
|
58
|
+
prop: string;
|
|
59
|
+
name: string;
|
|
60
|
+
disabled?: boolean;
|
|
61
|
+
size: 'small' | 'default' | 'large';
|
|
62
|
+
}>(),
|
|
63
|
+
{
|
|
64
|
+
disabled: false,
|
|
65
|
+
},
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
const dataSources = computed(() => services?.dataSourceService.get('dataSources'));
|
|
69
|
+
|
|
70
|
+
const getParamItemsConfig = ([dataSourceId, medthodName]: [Id, string] = ['', '']): CodeParamStatement[] => {
|
|
71
|
+
if (!dataSourceId) return [];
|
|
72
|
+
|
|
73
|
+
const paramStatements = dataSources.value
|
|
74
|
+
?.find((item) => item.id === dataSourceId)
|
|
75
|
+
?.methods?.find((item) => item.name === medthodName)?.params;
|
|
76
|
+
|
|
77
|
+
if (!paramStatements) return [];
|
|
78
|
+
|
|
79
|
+
return paramStatements.map((paramState: CodeParamStatement) => ({
|
|
80
|
+
labelWidth: '100px',
|
|
81
|
+
text: paramState.name,
|
|
82
|
+
...paramState,
|
|
83
|
+
}));
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
const paramsConfig = ref<CodeParamStatement[]>(getParamItemsConfig(props.model.dataSourceMethod));
|
|
87
|
+
|
|
88
|
+
const setParamsConfig = (dataSourceMethod: [Id, string], formState: any = {}) => {
|
|
89
|
+
// 通过下拉框选择的codeId变化后修正model的值,避免写入其他codeId的params
|
|
90
|
+
paramsConfig.value = dataSourceMethod ? getParamItemsConfig(dataSourceMethod) : [];
|
|
91
|
+
|
|
92
|
+
if (paramsConfig.value.length) {
|
|
93
|
+
props.model.params = createValues(formState, paramsConfig.value, {}, props.model.params);
|
|
94
|
+
} else {
|
|
95
|
+
props.model.params = {};
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
const cascaderConfig = {
|
|
100
|
+
type: 'cascader',
|
|
101
|
+
text: '数据源方法',
|
|
102
|
+
name: props.name,
|
|
103
|
+
labelWidth: '80px',
|
|
104
|
+
options: () =>
|
|
105
|
+
dataSources.value
|
|
106
|
+
?.filter((ds) => ds.methods?.length)
|
|
107
|
+
?.map((ds) => ({
|
|
108
|
+
label: `${ds.title}(${ds.id})`,
|
|
109
|
+
value: ds.id,
|
|
110
|
+
children: ds.methods?.map((method) => ({
|
|
111
|
+
label: method.name,
|
|
112
|
+
value: method.name,
|
|
113
|
+
})),
|
|
114
|
+
})) || [],
|
|
115
|
+
onChange: (formState: any, dataSourceMethod: [Id, string]) => {
|
|
116
|
+
setParamsConfig(dataSourceMethod, formState);
|
|
117
|
+
|
|
118
|
+
return dataSourceMethod;
|
|
119
|
+
},
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* 参数值修改更新
|
|
124
|
+
*/
|
|
125
|
+
const onChangeHandler = (value: any) => {
|
|
126
|
+
props.model.params = value.params;
|
|
127
|
+
emit('change', props.model);
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
const { codeBlockEditor, codeConfig, editCode, submitCode } = useDataSourceMethod();
|
|
131
|
+
|
|
132
|
+
const editCodeHandler = () => {
|
|
133
|
+
const [id, name] = props.model[props.name];
|
|
134
|
+
|
|
135
|
+
const dataSource = services?.dataSourceService.getDataSourceById(id);
|
|
136
|
+
|
|
137
|
+
if (!dataSource) return;
|
|
138
|
+
|
|
139
|
+
editCode(dataSource, name);
|
|
140
|
+
|
|
141
|
+
setParamsConfig([id, name]);
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
const submitCodeBlockHandler = (value: CodeBlockContent) => {
|
|
145
|
+
submitCode(value);
|
|
146
|
+
};
|
|
147
|
+
</script>
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div class="m-editor-data-source-methods">
|
|
3
|
+
<MagicTable :data="model[name]" :columns="methodColumns"></MagicTable>
|
|
4
|
+
|
|
5
|
+
<div class="m-editor-data-source-methods-footer">
|
|
6
|
+
<TMagicButton size="small" type="primary" :disabled="disabled" plain @click="createCodeHandler"
|
|
7
|
+
>添加</TMagicButton
|
|
8
|
+
>
|
|
9
|
+
</div>
|
|
10
|
+
|
|
11
|
+
<CodeBlockEditor
|
|
12
|
+
ref="codeBlockEditor"
|
|
13
|
+
v-if="codeConfig"
|
|
14
|
+
:disabled="disabled"
|
|
15
|
+
:content="codeConfig"
|
|
16
|
+
@submit="submitCodeHandler"
|
|
17
|
+
></CodeBlockEditor>
|
|
18
|
+
</div>
|
|
19
|
+
</template>
|
|
20
|
+
|
|
21
|
+
<script setup lang="ts">
|
|
22
|
+
import { TMagicButton } from '@tmagic/design';
|
|
23
|
+
import type { CodeBlockContent } from '@tmagic/schema';
|
|
24
|
+
import { MagicTable } from '@tmagic/table';
|
|
25
|
+
|
|
26
|
+
import CodeBlockEditor from '@editor/components/CodeBlockEditor.vue';
|
|
27
|
+
import { useDataSourceMethod } from '@editor/utils/use-data-source-method';
|
|
28
|
+
|
|
29
|
+
import { CodeParamStatement } from '..';
|
|
30
|
+
|
|
31
|
+
defineOptions({
|
|
32
|
+
name: 'MEditorDataSourceMethods',
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
const props = withDefaults(
|
|
36
|
+
defineProps<{
|
|
37
|
+
config: {
|
|
38
|
+
type: 'data-source-methods';
|
|
39
|
+
};
|
|
40
|
+
model: any;
|
|
41
|
+
prop: string;
|
|
42
|
+
lastValues?: any;
|
|
43
|
+
disabled: boolean;
|
|
44
|
+
name: string;
|
|
45
|
+
}>(),
|
|
46
|
+
{
|
|
47
|
+
disabled: false,
|
|
48
|
+
},
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
const emit = defineEmits(['change']);
|
|
52
|
+
|
|
53
|
+
const { codeConfig, codeBlockEditor, createCode, editCode, deleteCode, submitCode } = useDataSourceMethod();
|
|
54
|
+
|
|
55
|
+
const methodColumns = [
|
|
56
|
+
{
|
|
57
|
+
label: '名称',
|
|
58
|
+
prop: 'name',
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
label: '注释',
|
|
62
|
+
prop: 'desc',
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
label: '参数',
|
|
66
|
+
prop: 'params',
|
|
67
|
+
formatter: (params: CodeParamStatement[]) => params.map((item) => item.name).join(', '),
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
label: '操作',
|
|
71
|
+
fixed: 'right',
|
|
72
|
+
actions: [
|
|
73
|
+
{
|
|
74
|
+
text: '编辑',
|
|
75
|
+
handler: (row: CodeBlockContent) => {
|
|
76
|
+
editCode(props.model, row.name);
|
|
77
|
+
emit('change', props.model[props.name]);
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
text: '删除',
|
|
82
|
+
buttonType: 'danger',
|
|
83
|
+
handler: (row: CodeBlockContent) => {
|
|
84
|
+
deleteCode(props.model, row.name);
|
|
85
|
+
emit('change', props.model[props.name]);
|
|
86
|
+
},
|
|
87
|
+
},
|
|
88
|
+
],
|
|
89
|
+
},
|
|
90
|
+
];
|
|
91
|
+
|
|
92
|
+
const createCodeHandler = () => {
|
|
93
|
+
createCode(props.model);
|
|
94
|
+
|
|
95
|
+
emit('change', props.model[props.name]);
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
const submitCodeHandler = (values: CodeBlockContent) => {
|
|
99
|
+
submitCode(values);
|
|
100
|
+
|
|
101
|
+
emit('change', props.model[props.name]);
|
|
102
|
+
};
|
|
103
|
+
</script>
|
|
@@ -42,7 +42,7 @@ import { TMagicButton } from '@tmagic/design';
|
|
|
42
42
|
import { FormState } from '@tmagic/form';
|
|
43
43
|
import { ActionType } from '@tmagic/schema';
|
|
44
44
|
|
|
45
|
-
import type { EventSelectConfig, Services } from '@editor/type';
|
|
45
|
+
import type { CodeSelectColConfig, DataSourceMethodSelectConfig, EventSelectConfig, Services } from '@editor/type';
|
|
46
46
|
|
|
47
47
|
defineOptions({
|
|
48
48
|
name: 'MEditorEventSelect',
|
|
@@ -81,7 +81,7 @@ const actionTypeConfig = computed(() => {
|
|
|
81
81
|
const defaultActionTypeConfig = {
|
|
82
82
|
name: 'actionType',
|
|
83
83
|
text: '联动类型',
|
|
84
|
-
labelWidth: '
|
|
84
|
+
labelWidth: '80px',
|
|
85
85
|
type: 'select',
|
|
86
86
|
defaultValue: ActionType.COMP,
|
|
87
87
|
options: () => [
|
|
@@ -93,8 +93,15 @@ const actionTypeConfig = computed(() => {
|
|
|
93
93
|
{
|
|
94
94
|
text: '代码',
|
|
95
95
|
label: '代码',
|
|
96
|
+
disabled: !Object.keys(services?.codeBlockService.getCodeDsl() || {}).length,
|
|
96
97
|
value: ActionType.CODE,
|
|
97
98
|
},
|
|
99
|
+
{
|
|
100
|
+
text: '数据源',
|
|
101
|
+
label: '数据源',
|
|
102
|
+
disabled: !services?.dataSourceService.get('dataSources')?.filter((ds) => ds.methods?.length).length,
|
|
103
|
+
value: ActionType.DATA_SOURCE,
|
|
104
|
+
},
|
|
98
105
|
],
|
|
99
106
|
};
|
|
100
107
|
return { ...defaultActionTypeConfig, ...props.config.actionTypeConfig };
|
|
@@ -105,7 +112,7 @@ const targetCompConfig = computed(() => {
|
|
|
105
112
|
const defaultTargetCompConfig = {
|
|
106
113
|
name: 'to',
|
|
107
114
|
text: '联动组件',
|
|
108
|
-
labelWidth: '
|
|
115
|
+
labelWidth: '80px',
|
|
109
116
|
type: 'ui-select',
|
|
110
117
|
display: (mForm: FormState, { model }: { model: Record<any, any> }) => model.actionType === ActionType.COMP,
|
|
111
118
|
};
|
|
@@ -117,7 +124,7 @@ const compActionConfig = computed(() => {
|
|
|
117
124
|
const defaultCompActionConfig = {
|
|
118
125
|
name: 'method',
|
|
119
126
|
text: '动作',
|
|
120
|
-
labelWidth: '
|
|
127
|
+
labelWidth: '80px',
|
|
121
128
|
type: 'select',
|
|
122
129
|
display: (mForm: FormState, { model }: { model: Record<any, any> }) => model.actionType === ActionType.COMP,
|
|
123
130
|
options: (mForm: FormState, { model }: any) => {
|
|
@@ -135,14 +142,27 @@ const compActionConfig = computed(() => {
|
|
|
135
142
|
|
|
136
143
|
// 代码联动配置
|
|
137
144
|
const codeActionConfig = computed(() => {
|
|
138
|
-
const defaultCodeActionConfig = {
|
|
145
|
+
const defaultCodeActionConfig: CodeSelectColConfig = {
|
|
139
146
|
type: 'code-select-col',
|
|
140
147
|
labelWidth: 0,
|
|
141
|
-
|
|
148
|
+
name: 'codeId',
|
|
149
|
+
disabled: () => !services?.codeBlockService.getEditStatus(),
|
|
150
|
+
display: (mForm, { model }) => model.actionType === ActionType.CODE,
|
|
142
151
|
};
|
|
143
152
|
return { ...defaultCodeActionConfig, ...props.config.codeActionConfig };
|
|
144
153
|
});
|
|
145
154
|
|
|
155
|
+
// 数据源联动配置
|
|
156
|
+
const dataSourceActionConfig = computed(() => {
|
|
157
|
+
const defaultDataSourceActionConfig: DataSourceMethodSelectConfig = {
|
|
158
|
+
type: 'data-source-method-select',
|
|
159
|
+
name: 'dataSourceMethod',
|
|
160
|
+
labelWidth: 0,
|
|
161
|
+
display: (mForm, { model }) => model.actionType === ActionType.DATA_SOURCE,
|
|
162
|
+
};
|
|
163
|
+
return { ...defaultDataSourceActionConfig, ...props.config.dataSourceActionConfig };
|
|
164
|
+
});
|
|
165
|
+
|
|
146
166
|
// 兼容旧的数据格式
|
|
147
167
|
const tableConfig = computed(() => ({
|
|
148
168
|
type: 'table',
|
|
@@ -188,7 +208,13 @@ const actionsConfig = computed(() => ({
|
|
|
188
208
|
name: 'actions',
|
|
189
209
|
expandAll: true,
|
|
190
210
|
enableToggleMode: false,
|
|
191
|
-
items: [
|
|
211
|
+
items: [
|
|
212
|
+
actionTypeConfig.value,
|
|
213
|
+
targetCompConfig.value,
|
|
214
|
+
compActionConfig.value,
|
|
215
|
+
codeActionConfig.value,
|
|
216
|
+
dataSourceActionConfig.value,
|
|
217
|
+
],
|
|
192
218
|
},
|
|
193
219
|
],
|
|
194
220
|
}));
|
package/src/icons/CodeIcon.vue
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<!-- 代码icon,cdn链接:https://cloudcache.tencent-cloud.com/qcloud/ui/static/government/0d463ed5-6407-4498-8865-3d05b5e70115.svg -->
|
|
3
2
|
<svg viewBox="0 0 32 32" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
|
|
4
|
-
<!-- Generator: Sketch 60.1 (88133) - https://sketch.com -->
|
|
5
3
|
<defs><rect id="path-1" x="0" y="0" width="32" height="32"></rect></defs>
|
|
6
4
|
<g id="组件规范" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
|
|
7
5
|
<g id="03图标" transform="translate(-561.000000, -2356.000000)">
|
package/src/index.ts
CHANGED
|
@@ -23,6 +23,8 @@ import CodeSelect from './fields/CodeSelect.vue';
|
|
|
23
23
|
import CodeSelectCol from './fields/CodeSelectCol.vue';
|
|
24
24
|
import DataSourceFields from './fields/DataSourceFields.vue';
|
|
25
25
|
import DataSourceInput from './fields/DataSourceInput.vue';
|
|
26
|
+
import DataSourceMethods from './fields/DataSourceMethods.vue';
|
|
27
|
+
import DataSourceMethodSelect from './fields/DataSourceMethodSelect.vue';
|
|
26
28
|
import DataSourceSelect from './fields/DataSourceSelect.vue';
|
|
27
29
|
import EventSelect from './fields/EventSelect.vue';
|
|
28
30
|
import KeyValue from './fields/KeyValue.vue';
|
|
@@ -53,11 +55,14 @@ export { default as LayerPanel } from './layouts/sidebar/LayerPanel.vue';
|
|
|
53
55
|
export { default as CodeSelect } from './fields/CodeSelect.vue';
|
|
54
56
|
export { default as CodeSelectCol } from './fields/CodeSelectCol.vue';
|
|
55
57
|
export { default as DataSourceFields } from './fields/DataSourceFields.vue';
|
|
58
|
+
export { default as DataSourceMethods } from './fields/DataSourceMethods.vue';
|
|
56
59
|
export { default as DataSourceInput } from './fields/DataSourceInput.vue';
|
|
57
60
|
export { default as DataSourceSelect } from './fields/DataSourceSelect.vue';
|
|
61
|
+
export { default as DataSourceMethodSelect } from './fields/DataSourceMethodSelect.vue';
|
|
58
62
|
export { default as EventSelect } from './fields/EventSelect.vue';
|
|
59
63
|
export { default as KeyValue } from './fields/KeyValue.vue';
|
|
60
64
|
export { default as CodeBlockList } from './layouts/sidebar/code-block/CodeBlockList.vue';
|
|
65
|
+
export { default as CodeBlockListPanel } from './layouts/sidebar/code-block/CodeBlockListPanel.vue';
|
|
61
66
|
export { default as PropsPanel } from './layouts/PropsPanel.vue';
|
|
62
67
|
export { default as ToolButton } from './components/ToolButton.vue';
|
|
63
68
|
export { default as ContentMenu } from './components/ContentMenu.vue';
|
|
@@ -65,6 +70,7 @@ export { default as Icon } from './components/Icon.vue';
|
|
|
65
70
|
export { default as LayoutContainer } from './components/SplitView.vue';
|
|
66
71
|
export { default as SplitView } from './components/SplitView.vue';
|
|
67
72
|
export { default as Resizer } from './components/Resizer.vue';
|
|
73
|
+
export { default as CodeBlockEditor } from './components/CodeBlockEditor.vue';
|
|
68
74
|
|
|
69
75
|
const defaultInstallOpt: InstallOptions = {
|
|
70
76
|
// eslint-disable-next-line no-eval
|
|
@@ -90,5 +96,7 @@ export default {
|
|
|
90
96
|
app.component('m-fields-key-value', KeyValue);
|
|
91
97
|
app.component('m-fields-data-source-input', DataSourceInput);
|
|
92
98
|
app.component('m-fields-data-source-select', DataSourceSelect);
|
|
99
|
+
app.component('m-fields-data-source-methods', DataSourceMethods);
|
|
100
|
+
app.component('m-fields-data-source-method-select', DataSourceMethodSelect);
|
|
93
101
|
},
|
|
94
102
|
};
|
|
@@ -1,13 +1,32 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<div
|
|
2
|
+
<div :class="`magic-code-editor`">
|
|
3
|
+
<Teleport to="body" :disabled="!fullScreen">
|
|
4
|
+
<div
|
|
5
|
+
:class="`magic-code-editor-wrapper${fullScreen ? ' full-screen' : ''}`"
|
|
6
|
+
:style="!fullScreen && height ? `height: ${height}` : '100%'"
|
|
7
|
+
>
|
|
8
|
+
<TMagicButton
|
|
9
|
+
class="magic-code-editor-full-screen-icon"
|
|
10
|
+
circle
|
|
11
|
+
size="small"
|
|
12
|
+
:icon="FullScreen"
|
|
13
|
+
@click="fullScreenHandler"
|
|
14
|
+
></TMagicButton>
|
|
15
|
+
<div ref="codeEditor" class="magic-code-editor-content"></div>
|
|
16
|
+
</div>
|
|
17
|
+
</Teleport>
|
|
18
|
+
</div>
|
|
3
19
|
</template>
|
|
4
20
|
|
|
5
21
|
<script lang="ts" setup>
|
|
6
22
|
import { onMounted, onUnmounted, ref, watch } from 'vue';
|
|
23
|
+
import { FullScreen } from '@element-plus/icons-vue';
|
|
7
24
|
import { throttle } from 'lodash-es';
|
|
8
25
|
import * as monaco from 'monaco-editor';
|
|
9
26
|
import serialize from 'serialize-javascript';
|
|
10
27
|
|
|
28
|
+
import { TMagicButton } from '@tmagic/design';
|
|
29
|
+
|
|
11
30
|
defineOptions({
|
|
12
31
|
name: 'MEditorCodeEditor',
|
|
13
32
|
});
|
|
@@ -21,6 +40,7 @@ const props = withDefaults(
|
|
|
21
40
|
options?: {
|
|
22
41
|
[key: string]: any;
|
|
23
42
|
};
|
|
43
|
+
height?: string;
|
|
24
44
|
autoSave?: boolean;
|
|
25
45
|
}>(),
|
|
26
46
|
{
|
|
@@ -155,6 +175,17 @@ onUnmounted(() => {
|
|
|
155
175
|
resizeObserver.disconnect();
|
|
156
176
|
});
|
|
157
177
|
|
|
178
|
+
const fullScreen = ref(false);
|
|
179
|
+
const fullScreenHandler = () => {
|
|
180
|
+
fullScreen.value = !fullScreen.value;
|
|
181
|
+
setTimeout(() => {
|
|
182
|
+
vsEditor?.focus();
|
|
183
|
+
vsEditor?.layout();
|
|
184
|
+
vsDiffEditor?.focus();
|
|
185
|
+
vsDiffEditor?.layout();
|
|
186
|
+
});
|
|
187
|
+
};
|
|
188
|
+
|
|
158
189
|
defineExpose({
|
|
159
190
|
values,
|
|
160
191
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<div class="m-editor">
|
|
2
|
+
<div class="m-editor" ref="content">
|
|
3
3
|
<slot name="header"></slot>
|
|
4
4
|
|
|
5
5
|
<slot name="nav"></slot>
|
|
@@ -67,6 +67,8 @@ const DEFAULT_RIGHT_COLUMN_WIDTH = 480;
|
|
|
67
67
|
const codeOptions = inject('codeOptions', {});
|
|
68
68
|
const { editorService, uiService } = inject<Services>('services') || {};
|
|
69
69
|
|
|
70
|
+
const content = ref<HTMLDivElement>();
|
|
71
|
+
|
|
70
72
|
const root = computed(() => editorService?.get('root'));
|
|
71
73
|
|
|
72
74
|
const pageLength = computed(() => editorService?.get('pageLength') || 0);
|
|
@@ -91,13 +93,15 @@ watch(
|
|
|
91
93
|
|
|
92
94
|
columnWidth.value.left = left;
|
|
93
95
|
|
|
96
|
+
const container = content.value || document.body;
|
|
97
|
+
|
|
94
98
|
if (length <= 0) {
|
|
95
99
|
columnWidth.value.right = undefined;
|
|
96
|
-
columnWidth.value.center =
|
|
100
|
+
columnWidth.value.center = container.clientWidth - left;
|
|
97
101
|
} else {
|
|
98
102
|
const right = columnWidth.value.right || RightColumnWidthCacheData || DEFAULT_RIGHT_COLUMN_WIDTH;
|
|
99
103
|
columnWidth.value.right = right;
|
|
100
|
-
columnWidth.value.center =
|
|
104
|
+
columnWidth.value.center = container.clientWidth - left - right;
|
|
101
105
|
}
|
|
102
106
|
|
|
103
107
|
uiService?.set('columnWidth', columnWidth.value as GetColumnWidth);
|
|
@@ -58,14 +58,6 @@
|
|
|
58
58
|
<component v-else-if="config.slots?.codeBlockPanelTool" :is="config.slots.codeBlockPanelTool" />
|
|
59
59
|
</template>
|
|
60
60
|
|
|
61
|
-
<template
|
|
62
|
-
#code-block-edit-panel-header="{ id }"
|
|
63
|
-
v-if="config.$key === 'code-block' || config.slots?.codeBlockEditPanelHeader"
|
|
64
|
-
>
|
|
65
|
-
<slot v-if="config.$key === 'code-block'" name="code-block-edit-panel-header" :id="id"></slot>
|
|
66
|
-
<component v-else-if="config.slots?.codeBlockEditPanelHeader" :is="config.slots.codeBlockEditPanelHeader" />
|
|
67
|
-
</template>
|
|
68
|
-
|
|
69
61
|
<template
|
|
70
62
|
#layer-node-content="{ data: nodeData, node }"
|
|
71
63
|
v-if="config.$key === 'layer' || config.slots?.layerNodeContent"
|
|
@@ -93,7 +85,7 @@ import MIcon from '@editor/components/Icon.vue';
|
|
|
93
85
|
import type { MenuButton, MenuComponent, SideComponent, SideItem } from '@editor/type';
|
|
94
86
|
import { SideBarData } from '@editor/type';
|
|
95
87
|
|
|
96
|
-
import
|
|
88
|
+
import CodeBlockListPanel from './code-block/CodeBlockListPanel.vue';
|
|
97
89
|
import DataSourceListPanel from './data-source/DataSourceListPanel.vue';
|
|
98
90
|
import ComponentListPanel from './ComponentListPanel.vue';
|
|
99
91
|
import LayerPanel from './LayerPanel.vue';
|
|
@@ -143,7 +135,7 @@ const getItemConfig = (data: SideItem): SideComponent => {
|
|
|
143
135
|
type: 'component',
|
|
144
136
|
icon: EditPen,
|
|
145
137
|
text: '代码编辑',
|
|
146
|
-
component:
|
|
138
|
+
component: CodeBlockListPanel,
|
|
147
139
|
slots: {},
|
|
148
140
|
},
|
|
149
141
|
'data-source': {
|