@tmagic/editor 1.1.0-beta.2 → 1.1.0-beta.5
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 +1 -1
- package/dist/tmagic-editor.es.js +78 -65
- package/dist/tmagic-editor.es.js.map +1 -1
- package/dist/tmagic-editor.umd.js +75 -63
- package/dist/tmagic-editor.umd.js.map +1 -1
- package/dist/types/src/services/props.d.ts +20 -2
- package/dist/types/src/type.d.ts +1 -0
- package/dist/types/src/utils/props.d.ts +0 -20
- package/package.json +7 -7
- package/src/components/ScrollViewer.vue +1 -1
- package/src/layouts/sidebar/ComponentListPanel.vue +4 -15
- package/src/layouts/sidebar/LayerPanel.vue +11 -2
- package/src/layouts/workspace/Stage.vue +2 -0
- package/src/services/BaseService.ts +4 -9
- package/src/services/editor.ts +8 -8
- package/src/services/props.ts +46 -7
- package/src/services/ui.ts +8 -2
- package/src/theme/framework.scss +1 -1
- package/src/theme/stage.scss +2 -2
- package/src/type.ts +1 -0
- package/src/utils/editor.ts +2 -1
- package/src/utils/props.ts +0 -22
|
@@ -29,13 +29,31 @@ declare class Props extends BaseService {
|
|
|
29
29
|
* @param type 组件类型
|
|
30
30
|
* @returns 组件初始值
|
|
31
31
|
*/
|
|
32
|
-
getPropsValue(type: string, defaultValue?: Record<string, any>): Promise<any>;
|
|
32
|
+
getPropsValue(type: string, { inputEvent, ...defaultValue }?: Record<string, any>): Promise<any>;
|
|
33
33
|
createId(type: string | number): Promise<string>;
|
|
34
34
|
/**
|
|
35
35
|
* 将组件与组件的子元素配置中的id都设置成一个新的ID
|
|
36
36
|
* @param {Object} config 组件配置
|
|
37
37
|
*/
|
|
38
|
-
setNewItemId(config: MNode, parent?: MPage): Promise<
|
|
38
|
+
setNewItemId(config: MNode, parent?: MPage): Promise<MNode>;
|
|
39
|
+
/**
|
|
40
|
+
* 获取默认属性配置
|
|
41
|
+
* @param type 组件类型
|
|
42
|
+
* @returns Object
|
|
43
|
+
*/
|
|
44
|
+
getDefaultPropsValue(type: string): Promise<{
|
|
45
|
+
type: string;
|
|
46
|
+
layout: string;
|
|
47
|
+
style: {};
|
|
48
|
+
name: string;
|
|
49
|
+
items: never[];
|
|
50
|
+
} | {
|
|
51
|
+
type: string;
|
|
52
|
+
style: {};
|
|
53
|
+
name: string;
|
|
54
|
+
layout?: undefined;
|
|
55
|
+
items?: undefined;
|
|
56
|
+
}>;
|
|
39
57
|
}
|
|
40
58
|
export declare type PropsService = Props;
|
|
41
59
|
declare const _default: Props;
|
package/dist/types/src/type.d.ts
CHANGED
|
@@ -36,23 +36,3 @@ export declare const fillConfig: (config?: FormConfig) => {
|
|
|
36
36
|
})[];
|
|
37
37
|
}[];
|
|
38
38
|
export declare const DEFAULT_CONFIG: FormConfig;
|
|
39
|
-
/**
|
|
40
|
-
* 获取默认属性配置
|
|
41
|
-
* @param type 组件类型
|
|
42
|
-
* @returns Object
|
|
43
|
-
*/
|
|
44
|
-
export declare const getDefaultPropsValue: (type: string, id: string) => {
|
|
45
|
-
type: string;
|
|
46
|
-
id: string;
|
|
47
|
-
layout: string;
|
|
48
|
-
style: {};
|
|
49
|
-
name: string;
|
|
50
|
-
items: never[];
|
|
51
|
-
} | {
|
|
52
|
-
type: string;
|
|
53
|
-
id: string;
|
|
54
|
-
style: {};
|
|
55
|
-
name: string;
|
|
56
|
-
layout?: undefined;
|
|
57
|
-
items?: undefined;
|
|
58
|
-
};
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.1.0-beta.
|
|
2
|
+
"version": "1.1.0-beta.5",
|
|
3
3
|
"name": "@tmagic/editor",
|
|
4
4
|
"sideEffects": [
|
|
5
5
|
"dist/*",
|
|
@@ -43,11 +43,11 @@
|
|
|
43
43
|
"dependencies": {
|
|
44
44
|
"@babel/core": "^7.18.0",
|
|
45
45
|
"@element-plus/icons-vue": "^2.0.6",
|
|
46
|
-
"@tmagic/core": "1.1.0-beta.
|
|
47
|
-
"@tmagic/form": "1.1.0-beta.
|
|
48
|
-
"@tmagic/schema": "1.1.0-beta.
|
|
49
|
-
"@tmagic/stage": "1.1.0-beta.
|
|
50
|
-
"@tmagic/utils": "1.1.0-beta.
|
|
46
|
+
"@tmagic/core": "1.1.0-beta.5",
|
|
47
|
+
"@tmagic/form": "1.1.0-beta.5",
|
|
48
|
+
"@tmagic/schema": "1.1.0-beta.5",
|
|
49
|
+
"@tmagic/stage": "1.1.0-beta.5",
|
|
50
|
+
"@tmagic/utils": "1.1.0-beta.5",
|
|
51
51
|
"buffer": "^6.0.3",
|
|
52
52
|
"color": "^3.1.3",
|
|
53
53
|
"element-plus": "^2.2.6",
|
|
@@ -60,7 +60,7 @@
|
|
|
60
60
|
"vue": "^3.2.0"
|
|
61
61
|
},
|
|
62
62
|
"peerDependencies": {
|
|
63
|
-
"@tmagic/form": "1.1.0-beta.
|
|
63
|
+
"@tmagic/form": "1.1.0-beta.5",
|
|
64
64
|
"element-plus": "^2.2.6",
|
|
65
65
|
"monaco-editor": "^0.32.1",
|
|
66
66
|
"vue": "^3.2.0"
|
|
@@ -41,8 +41,7 @@ import { computed, defineComponent, inject, ref } from 'vue';
|
|
|
41
41
|
import serialize from 'serialize-javascript';
|
|
42
42
|
|
|
43
43
|
import type StageCore from '@tmagic/stage';
|
|
44
|
-
import {
|
|
45
|
-
import { addClassName, removeClassNameByClassName } from '@tmagic/utils';
|
|
44
|
+
import { removeClassNameByClassName } from '@tmagic/utils';
|
|
46
45
|
|
|
47
46
|
import MIcon from '@editor/components/Icon.vue';
|
|
48
47
|
import type { ComponentGroup, ComponentItem, Services, StageOptions } from '@editor/type';
|
|
@@ -125,19 +124,9 @@ export default defineComponent({
|
|
|
125
124
|
return;
|
|
126
125
|
}
|
|
127
126
|
|
|
128
|
-
if (timeout) return;
|
|
129
|
-
|
|
130
|
-
timeout =
|
|
131
|
-
if (!stageOptions || !stage.value) return;
|
|
132
|
-
const doc = stage.value.renderer.contentWindow?.document;
|
|
133
|
-
const els = stage.value.getElementsFromPoint(e);
|
|
134
|
-
for (const el of els) {
|
|
135
|
-
if (doc && !el.id.startsWith(GHOST_EL_ID_PREFIX) && (await stageOptions.isContainer(el))) {
|
|
136
|
-
addClassName(el, doc, stageOptions?.containerHighlightClassName);
|
|
137
|
-
break;
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
}, stageOptions?.containerHighlightDuration);
|
|
127
|
+
if (timeout || !stage.value) return;
|
|
128
|
+
|
|
129
|
+
timeout = stage.value.getAddContainerHighlightClassNameTimeout(e);
|
|
141
130
|
},
|
|
142
131
|
};
|
|
143
132
|
},
|
|
@@ -61,11 +61,12 @@ import type { ElTree } from 'element-plus';
|
|
|
61
61
|
import { throttle } from 'lodash-es';
|
|
62
62
|
|
|
63
63
|
import type { MNode, MPage } from '@tmagic/schema';
|
|
64
|
-
import { NodeType } from '@tmagic/schema';
|
|
64
|
+
import { MContainer, NodeType } from '@tmagic/schema';
|
|
65
65
|
import StageCore from '@tmagic/stage';
|
|
66
66
|
|
|
67
67
|
import type { EditorService } from '@editor/services/editor';
|
|
68
68
|
import type { Services } from '@editor/type';
|
|
69
|
+
import { Layout } from '@editor/type';
|
|
69
70
|
|
|
70
71
|
import LayerMenu from './LayerMenu.vue';
|
|
71
72
|
|
|
@@ -104,8 +105,16 @@ const useDrop = (tree: Ref<InstanceType<typeof ElTree> | undefined>, editorServi
|
|
|
104
105
|
return false;
|
|
105
106
|
},
|
|
106
107
|
|
|
107
|
-
handleDragEnd() {
|
|
108
|
+
async handleDragEnd(e: any) {
|
|
108
109
|
if (!tree.value) return;
|
|
110
|
+
const { data: node } = e;
|
|
111
|
+
const parent = editorService?.getParentById(node.id, false) as MContainer;
|
|
112
|
+
const layout = await editorService?.getLayout(parent);
|
|
113
|
+
node.style.position = layout;
|
|
114
|
+
if (layout === Layout.RELATIVE) {
|
|
115
|
+
node.style.top = 0;
|
|
116
|
+
node.style.left = 0;
|
|
117
|
+
}
|
|
109
118
|
const { data } = tree.value;
|
|
110
119
|
const [page] = data as [MPage];
|
|
111
120
|
editorService?.update(page);
|
|
@@ -36,18 +36,13 @@ const doAction = async (
|
|
|
36
36
|
let beforeArgs = args;
|
|
37
37
|
|
|
38
38
|
for (const beforeMethod of scope.pluginOptionsList[beforeMethodName]) {
|
|
39
|
-
|
|
39
|
+
beforeArgs = (await beforeMethod(...beforeArgs)) || [];
|
|
40
40
|
|
|
41
|
-
if (isError(
|
|
41
|
+
if (isError(beforeArgs)) throw beforeArgs;
|
|
42
42
|
|
|
43
|
-
if (!Array.isArray(
|
|
44
|
-
|
|
43
|
+
if (!Array.isArray(beforeArgs)) {
|
|
44
|
+
beforeArgs = [beforeArgs];
|
|
45
45
|
}
|
|
46
|
-
|
|
47
|
-
beforeArgs = beforeArgs.map((v: any, index: number) => {
|
|
48
|
-
if (typeof beforeReturnValue[index] === 'undefined') return v;
|
|
49
|
-
return beforeReturnValue[index];
|
|
50
|
-
});
|
|
51
46
|
}
|
|
52
47
|
|
|
53
48
|
let returnValue: any = await fn(beforeArgs, sourceMethod.bind(scope));
|
package/src/services/editor.ts
CHANGED
|
@@ -40,7 +40,6 @@ import {
|
|
|
40
40
|
isFixed,
|
|
41
41
|
setLayout,
|
|
42
42
|
} from '@editor/utils/editor';
|
|
43
|
-
import { log } from '@editor/utils/logger';
|
|
44
43
|
|
|
45
44
|
import BaseService from './BaseService';
|
|
46
45
|
|
|
@@ -90,7 +89,6 @@ class Editor extends BaseService {
|
|
|
90
89
|
*/
|
|
91
90
|
public set<T = MNode>(name: keyof StoreState, value: T) {
|
|
92
91
|
this.state[name] = value as any;
|
|
93
|
-
log('store set ', name, ' ', value);
|
|
94
92
|
|
|
95
93
|
if (name === 'root') {
|
|
96
94
|
this.state.pageLength = (value as unknown as MApp)?.items?.length || 0;
|
|
@@ -273,7 +271,8 @@ class Editor extends BaseService {
|
|
|
273
271
|
* @returns 添加后的节点
|
|
274
272
|
*/
|
|
275
273
|
public async add(addNode: AddMNode, parent?: MContainer | null): Promise<MNode> {
|
|
276
|
-
|
|
274
|
+
// 加入inputEvent是为给业务扩展时可以获取到更多的信息,只有在使用拖拽添加组件时才有改对象
|
|
275
|
+
const { type, inputEvent, ...config } = addNode;
|
|
277
276
|
const curNode = this.get<MContainer>('node');
|
|
278
277
|
|
|
279
278
|
let parentNode: MContainer | undefined;
|
|
@@ -305,7 +304,7 @@ class Editor extends BaseService {
|
|
|
305
304
|
const stage = this.get<StageCore | null>('stage');
|
|
306
305
|
const root = this.get<MApp>('root');
|
|
307
306
|
|
|
308
|
-
await stage?.add({ config: cloneDeep(newNode), root: cloneDeep(root) });
|
|
307
|
+
await stage?.add({ config: cloneDeep(newNode), parent: cloneDeep(parentNode), root: cloneDeep(root) });
|
|
309
308
|
|
|
310
309
|
if (layout === Layout.ABSOLUTE) {
|
|
311
310
|
const fixedLeft = fixNodeLeft(newNode, parentNode, stage?.renderer.contentWindow?.document);
|
|
@@ -322,10 +321,11 @@ class Editor extends BaseService {
|
|
|
322
321
|
this.pushHistoryState();
|
|
323
322
|
}
|
|
324
323
|
|
|
325
|
-
stage?.select(newNode.id);
|
|
326
|
-
|
|
327
324
|
if (isPage) {
|
|
328
325
|
this.state.pageLength += 1;
|
|
326
|
+
} else {
|
|
327
|
+
// 新增页面,这个时候页面还有渲染出来,此时select会出错,在runtime-ready的时候回去select
|
|
328
|
+
stage?.select(newNode.id);
|
|
329
329
|
}
|
|
330
330
|
|
|
331
331
|
this.emit('add', newNode);
|
|
@@ -507,7 +507,7 @@ class Editor extends BaseService {
|
|
|
507
507
|
return;
|
|
508
508
|
}
|
|
509
509
|
|
|
510
|
-
await propsService.setNewItemId(config, this.get('root'));
|
|
510
|
+
config = await propsService.setNewItemId(config, this.get('root'));
|
|
511
511
|
if (config.style) {
|
|
512
512
|
config.style = {
|
|
513
513
|
...config.style,
|
|
@@ -541,8 +541,8 @@ class Editor extends BaseService {
|
|
|
541
541
|
const doc = stage?.renderer.contentWindow?.document;
|
|
542
542
|
|
|
543
543
|
if (doc) {
|
|
544
|
-
const parentEl = doc.getElementById(`${parent.id}`);
|
|
545
544
|
const el = doc.getElementById(`${node.id}`);
|
|
545
|
+
const parentEl = el?.offsetParent;
|
|
546
546
|
if (parentEl && el) {
|
|
547
547
|
node.style.left = (parentEl.clientWidth - el.clientWidth) / 2;
|
|
548
548
|
}
|
package/src/services/props.ts
CHANGED
|
@@ -25,7 +25,7 @@ import { NodeType } from '@tmagic/schema';
|
|
|
25
25
|
import { isPop, toLine } from '@tmagic/utils';
|
|
26
26
|
|
|
27
27
|
import type { PropsState } from '@editor/type';
|
|
28
|
-
import { DEFAULT_CONFIG, fillConfig
|
|
28
|
+
import { DEFAULT_CONFIG, fillConfig } from '@editor/utils/props';
|
|
29
29
|
|
|
30
30
|
import BaseService from './BaseService';
|
|
31
31
|
|
|
@@ -36,7 +36,15 @@ class Props extends BaseService {
|
|
|
36
36
|
});
|
|
37
37
|
|
|
38
38
|
constructor() {
|
|
39
|
-
super([
|
|
39
|
+
super([
|
|
40
|
+
'setPropsConfig',
|
|
41
|
+
'getPropsConfig',
|
|
42
|
+
'setPropsValue',
|
|
43
|
+
'getPropsValue',
|
|
44
|
+
'createId',
|
|
45
|
+
'setNewItemId',
|
|
46
|
+
'getDefaultPropsValue',
|
|
47
|
+
]);
|
|
40
48
|
}
|
|
41
49
|
|
|
42
50
|
public setPropsConfigs(configs: Record<string, FormConfig>) {
|
|
@@ -88,7 +96,7 @@ class Props extends BaseService {
|
|
|
88
96
|
* @param type 组件类型
|
|
89
97
|
* @returns 组件初始值
|
|
90
98
|
*/
|
|
91
|
-
public async getPropsValue(type: string, defaultValue: Record<string, any> = {}) {
|
|
99
|
+
public async getPropsValue(type: string, { inputEvent, ...defaultValue }: Record<string, any> = {}) {
|
|
92
100
|
if (type === 'area') {
|
|
93
101
|
const value = (await this.getPropsValue('button')) as MComponent;
|
|
94
102
|
value.className = 'action-area';
|
|
@@ -99,12 +107,20 @@ class Props extends BaseService {
|
|
|
99
107
|
return value;
|
|
100
108
|
}
|
|
101
109
|
|
|
102
|
-
const data =
|
|
103
|
-
|
|
104
|
-
|
|
110
|
+
const [id, defaultPropsValue, data] = await Promise.all([
|
|
111
|
+
this.createId(type),
|
|
112
|
+
this.getDefaultPropsValue(type),
|
|
113
|
+
this.setNewItemId(
|
|
114
|
+
cloneDeep({
|
|
115
|
+
type,
|
|
116
|
+
...defaultValue,
|
|
117
|
+
} as any),
|
|
118
|
+
),
|
|
119
|
+
]);
|
|
105
120
|
|
|
106
121
|
return {
|
|
107
|
-
|
|
122
|
+
id,
|
|
123
|
+
...defaultPropsValue,
|
|
108
124
|
...mergeWith(cloneDeep(this.state.propsValueMap[type] || {}), data),
|
|
109
125
|
};
|
|
110
126
|
}
|
|
@@ -133,6 +149,29 @@ class Props extends BaseService {
|
|
|
133
149
|
await this.setNewItemId(item, config as MPage);
|
|
134
150
|
}
|
|
135
151
|
}
|
|
152
|
+
|
|
153
|
+
return config;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* 获取默认属性配置
|
|
158
|
+
* @param type 组件类型
|
|
159
|
+
* @returns Object
|
|
160
|
+
*/
|
|
161
|
+
public async getDefaultPropsValue(type: string) {
|
|
162
|
+
return ['page', 'container'].includes(type)
|
|
163
|
+
? {
|
|
164
|
+
type,
|
|
165
|
+
layout: 'absolute',
|
|
166
|
+
style: {},
|
|
167
|
+
name: type,
|
|
168
|
+
items: [],
|
|
169
|
+
}
|
|
170
|
+
: {
|
|
171
|
+
type,
|
|
172
|
+
style: {},
|
|
173
|
+
name: type,
|
|
174
|
+
};
|
|
136
175
|
}
|
|
137
176
|
}
|
|
138
177
|
|
package/src/services/ui.ts
CHANGED
|
@@ -155,10 +155,16 @@ class Ui extends BaseService {
|
|
|
155
155
|
const { stageRect, stageContainerRect } = state;
|
|
156
156
|
const { height, width } = stageContainerRect;
|
|
157
157
|
if (!width || !height) return 1;
|
|
158
|
-
|
|
158
|
+
|
|
159
|
+
// 30为标尺的大小
|
|
160
|
+
const stageWidth = stageRect.width + 30;
|
|
161
|
+
const stageHeight = stageRect.height + 30;
|
|
162
|
+
|
|
163
|
+
if (width > stageWidth && height > stageHeight) {
|
|
159
164
|
return 1;
|
|
160
165
|
}
|
|
161
|
-
|
|
166
|
+
// 60/80是为了不要让画布太过去贴住四周(这样好看些)
|
|
167
|
+
return Math.min((width - 60) / stageWidth || 1, (height - 80) / stageHeight || 1);
|
|
162
168
|
}
|
|
163
169
|
}
|
|
164
170
|
|
package/src/theme/framework.scss
CHANGED
package/src/theme/stage.scss
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
.m-editor-stage {
|
|
2
2
|
position: relative;
|
|
3
3
|
width: 100%;
|
|
4
|
-
height: calc(100% - $--page-bar-height);
|
|
4
|
+
height: calc(100% - #{$--page-bar-height});
|
|
5
5
|
overflow: hidden;
|
|
6
6
|
display: flex;
|
|
7
7
|
justify-content: center;
|
|
@@ -13,9 +13,9 @@
|
|
|
13
13
|
height: 100%;
|
|
14
14
|
z-index: 0;
|
|
15
15
|
position: relative;
|
|
16
|
-
border: 1px solid $--border-color;
|
|
17
16
|
transition: transform 0.3s;
|
|
18
17
|
box-sizing: content-box;
|
|
18
|
+
box-shadow: rgba(0, 0, 0, 0.04) 0px 3px 5px;
|
|
19
19
|
|
|
20
20
|
&::-webkit-scrollbar {
|
|
21
21
|
width: 0 !important;
|
package/src/type.ts
CHANGED
package/src/utils/editor.ts
CHANGED
|
@@ -223,7 +223,8 @@ export const fixNodeLeft = (config: MNode, parent: MContainer, doc?: Document) =
|
|
|
223
223
|
const el = doc.getElementById(`${config.id}`);
|
|
224
224
|
const parentEl = doc.getElementById(`${parent.id}`);
|
|
225
225
|
|
|
226
|
-
|
|
226
|
+
const left = Number(config.style?.left) || 0;
|
|
227
|
+
if (el && parentEl && el.offsetWidth + left > parentEl.offsetWidth) {
|
|
227
228
|
return parentEl.offsetWidth - el.offsetWidth;
|
|
228
229
|
}
|
|
229
230
|
|
package/src/utils/props.ts
CHANGED
|
@@ -237,25 +237,3 @@ export const fillConfig = (config: FormConfig = []) => [
|
|
|
237
237
|
|
|
238
238
|
// 默认组件属性表单配置
|
|
239
239
|
export const DEFAULT_CONFIG: FormConfig = fillConfig([]);
|
|
240
|
-
|
|
241
|
-
/**
|
|
242
|
-
* 获取默认属性配置
|
|
243
|
-
* @param type 组件类型
|
|
244
|
-
* @returns Object
|
|
245
|
-
*/
|
|
246
|
-
export const getDefaultPropsValue = (type: string, id: string) =>
|
|
247
|
-
['page', 'container'].includes(type)
|
|
248
|
-
? {
|
|
249
|
-
type,
|
|
250
|
-
id,
|
|
251
|
-
layout: 'absolute',
|
|
252
|
-
style: {},
|
|
253
|
-
name: type,
|
|
254
|
-
items: [],
|
|
255
|
-
}
|
|
256
|
-
: {
|
|
257
|
-
type,
|
|
258
|
-
id,
|
|
259
|
-
style: {},
|
|
260
|
-
name: type,
|
|
261
|
-
};
|