@tmagic/stage 1.1.6 → 1.2.0-beta.10
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-stage.mjs +219 -95
- package/dist/tmagic-stage.mjs.map +1 -1
- package/dist/tmagic-stage.umd.js +219 -94
- package/dist/tmagic-stage.umd.js.map +1 -1
- package/package.json +4 -4
- package/src/MoveableSelectParentAble.ts +78 -0
- package/src/Rule.ts +9 -5
- package/src/StageCore.ts +48 -15
- package/src/StageDragResize.ts +25 -9
- package/src/StageMask.ts +112 -77
- package/src/StageRender.ts +9 -9
- package/src/types.ts +3 -2
- package/src/util.ts +6 -0
- package/types/MoveableSelectParentAble.d.ts +9 -0
- package/types/Rule.d.ts +4 -3
- package/types/StageCore.d.ts +9 -0
- package/types/StageMask.d.ts +31 -9
- package/types/StageRender.d.ts +2 -3
- package/types/types.d.ts +3 -2
- package/types/util.d.ts +1 -0
package/dist/tmagic-stage.mjs
CHANGED
|
@@ -39,6 +39,77 @@ var Mode = /* @__PURE__ */ ((Mode2) => {
|
|
|
39
39
|
})(Mode || {});
|
|
40
40
|
const SELECTED_CLASS = "tmagic-stage-selected-area";
|
|
41
41
|
|
|
42
|
+
const selectParentAbles = (dr) => ({
|
|
43
|
+
name: "selectParent",
|
|
44
|
+
props: {},
|
|
45
|
+
events: {},
|
|
46
|
+
render(moveable, React) {
|
|
47
|
+
const rect = moveable.getRect();
|
|
48
|
+
const { pos2 } = moveable.state;
|
|
49
|
+
const editableViewer = moveable.useCSS(
|
|
50
|
+
"div",
|
|
51
|
+
`
|
|
52
|
+
{
|
|
53
|
+
position: absolute;
|
|
54
|
+
left: 0px;
|
|
55
|
+
top: 0px;
|
|
56
|
+
will-change: transform;
|
|
57
|
+
transform-origin: 0px 0px;
|
|
58
|
+
display: flex;
|
|
59
|
+
}
|
|
60
|
+
.moveable-button {
|
|
61
|
+
width: 20px;
|
|
62
|
+
height: 20px;
|
|
63
|
+
background: #4af;
|
|
64
|
+
border-radius: 4px;
|
|
65
|
+
appearance: none;
|
|
66
|
+
border: 0;
|
|
67
|
+
color: white;
|
|
68
|
+
font-size: 12px;
|
|
69
|
+
font-weight: bold;
|
|
70
|
+
}
|
|
71
|
+
`
|
|
72
|
+
);
|
|
73
|
+
return React.createElement(
|
|
74
|
+
editableViewer,
|
|
75
|
+
{
|
|
76
|
+
className: "moveable-editable",
|
|
77
|
+
style: {
|
|
78
|
+
transform: `translate(${pos2[0] - 25}px, ${pos2[1] - 30}px) rotate(${rect.rotation}deg) translate(10px)`
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
React.createElement(
|
|
82
|
+
"button",
|
|
83
|
+
{
|
|
84
|
+
className: "moveable-button",
|
|
85
|
+
title: "\u9009\u4E2D\u7236\u7EC4\u4EF6",
|
|
86
|
+
onClick: () => {
|
|
87
|
+
dr.emit("select-parent");
|
|
88
|
+
}
|
|
89
|
+
},
|
|
90
|
+
React.createElement(
|
|
91
|
+
"svg",
|
|
92
|
+
{
|
|
93
|
+
width: "1em",
|
|
94
|
+
height: "1em",
|
|
95
|
+
viewBox: "0 0 16 16",
|
|
96
|
+
fill: "none",
|
|
97
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
98
|
+
style: {
|
|
99
|
+
transform: "rotate(90deg)"
|
|
100
|
+
}
|
|
101
|
+
},
|
|
102
|
+
React.createElement("path", {
|
|
103
|
+
d: "M13.0001 4V10H4.20718L5.85363 8.35355L5.14652 7.64645L2.64652 10.1464C2.45126 10.3417 2.45126 10.6583 2.64652 10.8536L5.14652 13.3536L5.85363 12.6464L4.20718 11H13.0001C13.5524 11 14.0001 10.5523 14.0001 10V4H13.0001Z",
|
|
104
|
+
fill: "currentColor",
|
|
105
|
+
fillOpacity: "0.9"
|
|
106
|
+
})
|
|
107
|
+
)
|
|
108
|
+
)
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
|
|
42
113
|
var ContainerHighlightType = /* @__PURE__ */ ((ContainerHighlightType2) => {
|
|
43
114
|
ContainerHighlightType2["DEFAULT"] = "default";
|
|
44
115
|
ContainerHighlightType2["ALT"] = "alt";
|
|
@@ -135,6 +206,8 @@ const getScrollParent = (element, includeHidden = false) => {
|
|
|
135
206
|
return null;
|
|
136
207
|
for (let parent = element; parent.parentElement; ) {
|
|
137
208
|
parent = parent.parentElement;
|
|
209
|
+
if (parent.tagName === "HTML")
|
|
210
|
+
return parent;
|
|
138
211
|
style = getComputedStyle(parent);
|
|
139
212
|
if (isAbsolute(style) && isStatic(style))
|
|
140
213
|
continue;
|
|
@@ -219,6 +292,7 @@ const up = (deltaTop, target) => {
|
|
|
219
292
|
dist: upEls.length && swapIndex > -1 ? upEls[swapIndex].id : target.id
|
|
220
293
|
};
|
|
221
294
|
};
|
|
295
|
+
const isMoveableButton = (target) => target.classList.contains("moveable-button") || target.parentElement?.classList.contains("moveable-button");
|
|
222
296
|
|
|
223
297
|
class StageDragResize extends EventEmitter {
|
|
224
298
|
core;
|
|
@@ -493,10 +567,14 @@ class StageDragResize extends EventEmitter {
|
|
|
493
567
|
this.dragStatus = StageDragStatus.END;
|
|
494
568
|
const frame = this.moveableHelper?.getFrame(e.target);
|
|
495
569
|
this.emit("update", {
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
570
|
+
data: [
|
|
571
|
+
{
|
|
572
|
+
el: this.target,
|
|
573
|
+
style: {
|
|
574
|
+
transform: frame?.get("transform")
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
]
|
|
500
578
|
});
|
|
501
579
|
});
|
|
502
580
|
}
|
|
@@ -517,10 +595,14 @@ class StageDragResize extends EventEmitter {
|
|
|
517
595
|
this.dragStatus = StageDragStatus.END;
|
|
518
596
|
const frame = this.moveableHelper?.getFrame(e.target);
|
|
519
597
|
this.emit("update", {
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
598
|
+
data: [
|
|
599
|
+
{
|
|
600
|
+
el: this.target,
|
|
601
|
+
style: {
|
|
602
|
+
transform: frame?.get("transform")
|
|
603
|
+
}
|
|
604
|
+
}
|
|
605
|
+
]
|
|
524
606
|
});
|
|
525
607
|
});
|
|
526
608
|
}
|
|
@@ -625,7 +707,7 @@ class StageDragResize extends EventEmitter {
|
|
|
625
707
|
resizable: true,
|
|
626
708
|
scalable: false,
|
|
627
709
|
rotatable: false,
|
|
628
|
-
snappable:
|
|
710
|
+
snappable: true,
|
|
629
711
|
snapGap: isAbsolute || isFixed,
|
|
630
712
|
snapThreshold: 5,
|
|
631
713
|
snapDigit: 0,
|
|
@@ -656,6 +738,10 @@ class StageDragResize extends EventEmitter {
|
|
|
656
738
|
bottom: isSortable ? void 0 : this.container.clientHeight,
|
|
657
739
|
...moveableOptions.bounds || {}
|
|
658
740
|
},
|
|
741
|
+
props: {
|
|
742
|
+
selectParent: true
|
|
743
|
+
},
|
|
744
|
+
ables: [selectParentAbles(this)],
|
|
659
745
|
...options,
|
|
660
746
|
...moveableOptions
|
|
661
747
|
};
|
|
@@ -786,6 +872,7 @@ class Rule extends EventEmitter$1 {
|
|
|
786
872
|
verticalGuidelines = [];
|
|
787
873
|
container;
|
|
788
874
|
containerResizeObserver;
|
|
875
|
+
isShowGuides = true;
|
|
789
876
|
constructor(container) {
|
|
790
877
|
super();
|
|
791
878
|
this.container = container;
|
|
@@ -799,12 +886,13 @@ class Rule extends EventEmitter$1 {
|
|
|
799
886
|
});
|
|
800
887
|
this.containerResizeObserver.observe(this.container);
|
|
801
888
|
}
|
|
802
|
-
showGuides(
|
|
889
|
+
showGuides(isShowGuides = true) {
|
|
890
|
+
this.isShowGuides = isShowGuides;
|
|
803
891
|
this.hGuides.setState({
|
|
804
|
-
showGuides:
|
|
892
|
+
showGuides: isShowGuides
|
|
805
893
|
});
|
|
806
894
|
this.vGuides.setState({
|
|
807
|
-
showGuides:
|
|
895
|
+
showGuides: isShowGuides
|
|
808
896
|
});
|
|
809
897
|
}
|
|
810
898
|
setGuides([hLines, vLines]) {
|
|
@@ -874,7 +962,8 @@ class Rule extends EventEmitter$1 {
|
|
|
874
962
|
backgroundColor: "#fff",
|
|
875
963
|
lineColor: "#000",
|
|
876
964
|
textColor: "#000",
|
|
877
|
-
style: this.getGuidesStyle(type)
|
|
965
|
+
style: this.getGuidesStyle(type),
|
|
966
|
+
showGuides: this.isShowGuides
|
|
878
967
|
});
|
|
879
968
|
hGuidesChangeGuidesHandler = (e) => {
|
|
880
969
|
this.horizontalGuidelines = e.guides;
|
|
@@ -925,9 +1014,7 @@ const createWrapper = () => {
|
|
|
925
1014
|
class StageMask extends Rule {
|
|
926
1015
|
content = createContent();
|
|
927
1016
|
wrapper;
|
|
928
|
-
core;
|
|
929
1017
|
page = null;
|
|
930
|
-
pageScrollParent = null;
|
|
931
1018
|
scrollTop = 0;
|
|
932
1019
|
scrollLeft = 0;
|
|
933
1020
|
width = 0;
|
|
@@ -936,34 +1023,21 @@ class StageMask extends Rule {
|
|
|
936
1023
|
wrapperWidth = 0;
|
|
937
1024
|
maxScrollTop = 0;
|
|
938
1025
|
maxScrollLeft = 0;
|
|
939
|
-
intersectionObserver = null;
|
|
940
1026
|
isMultiSelectStatus = false;
|
|
941
1027
|
mode = Mode.ABSOLUTE;
|
|
942
|
-
|
|
1028
|
+
pageScrollParent = null;
|
|
1029
|
+
intersectionObserver = null;
|
|
943
1030
|
wrapperResizeObserver = null;
|
|
944
1031
|
highlightHandler = throttle((event) => {
|
|
945
1032
|
this.emit("highlight", event);
|
|
946
1033
|
}, throttleTime);
|
|
947
|
-
constructor(
|
|
1034
|
+
constructor() {
|
|
948
1035
|
const wrapper = createWrapper();
|
|
949
1036
|
super(wrapper);
|
|
950
1037
|
this.wrapper = wrapper;
|
|
951
|
-
this.
|
|
952
|
-
this.content.addEventListener("mousedown", this.mouseDownHandler);
|
|
1038
|
+
this.initContentEventListener();
|
|
953
1039
|
this.wrapper.appendChild(this.content);
|
|
954
|
-
this.
|
|
955
|
-
this.content.addEventListener("mousemove", this.highlightHandler);
|
|
956
|
-
this.content.addEventListener("mouseleave", this.mouseLeaveHandler);
|
|
957
|
-
const isMac = /mac os x/.test(navigator.userAgent.toLowerCase());
|
|
958
|
-
const ctrl = isMac ? "meta" : "ctrl";
|
|
959
|
-
KeyController.global.keydown(ctrl, (e) => {
|
|
960
|
-
e.inputEvent.preventDefault();
|
|
961
|
-
this.isMultiSelectStatus = true;
|
|
962
|
-
});
|
|
963
|
-
KeyController.global.keyup(ctrl, (e) => {
|
|
964
|
-
e.inputEvent.preventDefault();
|
|
965
|
-
this.isMultiSelectStatus = false;
|
|
966
|
-
});
|
|
1040
|
+
this.initMultiSelectEvent();
|
|
967
1041
|
}
|
|
968
1042
|
setMode(mode) {
|
|
969
1043
|
this.mode = mode;
|
|
@@ -980,9 +1054,66 @@ class StageMask extends Rule {
|
|
|
980
1054
|
if (!page)
|
|
981
1055
|
return;
|
|
982
1056
|
this.page = page;
|
|
983
|
-
this.
|
|
984
|
-
this.
|
|
1057
|
+
this.initObserverIntersection();
|
|
1058
|
+
this.initObserverWrapper();
|
|
1059
|
+
}
|
|
1060
|
+
pageResize(entries) {
|
|
1061
|
+
const [entry] = entries;
|
|
1062
|
+
const { clientHeight, clientWidth } = entry.target;
|
|
1063
|
+
this.setHeight(clientHeight);
|
|
1064
|
+
this.setWidth(clientWidth);
|
|
1065
|
+
this.scroll();
|
|
1066
|
+
}
|
|
1067
|
+
observerIntersection(el) {
|
|
1068
|
+
this.intersectionObserver?.observe(el);
|
|
1069
|
+
}
|
|
1070
|
+
mount(el) {
|
|
1071
|
+
if (!this.content)
|
|
1072
|
+
throw new Error("content \u4E0D\u5B58\u5728");
|
|
1073
|
+
el.appendChild(this.wrapper);
|
|
1074
|
+
}
|
|
1075
|
+
setLayout(el) {
|
|
1076
|
+
this.setMode(isFixedParent(el) ? Mode.FIXED : Mode.ABSOLUTE);
|
|
1077
|
+
}
|
|
1078
|
+
scrollIntoView(el) {
|
|
1079
|
+
el.scrollIntoView();
|
|
1080
|
+
if (!this.pageScrollParent)
|
|
1081
|
+
return;
|
|
1082
|
+
this.scrollLeft = this.pageScrollParent.scrollLeft;
|
|
1083
|
+
this.scrollTop = this.pageScrollParent.scrollTop;
|
|
1084
|
+
this.scroll();
|
|
1085
|
+
}
|
|
1086
|
+
destroy() {
|
|
1087
|
+
this.content?.remove();
|
|
1088
|
+
this.page = null;
|
|
1089
|
+
this.pageScrollParent = null;
|
|
985
1090
|
this.wrapperResizeObserver?.disconnect();
|
|
1091
|
+
this.content.removeEventListener("mouseleave", this.mouseLeaveHandler);
|
|
1092
|
+
super.destroy();
|
|
1093
|
+
}
|
|
1094
|
+
initContentEventListener() {
|
|
1095
|
+
this.content.addEventListener("mousedown", this.mouseDownHandler);
|
|
1096
|
+
this.content.addEventListener("wheel", this.mouseWheelHandler);
|
|
1097
|
+
this.content.addEventListener("mousemove", this.highlightHandler);
|
|
1098
|
+
this.content.addEventListener("mouseleave", this.mouseLeaveHandler);
|
|
1099
|
+
}
|
|
1100
|
+
initMultiSelectEvent() {
|
|
1101
|
+
const isMac = /mac os x/.test(navigator.userAgent.toLowerCase());
|
|
1102
|
+
const ctrl = isMac ? "meta" : "ctrl";
|
|
1103
|
+
KeyController.global.keydown(ctrl, (e) => {
|
|
1104
|
+
e.inputEvent.preventDefault();
|
|
1105
|
+
this.isMultiSelectStatus = true;
|
|
1106
|
+
});
|
|
1107
|
+
KeyController.global.on("blur", () => {
|
|
1108
|
+
this.isMultiSelectStatus = false;
|
|
1109
|
+
});
|
|
1110
|
+
KeyController.global.keyup(ctrl, (e) => {
|
|
1111
|
+
e.inputEvent.preventDefault();
|
|
1112
|
+
this.isMultiSelectStatus = false;
|
|
1113
|
+
});
|
|
1114
|
+
}
|
|
1115
|
+
initObserverIntersection() {
|
|
1116
|
+
this.pageScrollParent = getScrollParent(this.page) || null;
|
|
986
1117
|
this.intersectionObserver?.disconnect();
|
|
987
1118
|
if (typeof IntersectionObserver !== "undefined") {
|
|
988
1119
|
this.intersectionObserver = new IntersectionObserver(
|
|
@@ -1002,18 +1133,10 @@ class StageMask extends Rule {
|
|
|
1002
1133
|
}
|
|
1003
1134
|
);
|
|
1004
1135
|
}
|
|
1136
|
+
}
|
|
1137
|
+
initObserverWrapper() {
|
|
1138
|
+
this.wrapperResizeObserver?.disconnect();
|
|
1005
1139
|
if (typeof ResizeObserver !== "undefined") {
|
|
1006
|
-
this.pageResizeObserver = new ResizeObserver((entries) => {
|
|
1007
|
-
const [entry] = entries;
|
|
1008
|
-
const { clientHeight, clientWidth } = entry.target;
|
|
1009
|
-
this.setHeight(clientHeight);
|
|
1010
|
-
this.setWidth(clientWidth);
|
|
1011
|
-
this.scroll();
|
|
1012
|
-
if (this.core.dr.moveable) {
|
|
1013
|
-
this.core.dr.updateMoveable();
|
|
1014
|
-
}
|
|
1015
|
-
});
|
|
1016
|
-
this.pageResizeObserver.observe(page);
|
|
1017
1140
|
this.wrapperResizeObserver = new ResizeObserver((entries) => {
|
|
1018
1141
|
const [entry] = entries;
|
|
1019
1142
|
const { clientHeight, clientWidth } = entry.target;
|
|
@@ -1025,31 +1148,6 @@ class StageMask extends Rule {
|
|
|
1025
1148
|
this.wrapperResizeObserver.observe(this.wrapper);
|
|
1026
1149
|
}
|
|
1027
1150
|
}
|
|
1028
|
-
mount(el) {
|
|
1029
|
-
if (!this.content)
|
|
1030
|
-
throw new Error("content \u4E0D\u5B58\u5728");
|
|
1031
|
-
el.appendChild(this.wrapper);
|
|
1032
|
-
}
|
|
1033
|
-
setLayout(el) {
|
|
1034
|
-
this.setMode(isFixedParent(el) ? Mode.FIXED : Mode.ABSOLUTE);
|
|
1035
|
-
}
|
|
1036
|
-
scrollIntoView(el) {
|
|
1037
|
-
el.scrollIntoView();
|
|
1038
|
-
if (!this.pageScrollParent)
|
|
1039
|
-
return;
|
|
1040
|
-
this.scrollLeft = this.pageScrollParent.scrollLeft;
|
|
1041
|
-
this.scrollTop = this.pageScrollParent.scrollTop;
|
|
1042
|
-
this.scroll();
|
|
1043
|
-
}
|
|
1044
|
-
destroy() {
|
|
1045
|
-
this.content?.remove();
|
|
1046
|
-
this.page = null;
|
|
1047
|
-
this.pageScrollParent = null;
|
|
1048
|
-
this.pageResizeObserver?.disconnect();
|
|
1049
|
-
this.wrapperResizeObserver?.disconnect();
|
|
1050
|
-
this.content.removeEventListener("mouseleave", this.mouseLeaveHandler);
|
|
1051
|
-
super.destroy();
|
|
1052
|
-
}
|
|
1053
1151
|
scroll() {
|
|
1054
1152
|
this.fixScrollValue();
|
|
1055
1153
|
let { scrollLeft, scrollTop } = this;
|
|
@@ -1101,10 +1199,13 @@ class StageMask extends Rule {
|
|
|
1101
1199
|
event.stopPropagation();
|
|
1102
1200
|
if (event.button !== MouseButton.LEFT && event.button !== MouseButton.RIGHT)
|
|
1103
1201
|
return;
|
|
1104
|
-
if (!
|
|
1202
|
+
if (!event.target)
|
|
1203
|
+
return;
|
|
1204
|
+
const targetClassList = event.target.classList;
|
|
1205
|
+
if (!this.isMultiSelectStatus && targetClassList.contains("moveable-area")) {
|
|
1105
1206
|
return;
|
|
1106
1207
|
}
|
|
1107
|
-
if (
|
|
1208
|
+
if (targetClassList.contains("moveable-control") || isMoveableButton(event.target)) {
|
|
1108
1209
|
return;
|
|
1109
1210
|
}
|
|
1110
1211
|
this.content.removeEventListener("mousemove", this.highlightHandler);
|
|
@@ -1366,13 +1467,11 @@ class StageRender extends EventEmitter {
|
|
|
1366
1467
|
runtime = null;
|
|
1367
1468
|
iframe;
|
|
1368
1469
|
runtimeUrl;
|
|
1369
|
-
core;
|
|
1370
1470
|
render;
|
|
1371
|
-
constructor({
|
|
1471
|
+
constructor({ runtimeUrl, render }) {
|
|
1372
1472
|
super();
|
|
1373
|
-
this.
|
|
1374
|
-
this.
|
|
1375
|
-
this.render = core.config.render;
|
|
1473
|
+
this.runtimeUrl = runtimeUrl || "";
|
|
1474
|
+
this.render = render;
|
|
1376
1475
|
this.iframe = globalThis.document.createElement("iframe");
|
|
1377
1476
|
this.iframe.src = isSameDomain(this.runtimeUrl) ? this.runtimeUrl : "";
|
|
1378
1477
|
this.iframe.style.cssText = `
|
|
@@ -1415,6 +1514,9 @@ class StageRender extends EventEmitter {
|
|
|
1415
1514
|
this.on("runtime-ready", listener);
|
|
1416
1515
|
});
|
|
1417
1516
|
};
|
|
1517
|
+
getDocument() {
|
|
1518
|
+
return this.contentWindow?.document;
|
|
1519
|
+
}
|
|
1418
1520
|
destroy() {
|
|
1419
1521
|
this.iframe?.removeEventListener("load", this.loadHandler);
|
|
1420
1522
|
this.contentWindow = null;
|
|
@@ -1429,7 +1531,7 @@ class StageRender extends EventEmitter {
|
|
|
1429
1531
|
if (!this.contentWindow)
|
|
1430
1532
|
return;
|
|
1431
1533
|
if (this.render) {
|
|
1432
|
-
const el = await this.render(
|
|
1534
|
+
const el = await this.render();
|
|
1433
1535
|
if (el) {
|
|
1434
1536
|
this.contentWindow.document?.body?.appendChild(el);
|
|
1435
1537
|
}
|
|
@@ -1466,6 +1568,7 @@ class StageCore extends EventEmitter {
|
|
|
1466
1568
|
containerHighlightType;
|
|
1467
1569
|
isContainer;
|
|
1468
1570
|
canSelect;
|
|
1571
|
+
pageResizeObserver = null;
|
|
1469
1572
|
constructor(config) {
|
|
1470
1573
|
super();
|
|
1471
1574
|
this.config = config;
|
|
@@ -1475,8 +1578,8 @@ class StageCore extends EventEmitter {
|
|
|
1475
1578
|
this.containerHighlightClassName = config.containerHighlightClassName || CONTAINER_HIGHLIGHT_CLASS;
|
|
1476
1579
|
this.containerHighlightDuration = config.containerHighlightDuration || 800;
|
|
1477
1580
|
this.containerHighlightType = config.containerHighlightType;
|
|
1478
|
-
this.renderer = new StageRender({
|
|
1479
|
-
this.mask = new StageMask(
|
|
1581
|
+
this.renderer = new StageRender({ runtimeUrl: config.runtimeUrl, render: this.render.bind(this) });
|
|
1582
|
+
this.mask = new StageMask();
|
|
1480
1583
|
this.dr = new StageDragResize({ core: this, container: this.mask.content, mask: this.mask });
|
|
1481
1584
|
this.multiDr = new StageMultiDragResize({ core: this, container: this.mask.content, mask: this.mask });
|
|
1482
1585
|
this.highlightLayer = new StageHighlight({ core: this, container: this.mask.wrapper });
|
|
@@ -1485,6 +1588,7 @@ class StageCore extends EventEmitter {
|
|
|
1485
1588
|
});
|
|
1486
1589
|
this.renderer.on("page-el-update", (el) => {
|
|
1487
1590
|
this.mask?.observe(el);
|
|
1591
|
+
this.observePageResize(el);
|
|
1488
1592
|
});
|
|
1489
1593
|
this.mask.on("beforeSelect", async (event) => {
|
|
1490
1594
|
this.clearSelectStatus("multiSelect");
|
|
@@ -1526,11 +1630,14 @@ class StageCore extends EventEmitter {
|
|
|
1526
1630
|
this.selectedDomList.push(el);
|
|
1527
1631
|
}
|
|
1528
1632
|
this.multiSelect(this.selectedDomList);
|
|
1633
|
+
this.emit("multiSelect", this.selectedDomList);
|
|
1529
1634
|
});
|
|
1530
1635
|
this.dr.on("update", (data) => {
|
|
1531
1636
|
setTimeout(() => this.emit("update", data));
|
|
1532
1637
|
}).on("sort", (data) => {
|
|
1533
1638
|
setTimeout(() => this.emit("sort", data));
|
|
1639
|
+
}).on("select-parent", () => {
|
|
1640
|
+
this.emit("select-parent");
|
|
1534
1641
|
});
|
|
1535
1642
|
this.multiDr.on("update", (data) => {
|
|
1536
1643
|
setTimeout(() => this.emit("update", data));
|
|
@@ -1542,7 +1649,6 @@ class StageCore extends EventEmitter {
|
|
|
1542
1649
|
}
|
|
1543
1650
|
getElementsFromPoint(event) {
|
|
1544
1651
|
const { renderer, zoom } = this;
|
|
1545
|
-
const doc = renderer.contentWindow?.document;
|
|
1546
1652
|
let x = event.clientX;
|
|
1547
1653
|
let y = event.clientY;
|
|
1548
1654
|
if (renderer.iframe) {
|
|
@@ -1552,7 +1658,7 @@ class StageCore extends EventEmitter {
|
|
|
1552
1658
|
y = y - rect.top;
|
|
1553
1659
|
}
|
|
1554
1660
|
}
|
|
1555
|
-
return
|
|
1661
|
+
return renderer.getDocument()?.elementsFromPoint(x / zoom, y / zoom);
|
|
1556
1662
|
}
|
|
1557
1663
|
async getElementFromPoint(event) {
|
|
1558
1664
|
const els = this.getElementsFromPoint(event);
|
|
@@ -1588,28 +1694,28 @@ class StageCore extends EventEmitter {
|
|
|
1588
1694
|
this.mask.setLayout(el);
|
|
1589
1695
|
this.dr.select(el, event);
|
|
1590
1696
|
if (this.config.autoScrollIntoView || el.dataset.autoScrollIntoView) {
|
|
1591
|
-
this.mask.
|
|
1697
|
+
this.mask.observerIntersection(el);
|
|
1592
1698
|
}
|
|
1593
1699
|
this.selectedDom = el;
|
|
1594
|
-
|
|
1595
|
-
|
|
1700
|
+
const doc = this.renderer.getDocument();
|
|
1701
|
+
if (doc) {
|
|
1702
|
+
removeSelectedClassName(doc);
|
|
1596
1703
|
if (this.selectedDom) {
|
|
1597
|
-
addSelectedClassName(this.selectedDom,
|
|
1704
|
+
addSelectedClassName(this.selectedDom, doc);
|
|
1598
1705
|
}
|
|
1599
1706
|
}
|
|
1600
1707
|
}
|
|
1601
1708
|
async multiSelect(idOrElList) {
|
|
1602
1709
|
this.clearSelectStatus("select");
|
|
1603
|
-
|
|
1604
|
-
this.multiDr.multiSelect(
|
|
1605
|
-
this.emit("multiSelect", elList);
|
|
1710
|
+
this.selectedDomList = await Promise.all(idOrElList.map(async (idOrEl) => await this.getTargetElement(idOrEl)));
|
|
1711
|
+
this.multiDr.multiSelect(this.selectedDomList);
|
|
1606
1712
|
}
|
|
1607
1713
|
update(data) {
|
|
1608
1714
|
const { config } = data;
|
|
1609
1715
|
return this.renderer?.getRuntime().then((runtime) => {
|
|
1610
1716
|
runtime?.update?.(data);
|
|
1611
1717
|
setTimeout(() => {
|
|
1612
|
-
const el = this.renderer.
|
|
1718
|
+
const el = this.renderer.getDocument()?.getElementById(`${config.id}`);
|
|
1613
1719
|
if (el && el.id === this.selectedDom?.id) {
|
|
1614
1720
|
this.selectedDom = el;
|
|
1615
1721
|
this.mask.setLayout(el);
|
|
@@ -1665,7 +1771,7 @@ class StageCore extends EventEmitter {
|
|
|
1665
1771
|
async addContainerHighlightClassName(event, exclude) {
|
|
1666
1772
|
const els = this.getElementsFromPoint(event);
|
|
1667
1773
|
const { renderer } = this;
|
|
1668
|
-
const doc = renderer.
|
|
1774
|
+
const doc = renderer.getDocument();
|
|
1669
1775
|
if (!doc)
|
|
1670
1776
|
return;
|
|
1671
1777
|
for (const el of els) {
|
|
@@ -1681,17 +1787,35 @@ class StageCore extends EventEmitter {
|
|
|
1681
1787
|
}, this.containerHighlightDuration);
|
|
1682
1788
|
}
|
|
1683
1789
|
destroy() {
|
|
1684
|
-
const { mask, renderer, dr, highlightLayer } = this;
|
|
1790
|
+
const { mask, renderer, dr, highlightLayer, pageResizeObserver } = this;
|
|
1685
1791
|
renderer.destroy();
|
|
1686
1792
|
mask.destroy();
|
|
1687
1793
|
dr.destroy();
|
|
1688
1794
|
highlightLayer.destroy();
|
|
1795
|
+
pageResizeObserver?.disconnect();
|
|
1689
1796
|
this.removeAllListeners();
|
|
1690
1797
|
this.container = void 0;
|
|
1691
1798
|
}
|
|
1799
|
+
observePageResize(page) {
|
|
1800
|
+
if (typeof ResizeObserver !== "undefined") {
|
|
1801
|
+
this.pageResizeObserver = new ResizeObserver((entries) => {
|
|
1802
|
+
this.mask.pageResize(entries);
|
|
1803
|
+
if (this.dr.moveable) {
|
|
1804
|
+
this.dr.updateMoveable();
|
|
1805
|
+
}
|
|
1806
|
+
});
|
|
1807
|
+
this.pageResizeObserver.observe(page);
|
|
1808
|
+
}
|
|
1809
|
+
}
|
|
1810
|
+
async render() {
|
|
1811
|
+
if (this.config?.render) {
|
|
1812
|
+
return await this.config.render(this);
|
|
1813
|
+
}
|
|
1814
|
+
return null;
|
|
1815
|
+
}
|
|
1692
1816
|
async getTargetElement(idOrEl) {
|
|
1693
1817
|
if (typeof idOrEl === "string" || typeof idOrEl === "number") {
|
|
1694
|
-
const el = this.renderer.
|
|
1818
|
+
const el = this.renderer.getDocument()?.getElementById(`${idOrEl}`);
|
|
1695
1819
|
if (!el)
|
|
1696
1820
|
throw new Error(`\u4E0D\u5B58\u5728ID\u4E3A${idOrEl}\u7684\u5143\u7D20`);
|
|
1697
1821
|
return el;
|
|
@@ -1700,5 +1824,5 @@ class StageCore extends EventEmitter {
|
|
|
1700
1824
|
}
|
|
1701
1825
|
}
|
|
1702
1826
|
|
|
1703
|
-
export { CONTAINER_HIGHLIGHT_CLASS, ContainerHighlightType, DEFAULT_ZOOM, DRAG_EL_ID_PREFIX, GHOST_EL_ID_PREFIX, GuidesType, HIGHLIGHT_EL_ID_PREFIX, Mode, MouseButton, PAGE_CLASS, SELECTED_CLASS, StageDragResize, StageDragStatus, StageMask, StageRender, ZIndex, addSelectedClassName, calcValueByFontsize, StageCore as default, down, getAbsolutePosition, getMode, getOffset, getScrollParent, getTargetElStyle, isAbsolute, isFixed, isFixedParent, isRelative, isStatic, removeSelectedClassName, up };
|
|
1827
|
+
export { CONTAINER_HIGHLIGHT_CLASS, ContainerHighlightType, DEFAULT_ZOOM, DRAG_EL_ID_PREFIX, GHOST_EL_ID_PREFIX, GuidesType, HIGHLIGHT_EL_ID_PREFIX, Mode, MouseButton, PAGE_CLASS, SELECTED_CLASS, StageDragResize, StageDragStatus, StageMask, StageRender, ZIndex, addSelectedClassName, calcValueByFontsize, StageCore as default, down, getAbsolutePosition, getMode, getOffset, getScrollParent, getTargetElStyle, isAbsolute, isFixed, isFixedParent, isMoveableButton, isRelative, isStatic, removeSelectedClassName, up };
|
|
1704
1828
|
//# sourceMappingURL=tmagic-stage.mjs.map
|