@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.
@@ -28,6 +28,7 @@
28
28
  ZIndex2["SELECTED_EL"] = "666";
29
29
  ZIndex2["GHOST_EL"] = "700";
30
30
  ZIndex2["DRAG_EL"] = "9";
31
+ ZIndex2["HIGHLIGHT_EL"] = "8";
31
32
  return ZIndex2;
32
33
  })(ZIndex || {});
33
34
  var MouseButton = /* @__PURE__ */ ((MouseButton2) => {
@@ -177,7 +178,9 @@
177
178
  const down = (deltaTop, target) => {
178
179
  let swapIndex = 0;
179
180
  let addUpH = target.clientHeight;
180
- const brothers = Array.from(target.parentNode?.children || []).filter((node) => !node.id.startsWith(GHOST_EL_ID_PREFIX));
181
+ const brothers = Array.from(target.parentNode?.children || []).filter(
182
+ (node) => !node.id.startsWith(GHOST_EL_ID_PREFIX)
183
+ );
181
184
  const index = brothers.indexOf(target);
182
185
  const downEls = brothers.slice(index + 1);
183
186
  for (let i = 0; i < downEls.length; i++) {
@@ -198,7 +201,9 @@
198
201
  };
199
202
  };
200
203
  const up = (deltaTop, target) => {
201
- const brothers = Array.from(target.parentNode?.children || []).filter((node) => !node.id.startsWith(GHOST_EL_ID_PREFIX));
204
+ const brothers = Array.from(target.parentNode?.children || []).filter(
205
+ (node) => !node.id.startsWith(GHOST_EL_ID_PREFIX)
206
+ );
202
207
  const index = brothers.indexOf(target);
203
208
  const upEls = brothers.slice(0, index);
204
209
  let addUpH = target.clientHeight;
@@ -258,6 +263,10 @@
258
263
  select(el, event) {
259
264
  const oldTarget = this.target;
260
265
  this.target = el;
266
+ if (!this.dragEl) {
267
+ this.dragEl = globalThis.document.createElement("div");
268
+ this.container.append(this.dragEl);
269
+ }
261
270
  if (!this.moveable || this.target !== oldTarget) {
262
271
  this.init(el);
263
272
  this.moveableHelper = MoveableHelper__default.default.create({
@@ -308,6 +317,7 @@
308
317
  if (!this.moveable)
309
318
  return;
310
319
  this.destroyDragEl();
320
+ this.dragEl = void 0;
311
321
  this.moveable.target = null;
312
322
  this.moveable.updateTarget();
313
323
  }
@@ -327,9 +337,9 @@
327
337
  }
328
338
  this.mode = getMode(el);
329
339
  this.destroyGhostEl();
330
- this.destroyDragEl();
331
- this.dragEl = globalThis.document.createElement("div");
332
- this.container.append(this.dragEl);
340
+ if (!this.dragEl) {
341
+ return;
342
+ }
333
343
  this.dragEl.style.cssText = getTargetElStyle(el);
334
344
  this.dragEl.id = `${DRAG_EL_ID_PREFIX}${el.id}`;
335
345
  if (typeof this.core.config.updateDragEl === "function") {
@@ -686,7 +696,7 @@
686
696
  top: ${top}px;
687
697
  width: ${el.clientWidth}px;
688
698
  height: ${el.clientHeight}px;
689
- z-index: ${ZIndex.DRAG_EL};
699
+ z-index: ${ZIndex.HIGHLIGHT_EL};
690
700
  `;
691
701
  this.operationEl.id = `${prefix}${el.id}`;
692
702
  if (typeof this.core.config.updateDragEl === "function") {
@@ -981,19 +991,22 @@
981
991
  this.wrapperResizeObserver?.disconnect();
982
992
  this.intersectionObserver?.disconnect();
983
993
  if (typeof IntersectionObserver !== "undefined") {
984
- this.intersectionObserver = new IntersectionObserver((entries) => {
985
- entries.forEach((entry) => {
986
- const { target, intersectionRatio } = entry;
987
- if (intersectionRatio <= 0) {
988
- this.scrollIntoView(target);
989
- }
990
- this.intersectionObserver?.unobserve(target);
991
- });
992
- }, {
993
- root: this.pageScrollParent,
994
- rootMargin: "0px",
995
- threshold: 1
996
- });
994
+ this.intersectionObserver = new IntersectionObserver(
995
+ (entries) => {
996
+ entries.forEach((entry) => {
997
+ const { target, intersectionRatio } = entry;
998
+ if (intersectionRatio <= 0) {
999
+ this.scrollIntoView(target);
1000
+ }
1001
+ this.intersectionObserver?.unobserve(target);
1002
+ });
1003
+ },
1004
+ {
1005
+ root: this.pageScrollParent,
1006
+ rootMargin: "0px",
1007
+ threshold: 1
1008
+ }
1009
+ );
997
1010
  }
998
1011
  if (typeof ResizeObserver !== "undefined") {
999
1012
  this.pageResizeObserver = new ResizeObserver((entries) => {
@@ -1169,9 +1182,12 @@
1169
1182
  });
1170
1183
  this.moveableForMulti?.destroy();
1171
1184
  this.multiMoveableHelper?.clear();
1172
- this.moveableForMulti = new Moveable__default.default(this.container, this.getOptions({
1173
- target: this.dragElList
1174
- }));
1185
+ this.moveableForMulti = new Moveable__default.default(
1186
+ this.container,
1187
+ this.getOptions({
1188
+ target: this.dragElList
1189
+ })
1190
+ );
1175
1191
  this.multiMoveableHelper = MoveableHelper__default.default.create({
1176
1192
  useBeforeRender: true,
1177
1193
  useRender: false,
@@ -1180,7 +1196,9 @@
1180
1196
  const frames = [];
1181
1197
  const setFrames = (events) => {
1182
1198
  events.forEach((ev) => {
1183
- const matchEventTarget = this.targetList.find((targetItem) => targetItem.id === ev.target.id.replace(DRAG_EL_ID_PREFIX, ""));
1199
+ const matchEventTarget = this.targetList.find(
1200
+ (targetItem) => targetItem.id === ev.target.id.replace(DRAG_EL_ID_PREFIX, "")
1201
+ );
1184
1202
  if (!matchEventTarget)
1185
1203
  return;
1186
1204
  frames.push({
@@ -1199,10 +1217,14 @@
1199
1217
  const { events } = params;
1200
1218
  events.forEach((ev) => {
1201
1219
  const { width, height, beforeTranslate } = ev.drag;
1202
- const frameSnapShot = frames.find((frameItem) => frameItem.id === ev.target.id.replace(DRAG_EL_ID_PREFIX, ""));
1220
+ const frameSnapShot = frames.find(
1221
+ (frameItem) => frameItem.id === ev.target.id.replace(DRAG_EL_ID_PREFIX, "")
1222
+ );
1203
1223
  if (!frameSnapShot)
1204
1224
  return;
1205
- const targeEl = this.targetList.find((targetItem) => targetItem.id === ev.target.id.replace(DRAG_EL_ID_PREFIX, ""));
1225
+ const targeEl = this.targetList.find(
1226
+ (targetItem) => targetItem.id === ev.target.id.replace(DRAG_EL_ID_PREFIX, "")
1227
+ );
1206
1228
  if (!targeEl)
1207
1229
  return;
1208
1230
  const isParentIncluded = this.targetList.find((targetItem) => targetItem.id === targeEl.parentElement?.id);
@@ -1226,10 +1248,14 @@
1226
1248
  }).on("dragGroup", (params) => {
1227
1249
  const { events } = params;
1228
1250
  events.forEach((ev) => {
1229
- const frameSnapShot = frames.find((frameItem) => frameItem.id === ev.target.id.replace(DRAG_EL_ID_PREFIX, ""));
1251
+ const frameSnapShot = frames.find(
1252
+ (frameItem) => frameItem.id === ev.target.id.replace(DRAG_EL_ID_PREFIX, "")
1253
+ );
1230
1254
  if (!frameSnapShot)
1231
1255
  return;
1232
- const targeEl = this.targetList.find((targetItem) => targetItem.id === ev.target.id.replace(DRAG_EL_ID_PREFIX, ""));
1256
+ const targeEl = this.targetList.find(
1257
+ (targetItem) => targetItem.id === ev.target.id.replace(DRAG_EL_ID_PREFIX, "")
1258
+ );
1233
1259
  if (!targeEl)
1234
1260
  return;
1235
1261
  const isParentIncluded = this.targetList.find((targetItem) => targetItem.id === targeEl.parentElement?.id);
@@ -1420,9 +1446,12 @@
1420
1446
  postTmagicRuntimeReady() {
1421
1447
  this.contentWindow = this.iframe?.contentWindow;
1422
1448
  this.contentWindow.magic = this.getMagicApi();
1423
- this.contentWindow.postMessage({
1424
- tmagicRuntimeReady: true
1425
- }, "*");
1449
+ this.contentWindow.postMessage(
1450
+ {
1451
+ tmagicRuntimeReady: true
1452
+ },
1453
+ "*"
1454
+ );
1426
1455
  }
1427
1456
  }
1428
1457