@webority/ui-elements 0.6.12 → 0.6.13

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.
@@ -564,24 +564,24 @@ var l = Symbol("wui.trustedHtml"), u = (e) => String(e ?? "").replace(/&/g, "&am
564
564
  "Th",
565
565
  "Fr",
566
566
  "Sa"
567
- ], D = (e) => String(e).padStart(2, "0"), O = (e, t, n) => `${e}-${D(t + 1)}-${D(n)}`, k = (e) => {
567
+ ], D = (e) => String(e).padStart(2, "0"), ee = (e, t, n) => `${e}-${D(t + 1)}-${D(n)}`, O = (e) => {
568
568
  let t = /^(\d{4})-(\d{2})-(\d{2})$/.exec(e || "");
569
569
  return t ? {
570
570
  y: +t[1],
571
571
  m: t[2] - 1,
572
572
  d: +t[3]
573
573
  } : null;
574
- }, A = (e) => {
575
- let t = k(e);
574
+ }, k = (e) => {
575
+ let t = O(e);
576
576
  return t ? `${D(t.d)} ${T[t.m].slice(0, 3)} ${t.y}` : "";
577
- }, j = (e, t) => new Date(e, t + 1, 0).getDate(), M = (e, t) => {
577
+ }, A = (e, t) => new Date(e, t + 1, 0).getDate(), j = (e, t) => {
578
578
  for (; t < 0;) t += 12, --e;
579
579
  for (; t > 11;) t -= 12, e += 1;
580
580
  return {
581
581
  y: e,
582
582
  m: t
583
583
  };
584
- }, N = class extends HTMLElement {
584
+ }, M = class extends HTMLElement {
585
585
  static get observedAttributes() {
586
586
  return [
587
587
  "start",
@@ -624,13 +624,13 @@ var l = Symbol("wui.trustedHtml"), u = (e) => String(e ?? "").replace(/&/g, "&am
624
624
  text: e,
625
625
  empty: !0
626
626
  } : {
627
- text: `${A(this._start) || "Start"} – ${A(this._end) || "End"}`,
627
+ text: `${k(this._start) || "Start"} – ${k(this._end) || "End"}`,
628
628
  empty: !1
629
629
  };
630
630
  }
631
631
  render() {
632
632
  this._start = this.getAttribute("start") || this._start, this._end = this.getAttribute("end") || this._end;
633
- let e = k(this._start);
633
+ let e = O(this._start);
634
634
  e && (this._viewY = e.y, this._viewM = e.m);
635
635
  let t = this.getAttribute("size"), n = t === "sm" ? " input-sm" : t === "lg" ? " input-lg" : "", { text: r, empty: i } = this._label();
636
636
  this.innerHTML = `
@@ -658,20 +658,20 @@ var l = Symbol("wui.trustedHtml"), u = (e) => String(e ?? "").replace(/&/g, "&am
658
658
  r || (r = document.createElement("input"), r.type = "hidden", r.setAttribute("data-range-mirror", e), this.appendChild(r)), r.name = t, r.value = n || "";
659
659
  }
660
660
  _limits() {
661
- let e = k(this.getAttribute("min")), t = k(this.getAttribute("max")), n = e ? new Date(e.y, e.m, e.d).getTime() : -Infinity, r = t ? new Date(t.y, t.m, t.d).getTime() : Infinity;
661
+ let e = O(this.getAttribute("min")), t = O(this.getAttribute("max")), n = e ? new Date(e.y, e.m, e.d).getTime() : -Infinity, r = t ? new Date(t.y, t.m, t.d).getTime() : Infinity;
662
662
  return (e, t, i) => {
663
663
  let a = new Date(e, t, i).getTime();
664
664
  return a < n || a > r;
665
665
  };
666
666
  }
667
667
  _monthHtml(e, t) {
668
- let n = this._firstDay(), r = (new Date(e, t, 1).getDay() - n + 7) % 7, i = j(e, t), a = this._limits(), o = E.map((e, t) => E[(t + n) % 7]).map((e) => `<span>${e}</span>`).join(""), s = (e, t, n, r) => {
669
- let i = O(e, t, n), o = a(e, t, n);
668
+ let n = this._firstDay(), r = (new Date(e, t, 1).getDay() - n + 7) % 7, i = A(e, t), a = this._limits(), o = E.map((e, t) => E[(t + n) % 7]).map((e) => `<span>${e}</span>`).join(""), s = (e, t, n, r) => {
669
+ let i = ee(e, t, n), o = a(e, t, n);
670
670
  return `<button type="button" class="${["datepicker-day", r ? "is-outside" : ""].filter(Boolean).join(" ")}" data-iso="${i}"${o ? " disabled" : ""}>${n}</button>`;
671
- }, c = "", l = M(e, t - 1), u = j(l.y, l.m);
671
+ }, c = "", l = j(e, t - 1), u = A(l.y, l.m);
672
672
  for (let e = r - 1; e >= 0; e--) c += s(l.y, l.m, u - e, !0);
673
673
  for (let n = 1; n <= i; n++) c += s(e, t, n, !1);
674
- let d = M(e, t + 1), f = (7 - (r + i) % 7) % 7;
674
+ let d = j(e, t + 1), f = (7 - (r + i) % 7) % 7;
675
675
  for (let e = 1; e <= f; e++) c += s(d.y, d.m, e, !0);
676
676
  return `
677
677
  <div class="daterange-cal">
@@ -683,7 +683,7 @@ var l = Symbol("wui.trustedHtml"), u = (e) => String(e ?? "").replace(/&/g, "&am
683
683
  _renderView() {
684
684
  let e = this.querySelector(".daterange-pop");
685
685
  if (!e) return;
686
- let t = M(this._viewY, this._viewM + 1);
686
+ let t = j(this._viewY, this._viewM + 1);
687
687
  e.innerHTML = `
688
688
  <div class="daterange-head">
689
689
  <button type="button" class="datepicker-nav-btn" data-nav="-1" aria-label="Previous month"><i class="bi bi-chevron-left" aria-hidden="true"></i></button>
@@ -709,7 +709,7 @@ var l = Symbol("wui.trustedHtml"), u = (e) => String(e ?? "").replace(/&/g, "&am
709
709
  n.classList.toggle("is-range-start", i), n.classList.toggle("is-range-end", a), n.classList.toggle("in-range", o);
710
710
  }
711
711
  let i = e.querySelector("[data-range-hint]");
712
- i && (i.textContent = this._start ? this._end ? `${A(this._start)} – ${A(this._end)}` : "Pick an end date" : "Pick a start date");
712
+ i && (i.textContent = this._start ? this._end ? `${k(this._start)} – ${k(this._end)}` : "Pick an end date" : "Pick a start date");
713
713
  }
714
714
  _position(e, t) {
715
715
  i(e, t);
@@ -730,7 +730,7 @@ var l = Symbol("wui.trustedHtml"), u = (e) => String(e ?? "").replace(/&/g, "&am
730
730
  if (!e || !t) return;
731
731
  let r = () => !t.hidden;
732
732
  this._open = () => {
733
- let r = k(this._start);
733
+ let r = O(this._start);
734
734
  if (r) this._viewY = r.y, this._viewM = r.m;
735
735
  else {
736
736
  let e = /* @__PURE__ */ new Date();
@@ -743,7 +743,7 @@ var l = Symbol("wui.trustedHtml"), u = (e) => String(e ?? "").replace(/&/g, "&am
743
743
  this._popClick = !0;
744
744
  let t = e.target.closest("[data-nav]");
745
745
  if (t) {
746
- let e = M(this._viewY, this._viewM + Number(t.dataset.nav));
746
+ let e = j(this._viewY, this._viewM + Number(t.dataset.nav));
747
747
  this._viewY = e.y, this._viewM = e.m, this._renderView();
748
748
  return;
749
749
  }
@@ -768,7 +768,7 @@ var l = Symbol("wui.trustedHtml"), u = (e) => String(e ?? "").replace(/&/g, "&am
768
768
  disconnectedCallback() {
769
769
  this._onDocClick && document.removeEventListener("click", this._onDocClick), this._onDocKey && document.removeEventListener("keydown", this._onDocKey), o(this);
770
770
  }
771
- }, P = class extends HTMLElement {
771
+ }, N = class extends HTMLElement {
772
772
  _accessibleName() {
773
773
  return this.getAttribute("aria-label") || this.getAttribute("placeholder") || "Select";
774
774
  }
@@ -838,13 +838,13 @@ var l = Symbol("wui.trustedHtml"), u = (e) => String(e ?? "").replace(/&/g, "&am
838
838
  let e = this.hasAttribute("searchable"), t = this.getAttribute("search-placeholder") || "Search…", n = this.getAttribute("icon"), r = this.getAttribute("size"), i = r === "sm" ? " search-select-sm" : r === "lg" ? " search-select-lg" : "";
839
839
  c(this, this._values.join(",")), this.innerHTML = `
840
840
  <div class="search-select${i}">
841
- <div class="input search-select-control search-select-multi" role="combobox" aria-haspopup="listbox" aria-expanded="false" aria-label="${F(this._accessibleName())}"${this.hasAttribute("disabled") ? " aria-disabled=\"true\"" : ""}>
842
- ${n ? `<i class="bi bi-${F(n)} search-select-icon" aria-hidden="true"></i>` : ""}
841
+ <div class="input search-select-control search-select-multi" role="combobox" aria-haspopup="listbox" aria-expanded="false" aria-label="${P(this._accessibleName())}"${this.hasAttribute("disabled") ? " aria-disabled=\"true\"" : ""}>
842
+ ${n ? `<i class="bi bi-${P(n)} search-select-icon" aria-hidden="true"></i>` : ""}
843
843
  <div class="ms-chips" data-chips></div>
844
844
  <i class="bi bi-chevron-down search-select-caret" aria-hidden="true"></i>
845
845
  </div>
846
846
  <div class="search-select-menu search-select-menu-fixed" role="listbox" aria-multiselectable="true" tabindex="-1" hidden>
847
- ${e ? `<div class="search-select-search"><i class="bi bi-search" aria-hidden="true"></i><input class="search-select-input" placeholder="${F(t)}" aria-autocomplete="list" /><button type="button" class="search-select-clear" aria-label="Clear search" hidden><i class="bi bi-x" aria-hidden="true"></i></button></div>` : ""}
847
+ ${e ? `<div class="search-select-search"><i class="bi bi-search" aria-hidden="true"></i><input class="search-select-input" placeholder="${P(t)}" aria-autocomplete="list" /><button type="button" class="search-select-clear" aria-label="Clear search" hidden><i class="bi bi-x" aria-hidden="true"></i></button></div>` : ""}
848
848
  <div class="search-select-options"></div>
849
849
  <div class="search-select-empty" hidden>No matches</div>
850
850
  </div>
@@ -858,7 +858,7 @@ var l = Symbol("wui.trustedHtml"), u = (e) => String(e ?? "").replace(/&/g, "&am
858
858
  e.innerHTML = `<span class="search-select-placeholder">${u(t)}</span>`;
859
859
  return;
860
860
  }
861
- e.innerHTML = this._values.map((e) => `<span class="chip chip-sm"><span class="chip-label">${this._labelHtmlFor(e)}</span><button type="button" class="chip-remove" data-remove="${F(e)}" aria-label="Remove"><i class="bi bi-x" aria-hidden="true"></i></button></span>`).join(""), this._collapseChips();
861
+ e.innerHTML = this._values.map((e) => `<span class="chip chip-sm"><span class="chip-label">${this._labelHtmlFor(e)}</span><button type="button" class="chip-remove" data-remove="${P(e)}" aria-label="Remove"><i class="bi bi-x" aria-hidden="true"></i></button></span>`).join(""), this._collapseChips();
862
862
  }
863
863
  _collapseChips() {
864
864
  let e = this.querySelector("[data-chips]");
@@ -882,9 +882,9 @@ var l = Symbol("wui.trustedHtml"), u = (e) => String(e ?? "").replace(/&/g, "&am
882
882
  let t = this.querySelector(".search-select-options"), n = this.querySelector(".search-select-empty");
883
883
  if (!t) return;
884
884
  let r = (e || "").trim().toLowerCase(), i = this._readOptions();
885
- r && (i = i.filter((e) => ee(e.label).toLowerCase().includes(r))), t.innerHTML = i.map((e) => {
885
+ r && (i = i.filter((e) => te(e.label).toLowerCase().includes(r))), t.innerHTML = i.map((e) => {
886
886
  let t = this._values.includes(String(e.value));
887
- return `<button type="button" role="option" class="search-select-option${t ? " selected" : ""}" data-value="${F(e.value)}" aria-selected="${t}"><span class="ms-opt-label">${f(e)}</span><span class="ms-check"><i class="bi bi-check" aria-hidden="true"></i></span></button>`;
887
+ return `<button type="button" role="option" class="search-select-option${t ? " selected" : ""}" data-value="${P(e.value)}" aria-selected="${t}"><span class="ms-opt-label">${f(e)}</span><span class="ms-check"><i class="bi bi-check" aria-hidden="true"></i></span></button>`;
888
888
  }).join(""), n && (n.hidden = i.length > 0), this._active = -1;
889
889
  }
890
890
  _wire() {
@@ -946,7 +946,7 @@ var l = Symbol("wui.trustedHtml"), u = (e) => String(e ?? "").replace(/&/g, "&am
946
946
  disconnectedCallback() {
947
947
  this._onDocClick && document.removeEventListener("click", this._onDocClick), o(this), this._ro?.disconnect(), this._ro = null;
948
948
  }
949
- }, F = (e) => String(e ?? "").replace(/"/g, "&quot;").replace(/</g, "&lt;"), ee = (e) => String(e ?? "").replace(/<[^>]*>/g, ""), I = /[^0-9]/g, L = /[^0-9a-zA-Z]/g, R = class extends HTMLElement {
949
+ }, P = (e) => String(e ?? "").replace(/"/g, "&quot;").replace(/</g, "&lt;"), te = (e) => String(e ?? "").replace(/<[^>]*>/g, ""), ne = /[^0-9]/g, re = /[^0-9a-zA-Z]/g, F = class extends HTMLElement {
950
950
  static get observedAttributes() {
951
951
  return [
952
952
  "value",
@@ -976,7 +976,7 @@ var l = Symbol("wui.trustedHtml"), u = (e) => String(e ?? "").replace(/&/g, "&am
976
976
  this._value = this._clean(e), c(this, this._value), this._paint();
977
977
  }
978
978
  _clean(e) {
979
- return (e == null ? "" : String(e)).replace(this.mode === "alphanumeric" ? L : I, "").slice(0, this.length);
979
+ return (e == null ? "" : String(e)).replace(this.mode === "alphanumeric" ? re : ne, "").slice(0, this.length);
980
980
  }
981
981
  connectedCallback() {
982
982
  this._rendered || this.render();
@@ -1042,7 +1042,7 @@ var l = Symbol("wui.trustedHtml"), u = (e) => String(e ?? "").replace(/&/g, "&am
1042
1042
  document.activeElement === e && this._paint();
1043
1043
  });
1044
1044
  }
1045
- }, z = [
1045
+ }, I = [
1046
1046
  [
1047
1047
  "AF",
1048
1048
  "Afghanistan",
@@ -2268,11 +2268,67 @@ var l = Symbol("wui.trustedHtml"), u = (e) => String(e ?? "").replace(/&/g, "&am
2268
2268
  "Zimbabwe",
2269
2269
  "263"
2270
2270
  ]
2271
- ], B = (e) => (z.find((t) => t[0] === e) || [
2271
+ ], L = (e) => (I.find((t) => t[0] === e) || [
2272
2272
  "",
2273
2273
  "",
2274
2274
  ""
2275
- ])[2], V = (e) => `wui-flag wui-flag-${String(e).toLowerCase()}`, H = class extends HTMLElement {
2275
+ ])[2], R = (e) => `wui-flag wui-flag-${String(e).toLowerCase()}`, z = null, B = null;
2276
+ function ie() {
2277
+ return z ? Promise.resolve(z) : (B ||= Promise.all([import("./libphonenumber-js-BcNT8oq0.js"), import("./examples.mobile.json-BMXTGiGC.js")]).then(([e, t]) => (z = {
2278
+ AsYouType: e.AsYouType,
2279
+ getExampleNumber: e.getExampleNumber,
2280
+ isValidPhoneNumber: e.isValidPhoneNumber,
2281
+ examples: t.default || t
2282
+ }, z)).catch(() => null), B);
2283
+ }
2284
+ function V(e, t) {
2285
+ if (!z || !t) return t;
2286
+ try {
2287
+ return new z.AsYouType(e).input(t);
2288
+ } catch {
2289
+ return t;
2290
+ }
2291
+ }
2292
+ function H(e) {
2293
+ if (!z) return null;
2294
+ try {
2295
+ return z.getExampleNumber(e, z.examples)?.formatNational() || null;
2296
+ } catch {
2297
+ return null;
2298
+ }
2299
+ }
2300
+ function U(e) {
2301
+ if (!z || !e) return null;
2302
+ try {
2303
+ return z.isValidPhoneNumber(e);
2304
+ } catch {
2305
+ return null;
2306
+ }
2307
+ }
2308
+ function ae(e) {
2309
+ if (!z) return null;
2310
+ try {
2311
+ let t = z.getExampleNumber(e, z.examples);
2312
+ return t?.nationalNumber ? t.nationalNumber.length : null;
2313
+ } catch {
2314
+ return null;
2315
+ }
2316
+ }
2317
+ function oe(e) {
2318
+ if (!z || !e?.trim().startsWith("+")) return null;
2319
+ try {
2320
+ let t = new z.AsYouType();
2321
+ t.input(e.trim());
2322
+ let n = t.getCountry();
2323
+ return n ? {
2324
+ country: n,
2325
+ national: t.getNationalNumber() || ""
2326
+ } : null;
2327
+ } catch {
2328
+ return null;
2329
+ }
2330
+ }
2331
+ var W = class extends HTMLElement {
2276
2332
  static get observedAttributes() {
2277
2333
  return [
2278
2334
  "value",
@@ -2291,7 +2347,7 @@ var l = Symbol("wui.trustedHtml"), u = (e) => String(e ?? "").replace(/&/g, "&am
2291
2347
  this._rendered && (e === "country" && (this._country = n || "IN"), this.render());
2292
2348
  }
2293
2349
  get value() {
2294
- return `+${B(this._country)}${this._national}`;
2350
+ return `+${L(this._country)}${this._national}`;
2295
2351
  }
2296
2352
  set value(e) {
2297
2353
  this._national = String(e ?? "").replace(/[^0-9]/g, ""), this._commit();
@@ -2300,64 +2356,88 @@ var l = Symbol("wui.trustedHtml"), u = (e) => String(e ?? "").replace(/&/g, "&am
2300
2356
  c(this, this.value), this.dispatchEvent(new Event("change", { bubbles: !0 }));
2301
2357
  }
2302
2358
  render() {
2303
- let e = this.getAttribute("placeholder") || "Enter phone number";
2359
+ let e = this.getAttribute("placeholder") || H(this._country) || "Enter phone number";
2304
2360
  this._country = this.getAttribute("country") || this._country;
2305
- let t = z.map(([e, t, n]) => `<button type="button" role="option" class="country-dropdown-item${e === this._country ? " selected" : ""}" data-iso="${e}"><span class="${V(e)}" aria-hidden="true"></span><span class="country-name-text">${t}<span class="country-code-text">+${n}</span></span></button>`).join("");
2361
+ let t = I.map(([e, t, n]) => `<button type="button" role="option" class="country-dropdown-item${e === this._country ? " selected" : ""}" data-iso="${e}"><span class="${R(e)}" aria-hidden="true"></span><span class="country-name-text">${t}<span class="country-code-text">+${n}</span></span></button>`).join("");
2306
2362
  this.innerHTML = `
2307
2363
  <div class="phone-input-wrap">
2308
2364
  <div class="phone-country-adornment">
2309
2365
  <button type="button" class="country-toggle" aria-haspopup="listbox" aria-expanded="false"${this.hasAttribute("disabled") ? " disabled" : ""}>
2310
- <span class="${V(this._country)}" data-flag aria-hidden="true"></span>
2366
+ <span class="${R(this._country)}" data-flag aria-hidden="true"></span>
2311
2367
  <i class="bi bi-chevron-down phone-chevron" aria-hidden="true"></i>
2312
- <span class="phone-dial" data-dial>+${B(this._country)}</span>
2368
+ <span class="phone-dial" data-dial>+${L(this._country)}</span>
2313
2369
  </button>
2314
2370
  <div class="country-dropdown-menu" role="listbox" hidden>
2315
2371
  <div class="dropdown-search-wrapper"><span class="dropdown-search-icon"><i class="bi bi-search" aria-hidden="true"></i></span><input type="text" class="dropdown-search-input" placeholder="Search country or code" aria-label="Search countries" /></div>
2316
2372
  <div class="country-list-scroll">${t}<div class="country-empty" hidden>No countries found</div></div>
2317
2373
  </div>
2318
2374
  </div>
2319
- <input type="tel" class="input" placeholder="${U(e)}" value="${U(this._national)}"${this.hasAttribute("disabled") ? " disabled" : ""} />
2320
- </div>`, this._rendered = !0, c(this, this.value), this._wire();
2375
+ <input type="tel" class="input" placeholder="${G(e)}" value="${G(V(this._country, this._national))}"${this.hasAttribute("disabled") ? " disabled" : ""} />
2376
+ </div>
2377
+ <div class="field-error" data-phone-error hidden></div>`, this._rendered = !0, c(this, this.value), this._wire();
2321
2378
  }
2322
2379
  _wire() {
2323
- let e = this.querySelector(".country-toggle"), t = this.querySelector(".country-dropdown-menu"), n = this.querySelector(".dropdown-search-input"), r = this.querySelector(".country-list-scroll"), i = this.querySelector(".country-empty"), a = this.querySelector("input[type=tel]"), o = this.querySelector("[data-flag]"), s = this.querySelector("[data-dial]");
2324
- if (!e || !t) return;
2325
- let l = () => !t.hidden, u = () => {
2326
- let n = e.getBoundingClientRect(), r = t.offsetWidth || 320, i = t.offsetHeight || 320, a = window.innerHeight - n.bottom, o = a < i + 6 && n.top > a ? n.top - i - 6 : n.bottom + 6, s = Math.min(Math.max(8, n.left), Math.max(8, window.innerWidth - r - 8));
2327
- t.style.top = `${Math.max(8, o)}px`, t.style.left = `${s}px`;
2328
- }, d = () => {
2329
- t.hidden = !1, e.setAttribute("aria-expanded", "true"), n.value = "", p(""), u(), n.focus();
2380
+ let e = this.querySelector(".country-toggle"), t = this.querySelector(".phone-input-wrap"), n = this.querySelector(".country-dropdown-menu"), r = this.querySelector(".dropdown-search-input"), i = this.querySelector(".country-list-scroll"), a = this.querySelector(".country-empty"), o = this.querySelector("input[type=tel]"), s = this.querySelector("[data-flag]"), l = this.querySelector("[data-dial]");
2381
+ if (!e || !n) return;
2382
+ let u = () => !n.hidden, d = () => {
2383
+ let r = (t || e).getBoundingClientRect(), i = n.offsetWidth || 320, a = n.offsetHeight || 320, o = window.innerHeight - r.bottom, s = o < a + 6 && r.top > o ? r.top - a - 6 : r.bottom + 6, c = Math.min(Math.max(8, r.left), Math.max(8, window.innerWidth - i - 8));
2384
+ n.style.top = `${Math.max(8, s)}px`, n.style.left = `${c}px`;
2330
2385
  }, f = () => {
2331
- t.hidden = !0, e.setAttribute("aria-expanded", "false");
2386
+ n.hidden = !1, e.setAttribute("aria-expanded", "true"), r.value = "", m(""), d(), r.focus();
2387
+ }, p = () => {
2388
+ n.hidden = !0, e.setAttribute("aria-expanded", "false");
2332
2389
  };
2333
2390
  this._reposition = () => {
2334
- l() && u();
2391
+ u() && d();
2335
2392
  }, window.addEventListener("scroll", this._reposition, !0), window.addEventListener("resize", this._reposition);
2336
- let p = (e) => {
2393
+ let m = (e) => {
2337
2394
  let t = e.trim().toLowerCase(), n = 0;
2338
- for (let e of r.querySelectorAll(".country-dropdown-item")) {
2395
+ for (let e of i.querySelectorAll(".country-dropdown-item")) {
2339
2396
  let r = !t || e.textContent.toLowerCase().includes(t);
2340
2397
  e.hidden = !r, r && (n += 1);
2341
2398
  }
2342
- i && (i.hidden = n > 0);
2343
- }, m = (e) => {
2344
- this._country = e, this.setAttribute("country", e), o && (o.className = V(e)), s && (s.textContent = `+${B(e)}`);
2345
- for (let t of r.querySelectorAll(".country-dropdown-item")) t.classList.toggle("selected", t.dataset.iso === e);
2346
- f(), this._commit();
2399
+ a && (a.hidden = n > 0);
2400
+ }, h = (e) => {
2401
+ this._country = e, this.setAttribute("country", e), s && (s.className = R(e)), l && (l.textContent = `+${L(e)}`);
2402
+ for (let t of i.querySelectorAll(".country-dropdown-item")) t.classList.toggle("selected", t.dataset.iso === e);
2403
+ p(), this._commit();
2347
2404
  };
2348
- e.addEventListener("click", () => l() ? f() : d()), n.addEventListener("input", () => p(n.value)), r.addEventListener("click", (e) => {
2405
+ e.addEventListener("click", () => u() ? p() : f()), r.addEventListener("input", () => m(r.value)), i.addEventListener("click", (e) => {
2349
2406
  let t = e.target.closest(".country-dropdown-item");
2350
- t && m(t.dataset.iso);
2351
- }), a.addEventListener("input", () => {
2352
- this._national = a.value.replace(/[^0-9]/g, ""), this._commit();
2407
+ t && h(t.dataset.iso);
2408
+ });
2409
+ let g = this.querySelector("[data-phone-error]"), _ = (e) => {
2410
+ if (o.classList.toggle("is-invalid", e), e ? o.setAttribute("aria-invalid", "true") : o.removeAttribute("aria-invalid"), g) {
2411
+ if (e) {
2412
+ let e = H(this._country);
2413
+ g.textContent = e ? `Enter a valid phone number, e.g. ${e}` : "Enter a valid phone number";
2414
+ }
2415
+ g.hidden = !e;
2416
+ }
2417
+ };
2418
+ o.addEventListener("input", () => {
2419
+ let e = o.value.replace(/[^0-9]/g, ""), t = ae(this._country);
2420
+ t && e.length > t && (e = e.slice(0, t)), this._national = e;
2421
+ let n = V(this._country, this._national);
2422
+ o.value !== n && (o.value = n), this._commit(), o.classList.contains("is-invalid") && (!this._national || U(this.value) === !0) && _(!1);
2423
+ }), o.addEventListener("blur", () => {
2424
+ _(this._national.length > 0 && U(this.value) === !1);
2425
+ }), o.addEventListener("paste", (e) => {
2426
+ let t = oe(e.clipboardData?.getData("text"));
2427
+ t && (e.preventDefault(), this._national = t.national.replace(/[^0-9]/g, ""), t.country === this._country ? o.value = V(this._country, this._national) : this.setAttribute("country", t.country), this._commit(), this.querySelector("input[type=tel]")?.focus());
2353
2428
  }), this._onDocClick = (e) => {
2354
- l() && !this.contains(e.target) && f();
2355
- }, document.addEventListener("click", this._onDocClick), c(this, this.value);
2429
+ u() && !this.contains(e.target) && p();
2430
+ }, document.addEventListener("click", this._onDocClick), ie().then((e) => {
2431
+ if (!(!e || !o) && (this._national && (o.value = V(this._country, this._national)), !this.getAttribute("placeholder"))) {
2432
+ let e = H(this._country);
2433
+ e && (o.placeholder = e);
2434
+ }
2435
+ }), c(this, this.value);
2356
2436
  }
2357
2437
  disconnectedCallback() {
2358
2438
  this._reposition && (window.removeEventListener("scroll", this._reposition, !0), window.removeEventListener("resize", this._reposition)), this._onDocClick && document.removeEventListener("click", this._onDocClick);
2359
2439
  }
2360
- }, U = (e) => String(e ?? "").replace(/"/g, "&quot;").replace(/</g, "&lt;"), W = class extends HTMLElement {
2440
+ }, G = (e) => String(e ?? "").replace(/"/g, "&quot;").replace(/</g, "&lt;"), K = class extends HTMLElement {
2361
2441
  static get observedAttributes() {
2362
2442
  return [
2363
2443
  "value",
@@ -2417,19 +2497,19 @@ var l = Symbol("wui.trustedHtml"), u = (e) => String(e ?? "").replace(/&/g, "&am
2417
2497
  d && (this._value = String(d.value)), c(this, this._value);
2418
2498
  let p = e.map((e) => {
2419
2499
  let t = String(e.value) === String(this._value);
2420
- return `<button type="button" role="option" class="search-select-option${t ? " selected" : ""}" data-value="${G(e.value)}" aria-selected="${t}">${f(e)}</button>`;
2500
+ return `<button type="button" role="option" class="search-select-option${t ? " selected" : ""}" data-value="${q(e.value)}" aria-selected="${t}">${f(e)}</button>`;
2421
2501
  }).join("");
2422
2502
  this.innerHTML = `
2423
2503
  <div class="search-select${this.hasAttribute("compact") ? " search-select-compact" : ""}${i}">
2424
- <button type="button" role="combobox" class="input search-select-control" aria-haspopup="listbox" aria-expanded="false" aria-label="${G(this._accessibleName())}"${this.hasAttribute("disabled") ? " disabled" : ""}>
2425
- ${a ? `<i class="bi bi-${G(a)} search-select-icon" aria-hidden="true"></i>` : ""}
2504
+ <button type="button" role="combobox" class="input search-select-control" aria-haspopup="listbox" aria-expanded="false" aria-label="${q(this._accessibleName())}"${this.hasAttribute("disabled") ? " disabled" : ""}>
2505
+ ${a ? `<i class="bi bi-${q(a)} search-select-icon" aria-hidden="true"></i>` : ""}
2426
2506
  ${o ? `<span class="search-select-prefix">${u(o)}</span>` : ""}
2427
2507
  <span class="${d ? "" : "search-select-placeholder"}" data-label>${d ? f(d) : u(s)}</span>
2428
2508
  ${n ? "<span class=\"search-select-reset\" role=\"button\" aria-label=\"Clear selection\" hidden><i class=\"bi bi-x-lg\" aria-hidden=\"true\"></i></span>" : ""}
2429
2509
  <i class="bi bi-chevron-down search-select-caret" aria-hidden="true"></i>
2430
2510
  </button>
2431
2511
  <div class="search-select-menu search-select-menu-fixed" role="listbox" tabindex="-1" hidden>
2432
- ${t ? `<div class="search-select-search"><i class="bi bi-search" aria-hidden="true"></i><input class="search-select-input" placeholder="${G(l)}" aria-autocomplete="list" /><button type="button" class="search-select-clear" aria-label="Clear search" hidden><i class="bi bi-x" aria-hidden="true"></i></button></div>` : ""}
2512
+ ${t ? `<div class="search-select-search"><i class="bi bi-search" aria-hidden="true"></i><input class="search-select-input" placeholder="${q(l)}" aria-autocomplete="list" /><button type="button" class="search-select-clear" aria-label="Clear search" hidden><i class="bi bi-x" aria-hidden="true"></i></button></div>` : ""}
2433
2513
  <div class="search-select-options">${p}<div class="search-select-empty" hidden>No matches</div></div>
2434
2514
  </div>
2435
2515
  </div>`, this._rendered = !0, c(this, this._value), this._wire(), this._syncReset();
@@ -2521,14 +2601,14 @@ var l = Symbol("wui.trustedHtml"), u = (e) => String(e ?? "").replace(/&/g, "&am
2521
2601
  disconnectedCallback() {
2522
2602
  this._onDocClick && document.removeEventListener("click", this._onDocClick), o(this);
2523
2603
  }
2524
- }, G = (e) => String(e ?? "").replace(/"/g, "&quot;").replace(/</g, "&lt;"), K = "image/png,image/jpeg,image/webp", te = 5, q = {
2604
+ }, q = (e) => String(e ?? "").replace(/"/g, "&quot;").replace(/</g, "&lt;"), J = "image/png,image/jpeg,image/webp", se = 5, ce = {
2525
2605
  "image/png": [".png"],
2526
2606
  "image/jpeg": [".jpg", ".jpeg"],
2527
2607
  "image/webp": [".webp"],
2528
2608
  "image/gif": [".gif"],
2529
2609
  "image/svg+xml": [".svg"],
2530
2610
  "application/pdf": [".pdf"]
2531
- }, J = {
2611
+ }, le = {
2532
2612
  "image/png": "PNG",
2533
2613
  "image/jpeg": "JPG",
2534
2614
  "image/webp": "WEBP",
@@ -2546,7 +2626,7 @@ var l = Symbol("wui.trustedHtml"), u = (e) => String(e ?? "").replace(/&/g, "&am
2546
2626
  function X(e) {
2547
2627
  let t = [];
2548
2628
  for (let n of Y(e)) {
2549
- let e = J[n] || (n.startsWith(".") ? n.slice(1).toUpperCase() : n.toUpperCase());
2629
+ let e = le[n] || (n.startsWith(".") ? n.slice(1).toUpperCase() : n.toUpperCase());
2550
2630
  t.includes(e) || t.push(e);
2551
2631
  }
2552
2632
  return t.length <= 1 ? t[0] || "supported" : `${t.slice(0, -1).join(", ")} or ${t[t.length - 1]}`;
@@ -2555,11 +2635,11 @@ function Z(e, t) {
2555
2635
  let n = Y(t);
2556
2636
  if (!n.length) return !0;
2557
2637
  let r = (e.type || "").toLowerCase(), i = (e.name || "").toLowerCase();
2558
- return n.some((e) => e.startsWith(".") ? i.endsWith(e) : e.endsWith("/*") ? r.startsWith(e.slice(0, -1)) : r && r === e ? !0 : !r && (q[e] || []).some((e) => i.endsWith(e)));
2638
+ return n.some((e) => e.startsWith(".") ? i.endsWith(e) : e.endsWith("/*") ? r.startsWith(e.slice(0, -1)) : r && r === e ? !0 : !r && (ce[e] || []).some((e) => i.endsWith(e)));
2559
2639
  }
2560
- function ne(e, t = {}) {
2640
+ function ue(e, t = {}) {
2561
2641
  if (!e) return null;
2562
- let n = t.accept === void 0 ? K : t.accept, r = t.maxSizeMb || 5;
2642
+ let n = t.accept === void 0 ? J : t.accept, r = t.maxSizeMb || 5;
2563
2643
  return Z(e, n) ? e.size > r * 1024 * 1024 ? `Keep the file under ${r} MB.` : null : `Choose a ${X(n)} file.`;
2564
2644
  }
2565
2645
  //#endregion
@@ -2568,8 +2648,8 @@ var Q = (e, t) => {
2568
2648
  typeof customElements < "u" && !customElements.get(e) && customElements.define(e, t);
2569
2649
  };
2570
2650
  function $() {
2571
- Q("wui-select", W), Q("wui-phone", H), Q("wui-datepicker", w), Q("wui-date-range", N), Q("wui-autocomplete", p), Q("wui-multiselect", P), Q("wui-otp", R), Q("wui-status-icon", n);
2651
+ Q("wui-select", K), Q("wui-phone", W), Q("wui-datepicker", w), Q("wui-date-range", M), Q("wui-autocomplete", p), Q("wui-multiselect", N), Q("wui-otp", F), Q("wui-status-icon", n);
2572
2652
  }
2573
2653
  $();
2574
2654
  //#endregion
2575
- export { K as DEFAULT_IMAGE_ACCEPT, te as DEFAULT_MAX_SIZE_MB, t as STATUS_TONES, p as WuiAutocomplete, w as WuiDatePicker, N as WuiDateRange, P as WuiMultiSelect, R as WuiOtp, H as WuiPhone, W as WuiSelect, n as WuiStatusIcon, X as acceptLabel, $ as defineWeborityElements, Z as matchesAccept, ne as validateFile };
2655
+ export { J as DEFAULT_IMAGE_ACCEPT, se as DEFAULT_MAX_SIZE_MB, t as STATUS_TONES, p as WuiAutocomplete, w as WuiDatePicker, M as WuiDateRange, N as WuiMultiSelect, F as WuiOtp, W as WuiPhone, K as WuiSelect, n as WuiStatusIcon, X as acceptLabel, $ as defineWeborityElements, Z as matchesAccept, ue as validateFile };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webority/ui-elements",
3
- "version": "0.6.12",
3
+ "version": "0.6.13",
4
4
  "description": "Webority framework-agnostic UI custom elements (<wui-*>) — the single implementation of the interactive components, styled by @webority/theme. Used natively in Razor and wrapped by @webority/ui-react.",
5
5
  "license": "SEE LICENSE IN LICENSE",
6
6
  "type": "module",
@@ -26,6 +26,9 @@
26
26
  "sideEffects": [
27
27
  "./dist/*"
28
28
  ],
29
+ "dependencies": {
30
+ "libphonenumber-js": "^1.13.9"
31
+ },
29
32
  "devDependencies": {
30
33
  "vite": "^8.0.12"
31
34
  },