@tmagic/stage 1.0.0-beta.5 → 1.0.0-beta.6

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.
@@ -93,11 +93,11 @@ class StageDragResize extends EventEmitter {
93
93
  container;
94
94
  target;
95
95
  moveable;
96
+ horizontalGuidelines = [];
97
+ verticalGuidelines = [];
96
98
  dragStatus = "end" /* END */;
97
99
  elObserver;
98
100
  ghostEl;
99
- horizontalGuidelines = [];
100
- verticalGuidelines = [];
101
101
  mode = Mode.ABSOLUTE;
102
102
  constructor(config) {
103
103
  super();
@@ -242,10 +242,9 @@ class StageDragResize extends EventEmitter {
242
242
  const { renderer } = this.core;
243
243
  const getSnapElements = (await renderer.getRuntime())?.getSnapElements || (() => {
244
244
  const doc = renderer.contentWindow?.document;
245
- const elementGuidelines = (doc ? Array.from(doc.querySelectorAll("[id]")) : []).filter((element) => element !== this.target && !this.target?.contains(element));
246
- return elementGuidelines;
245
+ return doc ? Array.from(doc.querySelectorAll("[id]")) : [];
247
246
  });
248
- return getSnapElements(el);
247
+ return getSnapElements(el).filter((element) => element !== this.target && !this.target?.contains(element));
249
248
  }
250
249
  sort() {
251
250
  if (!this.target || !this.ghostEl)
@@ -325,11 +324,8 @@ class StageDragResize extends EventEmitter {
325
324
  resizable: true,
326
325
  snappable: !isSortable,
327
326
  snapGap: !isSortable,
328
- snapElement: !isSortable,
329
- snapVertical: !isSortable,
330
- snapHorizontal: !isSortable,
331
- snapCenter: !isSortable,
332
- container: renderer.contentWindow?.document.body,
327
+ snapDirections: { center: !isSortable, middle: !isSortable },
328
+ elementSnapDirections: { center: !isSortable, middle: !isSortable },
333
329
  elementGuidelines: isSortable ? [] : await this.getSnapElements(this.target),
334
330
  horizontalGuidelines: this.horizontalGuidelines,
335
331
  verticalGuidelines: this.verticalGuidelines,
@@ -17683,8 +17679,8 @@ class StageMask extends EventEmitter {
17683
17679
  this.core = config.core;
17684
17680
  const { config: coreConfig } = config.core;
17685
17681
  this.canSelect = coreConfig.canSelect || ((el) => !!el.id);
17686
- this.content.addEventListener("mousedown", this.mouseDownHandler, true);
17687
- this.content.addEventListener("contextmenu", this.contextmenuHandler, true);
17682
+ this.content.addEventListener("mousedown", this.mouseDownHandler);
17683
+ this.content.addEventListener("contextmenu", this.contextmenuHandler);
17688
17684
  this.wrapper.appendChild(this.content);
17689
17685
  this.hGuides = this.createGuides("horizontal");
17690
17686
  this.vGuides = this.createGuides("vertical");
@@ -17742,16 +17738,23 @@ class StageMask extends EventEmitter {
17742
17738
  });
17743
17739
  }
17744
17740
  showRule(show = true) {
17745
- this.hGuides.setState({
17746
- rulerStyle: {
17747
- visibility: show ? "" : "hidden"
17748
- }
17749
- });
17750
- this.vGuides.setState({
17751
- rulerStyle: {
17752
- visibility: show ? "" : "hidden"
17753
- }
17754
- });
17741
+ if (show) {
17742
+ this.hGuides.destroy();
17743
+ this.hGuides = this.createGuides("horizontal", this.core.dr.horizontalGuidelines);
17744
+ this.vGuides.destroy();
17745
+ this.vGuides = this.createGuides("vertical", this.core.dr.verticalGuidelines);
17746
+ } else {
17747
+ this.hGuides.setState({
17748
+ rulerStyle: {
17749
+ visibility: "hidden"
17750
+ }
17751
+ });
17752
+ this.vGuides.setState({
17753
+ rulerStyle: {
17754
+ visibility: "hidden"
17755
+ }
17756
+ });
17757
+ }
17755
17758
  }
17756
17759
  clearGuides() {
17757
17760
  this.vGuides.setState({
@@ -17773,13 +17776,21 @@ class StageMask extends EventEmitter {
17773
17776
  if (event.target.className.indexOf("moveable-control") !== -1) {
17774
17777
  return;
17775
17778
  }
17779
+ this.content.addEventListener("mousemove", this.mouseMoveHandler);
17776
17780
  this.select(event);
17777
17781
  };
17778
17782
  mouseUpHandler = () => {
17779
- this.content?.removeEventListener("mouseup", this.mouseUpHandler, true);
17783
+ this.content.removeEventListener("mousemove", this.mouseMoveHandler);
17784
+ this.content.removeEventListener("mouseup", this.mouseUpHandler);
17780
17785
  this.emit("selected", this.target);
17781
17786
  this.target = null;
17782
17787
  };
17788
+ mouseMoveHandler = (event) => {
17789
+ if (event.buttons) {
17790
+ this.core.dr.moveable?.dragStart(event);
17791
+ }
17792
+ this.content.removeEventListener("mousemove", this.mouseMoveHandler);
17793
+ };
17783
17794
  contextmenuHandler = async (event) => {
17784
17795
  await this.select(event);
17785
17796
  this.mouseUpHandler();
@@ -17805,7 +17816,7 @@ class StageMask extends EventEmitter {
17805
17816
  break;
17806
17817
  this.emit("select", el, event);
17807
17818
  this.target = el;
17808
- this.content?.addEventListener("mouseup", this.mouseUpHandler, true);
17819
+ this.content.addEventListener("mouseup", this.mouseUpHandler);
17809
17820
  break;
17810
17821
  }
17811
17822
  }
@@ -17817,8 +17828,9 @@ class StageMask extends EventEmitter {
17817
17828
  width: type === "horizontal" ? "100%" : "30px",
17818
17829
  height: type === "horizontal" ? "30px" : "100%"
17819
17830
  });
17820
- createGuides = (type) => new Guides(this.wrapper, {
17831
+ createGuides = (type, defaultGuides = []) => new Guides(this.wrapper, {
17821
17832
  type,
17833
+ defaultGuides,
17822
17834
  displayDragPos: true,
17823
17835
  backgroundColor: "#fff",
17824
17836
  lineColor: "#000",
@@ -17915,9 +17927,8 @@ class StageCore extends EventEmitter {
17915
17927
  this.dr = new StageDragResize({ core: this, container: this.mask.content });
17916
17928
  this.renderer.on("runtime-ready", (runtime) => this.emit("runtime-ready", runtime));
17917
17929
  this.renderer.on("page-el-update", (el) => this.mask?.observe(el));
17918
- this.mask.on("select", async (el, event) => {
17930
+ this.mask.on("select", async (el) => {
17919
17931
  await this.dr?.select(el);
17920
- setTimeout(() => this.dr?.moveable?.dragStart(event));
17921
17932
  });
17922
17933
  this.mask.on("selected", (el) => {
17923
17934
  this.select(el);