@tmagic/editor 1.0.0-rc.1 → 1.0.0-rc.4
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/coverage/clover.xml +476 -443
- package/coverage/coverage-final.json +10 -10
- package/coverage/lcov-report/index.html +55 -55
- package/coverage/lcov-report/src/Editor.vue.html +36 -9
- package/coverage/lcov-report/src/components/ContentMenu.vue.html +11 -11
- package/coverage/lcov-report/src/components/Icon.vue.html +2 -2
- package/coverage/lcov-report/src/components/ScrollViewer.vue.html +1 -1
- package/coverage/lcov-report/src/components/ToolButton.vue.html +25 -25
- package/coverage/lcov-report/src/components/index.html +5 -5
- package/coverage/lcov-report/src/index.html +14 -14
- package/coverage/lcov-report/src/layouts/AddPageBox.vue.html +1 -1
- package/coverage/lcov-report/src/layouts/Framework.vue.html +48 -9
- package/coverage/lcov-report/src/layouts/NavMenu.vue.html +1 -1
- package/coverage/lcov-report/src/layouts/PropsPanel.vue.html +2 -2
- package/coverage/lcov-report/src/layouts/Resizer.vue.html +1 -1
- package/coverage/lcov-report/src/layouts/index.html +15 -15
- package/coverage/lcov-report/src/layouts/sidebar/ComponentListPanel.vue.html +1 -1
- package/coverage/lcov-report/src/layouts/sidebar/LayerMenu.vue.html +17 -17
- package/coverage/lcov-report/src/layouts/sidebar/LayerPanel.vue.html +1 -1
- package/coverage/lcov-report/src/layouts/sidebar/Sidebar.vue.html +1 -1
- package/coverage/lcov-report/src/layouts/sidebar/TabPane.vue.html +2 -2
- package/coverage/lcov-report/src/layouts/sidebar/index.html +19 -19
- package/coverage/lcov-report/src/layouts/workspace/PageBar.vue.html +1 -1
- package/coverage/lcov-report/src/layouts/workspace/Stage.vue.html +13 -4
- package/coverage/lcov-report/src/layouts/workspace/ViewerMenu.vue.html +69 -33
- package/coverage/lcov-report/src/layouts/workspace/Workspace.vue.html +73 -10
- package/coverage/lcov-report/src/layouts/workspace/index.html +32 -32
- package/coverage/lcov-report/src/services/BaseService.ts.html +2 -2
- package/coverage/lcov-report/src/services/componentList.ts.html +1 -1
- package/coverage/lcov-report/src/services/editor.ts.html +100 -10
- package/coverage/lcov-report/src/services/events.ts.html +1 -1
- package/coverage/lcov-report/src/services/history.ts.html +1 -1
- package/coverage/lcov-report/src/services/index.html +15 -15
- package/coverage/lcov-report/src/services/props.ts.html +1 -1
- package/coverage/lcov-report/src/services/ui.ts.html +1 -1
- package/coverage/lcov-report/src/type.ts.html +1 -1
- package/coverage/lcov-report/src/utils/compose.ts.html +1 -1
- package/coverage/lcov-report/src/utils/config.ts.html +1 -1
- package/coverage/lcov-report/src/utils/editor.ts.html +1 -1
- package/coverage/lcov-report/src/utils/index.html +1 -1
- package/coverage/lcov-report/src/utils/index.ts.html +1 -1
- package/coverage/lcov-report/src/utils/logger.ts.html +1 -1
- package/coverage/lcov-report/src/utils/props.ts.html +1 -1
- package/coverage/lcov-report/src/utils/scroll-viewer.ts.html +1 -1
- package/coverage/lcov-report/src/utils/undo-redo.ts.html +1 -1
- package/coverage/lcov.info +1203 -1065
- package/dist/style.css +3 -3
- package/dist/tmagic-editor.es.js +86 -1233
- package/dist/tmagic-editor.es.js.map +1 -1
- package/dist/tmagic-editor.umd.js +87 -1234
- package/dist/tmagic-editor.umd.js.map +1 -1
- package/dist/types/src/Editor.vue.d.ts +14 -0
- package/dist/types/src/layouts/Framework.vue.d.ts +15 -3
- package/dist/types/src/layouts/workspace/Workspace.vue.d.ts +5 -1
- package/dist/types/src/services/BaseService.d.ts +1 -1
- package/package.json +16 -8
- package/src/Editor.vue +10 -1
- package/src/components/ContentMenu.vue +1 -1
- package/src/layouts/CodeEditor.vue +1 -4
- package/src/layouts/Framework.vue +14 -1
- package/src/layouts/PropsPanel.vue +1 -1
- package/src/layouts/sidebar/TabPane.vue +1 -1
- package/src/layouts/workspace/Stage.vue +3 -0
- package/src/layouts/workspace/ViewerMenu.vue +14 -2
- package/src/layouts/workspace/Workspace.vue +21 -0
- package/src/services/BaseService.ts +1 -1
- package/src/services/editor.ts +31 -1
- package/src/theme/props-panel.scss +6 -4
- package/src/utils/polyfills.ts +5 -19
|
@@ -34,6 +34,8 @@ declare const _default: DefineComponent<{
|
|
|
34
34
|
};
|
|
35
35
|
/** 中间工作区域中画布通过iframe渲染时的页面url */
|
|
36
36
|
runtimeUrl: StringConstructor;
|
|
37
|
+
/** 选中时是否自动滚动到可视区域 */
|
|
38
|
+
autoScrollIntoView: BooleanConstructor;
|
|
37
39
|
/** 组件的属性配置表单的dsl */
|
|
38
40
|
propsConfigs: {
|
|
39
41
|
type: PropType<Record<string, FormConfig>>;
|
|
@@ -63,6 +65,10 @@ declare const _default: DefineComponent<{
|
|
|
63
65
|
stageRect: {
|
|
64
66
|
type: PropType<StageRect>;
|
|
65
67
|
};
|
|
68
|
+
codeOptions: {
|
|
69
|
+
type: ObjectConstructor;
|
|
70
|
+
default: () => {};
|
|
71
|
+
};
|
|
66
72
|
}, Services, unknown, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, ("props-panel-mounted" | "update:modelValue")[], "props-panel-mounted" | "update:modelValue", VNodeProps & AllowedComponentProps & ComponentCustomProps, Readonly<ExtractPropTypes<{
|
|
67
73
|
/** 页面初始值 */
|
|
68
74
|
modelValue: {
|
|
@@ -93,6 +99,8 @@ declare const _default: DefineComponent<{
|
|
|
93
99
|
};
|
|
94
100
|
/** 中间工作区域中画布通过iframe渲染时的页面url */
|
|
95
101
|
runtimeUrl: StringConstructor;
|
|
102
|
+
/** 选中时是否自动滚动到可视区域 */
|
|
103
|
+
autoScrollIntoView: BooleanConstructor;
|
|
96
104
|
/** 组件的属性配置表单的dsl */
|
|
97
105
|
propsConfigs: {
|
|
98
106
|
type: PropType<Record<string, FormConfig>>;
|
|
@@ -122,11 +130,17 @@ declare const _default: DefineComponent<{
|
|
|
122
130
|
stageRect: {
|
|
123
131
|
type: PropType<StageRect>;
|
|
124
132
|
};
|
|
133
|
+
codeOptions: {
|
|
134
|
+
type: ObjectConstructor;
|
|
135
|
+
default: () => {};
|
|
136
|
+
};
|
|
125
137
|
}>> & {
|
|
126
138
|
"onProps-panel-mounted"?: ((...args: any[]) => any) | undefined;
|
|
127
139
|
"onUpdate:modelValue"?: ((...args: any[]) => any) | undefined;
|
|
128
140
|
}, {
|
|
129
141
|
menu: MenuBarData;
|
|
142
|
+
autoScrollIntoView: boolean;
|
|
143
|
+
codeOptions: Record<string, any>;
|
|
130
144
|
modelValue: MApp;
|
|
131
145
|
componentGroupList: ComponentGroup[];
|
|
132
146
|
propsConfigs: Record<string, FormConfig>;
|
|
@@ -1,11 +1,23 @@
|
|
|
1
|
-
import type { DefineComponent, ComputedRef, ComponentOptionsMixin,
|
|
1
|
+
import type { DefineComponent, ComputedRef, ComponentOptionsMixin, VNodeProps, AllowedComponentProps, ComponentCustomProps, ExtractPropTypes } from 'vue';
|
|
2
2
|
import type { MApp } from '@tmagic/schema';
|
|
3
3
|
import { GetColumnWidth } from '../type';
|
|
4
|
-
declare const _default: DefineComponent<{
|
|
4
|
+
declare const _default: DefineComponent<{
|
|
5
|
+
codeOptions: {
|
|
6
|
+
type: ObjectConstructor;
|
|
7
|
+
default: () => {};
|
|
8
|
+
};
|
|
9
|
+
}, {
|
|
5
10
|
root: ComputedRef<MApp | undefined>;
|
|
6
11
|
pageLength: ComputedRef<number>;
|
|
7
12
|
showSrc: ComputedRef<boolean | undefined>;
|
|
8
13
|
columnWidth: ComputedRef<GetColumnWidth | undefined>;
|
|
9
14
|
saveCode(value: string): void;
|
|
10
|
-
},
|
|
15
|
+
}, unknown, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, Record<string, any>, string, VNodeProps & AllowedComponentProps & ComponentCustomProps, Readonly<ExtractPropTypes<{
|
|
16
|
+
codeOptions: {
|
|
17
|
+
type: ObjectConstructor;
|
|
18
|
+
default: () => {};
|
|
19
|
+
};
|
|
20
|
+
}>>, {
|
|
21
|
+
codeOptions: Record<string, any>;
|
|
22
|
+
}>;
|
|
11
23
|
export default _default;
|
|
@@ -4,6 +4,7 @@ import type { MoveableOptions } from '@tmagic/stage';
|
|
|
4
4
|
import StageCore from '@tmagic/stage';
|
|
5
5
|
declare const _default: DefineComponent<{
|
|
6
6
|
runtimeUrl: StringConstructor;
|
|
7
|
+
autoScrollIntoView: BooleanConstructor;
|
|
7
8
|
render: {
|
|
8
9
|
type: PropType<() => HTMLDivElement>;
|
|
9
10
|
};
|
|
@@ -18,6 +19,7 @@ declare const _default: DefineComponent<{
|
|
|
18
19
|
page: ComputedRef<MPage | undefined>;
|
|
19
20
|
}, unknown, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, Record<string, any>, string, VNodeProps & AllowedComponentProps & ComponentCustomProps, Readonly<ExtractPropTypes<{
|
|
20
21
|
runtimeUrl: StringConstructor;
|
|
22
|
+
autoScrollIntoView: BooleanConstructor;
|
|
21
23
|
render: {
|
|
22
24
|
type: PropType<() => HTMLDivElement>;
|
|
23
25
|
};
|
|
@@ -27,5 +29,7 @@ declare const _default: DefineComponent<{
|
|
|
27
29
|
canSelect: {
|
|
28
30
|
type: PropType<(el: HTMLElement) => boolean | Promise<boolean>>;
|
|
29
31
|
};
|
|
30
|
-
}>>, {
|
|
32
|
+
}>>, {
|
|
33
|
+
autoScrollIntoView: boolean;
|
|
34
|
+
}>;
|
|
31
35
|
export default _default;
|
|
@@ -27,7 +27,7 @@ import { EventEmitter } from 'events';
|
|
|
27
27
|
* editorService.afterAdd();
|
|
28
28
|
* }
|
|
29
29
|
*
|
|
30
|
-
* 调用时的参数会透传到before方法的参数中, 然后before的return 会作为原方法的参数和after的参数,after
|
|
30
|
+
* 调用时的参数会透传到before方法的参数中, 然后before的return 会作为原方法的参数和after的参数,after第一个参数则是原方法的return值;
|
|
31
31
|
* 如需终止后续方法调用可以return new Error();
|
|
32
32
|
*
|
|
33
33
|
* 方法2:
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.0.0-rc.
|
|
2
|
+
"version": "1.0.0-rc.4",
|
|
3
3
|
"name": "@tmagic/editor",
|
|
4
4
|
"sideEffects": [
|
|
5
5
|
"dist/*",
|
|
@@ -43,25 +43,32 @@
|
|
|
43
43
|
"typescript"
|
|
44
44
|
],
|
|
45
45
|
"dependencies": {
|
|
46
|
+
"@babel/core": "^7.18.0",
|
|
46
47
|
"@element-plus/icons": "0.0.11",
|
|
47
|
-
"@tmagic/core": "^1.0.0-rc.
|
|
48
|
-
"@tmagic/form": "^1.0.0-rc.
|
|
49
|
-
"@tmagic/schema": "^1.0.0-rc.
|
|
50
|
-
"@tmagic/stage": "^1.0.0-rc.
|
|
51
|
-
"@tmagic/utils": "^1.0.0-rc.
|
|
48
|
+
"@tmagic/core": "^1.0.0-rc.4",
|
|
49
|
+
"@tmagic/form": "^1.0.0-rc.4",
|
|
50
|
+
"@tmagic/schema": "^1.0.0-rc.4",
|
|
51
|
+
"@tmagic/stage": "^1.0.0-rc.4",
|
|
52
|
+
"@tmagic/utils": "^1.0.0-rc.4",
|
|
52
53
|
"buffer": "^6.0.3",
|
|
53
54
|
"color": "^3.1.3",
|
|
54
55
|
"element-plus": "^2.2.0",
|
|
55
56
|
"events": "^3.3.0",
|
|
57
|
+
"gesto": "^1.7.0",
|
|
56
58
|
"keycon": "^1.1.2",
|
|
57
59
|
"lodash-es": "^4.17.21",
|
|
58
60
|
"monaco-editor": "^0.32.1",
|
|
59
61
|
"serialize-javascript": "^6.0.0",
|
|
60
62
|
"vue": "^3.2.0"
|
|
61
63
|
},
|
|
64
|
+
"peerDependencies": {
|
|
65
|
+
"@tmagic/form": "^1.0.0-rc.1",
|
|
66
|
+
"element-plus": "^2.2.0",
|
|
67
|
+
"vue": "^3.2.0"
|
|
68
|
+
},
|
|
62
69
|
"devDependencies": {
|
|
63
70
|
"@types/events": "^3.0.0",
|
|
64
|
-
"@types/jest": "^
|
|
71
|
+
"@types/jest": "^27.5.1",
|
|
65
72
|
"@types/lodash-es": "^4.17.4",
|
|
66
73
|
"@types/node": "^15.12.4",
|
|
67
74
|
"@types/serialize-javascript": "^5.0.1",
|
|
@@ -70,6 +77,7 @@
|
|
|
70
77
|
"@vue/compiler-sfc": "^3.2.0",
|
|
71
78
|
"@vue/test-utils": "^2.0.0-rc.20",
|
|
72
79
|
"@vue/vue3-jest": "^27.0.0-alpha.4",
|
|
80
|
+
"babel-jest": "^27.0.6",
|
|
73
81
|
"jest": "^27.5.1",
|
|
74
82
|
"jest-serializer-vue": "^2.0.2",
|
|
75
83
|
"jest-transform-stub": "^2.0.0",
|
|
@@ -80,5 +88,5 @@
|
|
|
80
88
|
"vite-plugin-dts": "^0.9.6",
|
|
81
89
|
"vue-tsc": "^0.0.24"
|
|
82
90
|
},
|
|
83
|
-
"gitHead": "
|
|
91
|
+
"gitHead": "28d5ad4573a27fa240f5e7d0902d3368e8d936b6"
|
|
84
92
|
}
|
package/src/Editor.vue
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<framework>
|
|
2
|
+
<framework :code-options="codeOptions">
|
|
3
3
|
<template #nav>
|
|
4
4
|
<slot name="nav" :editorService="editorService"><nav-menu :data="menu"></nav-menu></slot>
|
|
5
5
|
</template>
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
<slot name="workspace">
|
|
15
15
|
<workspace
|
|
16
16
|
:runtime-url="runtimeUrl"
|
|
17
|
+
:auto-scroll-into-view="autoScrollIntoView"
|
|
17
18
|
:render="render"
|
|
18
19
|
:moveable-options="moveableOptions"
|
|
19
20
|
:can-select="canSelect"
|
|
@@ -101,6 +102,9 @@ export default defineComponent({
|
|
|
101
102
|
/** 中间工作区域中画布通过iframe渲染时的页面url */
|
|
102
103
|
runtimeUrl: String,
|
|
103
104
|
|
|
105
|
+
/** 选中时是否自动滚动到可视区域 */
|
|
106
|
+
autoScrollIntoView: Boolean,
|
|
107
|
+
|
|
104
108
|
/** 组件的属性配置表单的dsl */
|
|
105
109
|
propsConfigs: {
|
|
106
110
|
type: Object as PropType<Record<string, FormConfig>>,
|
|
@@ -136,6 +140,11 @@ export default defineComponent({
|
|
|
136
140
|
stageRect: {
|
|
137
141
|
type: [String, Object] as PropType<StageRect>,
|
|
138
142
|
},
|
|
143
|
+
|
|
144
|
+
codeOptions: {
|
|
145
|
+
type: Object,
|
|
146
|
+
default: () => ({}),
|
|
147
|
+
},
|
|
139
148
|
},
|
|
140
149
|
|
|
141
150
|
emits: ['props-panel-mounted', 'update:modelValue'],
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<div v-if="menuData.length
|
|
2
|
+
<div v-if="menuData.length && visible" class="magic-editor-content-menu" ref="menu" :style="menuStyle">
|
|
3
3
|
<div>
|
|
4
4
|
<tool-button
|
|
5
5
|
v-for="(item, index) in menuData"
|
|
@@ -94,11 +94,7 @@ export default defineComponent({
|
|
|
94
94
|
const options = {
|
|
95
95
|
value: values.value,
|
|
96
96
|
language: props.language,
|
|
97
|
-
tabSize: 2,
|
|
98
97
|
theme: 'vs-dark',
|
|
99
|
-
fontFamily: 'dm, Menlo, Monaco, "Courier New", monospace',
|
|
100
|
-
fontSize: 14,
|
|
101
|
-
formatOnPaste: true,
|
|
102
98
|
...props.options,
|
|
103
99
|
};
|
|
104
100
|
|
|
@@ -117,6 +113,7 @@ export default defineComponent({
|
|
|
117
113
|
codeEditor.value.addEventListener('keydown', (e) => {
|
|
118
114
|
if (e.keyCode === 83 && (navigator.platform.match('Mac') ? e.metaKey : e.ctrlKey)) {
|
|
119
115
|
e.preventDefault();
|
|
116
|
+
e.stopPropagation();
|
|
120
117
|
emit('save', getEditorValue());
|
|
121
118
|
}
|
|
122
119
|
});
|
|
@@ -2,7 +2,13 @@
|
|
|
2
2
|
<div class="m-editor">
|
|
3
3
|
<slot name="nav" class="m-editor-nav-menu"></slot>
|
|
4
4
|
|
|
5
|
-
<magic-code-editor
|
|
5
|
+
<magic-code-editor
|
|
6
|
+
v-if="showSrc"
|
|
7
|
+
class="m-editor-content"
|
|
8
|
+
:init-values="root"
|
|
9
|
+
:options="codeOptions"
|
|
10
|
+
@save="saveCode"
|
|
11
|
+
></magic-code-editor>
|
|
6
12
|
|
|
7
13
|
<div class="m-editor-content" v-else>
|
|
8
14
|
<div class="m-editor-framework-left" :style="`width: ${columnWidth?.left}px`">
|
|
@@ -48,6 +54,13 @@ export default defineComponent({
|
|
|
48
54
|
Resizer,
|
|
49
55
|
},
|
|
50
56
|
|
|
57
|
+
props: {
|
|
58
|
+
codeOptions: {
|
|
59
|
+
type: Object,
|
|
60
|
+
default: () => ({}),
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
|
|
51
64
|
setup() {
|
|
52
65
|
const { editorService, uiService } = inject<Services>('services') || {};
|
|
53
66
|
|
|
@@ -59,6 +59,7 @@ export default defineComponent({
|
|
|
59
59
|
},
|
|
60
60
|
|
|
61
61
|
runtimeUrl: String,
|
|
62
|
+
autoScrollIntoView: Boolean,
|
|
62
63
|
|
|
63
64
|
canSelect: {
|
|
64
65
|
type: Function as PropType<(el: HTMLElement) => boolean | Promise<boolean>>,
|
|
@@ -100,6 +101,7 @@ export default defineComponent({
|
|
|
100
101
|
render: props.render,
|
|
101
102
|
runtimeUrl: props.runtimeUrl,
|
|
102
103
|
zoom: zoom.value,
|
|
104
|
+
autoScrollIntoView: props.autoScrollIntoView,
|
|
103
105
|
canSelect: (el, event, stop) => {
|
|
104
106
|
const elCanSelect = props.canSelect(el);
|
|
105
107
|
// 在组件联动过程中不能再往下选择,返回并触发 ui-select
|
|
@@ -209,6 +211,7 @@ export default defineComponent({
|
|
|
209
211
|
const { scrollTop, scrollLeft } = stage.mask;
|
|
210
212
|
if (layout === Layout.ABSOLUTE) {
|
|
211
213
|
config.style = {
|
|
214
|
+
...(config.style || {}),
|
|
212
215
|
position: 'absolute',
|
|
213
216
|
top: e.clientY - containerRect.top + scrollTop,
|
|
214
217
|
left: e.clientX - containerRect.left + scrollLeft,
|
|
@@ -69,8 +69,20 @@ export default defineComponent({
|
|
|
69
69
|
text: '粘贴',
|
|
70
70
|
display: () => canPaste.value,
|
|
71
71
|
handler: () => {
|
|
72
|
-
const
|
|
73
|
-
|
|
72
|
+
const stage = editorService?.get<StageCore>('stage');
|
|
73
|
+
|
|
74
|
+
const rect = menu.value?.$el.getBoundingClientRect();
|
|
75
|
+
const parentRect = stage?.container?.getBoundingClientRect();
|
|
76
|
+
let left = (rect?.left || 0) - (parentRect?.left || 0);
|
|
77
|
+
let top = (rect?.top || 0) - (parentRect?.top || 0);
|
|
78
|
+
|
|
79
|
+
if (node.value?.items && stage) {
|
|
80
|
+
const parentEl = stage.renderer.contentWindow?.document.getElementById(`${node.value.id}`);
|
|
81
|
+
const parentElRect = parentEl?.getBoundingClientRect();
|
|
82
|
+
left = left - (parentElRect?.left || 0);
|
|
83
|
+
top = top - (parentElRect?.top || 0);
|
|
84
|
+
}
|
|
85
|
+
|
|
74
86
|
editorService?.paste({ left, top });
|
|
75
87
|
},
|
|
76
88
|
},
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
<magic-stage
|
|
4
4
|
:key="page?.id"
|
|
5
5
|
:runtime-url="runtimeUrl"
|
|
6
|
+
:auto-scroll-into-view="autoScrollIntoView"
|
|
6
7
|
:render="render"
|
|
7
8
|
:moveable-options="moveableOptions"
|
|
8
9
|
:can-select="canSelect"
|
|
@@ -41,6 +42,7 @@ export default defineComponent({
|
|
|
41
42
|
|
|
42
43
|
props: {
|
|
43
44
|
runtimeUrl: String,
|
|
45
|
+
autoScrollIntoView: Boolean,
|
|
44
46
|
|
|
45
47
|
render: {
|
|
46
48
|
type: Function as PropType<() => HTMLDivElement>,
|
|
@@ -65,8 +67,13 @@ export default defineComponent({
|
|
|
65
67
|
workspace.value?.focus();
|
|
66
68
|
};
|
|
67
69
|
|
|
70
|
+
const mouseleaveHandler = () => {
|
|
71
|
+
workspace.value?.blur();
|
|
72
|
+
};
|
|
73
|
+
|
|
68
74
|
onMounted(() => {
|
|
69
75
|
workspace.value?.addEventListener('mouseenter', mouseenterHandler);
|
|
76
|
+
workspace.value?.addEventListener('mouseleave', mouseleaveHandler);
|
|
70
77
|
|
|
71
78
|
keycon = new KeyController(workspace.value);
|
|
72
79
|
|
|
@@ -80,6 +87,11 @@ export default defineComponent({
|
|
|
80
87
|
if (!node.value || isPage(node.value)) return;
|
|
81
88
|
services?.editorService.remove(node.value);
|
|
82
89
|
})
|
|
90
|
+
.keyup('backspace', (e) => {
|
|
91
|
+
e.inputEvent.preventDefault();
|
|
92
|
+
if (!node.value || isPage(node.value)) return;
|
|
93
|
+
services?.editorService.remove(node.value);
|
|
94
|
+
})
|
|
83
95
|
.keydown([ctrl, 'c'], (e) => {
|
|
84
96
|
e.inputEvent.preventDefault();
|
|
85
97
|
node.value && services?.editorService.copy(node.value);
|
|
@@ -146,14 +158,23 @@ export default defineComponent({
|
|
|
146
158
|
e.inputEvent.preventDefault();
|
|
147
159
|
services?.uiService.zoom(0.1);
|
|
148
160
|
})
|
|
161
|
+
.keydown([ctrl, 'numpadplus'], (e) => {
|
|
162
|
+
e.inputEvent.preventDefault();
|
|
163
|
+
services?.uiService.zoom(0.1);
|
|
164
|
+
})
|
|
149
165
|
.keydown([ctrl, '-'], (e) => {
|
|
150
166
|
e.inputEvent.preventDefault();
|
|
151
167
|
services?.uiService.zoom(-0.1);
|
|
168
|
+
})
|
|
169
|
+
.keydown([ctrl, 'numpad-'], (e) => {
|
|
170
|
+
e.inputEvent.preventDefault();
|
|
171
|
+
services?.uiService.zoom(-0.1);
|
|
152
172
|
});
|
|
153
173
|
});
|
|
154
174
|
|
|
155
175
|
onUnmounted(() => {
|
|
156
176
|
workspace.value?.removeEventListener('mouseenter', mouseenterHandler);
|
|
177
|
+
workspace.value?.removeEventListener('mouseleave', mouseleaveHandler);
|
|
157
178
|
keycon.destroy();
|
|
158
179
|
});
|
|
159
180
|
|
|
@@ -91,7 +91,7 @@ const doAction = async (
|
|
|
91
91
|
* editorService.afterAdd();
|
|
92
92
|
* }
|
|
93
93
|
*
|
|
94
|
-
* 调用时的参数会透传到before方法的参数中, 然后before的return 会作为原方法的参数和after的参数,after
|
|
94
|
+
* 调用时的参数会透传到before方法的参数中, 然后before的return 会作为原方法的参数和after的参数,after第一个参数则是原方法的return值;
|
|
95
95
|
* 如需终止后续方法调用可以return new Error();
|
|
96
96
|
*
|
|
97
97
|
* 方法2:
|
package/src/services/editor.ts
CHANGED
|
@@ -33,6 +33,7 @@ import {
|
|
|
33
33
|
change2Fixed,
|
|
34
34
|
COPY_STORAGE_KEY,
|
|
35
35
|
Fixed2Other,
|
|
36
|
+
generatePageNameByApp,
|
|
36
37
|
getNodeIndex,
|
|
37
38
|
initPosition,
|
|
38
39
|
isFixed,
|
|
@@ -194,6 +195,20 @@ class Editor extends BaseService {
|
|
|
194
195
|
historyService.empty();
|
|
195
196
|
}
|
|
196
197
|
|
|
198
|
+
if (node?.id) {
|
|
199
|
+
this.get<StageCore>('stage')
|
|
200
|
+
?.renderer.runtime?.getApp?.()
|
|
201
|
+
?.emit(
|
|
202
|
+
'editor:select',
|
|
203
|
+
{
|
|
204
|
+
node,
|
|
205
|
+
page,
|
|
206
|
+
parent,
|
|
207
|
+
},
|
|
208
|
+
getNodePath(node.id, this.get<MApp>('root').items),
|
|
209
|
+
);
|
|
210
|
+
}
|
|
211
|
+
|
|
197
212
|
this.emit('select', node);
|
|
198
213
|
|
|
199
214
|
return node!;
|
|
@@ -488,6 +503,10 @@ class Editor extends BaseService {
|
|
|
488
503
|
};
|
|
489
504
|
}
|
|
490
505
|
|
|
506
|
+
if (isPage(config)) {
|
|
507
|
+
config.name = generatePageNameByApp(this.get('root'));
|
|
508
|
+
}
|
|
509
|
+
|
|
491
510
|
return await this.add(config);
|
|
492
511
|
}
|
|
493
512
|
|
|
@@ -504,7 +523,18 @@ class Editor extends BaseService {
|
|
|
504
523
|
return;
|
|
505
524
|
}
|
|
506
525
|
|
|
507
|
-
if (
|
|
526
|
+
if (!node.style) return;
|
|
527
|
+
|
|
528
|
+
const stage = this.get<StageCore>('stage');
|
|
529
|
+
const doc = stage?.renderer.contentWindow?.document;
|
|
530
|
+
|
|
531
|
+
if (doc) {
|
|
532
|
+
const parentEl = doc.getElementById(`${parent.id}`);
|
|
533
|
+
const el = doc.getElementById(`${node.id}`);
|
|
534
|
+
if (parentEl && el) {
|
|
535
|
+
node.style.left = (parentEl.clientWidth - el.clientWidth) / 2;
|
|
536
|
+
}
|
|
537
|
+
} else if (parent.style && isNumber(parent.style?.width) && isNumber(node.style?.width)) {
|
|
508
538
|
node.style.left = (parent.style.width - node.style.width) / 2;
|
|
509
539
|
}
|
|
510
540
|
|
package/src/utils/polyfills.ts
CHANGED
|
@@ -1,22 +1,8 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Tencent is pleased to support the open source community by making TMagicEditor available.
|
|
3
|
-
*
|
|
4
|
-
* Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved.
|
|
5
|
-
*
|
|
6
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
-
* you may not use this file except in compliance with the License.
|
|
8
|
-
* You may obtain a copy of the License at
|
|
9
|
-
*
|
|
10
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
-
*
|
|
12
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
-
* See the License for the specific language governing permissions and
|
|
16
|
-
* limitations under the License.
|
|
17
|
-
*/
|
|
18
|
-
|
|
19
1
|
// serialize-javascript 依赖的 randombytes 依赖全局的 global 对象,因此此处需添加 global polyfill
|
|
20
|
-
if (typeof
|
|
2
|
+
if (typeof global === 'undefined') {
|
|
21
3
|
(window as any).global = window;
|
|
22
4
|
}
|
|
5
|
+
|
|
6
|
+
if (typeof globalThis === 'undefined') {
|
|
7
|
+
(window as any).globalThis = window;
|
|
8
|
+
}
|