@tmagic/stage 1.1.3 → 1.1.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.
@@ -22,6 +22,7 @@ var ZIndex = /* @__PURE__ */ ((ZIndex2) => {
22
22
  ZIndex2["SELECTED_EL"] = "666";
23
23
  ZIndex2["GHOST_EL"] = "700";
24
24
  ZIndex2["DRAG_EL"] = "9";
25
+ ZIndex2["HIGHLIGHT_EL"] = "8";
25
26
  return ZIndex2;
26
27
  })(ZIndex || {});
27
28
  var MouseButton = /* @__PURE__ */ ((MouseButton2) => {
@@ -171,7 +172,9 @@ const calcValueByFontsize = (doc, value) => {
171
172
  const down = (deltaTop, target) => {
172
173
  let swapIndex = 0;
173
174
  let addUpH = target.clientHeight;
174
- const brothers = Array.from(target.parentNode?.children || []).filter((node) => !node.id.startsWith(GHOST_EL_ID_PREFIX));
175
+ const brothers = Array.from(target.parentNode?.children || []).filter(
176
+ (node) => !node.id.startsWith(GHOST_EL_ID_PREFIX)
177
+ );
175
178
  const index = brothers.indexOf(target);
176
179
  const downEls = brothers.slice(index + 1);
177
180
  for (let i = 0; i < downEls.length; i++) {
@@ -192,7 +195,9 @@ const down = (deltaTop, target) => {
192
195
  };
193
196
  };
194
197
  const up = (deltaTop, target) => {
195
- const brothers = Array.from(target.parentNode?.children || []).filter((node) => !node.id.startsWith(GHOST_EL_ID_PREFIX));
198
+ const brothers = Array.from(target.parentNode?.children || []).filter(
199
+ (node) => !node.id.startsWith(GHOST_EL_ID_PREFIX)
200
+ );
196
201
  const index = brothers.indexOf(target);
197
202
  const upEls = brothers.slice(0, index);
198
203
  let addUpH = target.clientHeight;
@@ -252,6 +257,10 @@ class StageDragResize extends EventEmitter {
252
257
  select(el, event) {
253
258
  const oldTarget = this.target;
254
259
  this.target = el;
260
+ if (!this.dragEl) {
261
+ this.dragEl = globalThis.document.createElement("div");
262
+ this.container.append(this.dragEl);
263
+ }
255
264
  if (!this.moveable || this.target !== oldTarget) {
256
265
  this.init(el);
257
266
  this.moveableHelper = MoveableHelper.create({
@@ -302,6 +311,7 @@ class StageDragResize extends EventEmitter {
302
311
  if (!this.moveable)
303
312
  return;
304
313
  this.destroyDragEl();
314
+ this.dragEl = void 0;
305
315
  this.moveable.target = null;
306
316
  this.moveable.updateTarget();
307
317
  }
@@ -321,9 +331,9 @@ class StageDragResize extends EventEmitter {
321
331
  }
322
332
  this.mode = getMode(el);
323
333
  this.destroyGhostEl();
324
- this.destroyDragEl();
325
- this.dragEl = globalThis.document.createElement("div");
326
- this.container.append(this.dragEl);
334
+ if (!this.dragEl) {
335
+ return;
336
+ }
327
337
  this.dragEl.style.cssText = getTargetElStyle(el);
328
338
  this.dragEl.id = `${DRAG_EL_ID_PREFIX}${el.id}`;
329
339
  if (typeof this.core.config.updateDragEl === "function") {
@@ -680,7 +690,7 @@ class TargetCalibrate extends EventEmitter {
680
690
  top: ${top}px;
681
691
  width: ${el.clientWidth}px;
682
692
  height: ${el.clientHeight}px;
683
- z-index: ${ZIndex.DRAG_EL};
693
+ z-index: ${ZIndex.HIGHLIGHT_EL};
684
694
  `;
685
695
  this.operationEl.id = `${prefix}${el.id}`;
686
696
  if (typeof this.core.config.updateDragEl === "function") {
@@ -975,19 +985,22 @@ class StageMask extends Rule {
975
985
  this.wrapperResizeObserver?.disconnect();
976
986
  this.intersectionObserver?.disconnect();
977
987
  if (typeof IntersectionObserver !== "undefined") {
978
- this.intersectionObserver = new IntersectionObserver((entries) => {
979
- entries.forEach((entry) => {
980
- const { target, intersectionRatio } = entry;
981
- if (intersectionRatio <= 0) {
982
- this.scrollIntoView(target);
983
- }
984
- this.intersectionObserver?.unobserve(target);
985
- });
986
- }, {
987
- root: this.pageScrollParent,
988
- rootMargin: "0px",
989
- threshold: 1
990
- });
988
+ this.intersectionObserver = new IntersectionObserver(
989
+ (entries) => {
990
+ entries.forEach((entry) => {
991
+ const { target, intersectionRatio } = entry;
992
+ if (intersectionRatio <= 0) {
993
+ this.scrollIntoView(target);
994
+ }
995
+ this.intersectionObserver?.unobserve(target);
996
+ });
997
+ },
998
+ {
999
+ root: this.pageScrollParent,
1000
+ rootMargin: "0px",
1001
+ threshold: 1
1002
+ }
1003
+ );
991
1004
  }
992
1005
  if (typeof ResizeObserver !== "undefined") {
993
1006
  this.pageResizeObserver = new ResizeObserver((entries) => {
@@ -1163,9 +1176,12 @@ class StageMultiDragResize extends EventEmitter {
1163
1176
  });
1164
1177
  this.moveableForMulti?.destroy();
1165
1178
  this.multiMoveableHelper?.clear();
1166
- this.moveableForMulti = new Moveable(this.container, this.getOptions({
1167
- target: this.dragElList
1168
- }));
1179
+ this.moveableForMulti = new Moveable(
1180
+ this.container,
1181
+ this.getOptions({
1182
+ target: this.dragElList
1183
+ })
1184
+ );
1169
1185
  this.multiMoveableHelper = MoveableHelper.create({
1170
1186
  useBeforeRender: true,
1171
1187
  useRender: false,
@@ -1174,7 +1190,9 @@ class StageMultiDragResize extends EventEmitter {
1174
1190
  const frames = [];
1175
1191
  const setFrames = (events) => {
1176
1192
  events.forEach((ev) => {
1177
- const matchEventTarget = this.targetList.find((targetItem) => targetItem.id === ev.target.id.replace(DRAG_EL_ID_PREFIX, ""));
1193
+ const matchEventTarget = this.targetList.find(
1194
+ (targetItem) => targetItem.id === ev.target.id.replace(DRAG_EL_ID_PREFIX, "")
1195
+ );
1178
1196
  if (!matchEventTarget)
1179
1197
  return;
1180
1198
  frames.push({
@@ -1193,10 +1211,14 @@ class StageMultiDragResize extends EventEmitter {
1193
1211
  const { events } = params;
1194
1212
  events.forEach((ev) => {
1195
1213
  const { width, height, beforeTranslate } = ev.drag;
1196
- const frameSnapShot = frames.find((frameItem) => frameItem.id === ev.target.id.replace(DRAG_EL_ID_PREFIX, ""));
1214
+ const frameSnapShot = frames.find(
1215
+ (frameItem) => frameItem.id === ev.target.id.replace(DRAG_EL_ID_PREFIX, "")
1216
+ );
1197
1217
  if (!frameSnapShot)
1198
1218
  return;
1199
- const targeEl = this.targetList.find((targetItem) => targetItem.id === ev.target.id.replace(DRAG_EL_ID_PREFIX, ""));
1219
+ const targeEl = this.targetList.find(
1220
+ (targetItem) => targetItem.id === ev.target.id.replace(DRAG_EL_ID_PREFIX, "")
1221
+ );
1200
1222
  if (!targeEl)
1201
1223
  return;
1202
1224
  const isParentIncluded = this.targetList.find((targetItem) => targetItem.id === targeEl.parentElement?.id);
@@ -1220,10 +1242,14 @@ class StageMultiDragResize extends EventEmitter {
1220
1242
  }).on("dragGroup", (params) => {
1221
1243
  const { events } = params;
1222
1244
  events.forEach((ev) => {
1223
- const frameSnapShot = frames.find((frameItem) => frameItem.id === ev.target.id.replace(DRAG_EL_ID_PREFIX, ""));
1245
+ const frameSnapShot = frames.find(
1246
+ (frameItem) => frameItem.id === ev.target.id.replace(DRAG_EL_ID_PREFIX, "")
1247
+ );
1224
1248
  if (!frameSnapShot)
1225
1249
  return;
1226
- const targeEl = this.targetList.find((targetItem) => targetItem.id === ev.target.id.replace(DRAG_EL_ID_PREFIX, ""));
1250
+ const targeEl = this.targetList.find(
1251
+ (targetItem) => targetItem.id === ev.target.id.replace(DRAG_EL_ID_PREFIX, "")
1252
+ );
1227
1253
  if (!targeEl)
1228
1254
  return;
1229
1255
  const isParentIncluded = this.targetList.find((targetItem) => targetItem.id === targeEl.parentElement?.id);
@@ -1414,9 +1440,12 @@ class StageRender extends EventEmitter {
1414
1440
  postTmagicRuntimeReady() {
1415
1441
  this.contentWindow = this.iframe?.contentWindow;
1416
1442
  this.contentWindow.magic = this.getMagicApi();
1417
- this.contentWindow.postMessage({
1418
- tmagicRuntimeReady: true
1419
- }, "*");
1443
+ this.contentWindow.postMessage(
1444
+ {
1445
+ tmagicRuntimeReady: true
1446
+ },
1447
+ "*"
1448
+ );
1420
1449
  }
1421
1450
  }
1422
1451