@tmagic/editor 1.1.0-beta.9 → 1.1.2
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 +53 -4
- package/dist/tmagic-editor.mjs +1134 -928
- package/dist/tmagic-editor.mjs.map +1 -1
- package/dist/tmagic-editor.umd.js +1138 -929
- package/dist/tmagic-editor.umd.js.map +1 -1
- package/package.json +10 -10
- package/src/Editor.vue +28 -8
- package/src/components/ContentMenu.vue +4 -4
- package/src/components/Icon.vue +11 -23
- package/src/components/ScrollBar.vue +147 -0
- package/src/components/ScrollViewer.vue +89 -44
- package/src/components/ToolButton.vue +40 -138
- package/src/fields/UISelect.vue +2 -2
- package/src/index.ts +2 -2
- package/src/layouts/NavMenu.vue +156 -23
- package/src/layouts/PropsPanel.vue +49 -51
- package/src/layouts/sidebar/ComponentListPanel.vue +78 -90
- package/src/layouts/sidebar/LayerMenu.vue +3 -3
- package/src/layouts/sidebar/LayerPanel.vue +39 -8
- package/src/layouts/sidebar/Sidebar.vue +4 -0
- package/src/layouts/sidebar/TabPane.vue +12 -0
- package/src/layouts/workspace/PageBar.vue +2 -2
- package/src/layouts/workspace/PageBarScrollContainer.vue +13 -3
- package/src/layouts/workspace/Stage.vue +10 -92
- package/src/layouts/workspace/ViewerMenu.vue +3 -3
- package/src/layouts/workspace/Workspace.vue +133 -138
- package/src/services/componentList.ts +5 -0
- package/src/services/editor.ts +57 -20
- package/src/services/events.ts +8 -2
- package/src/services/props.ts +31 -52
- package/src/services/storage.ts +4 -0
- package/src/services/ui.ts +33 -30
- package/src/theme/component-list-panel.scss +0 -5
- package/src/theme/content-menu.scss +4 -0
- package/src/theme/icon.scss +6 -0
- package/src/theme/index.scss +1 -0
- package/src/theme/nav-menu.scss +6 -0
- package/src/type.ts +28 -10
- package/src/utils/index.ts +1 -0
- package/src/utils/operator.ts +3 -3
- package/src/utils/props.ts +0 -3
- package/src/utils/scroll-viewer.ts +90 -158
- package/src/utils/stage.ts +91 -0
- package/types/Editor.vue.d.ts +7 -7
- package/types/components/ContentMenu.vue.d.ts +8 -8
- package/types/components/Icon.vue.d.ts +62 -12
- package/types/components/ScrollBar.vue.d.ts +83 -0
- package/types/components/ScrollViewer.vue.d.ts +131 -19
- package/types/components/ToolButton.vue.d.ts +56 -59
- package/types/index.d.ts +2 -1
- package/types/layouts/NavMenu.vue.d.ts +92 -23
- package/types/layouts/PropsPanel.vue.d.ts +25 -208
- package/types/layouts/sidebar/ComponentListPanel.vue.d.ts +50 -12
- package/types/layouts/sidebar/LayerMenu.vue.d.ts +7 -7
- package/types/layouts/sidebar/LayerPanel.vue.d.ts +17 -15
- package/types/layouts/workspace/Workspace.vue.d.ts +54 -4
- package/types/services/componentList.d.ts +1 -0
- package/types/services/editor.d.ts +1 -0
- package/types/services/events.d.ts +1 -0
- package/types/services/props.d.ts +41 -9
- package/types/services/storage.d.ts +1 -0
- package/types/services/ui.d.ts +4 -1
- package/types/type.d.ts +25 -10
- package/types/utils/index.d.ts +1 -0
- package/types/utils/operator.d.ts +1 -1
- package/types/utils/props.d.ts +0 -1
- package/types/utils/scroll-viewer.d.ts +16 -18
- package/types/utils/stage.d.ts +3 -0
- package/src/utils/polyfills.ts +0 -8
- package/types/utils/polyfills.d.ts +0 -0
|
@@ -1,18 +1,20 @@
|
|
|
1
1
|
<template>
|
|
2
2
|
<div class="m-editor-workspace" tabindex="1" ref="workspace">
|
|
3
|
-
<
|
|
3
|
+
<slot name="stage">
|
|
4
|
+
<MagicStage :key="page?.id"></MagicStage>
|
|
5
|
+
</slot>
|
|
4
6
|
|
|
5
7
|
<slot name="workspace-content"></slot>
|
|
6
8
|
|
|
7
|
-
<
|
|
9
|
+
<PageBar>
|
|
8
10
|
<template #page-bar-title="{ page }"><slot name="page-bar-title" :page="page"></slot></template>
|
|
9
11
|
<template #page-bar-popover="{ page }"><slot name="page-bar-popover" :page="page"></slot></template>
|
|
10
|
-
</
|
|
12
|
+
</PageBar>
|
|
11
13
|
</div>
|
|
12
14
|
</template>
|
|
13
15
|
|
|
14
|
-
<script lang="ts">
|
|
15
|
-
import { computed,
|
|
16
|
+
<script lang="ts" setup>
|
|
17
|
+
import { computed, inject, onMounted, onUnmounted, ref } from 'vue';
|
|
16
18
|
import KeyController from 'keycon';
|
|
17
19
|
|
|
18
20
|
import type { MNode, MPage } from '@tmagic/schema';
|
|
@@ -23,140 +25,133 @@ import type { Services } from '../../type';
|
|
|
23
25
|
import PageBar from './PageBar.vue';
|
|
24
26
|
import MagicStage from './Stage.vue';
|
|
25
27
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
28
|
+
const services = inject<Services>('services');
|
|
29
|
+
const workspace = ref<HTMLDivElement>();
|
|
30
|
+
const nodes = computed(() => services?.editorService.get<MNode[]>('nodes'));
|
|
31
|
+
const page = computed(() => services?.editorService.get<MPage>('page'));
|
|
32
|
+
|
|
33
|
+
const mouseenterHandler = () => {
|
|
34
|
+
workspace.value?.focus();
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
const mouseleaveHandler = () => {
|
|
38
|
+
workspace.value?.blur();
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
let keycon: KeyController;
|
|
42
|
+
|
|
43
|
+
onMounted(() => {
|
|
44
|
+
workspace.value?.addEventListener('mouseenter', mouseenterHandler);
|
|
45
|
+
workspace.value?.addEventListener('mouseleave', mouseleaveHandler);
|
|
46
|
+
|
|
47
|
+
keycon = new KeyController(workspace.value);
|
|
48
|
+
|
|
49
|
+
const isMac = /mac os x/.test(navigator.userAgent.toLowerCase());
|
|
50
|
+
|
|
51
|
+
const ctrl = isMac ? 'meta' : 'ctrl';
|
|
52
|
+
|
|
53
|
+
keycon
|
|
54
|
+
.keyup('delete', (e) => {
|
|
55
|
+
e.inputEvent.preventDefault();
|
|
56
|
+
if (!nodes.value || isPage(nodes.value[0])) return;
|
|
57
|
+
services?.editorService.remove(nodes.value);
|
|
58
|
+
})
|
|
59
|
+
.keyup('backspace', (e) => {
|
|
60
|
+
e.inputEvent.preventDefault();
|
|
61
|
+
if (!nodes.value || isPage(nodes.value[0])) return;
|
|
62
|
+
services?.editorService.remove(nodes.value);
|
|
63
|
+
})
|
|
64
|
+
.keydown([ctrl, 'c'], (e) => {
|
|
65
|
+
e.inputEvent.preventDefault();
|
|
66
|
+
nodes.value && services?.editorService.copy(nodes.value);
|
|
67
|
+
})
|
|
68
|
+
.keydown([ctrl, 'v'], (e) => {
|
|
69
|
+
e.inputEvent.preventDefault();
|
|
70
|
+
nodes.value && services?.editorService.paste({ offsetX: 10, offsetY: 10 });
|
|
71
|
+
})
|
|
72
|
+
.keydown([ctrl, 'x'], (e) => {
|
|
73
|
+
e.inputEvent.preventDefault();
|
|
74
|
+
if (!nodes.value || isPage(nodes.value[0])) return;
|
|
75
|
+
services?.editorService.copy(nodes.value);
|
|
76
|
+
services?.editorService.remove(nodes.value);
|
|
77
|
+
})
|
|
78
|
+
.keydown([ctrl, 'z'], (e) => {
|
|
79
|
+
e.inputEvent.preventDefault();
|
|
80
|
+
services?.editorService.undo();
|
|
81
|
+
})
|
|
82
|
+
.keydown([ctrl, 'shift', 'z'], (e) => {
|
|
83
|
+
e.inputEvent.preventDefault();
|
|
84
|
+
services?.editorService.redo();
|
|
85
|
+
})
|
|
86
|
+
.keydown('up', (e) => {
|
|
87
|
+
e.inputEvent.preventDefault();
|
|
88
|
+
services?.editorService.move(0, -1);
|
|
89
|
+
})
|
|
90
|
+
.keydown('down', (e) => {
|
|
91
|
+
e.inputEvent.preventDefault();
|
|
92
|
+
services?.editorService.move(0, 1);
|
|
93
|
+
})
|
|
94
|
+
.keydown('left', (e) => {
|
|
95
|
+
e.inputEvent.preventDefault();
|
|
96
|
+
services?.editorService.move(-1, 0);
|
|
97
|
+
})
|
|
98
|
+
.keydown('right', (e) => {
|
|
99
|
+
e.inputEvent.preventDefault();
|
|
100
|
+
services?.editorService.move(1, 0);
|
|
101
|
+
})
|
|
102
|
+
.keydown([ctrl, 'up'], (e) => {
|
|
103
|
+
e.inputEvent.preventDefault();
|
|
104
|
+
services?.editorService.move(0, -10);
|
|
105
|
+
})
|
|
106
|
+
.keydown([ctrl, 'down'], (e) => {
|
|
107
|
+
e.inputEvent.preventDefault();
|
|
108
|
+
services?.editorService.move(0, 10);
|
|
109
|
+
})
|
|
110
|
+
.keydown([ctrl, 'left'], (e) => {
|
|
111
|
+
e.inputEvent.preventDefault();
|
|
112
|
+
services?.editorService.move(-10, 0);
|
|
113
|
+
})
|
|
114
|
+
.keydown([ctrl, 'right'], (e) => {
|
|
115
|
+
e.inputEvent.preventDefault();
|
|
116
|
+
services?.editorService.move(10, 0);
|
|
117
|
+
})
|
|
118
|
+
.keydown('tab', (e) => {
|
|
119
|
+
e.inputEvent.preventDefault();
|
|
120
|
+
services?.editorService.selectNextNode();
|
|
121
|
+
})
|
|
122
|
+
.keydown([ctrl, 'tab'], (e) => {
|
|
123
|
+
e.inputEvent.preventDefault();
|
|
124
|
+
services?.editorService.selectNextPage();
|
|
125
|
+
})
|
|
126
|
+
.keydown([ctrl, '='], (e) => {
|
|
127
|
+
e.inputEvent.preventDefault();
|
|
128
|
+
services?.uiService.zoom(0.1);
|
|
129
|
+
})
|
|
130
|
+
.keydown([ctrl, 'numpadplus'], (e) => {
|
|
131
|
+
e.inputEvent.preventDefault();
|
|
132
|
+
services?.uiService.zoom(0.1);
|
|
133
|
+
})
|
|
134
|
+
.keydown([ctrl, '-'], (e) => {
|
|
135
|
+
e.inputEvent.preventDefault();
|
|
136
|
+
services?.uiService.zoom(-0.1);
|
|
137
|
+
})
|
|
138
|
+
.keydown([ctrl, 'numpad-'], (e) => {
|
|
139
|
+
e.inputEvent.preventDefault();
|
|
140
|
+
services?.uiService.zoom(-0.1);
|
|
141
|
+
})
|
|
142
|
+
.keydown([ctrl, '0'], (e) => {
|
|
143
|
+
e.inputEvent.preventDefault();
|
|
144
|
+
services?.uiService.set('zoom', services.uiService.calcZoom());
|
|
145
|
+
})
|
|
146
|
+
.keydown([ctrl, '1'], (e) => {
|
|
147
|
+
e.inputEvent.preventDefault();
|
|
148
|
+
services?.uiService.set('zoom', 1);
|
|
147
149
|
});
|
|
150
|
+
});
|
|
148
151
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
});
|
|
154
|
-
|
|
155
|
-
return {
|
|
156
|
-
workspace,
|
|
157
|
-
|
|
158
|
-
page: computed(() => services?.editorService.get<MPage>('page')),
|
|
159
|
-
};
|
|
160
|
-
},
|
|
152
|
+
onUnmounted(() => {
|
|
153
|
+
workspace.value?.removeEventListener('mouseenter', mouseenterHandler);
|
|
154
|
+
workspace.value?.removeEventListener('mouseleave', mouseleaveHandler);
|
|
155
|
+
keycon.destroy();
|
|
161
156
|
});
|
|
162
157
|
</script>
|
|
@@ -41,6 +41,11 @@ class ComponentList extends BaseService {
|
|
|
41
41
|
public getList(): ComponentGroup[] {
|
|
42
42
|
return this.state.list;
|
|
43
43
|
}
|
|
44
|
+
|
|
45
|
+
public destroy() {
|
|
46
|
+
this.state.list = [];
|
|
47
|
+
this.removeAllListeners();
|
|
48
|
+
}
|
|
44
49
|
}
|
|
45
50
|
|
|
46
51
|
export type ComponentListService = ComponentList;
|
package/src/services/editor.ts
CHANGED
|
@@ -71,6 +71,7 @@ class Editor extends BaseService {
|
|
|
71
71
|
'sort',
|
|
72
72
|
'copy',
|
|
73
73
|
'paste',
|
|
74
|
+
'doPaste',
|
|
74
75
|
'duAlignCenter',
|
|
75
76
|
'alignCenter',
|
|
76
77
|
'moveLayer',
|
|
@@ -296,17 +297,27 @@ class Editor extends BaseService {
|
|
|
296
297
|
throw new Error('app下不能添加组件');
|
|
297
298
|
}
|
|
298
299
|
|
|
300
|
+
if (parent.id !== curNode.id) {
|
|
301
|
+
const index = parent.items.indexOf(curNode);
|
|
302
|
+
parent?.items?.splice(index + 1, 0, node);
|
|
303
|
+
} else {
|
|
304
|
+
// 新增节点添加到配置中
|
|
305
|
+
parent?.items?.push(node);
|
|
306
|
+
}
|
|
307
|
+
|
|
299
308
|
const layout = await this.getLayout(toRaw(parent), node as MNode);
|
|
300
309
|
node.style = getInitPositionStyle(node.style, layout);
|
|
301
310
|
|
|
302
|
-
await stage?.add({
|
|
311
|
+
await stage?.add({
|
|
312
|
+
config: cloneDeep(node),
|
|
313
|
+
parent: cloneDeep(parent),
|
|
314
|
+
parentId: parent.id,
|
|
315
|
+
root: cloneDeep(root),
|
|
316
|
+
});
|
|
303
317
|
|
|
304
318
|
node.style = fixNodePosition(node, parent, stage);
|
|
305
319
|
|
|
306
|
-
await stage?.update({ config: cloneDeep(node), root: cloneDeep(root) });
|
|
307
|
-
|
|
308
|
-
// 新增节点添加到配置中
|
|
309
|
-
parent?.items?.push(node);
|
|
320
|
+
await stage?.update({ config: cloneDeep(node), parentId: parent.id, root: cloneDeep(root) });
|
|
310
321
|
|
|
311
322
|
this.addModifiedNodeId(node.id);
|
|
312
323
|
|
|
@@ -322,9 +333,6 @@ class Editor extends BaseService {
|
|
|
322
333
|
public async add(addNode: AddMNode | MNode[], parent?: MContainer | null): Promise<MNode | MNode[]> {
|
|
323
334
|
const stage = this.get<StageCore | null>('stage');
|
|
324
335
|
|
|
325
|
-
const parentNode = parent && typeof parent !== 'function' ? parent : getAddParent(addNode);
|
|
326
|
-
if (!parentNode) throw new Error('未找到父元素');
|
|
327
|
-
|
|
328
336
|
// 新增多个组件只存在于粘贴多个组件,粘贴的是一个完整的config,所以不再需要getPropsValue
|
|
329
337
|
const addNodes = [];
|
|
330
338
|
if (!Array.isArray(addNode)) {
|
|
@@ -337,7 +345,13 @@ class Editor extends BaseService {
|
|
|
337
345
|
addNodes.push(...addNode);
|
|
338
346
|
}
|
|
339
347
|
|
|
340
|
-
const newNodes = await Promise.all(
|
|
348
|
+
const newNodes = await Promise.all(
|
|
349
|
+
addNodes.map((node) => {
|
|
350
|
+
const parentNode = parent && typeof parent !== 'function' ? parent : getAddParent(node);
|
|
351
|
+
if (!parentNode) throw new Error('未找到父元素');
|
|
352
|
+
return this.doAdd(node, parentNode);
|
|
353
|
+
}),
|
|
354
|
+
);
|
|
341
355
|
|
|
342
356
|
if (newNodes.length > 1) {
|
|
343
357
|
const newNodeIds = newNodes.map((node) => node.id);
|
|
@@ -359,7 +373,7 @@ class Editor extends BaseService {
|
|
|
359
373
|
|
|
360
374
|
this.emit('add', newNodes);
|
|
361
375
|
|
|
362
|
-
return
|
|
376
|
+
return Array.isArray(addNode) ? newNodes : newNodes[0];
|
|
363
377
|
}
|
|
364
378
|
|
|
365
379
|
public async doRemove(node: MNode): Promise<void> {
|
|
@@ -377,7 +391,7 @@ class Editor extends BaseService {
|
|
|
377
391
|
|
|
378
392
|
parent.items?.splice(index, 1);
|
|
379
393
|
const stage = this.get<StageCore | null>('stage');
|
|
380
|
-
stage?.remove({ id: node.id, root:
|
|
394
|
+
stage?.remove({ id: node.id, parentId: parent.id, root: cloneDeep(root) });
|
|
381
395
|
|
|
382
396
|
if (node.type === NodeType.PAGE) {
|
|
383
397
|
this.state.pageLength -= 1;
|
|
@@ -386,7 +400,7 @@ class Editor extends BaseService {
|
|
|
386
400
|
await this.select(root.items[0]);
|
|
387
401
|
stage?.select(root.items[0].id);
|
|
388
402
|
} else {
|
|
389
|
-
this.set('
|
|
403
|
+
this.set('nodes', [root]);
|
|
390
404
|
this.set('parent', null);
|
|
391
405
|
this.set('page', null);
|
|
392
406
|
this.set('stage', null);
|
|
@@ -417,7 +431,7 @@ class Editor extends BaseService {
|
|
|
417
431
|
// 更新历史记录
|
|
418
432
|
this.pushHistoryState();
|
|
419
433
|
|
|
420
|
-
this.emit('remove');
|
|
434
|
+
this.emit('remove', nodes);
|
|
421
435
|
}
|
|
422
436
|
|
|
423
437
|
public async doUpdate(config: MNode) {
|
|
@@ -466,7 +480,11 @@ class Editor extends BaseService {
|
|
|
466
480
|
nodes.splice(targetIndex, 1, newConfig);
|
|
467
481
|
this.set('nodes', nodes);
|
|
468
482
|
|
|
469
|
-
this.get<StageCore | null>('stage')?.update({
|
|
483
|
+
this.get<StageCore | null>('stage')?.update({
|
|
484
|
+
config: cloneDeep(newConfig),
|
|
485
|
+
parentId: parent.id,
|
|
486
|
+
root: cloneDeep(this.get('root')),
|
|
487
|
+
});
|
|
470
488
|
|
|
471
489
|
if (newConfig.type === NodeType.PAGE) {
|
|
472
490
|
this.set('page', newConfig);
|
|
@@ -491,7 +509,7 @@ class Editor extends BaseService {
|
|
|
491
509
|
|
|
492
510
|
this.emit('update', newNodes);
|
|
493
511
|
|
|
494
|
-
return
|
|
512
|
+
return Array.isArray(config) ? newNodes : newNodes[0];
|
|
495
513
|
}
|
|
496
514
|
|
|
497
515
|
/**
|
|
@@ -513,7 +531,11 @@ class Editor extends BaseService {
|
|
|
513
531
|
await this.update(parent);
|
|
514
532
|
await this.select(node);
|
|
515
533
|
|
|
516
|
-
this.get<StageCore | null>('stage')?.update({
|
|
534
|
+
this.get<StageCore | null>('stage')?.update({
|
|
535
|
+
config: cloneDeep(node),
|
|
536
|
+
parentId: parent.id,
|
|
537
|
+
root: cloneDeep(this.get('root')),
|
|
538
|
+
});
|
|
517
539
|
|
|
518
540
|
this.addModifiedNodeId(parent.id);
|
|
519
541
|
this.pushHistoryState();
|
|
@@ -540,11 +562,16 @@ class Editor extends BaseService {
|
|
|
540
562
|
|
|
541
563
|
if (!Array.isArray(config)) return;
|
|
542
564
|
|
|
543
|
-
const pasteConfigs = await
|
|
565
|
+
const pasteConfigs = await this.doPaste(config, position);
|
|
544
566
|
|
|
545
567
|
return this.add(pasteConfigs);
|
|
546
568
|
}
|
|
547
569
|
|
|
570
|
+
public async doPaste(config: MNode[], position: PastePosition = {}): Promise<MNode[]> {
|
|
571
|
+
const pasteConfigs = await beforePaste(position, cloneDeep(config));
|
|
572
|
+
return pasteConfigs;
|
|
573
|
+
}
|
|
574
|
+
|
|
548
575
|
public async doAlignCenter(config: MNode): Promise<MNode> {
|
|
549
576
|
const parent = this.getParentById(config.id);
|
|
550
577
|
|
|
@@ -598,7 +625,7 @@ class Editor extends BaseService {
|
|
|
598
625
|
*/
|
|
599
626
|
public async moveLayer(offset: number | LayerOffset): Promise<void> {
|
|
600
627
|
const parent = this.get<MContainer>('parent');
|
|
601
|
-
const node = this.get('node');
|
|
628
|
+
const node = this.get<MNode>('node');
|
|
602
629
|
const brothers: MNode[] = parent?.items || [];
|
|
603
630
|
const index = brothers.findIndex((item) => `${item.id}` === `${node?.id}`);
|
|
604
631
|
|
|
@@ -610,10 +637,15 @@ class Editor extends BaseService {
|
|
|
610
637
|
brothers.splice(index + parseInt(`${offset}`, 10), 0, brothers.splice(index, 1)[0]);
|
|
611
638
|
}
|
|
612
639
|
|
|
640
|
+
const grandparent = this.getParentById(parent.id);
|
|
613
641
|
this.get<StageCore | null>('stage')?.update({
|
|
614
642
|
config: cloneDeep(toRaw(parent)),
|
|
643
|
+
parentId: grandparent?.id,
|
|
615
644
|
root: cloneDeep(this.get<MApp>('root')),
|
|
616
645
|
});
|
|
646
|
+
|
|
647
|
+
this.addModifiedNodeId(parent.id);
|
|
648
|
+
this.pushHistoryState();
|
|
617
649
|
}
|
|
618
650
|
|
|
619
651
|
/**
|
|
@@ -632,7 +664,7 @@ class Editor extends BaseService {
|
|
|
632
664
|
const index = getNodeIndex(node, parent);
|
|
633
665
|
parent.items?.splice(index, 1);
|
|
634
666
|
|
|
635
|
-
await stage.remove({ id: node.id, root });
|
|
667
|
+
await stage.remove({ id: node.id, parentId: parent.id, root });
|
|
636
668
|
|
|
637
669
|
const layout = await this.getLayout(target);
|
|
638
670
|
|
|
@@ -647,7 +679,8 @@ class Editor extends BaseService {
|
|
|
647
679
|
|
|
648
680
|
await stage.select(targetId);
|
|
649
681
|
|
|
650
|
-
|
|
682
|
+
const targetParent = this.getParentById(target.id);
|
|
683
|
+
await stage.update({ config: cloneDeep(target), parentId: targetParent?.id, root });
|
|
651
684
|
|
|
652
685
|
await this.select(newConfig);
|
|
653
686
|
stage.select(newConfig.id);
|
|
@@ -708,6 +741,10 @@ class Editor extends BaseService {
|
|
|
708
741
|
this.set('nodes', []);
|
|
709
742
|
this.set('page', null);
|
|
710
743
|
this.set('parent', null);
|
|
744
|
+
this.set('stage', null);
|
|
745
|
+
this.set('highlightNode', null);
|
|
746
|
+
this.set('modifiedNodeIds', new Map());
|
|
747
|
+
this.set('pageLength', new Map());
|
|
711
748
|
}
|
|
712
749
|
|
|
713
750
|
public resetModifiedNodeId() {
|
package/src/services/events.ts
CHANGED
|
@@ -26,8 +26,8 @@ import type { ComponentGroup } from '../type';
|
|
|
26
26
|
|
|
27
27
|
import BaseService from './BaseService';
|
|
28
28
|
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
let eventMap: Record<string, EventOption[]> = reactive({});
|
|
30
|
+
let methodMap: Record<string, EventOption[]> = reactive({});
|
|
31
31
|
|
|
32
32
|
class Events extends BaseService {
|
|
33
33
|
constructor() {
|
|
@@ -75,6 +75,12 @@ class Events extends BaseService {
|
|
|
75
75
|
public getMethod(type: string) {
|
|
76
76
|
return cloneDeep(methodMap[type] || DEFAULT_METHODS);
|
|
77
77
|
}
|
|
78
|
+
|
|
79
|
+
public destroy() {
|
|
80
|
+
eventMap = reactive({});
|
|
81
|
+
methodMap = reactive({});
|
|
82
|
+
this.removeAllListeners();
|
|
83
|
+
}
|
|
78
84
|
}
|
|
79
85
|
|
|
80
86
|
export type EventsService = Events;
|