@tmagic/stage 1.1.0-beta.5 → 1.1.0-beta.8
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.es.js → tmagic-stage.mjs} +216 -158
- package/dist/tmagic-stage.mjs.map +1 -0
- package/dist/tmagic-stage.umd.js +228 -170
- package/dist/tmagic-stage.umd.js.map +1 -1
- package/package.json +13 -11
- package/src/StageCore.ts +14 -5
- package/src/StageDragResize.ts +1 -1
- package/src/StageMask.ts +10 -3
- package/src/StageMultiDragResize.ts +12 -8
- package/src/types.ts +1 -1
- package/tsconfig.build.json +13 -0
- package/{dist/types/src → types}/Rule.d.ts +0 -0
- package/{dist/types/src → types}/StageCore.d.ts +6 -0
- package/{dist/types/src → types}/StageDragResize.d.ts +0 -0
- package/{dist/types/src → types}/StageHighlight.d.ts +0 -0
- package/{dist/types/src → types}/StageMask.d.ts +0 -0
- package/{dist/types/src → types}/StageMultiDragResize.d.ts +1 -1
- package/{dist/types/src → types}/StageRender.d.ts +0 -0
- package/{dist/types/src → types}/TargetCalibrate.d.ts +0 -0
- package/{dist/types/src → types}/const.d.ts +0 -0
- package/{dist/types/src → types}/index.d.ts +0 -0
- package/types/logger.d.ts +5 -0
- package/{dist/types/src → types}/types.d.ts +1 -1
- package/{dist/types/src → types}/util.d.ts +0 -0
- package/dist/tmagic-stage.es.js.map +0 -1
- package/dist/types/src/vite-env.d.ts +0 -1
- package/src/vite-env.d.ts +0 -1
package/dist/tmagic-stage.umd.js
CHANGED
|
@@ -4,13 +4,13 @@
|
|
|
4
4
|
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.TMagicStage = {}, global.EventEmitter, global.utils, global.Moveable, global.MoveableHelper, global.KeyController, global.lodashEs, global.Guides));
|
|
5
5
|
})(this, (function (exports, EventEmitter, utils, Moveable, MoveableHelper, KeyController, lodashEs, Guides) { 'use strict';
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
const _interopDefaultLegacy = e => e && typeof e === 'object' && 'default' in e ? e : { default: e };
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
const EventEmitter__default = /*#__PURE__*/_interopDefaultLegacy(EventEmitter);
|
|
10
|
+
const Moveable__default = /*#__PURE__*/_interopDefaultLegacy(Moveable);
|
|
11
|
+
const MoveableHelper__default = /*#__PURE__*/_interopDefaultLegacy(MoveableHelper);
|
|
12
|
+
const KeyController__default = /*#__PURE__*/_interopDefaultLegacy(KeyController);
|
|
13
|
+
const Guides__default = /*#__PURE__*/_interopDefaultLegacy(Guides);
|
|
14
14
|
|
|
15
15
|
const GHOST_EL_ID_PREFIX = "ghost_el_";
|
|
16
16
|
const DRAG_EL_ID_PREFIX = "drag_el_";
|
|
@@ -210,14 +210,22 @@
|
|
|
210
210
|
};
|
|
211
211
|
|
|
212
212
|
class StageDragResize extends EventEmitter.EventEmitter {
|
|
213
|
+
core;
|
|
214
|
+
mask;
|
|
215
|
+
container;
|
|
216
|
+
target;
|
|
217
|
+
dragEl;
|
|
218
|
+
moveable;
|
|
219
|
+
horizontalGuidelines = [];
|
|
220
|
+
verticalGuidelines = [];
|
|
221
|
+
elementGuidelines = [];
|
|
222
|
+
mode = Mode.ABSOLUTE;
|
|
223
|
+
moveableOptions = {};
|
|
224
|
+
dragStatus = "end" /* END */;
|
|
225
|
+
ghostEl;
|
|
226
|
+
moveableHelper;
|
|
213
227
|
constructor(config) {
|
|
214
228
|
super();
|
|
215
|
-
this.horizontalGuidelines = [];
|
|
216
|
-
this.verticalGuidelines = [];
|
|
217
|
-
this.elementGuidelines = [];
|
|
218
|
-
this.mode = Mode.ABSOLUTE;
|
|
219
|
-
this.moveableOptions = {};
|
|
220
|
-
this.dragStatus = "end" /* END */;
|
|
221
229
|
this.core = config.core;
|
|
222
230
|
this.container = config.container;
|
|
223
231
|
this.mask = config.mask;
|
|
@@ -227,7 +235,7 @@
|
|
|
227
235
|
this.target = el;
|
|
228
236
|
if (!this.moveable || this.target !== oldTarget) {
|
|
229
237
|
this.init(el);
|
|
230
|
-
this.moveableHelper = MoveableHelper__default
|
|
238
|
+
this.moveableHelper = MoveableHelper__default.default.create({
|
|
231
239
|
useBeforeRender: true,
|
|
232
240
|
useRender: false,
|
|
233
241
|
createAuto: true
|
|
@@ -331,7 +339,7 @@
|
|
|
331
339
|
}
|
|
332
340
|
initMoveable() {
|
|
333
341
|
this.moveable?.destroy();
|
|
334
|
-
this.moveable = new Moveable__default
|
|
342
|
+
this.moveable = new Moveable__default.default(this.container, {
|
|
335
343
|
...this.moveableOptions
|
|
336
344
|
});
|
|
337
345
|
this.bindResizeEvent();
|
|
@@ -543,7 +551,7 @@
|
|
|
543
551
|
return ghostEl;
|
|
544
552
|
}
|
|
545
553
|
setGhostElChildrenId(el) {
|
|
546
|
-
for (const child of el.children) {
|
|
554
|
+
for (const child of Array.from(el.children)) {
|
|
547
555
|
if (child.id) {
|
|
548
556
|
child.id = `${GHOST_EL_ID_PREFIX}${child.id}`;
|
|
549
557
|
}
|
|
@@ -617,6 +625,11 @@
|
|
|
617
625
|
}
|
|
618
626
|
|
|
619
627
|
class TargetCalibrate extends EventEmitter.EventEmitter {
|
|
628
|
+
parent;
|
|
629
|
+
mask;
|
|
630
|
+
dr;
|
|
631
|
+
core;
|
|
632
|
+
operationEl;
|
|
620
633
|
constructor(config) {
|
|
621
634
|
super();
|
|
622
635
|
this.parent = config.parent;
|
|
@@ -684,6 +697,11 @@
|
|
|
684
697
|
}
|
|
685
698
|
|
|
686
699
|
class StageHighlight extends EventEmitter.EventEmitter {
|
|
700
|
+
core;
|
|
701
|
+
container;
|
|
702
|
+
target;
|
|
703
|
+
moveable;
|
|
704
|
+
calibrationTarget;
|
|
687
705
|
constructor(config) {
|
|
688
706
|
super();
|
|
689
707
|
this.core = config.core;
|
|
@@ -700,7 +718,7 @@
|
|
|
700
718
|
return;
|
|
701
719
|
this.target = el;
|
|
702
720
|
this.moveable?.destroy();
|
|
703
|
-
this.moveable = new Moveable__default
|
|
721
|
+
this.moveable = new Moveable__default.default(this.container, {
|
|
704
722
|
target: this.calibrationTarget.update(el, HIGHLIGHT_EL_ID_PREFIX),
|
|
705
723
|
origin: false,
|
|
706
724
|
rootContainer: this.core.container,
|
|
@@ -720,42 +738,15 @@
|
|
|
720
738
|
}
|
|
721
739
|
}
|
|
722
740
|
|
|
723
|
-
class Rule extends EventEmitter__default
|
|
741
|
+
class Rule extends EventEmitter__default.default {
|
|
742
|
+
hGuides;
|
|
743
|
+
vGuides;
|
|
744
|
+
horizontalGuidelines = [];
|
|
745
|
+
verticalGuidelines = [];
|
|
746
|
+
container;
|
|
747
|
+
containerResizeObserver;
|
|
724
748
|
constructor(container) {
|
|
725
749
|
super();
|
|
726
|
-
this.horizontalGuidelines = [];
|
|
727
|
-
this.verticalGuidelines = [];
|
|
728
|
-
this.getGuidesStyle = (type) => ({
|
|
729
|
-
position: "fixed",
|
|
730
|
-
zIndex: 1,
|
|
731
|
-
left: type === GuidesType.HORIZONTAL ? 0 : "-30px",
|
|
732
|
-
top: type === GuidesType.HORIZONTAL ? "-30px" : 0,
|
|
733
|
-
width: type === GuidesType.HORIZONTAL ? "100%" : "30px",
|
|
734
|
-
height: type === GuidesType.HORIZONTAL ? "30px" : "100%"
|
|
735
|
-
});
|
|
736
|
-
this.createGuides = (type, defaultGuides = []) => new Guides__default["default"](this.container, {
|
|
737
|
-
type,
|
|
738
|
-
defaultGuides,
|
|
739
|
-
displayDragPos: true,
|
|
740
|
-
backgroundColor: "#fff",
|
|
741
|
-
lineColor: "#000",
|
|
742
|
-
textColor: "#000",
|
|
743
|
-
style: this.getGuidesStyle(type)
|
|
744
|
-
});
|
|
745
|
-
this.hGuidesChangeGuidesHandler = (e) => {
|
|
746
|
-
this.horizontalGuidelines = e.guides;
|
|
747
|
-
this.emit("changeGuides", {
|
|
748
|
-
type: GuidesType.HORIZONTAL,
|
|
749
|
-
guides: this.horizontalGuidelines
|
|
750
|
-
});
|
|
751
|
-
};
|
|
752
|
-
this.vGuidesChangeGuidesHandler = (e) => {
|
|
753
|
-
this.verticalGuidelines = e.guides;
|
|
754
|
-
this.emit("changeGuides", {
|
|
755
|
-
type: GuidesType.VERTICAL,
|
|
756
|
-
guides: this.verticalGuidelines
|
|
757
|
-
});
|
|
758
|
-
};
|
|
759
750
|
this.container = container;
|
|
760
751
|
this.hGuides = this.createGuides(GuidesType.HORIZONTAL, this.horizontalGuidelines);
|
|
761
752
|
this.vGuides = this.createGuides(GuidesType.VERTICAL, this.verticalGuidelines);
|
|
@@ -827,6 +818,37 @@
|
|
|
827
818
|
this.containerResizeObserver.disconnect();
|
|
828
819
|
this.removeAllListeners();
|
|
829
820
|
}
|
|
821
|
+
getGuidesStyle = (type) => ({
|
|
822
|
+
position: "fixed",
|
|
823
|
+
zIndex: 1,
|
|
824
|
+
left: type === GuidesType.HORIZONTAL ? 0 : "-30px",
|
|
825
|
+
top: type === GuidesType.HORIZONTAL ? "-30px" : 0,
|
|
826
|
+
width: type === GuidesType.HORIZONTAL ? "100%" : "30px",
|
|
827
|
+
height: type === GuidesType.HORIZONTAL ? "30px" : "100%"
|
|
828
|
+
});
|
|
829
|
+
createGuides = (type, defaultGuides = []) => new Guides__default.default(this.container, {
|
|
830
|
+
type,
|
|
831
|
+
defaultGuides,
|
|
832
|
+
displayDragPos: true,
|
|
833
|
+
backgroundColor: "#fff",
|
|
834
|
+
lineColor: "#000",
|
|
835
|
+
textColor: "#000",
|
|
836
|
+
style: this.getGuidesStyle(type)
|
|
837
|
+
});
|
|
838
|
+
hGuidesChangeGuidesHandler = (e) => {
|
|
839
|
+
this.horizontalGuidelines = e.guides;
|
|
840
|
+
this.emit("changeGuides", {
|
|
841
|
+
type: GuidesType.HORIZONTAL,
|
|
842
|
+
guides: this.horizontalGuidelines
|
|
843
|
+
});
|
|
844
|
+
};
|
|
845
|
+
vGuidesChangeGuidesHandler = (e) => {
|
|
846
|
+
this.verticalGuidelines = e.guides;
|
|
847
|
+
this.emit("changeGuides", {
|
|
848
|
+
type: GuidesType.VERTICAL,
|
|
849
|
+
guides: this.verticalGuidelines
|
|
850
|
+
});
|
|
851
|
+
};
|
|
830
852
|
}
|
|
831
853
|
|
|
832
854
|
const wrapperClassName = "editor-mask-wrapper";
|
|
@@ -860,74 +882,30 @@
|
|
|
860
882
|
return el;
|
|
861
883
|
};
|
|
862
884
|
class StageMask extends Rule {
|
|
885
|
+
content = createContent();
|
|
886
|
+
wrapper;
|
|
887
|
+
core;
|
|
888
|
+
page = null;
|
|
889
|
+
pageScrollParent = null;
|
|
890
|
+
scrollTop = 0;
|
|
891
|
+
scrollLeft = 0;
|
|
892
|
+
width = 0;
|
|
893
|
+
height = 0;
|
|
894
|
+
wrapperHeight = 0;
|
|
895
|
+
wrapperWidth = 0;
|
|
896
|
+
maxScrollTop = 0;
|
|
897
|
+
maxScrollLeft = 0;
|
|
898
|
+
intersectionObserver = null;
|
|
899
|
+
isMultiSelectStatus = false;
|
|
900
|
+
mode = Mode.ABSOLUTE;
|
|
901
|
+
pageResizeObserver = null;
|
|
902
|
+
wrapperResizeObserver = null;
|
|
903
|
+
highlightHandler = lodashEs.throttle((event) => {
|
|
904
|
+
this.emit("highlight", event);
|
|
905
|
+
}, throttleTime);
|
|
863
906
|
constructor(config) {
|
|
864
907
|
const wrapper = createWrapper();
|
|
865
908
|
super(wrapper);
|
|
866
|
-
this.content = createContent();
|
|
867
|
-
this.page = null;
|
|
868
|
-
this.pageScrollParent = null;
|
|
869
|
-
this.scrollTop = 0;
|
|
870
|
-
this.scrollLeft = 0;
|
|
871
|
-
this.width = 0;
|
|
872
|
-
this.height = 0;
|
|
873
|
-
this.wrapperHeight = 0;
|
|
874
|
-
this.wrapperWidth = 0;
|
|
875
|
-
this.maxScrollTop = 0;
|
|
876
|
-
this.maxScrollLeft = 0;
|
|
877
|
-
this.intersectionObserver = null;
|
|
878
|
-
this.isMultiSelectStatus = false;
|
|
879
|
-
this.mode = Mode.ABSOLUTE;
|
|
880
|
-
this.pageResizeObserver = null;
|
|
881
|
-
this.wrapperResizeObserver = null;
|
|
882
|
-
this.highlightHandler = lodashEs.throttle((event) => {
|
|
883
|
-
this.emit("highlight", event);
|
|
884
|
-
}, throttleTime);
|
|
885
|
-
this.mouseDownHandler = (event) => {
|
|
886
|
-
this.emit("clearHighlight");
|
|
887
|
-
event.stopImmediatePropagation();
|
|
888
|
-
event.stopPropagation();
|
|
889
|
-
if (event.button !== MouseButton.LEFT && event.button !== MouseButton.RIGHT)
|
|
890
|
-
return;
|
|
891
|
-
if (!this.isMultiSelectStatus && event.target.className.indexOf("moveable-area") !== -1) {
|
|
892
|
-
return;
|
|
893
|
-
}
|
|
894
|
-
if (event.target.className.indexOf("moveable-control") !== -1) {
|
|
895
|
-
return;
|
|
896
|
-
}
|
|
897
|
-
this.content.removeEventListener("mousemove", this.highlightHandler);
|
|
898
|
-
if (this.isMultiSelectStatus) {
|
|
899
|
-
this.emit("beforeMultiSelect", event);
|
|
900
|
-
} else {
|
|
901
|
-
this.emit("beforeSelect", event);
|
|
902
|
-
}
|
|
903
|
-
globalThis.document.addEventListener("mouseup", this.mouseUpHandler);
|
|
904
|
-
};
|
|
905
|
-
this.mouseUpHandler = () => {
|
|
906
|
-
globalThis.document.removeEventListener("mouseup", this.mouseUpHandler);
|
|
907
|
-
this.content.addEventListener("mousemove", this.highlightHandler);
|
|
908
|
-
this.emit("select");
|
|
909
|
-
};
|
|
910
|
-
this.mouseWheelHandler = (event) => {
|
|
911
|
-
this.emit("clearHighlight");
|
|
912
|
-
if (!this.page)
|
|
913
|
-
throw new Error("page \u672A\u521D\u59CB\u5316");
|
|
914
|
-
const { deltaY, deltaX } = event;
|
|
915
|
-
if (this.page.clientHeight < this.wrapperHeight && deltaY)
|
|
916
|
-
return;
|
|
917
|
-
if (this.page.clientWidth < this.wrapperWidth && deltaX)
|
|
918
|
-
return;
|
|
919
|
-
if (this.maxScrollTop > 0) {
|
|
920
|
-
this.scrollTop = this.scrollTop + deltaY;
|
|
921
|
-
}
|
|
922
|
-
if (this.maxScrollLeft > 0) {
|
|
923
|
-
this.scrollLeft = this.scrollLeft + deltaX;
|
|
924
|
-
}
|
|
925
|
-
this.scroll();
|
|
926
|
-
this.emit("scroll", event);
|
|
927
|
-
};
|
|
928
|
-
this.mouseLeaveHandler = () => {
|
|
929
|
-
setTimeout(() => this.emit("clearHighlight"), throttleTime);
|
|
930
|
-
};
|
|
931
909
|
this.wrapper = wrapper;
|
|
932
910
|
this.core = config.core;
|
|
933
911
|
this.content.addEventListener("mousedown", this.mouseDownHandler);
|
|
@@ -935,11 +913,13 @@
|
|
|
935
913
|
this.content.addEventListener("wheel", this.mouseWheelHandler);
|
|
936
914
|
this.content.addEventListener("mousemove", this.highlightHandler);
|
|
937
915
|
this.content.addEventListener("mouseleave", this.mouseLeaveHandler);
|
|
938
|
-
|
|
916
|
+
const isMac = /mac os x/.test(navigator.userAgent.toLowerCase());
|
|
917
|
+
const ctrl = isMac ? "meta" : "ctrl";
|
|
918
|
+
KeyController__default.default.global.keydown(ctrl, (e) => {
|
|
939
919
|
e.inputEvent.preventDefault();
|
|
940
920
|
this.isMultiSelectStatus = true;
|
|
941
921
|
});
|
|
942
|
-
KeyController__default
|
|
922
|
+
KeyController__default.default.global.keyup(ctrl, (e) => {
|
|
943
923
|
e.inputEvent.preventDefault();
|
|
944
924
|
this.isMultiSelectStatus = false;
|
|
945
925
|
});
|
|
@@ -1071,13 +1051,66 @@
|
|
|
1071
1051
|
if (this.maxScrollLeft < this.scrollLeft)
|
|
1072
1052
|
this.scrollLeft = this.maxScrollLeft;
|
|
1073
1053
|
}
|
|
1054
|
+
mouseDownHandler = (event) => {
|
|
1055
|
+
this.emit("clearHighlight");
|
|
1056
|
+
event.stopImmediatePropagation();
|
|
1057
|
+
event.stopPropagation();
|
|
1058
|
+
if (event.button !== MouseButton.LEFT && event.button !== MouseButton.RIGHT)
|
|
1059
|
+
return;
|
|
1060
|
+
if (!this.isMultiSelectStatus && event.target.className.indexOf("moveable-area") !== -1) {
|
|
1061
|
+
return;
|
|
1062
|
+
}
|
|
1063
|
+
if (event.target.className.indexOf("moveable-control") !== -1) {
|
|
1064
|
+
return;
|
|
1065
|
+
}
|
|
1066
|
+
this.content.removeEventListener("mousemove", this.highlightHandler);
|
|
1067
|
+
if (this.isMultiSelectStatus) {
|
|
1068
|
+
this.emit("beforeMultiSelect", event);
|
|
1069
|
+
} else {
|
|
1070
|
+
this.emit("beforeSelect", event);
|
|
1071
|
+
}
|
|
1072
|
+
globalThis.document.addEventListener("mouseup", this.mouseUpHandler);
|
|
1073
|
+
};
|
|
1074
|
+
mouseUpHandler = () => {
|
|
1075
|
+
globalThis.document.removeEventListener("mouseup", this.mouseUpHandler);
|
|
1076
|
+
this.content.addEventListener("mousemove", this.highlightHandler);
|
|
1077
|
+
if (!this.isMultiSelectStatus) {
|
|
1078
|
+
this.emit("select");
|
|
1079
|
+
}
|
|
1080
|
+
};
|
|
1081
|
+
mouseWheelHandler = (event) => {
|
|
1082
|
+
this.emit("clearHighlight");
|
|
1083
|
+
if (!this.page)
|
|
1084
|
+
throw new Error("page \u672A\u521D\u59CB\u5316");
|
|
1085
|
+
const { deltaY, deltaX } = event;
|
|
1086
|
+
if (this.page.clientHeight < this.wrapperHeight && deltaY)
|
|
1087
|
+
return;
|
|
1088
|
+
if (this.page.clientWidth < this.wrapperWidth && deltaX)
|
|
1089
|
+
return;
|
|
1090
|
+
if (this.maxScrollTop > 0) {
|
|
1091
|
+
this.scrollTop = this.scrollTop + deltaY;
|
|
1092
|
+
}
|
|
1093
|
+
if (this.maxScrollLeft > 0) {
|
|
1094
|
+
this.scrollLeft = this.scrollLeft + deltaX;
|
|
1095
|
+
}
|
|
1096
|
+
this.scroll();
|
|
1097
|
+
this.emit("scroll", event);
|
|
1098
|
+
};
|
|
1099
|
+
mouseLeaveHandler = () => {
|
|
1100
|
+
setTimeout(() => this.emit("clearHighlight"), throttleTime);
|
|
1101
|
+
};
|
|
1074
1102
|
}
|
|
1075
1103
|
|
|
1076
1104
|
class StageMultiDragResize extends EventEmitter.EventEmitter {
|
|
1105
|
+
core;
|
|
1106
|
+
mask;
|
|
1107
|
+
container;
|
|
1108
|
+
targetList = [];
|
|
1109
|
+
dragElList = [];
|
|
1110
|
+
moveableForMulti;
|
|
1111
|
+
multiMoveableHelper;
|
|
1077
1112
|
constructor(config) {
|
|
1078
1113
|
super();
|
|
1079
|
-
this.targetList = [];
|
|
1080
|
-
this.dragElList = [];
|
|
1081
1114
|
this.core = config.core;
|
|
1082
1115
|
this.container = config.container;
|
|
1083
1116
|
this.mask = config.mask;
|
|
@@ -1098,10 +1131,10 @@
|
|
|
1098
1131
|
});
|
|
1099
1132
|
this.moveableForMulti?.destroy();
|
|
1100
1133
|
this.multiMoveableHelper?.clear();
|
|
1101
|
-
this.moveableForMulti = new Moveable__default
|
|
1134
|
+
this.moveableForMulti = new Moveable__default.default(this.container, this.getOptions({
|
|
1102
1135
|
target: this.dragElList
|
|
1103
1136
|
}));
|
|
1104
|
-
this.multiMoveableHelper = MoveableHelper__default
|
|
1137
|
+
this.multiMoveableHelper = MoveableHelper__default.default.create({
|
|
1105
1138
|
useBeforeRender: true,
|
|
1106
1139
|
useRender: false,
|
|
1107
1140
|
createAuto: true
|
|
@@ -1140,14 +1173,18 @@
|
|
|
1140
1173
|
this.update();
|
|
1141
1174
|
});
|
|
1142
1175
|
}
|
|
1143
|
-
canSelect(el) {
|
|
1176
|
+
canSelect(el, stop) {
|
|
1144
1177
|
if (el.className.includes(PAGE_CLASS)) {
|
|
1145
1178
|
this.core.highlightedDom = void 0;
|
|
1146
1179
|
this.core.highlightLayer.clearHighlight();
|
|
1180
|
+
stop();
|
|
1147
1181
|
return false;
|
|
1148
1182
|
}
|
|
1149
1183
|
const currentTargetMode = getMode(el);
|
|
1150
1184
|
let selectedDomMode = "";
|
|
1185
|
+
if (this.core.selectedDom?.className.includes(PAGE_CLASS)) {
|
|
1186
|
+
return true;
|
|
1187
|
+
}
|
|
1151
1188
|
if (this.targetList.length === 0 && this.core.selectedDom) {
|
|
1152
1189
|
selectedDomMode = getMode(this.core.selectedDom);
|
|
1153
1190
|
} else if (this.targetList.length > 0) {
|
|
@@ -1193,9 +1230,9 @@
|
|
|
1193
1230
|
});
|
|
1194
1231
|
}
|
|
1195
1232
|
getOptions(options = {}) {
|
|
1196
|
-
let {
|
|
1197
|
-
if (typeof
|
|
1198
|
-
|
|
1233
|
+
let { multiMoveableOptions = {} } = this.core.config;
|
|
1234
|
+
if (typeof multiMoveableOptions === "function") {
|
|
1235
|
+
multiMoveableOptions = multiMoveableOptions(this.core);
|
|
1199
1236
|
}
|
|
1200
1237
|
return {
|
|
1201
1238
|
defaultGroupRotate: 0,
|
|
@@ -1209,52 +1246,22 @@
|
|
|
1209
1246
|
origin: true,
|
|
1210
1247
|
padding: { left: 0, top: 0, right: 0, bottom: 0 },
|
|
1211
1248
|
...options,
|
|
1212
|
-
...
|
|
1249
|
+
...multiMoveableOptions
|
|
1213
1250
|
};
|
|
1214
1251
|
}
|
|
1215
1252
|
}
|
|
1216
1253
|
|
|
1217
|
-
|
|
1254
|
+
const style = ".tmagic-stage-container-highlight::after {\n content: '';\n position: absolute;\n width: 100%;\n height: 100%;\n top: 0;\n left: 0;\n background-color: #000;\n opacity: .1;\n pointer-events: none;\n}\n";
|
|
1218
1255
|
|
|
1219
1256
|
class StageRender extends EventEmitter.EventEmitter {
|
|
1257
|
+
contentWindow = null;
|
|
1258
|
+
runtime = null;
|
|
1259
|
+
iframe;
|
|
1260
|
+
runtimeUrl;
|
|
1261
|
+
core;
|
|
1262
|
+
render;
|
|
1220
1263
|
constructor({ core }) {
|
|
1221
1264
|
super();
|
|
1222
|
-
this.contentWindow = null;
|
|
1223
|
-
this.runtime = null;
|
|
1224
|
-
this.getMagicApi = () => ({
|
|
1225
|
-
onPageElUpdate: (el) => this.emit("page-el-update", el),
|
|
1226
|
-
onRuntimeReady: (runtime) => {
|
|
1227
|
-
this.runtime = runtime;
|
|
1228
|
-
globalThis.runtime = runtime;
|
|
1229
|
-
this.emit("runtime-ready", runtime);
|
|
1230
|
-
}
|
|
1231
|
-
});
|
|
1232
|
-
this.getRuntime = () => {
|
|
1233
|
-
if (this.runtime)
|
|
1234
|
-
return Promise.resolve(this.runtime);
|
|
1235
|
-
return new Promise((resolve) => {
|
|
1236
|
-
const listener = (runtime) => {
|
|
1237
|
-
this.off("runtime-ready", listener);
|
|
1238
|
-
resolve(runtime);
|
|
1239
|
-
};
|
|
1240
|
-
this.on("runtime-ready", listener);
|
|
1241
|
-
});
|
|
1242
|
-
};
|
|
1243
|
-
this.loadHandler = async () => {
|
|
1244
|
-
if (!this.contentWindow?.magic) {
|
|
1245
|
-
this.postTmagicRuntimeReady();
|
|
1246
|
-
}
|
|
1247
|
-
if (!this.contentWindow)
|
|
1248
|
-
return;
|
|
1249
|
-
if (this.render) {
|
|
1250
|
-
const el = await this.render(this.core);
|
|
1251
|
-
if (el) {
|
|
1252
|
-
this.contentWindow.document?.body?.appendChild(el);
|
|
1253
|
-
}
|
|
1254
|
-
}
|
|
1255
|
-
this.emit("onload");
|
|
1256
|
-
utils.injectStyle(this.contentWindow.document, style);
|
|
1257
|
-
};
|
|
1258
1265
|
this.core = core;
|
|
1259
1266
|
this.runtimeUrl = core.config.runtimeUrl || "";
|
|
1260
1267
|
this.render = core.config.render;
|
|
@@ -1267,6 +1274,14 @@
|
|
|
1267
1274
|
`;
|
|
1268
1275
|
this.iframe.addEventListener("load", this.loadHandler);
|
|
1269
1276
|
}
|
|
1277
|
+
getMagicApi = () => ({
|
|
1278
|
+
onPageElUpdate: (el) => this.emit("page-el-update", el),
|
|
1279
|
+
onRuntimeReady: (runtime) => {
|
|
1280
|
+
this.runtime = runtime;
|
|
1281
|
+
globalThis.runtime = runtime;
|
|
1282
|
+
this.emit("runtime-ready", runtime);
|
|
1283
|
+
}
|
|
1284
|
+
});
|
|
1270
1285
|
async mount(el) {
|
|
1271
1286
|
if (!this.iframe) {
|
|
1272
1287
|
throw Error("mount \u5931\u8D25");
|
|
@@ -1281,6 +1296,17 @@
|
|
|
1281
1296
|
el.appendChild(this.iframe);
|
|
1282
1297
|
this.postTmagicRuntimeReady();
|
|
1283
1298
|
}
|
|
1299
|
+
getRuntime = () => {
|
|
1300
|
+
if (this.runtime)
|
|
1301
|
+
return Promise.resolve(this.runtime);
|
|
1302
|
+
return new Promise((resolve) => {
|
|
1303
|
+
const listener = (runtime) => {
|
|
1304
|
+
this.off("runtime-ready", listener);
|
|
1305
|
+
resolve(runtime);
|
|
1306
|
+
};
|
|
1307
|
+
this.on("runtime-ready", listener);
|
|
1308
|
+
});
|
|
1309
|
+
};
|
|
1284
1310
|
destroy() {
|
|
1285
1311
|
this.iframe?.removeEventListener("load", this.loadHandler);
|
|
1286
1312
|
this.contentWindow = null;
|
|
@@ -1288,6 +1314,21 @@
|
|
|
1288
1314
|
this.iframe = void 0;
|
|
1289
1315
|
this.removeAllListeners();
|
|
1290
1316
|
}
|
|
1317
|
+
loadHandler = async () => {
|
|
1318
|
+
if (!this.contentWindow?.magic) {
|
|
1319
|
+
this.postTmagicRuntimeReady();
|
|
1320
|
+
}
|
|
1321
|
+
if (!this.contentWindow)
|
|
1322
|
+
return;
|
|
1323
|
+
if (this.render) {
|
|
1324
|
+
const el = await this.render(this.core);
|
|
1325
|
+
if (el) {
|
|
1326
|
+
this.contentWindow.document?.body?.appendChild(el);
|
|
1327
|
+
}
|
|
1328
|
+
}
|
|
1329
|
+
this.emit("onload");
|
|
1330
|
+
utils.injectStyle(this.contentWindow.document, style);
|
|
1331
|
+
};
|
|
1291
1332
|
postTmagicRuntimeReady() {
|
|
1292
1333
|
this.contentWindow = this.iframe?.contentWindow;
|
|
1293
1334
|
this.contentWindow.magic = this.getMagicApi();
|
|
@@ -1298,10 +1339,23 @@
|
|
|
1298
1339
|
}
|
|
1299
1340
|
|
|
1300
1341
|
class StageCore extends EventEmitter.EventEmitter {
|
|
1342
|
+
container;
|
|
1343
|
+
selectedDom;
|
|
1344
|
+
selectedDomList = [];
|
|
1345
|
+
highlightedDom;
|
|
1346
|
+
renderer;
|
|
1347
|
+
mask;
|
|
1348
|
+
dr;
|
|
1349
|
+
multiDr;
|
|
1350
|
+
highlightLayer;
|
|
1351
|
+
config;
|
|
1352
|
+
zoom = DEFAULT_ZOOM;
|
|
1353
|
+
containerHighlightClassName;
|
|
1354
|
+
containerHighlightDuration;
|
|
1355
|
+
isContainer;
|
|
1356
|
+
canSelect;
|
|
1301
1357
|
constructor(config) {
|
|
1302
1358
|
super();
|
|
1303
|
-
this.selectedDomList = [];
|
|
1304
|
-
this.zoom = DEFAULT_ZOOM;
|
|
1305
1359
|
this.config = config;
|
|
1306
1360
|
this.setZoom(config.zoom);
|
|
1307
1361
|
this.canSelect = config.canSelect || ((el) => !!el.id);
|
|
@@ -1346,7 +1400,6 @@
|
|
|
1346
1400
|
const el = await this.getElementFromPoint(event);
|
|
1347
1401
|
if (!el)
|
|
1348
1402
|
return;
|
|
1349
|
-
this.clearSelectStatus("select");
|
|
1350
1403
|
if (this.selectedDom && !this.selectedDom.className.includes(PAGE_CLASS)) {
|
|
1351
1404
|
this.selectedDomList.push(this.selectedDom);
|
|
1352
1405
|
this.selectedDom = void 0;
|
|
@@ -1357,8 +1410,7 @@
|
|
|
1357
1410
|
} else {
|
|
1358
1411
|
this.selectedDomList.push(el);
|
|
1359
1412
|
}
|
|
1360
|
-
this.
|
|
1361
|
-
this.emit("multiSelect", this.selectedDomList);
|
|
1413
|
+
this.multiSelect(this.selectedDomList);
|
|
1362
1414
|
});
|
|
1363
1415
|
this.dr.on("update", (data) => {
|
|
1364
1416
|
setTimeout(() => this.emit("update", data));
|
|
@@ -1400,7 +1452,7 @@
|
|
|
1400
1452
|
if (!canSelectByProp)
|
|
1401
1453
|
return false;
|
|
1402
1454
|
if (this.mask.isMultiSelectStatus) {
|
|
1403
|
-
return this.multiDr.canSelect(el);
|
|
1455
|
+
return this.multiDr.canSelect(el, stop);
|
|
1404
1456
|
}
|
|
1405
1457
|
return true;
|
|
1406
1458
|
}
|
|
@@ -1427,6 +1479,12 @@
|
|
|
1427
1479
|
}
|
|
1428
1480
|
}
|
|
1429
1481
|
}
|
|
1482
|
+
async multiSelect(idOrElList) {
|
|
1483
|
+
this.clearSelectStatus("select");
|
|
1484
|
+
const elList = await Promise.all(idOrElList.map(async (idOrEl) => await this.getTargetElement(idOrEl)));
|
|
1485
|
+
this.multiDr.multiSelect(elList);
|
|
1486
|
+
this.emit("multiSelect", elList);
|
|
1487
|
+
}
|
|
1430
1488
|
update(data) {
|
|
1431
1489
|
const { config } = data;
|
|
1432
1490
|
return this.renderer?.getRuntime().then((runtime) => {
|
|
@@ -1539,7 +1597,7 @@
|
|
|
1539
1597
|
exports.ZIndex = ZIndex;
|
|
1540
1598
|
exports.addSelectedClassName = addSelectedClassName;
|
|
1541
1599
|
exports.calcValueByFontsize = calcValueByFontsize;
|
|
1542
|
-
exports
|
|
1600
|
+
exports.default = StageCore;
|
|
1543
1601
|
exports.down = down;
|
|
1544
1602
|
exports.getAbsolutePosition = getAbsolutePosition;
|
|
1545
1603
|
exports.getMode = getMode;
|