@tmagic/stage 1.3.0 → 1.3.2

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.
@@ -212,6 +212,20 @@ const up = (deltaTop, target) => {
212
212
  };
213
213
  };
214
214
  const isMoveableButton = (target) => target.classList.contains("moveable-button") || target.parentElement?.classList.contains("moveable-button");
215
+ const getMarginValue = (el) => {
216
+ if (!el)
217
+ return {
218
+ marginLeft: 0,
219
+ marginTop: 0
220
+ };
221
+ const { marginLeft, marginTop } = getComputedStyle(el);
222
+ const marginLeftValue = parseFloat(marginLeft) || 0;
223
+ const marginTopValue = parseFloat(marginTop) || 0;
224
+ return {
225
+ marginLeft: marginLeftValue,
226
+ marginTop: marginTopValue
227
+ };
228
+ };
215
229
 
216
230
  class TargetShadow {
217
231
  el;
@@ -361,8 +375,9 @@ class DragResizeHelper {
361
375
  }
362
376
  } else {
363
377
  this.moveableHelper.onResize(e);
364
- this.target.style.left = `${this.frameSnapShot.left + beforeTranslate[0]}px`;
365
- this.target.style.top = `${this.frameSnapShot.top + beforeTranslate[1]}px`;
378
+ const { marginLeft, marginTop } = getMarginValue(this.target);
379
+ this.target.style.left = `${this.frameSnapShot.left + beforeTranslate[0] - marginLeft}px`;
380
+ this.target.style.top = `${this.frameSnapShot.top + beforeTranslate[1] - marginTop} - marginToppx`;
366
381
  }
367
382
  this.target.style.width = `${width}px`;
368
383
  this.target.style.height = `${height}px`;
@@ -381,8 +396,9 @@ class DragResizeHelper {
381
396
  return;
382
397
  }
383
398
  this.moveableHelper.onDrag(e);
384
- this.target.style.left = `${this.frameSnapShot.left + e.beforeTranslate[0]}px`;
385
- this.target.style.top = `${this.frameSnapShot.top + e.beforeTranslate[1]}px`;
399
+ const { marginLeft, marginTop } = getMarginValue(this.target);
400
+ this.target.style.left = `${this.frameSnapShot.left + e.beforeTranslate[0] - marginLeft}px`;
401
+ this.target.style.top = `${this.frameSnapShot.top + e.beforeTranslate[1] - marginTop}px`;
386
402
  }
387
403
  onRotateStart(e) {
388
404
  this.moveableHelper.onRotateStart(e);
@@ -452,8 +468,9 @@ class DragResizeHelper {
452
468
  return;
453
469
  const isParentIncluded = this.targetList.find((targetItem) => targetItem.id === targeEl.parentElement?.id);
454
470
  if (!isParentIncluded) {
455
- targeEl.style.left = `${frameSnapShot.left + beforeTranslate[0]}px`;
456
- targeEl.style.top = `${frameSnapShot.top + beforeTranslate[1]}px`;
471
+ const { marginLeft, marginTop } = getMarginValue(targeEl);
472
+ targeEl.style.left = `${frameSnapShot.left + beforeTranslate[0] - marginLeft}px`;
473
+ targeEl.style.top = `${frameSnapShot.top + beforeTranslate[1] - marginTop}px`;
457
474
  }
458
475
  targeEl.style.width = `${width}px`;
459
476
  targeEl.style.height = `${height}px`;
@@ -480,16 +497,18 @@ class DragResizeHelper {
480
497
  return;
481
498
  const isParentIncluded = this.targetList.find((targetItem) => targetItem.id === targeEl.parentElement?.id);
482
499
  if (!isParentIncluded) {
483
- targeEl.style.left = `${frameSnapShot.left + ev.beforeTranslate[0]}px`;
484
- targeEl.style.top = `${frameSnapShot.top + ev.beforeTranslate[1]}px`;
500
+ const { marginLeft, marginTop } = getMarginValue(targeEl);
501
+ targeEl.style.left = `${frameSnapShot.left + ev.beforeTranslate[0] - marginLeft}px`;
502
+ targeEl.style.top = `${frameSnapShot.top + ev.beforeTranslate[1] - marginTop}px`;
485
503
  }
486
504
  });
487
505
  this.moveableHelper.onDragGroup(e);
488
506
  }
