@tmagic/stage 1.5.13 → 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.
@@ -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)
@@ -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) {
@@ -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;
@@ -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
 
@@ -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)
@@ -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) {
@@ -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;
@@ -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
 
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.5.13",
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.13"
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
  }