@descope/web-components-ui 3.1.4 → 3.1.5
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.
- package/dist/cjs/index.cjs.js +34 -12
- package/dist/cjs/index.cjs.js.map +1 -1
- package/dist/index.esm.js +34 -12
- package/dist/index.esm.js.map +1 -1
- package/dist/umd/DescopeDev.js +1 -1
- package/dist/umd/DescopeDev.js.map +1 -1
- package/dist/umd/descope-country-subdivision-city-field.js +1 -1
- package/dist/umd/descope-country-subdivision-city-field.js.map +1 -1
- package/dist/umd/index.js +1 -1
- package/package.json +31 -31
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";(self.webpackChunk_descope_web_components_ui=self.webpackChunk_descope_web_components_ui||[]).push([[2478],{68749(i,t,e){e.r(t),e.d(t,{CountrySubdivisionCityFieldClass:()=>L,componentName:()=>$}),e(25003),e(27092);var s=e(72270),o=e(25964),n=e(63200);const r=async i=>{const t=await fetch(i);if(!t.ok)throw new Error(`[dataService] ${t.status} ${i}`);const e=await t.json();return e.data??e},a=async i=>r(`${i}/countries.json`),l=async(i,t)=>{try{return(await r(`${t}/countries/${i}/subdivisions.json`)).map(({code:i,...t})=>({...t,state_code:i}))}catch{return[]}},u=async(i,t,e)=>r(`${e}/countries/${i}/subdivisions/${t}/cities.json`),d=async i=>{const t=new URL("../labels.json",`${i}/`).href;return r(t)},h=async(i,t)=>r(`${t}/countries/${i}/cities.json`),c=(0,o.xE)("country-subdivision-city-field-internal"),b=Symbol("selecting"),y=({name:i,translations:t={}},e)=>e&&(t[e]||t[e.split("-")[0]])||i,p=i=>i?String(i).replace(/[&<>"']/g,i=>`&#${i.charCodeAt(0)};`):"",m=({name:i,iso2:t,iso3:e,translations:s,lang:o})=>{const n=y({name:i,translations:s},o),r=[n,t,e];n!==i&&r.push(i);const a=p(t),l=p(r.join(" ")),u=p(n);return`<div data-id="${a}" data-name="${l}" data-label="${u}">${u}</div>`},v=({name:i,state_code:t,translations:e,lang:s})=>{const o=y({name:i,translations:e},s),n=[o,t];o!==i&&n.push(i);const r=p(t),a=p(n.join(" ")),l=p(o);return`<div data-id="${r}" data-name="${a}" data-label="${l}">${l}</div>`},C=({name:i})=>{const t=p(i),e=p(i);return`<div data-id="${t}" data-name="${e}">${e}</div>`},g=i=>`<descope-combo-box id="${i}" item-label-path="data-name" item-value-path="data-id" allow-custom-value="false"></descope-combo-box>`,x=(0,s.yc)({componentName:c,baseSelector:""}),f=["disabled","readonly","size","bordered"],B=["hide-country","hide-subdivision","hide-city"],S=[...f,"label-type","country-label","subdivision-label","city-label",...B,"default-country","allowed-countries","pinned-countries","country-placeholder","subdivision-placeholder","city-placeholder","required","invalid","data-source-base-url","lang"],V=(0,n.Zz)()(class extends x{static get observedAttributes(){return[].concat(x.observedAttributes||[],S)}#i;#t;#e;#s=!1;#o=!1;#n=new Map;#r=null;#a=null;#l=null;#u=null;constructor(){super(),this.innerHTML=`\n <div class="wrapper">\n ${g("country-combo")}\n ${g("subdivision-combo")}\n ${g("city-combo")}\n </div>\n `,this.#i=this.querySelector("#country-combo"),this.#t=this.querySelector("#subdivision-combo"),this.#e=this.querySelector("#city-combo"),this.#d(),this.#h()}get#c(){return"true"===this.getAttribute("hide-country")}get#b(){return"true"===this.getAttribute("hide-subdivision")}get#y(){return"true"===this.getAttribute("hide-city")}get#p(){return!this.#m}get#m(){return this.getAttribute("data-source-base-url")||void 0}get#v(){const i=this.getAttribute("lang")||void 0;if(i)try{return Intl.getCanonicalLocales(i),i}catch{return}}get#C(){return this.getAttribute("default-country")?.toUpperCase()||void 0}get#g(){return this.getAttribute("subdivision-label")||void 0}get#x(){return this.getAttribute("subdivision-placeholder")||void 0}get#f(){return(this.getAttribute("allowed-countries")||"").split(",").map(i=>i.trim().toUpperCase()).filter(Boolean)}get#B(){return(this.getAttribute("pinned-countries")||"").split(",").map(i=>i.trim().toUpperCase()).filter(Boolean)}get#S(){return[this.#i,this.#t,this.#e]}get value(){return{country:this.#c?this.#C:this.#i.value||void 0,subdivision:!this.#b&&this.#s&&this.#t.value||void 0,city:!this.#y&&this.#o&&this.#e.value||void 0}}set value(i){if(!i)return;let t;try{t="string"==typeof i?JSON.parse(i):i}catch{return}this.#u={...t},this.#m&&this.#V()}init(){this.addEventListener("focus",i=>{if(i.isTrusted){const i=this.#S.find(i=>!i.classList.contains(`${c}-hidden`)&&!i.checkValidity());(i||this.#A())?.focus()}}),super.init?.(),this.#w(),this.#$(),this.#E(),this.#H()}#H(){this.#i.renderItem=m,this.#t.renderItem=v,this.#e.renderItem=C}attributeChangedCallback(i,t,e){if(super.attributeChangedCallback?.(i,t,e),t!==e)if("required"===i)this.#I();else if(B.includes(i)||"data-source-base-url"===i)this.#w(),"data-source-base-url"===i&&this.#E();else if("default-country"===i){const i=e?.toUpperCase();if(i&&i!==e)return void this.setAttribute("default-country",i);i&&this.#n.size?this.#L(i):i&&this.#c&&this.#T()}else"lang"===i?this.#U():"invalid"===i?"true"===e&&this.#R():"allowed-countries"===i||"pinned-countries"===i?this.#c||(this.#r?this.#F(this.#r):this.#T()):"country-label"===i?this.#O(this.#i,"label",e):"subdivision-label"===i?this.#O(this.#t,"label",e):"city-label"===i&&this.#O(this.#e,"label",e)}getValidity(){if(!this.isRequired)return{};const i=!this.#c&&!this.#i.value,t=!this.#b&&(this.#p||this.#s)&&!this.#t.value,e=!this.#y&&(this.#p||this.#o)&&!this.#e.value;return i||t||e?{valueMissing:!0}:{}}#R(){for(const i of[...this.#S].reverse())i.classList.contains(`${c}-hidden`)||i.checkValidity()||i.reportValidity()}#d(){[this.#i,this.#t].forEach(i=>{i.customValueTransformFn=t=>{const e=i.baseElement?.items?.find(i=>i["data-name"]===t);return e?.getAttribute("data-label")??t}})}#h(){this.#S.forEach(i=>{(0,o.EA)(this,i,{includeAttrs:[...f,"label-type"]})}),(0,o.EA)(this,this.#i,{includeAttrs:["default-country"],mapAttrs:{"default-country":"default-value"}}),[[this.#i,"country-placeholder"],[this.#t,"subdivision-placeholder"],[this.#e,"city-placeholder"]].forEach(([i,t])=>{(0,o.EA)(this,i,{includeAttrs:[t],mapAttrs:{[t]:"placeholder"}})})}#$(){this.#i.addEventListener("input",()=>this.#q()),this.#t.addEventListener("input",()=>this.#D()),this.#e.addEventListener("input",()=>this.#N()),this.handleFocusEventsDispatching(this.#S)}#E(){this.#m&&(this.#u?this.#V():this.#c&&!this.#C||this.#T())}async#V(){const{country:i,subdivision:t,city:e}=this.#u,s=!!t&&!this.#b,o=!!e&&!this.#y,n=this.#r??a(this.#m),r=this.#l??d(this.#m),c=s&&i?l(i,this.#m):null,y=o&&i?s&&t?u(i,t,this.#m):h(i,this.#m):null,[p,m,v,C]=(await Promise.allSettled([n,r,c,y])).map(i=>"fulfilled"===i.status?i.value:null);if(!this.#u)return;m&&(this.#l=m);const g=[];p&&(this.#r||(this.#r=p,this.#F(p)),i&&!this.#c&&g.push([this.#i,i]));const x=i?this.#n.get(i):null;x?.subdivisionType&&this.#M(x.subdivisionType),v&&(this.#a=v,this.#s=v.length>0,v.length>0&&(this.#t.data=v.map(i=>({...i,lang:this.#v})),t&&g.push([this.#t,t]))),C&&(this.#o=C.length>0,C.length>0&&(this.#e.data=C,e&&g.push([this.#e,e]))),this.#w(),this.#u=b,setTimeout(()=>{if(this.#u===b){for(const[i,t]of g){const e=i.items?.find(i=>i["data-id"]===t);e&&(i.selectedItem=e)}this.#u=null}})}#q(){this.#u!==b&&(this.#u=null,this.#k(),this.#_(),this.#L(this.#i.value),this.#N())}#D(){if(this.#u===b)return;this.#u=null;const i=this.#t.value;if(this.#_(),!this.#y&&i){const t=this.#i.value;t&&this.#P(t,i)}this.#N()}#L(i){if(!i)return;const t=this.#n.get(i);if(!t)return;const{hasSubdivisions:e,subdivisionType:s}=t;!this.#b&&e?(this.#M(s),this.#j(i)):this.#y||this.#P(i)}#M(i){const t=this.#z(i);this.#g||this.#O(this.#t,"label",t||null),this.#x||this.#O(this.#t,"placeholder",t||null)}#z(i){const t=this.#l?.subdivisionTypes,e=t?.[i]??t?._fallback;if(!e)return i;const s=this.#v;return s&&(e[s]||e[s.split("-")[0]])||e.en||i}async#W(){try{this.#l=await d(this.#m)}catch{}}async#T(){if(this.#m){this.#i.setAttribute("loading","true");try{const[i]=await Promise.all([a(this.#m),this.#W()]);this.#r=i,this.#F(i),!this.#u&&this.#C&&this.#L(this.#C)}catch(i){console.error(`[${c}] Failed to load countries`,i)}finally{this.#i.removeAttribute("loading")}}}async#j(i){this.#G(this.#t,!0),this.#t.setAttribute("loading","true");try{const t=await l(i,this.#m);this.#a=t,this.#s=t.length>0,this.#w(),t.length>0?this.#t.data=t.map(i=>({...i,lang:this.#v})):this.#y||this.#P(i)}catch(t){console.error(`[${c}] Failed to load subdivisions for ${i}`,t),this.#s=!1,this.#Z()}finally{this.#t.removeAttribute("loading")}}async#P(i,t){this.#e.setAttribute("loading","true");try{const e=await(t?u(i,t,this.#m):h(i,this.#m));this.#o=e.length>0,this.#w(),e.length>0&&(this.#e.data=e)}catch(e){console.error(`[${c}] Failed to load cities for ${i}${t?`/${t}`:""}`,e)}finally{this.#e.removeAttribute("loading")}}#U(){if(this.#r){const i=this.#i.value;this.#F(this.#r),i&&this.#J(this.#i,i)}if(this.#a&&this.#s){const i=this.#t.value;this.#t.data=this.#a.map(i=>({...i,lang:this.#v})),i&&this.#J(this.#t,i)}const i=this.#i.value;if(i){const t=this.#n.get(i);t?.subdivisionType&&this.#M(t.subdivisionType)}}#F(i){const t=this.#Q(i);this.#i.data=t.map(i=>({...i,lang:this.#v})),this.#n=new Map(i.map(i=>[i.iso2,i]))}#Q(i){const t=this.#f,e=this.#B;let s=t.length?i.filter(i=>t.includes(i.iso2)):[...i];return s.sort((i,t)=>y(i,this.#v).localeCompare(y(t,this.#v),this.#v)),e.length?[...e.map(i=>s.find(t=>t.iso2===i)).filter(Boolean),...s.filter(i=>!e.includes(i.iso2))]:s}#Z(){this.#G(this.#i,!this.#c),this.#G(this.#t,!this.#b&&(this.#p||this.#s)),this.#G(this.#e,!this.#y&&(this.#p||this.#o))}#G(i,t){i?.classList.toggle(`${c}-hidden`,!t)}#I(){const i=this.hasAttribute("required")?"true":null;this.#O(this.#i,"required",this.#c?null:i),this.#O(this.#t,"required",this.#b||!this.#p&&!this.#s?null:i),this.#O(this.#e,"required",this.#y||!this.#p&&!this.#o?null:i)}#w(){this.#Z(),this.#I(),this.setCustomValidity("")}#k(){this.#t.value="",this.#t.data=[],this.#s=!1,this.#g||this.#t.removeAttribute("label"),this.#x||this.#t.removeAttribute("placeholder"),this.#w()}#_(){this.#e.value="",this.#e.data=[],this.#o=!1,this.#w()}#N(){this.dispatchEvent(new Event("input",{bubbles:!0,composed:!0}))}#O(i,t,e){e?i.setAttribute(t,e):i.removeAttribute(t)}#A(){return this.#S.find(i=>!i.classList.contains(`${c}-hidden`))}#J(i,t){setTimeout(()=>{const e=i.items?.find(i=>i["data-id"]===t);e&&(i.selectedItem=e)})}});customElements.define(c,V);var A=e(88961),w=e(86365);const $=(0,o.xE)("country-subdivision-city-field"),E={selector:()=>":host"},H={selector:`${c} > .wrapper`},I={selector:`${c} > .wrapper > descope-combo-box`},L=(0,n.Zz)((0,A.RF)({componentNameOverride:(0,o.xE)("input-wrapper")}),(0,A.RF)({mappings:{hostWidth:{...E,property:"width"},hostDirection:[{...E,property:"direction"},{...I,property:w.C.cssVarList.hostDirection}],flexDirection:{...H,property:"flex-direction"},flexGap:{...H,property:"gap"},itemAlignment:{...H,property:"align-items"},itemMinWidth:{...I,property:"min-width"},itemFlexGrow:{...I,property:"flex-grow"},itemWidth:{...I,property:w.C.cssVarList.hostWidth}}}),A.VO,(0,A.OZ)({proxyProps:["value"],inputEvent:"input",proxyParentValidation:!0}),A.tQ,i=>class extends i{init(){super.init?.();const i=document.createElement("template");i.innerHTML=`\n <${c}\n tabindex="-1"\n ></${c}>\n `,this.baseElement.appendChild(i.content.cloneNode(!0)),this.inputElement=this.shadowRoot.querySelector(c),(0,o.EA)(this,this.inputElement,{includeAttrs:["size","bordered","required","label-type","disabled","readonly","hide-country","hide-subdivision","hide-city","default-country","allowed-countries","pinned-countries","country-label","subdivision-label","city-label","country-placeholder","subdivision-placeholder","city-placeholder","data-source-base-url","lang","invalid"]}),(0,o.Gh)(this,this.inputElement,{includeAttrs:["invalid"]})}})((0,A.tz)({slots:[],wrappedEleName:"vaadin-custom-field",style:()=>`\n :host {\n display: inline-flex;\n max-width: 100%;\n }\n vaadin-custom-field {\n line-height: unset;\n width: 100%;\n }\n\n ${c} {\n display: inline-block;\n box-sizing: border-box;\n user-select: none;\n width: 100%;\n max-width: 100%;\n }\n\n ${c} > .wrapper {\n display: flex;\n width: 100%;\n flex-wrap: wrap;\n }\n\n .${c}-hidden {\n display: none;\n }\n\n`,excludeAttrsSync:["tabindex","style","error-message"],componentName:$}));customElements.define($,L)}}]);
|
|
1
|
+
"use strict";(self.webpackChunk_descope_web_components_ui=self.webpackChunk_descope_web_components_ui||[]).push([[2478],{68749(i,t,e){e.r(t),e.d(t,{CountrySubdivisionCityFieldClass:()=>L,componentName:()=>w}),e(25003),e(27092);var s=e(72270),o=e(25964),n=e(63200);const a=async i=>{const t=await fetch(i);if(!t.ok)throw new Error(`[dataService] ${t.status} ${i}`);const e=await t.json();return e.data??e},r=async i=>a(`${i}/countries.json`),l=async(i,t)=>{try{return(await a(`${t}/countries/${i}/subdivisions.json`)).map(({code:i,...t})=>({...t,state_code:i}))}catch{return[]}},d=async(i,t,e)=>a(`${e}/countries/${i}/subdivisions/${t}/cities.json`),u=async i=>{const t=new URL("../labels.json",`${i}/`).href;return a(t)},h=async(i,t)=>a(`${t}/countries/${i}/cities.json`),c=(0,o.xE)("country-subdivision-city-field-internal"),b=Symbol("selecting"),y=({name:i,translations:t={}},e)=>e&&(t[e]||t[e.split("-")[0]])||i,m=i=>i?String(i).replace(/[&<>"']/g,i=>`&#${i.charCodeAt(0)};`):"",p=({name:i,iso2:t,iso3:e,translations:s,lang:o})=>{const n=y({name:i,translations:s},o),a=[n,t,e];n!==i&&a.push(i);const r=m(t),l=m(a.join(" ")),d=m(n);return`<div data-id="${r}" data-name="${l}" data-label="${d}">${d}</div>`},C=({name:i,state_code:t,translations:e,lang:s})=>{const o=y({name:i,translations:e},s),n=[o,t];o!==i&&n.push(i);const a=m(t),r=m(n.join(" ")),l=m(o);return`<div data-id="${a}" data-name="${r}" data-label="${l}">${l}</div>`},v=({name:i,translations:t,lang:e})=>{const s=y({name:i,translations:t},e),o=[s];s!==i&&o.push(i);const n=m(i),a=m(o.join(" ")),r=m(s);return`<div data-id="${n}" data-name="${a}" data-label="${r}">${r}</div>`},g=i=>`<descope-combo-box id="${i}" item-label-path="data-name" item-value-path="data-id" allow-custom-value="false"></descope-combo-box>`,x=(0,s.yc)({componentName:c,baseSelector:""}),f=["disabled","readonly","size","bordered"],B=["hide-country","hide-subdivision","hide-city"],V=[...f,"label-type","country-label","subdivision-label","city-label",...B,"default-country","allowed-countries","pinned-countries","country-placeholder","subdivision-placeholder","city-placeholder","required","invalid","data-source-base-url","lang"],S=(0,n.Zz)()(class extends x{static get observedAttributes(){return[].concat(x.observedAttributes||[],V)}#i;#t;#e;#s=!1;#o=!1;#n=new Map;#a=null;#r=null;#l=null;#d=null;#u=null;constructor(){super(),this.innerHTML=`\n <div class="wrapper">\n ${g("country-combo")}\n ${g("subdivision-combo")}\n ${g("city-combo")}\n </div>\n `,this.#i=this.querySelector("#country-combo"),this.#t=this.querySelector("#subdivision-combo"),this.#e=this.querySelector("#city-combo"),this.#h(),this.#c()}get#b(){return"true"===this.getAttribute("hide-country")}get#y(){return"true"===this.getAttribute("hide-subdivision")}get#m(){return"true"===this.getAttribute("hide-city")}get#p(){return!this.#C}get#C(){return this.getAttribute("data-source-base-url")||void 0}get#v(){const i=this.getAttribute("lang")||void 0;if(i)try{const[t]=Intl.getCanonicalLocales(i);return t}catch{return}}get#g(){return this.getAttribute("default-country")?.toUpperCase()||void 0}get#x(){return this.getAttribute("subdivision-label")||void 0}get#f(){return this.getAttribute("subdivision-placeholder")||void 0}get#B(){return(this.getAttribute("allowed-countries")||"").split(",").map(i=>i.trim().toUpperCase()).filter(Boolean)}get#V(){return(this.getAttribute("pinned-countries")||"").split(",").map(i=>i.trim().toUpperCase()).filter(Boolean)}get#S(){return[this.#i,this.#t,this.#e]}get value(){return{country:this.#b?this.#g:this.#i.value||void 0,subdivision:!this.#y&&this.#s&&this.#t.value||void 0,city:!this.#m&&this.#o&&this.#e.value||void 0}}set value(i){if(!i)return;let t;try{t="string"==typeof i?JSON.parse(i):i}catch{return}this.#u={...t},this.#C&&this.#A()}init(){this.addEventListener("focus",i=>{if(i.isTrusted){const i=this.#S.find(i=>!i.classList.contains(`${c}-hidden`)&&!i.checkValidity());(i||this.#$())?.focus()}}),super.init?.(),this.#w(),this.#E(),this.#H(),this.#I()}#I(){this.#i.renderItem=p,this.#t.renderItem=C,this.#e.renderItem=v}attributeChangedCallback(i,t,e){if(super.attributeChangedCallback?.(i,t,e),t!==e)if("required"===i)this.#L();else if(B.includes(i)||"data-source-base-url"===i)this.#w(),"data-source-base-url"===i&&this.#H();else if("default-country"===i){const i=e?.toUpperCase();if(i&&i!==e)return void this.setAttribute("default-country",i);i&&this.#n.size?this.#T(i):i&&this.#b&&this.#U()}else"lang"===i?this.#R():"invalid"===i?"true"===e&&this.#F():"allowed-countries"===i||"pinned-countries"===i?this.#b||(this.#a?this.#O(this.#a):this.#U()):"country-label"===i?this.#q(this.#i,"label",e):"subdivision-label"===i?this.#q(this.#t,"label",e):"city-label"===i&&this.#q(this.#e,"label",e)}getValidity(){if(!this.isRequired)return{};const i=!this.#b&&!this.#i.value,t=!this.#y&&(this.#p||this.#s)&&!this.#t.value,e=!this.#m&&(this.#p||this.#o)&&!this.#e.value;return i||t||e?{valueMissing:!0}:{}}#F(){for(const i of[...this.#S].reverse())i.classList.contains(`${c}-hidden`)||i.checkValidity()||i.reportValidity()}#h(){[this.#i,this.#t,this.#e].forEach(i=>{i.customValueTransformFn=t=>{const e=i.baseElement?.items?.find(i=>i["data-name"]===t);return e?.getAttribute("data-label")??t}})}#c(){this.#S.forEach(i=>{(0,o.EA)(this,i,{includeAttrs:[...f,"label-type"]})}),(0,o.EA)(this,this.#i,{includeAttrs:["default-country"],mapAttrs:{"default-country":"default-value"}}),[[this.#i,"country-placeholder"],[this.#t,"subdivision-placeholder"],[this.#e,"city-placeholder"]].forEach(([i,t])=>{(0,o.EA)(this,i,{includeAttrs:[t],mapAttrs:{[t]:"placeholder"}})})}#E(){this.#i.addEventListener("input",()=>this.#D()),this.#t.addEventListener("input",()=>this.#N()),this.#e.addEventListener("input",()=>this.#M()),this.handleFocusEventsDispatching(this.#S)}#H(){this.#C&&(this.#u?this.#A():this.#b&&!this.#g||this.#U())}async#A(){const{country:i,subdivision:t,city:e}=this.#u,s=!!t&&!this.#y,o=!!e&&!this.#m,n=this.#a??r(this.#C),a=this.#d??u(this.#C),c=s&&i?l(i,this.#C):null,y=o&&i?s&&t?d(i,t,this.#C):h(i,this.#C):null,[m,p,C,v]=(await Promise.allSettled([n,a,c,y])).map(i=>"fulfilled"===i.status?i.value:null);if(!this.#u)return;p&&(this.#d=p);const g=[];m&&(this.#a||(this.#a=m,this.#O(m)),i&&!this.#b&&g.push([this.#i,i]));const x=i?this.#n.get(i):null;x?.subdivisionType&&this.#k(x.subdivisionType),C&&(this.#r=C,this.#s=C.length>0,C.length>0&&(this.#t.data=C.map(i=>({...i,lang:this.#v})),t&&g.push([this.#t,t]))),v&&(this.#o=v.length>0,v.length>0&&(this.#l=v,this.#e.data=v.map(i=>({...i,lang:this.#v})),e&&g.push([this.#e,e]))),this.#w(),this.#u=b,setTimeout(()=>{if(this.#u===b){for(const[i,t]of g){const e=i.items?.find(i=>i["data-id"]===t);e&&(i.selectedItem=e)}this.#u=null}})}#D(){this.#u!==b&&(this.#u=null,this.#_(),this.#P(),this.#T(this.#i.value),this.#M())}#N(){if(this.#u===b)return;this.#u=null;const i=this.#t.value;if(this.#P(),!this.#m&&i){const t=this.#i.value;t&&this.#j(t,i)}this.#M()}#T(i){if(!i)return;const t=this.#n.get(i);if(!t)return;const{hasSubdivisions:e,subdivisionType:s}=t;!this.#y&&e?(this.#k(s),this.#z(i)):this.#m||this.#j(i)}#k(i){const t=this.#W(i);this.#x||this.#q(this.#t,"label",t||null),this.#f||this.#q(this.#t,"placeholder",t||null)}#W(i){const t=this.#d?.subdivisionTypes,e=t?.[i]??t?._fallback;if(!e)return i;const s=this.#v;return s&&(e[s]||e[s.split("-")[0]])||e.en||i}async#G(){try{this.#d=await u(this.#C)}catch{}}async#U(){if(this.#C){this.#i.setAttribute("loading","true");try{const[i]=await Promise.all([r(this.#C),this.#G()]);this.#a=i,this.#O(i),!this.#u&&this.#g&&this.#T(this.#g)}catch(i){console.error(`[${c}] Failed to load countries`,i)}finally{this.#i.removeAttribute("loading")}}}async#z(i){this.#Z(this.#t,!0),this.#t.setAttribute("loading","true");try{const t=await l(i,this.#C);this.#r=t,this.#s=t.length>0,this.#w(),t.length>0?this.#t.data=t.map(i=>({...i,lang:this.#v})):this.#m||this.#j(i)}catch(t){console.error(`[${c}] Failed to load subdivisions for ${i}`,t),this.#s=!1,this.#J()}finally{this.#t.removeAttribute("loading")}}async#j(i,t){this.#e.setAttribute("loading","true");try{const e=await(t?d(i,t,this.#C):h(i,this.#C));this.#o=e.length>0,this.#w(),e.length>0&&(this.#l=e,this.#e.data=e.map(i=>({...i,lang:this.#v})))}catch(e){console.error(`[${c}] Failed to load cities for ${i}${t?`/${t}`:""}`,e)}finally{this.#e.removeAttribute("loading")}}#R(){if(this.#a){const i=this.#i.value;this.#O(this.#a),i&&this.#Q(this.#i,i)}if(this.#r&&this.#s){const i=this.#t.value;this.#t.data=this.#r.map(i=>({...i,lang:this.#v})),i&&this.#Q(this.#t,i)}if(this.#l&&this.#o){const i=this.#e.value;this.#e.data=this.#l.map(i=>({...i,lang:this.#v})),i&&this.#Q(this.#e,i)}const i=this.#i.value;if(i){const t=this.#n.get(i);t?.subdivisionType&&this.#k(t.subdivisionType)}}#O(i){const t=this.#K(i);this.#i.data=t.map(i=>({...i,lang:this.#v})),this.#n=new Map(i.map(i=>[i.iso2,i]))}#K(i){const t=this.#B,e=this.#V;let s=t.length?i.filter(i=>t.includes(i.iso2)):[...i];return s.sort((i,t)=>y(i,this.#v).localeCompare(y(t,this.#v),this.#v)),e.length?[...e.map(i=>s.find(t=>t.iso2===i)).filter(Boolean),...s.filter(i=>!e.includes(i.iso2))]:s}#J(){this.#Z(this.#i,!this.#b),this.#Z(this.#t,!this.#y&&(this.#p||this.#s)),this.#Z(this.#e,!this.#m&&(this.#p||this.#o))}#Z(i,t){i?.classList.toggle(`${c}-hidden`,!t)}#L(){const i=this.hasAttribute("required")?"true":null;this.#q(this.#i,"required",this.#b?null:i),this.#q(this.#t,"required",this.#y||!this.#p&&!this.#s?null:i),this.#q(this.#e,"required",this.#m||!this.#p&&!this.#o?null:i)}#w(){this.#J(),this.#L(),this.setCustomValidity("")}#_(){this.#t.value="",this.#t.data=[],this.#s=!1,this.#x||this.#t.removeAttribute("label"),this.#f||this.#t.removeAttribute("placeholder"),this.#w()}#P(){this.#e.value="",this.#e.data=[],this.#l=null,this.#o=!1,this.#w()}#M(){this.dispatchEvent(new Event("input",{bubbles:!0,composed:!0}))}#q(i,t,e){e?i.setAttribute(t,e):i.removeAttribute(t)}#$(){return this.#S.find(i=>!i.classList.contains(`${c}-hidden`))}#Q(i,t){setTimeout(()=>{const e=i.items?.find(i=>i["data-id"]===t);e&&(i.selectedItem=e)})}});customElements.define(c,S);var A=e(88961),$=e(86365);const w=(0,o.xE)("country-subdivision-city-field"),E={selector:()=>":host"},H={selector:`${c} > .wrapper`},I={selector:`${c} > .wrapper > descope-combo-box`},L=(0,n.Zz)((0,A.RF)({componentNameOverride:(0,o.xE)("input-wrapper")}),(0,A.RF)({mappings:{hostWidth:{...E,property:"width"},hostDirection:[{...E,property:"direction"},{...I,property:$.C.cssVarList.hostDirection}],flexDirection:{...H,property:"flex-direction"},flexGap:{...H,property:"gap"},itemAlignment:{...H,property:"align-items"},itemMinWidth:{...I,property:"min-width"},itemFlexGrow:{...I,property:"flex-grow"},itemWidth:{...I,property:$.C.cssVarList.hostWidth}}}),A.VO,(0,A.OZ)({proxyProps:["value"],inputEvent:"input",proxyParentValidation:!0}),A.tQ,i=>class extends i{init(){super.init?.();const i=document.createElement("template");i.innerHTML=`\n <${c}\n tabindex="-1"\n ></${c}>\n `,this.baseElement.appendChild(i.content.cloneNode(!0)),this.inputElement=this.shadowRoot.querySelector(c),(0,o.EA)(this,this.inputElement,{includeAttrs:["size","bordered","required","label-type","disabled","readonly","hide-country","hide-subdivision","hide-city","default-country","allowed-countries","pinned-countries","country-label","subdivision-label","city-label","country-placeholder","subdivision-placeholder","city-placeholder","data-source-base-url","lang","invalid"]}),(0,o.Gh)(this,this.inputElement,{includeAttrs:["invalid"]})}})((0,A.tz)({slots:[],wrappedEleName:"vaadin-custom-field",style:()=>`\n :host {\n display: inline-flex;\n max-width: 100%;\n }\n vaadin-custom-field {\n line-height: unset;\n width: 100%;\n }\n\n ${c} {\n display: inline-block;\n box-sizing: border-box;\n user-select: none;\n width: 100%;\n max-width: 100%;\n }\n\n ${c} > .wrapper {\n display: flex;\n width: 100%;\n flex-wrap: wrap;\n }\n\n .${c}-hidden {\n display: none;\n }\n\n`,excludeAttrsSync:["tabindex","style","error-message"],componentName:w}));customElements.define(w,L)}}]);
|
|
2
2
|
//# sourceMappingURL=descope-country-subdivision-city-field.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"descope-country-subdivision-city-field.js","mappings":"wQASA,MAAMA,EAAYC,MAAOC,IACvB,MAAMC,QAAiBC,MAAMF,GAC7B,IAAKC,EAASE,GAAI,MAAM,IAAIC,MAAM,iBAAiBH,EAASI,UAAUL,KACtE,MAAMM,QAAaL,EAASK,OAE5B,OAAOA,EAAKC,MAAQD,GAGTE,EAAiBT,MAAOU,GACnCX,EAAU,GAAGW,oBAKFC,EAAoBX,MAAOY,EAA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B,sBAChBC,MAAO,IAAM,mJAUb,0IAQA,yFAMC,0CAKDC,iBAAkB,CAAC,WAAY,QAAS,iBACxChM,cAAa,KCxIjB4J,eAAeC,OAAO,EAAeK,E","sources":["webpack://@descope/web-components-ui/../components/descope-country-subdivision-city-field/src/data/dataService.js","webpack://@descope/web-components-ui/../components/descope-country-subdivision-city-field/src/component/descope-country-subdivision-city-field-internal/CountrySubdivisionCityFieldInternal.js","webpack://@descope/web-components-ui/../components/descope-country-subdivision-city-field/src/component/descope-country-subdivision-city-field-internal/index.js","webpack://@descope/web-components-ui/../components/descope-country-subdivision-city-field/src/component/CountrySubdivisionCityFieldClass.js","webpack://@descope/web-components-ui/../components/descope-country-subdivision-city-field/src/component/index.js"],"sourcesContent":["// Data service for country/subdivision/city data.\n//\n// Fetches from the CDN/S3 baseUrl. The URL structure (relative to baseUrl):\n// <baseUrl>/countries.json\n// <baseUrl>/countries/{iso2}/subdivisions.json\n// <baseUrl>/countries/{iso2}/subdivisions/{state_code}/cities.json\n// <baseUrl>/countries/{iso2}/cities.json (all cities for a country, used when subdivision is hidden)\n// <parent-of-baseUrl>/labels.json (shared labels/translations, one level up)\n\nconst fetchJson = async (url) => {\n const response = await fetch(url);\n if (!response.ok) throw new Error(`[dataService] ${response.status} ${url}`);\n const json = await response.json();\n // All files use a { data: [...] } envelope\n return json.data ?? json;\n};\n\nexport const fetchCountries = async (baseUrl) =>\n fetchJson(`${baseUrl}/countries.json`);\n\nconst normalizeSubdivisions = (data) =>\n data.map(({ code, ...rest }) => ({ ...rest, state_code: code }));\n\nexport const fetchSubdivisions = async (countryIso2, baseUrl) => {\n try {\n const data = await fetchJson(\n `${baseUrl}/countries/${countryIso2}/subdivisions.json`,\n );\n return normalizeSubdivisions(data);\n } catch {\n // No subdivisions file means the country has no subdivisions\n return [];\n }\n};\n\nexport const fetchCities = async (countryIso2, stateCode, baseUrl) =>\n fetchJson(\n `${baseUrl}/countries/${countryIso2}/subdivisions/${stateCode}/cities.json`,\n );\n\n// labels.json sits one directory above the language-specific base URL\n// e.g. baseUrl = \".../address/en\" → labels URL = \".../address/labels.json\"\nexport const fetchLabels = async (baseUrl) => {\n const labelsUrl = new URL('../labels.json', `${baseUrl}/`).href;\n return fetchJson(labelsUrl);\n};\n\nexport const fetchCitiesForCountry = async (countryIso2, baseUrl) =>\n fetchJson(`${baseUrl}/countries/${countryIso2}/cities.json`);\n","import { createBaseInputClass } from '@descope-ui/common/base-classes';\nimport {\n getComponentName,\n forwardAttrs,\n} from '@descope-ui/common/components-helpers';\nimport { compose } from '@descope-ui/common/utils';\nimport {\n fetchCountries,\n fetchSubdivisions,\n fetchCities,\n fetchCitiesForCountry,\n fetchLabels,\n} from '../../data/dataService';\n\nexport const componentName = getComponentName(\n 'country-subdivision-city-field-internal',\n);\n\n// Sentinel used in #pendingValue to signal that programmatic item selection is in progress.\n// Prevents cascade-clearing logic in input handlers from firing during programmatic selection.\nconst SELECTING = Symbol('selecting');\n\n// --- Translation ---\n\nconst resolveTranslation = ({ name, translations = {} }, lang) => {\n if (!lang) return name;\n return translations[lang] || translations[lang.split('-')[0]] || name;\n};\n\n// --- HTML Escaping ---\n\nconst escapeHtml = (str) => {\n if (!str) return '';\n return String(str).replace(/[&<>\"']/g, (c) => `&#${c.charCodeAt(0)};`);\n};\n\n// --- Item renderers ---\n\nconst countryItem = ({ name, iso2, iso3, translations, lang }) => {\n const displayName = resolveTranslation({ name, translations }, lang);\n const searchTerms = [displayName, iso2, iso3];\n if (displayName !== name) searchTerms.push(name);\n const escapedIso2 = escapeHtml(iso2);\n const escapedSearchTerms = escapeHtml(searchTerms.join(' '));\n const escapedLabel = escapeHtml(displayName);\n return `<div data-id=\"${escapedIso2}\" data-name=\"${escapedSearchTerms}\" data-label=\"${escapedLabel}\">${escapedLabel}</div>`;\n};\n\nconst subdivisionItem = ({ name, state_code, translations, lang }) => {\n const displayName = resolveTranslation({ name, translations }, lang);\n const searchTerms = [displayName, state_code];\n if (displayName !== name) searchTerms.push(name);\n const escapedStateCode = escapeHtml(state_code);\n const escapedSearchTerms = escapeHtml(searchTerms.join(' '));\n const escapedLabel = escapeHtml(displayName);\n return `<div data-id=\"${escapedStateCode}\" data-name=\"${escapedSearchTerms}\" data-label=\"${escapedLabel}\">${escapedLabel}</div>`;\n};\n\nconst cityItem = ({ name }) => {\n const escapedId = escapeHtml(name);\n const escapedName = escapeHtml(name);\n return `<div data-id=\"${escapedId}\" data-name=\"${escapedName}\">${escapedName}</div>`;\n};\n\nconst comboBoxHTML = (id) =>\n `<descope-combo-box id=\"${id}\" item-label-path=\"data-name\" item-value-path=\"data-id\" allow-custom-value=\"false\"></descope-combo-box>`;\n\n// --- Base class ---\n\nconst BaseInputClass = createBaseInputClass({\n componentName,\n baseSelector: '',\n});\n\nconst commonAttrs = ['disabled', 'readonly', 'size', 'bordered'];\nconst labelTypeAttrs = [\n 'label-type',\n 'country-label',\n 'subdivision-label',\n 'city-label',\n];\nconst visibilityAttrs = ['hide-country', 'hide-subdivision', 'hide-city'];\nconst countryConfigAttrs = [\n 'default-country',\n 'allowed-countries',\n 'pinned-countries',\n];\nconst placeholderAttrs = [\n 'country-placeholder',\n 'subdivision-placeholder',\n 'city-placeholder',\n];\nconst observedAttrs = [\n ...commonAttrs,\n ...labelTypeAttrs,\n ...visibilityAttrs,\n ...countryConfigAttrs,\n ...placeholderAttrs,\n 'required',\n 'invalid',\n 'data-source-base-url',\n 'lang',\n];\n\nclass RawCountrySubdivisionCityFieldInternal extends BaseInputClass {\n static get observedAttributes() {\n return [].concat(BaseInputClass.observedAttributes || [], observedAttrs);\n }\n\n #countryComboBox;\n #subdivisionComboBox;\n #cityComboBox;\n\n // Whether the subdivision/city field should be shown (data was found for selected country/subdivision)\n #subdivisionVisible = false;\n #cityVisible = false;\n\n // iso2 → country object (populated after countries are loaded)\n #countriesMap = new Map();\n #cachedCountries = null;\n #cachedSubdivisions = null;\n #labels = null;\n\n // Value requested programmatically before data has loaded.\n // Applied incrementally as each cascade layer (countries → subdivisions → cities) loads.\n #pendingValue = null;\n\n constructor() {\n super();\n\n this.innerHTML = `\n <div class=\"wrapper\">\n ${comboBoxHTML('country-combo')}\n ${comboBoxHTML('subdivision-combo')}\n ${comboBoxHTML('city-combo')}\n </div>\n `;\n\n this.#countryComboBox = this.querySelector('#country-combo');\n this.#subdivisionComboBox = this.querySelector('#subdivision-combo');\n this.#cityComboBox = this.querySelector('#city-combo');\n\n this.#setupValueTransform();\n this.#setupAttrForwarding();\n }\n\n // --- Attribute getters ---\n\n get #isHideCountry() {\n return this.getAttribute('hide-country') === 'true';\n }\n get #isHideSubdivision() {\n return this.getAttribute('hide-subdivision') === 'true';\n }\n get #isHideCity() {\n return this.getAttribute('hide-city') === 'true';\n }\n get #isNoDataSource() {\n return !this.#baseUrl;\n }\n get #baseUrl() {\n return this.getAttribute('data-source-base-url') || undefined;\n }\n get #lang() {\n const lang = this.getAttribute('lang') || undefined;\n if (!lang) return undefined;\n try {\n Intl.getCanonicalLocales(lang);\n return lang;\n } catch {\n return undefined; // invalid BCP47 tag — fall back to English\n }\n }\n get #defaultCountry() {\n return this.getAttribute('default-country')?.toUpperCase() || undefined;\n }\n get #subdivisionLabel() {\n return this.getAttribute('subdivision-label') || undefined;\n }\n get #subdivisionPlaceholder() {\n return this.getAttribute('subdivision-placeholder') || undefined;\n }\n\n get #allowedCountries() {\n return (this.getAttribute('allowed-countries') || '')\n .split(',')\n .map((c) => c.trim().toUpperCase())\n .filter(Boolean);\n }\n\n get #pinnedCountries() {\n return (this.getAttribute('pinned-countries') || '')\n .split(',')\n .map((c) => c.trim().toUpperCase())\n .filter(Boolean);\n }\n\n get #allCombos() {\n return [\n this.#countryComboBox,\n this.#subdivisionComboBox,\n this.#cityComboBox,\n ];\n }\n\n // --- Value ---\n\n get value() {\n const country = this.#isHideCountry\n ? this.#defaultCountry\n : this.#countryComboBox.value || undefined;\n\n const subdivision =\n !this.#isHideSubdivision && this.#subdivisionVisible\n ? this.#subdivisionComboBox.value || undefined\n : undefined;\n\n const city =\n !this.#isHideCity && this.#cityVisible\n ? this.#cityComboBox.value || undefined\n : undefined;\n\n return { country, subdivision, city };\n }\n\n set value(val) {\n if (!val) return;\n let parsed;\n try {\n parsed = typeof val === 'string' ? JSON.parse(val) : val;\n } catch {\n // Invalid JSON — silently ignore to prevent component crash\n return;\n }\n this.#pendingValue = { ...parsed };\n if (this.#baseUrl) this.#loadForPendingValue();\n }\n\n // --- Lifecycle ---\n\n init() {\n this.addEventListener('focus', (e) => {\n if (e.isTrusted) {\n const firstInvalidCombo = this.#allCombos.find(\n (combo) =>\n !combo.classList.contains(`${componentName}-hidden`) &&\n !combo.checkValidity(),\n );\n (firstInvalidCombo || this.#getFirstVisibleCombo())?.focus();\n }\n });\n\n super.init?.();\n\n this.#refreshState();\n this.#setupChangeListeners();\n this.#initData();\n this.#setCombosItemRenderers();\n }\n\n #setCombosItemRenderers() {\n this.#countryComboBox.renderItem = countryItem;\n this.#subdivisionComboBox.renderItem = subdivisionItem;\n this.#cityComboBox.renderItem = cityItem;\n }\n\n attributeChangedCallback(attrName, oldValue, newValue) {\n super.attributeChangedCallback?.(attrName, oldValue, newValue);\n\n if (oldValue === newValue) return;\n\n if (attrName === 'required') {\n this.#updateRequiredOnCombos();\n } else if (\n visibilityAttrs.includes(attrName) ||\n attrName === 'data-source-base-url'\n ) {\n this.#refreshState();\n if (attrName === 'data-source-base-url') this.#initData();\n } else if (attrName === 'default-country') {\n const upper = newValue?.toUpperCase();\n if (upper && upper !== newValue) {\n this.setAttribute('default-country', upper);\n return;\n }\n if (upper && this.#countriesMap.size) {\n this.#onCountrySelected(upper); // countries already loaded — trigger immediately\n } else if (upper && this.#isHideCountry) {\n // hide-country mode: countries may not have been loaded yet (e.g. no default-country at init).\n // Kick off loading now; #loadCountries will call #onCountrySelected once done.\n this.#loadCountries();\n }\n } else if (attrName === 'lang') {\n this.#rerenderOnLangChange();\n } else if (attrName === 'invalid') {\n if (newValue === 'true') this.#handleInvalidCombos();\n } else if (\n attrName === 'allowed-countries' ||\n attrName === 'pinned-countries'\n ) {\n if (!this.#isHideCountry) {\n // Re-render from cache if available to avoid a race condition between two simultaneous\n // fetch calls (one from data-source-base-url, one from the filter attribute change).\n if (this.#cachedCountries) {\n this.#renderCountryItems(this.#cachedCountries);\n } else {\n this.#loadCountries();\n }\n }\n } else if (attrName === 'country-label') {\n this.#setOrRemoveAttr(this.#countryComboBox, 'label', newValue);\n } else if (attrName === 'subdivision-label') {\n this.#setOrRemoveAttr(this.#subdivisionComboBox, 'label', newValue);\n } else if (attrName === 'city-label') {\n this.#setOrRemoveAttr(this.#cityComboBox, 'label', newValue);\n }\n }\n\n // --- Validation ---\n\n getValidity() {\n if (!this.isRequired) return {};\n\n const countryMissing = !this.#isHideCountry && !this.#countryComboBox.value;\n const subdivisionMissing =\n !this.#isHideSubdivision &&\n (this.#isNoDataSource || this.#subdivisionVisible) &&\n !this.#subdivisionComboBox.value;\n const cityMissing =\n !this.#isHideCity &&\n (this.#isNoDataSource || this.#cityVisible) &&\n !this.#cityComboBox.value;\n\n return countryMissing || subdivisionMissing || cityMissing\n ? { valueMissing: true }\n : {};\n }\n\n // Show validation errors on the specific combos that are missing a value.\n // Iterate in reverse so reportValidity's focus() lands on the first invalid combo last.\n #handleInvalidCombos() {\n for (const combo of [...this.#allCombos].reverse()) {\n if (combo.classList.contains(`${componentName}-hidden`)) continue;\n if (!combo.checkValidity()) combo.reportValidity();\n }\n }\n\n // --- Setup ---\n\n #setupValueTransform() {\n // Display only the item name in the input, while data-name includes ISO codes for search\n [this.#countryComboBox, this.#subdivisionComboBox].forEach((combo) => {\n \n combo.customValueTransformFn = (val) => {\n const item = combo.baseElement?.items?.find(\n (i) => i['data-name'] === val,\n );\n return item?.getAttribute('data-label') ?? val;\n };\n });\n }\n\n #setupAttrForwarding() {\n // Forward common attrs and label-type to all combos\n this.#allCombos.forEach((combo) => {\n forwardAttrs(this, combo, {\n includeAttrs: [...commonAttrs, 'label-type'],\n });\n });\n\n // Forward default-country as default-value to let the combo box handle initial selection\n forwardAttrs(this, this.#countryComboBox, {\n includeAttrs: ['default-country'],\n mapAttrs: { 'default-country': 'default-value' },\n });\n\n // Forward per-field placeholders\n [\n [this.#countryComboBox, 'country-placeholder'],\n [this.#subdivisionComboBox, 'subdivision-placeholder'],\n [this.#cityComboBox, 'city-placeholder'],\n ].forEach(([combo, attr]) => {\n forwardAttrs(this, combo, {\n includeAttrs: [attr],\n mapAttrs: { [attr]: 'placeholder' },\n });\n });\n }\n\n #setupChangeListeners() {\n // descope-combo-box dispatches 'input' (not 'change') on selection\n this.#countryComboBox.addEventListener('input', () =>\n this.#handleCountryChange(),\n );\n this.#subdivisionComboBox.addEventListener('input', () =>\n this.#handleSubdivisionChange(),\n );\n this.#cityComboBox.addEventListener('input', () =>\n this.#dispatchInputEvent(),\n );\n\n this.handleFocusEventsDispatching(this.#allCombos);\n }\n\n #initData() {\n // baseUrl is forwarded by the outer component after this element is connected;\n // wait for the attributeChangedCallback('data-source-base-url') to re-trigger.\n if (!this.#baseUrl) return;\n\n if (this.#pendingValue) {\n this.#loadForPendingValue();\n return;\n }\n\n if (!this.#isHideCountry || this.#defaultCountry) {\n // Load countries to populate #countriesMap even when hide-country=true, so that\n // #onCountrySelected can apply the correct subdivision type label for the default country.\n this.#loadCountries();\n }\n }\n\n // --- Programmatic value loading (parallel fetch) ---\n\n async #loadForPendingValue() {\n const {\n country: pendingCountry,\n subdivision: pendingSubdivision,\n city: pendingCity,\n } = this.#pendingValue;\n\n const shouldLoadSubdivisions =\n !!pendingSubdivision && !this.#isHideSubdivision;\n const shouldLoadCities = !!pendingCity && !this.#isHideCity;\n\n const countriesPromise =\n this.#cachedCountries ?? fetchCountries(this.#baseUrl);\n const labelsPromise = this.#labels ?? fetchLabels(this.#baseUrl);\n const subdivisionsPromise =\n shouldLoadSubdivisions && pendingCountry\n ? fetchSubdivisions(pendingCountry, this.#baseUrl)\n : null;\n const citiesPromise =\n shouldLoadCities && pendingCountry\n ? shouldLoadSubdivisions && pendingSubdivision\n ? fetchCities(pendingCountry, pendingSubdivision, this.#baseUrl)\n : fetchCitiesForCountry(pendingCountry, this.#baseUrl)\n : null;\n\n // Fetch everything in parallel; null entries resolve immediately as null\n const [countries, labels, subdivisions, cities] = (\n await Promise.allSettled([\n countriesPromise,\n labelsPromise,\n subdivisionsPromise,\n citiesPromise,\n ])\n ).map((result) => (result.status === 'fulfilled' ? result.value : null));\n\n // Cancelled by a subsequent set value call or user interaction\n if (!this.#pendingValue) return;\n\n if (labels) this.#labels = labels;\n\n // Collect items to select — do this before rendering so we can batch-select below\n const toSelect = [];\n\n if (countries) {\n if (!this.#cachedCountries) {\n this.#cachedCountries = countries;\n this.#renderCountryItems(countries);\n }\n if (pendingCountry && !this.#isHideCountry)\n toSelect.push([this.#countryComboBox, pendingCountry]);\n }\n\n const countryObj = pendingCountry\n ? this.#countriesMap.get(pendingCountry)\n : null;\n if (countryObj?.subdivisionType)\n this.#applySubdivisionType(countryObj.subdivisionType);\n\n if (subdivisions) {\n this.#cachedSubdivisions = subdivisions;\n this.#subdivisionVisible = subdivisions.length > 0;\n if (subdivisions.length > 0) {\n this.#subdivisionComboBox.data = subdivisions.map((s) => ({\n ...s,\n lang: this.#lang,\n }));\n if (pendingSubdivision)\n toSelect.push([this.#subdivisionComboBox, pendingSubdivision]);\n }\n }\n\n if (cities) {\n this.#cityVisible = cities.length > 0;\n if (cities.length > 0) {\n this.#cityComboBox.data = cities;\n if (pendingCity) toSelect.push([this.#cityComboBox, pendingCity]);\n }\n }\n\n this.#refreshState();\n\n // Apply all selections in one batch. #pendingValue is set to SELECTING so that\n // input events fired by selectedItem= don't trigger cascade-clearing in change handlers.\n this.#pendingValue = SELECTING;\n setTimeout(() => {\n if (this.#pendingValue !== SELECTING) return; // cancelled by a new set value call\n for (const [combo, id] of toSelect) {\n const item = combo.items?.find((i) => i['data-id'] === id);\n if (item) combo.selectedItem = item;\n }\n this.#pendingValue = null;\n });\n }\n\n // --- Change handlers ---\n\n #handleCountryChange() {\n if (this.#pendingValue === SELECTING) return; // programmatic selection in progress\n this.#pendingValue = null; // cancel any in-flight fetch\n this.#resetSubdivision();\n this.#resetCity();\n this.#onCountrySelected(this.#countryComboBox.value);\n this.#dispatchInputEvent();\n }\n\n #handleSubdivisionChange() {\n if (this.#pendingValue === SELECTING) return; // programmatic selection in progress\n this.#pendingValue = null; // cancel any in-flight fetch\n const subdivisionCode = this.#subdivisionComboBox.value;\n this.#resetCity();\n\n if (!this.#isHideCity && subdivisionCode) {\n const countryIso2 = this.#countryComboBox.value;\n if (countryIso2) this.#loadCities(countryIso2, subdivisionCode);\n }\n this.#dispatchInputEvent();\n }\n\n // --- Country selection ---\n\n #onCountrySelected(countryIso2) {\n if (!countryIso2) return;\n\n const country = this.#countriesMap.get(countryIso2);\n if (!country) return;\n\n const { hasSubdivisions, subdivisionType } = country;\n\n if (!this.#isHideSubdivision && hasSubdivisions) {\n this.#applySubdivisionType(subdivisionType);\n this.#loadSubdivisions(countryIso2);\n } else if (!this.#isHideCity) {\n this.#loadCities(countryIso2);\n }\n }\n\n // Apply subdivisionType as label/placeholder, but only when not overridden by an explicit attribute.\n #applySubdivisionType(subdivisionType) {\n const label = this.#resolveSubdivisionTypeLabel(subdivisionType);\n if (!this.#subdivisionLabel)\n this.#setOrRemoveAttr(this.#subdivisionComboBox, 'label', label || null);\n if (!this.#subdivisionPlaceholder)\n this.#setOrRemoveAttr(\n this.#subdivisionComboBox,\n 'placeholder',\n label || null,\n );\n }\n\n #resolveSubdivisionTypeLabel(subdivisionType) {\n const types = this.#labels?.subdivisionTypes;\n const entry = types?.[subdivisionType] ?? types?._fallback;\n if (!entry) return subdivisionType;\n const lang = this.#lang;\n return (\n (lang && (entry[lang] || entry[lang.split('-')[0]])) ||\n entry.en ||\n subdivisionType\n );\n }\n\n // --- Data loading ---\n\n async #loadLabels() {\n try {\n this.#labels = await fetchLabels(this.#baseUrl);\n } catch {\n // Labels are optional; fall back to raw subdivisionType name\n }\n }\n\n async #loadCountries() {\n if (!this.#baseUrl) return;\n this.#countryComboBox.setAttribute('loading', 'true');\n try {\n const [countries] = await Promise.all([\n fetchCountries(this.#baseUrl),\n this.#loadLabels(),\n ]);\n this.#cachedCountries = countries;\n this.#renderCountryItems(countries);\n // Skip defaultCountry if a programmatic set value is in flight\n if (!this.#pendingValue && this.#defaultCountry)\n this.#onCountrySelected(this.#defaultCountry);\n } catch (e) {\n \n console.error(`[${componentName}] Failed to load countries`, e);\n } finally {\n this.#countryComboBox.removeAttribute('loading');\n }\n }\n\n async #loadSubdivisions(countryIso2) {\n this.#setVisible(this.#subdivisionComboBox, true);\n this.#subdivisionComboBox.setAttribute('loading', 'true');\n try {\n const subdivisions = await fetchSubdivisions(countryIso2, this.#baseUrl);\n this.#cachedSubdivisions = subdivisions;\n this.#subdivisionVisible = subdivisions.length > 0;\n this.#refreshState();\n\n if (subdivisions.length > 0) {\n this.#subdivisionComboBox.data = subdivisions.map((s) => ({\n ...s,\n lang: this.#lang,\n }));\n } else if (!this.#isHideCity) {\n this.#loadCities(countryIso2);\n }\n } catch (e) {\n \n console.error(\n `[${componentName}] Failed to load subdivisions for ${countryIso2}`,\n e,\n );\n this.#subdivisionVisible = false;\n this.#applyVisibility();\n } finally {\n this.#subdivisionComboBox.removeAttribute('loading');\n }\n }\n\n // stateCode is optional: when omitted, loads all cities for the country\n async #loadCities(countryIso2, stateCode) {\n this.#cityComboBox.setAttribute('loading', 'true');\n try {\n const cities = await (stateCode\n ? fetchCities(countryIso2, stateCode, this.#baseUrl)\n : fetchCitiesForCountry(countryIso2, this.#baseUrl));\n this.#cityVisible = cities.length > 0;\n this.#refreshState();\n if (cities.length > 0) {\n this.#cityComboBox.data = cities;\n }\n } catch (e) {\n \n console.error(\n `[${componentName}] Failed to load cities for ${countryIso2}${stateCode ? `/${stateCode}` : ''}`,\n e,\n );\n } finally {\n this.#cityComboBox.removeAttribute('loading');\n }\n }\n\n #rerenderOnLangChange() {\n if (this.#cachedCountries) {\n const prevCountry = this.#countryComboBox.value;\n this.#renderCountryItems(this.#cachedCountries);\n if (prevCountry) this.#selectItemById(this.#countryComboBox, prevCountry);\n }\n if (this.#cachedSubdivisions && this.#subdivisionVisible) {\n const prevSubdivision = this.#subdivisionComboBox.value;\n this.#subdivisionComboBox.data = this.#cachedSubdivisions.map((s) => ({\n ...s,\n lang: this.#lang,\n }));\n if (prevSubdivision)\n this.#selectItemById(this.#subdivisionComboBox, prevSubdivision);\n }\n // Re-apply translated subdivision type label for the new lang\n const currentIso2 = this.#countryComboBox.value;\n if (currentIso2) {\n const country = this.#countriesMap.get(currentIso2);\n if (country?.subdivisionType)\n this.#applySubdivisionType(country.subdivisionType);\n }\n }\n\n // --- Country item rendering ---\n\n #renderCountryItems(countries) {\n const result = this.#applyCountryFilters(countries);\n this.#countryComboBox.data = result.map((c) => ({\n ...c,\n // Include the translated name in the data for search purposes, but not in the label which is rendered by renderItem\n lang: this.#lang,\n }));\n this.#countriesMap = new Map(countries.map((c) => [c.iso2, c]));\n }\n\n #applyCountryFilters(countries) {\n const allowed = this.#allowedCountries;\n const pinned = this.#pinnedCountries;\n\n let filtered = allowed.length\n ? countries.filter((c) => allowed.includes(c.iso2))\n : [...countries];\n\n filtered.sort((a, b) =>\n resolveTranslation(a, this.#lang).localeCompare(\n resolveTranslation(b, this.#lang),\n this.#lang,\n ),\n );\n\n if (!pinned.length) return filtered;\n\n const pinnedItems = pinned\n .map((iso2) => filtered.find((c) => c.iso2 === iso2))\n .filter(Boolean);\n const rest = filtered.filter((c) => !pinned.includes(c.iso2));\n return [...pinnedItems, ...rest];\n }\n\n // --- Visibility & required ---\n\n #applyVisibility() {\n this.#setVisible(this.#countryComboBox, !this.#isHideCountry);\n this.#setVisible(\n this.#subdivisionComboBox,\n !this.#isHideSubdivision &&\n (this.#isNoDataSource || this.#subdivisionVisible),\n );\n this.#setVisible(\n this.#cityComboBox,\n !this.#isHideCity && (this.#isNoDataSource || this.#cityVisible),\n );\n }\n\n #setVisible(el, visible) {\n el?.classList.toggle(`${componentName}-hidden`, !visible);\n }\n\n #updateRequiredOnCombos() {\n const required = this.hasAttribute('required') ? 'true' : null;\n this.#setOrRemoveAttr(\n this.#countryComboBox,\n 'required',\n !this.#isHideCountry ? required : null,\n );\n this.#setOrRemoveAttr(\n this.#subdivisionComboBox,\n 'required',\n !this.#isHideSubdivision &&\n (this.#isNoDataSource || this.#subdivisionVisible)\n ? required\n : null,\n );\n this.#setOrRemoveAttr(\n this.#cityComboBox,\n 'required',\n !this.#isHideCity && (this.#isNoDataSource || this.#cityVisible)\n ? required\n : null,\n );\n }\n\n #refreshState() {\n this.#applyVisibility();\n this.#updateRequiredOnCombos();\n // Re-evaluate validity so that the form knows when newly-visible required fields become empty.\n // e.g. subdivision becomes required after a country with states is selected.\n this.setCustomValidity('');\n }\n\n // --- Reset helpers ---\n\n #resetSubdivision() {\n this.#subdivisionComboBox.value = '';\n this.#subdivisionComboBox.data = [];\n this.#subdivisionVisible = false;\n // Clear any dynamically set label/placeholder from subdivisionType\n if (!this.#subdivisionLabel)\n this.#subdivisionComboBox.removeAttribute('label');\n if (!this.#subdivisionPlaceholder)\n this.#subdivisionComboBox.removeAttribute('placeholder');\n this.#refreshState();\n }\n\n #resetCity() {\n this.#cityComboBox.value = '';\n this.#cityComboBox.data = [];\n this.#cityVisible = false;\n this.#refreshState();\n }\n\n // --- Utility helpers ---\n\n #dispatchInputEvent() {\n this.dispatchEvent(new Event('input', { bubbles: true, composed: true }));\n }\n\n #setOrRemoveAttr(el, attr, value) {\n if (value) el.setAttribute(attr, value);\n else el.removeAttribute(attr);\n }\n\n #getFirstVisibleCombo() {\n return this.#allCombos.find(\n (combo) => !combo.classList.contains(`${componentName}-hidden`),\n );\n }\n\n #selectItemById(comboBox, id) {\n // Defer the lookup so MutationObserver has time to populate comboBox.items\n setTimeout(() => {\n const item = comboBox.items?.find((i) => i['data-id'] === id);\n if (item) comboBox.selectedItem = item;\n });\n }\n}\n\nexport const CountrySubdivisionCityFieldInternal = compose()(\n RawCountrySubdivisionCityFieldInternal,\n);\n","import {\n CountrySubdivisionCityFieldInternal,\n componentName,\n} from './CountrySubdivisionCityFieldInternal';\n\ncustomElements.define(componentName, CountrySubdivisionCityFieldInternal);\n","import {\n createStyleMixin,\n draggableMixin,\n createProxy,\n proxyInputMixin,\n componentNameValidationMixin,\n} from '@descope-ui/common/components-mixins';\nimport {\n getComponentName,\n forwardAttrs,\n syncAttrs,\n} from '@descope-ui/common/components-helpers';\nimport { compose } from '@descope-ui/common/utils';\nimport { ComboBoxClass } from '@descope-ui/descope-combo-box/class';\nimport { componentName as descopeInternalComponentName } from './descope-country-subdivision-city-field-internal/CountrySubdivisionCityFieldInternal';\n\nexport const componentName = getComponentName('country-subdivision-city-field');\n\nconst customMixin = (superclass) =>\n class CountrySubdivisionCityFieldMixinClass extends superclass {\n init() {\n super.init?.();\n\n const template = document.createElement('template');\n\n template.innerHTML = `\n <${descopeInternalComponentName}\n tabindex=\"-1\"\n ></${descopeInternalComponentName}>\n `;\n\n this.baseElement.appendChild(template.content.cloneNode(true));\n\n this.inputElement = this.shadowRoot.querySelector(\n descopeInternalComponentName,\n );\n\n forwardAttrs(this, this.inputElement, {\n includeAttrs: [\n 'size',\n 'bordered',\n 'required',\n 'label-type',\n 'disabled',\n 'readonly',\n 'hide-country',\n 'hide-subdivision',\n 'hide-city',\n 'default-country',\n 'allowed-countries',\n 'pinned-countries',\n 'country-label',\n 'subdivision-label',\n 'city-label',\n 'country-placeholder',\n 'subdivision-placeholder',\n 'city-placeholder',\n 'data-source-base-url',\n 'lang',\n 'invalid',\n ],\n });\n\n // Sync invalid attribute bidirectionally so external validation feedback propagates\n syncAttrs(this, this.inputElement, { includeAttrs: ['invalid'] });\n }\n };\n\nconst host = { selector: () => ':host' };\n\nconst internalWrapper = {\n selector: `${descopeInternalComponentName} > .wrapper`,\n};\n\nconst internalComboBoxes = {\n selector: `${descopeInternalComponentName} > .wrapper > descope-combo-box`,\n};\n\nexport const CountrySubdivisionCityFieldClass = compose(\n createStyleMixin({\n componentNameOverride: getComponentName('input-wrapper'),\n }),\n createStyleMixin({\n mappings: {\n hostWidth: { ...host, property: 'width' },\n hostDirection: [\n { ...host, property: 'direction' },\n {\n ...internalComboBoxes,\n property: ComboBoxClass.cssVarList.hostDirection,\n },\n ],\n flexDirection: { ...internalWrapper, property: 'flex-direction' },\n flexGap: { ...internalWrapper, property: 'gap' },\n itemAlignment: { ...internalWrapper, property: 'align-items' },\n itemMinWidth: { ...internalComboBoxes, property: 'min-width' },\n itemFlexGrow: { ...internalComboBoxes, property: 'flex-grow' },\n itemWidth: {\n ...internalComboBoxes,\n property: ComboBoxClass.cssVarList.hostWidth,\n },\n },\n }),\n draggableMixin,\n proxyInputMixin({\n proxyProps: ['value'],\n inputEvent: 'input',\n proxyParentValidation: true,\n }),\n componentNameValidationMixin,\n customMixin,\n)(\n createProxy({\n slots: [],\n wrappedEleName: 'vaadin-custom-field',\n style: () => `\n :host {\n display: inline-flex;\n max-width: 100%;\n }\n vaadin-custom-field {\n line-height: unset;\n width: 100%;\n }\n\n ${descopeInternalComponentName} {\n display: inline-block;\n box-sizing: border-box;\n user-select: none;\n width: 100%;\n max-width: 100%;\n }\n\n ${descopeInternalComponentName} > .wrapper {\n display: flex;\n width: 100%;\n flex-wrap: wrap;\n }\n\n .${descopeInternalComponentName}-hidden {\n display: none;\n }\n\n`,\n excludeAttrsSync: ['tabindex', 'style', 'error-message'],\n componentName,\n }),\n);\n","import '@vaadin/custom-field';\nimport '@descope-ui/descope-combo-box';\nimport './descope-country-subdivision-city-field-internal';\n\nimport {\n componentName,\n CountrySubdivisionCityFieldClass,\n} from './CountrySubdivisionCityFieldClass';\n\ncustomElements.define(componentName, CountrySubdivisionCityFieldClass);\n\nexport { CountrySubdivisionCityFieldClass, componentName };\n"],"names":["fetchJson","async","url","response","fetch","ok","Error","status","json","data","fetchCountries","baseUrl","fetchSubdivisions","countryIso2","map","code","rest","state_code","fetchCities","stateCode","fetchLabels","labelsUrl","URL","href","fetchCitiesForCountry","componentName","SELECTING","Symbol","resolveTranslation","name","translations","lang","split","escapeHtml","str","String","replace","c","charCodeAt","countryItem","iso2","iso3","displayName","searchTerms","push","escapedIso2","escapedSearchTerms","join","escapedLabel","subdivisionItem","escapedStateCode","cityItem","escapedId","escapedName","comboBoxHTML","id","BaseInputClass","baseSelector","commonAttrs","visibilityAttrs","observedAttrs","CountrySubdivisionCityFieldInternal","observedAttributes","concat","Map","constructor","super","this","innerHTML","querySelector","getAttribute","undefined","Intl","getCanonicalLocales","toUpperCase","trim","filter","Boolean","value","country","subdivision","city","val","parsed","JSON","parse","init","addEventListener","e","isTrusted","firstInvalidCombo","find","combo","classList","contains","checkValidity","focus","renderItem","attributeChangedCallback","attrName","oldValue","newValue","includes","upper","setAttribute","size","getValidity","isRequired","countryMissing","subdivisionMissing","cityMissing","valueMissing","reverse","reportValidity","forEach","customValueTransformFn","item","baseElement","items","i","includeAttrs","mapAttrs","attr","handleFocusEventsDispatching","pendingCountry","pendingSubdivision","pendingCity","shouldLoadSubdivisions","shouldLoadCities","countriesPromise","labelsPromise","subdivisionsPromise","citiesPromise","countries","labels","subdivisions","cities","Promise","allSettled","result","toSelect","countryObj","get","subdivisionType","length","s","setTimeout","selectedItem","subdivisionCode","hasSubdivisions","label","types","subdivisionTypes","entry","_fallback","en","all","console","error","removeAttribute","prevCountry","prevSubdivision","currentIso2","allowed","pinned","filtered","sort","a","b","localeCompare","el","visible","toggle","required","hasAttribute","setCustomValidity","dispatchEvent","Event","bubbles","composed","comboBox","customElements","define","host","selector","internalWrapper","internalComboBoxes","CountrySubdivisionCityFieldClass","componentNameOverride","mappings","hostWidth","property","hostDirection","ComboBoxClass","C","cssVarList","flexDirection","flexGap","itemAlignment","itemMinWidth","itemFlexGrow","itemWidth","proxyProps","inputEvent","proxyParentValidation","superclass","template","document","createElement","appendChild","content","cloneNode","inputElement","shadowRoot","slots","wrappedEleName","style","excludeAttrsSync"],"sourceRoot":""}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CC,cAAe,CACb,IAAKT,EAAMQ,SAAU,aACrB,IACKL,EACHK,SAAUE,EAAAC,EAAcC,WAAWH,gBAGvCI,cAAe,IAAKX,EAAiBM,SAAU,kBAC/CM,QAAS,IAAKZ,EAAiBM,SAAU,OACzCO,cAAe,IAAKb,EAAiBM,SAAU,eAC/CQ,aAAc,IAAKb,EAAoBK,SAAU,aACjDS,aAAc,IAAKd,EAAoBK,SAAU,aACjDU,UAAW,IACNf,EACHK,SAAUE,EAAAC,EAAcC,WAAWL,cAIzC,MACA,QAAgB,CACdY,WAAY,CAAC,SACbC,WAAY,QACZC,uBAAuB,IAEzB,KA3FmBC,GACnB,cAAoDA,EAClD,IAAAxH,GACErB,MAAMqB,SAEN,MAAMyH,EAAWC,SAASC,cAAc,YAExCF,EAAS5I,UAAY,YAClB,sCAEE,aAGLD,KAAKmD,YAAY6F,YAAYH,EAASI,QAAQC,WAAU,IAExDlJ,KAAKmJ,aAAenJ,KAAKoJ,WAAWlJ,cAClC,IAGF,QAAaF,KAAMA,KAAKmJ,aAAc,CACpC7F,aAAc,CACZ,OACA,WACA,WACA,aACA,WACA,WACA,eACA,mBACA,YACA,kBACA,oBACA,mBACA,gBACA,oBACA,aACA,sBACA,0BACA,mBACA,uBACA,OACA,cAKJ,QAAUtD,KAAMA,KAAKmJ,aAAc,CAAE7F,aAAc,CAAC,YACtD,GAa4C,EAkC9C,QAAY,CACV+F,MAAO,GACPC,eAAgB,sBAChBC,MAAO,IAAM,mJAUb,0IAQA,yFAMC,0CAKDC,iBAAkB,CAAC,WAAY,QAAS,iBACxCjM,cAAa,KCxIjB6J,eAAeC,OAAO,EAAeK,E","sources":["webpack://@descope/web-components-ui/../components/descope-country-subdivision-city-field/src/data/dataService.js","webpack://@descope/web-components-ui/../components/descope-country-subdivision-city-field/src/component/descope-country-subdivision-city-field-internal/CountrySubdivisionCityFieldInternal.js","webpack://@descope/web-components-ui/../components/descope-country-subdivision-city-field/src/component/descope-country-subdivision-city-field-internal/index.js","webpack://@descope/web-components-ui/../components/descope-country-subdivision-city-field/src/component/CountrySubdivisionCityFieldClass.js","webpack://@descope/web-components-ui/../components/descope-country-subdivision-city-field/src/component/index.js"],"sourcesContent":["// Data service for country/subdivision/city data.\n//\n// Fetches from the CDN/S3 baseUrl. The URL structure (relative to baseUrl):\n// <baseUrl>/countries.json\n// <baseUrl>/countries/{iso2}/subdivisions.json\n// <baseUrl>/countries/{iso2}/subdivisions/{state_code}/cities.json\n// <baseUrl>/countries/{iso2}/cities.json (all cities for a country, used when subdivision is hidden)\n// <parent-of-baseUrl>/labels.json (shared labels/translations, one level up)\n\nconst fetchJson = async (url) => {\n const response = await fetch(url);\n if (!response.ok) throw new Error(`[dataService] ${response.status} ${url}`);\n const json = await response.json();\n // All files use a { data: [...] } envelope\n return json.data ?? json;\n};\n\nexport const fetchCountries = async (baseUrl) =>\n fetchJson(`${baseUrl}/countries.json`);\n\nconst normalizeSubdivisions = (data) =>\n data.map(({ code, ...rest }) => ({ ...rest, state_code: code }));\n\nexport const fetchSubdivisions = async (countryIso2, baseUrl) => {\n try {\n const data = await fetchJson(\n `${baseUrl}/countries/${countryIso2}/subdivisions.json`,\n );\n return normalizeSubdivisions(data);\n } catch {\n // No subdivisions file means the country has no subdivisions\n return [];\n }\n};\n\nexport const fetchCities = async (countryIso2, stateCode, baseUrl) =>\n fetchJson(\n `${baseUrl}/countries/${countryIso2}/subdivisions/${stateCode}/cities.json`,\n );\n\n// labels.json sits one directory above the language-specific base URL\n// e.g. baseUrl = \".../address/en\" → labels URL = \".../address/labels.json\"\nexport const fetchLabels = async (baseUrl) => {\n const labelsUrl = new URL('../labels.json', `${baseUrl}/`).href;\n return fetchJson(labelsUrl);\n};\n\nexport const fetchCitiesForCountry = async (countryIso2, baseUrl) =>\n fetchJson(`${baseUrl}/countries/${countryIso2}/cities.json`);\n","import { createBaseInputClass } from '@descope-ui/common/base-classes';\nimport {\n getComponentName,\n forwardAttrs,\n} from '@descope-ui/common/components-helpers';\nimport { compose } from '@descope-ui/common/utils';\nimport {\n fetchCountries,\n fetchSubdivisions,\n fetchCities,\n fetchCitiesForCountry,\n fetchLabels,\n} from '../../data/dataService';\n\nexport const componentName = getComponentName(\n 'country-subdivision-city-field-internal',\n);\n\n// Sentinel used in #pendingValue to signal that programmatic item selection is in progress.\n// Prevents cascade-clearing logic in input handlers from firing during programmatic selection.\nconst SELECTING = Symbol('selecting');\n\n// --- Translation ---\n\nconst resolveTranslation = ({ name, translations = {} }, lang) => {\n if (!lang) return name;\n return translations[lang] || translations[lang.split('-')[0]] || name;\n};\n\n// --- HTML Escaping ---\n\nconst escapeHtml = (str) => {\n if (!str) return '';\n return String(str).replace(/[&<>\"']/g, (c) => `&#${c.charCodeAt(0)};`);\n};\n\n// --- Item renderers ---\n\nconst countryItem = ({ name, iso2, iso3, translations, lang }) => {\n const displayName = resolveTranslation({ name, translations }, lang);\n const searchTerms = [displayName, iso2, iso3];\n if (displayName !== name) searchTerms.push(name);\n const escapedIso2 = escapeHtml(iso2);\n const escapedSearchTerms = escapeHtml(searchTerms.join(' '));\n const escapedLabel = escapeHtml(displayName);\n return `<div data-id=\"${escapedIso2}\" data-name=\"${escapedSearchTerms}\" data-label=\"${escapedLabel}\">${escapedLabel}</div>`;\n};\n\nconst subdivisionItem = ({ name, state_code, translations, lang }) => {\n const displayName = resolveTranslation({ name, translations }, lang);\n const searchTerms = [displayName, state_code];\n if (displayName !== name) searchTerms.push(name);\n const escapedStateCode = escapeHtml(state_code);\n const escapedSearchTerms = escapeHtml(searchTerms.join(' '));\n const escapedLabel = escapeHtml(displayName);\n return `<div data-id=\"${escapedStateCode}\" data-name=\"${escapedSearchTerms}\" data-label=\"${escapedLabel}\">${escapedLabel}</div>`;\n};\n\nconst cityItem = ({ name, translations, lang }) => {\n const displayName = resolveTranslation({ name, translations }, lang);\n const searchTerms = [displayName];\n if (displayName !== name) searchTerms.push(name);\n const escapedId = escapeHtml(name);\n const escapedSearchTerms = escapeHtml(searchTerms.join(' '));\n const escapedLabel = escapeHtml(displayName);\n return `<div data-id=\"${escapedId}\" data-name=\"${escapedSearchTerms}\" data-label=\"${escapedLabel}\">${escapedLabel}</div>`;\n};\n\nconst comboBoxHTML = (id) =>\n `<descope-combo-box id=\"${id}\" item-label-path=\"data-name\" item-value-path=\"data-id\" allow-custom-value=\"false\"></descope-combo-box>`;\n\n// --- Base class ---\n\nconst BaseInputClass = createBaseInputClass({\n componentName,\n baseSelector: '',\n});\n\nconst commonAttrs = ['disabled', 'readonly', 'size', 'bordered'];\nconst labelTypeAttrs = [\n 'label-type',\n 'country-label',\n 'subdivision-label',\n 'city-label',\n];\nconst visibilityAttrs = ['hide-country', 'hide-subdivision', 'hide-city'];\nconst countryConfigAttrs = [\n 'default-country',\n 'allowed-countries',\n 'pinned-countries',\n];\nconst placeholderAttrs = [\n 'country-placeholder',\n 'subdivision-placeholder',\n 'city-placeholder',\n];\nconst observedAttrs = [\n ...commonAttrs,\n ...labelTypeAttrs,\n ...visibilityAttrs,\n ...countryConfigAttrs,\n ...placeholderAttrs,\n 'required',\n 'invalid',\n 'data-source-base-url',\n 'lang',\n];\n\nclass RawCountrySubdivisionCityFieldInternal extends BaseInputClass {\n static get observedAttributes() {\n return [].concat(BaseInputClass.observedAttributes || [], observedAttrs);\n }\n\n #countryComboBox;\n #subdivisionComboBox;\n #cityComboBox;\n\n // Whether the subdivision/city field should be shown (data was found for selected country/subdivision)\n #subdivisionVisible = false;\n #cityVisible = false;\n\n // iso2 → country object (populated after countries are loaded)\n #countriesMap = new Map();\n #cachedCountries = null;\n #cachedSubdivisions = null;\n #cachedCities = null;\n #labels = null;\n\n // Value requested programmatically before data has loaded.\n // Applied incrementally as each cascade layer (countries → subdivisions → cities) loads.\n #pendingValue = null;\n\n constructor() {\n super();\n\n this.innerHTML = `\n <div class=\"wrapper\">\n ${comboBoxHTML('country-combo')}\n ${comboBoxHTML('subdivision-combo')}\n ${comboBoxHTML('city-combo')}\n </div>\n `;\n\n this.#countryComboBox = this.querySelector('#country-combo');\n this.#subdivisionComboBox = this.querySelector('#subdivision-combo');\n this.#cityComboBox = this.querySelector('#city-combo');\n\n this.#setupValueTransform();\n this.#setupAttrForwarding();\n }\n\n // --- Attribute getters ---\n\n get #isHideCountry() {\n return this.getAttribute('hide-country') === 'true';\n }\n get #isHideSubdivision() {\n return this.getAttribute('hide-subdivision') === 'true';\n }\n get #isHideCity() {\n return this.getAttribute('hide-city') === 'true';\n }\n get #isNoDataSource() {\n return !this.#baseUrl;\n }\n get #baseUrl() {\n return this.getAttribute('data-source-base-url') || undefined;\n }\n get #lang() {\n const lang = this.getAttribute('lang') || undefined;\n if (!lang) return undefined;\n try {\n const [canonical] = Intl.getCanonicalLocales(lang);\n return canonical;\n } catch {\n return undefined; // invalid BCP47 tag — fall back to English\n }\n }\n get #defaultCountry() {\n return this.getAttribute('default-country')?.toUpperCase() || undefined;\n }\n get #subdivisionLabel() {\n return this.getAttribute('subdivision-label') || undefined;\n }\n get #subdivisionPlaceholder() {\n return this.getAttribute('subdivision-placeholder') || undefined;\n }\n\n get #allowedCountries() {\n return (this.getAttribute('allowed-countries') || '')\n .split(',')\n .map((c) => c.trim().toUpperCase())\n .filter(Boolean);\n }\n\n get #pinnedCountries() {\n return (this.getAttribute('pinned-countries') || '')\n .split(',')\n .map((c) => c.trim().toUpperCase())\n .filter(Boolean);\n }\n\n get #allCombos() {\n return [\n this.#countryComboBox,\n this.#subdivisionComboBox,\n this.#cityComboBox,\n ];\n }\n\n // --- Value ---\n\n get value() {\n const country = this.#isHideCountry\n ? this.#defaultCountry\n : this.#countryComboBox.value || undefined;\n\n const subdivision =\n !this.#isHideSubdivision && this.#subdivisionVisible\n ? this.#subdivisionComboBox.value || undefined\n : undefined;\n\n const city =\n !this.#isHideCity && this.#cityVisible\n ? this.#cityComboBox.value || undefined\n : undefined;\n\n return { country, subdivision, city };\n }\n\n set value(val) {\n if (!val) return;\n let parsed;\n try {\n parsed = typeof val === 'string' ? JSON.parse(val) : val;\n } catch {\n // Invalid JSON — silently ignore to prevent component crash\n return;\n }\n this.#pendingValue = { ...parsed };\n if (this.#baseUrl) this.#loadForPendingValue();\n }\n\n // --- Lifecycle ---\n\n init() {\n this.addEventListener('focus', (e) => {\n if (e.isTrusted) {\n const firstInvalidCombo = this.#allCombos.find(\n (combo) =>\n !combo.classList.contains(`${componentName}-hidden`) &&\n !combo.checkValidity(),\n );\n (firstInvalidCombo || this.#getFirstVisibleCombo())?.focus();\n }\n });\n\n super.init?.();\n\n this.#refreshState();\n this.#setupChangeListeners();\n this.#initData();\n this.#setCombosItemRenderers();\n }\n\n #setCombosItemRenderers() {\n this.#countryComboBox.renderItem = countryItem;\n this.#subdivisionComboBox.renderItem = subdivisionItem;\n this.#cityComboBox.renderItem = cityItem;\n }\n\n attributeChangedCallback(attrName, oldValue, newValue) {\n super.attributeChangedCallback?.(attrName, oldValue, newValue);\n\n if (oldValue === newValue) return;\n\n if (attrName === 'required') {\n this.#updateRequiredOnCombos();\n } else if (\n visibilityAttrs.includes(attrName) ||\n attrName === 'data-source-base-url'\n ) {\n this.#refreshState();\n if (attrName === 'data-source-base-url') this.#initData();\n } else if (attrName === 'default-country') {\n const upper = newValue?.toUpperCase();\n if (upper && upper !== newValue) {\n this.setAttribute('default-country', upper);\n return;\n }\n if (upper && this.#countriesMap.size) {\n this.#onCountrySelected(upper); // countries already loaded — trigger immediately\n } else if (upper && this.#isHideCountry) {\n // hide-country mode: countries may not have been loaded yet (e.g. no default-country at init).\n // Kick off loading now; #loadCountries will call #onCountrySelected once done.\n this.#loadCountries();\n }\n } else if (attrName === 'lang') {\n this.#rerenderOnLangChange();\n } else if (attrName === 'invalid') {\n if (newValue === 'true') this.#handleInvalidCombos();\n } else if (\n attrName === 'allowed-countries' ||\n attrName === 'pinned-countries'\n ) {\n if (!this.#isHideCountry) {\n // Re-render from cache if available to avoid a race condition between two simultaneous\n // fetch calls (one from data-source-base-url, one from the filter attribute change).\n if (this.#cachedCountries) {\n this.#renderCountryItems(this.#cachedCountries);\n } else {\n this.#loadCountries();\n }\n }\n } else if (attrName === 'country-label') {\n this.#setOrRemoveAttr(this.#countryComboBox, 'label', newValue);\n } else if (attrName === 'subdivision-label') {\n this.#setOrRemoveAttr(this.#subdivisionComboBox, 'label', newValue);\n } else if (attrName === 'city-label') {\n this.#setOrRemoveAttr(this.#cityComboBox, 'label', newValue);\n }\n }\n\n // --- Validation ---\n\n getValidity() {\n if (!this.isRequired) return {};\n\n const countryMissing = !this.#isHideCountry && !this.#countryComboBox.value;\n const subdivisionMissing =\n !this.#isHideSubdivision &&\n (this.#isNoDataSource || this.#subdivisionVisible) &&\n !this.#subdivisionComboBox.value;\n const cityMissing =\n !this.#isHideCity &&\n (this.#isNoDataSource || this.#cityVisible) &&\n !this.#cityComboBox.value;\n\n return countryMissing || subdivisionMissing || cityMissing\n ? { valueMissing: true }\n : {};\n }\n\n // Show validation errors on the specific combos that are missing a value.\n // Iterate in reverse so reportValidity's focus() lands on the first invalid combo last.\n #handleInvalidCombos() {\n for (const combo of [...this.#allCombos].reverse()) {\n if (combo.classList.contains(`${componentName}-hidden`)) continue;\n if (!combo.checkValidity()) combo.reportValidity();\n }\n }\n\n // --- Setup ---\n\n #setupValueTransform() {\n // Display only the item name in the input, while data-name includes ISO codes for search\n [\n this.#countryComboBox,\n this.#subdivisionComboBox,\n this.#cityComboBox,\n ].forEach((combo) => {\n combo.customValueTransformFn = (val) => {\n const item = combo.baseElement?.items?.find(\n (i) => i['data-name'] === val,\n );\n return item?.getAttribute('data-label') ?? val;\n };\n });\n }\n\n #setupAttrForwarding() {\n // Forward common attrs and label-type to all combos\n this.#allCombos.forEach((combo) => {\n forwardAttrs(this, combo, {\n includeAttrs: [...commonAttrs, 'label-type'],\n });\n });\n\n // Forward default-country as default-value to let the combo box handle initial selection\n forwardAttrs(this, this.#countryComboBox, {\n includeAttrs: ['default-country'],\n mapAttrs: { 'default-country': 'default-value' },\n });\n\n // Forward per-field placeholders\n [\n [this.#countryComboBox, 'country-placeholder'],\n [this.#subdivisionComboBox, 'subdivision-placeholder'],\n [this.#cityComboBox, 'city-placeholder'],\n ].forEach(([combo, attr]) => {\n forwardAttrs(this, combo, {\n includeAttrs: [attr],\n mapAttrs: { [attr]: 'placeholder' },\n });\n });\n }\n\n #setupChangeListeners() {\n // descope-combo-box dispatches 'input' (not 'change') on selection\n this.#countryComboBox.addEventListener('input', () =>\n this.#handleCountryChange(),\n );\n this.#subdivisionComboBox.addEventListener('input', () =>\n this.#handleSubdivisionChange(),\n );\n this.#cityComboBox.addEventListener('input', () =>\n this.#dispatchInputEvent(),\n );\n\n this.handleFocusEventsDispatching(this.#allCombos);\n }\n\n #initData() {\n // baseUrl is forwarded by the outer component after this element is connected;\n // wait for the attributeChangedCallback('data-source-base-url') to re-trigger.\n if (!this.#baseUrl) return;\n\n if (this.#pendingValue) {\n this.#loadForPendingValue();\n return;\n }\n\n if (!this.#isHideCountry || this.#defaultCountry) {\n // Load countries to populate #countriesMap even when hide-country=true, so that\n // #onCountrySelected can apply the correct subdivision type label for the default country.\n this.#loadCountries();\n }\n }\n\n // --- Programmatic value loading (parallel fetch) ---\n\n async #loadForPendingValue() {\n const {\n country: pendingCountry,\n subdivision: pendingSubdivision,\n city: pendingCity,\n } = this.#pendingValue;\n\n const shouldLoadSubdivisions =\n !!pendingSubdivision && !this.#isHideSubdivision;\n const shouldLoadCities = !!pendingCity && !this.#isHideCity;\n\n const countriesPromise =\n this.#cachedCountries ?? fetchCountries(this.#baseUrl);\n const labelsPromise = this.#labels ?? fetchLabels(this.#baseUrl);\n const subdivisionsPromise =\n shouldLoadSubdivisions && pendingCountry\n ? fetchSubdivisions(pendingCountry, this.#baseUrl)\n : null;\n const citiesPromise =\n shouldLoadCities && pendingCountry\n ? shouldLoadSubdivisions && pendingSubdivision\n ? fetchCities(pendingCountry, pendingSubdivision, this.#baseUrl)\n : fetchCitiesForCountry(pendingCountry, this.#baseUrl)\n : null;\n\n // Fetch everything in parallel; null entries resolve immediately as null\n const [countries, labels, subdivisions, cities] = (\n await Promise.allSettled([\n countriesPromise,\n labelsPromise,\n subdivisionsPromise,\n citiesPromise,\n ])\n ).map((result) => (result.status === 'fulfilled' ? result.value : null));\n\n // Cancelled by a subsequent set value call or user interaction\n if (!this.#pendingValue) return;\n\n if (labels) this.#labels = labels;\n\n // Collect items to select — do this before rendering so we can batch-select below\n const toSelect = [];\n\n if (countries) {\n if (!this.#cachedCountries) {\n this.#cachedCountries = countries;\n this.#renderCountryItems(countries);\n }\n if (pendingCountry && !this.#isHideCountry)\n toSelect.push([this.#countryComboBox, pendingCountry]);\n }\n\n const countryObj = pendingCountry\n ? this.#countriesMap.get(pendingCountry)\n : null;\n if (countryObj?.subdivisionType)\n this.#applySubdivisionType(countryObj.subdivisionType);\n\n if (subdivisions) {\n this.#cachedSubdivisions = subdivisions;\n this.#subdivisionVisible = subdivisions.length > 0;\n if (subdivisions.length > 0) {\n this.#subdivisionComboBox.data = subdivisions.map((s) => ({\n ...s,\n lang: this.#lang,\n }));\n if (pendingSubdivision)\n toSelect.push([this.#subdivisionComboBox, pendingSubdivision]);\n }\n }\n\n if (cities) {\n this.#cityVisible = cities.length > 0;\n if (cities.length > 0) {\n this.#cachedCities = cities;\n this.#cityComboBox.data = cities.map((c) => ({\n ...c,\n lang: this.#lang,\n }));\n if (pendingCity) toSelect.push([this.#cityComboBox, pendingCity]);\n }\n }\n\n this.#refreshState();\n\n // Apply all selections in one batch. #pendingValue is set to SELECTING so that\n // input events fired by selectedItem= don't trigger cascade-clearing in change handlers.\n this.#pendingValue = SELECTING;\n setTimeout(() => {\n if (this.#pendingValue !== SELECTING) return; // cancelled by a new set value call\n for (const [combo, id] of toSelect) {\n const item = combo.items?.find((i) => i['data-id'] === id);\n if (item) combo.selectedItem = item;\n }\n this.#pendingValue = null;\n });\n }\n\n // --- Change handlers ---\n\n #handleCountryChange() {\n if (this.#pendingValue === SELECTING) return; // programmatic selection in progress\n this.#pendingValue = null; // cancel any in-flight fetch\n this.#resetSubdivision();\n this.#resetCity();\n this.#onCountrySelected(this.#countryComboBox.value);\n this.#dispatchInputEvent();\n }\n\n #handleSubdivisionChange() {\n if (this.#pendingValue === SELECTING) return; // programmatic selection in progress\n this.#pendingValue = null; // cancel any in-flight fetch\n const subdivisionCode = this.#subdivisionComboBox.value;\n this.#resetCity();\n\n if (!this.#isHideCity && subdivisionCode) {\n const countryIso2 = this.#countryComboBox.value;\n if (countryIso2) this.#loadCities(countryIso2, subdivisionCode);\n }\n this.#dispatchInputEvent();\n }\n\n // --- Country selection ---\n\n #onCountrySelected(countryIso2) {\n if (!countryIso2) return;\n\n const country = this.#countriesMap.get(countryIso2);\n if (!country) return;\n\n const { hasSubdivisions, subdivisionType } = country;\n\n if (!this.#isHideSubdivision && hasSubdivisions) {\n this.#applySubdivisionType(subdivisionType);\n this.#loadSubdivisions(countryIso2);\n } else if (!this.#isHideCity) {\n this.#loadCities(countryIso2);\n }\n }\n\n // Apply subdivisionType as label/placeholder, but only when not overridden by an explicit attribute.\n #applySubdivisionType(subdivisionType) {\n const label = this.#resolveSubdivisionTypeLabel(subdivisionType);\n if (!this.#subdivisionLabel)\n this.#setOrRemoveAttr(this.#subdivisionComboBox, 'label', label || null);\n if (!this.#subdivisionPlaceholder)\n this.#setOrRemoveAttr(\n this.#subdivisionComboBox,\n 'placeholder',\n label || null,\n );\n }\n\n #resolveSubdivisionTypeLabel(subdivisionType) {\n const types = this.#labels?.subdivisionTypes;\n const entry = types?.[subdivisionType] ?? types?._fallback;\n if (!entry) return subdivisionType;\n const lang = this.#lang;\n return (\n (lang && (entry[lang] || entry[lang.split('-')[0]])) ||\n entry.en ||\n subdivisionType\n );\n }\n\n // --- Data loading ---\n\n async #loadLabels() {\n try {\n this.#labels = await fetchLabels(this.#baseUrl);\n } catch {\n // Labels are optional; fall back to raw subdivisionType name\n }\n }\n\n async #loadCountries() {\n if (!this.#baseUrl) return;\n this.#countryComboBox.setAttribute('loading', 'true');\n try {\n const [countries] = await Promise.all([\n fetchCountries(this.#baseUrl),\n this.#loadLabels(),\n ]);\n this.#cachedCountries = countries;\n this.#renderCountryItems(countries);\n // Skip defaultCountry if a programmatic set value is in flight\n if (!this.#pendingValue && this.#defaultCountry)\n this.#onCountrySelected(this.#defaultCountry);\n } catch (e) {\n console.error(`[${componentName}] Failed to load countries`, e);\n } finally {\n this.#countryComboBox.removeAttribute('loading');\n }\n }\n\n async #loadSubdivisions(countryIso2) {\n this.#setVisible(this.#subdivisionComboBox, true);\n this.#subdivisionComboBox.setAttribute('loading', 'true');\n try {\n const subdivisions = await fetchSubdivisions(countryIso2, this.#baseUrl);\n this.#cachedSubdivisions = subdivisions;\n this.#subdivisionVisible = subdivisions.length > 0;\n this.#refreshState();\n\n if (subdivisions.length > 0) {\n this.#subdivisionComboBox.data = subdivisions.map((s) => ({\n ...s,\n lang: this.#lang,\n }));\n } else if (!this.#isHideCity) {\n this.#loadCities(countryIso2);\n }\n } catch (e) {\n console.error(\n `[${componentName}] Failed to load subdivisions for ${countryIso2}`,\n e,\n );\n this.#subdivisionVisible = false;\n this.#applyVisibility();\n } finally {\n this.#subdivisionComboBox.removeAttribute('loading');\n }\n }\n\n // stateCode is optional: when omitted, loads all cities for the country\n async #loadCities(countryIso2, stateCode) {\n this.#cityComboBox.setAttribute('loading', 'true');\n try {\n const cities = await (stateCode\n ? fetchCities(countryIso2, stateCode, this.#baseUrl)\n : fetchCitiesForCountry(countryIso2, this.#baseUrl));\n this.#cityVisible = cities.length > 0;\n this.#refreshState();\n if (cities.length > 0) {\n this.#cachedCities = cities;\n this.#cityComboBox.data = cities.map((c) => ({\n ...c,\n lang: this.#lang,\n }));\n }\n } catch (e) {\n console.error(\n `[${componentName}] Failed to load cities for ${countryIso2}${stateCode ? `/${stateCode}` : ''}`,\n e,\n );\n } finally {\n this.#cityComboBox.removeAttribute('loading');\n }\n }\n\n #rerenderOnLangChange() {\n if (this.#cachedCountries) {\n const prevCountry = this.#countryComboBox.value;\n this.#renderCountryItems(this.#cachedCountries);\n if (prevCountry) this.#selectItemById(this.#countryComboBox, prevCountry);\n }\n if (this.#cachedSubdivisions && this.#subdivisionVisible) {\n const prevSubdivision = this.#subdivisionComboBox.value;\n this.#subdivisionComboBox.data = this.#cachedSubdivisions.map((s) => ({\n ...s,\n lang: this.#lang,\n }));\n if (prevSubdivision)\n this.#selectItemById(this.#subdivisionComboBox, prevSubdivision);\n }\n if (this.#cachedCities && this.#cityVisible) {\n const prevCity = this.#cityComboBox.value;\n this.#cityComboBox.data = this.#cachedCities.map((c) => ({\n ...c,\n lang: this.#lang,\n }));\n if (prevCity) this.#selectItemById(this.#cityComboBox, prevCity);\n }\n // Re-apply translated subdivision type label for the new lang\n const currentIso2 = this.#countryComboBox.value;\n if (currentIso2) {\n const country = this.#countriesMap.get(currentIso2);\n if (country?.subdivisionType)\n this.#applySubdivisionType(country.subdivisionType);\n }\n }\n\n // --- Country item rendering ---\n\n #renderCountryItems(countries) {\n const result = this.#applyCountryFilters(countries);\n this.#countryComboBox.data = result.map((c) => ({\n ...c,\n // Include the translated name in the data for search purposes, but not in the label which is rendered by renderItem\n lang: this.#lang,\n }));\n this.#countriesMap = new Map(countries.map((c) => [c.iso2, c]));\n }\n\n #applyCountryFilters(countries) {\n const allowed = this.#allowedCountries;\n const pinned = this.#pinnedCountries;\n\n let filtered = allowed.length\n ? countries.filter((c) => allowed.includes(c.iso2))\n : [...countries];\n\n filtered.sort((a, b) =>\n resolveTranslation(a, this.#lang).localeCompare(\n resolveTranslation(b, this.#lang),\n this.#lang,\n ),\n );\n\n if (!pinned.length) return filtered;\n\n const pinnedItems = pinned\n .map((iso2) => filtered.find((c) => c.iso2 === iso2))\n .filter(Boolean);\n const rest = filtered.filter((c) => !pinned.includes(c.iso2));\n return [...pinnedItems, ...rest];\n }\n\n // --- Visibility & required ---\n\n #applyVisibility() {\n this.#setVisible(this.#countryComboBox, !this.#isHideCountry);\n this.#setVisible(\n this.#subdivisionComboBox,\n !this.#isHideSubdivision &&\n (this.#isNoDataSource || this.#subdivisionVisible),\n );\n this.#setVisible(\n this.#cityComboBox,\n !this.#isHideCity && (this.#isNoDataSource || this.#cityVisible),\n );\n }\n\n #setVisible(el, visible) {\n el?.classList.toggle(`${componentName}-hidden`, !visible);\n }\n\n #updateRequiredOnCombos() {\n const required = this.hasAttribute('required') ? 'true' : null;\n this.#setOrRemoveAttr(\n this.#countryComboBox,\n 'required',\n !this.#isHideCountry ? required : null,\n );\n this.#setOrRemoveAttr(\n this.#subdivisionComboBox,\n 'required',\n !this.#isHideSubdivision &&\n (this.#isNoDataSource || this.#subdivisionVisible)\n ? required\n : null,\n );\n this.#setOrRemoveAttr(\n this.#cityComboBox,\n 'required',\n !this.#isHideCity && (this.#isNoDataSource || this.#cityVisible)\n ? required\n : null,\n );\n }\n\n #refreshState() {\n this.#applyVisibility();\n this.#updateRequiredOnCombos();\n // Re-evaluate validity so that the form knows when newly-visible required fields become empty.\n // e.g. subdivision becomes required after a country with states is selected.\n this.setCustomValidity('');\n }\n\n // --- Reset helpers ---\n\n #resetSubdivision() {\n this.#subdivisionComboBox.value = '';\n this.#subdivisionComboBox.data = [];\n this.#subdivisionVisible = false;\n // Clear any dynamically set label/placeholder from subdivisionType\n if (!this.#subdivisionLabel)\n this.#subdivisionComboBox.removeAttribute('label');\n if (!this.#subdivisionPlaceholder)\n this.#subdivisionComboBox.removeAttribute('placeholder');\n this.#refreshState();\n }\n\n #resetCity() {\n this.#cityComboBox.value = '';\n this.#cityComboBox.data = [];\n this.#cachedCities = null;\n this.#cityVisible = false;\n this.#refreshState();\n }\n\n // --- Utility helpers ---\n\n #dispatchInputEvent() {\n this.dispatchEvent(new Event('input', { bubbles: true, composed: true }));\n }\n\n #setOrRemoveAttr(el, attr, value) {\n if (value) el.setAttribute(attr, value);\n else el.removeAttribute(attr);\n }\n\n #getFirstVisibleCombo() {\n return this.#allCombos.find(\n (combo) => !combo.classList.contains(`${componentName}-hidden`),\n );\n }\n\n #selectItemById(comboBox, id) {\n // Defer the lookup so MutationObserver has time to populate comboBox.items\n setTimeout(() => {\n const item = comboBox.items?.find((i) => i['data-id'] === id);\n if (item) comboBox.selectedItem = item;\n });\n }\n}\n\nexport const CountrySubdivisionCityFieldInternal = compose()(\n RawCountrySubdivisionCityFieldInternal,\n);\n","import {\n CountrySubdivisionCityFieldInternal,\n componentName,\n} from './CountrySubdivisionCityFieldInternal';\n\ncustomElements.define(componentName, CountrySubdivisionCityFieldInternal);\n","import {\n createStyleMixin,\n draggableMixin,\n createProxy,\n proxyInputMixin,\n componentNameValidationMixin,\n} from '@descope-ui/common/components-mixins';\nimport {\n getComponentName,\n forwardAttrs,\n syncAttrs,\n} from '@descope-ui/common/components-helpers';\nimport { compose } from '@descope-ui/common/utils';\nimport { ComboBoxClass } from '@descope-ui/descope-combo-box/class';\nimport { componentName as descopeInternalComponentName } from './descope-country-subdivision-city-field-internal/CountrySubdivisionCityFieldInternal';\n\nexport const componentName = getComponentName('country-subdivision-city-field');\n\nconst customMixin = (superclass) =>\n class CountrySubdivisionCityFieldMixinClass extends superclass {\n init() {\n super.init?.();\n\n const template = document.createElement('template');\n\n template.innerHTML = `\n <${descopeInternalComponentName}\n tabindex=\"-1\"\n ></${descopeInternalComponentName}>\n `;\n\n this.baseElement.appendChild(template.content.cloneNode(true));\n\n this.inputElement = this.shadowRoot.querySelector(\n descopeInternalComponentName,\n );\n\n forwardAttrs(this, this.inputElement, {\n includeAttrs: [\n 'size',\n 'bordered',\n 'required',\n 'label-type',\n 'disabled',\n 'readonly',\n 'hide-country',\n 'hide-subdivision',\n 'hide-city',\n 'default-country',\n 'allowed-countries',\n 'pinned-countries',\n 'country-label',\n 'subdivision-label',\n 'city-label',\n 'country-placeholder',\n 'subdivision-placeholder',\n 'city-placeholder',\n 'data-source-base-url',\n 'lang',\n 'invalid',\n ],\n });\n\n // Sync invalid attribute bidirectionally so external validation feedback propagates\n syncAttrs(this, this.inputElement, { includeAttrs: ['invalid'] });\n }\n };\n\nconst host = { selector: () => ':host' };\n\nconst internalWrapper = {\n selector: `${descopeInternalComponentName} > .wrapper`,\n};\n\nconst internalComboBoxes = {\n selector: `${descopeInternalComponentName} > .wrapper > descope-combo-box`,\n};\n\nexport const CountrySubdivisionCityFieldClass = compose(\n createStyleMixin({\n componentNameOverride: getComponentName('input-wrapper'),\n }),\n createStyleMixin({\n mappings: {\n hostWidth: { ...host, property: 'width' },\n hostDirection: [\n { ...host, property: 'direction' },\n {\n ...internalComboBoxes,\n property: ComboBoxClass.cssVarList.hostDirection,\n },\n ],\n flexDirection: { ...internalWrapper, property: 'flex-direction' },\n flexGap: { ...internalWrapper, property: 'gap' },\n itemAlignment: { ...internalWrapper, property: 'align-items' },\n itemMinWidth: { ...internalComboBoxes, property: 'min-width' },\n itemFlexGrow: { ...internalComboBoxes, property: 'flex-grow' },\n itemWidth: {\n ...internalComboBoxes,\n property: ComboBoxClass.cssVarList.hostWidth,\n },\n },\n }),\n draggableMixin,\n proxyInputMixin({\n proxyProps: ['value'],\n inputEvent: 'input',\n proxyParentValidation: true,\n }),\n componentNameValidationMixin,\n customMixin,\n)(\n createProxy({\n slots: [],\n wrappedEleName: 'vaadin-custom-field',\n style: () => `\n :host {\n display: inline-flex;\n max-width: 100%;\n }\n vaadin-custom-field {\n line-height: unset;\n width: 100%;\n }\n\n ${descopeInternalComponentName} {\n display: inline-block;\n box-sizing: border-box;\n user-select: none;\n width: 100%;\n max-width: 100%;\n }\n\n ${descopeInternalComponentName} > .wrapper {\n display: flex;\n width: 100%;\n flex-wrap: wrap;\n }\n\n .${descopeInternalComponentName}-hidden {\n display: none;\n }\n\n`,\n excludeAttrsSync: ['tabindex', 'style', 'error-message'],\n componentName,\n }),\n);\n","import '@vaadin/custom-field';\nimport '@descope-ui/descope-combo-box';\nimport './descope-country-subdivision-city-field-internal';\n\nimport {\n componentName,\n CountrySubdivisionCityFieldClass,\n} from './CountrySubdivisionCityFieldClass';\n\ncustomElements.define(componentName, CountrySubdivisionCityFieldClass);\n\nexport { CountrySubdivisionCityFieldClass, componentName };\n"],"names":["fetchJson","async","url","response","fetch","ok","Error","status","json","data","fetchCountries","baseUrl","fetchSubdivisions","countryIso2","map","code","rest","state_code","fetchCities","stateCode","fetchLabels","labelsUrl","URL","href","fetchCitiesForCountry","componentName","SELECTING","Symbol","resolveTranslation","name","translations","lang","split","escapeHtml","str","String","replace","c","charCodeAt","countryItem","iso2","iso3","displayName","searchTerms","push","escapedIso2","escapedSearchTerms","join","escapedLabel","subdivisionItem","escapedStateCode","cityItem","escapedId","comboBoxHTML","id","BaseInputClass","baseSelector","commonAttrs","visibilityAttrs","observedAttrs","CountrySubdivisionCityFieldInternal","observedAttributes","concat","Map","constructor","super","this","innerHTML","querySelector","getAttribute","undefined","canonical","Intl","getCanonicalLocales","toUpperCase","trim","filter","Boolean","value","country","subdivision","city","val","parsed","JSON","parse","init","addEventListener","e","isTrusted","firstInvalidCombo","find","combo","classList","contains","checkValidity","focus","renderItem","attributeChangedCallback","attrName","oldValue","newValue","includes","upper","setAttribute","size","getValidity","isRequired","countryMissing","subdivisionMissing","cityMissing","valueMissing","reverse","reportValidity","forEach","customValueTransformFn","item","baseElement","items","i","includeAttrs","mapAttrs","attr","handleFocusEventsDispatching","pendingCountry","pendingSubdivision","pendingCity","shouldLoadSubdivisions","shouldLoadCities","countriesPromise","labelsPromise","subdivisionsPromise","citiesPromise","countries","labels","subdivisions","cities","Promise","allSettled","result","toSelect","countryObj","get","subdivisionType","length","s","setTimeout","selectedItem","subdivisionCode","hasSubdivisions","label","types","subdivisionTypes","entry","_fallback","en","all","console","error","removeAttribute","prevCountry","prevSubdivision","prevCity","currentIso2","allowed","pinned","filtered","sort","a","b","localeCompare","el","visible","toggle","required","hasAttribute","setCustomValidity","dispatchEvent","Event","bubbles","composed","comboBox","customElements","define","host","selector","internalWrapper","internalComboBoxes","CountrySubdivisionCityFieldClass","componentNameOverride","mappings","hostWidth","property","hostDirection","ComboBoxClass","C","cssVarList","flexDirection","flexGap","itemAlignment","itemMinWidth","itemFlexGrow","itemWidth","proxyProps","inputEvent","proxyParentValidation","superclass","template","document","createElement","appendChild","content","cloneNode","inputElement","shadowRoot","slots","wrappedEleName","style","excludeAttrsSync"],"sourceRoot":""}
|