@tmagic/stage 1.3.0-beta.8 → 1.3.1

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();
@@ -1791,8 +1815,6 @@ class Rule extends EventEmitter {
1791
1815
  this.container = container;
1792
1816
  this.hGuides = this.createGuides(GuidesType.HORIZONTAL, this.horizontalGuidelines);
1793
1817
  this.vGuides = this.createGuides(GuidesType.VERTICAL, this.verticalGuidelines);
1794
- this.hGuides.on("changeGuides", this.hGuidesChangeGuidesHandler);
1795
- this.vGuides.on("changeGuides", this.vGuidesChangeGuidesHandler);
1796
1818
  this.containerResizeObserver = new ResizeObserver(() => {
1797
1819
  this.vGuides.resize();
1798
1820
  this.hGuides.resize();
@@ -1879,16 +1901,26 @@ class Rule extends EventEmitter {
1879
1901
  width: type === GuidesType.HORIZONTAL ? "100%" : "30px",
1880
1902
  height: type === GuidesType.HORIZONTAL ? "30px" : "100%"
1881
1903
  });
1882
- createGuides = (type, defaultGuides = []) => new Guides(this.container, {
1883
- type,
1884
- defaultGuides,
1885
- displayDragPos: true,
1886
- backgroundColor: "#fff",
1887
- lineColor: "#000",
1888
- textColor: "#000",
1889
- style: this.getGuidesStyle(type),
1890
- showGuides: this.isShowGuides
1891
- });
1904
+ createGuides = (type, defaultGuides = []) => {
1905
+ const guides = new Guides(this.container, {
1906
+ type,
1907
+ defaultGuides,
1908
+ displayDragPos: true,
1909
+ backgroundColor: "#fff",
1910
+ lineColor: "#000",
1911
+ textColor: "#000",
1912
+ style: this.getGuidesStyle(type),
1913
+ showGuides: this.isShowGuides
1914
+ });
1915
+ const changEventHandler = {
1916
+ [GuidesType.HORIZONTAL]: this.hGuidesChangeGuidesHandler,
1917
+ [GuidesType.VERTICAL]: this.vGuidesChangeGuidesHandler
1918
+ }[type];
1919
+ if (changEventHandler) {
1920
+ guides.on("changeGuides", changEventHandler);
1921
+ }
1922
+ return guides;
1923
+ };
1892
1924
  hGuidesChangeGuidesHandler = (e) => {
1893
1925
  this.horizontalGuidelines = e.guides;
1894
1926
  this.emit("change-guides", {
@@ -2594,5 +2626,5 @@ class StageCore extends EventEmitter$1 {
2594
2626
  }
2595
2627
  }
2596
2628
 
2597
- 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 };
2598
2630
  //# sourceMappingURL=tmagic-stage.js.map