@tmagic/stage 1.5.0-beta.2 → 1.5.0-beta.4
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 +79 -64
- package/dist/tmagic-stage.umd.cjs +79 -64
- package/package.json +4 -4
- package/src/ActionManager.ts +23 -16
- package/src/DragResizeHelper.ts +20 -18
- package/src/StageCore.ts +58 -53
- package/src/StageDragResize.ts +1 -0
- package/src/StageHighlight.ts +1 -0
- package/types/index.d.ts +6 -6
package/dist/tmagic-stage.js
CHANGED
|
@@ -333,7 +333,7 @@ class DragResizeHelper {
|
|
|
333
333
|
/** 目标节点在蒙层上的占位节点,用于跟鼠标交互,避免鼠标事件直接作用到目标节点 */
|
|
334
334
|
targetShadow;
|
|
335
335
|
/** 要操作的原始目标节点 */
|
|
336
|
-
target;
|
|
336
|
+
target = null;
|
|
337
337
|
/** 多选:目标节点组 */
|
|
338
338
|
targetList = [];
|
|
339
339
|
/** 响应拖拽的状态事件,修改绝对定位布局下targetShadow的dom。
|
|
@@ -364,6 +364,8 @@ class DragResizeHelper {
|
|
|
364
364
|
});
|
|
365
365
|
}
|
|
366
366
|
destroy() {
|
|
367
|
+
this.target = null;
|
|
368
|
+
this.targetList = [];
|
|
367
369
|
this.targetShadow.destroy();
|
|
368
370
|
this.destroyGhostEl();
|
|
369
371
|
this.moveableHelper.clear();
|
|
@@ -970,6 +972,7 @@ class StageDragResize extends MoveableOptionsManager {
|
|
|
970
972
|
* 销毁实例
|
|
971
973
|
*/
|
|
972
974
|
destroy() {
|
|
975
|
+
this.target = null;
|
|
973
976
|
this.moveable?.destroy();
|
|
974
977
|
this.dragResizeHelper.destroy();
|
|
975
978
|
this.dragStatus = StageDragStatus.END;
|
|
@@ -1201,6 +1204,7 @@ class StageHighlight extends EventEmitter$1 {
|
|
|
1201
1204
|
* 销毁实例
|
|
1202
1205
|
*/
|
|
1203
1206
|
destroy() {
|
|
1207
|
+
this.target = void 0;
|
|
1204
1208
|
this.moveable?.destroy();
|
|
1205
1209
|
this.targetShadow?.destroy();
|
|
1206
1210
|
this.moveable = void 0;
|
|
@@ -1369,9 +1373,9 @@ class StageMultiDragResize extends MoveableOptionsManager {
|
|
|
1369
1373
|
const throttleTime = 100;
|
|
1370
1374
|
const defaultContainerHighlightDuration = 800;
|
|
1371
1375
|
class ActionManager extends EventEmitter {
|
|
1372
|
-
dr;
|
|
1373
|
-
multiDr;
|
|
1374
|
-
highlightLayer;
|
|
1376
|
+
dr = null;
|
|
1377
|
+
multiDr = null;
|
|
1378
|
+
highlightLayer = null;
|
|
1375
1379
|
/** 单选、多选、高亮的容器(蒙层的content) */
|
|
1376
1380
|
container;
|
|
1377
1381
|
/** 当前选中的节点 */
|
|
@@ -1438,7 +1442,7 @@ class ActionManager extends EventEmitter {
|
|
|
1438
1442
|
this.disabledMultiSelect = true;
|
|
1439
1443
|
if (this.multiDr) {
|
|
1440
1444
|
this.multiDr.destroy();
|
|
1441
|
-
this.multiDr =
|
|
1445
|
+
this.multiDr = null;
|
|
1442
1446
|
}
|
|
1443
1447
|
}
|
|
1444
1448
|
enableMultiSelect() {
|
|
@@ -1453,14 +1457,14 @@ class ActionManager extends EventEmitter {
|
|
|
1453
1457
|
* @param guidelines 参考线坐标数组
|
|
1454
1458
|
*/
|
|
1455
1459
|
setGuidelines(type, guidelines) {
|
|
1456
|
-
this.dr
|
|
1460
|
+
this.dr?.setGuidelines(type, guidelines);
|
|
1457
1461
|
this.multiDr?.setGuidelines(type, guidelines);
|
|
1458
1462
|
}
|
|
1459
1463
|
/**
|
|
1460
1464
|
* 清空所有参考线
|
|
1461
1465
|
*/
|
|
1462
1466
|
clearGuides() {
|
|
1463
|
-
this.dr
|
|
1467
|
+
this.dr?.clearGuides();
|
|
1464
1468
|
this.multiDr?.clearGuides();
|
|
1465
1469
|
}
|
|
1466
1470
|
/**
|
|
@@ -1468,7 +1472,7 @@ class ActionManager extends EventEmitter {
|
|
|
1468
1472
|
* @param el 变更的元素
|
|
1469
1473
|
*/
|
|
1470
1474
|
updateMoveable(el) {
|
|
1471
|
-
this.dr
|
|
1475
|
+
this.dr?.updateMoveable(el);
|
|
1472
1476
|
this.multiDr?.updateMoveable();
|
|
1473
1477
|
}
|
|
1474
1478
|
/**
|
|
@@ -1487,7 +1491,7 @@ class ActionManager extends EventEmitter {
|
|
|
1487
1491
|
return this.selectedElList;
|
|
1488
1492
|
}
|
|
1489
1493
|
getMoveableOption(key) {
|
|
1490
|
-
if (this.dr
|
|
1494
|
+
if (this.dr?.getTarget()) {
|
|
1491
1495
|
return this.dr.getOption(key);
|
|
1492
1496
|
}
|
|
1493
1497
|
if (this.multiDr?.targetList.length) {
|
|
@@ -1544,7 +1548,7 @@ class ActionManager extends EventEmitter {
|
|
|
1544
1548
|
select(el, event) {
|
|
1545
1549
|
this.setSelectedEl(el);
|
|
1546
1550
|
this.clearSelectStatus(SelectStatus.MULTI_SELECT);
|
|
1547
|
-
this.dr
|
|
1551
|
+
this.dr?.select(el, event);
|
|
1548
1552
|
}
|
|
1549
1553
|
multiSelect(ids) {
|
|
1550
1554
|
this.selectedElList = [];
|
|
@@ -1576,13 +1580,13 @@ class ActionManager extends EventEmitter {
|
|
|
1576
1580
|
return;
|
|
1577
1581
|
}
|
|
1578
1582
|
if (el === this.highlightedEl || !el) return;
|
|
1579
|
-
this.highlightLayer
|
|
1583
|
+
this.highlightLayer?.highlight(el);
|
|
1580
1584
|
this.highlightedEl = el;
|
|
1581
1585
|
this.emit("highlight", el);
|
|
1582
1586
|
}
|
|
1583
1587
|
clearHighlight() {
|
|
1584
1588
|
this.setHighlightEl(void 0);
|
|
1585
|
-
this.highlightLayer
|
|
1589
|
+
this.highlightLayer?.clearHighlight();
|
|
1586
1590
|
}
|
|
1587
1591
|
/**
|
|
1588
1592
|
* 用于在切换选择模式时清除上一次的状态
|
|
@@ -1593,7 +1597,7 @@ class ActionManager extends EventEmitter {
|
|
|
1593
1597
|
this.multiDr?.clearSelectStatus();
|
|
1594
1598
|
this.selectedElList = [];
|
|
1595
1599
|
} else {
|
|
1596
|
-
this.dr
|
|
1600
|
+
this.dr?.clearSelectStatus();
|
|
1597
1601
|
}
|
|
1598
1602
|
}
|
|
1599
1603
|
/**
|
|
@@ -1628,7 +1632,7 @@ class ActionManager extends EventEmitter {
|
|
|
1628
1632
|
return void 0;
|
|
1629
1633
|
}
|
|
1630
1634
|
getDragStatus() {
|
|
1631
|
-
return this.dr
|
|
1635
|
+
return this.dr?.getDragStatus();
|
|
1632
1636
|
}
|
|
1633
1637
|
destroy() {
|
|
1634
1638
|
this.container.removeEventListener("mousedown", this.mouseDownHandler);
|
|
@@ -1636,9 +1640,14 @@ class ActionManager extends EventEmitter {
|
|
|
1636
1640
|
this.container.removeEventListener("mouseleave", this.mouseLeaveHandler);
|
|
1637
1641
|
this.container.removeEventListener("wheel", this.mouseWheelHandler);
|
|
1638
1642
|
this.container.removeEventListener("dblclick", this.dblclickHandler);
|
|
1639
|
-
this.
|
|
1643
|
+
this.selectedEl = null;
|
|
1644
|
+
this.selectedElList = [];
|
|
1645
|
+
this.dr?.destroy();
|
|
1640
1646
|
this.multiDr?.destroy();
|
|
1641
|
-
this.highlightLayer
|
|
1647
|
+
this.highlightLayer?.destroy();
|
|
1648
|
+
this.dr = null;
|
|
1649
|
+
this.multiDr = null;
|
|
1650
|
+
this.highlightLayer = null;
|
|
1642
1651
|
}
|
|
1643
1652
|
on(eventName, listener) {
|
|
1644
1653
|
return super.on(eventName, listener);
|
|
@@ -1668,7 +1677,7 @@ class ActionManager extends EventEmitter {
|
|
|
1668
1677
|
}).on(AbleActionEventType.SELECT_PARENT, () => {
|
|
1669
1678
|
this.emit("select-parent");
|
|
1670
1679
|
}).on(AbleActionEventType.REMOVE, () => {
|
|
1671
|
-
const drTarget = this.dr
|
|
1680
|
+
const drTarget = this.dr?.getTarget();
|
|
1672
1681
|
if (!drTarget) return;
|
|
1673
1682
|
const data = {
|
|
1674
1683
|
data: [{ el: drTarget }]
|
|
@@ -2438,9 +2447,9 @@ class StageRender extends EventEmitter$1 {
|
|
|
2438
2447
|
|
|
2439
2448
|
class StageCore extends EventEmitter$1 {
|
|
2440
2449
|
container;
|
|
2441
|
-
renderer;
|
|
2442
|
-
mask;
|
|
2443
|
-
actionManager;
|
|
2450
|
+
renderer = null;
|
|
2451
|
+
mask = null;
|
|
2452
|
+
actionManager = null;
|
|
2444
2453
|
pageResizeObserver = null;
|
|
2445
2454
|
autoScrollIntoView;
|
|
2446
2455
|
customizedRender;
|
|
@@ -2472,13 +2481,15 @@ class StageCore extends EventEmitter$1 {
|
|
|
2472
2481
|
* @param id 选中的id
|
|
2473
2482
|
*/
|
|
2474
2483
|
async select(id, event) {
|
|
2475
|
-
const el = this.renderer
|
|
2476
|
-
if (el === this.actionManager
|
|
2477
|
-
await this.renderer
|
|
2478
|
-
|
|
2479
|
-
|
|
2484
|
+
const el = this.renderer?.getTargetElement(id) || null;
|
|
2485
|
+
if (el === this.actionManager?.getSelectedEl()) return;
|
|
2486
|
+
await this.renderer?.select([id]);
|
|
2487
|
+
if (el) {
|
|
2488
|
+
this.mask?.setLayout(el);
|
|
2489
|
+
}
|
|
2490
|
+
this.actionManager?.select(el, event);
|
|
2480
2491
|
if (el && (this.autoScrollIntoView || el.dataset.autoScrollIntoView)) {
|
|
2481
|
-
this.mask
|
|
2492
|
+
this.mask?.observerIntersection(el);
|
|
2482
2493
|
}
|
|
2483
2494
|
}
|
|
2484
2495
|
/**
|
|
@@ -2486,15 +2497,15 @@ class StageCore extends EventEmitter$1 {
|
|
|
2486
2497
|
* @param ids 选中元素的id列表
|
|
2487
2498
|
*/
|
|
2488
2499
|
async multiSelect(ids) {
|
|
2489
|
-
const els = ids.map((id) => this.renderer
|
|
2500
|
+
const els = ids.map((id) => this.renderer?.getTargetElement(id)).filter((el) => Boolean(el));
|
|
2490
2501
|
if (els.length === 0) return;
|
|
2491
2502
|
const lastEl = els[els.length - 1];
|
|
2492
2503
|
const isReduceSelect = els.length < this.actionManager.getSelectedElList().length;
|
|
2493
|
-
await this.renderer
|
|
2494
|
-
lastEl && this.mask
|
|
2495
|
-
this.actionManager
|
|
2504
|
+
await this.renderer?.select(ids);
|
|
2505
|
+
lastEl && this.mask?.setLayout(lastEl);
|
|
2506
|
+
this.actionManager?.multiSelect(ids);
|
|
2496
2507
|
if (lastEl && (this.autoScrollIntoView || lastEl.dataset.autoScrollIntoView) && !isReduceSelect) {
|
|
2497
|
-
this.mask
|
|
2508
|
+
this.mask?.observerIntersection(lastEl);
|
|
2498
2509
|
}
|
|
2499
2510
|
}
|
|
2500
2511
|
/**
|
|
@@ -2502,10 +2513,10 @@ class StageCore extends EventEmitter$1 {
|
|
|
2502
2513
|
* @param el 要高亮的元素
|
|
2503
2514
|
*/
|
|
2504
2515
|
highlight(id) {
|
|
2505
|
-
this.actionManager
|
|
2516
|
+
this.actionManager?.highlight(id);
|
|
2506
2517
|
}
|
|
2507
2518
|
clearHighlight() {
|
|
2508
|
-
this.actionManager
|
|
2519
|
+
this.actionManager?.clearHighlight();
|
|
2509
2520
|
}
|
|
2510
2521
|
/**
|
|
2511
2522
|
* 更新组件
|
|
@@ -2513,11 +2524,11 @@ class StageCore extends EventEmitter$1 {
|
|
|
2513
2524
|
*/
|
|
2514
2525
|
async update(data) {
|
|
2515
2526
|
const { config } = data;
|
|
2516
|
-
await this.renderer
|
|
2527
|
+
await this.renderer?.update(data);
|
|
2517
2528
|
setTimeout(() => {
|
|
2518
|
-
const el = this.renderer
|
|
2519
|
-
if (el && this.actionManager
|
|
2520
|
-
this.mask
|
|
2529
|
+
const el = this.renderer?.getTargetElement(`${config.id}`);
|
|
2530
|
+
if (el && this.actionManager?.isSelectedEl(el)) {
|
|
2531
|
+
this.mask?.setLayout(el);
|
|
2521
2532
|
this.actionManager.setSelectedEl(el);
|
|
2522
2533
|
this.actionManager.updateMoveable(el);
|
|
2523
2534
|
}
|
|
@@ -2528,17 +2539,17 @@ class StageCore extends EventEmitter$1 {
|
|
|
2528
2539
|
* @param data 组件信息数据
|
|
2529
2540
|
*/
|
|
2530
2541
|
async add(data) {
|
|
2531
|
-
return await this.renderer
|
|
2542
|
+
return await this.renderer?.add(data);
|
|
2532
2543
|
}
|
|
2533
2544
|
/**
|
|
2534
2545
|
* 从画布删除一个组件
|
|
2535
2546
|
* @param data 组件信息数据
|
|
2536
2547
|
*/
|
|
2537
2548
|
async remove(data) {
|
|
2538
|
-
return await this.renderer
|
|
2549
|
+
return await this.renderer?.remove(data);
|
|
2539
2550
|
}
|
|
2540
2551
|
setZoom(zoom = DEFAULT_ZOOM) {
|
|
2541
|
-
this.renderer
|
|
2552
|
+
this.renderer?.setZoom(zoom);
|
|
2542
2553
|
}
|
|
2543
2554
|
/**
|
|
2544
2555
|
* 挂载Dom节点
|
|
@@ -2547,16 +2558,16 @@ class StageCore extends EventEmitter$1 {
|
|
|
2547
2558
|
async mount(el) {
|
|
2548
2559
|
this.container = el;
|
|
2549
2560
|
const { mask, renderer } = this;
|
|
2550
|
-
await renderer
|
|
2551
|
-
mask
|
|
2561
|
+
await renderer?.mount(el);
|
|
2562
|
+
mask?.mount(el);
|
|
2552
2563
|
this.emit("mounted");
|
|
2553
2564
|
}
|
|
2554
2565
|
/**
|
|
2555
2566
|
* 清空所有参考线
|
|
2556
2567
|
*/
|
|
2557
2568
|
clearGuides() {
|
|
2558
|
-
this.mask
|
|
2559
|
-
this.actionManager
|
|
2569
|
+
this.mask?.clearGuides();
|
|
2570
|
+
this.actionManager?.clearGuides();
|
|
2560
2571
|
}
|
|
2561
2572
|
/**
|
|
2562
2573
|
* @deprecated 废弃接口,建议用delayedMarkContainer代替
|
|
@@ -2572,31 +2583,35 @@ class StageCore extends EventEmitter$1 {
|
|
|
2572
2583
|
* @returns timeoutId,调用方在鼠标移走时要取消该timeout,阻止标记
|
|
2573
2584
|
*/
|
|
2574
2585
|
delayedMarkContainer(event, excludeElList = []) {
|
|
2575
|
-
return this.actionManager
|
|
2586
|
+
return this.actionManager?.delayedMarkContainer(event, excludeElList);
|
|
2576
2587
|
}
|
|
2577
2588
|
getMoveableOption(key) {
|
|
2578
|
-
return this.actionManager
|
|
2589
|
+
return this.actionManager?.getMoveableOption(key);
|
|
2579
2590
|
}
|
|
2580
2591
|
getDragStatus() {
|
|
2581
|
-
return this.actionManager
|
|
2592
|
+
return this.actionManager?.getDragStatus();
|
|
2582
2593
|
}
|
|
2583
2594
|
disableMultiSelect() {
|
|
2584
|
-
this.actionManager
|
|
2595
|
+
this.actionManager?.disableMultiSelect();
|
|
2585
2596
|
}
|
|
2586
2597
|
enableMultiSelect() {
|
|
2587
|
-
this.actionManager
|
|
2598
|
+
this.actionManager?.enableMultiSelect();
|
|
2588
2599
|
}
|
|
2589
2600
|
/**
|
|
2590
2601
|
* 销毁实例
|
|
2591
2602
|
*/
|
|
2592
2603
|
destroy() {
|
|
2593
2604
|
const { mask, renderer, actionManager, pageResizeObserver } = this;
|
|
2594
|
-
renderer
|
|
2595
|
-
mask
|
|
2596
|
-
actionManager
|
|
2605
|
+
renderer?.destroy();
|
|
2606
|
+
mask?.destroy();
|
|
2607
|
+
actionManager?.destroy();
|
|
2597
2608
|
pageResizeObserver?.disconnect();
|
|
2598
2609
|
this.removeAllListeners();
|
|
2599
2610
|
this.container = void 0;
|
|
2611
|
+
this.renderer = null;
|
|
2612
|
+
this.mask = null;
|
|
2613
|
+
this.actionManager = null;
|
|
2614
|
+
this.pageResizeObserver = null;
|
|
2600
2615
|
}
|
|
2601
2616
|
on(eventName, listener) {
|
|
2602
2617
|
return super.on(eventName, listener);
|
|
@@ -2613,8 +2628,8 @@ class StageCore extends EventEmitter$1 {
|
|
|
2613
2628
|
}
|
|
2614
2629
|
if (typeof ResizeObserver !== "undefined") {
|
|
2615
2630
|
this.pageResizeObserver = new ResizeObserver((entries) => {
|
|
2616
|
-
this.mask
|
|
2617
|
-
this.actionManager
|
|
2631
|
+
this.mask?.pageResize(entries);
|
|
2632
|
+
this.actionManager?.updateMoveable();
|
|
2618
2633
|
});
|
|
2619
2634
|
this.pageResizeObserver.observe(page);
|
|
2620
2635
|
}
|
|
@@ -2639,18 +2654,18 @@ class StageCore extends EventEmitter$1 {
|
|
|
2639
2654
|
return actionManagerConfig;
|
|
2640
2655
|
}
|
|
2641
2656
|
initRenderEvent() {
|
|
2642
|
-
this.renderer
|
|
2657
|
+
this.renderer?.on("runtime-ready", (runtime) => {
|
|
2643
2658
|
this.emit("runtime-ready", runtime);
|
|
2644
2659
|
});
|
|
2645
|
-
this.renderer
|
|
2660
|
+
this.renderer?.on("page-el-update", (el) => {
|
|
2646
2661
|
this.mask?.observe(el);
|
|
2647
2662
|
this.observePageResize(el);
|
|
2648
2663
|
this.emit("page-el-update", el);
|
|
2649
2664
|
});
|
|
2650
2665
|
}
|
|
2651
2666
|
initMaskEvent() {
|
|
2652
|
-
this.mask
|
|
2653
|
-
this.actionManager
|
|
2667
|
+
this.mask?.on("change-guides", (data) => {
|
|
2668
|
+
this.actionManager?.setGuidelines(data.type, data.guides);
|
|
2654
2669
|
this.emit("change-guides", data);
|
|
2655
2670
|
});
|
|
2656
2671
|
}
|
|
@@ -2668,7 +2683,7 @@ class StageCore extends EventEmitter$1 {
|
|
|
2668
2683
|
* 初始化ActionManager类本身抛出来的事件监听
|
|
2669
2684
|
*/
|
|
2670
2685
|
initActionManagerEvent() {
|
|
2671
|
-
this.actionManager
|
|
2686
|
+
this.actionManager?.on("before-select", (el, event) => {
|
|
2672
2687
|
const id = getIdFromEl()(el);
|
|
2673
2688
|
id && this.select(id, event);
|
|
2674
2689
|
}).on("select", (selectedEl, event) => {
|
|
@@ -2685,7 +2700,7 @@ class StageCore extends EventEmitter$1 {
|
|
|
2685
2700
|
* 初始化DragResize类通过ActionManager抛出来的事件监听
|
|
2686
2701
|
*/
|
|
2687
2702
|
initDrEvent() {
|
|
2688
|
-
this.actionManager
|
|
2703
|
+
this.actionManager?.on("update", (data) => {
|
|
2689
2704
|
this.emit("update", data);
|
|
2690
2705
|
}).on("sort", (data) => {
|
|
2691
2706
|
this.emit("sort", data);
|
|
@@ -2699,10 +2714,10 @@ class StageCore extends EventEmitter$1 {
|
|
|
2699
2714
|
* 初始化MultiDragResize类通过ActionManager抛出来的事件监听
|
|
2700
2715
|
*/
|
|
2701
2716
|
initMulDrEvent() {
|
|
2702
|
-
this.actionManager
|
|
2717
|
+
this.actionManager?.on("change-to-select", (id, e) => {
|
|
2703
2718
|
this.select(id);
|
|
2704
2719
|
setTimeout(() => {
|
|
2705
|
-
const el = this.renderer
|
|
2720
|
+
const el = this.renderer?.getTargetElement(id);
|
|
2706
2721
|
el && this.emit("select", el, e);
|
|
2707
2722
|
});
|
|
2708
2723
|
}).on("multi-update", (data) => {
|
|
@@ -2713,7 +2728,7 @@ class StageCore extends EventEmitter$1 {
|
|
|
2713
2728
|
* 初始化Highlight类通过ActionManager抛出来的事件监听
|
|
2714
2729
|
*/
|
|
2715
2730
|
initHighlightEvent() {
|
|
2716
|
-
this.actionManager
|
|
2731
|
+
this.actionManager?.on("highlight", (highlightEl) => {
|
|
2717
2732
|
this.emit("highlight", highlightEl);
|
|
2718
2733
|
});
|
|
2719
2734
|
}
|
|
@@ -2721,7 +2736,7 @@ class StageCore extends EventEmitter$1 {
|
|
|
2721
2736
|
* 初始化Highlight类通过ActionManager抛出来的事件监听
|
|
2722
2737
|
*/
|
|
2723
2738
|
initMouseEvent() {
|
|
2724
|
-
this.actionManager
|
|
2739
|
+
this.actionManager?.on("mousemove", (event) => {
|
|
2725
2740
|
this.emit("mousemove", event);
|
|
2726
2741
|
}).on("mouseleave", (event) => {
|
|
2727
2742
|
this.emit("mouseleave", event);
|