@tmagic/stage 1.3.16 → 1.4.0-beta.2
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/README.md +2 -2
- package/dist/tmagic-stage.js +155 -103
- package/dist/tmagic-stage.umd.cjs +155 -103
- package/package.json +6 -6
- package/src/ActionManager.ts +57 -24
- package/src/DragResizeHelper.ts +12 -8
- package/src/MoveableActionsAble.ts +1 -1
- package/src/StageCore.ts +41 -25
- package/src/StageDragResize.ts +50 -23
- package/src/StageMask.ts +12 -1
- package/src/StageMultiDragResize.ts +18 -3
- package/src/StageRender.ts +22 -26
- package/src/TargetShadow.ts +1 -1
- package/src/const.ts +31 -0
- package/src/types.ts +73 -37
- package/src/util.ts +2 -2
- package/types/ActionManager.d.ts +10 -8
- package/types/DragResizeHelper.d.ts +2 -2
- package/types/StageCore.d.ts +9 -7
- package/types/StageDragResize.d.ts +8 -6
- package/types/StageMask.d.ts +3 -1
- package/types/StageMultiDragResize.d.ts +5 -2
- package/types/StageRender.d.ts +5 -3
- package/types/const.d.ts +27 -0
- package/types/types.d.ts +67 -33
- package/types/util.d.ts +2 -2
|
@@ -41,6 +41,27 @@
|
|
|
41
41
|
AbleActionEventType2["REMOVE"] = "remove";
|
|
42
42
|
return AbleActionEventType2;
|
|
43
43
|
})(AbleActionEventType || {});
|
|
44
|
+
var ContainerHighlightType = /* @__PURE__ */ ((ContainerHighlightType2) => {
|
|
45
|
+
ContainerHighlightType2["DEFAULT"] = "default";
|
|
46
|
+
ContainerHighlightType2["ALT"] = "alt";
|
|
47
|
+
return ContainerHighlightType2;
|
|
48
|
+
})(ContainerHighlightType || {});
|
|
49
|
+
var RenderType = /* @__PURE__ */ ((RenderType2) => {
|
|
50
|
+
RenderType2["IFRAME"] = "iframe";
|
|
51
|
+
RenderType2["NATIVE"] = "native";
|
|
52
|
+
return RenderType2;
|
|
53
|
+
})(RenderType || {});
|
|
54
|
+
var SelectStatus = /* @__PURE__ */ ((SelectStatus2) => {
|
|
55
|
+
SelectStatus2["SELECT"] = "select";
|
|
56
|
+
SelectStatus2["MULTI_SELECT"] = "multiSelect";
|
|
57
|
+
return SelectStatus2;
|
|
58
|
+
})(SelectStatus || {});
|
|
59
|
+
var StageDragStatus = /* @__PURE__ */ ((StageDragStatus2) => {
|
|
60
|
+
StageDragStatus2["START"] = "start";
|
|
61
|
+
StageDragStatus2["ING"] = "ing";
|
|
62
|
+
StageDragStatus2["END"] = "end";
|
|
63
|
+
return StageDragStatus2;
|
|
64
|
+
})(StageDragStatus || {});
|
|
44
65
|
|
|
45
66
|
const getParents = (el, relative) => {
|
|
46
67
|
let cur = el.parentElement;
|
|
@@ -299,7 +320,7 @@
|
|
|
299
320
|
}
|
|
300
321
|
updateEl(target, src) {
|
|
301
322
|
const el = src || globalThis.document.createElement("div");
|
|
302
|
-
el.id = `${this.idPrefix}${target.id}`;
|
|
323
|
+
el.id = `${this.idPrefix}_${target.id}`;
|
|
303
324
|
el.style.cssText = getTargetElStyle(target, this.zIndex);
|
|
304
325
|
if (typeof this.updateDragEl === "function") {
|
|
305
326
|
this.updateDragEl(el, target, this.container);
|
|
@@ -475,6 +496,7 @@
|
|
|
475
496
|
*/
|
|
476
497
|
onResizeGroup(e) {
|
|
477
498
|
const { events } = e;
|
|
499
|
+
this.moveableHelper.onResizeGroup(e);
|
|
478
500
|
events.forEach((ev) => {
|
|
479
501
|
const { width, height, beforeTranslate } = ev.drag;
|
|
480
502
|
const frameSnapShot = this.framesSnapShot.find(
|
|
@@ -496,23 +518,23 @@
|
|
|
496
518
|
targeEl.style.width = `${width}px`;
|
|
497
519
|
targeEl.style.height = `${height}px`;
|
|
498
520
|
});
|
|
499
|
-
this.moveableHelper.onResizeGroup(e);
|
|
500
521
|
}
|
|
501
522
|
onDragGroupStart(e) {
|
|
502
|
-
const { events } = e;
|
|
503
523
|
this.moveableHelper.onDragGroupStart(e);
|
|
524
|
+
const { events } = e;
|
|
504
525
|
this.setFramesSnapShot(events);
|
|
505
526
|
}
|
|
506
527
|
onDragGroup(e) {
|
|
528
|
+
this.moveableHelper.onDragGroup(e);
|
|
507
529
|
const { events } = e;
|
|
508
530
|
events.forEach((ev) => {
|
|
509
531
|
const frameSnapShot = this.framesSnapShot.find(
|
|
510
|
-
(frameItem) =>
|
|
532
|
+
(frameItem) => ev.target.id.startsWith(DRAG_EL_ID_PREFIX) && ev.target.id.endsWith(frameItem.id)
|
|
511
533
|
);
|
|
512
534
|
if (!frameSnapShot)
|
|
513
535
|
return;
|
|
514
536
|
const targeEl = this.targetList.find(
|
|
515
|
-
(targetItem) =>
|
|
537
|
+
(targetItem) => ev.target.id.startsWith(DRAG_EL_ID_PREFIX) && ev.target.id.endsWith(targetItem.id)
|
|
516
538
|
);
|
|
517
539
|
if (!targeEl)
|
|
518
540
|
return;
|
|
@@ -523,7 +545,6 @@
|
|
|
523
545
|
targeEl.style.top = `${frameSnapShot.top + ev.beforeTranslate[1] - marginTop}px`;
|
|
524
546
|
}
|
|
525
547
|
});
|
|
526
|
-
this.moveableHelper.onDragGroup(e);
|
|
527
548
|
}
|
|
528
549
|
getUpdatedElRect(el, parentEl, doc) {
|
|
529
550
|
const offset = this.mode === Mode.SORTABLE ? { left: 0, top: 0 } : { left: el.offsetLeft, top: el.offsetTop };
|
|
@@ -558,7 +579,7 @@
|
|
|
558
579
|
return;
|
|
559
580
|
events.forEach((ev) => {
|
|
560
581
|
const matchEventTarget = this.targetList.find(
|
|
561
|
-
(targetItem) =>
|
|
582
|
+
(targetItem) => ev.target.id.startsWith(DRAG_EL_ID_PREFIX) && ev.target.id.endsWith(targetItem.id)
|
|
562
583
|
);
|
|
563
584
|
if (!matchEventTarget)
|
|
564
585
|
return;
|
|
@@ -619,7 +640,7 @@
|
|
|
619
640
|
left: 0px;
|
|
620
641
|
top: 0px;
|
|
621
642
|
will-change: transform;
|
|
622
|
-
transform-origin:
|
|
643
|
+
transform-origin: 60px 28px;
|
|
623
644
|
display: flex;
|
|
624
645
|
}
|
|
625
646
|
${ableCss}
|
|
@@ -896,31 +917,9 @@
|
|
|
896
917
|
}
|
|
897
918
|
}
|
|
898
919
|
|
|
899
|
-
var ContainerHighlightType = /* @__PURE__ */ ((ContainerHighlightType2) => {
|
|
900
|
-
ContainerHighlightType2["DEFAULT"] = "default";
|
|
901
|
-
ContainerHighlightType2["ALT"] = "alt";
|
|
902
|
-
return ContainerHighlightType2;
|
|
903
|
-
})(ContainerHighlightType || {});
|
|
904
|
-
var RenderType = /* @__PURE__ */ ((RenderType2) => {
|
|
905
|
-
RenderType2["IFRAME"] = "iframe";
|
|
906
|
-
RenderType2["NATIVE"] = "native";
|
|
907
|
-
return RenderType2;
|
|
908
|
-
})(RenderType || {});
|
|
909
|
-
var SelectStatus = /* @__PURE__ */ ((SelectStatus2) => {
|
|
910
|
-
SelectStatus2["SELECT"] = "select";
|
|
911
|
-
SelectStatus2["MULTI_SELECT"] = "multiSelect";
|
|
912
|
-
return SelectStatus2;
|
|
913
|
-
})(SelectStatus || {});
|
|
914
|
-
var StageDragStatus = /* @__PURE__ */ ((StageDragStatus2) => {
|
|
915
|
-
StageDragStatus2["START"] = "start";
|
|
916
|
-
StageDragStatus2["ING"] = "ing";
|
|
917
|
-
StageDragStatus2["END"] = "end";
|
|
918
|
-
return StageDragStatus2;
|
|
919
|
-
})(StageDragStatus || {});
|
|
920
|
-
|
|
921
920
|
class StageDragResize extends MoveableOptionsManager {
|
|
922
921
|
/** 目标节点 */
|
|
923
|
-
target;
|
|
922
|
+
target = null;
|
|
924
923
|
/** Moveable拖拽类实例 */
|
|
925
924
|
moveable;
|
|
926
925
|
/** 拖动状态 */
|
|
@@ -953,6 +952,11 @@
|
|
|
953
952
|
* @param event 鼠标事件
|
|
954
953
|
*/
|
|
955
954
|
select(el, event) {
|
|
955
|
+
if (!el) {
|
|
956
|
+
this.moveable?.destroy();
|
|
957
|
+
this.moveable = void 0;
|
|
958
|
+
return;
|
|
959
|
+
}
|
|
956
960
|
if (!this.moveable || el !== this.target) {
|
|
957
961
|
this.initMoveable(el);
|
|
958
962
|
} else {
|
|
@@ -995,6 +999,12 @@
|
|
|
995
999
|
this.dragStatus = StageDragStatus.END;
|
|
996
1000
|
this.removeAllListeners();
|
|
997
1001
|
}
|
|
1002
|
+
on(eventName, listener) {
|
|
1003
|
+
return super.on(eventName, listener);
|
|
1004
|
+
}
|
|
1005
|
+
emit(eventName, ...args) {
|
|
1006
|
+
return super.emit(eventName, ...args);
|
|
1007
|
+
}
|
|
998
1008
|
init(el) {
|
|
999
1009
|
if (/(auto|scroll)/.test(el.style.overflow)) {
|
|
1000
1010
|
el.style.overflow = "hidden";
|
|
@@ -1095,16 +1105,19 @@
|
|
|
1095
1105
|
}).on("rotateEnd", (e) => {
|
|
1096
1106
|
this.dragStatus = StageDragStatus.END;
|
|
1097
1107
|
const frame = this.dragResizeHelper?.getFrame(e.target);
|
|
1098
|
-
this.
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1108
|
+
if (this.target && frame) {
|
|
1109
|
+
this.emit("update", {
|
|
1110
|
+
data: [
|
|
1111
|
+
{
|
|
1112
|
+
el: this.target,
|
|
1113
|
+
style: {
|
|
1114
|
+
transform: frame.get("transform")
|
|
1115
|
+
}
|
|
1104
1116
|
}
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1117
|
+
],
|
|
1118
|
+
parentEl: null
|
|
1119
|
+
});
|
|
1120
|
+
}
|
|
1108
1121
|
});
|
|
1109
1122
|
}
|
|
1110
1123
|
bindScaleEvent() {
|
|
@@ -1121,16 +1134,19 @@
|
|
|
1121
1134
|
}).on("scaleEnd", (e) => {
|
|
1122
1135
|
this.dragStatus = StageDragStatus.END;
|
|
1123
1136
|
const frame = this.dragResizeHelper.getFrame(e.target);
|
|
1124
|
-
this.
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1137
|
+
if (this.target && frame) {
|
|
1138
|
+
this.emit("update", {
|
|
1139
|
+
data: [
|
|
1140
|
+
{
|
|
1141
|
+
el: this.target,
|
|
1142
|
+
style: {
|
|
1143
|
+
transform: frame.get("transform")
|
|
1144
|
+
}
|
|
1130
1145
|
}
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1146
|
+
],
|
|
1147
|
+
parentEl: null
|
|
1148
|
+
});
|
|
1149
|
+
}
|
|
1134
1150
|
});
|
|
1135
1151
|
}
|
|
1136
1152
|
sort() {
|
|
@@ -1302,6 +1318,10 @@
|
|
|
1302
1318
|
this.dragResizeHelper.onDragGroup(e);
|
|
1303
1319
|
this.dragStatus = StageDragStatus.ING;
|
|
1304
1320
|
}).on("dragGroupEnd", () => {
|
|
1321
|
+
if (timeout) {
|
|
1322
|
+
globalThis.clearTimeout(timeout);
|
|
1323
|
+
timeout = void 0;
|
|
1324
|
+
}
|
|
1305
1325
|
const parentEl = this.markContainerEnd();
|
|
1306
1326
|
this.update(false, parentEl);
|
|
1307
1327
|
this.dragStatus = StageDragStatus.END;
|
|
@@ -1361,6 +1381,12 @@
|
|
|
1361
1381
|
this.moveableForMulti?.destroy();
|
|
1362
1382
|
this.dragResizeHelper.destroy();
|
|
1363
1383
|
}
|
|
1384
|
+
on(eventName, listener) {
|
|
1385
|
+
return super.on(eventName, listener);
|
|
1386
|
+
}
|
|
1387
|
+
emit(eventName, ...args) {
|
|
1388
|
+
return super.emit(eventName, ...args);
|
|
1389
|
+
}
|
|
1364
1390
|
/**
|
|
1365
1391
|
* 拖拽完成后将更新的位置信息暴露给上层业务方,业务方可以接收事件进行保存
|
|
1366
1392
|
* @param isResize 是否进行大小缩放
|
|
@@ -1391,7 +1417,7 @@
|
|
|
1391
1417
|
/** 单选、多选、高亮的容器(蒙层的content) */
|
|
1392
1418
|
container;
|
|
1393
1419
|
/** 当前选中的节点 */
|
|
1394
|
-
selectedEl;
|
|
1420
|
+
selectedEl = null;
|
|
1395
1421
|
/** 多选选中的节点组 */
|
|
1396
1422
|
selectedElList = [];
|
|
1397
1423
|
/** 当前高亮的节点 */
|
|
@@ -1422,7 +1448,7 @@
|
|
|
1422
1448
|
return;
|
|
1423
1449
|
}
|
|
1424
1450
|
this.emit("mousemove", event);
|
|
1425
|
-
this.highlight(el);
|
|
1451
|
+
this.highlight(el.id);
|
|
1426
1452
|
}, throttleTime);
|
|
1427
1453
|
constructor(config) {
|
|
1428
1454
|
super();
|
|
@@ -1526,6 +1552,7 @@
|
|
|
1526
1552
|
return el;
|
|
1527
1553
|
}
|
|
1528
1554
|
}
|
|
1555
|
+
return null;
|
|
1529
1556
|
}
|
|
1530
1557
|
/**
|
|
1531
1558
|
* 判断一个元素能否在当前场景被选中
|
|
@@ -1562,8 +1589,14 @@
|
|
|
1562
1589
|
this.clearSelectStatus(SelectStatus.MULTI_SELECT);
|
|
1563
1590
|
this.dr.select(el, event);
|
|
1564
1591
|
}
|
|
1565
|
-
multiSelect(
|
|
1566
|
-
this.selectedElList =
|
|
1592
|
+
multiSelect(ids) {
|
|
1593
|
+
this.selectedElList = [];
|
|
1594
|
+
ids.forEach((id) => {
|
|
1595
|
+
const el = this.getTargetElement(id);
|
|
1596
|
+
if (el) {
|
|
1597
|
+
this.selectedElList.push(el);
|
|
1598
|
+
}
|
|
1599
|
+
});
|
|
1567
1600
|
this.clearSelectStatus(SelectStatus.SELECT);
|
|
1568
1601
|
this.multiDr?.multiSelect(this.selectedElList);
|
|
1569
1602
|
}
|
|
@@ -1573,10 +1606,10 @@
|
|
|
1573
1606
|
setHighlightEl(el) {
|
|
1574
1607
|
this.highlightedEl = el;
|
|
1575
1608
|
}
|
|
1576
|
-
highlight(
|
|
1609
|
+
highlight(id) {
|
|
1577
1610
|
let el;
|
|
1578
1611
|
try {
|
|
1579
|
-
el = this.getTargetElement(
|
|
1612
|
+
el = this.getTargetElement(id);
|
|
1580
1613
|
} catch (error) {
|
|
1581
1614
|
this.clearHighlight();
|
|
1582
1615
|
return;
|
|
@@ -1652,6 +1685,12 @@
|
|
|
1652
1685
|
this.multiDr?.destroy();
|
|
1653
1686
|
this.highlightLayer.destroy();
|
|
1654
1687
|
}
|
|
1688
|
+
on(eventName, listener) {
|
|
1689
|
+
return super.on(eventName, listener);
|
|
1690
|
+
}
|
|
1691
|
+
emit(eventName, ...args) {
|
|
1692
|
+
return super.emit(eventName, ...args);
|
|
1693
|
+
}
|
|
1655
1694
|
createDr(config) {
|
|
1656
1695
|
const createDrHelper = () => new DragResizeHelper({
|
|
1657
1696
|
container: config.container,
|
|
@@ -1671,9 +1710,9 @@
|
|
|
1671
1710
|
setTimeout(() => this.emit("update", data));
|
|
1672
1711
|
}).on("sort", (data) => {
|
|
1673
1712
|
setTimeout(() => this.emit("sort", data));
|
|
1674
|
-
}).on(
|
|
1713
|
+
}).on(AbleActionEventType.SELECT_PARENT, () => {
|
|
1675
1714
|
this.emit("select-parent");
|
|
1676
|
-
}).on(
|
|
1715
|
+
}).on(AbleActionEventType.REMOVE, () => {
|
|
1677
1716
|
const drTarget = this.dr.getTarget();
|
|
1678
1717
|
if (!drTarget)
|
|
1679
1718
|
return;
|
|
@@ -1702,11 +1741,10 @@
|
|
|
1702
1741
|
});
|
|
1703
1742
|
multiDr?.on("update", (data) => {
|
|
1704
1743
|
this.emit("multi-update", data);
|
|
1705
|
-
}).on("change-to-select",
|
|
1744
|
+
}).on("change-to-select", (id, e) => {
|
|
1706
1745
|
if (this.isMultiSelectStatus)
|
|
1707
|
-
return
|
|
1708
|
-
|
|
1709
|
-
this.emit("change-to-select", el, e);
|
|
1746
|
+
return;
|
|
1747
|
+
this.emit("change-to-select", id, e);
|
|
1710
1748
|
});
|
|
1711
1749
|
return multiDr;
|
|
1712
1750
|
}
|
|
@@ -1740,11 +1778,13 @@
|
|
|
1740
1778
|
return;
|
|
1741
1779
|
if (this.selectedEl && !this.selectedEl.className.includes(PAGE_CLASS)) {
|
|
1742
1780
|
this.selectedElList.push(this.selectedEl);
|
|
1743
|
-
this.setSelectedEl(
|
|
1781
|
+
this.setSelectedEl(null);
|
|
1744
1782
|
}
|
|
1745
1783
|
const existIndex = this.selectedElList.findIndex((selectedDom) => selectedDom.id === el.id);
|
|
1746
1784
|
if (existIndex !== -1) {
|
|
1747
|
-
this.selectedElList.
|
|
1785
|
+
if (this.selectedElList.length > 1) {
|
|
1786
|
+
this.selectedElList.splice(existIndex, 1);
|
|
1787
|
+
}
|
|
1748
1788
|
} else {
|
|
1749
1789
|
this.selectedElList.push(el);
|
|
1750
1790
|
}
|
|
@@ -2131,6 +2171,12 @@
|
|
|
2131
2171
|
this.wrapperResizeObserver?.disconnect();
|
|
2132
2172
|
super.destroy();
|
|
2133
2173
|
}
|
|
2174
|
+
on(eventName, listener) {
|
|
2175
|
+
return super.on(eventName, listener);
|
|
2176
|
+
}
|
|
2177
|
+
emit(eventName, ...args) {
|
|
2178
|
+
return super.emit(eventName, ...args);
|
|
2179
|
+
}
|
|
2134
2180
|
/**
|
|
2135
2181
|
* 监听选中元素是否在画布可视区域内,如果目标元素不在可视区域内,通过滚动使该元素出现在可视区域
|
|
2136
2182
|
*/
|
|
@@ -2306,14 +2352,11 @@
|
|
|
2306
2352
|
const runtime = await this.getRuntime();
|
|
2307
2353
|
runtime?.update?.(data);
|
|
2308
2354
|
}
|
|
2309
|
-
async select(
|
|
2355
|
+
async select(ids) {
|
|
2310
2356
|
const runtime = await this.getRuntime();
|
|
2311
|
-
for (const
|
|
2312
|
-
await runtime?.select?.(
|
|
2313
|
-
|
|
2314
|
-
await runtime.beforeSelect(el);
|
|
2315
|
-
}
|
|
2316
|
-
this.flagSelectedEl(el);
|
|
2357
|
+
for (const id of ids) {
|
|
2358
|
+
await runtime?.select?.(id);
|
|
2359
|
+
this.flagSelectedEl(this.getTargetElement(id));
|
|
2317
2360
|
}
|
|
2318
2361
|
}
|
|
2319
2362
|
setZoom(zoom = DEFAULT_ZOOM) {
|
|
@@ -2369,14 +2412,8 @@
|
|
|
2369
2412
|
}
|
|
2370
2413
|
return this.getDocument()?.elementsFromPoint(x / this.zoom, y / this.zoom);
|
|
2371
2414
|
}
|
|
2372
|
-
getTargetElement(
|
|
2373
|
-
|
|
2374
|
-
const el = this.getDocument()?.getElementById(`${idOrEl}`);
|
|
2375
|
-
if (!el)
|
|
2376
|
-
throw new Error(`不存在ID为${idOrEl}的元素`);
|
|
2377
|
-
return el;
|
|
2378
|
-
}
|
|
2379
|
-
return idOrEl;
|
|
2415
|
+
getTargetElement(id) {
|
|
2416
|
+
return this.getDocument()?.getElementById(`${id}`) || null;
|
|
2380
2417
|
}
|
|
2381
2418
|
/**
|
|
2382
2419
|
* 销毁实例
|
|
@@ -2388,6 +2425,12 @@
|
|
|
2388
2425
|
this.iframe = void 0;
|
|
2389
2426
|
this.removeAllListeners();
|
|
2390
2427
|
}
|
|
2428
|
+
on(eventName, listener) {
|
|
2429
|
+
return super.on(eventName, listener);
|
|
2430
|
+
}
|
|
2431
|
+
emit(eventName, ...args) {
|
|
2432
|
+
return super.emit(eventName, ...args);
|
|
2433
|
+
}
|
|
2391
2434
|
createIframe() {
|
|
2392
2435
|
this.iframe = globalThis.document.createElement("iframe");
|
|
2393
2436
|
this.iframe.src = this.runtimeUrl && utils.isSameDomain(this.runtimeUrl) ? this.runtimeUrl : "";
|
|
@@ -2418,7 +2461,7 @@
|
|
|
2418
2461
|
const doc = this.getDocument();
|
|
2419
2462
|
if (doc) {
|
|
2420
2463
|
removeSelectedClassName(doc);
|
|
2421
|
-
addSelectedClassName(el, doc);
|
|
2464
|
+
el && addSelectedClassName(el, doc);
|
|
2422
2465
|
}
|
|
2423
2466
|
}
|
|
2424
2467
|
iframeLoadHandler = async () => {
|
|
@@ -2481,33 +2524,33 @@
|
|
|
2481
2524
|
}
|
|
2482
2525
|
/**
|
|
2483
2526
|
* 单选选中元素
|
|
2484
|
-
* @param
|
|
2527
|
+
* @param id 选中的id
|
|
2485
2528
|
*/
|
|
2486
|
-
async select(
|
|
2487
|
-
const el = this.renderer.getTargetElement(
|
|
2529
|
+
async select(id, event) {
|
|
2530
|
+
const el = this.renderer.getTargetElement(id);
|
|
2488
2531
|
if (el === this.actionManager.getSelectedEl())
|
|
2489
2532
|
return;
|
|
2490
|
-
await this.renderer.select([
|
|
2491
|
-
this.mask.setLayout(el);
|
|
2533
|
+
await this.renderer.select([id]);
|
|
2534
|
+
el && this.mask.setLayout(el);
|
|
2492
2535
|
this.actionManager.select(el, event);
|
|
2493
|
-
if (this.autoScrollIntoView || el.dataset.autoScrollIntoView) {
|
|
2536
|
+
if (el && (this.autoScrollIntoView || el.dataset.autoScrollIntoView)) {
|
|
2494
2537
|
this.mask.observerIntersection(el);
|
|
2495
2538
|
}
|
|
2496
2539
|
}
|
|
2497
2540
|
/**
|
|
2498
2541
|
* 多选选中多个元素
|
|
2499
|
-
* @param
|
|
2542
|
+
* @param ids 选中元素的id列表
|
|
2500
2543
|
*/
|
|
2501
|
-
async multiSelect(
|
|
2502
|
-
const els =
|
|
2544
|
+
async multiSelect(ids) {
|
|
2545
|
+
const els = ids.map((id) => this.renderer.getTargetElement(id)).filter((el) => Boolean(el));
|
|
2503
2546
|
if (els.length === 0)
|
|
2504
2547
|
return;
|
|
2505
2548
|
const lastEl = els[els.length - 1];
|
|
2506
2549
|
const isReduceSelect = els.length < this.actionManager.getSelectedElList().length;
|
|
2507
|
-
await this.renderer.select(
|
|
2508
|
-
this.mask.setLayout(lastEl);
|
|
2509
|
-
this.actionManager.multiSelect(
|
|
2510
|
-
if ((this.autoScrollIntoView || lastEl.dataset.autoScrollIntoView) && !isReduceSelect) {
|
|
2550
|
+
await this.renderer.select(ids);
|
|
2551
|
+
lastEl && this.mask.setLayout(lastEl);
|
|
2552
|
+
this.actionManager.multiSelect(ids);
|
|
2553
|
+
if (lastEl && (this.autoScrollIntoView || lastEl.dataset.autoScrollIntoView) && !isReduceSelect) {
|
|
2511
2554
|
this.mask.observerIntersection(lastEl);
|
|
2512
2555
|
}
|
|
2513
2556
|
}
|
|
@@ -2515,8 +2558,8 @@
|
|
|
2515
2558
|
* 高亮选中元素
|
|
2516
2559
|
* @param el 要高亮的元素
|
|
2517
2560
|
*/
|
|
2518
|
-
highlight(
|
|
2519
|
-
this.actionManager.highlight(
|
|
2561
|
+
highlight(id) {
|
|
2562
|
+
this.actionManager.highlight(id);
|
|
2520
2563
|
}
|
|
2521
2564
|
clearHighlight() {
|
|
2522
2565
|
this.actionManager.clearHighlight();
|
|
@@ -2612,6 +2655,12 @@
|
|
|
2612
2655
|
this.removeAllListeners();
|
|
2613
2656
|
this.container = void 0;
|
|
2614
2657
|
}
|
|
2658
|
+
on(eventName, listener) {
|
|
2659
|
+
return super.on(eventName, listener);
|
|
2660
|
+
}
|
|
2661
|
+
emit(eventName, ...args) {
|
|
2662
|
+
return super.emit(eventName, ...args);
|
|
2663
|
+
}
|
|
2615
2664
|
/**
|
|
2616
2665
|
* 监听页面大小变化
|
|
2617
2666
|
*/
|
|
@@ -2641,7 +2690,7 @@
|
|
|
2641
2690
|
updateDragEl: config.updateDragEl,
|
|
2642
2691
|
getRootContainer: () => this.container,
|
|
2643
2692
|
getRenderDocument: () => this.renderer.getDocument(),
|
|
2644
|
-
getTargetElement: (
|
|
2693
|
+
getTargetElement: (id) => this.renderer.getTargetElement(id),
|
|
2645
2694
|
getElementsFromPoint: (point) => this.renderer.getElementsFromPoint(point)
|
|
2646
2695
|
};
|
|
2647
2696
|
return actionManagerConfig;
|
|
@@ -2676,12 +2725,12 @@
|
|
|
2676
2725
|
* 初始化ActionManager类本身抛出来的事件监听
|
|
2677
2726
|
*/
|
|
2678
2727
|
initActionManagerEvent() {
|
|
2679
|
-
this.actionManager.on("before-select", (
|
|
2680
|
-
this.select(
|
|
2728
|
+
this.actionManager.on("before-select", (el, event) => {
|
|
2729
|
+
this.select(el.id, event);
|
|
2681
2730
|
}).on("select", (selectedEl, event) => {
|
|
2682
2731
|
this.emit("select", selectedEl, event);
|
|
2683
|
-
}).on("before-multi-select", (
|
|
2684
|
-
this.multiSelect(
|
|
2732
|
+
}).on("before-multi-select", (els) => {
|
|
2733
|
+
this.multiSelect(els.map((el) => el.id));
|
|
2685
2734
|
}).on("multi-select", (selectedElList, event) => {
|
|
2686
2735
|
this.emit("multi-select", selectedElList, event);
|
|
2687
2736
|
}).on("dblclick", (event) => {
|
|
@@ -2706,9 +2755,12 @@
|
|
|
2706
2755
|
* 初始化MultiDragResize类通过ActionManager抛出来的事件监听
|
|
2707
2756
|
*/
|
|
2708
2757
|
initMulDrEvent() {
|
|
2709
|
-
this.actionManager.on("change-to-select", (
|
|
2710
|
-
this.select(
|
|
2711
|
-
setTimeout(() =>
|
|
2758
|
+
this.actionManager.on("change-to-select", (id, e) => {
|
|
2759
|
+
this.select(id);
|
|
2760
|
+
setTimeout(() => {
|
|
2761
|
+
const el = this.renderer.getTargetElement(id);
|
|
2762
|
+
el && this.emit("select", el, e);
|
|
2763
|
+
});
|
|
2712
2764
|
}).on("multi-update", (data) => {
|
|
2713
2765
|
this.emit("update", data);
|
|
2714
2766
|
});
|
|
@@ -2717,7 +2769,7 @@
|
|
|
2717
2769
|
* 初始化Highlight类通过ActionManager抛出来的事件监听
|
|
2718
2770
|
*/
|
|
2719
2771
|
initHighlightEvent() {
|
|
2720
|
-
this.actionManager.on("highlight",
|
|
2772
|
+
this.actionManager.on("highlight", (highlightEl) => {
|
|
2721
2773
|
this.emit("highlight", highlightEl);
|
|
2722
2774
|
});
|
|
2723
2775
|
}
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.
|
|
2
|
+
"version": "1.4.0-beta.2",
|
|
3
3
|
"name": "@tmagic/stage",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": [
|
|
@@ -26,9 +26,9 @@
|
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
28
|
"@scena/guides": "^0.29.2",
|
|
29
|
-
"@tmagic/core": "1.
|
|
30
|
-
"@tmagic/schema": "1.
|
|
31
|
-
"@tmagic/utils": "1.
|
|
29
|
+
"@tmagic/core": "1.4.0-beta.2",
|
|
30
|
+
"@tmagic/schema": "1.4.0-beta.2",
|
|
31
|
+
"@tmagic/utils": "1.4.0-beta.2",
|
|
32
32
|
"events": "^3.3.0",
|
|
33
33
|
"keycon": "^1.4.0",
|
|
34
34
|
"lodash-es": "^4.17.21",
|
|
@@ -41,8 +41,8 @@
|
|
|
41
41
|
"@types/node": "^18.19.0",
|
|
42
42
|
"rimraf": "^3.0.2",
|
|
43
43
|
"sass": "^1.35.1",
|
|
44
|
-
"typescript": "^5.
|
|
45
|
-
"vite": "^5.
|
|
44
|
+
"typescript": "^5.4.2",
|
|
45
|
+
"vite": "^5.1.6"
|
|
46
46
|
},
|
|
47
47
|
"scripts": {
|
|
48
48
|
"build": "npm run build:type && vite build",
|