@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.
@@ -636,6 +636,7 @@
636
636
  top: ${top}px;
637
637
  width: ${el.clientWidth}px;
638
638
  height: ${el.clientHeight}px;
639
+ z-index: ${ZIndex.DRAG_EL};
639
640
  `;
640
641
  this.operationEl.id = `${prefix}${el.id}`;
641
642
  if (typeof this.core.config.updateDragEl === "function") {
@@ -703,7 +704,7 @@
703
704
  target: this.calibrationTarget.update(el, HIGHLIGHT_EL_ID_PREFIX),
704
705
  origin: false,
705
706
  rootContainer: this.core.container,
706
- zoom: 1
707
+ zoom: 2
707
708
  });
708
709
  }
709
710
  clearHighlight() {
@@ -874,7 +875,7 @@
874
875
  this.maxScrollTop = 0;
875
876
  this.maxScrollLeft = 0;
876
877
  this.intersectionObserver = null;
877
- this.shiftKeyDown = false;
878
+ this.isMultiSelectStatus = false;
878
879
  this.mode = Mode.ABSOLUTE;
879
880
  this.pageResizeObserver = null;
880
881
  this.wrapperResizeObserver = null;
@@ -887,19 +888,19 @@
887
888
  event.stopPropagation();
888
889
  if (event.button !== MouseButton.LEFT && event.button !== MouseButton.RIGHT)
889
890
  return;
890
- if (!this.shiftKeyDown && event.target.className.indexOf("moveable-area") !== -1) {
891
+ if (!this.isMultiSelectStatus && event.target.className.indexOf("moveable-area") !== -1) {
891
892
  return;
892
893
  }
893
894
  if (event.target.className.indexOf("moveable-control") !== -1) {
894
895
  return;
895
896
  }
896
897
  this.content.removeEventListener("mousemove", this.highlightHandler);
897
- if (this.shiftKeyDown) {
898
+ if (this.isMultiSelectStatus) {
898
899
  this.emit("beforeMultiSelect", event);
899
900
  } else {
900
901
  this.emit("beforeSelect", event);
901
- globalThis.document.addEventListener("mouseup", this.mouseUpHandler);
902
902
  }
903
+ globalThis.document.addEventListener("mouseup", this.mouseUpHandler);
903
904
  };
904
905
  this.mouseUpHandler = () => {
905
906
  globalThis.document.removeEventListener("mouseup", this.mouseUpHandler);
@@ -936,11 +937,11 @@
936
937
  this.content.addEventListener("mouseleave", this.mouseLeaveHandler);
937
938
  KeyController__default["default"].global.keydown("shift", (e) => {
938
939
  e.inputEvent.preventDefault();
939
- this.shiftKeyDown = true;
940
+ this.isMultiSelectStatus = true;
940
941
  });
941
942
  KeyController__default["default"].global.keyup("shift", (e) => {
942
943
  e.inputEvent.preventDefault();
943
- this.shiftKeyDown = false;
944
+ this.isMultiSelectStatus = false;
944
945
  });
945
946
  }
946
947
  setMode(mode) {
@@ -1097,19 +1098,9 @@
1097
1098
  });
1098
1099
  this.moveableForMulti?.destroy();
1099
1100
  this.multiMoveableHelper?.clear();
1100
- this.moveableForMulti = new Moveable__default["default"](this.container, {
1101
- target: this.dragElList,
1102
- defaultGroupRotate: 0,
1103
- defaultGroupOrigin: "50% 50%",
1104
- draggable: true,
1105
- resizable: true,
1106
- throttleDrag: 0,
1107
- startDragRotate: 0,
1108
- throttleDragRotate: 0,
1109
- zoom: 1,
1110
- origin: true,
1111
- padding: { left: 0, top: 0, right: 0, bottom: 0 }
1112
- });
1101
+ this.moveableForMulti = new Moveable__default["default"](this.container, this.getOptions({
1102
+ target: this.dragElList
1103
+ }));
1113
1104
  this.multiMoveableHelper = MoveableHelper__default["default"].create({
1114
1105
  useBeforeRender: true,
1115
1106
  useRender: false,
@@ -1149,12 +1140,31 @@
1149
1140
  this.update();
1150
1141
  });
1151
1142
  }
1143
+ canSelect(el) {
1144
+ if (el.className.includes(PAGE_CLASS)) {
1145
+ this.core.highlightedDom = void 0;
1146
+ this.core.highlightLayer.clearHighlight();
1147
+ return false;
1148
+ }
1149
+ const currentTargetMode = getMode(el);
1150
+ let selectedDomMode = "";
1151
+ if (this.targetList.length === 0 && this.core.selectedDom) {
1152
+ selectedDomMode = getMode(this.core.selectedDom);
1153
+ } else if (this.targetList.length > 0) {
1154
+ selectedDomMode = getMode(this.targetList[0]);
1155
+ }
1156
+ if (currentTargetMode !== selectedDomMode) {
1157
+ return false;
1158
+ }
1159
+ return true;
1160
+ }
1152
1161
  clearSelectStatus() {
1153
1162
  if (!this.moveableForMulti)
1154
1163
  return;
1155
1164
  this.destroyDragElList();
1156
1165
  this.moveableForMulti.target = null;
1157
1166
  this.moveableForMulti.updateTarget();
1167
+ this.targetList = [];
1158
1168
  }
1159
1169
  destroy() {
1160
1170
  this.moveableForMulti?.destroy();
@@ -1182,9 +1192,29 @@
1182
1192
  });
1183
1193
  });
1184
1194
  }
1195
+ getOptions(options = {}) {
1196
+ let { moveableOptions = {} } = this.core.config;
1197
+ if (typeof moveableOptions === "function") {
1198
+ moveableOptions = moveableOptions(this.core);
1199
+ }
1200
+ return {
1201
+ defaultGroupRotate: 0,
1202
+ defaultGroupOrigin: "50% 50%",
1203
+ draggable: true,
1204
+ resizable: true,
1205
+ throttleDrag: 0,
1206
+ startDragRotate: 0,
1207
+ throttleDragRotate: 0,
1208
+ zoom: 1,
1209
+ origin: true,
1210
+ padding: { left: 0, top: 0, right: 0, bottom: 0 },
1211
+ ...options,
1212
+ ...moveableOptions
1213
+ };
1214
+ }
1185
1215
  }
1186
1216
 
1187
- 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";
1217
+ 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";
1188
1218
 
1189
1219
  class StageRender extends EventEmitter.EventEmitter {
1190
1220
  constructor({ core }) {
@@ -1211,18 +1241,18 @@
1211
1241
  });
1212
1242
  };
1213
1243
  this.loadHandler = async () => {
1214
- this.contentWindow = this.iframe?.contentWindow;
1215
- this.contentWindow.magic = this.getMagicApi();
1244
+ if (!this.contentWindow?.magic) {
1245
+ this.postTmagicRuntimeReady();
1246
+ }
1247
+ if (!this.contentWindow)
1248
+ return;
1216
1249
  if (this.render) {
1217
1250
  const el = await this.render(this.core);
1218
1251
  if (el) {
1219
- this.iframe?.contentDocument?.body?.appendChild(el);
1252
+ this.contentWindow.document?.body?.appendChild(el);
1220
1253
  }
1221
1254
  }
1222
1255
  this.emit("onload");
1223
- this.contentWindow.postMessage({
1224
- tmagicRuntimeReady: true
1225
- }, "*");
1226
1256
  utils.injectStyle(this.contentWindow.document, style);
1227
1257
  };
1228
1258
  this.core = core;
@@ -1238,18 +1268,18 @@
1238
1268
  this.iframe.addEventListener("load", this.loadHandler);
1239
1269
  }
1240
1270
  async mount(el) {
1241
- if (this.iframe) {
1242
- if (!utils.isSameDomain(this.runtimeUrl) && this.runtimeUrl) {
1243
- let html = await fetch(this.runtimeUrl).then((res) => res.text());
1244
- const base = `${location.protocol}//${utils.getHost(this.runtimeUrl)}`;
1245
- html = html.replace("<head>", `<head>
1246
- <base href="${base}">`);
1247
- this.iframe.srcdoc = html;
1248
- }
1249
- el.appendChild(this.iframe);
1250
- } else {
1271
+ if (!this.iframe) {
1251
1272
  throw Error("mount \u5931\u8D25");
1252
1273
  }
1274
+ if (!utils.isSameDomain(this.runtimeUrl) && this.runtimeUrl) {
1275
+ let html = await fetch(this.runtimeUrl).then((res) => res.text());
1276
+ const base = `${location.protocol}//${utils.getHost(this.runtimeUrl)}`;
1277
+ html = html.replace("<head>", `<head>
1278
+ <base href="${base}">`);
1279
+ this.iframe.srcdoc = html;
1280
+ }
1281
+ el.appendChild(this.iframe);
1282
+ this.postTmagicRuntimeReady();
1253
1283
  }
