@rogieking/figui3 1.2.9 → 1.3.0

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.
Files changed (3) hide show
  1. package/example.html +2 -1
  2. package/fig.js +28 -5
  3. package/package.json +1 -1
package/example.html CHANGED
@@ -23,7 +23,8 @@
23
23
  <h2>UI3 Components</h2>
24
24
  </fig-header>
25
25
  <fig-content>
26
- <fig-input-joystick text="true"></fig-input-joystick>
26
+ <fig-input-joystick text="true"
27
+ onInput="console.log(event.target.value)"></fig-input-joystick>
27
28
  <fig-header>
28
29
  <h2>Details</h2>
29
30
  </fig-header>
package/fig.js CHANGED
@@ -1792,13 +1792,19 @@ class FigInputJoystick extends HTMLElement {
1792
1792
  }
1793
1793
 
1794
1794
  handleXInput(e) {
1795
+ e.stopPropagation();
1795
1796
  this.position.x = e.target.value;
1796
1797
  this.#syncHandlePosition();
1798
+ this.#emitInputEvent();
1799
+ this.#emitChangeEvent();
1797
1800
  }
1798
1801
 
1799
1802
  handleYInput(e) {
1803
+ e.stopPropagation();
1800
1804
  this.position.y = e.target.value;
1801
1805
  this.#syncHandlePosition();
1806
+ this.#emitInputEvent();
1807
+ this.#emitChangeEvent();
1802
1808
  }
1803
1809
 
1804
1810
  snapToGuide(value) {
@@ -1817,7 +1823,7 @@ class FigInputJoystick extends HTMLElement {
1817
1823
  return { x, y };
1818
1824
  }
1819
1825
 
1820
- updatePosition(e) {
1826
+ #updatePosition(e) {
1821
1827
  const rect = this.plane.getBoundingClientRect();
1822
1828
  let x = Math.max(0, Math.min(1, (e.clientX - rect.left) / rect.width));
1823
1829
  let y = Math.max(0, Math.min(1, (e.clientY - rect.top) / rect.height));
@@ -1839,7 +1845,24 @@ class FigInputJoystick extends HTMLElement {
1839
1845
  this.yInput.setAttribute("value", snapped.y.toFixed(3));
1840
1846
  }
1841
1847
 
1842
- this.dispatchEvent(new CustomEvent("input", { detail: this.position }));
1848
+ this.#emitInputEvent();
1849
+ }
1850
+ #emitInputEvent() {
1851
+ this.dispatchEvent(
1852
+ new CustomEvent("input", {
1853
+ bubbles: true,
1854
+ cancelable: true,
1855
+ })
1856
+ );
1857
+ }
1858
+
1859
+ #emitChangeEvent() {
1860
+ this.dispatchEvent(
1861
+ new CustomEvent("change", {
1862
+ bubbles: true,
1863
+ cancelable: true,
1864
+ })
1865
+ );
1843
1866
  }
1844
1867
 
1845
1868
  #syncHandlePosition() {
@@ -1849,12 +1872,12 @@ class FigInputJoystick extends HTMLElement {
1849
1872
 
1850
1873
  handleMouseDown(e) {
1851
1874
  this.isDragging = true;
1852
- this.updatePosition(e);
1875
+ this.#updatePosition(e);
1853
1876
 
1854
1877
  this.plane.style.cursor = "grabbing";
1855
1878
 
1856
1879
  const handleMouseMove = (e) => {
1857
- if (this.isDragging) this.updatePosition(e);
1880
+ if (this.isDragging) this.#updatePosition(e);
1858
1881
  };
1859
1882
 
1860
1883
  const handleMouseUp = () => {
@@ -1862,7 +1885,7 @@ class FigInputJoystick extends HTMLElement {
1862
1885
  this.plane.style.cursor = "";
1863
1886
  window.removeEventListener("mousemove", handleMouseMove);
1864
1887
  window.removeEventListener("mouseup", handleMouseUp);
1865
- this.dispatchEvent(new CustomEvent("change", { detail: this.position }));
1888
+ this.#emitChangeEvent();
1866
1889
  };
1867
1890
 
1868
1891
  window.addEventListener("mousemove", handleMouseMove);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rogieking/figui3",
3
- "version": "1.2.9",
3
+ "version": "1.3.0",
4
4
  "module": "index.ts",
5
5
  "type": "module",
6
6
  "devDependencies": {