@tmagic/editor 1.3.0-alpha.2 → 1.3.0-alpha.21
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 +91 -120
- package/dist/tmagic-editor.js +4609 -3257
- package/dist/tmagic-editor.js.map +1 -1
- package/dist/tmagic-editor.umd.cjs +5708 -4337
- package/dist/tmagic-editor.umd.cjs.map +1 -1
- package/package.json +21 -22
- package/src/Editor.vue +29 -7
- package/src/components/CodeBlockEditor.vue +170 -0
- package/src/components/CodeParams.vue +60 -0
- package/src/components/ContentMenu.vue +30 -11
- package/src/components/Icon.vue +5 -1
- package/src/components/Resizer.vue +45 -0
- package/src/components/ScrollBar.vue +5 -1
- package/src/components/ScrollViewer.vue +5 -1
- package/src/components/SearchInput.vue +4 -0
- package/src/components/{Layout.vue → SplitView.vue} +8 -4
- package/src/components/ToolButton.vue +5 -1
- package/src/editorProps.ts +35 -4
- package/src/fields/Code.vue +28 -20
- package/src/fields/CodeLink.vue +15 -10
- package/src/fields/CodeSelect.vue +19 -10
- package/src/fields/CodeSelectCol.vue +67 -83
- package/src/fields/DataSourceFieldSelect.vue +47 -0
- package/src/fields/DataSourceFields.vue +24 -21
- package/src/fields/DataSourceInput.vue +318 -0
- package/src/fields/DataSourceMethodSelect.vue +136 -0
- package/src/fields/DataSourceMethods.vue +103 -0
- package/src/fields/DataSourceSelect.vue +68 -0
- package/src/fields/EventSelect.vue +62 -22
- package/src/fields/KeyValue.vue +13 -11
- package/src/fields/UISelect.vue +59 -15
- 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/AppManageIcon.vue +5 -1
- package/src/icons/CenterIcon.vue +13 -0
- package/src/icons/CodeIcon.vue +5 -3
- package/src/index.ts +24 -3
- package/src/initService.ts +75 -16
- package/src/layouts/AddPageBox.vue +5 -1
- package/src/layouts/CodeEditor.vue +66 -11
- package/src/layouts/Framework.vue +32 -28
- package/src/layouts/NavMenu.vue +5 -1
- package/src/layouts/PropsPanel.vue +14 -4
- package/src/layouts/sidebar/ComponentListPanel.vue +11 -10
- package/src/layouts/sidebar/LayerMenu.vue +13 -25
- package/src/layouts/sidebar/LayerNode.vue +40 -0
- package/src/layouts/sidebar/LayerPanel.vue +71 -28
- package/src/layouts/sidebar/Sidebar.vue +13 -17
- package/src/layouts/sidebar/code-block/CodeBlockList.vue +84 -118
- package/src/layouts/sidebar/code-block/CodeBlockListPanel.vue +63 -0
- package/src/layouts/sidebar/data-source/DataSourceConfigPanel.vue +39 -34
- package/src/layouts/sidebar/data-source/DataSourceList.vue +145 -0
- package/src/layouts/sidebar/data-source/DataSourceListPanel.vue +17 -65
- package/src/layouts/workspace/Breadcrumb.vue +5 -1
- package/src/layouts/workspace/PageBar.vue +5 -1
- package/src/layouts/workspace/PageBarScrollContainer.vue +5 -1
- package/src/layouts/workspace/Stage.vue +30 -8
- package/src/layouts/workspace/ViewerMenu.vue +15 -36
- package/src/layouts/workspace/Workspace.vue +9 -134
- package/src/services/codeBlock.ts +20 -72
- package/src/services/dataSource.ts +17 -2
- package/src/services/dep.ts +23 -20
- package/src/services/editor.ts +3 -3
- package/src/services/keybinding.ts +185 -0
- package/src/services/props.ts +2 -2
- package/src/services/storage.ts +3 -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-input.scss +18 -0
- package/src/theme/data-source-methods.scss +13 -0
- package/src/theme/event.scss +15 -12
- package/src/theme/framework.scss +0 -3
- package/src/theme/layer-panel.scss +6 -0
- package/src/theme/layout.scss +4 -0
- package/src/theme/resizer.scss +25 -10
- package/src/theme/stage.scss +4 -0
- package/src/theme/theme.scss +2 -0
- package/src/type.ts +105 -7
- package/src/utils/config.ts +1 -1
- package/src/utils/content-menu.ts +92 -0
- package/src/utils/data-source/formConfigs/base.ts +35 -30
- package/src/utils/data-source/index.ts +75 -6
- package/src/utils/dep.ts +39 -7
- package/src/utils/index.ts +1 -1
- package/src/utils/keybinding-config.ts +120 -0
- package/src/utils/props.ts +298 -155
- package/src/utils/undo-redo.ts +1 -1
- package/types/Editor.vue.d.ts +37 -4
- 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 +8 -3
- package/types/components/Icon.vue.d.ts +2 -2
- package/types/{layouts → components}/Resizer.vue.d.ts +2 -2
- package/types/components/ScrollBar.vue.d.ts +1 -1
- package/types/components/ScrollViewer.vue.d.ts +8 -5
- package/types/components/SearchInput.vue.d.ts +1 -1
- package/types/components/{Layout.vue.d.ts → SplitView.vue.d.ts} +9 -6
- package/types/components/ToolButton.vue.d.ts +10 -7
- package/types/editorProps.d.ts +23 -4
- package/types/fields/Code.vue.d.ts +23 -18
- package/types/fields/CodeLink.vue.d.ts +13 -22
- package/types/fields/CodeSelect.vue.d.ts +12 -20
- package/types/fields/CodeSelectCol.vue.d.ts +14 -15
- package/types/fields/DataSourceFieldSelect.vue.d.ts +29 -0
- package/types/fields/DataSourceFields.vue.d.ts +13 -21
- package/types/fields/DataSourceInput.vue.d.ts +34 -0
- 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 +40 -0
- package/types/fields/EventSelect.vue.d.ts +3 -14
- package/types/fields/KeyValue.vue.d.ts +15 -27
- package/types/fields/UISelect.vue.d.ts +3 -12
- package/types/hooks/index.d.ts +3 -0
- package/types/hooks/use-code-block-edit.d.ts +125 -0
- package/types/hooks/use-data-source-method.d.ts +123 -0
- package/types/icons/AppManageIcon.vue.d.ts +1 -1
- package/types/icons/CenterIcon.vue.d.ts +2 -0
- package/types/icons/CodeIcon.vue.d.ts +1 -1
- package/types/index.d.ts +12 -2
- package/types/initService.d.ts +2 -2
- package/types/layouts/AddPageBox.vue.d.ts +1 -1
- package/types/layouts/CodeEditor.vue.d.ts +18 -10
- package/types/layouts/Framework.vue.d.ts +11 -32
- package/types/layouts/NavMenu.vue.d.ts +7 -4
- package/types/layouts/PropsPanel.vue.d.ts +276 -4
- package/types/layouts/sidebar/ComponentListPanel.vue.d.ts +4 -4
- package/types/layouts/sidebar/LayerMenu.vue.d.ts +2 -2
- package/types/layouts/sidebar/LayerNode.vue.d.ts +16 -0
- package/types/layouts/sidebar/LayerPanel.vue.d.ts +5 -5
- package/types/layouts/sidebar/Sidebar.vue.d.ts +16 -16
- package/types/layouts/sidebar/code-block/CodeBlockList.vue.d.ts +7 -12
- package/types/layouts/sidebar/code-block/CodeBlockListPanel.vue.d.ts +28 -0
- package/types/layouts/sidebar/data-source/DataSourceConfigPanel.vue.d.ts +4 -2
- 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/layouts/workspace/Breadcrumb.vue.d.ts +1 -1
- package/types/layouts/workspace/PageBar.vue.d.ts +5 -5
- package/types/layouts/workspace/PageBarScrollContainer.vue.d.ts +2 -2
- package/types/layouts/workspace/Stage.vue.d.ts +2 -2
- package/types/layouts/workspace/ViewerMenu.vue.d.ts +7 -4
- package/types/layouts/workspace/Workspace.vue.d.ts +9 -9
- 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/keybinding.d.ts +20 -0
- package/types/services/props.d.ts +10 -115
- package/types/type.d.ts +97 -7
- package/types/utils/config.d.ts +1 -1
- package/types/utils/content-menu.d.ts +7 -0
- package/types/utils/data-source/formConfigs/base.d.ts +2 -2
- package/types/utils/data-source/index.d.ts +7 -1
- package/types/utils/dep.d.ts +4 -2
- package/types/utils/index.d.ts +1 -1
- package/types/utils/keybinding-config.d.ts +3 -0
- package/types/utils/props.d.ts +13 -102
- package/src/components/CodeDraftEditor.vue +0 -144
- package/src/components/FunctionEditor.vue +0 -190
- package/src/layouts/Resizer.vue +0 -32
- package/src/layouts/sidebar/code-block/CodeBlockEditor.vue +0 -96
- package/types/components/CodeDraftEditor.vue.d.ts +0 -58
- package/types/components/FunctionEditor.vue.d.ts +0 -192
- package/types/layouts/sidebar/code-block/CodeBlockEditor.vue.d.ts +0 -25
- /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-alpha.
|
|
2
|
+
"version": "1.3.0-alpha.21",
|
|
3
3
|
"name": "@tmagic/editor",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": [
|
|
@@ -46,43 +46,42 @@
|
|
|
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.21",
|
|
50
|
+
"@tmagic/design": "1.3.0-alpha.21",
|
|
51
|
+
"@tmagic/form": "1.3.0-alpha.21",
|
|
52
|
+
"@tmagic/schema": "1.3.0-alpha.21",
|
|
53
|
+
"@tmagic/stage": "1.3.0-alpha.21",
|
|
54
|
+
"@tmagic/table": "1.3.0-alpha.21",
|
|
55
|
+
"@tmagic/utils": "1.3.0-alpha.21",
|
|
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
|
-
"vue": "^3.
|
|
64
|
+
"vue": "^3.3.4"
|
|
65
65
|
},
|
|
66
66
|
"peerDependencies": {
|
|
67
|
-
"@tmagic/design": "1.3.0-alpha.
|
|
68
|
-
"@tmagic/form": "1.3.0-alpha.
|
|
69
|
-
"monaco-editor": "^0.
|
|
70
|
-
"vue": "^3.
|
|
67
|
+
"@tmagic/design": "1.3.0-alpha.21",
|
|
68
|
+
"@tmagic/form": "1.3.0-alpha.21",
|
|
69
|
+
"monaco-editor": "^0.41.0",
|
|
70
|
+
"vue": "^3.3.4"
|
|
71
71
|
},
|
|
72
72
|
"devDependencies": {
|
|
73
73
|
"@types/events": "^3.0.0",
|
|
74
74
|
"@types/lodash-es": "^4.17.4",
|
|
75
75
|
"@types/node": "^15.12.4",
|
|
76
76
|
"@types/serialize-javascript": "^5.0.1",
|
|
77
|
-
"@vitejs/plugin-vue": "^4.
|
|
78
|
-
"@vue/compiler-sfc": "^3.
|
|
79
|
-
"@vue/test-utils": "^2.
|
|
77
|
+
"@vitejs/plugin-vue": "^4.2.3",
|
|
78
|
+
"@vue/compiler-sfc": "^3.3.4",
|
|
79
|
+
"@vue/test-utils": "^2.3.2",
|
|
80
80
|
"rimraf": "^3.0.2",
|
|
81
81
|
"sass": "^1.35.1",
|
|
82
82
|
"tsc-alias": "^1.8.5",
|
|
83
83
|
"typescript": "^5.0.4",
|
|
84
|
-
"vite": "^4.
|
|
85
|
-
"
|
|
86
|
-
"vue-tsc": "^1.0.11"
|
|
84
|
+
"vite": "^4.4.4",
|
|
85
|
+
"vue-tsc": "^1.6.5"
|
|
87
86
|
}
|
|
88
87
|
}
|
package/src/Editor.vue
CHANGED
|
@@ -1,9 +1,19 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<Framework
|
|
2
|
+
<Framework>
|
|
3
|
+
<template #header>
|
|
4
|
+
<slot name="header"></slot>
|
|
5
|
+
</template>
|
|
6
|
+
|
|
3
7
|
<template #nav>
|
|
4
8
|
<slot name="nav" :editorService="editorService"><TMagicNavMenu :data="menu"></TMagicNavMenu></slot>
|
|
5
9
|
</template>
|
|
6
10
|
|
|
11
|
+
<template #content-before>
|
|
12
|
+
<slot name="content-before"></slot>
|
|
13
|
+
</template>
|
|
14
|
+
|
|
15
|
+
<template #src-code><slot name="src-code" :editorService="editorService"></slot></template>
|
|
16
|
+
|
|
7
17
|
<template #sidebar>
|
|
8
18
|
<slot name="sidebar" :editorService="editorService">
|
|
9
19
|
<Sidebar :data="sidebar" :layer-content-menu="layerContentMenu">
|
|
@@ -30,10 +40,6 @@
|
|
|
30
40
|
<template #code-block-panel-tool="{ id, data }">
|
|
31
41
|
<slot name="code-block-panel-tool" :id="id" :data="data"></slot>
|
|
32
42
|
</template>
|
|
33
|
-
|
|
34
|
-
<template #code-block-edit-panel-header="{ id }">
|
|
35
|
-
<slot name="code-block-edit-panel-header" :id="id"></slot>
|
|
36
|
-
</template>
|
|
37
43
|
</Sidebar>
|
|
38
44
|
</slot>
|
|
39
45
|
</template>
|
|
@@ -51,7 +57,10 @@
|
|
|
51
57
|
|
|
52
58
|
<template #props-panel>
|
|
53
59
|
<slot name="props-panel">
|
|
54
|
-
<PropsPanel
|
|
60
|
+
<PropsPanel
|
|
61
|
+
:extend-state="extendFormState"
|
|
62
|
+
@mounted="(instance: any) => $emit('props-panel-mounted', instance)"
|
|
63
|
+
>
|
|
55
64
|
<template #props-panel-header>
|
|
56
65
|
<slot name="props-panel-header"></slot>
|
|
57
66
|
</template>
|
|
@@ -60,6 +69,14 @@
|
|
|
60
69
|
</template>
|
|
61
70
|
|
|
62
71
|
<template #empty><slot name="empty" :editorService="editorService"></slot></template>
|
|
72
|
+
|
|
73
|
+
<template #content-after>
|
|
74
|
+
<slot name="content-after"></slot>
|
|
75
|
+
</template>
|
|
76
|
+
|
|
77
|
+
<template #footer>
|
|
78
|
+
<slot name="footer"></slot>
|
|
79
|
+
</template>
|
|
63
80
|
</Framework>
|
|
64
81
|
</template>
|
|
65
82
|
|
|
@@ -78,15 +95,17 @@ import depService from './services/dep';
|
|
|
78
95
|
import editorService from './services/editor';
|
|
79
96
|
import eventsService from './services/events';
|
|
80
97
|
import historyService from './services/history';
|
|
98
|
+
import keybindingService from './services/keybinding';
|
|
81
99
|
import propsService from './services/props';
|
|
82
100
|
import storageService from './services/storage';
|
|
83
101
|
import uiService from './services/ui';
|
|
102
|
+
import keybindingConfig from './utils/keybinding-config';
|
|
84
103
|
import editorProps from './editorProps';
|
|
85
104
|
import { initServiceEvents, initServiceState } from './initService';
|
|
86
105
|
import type { Services } from './type';
|
|
87
106
|
|
|
88
107
|
export default defineComponent({
|
|
89
|
-
name: '
|
|
108
|
+
name: 'MEditor',
|
|
90
109
|
|
|
91
110
|
components: {
|
|
92
111
|
TMagicNavMenu: NavMenu,
|
|
@@ -112,10 +131,13 @@ export default defineComponent({
|
|
|
112
131
|
codeBlockService,
|
|
113
132
|
depService,
|
|
114
133
|
dataSourceService,
|
|
134
|
+
keybindingService,
|
|
115
135
|
};
|
|
116
136
|
|
|
117
137
|
initServiceEvents(props, emit, services);
|
|
118
138
|
initServiceState(props, services);
|
|
139
|
+
keybindingService.registe(keybindingConfig);
|
|
140
|
+
keybindingService.registeEl('global');
|
|
119
141
|
|
|
120
142
|
provide('services', services);
|
|
121
143
|
|
|
@@ -0,0 +1,170 @@
|
|
|
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
|
+
@submit="submitForm"
|
|
13
|
+
@error="errorHandler"
|
|
14
|
+
@open="openHandler"
|
|
15
|
+
></MFormDrawer>
|
|
16
|
+
</template>
|
|
17
|
+
|
|
18
|
+
<script lang="ts" setup>
|
|
19
|
+
import { computed, inject, ref } from 'vue';
|
|
20
|
+
|
|
21
|
+
import { tMagicMessage } from '@tmagic/design';
|
|
22
|
+
import { ColumnConfig, FormState, MFormDrawer } from '@tmagic/form';
|
|
23
|
+
import type { CodeBlockContent } from '@tmagic/schema';
|
|
24
|
+
|
|
25
|
+
import type { Services } from '@editor/type';
|
|
26
|
+
import { getConfig } from '@editor/utils/config';
|
|
27
|
+
|
|
28
|
+
defineOptions({
|
|
29
|
+
name: 'MEditorCodeBlockEditor',
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
const props = defineProps<{
|
|
33
|
+
content: CodeBlockContent;
|
|
34
|
+
disabled?: boolean;
|
|
35
|
+
isDataSource?: boolean;
|
|
36
|
+
}>();
|
|
37
|
+
|
|
38
|
+
const emit = defineEmits<{
|
|
39
|
+
submit: [values: CodeBlockContent];
|
|
40
|
+
}>();
|
|
41
|
+
|
|
42
|
+
const services = inject<Services>('services');
|
|
43
|
+
|
|
44
|
+
const columnWidth = computed(() => services?.uiService.get('columnWidth'));
|
|
45
|
+
const size = computed(() =>
|
|
46
|
+
columnWidth.value ? columnWidth.value.center + columnWidth.value.right - (props.isDataSource ? 100 : 0) : 600,
|
|
47
|
+
);
|
|
48
|
+
|
|
49
|
+
const codeEditorHeight = ref('600px');
|
|
50
|
+
|
|
51
|
+
const defaultParamColConfig: ColumnConfig = {
|
|
52
|
+
type: 'row',
|
|
53
|
+
label: '参数类型',
|
|
54
|
+
items: [
|
|
55
|
+
{
|
|
56
|
+
text: '参数类型',
|
|
57
|
+
labelWidth: '70px',
|
|
58
|
+
type: 'select',
|
|
59
|
+
name: 'type',
|
|
60
|
+
options: [
|
|
61
|
+
{
|
|
62
|
+
text: '数字',
|
|
63
|
+
label: '数字',
|
|
64
|
+
value: 'number',
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
text: '字符串',
|
|
68
|
+
label: '字符串',
|
|
69
|
+
value: 'text',
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
text: '组件',
|
|
73
|
+
label: '组件',
|
|
74
|
+
value: 'ui-select',
|
|
75
|
+
},
|
|
76
|
+
],
|
|
77
|
+
},
|
|
78
|
+
],
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
const functionConfig = computed(() => [
|
|
82
|
+
{
|
|
83
|
+
text: '名称',
|
|
84
|
+
name: 'name',
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
text: '描述',
|
|
88
|
+
name: 'desc',
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
text: '执行时机',
|
|
92
|
+
name: 'timing',
|
|
93
|
+
type: 'select',
|
|
94
|
+
options: [
|
|
95
|
+
{ text: '初始化前', value: 'beforeInit' },
|
|
96
|
+
{ text: '初始化后', value: 'afterInit' },
|
|
97
|
+
],
|
|
98
|
+
display: () => props.isDataSource,
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
type: 'table',
|
|
102
|
+
border: true,
|
|
103
|
+
text: '参数',
|
|
104
|
+
enableFullscreen: false,
|
|
105
|
+
enableToggleMode: false,
|
|
106
|
+
name: 'params',
|
|
107
|
+
dropSort: false,
|
|
108
|
+
items: [
|
|
109
|
+
{
|
|
110
|
+
type: 'text',
|
|
111
|
+
label: '参数名',
|
|
112
|
+
name: 'name',
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
type: 'text',
|
|
116
|
+
label: '描述',
|
|
117
|
+
name: 'extra',
|
|
118
|
+
},
|
|
119
|
+
services?.codeBlockService.getParamsColConfig() || defaultParamColConfig,
|
|
120
|
+
],
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
name: 'content',
|
|
124
|
+
type: 'vs-code',
|
|
125
|
+
options: inject('codeOptions', {}),
|
|
126
|
+
height: codeEditorHeight.value,
|
|
127
|
+
onChange: (formState: FormState | undefined, code: string) => {
|
|
128
|
+
try {
|
|
129
|
+
// 检测js代码是否存在语法错误
|
|
130
|
+
getConfig('parseDSL')(code);
|
|
131
|
+
|
|
132
|
+
return code;
|
|
133
|
+
} catch (error: any) {
|
|
134
|
+
tMagicMessage.error(error.message);
|
|
135
|
+
|
|
136
|
+
throw error;
|
|
137
|
+
}
|
|
138
|
+
},
|
|
139
|
+
},
|
|
140
|
+
]);
|
|
141
|
+
|
|
142
|
+
const submitForm = async (values: CodeBlockContent) => {
|
|
143
|
+
emit('submit', values);
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
const errorHandler = (error: any) => {
|
|
147
|
+
tMagicMessage.error(error.message);
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
const fomDrawer = ref<InstanceType<typeof MFormDrawer>>();
|
|
151
|
+
|
|
152
|
+
const openHandler = () => {
|
|
153
|
+
setTimeout(() => {
|
|
154
|
+
if (fomDrawer.value) {
|
|
155
|
+
const height = fomDrawer.value?.bodyHeight - 348 - (props.isDataSource ? 50 : 0);
|
|
156
|
+
codeEditorHeight.value = `${height > 100 ? height : 600}px`;
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
defineExpose({
|
|
162
|
+
show() {
|
|
163
|
+
fomDrawer.value?.show();
|
|
164
|
+
},
|
|
165
|
+
|
|
166
|
+
hide() {
|
|
167
|
+
fomDrawer.value?.hide();
|
|
168
|
+
},
|
|
169
|
+
});
|
|
170
|
+
</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,14 +4,16 @@
|
|
|
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">
|
|
14
15
|
<content-menu
|
|
16
|
+
v-if="subMenuData.length"
|
|
15
17
|
class="sub-menu"
|
|
16
18
|
ref="subMenu"
|
|
17
19
|
:menu-data="subMenuData"
|
|
@@ -22,13 +24,17 @@
|
|
|
22
24
|
</div>
|
|
23
25
|
</template>
|
|
24
26
|
|
|
25
|
-
<script lang="ts" setup
|
|
27
|
+
<script lang="ts" setup>
|
|
26
28
|
import { nextTick, onMounted, onUnmounted, ref } from 'vue';
|
|
27
29
|
|
|
28
30
|
import { MenuButton, MenuComponent } from '@editor/type';
|
|
29
31
|
|
|
30
32
|
import ToolButton from './ToolButton.vue';
|
|
31
33
|
|
|
34
|
+
defineOptions({
|
|
35
|
+
name: 'MEditorContentMenu',
|
|
36
|
+
});
|
|
37
|
+
|
|
32
38
|
const props = withDefaults(
|
|
33
39
|
defineProps<{
|
|
34
40
|
menuData?: (MenuButton | MenuComponent)[];
|
|
@@ -43,6 +49,7 @@ const props = withDefaults(
|
|
|
43
49
|
const emit = defineEmits(['hide', 'show']);
|
|
44
50
|
|
|
45
51
|
const menu = ref<HTMLDivElement>();
|
|
52
|
+
const buttons = ref<InstanceType<typeof ToolButton>[]>();
|
|
46
53
|
const subMenu = ref<any>();
|
|
47
54
|
const visible = ref(false);
|
|
48
55
|
const subMenuData = ref<(MenuButton | MenuComponent)[]>([]);
|
|
@@ -51,6 +58,8 @@ const menuStyle = ref({
|
|
|
51
58
|
top: '0',
|
|
52
59
|
});
|
|
53
60
|
|
|
61
|
+
const contains = (el: HTMLElement) => menu.value?.contains(el) || subMenu.value?.contains(el);
|
|
62
|
+
|
|
54
63
|
const hide = () => {
|
|
55
64
|
if (!visible.value) return;
|
|
56
65
|
|
|
@@ -65,7 +74,7 @@ const hideHandler = (e: MouseEvent) => {
|
|
|
65
74
|
if (!visible.value || !target) {
|
|
66
75
|
return;
|
|
67
76
|
}
|
|
68
|
-
if (
|
|
77
|
+
if (contains(target)) {
|
|
69
78
|
return;
|
|
70
79
|
}
|
|
71
80
|
hide();
|
|
@@ -94,19 +103,27 @@ const show = (e: MouseEvent) => {
|
|
|
94
103
|
}, 300);
|
|
95
104
|
};
|
|
96
105
|
|
|
97
|
-
const showSubMenu = (item: MenuButton | MenuComponent) => {
|
|
106
|
+
const showSubMenu = (item: MenuButton | MenuComponent, index: number) => {
|
|
98
107
|
const menuItem = item as MenuButton;
|
|
99
108
|
if (typeof item !== 'object' || !menuItem.items?.length) {
|
|
100
109
|
return;
|
|
101
110
|
}
|
|
102
111
|
|
|
103
|
-
subMenuData.value = menuItem.items;
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
112
|
+
subMenuData.value = menuItem.items || [];
|
|
113
|
+
setTimeout(() => {
|
|
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
|
+
}
|
|
121
|
+
subMenu.value?.show({
|
|
122
|
+
clientX: menu.value.offsetLeft + menu.value.clientWidth,
|
|
123
|
+
clientY: y,
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
}, 0);
|
|
110
127
|
};
|
|
111
128
|
|
|
112
129
|
onMounted(() => {
|
|
@@ -122,7 +139,9 @@ onUnmounted(() => {
|
|
|
122
139
|
});
|
|
123
140
|
|
|
124
141
|
defineExpose({
|
|
142
|
+
menu,
|
|
125
143
|
hide,
|
|
126
144
|
show,
|
|
145
|
+
contains,
|
|
127
146
|
});
|
|
128
147
|
</script>
|
package/src/components/Icon.vue
CHANGED
|
@@ -7,12 +7,16 @@
|
|
|
7
7
|
<TMagicIcon v-else class="magic-editor-icon"><component :is="toRaw(icon)"></component></TMagicIcon>
|
|
8
8
|
</template>
|
|
9
9
|
|
|
10
|
-
<script lang="ts" setup
|
|
10
|
+
<script lang="ts" setup>
|
|
11
11
|
import { toRaw } from 'vue';
|
|
12
12
|
import { Edit } from '@element-plus/icons-vue';
|
|
13
13
|
|
|
14
14
|
import { TMagicIcon } from '@tmagic/design';
|
|
15
15
|
|
|
16
|
+
defineOptions({
|
|
17
|
+
name: 'MEditorIcon',
|
|
18
|
+
});
|
|
19
|
+
|
|
16
20
|
defineProps<{
|
|
17
21
|
icon?: any;
|
|
18
22
|
}>();
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<span ref="target" class="m-editor-resizer" :class="{ 'm-editor-resizer-draging': isDraging }">
|
|
3
|
+
<slot></slot>
|
|
4
|
+
</span>
|
|
5
|
+
</template>
|
|
6
|
+
|
|
7
|
+
<script lang="ts" setup>
|
|
8
|
+
import { onMounted, onUnmounted, ref } from 'vue';
|
|
9
|
+
import Gesto from 'gesto';
|
|
10
|
+
|
|
11
|
+
defineOptions({
|
|
12
|
+
name: 'MEditorResizer',
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
const emit = defineEmits(['change']);
|
|
16
|
+
|
|
17
|
+
const target = ref<HTMLSpanElement>();
|
|
18
|
+
const isDraging = ref(false);
|
|
19
|
+
|
|
20
|
+
let getso: Gesto;
|
|
21
|
+
|
|
22
|
+
onMounted(() => {
|
|
23
|
+
if (!target.value) return;
|
|
24
|
+
getso = new Gesto(target.value, {
|
|
25
|
+
container: window,
|
|
26
|
+
pinchOutside: true,
|
|
27
|
+
})
|
|
28
|
+
.on('drag', (e) => {
|
|
29
|
+
if (!target.value) return;
|
|
30
|
+
|
|
31
|
+
emit('change', e.deltaX);
|
|
32
|
+
})
|
|
33
|
+
.on('dragStart', () => {
|
|
34
|
+
isDraging.value = true;
|
|
35
|
+
})
|
|
36
|
+
.on('dragEnd', () => {
|
|
37
|
+
isDraging.value = false;
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
onUnmounted(() => {
|
|
42
|
+
getso?.unset();
|
|
43
|
+
isDraging.value = false;
|
|
44
|
+
});
|
|
45
|
+
</script>
|
|
@@ -4,10 +4,14 @@
|
|
|
4
4
|
</div>
|
|
5
5
|
</template>
|
|
6
6
|
|
|
7
|
-
<script lang="ts" setup
|
|
7
|
+
<script lang="ts" setup>
|
|
8
8
|
import { computed, onMounted, onUnmounted, ref } from 'vue';
|
|
9
9
|
import Gesto from 'gesto';
|
|
10
10
|
|
|
11
|
+
defineOptions({
|
|
12
|
+
name: 'MEditorScrollBar',
|
|
13
|
+
});
|
|
14
|
+
|
|
11
15
|
const props = defineProps<{
|
|
12
16
|
size: number;
|
|
13
17
|
scrollSize: number;
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
</div>
|
|
23
23
|
</template>
|
|
24
24
|
|
|
25
|
-
<script lang="ts" setup
|
|
25
|
+
<script lang="ts" setup>
|
|
26
26
|
import { computed, onMounted, onUnmounted, ref, watch } from 'vue';
|
|
27
27
|
|
|
28
28
|
import type { ScrollViewerEvent } from '@editor/type';
|
|
@@ -30,6 +30,10 @@ import { ScrollViewer } from '@editor/utils/scroll-viewer';
|
|
|
30
30
|
|
|
31
31
|
import ScrollBar from './ScrollBar.vue';
|
|
32
32
|
|
|
33
|
+
defineOptions({
|
|
34
|
+
name: 'MEditorScrollViewer',
|
|
35
|
+
});
|
|
36
|
+
|
|
33
37
|
const props = withDefaults(
|
|
34
38
|
defineProps<{
|
|
35
39
|
width?: number;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<template>
|
|
2
2
|
<div ref="el" class="m-editor-layout">
|
|
3
|
-
<template v-if="hasLeft">
|
|
3
|
+
<template v-if="hasLeft && $slots.left">
|
|
4
4
|
<div class="m-editor-layout-left" :class="leftClass" :style="`width: ${left}px`">
|
|
5
5
|
<slot name="left"></slot>
|
|
6
6
|
</div>
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
<slot name="center"></slot>
|
|
12
12
|
</div>
|
|
13
13
|
|
|
14
|
-
<template v-if="hasRight">
|
|
14
|
+
<template v-if="hasRight && $slots.right">
|
|
15
15
|
<Resizer @change="changeRight"></Resizer>
|
|
16
16
|
<div class="m-editor-layout-right" :class="rightClass" :style="`width: ${right}px`">
|
|
17
17
|
<slot name="right"></slot>
|
|
@@ -20,10 +20,14 @@
|
|
|
20
20
|
</div>
|
|
21
21
|
</template>
|
|
22
22
|
|
|
23
|
-
<script lang="ts" setup
|
|
23
|
+
<script lang="ts" setup>
|
|
24
24
|
import { computed, onMounted, onUnmounted, ref } from 'vue';
|
|
25
25
|
|
|
26
|
-
import Resizer from '
|
|
26
|
+
import Resizer from './Resizer.vue';
|
|
27
|
+
|
|
28
|
+
defineOptions({
|
|
29
|
+
name: 'MEditorLayout',
|
|
30
|
+
});
|
|
27
31
|
|
|
28
32
|
const emit = defineEmits(['update:left', 'change', 'update:right']);
|
|
29
33
|
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
</div>
|
|
44
44
|
</template>
|
|
45
45
|
|
|
46
|
-
<script lang="ts" setup
|
|
46
|
+
<script lang="ts" setup>
|
|
47
47
|
import { computed, inject } from 'vue';
|
|
48
48
|
import { ArrowDown } from '@element-plus/icons-vue';
|
|
49
49
|
|
|
@@ -60,6 +60,10 @@ import {
|
|
|
60
60
|
import MIcon from '../components/Icon.vue';
|
|
61
61
|
import type { MenuButton, MenuComponent, Services } from '../type';
|
|
62
62
|
|
|
63
|
+
defineOptions({
|
|
64
|
+
name: 'MEditorToolButton',
|
|
65
|
+
});
|
|
66
|
+
|
|
63
67
|
const props = withDefaults(
|
|
64
68
|
defineProps<{
|
|
65
69
|
data?: MenuButton | MenuComponent;
|