@tmagic/stage 1.5.0-beta.1 → 1.5.0-beta.3

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.
@@ -330,7 +330,7 @@
330
330
  /** 目标节点在蒙层上的占位节点,用于跟鼠标交互,避免鼠标事件直接作用到目标节点 */
331
331
  targetShadow;
332
332
  /** 要操作的原始目标节点 */
333
- target;
333
+ target = null;
334
334
  /** 多选:目标节点组 */
335
335
  targetList = [];
336
336
  /** 响应拖拽的状态事件,修改绝对定位布局下targetShadow的dom。
@@ -361,6 +361,8 @@
361
361
  });
362
362
  }
363
363
  destroy() {
364
+ this.target = null;
365
+ this.targetList = [];
364
366
  this.targetShadow.destroy();
365
367
  this.destroyGhostEl();
366
368
  this.moveableHelper.clear();
@@ -967,6 +969,7 @@
967
969
  * 销毁实例
968
970
  */
969
971
  destroy() {
972
+ this.target = null;
970
973
  this.moveable?.destroy();
971
974
  this.dragResizeHelper.destroy();
972
975
  this.dragStatus = StageDragStatus.END;
@@ -1198,6 +1201,7 @@
1198
1201
  * 销毁实例
1199
1202
  */
1200
1203
  destroy() {
1204
+ this.target = void 0;
1201
1205
  this.moveable?.destroy();
1202
1206
  this.targetShadow?.destroy();
1203
1207
  this.moveable = void 0;
@@ -1366,9 +1370,9 @@
1366
1370
  const throttleTime = 100;
1367
1371
  const defaultContainerHighlightDuration = 800;
1368
1372
  class ActionManager extends EventEmitter {
1369
- dr;
1370
- multiDr;
1371
- highlightLayer;
1373
+ dr = null;
1374
+ multiDr = null;
1375
+ highlightLayer = null;
1372
1376
  /** 单选、多选、高亮的容器(蒙层的content) */
1373
1377
  container;
1374
1378
  /** 当前选中的节点 */
@@ -1435,7 +1439,7 @@
1435
1439
  this.disabledMultiSelect = true;
1436
1440
  if (this.multiDr) {
1437
1441
  this.multiDr.destroy();
1438
- this.multiDr = void 0;
1442
+ this.multiDr = null;
1439
1443
  }
1440
1444
  }
1441
1445
  enableMultiSelect() {
@@ -1450,14 +1454,14 @@
1450
1454
  * @param guidelines 参考线坐标数组
1451
1455
  */
1452
1456
  setGuidelines(type, guidelines) {
1453
- this.dr.setGuidelines(type, guidelines);
1457
+ this.dr?.setGuidelines(type, guidelines);
1454
1458
  this.multiDr?.setGuidelines(type, guidelines);
1455
1459
  }
1456
1460
  /**
1457
1461
  * 清空所有参考线
1458
1462
  */
1459
1463
  clearGuides() {
1460
- this.dr.clearGuides();
1464
+ this.dr?.clearGuides();
1461
1465
  this.multiDr?.clearGuides();
1462
1466
  }
1463
1467
  /**
@@ -1465,7 +1469,7 @@
1465
1469
  * @param el 变更的元素
1466
1470
  */
1467
1471
  updateMoveable(el) {
1468
- this.dr.updateMoveable(el);
1472
+ this.dr?.updateMoveable(el);
1469
1473
  this.multiDr?.updateMoveable();
1470
1474
  }
1471
1475
  /**
@@ -1484,7 +1488,7 @@
1484
1488
  return this.selectedElList;
1485
1489
  }
1486
1490
  getMoveableOption(key) {
1487
- if (this.dr.getTarget()) {
1491
+ if (this.dr?.getTarget()) {
1488
1492
  return this.dr.getOption(key);
1489
1493
  }
1490
1494
  if (this.multiDr?.targetList.length) {
@@ -1541,7 +1545,7 @@
1541
1545
  select(el, event) {
1542
1546
  this.setSelectedEl(el);
1543
1547
  this.clearSelectStatus(SelectStatus.MULTI_SELECT);
1544
- this.dr.select(el, event);
1548
+ this.dr?.select(el, event);
1545
1549
  }
1546
1550
  multiSelect(ids) {
1547
1551
  this.selectedElList = [];
@@ -1573,13 +1577,13 @@
1573
1577
  return;
1574
1578
  }
1575
1579
  if (el === this.highlightedEl || !el) return;
1576
- this.highlightLayer.highlight(el);
1580
+ this.highlightLayer?.highlight(el);
1577
1581
  this.highlightedEl = el;
1578
1582
  this.emit("highlight", el);
1579
1583
  }
1580
1584
  clearHighlight() {
1581
1585
  this.setHighlightEl(void 0);
1582
- this.highlightLayer.clearHighlight();
1586
+ this.highlightLayer?.clearHighlight();
1583
1587
  }
1584
1588
  /**
1585
1589
  * 用于在切换选择模式时清除上一次的状态
@@ -1590,7 +1594,7 @@
1590
1594
  this.multiDr?.clearSelectStatus();
1591
1595
  this.selectedElList = [];
1592
1596
  } else {
1593
- this.dr.clearSelectStatus();
1597
+ this.dr?.clearSelectStatus();
1594
1598
  }
1595
1599
  }
1596
1600
  /**
@@ -1625,7 +1629,7 @@
1625
1629
  return void 0;
1626
1630
  }
1627
1631
  getDragStatus() {
1628
- return this.dr.getDragStatus();
1632
+ return this.dr?.getDragStatus();
1629
1633
  }
1630
1634
  destroy() {
1631
1635
  this.container.removeEventListener("mousedown", this.mouseDownHandler);
@@ -1633,9 +1637,14 @@
1633
1637
  this.container.removeEventListener("mouseleave", this.mouseLeaveHandler);
1634
1638
  this.container.removeEventListener("wheel", this.mouseWheelHandler);
1635
1639
  this.container.removeEventListener("dblclick", this.dblclickHandler);
1636
- this.dr.destroy();
1640
+ this.selectedEl = null;
1641
+ this.selectedElList = [];
1642
+ this.dr?.destroy();
1637
1643
  this.multiDr?.destroy();
1638
- this.highlightLayer.destroy();
1644
+ this.highlightLayer?.destroy();
1645
+ this.dr = null;
1646
+ this.multiDr = null;
1647
+ this.highlightLayer = null;
1639
1648
  }
1640
1649
  on(eventName, listener) {
1641
1650
  return super.on(eventName, listener);
@@ -1665,7 +1674,7 @@
1665
1674
  }).on(AbleActionEventType.SELECT_PARENT, () => {
1666
1675
  this.emit("select-parent");
1667
1676
  }).on(AbleActionEventType.REMOVE, () => {
1668
- const drTarget = this.dr.getTarget();
1677
+ const drTarget = this.dr?.getTarget();
1669
1678
  if (!drTarget) return;
1670
1679
  const data = {
1671
1680
  data: [{ el: drTarget }]
@@ -2435,9 +2444,9 @@
2435
2444
 
2436
2445
  class StageCore extends EventEmitter.EventEmitter {
2437
2446
  container;
2438
- renderer;
2439
- mask;
2440
- actionManager;
2447
+ renderer = null;
2448
+ mask = null;
2449
+ actionManager = null;
2441
2450
  pageResizeObserver = null;
2442
2451
  autoScrollIntoView;
2443
2452
  customizedRender;
@@ -2469,13 +2478,15 @@
2469
2478
  * @param id 选中的id
2470
2479
  */
2471
2480
  async select(id, event) {
2472
- const el = this.renderer.getTargetElement(id);
2473
- if (el === this.actionManager.getSelectedEl()) return;
2474
- await this.renderer.select([id]);
2475
- el && this.mask.setLayout(el);
2476
- this.actionManager.select(el, event);
2481
+ const el = this.renderer?.getTargetElement(id) || null;
2482
+ if (el === this.actionManager?.getSelectedEl()) return;
2483
+ await this.renderer?.select([id]);
2484
+ if (el) {
2485
+ this.mask?.setLayout(el);
2486
+ }
2487
+ this.actionManager?.select(el, event);
2477
2488
  if (el && (this.autoScrollIntoView || el.dataset.autoScrollIntoView)) {
2478
- this.mask.observerIntersection(el);
2489
+ this.mask?.observerIntersection(el);
2479
2490
  }
2480
2491
  }
2481
2492
  /**
@@ -2483,15 +2494,15 @@
2483
2494
  * @param ids 选中元素的id列表
2484
2495
  */
2485
2496
  async multiSelect(ids) {
2486
- const els = ids.map((id) => this.renderer.getTargetElement(id)).filter((el) => Boolean(el));
2497
+ const els = ids.map((id) => this.renderer?.getTargetElement(id)).filter((el) => Boolean(el));
2487
2498
  if (els.length === 0) return;
2488
2499
  const lastEl = els[els.length - 1];
2489
2500
  const isReduceSelect = els.length < this.actionManager.getSelectedElList().length;
2490
- await this.renderer.select(ids);
2491
- lastEl && this.mask.setLayout(lastEl);
2492
- this.actionManager.multiSelect(ids);
2501
+ await this.renderer?.select(ids);
2502
+ lastEl && this.mask?.setLayout(lastEl);
2503
+ this.actionManager?.multiSelect(ids);
2493
2504
  if (lastEl && (this.autoScrollIntoView || lastEl.dataset.autoScrollIntoView) && !isReduceSelect) {
2494
- this.mask.observerIntersection(lastEl);
2505
+ this.mask?.observerIntersection(lastEl);
2495
2506
  }
2496
2507
  }
2497
2508
  /**
@@ -2499,10 +2510,10 @@
2499
2510
  * @param el 要高亮的元素
2500
2511
  */
2501
2512
  highlight(id) {
2502
- this.actionManager.highlight(id);
2513
+ this.actionManager?.highlight(id);
2503
2514
  }
2504
2515
  clearHighlight() {
2505
- this.actionManager.clearHighlight();
2516
+ this.actionManager?.clearHighlight();
2506
2517
  }
2507
2518
  /**
2508
2519
  * 更新组件
@@ -2510,11 +2521,11 @@
2510
2521
  */
2511
2522
  async update(data) {
2512
2523
  const { config } = data;
2513
- await this.renderer.update(data);
2524
+ await this.renderer?.update(data);
2514
2525
  setTimeout(() => {
2515
- const el = this.renderer.getTargetElement(`${config.id}`);
2516
- if (el && this.actionManager.isSelectedEl(el)) {
2517
- this.mask.setLayout(el);
2526
+ const el = this.renderer?.getTargetElement(`${config.id}`);
2527
+ if (el && this.actionManager?.isSelectedEl(el)) {
2528
+ this.mask?.setLayout(el);
2518
2529
  this.actionManager.setSelectedEl(el);
2519
2530
  this.actionManager.updateMoveable(el);
2520
2531
  }
@@ -2525,17 +2536,17 @@
2525
2536
  * @param data 组件信息数据
2526
2537
  */
2527
2538
  async add(data) {
2528
- return await this.renderer.add(data);
2539
+ return await this.renderer?.add(data);
2529
2540
  }
2530
2541
  /**
2531
2542
  * 从画布删除一个组件
2532
2543
  * @param data 组件信息数据
2533
2544
  */
2534
2545
  async remove(data) {
2535
- return await this.renderer.remove(data);
2546
+ return await this.renderer?.remove(data);
2536
2547
  }
2537
2548
  setZoom(zoom = DEFAULT_ZOOM) {
2538
- this.renderer.setZoom(zoom);
2549
+ this.renderer?.setZoom(zoom);
2539
2550
  }
2540
2551
  /**
2541
2552
  * 挂载Dom节点
@@ -2544,16 +2555,16 @@
2544
2555
  async mount(el) {
2545
2556
  this.container = el;
2546
2557
  const { mask, renderer } = this;
2547
- await renderer.mount(el);
2548
- mask.mount(el);
2558
+ await renderer?.mount(el);
2559
+ mask?.mount(el);
2549
2560
  this.emit("mounted");
2550
2561
  }
2551
2562
  /**
2552
2563
  * 清空所有参考线
2553
2564
  */
2554
2565
  clearGuides() {
2555
- this.mask.clearGuides();
2556
- this.actionManager.clearGuides();
2566
+ this.mask?.clearGuides();
2567
+ this.actionManager?.clearGuides();
2557
2568
  }
2558
2569
  /**
2559
2570
  * @deprecated 废弃接口,建议用delayedMarkContainer代替
@@ -2569,31 +2580,35 @@
2569
2580
  * @returns timeoutId,调用方在鼠标移走时要取消该timeout,阻止标记
2570
2581
  */
2571
2582
  delayedMarkContainer(event, excludeElList = []) {
2572
- return this.actionManager.delayedMarkContainer(event, excludeElList);
2583
+ return this.actionManager?.delayedMarkContainer(event, excludeElList);
2573
2584
  }
2574
2585
  getMoveableOption(key) {
2575
- return this.actionManager.getMoveableOption(key);
2586
+ return this.actionManager?.getMoveableOption(key);
2576
2587
  }
2577
2588
  getDragStatus() {
2578
- return this.actionManager.getDragStatus();
2589
+ return this.actionManager?.getDragStatus();
2579
2590
  }
2580
2591
  disableMultiSelect() {
2581
- this.actionManager.disableMultiSelect();
2592
+ this.actionManager?.disableMultiSelect();
2582
2593
  }
2583
2594
  enableMultiSelect() {
2584
- this.actionManager.enableMultiSelect();
2595
+ this.actionManager?.enableMultiSelect();
2585
2596
  }
2586
2597
  /**
2587
2598
  * 销毁实例
2588
2599
  */
2589
2600
  destroy() {
2590
2601
  const { mask, renderer, actionManager, pageResizeObserver } = this;
2591
- renderer.destroy();
2592
- mask.destroy();
2593
- actionManager.destroy();
2602
+ renderer?.destroy();
2603
+ mask?.destroy();
2604
+ actionManager?.destroy();
2594
2605
  pageResizeObserver?.disconnect();
2595
2606
  this.removeAllListeners();
2596
2607
  this.container = void 0;
2608
+ this.renderer = null;
2609
+ this.mask = null;
2610
+ this.actionManager = null;
2611
+ this.pageResizeObserver = null;
2597
2612
  }
2598
2613
  on(eventName, listener) {
2599
2614
  return super.on(eventName, listener);
@@ -2610,8 +2625,8 @@
2610
2625
  }
2611
2626
  if (typeof ResizeObserver !== "undefined") {
2612
2627
  this.pageResizeObserver = new ResizeObserver((entries) => {
2613
- this.mask.pageResize(entries);
2614
- this.actionManager.updateMoveable();
2628
+ this.mask?.pageResize(entries);
2629
+ this.actionManager?.updateMoveable();
2615
2630
  });
2616
2631
  this.pageResizeObserver.observe(page);
2617
2632
  }
@@ -2636,18 +2651,18 @@
2636
2651
  return actionManagerConfig;
2637
2652
  }
2638
2653
  initRenderEvent() {
2639
- this.renderer.on("runtime-ready", (runtime) => {
2654
+ this.renderer?.on("runtime-ready", (runtime) => {
2640
2655
  this.emit("runtime-ready", runtime);
2641
2656
  });
2642
- this.renderer.on("page-el-update", (el) => {
2657
+ this.renderer?.on("page-el-update", (el) => {
2643
2658
  this.mask?.observe(el);
2644
2659
  this.observePageResize(el);
2645
2660
  this.emit("page-el-update", el);
2646
2661
  });
2647
2662
  }
2648
2663
  initMaskEvent() {
2649
- this.mask.on("change-guides", (data) => {
2650
- this.actionManager.setGuidelines(data.type, data.guides);
2664
+ this.mask?.on("change-guides", (data) => {
2665
+ this.actionManager?.setGuidelines(data.type, data.guides);
2651
2666
  this.emit("change-guides", data);
2652
2667
  });
2653
2668
  }
@@ -2665,7 +2680,7 @@
2665
2680
  * 初始化ActionManager类本身抛出来的事件监听
2666
2681
  */
2667
2682
  initActionManagerEvent() {
2668
- this.actionManager.on("before-select", (el, event) => {
2683
+ this.actionManager?.on("before-select", (el, event) => {
2669
2684
  const id = utils.getIdFromEl()(el);
2670
2685
  id && this.select(id, event);
2671
2686
  }).on("select", (selectedEl, event) => {
@@ -2682,7 +2697,7 @@
2682
2697
  * 初始化DragResize类通过ActionManager抛出来的事件监听
2683
2698
  */
2684
2699
  initDrEvent() {
2685
- this.actionManager.on("update", (data) => {
2700
+ this.actionManager?.on("update", (data) => {
2686
2701
  this.emit("update", data);
2687
2702
  }).on("sort", (data) => {
2688
2703
  this.emit("sort", data);
@@ -2696,10 +2711,10 @@
2696
2711
  * 初始化MultiDragResize类通过ActionManager抛出来的事件监听
2697
2712
  */
2698
2713
  initMulDrEvent() {
2699
- this.actionManager.on("change-to-select", (id, e) => {
2714
+ this.actionManager?.on("change-to-select", (id, e) => {
2700
2715
  this.select(id);
2701
2716
  setTimeout(() => {
2702
- const el = this.renderer.getTargetElement(id);
2717
+ const el = this.renderer?.getTargetElement(id);
2703
2718
  el && this.emit("select", el, e);
2704
2719
  });
2705
2720
  }).on("multi-update", (data) => {
@@ -2710,7 +2725,7 @@
2710
2725
  * 初始化Highlight类通过ActionManager抛出来的事件监听
2711
2726
  */
2712
2727
  initHighlightEvent() {
2713
- this.actionManager.on("highlight", (highlightEl) => {
2728
+ this.actionManager?.on("highlight", (highlightEl) => {
2714
2729
  this.emit("highlight", highlightEl);
2715
2730
  });
2716
2731
  }
@@ -2718,7 +2733,7 @@
2718
2733
  * 初始化Highlight类通过ActionManager抛出来的事件监听
2719
2734
  */
2720
2735
  initMouseEvent() {
2721
- this.actionManager.on("mousemove", (event) => {
2736
+ this.actionManager?.on("mousemove", (event) => {
2722
2737
  this.emit("mousemove", event);
2723
2738
  }).on("mouseleave", (event) => {
2724
2739
  this.emit("mouseleave", event);
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.5.0-beta.1",
2
+ "version": "1.5.0-beta.3",
3
3
  "name": "@tmagic/stage",
4
4
  "type": "module",
5
5
  "main": "dist/tmagic-stage.umd.cjs",
@@ -45,9 +45,9 @@
45
45
  },
46
46
  "peerDependencies": {
47
47
  "typescript": "*",
48
- "@tmagic/utils": "1.5.0-beta.1",
49
- "@tmagic/core": "1.5.0-beta.1",
50
- "@tmagic/schema": "1.5.0-beta.1"
48
+ "@tmagic/core": "1.5.0-beta.3",
49
+ "@tmagic/schema": "1.5.0-beta.3",
50
+ "@tmagic/utils": "1.5.0-beta.3"
51
51
  },
52
52
  "peerDependenciesMeta": {
53
53
  "typescript": {
@@ -65,9 +65,9 @@ const defaultContainerHighlightDuration = 800;
65
65
  * @extends EventEmitter
66
66
  */
67
67
  export default class ActionManager extends EventEmitter {
68
- private dr: StageDragResize;
69
- private multiDr?: StageMultiDragResize;
70
- private highlightLayer: StageHighlight;
68
+ private dr: StageDragResize | null = null;
69
+ private multiDr: StageMultiDragResize | null = null;
70
+ private highlightLayer: StageHighlight | null = null;
71
71
  /** 单选、多选、高亮的容器(蒙层的content) */
72
72
  private container: HTMLElement;
73
73
  /** 当前选中的节点 */
@@ -143,7 +143,7 @@ export default class ActionManager extends EventEmitter {
143
143
  this.disabledMultiSelect = true;
144
144
  if (this.multiDr) {
145
145
  this.multiDr.destroy();
146
- this.multiDr = undefined;
146
+ this.multiDr = null;
147
147
  }
148
148
  }
149
149
 
@@ -161,7 +161,7 @@ export default class ActionManager extends EventEmitter {
161
161
  * @param guidelines 参考线坐标数组
162
162
  */
163
163
  public setGuidelines(type: GuidesType, guidelines: number[]): void {
164
- this.dr.setGuidelines(type, guidelines);
164
+ this.dr?.setGuidelines(type, guidelines);
165
165
  this.multiDr?.setGuidelines(type, guidelines);
166
166
  }
167
167
 
@@ -169,7 +169,7 @@ export default class ActionManager extends EventEmitter {
169
169
  * 清空所有参考线
170
170
  */
171
171
  public clearGuides(): void {
172
- this.dr.clearGuides();
172
+ this.dr?.clearGuides();
173
173
  this.multiDr?.clearGuides();
174
174
  }
175
175
 
@@ -178,7 +178,7 @@ export default class ActionManager extends EventEmitter {
178
178
  * @param el 变更的元素
179
179
  */
180
180
  public updateMoveable(el?: HTMLElement): void {
181
- this.dr.updateMoveable(el);
181
+ this.dr?.updateMoveable(el);
182
182
  // 多选时不可配置元素,因此不存在多选元素变更,不需要传el
183
183
  this.multiDr?.updateMoveable();
184
184
  }
@@ -204,7 +204,7 @@ export default class ActionManager extends EventEmitter {
204
204
  }
205
205
 
206
206
  public getMoveableOption<K extends keyof MoveableOptions>(key: K): MoveableOptions[K] | undefined {
207
- if (this.dr.getTarget()) {
207
+ if (this.dr?.getTarget()) {
208
208
  return this.dr.getOption(key);
209
209
  }
210
210
  if (this.multiDr?.targetList.length) {
@@ -271,7 +271,7 @@ export default class ActionManager extends EventEmitter {
271
271
  public select(el: HTMLElement | null, event?: MouseEvent): void {
272
272
  this.setSelectedEl(el);
273
273
  this.clearSelectStatus(SelectStatus.MULTI_SELECT);
274
- this.dr.select(el, event);
274
+ this.dr?.select(el, event);
275
275
  }
276
276
 
277
277
  public multiSelect(ids: Id[]): void {
@@ -310,14 +310,14 @@ export default class ActionManager extends EventEmitter {
310
310
  }
311
311
  if (el === this.highlightedEl || !el) return;
312
312
 
313
- this.highlightLayer.highlight(el);
313
+ this.highlightLayer?.highlight(el);
314
314
  this.highlightedEl = el;
315
315
  this.emit('highlight', el);
316
316
  }
317
317
 
318
318
  public clearHighlight(): void {
319
319
  this.setHighlightEl(undefined);
320
- this.highlightLayer.clearHighlight();
320
+ this.highlightLayer?.clearHighlight();
321
321
  }
322
322
 
323
323
  /**
@@ -329,7 +329,7 @@ export default class ActionManager extends EventEmitter {
329
329
  this.multiDr?.clearSelectStatus();
330
330
  this.selectedElList = [];
331
331
  } else {
332
- this.dr.clearSelectStatus();
332
+ this.dr?.clearSelectStatus();
333
333
  }
334
334
  }
335
335
 
@@ -373,7 +373,7 @@ export default class ActionManager extends EventEmitter {
373
373
  }
374
374
 
375
375
  public getDragStatus() {
376
- return this.dr.getDragStatus();
376
+ return this.dr?.getDragStatus();
377
377
  }
378
378
 
379
379
  public destroy(): void {
@@ -382,9 +382,16 @@ export default class ActionManager extends EventEmitter {
382
382
  this.container.removeEventListener('mouseleave', this.mouseLeaveHandler);
383
383
  this.container.removeEventListener('wheel', this.mouseWheelHandler);
384
384
  this.container.removeEventListener('dblclick', this.dblclickHandler);
385
- this.dr.destroy();
385
+ this.selectedEl = null;
386
+ this.selectedElList = [];
387
+
388
+ this.dr?.destroy();
386
389
  this.multiDr?.destroy();
387
- this.highlightLayer.destroy();
390
+ this.highlightLayer?.destroy();
391
+
392
+ this.dr = null;
393
+ this.multiDr = null;
394
+ this.highlightLayer = null;
388
395
  }
389
396
 
390
397
  public on<Name extends keyof ActionManagerEvents, Param extends ActionManagerEvents[Name]>(
@@ -431,7 +438,7 @@ export default class ActionManager extends EventEmitter {
431
438
  this.emit('select-parent');
432
439
  })
433
440
  .on(AbleActionEventType.REMOVE, () => {
434
- const drTarget = this.dr.getTarget();
441
+ const drTarget = this.dr?.getTarget();
435
442
  if (!drTarget) return;
436
443
  const data: RemoveEventData = {
437
444
  data: [{ el: drTarget }],
@@ -50,7 +50,7 @@ export default class DragResizeHelper {
50
50
  /** 目标节点在蒙层上的占位节点,用于跟鼠标交互,避免鼠标事件直接作用到目标节点 */
51
51
  private targetShadow: TargetShadow;
52
52
  /** 要操作的原始目标节点 */
53
- private target!: HTMLElement;
53
+ private target: HTMLElement | null = null;
54
54
  /** 多选:目标节点组 */
55
55
  private targetList: HTMLElement[] = [];
56
56
  /** 响应拖拽的状态事件,修改绝对定位布局下targetShadow的dom。
@@ -84,6 +84,8 @@ export default class DragResizeHelper {
84
84
  }
85
85
 
86
86
  public destroy(): void {
87
+ this.target = null;
88
+ this.targetList = [];
87
89
  this.targetShadow.destroy();
88
90
  this.destroyGhostEl();
89
91
  this.moveableHelper.clear();
@@ -114,8 +116,8 @@ export default class DragResizeHelper {
114
116
  public onResizeStart(e: OnResizeStart): void {
115
117
  this.moveableHelper.onResizeStart(e);
116
118
 
117
- this.frameSnapShot.top = this.target.offsetTop;
118
- this.frameSnapShot.left = this.target.offsetLeft;
119
+ this.frameSnapShot.top = this.target!.offsetTop;
120
+ this.frameSnapShot.left = this.target!.offsetLeft;
119
121
  }
120
122
 
121
123
  public onResize(e: OnResize): void {
@@ -123,33 +125,33 @@ export default class DragResizeHelper {
123
125
  const { beforeTranslate } = drag;
124
126
  // 流式布局
125
127
  if (this.mode === Mode.SORTABLE) {
126
- this.target.style.top = '0px';
128
+ this.target!.style.top = '0px';
127
129
  if (this.targetShadow.el) {
128
130
  this.targetShadow.el.style.width = `${width}px`;
129
131
  this.targetShadow.el.style.height = `${height}px`;
130
132
  }
131
133
  } else {
132
134
  this.moveableHelper.onResize(e);
133
- const { marginLeft, marginTop } = getMarginValue(this.target);
134
- this.target.style.left = `${this.frameSnapShot.left + beforeTranslate[0] - marginLeft}px`;
135
- this.target.style.top = `${this.frameSnapShot.top + beforeTranslate[1] - marginTop}px`;
135
+ const { marginLeft, marginTop } = getMarginValue(this.target!);
136
+ this.target!.style.left = `${this.frameSnapShot.left + beforeTranslate[0] - marginLeft}px`;
137
+ this.target!.style.top = `${this.frameSnapShot.top + beforeTranslate[1] - marginTop}px`;
136
138
  }
137
139
 
138
- const { borderLeftWidth, borderRightWidth, borderTopWidth, borderBottomWidth } = getBorderWidth(this.target);
140
+ const { borderLeftWidth, borderRightWidth, borderTopWidth, borderBottomWidth } = getBorderWidth(this.target!);
139
141
 
140
- this.target.style.width = `${width + borderLeftWidth + borderRightWidth}px`;
141
- this.target.style.height = `${height + borderTopWidth + borderBottomWidth}px`;
142
+ this.target!.style.width = `${width + borderLeftWidth + borderRightWidth}px`;
143
+ this.target!.style.height = `${height + borderTopWidth + borderBottomWidth}px`;
142
144
  }
143
145
 
144
146
  public onDragStart(e: OnDragStart): void {
145
147
  this.moveableHelper.onDragStart(e);
146
148
 
147
149
  if (this.mode === Mode.SORTABLE) {
148
- this.ghostEl = this.generateGhostEl(this.target);
150
+ this.ghostEl = this.generateGhostEl(this.target!);
149
151
  }
150
152
 
151
- this.frameSnapShot.top = this.target.offsetTop;
152
- this.frameSnapShot.left = this.target.offsetLeft;
153
+ this.frameSnapShot.top = this.target!.offsetTop;
154
+ this.frameSnapShot.left = this.target!.offsetLeft;
153
155
  }
154
156
 
155
157
  public onDrag(e: OnDrag): void {
@@ -161,10 +163,10 @@ export default class DragResizeHelper {
161
163
 
162
164
  this.moveableHelper.onDrag(e);
163
165
 
164
- const { marginLeft, marginTop } = getMarginValue(this.target);
166
+ const { marginLeft, marginTop } = getMarginValue(this.target!);
165
167
 
166
- this.target.style.left = `${this.frameSnapShot.left + e.beforeTranslate[0] - marginLeft}px`;
167
- this.target.style.top = `${this.frameSnapShot.top + e.beforeTranslate[1] - marginTop}px`;
168
+ this.target!.style.left = `${this.frameSnapShot.left + e.beforeTranslate[0] - marginLeft}px`;
169
+ this.target!.style.top = `${this.frameSnapShot.top + e.beforeTranslate[1] - marginTop}px`;
168
170
  }
169
171
 
170
172
  public onRotateStart(e: OnRotateStart): void {
@@ -174,7 +176,7 @@ export default class DragResizeHelper {
174
176
  public onRotate(e: OnRotate): void {
175
177
  this.moveableHelper.onRotate(e);
176
178
  const frame = this.moveableHelper.getFrame(e.target);
177
- this.target.style.transform = frame?.toCSSObject().transform || '';
179
+ this.target!.style.transform = frame?.toCSSObject().transform || '';
178
180
  }
179
181
 
180
182
  public onScaleStart(e: OnScaleStart): void {
@@ -184,7 +186,7 @@ export default class DragResizeHelper {
184
186
  public onScale(e: OnScale): void {
185
187
  this.moveableHelper.onScale(e);
186
188
  const frame = this.moveableHelper.getFrame(e.target);
187
- this.target.style.transform = frame?.toCSSObject().transform || '';
189
+ this.target!.style.transform = frame?.toCSSObject().transform || '';
188
190
  }
189
191
 
190
192
  public getGhostEl(): HTMLElement | undefined {