489
507
  getUpdatedElRect(el, parentEl, doc) {
490
508
  const offset = this.mode === Mode.SORTABLE ? { left: 0, top: 0 } : { left: el.offsetLeft, top: el.offsetTop };
491
- let left = calcValueByFontsize(doc, offset.left);
492
- let top = calcValueByFontsize(doc, offset.top);
509
+ const { marginLeft, marginTop } = getMarginValue(el);
510
+ let left = calcValueByFontsize(doc, offset.left) - marginLeft;
511
+ let top = calcValueByFontsize(doc, offset.top) - marginTop;
493
512
  const width = calcValueByFontsize(doc, el.clientWidth);
494
513
  const height = calcValueByFontsize(doc, el.clientHeight);
495
514
  let shadowEl = this.getShadowEl();
@@ -544,6 +563,8 @@ class DragResizeHelper {
544
563
  ghostEl.style.position = "absolute";
545
564
  ghostEl.style.left = `${left}px`;
546
565
  ghostEl.style.top = `${top}px`;
566
+ ghostEl.style.marginLeft = "0";
567
+ ghostEl.style.marginTop = "0";
547
568
  el.after(ghostEl);
548
569
  return ghostEl;
549
570
  }
@@ -1362,6 +1383,9 @@ class ActionManager extends EventEmitter {
1362
1383
  isContainer;
1363
1384
  getRenderDocument;
1364
1385
  mouseMoveHandler = throttle(async (event) => {
1386
+ if (event.target?.classList?.contains("moveable-direction")) {
1387
+ return;
1388
+ }
1365
1389
  const el = await this.getElementFromPoint(event);
1366
1390
  if (!el) {
1367
1391
  this.clearHighlight();
@@ -2602,5 +2626,5 @@ class StageCore extends EventEmitter$1 {
2602
2626
  }
2603
2627
  }
2604
2628
 
2605
- export { AbleActionEventType, CONTAINER_HIGHLIGHT_CLASS_NAME, ContainerHighlightType, DEFAULT_ZOOM, DRAG_EL_ID_PREFIX, GHOST_EL_ID_PREFIX, GuidesType, HIGHLIGHT_EL_ID_PREFIX, Mode, MouseButton, PAGE_CLASS, SELECTED_CLASS, SelectStatus, StageDragResize, StageDragStatus, StageMask, StageRender, ZIndex, addSelectedClassName, calcValueByFontsize, StageCore as default, down, getAbsolutePosition, getMode, getOffset, getScrollParent, getTargetElStyle, isAbsolute, isFixed, isFixedParent, isMoveableButton, isRelative, isStatic, removeSelectedClassName, up };
2629
+ export { AbleActionEventType, CONTAINER_HIGHLIGHT_CLASS_NAME, ContainerHighlightType, DEFAULT_ZOOM, DRAG_EL_ID_PREFIX, GHOST_EL_ID_PREFIX, GuidesType, HIGHLIGHT_EL_ID_PREFIX, Mode, MouseButton, PAGE_CLASS, SELECTED_CLASS, SelectStatus, StageDragResize, StageDragStatus, StageMask, StageRender, ZIndex, addSelectedClassName, calcValueByFontsize, StageCore as default, down, getAbsolutePosition, getMarginValue, getMode, getOffset, getScrollParent, getTargetElStyle, isAbsolute, isFixed, isFixedParent, isMoveableButton, isRelative, isStatic, removeSelectedClassName, up };
2606
2630
  //# sourceMappingURL=tmagic-stage.js.map