@tmagic/stage 1.5.0-beta.1 → 1.5.0-beta.11
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 +139 -110
- package/dist/tmagic-stage.umd.cjs +139 -104
- package/package.json +6 -6
- package/src/ActionManager.ts +23 -16
- package/src/DragResizeHelper.ts +54 -42
- package/src/MoveableActionsAble.ts +23 -3
- package/src/MoveableOptionsManager.ts +2 -1
- package/src/StageCore.ts +58 -53
- package/src/StageDragResize.ts +2 -1
- package/src/StageHighlight.ts +1 -0
- package/src/StageRender.ts +13 -13
- package/src/index.ts +5 -1
- package/src/util.ts +17 -11
- package/types/index.d.ts +38 -14
package/dist/tmagic-stage.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import EventEmitter, { EventEmitter as EventEmitter$1 } from 'events';
|
|
2
|
-
import { removeClassName, guid, setIdToEl,
|
|
2
|
+
import { removeClassName, getIdFromEl, guid, setIdToEl, getElById, calcValueByFontsize, addClassName, removeClassNameByClassName, getDocument, createDiv, injectStyle, isSameDomain, getHost } from '@tmagic/utils';
|
|
3
3
|
import KeyController from 'keycon';
|
|
4
4
|
import { merge, throttle } from 'lodash-es';
|
|
5
5
|
import { Env } from '@tmagic/core';
|
|
6
6
|
import MoveableHelper from 'moveable-helper';
|
|
7
|
-
import
|
|
7
|
+
import Moveable__default from 'moveable';
|
|
8
|
+
export * from 'moveable';
|
|
8
9
|
import Guides from '@scena/guides';
|
|
9
10
|
|
|
10
11
|
const GHOST_EL_ID_PREFIX = "ghost_el_";
|
|
@@ -178,7 +179,7 @@ const down = (deltaTop, target) => {
|
|
|
178
179
|
let swapIndex = 0;
|
|
179
180
|
let addUpH = target.clientHeight;
|
|
180
181
|
const brothers = Array.from(target.parentNode?.children || []).filter(
|
|
181
|
-
(
|
|
182
|
+
(child) => !getIdFromEl()(child)?.startsWith(GHOST_EL_ID_PREFIX)
|
|
182
183
|
);
|
|
183
184
|
const index = brothers.indexOf(target);
|
|
184
185
|
const downEls = brothers.slice(index + 1);
|
|
@@ -194,14 +195,15 @@ const down = (deltaTop, target) => {
|
|
|
194
195
|
addUpH += ele.clientHeight / 2;
|
|
195
196
|
swapIndex = i;
|
|
196
197
|
}
|
|
198
|
+
const src = getIdFromEl()(target) || "";
|
|
197
199
|
return {
|
|
198
|
-
src
|
|
199
|
-
dist: downEls.length && swapIndex > -1 ? downEls[swapIndex]
|
|
200
|
+
src,
|
|
201
|
+
dist: downEls.length && swapIndex > -1 ? getIdFromEl()(downEls[swapIndex]) || "" : src
|
|
200
202
|
};
|
|
201
203
|
};
|
|
202
204
|
const up = (deltaTop, target) => {
|
|
203
205
|
const brothers = Array.from(target.parentNode?.children || []).filter(
|
|
204
|
-
(
|
|
206
|
+
(child) => !getIdFromEl()(child)?.startsWith(GHOST_EL_ID_PREFIX)
|
|
205
207
|
);
|
|
206
208
|
const index = brothers.indexOf(target);
|
|
207
209
|
const upEls = brothers.slice(0, index);
|
|
@@ -216,9 +218,10 @@ const up = (deltaTop, target) => {
|
|
|
216
218
|
addUpH += ele.clientHeight / 2;
|
|
217
219
|
swapIndex = i;
|
|
218
220
|
}
|
|
221
|
+
const src = getIdFromEl()(target) || "";
|
|
219
222
|
return {
|
|
220
|
-
src
|
|
221
|
-
dist: upEls.length && swapIndex > -1 ? upEls[swapIndex]
|
|
223
|
+
src,
|
|
224
|
+
dist: upEls.length && swapIndex > -1 ? getIdFromEl()(upEls[swapIndex]) || "" : src
|
|
222
225
|
};
|
|
223
226
|
};
|
|
224
227
|
const isMoveableButton = (target) => target.classList.contains("moveable-button") || target.parentElement?.classList.contains("moveable-button");
|
|
@@ -328,12 +331,11 @@ class TargetShadow {
|
|
|
328
331
|
};
|
|
329
332
|
}
|
|
330
333
|
|
|
331
|
-
const getId = getIdFromEl();
|
|
332
334
|
class DragResizeHelper {
|
|
333
335
|
/** 目标节点在蒙层上的占位节点,用于跟鼠标交互,避免鼠标事件直接作用到目标节点 */
|
|
334
336
|
targetShadow;
|
|
335
337
|
/** 要操作的原始目标节点 */
|
|
336
|
-
target;
|
|
338
|
+
target = null;
|
|
337
339
|
/** 多选:目标节点组 */
|
|
338
340
|
targetList = [];
|
|
339
341
|
/** 响应拖拽的状态事件,修改绝对定位布局下targetShadow的dom。
|
|
@@ -364,6 +366,8 @@ class DragResizeHelper {
|
|
|
364
366
|
});
|
|
365
367
|
}
|
|
366
368
|
destroy() {
|
|
369
|
+
this.target = null;
|
|
370
|
+
this.targetList = [];
|
|
367
371
|
this.targetShadow.destroy();
|
|
368
372
|
this.destroyGhostEl();
|
|
369
373
|
this.moveableHelper.clear();
|
|
@@ -486,14 +490,16 @@ class DragResizeHelper {
|
|
|
486
490
|
events.forEach((ev) => {
|
|
487
491
|
const { width, height, beforeTranslate } = ev.drag;
|
|
488
492
|
const frameSnapShot = this.framesSnapShot.find(
|
|
489
|
-
(frameItem) => frameItem.id ===
|
|
493
|
+
(frameItem) => frameItem.id === getIdFromEl()(ev.target)?.replace(DRAG_EL_ID_PREFIX, "")
|
|
490
494
|
);
|
|
491
495
|
if (!frameSnapShot) return;
|
|
492
496
|
const targeEl = this.targetList.find(
|
|
493
|
-
(targetItem) => targetItem
|
|
497
|
+
(targetItem) => getIdFromEl()(targetItem) === getIdFromEl()(ev.target)?.replace(DRAG_EL_ID_PREFIX, "")
|
|
494
498
|
);
|
|
495
499
|
if (!targeEl) return;
|
|
496
|
-
const isParentIncluded = this.targetList.find(
|
|
500
|
+
const isParentIncluded = this.targetList.find(
|
|
501
|
+
(targetItem) => getIdFromEl()(targetItem) === getIdFromEl()(targeEl.parentElement)
|
|
502
|
+
);
|
|
497
503
|
if (!isParentIncluded) {
|
|
498
504
|
const { marginLeft, marginTop } = getMarginValue(targeEl);
|
|
499
505
|
targeEl.style.left = `${frameSnapShot.left + beforeTranslate[0] - marginLeft}px`;
|
|
@@ -513,14 +519,16 @@ class DragResizeHelper {
|
|
|
513
519
|
const { events } = e;
|
|
514
520
|
events.forEach((ev) => {
|
|
515
521
|
const frameSnapShot = this.framesSnapShot.find(
|
|
516
|
-
(frameItem) =>
|
|
522
|
+
(frameItem) => getIdFromEl()(ev.target)?.startsWith(DRAG_EL_ID_PREFIX) && getIdFromEl()(ev.target)?.endsWith(frameItem.id)
|
|
517
523
|
);
|
|
518
524
|
if (!frameSnapShot) return;
|
|
519
525
|
const targeEl = this.targetList.find(
|
|
520
|
-
(targetItem) =>
|
|
526
|
+
(targetItem) => getIdFromEl()(ev.target)?.startsWith(DRAG_EL_ID_PREFIX) && getIdFromEl()(targetItem) && getIdFromEl()(ev.target)?.endsWith(getIdFromEl()(targetItem))
|
|
521
527
|
);
|
|
522
528
|
if (!targeEl) return;
|
|
523
|
-
const isParentIncluded = this.targetList.find(
|
|
529
|
+
const isParentIncluded = this.targetList.find(
|
|
530
|
+
(targetItem) => getIdFromEl()(targetItem) === getIdFromEl()(targeEl.parentElement)
|
|
531
|
+
);
|
|
524
532
|
if (!isParentIncluded) {
|
|
525
533
|
const { marginLeft, marginTop } = getMarginValue(targeEl);
|
|
526
534
|
targeEl.style.left = `${frameSnapShot.left + ev.beforeTranslate[0] - marginLeft}px`;
|
|
@@ -539,7 +547,7 @@ class DragResizeHelper {
|
|
|
539
547
|
let shadowEl = this.getShadowEl();
|
|
540
548
|
const shadowEls = this.getShadowEls();
|
|
541
549
|
if (shadowEls.length) {
|
|
542
|
-
shadowEl = shadowEls.find((item) =>
|
|
550
|
+
shadowEl = shadowEls.find((item) => getIdFromEl()(item)?.endsWith(getIdFromEl()(el) || ""));
|
|
543
551
|
}
|
|
544
552
|
if (parentEl && this.mode === Mode.ABSOLUTE && shadowEl) {
|
|
545
553
|
const targetShadowHtmlEl = shadowEl;
|
|
@@ -560,10 +568,10 @@ class DragResizeHelper {
|
|
|
560
568
|
if (this.framesSnapShot.length > 0) return;
|
|
561
569
|
events.forEach((ev) => {
|
|
562
570
|
const matchEventTarget = this.targetList.find(
|
|
563
|
-
(targetItem) =>
|
|
571
|
+
(targetItem) => getIdFromEl()(ev.target)?.startsWith(DRAG_EL_ID_PREFIX) && getIdFromEl()(ev.target)?.endsWith(getIdFromEl()(targetItem) || "")
|
|
564
572
|
);
|
|
565
573
|
if (!matchEventTarget) return;
|
|
566
|
-
const id =
|
|
574
|
+
const id = getIdFromEl()(matchEventTarget);
|
|
567
575
|
id && this.framesSnapShot.push({
|
|
568
576
|
left: matchEventTarget.offsetLeft,
|
|
569
577
|
top: matchEventTarget.offsetTop,
|
|
@@ -578,24 +586,27 @@ class DragResizeHelper {
|
|
|
578
586
|
if (this.ghostEl) {
|
|
579
587
|
this.destroyGhostEl();
|
|
580
588
|
}
|
|
581
|
-
const ghostEl =
|
|
582
|
-
this.setGhostElChildrenId(ghostEl);
|
|
589
|
+
const ghostEl = document.createElement("div");
|
|
583
590
|
const { top, left } = getAbsolutePosition(el, getOffset(el));
|
|
584
|
-
setIdToEl()(ghostEl, `${GHOST_EL_ID_PREFIX}${
|
|
585
|
-
ghostEl.style.
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
591
|
+
setIdToEl()(ghostEl, `${GHOST_EL_ID_PREFIX}${getIdFromEl()(el)}`);
|
|
592
|
+
ghostEl.style.cssText = `
|
|
593
|
+
z-index: ${ZIndex.GHOST_EL};
|
|
594
|
+
opacity: .6;
|
|
595
|
+
position: absolute;
|
|
596
|
+
left: ${left}px;
|
|
597
|
+
top: ${top}px;
|
|
598
|
+
margin: 0;
|
|
599
|
+
background: blue;
|
|
600
|
+
width: ${el.clientWidth}px;
|
|
601
|
+
height: ${el.clientHeight}px;
|
|
602
|
+
`;
|
|
592
603
|
el.after(ghostEl);
|
|
593
604
|
return ghostEl;
|
|
594
605
|
}
|
|
595
606
|
setGhostElChildrenId(el) {
|
|
596
607
|
for (const child of Array.from(el.children)) {
|
|
597
608
|
const el2 = child;
|
|
598
|
-
const id =
|
|
609
|
+
const id = getIdFromEl()(el2);
|
|
599
610
|
if (id) {
|
|
600
611
|
setIdToEl()(el2, `${GHOST_EL_ID_PREFIX}${id}`);
|
|
601
612
|
}
|
|
@@ -608,9 +619,10 @@ class DragResizeHelper {
|
|
|
608
619
|
|
|
609
620
|
const ableCss = ".moveable-button {\n width: 20px;\n height: 20px;\n background: #4af;\n border-radius: 4px;\n appearance: none;\n border: 0;\n color: white;\n font-size: 12px;\n font-weight: bold;\n margin-left: 2px;\n position: relative;\n}\n.moveable-remove-button:before, .moveable-remove-button:after {\n content: \"\";\n position: absolute;\n left: 50%;\n top: 50%;\n transform: translate(-50%, -50%) rotate(45deg);\n width: 14px;\n height: 2px;\n background: #fff;\n border-radius: 1px;\n cursor: pointer;\n}\n.moveable-remove-button:after {\n transform: translate(-50%, -50%) rotate(-45deg);\n}\n\n.moveable-select-parent-arrow-top-icon {\n transform: rotateZ(-45deg);\n width: 4px;\n height: 4px;\n border-color: #fff;\n border-width: 2px 2px 0 0;\n border-style: solid;\n position: absolute;\n left: 4px;\n top: 4px;\n}\n\n.moveable-select-parent-arrow-body-icon {\n width: 7px;\n height: 11px;\n border-color: #fff;\n border-width: 0 0 2px 2px;\n border-style: solid;\n}\n\n.moveable-drag-area-button {\n cursor: move;\n}\n\n.moveable-drag-area-button .moveable-select-parent-arrow-top-icon {\n width: 2px;\n height: 2px;\n}\n\n.moveable-drag-area-button .moveable-select-parent-arrow-top-icon-top {\n transform: rotateZ(-45deg) translateX(-50%);\n left: 50%;\n top: 3px;\n transform-origin: left;\n}\n\n.moveable-drag-area-button .moveable-select-parent-arrow-top-icon-bottom {\n transform: rotateZ(135deg) translateX(-50%);\n transform-origin: left;\n left: 50%;\n top: auto;\n bottom: 3px;\n}\n\n.moveable-drag-area-button .moveable-select-parent-arrow-top-icon-right {\n transform: rotateZ(45deg) translateY(-50%);\n transform-origin: top;\n right: 3px;\n left: auto;\n top: 50%;\n}\n\n.moveable-drag-area-button .moveable-select-parent-arrow-top-icon-left {\n transform: rotateZ(235deg) translateY(-50%);\n transform-origin: top;\n left: 3px;\n top: 50%;\n}\n\n.moveable-drag-area-button .moveable-select-parent-arrow-body-icon-horizontal {\n width: 2px;\n height: 11px;\n background-color: #fff;\n position: absolute;\n transform: translateX(-50%);\n left: 50%;\n top: 4px;\n}\n\n.moveable-drag-area-button .moveable-select-parent-arrow-body-icon-vertical {\n width: 11px;\n height: 2px;\n background-color: #fff;\n position: absolute;\n transform: translateY(-50%);\n left: 4px;\n top: 50%;;\n}\n\n";
|
|
610
621
|
|
|
611
|
-
const MoveableActionsAble = (handler) => ({
|
|
622
|
+
const MoveableActionsAble = (handler, customizedButton = []) => ({
|
|
612
623
|
name: "actions",
|
|
613
624
|
props: [],
|
|
625
|
+
always: true,
|
|
614
626
|
events: [],
|
|
615
627
|
render(moveable, React) {
|
|
616
628
|
const rect = moveable.getRect();
|
|
@@ -634,10 +646,14 @@ const MoveableActionsAble = (handler) => ({
|
|
|
634
646
|
{
|
|
635
647
|
className: "moveable-editable",
|
|
636
648
|
style: {
|
|
637
|
-
transform: `translate(${pos2[0] -
|
|
649
|
+
transform: `translate(${pos2[0] - (customizedButton.length + 3) * 20}px, ${pos2[1] - 28}px) rotate(${rect.rotation}deg)`
|
|
638
650
|
}
|
|
639
651
|
},
|
|
640
652
|
[
|
|
653
|
+
...customizedButton.map((buttonRenderer) => {
|
|
654
|
+
const options = buttonRenderer(React);
|
|
655
|
+
return React.createElement("button", options.props || {}, ...options.children || []);
|
|
656
|
+
}),
|
|
641
657
|
React.createElement(
|
|
642
658
|
"button",
|
|
643
659
|
{
|
|
@@ -759,7 +775,7 @@ class MoveableOptionsManager extends EventEmitter {
|
|
|
759
775
|
*/
|
|
760
776
|
getOptions(isMultiSelect, runtimeOptions = {}) {
|
|
761
777
|
const defaultOptions = this.getDefaultOptions(isMultiSelect);
|
|
762
|
-
const customizedOptions = this.getCustomizeOptions();
|
|
778
|
+
const customizedOptions = this.getCustomizeOptions() || {};
|
|
763
779
|
this.options = merge(defaultOptions, customizedOptions, runtimeOptions);
|
|
764
780
|
return this.options;
|
|
765
781
|
}
|
|
@@ -970,6 +986,7 @@ class StageDragResize extends MoveableOptionsManager {
|
|
|
970
986
|
* 销毁实例
|
|
971
987
|
*/
|
|
972
988
|
destroy() {
|
|
989
|
+
this.target = null;
|
|
973
990
|
this.moveable?.destroy();
|
|
974
991
|
this.dragResizeHelper.destroy();
|
|
975
992
|
this.dragStatus = StageDragStatus.END;
|
|
@@ -998,7 +1015,7 @@ class StageDragResize extends MoveableOptionsManager {
|
|
|
998
1015
|
const options = this.init(el);
|
|
999
1016
|
this.dragResizeHelper.clear();
|
|
1000
1017
|
this.moveable?.destroy();
|
|
1001
|
-
this.moveable = new
|
|
1018
|
+
this.moveable = new Moveable__default(this.container, {
|
|
1002
1019
|
...options
|
|
1003
1020
|
});
|
|
1004
1021
|
this.bindResizeEvent();
|
|
@@ -1180,7 +1197,7 @@ class StageHighlight extends EventEmitter$1 {
|
|
|
1180
1197
|
this.moveable.zoom = 2;
|
|
1181
1198
|
this.moveable.updateRect();
|
|
1182
1199
|
} else {
|
|
1183
|
-
this.moveable = new
|
|
1200
|
+
this.moveable = new Moveable__default(this.container, {
|
|
1184
1201
|
target: this.targetShadow?.el,
|
|
1185
1202
|
origin: false,
|
|
1186
1203
|
rootContainer: this.getRootContainer(),
|
|
@@ -1201,6 +1218,7 @@ class StageHighlight extends EventEmitter$1 {
|
|
|
1201
1218
|
* 销毁实例
|
|
1202
1219
|
*/
|
|
1203
1220
|
destroy() {
|
|
1221
|
+
this.target = void 0;
|
|
1204
1222
|
this.moveable?.destroy();
|
|
1205
1223
|
this.targetShadow?.destroy();
|
|
1206
1224
|
this.moveable = void 0;
|
|
@@ -1252,7 +1270,7 @@ class StageMultiDragResize extends MoveableOptionsManager {
|
|
|
1252
1270
|
this.setElementGuidelines(this.targetList);
|
|
1253
1271
|
this.moveableForMulti?.destroy();
|
|
1254
1272
|
this.dragResizeHelper.clear();
|
|
1255
|
-
this.moveableForMulti = new
|
|
1273
|
+
this.moveableForMulti = new Moveable__default(
|
|
1256
1274
|
this.container,
|
|
1257
1275
|
this.getOptions(true, {
|
|
1258
1276
|
target: this.dragResizeHelper.getShadowEls()
|
|
@@ -1369,9 +1387,9 @@ class StageMultiDragResize extends MoveableOptionsManager {
|
|
|
1369
1387
|
const throttleTime = 100;
|
|
1370
1388
|
const defaultContainerHighlightDuration = 800;
|
|
1371
1389
|
class ActionManager extends EventEmitter {
|
|
1372
|
-
dr;
|
|
1373
|
-
multiDr;
|
|
1374
|
-
highlightLayer;
|
|
1390
|
+
dr = null;
|
|
1391
|
+
multiDr = null;
|
|
1392
|
+
highlightLayer = null;
|
|
1375
1393
|
/** 单选、多选、高亮的容器(蒙层的content) */
|
|
1376
1394
|
container;
|
|
1377
1395
|
/** 当前选中的节点 */
|
|
@@ -1438,7 +1456,7 @@ class ActionManager extends EventEmitter {
|
|
|
1438
1456
|
this.disabledMultiSelect = true;
|
|
1439
1457
|
if (this.multiDr) {
|
|
1440
1458
|
this.multiDr.destroy();
|
|
1441
|
-
this.multiDr =
|
|
1459
|
+
this.multiDr = null;
|
|
1442
1460
|
}
|
|
1443
1461
|
}
|
|
1444
1462
|
enableMultiSelect() {
|
|
@@ -1453,14 +1471,14 @@ class ActionManager extends EventEmitter {
|
|
|
1453
1471
|
* @param guidelines 参考线坐标数组
|
|
1454
1472
|
*/
|
|
1455
1473
|
setGuidelines(type, guidelines) {
|
|
1456
|
-
this.dr
|
|
1474
|
+
this.dr?.setGuidelines(type, guidelines);
|
|
1457
1475
|
this.multiDr?.setGuidelines(type, guidelines);
|
|
1458
1476
|
}
|
|
1459
1477
|
/**
|
|
1460
1478
|
* 清空所有参考线
|
|
1461
1479
|
*/
|
|
1462
1480
|
clearGuides() {
|
|
1463
|
-
this.dr
|
|
1481
|
+
this.dr?.clearGuides();
|
|
1464
1482
|
this.multiDr?.clearGuides();
|
|
1465
1483
|
}
|
|
1466
1484
|
/**
|
|
@@ -1468,7 +1486,7 @@ class ActionManager extends EventEmitter {
|
|
|
1468
1486
|
* @param el 变更的元素
|
|
1469
1487
|
*/
|
|
1470
1488
|
updateMoveable(el) {
|
|
1471
|
-
this.dr
|
|
1489
|
+
this.dr?.updateMoveable(el);
|
|
1472
1490
|
this.multiDr?.updateMoveable();
|
|
1473
1491
|
}
|
|
1474
1492
|
/**
|
|
@@ -1487,7 +1505,7 @@ class ActionManager extends EventEmitter {
|
|
|
1487
1505
|
return this.selectedElList;
|
|
1488
1506
|
}
|
|
1489
1507
|
getMoveableOption(key) {
|
|
1490
|
-
if (this.dr
|
|
1508
|
+
if (this.dr?.getTarget()) {
|
|
1491
1509
|
return this.dr.getOption(key);
|
|
1492
1510
|
}
|
|
1493
1511
|
if (this.multiDr?.targetList.length) {
|
|
@@ -1544,7 +1562,7 @@ class ActionManager extends EventEmitter {
|
|
|
1544
1562
|
select(el, event) {
|
|
1545
1563
|
this.setSelectedEl(el);
|
|
1546
1564
|
this.clearSelectStatus(SelectStatus.MULTI_SELECT);
|
|
1547
|
-
this.dr
|
|
1565
|
+
this.dr?.select(el, event);
|
|
1548
1566
|
}
|
|
1549
1567
|
multiSelect(ids) {
|
|
1550
1568
|
this.selectedElList = [];
|
|
@@ -1576,13 +1594,13 @@ class ActionManager extends EventEmitter {
|
|
|
1576
1594
|
return;
|
|
1577
1595
|
}
|
|
1578
1596
|
if (el === this.highlightedEl || !el) return;
|
|
1579
|
-
this.highlightLayer
|
|
1597
|
+
this.highlightLayer?.highlight(el);
|
|
1580
1598
|
this.highlightedEl = el;
|
|
1581
1599
|
this.emit("highlight", el);
|
|
1582
1600
|
}
|
|
1583
1601
|
clearHighlight() {
|
|
1584
1602
|
this.setHighlightEl(void 0);
|
|
1585
|
-
this.highlightLayer
|
|
1603
|
+
this.highlightLayer?.clearHighlight();
|
|
1586
1604
|
}
|
|
1587
1605
|
/**
|
|
1588
1606
|
* 用于在切换选择模式时清除上一次的状态
|
|
@@ -1593,7 +1611,7 @@ class ActionManager extends EventEmitter {
|
|
|
1593
1611
|
this.multiDr?.clearSelectStatus();
|
|
1594
1612
|
this.selectedElList = [];
|
|
1595
1613
|
} else {
|
|
1596
|
-
this.dr
|
|
1614
|
+
this.dr?.clearSelectStatus();
|
|
1597
1615
|
}
|
|
1598
1616
|
}
|
|
1599
1617
|
/**
|
|
@@ -1628,7 +1646,7 @@ class ActionManager extends EventEmitter {
|
|
|
1628
1646
|
return void 0;
|
|
1629
1647
|
}
|
|
1630
1648
|
getDragStatus() {
|
|
1631
|
-
return this.dr
|
|
1649
|
+
return this.dr?.getDragStatus();
|
|
1632
1650
|
}
|
|
1633
1651
|
destroy() {
|
|
1634
1652
|
this.container.removeEventListener("mousedown", this.mouseDownHandler);
|
|
@@ -1636,9 +1654,14 @@ class ActionManager extends EventEmitter {
|
|
|
1636
1654
|
this.container.removeEventListener("mouseleave", this.mouseLeaveHandler);
|
|
1637
1655
|
this.container.removeEventListener("wheel", this.mouseWheelHandler);
|
|
1638
1656
|
this.container.removeEventListener("dblclick", this.dblclickHandler);
|
|
1639
|
-
this.
|
|
1657
|
+
this.selectedEl = null;
|
|
1658
|
+
this.selectedElList = [];
|
|
1659
|
+
this.dr?.destroy();
|
|
1640
1660
|
this.multiDr?.destroy();
|
|
1641
|
-
this.highlightLayer
|
|
1661
|
+
this.highlightLayer?.destroy();
|
|
1662
|
+
this.dr = null;
|
|
1663
|
+
this.multiDr = null;
|
|
1664
|
+
this.highlightLayer = null;
|
|
1642
1665
|
}
|
|
1643
1666
|
on(eventName, listener) {
|
|
1644
1667
|
return super.on(eventName, listener);
|
|
@@ -1668,7 +1691,7 @@ class ActionManager extends EventEmitter {
|
|
|
1668
1691
|
}).on(AbleActionEventType.SELECT_PARENT, () => {
|
|
1669
1692
|
this.emit("select-parent");
|
|
1670
1693
|
}).on(AbleActionEventType.REMOVE, () => {
|
|
1671
|
-
const drTarget = this.dr
|
|
1694
|
+
const drTarget = this.dr?.getTarget();
|
|
1672
1695
|
if (!drTarget) return;
|
|
1673
1696
|
const data = {
|
|
1674
1697
|
data: [{ el: drTarget }]
|
|
@@ -2361,6 +2384,16 @@ class StageRender extends EventEmitter$1 {
|
|
|
2361
2384
|
getTargetElement(id) {
|
|
2362
2385
|
return getElById()(this.getDocument(), id);
|
|
2363
2386
|
}
|
|
2387
|
+
postTmagicRuntimeReady() {
|
|
2388
|
+
this.contentWindow = this.iframe?.contentWindow;
|
|
2389
|
+
this.contentWindow.magic = this.getMagicApi();
|
|
2390
|
+
this.contentWindow.postMessage(
|
|
2391
|
+
{
|
|
2392
|
+
tmagicRuntimeReady: true
|
|
2393
|
+
},
|
|
2394
|
+
"*"
|
|
2395
|
+
);
|
|
2396
|
+
}
|
|
2364
2397
|
/**
|
|
2365
2398
|
* 销毁实例
|
|
2366
2399
|
*/
|
|
@@ -2424,23 +2457,13 @@ class StageRender extends EventEmitter$1 {
|
|
|
2424
2457
|
this.emit("onload");
|
|
2425
2458
|
injectStyle(this.contentWindow.document, style);
|
|
2426
2459
|
};
|
|
2427
|
-
postTmagicRuntimeReady() {
|
|
2428
|
-
this.contentWindow = this.iframe?.contentWindow;
|
|
2429
|
-
this.contentWindow.magic = this.getMagicApi();
|
|
2430
|
-
this.contentWindow.postMessage(
|
|
2431
|
-
{
|
|
2432
|
-
tmagicRuntimeReady: true
|
|
2433
|
-
},
|
|
2434
|
-
"*"
|
|
2435
|
-
);
|
|
2436
|
-
}
|
|
2437
2460
|
}
|
|
2438
2461
|
|
|
2439
2462
|
class StageCore extends EventEmitter$1 {
|
|
2440
2463
|
container;
|
|
2441
|
-
renderer;
|
|
2442
|
-
mask;
|
|
2443
|
-
actionManager;
|
|
2464
|
+
renderer = null;
|
|
2465
|
+
mask = null;
|
|
2466
|
+
actionManager = null;
|
|
2444
2467
|
pageResizeObserver = null;
|
|
2445
2468
|
autoScrollIntoView;
|
|
2446
2469
|
customizedRender;
|
|
@@ -2472,13 +2495,15 @@ class StageCore extends EventEmitter$1 {
|
|
|
2472
2495
|
* @param id 选中的id
|
|
2473
2496
|
*/
|
|
2474
2497
|
async select(id, event) {
|
|
2475
|
-
const el = this.renderer
|
|
2476
|
-
if (el === this.actionManager
|
|
2477
|
-
await this.renderer
|
|
2478
|
-
|
|
2479
|
-
|
|
2498
|
+
const el = this.renderer?.getTargetElement(id) || null;
|
|
2499
|
+
if (el === this.actionManager?.getSelectedEl()) return;
|
|
2500
|
+
await this.renderer?.select([id]);
|
|
2501
|
+
if (el) {
|
|
2502
|
+
this.mask?.setLayout(el);
|
|
2503
|
+
}
|
|
2504
|
+
this.actionManager?.select(el, event);
|
|
2480
2505
|
if (el && (this.autoScrollIntoView || el.dataset.autoScrollIntoView)) {
|
|
2481
|
-
this.mask
|
|
2506
|
+
this.mask?.observerIntersection(el);
|
|
2482
2507
|
}
|
|
2483
2508
|
}
|
|
2484
2509
|
/**
|
|
@@ -2486,15 +2511,15 @@ class StageCore extends EventEmitter$1 {
|
|
|
2486
2511
|
* @param ids 选中元素的id列表
|
|
2487
2512
|
*/
|
|
2488
2513
|
async multiSelect(ids) {
|
|
2489
|
-
const els = ids.map((id) => this.renderer
|
|
2514
|
+
const els = ids.map((id) => this.renderer?.getTargetElement(id)).filter((el) => Boolean(el));
|
|
2490
2515
|
if (els.length === 0) return;
|
|
2491
2516
|
const lastEl = els[els.length - 1];
|
|
2492
2517
|
const isReduceSelect = els.length < this.actionManager.getSelectedElList().length;
|
|
2493
|
-
await this.renderer
|
|
2494
|
-
lastEl && this.mask
|
|
2495
|
-
this.actionManager
|
|
2518
|
+
await this.renderer?.select(ids);
|
|
2519
|
+
lastEl && this.mask?.setLayout(lastEl);
|
|
2520
|
+
this.actionManager?.multiSelect(ids);
|
|
2496
2521
|
if (lastEl && (this.autoScrollIntoView || lastEl.dataset.autoScrollIntoView) && !isReduceSelect) {
|
|
2497
|
-
this.mask
|
|
2522
|
+
this.mask?.observerIntersection(lastEl);
|
|
2498
2523
|
}
|
|
2499
2524
|
}
|
|
2500
2525
|
/**
|
|
@@ -2502,10 +2527,10 @@ class StageCore extends EventEmitter$1 {
|
|
|
2502
2527
|
* @param el 要高亮的元素
|
|
2503
2528
|
*/
|
|
2504
2529
|
highlight(id) {
|
|
2505
|
-
this.actionManager
|
|
2530
|
+
this.actionManager?.highlight(id);
|
|
2506
2531
|
}
|
|
2507
2532
|
clearHighlight() {
|
|
2508
|
-
this.actionManager
|
|
2533
|
+
this.actionManager?.clearHighlight();
|
|
2509
2534
|
}
|
|
2510
2535
|
/**
|
|
2511
2536
|
* 更新组件
|
|
@@ -2513,11 +2538,11 @@ class StageCore extends EventEmitter$1 {
|
|
|
2513
2538
|
*/
|
|
2514
2539
|
async update(data) {
|
|
2515
2540
|
const { config } = data;
|
|
2516
|
-
await this.renderer
|
|
2541
|
+
await this.renderer?.update(data);
|
|
2517
2542
|
setTimeout(() => {
|
|
2518
|
-
const el = this.renderer
|
|
2519
|
-
if (el && this.actionManager
|
|
2520
|
-
this.mask
|
|
2543
|
+
const el = this.renderer?.getTargetElement(`${config.id}`);
|
|
2544
|
+
if (el && this.actionManager?.isSelectedEl(el)) {
|
|
2545
|
+
this.mask?.setLayout(el);
|
|
2521
2546
|
this.actionManager.setSelectedEl(el);
|
|
2522
2547
|
this.actionManager.updateMoveable(el);
|
|
2523
2548
|
}
|
|
@@ -2528,17 +2553,17 @@ class StageCore extends EventEmitter$1 {
|
|
|
2528
2553
|
* @param data 组件信息数据
|
|
2529
2554
|
*/
|
|
2530
2555
|
async add(data) {
|
|
2531
|
-
return await this.renderer
|
|
2556
|
+
return await this.renderer?.add(data);
|
|
2532
2557
|
}
|
|
2533
2558
|
/**
|
|
2534
2559
|
* 从画布删除一个组件
|
|
2535
2560
|
* @param data 组件信息数据
|
|
2536
2561
|
*/
|
|
2537
2562
|
async remove(data) {
|
|
2538
|
-
return await this.renderer
|
|
2563
|
+
return await this.renderer?.remove(data);
|
|
2539
2564
|
}
|
|
2540
2565
|
setZoom(zoom = DEFAULT_ZOOM) {
|
|
2541
|
-
this.renderer
|
|
2566
|
+
this.renderer?.setZoom(zoom);
|
|
2542
2567
|
}
|
|
2543
2568
|
/**
|
|
2544
2569
|
* 挂载Dom节点
|
|
@@ -2547,16 +2572,16 @@ class StageCore extends EventEmitter$1 {
|
|
|
2547
2572
|
async mount(el) {
|
|
2548
2573
|
this.container = el;
|
|
2549
2574
|
const { mask, renderer } = this;
|
|
2550
|
-
await renderer
|
|
2551
|
-
mask
|
|
2575
|
+
await renderer?.mount(el);
|
|
2576
|
+
mask?.mount(el);
|
|
2552
2577
|
this.emit("mounted");
|
|
2553
2578
|
}
|
|
2554
2579
|
/**
|
|
2555
2580
|
* 清空所有参考线
|
|
2556
2581
|
*/
|
|
2557
2582
|
clearGuides() {
|
|
2558
|
-
this.mask
|
|
2559
|
-
this.actionManager
|
|
2583
|
+
this.mask?.clearGuides();
|
|
2584
|
+
this.actionManager?.clearGuides();
|
|
2560
2585
|
}
|
|
2561
2586
|
/**
|
|
2562
2587
|
* @deprecated 废弃接口,建议用delayedMarkContainer代替
|
|
@@ -2572,31 +2597,35 @@ class StageCore extends EventEmitter$1 {
|
|
|
2572
2597
|
* @returns timeoutId,调用方在鼠标移走时要取消该timeout,阻止标记
|
|
2573
2598
|
*/
|
|
2574
2599
|
delayedMarkContainer(event, excludeElList = []) {
|
|
2575
|
-
return this.actionManager
|
|
2600
|
+
return this.actionManager?.delayedMarkContainer(event, excludeElList);
|
|
2576
2601
|
}
|
|
2577
2602
|
getMoveableOption(key) {
|
|
2578
|
-
return this.actionManager
|
|
2603
|
+
return this.actionManager?.getMoveableOption(key);
|
|
2579
2604
|
}
|
|
2580
2605
|
getDragStatus() {
|
|
2581
|
-
return this.actionManager
|
|
2606
|
+
return this.actionManager?.getDragStatus();
|
|
2582
2607
|
}
|
|
2583
2608
|
disableMultiSelect() {
|
|
2584
|
-
this.actionManager
|
|
2609
|
+
this.actionManager?.disableMultiSelect();
|
|
2585
2610
|
}
|
|
2586
2611
|
enableMultiSelect() {
|
|
2587
|
-
this.actionManager
|
|
2612
|
+
this.actionManager?.enableMultiSelect();
|
|
2588
2613
|
}
|
|
2589
2614
|
/**
|
|
2590
2615
|
* 销毁实例
|
|
2591
2616
|
*/
|
|
2592
2617
|
destroy() {
|
|
2593
2618
|
const { mask, renderer, actionManager, pageResizeObserver } = this;
|
|
2594
|
-
renderer
|
|
2595
|
-
mask
|
|
2596
|
-
actionManager
|
|
2619
|
+
renderer?.destroy();
|
|
2620
|
+
mask?.destroy();
|
|
2621
|
+
actionManager?.destroy();
|
|
2597
2622
|
pageResizeObserver?.disconnect();
|
|
2598
2623
|
this.removeAllListeners();
|
|
2599
2624
|
this.container = void 0;
|
|
2625
|
+
this.renderer = null;
|
|
2626
|
+
this.mask = null;
|
|
2627
|
+
this.actionManager = null;
|
|
2628
|
+
this.pageResizeObserver = null;
|
|
2600
2629
|
}
|
|
2601
2630
|
on(eventName, listener) {
|
|
2602
2631
|
return super.on(eventName, listener);
|
|
@@ -2613,8 +2642,8 @@ class StageCore extends EventEmitter$1 {
|
|
|
2613
2642
|
}
|
|
2614
2643
|
if (typeof ResizeObserver !== "undefined") {
|
|
2615
2644
|
this.pageResizeObserver = new ResizeObserver((entries) => {
|
|
2616
|
-
this.mask
|
|
2617
|
-
this.actionManager
|
|
2645
|
+
this.mask?.pageResize(entries);
|
|
2646
|
+
this.actionManager?.updateMoveable();
|
|
2618
2647
|
});
|
|
2619
2648
|
this.pageResizeObserver.observe(page);
|
|
2620
2649
|
}
|
|
@@ -2639,18 +2668,18 @@ class StageCore extends EventEmitter$1 {
|
|
|
2639
2668
|
return actionManagerConfig;
|
|
2640
2669
|
}
|
|
2641
2670
|
initRenderEvent() {
|
|
2642
|
-
this.renderer
|
|
2671
|
+
this.renderer?.on("runtime-ready", (runtime) => {
|
|
2643
2672
|
this.emit("runtime-ready", runtime);
|
|
2644
2673
|
});
|
|
2645
|
-
this.renderer
|
|
2674
|
+
this.renderer?.on("page-el-update", (el) => {
|
|
2646
2675
|
this.mask?.observe(el);
|
|
2647
2676
|
this.observePageResize(el);
|
|
2648
2677
|
this.emit("page-el-update", el);
|
|
2649
2678
|
});
|
|
2650
2679
|
}
|
|
2651
2680
|
initMaskEvent() {
|
|
2652
|
-
this.mask
|
|
2653
|
-
this.actionManager
|
|
2681
|
+
this.mask?.on("change-guides", (data) => {
|
|
2682
|
+
this.actionManager?.setGuidelines(data.type, data.guides);
|
|
2654
2683
|
this.emit("change-guides", data);
|
|
2655
2684
|
});
|
|
2656
2685
|
}
|
|
@@ -2668,7 +2697,7 @@ class StageCore extends EventEmitter$1 {
|
|
|
2668
2697
|
* 初始化ActionManager类本身抛出来的事件监听
|
|
2669
2698
|
*/
|
|
2670
2699
|
initActionManagerEvent() {
|
|
2671
|
-
this.actionManager
|
|
2700
|
+
this.actionManager?.on("before-select", (el, event) => {
|
|
2672
2701
|
const id = getIdFromEl()(el);
|
|
2673
2702
|
id && this.select(id, event);
|
|
2674
2703
|
}).on("select", (selectedEl, event) => {
|
|
@@ -2685,7 +2714,7 @@ class StageCore extends EventEmitter$1 {
|
|
|
2685
2714
|
* 初始化DragResize类通过ActionManager抛出来的事件监听
|
|
2686
2715
|
*/
|
|
2687
2716
|
initDrEvent() {
|
|
2688
|
-
this.actionManager
|
|
2717
|
+
this.actionManager?.on("update", (data) => {
|
|
2689
2718
|
this.emit("update", data);
|
|
2690
2719
|
}).on("sort", (data) => {
|
|
2691
2720
|
this.emit("sort", data);
|
|
@@ -2699,10 +2728,10 @@ class StageCore extends EventEmitter$1 {
|
|
|
2699
2728
|
* 初始化MultiDragResize类通过ActionManager抛出来的事件监听
|
|
2700
2729
|
*/
|
|
2701
2730
|
initMulDrEvent() {
|
|
2702
|
-
this.actionManager
|
|
2731
|
+
this.actionManager?.on("change-to-select", (id, e) => {
|
|
2703
2732
|
this.select(id);
|
|
2704
2733
|
setTimeout(() => {
|
|
2705
|
-
const el = this.renderer
|
|
2734
|
+
const el = this.renderer?.getTargetElement(id);
|
|
2706
2735
|
el && this.emit("select", el, e);
|
|
2707
2736
|
});
|
|
2708
2737
|
}).on("multi-update", (data) => {
|
|
@@ -2713,7 +2742,7 @@ class StageCore extends EventEmitter$1 {
|
|
|
2713
2742
|
* 初始化Highlight类通过ActionManager抛出来的事件监听
|
|
2714
2743
|
*/
|
|
2715
2744
|
initHighlightEvent() {
|
|
2716
|
-
this.actionManager
|
|
2745
|
+
this.actionManager?.on("highlight", (highlightEl) => {
|
|
2717
2746
|
this.emit("highlight", highlightEl);
|
|
2718
2747
|
});
|
|
2719
2748
|
}
|
|
@@ -2721,7 +2750,7 @@ class StageCore extends EventEmitter$1 {
|
|
|
2721
2750
|
* 初始化Highlight类通过ActionManager抛出来的事件监听
|
|
2722
2751
|
*/
|
|
2723
2752
|
initMouseEvent() {
|
|
2724
|
-
this.actionManager
|
|
2753
|
+
this.actionManager?.on("mousemove", (event) => {
|
|
2725
2754
|
this.emit("mousemove", event);
|
|
2726
2755
|
}).on("mouseleave", (event) => {
|
|
2727
2756
|
this.emit("mouseleave", event);
|
|
@@ -2731,4 +2760,4 @@ class StageCore extends EventEmitter$1 {
|
|
|
2731
2760
|
}
|
|
2732
2761
|
}
|
|
2733
2762
|
|
|
2734
|
-
export { AbleActionEventType, CONTAINER_HIGHLIGHT_CLASS_NAME, ContainerHighlightType, DEFAULT_ZOOM, DRAG_EL_ID_PREFIX, GHOST_EL_ID_PREFIX, GuidesType, HIGHLIGHT_EL_ID_PREFIX, Mode, MouseButton, 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 };
|
|
2763
|
+
export { AbleActionEventType, CONTAINER_HIGHLIGHT_CLASS_NAME, ContainerHighlightType, DEFAULT_ZOOM, DRAG_EL_ID_PREFIX, GHOST_EL_ID_PREFIX, GuidesType, HIGHLIGHT_EL_ID_PREFIX, Mode, MouseButton, 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 };
|