@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.
@@ -209,6 +209,20 @@
209
209
  };
210
210
  };
211
211
  const isMoveableButton = (target) => target.classList.contains("moveable-button") || target.parentElement?.classList.contains("moveable-button");
212
+ const getMarginValue = (el) => {
213
+ if (!el)
214
+ return {
215
+ marginLeft: 0,
216
+ marginTop: 0
217
+ };
218
+ const { marginLeft, marginTop } = getComputedStyle(el);
219
+ const marginLeftValue = parseFloat(marginLeft) || 0;
220
+ const marginTopValue = parseFloat(marginTop) || 0;
221
+ return {
222
+ marginLeft: marginLeftValue,
223
+ marginTop: marginTopValue
224
+ };
225
+ };
212
226
 
213
227
  class TargetShadow {
214
228
  el;
@@ -358,8 +372,9 @@
358
372
  }
359
373
  } else {
360
374
  this.moveableHelper.onResize(e);
361
- this.target.style.left = `${this.frameSnapShot.left + beforeTranslate[0]}px`;
362
- this.target.style.top = `${this.frameSnapShot.top + beforeTranslate[1]}px`;
375
+ const { marginLeft, marginTop } = getMarginValue(this.target);
376
+ this.target.style.left = `${this.frameSnapShot.left + beforeTranslate[0] - marginLeft}px`;
377
+ this.target.style.top = `${this.frameSnapShot.top + beforeTranslate[1] - marginTop} - marginToppx`;
363
378
  }
364
379
  this.target.style.width = `${width}px`;
365
380
  this.target.style.height = `${height}px`;
@@ -378,8 +393,9 @@
378
393
  return;
379
394
  }
380
395
  this.moveableHelper.onDrag(e);
381
- this.target.style.left = `${this.frameSnapShot.left + e.beforeTranslate[0]}px`;
382
- this.target.style.top = `${this.frameSnapShot.top + e.beforeTranslate[1]}px`;
396
+ const { marginLeft, marginTop } = getMarginValue(this.target);
397
+ this.target.style.left = `${this.frameSnapShot.left + e.beforeTranslate[0] - marginLeft}px`;
398
+ this.target.style.top = `${this.frameSnapShot.top + e.beforeTranslate[1] - marginTop}px`;
383
399
  }
384
400
  onRotateStart(e) {
385
401
  this.moveableHelper.onRotateStart(e);
@@ -449,8 +465,9 @@
449
465
  return;
450
466
  const isParentIncluded = this.targetList.find((targetItem) => targetItem.id === targeEl.parentElement?.id);
451
467
  if (!isParentIncluded) {
452
- targeEl.style.left = `${frameSnapShot.left + beforeTranslate[0]}px`;
453
- targeEl.style.top = `${frameSnapShot.top + beforeTranslate[1]}px`;
468
+ const { marginLeft, marginTop } = getMarginValue(targeEl);
469
+ targeEl.style.left = `${frameSnapShot.left + beforeTranslate[0] - marginLeft}px`;
470
+ targeEl.style.top = `${frameSnapShot.top + beforeTranslate[1] - marginTop}px`;
454
471
  }
455
472
  targeEl.style.width = `${width}px`;
456
473
  targeEl.style.height = `${height}px`;
@@ -477,16 +494,18 @@
477
494
  return;
478
495
  const isParentIncluded = this.targetList.find((targetItem) => targetItem.id === targeEl.parentElement?.id);
479
496
  if (!isParentIncluded) {
480
- targeEl.style.left = `${frameSnapShot.left + ev.beforeTranslate[0]}px`;
481
- targeEl.style.top = `${frameSnapShot.top + ev.beforeTranslate[1]}px`;
497
+ const { marginLeft, marginTop } = getMarginValue(targeEl);
498
+ targeEl.style.left = `${frameSnapShot.left + ev.beforeTranslate[0] - marginLeft}px`;
499
+ targeEl.style.top = `${frameSnapShot.top + ev.beforeTranslate[1] - marginTop}px`;
482
500
  }
483
501
  });
484
502
  this.moveableHelper.onDragGroup(e);
485
503
  }
486
504
  getUpdatedElRect(el, parentEl, doc) {
487
505
  const offset = this.mode === Mode.SORTABLE ? { left: 0, top: 0 } : { left: el.offsetLeft, top: el.offsetTop };
488
- let left = calcValueByFontsize(doc, offset.left);
489
- let top = calcValueByFontsize(doc, offset.top);
506
+ const { marginLeft, marginTop } = getMarginValue(el);
507
+ let left = calcValueByFontsize(doc, offset.left) - marginLeft;
508
+ let top = calcValueByFontsize(doc, offset.top) - marginTop;
490
509
  const width = calcValueByFontsize(doc, el.clientWidth);
491
510
  const height = calcValueByFontsize(doc, el.clientHeight);
492
511
  let shadowEl = this.getShadowEl();
@@ -541,6 +560,8 @@
541
560
  ghostEl.style.position = "absolute";
542
561
  ghostEl.style.left = `${left}px`;
543
562
  ghostEl.style.top = `${top}px`;
563
+ ghostEl.style.marginLeft = "0";
564
+ ghostEl.style.marginTop = "0";
544
565
  el.after(ghostEl);
545
566
  return ghostEl;
546
567
  }
@@ -1359,6 +1380,9 @@
1359
1380
  isContainer;
1360
1381
  getRenderDocument;
1361
1382
  mouseMoveHandler = lodashEs.throttle(async (event) => {
1383
+ if (event.target?.classList?.contains("moveable-direction")) {
1384
+ return;
1385
+ }
1362
1386
  const el = await this.getElementFromPoint(event);
1363
1387
  if (!el) {
1364
1388
  this.clearHighlight();
@@ -2622,6 +2646,7 @@
2622
2646
  exports.default = StageCore;
2623
2647
  exports.down = down;
2624
2648
  exports.getAbsolutePosition = getAbsolutePosition;
2649
+ exports.getMarginValue = getMarginValue;
2625
2650
  exports.getMode = getMode;
2626
2651
  exports.getOffset = getOffset;
2627
2652
  exports.getScrollParent = getScrollParent;