@tmagic/editor 1.1.0-beta.7 → 1.1.0
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 +50 -0
- package/dist/tmagic-editor.mjs +1198 -1027
- package/dist/tmagic-editor.mjs.map +1 -1
- package/dist/tmagic-editor.umd.js +1201 -1026
- package/dist/tmagic-editor.umd.js.map +1 -1
- package/package.json +10 -10
- package/src/Editor.vue +22 -6
- package/src/components/ContentMenu.vue +4 -4
- package/src/components/Icon.vue +7 -21
- 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 -0
- package/src/layouts/NavMenu.vue +156 -23
- package/src/layouts/PropsPanel.vue +49 -51
- package/src/layouts/sidebar/LayerMenu.vue +3 -3
- package/src/layouts/sidebar/LayerPanel.vue +39 -8
- package/src/layouts/workspace/PageBar.vue +1 -1
- package/src/layouts/workspace/Stage.vue +8 -86
- package/src/layouts/workspace/ViewerMenu.vue +10 -13
- package/src/layouts/workspace/Workspace.vue +133 -138
- package/src/services/componentList.ts +5 -0
- package/src/services/editor.ts +201 -112
- 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 +32 -30
- package/src/theme/component-list-panel.scss +5 -0
- package/src/theme/nav-menu.scss +6 -0
- package/src/type.ts +28 -11
- package/src/utils/editor.ts +17 -10
- package/src/utils/index.ts +1 -0
- package/src/utils/operator.ts +22 -123
- 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 +17 -8
- 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 -0
- package/types/layouts/NavMenu.vue.d.ts +92 -23
- package/types/layouts/PropsPanel.vue.d.ts +25 -208
- package/types/layouts/sidebar/LayerMenu.vue.d.ts +7 -7
- package/types/layouts/sidebar/LayerPanel.vue.d.ts +17 -15
- package/types/layouts/workspace/ViewerMenu.vue.d.ts +3 -3
- package/types/layouts/workspace/Workspace.vue.d.ts +54 -4
- package/types/services/componentList.d.ts +1 -0
- package/types/services/editor.d.ts +10 -17
- 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 +3 -1
- package/types/type.d.ts +25 -11
- package/types/utils/editor.d.ts +4 -1
- package/types/utils/index.d.ts +1 -0
- package/types/utils/operator.d.ts +3 -26
- 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/services/ui.ts
CHANGED
|
@@ -64,16 +64,6 @@ class Ui extends BaseService {
|
|
|
64
64
|
center: 'auto',
|
|
65
65
|
});
|
|
66
66
|
});
|
|
67
|
-
|
|
68
|
-
const columnWidthCacheData = globalThis.localStorage.getItem(COLUMN_WIDTH_STORAGE_KEY);
|
|
69
|
-
if (columnWidthCacheData) {
|
|
70
|
-
try {
|
|
71
|
-
const columnWidthCache = JSON.parse(columnWidthCacheData);
|
|
72
|
-
this.setColumnWidth(columnWidthCache);
|
|
73
|
-
} catch (e) {
|
|
74
|
-
console.error(e);
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
67
|
}
|
|
78
68
|
|
|
79
69
|
public set<T = any>(name: keyof UiState, value: T) {
|
|
@@ -98,21 +88,49 @@ class Ui extends BaseService {
|
|
|
98
88
|
}
|
|
99
89
|
|
|
100
90
|
(state as any)[name] = value;
|
|
101
|
-
|
|
102
|
-
if (name === 'stageContainerRect') {
|
|
103
|
-
state.zoom = this.calcZoom();
|
|
104
|
-
}
|
|
105
91
|
}
|
|
106
92
|
|
|
107
93
|
public get<T>(name: keyof typeof state): T {
|
|
108
94
|
return (state as any)[name];
|
|
109
95
|
}
|
|
110
96
|
|
|
97
|
+
public initColumnWidth() {
|
|
98
|
+
const columnWidthCacheData = globalThis.localStorage.getItem(COLUMN_WIDTH_STORAGE_KEY);
|
|
99
|
+
if (columnWidthCacheData) {
|
|
100
|
+
try {
|
|
101
|
+
const columnWidthCache = JSON.parse(columnWidthCacheData);
|
|
102
|
+
this.setColumnWidth(columnWidthCache);
|
|
103
|
+
} catch (e) {
|
|
104
|
+
console.error(e);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
111
109
|
public zoom(zoom: number) {
|
|
112
110
|
this.set('zoom', (this.get<number>('zoom') * 100 + zoom * 100) / 100);
|
|
113
111
|
if (this.get<number>('zoom') < 0.1) this.set('zoom', 0.1);
|
|
114
112
|
}
|
|
115
113
|
|
|
114
|
+
public calcZoom() {
|
|
115
|
+
const { stageRect, stageContainerRect } = state;
|
|
116
|
+
const { height, width } = stageContainerRect;
|
|
117
|
+
if (!width || !height) return 1;
|
|
118
|
+
|
|
119
|
+
// 30为标尺的大小
|
|
120
|
+
const stageWidth = stageRect.width + 30;
|
|
121
|
+
const stageHeight = stageRect.height + 30;
|
|
122
|
+
|
|
123
|
+
if (width > stageWidth && height > stageHeight) {
|
|
124
|
+
return 1;
|
|
125
|
+
}
|
|
126
|
+
// 60/80是为了不要让画布太过去贴住四周(这样好看些)
|
|
127
|
+
return Math.min((width - 60) / stageWidth || 1, (height - 80) / stageHeight || 1);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
public destroy() {
|
|
131
|
+
this.removeAllListeners();
|
|
132
|
+
}
|
|
133
|
+
|
|
116
134
|
private setColumnWidth({ left, center, right }: SetColumnWidth) {
|
|
117
135
|
const columnWidth = {
|
|
118
136
|
...toRaw(this.get<GetColumnWidth>('columnWidth')),
|
|
@@ -150,22 +168,6 @@ class Ui extends BaseService {
|
|
|
150
168
|
};
|
|
151
169
|
state.zoom = this.calcZoom();
|
|
152
170
|
}
|
|
153
|
-
|
|
154
|
-
private calcZoom() {
|
|
155
|
-
const { stageRect, stageContainerRect } = state;
|
|
156
|
-
const { height, width } = stageContainerRect;
|
|
157
|
-
if (!width || !height) return 1;
|
|
158
|
-
|
|
159
|
-
// 30为标尺的大小
|
|
160
|
-
const stageWidth = stageRect.width + 30;
|
|
161
|
-
const stageHeight = stageRect.height + 30;
|
|
162
|
-
|
|
163
|
-
if (width > stageWidth && height > stageHeight) {
|
|
164
|
-
return 1;
|
|
165
|
-
}
|
|
166
|
-
// 60/80是为了不要让画布太过去贴住四周(这样好看些)
|
|
167
|
-
return Math.min((width - 60) / stageWidth || 1, (height - 80) / stageHeight || 1);
|
|
168
|
-
}
|
|
169
171
|
}
|
|
170
172
|
|
|
171
173
|
export type UiService = Ui;
|
package/src/theme/nav-menu.scss
CHANGED
package/src/type.ts
CHANGED
|
@@ -21,7 +21,7 @@ import type { Component } from 'vue';
|
|
|
21
21
|
import type { FormConfig } from '@tmagic/form';
|
|
22
22
|
import type { Id, MApp, MContainer, MNode, MPage } from '@tmagic/schema';
|
|
23
23
|
import type StageCore from '@tmagic/stage';
|
|
24
|
-
import type { MoveableOptions } from '@tmagic/stage';
|
|
24
|
+
import type { ContainerHighlightType, MoveableOptions } from '@tmagic/stage';
|
|
25
25
|
|
|
26
26
|
import type { ComponentListService } from './services/componentList';
|
|
27
27
|
import type { EditorService } from './services/editor';
|
|
@@ -53,6 +53,7 @@ export interface StageOptions {
|
|
|
53
53
|
autoScrollIntoView: boolean;
|
|
54
54
|
containerHighlightClassName: string;
|
|
55
55
|
containerHighlightDuration: number;
|
|
56
|
+
containerHighlightType: ContainerHighlightType;
|
|
56
57
|
render: () => HTMLDivElement;
|
|
57
58
|
moveableOptions: MoveableOptions | ((core?: StageCore) => MoveableOptions);
|
|
58
59
|
canSelect: (el: HTMLElement) => boolean | Promise<boolean>;
|
|
@@ -81,16 +82,22 @@ export interface ComponentGroupState {
|
|
|
81
82
|
list: ComponentGroup[];
|
|
82
83
|
}
|
|
83
84
|
|
|
85
|
+
export enum ColumnLayout {
|
|
86
|
+
LEFT = 'left',
|
|
87
|
+
CENTER = 'center',
|
|
88
|
+
RIGHT = 'right',
|
|
89
|
+
}
|
|
90
|
+
|
|
84
91
|
export interface SetColumnWidth {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
92
|
+
[ColumnLayout.LEFT]?: number;
|
|
93
|
+
[ColumnLayout.CENTER]?: number | 'auto';
|
|
94
|
+
[ColumnLayout.RIGHT]?: number;
|
|
88
95
|
}
|
|
89
96
|
|
|
90
97
|
export interface GetColumnWidth {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
98
|
+
[ColumnLayout.LEFT]: number;
|
|
99
|
+
[ColumnLayout.CENTER]: number;
|
|
100
|
+
[ColumnLayout.RIGHT]: number;
|
|
94
101
|
}
|
|
95
102
|
|
|
96
103
|
export interface StageRect {
|
|
@@ -173,6 +180,7 @@ export interface MenuButton {
|
|
|
173
180
|
/** type为button/dropdown时点击运行的方法 */
|
|
174
181
|
handler?: (data: Services, event: MouseEvent) => Promise<any> | any;
|
|
175
182
|
/** type为dropdown时,下拉的菜单列表, 或者有子菜单时 */
|
|
183
|
+
className?: string;
|
|
176
184
|
items?: MenuButton[];
|
|
177
185
|
}
|
|
178
186
|
|
|
@@ -186,6 +194,7 @@ export interface MenuComponent {
|
|
|
186
194
|
listeners?: Record<string, Function>;
|
|
187
195
|
slots?: Record<string, any>;
|
|
188
196
|
/** 是否显示,默认为true */
|
|
197
|
+
className?: string;
|
|
189
198
|
display?: boolean | ((data?: Services) => Promise<boolean> | boolean);
|
|
190
199
|
}
|
|
191
200
|
|
|
@@ -208,16 +217,17 @@ export type MenuItem =
|
|
|
208
217
|
| 'guides'
|
|
209
218
|
| 'rule'
|
|
210
219
|
| MenuButton
|
|
211
|
-
| MenuComponent
|
|
220
|
+
| MenuComponent
|
|
221
|
+
| string;
|
|
212
222
|
|
|
213
223
|
/** 工具栏 */
|
|
214
224
|
export interface MenuBarData {
|
|
215
225
|
/** 顶部工具栏左边项 */
|
|
216
|
-
|
|
226
|
+
[ColumnLayout.LEFT]?: MenuItem[];
|
|
217
227
|
/** 顶部工具栏中间项 */
|
|
218
|
-
|
|
228
|
+
[ColumnLayout.CENTER]?: MenuItem[];
|
|
219
229
|
/** 顶部工具栏右边项 */
|
|
220
|
-
|
|
230
|
+
[ColumnLayout.RIGHT]?: MenuItem[];
|
|
221
231
|
}
|
|
222
232
|
|
|
223
233
|
export interface SideComponent extends MenuComponent {
|
|
@@ -286,3 +296,10 @@ export enum Keys {
|
|
|
286
296
|
|
|
287
297
|
export const H_GUIDE_LINE_STORAGE_KEY = '$MagicStageHorizontalGuidelinesData';
|
|
288
298
|
export const V_GUIDE_LINE_STORAGE_KEY = '$MagicStageVerticalGuidelinesData';
|
|
299
|
+
|
|
300
|
+
export interface ScrollViewerEvent {
|
|
301
|
+
scrollLeft: number;
|
|
302
|
+
scrollTop: number;
|
|
303
|
+
scrollHeight: number;
|
|
304
|
+
scrollWidth: number;
|
|
305
|
+
}
|
package/src/utils/editor.ts
CHANGED
|
@@ -88,10 +88,10 @@ export const getRelativeStyle = (style: Record<string, any> = {}): Record<string
|
|
|
88
88
|
left: 0,
|
|
89
89
|
});
|
|
90
90
|
|
|
91
|
-
const getMiddleTop = (
|
|
92
|
-
let height = style
|
|
91
|
+
const getMiddleTop = (node: MNode, parentNode: MNode, stage: StageCore | null) => {
|
|
92
|
+
let height = node.style?.height || 0;
|
|
93
93
|
|
|
94
|
-
if (!stage || typeof style
|
|
94
|
+
if (!stage || typeof node.style?.top !== 'undefined' || !parentNode.style) return node.style?.top;
|
|
95
95
|
|
|
96
96
|
if (!isNumber(height)) {
|
|
97
97
|
height = 0;
|
|
@@ -103,20 +103,15 @@ const getMiddleTop = (style: Record<string, any> = {}, parentNode: MNode, stage:
|
|
|
103
103
|
const { scrollTop = 0, wrapperHeight } = stage.mask;
|
|
104
104
|
return (wrapperHeight - height) / 2 + scrollTop;
|
|
105
105
|
}
|
|
106
|
+
|
|
106
107
|
return (parentHeight - height) / 2;
|
|
107
108
|
};
|
|
108
109
|
|
|
109
|
-
export const getInitPositionStyle = (
|
|
110
|
-
style: Record<string, any> = {},
|
|
111
|
-
layout: Layout,
|
|
112
|
-
parentNode: MNode,
|
|
113
|
-
stage: StageCore,
|
|
114
|
-
) => {
|
|
110
|
+
export const getInitPositionStyle = (style: Record<string, any> = {}, layout: Layout) => {
|
|
115
111
|
if (layout === Layout.ABSOLUTE) {
|
|
116
112
|
return {
|
|
117
113
|
...style,
|
|
118
114
|
position: 'absolute',
|
|
119
|
-
top: getMiddleTop(style, parentNode, stage),
|
|
120
115
|
};
|
|
121
116
|
}
|
|
122
117
|
|
|
@@ -230,3 +225,15 @@ export const fixNodeLeft = (config: MNode, parent: MContainer, doc?: Document) =
|
|
|
230
225
|
|
|
231
226
|
return config.style.left;
|
|
232
227
|
};
|
|
228
|
+
|
|
229
|
+
export const fixNodePosition = (config: MNode, parent: MContainer, stage: StageCore | null) => {
|
|
230
|
+
if (config.style?.position !== 'absolute') {
|
|
231
|
+
return config.style;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
return {
|
|
235
|
+
...(config.style || {}),
|
|
236
|
+
top: getMiddleTop(config, parent, stage),
|
|
237
|
+
left: fixNodeLeft(config, parent, stage?.renderer.contentWindow?.document),
|
|
238
|
+
};
|
|
239
|
+
};
|
package/src/utils/index.ts
CHANGED
package/src/utils/operator.ts
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
import { toRaw } from 'vue';
|
|
2
|
-
import {
|
|
2
|
+
import { isEmpty } from 'lodash-es';
|
|
3
3
|
|
|
4
|
-
import { Id, MApp, MContainer, MNode
|
|
4
|
+
import { Id, MApp, MContainer, MNode } from '@tmagic/schema';
|
|
5
5
|
import StageCore from '@tmagic/stage';
|
|
6
6
|
import { isPage } from '@tmagic/utils';
|
|
7
7
|
|
|
8
8
|
import editorService from '../services/editor';
|
|
9
|
-
import historyService from '../services/history';
|
|
10
9
|
import propsService from '../services/props';
|
|
11
|
-
import { AddMNode,
|
|
12
|
-
import {
|
|
10
|
+
import { AddMNode, PastePosition } from '../type';
|
|
11
|
+
import { generatePageNameByApp, getInitPositionStyle } from '../utils/editor';
|
|
13
12
|
|
|
14
13
|
/**
|
|
15
14
|
* 粘贴前置操作:返回分配了新id以及校准了坐标的配置
|
|
@@ -17,7 +16,7 @@ import { fixNodeLeft, generatePageNameByApp, getInitPositionStyle, getNodeIndex
|
|
|
17
16
|
* @param config 待粘贴的元素配置(复制时保存的那份配置)
|
|
18
17
|
* @returns
|
|
19
18
|
*/
|
|
20
|
-
export const beforePaste = async (position: PastePosition, config: MNode[]) => {
|
|
19
|
+
export const beforePaste = async (position: PastePosition, config: MNode[]): Promise<MNode[]> => {
|
|
21
20
|
if (!config[0]?.style) return config;
|
|
22
21
|
const curNode = editorService.get<MContainer>('node');
|
|
23
22
|
// 将数组中第一个元素的坐标作为参照点
|
|
@@ -43,7 +42,7 @@ export const beforePaste = async (position: PastePosition, config: MNode[]) => {
|
|
|
43
42
|
pastePosition.top = configItem.style?.top - referenceTop + pastePosition.top;
|
|
44
43
|
}
|
|
45
44
|
|
|
46
|
-
const pasteConfig = await propsService.setNewItemId(configItem
|
|
45
|
+
const pasteConfig = await propsService.setNewItemId(configItem);
|
|
47
46
|
|
|
48
47
|
if (pasteConfig.style) {
|
|
49
48
|
const { left, top } = pasteConfig.style;
|
|
@@ -69,54 +68,6 @@ export const beforePaste = async (position: PastePosition, config: MNode[]) => {
|
|
|
69
68
|
return pasteConfigs;
|
|
70
69
|
};
|
|
71
70
|
|
|
72
|
-
/**
|
|
73
|
-
* 新增元素前置操作,实现了在编辑器中新增元素节点,并返回新增元素信息以供stage更新
|
|
74
|
-
* @param addNode 待添加元素的配置
|
|
75
|
-
* @param parent 父级容器(可选)
|
|
76
|
-
* @returns 新增的元素,父级元素,布局方式,是否为根页面
|
|
77
|
-
*/
|
|
78
|
-
export const beforeAdd = async (
|
|
79
|
-
addNode: AddMNode,
|
|
80
|
-
parent?: MContainer | null,
|
|
81
|
-
): Promise<{ parentNode: MContainer; newNode: MNode; layout: Layout; isPage: boolean }> => {
|
|
82
|
-
// 加入inputEvent是为给业务扩展时可以获取到更多的信息,只有在使用拖拽添加组件时才有改对象
|
|
83
|
-
const { type, inputEvent, ...config } = addNode;
|
|
84
|
-
const curNode = editorService.get<MContainer>('node');
|
|
85
|
-
|
|
86
|
-
let parentNode: MContainer | undefined;
|
|
87
|
-
const isPage = type === NodeType.PAGE;
|
|
88
|
-
|
|
89
|
-
if (isPage) {
|
|
90
|
-
parentNode = editorService.get<MApp>('root');
|
|
91
|
-
// 由于支持中间件扩展,在parent参数为undefined时,parent会变成next函数
|
|
92
|
-
} else if (parent && typeof parent !== 'function') {
|
|
93
|
-
parentNode = parent;
|
|
94
|
-
} else if (curNode.items) {
|
|
95
|
-
parentNode = curNode;
|
|
96
|
-
} else {
|
|
97
|
-
parentNode = editorService.getParentById(curNode.id, false);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
if (!parentNode) throw new Error('未找到父元素');
|
|
101
|
-
|
|
102
|
-
const layout = await editorService.getLayout(toRaw(parentNode), addNode as MNode);
|
|
103
|
-
const newNode = { ...toRaw(await propsService.getPropsValue(type, config)) };
|
|
104
|
-
newNode.style = getInitPositionStyle(newNode.style, layout, parentNode, editorService.get<StageCore>('stage'));
|
|
105
|
-
|
|
106
|
-
if ((parentNode?.type === NodeType.ROOT || curNode.type === NodeType.ROOT) && newNode.type !== NodeType.PAGE) {
|
|
107
|
-
throw new Error('app下不能添加组件');
|
|
108
|
-
}
|
|
109
|
-
// 新增节点添加到配置中
|
|
110
|
-
parentNode?.items?.push(newNode);
|
|
111
|
-
// 返回新增信息以供stage更新
|
|
112
|
-
return {
|
|
113
|
-
parentNode,
|
|
114
|
-
newNode,
|
|
115
|
-
layout,
|
|
116
|
-
isPage,
|
|
117
|
-
};
|
|
118
|
-
};
|
|
119
|
-
|
|
120
71
|
/**
|
|
121
72
|
* 将元素粘贴到容器内时,将相对于画布坐标转换为相对于容器的坐标
|
|
122
73
|
* @param position PastePosition 粘贴时相对于画布的坐标
|
|
@@ -135,76 +86,24 @@ export const getPositionInContainer = (position: PastePosition = {}, id: Id) =>
|
|
|
135
86
|
};
|
|
136
87
|
};
|
|
137
88
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
* @param parentNode 父元素
|
|
141
|
-
* @param newNode 当前新增元素
|
|
142
|
-
* @param layout 布局方式
|
|
143
|
-
*/
|
|
144
|
-
export const notifyAddToStage = async (parentNode: MContainer, newNode: MNode, layout: Layout) => {
|
|
145
|
-
const stage = editorService.get<StageCore | null>('stage');
|
|
146
|
-
const root = editorService.get<MApp>('root');
|
|
147
|
-
|
|
148
|
-
await stage?.add({ config: cloneDeep(newNode), parent: cloneDeep(parentNode), root: cloneDeep(root) });
|
|
89
|
+
export const getAddParent = (node: MNode) => {
|
|
90
|
+
const curNode = editorService.get<MContainer>('node');
|
|
149
91
|
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
92
|
+
let parentNode;
|
|
93
|
+
if (isPage(node)) {
|
|
94
|
+
parentNode = editorService.get<MApp>('root');
|
|
95
|
+
} else if (curNode.items) {
|
|
96
|
+
parentNode = curNode;
|
|
97
|
+
} else {
|
|
98
|
+
parentNode = editorService.getParentById(curNode.id, false);
|
|
156
99
|
}
|
|
100
|
+
return parentNode;
|
|
157
101
|
};
|
|
158
102
|
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
if (!node?.id) return;
|
|
166
|
-
|
|
167
|
-
const stage = editorService.get<StageCore | null>('stage');
|
|
168
|
-
const root = editorService.get<MApp | null>('root');
|
|
169
|
-
|
|
170
|
-
if (!root) throw new Error('没有root');
|
|
171
|
-
|
|
172
|
-
const { parent, node: curNode } = editorService.getNodeInfo(node.id, false);
|
|
173
|
-
|
|
174
|
-
if (!parent || !curNode) throw new Error('找不要删除的节点');
|
|
175
|
-
|
|
176
|
-
const index = getNodeIndex(curNode, parent);
|
|
177
|
-
|
|
178
|
-
if (typeof index !== 'number' || index === -1) throw new Error('找不要删除的节点');
|
|
179
|
-
// 从配置中删除元素
|
|
180
|
-
parent.items?.splice(index, 1);
|
|
181
|
-
|
|
182
|
-
// 通知stage更新
|
|
183
|
-
stage?.remove({ id: node.id, root: cloneDeep(root) });
|
|
184
|
-
|
|
185
|
-
if (node.type === NodeType.PAGE) {
|
|
186
|
-
editorService.state.pageLength -= 1;
|
|
187
|
-
|
|
188
|
-
if (root.items[0]) {
|
|
189
|
-
await editorService.select(root.items[0]);
|
|
190
|
-
stage?.select(root.items[0].id);
|
|
191
|
-
} else {
|
|
192
|
-
editorService.set('node', null);
|
|
193
|
-
editorService.set('nodes', []);
|
|
194
|
-
editorService.set('parent', null);
|
|
195
|
-
editorService.set('page', null);
|
|
196
|
-
editorService.set('stage', null);
|
|
197
|
-
editorService.set('highlightNode', null);
|
|
198
|
-
editorService.resetModifiedNodeId();
|
|
199
|
-
historyService.reset();
|
|
200
|
-
|
|
201
|
-
editorService.emit('remove', node);
|
|
202
|
-
|
|
203
|
-
return;
|
|
204
|
-
}
|
|
205
|
-
} else {
|
|
206
|
-
await editorService.select(parent);
|
|
207
|
-
stage?.select(parent.id);
|
|
208
|
-
}
|
|
209
|
-
return parent;
|
|
103
|
+
export const getDefaultConfig = async (addNode: AddMNode, parentNode: MContainer) => {
|
|
104
|
+
const { type, inputEvent, ...config } = addNode;
|
|
105
|
+
const layout = await editorService.getLayout(toRaw(parentNode), addNode as MNode);
|
|
106
|
+
const newNode = { ...toRaw(await propsService.getPropsValue(type, config)) };
|
|
107
|
+
newNode.style = getInitPositionStyle(newNode.style, layout);
|
|
108
|
+
return newNode;
|
|
210
109
|
};
|