zs3-ui-components 1.2.0 → 1.2.2

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.

Potentially problematic release.


This version of zs3-ui-components might be problematic. Click here for more details.

package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # ZS3 UI Components
2
2
 
3
- **v1.2.0** · Modern Web Components library with built-in theming, i18n, reactive state, HTTP client, and more.
3
+ **v1.2.2** · Modern Web Components library with built-in theming, i18n, reactive state, HTTP client, and more.
4
4
 
5
5
  ZS3 UI Components is a zero-dependency UI library based on native **Web Components** (Custom Elements + Shadow DOM). It provides a complete set of UI components and utilities that work in any framework or in plain HTML.
6
6
 
@@ -1984,7 +1984,7 @@ Logger avançat amb nivells i formatació a la consola del navegador.
1984
1984
  ```ts
1985
1985
  import { log } from 'zs3-ui-components'
1986
1986
 
1987
- log.info('Aplicació iniciada', { version: '1.2.0' })
1987
+ log.info('Aplicació iniciada', { version: '1.2.2' })
1988
1988
  log.warn('Configuració incompleta', { missing: 'api-key' })
1989
1989
  log.error('Error en la petició', { code: 500, url: '/api/users' })
1990
1990
  log.success('Operació completada!')
@@ -2055,6 +2055,8 @@ window.diHasDemo = () => {
2055
2055
 
2056
2056
  Helper per seleccionar i manipular elements del DOM.
2057
2057
 
2058
+ #### `$` global
2059
+
2058
2060
  ```ts
2059
2061
  import { $ } from 'zs3-ui-components'
2060
2062
 
@@ -2067,6 +2069,33 @@ $('#my-element')?.text('Nou contingut')
2067
2069
  $('#my-element')?.attr('aria-label', 'Descripció')
2068
2070
  ```
2069
2071
 
2072
+ #### `this.$` — Helper scope-aware dins de components
2073
+
2074
+ Tots els components que extenen `$BaseComponent` disposen de la propietat `this.$`, que és
2075
+ una versió de `$` vinculada automàticament al **shadow DOM del component** (o al `_container`
2076
+ si el component s'usa com a pàgina via Router).
2077
+
2078
+ Permet seleccionar elements interns del component sense risc de col·lisió amb altres components
2079
+ o amb el `document` global, ja que la cerca queda limitada a l'arbre intern del component.
2080
+
2081
+ ```ts
2082
+ class MyComponent extends $BaseComponent {
2083
+ render(): void {
2084
+ this.setHTML(`<button class="my-btn">Click</button>`)
2085
+ }
2086
+
2087
+ protected afterMount(): void {
2088
+ // Cerca limitada al shadow DOM d'aquest component
2089
+ this.$('.my-btn')?.addClass('active')
2090
+ this.$('input')?.value('valor inicial')
2091
+ this.$('.title')?.text(this.t('my.title.key'))
2092
+ }
2093
+ }
2094
+ ```
2095
+
2096
+ > **Nota:** `this.$` és equivalent a `$(selector, this.shadowRoot)`. Usar `$` global des de dins
2097
+ > d'un component amb shadow DOM **no funcionaria**, ja que el shadow DOM no és accessible des del `document`.
2098
+
2070
2099
  #### HTML inline (index2.html)
2071
2100
 
2072
2101
  ```html
@@ -1,3 +1,4 @@
1
+ import { ZS3 } from '../zs3';
1
2
  /**
2
3
  * Opcions per al mètode emit
3
4
  */
