@tmagic/stage 1.4.7 → 1.4.8
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.js +69 -138
- package/dist/tmagic-stage.umd.cjs +69 -138
- package/package.json +9 -5
- package/src/ActionManager.ts +0 -661
- package/src/DragResizeHelper.ts +0 -396
- package/src/MoveableActionsAble.ts +0 -91
- package/src/MoveableOptionsManager.ts +0 -274
- package/src/Rule.ts +0 -173
- package/src/StageCore.ts +0 -417
- package/src/StageDragResize.ts +0 -357
- package/src/StageHighlight.ts +0 -89
- package/src/StageMask.ts +0 -337
- package/src/StageMultiDragResize.ts +0 -229
- package/src/StageRender.ts +0 -252
- package/src/TargetShadow.ts +0 -122
- package/src/const.ts +0 -111
- package/src/index.ts +0 -29
- package/src/logger.ts +0 -37
- package/src/moveable-able.css +0 -108
- package/src/style.css +0 -15
- package/src/types.ts +0 -309
- package/src/util.ts +0 -272
- package/tsconfig.build.json +0 -13
|
@@ -136,27 +136,21 @@
|
|
|
136
136
|
return fixed;
|
|
137
137
|
};
|
|
138
138
|
const getMode = (el) => {
|
|
139
|
-
if (isFixedParent(el))
|
|
140
|
-
return Mode.FIXED;
|
|
139
|
+
if (isFixedParent(el)) return Mode.FIXED;
|
|
141
140
|
const style = getComputedStyle(el);
|
|
142
|
-
if (isStatic(style) || isRelative(style))
|
|
143
|
-
return Mode.SORTABLE;
|
|
141
|
+
if (isStatic(style) || isRelative(style)) return Mode.SORTABLE;
|
|
144
142
|
return Mode.ABSOLUTE;
|
|
145
143
|
};
|
|
146
144
|
const getScrollParent = (element, includeHidden = false) => {
|
|
147
145
|
let style = getComputedStyle(element);
|
|
148
146
|
const overflowRegex = includeHidden ? /(auto|scroll|hidden)/ : /(auto|scroll)/;
|
|
149
|
-
if (isFixed(style))
|
|
150
|
-
return null;
|
|
147
|
+
if (isFixed(style)) return null;
|
|
151
148
|
for (let parent = element; parent.parentElement; ) {
|
|
152
149
|
parent = parent.parentElement;
|
|
153
|
-
if (parent.tagName === "HTML")
|
|
154
|
-
return parent;
|
|
150
|
+
if (parent.tagName === "HTML") return parent;
|
|
155
151
|
style = getComputedStyle(parent);
|
|
156
|
-
if (isAbsolute(style) && isStatic(style))
|
|
157
|
-
|
|
158
|
-
if (overflowRegex.test(style.overflow + style.overflowY + style.overflowX))
|
|
159
|
-
return parent;
|
|
152
|
+
if (isAbsolute(style) && isStatic(style)) continue;
|
|
153
|
+
if (overflowRegex.test(style.overflow + style.overflowY + style.overflowX)) return parent;
|
|
160
154
|
}
|
|
161
155
|
return null;
|
|
162
156
|
};
|
|
@@ -164,8 +158,7 @@
|
|
|
164
158
|
const oldEl = doc.querySelector(`.${SELECTED_CLASS}`);
|
|
165
159
|
if (oldEl) {
|
|
166
160
|
utils.removeClassName(oldEl, SELECTED_CLASS);
|
|
167
|
-
if (oldEl.parentNode)
|
|
168
|
-
utils.removeClassName(oldEl.parentNode, `${SELECTED_CLASS}-parent`);
|
|
161
|
+
if (oldEl.parentNode) utils.removeClassName(oldEl.parentNode, `${SELECTED_CLASS}-parent`);
|
|
169
162
|
doc.querySelectorAll(`.${SELECTED_CLASS}-parents`).forEach((item) => {
|
|
170
163
|
utils.removeClassName(item, `${SELECTED_CLASS}-parents`);
|
|
171
164
|
});
|
|
@@ -213,13 +206,10 @@
|
|
|
213
206
|
let swapIndex = upEls.length - 1;
|
|
214
207
|
for (let i = upEls.length - 1; i >= 0; i--) {
|
|
215
208
|
const ele = upEls[i];
|
|
216
|
-
if (!ele)
|
|
217
|
-
|
|
218
|
-
if (ele.style.position === "fixed")
|
|
219
|
-
continue;
|
|
209
|
+
if (!ele) continue;
|
|
210
|
+
if (ele.style.position === "fixed") continue;
|
|
220
211
|
addUpH += ele.clientHeight / 2;
|
|
221
|
-
if (-deltaTop <= addUpH)
|
|
222
|
-
break;
|
|
212
|
+
if (-deltaTop <= addUpH) break;
|
|
223
213
|
addUpH += ele.clientHeight / 2;
|
|
224
214
|
swapIndex = i;
|
|
225
215
|
}
|
|
@@ -494,13 +484,11 @@
|
|
|
494
484
|
const frameSnapShot = this.framesSnapShot.find(
|
|
495
485
|
(frameItem) => frameItem.id === ev.target.id.replace(DRAG_EL_ID_PREFIX, "")
|
|
496
486
|
);
|
|
497
|
-
if (!frameSnapShot)
|
|
498
|
-
return;
|
|
487
|
+
if (!frameSnapShot) return;
|
|
499
488
|
const targeEl = this.targetList.find(
|
|
500
489
|
(targetItem) => targetItem.id === ev.target.id.replace(DRAG_EL_ID_PREFIX, "")
|
|
501
490
|
);
|
|
502
|
-
if (!targeEl)
|
|
503
|
-
return;
|
|
491
|
+
if (!targeEl) return;
|
|
504
492
|
const isParentIncluded = this.targetList.find((targetItem) => targetItem.id === targeEl.parentElement?.id);
|
|
505
493
|
if (!isParentIncluded) {
|
|
506
494
|
const { marginLeft, marginTop } = getMarginValue(targeEl);
|
|
@@ -523,13 +511,11 @@
|
|
|
523
511
|
const frameSnapShot = this.framesSnapShot.find(
|
|
524
512
|
(frameItem) => ev.target.id.startsWith(DRAG_EL_ID_PREFIX) && ev.target.id.endsWith(frameItem.id)
|
|
525
513
|
);
|
|
526
|
-
if (!frameSnapShot)
|
|
527
|
-
return;
|
|
514
|
+
if (!frameSnapShot) return;
|
|
528
515
|
const targeEl = this.targetList.find(
|
|
529
516
|
(targetItem) => ev.target.id.startsWith(DRAG_EL_ID_PREFIX) && ev.target.id.endsWith(targetItem.id)
|
|
530
517
|
);
|
|
531
|
-
if (!targeEl)
|
|
532
|
-
return;
|
|
518
|
+
if (!targeEl) return;
|
|
533
519
|
const isParentIncluded = this.targetList.find((targetItem) => targetItem.id === targeEl.parentElement?.id);
|
|
534
520
|
if (!isParentIncluded) {
|
|
535
521
|
const { marginLeft, marginTop } = getMarginValue(targeEl);
|
|
@@ -567,14 +553,12 @@
|
|
|
567
553
|
* 多选状态设置多个节点的快照
|
|
568
554
|
*/
|
|
569
555
|
setFramesSnapShot(events) {
|
|
570
|
-
if (this.framesSnapShot.length > 0)
|
|
571
|
-
return;
|
|
556
|
+
if (this.framesSnapShot.length > 0) return;
|
|
572
557
|
events.forEach((ev) => {
|
|
573
558
|
const matchEventTarget = this.targetList.find(
|
|
574
559
|
(targetItem) => ev.target.id.startsWith(DRAG_EL_ID_PREFIX) && ev.target.id.endsWith(targetItem.id)
|
|
575
560
|
);
|
|
576
|
-
if (!matchEventTarget)
|
|
577
|
-
return;
|
|
561
|
+
if (!matchEventTarget) return;
|
|
578
562
|
this.framesSnapShot.push({
|
|
579
563
|
left: matchEventTarget.offsetLeft,
|
|
580
564
|
top: matchEventTarget.offsetTop,
|
|
@@ -876,16 +860,13 @@
|
|
|
876
860
|
const frame = globalThis.document.createDocumentFragment();
|
|
877
861
|
for (const element of allElList) {
|
|
878
862
|
let node = element.element || element;
|
|
879
|
-
if (!node || typeof node === "string")
|
|
880
|
-
continue;
|
|
863
|
+
if (!node || typeof node === "string") continue;
|
|
881
864
|
if (typeof node === "function") {
|
|
882
865
|
node = node();
|
|
883
866
|
}
|
|
884
|
-
if (this.isInElementList(node, selectedElList))
|
|
885
|
-
continue;
|
|
867
|
+
if (this.isInElementList(node, selectedElList)) continue;
|
|
886
868
|
const { width, height } = node.getBoundingClientRect();
|
|
887
|
-
if (!width || !height)
|
|
888
|
-
continue;
|
|
869
|
+
if (!width || !height) continue;
|
|
889
870
|
const { left, top } = getOffset(node);
|
|
890
871
|
const elementGuideline = globalThis.document.createElement("div");
|
|
891
872
|
elementGuideline.style.cssText = `position: absolute;width: ${width}px;height: ${height}px;top: ${top}px;left: ${left}px`;
|
|
@@ -902,8 +883,7 @@
|
|
|
902
883
|
*/
|
|
903
884
|
isInElementList(ele, eleList) {
|
|
904
885
|
for (const eleItem of eleList) {
|
|
905
|
-
if (ele === eleItem)
|
|
906
|
-
return true;
|
|
886
|
+
if (ele === eleItem) return true;
|
|
907
887
|
}
|
|
908
888
|
return false;
|
|
909
889
|
}
|
|
@@ -962,10 +942,8 @@
|
|
|
962
942
|
* 初始化选中框并渲染出来
|
|
963
943
|
*/
|
|
964
944
|
updateMoveable(el = this.target) {
|
|
965
|
-
if (!this.moveable)
|
|
966
|
-
|
|
967
|
-
if (!el)
|
|
968
|
-
throw new Error("未选中任何节点");
|
|
945
|
+
if (!this.moveable) return;
|
|
946
|
+
if (!el) throw new Error("未选中任何节点");
|
|
969
947
|
const options = this.init(el);
|
|
970
948
|
Object.entries(options).forEach(([key, value]) => {
|
|
971
949
|
this.moveable[key] = value;
|
|
@@ -973,8 +951,7 @@
|
|
|
973
951
|
this.moveable.updateRect();
|
|
974
952
|
}
|
|
975
953
|
clearSelectStatus() {
|
|
976
|
-
if (!this.moveable)
|
|
977
|
-
return;
|
|
954
|
+
if (!this.moveable) return;
|
|
978
955
|
this.dragResizeHelper.destroyShadowEl();
|
|
979
956
|
this.moveable.target = null;
|
|
980
957
|
this.moveable.updateRect();
|
|
@@ -1023,16 +1000,13 @@
|
|
|
1023
1000
|
this.bindScaleEvent();
|
|
1024
1001
|
}
|
|
1025
1002
|
bindResizeEvent() {
|
|
1026
|
-
if (!this.moveable)
|
|
1027
|
-
throw new Error("moveable 未初始化");
|
|
1003
|
+
if (!this.moveable) throw new Error("moveable 未初始化");
|
|
1028
1004
|
this.moveable.on("resizeStart", (e) => {
|
|
1029
|
-
if (!this.target)
|
|
1030
|
-
return;
|
|
1005
|
+
if (!this.target) return;
|
|
1031
1006
|
this.dragStatus = StageDragStatus.START;
|
|
1032
1007
|
this.dragResizeHelper.onResizeStart(e);
|
|
1033
1008
|
}).on("resize", (e) => {
|
|
1034
|
-
if (!this.moveable || !this.target || !this.dragResizeHelper.getShadowEl())
|
|
1035
|
-
return;
|
|
1009
|
+
if (!this.moveable || !this.target || !this.dragResizeHelper.getShadowEl()) return;
|
|
1036
1010
|
this.dragStatus = StageDragStatus.ING;
|
|
1037
1011
|
this.dragResizeHelper.onResize(e);
|
|
1038
1012
|
}).on("resizeEnd", () => {
|
|
@@ -1041,18 +1015,15 @@
|
|
|
1041
1015
|
});
|
|
1042
1016
|
}
|
|
1043
1017
|
bindDragEvent() {
|
|
1044
|
-
if (!this.moveable)
|
|
1045
|
-
throw new Error("moveable 未初始化");
|
|
1018
|
+
if (!this.moveable) throw new Error("moveable 未初始化");
|
|
1046
1019
|
let timeout;
|
|
1047
1020
|
this.moveable.on("dragStart", (e) => {
|
|
1048
|
-
if (!this.target)
|
|
1049
|
-
throw new Error("未选中组件");
|
|
1021
|
+
if (!this.target) throw new Error("未选中组件");
|
|
1050
1022
|
this.dragStatus = StageDragStatus.START;
|
|
1051
1023
|
this.dragResizeHelper.onDragStart(e);
|
|
1052
1024
|
this.emit("drag-start", e);
|
|
1053
1025
|
}).on("drag", (e) => {
|
|
1054
|
-
if (!this.target || !this.dragResizeHelper.getShadowEl())
|
|
1055
|
-
return;
|
|
1026
|
+
if (!this.target || !this.dragResizeHelper.getShadowEl()) return;
|
|
1056
1027
|
if (timeout) {
|
|
1057
1028
|
globalThis.clearTimeout(timeout);
|
|
1058
1029
|
timeout = void 0;
|
|
@@ -1084,14 +1055,12 @@
|
|
|
1084
1055
|
});
|
|
1085
1056
|
}
|
|
1086
1057
|
bindRotateEvent() {
|
|
1087
|
-
if (!this.moveable)
|
|
1088
|
-
throw new Error("moveable 未初始化");
|
|
1058
|
+
if (!this.moveable) throw new Error("moveable 未初始化");
|
|
1089
1059
|
this.moveable.on("rotateStart", (e) => {
|
|
1090
1060
|
this.dragStatus = StageDragStatus.START;
|
|
1091
1061
|
this.dragResizeHelper.onRotateStart(e);
|
|
1092
1062
|
}).on("rotate", (e) => {
|
|
1093
|
-
if (!this.target || !this.dragResizeHelper.getShadowEl())
|
|
1094
|
-
return;
|
|
1063
|
+
if (!this.target || !this.dragResizeHelper.getShadowEl()) return;
|
|
1095
1064
|
this.dragStatus = StageDragStatus.ING;
|
|
1096
1065
|
this.dragResizeHelper.onRotate(e);
|
|
1097
1066
|
}).on("rotateEnd", (e) => {
|
|
@@ -1113,14 +1082,12 @@
|
|
|
1113
1082
|
});
|
|
1114
1083
|
}
|
|
1115
1084
|
bindScaleEvent() {
|
|
1116
|
-
if (!this.moveable)
|
|
1117
|
-
throw new Error("moveable 未初始化");
|
|
1085
|
+
if (!this.moveable) throw new Error("moveable 未初始化");
|
|
1118
1086
|
this.moveable.on("scaleStart", (e) => {
|
|
1119
1087
|
this.dragStatus = StageDragStatus.START;
|
|
1120
1088
|
this.dragResizeHelper.onScaleStart(e);
|
|
1121
1089
|
}).on("scale", (e) => {
|
|
1122
|
-
if (!this.target || !this.dragResizeHelper.getShadowEl())
|
|
1123
|
-
return;
|
|
1090
|
+
if (!this.target || !this.dragResizeHelper.getShadowEl()) return;
|
|
1124
1091
|
this.dragStatus = StageDragStatus.ING;
|
|
1125
1092
|
this.dragResizeHelper.onScale(e);
|
|
1126
1093
|
}).on("scaleEnd", (e) => {
|
|
@@ -1142,8 +1109,7 @@
|
|
|
1142
1109
|
});
|
|
1143
1110
|
}
|
|
1144
1111
|
sort() {
|
|
1145
|
-
if (!this.target || !this.dragResizeHelper.getGhostEl())
|
|
1146
|
-
throw new Error("未知错误");
|
|
1112
|
+
if (!this.target || !this.dragResizeHelper.getGhostEl()) throw new Error("未知错误");
|
|
1147
1113
|
const { top } = this.dragResizeHelper.getGhostEl().getBoundingClientRect();
|
|
1148
1114
|
const { top: oriTop } = this.target.getBoundingClientRect();
|
|
1149
1115
|
const deltaTop = top - oriTop;
|
|
@@ -1161,11 +1127,9 @@
|
|
|
1161
1127
|
}
|
|
1162
1128
|
}
|
|
1163
1129
|
update(isResize = false, parentEl = null) {
|
|
1164
|
-
if (!this.target)
|
|
1165
|
-
return;
|
|
1130
|
+
if (!this.target) return;
|
|
1166
1131
|
const doc = this.getRenderDocument();
|
|
1167
|
-
if (!doc)
|
|
1168
|
-
return;
|
|
1132
|
+
if (!doc) return;
|
|
1169
1133
|
const rect = this.dragResizeHelper.getUpdatedElRect(this.target, parentEl, doc);
|
|
1170
1134
|
this.emit("update", {
|
|
1171
1135
|
data: [
|
|
@@ -1201,8 +1165,7 @@
|
|
|
1201
1165
|
* @param el 选中组件的Dom节点元素
|
|
1202
1166
|
*/
|
|
1203
1167
|
highlight(el) {
|
|
1204
|
-
if (!el || el === this.target)
|
|
1205
|
-
return;
|
|
1168
|
+
if (!el || el === this.target) return;
|
|
1206
1169
|
this.target = el;
|
|
1207
1170
|
this.targetShadow?.update(el);
|
|
1208
1171
|
if (this.moveable) {
|
|
@@ -1221,8 +1184,7 @@
|
|
|
1221
1184
|
* 清空高亮
|
|
1222
1185
|
*/
|
|
1223
1186
|
clearHighlight() {
|
|
1224
|
-
if (!this.moveable || !this.target)
|
|
1225
|
-
return;
|
|
1187
|
+
if (!this.moveable || !this.target) return;
|
|
1226
1188
|
this.moveable.zoom = 0;
|
|
1227
1189
|
this.moveable.updateRect();
|
|
1228
1190
|
this.target = void 0;
|
|
@@ -1341,10 +1303,8 @@
|
|
|
1341
1303
|
return true;
|
|
1342
1304
|
}
|
|
1343
1305
|
updateMoveable(eleList = this.targetList) {
|
|
1344
|
-
if (!this.moveableForMulti)
|
|
1345
|
-
|
|
1346
|
-
if (!eleList)
|
|
1347
|
-
throw new Error("未选中任何节点");
|
|
1306
|
+
if (!this.moveableForMulti) return;
|
|
1307
|
+
if (!eleList) throw new Error("未选中任何节点");
|
|
1348
1308
|
this.targetList = eleList;
|
|
1349
1309
|
this.dragResizeHelper.setTargetList(eleList);
|
|
1350
1310
|
const options = this.getOptions(true, {
|
|
@@ -1359,8 +1319,7 @@
|
|
|
1359
1319
|
* 清除多选状态
|
|
1360
1320
|
*/
|
|
1361
1321
|
clearSelectStatus() {
|
|
1362
|
-
if (!this.moveableForMulti)
|
|
1363
|
-
return;
|
|
1322
|
+
if (!this.moveableForMulti) return;
|
|
1364
1323
|
this.dragResizeHelper.clearMultiSelectStatus();
|
|
1365
1324
|
this.moveableForMulti.target = null;
|
|
1366
1325
|
this.moveableForMulti.updateTarget();
|
|
@@ -1384,11 +1343,9 @@
|
|
|
1384
1343
|
* @param isResize 是否进行大小缩放
|
|
1385
1344
|
*/
|
|
1386
1345
|
update(isResize = false, parentEl = null) {
|
|
1387
|
-
if (this.targetList.length === 0)
|
|
1388
|
-
return;
|
|
1346
|
+
if (this.targetList.length === 0) return;
|
|
1389
1347
|
const doc = this.getRenderDocument();
|
|
1390
|
-
if (!doc)
|
|
1391
|
-
return;
|
|
1348
|
+
if (!doc) return;
|
|
1392
1349
|
const data = this.targetList.map((targetItem) => {
|
|
1393
1350
|
const rect = this.dragResizeHelper.getUpdatedElRect(targetItem, parentEl, doc);
|
|
1394
1351
|
return {
|
|
@@ -1539,8 +1496,7 @@
|
|
|
1539
1496
|
const stop = () => stopped = true;
|
|
1540
1497
|
for (const el of els) {
|
|
1541
1498
|
if (!el.id.startsWith(GHOST_EL_ID_PREFIX) && await this.isElCanSelect(el, event, stop)) {
|
|
1542
|
-
if (stopped)
|
|
1543
|
-
break;
|
|
1499
|
+
if (stopped) break;
|
|
1544
1500
|
return el;
|
|
1545
1501
|
}
|
|
1546
1502
|
}
|
|
@@ -1555,8 +1511,7 @@
|
|
|
1555
1511
|
*/
|
|
1556
1512
|
async isElCanSelect(el, event, stop) {
|
|
1557
1513
|
const canSelectByProp = await this.canSelect(el, event, stop);
|
|
1558
|
-
if (!canSelectByProp)
|
|
1559
|
-
return false;
|
|
1514
|
+
if (!canSelectByProp) return false;
|
|
1560
1515
|
if (this.isMultiSelectStatus) {
|
|
1561
1516
|
return this.canMultiSelect(el, stop);
|
|
1562
1517
|
}
|
|
@@ -1610,8 +1565,7 @@
|
|
|
1610
1565
|
this.clearHighlight();
|
|
1611
1566
|
return;
|
|
1612
1567
|
}
|
|
1613
|
-
if (el === this.highlightedEl || !el)
|
|
1614
|
-
return;
|
|
1568
|
+
if (el === this.highlightedEl || !el) return;
|
|
1615
1569
|
this.highlightLayer.highlight(el);
|
|
1616
1570
|
this.highlightedEl = el;
|
|
1617
1571
|
this.emit("highlight", el);
|
|
@@ -1639,8 +1593,7 @@
|
|
|
1639
1593
|
*/
|
|
1640
1594
|
async addContainerHighlightClassName(event, excludeElList) {
|
|
1641
1595
|
const doc = this.getRenderDocument();
|
|
1642
|
-
if (!doc)
|
|
1643
|
-
return;
|
|
1596
|
+
if (!doc) return;
|
|
1644
1597
|
const els = this.getElementsFromPoint(event);
|
|
1645
1598
|
for (const el of els) {
|
|
1646
1599
|
if (!el.id.startsWith(GHOST_EL_ID_PREFIX) && await this.isContainer?.(el) && !excludeElList.includes(el)) {
|
|
@@ -1706,8 +1659,7 @@
|
|
|
1706
1659
|
this.emit("select-parent");
|
|
1707
1660
|
}).on(AbleActionEventType.REMOVE, () => {
|
|
1708
1661
|
const drTarget = this.dr.getTarget();
|
|
1709
|
-
if (!drTarget)
|
|
1710
|
-
return;
|
|
1662
|
+
if (!drTarget) return;
|
|
1711
1663
|
const data = {
|
|
1712
1664
|
data: [{ el: drTarget }]
|
|
1713
1665
|
};
|
|
@@ -1734,8 +1686,7 @@
|
|
|
1734
1686
|
multiDr?.on("update", (data) => {
|
|
1735
1687
|
this.emit("multi-update", data);
|
|
1736
1688
|
}).on("change-to-select", (id, e) => {
|
|
1737
|
-
if (this.isMultiSelectStatus)
|
|
1738
|
-
return;
|
|
1689
|
+
if (this.isMultiSelectStatus) return;
|
|
1739
1690
|
this.emit("change-to-select", id, e);
|
|
1740
1691
|
});
|
|
1741
1692
|
return multiDr;
|
|
@@ -1766,8 +1717,7 @@
|
|
|
1766
1717
|
*/
|
|
1767
1718
|
async beforeMultiSelect(event) {
|
|
1768
1719
|
const el = await this.getElementFromPoint(event);
|
|
1769
|
-
if (!el)
|
|
1770
|
-
return;
|
|
1720
|
+
if (!el) return;
|
|
1771
1721
|
if (this.selectedEl && !this.selectedEl.className.includes(PAGE_CLASS)) {
|
|
1772
1722
|
this.selectedElList.push(this.selectedEl);
|
|
1773
1723
|
this.setSelectedEl(null);
|
|
@@ -1845,8 +1795,7 @@
|
|
|
1845
1795
|
this.clearHighlight();
|
|
1846
1796
|
event.stopImmediatePropagation();
|
|
1847
1797
|
event.stopPropagation();
|
|
1848
|
-
if (this.isStopTriggerSelect(event))
|
|
1849
|
-
return;
|
|
1798
|
+
if (this.isStopTriggerSelect(event)) return;
|
|
1850
1799
|
this.container.removeEventListener("mousemove", this.mouseMoveHandler);
|
|
1851
1800
|
if (this.isMultiSelectStatus) {
|
|
1852
1801
|
await this.beforeMultiSelect(event);
|
|
@@ -1855,17 +1804,14 @@
|
|
|
1855
1804
|
}
|
|
1856
1805
|
} else {
|
|
1857
1806
|
const el = await this.getElementFromPoint(event);
|
|
1858
|
-
if (!el)
|
|
1859
|
-
return;
|
|
1807
|
+
if (!el) return;
|
|
1860
1808
|
this.emit("before-select", el, event);
|
|
1861
1809
|
}
|
|
1862
1810
|
utils.getDocument().addEventListener("mouseup", this.mouseUpHandler);
|
|
1863
1811
|
};
|
|
1864
1812
|
isStopTriggerSelect(event) {
|
|
1865
|
-
if (event.button !== MouseButton.LEFT && event.button !== MouseButton.RIGHT)
|
|
1866
|
-
|
|
1867
|
-
if (!event.target)
|
|
1868
|
-
return true;
|
|
1813
|
+
if (event.button !== MouseButton.LEFT && event.button !== MouseButton.RIGHT) return true;
|
|
1814
|
+
if (!event.target) return true;
|
|
1869
1815
|
const targetClassList = event.target.classList;
|
|
1870
1816
|
if (!this.isMultiSelectStatus && targetClassList.contains("moveable-area")) {
|
|
1871
1817
|
return true;
|
|
@@ -2107,8 +2053,7 @@
|
|
|
2107
2053
|
* @param page 页面Dom节点
|
|
2108
2054
|
*/
|
|
2109
2055
|
observe(page) {
|
|
2110
|
-
if (!page)
|
|
2111
|
-
return;
|
|
2056
|
+
if (!page) return;
|
|
2112
2057
|
this.page = page;
|
|
2113
2058
|
this.initObserverIntersection();
|
|
2114
2059
|
this.initObserverWrapper();
|
|
@@ -2136,19 +2081,16 @@
|
|
|
2136
2081
|
* @param el 将蒙层挂载到该Dom节点上
|
|
2137
2082
|
*/
|
|
2138
2083
|
mount(el) {
|
|
2139
|
-
if (!this.content)
|
|
2140
|
-
throw new Error("content 不存在");
|
|
2084
|
+
if (!this.content) throw new Error("content 不存在");
|
|
2141
2085
|
el.appendChild(this.wrapper);
|
|
2142
2086
|
}
|
|
2143
2087
|
setLayout(el) {
|
|
2144
2088
|
this.setMode(isFixedParent(el) ? Mode.FIXED : Mode.ABSOLUTE);
|
|
2145
2089
|
}
|
|
2146
2090
|
scrollIntoView(el) {
|
|
2147
|
-
if (!this.page || el.getBoundingClientRect().left >= this.page.scrollWidth)
|
|
2148
|
-
return;
|
|
2091
|
+
if (!this.page || el.getBoundingClientRect().left >= this.page.scrollWidth) return;
|
|
2149
2092
|
el.scrollIntoView();
|
|
2150
|
-
if (!this.pageScrollParent)
|
|
2151
|
-
return;
|
|
2093
|
+
if (!this.pageScrollParent) return;
|
|
2152
2094
|
this.scrollLeft = this.pageScrollParent.scrollLeft;
|
|
2153
2095
|
this.scrollTop = this.pageScrollParent.scrollTop;
|
|
2154
2096
|
this.scroll();
|
|
@@ -2272,23 +2214,16 @@
|
|
|
2272
2214
|
* 由于滚动容器变化等因素,会导致当前滚动的距离不正确
|
|
2273
2215
|
*/
|
|
2274
2216
|
fixScrollValue() {
|
|
2275
|
-
if (this.scrollTop < 0)
|
|
2276
|
-
|
|
2277
|
-
if (this.
|
|
2278
|
-
|
|
2279
|
-
if (this.maxScrollTop < this.scrollTop)
|
|
2280
|
-
this.scrollTop = this.maxScrollTop;
|
|
2281
|
-
if (this.maxScrollLeft < this.scrollLeft)
|
|
2282
|
-
this.scrollLeft = this.maxScrollLeft;
|
|
2217
|
+
if (this.scrollTop < 0) this.scrollTop = 0;
|
|
2218
|
+
if (this.scrollLeft < 0) this.scrollLeft = 0;
|
|
2219
|
+
if (this.maxScrollTop < this.scrollTop) this.scrollTop = this.maxScrollTop;
|
|
2220
|
+
if (this.maxScrollLeft < this.scrollLeft) this.scrollLeft = this.maxScrollLeft;
|
|
2283
2221
|
}
|
|
2284
2222
|
mouseWheelHandler = (event) => {
|
|
2285
|
-
if (!this.page)
|
|
2286
|
-
throw new Error("page 未初始化");
|
|
2223
|
+
if (!this.page) throw new Error("page 未初始化");
|
|
2287
2224
|
const { deltaY, deltaX } = event;
|
|
2288
|
-
if (this.page.clientHeight < this.wrapperHeight && deltaY)
|
|
2289
|
-
|
|
2290
|
-
if (this.page.clientWidth < this.wrapperWidth && deltaX)
|
|
2291
|
-
return;
|
|
2225
|
+
if (this.page.clientHeight < this.wrapperHeight && deltaY) return;
|
|
2226
|
+
if (this.page.clientWidth < this.wrapperWidth && deltaX) return;
|
|
2292
2227
|
if (this.maxScrollTop > 0) {
|
|
2293
2228
|
this.scrollTop = this.scrollTop + deltaY;
|
|
2294
2229
|
}
|
|
@@ -2374,8 +2309,7 @@
|
|
|
2374
2309
|
}
|
|
2375
2310
|
}
|
|
2376
2311
|
getRuntime = () => {
|
|
2377
|
-
if (this.runtime)
|
|
2378
|
-
return Promise.resolve(this.runtime);
|
|
2312
|
+
if (this.runtime) return Promise.resolve(this.runtime);
|
|
2379
2313
|
return new Promise((resolve) => {
|
|
2380
2314
|
const listener = (runtime) => {
|
|
2381
2315
|
this.off("runtime-ready", listener);
|
|
@@ -2460,8 +2394,7 @@
|
|
|
2460
2394
|
if (!this.contentWindow?.magic) {
|
|
2461
2395
|
this.postTmagicRuntimeReady();
|
|
2462
2396
|
}
|
|
2463
|
-
if (!this.contentWindow)
|
|
2464
|
-
return;
|
|
2397
|
+
if (!this.contentWindow) return;
|
|
2465
2398
|
if (this.customizedRender) {
|
|
2466
2399
|
const el = await this.customizedRender();
|
|
2467
2400
|
if (el) {
|
|
@@ -2520,8 +2453,7 @@
|
|
|
2520
2453
|
*/
|
|
2521
2454
|
async select(id, event) {
|
|
2522
2455
|
const el = this.renderer.getTargetElement(id);
|
|
2523
|
-
if (el === this.actionManager.getSelectedEl())
|
|
2524
|
-
return;
|
|
2456
|
+
if (el === this.actionManager.getSelectedEl()) return;
|
|
2525
2457
|
await this.renderer.select([id]);
|
|
2526
2458
|
el && this.mask.setLayout(el);
|
|
2527
2459
|
this.actionManager.select(el, event);
|
|
@@ -2535,8 +2467,7 @@
|
|
|
2535
2467
|
*/
|
|
2536
2468
|
async multiSelect(ids) {
|
|
2537
2469
|
const els = ids.map((id) => this.renderer.getTargetElement(id)).filter((el) => Boolean(el));
|
|
2538
|
-
if (els.length === 0)
|
|
2539
|
-
return;
|
|
2470
|
+
if (els.length === 0) return;
|
|
2540
2471
|
const lastEl = els[els.length - 1];
|
|
2541
2472
|
const isReduceSelect = els.length < this.actionManager.getSelectedElList().length;
|
|
2542
2473
|
await this.renderer.select(ids);
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.4.
|
|
2
|
+
"version": "1.4.8",
|
|
3
3
|
"name": "@tmagic/stage",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": [
|
|
@@ -16,6 +16,10 @@
|
|
|
16
16
|
},
|
|
17
17
|
"./*": "./*"
|
|
18
18
|
},
|
|
19
|
+
"files": [
|
|
20
|
+
"dist",
|
|
21
|
+
"types"
|
|
22
|
+
],
|
|
19
23
|
"license": "Apache-2.0",
|
|
20
24
|
"engines": {
|
|
21
25
|
"node": ">=18"
|
|
@@ -38,13 +42,13 @@
|
|
|
38
42
|
"@types/node": "^18.19.0",
|
|
39
43
|
"rimraf": "^3.0.2",
|
|
40
44
|
"sass": "^1.77.0",
|
|
41
|
-
"vite": "^5.
|
|
45
|
+
"vite": "^5.3.1"
|
|
42
46
|
},
|
|
43
47
|
"peerDependencies": {
|
|
44
48
|
"typescript": "*",
|
|
45
|
-
"@tmagic/core": "1.4.
|
|
46
|
-
"@tmagic/utils": "1.4.
|
|
47
|
-
"@tmagic/schema": "1.4.
|
|
49
|
+
"@tmagic/core": "1.4.8",
|
|
50
|
+
"@tmagic/utils": "1.4.8",
|
|
51
|
+
"@tmagic/schema": "1.4.8"
|
|
48
52
|
},
|
|
49
53
|
"peerDependenciesMeta": {
|
|
50
54
|
"typescript": {
|