@rogieking/figui3 1.8.1 → 1.8.3

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 +17 -0
  2. package/fig.js +27 -6
  3. package/package.json +1 -1
package/example.html CHANGED
@@ -26,6 +26,8 @@
26
26
  <h2><label>Effects/</label>UI3 Components</h2>
27
27
  </fig-header>
28
28
 
29
+
30
+
29
31
  <fig-input-text disabled
30
32
  value="Disabled"><span slot="append">%</span></fig-input-text>
31
33
 
@@ -71,7 +73,10 @@
71
73
 
72
74
  <fig-content>
73
75
 
76
+
74
77
  <br /><br /><br /><br /><br /><br /><br /><br /><br />
78
+
79
+
75
80
  <hstack>
76
81
  <fig-tooltip text="Tooltip"
77
82
  delay="0">
@@ -112,6 +117,7 @@
112
117
 
113
118
  </hstack>
114
119
  <br /><br /><br /><br /><br /><br /><br /><br /><br />
120
+
115
121
  <fig-button type="link"
116
122
  href="https://www.google.com">
117
123
  <svg width="24"
@@ -284,6 +290,17 @@
284
290
  label="Upload image"
285
291
  size="large"></fig-image>
286
292
  </fig-field>
293
+ <script>
294
+ function updateImages() {
295
+ const images = document.querySelectorAll('fig-image');
296
+ images.forEach(image => {
297
+ //image.setAttribute("src", "https://picsum.photos/200?random=" + Math.random());
298
+ image.src = "https://picsum.photos/200?random=" + Math.random();
299
+ });
300
+ }
301
+ </script>
302
+
303
+ <button onclick="updateImages()">Change src</button>
287
304
 
288
305
  <br /><br />
289
306
  <fig-header>
package/fig.js CHANGED
@@ -1869,12 +1869,13 @@ window.customElements.define("fig-combo-input", FigComboInput);
1869
1869
  * @attr {boolean} disabled - Whether the chip is disabled
1870
1870
  */
1871
1871
  class FigChit extends HTMLElement {
1872
+ #src = null;
1872
1873
  constructor() {
1873
1874
  super();
1874
1875
  }
1875
1876
  connectedCallback() {
1876
1877
  this.type = this.getAttribute("type") || "color";
1877
- this.src = this.getAttribute("src") || "";
1878
+ this.#src = this.getAttribute("src") || "";
1878
1879
  this.value = this.getAttribute("value") || "#000000";
1879
1880
  this.size = this.getAttribute("size") || "small";
1880
1881
  this.disabled = this.getAttribute("disabled") === "true";
@@ -1887,15 +1888,23 @@ class FigChit extends HTMLElement {
1887
1888
  }
1888
1889
  #updateSrc(src) {
1889
1890
  if (src) {
1890
- this.src = src;
1891
+ this.#src = src;
1891
1892
  this.style.setProperty("--src", `url(${src})`);
1892
1893
  } else {
1893
1894
  this.style.removeProperty("--src");
1895
+ this.#src = null;
1894
1896
  }
1895
1897
  }
1896
1898
  static get observedAttributes() {
1897
1899
  return ["src", "value", "disabled"];
1898
1900
  }
1901
+ get src() {
1902
+ return this.#src;
1903
+ }
1904
+ set src(value) {
1905
+ this.#src = value;
1906
+ this.setAttribute("src", value);
1907
+ }
1899
1908
  attributeChangedCallback(name, oldValue, newValue) {
1900
1909
  switch (name) {
1901
1910
  case "src":
@@ -1948,12 +1957,13 @@ class FigImage extends HTMLElement {
1948
1957
  }</div>`;
1949
1958
  }
1950
1959
  connectedCallback() {
1951
- this.src = this.getAttribute("src") || "";
1960
+ this.#src = this.getAttribute("src") || "";
1952
1961
  this.upload = this.getAttribute("upload") === "true";
1953
1962
  this.download = this.getAttribute("download") === "true";
1954
1963
  this.label = this.getAttribute("label") || "Upload";
1955
1964
  this.size = this.getAttribute("size") || "small";
1956
1965
  this.innerHTML = this.#getInnerHTML();
1966
+ this.#updateRefs();
1957
1967
  }
1958
1968
  disconnectedCallback() {
1959
1969
  this.fileInput.removeEventListener(
@@ -1978,7 +1988,6 @@ class FigImage extends HTMLElement {
1978
1988
  );
1979
1989
  }
1980
1990
  if (this.download) {
1981
- console.log("binding download");
1982
1991
  this.downloadButton = this.querySelector("fig-button[type='download']");
1983
1992
  this.downloadButton.removeEventListener(
1984
1993
  "click",
@@ -2033,13 +2042,21 @@ class FigImage extends HTMLElement {
2033
2042
 
2034
2043
  // Get blob from canvas
2035
2044
  canvas.toBlob((blob) => {
2036
- this.blob = URL.createObjectURL(blob);
2045
+ if (this.blob) {
2046
+ URL.revokeObjectURL(this.blob);
2047
+ }
2048
+ if (blob) {
2049
+ this.blob = URL.createObjectURL(blob);
2050
+ }
2037
2051
  });
2038
2052
  };
2039
2053
  this.image.src = src;
2040
2054
  });
2041
2055
  }
2042
2056
  async #handleFileInput(e) {
2057
+ if (this.blob) {
2058
+ URL.revokeObjectURL(this.blob);
2059
+ }
2043
2060
  this.blob = URL.createObjectURL(e.target.files[0]);
2044
2061
  //set base64 url
2045
2062
  const reader = new FileReader();
@@ -2079,11 +2096,15 @@ class FigImage extends HTMLElement {
2079
2096
  }
2080
2097
  set src(value) {
2081
2098
  this.#src = value;
2099
+ this.setAttribute("src", value);
2082
2100
  }
2083
2101
 
2084
2102
  attributeChangedCallback(name, oldValue, newValue) {
2085
2103
  if (name === "src") {
2086
- this.src = newValue;
2104
+ //this.src = newValue;
2105
+ if (!this.chit) {
2106
+ this.chit = this.querySelector("fig-chit");
2107
+ }
2087
2108
  if (this.chit) {
2088
2109
  this.chit.setAttribute("src", this.#src);
2089
2110
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rogieking/figui3",
3
- "version": "1.8.1",
3
+ "version": "1.8.3",
4
4
  "module": "index.ts",
5
5
  "type": "module",
6
6
  "devDependencies": {