@@ -101,6 +102,27 @@ export declare abstract class $BaseComponent extends HTMLElement {
101
102
  * @example this._moveDragSelector = '.title-bar' // per zs3-window
102
103
  */
103
104
  protected _moveDragSelector: string | null;
105
+ /**
106
+ * Helper DOM scope-aware basat en la funció `$` de ZS3.
107
+ *
108
+ * Equivalent a `$(selector)` però limitat al shadow DOM del component (o al `_container`
109
+ * si el component s'usa com a pàgina via Router sense shadow DOM).
110
+ *
111
+ * Permet seleccionar elements interns del component de forma segura sense haver d'accedir
112
+ * al `document` global, evitant col·lisions amb altres components o el document principal.
113
+ *
114
+ * Retorna una instància de `ZS3` amb l'API encadenada, o `null` si el selector no troba res.
115
+ *
116
+ * @param selector - Selector CSS per cercar dins del shadow DOM del component.
117
+ * @returns Instància `ZS3` amb l'element seleccionat, o `null` si no existeix.
118
+ *
119
+ * @example
120
+ * // Dins d'un mètode del component:
121
+ * this.$('.my-button')?.addClass('active')
122
+ * this.$('input')?.value('nou valor')
123
+ * this.$('.title')?.text(this.t('my.title.key'))
124
+ */
125
+ $: (selector: string) => ZS3 | null;
104
126
  /**
105
127
  * Initializes the base component
106
128
  * @param options - Configuration options for the component
package/dist/index.js CHANGED
@@ -14,7 +14,7 @@ class T {
14
14
  * @returns {string} Library version.
15
15
  */
16
16
  static version() {
17
- return "1.2.0";
17
+ return "1.2.2";
18
18
  }
19
19
  /**
20
20
  * Creates a ZS3 instance from an HTMLElement.
@@ -427,7 +427,7 @@ class T {
427
427
  return this.list[0]?.cloneNode(t) ?? null;
428
428
  }
429
429
  }
430
- const J = (e, t) => e != null && e.length > 0 ? new T(e, t) : null, $e = () => ({
430
+ const Y = (e, t) => e != null && e.length > 0 ? new T(e, t) : null, $e = () => ({
431
431
  userAgent: navigator.userAgent,
432
432
  language: navigator.language,
433
433
  platform: navigator.platform,
@@ -453,16 +453,16 @@ class Et {
453
453
  constructor() {
454
454
  this.start = (t, s, i = document) => {
455
455
  const r = `${t}:${s}`, o = this.debugging.get(r) ?? [];
456
- o.some((c) => c.root === i) || (J(t, i)?.addEvent(s, this.doDebug), o.push({ selector: t, eventType: s, root: i }), this.debugging.set(r, o));
456
+ o.some((c) => c.root === i) || (Y(t, i)?.addEvent(s, this.doDebug), o.push({ selector: t, eventType: s, root: i }), this.debugging.set(r, o));
457
457
  }, this.stop = (t, s, i = document) => {
458
458
  const r = `${t}:${s}`, o = this.debugging.get(r);
459
459
  if (!o) return;
460
460
  const a = o.findIndex((c) => c.root === i);
461
- a !== -1 && (J(t, i)?.removeEvent(s, this.doDebug), o.splice(a, 1), o.length === 0 && this.debugging.delete(r));
461
+ a !== -1 && (Y(t, i)?.removeEvent(s, this.doDebug), o.splice(a, 1), o.length === 0 && this.debugging.delete(r));
462
462
  }, this.stopAll = () => {
463
463
  this.debugging.forEach((t) => {
464
464
  t.forEach(({ selector: s, eventType: i, root: r }) => {
465
- J(s, r)?.removeEvent(i, this.doDebug);
465
+ Y(s, r)?.removeEvent(i, this.doDebug);
466
466
  });
467
467
  }), this.debugging.clear();
468
468
  }, this.doDebug = (t) => {
@@ -646,7 +646,7 @@ class Ae {
646
646
  }
647
647
  }
648
648
  const Mt = new xt(), Lt = new Et(), lt = new _t(), X = new Tt();
649
- typeof window < "u" && (window.$ = J, window.log = lt, window.debug = Lt, window.storage = X, window.params = Mt);
649
+ typeof window < "u" && (window.$ = Y, window.log = lt, window.debug = Lt, window.storage = X, window.params = Mt);
650
650
  window.addEventListener("load", () => {
651
651
  lt.success("ZS3 v" + T.version() + " loaded");
652
652
  });
@@ -962,7 +962,7 @@ class At {
962
962
  }
963
963
  }
964
964
  const He = new At();
965
- class Oe {
965
+ class Re {
966
966
  /**
967
967
  * Crea una nova instància del Router.
968
968
  *
@@ -1494,7 +1494,7 @@ class U extends Error {
1494
1494
  return this.status === 408 || this.message.includes("timeout");
1495
1495
  }
1496
1496
  }
1497
- class Re {
1497
+ class Oe {
1498
1498
  constructor(t = {}) {
1499
1499
  this.requestInterceptors = [], this.responseInterceptors = [], this.errorInterceptors = [], this.baseUrl = (t.baseUrl ?? "").replace(/\/+$/, ""), this.defaultTimeout = t.timeout ?? 1e4, this.defaultRetries = t.retries ?? 0, this.defaultRetryDelay = t.retryDelay ?? 1e3, this.defaultHeaders = {
1500
1500
  "Content-Type": "application/json",
@@ -1684,7 +1684,7 @@ const Pt = (e, t = {}) => {
1684
1684
  }
1685
1685
  e.dispatchEvent(r);
1686
1686
  }, Ht = (e, t, s, i, r, o) => {
1687
- const a = Ot(t, s, i, r), c = r, l = e, m = () => {
1687
+ const a = Rt(t, s, i, r), c = r, l = e, m = () => {
1688
1688
  switch (st(e, "zs3-float-show-start", t), l._floatIsShown = !0, t) {
1689
1689
  case "top":
1690
1690
  e.style.top = `${c}px`;
@@ -1722,7 +1722,7 @@ const Pt = (e, t = {}) => {
1722
1722
  }, o * 1e3);
1723
1723
  }, g = l._floatShowHandler, p = l._floatHideHandler;
1724
1724
  g && e.removeEventListener("mouseenter", g), p && e.removeEventListener("mouseleave", p), l._floatShowHandler = m, l._floatHideHandler = b, e.addEventListener("mouseenter", m), e.addEventListener("mouseleave", b);
1725
- }, Ot = (e, t, s, i) => {
1725
+ }, Rt = (e, t, s, i) => {
1726
1726
  switch (e) {
1727
1727
  case "top":
1728
1728
  case "bottom":
@@ -1731,7 +1731,7 @@ const Pt = (e, t = {}) => {
1731
1731
  case "right":
1732
1732
  return -t.width * s + i;
1733
1733
  }
1734
- }, W = (e, t, s) => {
1734
+ }, J = (e, t, s) => {
1735
1735
  const i = new CustomEvent(t, {
1736
1736
  detail: s,
1737
1737
  bubbles: !0,
@@ -1744,7 +1744,7 @@ const Pt = (e, t = {}) => {
1744
1744
  console.error(`Error executing ${t} attribute:`, o);
1745
1745
  }
1746
1746
  e.dispatchEvent(i);
1747
- }, Rt = (e) => {
1747
+ }, Ot = (e) => {
1748
1748
  const { container: t, dragHandle: s = t, direction: i = "xy" } = e;
1749
1749
  if (!t)
1750
1750
  return console.warn("move: container is required"), null;
@@ -1757,7 +1757,7 @@ const Pt = (e, t = {}) => {
1757
1757
  if (S.button !== 0) return;
1758
1758
  a = !0, c = S.clientX, l = S.clientY;
1759
1759
  const et = window.getComputedStyle(t);
1760
- m = parseFloat(et.left) || 0, b = parseFloat(et.top) || 0, g = m, p = b, $.clear(), t.classList.add("zs3-dragging"), s.style.cursor = "grabbing", S.preventDefault(), W(t, "zs3-move-start", {
1760
+ m = parseFloat(et.left) || 0, b = parseFloat(et.top) || 0, g = m, p = b, $.clear(), t.classList.add("zs3-dragging"), s.style.cursor = "grabbing", S.preventDefault(), J(t, "zs3-move-start", {
1761
1761
  direction: i,
1762
1762
  element: t,
1763
1763
  startX: m,
@@ -1769,14 +1769,14 @@ const Pt = (e, t = {}) => {
1769
1769
  let B = m + et, F = b + wt;
1770
1770
  const pt = ht.width - ut.width, mt = ht.height - ut.height, N = /* @__PURE__ */ new Set();
1771
1771
  B <= 0 && (B = 0, N.add("left")), B >= pt && (B = pt, N.add("right")), F <= 0 && (F = 0, N.add("top")), F >= mt && (F = mt, N.add("bottom")), N.forEach((ft) => {
1772
- $.has(ft) || W(t, "zs3-move-boundary", {
1772
+ $.has(ft) || J(t, "zs3-move-boundary", {
1773
1773
  direction: i,
1774
1774
  element: t,
1775
1775
  x: B,
1776
1776
  y: F,
1777
1777
  boundary: ft
1778
1778
  });
1779
- }), $ = N, (i === "x" || i === "xy") && (t.style.left = `${B}px`, g = B), (i === "y" || i === "xy") && (t.style.top = `${F}px`, p = F), W(t, "zs3-move", {
1779
+ }), $ = N, (i === "x" || i === "xy") && (t.style.left = `${B}px`, g = B), (i === "y" || i === "xy") && (t.style.top = `${F}px`, p = F), J(t, "zs3-move", {
1780
1780
  direction: i,
1781
1781
  element: t,
1782
1782
  x: g,
@@ -1785,14 +1785,14 @@ const Pt = (e, t = {}) => {
1785
1785
  deltaY: p - b
1786
1786
  });
1787
1787
  }, q = () => {
1788
- a && (a = !1, t.classList.remove("zs3-dragging"), s.style.cursor = "grab", W(t, "zs3-move-end", {
1788
+ a && (a = !1, t.classList.remove("zs3-dragging"), s.style.cursor = "grab", J(t, "zs3-move-end", {
1789
1789
  direction: i,
1790
1790
  element: t,
1791
1791
  endX: g,
1792
1792
  endY: p
1793
1793
  }), document.removeEventListener("mousemove", D), document.removeEventListener("mouseup", q), document.removeEventListener("keydown", j));
1794
1794
  }, j = (S) => {
1795
- S.key === "Escape" && a && (a = !1, t.classList.remove("zs3-dragging"), s.style.cursor = "grab", (i === "x" || i === "xy") && (t.style.left = `${m}px`), (i === "y" || i === "xy") && (t.style.top = `${b}px`), W(t, "zs3-move-cancel", {
1795
+ S.key === "Escape" && a && (a = !1, t.classList.remove("zs3-dragging"), s.style.cursor = "grab", (i === "x" || i === "xy") && (t.style.left = `${m}px`), (i === "y" || i === "xy") && (t.style.top = `${b}px`), J(t, "zs3-move-cancel", {
1796
1796
  direction: i,
1797
1797
  element: t
1798
1798
  }), document.removeEventListener("mousemove", D), document.removeEventListener("mouseup", q), document.removeEventListener("keydown", j));
@@ -1831,7 +1831,7 @@ class k extends HTMLElement {
1831
1831
  slotAssignment: this._options.slotAssignment,
1832
1832
  clonable: this._options.clonable,
1833
1833
  serializable: this._options.serializable
1834
- })), this.initialize(), this.emitLifecycleEvent("zs3-built", { phase: "complete" });
1834
+ })), this.initialize(), this.emitLifecycleEvent("zs3-built", { phase: "complete" }), this.$ = (s) => Y(s, this.shadowRoot ?? this._container ?? void 0);
1835
1835
  }
1836
1836
  /**
1837
1837
  * Initialize component (called in constructor)
@@ -1909,7 +1909,7 @@ class k extends HTMLElement {
1909
1909
  "log",
1910
1910
  "window",
1911
1911
  b
1912
- ).call(this, l, s, J, lt, window), m;
1912
+ ).call(this, l, s, Y, lt, window), m;
1913
1913
  }
1914
1914
  /**
1915
1915
  * Emit lifecycle event (internal use)
@@ -1985,7 +1985,7 @@ class k extends HTMLElement {
1985
1985
  const t = this.getAttribute("move"), s = this._moveContainerSelector === ":host" ? this : this.qs(this._moveContainerSelector);
1986
1986
  if (!s) return;
1987
1987
  let i;
1988
- this._moveDragSelector ? i = this._moveDragSelector === ":host" ? this : this.qs(this._moveDragSelector) : i = s, i && (t && ["x", "y", "xy"].includes(t) ? Rt({ container: s, dragHandle: i, direction: t }) : Bt(i));
1988
+ this._moveDragSelector ? i = this._moveDragSelector === ":host" ? this : this.qs(this._moveDragSelector) : i = s, i && (t && ["x", "y", "xy"].includes(t) ? Ot({ container: s, dragHandle: i, direction: t }) : Bt(i));
1989
1989
  }
1990
1990
  /**
1991
1991
  * Request an animation frame update
@@ -2107,7 +2107,7 @@ class k extends HTMLElement {
2107
2107
  */
2108
2108
  handleLocaleChange(t) {
2109
2109
  const s = t;
2110
- this.onLocaleChange(s.detail.locale), this._mounted && (this.render(), this.applyFloatEffect(), this.applyMoveEffect());
2110
+ this.onLocaleChange(s.detail.locale);
2111
2111
  }
2112
2112
  /**
2113
2113
  * Hook called when locale changes
@@ -3681,7 +3681,7 @@ u = w([
3681
3681
  ], u);
3682
3682
  customElements.get("zs3-form") || customElements.define("zs3-form", u);
3683
3683
  typeof window < "u" && (window.$Form = u);
3684
- var Zt = Object.defineProperty, te = Object.getOwnPropertyDescriptor, Y = (e, t, s, i) => {
3684
+ var Zt = Object.defineProperty, te = Object.getOwnPropertyDescriptor, W = (e, t, s, i) => {
3685
3685
  for (var r = i > 1 ? void 0 : i ? te(t, s) : t, o = e.length - 1, a; o >= 0; o--)
3686
3686
  (a = e[o]) && (r = (i ? a(t, s, r) : a(r)) || r);
3687
3687
  return i && r && Zt(t, s, r), r;
@@ -3755,22 +3755,22 @@ let H = class extends u {
3755
3755
  }), e.appendChild(t), this._buttons.push(t);
3756
3756
  }
3757
3757
  };
3758
- Y([
3758
+ W([
3759
3759
  n("show-register", { type: "boolean" })
3760
3760
  ], H.prototype, "showRegister", 2);
3761
- Y([
3761
+ W([
3762
3762
  n("login-text", { type: "string" })
3763
3763
  ], H.prototype, "loginText", 2);
3764
- Y([
3764
+ W([
3765
3765
  n("register-text", { type: "string" })
3766
3766
  ], H.prototype, "registerText", 2);
3767
- Y([
3767
+ W([
3768
3768
  n("i18n-login-text", { type: "string" })
3769
3769
  ], H.prototype, "i18nLoginText", 2);
3770
- Y([
3770
+ W([
3771
3771
  n("i18n-register-text", { type: "string" })
3772
3772
  ], H.prototype, "i18nRegisterText", 2);
3773
- H = Y([
3773
+ H = W([
3774
3774
  x("zs3-login-form"),
3775
3775
  E(ee, { inherit: !0 })
3776
3776
  ], H);
@@ -5331,7 +5331,7 @@ rt = yt([
5331
5331
  E(xe)
5332
5332
  ], rt);
5333
5333
  typeof window < "u" && (window.$SelectTheme = rt);
5334
- var _e = Object.defineProperty, Te = Object.getOwnPropertyDescriptor, O = (e, t, s, i) => {
5334
+ var _e = Object.defineProperty, Te = Object.getOwnPropertyDescriptor, R = (e, t, s, i) => {
5335
5335
  for (var r = i > 1 ? void 0 : i ? Te(t, s) : t, o = e.length - 1, a; o >= 0; o--)
5336
5336
  (a = e[o]) && (r = (i ? a(t, s, r) : a(r)) || r);
5337
5337
  return i && r && _e(t, s, r), r;
@@ -5673,28 +5673,28 @@ let L = class extends k {
5673
5673
  });
5674
5674
  }
5675
5675
  };
5676
- O([
5676
+ R([
5677
5677
  n("direction", { type: "string", default: "row" })
5678
5678
  ], L.prototype, "direction", 2);
5679
- O([
5679
+ R([
5680
5680
  n("float", { type: "string" })
5681
5681
  ], L.prototype, "float", 2);
5682
- O([
5682
+ R([
5683
5683
  n("align", { type: "string" })
5684
5684
  ], L.prototype, "align", 2);
5685
- O([
5685
+ R([
5686
5686
  n("gap", { type: "string" })
5687
5687
  ], L.prototype, "gap", 2);
5688
- O([
5688
+ R([
5689
5689
  n("variant", { type: "string" })
5690
5690
  ], L.prototype, "variant", 2);
5691
- O([
5691
+ R([
5692
5692
  n("rounded", { type: "boolean" })
5693
5693
  ], L.prototype, "rounded", 2);
5694
- O([
5694
+ R([
5695
5695
  n("i18n-aria-label", { type: "string" })
5696
5696
  ], L.prototype, "i18nAriaLabel", 2);
5697
- L = O([
5697
+ L = R([
5698
5698
  x("zs3-toolbar"),
5699
5699
  E(Me),
5700
5700
  vt(".toolbar"),
@@ -5702,7 +5702,7 @@ L = O([
5702
5702
  ], L);
5703
5703
  customElements.get("zs3-toolbar") || customElements.define("zs3-toolbar", L);
5704
5704
  typeof window < "u" && (window.$Toolbar = L);
5705
- var Le = Object.defineProperty, Ce = Object.getOwnPropertyDescriptor, R = (e, t, s, i) => {
5705
+ var Le = Object.defineProperty, Ce = Object.getOwnPropertyDescriptor, O = (e, t, s, i) => {
5706
5706
  for (var r = i > 1 ? void 0 : i ? Ce(t, s) : t, o = e.length - 1, a; o >= 0; o--)
5707
5707
  (a = e[o]) && (r = (i ? a(t, s, r) : a(r)) || r);
5708
5708
  return i && r && Le(t, s, r), r;
@@ -5879,28 +5879,28 @@ let C = class extends k {
5879
5879
  this.setAttribute("title", e);
5880
5880
  }
5881
5881
  };
5882
- R([
5882
+ O([
5883
5883
  n("title", { type: "string" })
5884
5884
  ], C.prototype, "windowTitle", 2);
5885
- R([
5885
+ O([
5886
5886
  n("width", { type: "string" })
5887
5887
  ], C.prototype, "width", 2);
5888
- R([
5888
+ O([
5889
5889
  n("height", { type: "string" })
5890
5890
  ], C.prototype, "height", 2);
5891
- R([
5891
+ O([
5892
5892
  n("closable", { type: "boolean" })
5893
5893
  ], C.prototype, "closable", 2);
5894
- R([
5894
+ O([
5895
5895
  n("minimizable", { type: "boolean" })
5896
5896
  ], C.prototype, "minimizable", 2);
5897
- R([
5897
+ O([
5898
5898
  n("maximizable", { type: "boolean" })
5899
5899
  ], C.prototype, "maximizable", 2);
5900
- R([
5900
+ O([
5901
5901
  n("i18n-title", { type: "string" })
5902
5902
  ], C.prototype, "i18nTitle", 2);
5903
- C = R([
5903
+ C = O([
5904
5904
  x("zs3-window"),
5905
5905
  E([
5906
5906
  "title",
@@ -5922,7 +5922,7 @@ C = R([
5922
5922
  customElements.get("zs3-window") || customElements.define("zs3-window", C);
5923
5923
  typeof window < "u" && (window.$Window = C);
5924
5924
  export {
5925
- J as $,
5925
+ Y as $,
5926
5926
  k as $BaseComponent,
5927
5927
  f as $Button,
5928
5928
  Et as $Debug,
@@ -5950,11 +5950,11 @@ export {
5950
5950
  At as DIContainer,
5951
5951
  $t as EventBus,
5952
5952
  vt as Float,
5953
- Re as HttpClient,
5953
+ Oe as HttpClient,
5954
5954
  U as HttpError,
5955
5955
  Ft as Move,
5956
5956
  E as ObservedAttributes,
5957
- Oe as Router,
5957
+ Re as Router,
5958
5958
  Ct as ThemeChangeEvent,
5959
5959
  K as ThemeManager,
5960
5960
  T as ZS3,
@@ -5972,7 +5972,7 @@ export {
5972
5972
  bt as initThemeSystem,
5973
5973
  Be as isMoveEnabled,
5974
5974
  lt as log,
5975
- Rt as move,
5975
+ Ot as move,
5976
5976
  Mt as params,
5977
5977
  Pe as setCSSVariable,
5978
5978
  X as storage,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zs3-ui-components",
3
- "version": "1.2.0",
3
+ "version": "1.2.2",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",