@tmagic/editor 1.1.0-beta.11 → 1.1.0-beta.12
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/tmagic-editor.mjs +41 -43
- package/dist/tmagic-editor.mjs.map +1 -1
- package/dist/tmagic-editor.umd.js +40 -43
- package/dist/tmagic-editor.umd.js.map +1 -1
- package/package.json +9 -9
- package/src/Editor.vue +1 -0
- package/src/layouts/workspace/PageBar.vue +1 -1
- package/src/layouts/workspace/Workspace.vue +3 -1
- package/src/services/editor.ts +17 -6
- package/src/services/props.ts +26 -53
- package/src/utils/operator.ts +1 -1
- package/src/utils/props.ts +0 -3
- package/types/services/editor.d.ts +1 -0
- package/types/services/props.d.ts +40 -9
- package/types/utils/props.d.ts +0 -1
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.1.0-beta.
|
|
2
|
+
"version": "1.1.0-beta.12",
|
|
3
3
|
"name": "@tmagic/editor",
|
|
4
4
|
"sideEffects": [
|
|
5
5
|
"dist/*",
|
|
@@ -45,11 +45,11 @@
|
|
|
45
45
|
"dependencies": {
|
|
46
46
|
"@babel/core": "^7.18.0",
|
|
47
47
|
"@element-plus/icons-vue": "^2.0.6",
|
|
48
|
-
"@tmagic/core": "1.1.0-beta.
|
|
49
|
-
"@tmagic/form": "1.1.0-beta.
|
|
50
|
-
"@tmagic/schema": "1.1.0-beta.
|
|
51
|
-
"@tmagic/stage": "1.1.0-beta.
|
|
52
|
-
"@tmagic/utils": "1.1.0-beta.
|
|
48
|
+
"@tmagic/core": "1.1.0-beta.12",
|
|
49
|
+
"@tmagic/form": "1.1.0-beta.12",
|
|
50
|
+
"@tmagic/schema": "1.1.0-beta.12",
|
|
51
|
+
"@tmagic/stage": "1.1.0-beta.12",
|
|
52
|
+
"@tmagic/utils": "1.1.0-beta.12",
|
|
53
53
|
"buffer": "^6.0.3",
|
|
54
54
|
"color": "^3.1.3",
|
|
55
55
|
"element-plus": "^2.2.6",
|
|
@@ -57,14 +57,14 @@
|
|
|
57
57
|
"gesto": "^1.7.0",
|
|
58
58
|
"keycon": "^1.1.2",
|
|
59
59
|
"lodash-es": "^4.17.21",
|
|
60
|
-
"monaco-editor": "^0.
|
|
60
|
+
"monaco-editor": "^0.34.0",
|
|
61
61
|
"serialize-javascript": "^6.0.0",
|
|
62
62
|
"vue": "^3.2.37"
|
|
63
63
|
},
|
|
64
64
|
"peerDependencies": {
|
|
65
|
-
"@tmagic/form": "1.1.0-beta.
|
|
65
|
+
"@tmagic/form": "1.1.0-beta.12",
|
|
66
66
|
"element-plus": "^2.2.6",
|
|
67
|
-
"monaco-editor": "^0.
|
|
67
|
+
"monaco-editor": "^0.34.0",
|
|
68
68
|
"vue": "^3.2.37"
|
|
69
69
|
},
|
|
70
70
|
"devDependencies": {
|
package/src/Editor.vue
CHANGED
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
<template #workspace>
|
|
22
22
|
<slot name="workspace" :editorService="editorService">
|
|
23
23
|
<workspace>
|
|
24
|
+
<template #stage><slot name="stage"></slot></template>
|
|
24
25
|
<template #workspace-content><slot name="workspace-content" :editorService="editorService"></slot></template>
|
|
25
26
|
<template #page-bar-title="{ page }"><slot name="page-bar-title" :page="page"></slot></template>
|
|
26
27
|
<template #page-bar-popover="{ page }"><slot name="page-bar-popover" :page="page"></slot></template>
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
<div class="m-editor-page-bar-title">
|
|
11
11
|
<slot name="page-bar-title" :page="item">
|
|
12
12
|
<el-tooltip effect="dark" placement="top-start" :content="item.name">
|
|
13
|
-
<span>{{ item.name }}</span>
|
|
13
|
+
<span>{{ item.name || item.id }}</span>
|
|
14
14
|
</el-tooltip>
|
|
15
15
|
</slot>
|
|
16
16
|
</div>
|
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',
|
|
@@ -367,7 +368,7 @@ class Editor extends BaseService {
|
|
|
367
368
|
|
|
368
369
|
this.emit('add', newNodes);
|
|
369
370
|
|
|
370
|
-
return
|
|
371
|
+
return Array.isArray(addNode) ? newNodes : newNodes[0];
|
|
371
372
|
}
|
|
372
373
|
|
|
373
374
|
public async doRemove(node: MNode): Promise<void> {
|
|
@@ -503,7 +504,7 @@ class Editor extends BaseService {
|
|
|
503
504
|
|
|
504
505
|
this.emit('update', newNodes);
|
|
505
506
|
|
|
506
|
-
return
|
|
507
|
+
return Array.isArray(config) ? newNodes : newNodes[0];
|
|
507
508
|
}
|
|
508
509
|
|
|
509
510
|
/**
|
|
@@ -556,11 +557,16 @@ class Editor extends BaseService {
|
|
|
556
557
|
|
|
557
558
|
if (!Array.isArray(config)) return;
|
|
558
559
|
|
|
559
|
-
const pasteConfigs = await
|
|
560
|
+
const pasteConfigs = await this.doPaste(config, position);
|
|
560
561
|
|
|
561
562
|
return this.add(pasteConfigs);
|
|
562
563
|
}
|
|
563
564
|
|
|
565
|
+
public async doPaste(config: MNode[], position: PastePosition = {}): Promise<MNode[]> {
|
|
566
|
+
const pasteConfigs = await beforePaste(position, cloneDeep(config));
|
|
567
|
+
return pasteConfigs;
|
|
568
|
+
}
|
|
569
|
+
|
|
564
570
|
public async doAlignCenter(config: MNode): Promise<MNode> {
|
|
565
571
|
const parent = this.getParentById(config.id);
|
|
566
572
|
|
|
@@ -614,7 +620,7 @@ class Editor extends BaseService {
|
|
|
614
620
|
*/
|
|
615
621
|
public async moveLayer(offset: number | LayerOffset): Promise<void> {
|
|
616
622
|
const parent = this.get<MContainer>('parent');
|
|
617
|
-
const node = this.get('node');
|
|
623
|
+
const node = this.get<MNode>('node');
|
|
618
624
|
const brothers: MNode[] = parent?.items || [];
|
|
619
625
|
const index = brothers.findIndex((item) => `${item.id}` === `${node?.id}`);
|
|
620
626
|
|
|
@@ -626,11 +632,15 @@ class Editor extends BaseService {
|
|
|
626
632
|
brothers.splice(index + parseInt(`${offset}`, 10), 0, brothers.splice(index, 1)[0]);
|
|
627
633
|
}
|
|
628
634
|
|
|
635
|
+
const grandparent = this.getParentById(parent.id);
|
|
629
636
|
this.get<StageCore | null>('stage')?.update({
|
|
630
637
|
config: cloneDeep(toRaw(parent)),
|
|
631
|
-
parentId:
|
|
638
|
+
parentId: grandparent?.id,
|
|
632
639
|
root: cloneDeep(this.get<MApp>('root')),
|
|
633
640
|
});
|
|
641
|
+
|
|
642
|
+
this.addModifiedNodeId(parent.id);
|
|
643
|
+
this.pushHistoryState();
|
|
634
644
|
}
|
|
635
645
|
|
|
636
646
|
/**
|
|
@@ -664,7 +674,8 @@ class Editor extends BaseService {
|
|
|
664
674
|
|
|
665
675
|
await stage.select(targetId);
|
|
666
676
|
|
|
667
|
-
|
|
677
|
+
const targetParent = this.getParentById(target.id);
|
|
678
|
+
await stage.update({ config: cloneDeep(target), parentId: targetParent?.id, root });
|
|
668
679
|
|
|
669
680
|
await this.select(newConfig);
|
|
670
681
|
stage.select(newConfig.id);
|
package/src/services/props.ts
CHANGED
|
@@ -20,12 +20,11 @@ import { reactive } from 'vue';
|
|
|
20
20
|
import { cloneDeep, mergeWith } from 'lodash-es';
|
|
21
21
|
|
|
22
22
|
import type { FormConfig } from '@tmagic/form';
|
|
23
|
-
import type {
|
|
24
|
-
import {
|
|
25
|
-
import { isPop, toLine } from '@tmagic/utils';
|
|
23
|
+
import type { MComponent, MNode } from '@tmagic/schema';
|
|
24
|
+
import { toLine } from '@tmagic/utils';
|
|
26
25
|
|
|
27
26
|
import type { PropsState } from '../type';
|
|
28
|
-
import {
|
|
27
|
+
import { fillConfig } from '../utils/props';
|
|
29
28
|
|
|
30
29
|
import BaseService from './BaseService';
|
|
31
30
|
|
|
@@ -43,6 +42,7 @@ class Props extends BaseService {
|
|
|
43
42
|
'getPropsValue',
|
|
44
43
|
'createId',
|
|
45
44
|
'setNewItemId',
|
|
45
|
+
'fillConfig',
|
|
46
46
|
'getDefaultPropsValue',
|
|
47
47
|
]);
|
|
48
48
|
}
|
|
@@ -54,13 +54,17 @@ class Props extends BaseService {
|
|
|
54
54
|
this.emit('props-configs-change');
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
+
public async fillConfig(config: FormConfig) {
|
|
58
|
+
return fillConfig(config);
|
|
59
|
+
}
|
|
60
|
+
|
|
57
61
|
/**
|
|
58
62
|
* 为指定类型组件设置组件属性表单配置
|
|
59
63
|
* @param type 组件类型
|
|
60
64
|
* @param config 组件属性表单配置
|
|
61
65
|
*/
|
|
62
|
-
public setPropsConfig(type: string, config: FormConfig) {
|
|
63
|
-
this.state.propsConfigMap[type] = fillConfig(Array.isArray(config) ? config : [config]);
|
|
66
|
+
public async setPropsConfig(type: string, config: FormConfig) {
|
|
67
|
+
this.state.propsConfigMap[type] = await this.fillConfig(Array.isArray(config) ? config : [config]);
|
|
64
68
|
}
|
|
65
69
|
|
|
66
70
|
/**
|
|
@@ -73,7 +77,7 @@ class Props extends BaseService {
|
|
|
73
77
|
return await this.getPropsConfig('button');
|
|
74
78
|
}
|
|
75
79
|
|
|
76
|
-
return cloneDeep(this.state.propsConfigMap[type] ||
|
|
80
|
+
return cloneDeep(this.state.propsConfigMap[type] || (await this.fillConfig([])));
|
|
77
81
|
}
|
|
78
82
|
|
|
79
83
|
public setPropsValues(values: Record<string, MNode>) {
|
|
@@ -125,19 +129,6 @@ class Props extends BaseService {
|
|
|
125
129
|
};
|
|
126
130
|
}
|
|
127
131
|
|
|
128
|
-
/**
|
|
129
|
-
* 生成指定位数的GUID,无【-】格式
|
|
130
|
-
* @param digit 位数,默认值8
|
|
131
|
-
* @returns
|
|
132
|
-
*/
|
|
133
|
-
guid(digit = 8): string {
|
|
134
|
-
return 'x'.repeat(digit).replace(/[xy]/g, (c) => {
|
|
135
|
-
const r = (Math.random() * 16) | 0;
|
|
136
|
-
const v = c == 'x' ? r : (r & 0x3) | 0x8;
|
|
137
|
-
return v.toString(16);
|
|
138
|
-
});
|
|
139
|
-
}
|
|
140
|
-
|
|
141
132
|
public async createId(type: string | number): Promise<string> {
|
|
142
133
|
return `${type}_${this.guid()}`;
|
|
143
134
|
}
|
|
@@ -147,19 +138,12 @@ class Props extends BaseService {
|
|
|
147
138
|
* @param {Object} config 组件配置
|
|
148
139
|
*/
|
|
149
140
|
/* eslint no-param-reassign: ["error", { "props": false }] */
|
|
150
|
-
public async setNewItemId(config: MNode
|
|
151
|
-
const oldId = config.id;
|
|
152
|
-
|
|
141
|
+
public async setNewItemId(config: MNode) {
|
|
153
142
|
config.id = await this.createId(config.type || 'component');
|
|
154
143
|
|
|
155
|
-
// 只有弹窗在页面下的一级子元素才有效
|
|
156
|
-
if (isPop(config) && parent?.type === NodeType.PAGE) {
|
|
157
|
-
updatePopId(oldId, config.id, parent);
|
|
158
|
-
}
|
|
159
|
-
|
|
160
144
|
if (config.items && Array.isArray(config.items)) {
|
|
161
145
|
for (const item of config.items) {
|
|
162
|
-
await this.setNewItemId(item
|
|
146
|
+
await this.setNewItemId(item);
|
|
163
147
|
}
|
|
164
148
|
}
|
|
165
149
|
|
|
@@ -186,31 +170,20 @@ class Props extends BaseService {
|
|
|
186
170
|
name: type,
|
|
187
171
|
};
|
|
188
172
|
}
|
|
189
|
-
}
|
|
190
173
|
|
|
191
|
-
/**
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
if (config.popId === oldId) {
|
|
205
|
-
config.popId = popId;
|
|
206
|
-
return;
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
if (Array.isArray(config.items)) {
|
|
210
|
-
updatePopId(oldId, popId, config as MPage);
|
|
211
|
-
}
|
|
212
|
-
});
|
|
213
|
-
};
|
|
174
|
+
/**
|
|
175
|
+
* 生成指定位数的GUID,无【-】格式
|
|
176
|
+
* @param digit 位数,默认值8
|
|
177
|
+
* @returns
|
|
178
|
+
*/
|
|
179
|
+
private guid(digit = 8): string {
|
|
180
|
+
return 'x'.repeat(digit).replace(/[xy]/g, (c) => {
|
|
181
|
+
const r = (Math.random() * 16) | 0;
|
|
182
|
+
const v = c === 'x' ? r : (r & 0x3) | 0x8;
|
|
183
|
+
return v.toString(16);
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
}
|
|
214
187
|
|
|
215
188
|
export type PropsService = Props;
|
|
216
189
|
|
package/src/utils/operator.ts
CHANGED
|
@@ -42,7 +42,7 @@ export const beforePaste = async (position: PastePosition, config: MNode[]): Pro
|
|
|
42
42
|
pastePosition.top = configItem.style?.top - referenceTop + pastePosition.top;
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
-
const pasteConfig = await propsService.setNewItemId(configItem
|
|
45
|
+
const pasteConfig = await propsService.setNewItemId(configItem);
|
|
46
46
|
|
|
47
47
|
if (pasteConfig.style) {
|
|
48
48
|
const { left, top } = pasteConfig.style;
|
package/src/utils/props.ts
CHANGED
|
@@ -106,6 +106,7 @@ declare class Editor extends BaseService {
|
|
|
106
106
|
* @returns 添加后的组件节点配置
|
|
107
107
|
*/
|
|
108
108
|
paste(position?: PastePosition): Promise<MNode | MNode[] | void>;
|
|
109
|
+
doPaste(config: MNode[], position?: PastePosition): Promise<MNode[]>;
|
|
109
110
|
doAlignCenter(config: MNode): Promise<MNode>;
|
|
110
111
|
/**
|
|
111
112
|
* 将指点节点设置居中
|
|
@@ -1,16 +1,47 @@
|
|
|
1
1
|
import type { FormConfig } from '@tmagic/form';
|
|
2
|
-
import type { MNode
|
|
2
|
+
import type { MNode } from '@tmagic/schema';
|
|
3
3
|
import BaseService from './BaseService';
|
|
4
4
|
declare class Props extends BaseService {
|
|
5
5
|
private state;
|
|
6
6
|
constructor();
|
|
7
7
|
setPropsConfigs(configs: Record<string, FormConfig>): void;
|
|
8
|
+
fillConfig(config: FormConfig): Promise<{
|
|
9
|
+
type: string;
|
|
10
|
+
items: ({
|
|
11
|
+
title: string;
|
|
12
|
+
labelWidth: string;
|
|
13
|
+
items: (import("@tmagic/form").ChildConfig & {
|
|
14
|
+
[key: string]: any;
|
|
15
|
+
})[];
|
|
16
|
+
} | {
|
|
17
|
+
title: string;
|
|
18
|
+
items: {
|
|
19
|
+
type: string;
|
|
20
|
+
name: string;
|
|
21
|
+
items: ({
|
|
22
|
+
name: string;
|
|
23
|
+
label: string;
|
|
24
|
+
type: string;
|
|
25
|
+
options: (mForm: import("@tmagic/form").FormState, { formValue }: any) => {
|
|
26
|
+
text: string;
|
|
27
|
+
value: string;
|
|
28
|
+
}[];
|
|
29
|
+
} | {
|
|
30
|
+
name: string;
|
|
31
|
+
label: string;
|
|
32
|
+
type: string;
|
|
33
|
+
options?: undefined;
|
|
34
|
+
})[];
|
|
35
|
+
}[];
|
|
36
|
+
labelWidth?: undefined;
|
|
37
|
+
})[];
|
|
38
|
+
}[]>;
|
|
8
39
|
/**
|
|
9
40
|
* 为指定类型组件设置组件属性表单配置
|
|
10
41
|
* @param type 组件类型
|
|
11
42
|
* @param config 组件属性表单配置
|
|
12
43
|
*/
|
|
13
|
-
setPropsConfig(type: string, config: FormConfig): void
|
|
44
|
+
setPropsConfig(type: string, config: FormConfig): Promise<void>;
|
|
14
45
|
/**
|
|
15
46
|
* 获取指点类型的组件属性表单配置
|
|
16
47
|
* @param type 组件类型
|
|
@@ -30,18 +61,12 @@ declare class Props extends BaseService {
|
|
|
30
61
|
* @returns 组件初始值
|
|
31
62
|
*/
|
|
32
63
|
getPropsValue(type: string, { inputEvent, ...defaultValue }?: Record<string, any>): Promise<any>;
|
|
33
|
-
/**
|
|
34
|
-
* 生成指定位数的GUID,无【-】格式
|
|
35
|
-
* @param digit 位数,默认值8
|
|
36
|
-
* @returns
|
|
37
|
-
*/
|
|
38
|
-
guid(digit?: number): string;
|
|
39
64
|
createId(type: string | number): Promise<string>;
|
|
40
65
|
/**
|
|
41
66
|
* 将组件与组件的子元素配置中的id都设置成一个新的ID
|
|
42
67
|
* @param {Object} config 组件配置
|
|
43
68
|
*/
|
|
44
|
-
setNewItemId(config: MNode
|
|
69
|
+
setNewItemId(config: MNode): Promise<MNode>;
|
|
45
70
|
/**
|
|
46
71
|
* 获取默认属性配置
|
|
47
72
|
* @param type 组件类型
|
|
@@ -60,6 +85,12 @@ declare class Props extends BaseService {
|
|
|
60
85
|
layout?: undefined;
|
|
61
86
|
items?: undefined;
|
|
62
87
|
}>;
|
|
88
|
+
/**
|
|
89
|
+
* 生成指定位数的GUID,无【-】格式
|
|
90
|
+
* @param digit 位数,默认值8
|
|
91
|
+
* @returns
|
|
92
|
+
*/
|
|
93
|
+
private guid;
|
|
63
94
|
}
|
|
64
95
|
export declare type PropsService = Props;
|
|
65
96
|
declare const _default: Props;
|
package/types/utils/props.d.ts
CHANGED