@rogieking/figui3 1.2.9 → 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.
Files changed (3) hide show
  1. package/example.html +2 -1
  2. package/fig.js +32 -7
  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,21 @@ class FigInputJoystick extends HTMLElement {
1792
1792
  }
1793
1793
 
1794
1794
  handleXInput(e) {
1795
- this.position.x = e.target.value;
1795
+ e.stopPropagation();
1796
+ this.position.x = Number(e.target.value);
1797
+ this.value = [this.position.x, this.position.y];
1796
1798
  this.#syncHandlePosition();
1799
+ this.#emitInputEvent();
1800
+ this.#emitChangeEvent();
1797
1801
  }
1798
1802
 
1799
1803
  handleYInput(e) {
1800
- this.position.y = e.target.value;
1804
+ e.stopPropagation();
1805
+ this.position.y = Number(e.target.value);
1806
+ this.value = [this.position.x, this.position.y];
1801
1807
  this.#syncHandlePosition();
1808
+ this.#emitInputEvent();
1809
+ this.#emitChangeEvent();
1802
1810
  }
1803
1811
 
1804
1812
  snapToGuide(value) {
@@ -1817,7 +1825,7 @@ class FigInputJoystick extends HTMLElement {
1817
1825
  return { x, y };
1818
1826
  }
1819
1827
 
1820
- updatePosition(e) {
1828
+ #updatePosition(e) {
1821
1829
  const rect = this.plane.getBoundingClientRect();
1822
1830
  let x = Math.max(0, Math.min(1, (e.clientX - rect.left) / rect.width));
1823
1831
  let y = Math.max(0, Math.min(1, (e.clientY - rect.top) / rect.height));
@@ -1839,7 +1847,24 @@ class FigInputJoystick extends HTMLElement {
1839
1847
  this.yInput.setAttribute("value", snapped.y.toFixed(3));
1840
1848
  }
1841
1849
 
1842
- this.dispatchEvent(new CustomEvent("input", { detail: this.position }));
1850
+ this.#emitInputEvent();
1851
+ }
1852
+ #emitInputEvent() {
1853
+ this.dispatchEvent(
1854
+ new CustomEvent("input", {
1855
+ bubbles: true,
1856
+ cancelable: true,
1857
+ })
1858
+ );
1859
+ }
1860
+
1861
+ #emitChangeEvent() {
1862
+ this.dispatchEvent(
1863
+ new CustomEvent("change", {
1864
+ bubbles: true,
1865
+ cancelable: true,
1866
+ })
1867
+ );
1843
1868
  }
1844
1869
 
1845
1870
  #syncHandlePosition() {
@@ -1849,12 +1874,12 @@ class FigInputJoystick extends HTMLElement {
1849
1874
 
1850
1875
  handleMouseDown(e) {
1851
1876
  this.isDragging = true;
1852
- this.updatePosition(e);
1877
+ this.#updatePosition(e);
1853
1878
 
1854
1879
  this.plane.style.cursor = "grabbing";
1855
1880
 
1856
1881
  const handleMouseMove = (e) => {
1857
- if (this.isDragging) this.updatePosition(e);
1882
+ if (this.isDragging) this.#updatePosition(e);
1858
1883
  };
1859
1884
 
1860
1885
  const handleMouseUp = () => {
@@ -1862,7 +1887,7 @@ class FigInputJoystick extends HTMLElement {
1862
1887
  this.plane.style.cursor = "";
1863
1888
  window.removeEventListener("mousemove", handleMouseMove);
1864
1889
  window.removeEventListener("mouseup", handleMouseUp);
1865
- this.dispatchEvent(new CustomEvent("change", { detail: this.position }));
1890
+ this.#emitChangeEvent();
1866
1891
  };
1867
1892
 
1868
1893
  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.1",
4
4
  "module": "index.ts",
5
5
  "type": "module",
6
6
  "devDependencies": {