1254
1284
  destroy() {
1255
1285
  this.iframe?.removeEventListener("load", this.loadHandler);
@@ -1258,6 +1288,13 @@
1258
1288
  this.iframe = void 0;
1259
1289
  this.removeAllListeners();
1260
1290
  }
1291
+ postTmagicRuntimeReady() {
1292
+ this.contentWindow = this.iframe?.contentWindow;
1293
+ this.contentWindow.magic = this.getMagicApi();
1294
+ this.contentWindow.postMessage({
1295
+ tmagicRuntimeReady: true
1296
+ }, "*");
1297
+ }
1261
1298
  }
1262
1299
 
1263
1300
  class StageCore extends EventEmitter.EventEmitter {
@@ -1294,7 +1331,7 @@
1294
1331
  this.dr.setGuidelines(data.type, data.guides);
1295
1332
  this.emit("changeGuides", data);
1296
1333
  }).on("highlight", async (event) => {
1297
- const el = await this.getElementFromPoint(event, "mousemove");
1334
+ const el = await this.getElementFromPoint(event);
1298
1335
  if (!el)
1299
1336
  return;
1300
1337
  await this.highlight(el);
@@ -1309,8 +1346,6 @@
1309
1346
  const el = await this.getElementFromPoint(event);
1310
1347
  if (!el)
1311
1348
  return;
1312
- if (el.className.includes(PAGE_CLASS))
1313
- return;
1314
1349
  this.clearSelectStatus("select");
1315
1350
  if (this.selectedDom && !this.selectedDom.className.includes(PAGE_CLASS)) {
1316
1351
  this.selectedDomList.push(this.selectedDom);
@@ -1348,22 +1383,29 @@
1348
1383
  }
1349
1384
  return doc?.elementsFromPoint(x / zoom, y / zoom);
1350
1385
  }
1351
- async getElementFromPoint(event, type) {
1386
+ async getElementFromPoint(event) {
1352
1387
  const els = this.getElementsFromPoint(event);
1353
1388
  let stopped = false;
1354
1389
  const stop = () => stopped = true;
1355
1390
  for (const el of els) {
1356
- if (!el.id.startsWith(GHOST_EL_ID_PREFIX) && await this.canSelect(el, event, stop)) {
1391
+ if (!el.id.startsWith(GHOST_EL_ID_PREFIX) && await this.isElCanSelect(el, event, stop)) {
1357
1392
  if (stopped)
1358
1393
  break;
1359
- if (event.type === type) {
1360
- return el;
1361
- }
1362
1394
  return el;
1363
1395
  }
1364
1396
  }
1365
1397
  }
1398
+ async isElCanSelect(el, event, stop) {
1399
+ const canSelectByProp = await this.canSelect(el, event, stop);
1400
+ if (!canSelectByProp)
1401
+ return false;
1402
+ if (this.mask.isMultiSelectStatus) {
1403
+ return this.multiDr.canSelect(el);
1404
+ }
1405
+ return true;
1406
+ }
1366
1407
  async select(idOrEl, event) {
1408
+ this.clearSelectStatus("multiSelect");
1367
1409
  const el = await this.getTargetElement(idOrEl);
1368
1410
  if (el === this.selectedDom)
1369
1411
  return;
@@ -1373,7 +1415,6 @@
1373
1415
  await runtime.beforeSelect(el);
1374
1416
  }
1375
1417
  this.mask.setLayout(el);
1376
- this.multiDr.destroyDragElList();
1377
1418
  this.dr.select(el, event);
1378
1419
  if (this.config.autoScrollIntoView || el.dataset.autoScrollIntoView) {
1379
1420
  this.mask.intersectionObserver?.observe(el);