@tmagic/stage 1.5.12 → 1.5.14

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.
@@ -293,7 +293,7 @@ class TargetShadow {
293
293
  }
294
294
  destroyEl() {
295
295
  this.el?.remove();
296
- this.el = undefined;
296
+ this.el = void 0;
297
297
  }
298
298
  destroyEls() {
299
299
  this.els.forEach((el) => {
@@ -453,7 +453,7 @@ class DragResizeHelper {
453
453
  }
454
454
  destroyGhostEl() {
455
455
  this.ghostEl?.remove();
456
- this.ghostEl = undefined;
456
+ this.ghostEl = void 0;
457
457
  }
458
458
  clear() {
459
459
  this.moveableHelper.clear();
@@ -522,9 +522,13 @@ class DragResizeHelper {
522
522
  (frameItem) => getIdFromEl()(ev.target)?.startsWith(DRAG_EL_ID_PREFIX) && getIdFromEl()(ev.target)?.endsWith(frameItem.id)
523
523
  );
524
524
  if (!frameSnapShot) return;
525
- const targeEl = this.targetList.find(
526
- (targetItem) => getIdFromEl()(ev.target)?.startsWith(DRAG_EL_ID_PREFIX) && getIdFromEl()(targetItem) && getIdFromEl()(ev.target)?.endsWith(getIdFromEl()(targetItem))
527
- );
525
+ const findTargetElFuctin = (targetItem) => {
526
+ const getId = getIdFromEl();
527
+ const targetId = getId(ev.target);
528
+ const targetItemId = getId(targetItem);
529
+ return targetId?.startsWith(DRAG_EL_ID_PREFIX) && targetItemId && targetId?.endsWith(targetItemId);
530
+ };
531
+ const targeEl = this.targetList.find(findTargetElFuctin);
528
532
  if (!targeEl) return;
529
533
  const isParentIncluded = this.targetList.find(
530
534
  (targetItem) => getIdFromEl()(targetItem) === getIdFromEl()(targeEl.parentElement)
@@ -802,7 +806,7 @@ class MoveableOptionsManager extends EventEmitter {
802
806
  top: 0,
803
807
  left: 0,
804
808
  right: this.container.clientWidth,
805
- bottom: isSortable ? undefined : this.container.clientHeight
809
+ bottom: isSortable ? void 0 : this.container.clientHeight
806
810
  }
807
811
  };
808
812
  const differenceOptions = isMultiSelect ? this.getMultiOptions() : this.getSingleOptions();
@@ -952,7 +956,7 @@ class StageDragResize extends MoveableOptionsManager {
952
956
  select(el, event) {
953
957
  if (!el) {
954
958
  this.moveable?.destroy();
955
- this.moveable = undefined;
959
+ this.moveable = void 0;
956
960
  return;
957
961
  }
958
962
  if (!this.moveable || el !== this.target) {
@@ -1053,7 +1057,7 @@ class StageDragResize extends MoveableOptionsManager {
1053
1057
  if (!this.target || !this.dragResizeHelper.getShadowEl()) return;
1054
1058
  if (timeout) {
1055
1059
  globalThis.clearTimeout(timeout);
1056
- timeout = undefined;
1060
+ timeout = void 0;
1057
1061
  }
1058
1062
  timeout = this.delayedMarkContainer(e.inputEvent, [this.target]);
1059
1063
  this.dragStatus = StageDragStatus.ING;
@@ -1061,7 +1065,7 @@ class StageDragResize extends MoveableOptionsManager {
1061
1065
  }).on("dragEnd", () => {
1062
1066
  if (timeout) {
1063
1067
  globalThis.clearTimeout(timeout);
1064
- timeout = undefined;
1068
+ timeout = void 0;
1065
1069
  }
1066
1070
  const parentEl = this.markContainerEnd();
1067
1071
  if (this.dragStatus === StageDragStatus.ING) {
@@ -1215,17 +1219,17 @@ class StageHighlight extends EventEmitter$1 {
1215
1219
  if (!this.moveable || !this.target) return;
1216
1220
  this.moveable.zoom = 0;
1217
1221
  this.moveable.updateRect();
1218
- this.target = undefined;
1222
+ this.target = void 0;
1219
1223
  }
1220
1224
  /**
1221
1225
  * 销毁实例
1222
1226
  */
1223
1227
  destroy() {
1224
- this.target = undefined;
1228
+ this.target = void 0;
1225
1229
  this.moveable?.destroy();
1226
1230
  this.targetShadow?.destroy();
1227
- this.moveable = undefined;
1228
- this.targetShadow = undefined;
1231
+ this.moveable = void 0;
1232
+ this.targetShadow = void 0;
1229
1233
  }
1230
1234
  }
1231
1235
 
@@ -1295,7 +1299,7 @@ class StageMultiDragResize extends MoveableOptionsManager {
1295
1299
  }).on("dragGroup", (e) => {
1296
1300
  if (timeout) {
1297
1301
  globalThis.clearTimeout(timeout);
1298
- timeout = undefined;
1302
+ timeout = void 0;
1299
1303
  }
1300
1304
  timeout = this.delayedMarkContainer(e.inputEvent, this.targetList);
1301
1305
  this.dragResizeHelper.onDragGroup(e);
@@ -1303,7 +1307,7 @@ class StageMultiDragResize extends MoveableOptionsManager {
1303
1307
  }).on("dragGroupEnd", () => {
1304
1308
  if (timeout) {
1305
1309
  globalThis.clearTimeout(timeout);
1306
- timeout = undefined;
1310
+ timeout = void 0;
1307
1311
  }
1308
1312
  const parentEl = this.markContainerEnd();
1309
1313
  this.update(false, parentEl);
@@ -1417,18 +1421,21 @@ class ActionManager extends EventEmitter {
1417
1421
  getRenderDocument;
1418
1422
  disabledMultiSelect = false;
1419
1423
  config;
1420
- mouseMoveHandler = throttle(async (event) => {
1421
- if (event.target?.classList?.contains("moveable-direction")) {
1422
- return;
1423
- }
1424
- const el = await this.getElementFromPoint(event);
1425
- const id = getIdFromEl()(el);
1426
- if (!id) {
1427
- this.clearHighlight();
1428
- return;
1429
- }
1430
- this.emit("mousemove", event);
1431
- this.highlight(id);
1424
+ mouseMoveHandler = throttle((event) => {
1425
+ const handler = async () => {
1426
+ if (event.target?.classList?.contains("moveable-direction")) {
1427
+ return;
1428
+ }
1429
+ const el = await this.getElementFromPoint(event);
1430
+ const id = getIdFromEl()(el);
1431
+ if (!id) {
1432
+ this.clearHighlight();
1433
+ return;
1434
+ }
1435
+ this.emit("mousemove", event);
1436
+ this.highlight(id);
1437
+ };
1438
+ handler();
1432
1439
  }, throttleTime);
1433
1440
  constructor(config) {
1434
1441
  super();
@@ -1590,6 +1597,7 @@ class ActionManager extends EventEmitter {
1590
1597
  el = this.getTargetElement(id);
1591
1598
  } catch (error) {
1592
1599
  this.clearHighlight();
1600
+ console.warn("getTargetElement error:", error);
1593
1601
  return;
1594
1602
  }
1595
1603
  if (el === this.getSelectedEl() || this.multiDr?.dragStatus === StageDragStatus.ING) {
@@ -1602,7 +1610,7 @@ class ActionManager extends EventEmitter {
1602
1610
  this.emit("highlight", el);
1603
1611
  }
1604
1612
  clearHighlight() {
1605
- this.setHighlightEl(undefined);
1613
+ this.setHighlightEl(void 0);
1606
1614
  this.highlightLayer?.clearHighlight();
1607
1615
  }
1608
1616
  /**
@@ -1646,7 +1654,7 @@ class ActionManager extends EventEmitter {
1646
1654
  this.addContainerHighlightClassName(event, excludeElList);
1647
1655
  }, this.containerHighlightDuration);
1648
1656
  }
1649
- return undefined;
1657
+ return void 0;
1650
1658
  }
1651
1659
  getDragStatus() {
1652
1660
  return this.dr?.getDragStatus();
@@ -1830,23 +1838,26 @@ class ActionManager extends EventEmitter {
1830
1838
  /**
1831
1839
  * 在down事件中集中cpu处理画布中选中操作渲染,在up事件中再通知外面的编辑器更新
1832
1840
  */
1833
- mouseDownHandler = async (event) => {
1834
- this.clearHighlight();
1835
- event.stopImmediatePropagation();
1836
- event.stopPropagation();
1837
- if (this.isStopTriggerSelect(event)) return;
1838
- this.container.removeEventListener("mousemove", this.mouseMoveHandler);
1839
- if (this.isMultiSelectStatus) {
1840
- await this.beforeMultiSelect(event);
1841
- if (this.selectedElList.length > 0) {
1842
- this.emit("before-multi-select", this.selectedElList);
1841
+ mouseDownHandler = (event) => {
1842
+ const handler = async () => {
1843
+ this.clearHighlight();
1844
+ event.stopImmediatePropagation();
1845
+ event.stopPropagation();
1846
+ if (this.isStopTriggerSelect(event)) return;
1847
+ this.container.removeEventListener("mousemove", this.mouseMoveHandler);
1848
+ if (this.isMultiSelectStatus) {
1849
+ await this.beforeMultiSelect(event);
1850
+ if (this.selectedElList.length > 0) {
1851
+ this.emit("before-multi-select", this.selectedElList);
1852
+ }
1853
+ } else {
1854
+ const el = await this.getElementFromPoint(event);
1855
+ if (!el) return;
1856
+ this.emit("before-select", el, event);
1843
1857
  }
1844
- } else {
1845
- const el = await this.getElementFromPoint(event);
1846
- if (!el) return;
1847
- this.emit("before-select", el, event);
1848
- }
1849
- getDocument().addEventListener("mouseup", this.mouseUpHandler);
1858
+ getDocument().addEventListener("mouseup", this.mouseUpHandler);
1859
+ };
1860
+ handler();
1850
1861
  };
1851
1862
  isStopTriggerSelect(event) {
1852
1863
  if (event.button !== MouseButton.LEFT && event.button !== MouseButton.RIGHT) return true;
@@ -2409,7 +2420,7 @@ class StageRender extends EventEmitter$1 {
2409
2420
  this.iframe?.removeEventListener("load", this.iframeLoadHandler);
2410
2421
  this.contentWindow = null;
2411
2422
  this.iframe?.remove();
2412
- this.iframe = undefined;
2423
+ this.iframe = void 0;
2413
2424
  this.removeAllListeners();
2414
2425
  }
2415
2426
  on(eventName, listener) {
@@ -2451,19 +2462,22 @@ class StageRender extends EventEmitter$1 {
2451
2462
  el && addSelectedClassName(el, doc);
2452
2463
  }
2453
2464
  }
2454
- iframeLoadHandler = async () => {
2455
- if (!this.contentWindow?.magic) {
2456
- this.postTmagicRuntimeReady();
2457
- }
2458
- if (!this.contentWindow) return;
2459
- if (this.customizedRender) {
2460
- const el = await this.customizedRender();
2461
- if (el) {
2462
- this.contentWindow.document?.body?.appendChild(el);
2465
+ iframeLoadHandler = () => {
2466
+ const handler = async () => {
2467
+ if (!this.contentWindow?.magic) {
2468
+ this.postTmagicRuntimeReady();
2463
2469
  }
2464
- }
2465
- this.emit("onload");
2466
- injectStyle(this.contentWindow.document, style);
2470
+ if (!this.contentWindow) return;
2471
+ if (this.customizedRender) {
2472
+ const el = await this.customizedRender();
2473
+ if (el) {
2474
+ this.contentWindow.document?.body?.appendChild(el);
2475
+ }
2476
+ }
2477
+ this.emit("onload");
2478
+ injectStyle(this.contentWindow.document, style);
2479
+ };
2480
+ handler();
2467
2481
  };
2468
2482
  }
2469
2483
 
@@ -2629,7 +2643,7 @@ class StageCore extends EventEmitter$1 {
2629
2643
  actionManager?.destroy();
2630
2644
  pageResizeObserver?.disconnect();
2631
2645
  this.removeAllListeners();
2632
- this.container = undefined;
2646
+ this.container = void 0;
2633
2647
  this.renderer = null;
2634
2648
  this.mask = null;
2635
2649
  this.actionManager = null;
@@ -2766,7 +2766,7 @@
2766
2766
  }
2767
2767
  destroyEl() {
2768
2768
  this.el?.remove();
2769
- this.el = undefined;
2769
+ this.el = void 0;
2770
2770
  }
2771
2771
  destroyEls() {
2772
2772
  this.els.forEach((el) => {
@@ -2926,7 +2926,7 @@
2926
2926
  }
2927
2927
  destroyGhostEl() {
2928
2928
  this.ghostEl?.remove();
2929
- this.ghostEl = undefined;
2929
+ this.ghostEl = void 0;
2930
2930
  }
2931
2931
  clear() {
2932
2932
  this.moveableHelper.clear();
@@ -2995,9 +2995,13 @@
2995
2995
  (frameItem) => core.getIdFromEl()(ev.target)?.startsWith(DRAG_EL_ID_PREFIX) && core.getIdFromEl()(ev.target)?.endsWith(frameItem.id)
2996
2996
  );
2997
2997
  if (!frameSnapShot) return;
2998
- const targeEl = this.targetList.find(
2999
- (targetItem) => core.getIdFromEl()(ev.target)?.startsWith(DRAG_EL_ID_PREFIX) && core.getIdFromEl()(targetItem) && core.getIdFromEl()(ev.target)?.endsWith(core.getIdFromEl()(targetItem))
3000
- );
2998
+ const findTargetElFuctin = (targetItem) => {
2999
+ const getId = core.getIdFromEl();
3000
+ const targetId = getId(ev.target);
3001
+ const targetItemId = getId(targetItem);
3002
+ return targetId?.startsWith(DRAG_EL_ID_PREFIX) && targetItemId && targetId?.endsWith(targetItemId);
3003
+ };
3004
+ const targeEl = this.targetList.find(findTargetElFuctin);
3001
3005
  if (!targeEl) return;
3002
3006
  const isParentIncluded = this.targetList.find(
3003
3007
  (targetItem) => core.getIdFromEl()(targetItem) === core.getIdFromEl()(targeEl.parentElement)
@@ -3275,7 +3279,7 @@
3275
3279
  top: 0,
3276
3280
  left: 0,
3277
3281
  right: this.container.clientWidth,
3278
- bottom: isSortable ? undefined : this.container.clientHeight
3282
+ bottom: isSortable ? void 0 : this.container.clientHeight
3279
3283
  }
3280
3284
  };
3281
3285
  const differenceOptions = isMultiSelect ? this.getMultiOptions() : this.getSingleOptions();
@@ -3425,7 +3429,7 @@
3425
3429
  select(el, event) {
3426
3430
  if (!el) {
3427
3431
  this.moveable?.destroy();
3428
- this.moveable = undefined;
3432
+ this.moveable = void 0;
3429
3433
  return;
3430
3434
  }
3431
3435
  if (!this.moveable || el !== this.target) {
@@ -3526,7 +3530,7 @@
3526
3530
  if (!this.target || !this.dragResizeHelper.getShadowEl()) return;
3527
3531
  if (timeout) {
3528
3532
  globalThis.clearTimeout(timeout);
3529
- timeout = undefined;
3533
+ timeout = void 0;
3530
3534
  }
3531
3535
  timeout = this.delayedMarkContainer(e.inputEvent, [this.target]);
3532
3536
  this.dragStatus = StageDragStatus.ING;
@@ -3534,7 +3538,7 @@
3534
3538
  }).on("dragEnd", () => {
3535
3539
  if (timeout) {
3536
3540
  globalThis.clearTimeout(timeout);
3537
- timeout = undefined;
3541
+ timeout = void 0;
3538
3542
  }
3539
3543
  const parentEl = this.markContainerEnd();
3540
3544
  if (this.dragStatus === StageDragStatus.ING) {
@@ -3688,17 +3692,17 @@
3688
3692
  if (!this.moveable || !this.target) return;
3689
3693
  this.moveable.zoom = 0;
3690
3694
  this.moveable.updateRect();
3691
- this.target = undefined;
3695
+ this.target = void 0;
3692
3696
  }
3693
3697
  /**
3694
3698
  * 销毁实例
3695
3699
  */
3696
3700
  destroy() {
3697
- this.target = undefined;
3701
+ this.target = void 0;
3698
3702
  this.moveable?.destroy();
3699
3703
  this.targetShadow?.destroy();
3700
- this.moveable = undefined;
3701
- this.targetShadow = undefined;
3704
+ this.moveable = void 0;
3705
+ this.targetShadow = void 0;
3702
3706
  }
3703
3707
  }
3704
3708
 
@@ -3768,7 +3772,7 @@
3768
3772
  }).on("dragGroup", (e) => {
3769
3773
  if (timeout) {
3770
3774
  globalThis.clearTimeout(timeout);
3771
- timeout = undefined;
3775
+ timeout = void 0;
3772
3776
  }
3773
3777
  timeout = this.delayedMarkContainer(e.inputEvent, this.targetList);
3774
3778
  this.dragResizeHelper.onDragGroup(e);
@@ -3776,7 +3780,7 @@
3776
3780
  }).on("dragGroupEnd", () => {
3777
3781
  if (timeout) {
3778
3782
  globalThis.clearTimeout(timeout);
3779
- timeout = undefined;
3783
+ timeout = void 0;
3780
3784
  }
3781
3785
  const parentEl = this.markContainerEnd();
3782
3786
  this.update(false, parentEl);
@@ -3890,18 +3894,21 @@
3890
3894
  getRenderDocument;
3891
3895
  disabledMultiSelect = false;
3892
3896
  config;
3893
- mouseMoveHandler = throttle(async (event) => {
3894
- if (event.target?.classList?.contains("moveable-direction")) {
3895
- return;
3896
- }
3897
- const el = await this.getElementFromPoint(event);
3898
- const id = core.getIdFromEl()(el);
3899
- if (!id) {
3900
- this.clearHighlight();
3901
- return;
3902
- }
3903
- this.emit("mousemove", event);
3904
- this.highlight(id);
3897
+ mouseMoveHandler = throttle((event) => {
3898
+ const handler = async () => {
3899
+ if (event.target?.classList?.contains("moveable-direction")) {
3900
+ return;
3901
+ }
3902
+ const el = await this.getElementFromPoint(event);
3903
+ const id = core.getIdFromEl()(el);
3904
+ if (!id) {
3905
+ this.clearHighlight();
3906
+ return;
3907
+ }
3908
+ this.emit("mousemove", event);
3909
+ this.highlight(id);
3910
+ };
3911
+ handler();
3905
3912
  }, throttleTime);
3906
3913
  constructor(config) {
3907
3914
  super();
@@ -4063,6 +4070,7 @@
4063
4070
  el = this.getTargetElement(id);
4064
4071
  } catch (error) {
4065
4072
  this.clearHighlight();
4073
+ console.warn("getTargetElement error:", error);
4066
4074
  return;
4067
4075
  }
4068
4076
  if (el === this.getSelectedEl() || this.multiDr?.dragStatus === StageDragStatus.ING) {
@@ -4075,7 +4083,7 @@
4075
4083
  this.emit("highlight", el);
4076
4084
  }
4077
4085
  clearHighlight() {
4078
- this.setHighlightEl(undefined);
4086
+ this.setHighlightEl(void 0);
4079
4087
  this.highlightLayer?.clearHighlight();
4080
4088
  }
4081
4089
  /**
@@ -4119,7 +4127,7 @@
4119
4127
  this.addContainerHighlightClassName(event, excludeElList);
4120
4128
  }, this.containerHighlightDuration);
4121
4129
  }
4122
- return undefined;
4130
+ return void 0;
4123
4131
  }
4124
4132
  getDragStatus() {
4125
4133
  return this.dr?.getDragStatus();
@@ -4303,23 +4311,26 @@
4303
4311
  /**
4304
4312
  * 在down事件中集中cpu处理画布中选中操作渲染,在up事件中再通知外面的编辑器更新
4305
4313
  */
4306
- mouseDownHandler = async (event) => {
4307
- this.clearHighlight();
4308
- event.stopImmediatePropagation();
4309
- event.stopPropagation();
4310
- if (this.isStopTriggerSelect(event)) return;
4311
- this.container.removeEventListener("mousemove", this.mouseMoveHandler);
4312
- if (this.isMultiSelectStatus) {
4313
- await this.beforeMultiSelect(event);
4314
- if (this.selectedElList.length > 0) {
4315
- this.emit("before-multi-select", this.selectedElList);
4314
+ mouseDownHandler = (event) => {
4315
+ const handler = async () => {
4316
+ this.clearHighlight();
4317
+ event.stopImmediatePropagation();
4318
+ event.stopPropagation();
4319
+ if (this.isStopTriggerSelect(event)) return;
4320
+ this.container.removeEventListener("mousemove", this.mouseMoveHandler);
4321
+ if (this.isMultiSelectStatus) {
4322
+ await this.beforeMultiSelect(event);
4323
+ if (this.selectedElList.length > 0) {
4324
+ this.emit("before-multi-select", this.selectedElList);
4325
+ }
4326
+ } else {
4327
+ const el = await this.getElementFromPoint(event);
4328
+ if (!el) return;
4329
+ this.emit("before-select", el, event);
4316
4330
  }
4317
- } else {
4318
- const el = await this.getElementFromPoint(event);
4319
- if (!el) return;
4320
- this.emit("before-select", el, event);
4321
- }
4322
- core.getDocument().addEventListener("mouseup", this.mouseUpHandler);
4331
+ core.getDocument().addEventListener("mouseup", this.mouseUpHandler);
4332
+ };
4333
+ handler();
4323
4334
  };
4324
4335
  isStopTriggerSelect(event) {
4325
4336
  if (event.button !== MouseButton.LEFT && event.button !== MouseButton.RIGHT) return true;
@@ -4882,7 +4893,7 @@
4882
4893
  this.iframe?.removeEventListener("load", this.iframeLoadHandler);
4883
4894
  this.contentWindow = null;
4884
4895
  this.iframe?.remove();
4885
- this.iframe = undefined;
4896
+ this.iframe = void 0;
4886
4897
  this.removeAllListeners();
4887
4898
  }
4888
4899
  on(eventName, listener) {
@@ -4924,19 +4935,22 @@
4924
4935
  el && addSelectedClassName(el, doc);
4925
4936
  }
4926
4937
  }
4927
- iframeLoadHandler = async () => {
4928
- if (!this.contentWindow?.magic) {
4929
- this.postTmagicRuntimeReady();
4930
- }
4931
- if (!this.contentWindow) return;
4932
- if (this.customizedRender) {
4933
- const el = await this.customizedRender();
4934
- if (el) {
4935
- this.contentWindow.document?.body?.appendChild(el);
4938
+ iframeLoadHandler = () => {
4939
+ const handler = async () => {
4940
+ if (!this.contentWindow?.magic) {
4941
+ this.postTmagicRuntimeReady();
4936
4942
  }
4937
- }
4938
- this.emit("onload");
4939
- core.injectStyle(this.contentWindow.document, style);
4943
+ if (!this.contentWindow) return;
4944
+ if (this.customizedRender) {
4945
+ const el = await this.customizedRender();
4946
+ if (el) {
4947
+ this.contentWindow.document?.body?.appendChild(el);
4948
+ }
4949
+ }
4950
+ this.emit("onload");
4951
+ core.injectStyle(this.contentWindow.document, style);
4952
+ };
4953
+ handler();
4940
4954
  };
4941
4955
  }
4942
4956
 
@@ -5102,7 +5116,7 @@
5102
5116
  actionManager?.destroy();
5103
5117
  pageResizeObserver?.disconnect();
5104
5118
  this.removeAllListeners();
5105
- this.container = undefined;
5119
+ this.container = void 0;
5106
5120
  this.renderer = null;
5107
5121
  this.mask = null;
5108
5122
  this.actionManager = null;
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.5.12",
2
+ "version": "1.5.14",
3
3
  "name": "@tmagic/stage",
4
4
  "type": "module",
5
5
  "main": "dist/tmagic-stage.umd.cjs",
@@ -42,7 +42,7 @@
42
42
  },
43
43
  "peerDependencies": {
44
44
  "typescript": "*",
45
- "@tmagic/core": "1.5.12"
45
+ "@tmagic/core": "1.5.14"
46
46
  },
47
47
  "peerDependenciesMeta": {
48
48
  "typescript": {
@@ -92,20 +92,24 @@ export default class ActionManager extends EventEmitter {
92
92
  private disabledMultiSelect = false;
93
93
  private config: ActionManagerConfig;
94
94
 
95
- private mouseMoveHandler = throttle(async (event: MouseEvent): Promise<void> => {
96
- if ((event.target as HTMLDivElement)?.classList?.contains('moveable-direction')) {
97
- return;
98
- }
95
+ private mouseMoveHandler = throttle((event: MouseEvent): void => {
96
+ const handler = async () => {
97
+ if ((event.target as HTMLDivElement)?.classList?.contains('moveable-direction')) {
98
+ return;
99
+ }
99
100
 
100
- const el = await this.getElementFromPoint(event);
101
- const id = getIdFromEl()(el);
102
- if (!id) {
103
- this.clearHighlight();
104
- return;
105
- }
101
+ const el = await this.getElementFromPoint(event);
102
+ const id = getIdFromEl()(el);
103
+ if (!id) {
104
+ this.clearHighlight();
105
+ return;
106
+ }
107
+
108
+ this.emit('mousemove', event);
109
+ this.highlight(id);
110
+ };
106
111
 
107
- this.emit('mousemove', event);
108
- this.highlight(id);
112
+ handler();
109
113
  }, throttleTime);
110
114
 
111
115
  constructor(config: ActionManagerConfig) {
@@ -299,6 +303,7 @@ export default class ActionManager extends EventEmitter {
299
303
  el = this.getTargetElement(id);
300
304
  } catch (error) {
301
305
  this.clearHighlight();
306
+ console.warn('getTargetElement error:', error);
302
307
  return;
303
308
  }
304
309
 
@@ -606,29 +611,33 @@ export default class ActionManager extends EventEmitter {
606
611
  /**
607
612
  * 在down事件中集中cpu处理画布中选中操作渲染,在up事件中再通知外面的编辑器更新
608
613
  */
609
- private mouseDownHandler = async (event: MouseEvent): Promise<void> => {
610
- this.clearHighlight();
611
- event.stopImmediatePropagation();
612
- event.stopPropagation();
614
+ private mouseDownHandler = (event: MouseEvent): void => {
615
+ const handler = async () => {
616
+ this.clearHighlight();
617
+ event.stopImmediatePropagation();
618
+ event.stopPropagation();
613
619
 
614
- if (this.isStopTriggerSelect(event)) return;
620
+ if (this.isStopTriggerSelect(event)) return;
615
621
 
616
- // 点击状态下不触发高亮事件
617
- this.container.removeEventListener('mousemove', this.mouseMoveHandler);
622
+ // 点击状态下不触发高亮事件
623
+ this.container.removeEventListener('mousemove', this.mouseMoveHandler);
618
624
 
619
- // 判断触发多选还是单选
620
- if (this.isMultiSelectStatus) {
621
- await this.beforeMultiSelect(event);
622
- if (this.selectedElList.length > 0) {
623
- this.emit('before-multi-select', this.selectedElList);
625
+ // 判断触发多选还是单选
626
+ if (this.isMultiSelectStatus) {
627
+ await this.beforeMultiSelect(event);
628
+ if (this.selectedElList.length > 0) {
629
+ this.emit('before-multi-select', this.selectedElList);
630
+ }
631
+ } else {
632
+ const el = await this.getElementFromPoint(event);
633
+ if (!el) return;
634
+ this.emit('before-select', el, event);
624
635
  }
625
- } else {
626
- const el = await this.getElementFromPoint(event);
627
- if (!el) return;
628
- this.emit('before-select', el, event);
629
- }
630
636
 
631
- getDocument().addEventListener('mouseup', this.mouseUpHandler);
637
+ getDocument().addEventListener('mouseup', this.mouseUpHandler);
638
+ };
639
+
640
+ handler();
632
641
  };
633
642
 
634
643
  private isStopTriggerSelect(event: MouseEvent): boolean {
@@ -285,13 +285,18 @@ export default class DragResizeHelper {
285
285
  getIdFromEl()(ev.target)?.startsWith(DRAG_EL_ID_PREFIX) && getIdFromEl()(ev.target)?.endsWith(frameItem.id),
286
286
  );
287
287
  if (!frameSnapShot) return;
288
- const targeEl = this.targetList.find(
289
- (targetItem) =>
290
- getIdFromEl()(ev.target)?.startsWith(DRAG_EL_ID_PREFIX) &&
291
- getIdFromEl()(targetItem) &&
292
- getIdFromEl()(ev.target)?.endsWith(getIdFromEl()(targetItem)!),
293
- );
288
+
289
+ const findTargetElFuctin = (targetItem: HTMLElement) => {
290
+ const getId = getIdFromEl();
291
+ const targetId = getId(ev.target);
292
+ const targetItemId = getId(targetItem);
293
+ return targetId?.startsWith(DRAG_EL_ID_PREFIX) && targetItemId && targetId?.endsWith(targetItemId);
294
+ };
295
+
296
+ const targeEl = this.targetList.find(findTargetElFuctin);
297
+
294
298
  if (!targeEl) return;
299
+
295
300
  // 元素与其所属组同时加入多选列表时,只更新父元素
296
301
  const isParentIncluded = this.targetList.find(
297
302
  (targetItem) => getIdFromEl()(targetItem) === getIdFromEl()(targeEl.parentElement),
@@ -16,7 +16,6 @@
16
16
  * limitations under the License.
17
17
  */
18
18
 
19
- /* eslint-disable no-param-reassign */
20
19
  import Moveable, { MoveableOptions } from 'moveable';
21
20
 
22
21
  import { getIdFromEl } from '@tmagic/core';
@@ -235,22 +235,26 @@ export default class StageRender extends EventEmitter {
235
235
  }
236
236
  }
237
237
 
238
- private iframeLoadHandler = async () => {
239
- if (!this.contentWindow?.magic) {
240
- this.postTmagicRuntimeReady();
241
- }
238
+ private iframeLoadHandler = () => {
239
+ const handler = async () => {
240
+ if (!this.contentWindow?.magic) {
241
+ this.postTmagicRuntimeReady();
242
+ }
242
243
 
243
- if (!this.contentWindow) return;
244
+ if (!this.contentWindow) return;
244
245
 
245
- if (this.customizedRender) {
246
- const el = await this.customizedRender();
247
- if (el) {
248
- this.contentWindow.document?.body?.appendChild(el);
246
+ if (this.customizedRender) {
247
+ const el = await this.customizedRender();
248
+ if (el) {
249
+ this.contentWindow.document?.body?.appendChild(el);
250
+ }
249
251
  }
250
- }
251
252
 
252
- this.emit('onload');
253
+ this.emit('onload');
254
+
255
+ injectStyle(this.contentWindow.document, style);
256
+ };
253
257
 
254
- injectStyle(this.contentWindow.document, style);
258
+ handler();
255
259
  };
256
260
  }
package/types/index.d.ts CHANGED
@@ -2,7 +2,7 @@ import * as _tmagic_editor from '@tmagic/editor';
2
2
  import EventEmitter, { EventEmitter as EventEmitter$1 } from 'events';
3
3
  import { OnResizeStart, OnResize, OnDragStart, OnDrag, OnRotateStart, OnRotate, OnScaleStart, OnScale, OnResizeGroupStart, OnResizeGroup, OnDragGroupStart, OnDragGroup, MoveableOptions, Renderer, MoveableManagerInterface } from 'moveable';
4
4
  export * from 'moveable';
5
- import Core, { Id, MApp, MNode, MContainer } from '@tmagic/core';
5
+ import Core, { MApp, Id, MNode, MContainer } from '@tmagic/core';
6
6
  import Guides, { GuidesOptions } from '@scena/guides';
7
7
  export { GuidesOptions } from '@scena/guides';
8
8
  import MoveableHelper from 'moveable-helper';
@@ -1022,4 +1022,5 @@ declare const _default: (handler: (type: AbleActionEventType) => void, customize
1022
1022
  render(moveable: MoveableManagerInterface<any, any>, React: Renderer): any;
1023
1023
  };
1024
1024
 
1025
- export { AbleActionEventType, type AbleCustomizedButton, type ActionManagerConfig, type ActionManagerEvents, CONTAINER_HIGHLIGHT_CLASS_NAME, type CanSelect, ContainerHighlightType, type CoreEvents, type CustomizeMoveableOptions, type CustomizeMoveableOptionsCallbackConfig, type CustomizeRender, DEFAULT_ZOOM, DRAG_EL_ID_PREFIX, type DelayedMarkContainer, type DrEvents, type DragResizeHelperConfig, GHOST_EL_ID_PREFIX, type GetElementsFromPoint, type GetRenderDocument, type GetRootContainer, type GetTargetElement, type GuidesEventData, GuidesType, HIGHLIGHT_EL_ID_PREFIX, type IsContainer, type Magic, type MarkContainerEnd, type MaskEvents, Mode, MouseButton, _default as MoveableActionsAble, type MoveableOptionsManagerConfig, type MultiDrEvents, type Offset, PAGE_CLASS, type Point, type Rect, type RemoveData, type RemoveEventData, type RenderEvents, RenderType, type RuleOptions, type Runtime, type RuntimeWindow, SELECTED_CLASS, SelectStatus, type SortEventData, type StageCoreConfig, StageDragResize, type StageDragResizeConfig, StageDragStatus, type StageHighlightConfig, StageMask, type StageMaskConfig, type StageMultiDragResizeConfig, StageRender, type StageRenderConfig, type TargetElement, type TargetShadowConfig, type UpdateData, type UpdateDragEl, type UpdateEventData, ZIndex, addSelectedClassName, StageCore as default, down, getAbsolutePosition, getBorderWidth, getMarginValue, getMode, getOffset, getScrollParent, getTargetElStyle, isAbsolute, isFixed, isFixedParent, isMoveableButton, isRelative, isStatic, removeSelectedClassName, up };
1025
+ export { AbleActionEventType, CONTAINER_HIGHLIGHT_CLASS_NAME, ContainerHighlightType, DEFAULT_ZOOM, DRAG_EL_ID_PREFIX, GHOST_EL_ID_PREFIX, GuidesType, HIGHLIGHT_EL_ID_PREFIX, Mode, MouseButton, _default as MoveableActionsAble, PAGE_CLASS, RenderType, SELECTED_CLASS, SelectStatus, StageDragResize, StageDragStatus, StageMask, StageRender, ZIndex, addSelectedClassName, StageCore as default, down, getAbsolutePosition, getBorderWidth, getMarginValue, getMode, getOffset, getScrollParent, getTargetElStyle, isAbsolute, isFixed, isFixedParent, isMoveableButton, isRelative, isStatic, removeSelectedClassName, up };
1026
+ export type { AbleCustomizedButton, ActionManagerConfig, ActionManagerEvents, CanSelect, CoreEvents, CustomizeMoveableOptions, CustomizeMoveableOptionsCallbackConfig, CustomizeRender, DelayedMarkContainer, DrEvents, DragResizeHelperConfig, GetElementsFromPoint, GetRenderDocument, GetRootContainer, GetTargetElement, GuidesEventData, IsContainer, Magic, MarkContainerEnd, MaskEvents, MoveableOptionsManagerConfig, MultiDrEvents, Offset, Point, Rect, RemoveData, RemoveEventData, RenderEvents, RuleOptions, Runtime, RuntimeWindow, SortEventData, StageCoreConfig, StageDragResizeConfig, StageHighlightConfig, StageMaskConfig, StageMultiDragResizeConfig, StageRenderConfig, TargetElement, TargetShadowConfig, UpdateData, UpdateDragEl, UpdateEventData };