@tmagic/stage 1.5.13 → 1.5.15
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 +57 -43
- package/dist/tmagic-stage.umd.cjs +57 -43
- package/package.json +2 -2
- package/src/ActionManager.ts +39 -30
- package/src/DragResizeHelper.ts +11 -6
- package/src/StageDragResize.ts +0 -1
- package/src/StageRender.ts +16 -12
package/dist/tmagic-stage.js
CHANGED
|
@@ -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
|
|
526
|
-
|
|
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(
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
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 =
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
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
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
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 =
|
|
2455
|
-
|
|
2456
|
-
this.
|
|
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
|
-
|
|
2466
|
-
|
|
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
|
|
2999
|
-
|
|
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(
|
|
3894
|
-
|
|
3895
|
-
|
|
3896
|
-
|
|
3897
|
-
|
|
3898
|
-
|
|
3899
|
-
|
|
3900
|
-
|
|
3901
|
-
|
|
3902
|
-
|
|
3903
|
-
|
|
3904
|
-
|
|
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 =
|
|
4307
|
-
|
|
4308
|
-
|
|
4309
|
-
|
|
4310
|
-
|
|
4311
|
-
|
|
4312
|
-
|
|
4313
|
-
|
|
4314
|
-
|
|
4315
|
-
|
|
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
|
-
|
|
4318
|
-
|
|
4319
|
-
|
|
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 =
|
|
4928
|
-
|
|
4929
|
-
this.
|
|
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
|
-
|
|
4939
|
-
|
|
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.
|
|
2
|
+
"version": "1.5.15",
|
|
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.
|
|
45
|
+
"@tmagic/core": "1.5.15"
|
|
46
46
|
},
|
|
47
47
|
"peerDependenciesMeta": {
|
|
48
48
|
"typescript": {
|
package/src/ActionManager.ts
CHANGED
|
@@ -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(
|
|
96
|
-
|
|
97
|
-
|
|
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
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
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
|
-
|
|
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 =
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
614
|
+
private mouseDownHandler = (event: MouseEvent): void => {
|
|
615
|
+
const handler = async () => {
|
|
616
|
+
this.clearHighlight();
|
|
617
|
+
event.stopImmediatePropagation();
|
|
618
|
+
event.stopPropagation();
|
|
613
619
|
|
|
614
|
-
|
|
620
|
+
if (this.isStopTriggerSelect(event)) return;
|
|
615
621
|
|
|
616
|
-
|
|
617
|
-
|
|
622
|
+
// 点击状态下不触发高亮事件
|
|
623
|
+
this.container.removeEventListener('mousemove', this.mouseMoveHandler);
|
|
618
624
|
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
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
|
-
|
|
637
|
+
getDocument().addEventListener('mouseup', this.mouseUpHandler);
|
|
638
|
+
};
|
|
639
|
+
|
|
640
|
+
handler();
|
|
632
641
|
};
|
|
633
642
|
|
|
634
643
|
private isStopTriggerSelect(event: MouseEvent): boolean {
|
package/src/DragResizeHelper.ts
CHANGED
|
@@ -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
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
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),
|
package/src/StageDragResize.ts
CHANGED
package/src/StageRender.ts
CHANGED
|
@@ -235,22 +235,26 @@ export default class StageRender extends EventEmitter {
|
|
|
235
235
|
}
|
|
236
236
|
}
|
|
237
237
|
|
|
238
|
-
private iframeLoadHandler =
|
|
239
|
-
|
|
240
|
-
this.
|
|
241
|
-
|
|
238
|
+
private iframeLoadHandler = () => {
|
|
239
|
+
const handler = async () => {
|
|
240
|
+
if (!this.contentWindow?.magic) {
|
|
241
|
+
this.postTmagicRuntimeReady();
|
|
242
|
+
}
|
|
242
243
|
|
|
243
|
-
|
|
244
|
+
if (!this.contentWindow) return;
|
|
244
245
|
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
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
|
-
|
|
253
|
+
this.emit('onload');
|
|
254
|
+
|
|
255
|
+
injectStyle(this.contentWindow.document, style);
|
|
256
|
+
};
|
|
253
257
|
|
|
254
|
-
|
|
258
|
+
handler();
|
|
255
259
|
};
|
|
256
260
|
}
|