@tmagic/stage 1.4.0-beta.1 → 1.4.0
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 +143 -95
- package/dist/tmagic-stage.umd.cjs +143 -95
- package/package.json +4 -4
- package/src/ActionManager.ts +57 -24
- package/src/DragResizeHelper.ts +2 -2
- package/src/StageCore.ts +41 -25
- package/src/StageDragResize.ts +50 -23
- package/src/StageMask.ts +12 -1
- package/src/StageMultiDragResize.ts +14 -3
- package/src/StageRender.ts +22 -26
- 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;
|
|
@@ -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() {
|
|
@@ -1365,6 +1381,12 @@
|
|
|
1365
1381
|
this.moveableForMulti?.destroy();
|
|
1366
1382
|
this.dragResizeHelper.destroy();
|
|
1367
1383
|
}
|
|
1384
|
+
on(eventName, listener) {
|
|
1385
|
+
return super.on(eventName, listener);
|
|
1386
|
+
}
|
|
1387
|
+
emit(eventName, ...args) {
|
|
1388
|
+
return super.emit(eventName, ...args);
|
|
1389
|
+
}
|
|
1368
1390
|
/**
|
|
1369
1391
|
* 拖拽完成后将更新的位置信息暴露给上层业务方,业务方可以接收事件进行保存
|
|
1370
1392
|
* @param isResize 是否进行大小缩放
|
|
@@ -1395,7 +1417,7 @@
|
|
|
1395
1417
|
/** 单选、多选、高亮的容器(蒙层的content) */
|
|
1396
1418
|
container;
|
|
1397
1419
|
/** 当前选中的节点 */
|
|
1398
|
-
selectedEl;
|
|
1420
|
+
selectedEl = null;
|
|
1399
1421
|
/** 多选选中的节点组 */
|
|
1400
1422
|
selectedElList = [];
|
|
1401
1423
|
/** 当前高亮的节点 */
|
|
@@ -1426,7 +1448,7 @@
|
|
|
1426
1448
|
return;
|
|
1427
1449
|
}
|
|
1428
1450
|
this.emit("mousemove", event);
|
|
1429
|
-
this.highlight(el);
|
|
1451
|
+
this.highlight(el.id);
|
|
1430
1452
|
}, throttleTime);
|
|
1431
1453
|
constructor(config) {
|
|
1432
1454
|
super();
|
|
@@ -1530,6 +1552,7 @@
|
|
|
1530
1552
|
return el;
|
|
1531
1553
|
}
|
|
1532
1554
|
}
|
|
1555
|
+
return null;
|
|
1533
1556
|
}
|
|
1534
1557
|
/**
|
|
1535
1558
|
* 判断一个元素能否在当前场景被选中
|
|
@@ -1566,8 +1589,14 @@
|
|
|
1566
1589
|
this.clearSelectStatus(SelectStatus.MULTI_SELECT);
|
|
1567
1590
|
this.dr.select(el, event);
|
|
1568
1591
|
}
|
|
1569
|
-
multiSelect(
|
|
1570
|
-
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
|
+
});
|
|
1571
1600
|
this.clearSelectStatus(SelectStatus.SELECT);
|
|
1572
1601
|
this.multiDr?.multiSelect(this.selectedElList);
|
|
1573
1602
|
}
|
|
@@ -1577,10 +1606,10 @@
|
|
|
1577
1606
|
setHighlightEl(el) {
|
|
1578
1607
|
this.highlightedEl = el;
|
|
1579
1608
|
}
|
|
1580
|
-
highlight(
|
|
1609
|
+
highlight(id) {
|
|
1581
1610
|
let el;
|
|
1582
1611
|
try {
|
|
1583
|
-
el = this.getTargetElement(
|
|
1612
|
+
el = this.getTargetElement(id);
|
|
1584
1613
|
} catch (error) {
|
|
1585
1614
|
this.clearHighlight();
|
|
1586
1615
|
return;
|
|
@@ -1656,6 +1685,12 @@
|
|
|
1656
1685
|
this.multiDr?.destroy();
|
|
1657
1686
|
this.highlightLayer.destroy();
|
|
1658
1687
|
}
|
|
1688
|
+
on(eventName, listener) {
|
|
1689
|
+
return super.on(eventName, listener);
|
|
1690
|
+
}
|
|
1691
|
+
emit(eventName, ...args) {
|
|
1692
|
+
return super.emit(eventName, ...args);
|
|
1693
|
+
}
|
|
1659
1694
|
createDr(config) {
|
|
1660
1695
|
const createDrHelper = () => new DragResizeHelper({
|
|
1661
1696
|
container: config.container,
|
|
@@ -1675,9 +1710,9 @@
|
|
|
1675
1710
|
setTimeout(() => this.emit("update", data));
|
|
1676
1711
|
}).on("sort", (data) => {
|
|
1677
1712
|
setTimeout(() => this.emit("sort", data));
|
|
1678
|
-
}).on(
|
|
1713
|
+
}).on(AbleActionEventType.SELECT_PARENT, () => {
|
|
1679
1714
|
this.emit("select-parent");
|
|
1680
|
-
}).on(
|
|
1715
|
+
}).on(AbleActionEventType.REMOVE, () => {
|
|
1681
1716
|
const drTarget = this.dr.getTarget();
|
|
1682
1717
|
if (!drTarget)
|
|
1683
1718
|
return;
|
|
@@ -1706,11 +1741,10 @@
|
|
|
1706
1741
|
});
|
|
1707
1742
|
multiDr?.on("update", (data) => {
|
|
1708
1743
|
this.emit("multi-update", data);
|
|
1709
|
-
}).on("change-to-select",
|
|
1744
|
+
}).on("change-to-select", (id, e) => {
|
|
1710
1745
|
if (this.isMultiSelectStatus)
|
|
1711
|
-
return
|
|
1712
|
-
|
|
1713
|
-
this.emit("change-to-select", el, e);
|
|
1746
|
+
return;
|
|
1747
|
+
this.emit("change-to-select", id, e);
|
|
1714
1748
|
});
|
|
1715
1749
|
return multiDr;
|
|
1716
1750
|
}
|
|
@@ -1744,11 +1778,13 @@
|
|
|
1744
1778
|
return;
|
|
1745
1779
|
if (this.selectedEl && !this.selectedEl.className.includes(PAGE_CLASS)) {
|
|
1746
1780
|
this.selectedElList.push(this.selectedEl);
|
|
1747
|
-
this.setSelectedEl(
|
|
1781
|
+
this.setSelectedEl(null);
|
|
1748
1782
|
}
|
|
1749
1783
|
const existIndex = this.selectedElList.findIndex((selectedDom) => selectedDom.id === el.id);
|
|
1750
1784
|
if (existIndex !== -1) {
|
|
1751
|
-
this.selectedElList.
|
|
1785
|
+
if (this.selectedElList.length > 1) {
|
|
1786
|
+
this.selectedElList.splice(existIndex, 1);
|
|
1787
|
+
}
|
|
1752
1788
|
} else {
|
|
1753
1789
|
this.selectedElList.push(el);
|
|
1754
1790
|
}
|
|
@@ -2135,6 +2171,12 @@
|
|
|
2135
2171
|
this.wrapperResizeObserver?.disconnect();
|
|
2136
2172
|
super.destroy();
|
|
2137
2173
|
}
|
|
2174
|
+
on(eventName, listener) {
|
|
2175
|
+
return super.on(eventName, listener);
|
|
2176
|
+
}
|
|
2177
|
+
emit(eventName, ...args) {
|
|
2178
|
+
return super.emit(eventName, ...args);
|
|
2179
|
+
}
|
|
2138
2180
|
/**
|
|
2139
2181
|
* 监听选中元素是否在画布可视区域内,如果目标元素不在可视区域内,通过滚动使该元素出现在可视区域
|
|
2140
2182
|
*/
|
|
@@ -2310,14 +2352,11 @@
|
|
|
2310
2352
|
const runtime = await this.getRuntime();
|
|
2311
2353
|
runtime?.update?.(data);
|
|
2312
2354
|
}
|
|
2313
|
-
async select(
|
|
2355
|
+
async select(ids) {
|
|
2314
2356
|
const runtime = await this.getRuntime();
|
|
2315
|
-
for (const
|
|
2316
|
-
await runtime?.select?.(
|
|
2317
|
-
|
|
2318
|
-
await runtime.beforeSelect(el);
|
|
2319
|
-
}
|
|
2320
|
-
this.flagSelectedEl(el);
|
|
2357
|
+
for (const id of ids) {
|
|
2358
|
+
await runtime?.select?.(id);
|
|
2359
|
+
this.flagSelectedEl(this.getTargetElement(id));
|
|
2321
2360
|
}
|
|
2322
2361
|
}
|
|
2323
2362
|
setZoom(zoom = DEFAULT_ZOOM) {
|
|
@@ -2373,14 +2412,8 @@
|
|
|
2373
2412
|
}
|
|
2374
2413
|
return this.getDocument()?.elementsFromPoint(x / this.zoom, y / this.zoom);
|
|
2375
2414
|
}
|
|
2376
|
-
getTargetElement(
|
|
2377
|
-
|
|
2378
|
-
const el = this.getDocument()?.getElementById(`${idOrEl}`);
|
|
2379
|
-
if (!el)
|
|
2380
|
-
throw new Error(`不存在ID为${idOrEl}的元素`);
|
|
2381
|
-
return el;
|
|
2382
|
-
}
|
|
2383
|
-
return idOrEl;
|
|
2415
|
+
getTargetElement(id) {
|
|
2416
|
+
return this.getDocument()?.getElementById(`${id}`) || null;
|
|
2384
2417
|
}
|
|
2385
2418
|
/**
|
|
2386
2419
|
* 销毁实例
|
|
@@ -2392,6 +2425,12 @@
|
|
|
2392
2425
|
this.iframe = void 0;
|
|
2393
2426
|
this.removeAllListeners();
|
|
2394
2427
|
}
|
|
2428
|
+
on(eventName, listener) {
|
|
2429
|
+
return super.on(eventName, listener);
|
|
2430
|
+
}
|
|
2431
|
+
emit(eventName, ...args) {
|
|
2432
|
+
return super.emit(eventName, ...args);
|
|
2433
|
+
}
|
|
2395
2434
|
createIframe() {
|
|
2396
2435
|
this.iframe = globalThis.document.createElement("iframe");
|
|
2397
2436
|
this.iframe.src = this.runtimeUrl && utils.isSameDomain(this.runtimeUrl) ? this.runtimeUrl : "";
|
|
@@ -2422,7 +2461,7 @@
|
|
|
2422
2461
|
const doc = this.getDocument();
|
|
2423
2462
|
if (doc) {
|
|
2424
2463
|
removeSelectedClassName(doc);
|
|
2425
|
-
addSelectedClassName(el, doc);
|
|
2464
|
+
el && addSelectedClassName(el, doc);
|
|
2426
2465
|
}
|
|
2427
2466
|
}
|
|
2428
2467
|
iframeLoadHandler = async () => {
|
|
@@ -2485,33 +2524,33 @@
|
|
|
2485
2524
|
}
|
|
2486
2525
|
/**
|
|
2487
2526
|
* 单选选中元素
|
|
2488
|
-
* @param
|
|
2527
|
+
* @param id 选中的id
|
|
2489
2528
|
*/
|
|
2490
|
-
async select(
|
|
2491
|
-
const el = this.renderer.getTargetElement(
|
|
2529
|
+
async select(id, event) {
|
|
2530
|
+
const el = this.renderer.getTargetElement(id);
|
|
2492
2531
|
if (el === this.actionManager.getSelectedEl())
|
|
2493
2532
|
return;
|
|
2494
|
-
await this.renderer.select([
|
|
2495
|
-
this.mask.setLayout(el);
|
|
2533
|
+
await this.renderer.select([id]);
|
|
2534
|
+
el && this.mask.setLayout(el);
|
|
2496
2535
|
this.actionManager.select(el, event);
|
|
2497
|
-
if (this.autoScrollIntoView || el.dataset.autoScrollIntoView) {
|
|
2536
|
+
if (el && (this.autoScrollIntoView || el.dataset.autoScrollIntoView)) {
|
|
2498
2537
|
this.mask.observerIntersection(el);
|
|
2499
2538
|
}
|
|
2500
2539
|
}
|
|
2501
2540
|
/**
|
|
2502
2541
|
* 多选选中多个元素
|
|
2503
|
-
* @param
|
|
2542
|
+
* @param ids 选中元素的id列表
|
|
2504
2543
|
*/
|
|
2505
|
-
async multiSelect(
|
|
2506
|
-
const els =
|
|
2544
|
+
async multiSelect(ids) {
|
|
2545
|
+
const els = ids.map((id) => this.renderer.getTargetElement(id)).filter((el) => Boolean(el));
|
|
2507
2546
|
if (els.length === 0)
|
|
2508
2547
|
return;
|
|
2509
2548
|
const lastEl = els[els.length - 1];
|
|
2510
2549
|
const isReduceSelect = els.length < this.actionManager.getSelectedElList().length;
|
|
2511
|
-
await this.renderer.select(
|
|
2512
|
-
this.mask.setLayout(lastEl);
|
|
2513
|
-
this.actionManager.multiSelect(
|
|
2514
|
-
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) {
|
|
2515
2554
|
this.mask.observerIntersection(lastEl);
|
|
2516
2555
|
}
|
|
2517
2556
|
}
|
|
@@ -2519,8 +2558,8 @@
|
|
|
2519
2558
|
* 高亮选中元素
|
|
2520
2559
|
* @param el 要高亮的元素
|
|
2521
2560
|
*/
|
|
2522
|
-
highlight(
|
|
2523
|
-
this.actionManager.highlight(
|
|
2561
|
+
highlight(id) {
|
|
2562
|
+
this.actionManager.highlight(id);
|
|
2524
2563
|
}
|
|
2525
2564
|
clearHighlight() {
|
|
2526
2565
|
this.actionManager.clearHighlight();
|
|
@@ -2616,6 +2655,12 @@
|
|
|
2616
2655
|
this.removeAllListeners();
|
|
2617
2656
|
this.container = void 0;
|
|
2618
2657
|
}
|
|
2658
|
+
on(eventName, listener) {
|
|
2659
|
+
return super.on(eventName, listener);
|
|
2660
|
+
}
|
|
2661
|
+
emit(eventName, ...args) {
|
|
2662
|
+
return super.emit(eventName, ...args);
|
|
2663
|
+
}
|
|
2619
2664
|
/**
|
|
2620
2665
|
* 监听页面大小变化
|
|
2621
2666
|
*/
|
|
@@ -2645,7 +2690,7 @@
|
|
|
2645
2690
|
updateDragEl: config.updateDragEl,
|
|
2646
2691
|
getRootContainer: () => this.container,
|
|
2647
2692
|
getRenderDocument: () => this.renderer.getDocument(),
|
|
2648
|
-
getTargetElement: (
|
|
2693
|
+
getTargetElement: (id) => this.renderer.getTargetElement(id),
|
|
2649
2694
|
getElementsFromPoint: (point) => this.renderer.getElementsFromPoint(point)
|
|
2650
2695
|
};
|
|
2651
2696
|
return actionManagerConfig;
|
|
@@ -2680,12 +2725,12 @@
|
|
|
2680
2725
|
* 初始化ActionManager类本身抛出来的事件监听
|
|
2681
2726
|
*/
|
|
2682
2727
|
initActionManagerEvent() {
|
|
2683
|
-
this.actionManager.on("before-select", (
|
|
2684
|
-
this.select(
|
|
2728
|
+
this.actionManager.on("before-select", (el, event) => {
|
|
2729
|
+
this.select(el.id, event);
|
|
2685
2730
|
}).on("select", (selectedEl, event) => {
|
|
2686
2731
|
this.emit("select", selectedEl, event);
|
|
2687
|
-
}).on("before-multi-select", (
|
|
2688
|
-
this.multiSelect(
|
|
2732
|
+
}).on("before-multi-select", (els) => {
|
|
2733
|
+
this.multiSelect(els.map((el) => el.id));
|
|
2689
2734
|
}).on("multi-select", (selectedElList, event) => {
|
|
2690
2735
|
this.emit("multi-select", selectedElList, event);
|
|
2691
2736
|
}).on("dblclick", (event) => {
|
|
@@ -2710,9 +2755,12 @@
|
|
|
2710
2755
|
* 初始化MultiDragResize类通过ActionManager抛出来的事件监听
|
|
2711
2756
|
*/
|
|
2712
2757
|
initMulDrEvent() {
|
|
2713
|
-
this.actionManager.on("change-to-select", (
|
|
2714
|
-
this.select(
|
|
2715
|
-
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
|
+
});
|
|
2716
2764
|
}).on("multi-update", (data) => {
|
|
2717
2765
|
this.emit("update", data);
|
|
2718
2766
|
});
|
|
@@ -2721,7 +2769,7 @@
|
|
|
2721
2769
|
* 初始化Highlight类通过ActionManager抛出来的事件监听
|
|
2722
2770
|
*/
|
|
2723
2771
|
initHighlightEvent() {
|
|
2724
|
-
this.actionManager.on("highlight",
|
|
2772
|
+
this.actionManager.on("highlight", (highlightEl) => {
|
|
2725
2773
|
this.emit("highlight", highlightEl);
|
|
2726
2774
|
});
|
|
2727
2775
|
}
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.4.0
|
|
2
|
+
"version": "1.4.0",
|
|
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.4.0
|
|
30
|
-
"@tmagic/schema": "1.4.0
|
|
31
|
-
"@tmagic/utils": "1.4.0
|
|
29
|
+
"@tmagic/core": "1.4.0",
|
|
30
|
+
"@tmagic/schema": "1.4.0",
|
|
31
|
+
"@tmagic/utils": "1.4.0",
|
|
32
32
|
"events": "^3.3.0",
|
|
33
33
|
"keycon": "^1.4.0",
|
|
34
34
|
"lodash-es": "^4.17.21",
|
package/src/ActionManager.ts
CHANGED
|
@@ -25,15 +25,25 @@ import { Env } from '@tmagic/core';
|
|
|
25
25
|
import type { Id } from '@tmagic/schema';
|
|
26
26
|
import { addClassName, getDocument, removeClassNameByClassName } from '@tmagic/utils';
|
|
27
27
|
|
|
28
|
-
import {
|
|
28
|
+
import {
|
|
29
|
+
AbleActionEventType,
|
|
30
|
+
CONTAINER_HIGHLIGHT_CLASS_NAME,
|
|
31
|
+
ContainerHighlightType,
|
|
32
|
+
GHOST_EL_ID_PREFIX,
|
|
33
|
+
GuidesType,
|
|
34
|
+
MouseButton,
|
|
35
|
+
PAGE_CLASS,
|
|
36
|
+
SelectStatus,
|
|
37
|
+
StageDragStatus,
|
|
38
|
+
} from './const';
|
|
29
39
|
import DragResizeHelper from './DragResizeHelper';
|
|
30
40
|
import StageDragResize from './StageDragResize';
|
|
31
41
|
import StageHighlight from './StageHighlight';
|
|
32
42
|
import StageMultiDragResize from './StageMultiDragResize';
|
|
33
|
-
import {
|
|
43
|
+
import type {
|
|
34
44
|
ActionManagerConfig,
|
|
45
|
+
ActionManagerEvents,
|
|
35
46
|
CanSelect,
|
|
36
|
-
ContainerHighlightType,
|
|
37
47
|
CustomizeMoveableOptions,
|
|
38
48
|
CustomizeMoveableOptionsCallbackConfig,
|
|
39
49
|
GetElementsFromPoint,
|
|
@@ -42,8 +52,7 @@ import {
|
|
|
42
52
|
IsContainer,
|
|
43
53
|
Point,
|
|
44
54
|
RemoveEventData,
|
|
45
|
-
|
|
46
|
-
StageDragStatus,
|
|
55
|
+
SortEventData,
|
|
47
56
|
UpdateEventData,
|
|
48
57
|
} from './types';
|
|
49
58
|
import { isMoveableButton } from './util';
|
|
@@ -62,7 +71,7 @@ export default class ActionManager extends EventEmitter {
|
|
|
62
71
|
/** 单选、多选、高亮的容器(蒙层的content) */
|
|
63
72
|
private container: HTMLElement;
|
|
64
73
|
/** 当前选中的节点 */
|
|
65
|
-
private selectedEl: HTMLElement |
|
|
74
|
+
private selectedEl: HTMLElement | null = null;
|
|
66
75
|
/** 多选选中的节点组 */
|
|
67
76
|
private selectedElList: HTMLElement[] = [];
|
|
68
77
|
/** 当前高亮的节点 */
|
|
@@ -96,7 +105,7 @@ export default class ActionManager extends EventEmitter {
|
|
|
96
105
|
}
|
|
97
106
|
|
|
98
107
|
this.emit('mousemove', event);
|
|
99
|
-
this.highlight(el);
|
|
108
|
+
this.highlight(el.id);
|
|
100
109
|
}, throttleTime);
|
|
101
110
|
|
|
102
111
|
constructor(config: ActionManagerConfig) {
|
|
@@ -181,11 +190,11 @@ export default class ActionManager extends EventEmitter {
|
|
|
181
190
|
return el.id === this.selectedEl?.id;
|
|
182
191
|
}
|
|
183
192
|
|
|
184
|
-
public setSelectedEl(el
|
|
193
|
+
public setSelectedEl(el: HTMLElement | null): void {
|
|
185
194
|
this.selectedEl = el;
|
|
186
195
|
}
|
|
187
196
|
|
|
188
|
-
public getSelectedEl(): HTMLElement |
|
|
197
|
+
public getSelectedEl(): HTMLElement | null {
|
|
189
198
|
return this.selectedEl;
|
|
190
199
|
}
|
|
191
200
|
|
|
@@ -207,7 +216,7 @@ export default class ActionManager extends EventEmitter {
|
|
|
207
216
|
* @param event 鼠标事件
|
|
208
217
|
* @returns 鼠标下方第一个可选中元素
|
|
209
218
|
*/
|
|
210
|
-
public async getElementFromPoint(event: MouseEvent): Promise<HTMLElement |
|
|
219
|
+
public async getElementFromPoint(event: MouseEvent): Promise<HTMLElement | null> {
|
|
211
220
|
const els = this.getElementsFromPoint(event as Point);
|
|
212
221
|
|
|
213
222
|
this.emit('get-elements-from-point', els);
|
|
@@ -220,6 +229,7 @@ export default class ActionManager extends EventEmitter {
|
|
|
220
229
|
return el;
|
|
221
230
|
}
|
|
222
231
|
}
|
|
232
|
+
return null;
|
|
223
233
|
}
|
|
224
234
|
|
|
225
235
|
/**
|
|
@@ -257,14 +267,20 @@ export default class ActionManager extends EventEmitter {
|
|
|
257
267
|
return this.multiDr?.canSelect(el, selectedEl) || false;
|
|
258
268
|
}
|
|
259
269
|
|
|
260
|
-
public select(el: HTMLElement, event
|
|
270
|
+
public select(el: HTMLElement | null, event?: MouseEvent): void {
|
|
261
271
|
this.setSelectedEl(el);
|
|
262
272
|
this.clearSelectStatus(SelectStatus.MULTI_SELECT);
|
|
263
273
|
this.dr.select(el, event);
|
|
264
274
|
}
|
|
265
275
|
|
|
266
|
-
public multiSelect(
|
|
267
|
-
this.selectedElList =
|
|
276
|
+
public multiSelect(ids: Id[]): void {
|
|
277
|
+
this.selectedElList = [];
|
|
278
|
+
ids.forEach((id) => {
|
|
279
|
+
const el = this.getTargetElement(id);
|
|
280
|
+
if (el) {
|
|
281
|
+
this.selectedElList.push(el);
|
|
282
|
+
}
|
|
283
|
+
});
|
|
268
284
|
this.clearSelectStatus(SelectStatus.SELECT);
|
|
269
285
|
this.multiDr?.multiSelect(this.selectedElList);
|
|
270
286
|
}
|
|
@@ -277,10 +293,10 @@ export default class ActionManager extends EventEmitter {
|
|
|
277
293
|
this.highlightedEl = el;
|
|
278
294
|
}
|
|
279
295
|
|
|
280
|
-
public highlight(
|
|
296
|
+
public highlight(id: Id): void {
|
|
281
297
|
let el;
|
|
282
298
|
try {
|
|
283
|
-
el = this.getTargetElement(
|
|
299
|
+
el = this.getTargetElement(id);
|
|
284
300
|
} catch (error) {
|
|
285
301
|
this.clearHighlight();
|
|
286
302
|
return;
|
|
@@ -366,6 +382,20 @@ export default class ActionManager extends EventEmitter {
|
|
|
366
382
|
this.highlightLayer.destroy();
|
|
367
383
|
}
|
|
368
384
|
|
|
385
|
+
public on<Name extends keyof ActionManagerEvents, Param extends ActionManagerEvents[Name]>(
|
|
386
|
+
eventName: Name,
|
|
387
|
+
listener: (...args: Param) => void,
|
|
388
|
+
) {
|
|
389
|
+
return super.on(eventName, listener as any);
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
public emit<Name extends keyof ActionManagerEvents, Param extends ActionManagerEvents[Name]>(
|
|
393
|
+
eventName: Name,
|
|
394
|
+
...args: Param
|
|
395
|
+
) {
|
|
396
|
+
return super.emit(eventName, ...args);
|
|
397
|
+
}
|
|
398
|
+
|
|
369
399
|
private createDr(config: ActionManagerConfig) {
|
|
370
400
|
const createDrHelper = () =>
|
|
371
401
|
new DragResizeHelper({
|
|
@@ -388,14 +418,14 @@ export default class ActionManager extends EventEmitter {
|
|
|
388
418
|
// 点击组件并立即拖动的场景,要保证select先被触发,延迟update通知
|
|
389
419
|
setTimeout(() => this.emit('update', data));
|
|
390
420
|
})
|
|
391
|
-
.on('sort', (data:
|
|
421
|
+
.on('sort', (data: SortEventData) => {
|
|
392
422
|
// 点击组件并立即拖动的场景,要保证select先被触发,延迟update通知
|
|
393
423
|
setTimeout(() => this.emit('sort', data));
|
|
394
424
|
})
|
|
395
|
-
.on(
|
|
425
|
+
.on(AbleActionEventType.SELECT_PARENT, () => {
|
|
396
426
|
this.emit('select-parent');
|
|
397
427
|
})
|
|
398
|
-
.on(
|
|
428
|
+
.on(AbleActionEventType.REMOVE, () => {
|
|
399
429
|
const drTarget = this.dr.getTarget();
|
|
400
430
|
if (!drTarget) return;
|
|
401
431
|
const data: RemoveEventData = {
|
|
@@ -430,11 +460,10 @@ export default class ActionManager extends EventEmitter {
|
|
|
430
460
|
?.on('update', (data: UpdateEventData) => {
|
|
431
461
|
this.emit('multi-update', data);
|
|
432
462
|
})
|
|
433
|
-
.on('change-to-select',
|
|
463
|
+
.on('change-to-select', (id: Id, e: MouseEvent) => {
|
|
434
464
|
// 如果还在多选状态,不触发切换到单选
|
|
435
|
-
if (this.isMultiSelectStatus) return
|
|
436
|
-
|
|
437
|
-
this.emit('change-to-select', el, e);
|
|
465
|
+
if (this.isMultiSelectStatus) return;
|
|
466
|
+
this.emit('change-to-select', id, e);
|
|
438
467
|
});
|
|
439
468
|
|
|
440
469
|
return multiDr;
|
|
@@ -474,13 +503,16 @@ export default class ActionManager extends EventEmitter {
|
|
|
474
503
|
// 如果已有单选选中元素,不是magic-ui-page就可以加入多选列表
|
|
475
504
|
if (this.selectedEl && !this.selectedEl.className.includes(PAGE_CLASS)) {
|
|
476
505
|
this.selectedElList.push(this.selectedEl as HTMLElement);
|
|
477
|
-
this.setSelectedEl(
|
|
506
|
+
this.setSelectedEl(null);
|
|
478
507
|
}
|
|
508
|
+
|
|
479
509
|
// 判断元素是否已在多选列表
|
|
480
510
|
const existIndex = this.selectedElList.findIndex((selectedDom) => selectedDom.id === el.id);
|
|
481
511
|
if (existIndex !== -1) {
|
|
482
512
|
// 再次点击取消选中
|
|
483
|
-
this.selectedElList.
|
|
513
|
+
if (this.selectedElList.length > 1) {
|
|
514
|
+
this.selectedElList.splice(existIndex, 1);
|
|
515
|
+
}
|
|
484
516
|
} else {
|
|
485
517
|
this.selectedElList.push(el);
|
|
486
518
|
}
|
|
@@ -580,6 +612,7 @@ export default class ActionManager extends EventEmitter {
|
|
|
580
612
|
if (!el) return;
|
|
581
613
|
this.emit('before-select', el, event);
|
|
582
614
|
}
|
|
615
|
+
|
|
583
616
|
getDocument().addEventListener('mouseup', this.mouseUpHandler);
|
|
584
617
|
};
|
|
585
618
|
|
package/src/DragResizeHelper.ts
CHANGED
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
* limitations under the License.
|
|
17
17
|
*/
|
|
18
18
|
|
|
19
|
-
import {
|
|
19
|
+
import type {
|
|
20
20
|
OnDrag,
|
|
21
21
|
OnDragGroup,
|
|
22
22
|
OnDragGroupStart,
|
|
@@ -34,7 +34,7 @@ import MoveableHelper from 'moveable-helper';
|
|
|
34
34
|
|
|
35
35
|
import { DRAG_EL_ID_PREFIX, GHOST_EL_ID_PREFIX, Mode, ZIndex } from './const';
|
|
36
36
|
import TargetShadow from './TargetShadow';
|
|
37
|
-
import { DragResizeHelperConfig, Rect, TargetElement } from './types';
|
|
37
|
+
import type { DragResizeHelperConfig, Rect, TargetElement } from './types';
|
|
38
38
|
import { calcValueByFontsize, getAbsolutePosition, getBorderWidth, getMarginValue, getOffset } from './util';
|
|
39
39
|
|
|
40
40
|
/**
|