@tmagic/editor 1.0.0-beta.12 → 1.0.0-beta.13
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 +1444 -0
- package/coverage/coverage-final.json +34 -0
- package/coverage/lcov-report/Icon.vue.html +172 -0
- package/coverage/lcov-report/ToolButton.vue.html +655 -0
- package/coverage/lcov-report/base.css +224 -0
- package/coverage/lcov-report/block-navigation.js +87 -0
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/index.html +206 -0
- package/coverage/lcov-report/layouts/sidebar/LayerMenu.vue.html +364 -0
- package/coverage/lcov-report/layouts/sidebar/index.html +116 -0
- package/coverage/lcov-report/prettify.css +1 -0
- package/coverage/lcov-report/prettify.js +2 -0
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +196 -0
- package/coverage/lcov-report/src/Editor.vue.html +787 -0
- package/coverage/lcov-report/src/components/Icon.vue.html +172 -0
- package/coverage/lcov-report/src/components/ScrollViewer.vue.html +283 -0
- package/coverage/lcov-report/src/components/ToolButton.vue.html +655 -0
- package/coverage/lcov-report/src/components/index.html +146 -0
- package/coverage/lcov-report/src/index.html +131 -0
- package/coverage/lcov-report/src/layouts/AddPageBox.vue.html +214 -0
- package/coverage/lcov-report/src/layouts/Framework.vue.html +304 -0
- package/coverage/lcov-report/src/layouts/NavMenu.vue.html +208 -0
- package/coverage/lcov-report/src/layouts/PropsPanel.vue.html +316 -0
- package/coverage/lcov-report/src/layouts/Resizer.vue.html +268 -0
- package/coverage/lcov-report/src/layouts/index.html +176 -0
- package/coverage/lcov-report/src/layouts/sidebar/ComponentListPanel.vue.html +292 -0
- package/coverage/lcov-report/src/layouts/sidebar/LayerMenu.vue.html +364 -0
- package/coverage/lcov-report/src/layouts/sidebar/LayerPanel.vue.html +853 -0
- package/coverage/lcov-report/src/layouts/sidebar/Sidebar.vue.html +343 -0
- package/coverage/lcov-report/src/layouts/sidebar/index.html +161 -0
- package/coverage/lcov-report/src/layouts/workspace/PageBar.vue.html +631 -0
- package/coverage/lcov-report/src/layouts/workspace/Stage.vue.html +766 -0
- package/coverage/lcov-report/src/layouts/workspace/ViewerMenu.vue.html +421 -0
- package/coverage/lcov-report/src/layouts/workspace/Workspace.vue.html +586 -0
- package/coverage/lcov-report/src/layouts/workspace/index.html +161 -0
- package/coverage/lcov-report/src/services/BaseService.ts.html +643 -0
- package/coverage/lcov-report/src/services/componentList.ts.html +229 -0
- package/coverage/lcov-report/src/services/editor.ts.html +1984 -0
- package/coverage/lcov-report/src/services/events.ts.html +331 -0
- package/coverage/lcov-report/src/services/history.ts.html +457 -0
- package/coverage/lcov-report/src/services/index.html +206 -0
- package/coverage/lcov-report/src/services/props.ts.html +418 -0
- package/coverage/lcov-report/src/services/ui.ts.html +514 -0
- package/coverage/lcov-report/src/type.ts.html +850 -0
- package/coverage/lcov-report/src/utils/compose.ts.html +184 -0
- package/coverage/lcov-report/src/utils/config.ts.html +172 -0
- package/coverage/lcov-report/src/utils/editor.ts.html +838 -0
- package/coverage/lcov-report/src/utils/index.html +221 -0
- package/coverage/lcov-report/src/utils/index.ts.html +151 -0
- package/coverage/lcov-report/src/utils/logger.ts.html +226 -0
- package/coverage/lcov-report/src/utils/props.ts.html +739 -0
- package/coverage/lcov-report/src/utils/scroll-viewer.ts.html +733 -0
- package/coverage/lcov-report/src/utils/undo-redo.ts.html +313 -0
- package/coverage/lcov-report/utils/index.html +116 -0
- package/coverage/lcov-report/utils/undo-redo.ts.html +313 -0
- package/coverage/lcov.info +3407 -0
- package/dist/style.css +3 -2
- package/dist/tmagic-editor.es.js +326 -194
- package/dist/tmagic-editor.es.js.map +1 -1
- package/dist/tmagic-editor.umd.js +328 -197
- package/dist/tmagic-editor.umd.js.map +1 -1
- package/dist/types/src/layouts/sidebar/LayerPanel.vue.d.ts +1 -1
- package/dist/types/src/services/editor.d.ts +5 -2
- package/dist/types/src/services/ui.d.ts +1 -0
- package/dist/types/src/utils/editor.d.ts +2 -2
- package/package.json +18 -9
- package/src/components/ScrollViewer.vue +1 -1
- package/src/components/ToolButton.vue +3 -3
- package/src/layouts/workspace/Workspace.vue +74 -16
- package/src/services/BaseService.ts +1 -1
- package/src/services/editor.ts +65 -9
- package/src/services/ui.ts +5 -0
- package/src/theme/layer-panel.scss +1 -0
- package/src/utils/editor.ts +6 -2
- package/tsconfig.json +0 -9
- package/vite.config.ts +0 -30
|
@@ -2,7 +2,7 @@ import type { Translator } from 'element-plus';
|
|
|
2
2
|
import type { Nullable } from 'element-plus/es/utils';
|
|
3
3
|
import type { default } from 'element-plus/es/components/tree/src/model/node';
|
|
4
4
|
import type { TreeOptionProps, TreeKey, LoadFunction, FilterNodeMethodFunction, TreeNodeData, FakeNode, TreeNodeLoadedDefaultProps, TreeData } from 'element-plus/es/components/tree/src/tree.type';
|
|
5
|
-
import type { DebouncedFunc } from 'lodash';
|
|
5
|
+
import type { DebouncedFunc } from 'lodash-es';
|
|
6
6
|
import type { DefineComponent, ComputedRef, ComponentInternalInstance, ExtractPropTypes, PropType, Component, ComputedOptions, MethodOptions, VNodeProps, AllowedComponentProps, ComponentCustomProps, Slot, ComponentPublicInstance, ComponentOptionsBase, ComponentOptionsMixin, DebuggerEvent, nextTick, WatchOptions, WatchStopHandle, ShallowUnwrapRef, ComponentCustomProperties, EmitsOptions, Ref } from 'vue';
|
|
7
7
|
import type { Id, MNode } from '@tmagic/schema';
|
|
8
8
|
declare const _default: DefineComponent<{}, {
|
|
@@ -41,13 +41,15 @@ declare class Editor extends BaseService {
|
|
|
41
41
|
/**
|
|
42
42
|
* 只有容器拥有布局
|
|
43
43
|
*/
|
|
44
|
-
getLayout(
|
|
44
|
+
getLayout(parent: MNode, node?: MNode): Promise<Layout>;
|
|
45
45
|
/**
|
|
46
46
|
* 选中指定节点(将指定节点设置成当前选中状态)
|
|
47
47
|
* @param config 指定节点配置或者ID
|
|
48
48
|
* @returns 当前选中的节点配置
|
|
49
49
|
*/
|
|
50
50
|
select(config: MNode | Id): Promise<MNode> | never;
|
|
51
|
+
selectNextNode(): Promise<MNode> | never;
|
|
52
|
+
selectNextPage(): Promise<MNode> | never;
|
|
51
53
|
/**
|
|
52
54
|
* 高亮指定节点
|
|
53
55
|
* @param config 指定节点配置或者ID
|
|
@@ -60,7 +62,7 @@ declare class Editor extends BaseService {
|
|
|
60
62
|
* @param parent 要添加到的容器组件节点配置,如果不设置,默认为当前选中的组件的父节点
|
|
61
63
|
* @returns 添加后的节点
|
|
62
64
|
*/
|
|
63
|
-
add(
|
|
65
|
+
add(addNode: AddMNode, parent?: MContainer | null): Promise<MNode>;
|
|
64
66
|
/**
|
|
65
67
|
* 删除组件
|
|
66
68
|
* @param {Object} node
|
|
@@ -116,6 +118,7 @@ declare class Editor extends BaseService {
|
|
|
116
118
|
* @returns 下一步数据
|
|
117
119
|
*/
|
|
118
120
|
redo(): Promise<StepValue | null>;
|
|
121
|
+
move(left: number, top: number): Promise<void>;
|
|
119
122
|
destroy(): void;
|
|
120
123
|
resetModifiedNodeId(): void;
|
|
121
124
|
private addModifiedNodeId;
|
|
@@ -37,9 +37,9 @@ export declare const setNewItemId: (config: MNode, parent?: MPage | undefined) =
|
|
|
37
37
|
* @returns {boolean}
|
|
38
38
|
*/
|
|
39
39
|
export declare const isFixed: (node: MNode) => boolean;
|
|
40
|
-
export declare const getNodeIndex: (node: MNode, parent: MContainer) => number;
|
|
40
|
+
export declare const getNodeIndex: (node: MNode, parent: MContainer | MApp) => number;
|
|
41
41
|
export declare const toRelative: (node: MNode) => MNode;
|
|
42
42
|
export declare const initPosition: (node: MNode, layout: Layout, parentNode: MNode, stage: StageCore) => MNode;
|
|
43
43
|
export declare const setLayout: (node: MNode, layout: Layout) => MNode;
|
|
44
44
|
export declare const change2Fixed: (node: MNode, root: MApp) => MNode;
|
|
45
|
-
export declare const Fixed2Other: (node: MNode, root: MApp, getLayout: (
|
|
45
|
+
export declare const Fixed2Other: (node: MNode, root: MApp, getLayout: (parent: MNode, node?: MNode | undefined) => Promise<Layout>) => Promise<MNode>;
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.0.0-beta.
|
|
2
|
+
"version": "1.0.0-beta.13",
|
|
3
3
|
"name": "@tmagic/editor",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"main": "dist/tmagic-editor.umd.js",
|
|
@@ -16,8 +16,11 @@
|
|
|
16
16
|
"require": "./dist/style.css"
|
|
17
17
|
}
|
|
18
18
|
},
|
|
19
|
+
"license": "Apache-2.0",
|
|
19
20
|
"scripts": {
|
|
20
|
-
"build": "vite build"
|
|
21
|
+
"build": "vite build",
|
|
22
|
+
"test": "jest --maxWorkers=8",
|
|
23
|
+
"test:coverage": "jest --maxWorkers=16 --coverage"
|
|
21
24
|
},
|
|
22
25
|
"engines": {
|
|
23
26
|
"node": ">=14"
|
|
@@ -37,11 +40,11 @@
|
|
|
37
40
|
],
|
|
38
41
|
"dependencies": {
|
|
39
42
|
"@element-plus/icons": "0.0.11",
|
|
40
|
-
"@tmagic/core": "^1.0.0-beta.
|
|
41
|
-
"@tmagic/form": "^1.0.0-beta.
|
|
42
|
-
"@tmagic/schema": "^1.0.0-beta.
|
|
43
|
-
"@tmagic/stage": "^1.0.0-beta.
|
|
44
|
-
"@tmagic/utils": "^1.0.0-beta.
|
|
43
|
+
"@tmagic/core": "^1.0.0-beta.13",
|
|
44
|
+
"@tmagic/form": "^1.0.0-beta.13",
|
|
45
|
+
"@tmagic/schema": "^1.0.0-beta.13",
|
|
46
|
+
"@tmagic/stage": "^1.0.0-beta.13",
|
|
47
|
+
"@tmagic/utils": "^1.0.0-beta.13",
|
|
45
48
|
"color": "^3.1.3",
|
|
46
49
|
"element-plus": "^2.1.7",
|
|
47
50
|
"events": "^3.3.0",
|
|
@@ -53,18 +56,24 @@
|
|
|
53
56
|
},
|
|
54
57
|
"devDependencies": {
|
|
55
58
|
"@types/events": "^3.0.0",
|
|
59
|
+
"@types/jest": "^26.0.23",
|
|
56
60
|
"@types/lodash-es": "^4.17.4",
|
|
57
61
|
"@types/node": "^15.12.4",
|
|
58
62
|
"@types/serialize-javascript": "^5.0.1",
|
|
59
63
|
"@vitejs/plugin-vue": "^1.2.3",
|
|
60
64
|
"@vitejs/plugin-vue-jsx": "^1.1.6",
|
|
61
65
|
"@vue/compiler-sfc": "^3.2.0",
|
|
62
|
-
"@vue/test-utils": "^2.0.0-rc.
|
|
66
|
+
"@vue/test-utils": "^2.0.0-rc.20",
|
|
67
|
+
"@vue/vue3-jest": "^27.0.0-alpha.4",
|
|
68
|
+
"jest": "^27.5.1",
|
|
69
|
+
"jest-serializer-vue": "^2.0.2",
|
|
70
|
+
"jest-transform-stub": "^2.0.0",
|
|
63
71
|
"sass": "^1.35.1",
|
|
72
|
+
"ts-jest": "^27.1.4",
|
|
64
73
|
"typescript": "^4.3.4",
|
|
65
74
|
"vite": "^2.3.7",
|
|
66
75
|
"vite-plugin-dts": "^0.9.6",
|
|
67
76
|
"vue-tsc": "^0.0.24"
|
|
68
77
|
},
|
|
69
|
-
"gitHead": "
|
|
78
|
+
"gitHead": "ca2b203614cbdaff580e5cb6f35630f50b827451"
|
|
70
79
|
}
|
|
@@ -64,13 +64,13 @@ export default defineComponent({
|
|
|
64
64
|
const services = inject<Services>('services');
|
|
65
65
|
const uiService = services?.uiService;
|
|
66
66
|
|
|
67
|
-
const zoomInHandler = () => uiService?.set('zoom', zoom.value + 0.1);
|
|
68
|
-
const zoomOutHandler = () => uiService?.set('zoom', zoom.value - 0.1);
|
|
69
|
-
|
|
70
67
|
const zoom = computed((): number => uiService?.get<number>('zoom') ?? 1);
|
|
71
68
|
const showGuides = computed((): boolean => uiService?.get<boolean>('showGuides') ?? true);
|
|
72
69
|
const showRule = computed((): boolean => uiService?.get<boolean>('showRule') ?? true);
|
|
73
70
|
|
|
71
|
+
const zoomInHandler = () => uiService?.zoom(0.1);
|
|
72
|
+
const zoomOutHandler = () => uiService?.zoom(-0.1);
|
|
73
|
+
|
|
74
74
|
const item = computed((): MenuButton | MenuComponent => {
|
|
75
75
|
if (typeof props.data !== 'string') {
|
|
76
76
|
return props.data;
|
|
@@ -24,6 +24,7 @@ import KeyController from 'keycon';
|
|
|
24
24
|
import type { MNode, MPage } from '@tmagic/schema';
|
|
25
25
|
import type { MoveableOptions } from '@tmagic/stage';
|
|
26
26
|
import StageCore from '@tmagic/stage';
|
|
27
|
+
import { isPage } from '@tmagic/utils';
|
|
27
28
|
|
|
28
29
|
import type { Services } from '@editor/type';
|
|
29
30
|
|
|
@@ -64,38 +65,95 @@ export default defineComponent({
|
|
|
64
65
|
workspace.value?.focus();
|
|
65
66
|
};
|
|
66
67
|
|
|
67
|
-
const mouseleaveHandler = () => {
|
|
68
|
-
workspace.value?.blur();
|
|
69
|
-
};
|
|
70
|
-
|
|
71
68
|
onMounted(() => {
|
|
72
69
|
workspace.value?.addEventListener('mouseenter', mouseenterHandler);
|
|
73
70
|
|
|
74
|
-
workspace.value?.addEventListener('mouseleave', mouseleaveHandler);
|
|
75
|
-
|
|
76
71
|
keycon = new KeyController(workspace.value);
|
|
77
72
|
|
|
73
|
+
const isMac = /mac os x/.test(navigator.userAgent.toLowerCase());
|
|
74
|
+
|
|
75
|
+
const ctrl = isMac ? 'meta' : 'ctrl';
|
|
76
|
+
|
|
78
77
|
keycon
|
|
79
|
-
.keyup('delete', () => {
|
|
80
|
-
|
|
78
|
+
.keyup('delete', (e) => {
|
|
79
|
+
e.inputEvent.preventDefault();
|
|
80
|
+
if (!node.value || isPage(node.value)) return;
|
|
81
|
+
services?.editorService.remove(node.value);
|
|
81
82
|
})
|
|
82
|
-
.
|
|
83
|
+
.keydown([ctrl, 'c'], (e) => {
|
|
84
|
+
e.inputEvent.preventDefault();
|
|
83
85
|
node.value && services?.editorService.copy(node.value);
|
|
84
86
|
})
|
|
85
|
-
.keyup([
|
|
87
|
+
.keyup([ctrl, 'v'], (e) => {
|
|
88
|
+
e.inputEvent.preventDefault();
|
|
86
89
|
node.value && services?.editorService.paste();
|
|
87
90
|
})
|
|
88
|
-
.keyup([
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
91
|
+
.keyup([ctrl, 'x'], (e) => {
|
|
92
|
+
e.inputEvent.preventDefault();
|
|
93
|
+
if (!node.value || isPage(node.value)) return;
|
|
94
|
+
services?.editorService.copy(node.value);
|
|
95
|
+
services?.editorService.remove(node.value);
|
|
96
|
+
})
|
|
97
|
+
.keydown([ctrl, 'z'], (e) => {
|
|
98
|
+
e.inputEvent.preventDefault();
|
|
99
|
+
services?.editorService.undo();
|
|
100
|
+
})
|
|
101
|
+
.keydown([ctrl, 'shift', 'z'], (e) => {
|
|
102
|
+
e.inputEvent.preventDefault();
|
|
103
|
+
services?.editorService.redo();
|
|
104
|
+
})
|
|
105
|
+
.keydown('up', (e) => {
|
|
106
|
+
e.inputEvent.preventDefault();
|
|
107
|
+
services?.editorService.move(0, -1);
|
|
108
|
+
})
|
|
109
|
+
.keydown('down', (e) => {
|
|
110
|
+
e.inputEvent.preventDefault();
|
|
111
|
+
services?.editorService.move(0, 1);
|
|
112
|
+
})
|
|
113
|
+
.keydown('left', (e) => {
|
|
114
|
+
e.inputEvent.preventDefault();
|
|
115
|
+
services?.editorService.move(-1, 0);
|
|
116
|
+
})
|
|
117
|
+
.keydown('right', (e) => {
|
|
118
|
+
e.inputEvent.preventDefault();
|
|
119
|
+
services?.editorService.move(1, 0);
|
|
120
|
+
})
|
|
121
|
+
.keydown([ctrl, 'up'], (e) => {
|
|
122
|
+
e.inputEvent.preventDefault();
|
|
123
|
+
services?.editorService.move(0, -10);
|
|
124
|
+
})
|
|
125
|
+
.keydown([ctrl, 'down'], (e) => {
|
|
126
|
+
e.inputEvent.preventDefault();
|
|
127
|
+
services?.editorService.move(0, 10);
|
|
128
|
+
})
|
|
129
|
+
.keydown([ctrl, 'left'], (e) => {
|
|
130
|
+
e.inputEvent.preventDefault();
|
|
131
|
+
services?.editorService.move(-10, 0);
|
|
132
|
+
})
|
|
133
|
+
.keydown([ctrl, 'right'], (e) => {
|
|
134
|
+
e.inputEvent.preventDefault();
|
|
135
|
+
services?.editorService.move(10, 0);
|
|
136
|
+
})
|
|
137
|
+
.keydown('tab', (e) => {
|
|
138
|
+
e.inputEvent.preventDefault();
|
|
139
|
+
services?.editorService.selectNextNode();
|
|
140
|
+
})
|
|
141
|
+
.keydown([ctrl, 'tab'], (e) => {
|
|
142
|
+
e.inputEvent.preventDefault();
|
|
143
|
+
services?.editorService.selectNextPage();
|
|
144
|
+
})
|
|
145
|
+
.keydown([ctrl, '='], (e) => {
|
|
146
|
+
e.inputEvent.preventDefault();
|
|
147
|
+
services?.uiService.zoom(0.1);
|
|
148
|
+
})
|
|
149
|
+
.keydown([ctrl, '-'], (e) => {
|
|
150
|
+
e.inputEvent.preventDefault();
|
|
151
|
+
services?.uiService.zoom(-0.1);
|
|
93
152
|
});
|
|
94
153
|
});
|
|
95
154
|
|
|
96
155
|
onUnmounted(() => {
|
|
97
156
|
workspace.value?.removeEventListener('mouseenter', mouseenterHandler);
|
|
98
|
-
workspace.value?.removeEventListener('mouseleave', mouseleaveHandler);
|
|
99
157
|
keycon.destroy();
|
|
100
158
|
});
|
|
101
159
|
|
|
@@ -53,7 +53,7 @@ const doAction = async (
|
|
|
53
53
|
let returnValue: any = await fn(beforeArgs, sourceMethod.bind(scope));
|
|
54
54
|
|
|
55
55
|
for (const afterMethod of scope.pluginOptionsList[afterMethodName]) {
|
|
56
|
-
returnValue = await afterMethod(...beforeArgs
|
|
56
|
+
returnValue = await afterMethod(returnValue, ...beforeArgs);
|
|
57
57
|
|
|
58
58
|
if (isError(returnValue)) throw returnValue;
|
|
59
59
|
}
|
package/src/services/editor.ts
CHANGED
|
@@ -23,7 +23,7 @@ import serialize from 'serialize-javascript';
|
|
|
23
23
|
import type { Id, MApp, MComponent, MContainer, MNode, MPage } from '@tmagic/schema';
|
|
24
24
|
import { NodeType } from '@tmagic/schema';
|
|
25
25
|
import StageCore from '@tmagic/stage';
|
|
26
|
-
import { getNodePath, isPop } from '@tmagic/utils';
|
|
26
|
+
import { getNodePath, isNumber, isPage, isPop } from '@tmagic/utils';
|
|
27
27
|
|
|
28
28
|
import historyService, { StepValue } from '@editor/services/history';
|
|
29
29
|
import propsService from '@editor/services/props';
|
|
@@ -108,7 +108,7 @@ class Editor extends BaseService {
|
|
|
108
108
|
* @returns {EditorNodeInfo}
|
|
109
109
|
*/
|
|
110
110
|
public getNodeInfo(id: Id): EditorNodeInfo {
|
|
111
|
-
const root = this.get<MApp | null>('root');
|
|
111
|
+
const root = toRaw(this.get<MApp | null>('root'));
|
|
112
112
|
if (!root) return {};
|
|
113
113
|
|
|
114
114
|
if (id === root.id) {
|
|
@@ -159,13 +159,15 @@ class Editor extends BaseService {
|
|
|
159
159
|
/**
|
|
160
160
|
* 只有容器拥有布局
|
|
161
161
|
*/
|
|
162
|
-
public async getLayout(
|
|
163
|
-
if (node
|
|
164
|
-
|
|
162
|
+
public async getLayout(parent: MNode, node?: MNode): Promise<Layout> {
|
|
163
|
+
if (node && typeof node !== 'function' && isFixed(node)) return Layout.FIXED;
|
|
164
|
+
|
|
165
|
+
if (parent.layout) {
|
|
166
|
+
return parent.layout;
|
|
165
167
|
}
|
|
166
168
|
|
|
167
169
|
// 如果该节点没有设置position,则认为是流式布局,例如获取root的布局时
|
|
168
|
-
if (!
|
|
170
|
+
if (!parent.style?.position) {
|
|
169
171
|
return Layout.RELATIVE;
|
|
170
172
|
}
|
|
171
173
|
|
|
@@ -191,6 +193,39 @@ class Editor extends BaseService {
|
|
|
191
193
|
return node!;
|
|
192
194
|
}
|
|
193
195
|
|
|
196
|
+
public async selectNextNode(): Promise<MNode> | never {
|
|
197
|
+
const node = toRaw(this.get('node'));
|
|
198
|
+
|
|
199
|
+
if (!node || isPage(node) || node.type === NodeType.ROOT) return node;
|
|
200
|
+
|
|
201
|
+
const parent = toRaw(this.getParentById(node.id));
|
|
202
|
+
|
|
203
|
+
if (!parent) return node;
|
|
204
|
+
|
|
205
|
+
const index = getNodeIndex(node, parent);
|
|
206
|
+
|
|
207
|
+
const nextNode = parent.items[index + 1] || parent.items[0];
|
|
208
|
+
|
|
209
|
+
await this.select(nextNode);
|
|
210
|
+
this.get<StageCore>('stage')?.select(nextNode.id);
|
|
211
|
+
|
|
212
|
+
return nextNode;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
public async selectNextPage(): Promise<MNode> | never {
|
|
216
|
+
const root = toRaw(this.get<MApp>('root'));
|
|
217
|
+
const page = toRaw(this.get('page'));
|
|
218
|
+
|
|
219
|
+
const index = getNodeIndex(page, root);
|
|
220
|
+
|
|
221
|
+
const nextPage = root.items[index + 1] || root.items[0];
|
|
222
|
+
|
|
223
|
+
await this.select(nextPage);
|
|
224
|
+
this.get<StageCore>('stage')?.select(nextPage.id);
|
|
225
|
+
|
|
226
|
+
return nextPage;
|
|
227
|
+
}
|
|
228
|
+
|
|
194
229
|
/**
|
|
195
230
|
* 高亮指定节点
|
|
196
231
|
* @param config 指定节点配置或者ID
|
|
@@ -209,7 +244,8 @@ class Editor extends BaseService {
|
|
|
209
244
|
* @param parent 要添加到的容器组件节点配置,如果不设置,默认为当前选中的组件的父节点
|
|
210
245
|
* @returns 添加后的节点
|
|
211
246
|
*/
|
|
212
|
-
public async add(
|
|
247
|
+
public async add(addNode: AddMNode, parent?: MContainer | null): Promise<MNode> {
|
|
248
|
+
const { type, ...config } = addNode;
|
|
213
249
|
const curNode = this.get<MContainer>('node');
|
|
214
250
|
|
|
215
251
|
let parentNode: MNode | undefined;
|
|
@@ -227,7 +263,7 @@ class Editor extends BaseService {
|
|
|
227
263
|
|
|
228
264
|
if (!parentNode) throw new Error('未找到父元素');
|
|
229
265
|
|
|
230
|
-
const layout = await this.getLayout(parentNode);
|
|
266
|
+
const layout = await this.getLayout(toRaw(parentNode), addNode as MNode);
|
|
231
267
|
const newNode = initPosition(
|
|
232
268
|
{ ...toRaw(await propsService.getPropsValue(type, config)) },
|
|
233
269
|
layout,
|
|
@@ -432,7 +468,7 @@ class Editor extends BaseService {
|
|
|
432
468
|
public async alignCenter(config: MNode): Promise<MNode | void> {
|
|
433
469
|
const parent = this.get<MContainer>('parent');
|
|
434
470
|
const node = this.get<MNode>('node');
|
|
435
|
-
const layout = await this.getLayout(parent);
|
|
471
|
+
const layout = await this.getLayout(toRaw(parent), toRaw(node));
|
|
436
472
|
if (layout === Layout.RELATIVE) {
|
|
437
473
|
return;
|
|
438
474
|
}
|
|
@@ -490,6 +526,26 @@ class Editor extends BaseService {
|
|
|
490
526
|
return value;
|
|
491
527
|
}
|
|
492
528
|
|
|
529
|
+
public async move(left: number, top: number) {
|
|
530
|
+
const node = toRaw(this.get('node'));
|
|
531
|
+
if (!node || isPage(node)) return;
|
|
532
|
+
|
|
533
|
+
const { style, id } = node;
|
|
534
|
+
if (!style || style.position !== 'absolute') return;
|
|
535
|
+
|
|
536
|
+
if (top && !isNumber(style.top)) return;
|
|
537
|
+
if (left && !isNumber(style.left)) return;
|
|
538
|
+
|
|
539
|
+
this.update({
|
|
540
|
+
id,
|
|
541
|
+
style: {
|
|
542
|
+
...style,
|
|
543
|
+
left: Number(style.left) + left,
|
|
544
|
+
top: Number(style.top) + top,
|
|
545
|
+
},
|
|
546
|
+
});
|
|
547
|
+
}
|
|
548
|
+
|
|
493
549
|
public destroy() {
|
|
494
550
|
this.removeAllListeners();
|
|
495
551
|
this.set('root', null);
|
package/src/services/ui.ts
CHANGED
|
@@ -91,6 +91,11 @@ class Ui extends BaseService {
|
|
|
91
91
|
return (state as any)[name];
|
|
92
92
|
}
|
|
93
93
|
|
|
94
|
+
public zoom(zoom: number) {
|
|
95
|
+
this.set('zoom', (this.get<number>('zoom') * 100 + zoom * 100) / 100);
|
|
96
|
+
if (this.get<number>('zoom') < 0.1) this.set('zoom', 0.1);
|
|
97
|
+
}
|
|
98
|
+
|
|
94
99
|
private setColumnWidth({ left, center, right }: SetColumnWidth) {
|
|
95
100
|
const columnWidth = {
|
|
96
101
|
...toRaw(this.get<GetColumnWidth>('columnWidth')),
|
package/src/utils/editor.ts
CHANGED
|
@@ -125,7 +125,7 @@ export const setNewItemId = (config: MNode, parent?: MPage) => {
|
|
|
125
125
|
*/
|
|
126
126
|
export const isFixed = (node: MNode): boolean => node.style?.position === 'fixed';
|
|
127
127
|
|
|
128
|
-
export const getNodeIndex = (node: MNode, parent: MContainer): number => {
|
|
128
|
+
export const getNodeIndex = (node: MNode, parent: MContainer | MApp): number => {
|
|
129
129
|
const items = parent?.items || [];
|
|
130
130
|
return items.findIndex((item: MNode) => `${item.id}` === `${node.id}`);
|
|
131
131
|
};
|
|
@@ -213,7 +213,11 @@ export const change2Fixed = (node: MNode, root: MApp) => {
|
|
|
213
213
|
return node;
|
|
214
214
|
};
|
|
215
215
|
|
|
216
|
-
export const Fixed2Other = async (
|
|
216
|
+
export const Fixed2Other = async (
|
|
217
|
+
node: MNode,
|
|
218
|
+
root: MApp,
|
|
219
|
+
getLayout: (parent: MNode, node?: MNode) => Promise<Layout>,
|
|
220
|
+
) => {
|
|
217
221
|
const path = getNodePath(node.id, root.items);
|
|
218
222
|
const cur = path.pop();
|
|
219
223
|
const offset = {
|
package/tsconfig.json
DELETED
package/vite.config.ts
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
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
|
-
import path from 'path';
|
|
20
|
-
|
|
21
|
-
import { defineConfig } from 'vite';
|
|
22
|
-
|
|
23
|
-
import { getBaseConfig } from '../vite-config';
|
|
24
|
-
|
|
25
|
-
import pkg from './package.json';
|
|
26
|
-
|
|
27
|
-
const deps = Object.keys(pkg.dependencies);
|
|
28
|
-
const alias = [{ find: /@editor/, replacement: path.join(__dirname, './src') }];
|
|
29
|
-
|
|
30
|
-
export default defineConfig(getBaseConfig(deps, 'TMagicEditor', alias));
|