@tmagic/editor 1.3.0-alpha.9 → 1.3.0-beta.0
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 +77 -218
- package/dist/tmagic-editor.js +4143 -3302
- package/dist/tmagic-editor.js.map +1 -1
- package/dist/tmagic-editor.umd.cjs +5289 -4434
- package/dist/tmagic-editor.umd.cjs.map +1 -1
- package/package.json +15 -15
- package/src/Editor.vue +4 -5
- package/src/components/CodeBlockEditor.vue +257 -0
- package/src/components/CodeParams.vue +60 -0
- package/src/components/ContentMenu.vue +11 -3
- package/src/editorProps.ts +30 -5
- package/src/fields/Code.vue +23 -19
- package/src/fields/CodeLink.vue +6 -7
- package/src/fields/CodeSelect.vue +12 -9
- package/src/fields/CodeSelectCol.vue +70 -81
- package/src/fields/DataSourceFieldSelect.vue +47 -0
- package/src/fields/DataSourceFields.vue +28 -22
- package/src/fields/DataSourceInput.vue +21 -58
- package/src/fields/DataSourceMethodSelect.vue +136 -0
- package/src/fields/DataSourceMethods.vue +103 -0
- package/src/fields/DataSourceSelect.vue +5 -12
- package/src/fields/EventSelect.vue +53 -19
- package/src/fields/KeyValue.vue +9 -11
- package/src/fields/UISelect.vue +54 -14
- package/src/hooks/index.ts +21 -0
- package/src/hooks/use-code-block-edit.ts +84 -0
- package/src/hooks/use-data-source-method.ts +100 -0
- package/src/{utils/stage.ts → hooks/use-stage.ts} +4 -7
- package/src/icons/CenterIcon.vue +13 -0
- package/src/icons/CodeIcon.vue +0 -2
- package/src/icons/FolderMinusIcon.vue +22 -0
- package/src/index.ts +12 -0
- package/src/initService.ts +69 -16
- package/src/layouts/CodeEditor.vue +35 -3
- package/src/layouts/Framework.vue +7 -3
- package/src/layouts/PropsPanel.vue +8 -3
- package/src/layouts/sidebar/ComponentListPanel.vue +4 -6
- package/src/layouts/sidebar/LayerMenu.vue +20 -21
- package/src/layouts/sidebar/LayerPanel.vue +12 -2
- package/src/layouts/sidebar/Sidebar.vue +22 -36
- package/src/layouts/sidebar/code-block/CodeBlockList.vue +81 -119
- package/src/layouts/sidebar/code-block/CodeBlockListPanel.vue +64 -0
- package/src/layouts/sidebar/data-source/DataSourceConfigPanel.vue +27 -47
- package/src/layouts/sidebar/data-source/DataSourceList.vue +145 -0
- package/src/layouts/sidebar/data-source/DataSourceListPanel.vue +58 -85
- package/src/layouts/workspace/Stage.vue +3 -2
- package/src/layouts/workspace/ViewerMenu.vue +10 -35
- package/src/services/codeBlock.ts +18 -71
- package/src/services/dataSource.ts +16 -1
- package/src/services/dep.ts +22 -20
- package/src/services/editor.ts +46 -18
- package/src/services/props.ts +2 -2
- package/src/theme/code-block.scss +5 -117
- package/src/theme/code-editor.scss +27 -2
- package/src/theme/content-menu.scss +1 -1
- package/src/theme/data-source-methods.scss +13 -0
- package/src/theme/data-source.scss +11 -0
- package/src/theme/event.scss +15 -12
- package/src/theme/framework.scss +0 -3
- package/src/theme/layout.scss +4 -0
- package/src/theme/sidebar.scss +18 -60
- package/src/theme/theme.scss +1 -0
- package/src/type.ts +47 -7
- package/src/utils/content-menu.ts +92 -0
- package/src/utils/data-source/formConfigs/base.ts +28 -30
- package/src/utils/data-source/index.ts +65 -2
- package/src/utils/dep.ts +33 -7
- package/src/utils/index.ts +1 -1
- package/src/utils/props.ts +298 -189
- package/src/utils/undo-redo.ts +1 -1
- package/types/Editor.vue.d.ts +30 -6
- package/types/components/CodeBlockEditor.vue.d.ts +23 -0
- package/types/components/CodeParams.vue.d.ts +26 -0
- package/types/components/ContentMenu.vue.d.ts +2 -2
- package/types/components/ToolButton.vue.d.ts +3 -3
- package/types/editorProps.d.ts +19 -5
- package/types/fields/Code.vue.d.ts +24 -19
- package/types/fields/CodeLink.vue.d.ts +12 -21
- package/types/fields/CodeSelect.vue.d.ts +6 -17
- package/types/fields/CodeSelectCol.vue.d.ts +10 -14
- package/types/fields/DataSourceFieldSelect.vue.d.ts +29 -0
- package/types/fields/DataSourceFields.vue.d.ts +7 -18
- package/types/fields/DataSourceInput.vue.d.ts +10 -30
- package/types/fields/DataSourceMethodSelect.vue.d.ts +29 -0
- package/types/fields/DataSourceMethods.vue.d.ts +32 -0
- package/types/fields/DataSourceSelect.vue.d.ts +13 -29
- package/types/fields/EventSelect.vue.d.ts +2 -13
- package/types/fields/KeyValue.vue.d.ts +9 -24
- package/types/fields/UISelect.vue.d.ts +2 -11
- package/types/hooks/index.d.ts +3 -0
- package/types/{components/FunctionEditor.vue.d.ts → hooks/use-code-block-edit.d.ts} +31 -121
- package/types/hooks/use-data-source-method.d.ts +123 -0
- package/types/icons/CenterIcon.vue.d.ts +2 -0
- package/types/icons/FolderMinusIcon.vue.d.ts +2 -0
- package/types/index.d.ts +6 -0
- package/types/initService.d.ts +2 -2
- package/types/layouts/CodeEditor.vue.d.ts +7 -4
- package/types/layouts/PropsPanel.vue.d.ts +274 -2
- 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} +9 -5
- 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 +6 -37
- package/types/services/dataSource.d.ts +7 -1
- package/types/services/dep.d.ts +12 -21
- package/types/services/editor.d.ts +1 -1
- package/types/services/props.d.ts +10 -115
- package/types/type.d.ts +42 -7
- package/types/utils/content-menu.d.ts +7 -0
- package/types/utils/data-source/formConfigs/base.d.ts +1 -2
- package/types/utils/data-source/index.d.ts +5 -0
- package/types/utils/dep.d.ts +4 -2
- package/types/utils/index.d.ts +1 -1
- package/types/utils/props.d.ts +13 -102
- 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
- /package/types/{utils/stage.d.ts → hooks/use-stage.d.ts} +0 -0
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.3.0-
|
|
2
|
+
"version": "1.3.0-beta.0",
|
|
3
3
|
"name": "@tmagic/editor",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": [
|
|
@@ -46,27 +46,27 @@
|
|
|
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-
|
|
50
|
-
"@tmagic/design": "1.3.0-
|
|
51
|
-
"@tmagic/form": "1.3.0-
|
|
52
|
-
"@tmagic/schema": "1.3.0-
|
|
53
|
-
"@tmagic/stage": "1.3.0-
|
|
54
|
-
"@tmagic/table": "1.3.0-
|
|
55
|
-
"@tmagic/utils": "1.3.0-
|
|
49
|
+
"@tmagic/core": "1.3.0-beta.0",
|
|
50
|
+
"@tmagic/design": "1.3.0-beta.0",
|
|
51
|
+
"@tmagic/form": "1.3.0-beta.0",
|
|
52
|
+
"@tmagic/schema": "1.3.0-beta.0",
|
|
53
|
+
"@tmagic/stage": "1.3.0-beta.0",
|
|
54
|
+
"@tmagic/table": "1.3.0-beta.0",
|
|
55
|
+
"@tmagic/utils": "1.3.0-beta.0",
|
|
56
56
|
"buffer": "^6.0.3",
|
|
57
57
|
"color": "^3.1.3",
|
|
58
58
|
"events": "^3.3.0",
|
|
59
|
-
"gesto": "^1.
|
|
60
|
-
"keycon": "^1.
|
|
59
|
+
"gesto": "^1.19.1",
|
|
60
|
+
"keycon": "^1.4.0",
|
|
61
61
|
"lodash-es": "^4.17.21",
|
|
62
|
-
"monaco-editor": "^0.
|
|
62
|
+
"monaco-editor": "^0.41.0",
|
|
63
63
|
"serialize-javascript": "^6.0.0",
|
|
64
64
|
"vue": "^3.3.4"
|
|
65
65
|
},
|
|
66
66
|
"peerDependencies": {
|
|
67
|
-
"@tmagic/design": "1.3.0-
|
|
68
|
-
"@tmagic/form": "1.3.0-
|
|
69
|
-
"monaco-editor": "^0.
|
|
67
|
+
"@tmagic/design": "1.3.0-beta.0",
|
|
68
|
+
"@tmagic/form": "1.3.0-beta.0",
|
|
69
|
+
"monaco-editor": "^0.41.0",
|
|
70
70
|
"vue": "^3.3.4"
|
|
71
71
|
},
|
|
72
72
|
"devDependencies": {
|
|
@@ -81,7 +81,7 @@
|
|
|
81
81
|
"sass": "^1.35.1",
|
|
82
82
|
"tsc-alias": "^1.8.5",
|
|
83
83
|
"typescript": "^5.0.4",
|
|
84
|
-
"vite": "^4.
|
|
84
|
+
"vite": "^4.4.4",
|
|
85
85
|
"vue-tsc": "^1.6.5"
|
|
86
86
|
}
|
|
87
87
|
}
|
package/src/Editor.vue
CHANGED
|
@@ -40,10 +40,6 @@
|
|
|
40
40
|
<template #code-block-panel-tool="{ id, data }">
|
|
41
41
|
<slot name="code-block-panel-tool" :id="id" :data="data"></slot>
|
|
42
42
|
</template>
|
|
43
|
-
|
|
44
|
-
<template #code-block-edit-panel-header="{ id }">
|
|
45
|
-
<slot name="code-block-edit-panel-header" :id="id"></slot>
|
|
46
|
-
</template>
|
|
47
43
|
</Sidebar>
|
|
48
44
|
</slot>
|
|
49
45
|
</template>
|
|
@@ -61,7 +57,10 @@
|
|
|
61
57
|
|
|
62
58
|
<template #props-panel>
|
|
63
59
|
<slot name="props-panel">
|
|
64
|
-
<PropsPanel
|
|
60
|
+
<PropsPanel
|
|
61
|
+
:extend-state="extendFormState"
|
|
62
|
+
@mounted="(instance: any) => $emit('props-panel-mounted', instance)"
|
|
63
|
+
>
|
|
65
64
|
<template #props-panel-header>
|
|
66
65
|
<slot name="props-panel-header"></slot>
|
|
67
66
|
</template>
|
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<MFormDrawer
|
|
3
|
+
class="m-editor-code-block-editor"
|
|
4
|
+
ref="fomDrawer"
|
|
5
|
+
label-width="80px"
|
|
6
|
+
:close-on-press-escape="false"
|
|
7
|
+
:title="content.name"
|
|
8
|
+
:width="size"
|
|
9
|
+
:config="functionConfig"
|
|
10
|
+
:values="content"
|
|
11
|
+
:disabled="disabled"
|
|
12
|
+
:before-close="beforeClose"
|
|
13
|
+
@change="changeHandler"
|
|
14
|
+
@submit="submitForm"
|
|
15
|
+
@error="errorHandler"
|
|
16
|
+
@open="openHandler"
|
|
17
|
+
@closed="closedHandler"
|
|
18
|
+
>
|
|
19
|
+
<template #left>
|
|
20
|
+
<TMagicButton type="primary" text @click="difVisible = true">查看修改</TMagicButton>
|
|
21
|
+
</template>
|
|
22
|
+
</MFormDrawer>
|
|
23
|
+
|
|
24
|
+
<TMagicDialog v-model="difVisible" title="查看修改" fullscreen>
|
|
25
|
+
<div style="display: flex; margin-bottom: 10px">
|
|
26
|
+
<div style="flex: 1"><TMagicTag size="small" type="info">修改前</TMagicTag></div>
|
|
27
|
+
<div style="flex: 1"><TMagicTag size="small" type="success">修改后</TMagicTag></div>
|
|
28
|
+
</div>
|
|
29
|
+
|
|
30
|
+
<CodeEditor
|
|
31
|
+
v-if="difVisible"
|
|
32
|
+
ref="magicVsEditor"
|
|
33
|
+
type="diff"
|
|
34
|
+
language="json"
|
|
35
|
+
:initValues="content.content"
|
|
36
|
+
:modifiedValues="fomDrawer?.form?.values.content"
|
|
37
|
+
:style="`height: ${height - 200}px`"
|
|
38
|
+
></CodeEditor>
|
|
39
|
+
|
|
40
|
+
<template #footer>
|
|
41
|
+
<span class="dialog-footer">
|
|
42
|
+
<TMagicButton size="small" @click="difVisible = false">取消</TMagicButton>
|
|
43
|
+
<TMagicButton size="small" type="primary" @click="diffChange">确定</TMagicButton>
|
|
44
|
+
</span>
|
|
45
|
+
</template>
|
|
46
|
+
</TMagicDialog>
|
|
47
|
+
</template>
|
|
48
|
+
|
|
49
|
+
<script lang="ts" setup>
|
|
50
|
+
import { computed, inject, onUnmounted, ref } from 'vue';
|
|
51
|
+
|
|
52
|
+
import { TMagicButton, TMagicDialog, tMagicMessage, tMagicMessageBox, TMagicTag } from '@tmagic/design';
|
|
53
|
+
import { ColumnConfig, FormState, MFormDrawer } from '@tmagic/form';
|
|
54
|
+
import type { CodeBlockContent } from '@tmagic/schema';
|
|
55
|
+
|
|
56
|
+
import CodeEditor from '@editor/layouts/CodeEditor.vue';
|
|
57
|
+
import type { Services } from '@editor/type';
|
|
58
|
+
import { getConfig } from '@editor/utils/config';
|
|
59
|
+
|
|
60
|
+
defineOptions({
|
|
61
|
+
name: 'MEditorCodeBlockEditor',
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
const props = defineProps<{
|
|
65
|
+
content: CodeBlockContent;
|
|
66
|
+
disabled?: boolean;
|
|
67
|
+
isDataSource?: boolean;
|
|
68
|
+
}>();
|
|
69
|
+
|
|
70
|
+
const emit = defineEmits<{
|
|
71
|
+
submit: [values: CodeBlockContent];
|
|
72
|
+
}>();
|
|
73
|
+
|
|
74
|
+
const services = inject<Services>('services');
|
|
75
|
+
|
|
76
|
+
const difVisible = ref(false);
|
|
77
|
+
const height = ref(globalThis.innerHeight);
|
|
78
|
+
|
|
79
|
+
const windowReizehandler = () => {
|
|
80
|
+
height.value = globalThis.innerHeight;
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
globalThis.addEventListener('resize', windowReizehandler);
|
|
84
|
+
|
|
85
|
+
onUnmounted(() => {
|
|
86
|
+
globalThis.removeEventListener('resize', windowReizehandler);
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
const magicVsEditor = ref<InstanceType<typeof CodeEditor>>();
|
|
90
|
+
|
|
91
|
+
const diffChange = () => {
|
|
92
|
+
if (!magicVsEditor.value || !fomDrawer.value?.form) {
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
fomDrawer.value.form.values.content = magicVsEditor.value.getEditorValue();
|
|
97
|
+
|
|
98
|
+
difVisible.value = false;
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
const columnWidth = computed(() => services?.uiService.get('columnWidth'));
|
|
102
|
+
const size = computed(() =>
|
|
103
|
+
columnWidth.value ? columnWidth.value.center + columnWidth.value.right - (props.isDataSource ? 100 : 0) : 600,
|
|
104
|
+
);
|
|
105
|
+
|
|
106
|
+
const codeEditorHeight = ref('600px');
|
|
107
|
+
|
|
108
|
+
const defaultParamColConfig: ColumnConfig = {
|
|
109
|
+
type: 'row',
|
|
110
|
+
label: '参数类型',
|
|
111
|
+
items: [
|
|
112
|
+
{
|
|
113
|
+
text: '参数类型',
|
|
114
|
+
labelWidth: '70px',
|
|
115
|
+
type: 'select',
|
|
116
|
+
name: 'type',
|
|
117
|
+
options: [
|
|
118
|
+
{
|
|
119
|
+
text: '数字',
|
|
120
|
+
label: '数字',
|
|
121
|
+
value: 'number',
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
text: '字符串',
|
|
125
|
+
label: '字符串',
|
|
126
|
+
value: 'text',
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
text: '组件',
|
|
130
|
+
label: '组件',
|
|
131
|
+
value: 'ui-select',
|
|
132
|
+
},
|
|
133
|
+
],
|
|
134
|
+
},
|
|
135
|
+
],
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
const functionConfig = computed(() => [
|
|
139
|
+
{
|
|
140
|
+
text: '名称',
|
|
141
|
+
name: 'name',
|
|
142
|
+
},
|
|
143
|
+
{
|
|
144
|
+
text: '描述',
|
|
145
|
+
name: 'desc',
|
|
146
|
+
},
|
|
147
|
+
{
|
|
148
|
+
text: '执行时机',
|
|
149
|
+
name: 'timing',
|
|
150
|
+
type: 'select',
|
|
151
|
+
options: [
|
|
152
|
+
{ text: '初始化前', value: 'beforeInit' },
|
|
153
|
+
{ text: '初始化后', value: 'afterInit' },
|
|
154
|
+
],
|
|
155
|
+
display: () => props.isDataSource,
|
|
156
|
+
},
|
|
157
|
+
{
|
|
158
|
+
type: 'table',
|
|
159
|
+
border: true,
|
|
160
|
+
text: '参数',
|
|
161
|
+
enableFullscreen: false,
|
|
162
|
+
enableToggleMode: false,
|
|
163
|
+
name: 'params',
|
|
164
|
+
dropSort: false,
|
|
165
|
+
items: [
|
|
166
|
+
{
|
|
167
|
+
type: 'text',
|
|
168
|
+
label: '参数名',
|
|
169
|
+
name: 'name',
|
|
170
|
+
},
|
|
171
|
+
{
|
|
172
|
+
type: 'text',
|
|
173
|
+
label: '描述',
|
|
174
|
+
name: 'extra',
|
|
175
|
+
},
|
|
176
|
+
services?.codeBlockService.getParamsColConfig() || defaultParamColConfig,
|
|
177
|
+
],
|
|
178
|
+
},
|
|
179
|
+
{
|
|
180
|
+
name: 'content',
|
|
181
|
+
type: 'vs-code',
|
|
182
|
+
options: inject('codeOptions', {}),
|
|
183
|
+
height: codeEditorHeight.value,
|
|
184
|
+
onChange: (formState: FormState | undefined, code: string) => {
|
|
185
|
+
try {
|
|
186
|
+
// 检测js代码是否存在语法错误
|
|
187
|
+
getConfig('parseDSL')(code);
|
|
188
|
+
|
|
189
|
+
return code;
|
|
190
|
+
} catch (error: any) {
|
|
191
|
+
tMagicMessage.error(error.message);
|
|
192
|
+
|
|
193
|
+
throw error;
|
|
194
|
+
}
|
|
195
|
+
},
|
|
196
|
+
},
|
|
197
|
+
]);
|
|
198
|
+
|
|
199
|
+
const submitForm = (values: CodeBlockContent) => {
|
|
200
|
+
emit('submit', values);
|
|
201
|
+
};
|
|
202
|
+
|
|
203
|
+
const errorHandler = (error: any) => {
|
|
204
|
+
tMagicMessage.error(error.message);
|
|
205
|
+
};
|
|
206
|
+
|
|
207
|
+
const fomDrawer = ref<InstanceType<typeof MFormDrawer>>();
|
|
208
|
+
|
|
209
|
+
const openHandler = () => {
|
|
210
|
+
setTimeout(() => {
|
|
211
|
+
if (fomDrawer.value) {
|
|
212
|
+
const height = fomDrawer.value?.bodyHeight - 348 - (props.isDataSource ? 50 : 0);
|
|
213
|
+
codeEditorHeight.value = `${height > 100 ? height : 600}px`;
|
|
214
|
+
}
|
|
215
|
+
});
|
|
216
|
+
};
|
|
217
|
+
|
|
218
|
+
const changedValue = ref<CodeBlockContent>();
|
|
219
|
+
const changeHandler = (values: CodeBlockContent) => {
|
|
220
|
+
changedValue.value = values;
|
|
221
|
+
};
|
|
222
|
+
|
|
223
|
+
const beforeClose = (done: (cancel?: boolean) => void) => {
|
|
224
|
+
if (!changedValue.value) {
|
|
225
|
+
done();
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
tMagicMessageBox
|
|
229
|
+
.confirm('当前代码块已修改,是否保存?', '提示', {
|
|
230
|
+
confirmButtonText: '保存并关闭',
|
|
231
|
+
cancelButtonText: '不保存并关闭',
|
|
232
|
+
type: 'warning',
|
|
233
|
+
distinguishCancelAndClose: true,
|
|
234
|
+
})
|
|
235
|
+
.then(() => {
|
|
236
|
+
changedValue.value && submitForm(changedValue.value);
|
|
237
|
+
done();
|
|
238
|
+
})
|
|
239
|
+
.catch((action: string) => {
|
|
240
|
+
done(action === 'close');
|
|
241
|
+
});
|
|
242
|
+
};
|
|
243
|
+
|
|
244
|
+
const closedHandler = () => {
|
|
245
|
+
changedValue.value = undefined;
|
|
246
|
+
};
|
|
247
|
+
|
|
248
|
+
defineExpose({
|
|
249
|
+
show() {
|
|
250
|
+
fomDrawer.value?.show();
|
|
251
|
+
},
|
|
252
|
+
|
|
253
|
+
hide() {
|
|
254
|
+
fomDrawer.value?.hide();
|
|
255
|
+
},
|
|
256
|
+
});
|
|
257
|
+
</script>
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<MForm
|
|
3
|
+
ref="form"
|
|
4
|
+
:config="codeParamsConfig"
|
|
5
|
+
:init-values="model"
|
|
6
|
+
:disabled="disabled"
|
|
7
|
+
:size="size"
|
|
8
|
+
:watch-props="false"
|
|
9
|
+
@change="onParamsChangeHandler"
|
|
10
|
+
></MForm>
|
|
11
|
+
</template>
|
|
12
|
+
|
|
13
|
+
<script lang="ts" setup>
|
|
14
|
+
import { computed, ref } from 'vue';
|
|
15
|
+
|
|
16
|
+
import { FormConfig, MForm } from '@tmagic/form';
|
|
17
|
+
|
|
18
|
+
import type { CodeParamStatement } from '@editor/type';
|
|
19
|
+
import { error } from '@editor/utils';
|
|
20
|
+
|
|
21
|
+
defineOptions({
|
|
22
|
+
name: 'MEditorCodeParams',
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
const props = defineProps<{
|
|
26
|
+
model: any;
|
|
27
|
+
size?: 'small' | 'default' | 'large';
|
|
28
|
+
disabled?: boolean;
|
|
29
|
+
name: string;
|
|
30
|
+
paramsConfig: CodeParamStatement[];
|
|
31
|
+
}>();
|
|
32
|
+
|
|
33
|
+
const emit = defineEmits(['change']);
|
|
34
|
+
|
|
35
|
+
const form = ref<InstanceType<typeof MForm>>();
|
|
36
|
+
|
|
37
|
+
const getFormConfig = (items: FormConfig = []) => [
|
|
38
|
+
{
|
|
39
|
+
type: 'fieldset',
|
|
40
|
+
items,
|
|
41
|
+
legend: '参数',
|
|
42
|
+
labelWidth: '70px',
|
|
43
|
+
name: props.name,
|
|
44
|
+
},
|
|
45
|
+
];
|
|
46
|
+
|
|
47
|
+
const codeParamsConfig = computed(() => getFormConfig(props.paramsConfig));
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* 参数值修改更新
|
|
51
|
+
*/
|
|
52
|
+
const onParamsChangeHandler = async () => {
|
|
53
|
+
try {
|
|
54
|
+
const value = await form.value?.submitForm(true);
|
|
55
|
+
emit('change', value);
|
|
56
|
+
} catch (e) {
|
|
57
|
+
error(e);
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
</script>
|
|
@@ -4,10 +4,11 @@
|
|
|
4
4
|
<ToolButton
|
|
5
5
|
v-for="(item, index) in menuData"
|
|
6
6
|
event-type="mouseup"
|
|
7
|
+
ref="buttons"
|
|
7
8
|
:data="item"
|
|
8
9
|
:key="index"
|
|
9
10
|
@mouseup="hide"
|
|
10
|
-
@mouseenter="showSubMenu(item)"
|
|
11
|
+
@mouseenter="showSubMenu(item, index)"
|
|
11
12
|
></ToolButton>
|
|
12
13
|
</div>
|
|
13
14
|
<teleport to="body">
|
|
@@ -48,6 +49,7 @@ const props = withDefaults(
|
|
|
48
49
|
const emit = defineEmits(['hide', 'show']);
|
|
49
50
|
|
|
50
51
|
const menu = ref<HTMLDivElement>();
|
|
52
|
+
const buttons = ref<InstanceType<typeof ToolButton>[]>();
|
|
51
53
|
const subMenu = ref<any>();
|
|
52
54
|
const visible = ref(false);
|
|
53
55
|
const subMenuData = ref<(MenuButton | MenuComponent)[]>([]);
|
|
@@ -101,7 +103,7 @@ const show = (e: MouseEvent) => {
|
|
|
101
103
|
}, 300);
|
|
102
104
|
};
|
|
103
105
|
|
|
104
|
-
const showSubMenu = (item: MenuButton | MenuComponent) => {
|
|
106
|
+
const showSubMenu = (item: MenuButton | MenuComponent, index: number) => {
|
|
105
107
|
const menuItem = item as MenuButton;
|
|
106
108
|
if (typeof item !== 'object' || !menuItem.items?.length) {
|
|
107
109
|
return;
|
|
@@ -110,9 +112,15 @@ const showSubMenu = (item: MenuButton | MenuComponent) => {
|
|
|
110
112
|
subMenuData.value = menuItem.items || [];
|
|
111
113
|
setTimeout(() => {
|
|
112
114
|
if (menu.value) {
|
|
115
|
+
// 将子菜单放置在按钮右侧,与按钮齐平
|
|
116
|
+
let y = menu.value.offsetTop;
|
|
117
|
+
if (buttons.value?.[index].$el) {
|
|
118
|
+
const rect = buttons.value?.[index].$el.getBoundingClientRect();
|
|
119
|
+
y = rect.top;
|
|
120
|
+
}
|
|
113
121
|
subMenu.value?.show({
|
|
114
122
|
clientX: menu.value.offsetLeft + menu.value.clientWidth,
|
|
115
|
-
clientY:
|
|
123
|
+
clientY: y,
|
|
116
124
|
});
|
|
117
125
|
}
|
|
118
126
|
}, 0);
|
package/src/editorProps.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { PropType } from 'vue';
|
|
2
2
|
|
|
3
3
|
import type { EventOption } from '@tmagic/core';
|
|
4
|
-
import type { FormConfig } from '@tmagic/form';
|
|
5
|
-
import type { MApp, MNode } from '@tmagic/schema';
|
|
4
|
+
import type { FormConfig, FormState } from '@tmagic/form';
|
|
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,7 +93,14 @@ export default {
|
|
|
79
93
|
default: () => ({}),
|
|
80
94
|
},
|
|
81
95
|
|
|
82
|
-
|
|
96
|
+
/** 添加数据源时的默认值 */
|
|
97
|
+
datasourceValues: {
|
|
98
|
+
type: Object as PropType<Record<string, Partial<DataSourceSchema>>>,
|
|
99
|
+
default: () => ({}),
|
|
100
|
+
},
|
|
101
|
+
|
|
102
|
+
/** 数据源的属性配置表单的dsl */
|
|
103
|
+
datasourceConfigs: {
|
|
83
104
|
type: Object as PropType<Record<string, FormConfig>>,
|
|
84
105
|
default: () => ({}),
|
|
85
106
|
},
|
|
@@ -137,4 +158,8 @@ export default {
|
|
|
137
158
|
disabledDragStart: {
|
|
138
159
|
type: Boolean,
|
|
139
160
|
},
|
|
161
|
+
|
|
162
|
+
extendFormState: {
|
|
163
|
+
type: Function as PropType<(state: FormState) => Record<string, any> | Promise<Record<string, any>>>,
|
|
164
|
+
},
|
|
140
165
|
};
|
package/src/fields/Code.vue
CHANGED
|
@@ -1,15 +1,20 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<
|
|
3
|
-
:
|
|
2
|
+
<MagicCodeEditor
|
|
3
|
+
:height="config.height"
|
|
4
4
|
:init-values="model[name]"
|
|
5
|
-
:language="language"
|
|
6
|
-
:options="
|
|
5
|
+
:language="config.language"
|
|
6
|
+
:options="{
|
|
7
|
+
...config.options,
|
|
8
|
+
readOnly: disabled,
|
|
9
|
+
}"
|
|
7
10
|
@save="save"
|
|
8
|
-
></
|
|
11
|
+
></MagicCodeEditor>
|
|
9
12
|
</template>
|
|
10
13
|
|
|
11
14
|
<script lang="ts" setup>
|
|
12
|
-
import {
|
|
15
|
+
import type { FieldProps } from '@tmagic/form';
|
|
16
|
+
|
|
17
|
+
import MagicCodeEditor from '@editor/layouts/CodeEditor.vue';
|
|
13
18
|
|
|
14
19
|
defineOptions({
|
|
15
20
|
name: 'MEditorCode',
|
|
@@ -17,19 +22,18 @@ defineOptions({
|
|
|
17
22
|
|
|
18
23
|
const emit = defineEmits(['change']);
|
|
19
24
|
|
|
20
|
-
const props =
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
const height = computed(() => props.config.height || `${document.body.clientHeight - 168}px`);
|
|
25
|
+
const props = withDefaults(
|
|
26
|
+
defineProps<
|
|
27
|
+
FieldProps<{
|
|
28
|
+
language?: string;
|
|
29
|
+
options?: Object;
|
|
30
|
+
height?: string;
|
|
31
|
+
}>
|
|
32
|
+
>(),
|
|
33
|
+
{
|
|
34
|
+
disabled: false,
|
|
35
|
+
},
|
|
36
|
+
);
|
|
33
37
|
|
|
34
38
|
const save = (v: string) => {
|
|
35
39
|
props.model[props.name] = v;
|
package/src/fields/CodeLink.vue
CHANGED
|
@@ -6,24 +6,23 @@
|
|
|
6
6
|
import { computed, reactive, watch } from 'vue';
|
|
7
7
|
import serialize from 'serialize-javascript';
|
|
8
8
|
|
|
9
|
+
import type { FieldProps } from '@tmagic/form';
|
|
10
|
+
|
|
9
11
|
import { getConfig } from '@editor/utils/config';
|
|
10
12
|
|
|
11
13
|
defineOptions({
|
|
12
14
|
name: 'MEditorCodeLink',
|
|
13
15
|
});
|
|
14
16
|
|
|
15
|
-
const props = defineProps<
|
|
16
|
-
|
|
17
|
+
const props = defineProps<
|
|
18
|
+
FieldProps<{
|
|
17
19
|
type: 'code-link';
|
|
18
20
|
name: string;
|
|
19
21
|
text?: string;
|
|
20
22
|
formTitle?: string;
|
|
21
23
|
codeOptions?: Object;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
name: string;
|
|
25
|
-
prop: string;
|
|
26
|
-
}>();
|
|
24
|
+
}>
|
|
25
|
+
>();
|
|
27
26
|
|
|
28
27
|
const emit = defineEmits(['change']);
|
|
29
28
|
|
|
@@ -7,28 +7,29 @@
|
|
|
7
7
|
</template>
|
|
8
8
|
|
|
9
9
|
<script lang="ts" setup>
|
|
10
|
-
import { computed, watch } from 'vue';
|
|
10
|
+
import { computed, inject, watch } from 'vue';
|
|
11
11
|
import { isEmpty } from 'lodash-es';
|
|
12
12
|
|
|
13
13
|
import { TMagicCard } from '@tmagic/design';
|
|
14
|
+
import type { FieldProps } from '@tmagic/form';
|
|
14
15
|
import { HookType } from '@tmagic/schema';
|
|
15
16
|
|
|
17
|
+
import type { Services } from '@editor/type';
|
|
18
|
+
|
|
16
19
|
defineOptions({
|
|
17
20
|
name: 'MEditorCodeSelect',
|
|
18
21
|
});
|
|
19
22
|
|
|
20
23
|
const emit = defineEmits(['change']);
|
|
21
24
|
|
|
25
|
+
const services = inject<Services>('services');
|
|
26
|
+
|
|
22
27
|
const props = withDefaults(
|
|
23
|
-
defineProps<
|
|
24
|
-
|
|
28
|
+
defineProps<
|
|
29
|
+
FieldProps<{
|
|
25
30
|
className?: string;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
prop: string;
|
|
29
|
-
name: string;
|
|
30
|
-
size: 'small' | 'default' | 'large';
|
|
31
|
-
}>(),
|
|
31
|
+
}>
|
|
32
|
+
>(),
|
|
32
33
|
{},
|
|
33
34
|
);
|
|
34
35
|
|
|
@@ -41,7 +42,9 @@ const codeConfig = computed(() => ({
|
|
|
41
42
|
items: [
|
|
42
43
|
{
|
|
43
44
|
type: 'code-select-col',
|
|
45
|
+
name: 'codeId',
|
|
44
46
|
labelWidth: 0,
|
|
47
|
+
disabled: () => !services?.codeBlockService.getEditStatus(),
|
|
45
48
|
},
|
|
46
49
|
],
|
|
47
50
|
}));
|