@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.
@@ -100,11 +100,11 @@
100
100
  container;
101
101
  target;
102
102
  moveable;
103
+ horizontalGuidelines = [];
104
+ verticalGuidelines = [];
103
105
  dragStatus = "end" /* END */;
104
106
  elObserver;
105
107
  ghostEl;
106
- horizontalGuidelines = [];
107
- verticalGuidelines = [];
108
108
  mode = Mode.ABSOLUTE;
109
109
  constructor(config) {
110
110
  super();
@@ -249,10 +249,9 @@
249
249
  const { renderer } = this.core;
250
250
  const getSnapElements = (await renderer.getRuntime())?.getSnapElements || (() => {
251
251
  const doc = renderer.contentWindow?.document;
252
- const elementGuidelines = (doc ? Array.from(doc.querySelectorAll("[id]")) : []).filter((element) => element !== this.target && !this.target?.contains(element));
253
- return elementGuidelines;
252
+ return doc ? Array.from(doc.querySelectorAll("[id]")) : [];
254
253
  });
255
- return getSnapElements(el);
254
+ return getSnapElements(el).filter((element) => element !== this.target && !this.target?.contains(element));
256
255
  }
257
256
  sort() {
258
257
  if (!this.target || !this.ghostEl)
@@ -332,11 +331,8 @@
332
331
  resizable: true,
333
332
  snappable: !isSortable,
334
333
  snapGap: !isSortable,
335
- snapElement: !isSortable,
336
- snapVertical: !isSortable,
337
- snapHorizontal: !isSortable,
338
- snapCenter: !isSortable,
339
- container: renderer.contentWindow?.document.body,
334
+ snapDirections: { center: !isSortable, middle: !isSortable },
335
+ elementSnapDirections: { center: !isSortable, middle: !isSortable },
340
336
  elementGuidelines: isSortable ? [] : await this.getSnapElements(this.target),
341
337
  horizontalGuidelines: this.horizontalGuidelines,
342
338
  verticalGuidelines: this.verticalGuidelines,
@@ -17690,8 +17686,8 @@
17690
17686
  this.core = config.core;
17691
17687
  const { config: coreConfig } = config.core;
17692
17688
  this.canSelect = coreConfig.canSelect || ((el) => !!el.id);
17693
- this.content.addEventListener("mousedown", this.mouseDownHandler, true);
17694
- this.content.addEventListener("contextmenu", this.contextmenuHandler, true);
17689
+ this.content.addEventListener("mousedown", this.mouseDownHandler);
17690
+ this.content.addEventListener("contextmenu", this.contextmenuHandler);
17695
17691
  this.wrapper.appendChild(this.content);
17696
17692
  this.hGuides = this.createGuides("horizontal");
17697
17693
  this.vGuides = this.createGuides("vertical");
@@ -17749,16 +17745,23 @@
17749
17745
  });
17750
17746
  }
17751
17747
  showRule(show = true) {
17752
- this.hGuides.setState({
17753
- rulerStyle: {
17754
- visibility: show ? "" : "hidden"
17755
- }
17756
- });
17757
- this.vGuides.setState({
17758
- rulerStyle: {
17759
- visibility: show ? "" : "hidden"
17760
- }
17761
- });
17748
+ if (show) {
17749
+ this.hGuides.destroy();
17750
+ this.hGuides = this.createGuides("horizontal", this.core.dr.horizontalGuidelines);
17751
+ this.vGuides.destroy();
17752
+ this.vGuides = this.createGuides("vertical", this.core.dr.verticalGuidelines);
17753
+ } else {
17754
+ this.hGuides.setState({
17755
+ rulerStyle: {
17756
+ visibility: "hidden"
17757
+ }
17758
+ });
17759
+ this.vGuides.setState({
17760
+ rulerStyle: {
17761
+ visibility: "hidden"
17762
+ }
17763
+ });
17764
+ }
17762
17765
  }
17763
17766
  clearGuides() {
17764
17767
  this.vGuides.setState({
@@ -17780,13 +17783,21 @@
17780
17783
  if (event.target.className.indexOf("moveable-control") !== -1) {
17781
17784
  return;
17782
17785
  }
17786
+ this.content.addEventListener("mousemove", this.mouseMoveHandler);
17783
17787
  this.select(event);
17784
17788
  };
17785
17789
  mouseUpHandler = () => {
17786
- this.content?.removeEventListener("mouseup", this.mouseUpHandler, true);
17790
+ this.content.removeEventListener("mousemove", this.mouseMoveHandler);
17791
+ this.content.removeEventListener("mouseup", this.mouseUpHandler);
17787
17792
  this.emit("selected", this.target);
17788
17793
  this.target = null;
17789
17794
  };
17795
+ mouseMoveHandler = (event) => {
17796
+ if (event.buttons) {
17797
+ this.core.dr.moveable?.dragStart(event);
17798
+ }
17799
+ this.content.removeEventListener("mousemove", this.mouseMoveHandler);
17800
+ };
17790
17801
  contextmenuHandler = async (event) => {
17791
17802
  await this.select(event);
17792
17803
  this.mouseUpHandler();
@@ -17812,7 +17823,7 @@
17812
17823
  break;
17813
17824
  this.emit("select", el, event);
17814
17825
  this.target = el;
17815
- this.content?.addEventListener("mouseup", this.mouseUpHandler, true);
17826
+ this.content.addEventListener("mouseup", this.mouseUpHandler);
17816
17827
  break;
17817
17828
  }
17818
17829
  }
@@ -17824,8 +17835,9 @@
17824
17835
  width: type === "horizontal" ? "100%" : "30px",
17825
17836
  height: type === "horizontal" ? "30px" : "100%"
17826
17837
  });
17827
- createGuides = (type) => new Guides__default["default"](this.wrapper, {
17838
+ createGuides = (type, defaultGuides = []) => new Guides__default["default"](this.wrapper, {
17828
17839
  type,
17840
+ defaultGuides,
17829
17841
  displayDragPos: true,
17830
17842
  backgroundColor: "#fff",
17831
17843
  lineColor: "#000",
@@ -17922,9 +17934,8 @@
17922
17934
  this.dr = new StageDragResize({ core: this, container: this.mask.content });
17923
17935
  this.renderer.on("runtime-ready", (runtime) => this.emit("runtime-ready", runtime));
17924
17936
  this.renderer.on("page-el-update", (el) => this.mask?.observe(el));
17925
- this.mask.on("select", async (el, event) => {
17937
+ this.mask.on("select", async (el) => {
17926
17938
  await this.dr?.select(el);
17927
- setTimeout(() => this.dr?.moveable?.dragStart(event));
17928
17939
  });
17929
17940
  this.mask.on("selected", (el) => {
17930
17941
  this.select(el);