@tmagic/editor 1.3.0-alpha.0 → 1.3.0-alpha.10
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 +46 -9
- package/dist/tmagic-editor.js +1764 -871
- package/dist/tmagic-editor.js.map +1 -1
- package/dist/tmagic-editor.umd.cjs +1781 -882
- package/dist/tmagic-editor.umd.cjs.map +1 -1
- package/package.json +19 -20
- package/src/Editor.vue +29 -3
- package/src/components/CodeDraftEditor.vue +5 -1
- package/src/components/ContentMenu.vue +30 -11
- package/src/components/FunctionEditor.vue +12 -5
- 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 +5 -1
- package/src/fields/Code.vue +5 -1
- package/src/fields/CodeLink.vue +9 -3
- package/src/fields/CodeSelect.vue +8 -2
- package/src/fields/CodeSelectCol.vue +6 -2
- package/src/fields/DataSourceFields.vue +5 -1
- package/src/fields/DataSourceInput.vue +358 -0
- package/src/fields/DataSourceSelect.vue +75 -0
- package/src/fields/EventSelect.vue +9 -3
- package/src/fields/KeyValue.vue +4 -0
- package/src/fields/UISelect.vue +5 -1
- package/src/icons/AppManageIcon.vue +5 -1
- package/src/icons/CenterIcon.vue +13 -0
- package/src/icons/CodeIcon.vue +5 -1
- package/src/index.ts +13 -3
- package/src/initService.ts +73 -0
- package/src/layouts/AddPageBox.vue +5 -1
- package/src/layouts/CodeEditor.vue +34 -10
- package/src/layouts/Framework.vue +25 -25
- package/src/layouts/NavMenu.vue +5 -1
- package/src/layouts/PropsPanel.vue +14 -4
- package/src/layouts/sidebar/ComponentListPanel.vue +8 -5
- package/src/layouts/sidebar/LayerMenu.vue +13 -25
- package/src/layouts/sidebar/LayerNode.vue +40 -0
- package/src/layouts/sidebar/LayerPanel.vue +70 -27
- package/src/layouts/sidebar/Sidebar.vue +11 -7
- package/src/layouts/sidebar/code-block/CodeBlockEditor.vue +8 -4
- package/src/layouts/sidebar/code-block/CodeBlockList.vue +5 -1
- package/src/layouts/sidebar/data-source/DataSourceConfigPanel.vue +4 -0
- package/src/layouts/sidebar/data-source/DataSourceListPanel.vue +22 -2
- 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 +29 -7
- package/src/layouts/workspace/ViewerMenu.vue +15 -36
- package/src/layouts/workspace/Workspace.vue +9 -134
- package/src/services/codeBlock.ts +3 -2
- package/src/services/dep.ts +4 -0
- package/src/services/keybinding.ts +185 -0
- package/src/services/storage.ts +3 -2
- package/src/theme/content-menu.scss +1 -1
- package/src/theme/data-source-input.scss +18 -0
- 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 +1 -0
- package/src/type.ts +59 -1
- package/src/utils/config.ts +1 -1
- package/src/utils/content-menu.ts +92 -0
- package/src/utils/dep.ts +7 -1
- package/src/utils/keybinding-config.ts +120 -0
- package/src/utils/props.ts +34 -0
- package/types/Editor.vue.d.ts +7 -1
- package/types/components/CodeDraftEditor.vue.d.ts +6 -3
- package/types/components/ContentMenu.vue.d.ts +10 -5
- package/types/components/FunctionEditor.vue.d.ts +74 -51
- 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 +8 -5
- package/types/editorProps.d.ts +4 -1
- package/types/fields/Code.vue.d.ts +1 -1
- package/types/fields/CodeLink.vue.d.ts +9 -9
- package/types/fields/CodeSelect.vue.d.ts +10 -7
- package/types/fields/CodeSelectCol.vue.d.ts +8 -5
- package/types/fields/DataSourceFields.vue.d.ts +8 -5
- package/types/fields/DataSourceInput.vue.d.ts +54 -0
- package/types/fields/DataSourceSelect.vue.d.ts +56 -0
- package/types/fields/EventSelect.vue.d.ts +3 -3
- package/types/fields/KeyValue.vue.d.ts +8 -5
- package/types/fields/UISelect.vue.d.ts +1 -1
- 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 +7 -2
- package/types/initService.d.ts +1 -1
- package/types/layouts/AddPageBox.vue.d.ts +1 -1
- package/types/layouts/CodeEditor.vue.d.ts +16 -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 +18 -15
- package/types/layouts/sidebar/code-block/CodeBlockEditor.vue.d.ts +4 -4
- package/types/layouts/sidebar/code-block/CodeBlockList.vue.d.ts +7 -7
- package/types/layouts/sidebar/data-source/DataSourceConfigPanel.vue.d.ts +1 -1
- package/types/layouts/sidebar/data-source/DataSourceListPanel.vue.d.ts +3 -3
- 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/keybinding.d.ts +20 -0
- package/types/type.d.ts +56 -1
- package/types/utils/config.d.ts +1 -1
- package/types/utils/content-menu.d.ts +7 -0
- package/types/utils/keybinding-config.d.ts +3 -0
- package/src/layouts/Resizer.vue +0 -32
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<div class="m-editor-workspace"
|
|
2
|
+
<div class="m-editor-workspace">
|
|
3
3
|
<Breadcrumb></Breadcrumb>
|
|
4
4
|
|
|
5
5
|
<slot name="stage">
|
|
@@ -15,149 +15,24 @@
|
|
|
15
15
|
</div>
|
|
16
16
|
</template>
|
|
17
17
|
|
|
18
|
-
<script lang="ts" setup
|
|
19
|
-
import { computed, inject
|
|
20
|
-
import KeyController from 'keycon';
|
|
18
|
+
<script lang="ts" setup>
|
|
19
|
+
import { computed, inject } from 'vue';
|
|
21
20
|
|
|
22
|
-
import {
|
|
23
|
-
|
|
24
|
-
import type { MenuButton, MenuComponent, Services } from '@editor/type';
|
|
21
|
+
import { MenuButton, MenuComponent, Services } from '@editor/type';
|
|
25
22
|
|
|
26
23
|
import Breadcrumb from './Breadcrumb.vue';
|
|
27
24
|
import PageBar from './PageBar.vue';
|
|
28
25
|
import MagicStage from './Stage.vue';
|
|
29
26
|
|
|
27
|
+
defineOptions({
|
|
28
|
+
name: 'MEditorWorkspace',
|
|
29
|
+
});
|
|
30
|
+
|
|
30
31
|
defineProps<{
|
|
31
32
|
stageContentMenu: (MenuButton | MenuComponent)[];
|
|
32
33
|
}>();
|
|
33
34
|
|
|
34
35
|
const services = inject<Services>('services');
|
|
35
|
-
const workspace = ref<HTMLDivElement>();
|
|
36
|
-
const nodes = computed(() => services?.editorService.get('nodes'));
|
|
37
|
-
const page = computed(() => services?.editorService.get('page'));
|
|
38
|
-
|
|
39
|
-
const mouseenterHandler = () => {
|
|
40
|
-
workspace.value?.focus();
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
const mouseleaveHandler = () => {
|
|
44
|
-
workspace.value?.blur();
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
let keycon: KeyController;
|
|
48
|
-
|
|
49
|
-
onMounted(() => {
|
|
50
|
-
workspace.value?.addEventListener('mouseenter', mouseenterHandler);
|
|
51
|
-
workspace.value?.addEventListener('mouseleave', mouseleaveHandler);
|
|
52
36
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
const isMac = /mac os x/.test(navigator.userAgent.toLowerCase());
|
|
56
|
-
|
|
57
|
-
const ctrl = isMac ? 'meta' : 'ctrl';
|
|
58
|
-
|
|
59
|
-
keycon
|
|
60
|
-
.keyup('delete', (e) => {
|
|
61
|
-
e.inputEvent.preventDefault();
|
|
62
|
-
if (!nodes.value || isPage(nodes.value[0])) return;
|
|
63
|
-
services?.editorService.remove(nodes.value);
|
|
64
|
-
})
|
|
65
|
-
.keyup('backspace', (e) => {
|
|
66
|
-
e.inputEvent.preventDefault();
|
|
67
|
-
if (!nodes.value || isPage(nodes.value[0])) return;
|
|
68
|
-
services?.editorService.remove(nodes.value);
|
|
69
|
-
})
|
|
70
|
-
.keydown([ctrl, 'c'], (e) => {
|
|
71
|
-
e.inputEvent.preventDefault();
|
|
72
|
-
nodes.value && services?.editorService.copy(nodes.value);
|
|
73
|
-
})
|
|
74
|
-
.keydown([ctrl, 'v'], (e) => {
|
|
75
|
-
e.inputEvent.preventDefault();
|
|
76
|
-
nodes.value && services?.editorService.paste({ offsetX: 10, offsetY: 10 });
|
|
77
|
-
})
|
|
78
|
-
.keydown([ctrl, 'x'], (e) => {
|
|
79
|
-
e.inputEvent.preventDefault();
|
|
80
|
-
if (!nodes.value || isPage(nodes.value[0])) return;
|
|
81
|
-
services?.editorService.copy(nodes.value);
|
|
82
|
-
services?.editorService.remove(nodes.value);
|
|
83
|
-
})
|
|
84
|
-
.keydown([ctrl, 'z'], (e) => {
|
|
85
|
-
e.inputEvent.preventDefault();
|
|
86
|
-
services?.editorService.undo();
|
|
87
|
-
})
|
|
88
|
-
.keydown([ctrl, 'shift', 'z'], (e) => {
|
|
89
|
-
e.inputEvent.preventDefault();
|
|
90
|
-
services?.editorService.redo();
|
|
91
|
-
})
|
|
92
|
-
.keydown('up', (e) => {
|
|
93
|
-
e.inputEvent.preventDefault();
|
|
94
|
-
services?.editorService.move(0, -1);
|
|
95
|
-
})
|
|
96
|
-
.keydown('down', (e) => {
|
|
97
|
-
e.inputEvent.preventDefault();
|
|
98
|
-
services?.editorService.move(0, 1);
|
|
99
|
-
})
|
|
100
|
-
.keydown('left', (e) => {
|
|
101
|
-
e.inputEvent.preventDefault();
|
|
102
|
-
services?.editorService.move(-1, 0);
|
|
103
|
-
})
|
|
104
|
-
.keydown('right', (e) => {
|
|
105
|
-
e.inputEvent.preventDefault();
|
|
106
|
-
services?.editorService.move(1, 0);
|
|
107
|
-
})
|
|
108
|
-
.keydown([ctrl, 'up'], (e) => {
|
|
109
|
-
e.inputEvent.preventDefault();
|
|
110
|
-
services?.editorService.move(0, -10);
|
|
111
|
-
})
|
|
112
|
-
.keydown([ctrl, 'down'], (e) => {
|
|
113
|
-
e.inputEvent.preventDefault();
|
|
114
|
-
services?.editorService.move(0, 10);
|
|
115
|
-
})
|
|
116
|
-
.keydown([ctrl, 'left'], (e) => {
|
|
117
|
-
e.inputEvent.preventDefault();
|
|
118
|
-
services?.editorService.move(-10, 0);
|
|
119
|
-
})
|
|
120
|
-
.keydown([ctrl, 'right'], (e) => {
|
|
121
|
-
e.inputEvent.preventDefault();
|
|
122
|
-
services?.editorService.move(10, 0);
|
|
123
|
-
})
|
|
124
|
-
.keydown('tab', (e) => {
|
|
125
|
-
e.inputEvent.preventDefault();
|
|
126
|
-
services?.editorService.selectNextNode();
|
|
127
|
-
})
|
|
128
|
-
.keydown([ctrl, 'tab'], (e) => {
|
|
129
|
-
e.inputEvent.preventDefault();
|
|
130
|
-
services?.editorService.selectNextPage();
|
|
131
|
-
})
|
|
132
|
-
.keydown([ctrl, '='], (e) => {
|
|
133
|
-
e.inputEvent.preventDefault();
|
|
134
|
-
services?.uiService.zoom(0.1);
|
|
135
|
-
})
|
|
136
|
-
.keydown([ctrl, 'numpadplus'], (e) => {
|
|
137
|
-
e.inputEvent.preventDefault();
|
|
138
|
-
services?.uiService.zoom(0.1);
|
|
139
|
-
})
|
|
140
|
-
.keydown([ctrl, '-'], (e) => {
|
|
141
|
-
e.inputEvent.preventDefault();
|
|
142
|
-
services?.uiService.zoom(-0.1);
|
|
143
|
-
})
|
|
144
|
-
.keydown([ctrl, 'numpad-'], (e) => {
|
|
145
|
-
e.inputEvent.preventDefault();
|
|
146
|
-
services?.uiService.zoom(-0.1);
|
|
147
|
-
})
|
|
148
|
-
.keydown([ctrl, '0'], async (e) => {
|
|
149
|
-
e.inputEvent.preventDefault();
|
|
150
|
-
services?.uiService.set('zoom', await services.uiService.calcZoom());
|
|
151
|
-
})
|
|
152
|
-
.keydown([ctrl, '1'], (e) => {
|
|
153
|
-
e.inputEvent.preventDefault();
|
|
154
|
-
services?.uiService.set('zoom', 1);
|
|
155
|
-
});
|
|
156
|
-
});
|
|
157
|
-
|
|
158
|
-
onUnmounted(() => {
|
|
159
|
-
workspace.value?.removeEventListener('mouseenter', mouseenterHandler);
|
|
160
|
-
workspace.value?.removeEventListener('mouseleave', mouseleaveHandler);
|
|
161
|
-
keycon.destroy();
|
|
162
|
-
});
|
|
37
|
+
const page = computed(() => services?.editorService.get('page'));
|
|
163
38
|
</script>
|
|
@@ -23,6 +23,7 @@ import { CodeBlockContent, CodeBlockDSL, Id } from '@tmagic/schema';
|
|
|
23
23
|
|
|
24
24
|
import type { CodeState } from '@editor/type';
|
|
25
25
|
import { CODE_DRAFT_STORAGE_KEY } from '@editor/type';
|
|
26
|
+
import { getConfig } from '@editor/utils/config';
|
|
26
27
|
|
|
27
28
|
import BaseService from './BaseService';
|
|
28
29
|
|
|
@@ -95,8 +96,8 @@ class CodeBlock extends BaseService {
|
|
|
95
96
|
const codeConfigProcessed = codeConfig;
|
|
96
97
|
if (codeConfig.content) {
|
|
97
98
|
// 在保存的时候转换代码内容
|
|
98
|
-
|
|
99
|
-
codeConfigProcessed.content =
|
|
99
|
+
const parseDSL = getConfig('parseDSL');
|
|
100
|
+
codeConfigProcessed.content = parseDSL(codeConfig.content);
|
|
100
101
|
}
|
|
101
102
|
|
|
102
103
|
const existContent = codeDsl[id] || {};
|
package/src/services/dep.ts
CHANGED
|
@@ -262,11 +262,14 @@ export class Watcher extends EventEmitter {
|
|
|
262
262
|
Object.values(this.targets).forEach((targets) => {
|
|
263
263
|
Object.values(targets).forEach((target) => {
|
|
264
264
|
nodes.forEach((node) => {
|
|
265
|
+
// 先删除原有依赖,重新收集
|
|
265
266
|
target.removeDep(node);
|
|
266
267
|
this.collectItem(node, target, deep);
|
|
267
268
|
});
|
|
268
269
|
});
|
|
269
270
|
});
|
|
271
|
+
|
|
272
|
+
this.emit('collected', nodes, deep);
|
|
270
273
|
}
|
|
271
274
|
|
|
272
275
|
/**
|
|
@@ -299,6 +302,7 @@ export class Watcher extends EventEmitter {
|
|
|
299
302
|
|
|
300
303
|
if (target.isTarget(key, value)) {
|
|
301
304
|
target.updateDep(node, fullKey);
|
|
305
|
+
this.emit('update-dep', node, fullKey);
|
|
302
306
|
} else if (!keyIsItems && Array.isArray(value)) {
|
|
303
307
|
value.forEach((item, index) => {
|
|
304
308
|
collectTarget(item, `${fullKey}.${index}`);
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
import KeyController, { KeyControllerEvent } from 'keycon';
|
|
2
|
+
|
|
3
|
+
import { isPage } from '@tmagic/utils';
|
|
4
|
+
|
|
5
|
+
import { KeyBindingCacheItem, KeyBindingCommand, KeyBindingItem } from '@editor/type';
|
|
6
|
+
|
|
7
|
+
import BaseService from './BaseService';
|
|
8
|
+
import editorService from './editor';
|
|
9
|
+
import uiService from './ui';
|
|
10
|
+
|
|
11
|
+
class Keybinding extends BaseService {
|
|
12
|
+
public ctrlKey = /mac os x/.test(navigator.userAgent.toLowerCase()) ? 'meta' : 'ctrl';
|
|
13
|
+
|
|
14
|
+
private controllers = new Map<string, KeyController>();
|
|
15
|
+
|
|
16
|
+
private bindingList: KeyBindingCacheItem[] = [];
|
|
17
|
+
|
|
18
|
+
private commands: Record<KeyBindingCommand | string, (e: KeyboardEvent) => void | Promise<void>> = {
|
|
19
|
+
[KeyBindingCommand.DELETE_NODE]: () => {
|
|
20
|
+
const nodes = editorService.get('nodes');
|
|
21
|
+
|
|
22
|
+
if (!nodes || isPage(nodes[0])) return;
|
|
23
|
+
editorService.remove(nodes);
|
|
24
|
+
},
|
|
25
|
+
[KeyBindingCommand.COPY_NODE]: () => {
|
|
26
|
+
const nodes = editorService.get('nodes');
|
|
27
|
+
nodes && editorService.copy(nodes);
|
|
28
|
+
},
|
|
29
|
+
[KeyBindingCommand.CUT_NODE]: () => {
|
|
30
|
+
const nodes = editorService.get('nodes');
|
|
31
|
+
|
|
32
|
+
if (!nodes || isPage(nodes[0])) return;
|
|
33
|
+
editorService.copy(nodes);
|
|
34
|
+
editorService.remove(nodes);
|
|
35
|
+
},
|
|
36
|
+
[KeyBindingCommand.PASTE_NODE]: () => {
|
|
37
|
+
const nodes = editorService.get('nodes');
|
|
38
|
+
nodes && editorService.paste({ offsetX: 10, offsetY: 10 });
|
|
39
|
+
},
|
|
40
|
+
[KeyBindingCommand.UNDO]: () => {
|
|
41
|
+
editorService.undo();
|
|
42
|
+
},
|
|
43
|
+
[KeyBindingCommand.REDO]: () => {
|
|
44
|
+
editorService.redo();
|
|
45
|
+
},
|
|
46
|
+
[KeyBindingCommand.ZOOM_IN]: () => {
|
|
47
|
+
uiService.zoom(0.1);
|
|
48
|
+
},
|
|
49
|
+
[KeyBindingCommand.ZOOM_OUT]: () => {
|
|
50
|
+
uiService.zoom(-0.1);
|
|
51
|
+
},
|
|
52
|
+
[KeyBindingCommand.ZOOM_RESET]: () => {
|
|
53
|
+
uiService.set('zoom', 1);
|
|
54
|
+
},
|
|
55
|
+
[KeyBindingCommand.ZOOM_FIT]: async () => {
|
|
56
|
+
uiService.set('zoom', await uiService.calcZoom());
|
|
57
|
+
},
|
|
58
|
+
[KeyBindingCommand.MOVE_UP_1]: () => {
|
|
59
|
+
editorService.move(0, -1);
|
|
60
|
+
},
|
|
61
|
+
[KeyBindingCommand.MOVE_DOWN_1]: () => {
|
|
62
|
+
editorService.move(0, 1);
|
|
63
|
+
},
|
|
64
|
+
[KeyBindingCommand.MOVE_LEFT_1]: () => {
|
|
65
|
+
editorService.move(-1, 0);
|
|
66
|
+
},
|
|
67
|
+
[KeyBindingCommand.MOVE_RIGHT_1]: () => {
|
|
68
|
+
editorService.move(1, 0);
|
|
69
|
+
},
|
|
70
|
+
[KeyBindingCommand.MOVE_UP_10]: () => {
|
|
71
|
+
editorService.move(0, -10);
|
|
72
|
+
},
|
|
73
|
+
[KeyBindingCommand.MOVE_DOWN_10]: () => {
|
|
74
|
+
editorService.move(0, 10);
|
|
75
|
+
},
|
|
76
|
+
[KeyBindingCommand.MOVE_LEFT_10]: () => {
|
|
77
|
+
editorService.move(-10, 0);
|
|
78
|
+
},
|
|
79
|
+
[KeyBindingCommand.MOVE_RIGHT_10]: () => {
|
|
80
|
+
editorService.move(10, 0);
|
|
81
|
+
},
|
|
82
|
+
[KeyBindingCommand.SWITCH_NODE]: () => {
|
|
83
|
+
editorService.selectNextNode();
|
|
84
|
+
},
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
public registeCommand(command: string, handler: (e: KeyboardEvent) => void | Promise<void>) {
|
|
88
|
+
this.commands[command] = handler;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
public unregisteCommand(command: string) {
|
|
92
|
+
delete this.commands[command];
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
public registeEl(name: string, el?: HTMLElement) {
|
|
96
|
+
if (name !== 'global' && !el) {
|
|
97
|
+
throw new Error('只有name为global可以不传el');
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const keycon = new KeyController(el);
|
|
101
|
+
this.controllers.set(name, keycon);
|
|
102
|
+
this.bind(name);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
public unregisteEl(name: string) {
|
|
106
|
+
this.controllers.get(name)?.destroy();
|
|
107
|
+
this.controllers.delete(name);
|
|
108
|
+
this.bindingList.forEach((item) => {
|
|
109
|
+
item.binded = false;
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
public registe(maps: KeyBindingItem[]) {
|
|
114
|
+
for (const keybindingItem of maps) {
|
|
115
|
+
const { command, keybinding, when } = keybindingItem;
|
|
116
|
+
|
|
117
|
+
for (const [type = '', eventType = 'keydown'] of when) {
|
|
118
|
+
const cacheItem: KeyBindingCacheItem = { type, command, keybinding, eventType, binded: false };
|
|
119
|
+
|
|
120
|
+
this.bindingList.push(cacheItem);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
this.bind();
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
public reset() {
|
|
128
|
+
this.controllers.forEach((keycon) => {
|
|
129
|
+
keycon.destroy();
|
|
130
|
+
});
|
|
131
|
+
this.controllers.clear();
|
|
132
|
+
this.bindingList = [];
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
public destroy() {
|
|
136
|
+
this.reset();
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
private bind(name?: string) {
|
|
140
|
+
for (const item of this.bindingList) {
|
|
141
|
+
const { type, eventType, command, keybinding, binded } = item;
|
|
142
|
+
|
|
143
|
+
if (name && name !== type) {
|
|
144
|
+
continue;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
if (binded) {
|
|
148
|
+
continue;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
const keycon = this.controllers.get(type);
|
|
152
|
+
if (!keycon) {
|
|
153
|
+
continue;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
const handler = (e: KeyControllerEvent) => {
|
|
157
|
+
e.inputEvent.preventDefault();
|
|
158
|
+
|
|
159
|
+
this.commands[command]?.(e.inputEvent);
|
|
160
|
+
};
|
|
161
|
+
this.getKeyconKeys(keybinding).forEach((keys) => {
|
|
162
|
+
if (keys[0]) {
|
|
163
|
+
keycon[eventType](keys, handler);
|
|
164
|
+
} else {
|
|
165
|
+
keycon[eventType](handler);
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
item.binded = true;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
private getKeyconKeys(keybinding: string | string[] = '') {
|
|
174
|
+
const splitKey = (key: string) => key.split('+').map((k) => (k === 'ctrl' ? this.ctrlKey : k));
|
|
175
|
+
|
|
176
|
+
if (Array.isArray(keybinding)) {
|
|
177
|
+
return keybinding.map((key) => splitKey(key));
|
|
178
|
+
}
|
|
179
|
+
return [splitKey(keybinding)];
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
export type KeybindingService = Keybinding;
|
|
184
|
+
|
|
185
|
+
export default new Keybinding();
|
package/src/services/storage.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import serialize from 'serialize-javascript';
|
|
2
2
|
|
|
3
|
+
import { getConfig } from '@editor/utils/config';
|
|
4
|
+
|
|
3
5
|
import BaseService from './BaseService';
|
|
4
6
|
|
|
5
7
|
interface Options {
|
|
@@ -64,8 +66,7 @@ export class WebStorage extends BaseService {
|
|
|
64
66
|
|
|
65
67
|
switch (protocol) {
|
|
66
68
|
case Protocol.OBJECT:
|
|
67
|
-
|
|
68
|
-
return eval(`(${item})`);
|
|
69
|
+
return getConfig('parseDSL')(`(${item})`);
|
|
69
70
|
case Protocol.JSON:
|
|
70
71
|
return JSON.parse(item);
|
|
71
72
|
case Protocol.NUMBER:
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
.tmagic-data-source-input-text {
|
|
2
|
+
.el-input__wrapper.tmagic-data-source-input-text-wrapper {
|
|
3
|
+
overflow: hidden;
|
|
4
|
+
padding-right: 30px;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
.el-input__inner {
|
|
8
|
+
display: flex;
|
|
9
|
+
align-items: center;
|
|
10
|
+
overflow: hidden;
|
|
11
|
+
white-space: nowrap;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
.tmagic-data-source-input-icon {
|
|
15
|
+
position: absolute;
|
|
16
|
+
right: 7px;
|
|
17
|
+
}
|
|
18
|
+
}
|
package/src/theme/framework.scss
CHANGED
package/src/theme/layout.scss
CHANGED
package/src/theme/resizer.scss
CHANGED
|
@@ -4,14 +4,38 @@
|
|
|
4
4
|
width: 8px;
|
|
5
5
|
margin: 0 -5px;
|
|
6
6
|
height: 100%;
|
|
7
|
-
opacity: 0.
|
|
7
|
+
opacity: 0.8;
|
|
8
8
|
background: padding-box #d8dee8;
|
|
9
9
|
box-sizing: border-box;
|
|
10
10
|
cursor: col-resize;
|
|
11
11
|
z-index: 1;
|
|
12
|
+
position: relative;
|
|
12
13
|
|
|
13
14
|
&:hover {
|
|
14
15
|
border-color: #d8dee8;
|
|
16
|
+
|
|
17
|
+
.icon-container {
|
|
18
|
+
visibility: visible;
|
|
19
|
+
opacity: 1;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
&.m-editor-resizer-draging {
|
|
24
|
+
&::after {
|
|
25
|
+
content: "";
|
|
26
|
+
position: absolute;
|
|
27
|
+
width: 600px;
|
|
28
|
+
height: 100%;
|
|
29
|
+
left: 0;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
&::before {
|
|
33
|
+
content: "";
|
|
34
|
+
position: absolute;
|
|
35
|
+
width: 600px;
|
|
36
|
+
height: 100%;
|
|
37
|
+
right: 0;
|
|
38
|
+
}
|
|
15
39
|
}
|
|
16
40
|
|
|
17
41
|
.icon-container {
|
|
@@ -40,12 +64,3 @@
|
|
|
40
64
|
font-size: 18px;
|
|
41
65
|
}
|
|
42
66
|
}
|
|
43
|
-
|
|
44
|
-
.magic-editor-resizer:hover {
|
|
45
|
-
.icon-container {
|
|
46
|
-
visibility: visible;
|
|
47
|
-
opacity: 1;
|
|
48
|
-
}
|
|
49
|
-
// border-left: 5px solid rgba(0,0,0,.5);
|
|
50
|
-
// border-right: 5px solid rgba(0,0,0,.5);
|
|
51
|
-
}
|
package/src/theme/stage.scss
CHANGED
package/src/theme/theme.scss
CHANGED
package/src/type.ts
CHANGED
|
@@ -30,11 +30,12 @@ import type {
|
|
|
30
30
|
|
|
31
31
|
import type { CodeBlockService } from './services/codeBlock';
|
|
32
32
|
import type { ComponentListService } from './services/componentList';
|
|
33
|
-
import { DataSourceService } from './services/dataSource';
|
|
33
|
+
import type { DataSourceService } from './services/dataSource';
|
|
34
34
|
import type { DepService } from './services/dep';
|
|
35
35
|
import type { EditorService } from './services/editor';
|
|
36
36
|
import type { EventsService } from './services/events';
|
|
37
37
|
import type { HistoryService } from './services/history';
|
|
38
|
+
import type { KeybindingService } from './services/keybinding';
|
|
38
39
|
import type { PropsService } from './services/props';
|
|
39
40
|
import type { StorageService } from './services/storage';
|
|
40
41
|
import type { UiService } from './services/ui';
|
|
@@ -44,6 +45,7 @@ export type BeforeAdd = (config: MNode, parent: MContainer) => Promise<MNode> |
|
|
|
44
45
|
export type GetConfig = (config: FormConfig) => Promise<FormConfig> | FormConfig;
|
|
45
46
|
|
|
46
47
|
export interface InstallOptions {
|
|
48
|
+
parseDSL: (dsl: string) => MApp;
|
|
47
49
|
[key: string]: any;
|
|
48
50
|
}
|
|
49
51
|
|
|
@@ -58,6 +60,7 @@ export interface Services {
|
|
|
58
60
|
codeBlockService: CodeBlockService;
|
|
59
61
|
depService: DepService;
|
|
60
62
|
dataSourceService: DataSourceService;
|
|
63
|
+
keybindingService: KeybindingService;
|
|
61
64
|
}
|
|
62
65
|
|
|
63
66
|
export interface StageOptions {
|
|
@@ -427,3 +430,58 @@ export interface EventSelectConfig {
|
|
|
427
430
|
/** 联动代码配置 */
|
|
428
431
|
codeActionConfig?: FormItem;
|
|
429
432
|
}
|
|
433
|
+
|
|
434
|
+
export enum KeyBindingCommand {
|
|
435
|
+
/** 复制 */
|
|
436
|
+
COPY_NODE = 'tmagic-system-copy-node',
|
|
437
|
+
/** 粘贴 */
|
|
438
|
+
PASTE_NODE = 'tmagic-system-paste-node',
|
|
439
|
+
/** 删除 */
|
|
440
|
+
DELETE_NODE = 'tmagic-system-delete-node',
|
|
441
|
+
/** 剪切 */
|
|
442
|
+
CUT_NODE = 'tmagic-system-cut-node',
|
|
443
|
+
/** 撤销 */
|
|
444
|
+
UNDO = 'tmagic-system-undo',
|
|
445
|
+
/** 重做 */
|
|
446
|
+
REDO = 'tmagic-system-redo',
|
|
447
|
+
/** 放大 */
|
|
448
|
+
ZOOM_IN = 'tmagic-system-zoom-in',
|
|
449
|
+
/** 缩小 */
|
|
450
|
+
ZOOM_OUT = 'tmagic-system-zoom-out',
|
|
451
|
+
/** 缩放到实际大小 */
|
|
452
|
+
ZOOM_RESET = 'tmagic-system-zoom-reset',
|
|
453
|
+
/** 缩放以适应 */
|
|
454
|
+
ZOOM_FIT = 'tmagic-system-zoom-fit',
|
|
455
|
+
/** 向上移动1px */
|
|
456
|
+
MOVE_UP_1 = 'tmagic-system-move-up-1',
|
|
457
|
+
/** 向下移动1px */
|
|
458
|
+
MOVE_DOWN_1 = 'tmagic-system-move-down-1',
|
|
459
|
+
/** 向左移动1px */
|
|
460
|
+
MOVE_LEFT_1 = 'tmagic-system-move-left-1',
|
|
461
|
+
/** 向右移动1px */
|
|
462
|
+
MOVE_RIGHT_1 = 'tmagic-system-move-right-1',
|
|
463
|
+
/** 向上移动10px */
|
|
464
|
+
MOVE_UP_10 = 'tmagic-system-move-up-10',
|
|
465
|
+
/** 向下移动10px */
|
|
466
|
+
MOVE_DOWN_10 = 'tmagic-system-move-down-10',
|
|
467
|
+
/** 向左移动10px */
|
|
468
|
+
MOVE_LEFT_10 = 'tmagic-system-move-left-10',
|
|
469
|
+
/** 向右移动10px */
|
|
470
|
+
MOVE_RIGHT_10 = 'tmagic-system-move-right-10',
|
|
471
|
+
/** 切换组件 */
|
|
472
|
+
SWITCH_NODE = 'tmagic-system-switch-node',
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
export interface KeyBindingItem {
|
|
476
|
+
command: KeyBindingCommand | string;
|
|
477
|
+
keybinding?: string | string[];
|
|
478
|
+
when: [string, 'keyup' | 'keydown'][];
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
export interface KeyBindingCacheItem {
|
|
482
|
+
type: string;
|
|
483
|
+
command: KeyBindingCommand | string;
|
|
484
|
+
keybinding?: string | string[];
|
|
485
|
+
eventType: 'keyup' | 'keydown';
|
|
486
|
+
binded: boolean;
|
|
487
|
+
}
|
package/src/utils/config.ts
CHANGED
|
@@ -24,6 +24,6 @@ const setConfig = (option: InstallOptions): void => {
|
|
|
24
24
|
$TMAGIC_EDITOR = option;
|
|
25
25
|
};
|
|
26
26
|
|
|
27
|
-
const getConfig = (key:
|
|
27
|
+
const getConfig = <K extends keyof InstallOptions>(key: K): InstallOptions[K] => $TMAGIC_EDITOR[key];
|
|
28
28
|
|
|
29
29
|
export { getConfig, setConfig };
|