@tmagic/stage 1.2.0-beta.1 → 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 -98
- package/dist/tmagic-stage.mjs.map +1 -1
- package/dist/tmagic-stage.umd.js +219 -97
- 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 -81
- 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,37 +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.on("blur", () => {
|
|
964
|
-
this.isMultiSelectStatus = false;
|
|
965
|
-
});
|
|
966
|
-
KeyController.global.keyup(ctrl, (e) => {
|
|
967
|
-
e.inputEvent.preventDefault();
|
|
968
|
-
this.isMultiSelectStatus = false;
|
|
969
|
-
});
|
|
1040
|
+
this.initMultiSelectEvent();
|
|
970
1041
|
}
|
|
971
1042
|
setMode(mode) {
|
|
972
1043
|
this.mode = mode;
|
|
@@ -983,9 +1054,66 @@ class StageMask extends Rule {
|
|
|
983
1054
|
if (!page)
|
|
984
1055
|
return;
|
|
985
1056
|
this.page = page;
|
|
986
|
-
this.
|
|
987
|
-
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;
|
|
988
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;
|
|
989
1117
|
this.intersectionObserver?.disconnect();
|
|
990
1118
|
if (typeof IntersectionObserver !== "undefined") {
|
|
991
1119
|
this.intersectionObserver = new IntersectionObserver(
|
|
@@ -1005,18 +1133,10 @@ class StageMask extends Rule {
|
|
|
1005
1133
|
}
|
|
1006
1134
|
);
|
|
1007
1135
|
}
|
|
1136
|
+
}
|
|
1137
|
+
initObserverWrapper() {
|
|
1138
|
+
this.wrapperResizeObserver?.disconnect();
|
|
1008
1139
|
if (typeof ResizeObserver !== "undefined") {
|
|
1009
|
-
this.pageResizeObserver = new ResizeObserver((entries) => {
|
|
1010
|
-
const [entry] = entries;
|
|
1011
|
-
const { clientHeight, clientWidth } = entry.target;
|
|
1012
|
-
this.setHeight(clientHeight);
|
|
1013
|
-
this.setWidth(clientWidth);
|
|
1014
|
-
this.scroll();
|
|
1015
|
-
if (this.core.dr.moveable) {
|
|
1016
|
-
this.core.dr.updateMoveable();
|
|
1017
|
-
}
|
|
1018
|
-
});
|
|
1019
|
-
this.pageResizeObserver.observe(page);
|
|
1020
1140
|
this.wrapperResizeObserver = new ResizeObserver((entries) => {
|
|
1021
1141
|
const [entry] = entries;
|
|
1022
1142
|
const { clientHeight, clientWidth } = entry.target;
|
|
@@ -1028,31 +1148,6 @@ class StageMask extends Rule {
|
|
|
1028
1148
|
this.wrapperResizeObserver.observe(this.wrapper);
|
|
1029
1149
|
}
|
|
1030
1150
|
}
|
|
1031
|
-
mount(el) {
|
|
1032
|
-
if (!this.content)
|
|
1033
|
-
throw new Error("content \u4E0D\u5B58\u5728");
|
|
1034
|
-
el.appendChild(this.wrapper);
|
|
1035
|
-
}
|
|
1036
|
-
setLayout(el) {
|
|
1037
|
-
this.setMode(isFixedParent(el) ? Mode.FIXED : Mode.ABSOLUTE);
|
|
1038
|
-
}
|
|
1039
|
-
scrollIntoView(el) {
|
|
1040
|
-
el.scrollIntoView();
|
|
1041
|
-
if (!this.pageScrollParent)
|
|
1042
|
-
return;
|
|
1043
|
-
this.scrollLeft = this.pageScrollParent.scrollLeft;
|
|
1044
|
-
this.scrollTop = this.pageScrollParent.scrollTop;
|
|
1045
|
-
this.scroll();
|
|
1046
|
-
}
|
|
1047
|
-
destroy() {
|
|
1048
|
-
this.content?.remove();
|
|
1049
|
-
this.page = null;
|
|
1050
|
-
this.pageScrollParent = null;
|
|
1051
|
-
this.pageResizeObserver?.disconnect();
|
|
1052
|
-
this.wrapperResizeObserver?.disconnect();
|
|
1053
|
-
this.content.removeEventListener("mouseleave", this.mouseLeaveHandler);
|
|
1054
|
-
super.destroy();
|
|
1055
|
-
}
|
|
1056
1151
|
scroll() {
|
|
1057
1152
|
this.fixScrollValue();
|
|
1058
1153
|
let { scrollLeft, scrollTop } = this;
|
|
@@ -1104,10 +1199,13 @@ class StageMask extends Rule {
|
|
|
1104
1199
|
event.stopPropagation();
|
|
1105
1200
|
if (event.button !== MouseButton.LEFT && event.button !== MouseButton.RIGHT)
|
|
1106
1201
|
return;
|
|
1107
|
-
if (!
|
|
1202
|
+
if (!event.target)
|
|
1203
|
+
return;
|
|
1204
|
+
const targetClassList = event.target.classList;
|
|
1205
|
+
if (!this.isMultiSelectStatus && targetClassList.contains("moveable-area")) {
|
|
1108
1206
|
return;
|
|
1109
1207
|
}
|
|
1110
|
-
if (
|
|
1208
|
+
if (targetClassList.contains("moveable-control") || isMoveableButton(event.target)) {
|
|
1111
1209
|
return;
|
|
1112
1210
|
}
|
|
1113
1211
|
this.content.removeEventListener("mousemove", this.highlightHandler);
|
|
@@ -1369,13 +1467,11 @@ class StageRender extends EventEmitter {
|
|
|
1369
1467
|
runtime = null;
|
|
1370
1468
|
iframe;
|
|
1371
1469
|
runtimeUrl;
|
|
1372
|
-
core;
|
|
1373
1470
|
render;
|
|
1374
|
-
constructor({
|
|
1471
|
+
constructor({ runtimeUrl, render }) {
|
|
1375
1472
|
super();
|
|
1376
|
-
this.
|
|
1377
|
-
this.
|
|
1378
|
-
this.render = core.config.render;
|
|
1473
|
+
this.runtimeUrl = runtimeUrl || "";
|
|
1474
|
+
this.render = render;
|
|
1379
1475
|
this.iframe = globalThis.document.createElement("iframe");
|
|
1380
1476
|
this.iframe.src = isSameDomain(this.runtimeUrl) ? this.runtimeUrl : "";
|
|
1381
1477
|
this.iframe.style.cssText = `
|
|
@@ -1418,6 +1514,9 @@ class StageRender extends EventEmitter {
|
|
|
1418
1514
|
this.on("runtime-ready", listener);
|
|
1419
1515
|
});
|
|
1420
1516
|
};
|
|
1517
|
+
getDocument() {
|
|
1518
|
+
return this.contentWindow?.document;
|
|
1519
|
+
}
|
|
1421
1520
|
destroy() {
|
|
1422
1521
|
this.iframe?.removeEventListener("load", this.loadHandler);
|
|
1423
1522
|
this.contentWindow = null;
|
|
@@ -1432,7 +1531,7 @@ class StageRender extends EventEmitter {
|
|
|
1432
1531
|
if (!this.contentWindow)
|
|
1433
1532
|
return;
|
|
1434
1533
|
if (this.render) {
|
|
1435
|
-
const el = await this.render(
|
|
1534
|
+
const el = await this.render();
|
|
1436
1535
|
if (el) {
|
|
1437
1536
|
this.contentWindow.document?.body?.appendChild(el);
|
|
1438
1537
|
}
|
|
@@ -1469,6 +1568,7 @@ class StageCore extends EventEmitter {
|
|
|
1469
1568
|
containerHighlightType;
|
|
1470
1569
|
isContainer;
|
|
1471
1570
|
canSelect;
|
|
1571
|
+
pageResizeObserver = null;
|
|
1472
1572
|
constructor(config) {
|
|
1473
1573
|
super();
|
|
1474
1574
|
this.config = config;
|
|
@@ -1478,8 +1578,8 @@ class StageCore extends EventEmitter {
|
|
|
1478
1578
|
this.containerHighlightClassName = config.containerHighlightClassName || CONTAINER_HIGHLIGHT_CLASS;
|
|
1479
1579
|
this.containerHighlightDuration = config.containerHighlightDuration || 800;
|
|
1480
1580
|
this.containerHighlightType = config.containerHighlightType;
|
|
1481
|
-
this.renderer = new StageRender({
|
|
1482
|
-
this.mask = new StageMask(
|
|
1581
|
+
this.renderer = new StageRender({ runtimeUrl: config.runtimeUrl, render: this.render.bind(this) });
|
|
1582
|
+
this.mask = new StageMask();
|
|
1483
1583
|
this.dr = new StageDragResize({ core: this, container: this.mask.content, mask: this.mask });
|
|
1484
1584
|
this.multiDr = new StageMultiDragResize({ core: this, container: this.mask.content, mask: this.mask });
|
|
1485
1585
|
this.highlightLayer = new StageHighlight({ core: this, container: this.mask.wrapper });
|
|
@@ -1488,6 +1588,7 @@ class StageCore extends EventEmitter {
|
|
|
1488
1588
|
});
|
|
1489
1589
|
this.renderer.on("page-el-update", (el) => {
|
|
1490
1590
|
this.mask?.observe(el);
|
|
1591
|
+
this.observePageResize(el);
|
|
1491
1592
|
});
|
|
1492
1593
|
this.mask.on("beforeSelect", async (event) => {
|
|
1493
1594
|
this.clearSelectStatus("multiSelect");
|
|
@@ -1529,11 +1630,14 @@ class StageCore extends EventEmitter {
|
|
|
1529
1630
|
this.selectedDomList.push(el);
|
|
1530
1631
|
}
|
|
1531
1632
|
this.multiSelect(this.selectedDomList);
|
|
1633
|
+
this.emit("multiSelect", this.selectedDomList);
|
|
1532
1634
|
});
|
|
1533
1635
|
this.dr.on("update", (data) => {
|
|
1534
1636
|
setTimeout(() => this.emit("update", data));
|
|
1535
1637
|
}).on("sort", (data) => {
|
|
1536
1638
|
setTimeout(() => this.emit("sort", data));
|
|
1639
|
+
}).on("select-parent", () => {
|
|
1640
|
+
this.emit("select-parent");
|
|
1537
1641
|
});
|
|
1538
1642
|
this.multiDr.on("update", (data) => {
|
|
1539
1643
|
setTimeout(() => this.emit("update", data));
|
|
@@ -1545,7 +1649,6 @@ class StageCore extends EventEmitter {
|
|
|
1545
1649
|
}
|
|
1546
1650
|
getElementsFromPoint(event) {
|
|
1547
1651
|
const { renderer, zoom } = this;
|
|
1548
|
-
const doc = renderer.contentWindow?.document;
|
|
1549
1652
|
let x = event.clientX;
|
|
1550
1653
|
let y = event.clientY;
|
|
1551
1654
|
if (renderer.iframe) {
|
|
@@ -1555,7 +1658,7 @@ class StageCore extends EventEmitter {
|
|
|
1555
1658
|
y = y - rect.top;
|
|
1556
1659
|
}
|
|
1557
1660
|
}
|
|
1558
|
-
return
|
|
1661
|
+
return renderer.getDocument()?.elementsFromPoint(x / zoom, y / zoom);
|
|
1559
1662
|
}
|
|
1560
1663
|
async getElementFromPoint(event) {
|
|
1561
1664
|
const els = this.getElementsFromPoint(event);
|
|
@@ -1591,28 +1694,28 @@ class StageCore extends EventEmitter {
|
|
|
1591
1694
|
this.mask.setLayout(el);
|
|
1592
1695
|
this.dr.select(el, event);
|
|
1593
1696
|
if (this.config.autoScrollIntoView || el.dataset.autoScrollIntoView) {
|
|
1594
|
-
this.mask.
|
|
1697
|
+
this.mask.observerIntersection(el);
|
|
1595
1698
|
}
|
|
1596
1699
|
this.selectedDom = el;
|
|
1597
|
-
|
|
1598
|
-
|
|
1700
|
+
const doc = this.renderer.getDocument();
|
|
1701
|
+
if (doc) {
|
|
1702
|
+
removeSelectedClassName(doc);
|
|
1599
1703
|
if (this.selectedDom) {
|
|
1600
|
-
addSelectedClassName(this.selectedDom,
|
|
1704
|
+
addSelectedClassName(this.selectedDom, doc);
|
|
1601
1705
|
}
|
|
1602
1706
|
}
|
|
1603
1707
|
}
|
|
1604
1708
|
async multiSelect(idOrElList) {
|
|
1605
1709
|
this.clearSelectStatus("select");
|
|
1606
|
-
|
|
1607
|
-
this.multiDr.multiSelect(
|
|
1608
|
-
this.emit("multiSelect", elList);
|
|
1710
|
+
this.selectedDomList = await Promise.all(idOrElList.map(async (idOrEl) => await this.getTargetElement(idOrEl)));
|
|
1711
|
+
this.multiDr.multiSelect(this.selectedDomList);
|
|
1609
1712
|
}
|
|
1610
1713
|
update(data) {
|
|
1611
1714
|
const { config } = data;
|
|
1612
1715
|
return this.renderer?.getRuntime().then((runtime) => {
|
|
1613
1716
|
runtime?.update?.(data);
|
|
1614
1717
|
setTimeout(() => {
|
|
1615
|
-
const el = this.renderer.
|
|
1718
|
+
const el = this.renderer.getDocument()?.getElementById(`${config.id}`);
|
|
1616
1719
|
if (el && el.id === this.selectedDom?.id) {
|
|
1617
1720
|
this.selectedDom = el;
|
|
1618
1721
|
this.mask.setLayout(el);
|
|
@@ -1668,7 +1771,7 @@ class StageCore extends EventEmitter {
|
|
|
1668
1771
|
async addContainerHighlightClassName(event, exclude) {
|
|
1669
1772
|
const els = this.getElementsFromPoint(event);
|
|
1670
1773
|
const { renderer } = this;
|
|
1671
|
-
const doc = renderer.
|
|
1774
|
+
const doc = renderer.getDocument();
|
|
1672
1775
|
if (!doc)
|
|
1673
1776
|
return;
|
|
1674
1777
|
for (const el of els) {
|
|
@@ -1684,17 +1787,35 @@ class StageCore extends EventEmitter {
|
|
|
1684
1787
|
}, this.containerHighlightDuration);
|
|
1685
1788
|
}
|
|
1686
1789
|
destroy() {
|
|
1687
|
-
const { mask, renderer, dr, highlightLayer } = this;
|
|
1790
|
+
const { mask, renderer, dr, highlightLayer, pageResizeObserver } = this;
|
|
1688
1791
|
renderer.destroy();
|
|
1689
1792
|
mask.destroy();
|
|
1690
1793
|
dr.destroy();
|
|
1691
1794
|
highlightLayer.destroy();
|
|
1795
|
+
pageResizeObserver?.disconnect();
|
|
1692
1796
|
this.removeAllListeners();
|
|
1693
1797
|
this.container = void 0;
|
|
1694
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
|
+
}
|
|
1695
1816
|
async getTargetElement(idOrEl) {
|
|
1696
1817
|
if (typeof idOrEl === "string" || typeof idOrEl === "number") {
|
|
1697
|
-
const el = this.renderer.
|
|
1818
|
+
const el = this.renderer.getDocument()?.getElementById(`${idOrEl}`);
|
|
1698
1819
|
if (!el)
|
|
1699
1820
|
throw new Error(`\u4E0D\u5B58\u5728ID\u4E3A${idOrEl}\u7684\u5143\u7D20`);
|
|
1700
1821
|
return el;
|
|
@@ -1703,5 +1824,5 @@ class StageCore extends EventEmitter {
|
|
|
1703
1824
|
}
|
|
1704
1825
|
}
|
|
1705
1826
|
|
|
1706
|
-
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 };
|
|
1707
1828
|
//# sourceMappingURL=tmagic-stage.mjs.map
|