@tmagic/stage 1.1.0-beta.4 → 1.1.0-beta.5
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 +87 -46
- package/dist/tmagic-stage.es.js.map +1 -1
- package/dist/tmagic-stage.umd.js +87 -46
- package/dist/tmagic-stage.umd.js.map +1 -1
- package/dist/types/src/StageCore.d.ts +2 -1
- package/dist/types/src/StageMask.d.ts +1 -1
- package/dist/types/src/StageMultiDragResize.d.ts +7 -0
- package/dist/types/src/StageRender.d.ts +1 -0
- package/package.json +4 -4
- package/src/StageCore.ts +15 -9
- package/src/StageHighlight.ts +1 -1
- package/src/StageMask.ts +7 -7
- package/src/StageMultiDragResize.ts +61 -15
- package/src/StageRender.ts +28 -18
- package/src/TargetCalibrate.ts +2 -1
- package/src/style.css +1 -0
package/dist/tmagic-stage.es.js
CHANGED
|
@@ -630,6 +630,7 @@ class TargetCalibrate extends EventEmitter {
|
|
|
630
630
|
top: ${top}px;
|
|
631
631
|
width: ${el.clientWidth}px;
|
|
632
632
|
height: ${el.clientHeight}px;
|
|
633
|
+
z-index: ${ZIndex.DRAG_EL};
|
|
633
634
|
`;
|
|
634
635
|
this.operationEl.id = `${prefix}${el.id}`;
|
|
635
636
|
if (typeof this.core.config.updateDragEl === "function") {
|
|
@@ -697,7 +698,7 @@ class StageHighlight extends EventEmitter {
|
|
|
697
698
|
target: this.calibrationTarget.update(el, HIGHLIGHT_EL_ID_PREFIX),
|
|
698
699
|
origin: false,
|
|
699
700
|
rootContainer: this.core.container,
|
|
700
|
-
zoom:
|
|
701
|
+
zoom: 2
|
|
701
702
|
});
|
|
702
703
|
}
|
|
703
704
|
clearHighlight() {
|
|
@@ -868,7 +869,7 @@ class StageMask extends Rule {
|
|
|
868
869
|
this.maxScrollTop = 0;
|
|
869
870
|
this.maxScrollLeft = 0;
|
|
870
871
|
this.intersectionObserver = null;
|
|
871
|
-
this.
|
|
872
|
+
this.isMultiSelectStatus = false;
|
|
872
873
|
this.mode = Mode.ABSOLUTE;
|
|
873
874
|
this.pageResizeObserver = null;
|
|
874
875
|
this.wrapperResizeObserver = null;
|
|
@@ -881,19 +882,19 @@ class StageMask extends Rule {
|
|
|
881
882
|
event.stopPropagation();
|
|
882
883
|
if (event.button !== MouseButton.LEFT && event.button !== MouseButton.RIGHT)
|
|
883
884
|
return;
|
|
884
|
-
if (!this.
|
|
885
|
+
if (!this.isMultiSelectStatus && event.target.className.indexOf("moveable-area") !== -1) {
|
|
885
886
|
return;
|
|
886
887
|
}
|
|
887
888
|
if (event.target.className.indexOf("moveable-control") !== -1) {
|
|
888
889
|
return;
|
|
889
890
|
}
|
|
890
891
|
this.content.removeEventListener("mousemove", this.highlightHandler);
|
|
891
|
-
if (this.
|
|
892
|
+
if (this.isMultiSelectStatus) {
|
|
892
893
|
this.emit("beforeMultiSelect", event);
|
|
893
894
|
} else {
|
|
894
895
|
this.emit("beforeSelect", event);
|
|
895
|
-
globalThis.document.addEventListener("mouseup", this.mouseUpHandler);
|
|
896
896
|
}
|
|
897
|
+
globalThis.document.addEventListener("mouseup", this.mouseUpHandler);
|
|
897
898
|
};
|
|
898
899
|
this.mouseUpHandler = () => {
|
|
899
900
|
globalThis.document.removeEventListener("mouseup", this.mouseUpHandler);
|
|
@@ -930,11 +931,11 @@ class StageMask extends Rule {
|
|
|
930
931
|
this.content.addEventListener("mouseleave", this.mouseLeaveHandler);
|
|
931
932
|
KeyController.global.keydown("shift", (e) => {
|
|
932
933
|
e.inputEvent.preventDefault();
|
|
933
|
-
this.
|
|
934
|
+
this.isMultiSelectStatus = true;
|
|
934
935
|
});
|
|
935
936
|
KeyController.global.keyup("shift", (e) => {
|
|
936
937
|
e.inputEvent.preventDefault();
|
|
937
|
-
this.
|
|
938
|
+
this.isMultiSelectStatus = false;
|
|
938
939
|
});
|
|
939
940
|
}
|
|
940
941
|
setMode(mode) {
|
|
@@ -1091,19 +1092,9 @@ class StageMultiDragResize extends EventEmitter {
|
|
|
1091
1092
|
});
|
|
1092
1093
|
this.moveableForMulti?.destroy();
|
|
1093
1094
|
this.multiMoveableHelper?.clear();
|
|
1094
|
-
this.moveableForMulti = new Moveable(this.container, {
|
|
1095
|
-
target: this.dragElList
|
|
1096
|
-
|
|
1097
|
-
defaultGroupOrigin: "50% 50%",
|
|
1098
|
-
draggable: true,
|
|
1099
|
-
resizable: true,
|
|
1100
|
-
throttleDrag: 0,
|
|
1101
|
-
startDragRotate: 0,
|
|
1102
|
-
throttleDragRotate: 0,
|
|
1103
|
-
zoom: 1,
|
|
1104
|
-
origin: true,
|
|
1105
|
-
padding: { left: 0, top: 0, right: 0, bottom: 0 }
|
|
1106
|
-
});
|
|
1095
|
+
this.moveableForMulti = new Moveable(this.container, this.getOptions({
|
|
1096
|
+
target: this.dragElList
|
|
1097
|
+
}));
|
|
1107
1098
|
this.multiMoveableHelper = MoveableHelper.create({
|
|
1108
1099
|
useBeforeRender: true,
|
|
1109
1100
|
useRender: false,
|
|
@@ -1143,12 +1134,31 @@ class StageMultiDragResize extends EventEmitter {
|
|
|
1143
1134
|
this.update();
|
|
1144
1135
|
});
|
|
1145
1136
|
}
|
|
1137
|
+
canSelect(el) {
|
|
1138
|
+
if (el.className.includes(PAGE_CLASS)) {
|
|
1139
|
+
this.core.highlightedDom = void 0;
|
|
1140
|
+
this.core.highlightLayer.clearHighlight();
|
|
1141
|
+
return false;
|
|
1142
|
+
}
|
|
1143
|
+
const currentTargetMode = getMode(el);
|
|
1144
|
+
let selectedDomMode = "";
|
|
1145
|
+
if (this.targetList.length === 0 && this.core.selectedDom) {
|
|
1146
|
+
selectedDomMode = getMode(this.core.selectedDom);
|
|
1147
|
+
} else if (this.targetList.length > 0) {
|
|
1148
|
+
selectedDomMode = getMode(this.targetList[0]);
|
|
1149
|
+
}
|
|
1150
|
+
if (currentTargetMode !== selectedDomMode) {
|
|
1151
|
+
return false;
|
|
1152
|
+
}
|
|
1153
|
+
return true;
|
|
1154
|
+
}
|
|
1146
1155
|
clearSelectStatus() {
|
|
1147
1156
|
if (!this.moveableForMulti)
|
|
1148
1157
|
return;
|
|
1149
1158
|
this.destroyDragElList();
|
|
1150
1159
|
this.moveableForMulti.target = null;
|
|
1151
1160
|
this.moveableForMulti.updateTarget();
|
|
1161
|
+
this.targetList = [];
|
|
1152
1162
|
}
|
|
1153
1163
|
destroy() {
|
|
1154
1164
|
this.moveableForMulti?.destroy();
|
|
@@ -1176,9 +1186,29 @@ class StageMultiDragResize extends EventEmitter {
|
|
|
1176
1186
|
});
|
|
1177
1187
|
});
|
|
1178
1188
|
}
|
|
1189
|
+
getOptions(options = {}) {
|
|
1190
|
+
let { moveableOptions = {} } = this.core.config;
|
|
1191
|
+
if (typeof moveableOptions === "function") {
|
|
1192
|
+
moveableOptions = moveableOptions(this.core);
|
|
1193
|
+
}
|
|
1194
|
+
return {
|
|
1195
|
+
defaultGroupRotate: 0,
|
|
1196
|
+
defaultGroupOrigin: "50% 50%",
|
|
1197
|
+
draggable: true,
|
|
1198
|
+
resizable: true,
|
|
1199
|
+
throttleDrag: 0,
|
|
1200
|
+
startDragRotate: 0,
|
|
1201
|
+
throttleDragRotate: 0,
|
|
1202
|
+
zoom: 1,
|
|
1203
|
+
origin: true,
|
|
1204
|
+
padding: { left: 0, top: 0, right: 0, bottom: 0 },
|
|
1205
|
+
...options,
|
|
1206
|
+
...moveableOptions
|
|
1207
|
+
};
|
|
1208
|
+
}
|
|
1179
1209
|
}
|
|
1180
1210
|
|
|
1181
|
-
var 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}\n";
|
|
1211
|
+
var 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";
|
|
1182
1212
|
|
|
1183
1213
|
class StageRender extends EventEmitter {
|
|
1184
1214
|
constructor({ core }) {
|
|
@@ -1205,18 +1235,18 @@ class StageRender extends EventEmitter {
|
|
|
1205
1235
|
});
|
|
1206
1236
|
};
|
|
1207
1237
|
this.loadHandler = async () => {
|
|
1208
|
-
this.contentWindow
|
|
1209
|
-
|
|
1238
|
+
if (!this.contentWindow?.magic) {
|
|
1239
|
+
this.postTmagicRuntimeReady();
|
|
1240
|
+
}
|
|
1241
|
+
if (!this.contentWindow)
|
|
1242
|
+
return;
|
|
1210
1243
|
if (this.render) {
|
|
1211
1244
|
const el = await this.render(this.core);
|
|
1212
1245
|
if (el) {
|
|
1213
|
-
this.
|
|
1246
|
+
this.contentWindow.document?.body?.appendChild(el);
|
|
1214
1247
|
}
|
|
1215
1248
|
}
|
|
1216
1249
|
this.emit("onload");
|
|
1217
|
-
this.contentWindow.postMessage({
|
|
1218
|
-
tmagicRuntimeReady: true
|
|
1219
|
-
}, "*");
|
|
1220
1250
|
injectStyle(this.contentWindow.document, style);
|
|
1221
1251
|
};
|
|
1222
1252
|
this.core = core;
|
|
@@ -1232,18 +1262,18 @@ class StageRender extends EventEmitter {
|
|
|
1232
1262
|
this.iframe.addEventListener("load", this.loadHandler);
|
|
1233
1263
|
}
|
|
1234
1264
|
async mount(el) {
|
|
1235
|
-
if (this.iframe) {
|
|
1236
|
-
if (!isSameDomain(this.runtimeUrl) && this.runtimeUrl) {
|
|
1237
|
-
let html = await fetch(this.runtimeUrl).then((res) => res.text());
|
|
1238
|
-
const base = `${location.protocol}//${getHost(this.runtimeUrl)}`;
|
|
1239
|
-
html = html.replace("<head>", `<head>
|
|
1240
|
-
<base href="${base}">`);
|
|
1241
|
-
this.iframe.srcdoc = html;
|
|
1242
|
-
}
|
|
1243
|
-
el.appendChild(this.iframe);
|
|
1244
|
-
} else {
|
|
1265
|
+
if (!this.iframe) {
|
|
1245
1266
|
throw Error("mount \u5931\u8D25");
|
|
1246
1267
|
}
|
|
1268
|
+
if (!isSameDomain(this.runtimeUrl) && this.runtimeUrl) {
|
|
1269
|
+
let html = await fetch(this.runtimeUrl).then((res) => res.text());
|
|
1270
|
+
const base = `${location.protocol}//${getHost(this.runtimeUrl)}`;
|
|
1271
|
+
html = html.replace("<head>", `<head>
|
|
1272
|
+
<base href="${base}">`);
|
|
1273
|
+
this.iframe.srcdoc = html;
|
|
1274
|
+
}
|
|
1275
|
+
el.appendChild(this.iframe);
|
|
1276
|
+
this.postTmagicRuntimeReady();
|
|
1247
1277
|
}
|
|
1248
1278
|
destroy() {
|
|
1249
1279
|
this.iframe?.removeEventListener("load", this.loadHandler);
|
|
@@ -1252,6 +1282,13 @@ class StageRender extends EventEmitter {
|
|
|
1252
1282
|
this.iframe = void 0;
|
|
1253
1283
|
this.removeAllListeners();
|
|
1254
1284
|
}
|
|
1285
|
+
postTmagicRuntimeReady() {
|
|
1286
|
+
this.contentWindow = this.iframe?.contentWindow;
|
|
1287
|
+
this.contentWindow.magic = this.getMagicApi();
|
|
1288
|
+
this.contentWindow.postMessage({
|
|
1289
|
+
tmagicRuntimeReady: true
|
|
1290
|
+
}, "*");
|
|
1291
|
+
}
|
|
1255
1292
|
}
|
|
1256
1293
|
|
|
1257
1294
|
class StageCore extends EventEmitter {
|
|
@@ -1288,7 +1325,7 @@ class StageCore extends EventEmitter {
|
|
|
1288
1325
|
this.dr.setGuidelines(data.type, data.guides);
|
|
1289
1326
|
this.emit("changeGuides", data);
|
|
1290
1327
|
}).on("highlight", async (event) => {
|
|
1291
|
-
const el = await this.getElementFromPoint(event
|
|
1328
|
+
const el = await this.getElementFromPoint(event);
|
|
1292
1329
|
if (!el)
|
|
1293
1330
|
return;
|
|
1294
1331
|
await this.highlight(el);
|
|
@@ -1303,8 +1340,6 @@ class StageCore extends EventEmitter {
|
|
|
1303
1340
|
const el = await this.getElementFromPoint(event);
|
|
1304
1341
|
if (!el)
|
|
1305
1342
|
return;
|
|
1306
|
-
if (el.className.includes(PAGE_CLASS))
|
|
1307
|
-
return;
|
|
1308
1343
|
this.clearSelectStatus("select");
|
|
1309
1344
|
if (this.selectedDom && !this.selectedDom.className.includes(PAGE_CLASS)) {
|
|
1310
1345
|
this.selectedDomList.push(this.selectedDom);
|
|
@@ -1342,22 +1377,29 @@ class StageCore extends EventEmitter {
|
|
|
1342
1377
|
}
|
|
1343
1378
|
return doc?.elementsFromPoint(x / zoom, y / zoom);
|
|
1344
1379
|
}
|
|
1345
|
-
async getElementFromPoint(event
|
|
1380
|
+
async getElementFromPoint(event) {
|
|
1346
1381
|
const els = this.getElementsFromPoint(event);
|
|
1347
1382
|
let stopped = false;
|
|
1348
1383
|
const stop = () => stopped = true;
|
|
1349
1384
|
for (const el of els) {
|
|
1350
|
-
if (!el.id.startsWith(GHOST_EL_ID_PREFIX) && await this.
|
|
1385
|
+
if (!el.id.startsWith(GHOST_EL_ID_PREFIX) && await this.isElCanSelect(el, event, stop)) {
|
|
1351
1386
|
if (stopped)
|
|
1352
1387
|
break;
|
|
1353
|
-
if (event.type === type) {
|
|
1354
|
-
return el;
|
|
1355
|
-
}
|
|
1356
1388
|
return el;
|
|
1357
1389
|
}
|
|
1358
1390
|
}
|
|
1359
1391
|
}
|
|
1392
|
+
async isElCanSelect(el, event, stop) {
|
|
1393
|
+
const canSelectByProp = await this.canSelect(el, event, stop);
|
|
1394
|
+
if (!canSelectByProp)
|
|
1395
|
+
return false;
|
|
1396
|
+
if (this.mask.isMultiSelectStatus) {
|
|
1397
|
+
return this.multiDr.canSelect(el);
|
|
1398
|
+
}
|
|
1399
|
+
return true;
|
|
1400
|
+
}
|
|
1360
1401
|
async select(idOrEl, event) {
|
|
1402
|
+
this.clearSelectStatus("multiSelect");
|
|
1361
1403
|
const el = await this.getTargetElement(idOrEl);
|
|
1362
1404
|
if (el === this.selectedDom)
|
|
1363
1405
|
return;
|
|
@@ -1367,7 +1409,6 @@ class StageCore extends EventEmitter {
|
|
|
1367
1409
|
await runtime.beforeSelect(el);
|
|
1368
1410
|
}
|
|
1369
1411
|
this.mask.setLayout(el);
|
|
1370
|
-
this.multiDr.destroyDragElList();
|
|
1371
1412
|
this.dr.select(el, event);
|
|
1372
1413
|
if (this.config.autoScrollIntoView || el.dataset.autoScrollIntoView) {
|
|
1373
1414
|
this.mask.intersectionObserver?.observe(el);
|