@tmagic/stage 1.3.5 → 1.3.7
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/LICENSE +5432 -0
- package/dist/tmagic-stage.js +198 -125
- package/dist/tmagic-stage.js.map +1 -1
- package/dist/tmagic-stage.umd.cjs +198 -124
- package/dist/tmagic-stage.umd.cjs.map +1 -1
- package/package.json +13 -13
- package/src/ActionManager.ts +124 -84
- package/src/MoveableActionsAble.ts +1 -1
- package/src/MoveableOptionsManager.ts +2 -2
- package/src/Rule.ts +7 -2
- package/src/StageCore.ts +19 -5
- package/src/StageMask.ts +3 -2
- package/src/StageRender.ts +63 -28
- package/src/TargetShadow.ts +1 -1
- package/src/const.ts +5 -0
- package/src/index.ts +1 -0
- package/src/types.ts +14 -4
- package/types/ActionManager.d.ts +8 -6
- package/types/MoveableActionsAble.d.ts +1 -1
- package/types/MoveableOptionsManager.d.ts +1 -1
- package/types/Rule.d.ts +3 -1
- package/types/StageCore.d.ts +2 -0
- package/types/StageMask.d.ts +2 -1
- package/types/StageRender.d.ts +7 -3
- package/types/const.d.ts +4 -0
- package/types/index.d.ts +1 -0
- package/types/types.d.ts +13 -4
package/dist/tmagic-stage.js
CHANGED
|
@@ -39,6 +39,11 @@ var Mode = /* @__PURE__ */ ((Mode2) => {
|
|
|
39
39
|
return Mode2;
|
|
40
40
|
})(Mode || {});
|
|
41
41
|
const SELECTED_CLASS = "tmagic-stage-selected-area";
|
|
42
|
+
var AbleActionEventType = /* @__PURE__ */ ((AbleActionEventType2) => {
|
|
43
|
+
AbleActionEventType2["SELECT_PARENT"] = "select-parent";
|
|
44
|
+
AbleActionEventType2["REMOVE"] = "remove";
|
|
45
|
+
return AbleActionEventType2;
|
|
46
|
+
})(AbleActionEventType || {});
|
|
42
47
|
|
|
43
48
|
const getParents = (el, relative) => {
|
|
44
49
|
let cur = el.parentElement;
|
|
@@ -282,7 +287,7 @@ class TargetShadow {
|
|
|
282
287
|
el.id = `${this.idPrefix}${target.id}`;
|
|
283
288
|
el.style.cssText = getTargetElStyle(target, this.zIndex);
|
|
284
289
|
if (typeof this.updateDragEl === "function") {
|
|
285
|
-
this.updateDragEl(el, target);
|
|
290
|
+
this.updateDragEl(el, target, this.container);
|
|
286
291
|
}
|
|
287
292
|
const isFixed = isFixedParent(target);
|
|
288
293
|
const mode = this.container.dataset.mode || Mode.ABSOLUTE;
|
|
@@ -582,28 +587,6 @@ class DragResizeHelper {
|
|
|
582
587
|
|
|
583
588
|
const ableCss = ".moveable-button {\n width: 20px;\n height: 20px;\n background: #4af;\n border-radius: 4px;\n appearance: none;\n border: 0;\n color: white;\n font-size: 12px;\n font-weight: bold;\n margin-left: 2px;\n position: relative;\n}\n.moveable-remove-button:before, .moveable-remove-button:after {\n content: \"\";\n position: absolute;\n left: 50%;\n top: 50%;\n transform: translate(-50%, -50%) rotate(45deg);\n width: 14px;\n height: 2px;\n background: #fff;\n border-radius: 1px;\n cursor: pointer;\n}\n.moveable-remove-button:after {\n transform: translate(-50%, -50%) rotate(-45deg);\n}\n\n.moveable-select-parent-arrow-top-icon {\n transform: rotateZ(-45deg);\n width: 4px;\n height: 4px;\n border-color: #fff;\n border-width: 2px 2px 0 0;\n border-style: solid;\n position: absolute;\n left: 4px;\n top: 4px;\n}\n\n.moveable-select-parent-arrow-body-icon {\n width: 7px;\n height: 11px;\n border-color: #fff;\n border-width: 0 0 2px 2px;\n border-style: solid;\n}\n\n.moveable-drag-area-button {\n cursor: move;\n}\n\n.moveable-drag-area-button .moveable-select-parent-arrow-top-icon {\n width: 2px;\n height: 2px;\n}\n\n.moveable-drag-area-button .moveable-select-parent-arrow-top-icon-top {\n transform: rotateZ(-45deg) translateX(-50%);\n left: 50%;\n top: 3px;\n transform-origin: left;\n}\n\n.moveable-drag-area-button .moveable-select-parent-arrow-top-icon-bottom {\n transform: rotateZ(135deg) translateX(-50%);\n transform-origin: left;\n left: 50%;\n top: auto;\n bottom: 3px;\n}\n\n.moveable-drag-area-button .moveable-select-parent-arrow-top-icon-right {\n transform: rotateZ(45deg) translateY(-50%);\n transform-origin: top;\n right: 3px;\n left: auto;\n top: 50%;\n}\n\n.moveable-drag-area-button .moveable-select-parent-arrow-top-icon-left {\n transform: rotateZ(235deg) translateY(-50%);\n transform-origin: top;\n left: 3px;\n top: 50%;\n}\n\n.moveable-drag-area-button .moveable-select-parent-arrow-body-icon-horizontal {\n width: 2px;\n height: 11px;\n background-color: #fff;\n position: absolute;\n transform: translateX(-50%);\n left: 50%;\n top: 4px;\n}\n\n.moveable-drag-area-button .moveable-select-parent-arrow-body-icon-vertical {\n width: 11px;\n height: 2px;\n background-color: #fff;\n position: absolute;\n transform: translateY(-50%);\n left: 4px;\n top: 50%;;\n}\n\n";
|
|
584
589
|
|
|
585
|
-
var ContainerHighlightType = /* @__PURE__ */ ((ContainerHighlightType2) => {
|
|
586
|
-
ContainerHighlightType2["DEFAULT"] = "default";
|
|
587
|
-
ContainerHighlightType2["ALT"] = "alt";
|
|
588
|
-
return ContainerHighlightType2;
|
|
589
|
-
})(ContainerHighlightType || {});
|
|
590
|
-
var SelectStatus = /* @__PURE__ */ ((SelectStatus2) => {
|
|
591
|
-
SelectStatus2["SELECT"] = "select";
|
|
592
|
-
SelectStatus2["MULTI_SELECT"] = "multiSelect";
|
|
593
|
-
return SelectStatus2;
|
|
594
|
-
})(SelectStatus || {});
|
|
595
|
-
var StageDragStatus = /* @__PURE__ */ ((StageDragStatus2) => {
|
|
596
|
-
StageDragStatus2["START"] = "start";
|
|
597
|
-
StageDragStatus2["ING"] = "ing";
|
|
598
|
-
StageDragStatus2["END"] = "end";
|
|
599
|
-
return StageDragStatus2;
|
|
600
|
-
})(StageDragStatus || {});
|
|
601
|
-
var AbleActionEventType = /* @__PURE__ */ ((AbleActionEventType2) => {
|
|
602
|
-
AbleActionEventType2["SELECT_PARENT"] = "select-parent";
|
|
603
|
-
AbleActionEventType2["REMOVE"] = "remove";
|
|
604
|
-
return AbleActionEventType2;
|
|
605
|
-
})(AbleActionEventType || {});
|
|
606
|
-
|
|
607
590
|
const MoveableActionsAble = (handler) => ({
|
|
608
591
|
name: "actions",
|
|
609
592
|
props: [],
|
|
@@ -896,6 +879,28 @@ class MoveableOptionsManager extends EventEmitter {
|
|
|
896
879
|
}
|
|
897
880
|
}
|
|
898
881
|
|
|
882
|
+
var ContainerHighlightType = /* @__PURE__ */ ((ContainerHighlightType2) => {
|
|
883
|
+
ContainerHighlightType2["DEFAULT"] = "default";
|
|
884
|
+
ContainerHighlightType2["ALT"] = "alt";
|
|
885
|
+
return ContainerHighlightType2;
|
|
886
|
+
})(ContainerHighlightType || {});
|
|
887
|
+
var RenderType = /* @__PURE__ */ ((RenderType2) => {
|
|
888
|
+
RenderType2["IFRAME"] = "iframe";
|
|
889
|
+
RenderType2["NATIVE"] = "native";
|
|
890
|
+
return RenderType2;
|
|
891
|
+
})(RenderType || {});
|
|
892
|
+
var SelectStatus = /* @__PURE__ */ ((SelectStatus2) => {
|
|
893
|
+
SelectStatus2["SELECT"] = "select";
|
|
894
|
+
SelectStatus2["MULTI_SELECT"] = "multiSelect";
|
|
895
|
+
return SelectStatus2;
|
|
896
|
+
})(SelectStatus || {});
|
|
897
|
+
var StageDragStatus = /* @__PURE__ */ ((StageDragStatus2) => {
|
|
898
|
+
StageDragStatus2["START"] = "start";
|
|
899
|
+
StageDragStatus2["ING"] = "ing";
|
|
900
|
+
StageDragStatus2["END"] = "end";
|
|
901
|
+
return StageDragStatus2;
|
|
902
|
+
})(StageDragStatus || {});
|
|
903
|
+
|
|
899
904
|
class StageDragResize extends MoveableOptionsManager {
|
|
900
905
|
/** 目标节点 */
|
|
901
906
|
target;
|
|
@@ -1388,6 +1393,8 @@ class ActionManager extends EventEmitter {
|
|
|
1388
1393
|
canSelect;
|
|
1389
1394
|
isContainer;
|
|
1390
1395
|
getRenderDocument;
|
|
1396
|
+
disabledMultiSelect = false;
|
|
1397
|
+
config;
|
|
1391
1398
|
mouseMoveHandler = throttle(async (event) => {
|
|
1392
1399
|
if (event.target?.classList?.contains("moveable-direction")) {
|
|
1393
1400
|
return;
|
|
@@ -1402,38 +1409,21 @@ class ActionManager extends EventEmitter {
|
|
|
1402
1409
|
}, throttleTime);
|
|
1403
1410
|
constructor(config) {
|
|
1404
1411
|
super();
|
|
1412
|
+
this.config = config;
|
|
1405
1413
|
this.container = config.container;
|
|
1406
1414
|
this.containerHighlightClassName = config.containerHighlightClassName || CONTAINER_HIGHLIGHT_CLASS_NAME;
|
|
1407
1415
|
this.containerHighlightDuration = config.containerHighlightDuration || defaultContainerHighlightDuration;
|
|
1408
1416
|
this.containerHighlightType = config.containerHighlightType;
|
|
1417
|
+
this.disabledMultiSelect = config.disabledMultiSelect ?? false;
|
|
1409
1418
|
this.getTargetElement = config.getTargetElement;
|
|
1410
1419
|
this.getElementsFromPoint = config.getElementsFromPoint;
|
|
1411
1420
|
this.canSelect = config.canSelect || ((el) => !!el.id);
|
|
1412
1421
|
this.getRenderDocument = config.getRenderDocument;
|
|
1413
1422
|
this.isContainer = config.isContainer;
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
}
|
|
1418
|
-
this.dr = new StageDragResize({
|
|
1419
|
-
container: config.container,
|
|
1420
|
-
disabledDragStart: config.disabledDragStart,
|
|
1421
|
-
moveableOptions: this.changeCallback(config.moveableOptions, false),
|
|
1422
|
-
dragResizeHelper: createDrHelper(),
|
|
1423
|
-
getRootContainer: config.getRootContainer,
|
|
1424
|
-
getRenderDocument: config.getRenderDocument,
|
|
1425
|
-
markContainerEnd: this.markContainerEnd.bind(this),
|
|
1426
|
-
delayedMarkContainer: this.delayedMarkContainer.bind(this)
|
|
1427
|
-
});
|
|
1428
|
-
this.multiDr = new StageMultiDragResize({
|
|
1429
|
-
container: config.container,
|
|
1430
|
-
moveableOptions: this.changeCallback(config.moveableOptions, true),
|
|
1431
|
-
dragResizeHelper: createDrHelper(),
|
|
1432
|
-
getRootContainer: config.getRootContainer,
|
|
1433
|
-
getRenderDocument: config.getRenderDocument,
|
|
1434
|
-
markContainerEnd: this.markContainerEnd.bind(this),
|
|
1435
|
-
delayedMarkContainer: this.delayedMarkContainer.bind(this)
|
|
1436
|
-
});
|
|
1423
|
+
this.dr = this.createDr(config);
|
|
1424
|
+
if (!this.disabledMultiSelect) {
|
|
1425
|
+
this.multiDr = this.createMultiDr(config);
|
|
1426
|
+
}
|
|
1437
1427
|
this.highlightLayer = new StageHighlight({
|
|
1438
1428
|
container: config.container,
|
|
1439
1429
|
updateDragEl: config.updateDragEl,
|
|
@@ -1441,7 +1431,19 @@ class ActionManager extends EventEmitter {
|
|
|
1441
1431
|
});
|
|
1442
1432
|
this.initMouseEvent();
|
|
1443
1433
|
this.initKeyEvent();
|
|
1444
|
-
|
|
1434
|
+
}
|
|
1435
|
+
disableMultiSelect() {
|
|
1436
|
+
this.disabledMultiSelect = true;
|
|
1437
|
+
if (this.multiDr) {
|
|
1438
|
+
this.multiDr.destroy();
|
|
1439
|
+
this.multiDr = void 0;
|
|
1440
|
+
}
|
|
1441
|
+
}
|
|
1442
|
+
enableMultiSelect() {
|
|
1443
|
+
this.disabledMultiSelect = false;
|
|
1444
|
+
if (!this.multiDr) {
|
|
1445
|
+
this.multiDr = this.createMultiDr(this.config);
|
|
1446
|
+
}
|
|
1445
1447
|
}
|
|
1446
1448
|
/**
|
|
1447
1449
|
* 设置水平/垂直参考线
|
|
@@ -1450,14 +1452,14 @@ class ActionManager extends EventEmitter {
|
|
|
1450
1452
|
*/
|
|
1451
1453
|
setGuidelines(type, guidelines) {
|
|
1452
1454
|
this.dr.setGuidelines(type, guidelines);
|
|
1453
|
-
this.multiDr
|
|
1455
|
+
this.multiDr?.setGuidelines(type, guidelines);
|
|
1454
1456
|
}
|
|
1455
1457
|
/**
|
|
1456
1458
|
* 清空所有参考线
|
|
1457
1459
|
*/
|
|
1458
1460
|
clearGuides() {
|
|
1459
1461
|
this.dr.clearGuides();
|
|
1460
|
-
this.multiDr
|
|
1462
|
+
this.multiDr?.clearGuides();
|
|
1461
1463
|
}
|
|
1462
1464
|
/**
|
|
1463
1465
|
* 更新moveable,外部主要调用场景是元素配置变更、页面大小变更
|
|
@@ -1465,7 +1467,7 @@ class ActionManager extends EventEmitter {
|
|
|
1465
1467
|
*/
|
|
1466
1468
|
updateMoveable(el) {
|
|
1467
1469
|
this.dr.updateMoveable(el);
|
|
1468
|
-
this.multiDr
|
|
1470
|
+
this.multiDr?.updateMoveable();
|
|
1469
1471
|
}
|
|
1470
1472
|
/**
|
|
1471
1473
|
* 判断是否单选选中的元素
|
|
@@ -1486,7 +1488,7 @@ class ActionManager extends EventEmitter {
|
|
|
1486
1488
|
if (this.dr.getTarget()) {
|
|
1487
1489
|
return this.dr.getOption(key);
|
|
1488
1490
|
}
|
|
1489
|
-
if (this.multiDr
|
|
1491
|
+
if (this.multiDr?.targetList.length) {
|
|
1490
1492
|
return this.multiDr.getOption(key);
|
|
1491
1493
|
}
|
|
1492
1494
|
}
|
|
@@ -1536,17 +1538,17 @@ class ActionManager extends EventEmitter {
|
|
|
1536
1538
|
if (selectedEl?.className.includes(PAGE_CLASS)) {
|
|
1537
1539
|
return true;
|
|
1538
1540
|
}
|
|
1539
|
-
return this.multiDr
|
|
1541
|
+
return this.multiDr?.canSelect(el, selectedEl) || false;
|
|
1540
1542
|
}
|
|
1541
1543
|
select(el, event) {
|
|
1542
|
-
this.
|
|
1544
|
+
this.setSelectedEl(el);
|
|
1543
1545
|
this.clearSelectStatus(SelectStatus.MULTI_SELECT);
|
|
1544
1546
|
this.dr.select(el, event);
|
|
1545
1547
|
}
|
|
1546
1548
|
multiSelect(idOrElList) {
|
|
1547
1549
|
this.selectedElList = idOrElList.map((idOrEl) => this.getTargetElement(idOrEl));
|
|
1548
1550
|
this.clearSelectStatus(SelectStatus.SELECT);
|
|
1549
|
-
this.multiDr
|
|
1551
|
+
this.multiDr?.multiSelect(this.selectedElList);
|
|
1550
1552
|
}
|
|
1551
1553
|
getHighlightEl() {
|
|
1552
1554
|
return this.highlightedEl;
|
|
@@ -1562,7 +1564,7 @@ class ActionManager extends EventEmitter {
|
|
|
1562
1564
|
this.clearHighlight();
|
|
1563
1565
|
return;
|
|
1564
1566
|
}
|
|
1565
|
-
if (el === this.getSelectedEl() || this.multiDr
|
|
1567
|
+
if (el === this.getSelectedEl() || this.multiDr?.dragStatus === StageDragStatus.ING) {
|
|
1566
1568
|
this.clearHighlight();
|
|
1567
1569
|
return;
|
|
1568
1570
|
}
|
|
@@ -1582,7 +1584,7 @@ class ActionManager extends EventEmitter {
|
|
|
1582
1584
|
*/
|
|
1583
1585
|
clearSelectStatus(selectType) {
|
|
1584
1586
|
if (selectType === SelectStatus.MULTI_SELECT) {
|
|
1585
|
-
this.multiDr
|
|
1587
|
+
this.multiDr?.clearSelectStatus();
|
|
1586
1588
|
this.selectedElList = [];
|
|
1587
1589
|
} else {
|
|
1588
1590
|
this.dr.clearSelectStatus();
|
|
@@ -1629,9 +1631,67 @@ class ActionManager extends EventEmitter {
|
|
|
1629
1631
|
this.container.removeEventListener("mouseleave", this.mouseLeaveHandler);
|
|
1630
1632
|
this.container.removeEventListener("wheel", this.mouseWheelHandler);
|
|
1631
1633
|
this.dr.destroy();
|
|
1632
|
-
this.multiDr
|
|
1634
|
+
this.multiDr?.destroy();
|
|
1633
1635
|
this.highlightLayer.destroy();
|
|
1634
1636
|
}
|
|
1637
|
+
createDr(config) {
|
|
1638
|
+
const createDrHelper = () => new DragResizeHelper({
|
|
1639
|
+
container: config.container,
|
|
1640
|
+
updateDragEl: config.updateDragEl
|
|
1641
|
+
});
|
|
1642
|
+
const dr = new StageDragResize({
|
|
1643
|
+
container: config.container,
|
|
1644
|
+
disabledDragStart: config.disabledDragStart,
|
|
1645
|
+
moveableOptions: this.changeCallback(config.moveableOptions, false),
|
|
1646
|
+
dragResizeHelper: createDrHelper(),
|
|
1647
|
+
getRootContainer: config.getRootContainer,
|
|
1648
|
+
getRenderDocument: config.getRenderDocument,
|
|
1649
|
+
markContainerEnd: this.markContainerEnd.bind(this),
|
|
1650
|
+
delayedMarkContainer: this.delayedMarkContainer.bind(this)
|
|
1651
|
+
});
|
|
1652
|
+
dr.on("update", (data) => {
|
|
1653
|
+
setTimeout(() => this.emit("update", data));
|
|
1654
|
+
}).on("sort", (data) => {
|
|
1655
|
+
setTimeout(() => this.emit("sort", data));
|
|
1656
|
+
}).on("select-parent", () => {
|
|
1657
|
+
this.emit("select-parent");
|
|
1658
|
+
}).on("remove", () => {
|
|
1659
|
+
const drTarget = this.dr.getTarget();
|
|
1660
|
+
if (!drTarget)
|
|
1661
|
+
return;
|
|
1662
|
+
const data = {
|
|
1663
|
+
data: [{ el: drTarget }]
|
|
1664
|
+
};
|
|
1665
|
+
this.emit("remove", data);
|
|
1666
|
+
}).on("drag-start", (e) => {
|
|
1667
|
+
this.emit("drag-start", e);
|
|
1668
|
+
});
|
|
1669
|
+
return dr;
|
|
1670
|
+
}
|
|
1671
|
+
createMultiDr(config) {
|
|
1672
|
+
const createDrHelper = () => new DragResizeHelper({
|
|
1673
|
+
container: config.container,
|
|
1674
|
+
updateDragEl: config.updateDragEl
|
|
1675
|
+
});
|
|
1676
|
+
const multiDr = new StageMultiDragResize({
|
|
1677
|
+
container: config.container,
|
|
1678
|
+
moveableOptions: this.changeCallback(config.moveableOptions, true),
|
|
1679
|
+
dragResizeHelper: createDrHelper(),
|
|
1680
|
+
getRootContainer: config.getRootContainer,
|
|
1681
|
+
getRenderDocument: config.getRenderDocument,
|
|
1682
|
+
markContainerEnd: this.markContainerEnd.bind(this),
|
|
1683
|
+
delayedMarkContainer: this.delayedMarkContainer.bind(this)
|
|
1684
|
+
});
|
|
1685
|
+
multiDr?.on("update", (data) => {
|
|
1686
|
+
this.emit("multi-update", data);
|
|
1687
|
+
}).on("change-to-select", async (id) => {
|
|
1688
|
+
if (this.isMultiSelectStatus)
|
|
1689
|
+
return false;
|
|
1690
|
+
const el = this.getTargetElement(id);
|
|
1691
|
+
this.emit("change-to-select", el);
|
|
1692
|
+
});
|
|
1693
|
+
return multiDr;
|
|
1694
|
+
}
|
|
1635
1695
|
changeCallback(options, isMulti) {
|
|
1636
1696
|
if (typeof options === "function") {
|
|
1637
1697
|
return () => {
|
|
@@ -1662,7 +1722,7 @@ class ActionManager extends EventEmitter {
|
|
|
1662
1722
|
return;
|
|
1663
1723
|
if (this.selectedEl && !this.selectedEl.className.includes(PAGE_CLASS)) {
|
|
1664
1724
|
this.selectedElList.push(this.selectedEl);
|
|
1665
|
-
this.
|
|
1725
|
+
this.setSelectedEl(void 0);
|
|
1666
1726
|
}
|
|
1667
1727
|
const existIndex = this.selectedElList.findIndex((selectedDom) => selectedDom.id === el.id);
|
|
1668
1728
|
if (existIndex !== -1) {
|
|
@@ -1702,14 +1762,20 @@ class ActionManager extends EventEmitter {
|
|
|
1702
1762
|
const ctrl = isMac ? "meta" : "ctrl";
|
|
1703
1763
|
KeyController.global.keydown(ctrl, (e) => {
|
|
1704
1764
|
e.inputEvent.preventDefault();
|
|
1705
|
-
this.
|
|
1765
|
+
if (!this.disabledMultiSelect) {
|
|
1766
|
+
this.isMultiSelectStatus = true;
|
|
1767
|
+
}
|
|
1706
1768
|
});
|
|
1707
1769
|
KeyController.global.on("blur", () => {
|
|
1708
|
-
this.
|
|
1770
|
+
if (!this.disabledMultiSelect) {
|
|
1771
|
+
this.isMultiSelectStatus = false;
|
|
1772
|
+
}
|
|
1709
1773
|
});
|
|
1710
1774
|
KeyController.global.keyup(ctrl, (e) => {
|
|
1711
1775
|
e.inputEvent.preventDefault();
|
|
1712
|
-
this.
|
|
1776
|
+
if (!this.disabledMultiSelect) {
|
|
1777
|
+
this.isMultiSelectStatus = false;
|
|
1778
|
+
}
|
|
1713
1779
|
});
|
|
1714
1780
|
KeyController.global.keydown("alt", (e) => {
|
|
1715
1781
|
e.inputEvent.preventDefault();
|
|
@@ -1721,36 +1787,6 @@ class ActionManager extends EventEmitter {
|
|
|
1721
1787
|
this.isAltKeydown = false;
|
|
1722
1788
|
});
|
|
1723
1789
|
}
|
|
1724
|
-
/**
|
|
1725
|
-
* 处理单选、多选抛出来的事件
|
|
1726
|
-
*/
|
|
1727
|
-
initActionEvent() {
|
|
1728
|
-
this.dr.on("update", (data) => {
|
|
1729
|
-
setTimeout(() => this.emit("update", data));
|
|
1730
|
-
}).on("sort", (data) => {
|
|
1731
|
-
setTimeout(() => this.emit("sort", data));
|
|
1732
|
-
}).on("select-parent", () => {
|
|
1733
|
-
this.emit("select-parent");
|
|
1734
|
-
}).on("remove", () => {
|
|
1735
|
-
const drTarget = this.dr.getTarget();
|
|
1736
|
-
if (!drTarget)
|
|
1737
|
-
return;
|
|
1738
|
-
const data = {
|
|
1739
|
-
data: [{ el: drTarget }]
|
|
1740
|
-
};
|
|
1741
|
-
this.emit("remove", data);
|
|
1742
|
-
}).on("drag-start", (e) => {
|
|
1743
|
-
this.emit("drag-start", e);
|
|
1744
|
-
});
|
|
1745
|
-
this.multiDr.on("update", (data) => {
|
|
1746
|
-
this.emit("multi-update", data);
|
|
1747
|
-
}).on("change-to-select", async (id) => {
|
|
1748
|
-
if (this.isMultiSelectStatus)
|
|
1749
|
-
return false;
|
|
1750
|
-
const el = this.getTargetElement(id);
|
|
1751
|
-
this.emit("change-to-select", el);
|
|
1752
|
-
});
|
|
1753
|
-
}
|
|
1754
1790
|
/**
|
|
1755
1791
|
* 在down事件中集中cpu处理画布中选中操作渲染,在up事件中再通知外面的编辑器更新
|
|
1756
1792
|
*/
|
|
@@ -1791,13 +1827,13 @@ class ActionManager extends EventEmitter {
|
|
|
1791
1827
|
/**
|
|
1792
1828
|
* 在up事件中负责对外通知选中事件,通知画布之外的编辑器更新
|
|
1793
1829
|
*/
|
|
1794
|
-
mouseUpHandler = () => {
|
|
1830
|
+
mouseUpHandler = (event) => {
|
|
1795
1831
|
getDocument().removeEventListener("mouseup", this.mouseUpHandler);
|
|
1796
1832
|
this.container.addEventListener("mousemove", this.mouseMoveHandler);
|
|
1797
1833
|
if (this.isMultiSelectStatus) {
|
|
1798
|
-
this.emit("multi-select", this.selectedElList);
|
|
1834
|
+
this.emit("multi-select", this.selectedElList, event);
|
|
1799
1835
|
} else {
|
|
1800
|
-
this.emit("select", this.selectedEl);
|
|
1836
|
+
this.emit("select", this.selectedEl, event);
|
|
1801
1837
|
}
|
|
1802
1838
|
};
|
|
1803
1839
|
mouseLeaveHandler = (event) => {
|
|
@@ -1817,8 +1853,10 @@ class Rule extends EventEmitter {
|
|
|
1817
1853
|
container;
|
|
1818
1854
|
containerResizeObserver;
|
|
1819
1855
|
isShowGuides = true;
|
|
1820
|
-
|
|
1856
|
+
guidesOptions;
|
|
1857
|
+
constructor(container, options) {
|
|
1821
1858
|
super();
|
|
1859
|
+
this.guidesOptions = options?.guidesOptions || {};
|
|
1822
1860
|
this.container = container;
|
|
1823
1861
|
this.hGuides = this.createGuides(GuidesType.HORIZONTAL, this.horizontalGuidelines);
|
|
1824
1862
|
this.vGuides = this.createGuides(GuidesType.VERTICAL, this.verticalGuidelines);
|
|
@@ -1917,7 +1955,8 @@ class Rule extends EventEmitter {
|
|
|
1917
1955
|
lineColor: "#000",
|
|
1918
1956
|
textColor: "#000",
|
|
1919
1957
|
style: this.getGuidesStyle(type),
|
|
1920
|
-
showGuides: this.isShowGuides
|
|
1958
|
+
showGuides: this.isShowGuides,
|
|
1959
|
+
...this.guidesOptions
|
|
1921
1960
|
});
|
|
1922
1961
|
const changEventHandler = {
|
|
1923
1962
|
[GuidesType.HORIZONTAL]: this.hGuidesChangeGuidesHandler,
|
|
@@ -1989,9 +2028,9 @@ class StageMask extends Rule {
|
|
|
1989
2028
|
pageScrollParent = null;
|
|
1990
2029
|
intersectionObserver = null;
|
|
1991
2030
|
wrapperResizeObserver = null;
|
|
1992
|
-
constructor() {
|
|
2031
|
+
constructor(options) {
|
|
1993
2032
|
const wrapper = createWrapper();
|
|
1994
|
-
super(wrapper);
|
|
2033
|
+
super(wrapper, options);
|
|
1995
2034
|
this.wrapper = wrapper;
|
|
1996
2035
|
this.content.addEventListener("wheel", this.mouseWheelHandler);
|
|
1997
2036
|
this.wrapper.appendChild(this.content);
|
|
@@ -2206,22 +2245,22 @@ class StageRender extends EventEmitter$1 {
|
|
|
2206
2245
|
contentWindow = null;
|
|
2207
2246
|
runtime = null;
|
|
2208
2247
|
iframe;
|
|
2248
|
+
nativeContainer;
|
|
2209
2249
|
runtimeUrl;
|
|
2210
2250
|
zoom = DEFAULT_ZOOM;
|
|
2251
|
+
renderType;
|
|
2211
2252
|
customizedRender;
|
|
2212
|
-
constructor({ runtimeUrl, zoom, customizedRender }) {
|
|
2253
|
+
constructor({ runtimeUrl, zoom, customizedRender, renderType = RenderType.IFRAME }) {
|
|
2213
2254
|
super();
|
|
2255
|
+
this.renderType = renderType;
|
|
2214
2256
|
this.runtimeUrl = runtimeUrl || "";
|
|
2215
2257
|
this.customizedRender = customizedRender;
|
|
2216
2258
|
this.setZoom(zoom);
|
|
2217
|
-
this.
|
|
2218
|
-
|
|
2219
|
-
this.
|
|
2220
|
-
|
|
2221
|
-
|
|
2222
|
-
height: 100%;
|
|
2223
|
-
`;
|
|
2224
|
-
this.iframe.addEventListener("load", this.loadHandler);
|
|
2259
|
+
if (this.renderType === RenderType.IFRAME) {
|
|
2260
|
+
this.createIframe();
|
|
2261
|
+
} else if (this.renderType === RenderType.NATIVE) {
|
|
2262
|
+
this.createNativeContainer();
|
|
2263
|
+
}
|
|
2225
2264
|
}
|
|
2226
2265
|
getMagicApi = () => ({
|
|
2227
2266
|
onPageElUpdate: (el) => this.emit("page-el-update", el),
|
|
@@ -2261,18 +2300,19 @@ class StageRender extends EventEmitter$1 {
|
|
|
2261
2300
|
* @param el 将页面挂载到该Dom节点上
|
|
2262
2301
|
*/
|
|
2263
2302
|
async mount(el) {
|
|
2264
|
-
if (
|
|
2265
|
-
|
|
2266
|
-
|
|
2267
|
-
|
|
2268
|
-
|
|
2269
|
-
const base = `${location.protocol}//${getHost(this.runtimeUrl)}`;
|
|
2270
|
-
html = html.replace("<head>", `<head>
|
|
2303
|
+
if (this.iframe) {
|
|
2304
|
+
if (!isSameDomain(this.runtimeUrl) && this.runtimeUrl) {
|
|
2305
|
+
let html = await fetch(this.runtimeUrl).then((res) => res.text());
|
|
2306
|
+
const base = `${location.protocol}//${getHost(this.runtimeUrl)}`;
|
|
2307
|
+
html = html.replace("<head>", `<head>
|
|
2271
2308
|
<base href="${base}">`);
|
|
2272
|
-
|
|
2309
|
+
this.iframe.srcdoc = html;
|
|
2310
|
+
}
|
|
2311
|
+
el.appendChild(this.iframe);
|
|
2312
|
+
this.postTmagicRuntimeReady();
|
|
2313
|
+
} else if (this.nativeContainer) {
|
|
2314
|
+
el.appendChild(this.nativeContainer);
|
|
2273
2315
|
}
|
|
2274
|
-
el.appendChild(this.iframe);
|
|
2275
|
-
this.postTmagicRuntimeReady();
|
|
2276
2316
|
}
|
|
2277
2317
|
getRuntime = () => {
|
|
2278
2318
|
if (this.runtime)
|
|
@@ -2318,12 +2358,34 @@ class StageRender extends EventEmitter$1 {
|
|
|
2318
2358
|
* 销毁实例
|
|
2319
2359
|
*/
|
|
2320
2360
|
destroy() {
|
|
2321
|
-
this.iframe?.removeEventListener("load", this.
|
|
2361
|
+
this.iframe?.removeEventListener("load", this.iframeLoadHandler);
|
|
2322
2362
|
this.contentWindow = null;
|
|
2323
2363
|
this.iframe?.remove();
|
|
2324
2364
|
this.iframe = void 0;
|
|
2325
2365
|
this.removeAllListeners();
|
|
2326
2366
|
}
|
|
2367
|
+
createIframe() {
|
|
2368
|
+
this.iframe = globalThis.document.createElement("iframe");
|
|
2369
|
+
this.iframe.src = this.runtimeUrl && isSameDomain(this.runtimeUrl) ? this.runtimeUrl : "";
|
|
2370
|
+
this.iframe.style.cssText = `
|
|
2371
|
+
border: 0;
|
|
2372
|
+
width: 100%;
|
|
2373
|
+
height: 100%;
|
|
2374
|
+
`;
|
|
2375
|
+
this.iframe.addEventListener("load", this.iframeLoadHandler);
|
|
2376
|
+
return this.iframe;
|
|
2377
|
+
}
|
|
2378
|
+
async createNativeContainer() {
|
|
2379
|
+
this.contentWindow = globalThis;
|
|
2380
|
+
this.nativeContainer = globalThis.document.createElement("div");
|
|
2381
|
+
this.contentWindow.magic = this.getMagicApi();
|
|
2382
|
+
if (this.customizedRender) {
|
|
2383
|
+
const el = await this.customizedRender();
|
|
2384
|
+
if (el) {
|
|
2385
|
+
this.nativeContainer.appendChild(el);
|
|
2386
|
+
}
|
|
2387
|
+
}
|
|
2388
|
+
}
|
|
2327
2389
|
/**
|
|
2328
2390
|
* 在runtime中对被选中的元素进行标记,部分组件有对选中态进行特殊显示的需求
|
|
2329
2391
|
* @param el 被选中的元素
|
|
@@ -2335,7 +2397,7 @@ class StageRender extends EventEmitter$1 {
|
|
|
2335
2397
|
addSelectedClassName(el, doc);
|
|
2336
2398
|
}
|
|
2337
2399
|
}
|
|
2338
|
-
|
|
2400
|
+
iframeLoadHandler = async () => {
|
|
2339
2401
|
if (!this.contentWindow?.magic) {
|
|
2340
2402
|
this.postTmagicRuntimeReady();
|
|
2341
2403
|
}
|
|
@@ -2377,6 +2439,7 @@ class StageCore extends EventEmitter$1 {
|
|
|
2377
2439
|
this.renderer = new StageRender({
|
|
2378
2440
|
runtimeUrl: config.runtimeUrl,
|
|
2379
2441
|
zoom: config.zoom,
|
|
2442
|
+
renderType: config.renderType,
|
|
2380
2443
|
customizedRender: async () => {
|
|
2381
2444
|
if (this?.customizedRender) {
|
|
2382
2445
|
return await this.customizedRender(this);
|
|
@@ -2384,7 +2447,9 @@ class StageCore extends EventEmitter$1 {
|
|
|
2384
2447
|
return null;
|
|
2385
2448
|
}
|
|
2386
2449
|
});
|
|
2387
|
-
this.mask = new StageMask(
|
|
2450
|
+
this.mask = new StageMask({
|
|
2451
|
+
guidesOptions: config.guidesOptions
|
|
2452
|
+
});
|
|
2388
2453
|
this.actionManager = new ActionManager(this.getActionManagerConfig(config));
|
|
2389
2454
|
this.initRenderEvent();
|
|
2390
2455
|
this.initActionEvent();
|
|
@@ -2505,6 +2570,12 @@ class StageCore extends EventEmitter$1 {
|
|
|
2505
2570
|
getDragStatus() {
|
|
2506
2571
|
return this.actionManager.getDragStatus();
|
|
2507
2572
|
}
|
|
2573
|
+
disableMultiSelect() {
|
|
2574
|
+
this.actionManager.disableMultiSelect();
|
|
2575
|
+
}
|
|
2576
|
+
enableMultiSelect() {
|
|
2577
|
+
this.actionManager.enableMultiSelect();
|
|
2578
|
+
}
|
|
2508
2579
|
/**
|
|
2509
2580
|
* 销毁实例
|
|
2510
2581
|
*/
|
|
@@ -2537,6 +2608,7 @@ class StageCore extends EventEmitter$1 {
|
|
|
2537
2608
|
moveableOptions: config.moveableOptions,
|
|
2538
2609
|
container: this.mask.content,
|
|
2539
2610
|
disabledDragStart: config.disabledDragStart,
|
|
2611
|
+
disabledMultiSelect: config.disabledMultiSelect,
|
|
2540
2612
|
canSelect: config.canSelect,
|
|
2541
2613
|
isContainer: config.isContainer,
|
|
2542
2614
|
updateDragEl: config.updateDragEl,
|
|
@@ -2554,6 +2626,7 @@ class StageCore extends EventEmitter$1 {
|
|
|
2554
2626
|
this.renderer.on("page-el-update", (el) => {
|
|
2555
2627
|
this.mask?.observe(el);
|
|
2556
2628
|
this.observePageResize(el);
|
|
2629
|
+
this.emit("page-el-update", el);
|
|
2557
2630
|
});
|
|
2558
2631
|
}
|
|
2559
2632
|
initMaskEvent() {
|
|
@@ -2578,12 +2651,12 @@ class StageCore extends EventEmitter$1 {
|
|
|
2578
2651
|
initActionManagerEvent() {
|
|
2579
2652
|
this.actionManager.on("before-select", (idOrEl, event) => {
|
|
2580
2653
|
this.select(idOrEl, event);
|
|
2581
|
-
}).on("select", (selectedEl) => {
|
|
2582
|
-
this.emit("select", selectedEl);
|
|
2654
|
+
}).on("select", (selectedEl, event) => {
|
|
2655
|
+
this.emit("select", selectedEl, event);
|
|
2583
2656
|
}).on("before-multi-select", (idOrElList) => {
|
|
2584
2657
|
this.multiSelect(idOrElList);
|
|
2585
|
-
}).on("multi-select", (selectedElList) => {
|
|
2586
|
-
this.emit("multi-select", selectedElList);
|
|
2658
|
+
}).on("multi-select", (selectedElList, event) => {
|
|
2659
|
+
this.emit("multi-select", selectedElList, event);
|
|
2587
2660
|
});
|
|
2588
2661
|
}
|
|
2589
2662
|
/**
|
|
@@ -2633,5 +2706,5 @@ class StageCore extends EventEmitter$1 {
|
|
|
2633
2706
|
}
|
|
2634
2707
|
}
|
|
2635
2708
|
|
|
2636
|
-
export { AbleActionEventType, CONTAINER_HIGHLIGHT_CLASS_NAME, ContainerHighlightType, DEFAULT_ZOOM, DRAG_EL_ID_PREFIX, GHOST_EL_ID_PREFIX, GuidesType, HIGHLIGHT_EL_ID_PREFIX, Mode, MouseButton, PAGE_CLASS, SELECTED_CLASS, SelectStatus, StageDragResize, StageDragStatus, StageMask, StageRender, ZIndex, addSelectedClassName, calcValueByFontsize, StageCore as default, down, getAbsolutePosition, getMarginValue, getMode, getOffset, getScrollParent, getTargetElStyle, isAbsolute, isFixed, isFixedParent, isMoveableButton, isRelative, isStatic, removeSelectedClassName, up };
|
|
2709
|
+
export { AbleActionEventType, CONTAINER_HIGHLIGHT_CLASS_NAME, ContainerHighlightType, DEFAULT_ZOOM, DRAG_EL_ID_PREFIX, GHOST_EL_ID_PREFIX, GuidesType, HIGHLIGHT_EL_ID_PREFIX, Mode, MouseButton, PAGE_CLASS, RenderType, SELECTED_CLASS, SelectStatus, StageDragResize, StageDragStatus, StageMask, StageRender, ZIndex, addSelectedClassName, calcValueByFontsize, StageCore as default, down, getAbsolutePosition, getMarginValue, getMode, getOffset, getScrollParent, getTargetElStyle, isAbsolute, isFixed, isFixedParent, isMoveableButton, isRelative, isStatic, removeSelectedClassName, up };
|
|
2637
2710
|
//# sourceMappingURL=tmagic-stage.js.map
|