@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
|
@@ -1048,44 +1048,6 @@
|
|
|
1048
1048
|
top
|
|
1049
1049
|
};
|
|
1050
1050
|
};
|
|
1051
|
-
const beforeRemove = async (node) => {
|
|
1052
|
-
if (!node?.id)
|
|
1053
|
-
return;
|
|
1054
|
-
const stage = editorService.get("stage");
|
|
1055
|
-
const root = editorService.get("root");
|
|
1056
|
-
if (!root)
|
|
1057
|
-
throw new Error("\u6CA1\u6709root");
|
|
1058
|
-
const { parent, node: curNode } = editorService.getNodeInfo(node.id, false);
|
|
1059
|
-
if (!parent || !curNode)
|
|
1060
|
-
throw new Error("\u627E\u4E0D\u8981\u5220\u9664\u7684\u8282\u70B9");
|
|
1061
|
-
const index = getNodeIndex(curNode, parent);
|
|
1062
|
-
if (typeof index !== "number" || index === -1)
|
|
1063
|
-
throw new Error("\u627E\u4E0D\u8981\u5220\u9664\u7684\u8282\u70B9");
|
|
1064
|
-
parent.items?.splice(index, 1);
|
|
1065
|
-
stage?.remove({ id: node.id, root: lodashEs.cloneDeep(root) });
|
|
1066
|
-
if (node.type === schema.NodeType.PAGE) {
|
|
1067
|
-
editorService.state.pageLength -= 1;
|
|
1068
|
-
if (root.items[0]) {
|
|
1069
|
-
await editorService.select(root.items[0]);
|
|
1070
|
-
stage?.select(root.items[0].id);
|
|
1071
|
-
} else {
|
|
1072
|
-
editorService.set("node", null);
|
|
1073
|
-
editorService.set("nodes", []);
|
|
1074
|
-
editorService.set("parent", null);
|
|
1075
|
-
editorService.set("page", null);
|
|
1076
|
-
editorService.set("stage", null);
|
|
1077
|
-
editorService.set("highlightNode", null);
|
|
1078
|
-
editorService.resetModifiedNodeId();
|
|
1079
|
-
historyService.reset();
|
|
1080
|
-
editorService.emit("remove", node);
|
|
1081
|
-
return;
|
|
1082
|
-
}
|
|
1083
|
-
} else {
|
|
1084
|
-
await editorService.select(parent);
|
|
1085
|
-
stage?.select(parent.id);
|
|
1086
|
-
}
|
|
1087
|
-
return parent;
|
|
1088
|
-
};
|
|
1089
1051
|
const getAddParent = (addNode) => {
|
|
1090
1052
|
const curNode = editorService.get("node");
|
|
1091
1053
|
let parentNode;
|
|
@@ -1118,11 +1080,14 @@
|
|
|
1118
1080
|
"select",
|
|
1119
1081
|
"doAdd",
|
|
1120
1082
|
"add",
|
|
1083
|
+
"doRemove",
|
|
1121
1084
|
"remove",
|
|
1085
|
+
"doUpdate",
|
|
1122
1086
|
"update",
|
|
1123
1087
|
"sort",
|
|
1124
1088
|
"copy",
|
|
1125
1089
|
"paste",
|
|
1090
|
+
"duAlignCenter",
|
|
1126
1091
|
"alignCenter",
|
|
1127
1092
|
"moveLayer",
|
|
1128
1093
|
"moveToContainer",
|
|
@@ -1298,31 +1263,47 @@
|
|
|
1298
1263
|
this.emit("add", newNodes);
|
|
1299
1264
|
return newNodes.length > 1 ? newNodes[0] : newNodes;
|
|
1300
1265
|
}
|
|
1301
|
-
async
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1266
|
+
async doRemove(node) {
|
|
1267
|
+
const root = this.get("root");
|
|
1268
|
+
if (!root)
|
|
1269
|
+
throw new Error("\u6CA1\u6709root");
|
|
1270
|
+
const { parent, node: curNode } = this.getNodeInfo(node.id);
|
|
1271
|
+
if (!parent || !curNode)
|
|
1272
|
+
throw new Error("\u627E\u4E0D\u8981\u5220\u9664\u7684\u8282\u70B9");
|
|
1273
|
+
const index = getNodeIndex(curNode, parent);
|
|
1274
|
+
if (typeof index !== "number" || index === -1)
|
|
1275
|
+
throw new Error("\u627E\u4E0D\u8981\u5220\u9664\u7684\u8282\u70B9");
|
|
1276
|
+
parent.items?.splice(index, 1);
|
|
1277
|
+
const stage = this.get("stage");
|
|
1278
|
+
stage?.remove({ id: node.id, root: this.get("root") });
|
|
1279
|
+
if (node.type === schema.NodeType.PAGE) {
|
|
1280
|
+
this.state.pageLength -= 1;
|
|
1281
|
+
if (root.items[0]) {
|
|
1282
|
+
await this.select(root.items[0]);
|
|
1283
|
+
stage?.select(root.items[0].id);
|
|
1284
|
+
} else {
|
|
1285
|
+
this.set("node", null);
|
|
1286
|
+
this.set("parent", null);
|
|
1287
|
+
this.set("page", null);
|
|
1288
|
+
this.set("stage", null);
|
|
1289
|
+
this.set("highlightNode", null);
|
|
1290
|
+
this.resetModifiedNodeId();
|
|
1291
|
+
historyService.reset();
|
|
1292
|
+
return;
|
|
1293
|
+
}
|
|
1294
|
+
} else {
|
|
1295
|
+
await this.select(parent);
|
|
1296
|
+
stage?.select(parent.id);
|
|
1305
1297
|
}
|
|
1306
|
-
|
|
1307
|
-
const removeParent = await beforeRemove(node);
|
|
1308
|
-
if (!removeParent)
|
|
1309
|
-
return node;
|
|
1310
|
-
this.addModifiedNodeId(removeParent.id);
|
|
1311
|
-
this.pushHistoryState();
|
|
1312
|
-
this.emit("remove", node);
|
|
1313
|
-
return node;
|
|
1298
|
+
this.addModifiedNodeId(parent.id);
|
|
1314
1299
|
}
|
|
1315
|
-
async
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
}));
|
|
1319
|
-
const nodeIds = nodes.map((node) => node.id);
|
|
1320
|
-
this.addModifiedNodeId(nodeIds.join("-"));
|
|
1300
|
+
async remove(nodeOrNodeList) {
|
|
1301
|
+
const nodes = Array.isArray(nodeOrNodeList) ? nodeOrNodeList : [nodeOrNodeList];
|
|
1302
|
+
await Promise.all(nodes.map((node) => this.doRemove(node)));
|
|
1321
1303
|
this.pushHistoryState();
|
|
1322
|
-
this.emit("
|
|
1323
|
-
return nodes;
|
|
1304
|
+
this.emit("remove");
|
|
1324
1305
|
}
|
|
1325
|
-
async
|
|
1306
|
+
async doUpdate(config) {
|
|
1326
1307
|
if (!config?.id)
|
|
1327
1308
|
throw new Error("\u6CA1\u6709\u914D\u7F6E\u6216\u8005\u914D\u7F6E\u7F3A\u5C11id\u503C");
|
|
1328
1309
|
const info = this.getNodeInfo(config.id, false);
|
|
@@ -1363,10 +1344,15 @@
|
|
|
1363
1344
|
this.set("page", newConfig);
|
|
1364
1345
|
}
|
|
1365
1346
|
this.addModifiedNodeId(newConfig.id);
|
|
1366
|
-
this.pushHistoryState();
|
|
1367
|
-
this.emit("update", newConfig);
|
|
1368
1347
|
return newConfig;
|
|
1369
1348
|
}
|
|
1349
|
+
async update(config) {
|
|
1350
|
+
const nodes = Array.isArray(config) ? config : [config];
|
|
1351
|
+
const newNodes = await Promise.all(nodes.map((node) => this.doUpdate(node)));
|
|
1352
|
+
this.pushHistoryState();
|
|
1353
|
+
this.emit("update", newNodes);
|
|
1354
|
+
return newNodes.length > 1 ? newNodes[0] : newNodes;
|
|
1355
|
+
}
|
|
1370
1356
|
async sort(id1, id2) {
|
|
1371
1357
|
const node = this.get("node");
|
|
1372
1358
|
const parent = lodashEs.cloneDeep(vue.toRaw(this.get("parent")));
|
|
@@ -1393,15 +1379,17 @@
|
|
|
1393
1379
|
const pasteConfigs = await beforePaste(position, config);
|
|
1394
1380
|
return this.add(pasteConfigs);
|
|
1395
1381
|
}
|
|
1396
|
-
async
|
|
1397
|
-
const parent = this.
|
|
1398
|
-
|
|
1399
|
-
|
|
1382
|
+
async doAlignCenter(config) {
|
|
1383
|
+
const parent = this.getParentById(config.id);
|
|
1384
|
+
if (!parent)
|
|
1385
|
+
throw new Error("\u627E\u4E0D\u5230\u7236\u8282\u70B9");
|
|
1386
|
+
const node = lodashEs.cloneDeep(vue.toRaw(config));
|
|
1387
|
+
const layout = await this.getLayout(parent, node);
|
|
1400
1388
|
if (layout === Layout.RELATIVE) {
|
|
1401
|
-
return;
|
|
1389
|
+
return config;
|
|
1402
1390
|
}
|
|
1403
1391
|
if (!node.style)
|
|
1404
|
-
return;
|
|
1392
|
+
return config;
|
|
1405
1393
|
const stage = this.get("stage");
|
|
1406
1394
|
const doc = stage?.renderer.contentWindow?.document;
|
|
1407
1395
|
if (doc) {
|
|
@@ -1413,14 +1401,15 @@
|
|
|
1413
1401
|
} else if (parent.style && utils.isNumber(parent.style?.width) && utils.isNumber(node.style?.width)) {
|
|
1414
1402
|
node.style.left = (parent.style.width - node.style.width) / 2;
|
|
1415
1403
|
}
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
this.
|
|
1423
|
-
|
|
1404
|
+
return node;
|
|
1405
|
+
}
|
|
1406
|
+
async alignCenter(config) {
|
|
1407
|
+
const nodes = Array.isArray(config) ? config : [config];
|
|
1408
|
+
const stage = this.get("stage");
|
|
1409
|
+
const newNodes = await Promise.all(nodes.map((node) => this.doAlignCenter(node)));
|
|
1410
|
+
const newNode = await this.update(newNodes);
|
|
1411
|
+
await stage?.multiSelect(newNodes.map((node) => node.id));
|
|
1412
|
+
return newNode;
|
|
1424
1413
|
}
|
|
1425
1414
|
async moveLayer(offset) {
|
|
1426
1415
|
const parent = this.get("parent");
|
|
@@ -3622,11 +3611,11 @@
|
|
|
3622
3611
|
{
|
|
3623
3612
|
type: "button",
|
|
3624
3613
|
text: "\u6C34\u5E73\u5C45\u4E2D",
|
|
3625
|
-
display: () => canCenter.value
|
|
3614
|
+
display: () => canCenter.value,
|
|
3626
3615
|
handler: () => {
|
|
3627
|
-
if (!
|
|
3616
|
+
if (!nodes.value)
|
|
3628
3617
|
return;
|
|
3629
|
-
editorService?.alignCenter(
|
|
3618
|
+
editorService?.alignCenter(nodes.value);
|
|
3630
3619
|
}
|
|
3631
3620
|
},
|
|
3632
3621
|
{
|
|
@@ -3779,6 +3768,7 @@
|
|
|
3779
3768
|
isContainer: stageOptions.isContainer,
|
|
3780
3769
|
containerHighlightClassName: stageOptions.containerHighlightClassName,
|
|
3781
3770
|
containerHighlightDuration: stageOptions.containerHighlightDuration,
|
|
3771
|
+
containerHighlightType: stageOptions.containerHighlightType,
|
|
3782
3772
|
canSelect: (el, event, stop) => {
|
|
3783
3773
|
const elCanSelect = stageOptions.canSelect(el);
|
|
3784
3774
|
if (uiSelectMode.value && elCanSelect && event.type === "mousedown") {
|
|
@@ -3807,10 +3797,12 @@
|
|
|
3807
3797
|
});
|
|
3808
3798
|
stage?.on("update", (ev) => {
|
|
3809
3799
|
if (ev.parentEl) {
|
|
3810
|
-
|
|
3800
|
+
for (const data of ev.data) {
|
|
3801
|
+
services?.editorService.moveToContainer({ id: data.el.id, style: data.style }, ev.parentEl.id);
|
|
3802
|
+
}
|
|
3811
3803
|
return;
|
|
3812
3804
|
}
|
|
3813
|
-
services?.editorService.update({ id:
|
|
3805
|
+
services?.editorService.update(ev.data.map((data) => ({ id: data.el.id, style: data.style })));
|
|
3814
3806
|
});
|
|
3815
3807
|
stage?.on("sort", (ev) => {
|
|
3816
3808
|
services?.editorService.sort(ev.src, ev.dist);
|
|
@@ -4285,6 +4277,10 @@
|
|
|
4285
4277
|
type: Number,
|
|
4286
4278
|
default: 800
|
|
4287
4279
|
},
|
|
4280
|
+
containerHighlightType: {
|
|
4281
|
+
type: String,
|
|
4282
|
+
default: StageCore.ContainerHighlightType.DEFAULT
|
|
4283
|
+
},
|
|
4288
4284
|
stageRect: {
|
|
4289
4285
|
type: [String, Object]
|
|
4290
4286
|
},
|
|
@@ -4355,7 +4351,8 @@
|
|
|
4355
4351
|
updateDragEl: props.updateDragEl,
|
|
4356
4352
|
isContainer: props.isContainer,
|
|
4357
4353
|
containerHighlightClassName: props.containerHighlightClassName,
|
|
4358
|
-
containerHighlightDuration: props.containerHighlightDuration
|
|
4354
|
+
containerHighlightDuration: props.containerHighlightDuration,
|
|
4355
|
+
containerHighlightType: props.containerHighlightType
|
|
4359
4356
|
}));
|
|
4360
4357
|
return services;
|
|
4361
4358
|
}
|