@tmagic/editor 1.1.0-beta.8 → 1.1.0-beta.9
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 +79 -82
- package/dist/tmagic-editor.mjs.map +1 -1
- package/dist/tmagic-editor.umd.js +78 -81
- package/dist/tmagic-editor.umd.js.map +1 -1
- package/package.json +7 -7
- package/src/Editor.vue +8 -2
- package/src/layouts/workspace/Stage.vue +6 -2
- package/src/layouts/workspace/ViewerMenu.vue +3 -3
- package/src/services/editor.ts +95 -60
- package/src/type.ts +2 -1
- package/src/utils/operator.ts +3 -57
- package/types/Editor.vue.d.ts +10 -1
- package/types/services/editor.d.ts +6 -9
- package/types/type.d.ts +2 -1
- package/types/utils/operator.d.ts +0 -6
package/dist/tmagic-editor.mjs
CHANGED
|
@@ -3,7 +3,7 @@ import serialize from 'serialize-javascript';
|
|
|
3
3
|
import { Delete, Close, Plus, Edit, Grid, ScaleToOriginal, ZoomOut, ZoomIn, Right, Back, ArrowDown, Files, DocumentCopy, Coin, ArrowLeftBold, ArrowRightBold, CaretBottom, Top, Bottom } from '@element-plus/icons-vue';
|
|
4
4
|
import { throttle, cloneDeep, mergeWith, isEmpty, uniq } from 'lodash-es';
|
|
5
5
|
import * as monaco from 'monaco-editor';
|
|
6
|
-
import StageCore, { GuidesType, getOffset, calcValueByFontsize, CONTAINER_HIGHLIGHT_CLASS } from '@tmagic/stage';
|
|
6
|
+
import StageCore, { GuidesType, getOffset, calcValueByFontsize, CONTAINER_HIGHLIGHT_CLASS, ContainerHighlightType } from '@tmagic/stage';
|
|
7
7
|
import { NodeType } from '@tmagic/schema';
|
|
8
8
|
import { isPop, getNodePath, isNumber, isPage, toLine, removeClassNameByClassName } from '@tmagic/utils';
|
|
9
9
|
import { EventEmitter } from 'events';
|
|
@@ -1030,44 +1030,6 @@ const getPositionInContainer = (position = {}, id) => {
|
|
|
1030
1030
|
top
|
|
1031
1031
|
};
|
|
1032
1032
|
};
|
|
1033
|
-
const beforeRemove = async (node) => {
|
|
1034
|
-
if (!node?.id)
|
|
1035
|
-
return;
|
|
1036
|
-
const stage = editorService.get("stage");
|
|
1037
|
-
const root = editorService.get("root");
|
|
1038
|
-
if (!root)
|
|
1039
|
-
throw new Error("\u6CA1\u6709root");
|
|
1040
|
-
const { parent, node: curNode } = editorService.getNodeInfo(node.id, false);
|
|
1041
|
-
if (!parent || !curNode)
|
|
1042
|
-
throw new Error("\u627E\u4E0D\u8981\u5220\u9664\u7684\u8282\u70B9");
|
|
1043
|
-
const index = getNodeIndex(curNode, parent);
|
|
1044
|
-
if (typeof index !== "number" || index === -1)
|
|
1045
|
-
throw new Error("\u627E\u4E0D\u8981\u5220\u9664\u7684\u8282\u70B9");
|
|
1046
|
-
parent.items?.splice(index, 1);
|
|
1047
|
-
stage?.remove({ id: node.id, root: cloneDeep(root) });
|
|
1048
|
-
if (node.type === NodeType.PAGE) {
|
|
1049
|
-
editorService.state.pageLength -= 1;
|
|
1050
|
-
if (root.items[0]) {
|
|
1051
|
-
await editorService.select(root.items[0]);
|
|
1052
|
-
stage?.select(root.items[0].id);
|
|
1053
|
-
} else {
|
|
1054
|
-
editorService.set("node", null);
|
|
1055
|
-
editorService.set("nodes", []);
|
|
1056
|
-
editorService.set("parent", null);
|
|
1057
|
-
editorService.set("page", null);
|
|
1058
|
-
editorService.set("stage", null);
|
|
1059
|
-
editorService.set("highlightNode", null);
|
|
1060
|
-
editorService.resetModifiedNodeId();
|
|
1061
|
-
historyService.reset();
|
|
1062
|
-
editorService.emit("remove", node);
|
|
1063
|
-
return;
|
|
1064
|
-
}
|
|
1065
|
-
} else {
|
|
1066
|
-
await editorService.select(parent);
|
|
1067
|
-
stage?.select(parent.id);
|
|
1068
|
-
}
|
|
1069
|
-
return parent;
|
|
1070
|
-
};
|
|
1071
1033
|
const getAddParent = (addNode) => {
|
|
1072
1034
|
const curNode = editorService.get("node");
|
|
1073
1035
|
let parentNode;
|
|
@@ -1100,11 +1062,14 @@ class Editor$1 extends BaseService {
|
|
|
1100
1062
|
"select",
|
|
1101
1063
|
"doAdd",
|
|
1102
1064
|
"add",
|
|
1065
|
+
"doRemove",
|
|
1103
1066
|
"remove",
|
|
1067
|
+
"doUpdate",
|
|
1104
1068
|
"update",
|
|
1105
1069
|
"sort",
|
|
1106
1070
|
"copy",
|
|
1107
1071
|
"paste",
|
|
1072
|
+
"duAlignCenter",
|
|
1108
1073
|
"alignCenter",
|
|
1109
1074
|
"moveLayer",
|
|
1110
1075
|
"moveToContainer",
|
|
@@ -1280,31 +1245,47 @@ class Editor$1 extends BaseService {
|
|
|
1280
1245
|
this.emit("add", newNodes);
|
|
1281
1246
|
return newNodes.length > 1 ? newNodes[0] : newNodes;
|
|
1282
1247
|
}
|
|
1283
|
-
async
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1248
|
+
async doRemove(node) {
|
|
1249
|
+
const root = this.get("root");
|
|
1250
|
+
if (!root)
|
|
1251
|
+
throw new Error("\u6CA1\u6709root");
|
|
1252
|
+
const { parent, node: curNode } = this.getNodeInfo(node.id);
|
|
1253
|
+
if (!parent || !curNode)
|
|
1254
|
+
throw new Error("\u627E\u4E0D\u8981\u5220\u9664\u7684\u8282\u70B9");
|
|
1255
|
+
const index = getNodeIndex(curNode, parent);
|
|
1256
|
+
if (typeof index !== "number" || index === -1)
|
|
1257
|
+
throw new Error("\u627E\u4E0D\u8981\u5220\u9664\u7684\u8282\u70B9");
|
|
1258
|
+
parent.items?.splice(index, 1);
|
|
1259
|
+
const stage = this.get("stage");
|
|
1260
|
+
stage?.remove({ id: node.id, root: this.get("root") });
|
|
1261
|
+
if (node.type === NodeType.PAGE) {
|
|
1262
|
+
this.state.pageLength -= 1;
|
|
1263
|
+
if (root.items[0]) {
|
|
1264
|
+
await this.select(root.items[0]);
|
|
1265
|
+
stage?.select(root.items[0].id);
|
|
1266
|
+
} else {
|
|
1267
|
+
this.set("node", null);
|
|
1268
|
+
this.set("parent", null);
|
|
1269
|
+
this.set("page", null);
|
|
1270
|
+
this.set("stage", null);
|
|
1271
|
+
this.set("highlightNode", null);
|
|
1272
|
+
this.resetModifiedNodeId();
|
|
1273
|
+
historyService.reset();
|
|
1274
|
+
return;
|
|
1275
|
+
}
|
|
1276
|
+
} else {
|
|
1277
|
+
await this.select(parent);
|
|
1278
|
+
stage?.select(parent.id);
|
|
1287
1279
|
}
|
|
1288
|
-
|
|
1289
|
-
const removeParent = await beforeRemove(node);
|
|
1290
|
-
if (!removeParent)
|
|
1291
|
-
return node;
|
|
1292
|
-
this.addModifiedNodeId(removeParent.id);
|
|
1293
|
-
this.pushHistoryState();
|
|
1294
|
-
this.emit("remove", node);
|
|
1295
|
-
return node;
|
|
1280
|
+
this.addModifiedNodeId(parent.id);
|
|
1296
1281
|
}
|
|
1297
|
-
async
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
}));
|
|
1301
|
-
const nodeIds = nodes.map((node) => node.id);
|
|
1302
|
-
this.addModifiedNodeId(nodeIds.join("-"));
|
|
1282
|
+
async remove(nodeOrNodeList) {
|
|
1283
|
+
const nodes = Array.isArray(nodeOrNodeList) ? nodeOrNodeList : [nodeOrNodeList];
|
|
1284
|
+
await Promise.all(nodes.map((node) => this.doRemove(node)));
|
|
1303
1285
|
this.pushHistoryState();
|
|
1304
|
-
this.emit("
|
|
1305
|
-
return nodes;
|
|
1286
|
+
this.emit("remove");
|
|
1306
1287
|
}
|
|
1307
|
-
async
|
|
1288
|
+
async doUpdate(config) {
|
|
1308
1289
|
if (!config?.id)
|
|
1309
1290
|
throw new Error("\u6CA1\u6709\u914D\u7F6E\u6216\u8005\u914D\u7F6E\u7F3A\u5C11id\u503C");
|
|
1310
1291
|
const info = this.getNodeInfo(config.id, false);
|
|
@@ -1345,10 +1326,15 @@ class Editor$1 extends BaseService {
|
|
|
1345
1326
|
this.set("page", newConfig);
|
|
1346
1327
|
}
|
|
1347
1328
|
this.addModifiedNodeId(newConfig.id);
|
|
1348
|
-
this.pushHistoryState();
|
|
1349
|
-
this.emit("update", newConfig);
|
|
1350
1329
|
return newConfig;
|
|
1351
1330
|
}
|
|
1331
|
+
async update(config) {
|
|
1332
|
+
const nodes = Array.isArray(config) ? config : [config];
|
|
1333
|
+
const newNodes = await Promise.all(nodes.map((node) => this.doUpdate(node)));
|
|
1334
|
+
this.pushHistoryState();
|
|
1335
|
+
this.emit("update", newNodes);
|
|
1336
|
+
return newNodes.length > 1 ? newNodes[0] : newNodes;
|
|
1337
|
+
}
|
|
1352
1338
|
async sort(id1, id2) {
|
|
1353
1339
|
const node = this.get("node");
|
|
1354
1340
|
const parent = cloneDeep(toRaw(this.get("parent")));
|
|
@@ -1375,15 +1361,17 @@ class Editor$1 extends BaseService {
|
|
|
1375
1361
|
const pasteConfigs = await beforePaste(position, config);
|
|
1376
1362
|
return this.add(pasteConfigs);
|
|
1377
1363
|
}
|
|
1378
|
-
async
|
|
1379
|
-
const parent = this.
|
|
1380
|
-
|
|
1381
|
-
|
|
1364
|
+
async doAlignCenter(config) {
|
|
1365
|
+
const parent = this.getParentById(config.id);
|
|
1366
|
+
if (!parent)
|
|
1367
|
+
throw new Error("\u627E\u4E0D\u5230\u7236\u8282\u70B9");
|
|
1368
|
+
const node = cloneDeep(toRaw(config));
|
|
1369
|
+
const layout = await this.getLayout(parent, node);
|
|
1382
1370
|
if (layout === Layout.RELATIVE) {
|
|
1383
|
-
return;
|
|
1371
|
+
return config;
|
|
1384
1372
|
}
|
|
1385
1373
|
if (!node.style)
|
|
1386
|
-
return;
|
|
1374
|
+
return config;
|
|
1387
1375
|
const stage = this.get("stage");
|
|
1388
1376
|
const doc = stage?.renderer.contentWindow?.document;
|
|
1389
1377
|
if (doc) {
|
|
@@ -1395,14 +1383,15 @@ class Editor$1 extends BaseService {
|
|
|
1395
1383
|
} else if (parent.style && isNumber(parent.style?.width) && isNumber(node.style?.width)) {
|
|
1396
1384
|
node.style.left = (parent.style.width - node.style.width) / 2;
|
|
1397
1385
|
}
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
this.
|
|
1405
|
-
|
|
1386
|
+
return node;
|
|
1387
|
+
}
|
|
1388
|
+
async alignCenter(config) {
|
|
1389
|
+
const nodes = Array.isArray(config) ? config : [config];
|
|
1390
|
+
const stage = this.get("stage");
|
|
1391
|
+
const newNodes = await Promise.all(nodes.map((node) => this.doAlignCenter(node)));
|
|
1392
|
+
const newNode = await this.update(newNodes);
|
|
1393
|
+
await stage?.multiSelect(newNodes.map((node) => node.id));
|
|
1394
|
+
return newNode;
|
|
1406
1395
|
}
|
|
1407
1396
|
async moveLayer(offset) {
|
|
1408
1397
|
const parent = this.get("parent");
|
|
@@ -3604,11 +3593,11 @@ const _sfc_main$3 = /* @__PURE__ */ defineComponent({
|
|
|
3604
3593
|
{
|
|
3605
3594
|
type: "button",
|
|
3606
3595
|
text: "\u6C34\u5E73\u5C45\u4E2D",
|
|
3607
|
-
display: () => canCenter.value
|
|
3596
|
+
display: () => canCenter.value,
|
|
3608
3597
|
handler: () => {
|
|
3609
|
-
if (!
|
|
3598
|
+
if (!nodes.value)
|
|
3610
3599
|
return;
|
|
3611
|
-
editorService?.alignCenter(
|
|
3600
|
+
editorService?.alignCenter(nodes.value);
|
|
3612
3601
|
}
|
|
3613
3602
|
},
|
|
3614
3603
|
{
|
|
@@ -3761,6 +3750,7 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
|
|
|
3761
3750
|
isContainer: stageOptions.isContainer,
|
|
3762
3751
|
containerHighlightClassName: stageOptions.containerHighlightClassName,
|
|
3763
3752
|
containerHighlightDuration: stageOptions.containerHighlightDuration,
|
|
3753
|
+
containerHighlightType: stageOptions.containerHighlightType,
|
|
3764
3754
|
canSelect: (el, event, stop) => {
|
|
3765
3755
|
const elCanSelect = stageOptions.canSelect(el);
|
|
3766
3756
|
if (uiSelectMode.value && elCanSelect && event.type === "mousedown") {
|
|
@@ -3789,10 +3779,12 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
|
|
|
3789
3779
|
});
|
|
3790
3780
|
stage?.on("update", (ev) => {
|
|
3791
3781
|
if (ev.parentEl) {
|
|
3792
|
-
|
|
3782
|
+
for (const data of ev.data) {
|
|
3783
|
+
services?.editorService.moveToContainer({ id: data.el.id, style: data.style }, ev.parentEl.id);
|
|
3784
|
+
}
|
|
3793
3785
|
return;
|
|
3794
3786
|
}
|
|
3795
|
-
services?.editorService.update({ id:
|
|
3787
|
+
services?.editorService.update(ev.data.map((data) => ({ id: data.el.id, style: data.style })));
|
|
3796
3788
|
});
|
|
3797
3789
|
stage?.on("sort", (ev) => {
|
|
3798
3790
|
services?.editorService.sort(ev.src, ev.dist);
|
|
@@ -4267,6 +4259,10 @@ const _sfc_main = defineComponent({
|
|
|
4267
4259
|
type: Number,
|
|
4268
4260
|
default: 800
|
|
4269
4261
|
},
|
|
4262
|
+
containerHighlightType: {
|
|
4263
|
+
type: String,
|
|
4264
|
+
default: ContainerHighlightType.DEFAULT
|
|
4265
|
+
},
|
|
4270
4266
|
stageRect: {
|
|
4271
4267
|
type: [String, Object]
|
|
4272
4268
|
},
|
|
@@ -4337,7 +4333,8 @@ const _sfc_main = defineComponent({
|
|
|
4337
4333
|
updateDragEl: props.updateDragEl,
|
|
4338
4334
|
isContainer: props.isContainer,
|
|
4339
4335
|
containerHighlightClassName: props.containerHighlightClassName,
|
|
4340
|
-
containerHighlightDuration: props.containerHighlightDuration
|
|
4336
|
+
containerHighlightDuration: props.containerHighlightDuration,
|
|
4337
|
+
containerHighlightType: props.containerHighlightType
|
|
4341
4338
|
}));
|
|
4342
4339
|
return services;
|
|
4343
4340
|
}
|