builder-settings-types 0.0.413 → 0.0.414
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.
|
@@ -585,7 +585,7 @@
|
|
|
585
585
|
<path d="M9.39651 1.01051C11.3739 1.1085 13.2506 1.93712 14.6572 3.34372C16.1573 4.84391 16.9999 6.87849 17 9C17 11.1217 16.1575 13.157 14.6572 14.6572C13.157 16.1575 11.1217 17 9 17C6.87849 16.9999 4.84391 16.1573 3.34372 14.6572C1.84345 13.157 1 11.1217 1 9C1.00007 6.8784 1.84352 4.84393 3.34372 3.34372C4.84393 1.84352 6.8784 1.00007 9 1L9.39651 1.01051ZM6.37728 9.63633C6.4447 11.3419 6.77841 12.8501 7.26681 13.9492C7.54127 14.5668 7.85143 15.0276 8.16398 15.3251C8.47319 15.6194 8.75489 15.7282 9 15.7283C9.24512 15.7283 9.52678 15.6193 9.83602 15.3251C10.1486 15.0276 10.4587 14.5668 10.7332 13.9492C11.2216 12.8501 11.5563 11.3419 11.6237 9.63633L6.37728 9.63633ZM2.30324 9.63633C2.45049 11.1873 3.13189 12.6472 4.2428 13.7582C4.89509 14.4104 5.66859 14.9125 6.50914 15.2477C6.36305 15.0042 6.22802 14.7421 6.10498 14.4652C5.53369 13.1795 5.17153 11.4895 5.10367 9.63633H2.30324ZM12.8963 9.63633C12.8285 11.4894 12.4672 13.1795 11.896 14.4652C11.7729 14.7422 11.637 15.0041 11.4909 15.2477C12.3317 14.9125 13.1057 14.4106 13.7582 13.7582C14.8691 12.6472 15.5505 11.1873 15.6977 9.63633H12.8963ZM11.4918 2.7523C11.6379 2.99583 11.7729 3.25794 11.896 3.53481C12.4673 4.8206 12.8285 6.51129 12.8963 8.36462H15.6977C15.5506 6.81361 14.869 5.3538 13.7582 4.2428C13.1059 3.59052 12.3324 3.0875 11.4918 2.7523ZM9 2.27266C8.75489 2.27274 8.47319 2.38159 8.16398 2.67586C7.85146 2.97338 7.54123 3.43415 7.26681 4.05171C6.77841 5.1509 6.44466 6.65897 6.37728 8.36462H11.6237C11.5563 6.65889 11.2216 5.15091 10.7332 4.05171C10.4587 3.434 10.1486 2.97336 9.83602 2.67586C9.5267 2.38149 9.24517 2.27266 9 2.27266ZM6.50818 2.7523C5.6678 3.0875 4.89497 3.59064 4.2428 4.2428C3.13179 5.35382 2.4504 6.81352 2.30324 8.36462H5.10367C5.17149 6.51128 5.53363 4.8206 6.10498 3.53481C6.22796 3.25809 6.36217 2.99572 6.50818 2.7523Z" fill="#637381"/>
|
|
586
586
|
</svg>`,I3=`<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
587
587
|
<path fill-rule="evenodd" clip-rule="evenodd" d="M11.9942 13.4085L17.6485 19.0631C17.837 19.2452 18.0894 19.346 18.3515 19.3437C18.6136 19.3414 18.8643 19.2363 19.0496 19.051C19.2349 18.8656 19.34 18.6149 19.3423 18.3528C19.3446 18.0908 19.2438 17.8383 19.0618 17.6497L13.4075 11.9951L19.0618 6.34039C19.2438 6.15186 19.3446 5.89936 19.3423 5.63728C19.34 5.37519 19.2349 5.12448 19.0496 4.93915C18.8643 4.75381 18.6136 4.64869 18.3515 4.64641C18.0894 4.64413 17.837 4.74489 17.6485 4.92697L11.9942 10.5816L6.33992 4.92697C6.15056 4.74939 5.89954 4.65245 5.63999 4.65666C5.38043 4.66088 5.13269 4.76592 4.9492 4.94955C4.76571 5.13319 4.66085 5.38102 4.65682 5.6406C4.65279 5.90018 4.7499 6.15114 4.9276 6.34039L10.5809 11.9951L4.9266 17.6497C4.83114 17.7419 4.75499 17.8522 4.70261 17.9742C4.65022 18.0961 4.62265 18.2273 4.6215 18.36C4.62034 18.4928 4.64563 18.6244 4.69589 18.7472C4.74615 18.8701 4.82036 18.9817 4.91421 19.0755C5.00806 19.1694 5.11966 19.2436 5.24249 19.2939C5.36533 19.3441 5.49695 19.3694 5.62966 19.3683C5.76238 19.3671 5.89353 19.3395 6.01548 19.2872C6.13742 19.2348 6.24772 19.1586 6.33992 19.0631L11.9942 13.4085Z" fill="#637381"/>
|
|
588
|
-
</svg>`,es="Enter text in {language}...",N3="Enter text in ",xe=(t,e,r)=>({label:e,placeholder:`${N3}${t}`}),Hc={en:xe("en","English"),ka:xe("ka","ქართული"),de:xe("de","Deutsch"),fr:xe("fr","Français"),es:xe("es","Español"),it:xe("it","Italiano"),pt:xe("pt","Português"),nl:xe("nl","Nederlands"),sv:xe("sv","Svenska"),no:xe("no","Norsk"),da:xe("da","Dansk"),fi:xe("fi","Suomi"),pl:xe("pl","Polski"),cs:xe("cs","Čeština"),sk:xe("sk","Slovenčina"),hu:xe("hu","Magyar"),ro:xe("ro","Română"),bg:xe("bg","Български"),uk:xe("uk","Українська"),ru:xe("ru","Русский"),sr:xe("sr","Српски"),hr:xe("hr","Hrvatski"),sl:xe("sl","Slovenščina"),el:xe("el","Ελληνικά"),tr:xe("tr","Türkçe"),ar:xe("ar","العربية"),he:xe("he","עברית"),fa:xe("fa","فارسی"),ur:xe("ur","اردو"),hi:xe("hi","हिन्दी"),bn:xe("bn","বাংলা"),ta:xe("ta","தமிழ்"),te:xe("te","తెలుగు"),mr:xe("mr","मराठी"),gu:xe("gu","ગુજરાતી"),pa:xe("pa","ਪੰਜਾਬੀ"),th:xe("th","ไทย"),vi:xe("vi","TiếngViệt"),id:xe("id","BahasaIndonesia"),ms:xe("ms","BahasaMelayu"),fil:xe("fil","Filipino"),zh:xe("zh","中文"),ja:xe("ja","日本語"),ko:xe("ko","한국어"),sw:xe("sw","Kiswahili"),am:xe("am","አማርኛ"),yo:xe("yo","Yorùbá"),zu:xe("zu","IsiZulu")};function Uc(t){var r,a;const e=Hc[((r=t==null?void 0:t.toLowerCase)==null?void 0:r.call(t))||""];return e!=null&&e.label?e.label:((a=t==null?void 0:t.toUpperCase)==null?void 0:a.call(t))||String(t)}function Wn(t,e=es){var n;const r=Hc[((n=t==null?void 0:t.toLowerCase)==null?void 0:n.call(t))||""];if(r!=null&&r.placeholder)return r.placeholder;const a=Uc(t);return e.includes("{language}")?e.replace("{language}",a):e}function M3(t){const e=document.createElement("div");e.classList.add("simple-multi-language-title");const r=document.createElement("span");r.textContent=t.title??"";const a=document.createElement("button");return a.classList.add("multi-language-eye-icon"),a.innerHTML=A3,a.addEventListener("click",n=>{n.preventDefault(),t.onEyeIconClick()}),e.appendChild(r),e.appendChild(a),e}let Pi;function v0(t,e){Pi||(Pi=document.createElement("canvas"));const r=Pi.getContext("2d");if(!r)return t.length*10;const a=`${e.fontStyle} ${e.fontWeight} ${e.fontSize} ${e.fontFamily}`.trim();return r.font=a,r.measureText(t).width}function Jr(t,e){const r=window.getComputedStyle(t),a=parseFloat(r.paddingLeft)||0,n=parseFloat(r.paddingRight)||0,i=parseFloat(r.borderLeftWidth)||0,s=parseFloat(r.borderRightWidth)||0,o=Math.max(0,t.clientWidth-a-n-i-s);if(o<=0){t.placeholder=e;return}if(v0(e,r)<=o){t.placeholder=e;return}const c="...";let f=0,h=e.length,u=0;for(;f<=h;){const m=Math.floor((f+h)/2),d=e.slice(0,m).trimEnd()+c;v0(d,r)<=o?(u=m,f=m+1):h=m-1}const p=e.slice(0,u).trimEnd()+c;t.placeholder=p}function Xs(t,e=3){t.style.height="auto";const r=window.getComputedStyle(t),a=parseFloat(r.lineHeight)||20,n=parseFloat(r.paddingTop)+parseFloat(r.paddingBottom),i=parseFloat(r.borderTopWidth)+parseFloat(r.borderBottomWidth),s=a*e+n+i,o=Math.min(t.scrollHeight||55,s);t.style.height=`${o}px`,t.scrollHeight>s?t.style.overflowY="auto":t.style.overflowY="hidden"}function O3(t,e=3){requestAnimationFrame(()=>{t.offsetHeight,Xs(t,e);const r=t.getAttribute("data-full-placeholder");r&&Jr(t,r)})}function Wc(t){const e=document.createElement("div");e.classList.add("simple-multi-language-row");const r=document.createElement("label");if(r.classList.add("simple-language-label"),r.textContent=Uc(t.languageCode),r.setAttribute("for",`textarea-${t.languageCode}`),e.appendChild(r),t.multiImg&&t.uploadSetting){const a=t.uploadSetting.draw();a.classList.add("simple-language-upload"),e.appendChild(a)}else{const a=document.createElement("textarea");a.id=`textarea-${t.languageCode}`,a.classList.add("simple-language-textarea"),t.isPopupMode&&a.classList.add("popup-mode"),a.value=t.value||"",a.rows=1,a.style.overflowY="hidden",a.setAttribute("data-full-placeholder",t.placeholder),Jr(a,t.placeholder),t.dataTestId&&a.setAttribute("data-test-id",t.dataTestId);const n=t.maxRows??3;let i=!1,s=!1,o=null;a.addEventListener("compositionstart",()=>{s=!0}),a.addEventListener("compositionend",()=>{s=!1}),a.addEventListener("input",l=>{const c=l.target;i=!0,o&&clearTimeout(o),o=setTimeout(()=>{i=!1,o=null},300),t.onInput(t.languageCode,c.value),Xs(c,n);const f=a.getAttribute("data-full-placeholder")||"";f&&Jr(a,f)}),a.__isUserTyping=()=>i||s,e.appendChild(a),O3(a,n)}return e}function P3(t){const e=document.createElement("div");e.classList.add("multi-language-popup-overlay");const r=document.createElement("div");r.classList.add("multi-language-popup");const a=document.createElement("div");a.classList.add("multi-language-popup-header");const n=document.createElement("h3");n.classList.add("multi-language-popup-title"),n.textContent="All Languages";const i=document.createElement("button");i.classList.add("multi-language-close-button"),i.innerHTML=I3,i.addEventListener("click",()=>t.onClose()),a.appendChild(n),a.appendChild(i),r.appendChild(a);const s=document.createElement("div");s.classList.add("multi-language-popup-content"),t.languages.forEach(c=>{var d;const f=((d=t.values)==null?void 0:d[c])||"",h=Wn(c,t.placeholder),u=t.uploadSettings.get(c),p=t.dataTestPath?`${t.dataTestPath}_${c}`:void 0,m=Wc({languageCode:c,value:f,placeholder:h,isDefaultLanguage:!1,isPopupMode:!0,multiImg:t.multiImg,onInput:t.onInput,uploadSetting:u,dataTestId:p});s.appendChild(m)}),r.appendChild(s);const o=document.createElement("div");o.classList.add("multi-language-popup-footer");const l=document.createElement("button");return l.classList.add("multi-language-done-button"),l.textContent="Done",l.addEventListener("click",()=>t.onClose()),o.appendChild(l),r.appendChild(o),e.appendChild(r),e.addEventListener("mousedown",c=>{c.target===e&&t.onClose()}),e}class ts{static getComponentGroup(e){var s;const r=(s=e.group)==null?void 0:s.trim();if(r)return r;const a=(e.id||"").trim(),n=(e.title||"").trim();if(a&&n){const o=` > ${n}`;if(a.endsWith(o))return a.slice(0,a.length-o.length)||a}return a.split(" > ")[0]||"unknown"}static exportToExcel(e,r,a="translations.xlsx"){const n={};e.forEach(h=>{const u=this.getComponentGroup(h);n[u]||(n[u]=[]),n[u].push(h)});const i=[],s=["Key","Component","Title",...r];i.push(s),i.push([]),Object.keys(n).sort().forEach((h,u)=>{const p=n[h];p.sort((d,g)=>(d.settingTitle||d.title||"").localeCompare(g.settingTitle||g.title||"")),u>0&&i.push([]);const m=["",h,""];r.forEach(()=>m.push("")),i.push(m),p.forEach(d=>{const g=d.settingTitle||this.extractSettingKey(d.title||d.id),w=[d.keyPath||this.extractSettingKey(d.title||d.id),"",g];r.forEach(x=>{w.push(d.value[x]||"")}),i.push(w)})});const l=er.aoa_to_sheet(i),c=[{wch:35},{wch:20},{wch:25},...r.map(()=>({wch:25}))];l["!cols"]=c;const f=er.book_new();er.book_append_sheet(f,l,"Translations"),qi(f,a)}static extractSettingKey(e){return e?e.replace(/ > /g,"."):""}static async importFromExcel(e,r){return new Promise((a,n)=>{const i=new FileReader;i.onload=s=>{var o;try{const l=(o=s.target)==null?void 0:o.result,c=ai(l,{type:"binary"}),f=c.SheetNames[0],h=c.Sheets[f],u=er.sheet_to_json(h,{header:1});if(u.length<2){n(new Error("Excel file is empty or invalid"));return}const p=u[0],m=p.indexOf("Component"),d=p.indexOf("Title"),g=p.indexOf("Key"),v=p.indexOf("Component Path");if(d===-1&&v===-1){n(new Error("Excel file must have 'Title' or 'Component Path' column"));return}const w={};r.forEach(I=>{const L=p.indexOf(I);L!==-1&&(w[I]=L)});const x=[];let b="";for(let I=1;I<u.length;I++){const L=u[I];if(!(!L||L.length===0||L.every(y=>!y||String(y).trim()==="")))if(m!==-1&&d!==-1){const y=L[m],P=typeof y=="string"?y.trim():y!=null?String(y).trim():"";P&&(b=P);const N=L[d],z=typeof N=="string"?N.trim():N!=null?String(N).trim():"",B=g!==-1?L[g]:void 0,D=typeof B=="string"?B.trim():B!=null?String(B).trim():"";if(!z&&!D)continue;const J=(D||z).replace(/\./g," > "),le=b?`${b} > ${J}`:J,ne={};r.forEach(he=>{const oe=w[he];if(oe!==void 0){const Fe=L[oe];ne[he]=Fe!=null?String(Fe):""}}),x.push({id:le,title:J,settingTitle:z||D,keyPath:D||void 0,value:ne})}else{const y=L[v!==-1?v:0],P=typeof y=="string"?y.trim():"";if(!P)continue;const N={};r.forEach(z=>{const B=w[z];if(B!==void 0){const D=L[B];N[z]=D!=null?String(D):""}}),x.push({id:P,title:P,value:N})}}a(x)}catch(l){n(l)}},i.onerror=()=>{n(new Error("Failed to read file"))},i.readAsBinaryString(e)})}static isMultiLanguageValue(e){if(!e||typeof e!="object"||Array.isArray(e))return!1;const r=Object.keys(e),a=/^[a-z]{2}(-[a-z]{2})?$/i,n=r.filter(s=>!s.startsWith("$"));if(n.length===0)return!1;const i=n.filter(s=>a.test(s)&&typeof e[s]=="string");return i.length>0&&i.length>=n.length*.5}static extractMultiLanguageValues(e,r,a="",n){const i=[];for(const[s,o]of Object.entries(e)){const l=a?`${a} > ${s}`:s,c=`${r} > ${l}`;if(this.isMultiLanguageValue(o)){const h=(n?n(c):void 0)||l.replace(/ > /g,"."),u={};for(const[p,m]of Object.entries(o))!p.startsWith("$")&&typeof m=="string"&&(u[p]=m);i.push({id:c,title:l,settingTitle:h,group:r,keyPath:l.replace(/ > /g,"."),value:u})}else if(o&&typeof o=="object"&&!Array.isArray(o)){const f=this.extractMultiLanguageValues(o,r,l,n);i.push(...f)}else Array.isArray(o)&&o.forEach((f,h)=>{if(f&&typeof f=="object"){const u=this.extractMultiLanguageValues(f,r,`${l}[${h}]`,n);i.push(...u)}})}return i}static exportFromComponentInstances(e,r="translations.xlsx",a,n){const i=[],s=!!(n&&n.length),o=new Set(n||[]);if(e.forEach(c=>{if(!c.currentSettings)return;this.extractMultiLanguageValues(c.currentSettings,c.component,"",a).forEach(h=>{i.push(h),s||Object.keys(h.value).forEach(u=>o.add(u))})}),i.length===0){console.warn("No translations found in the provided components");return}const l=Array.from(o).sort();this.exportToExcel(i,l,r)}static async importToComponentInstances(e,r,a,n){const i=!!(n&&n.length),s=new Set(n||[]);r.forEach(h=>{if(!h.currentSettings)return;this.extractMultiLanguageValues(h.currentSettings,h.component).forEach(p=>{i||Object.keys(p.value).forEach(m=>s.add(m))})});const o=Array.from(s).sort(),l=await this.importFromExcel(e,o);a&&l.forEach(h=>{const u=(h.id||"").split(" > "),p=u[0]||"",m=(h.keyPath||h.settingTitle||h.title||u[u.length-1]||"").trim();if(!p||!m)return;const d=a(p,m);d&&(h.id=`${p} > ${d}`,h.title=d)});const c=new Map;return l.forEach(h=>{c.set(h.id,h.value)}),r.map(h=>{const u=this.updateSettingsWithTranslations(JSON.parse(JSON.stringify(h.currentSettings)),h.component,c);return{...h,currentSettings:u}})}static updateSettingsWithTranslations(e,r,a,n=""){const i={};for(const[s,o]of Object.entries(e)){const l=n?`${n} > ${s}`:s,c=`${r} > ${l}`;if(this.isMultiLanguageValue(o)){const f=a.get(c);if(f){const h={...f};for(const[u,p]of Object.entries(o))u.startsWith("$")&&(h[u]=p);i[s]=h}else i[s]=o}else o&&typeof o=="object"&&!Array.isArray(o)?i[s]=this.updateSettingsWithTranslations(o,r,a,l):Array.isArray(o)?i[s]=o.map((f,h)=>f&&typeof f=="object"?this.updateSettingsWithTranslations(f,r,a,`${l}[${h}]`):f):i[s]=o}return i}}const Qt=class Qt extends Ae{constructor(e){super(e),this.inputType={},this.container=null,this.defaultLanguage="",this.uploadSettings=new Map,this.popup=null,this.componentPath="",this.$id="",this.isDerty=!1,this.instanceId=$n(),this.componentPath=e.title||this.instanceId,e.default?this.value=e.default:this.value||(this.value={}),this.value.$id=this.$id=$n(),this.messageHandler=n=>{const{type:i,data:s}=n.data||{};i==="TEXT_ELEMENT_CLICKED"&&s.$id==this.$id&&this.showPopup()};const r=Qt.messageListeners.get(this.instanceId);r&&window.removeEventListener("message",r),Qt.messageListeners.set(this.instanceId,this.messageHandler),window.addEventListener("message",this.messageHandler),this.defaultLanguage=this.resolveDefaultLanguage();const a=e.multiImg?e.defaultValue||"":e.defaultValue||Wn(this.defaultLanguage);e.languages.forEach(n=>{var i,s;n in(this.value||{})||(this.value||(this.value={}),n===this.defaultLanguage&&a?this.value[n]=((i=e.default)==null?void 0:i[n])||a:this.value[n]=((s=e.default)==null?void 0:s[n])||"")})}normalizeLanguageCode(e){return(e||"").trim().toLowerCase()}findLanguageMatch(e){const r=this.normalizeLanguageCode(e);return this.props.languages.find(a=>this.normalizeLanguageCode(a)===r)}resolveDefaultLanguage(){const e=this.findLanguageMatch(Ae.DefaultLanguage),r=Ae.HasExplicitCurrentLanguage()&&Ae.CurrentLanguage()?this.findLanguageMatch(Ae.CurrentLanguage()):void 0;return e||r||this.props.languages[0]}createTextareaRowForLanguage(e,r=!1){var o;const a=((o=this.value)==null?void 0:o[e])||"",n=Wn(e,this.props.placeholder||es),i=this.uploadSettings.get(e);if(this.props.multiImg&&!i){const l=new mn({defaultUrl:a||"",title:"",id:`${this.id}_upload_${e}`});l.setOnChange(c=>{this.updateLanguageValue(e,c),e===this.defaultLanguage&&this.updateOtherLanguagePlaceholders(c)}),this.uploadSettings.set(e,l)}const s=this.getDataPropsPath()?`${this.getDataPropsPath()}_${e}`:void 0;return Wc({languageCode:e,value:a,placeholder:n,isDefaultLanguage:e===this.defaultLanguage,isPopupMode:r,multiImg:this.props.multiImg||!1,onInput:(l,c)=>{this.updateLanguageValue(l,c),l===this.defaultLanguage&&this.updateOtherLanguagePlaceholders(c)},uploadSetting:this.uploadSettings.get(e),dataTestId:s})}updateLanguageValue(e,r){this.value||(this.value={});const a={...this.value,[e]:r};this.setValue(a)}updateOtherLanguagePlaceholders(e){!this.container&&!this.popup||this.props.languages.forEach(r=>{if(r===this.defaultLanguage)return;const a=e||Wn(r,this.props.placeholder||es);[this.container,this.popup].forEach(n=>{const i=n==null?void 0:n.querySelector(`#textarea-${r}`);i&&(!i.value||i.value.trim()==="")&&(i.setAttribute("data-full-placeholder",a),Jr(i,a))})})}renderContent(e){const r=e.querySelector(".simple-multi-language-content");if(!r)return;r.innerHTML="";const a=Ae.HasExplicitCurrentLanguage(),n=Ae.CurrentLanguage();if(!a||!n||!this.props.languages.includes(n))this.props.languages.forEach(i=>{const s=this.createTextareaRowForLanguage(i,!1);r.appendChild(s)});else{const i=this.createTextareaRowForLanguage(n,!1);r.appendChild(i);const s=r.querySelector(".simple-language-textarea");if(s){const o=s.getAttribute("data-full-placeholder")||"";o&&Jr(s,o)}}}showPopup(){var e;this.popup||(this.props.multiImg&&this.props.languages.forEach(r=>{var a;if(!this.uploadSettings.has(r)){const n=((a=this.value)==null?void 0:a[r])||"",i=new mn({defaultUrl:n,title:"",id:`${this.id}_upload_${r}`});i.setOnChange(s=>{this.updateLanguageValue(r,s),r===this.defaultLanguage&&this.updateOtherLanguagePlaceholders(s)}),this.uploadSettings.set(r,i)}}),this.popup=P3({languages:this.props.languages,values:this.value||{},placeholder:this.props.placeholder,multiImg:this.props.multiImg||!1,onClose:()=>this.closePopup(),onInput:(r,a)=>{this.updateLanguageValue(r,a),r===this.defaultLanguage&&this.updateOtherLanguagePlaceholders(a)},uploadSettings:this.uploadSettings,dataTestPath:this.getDataPropsPath()}),document.body.appendChild(this.popup),this.updateOtherLanguagePlaceholders(((e=this.value)==null?void 0:e[this.defaultLanguage])||""))}closePopup(){this.popup&&(document.body.removeChild(this.popup),this.popup=null)}draw(){const e=document.createElement("div");e.classList.add("simple-multi-language-wrapper"),this.defaultLanguage=this.resolveDefaultLanguage();const r=M3({title:this.props.title??"",onEyeIconClick:()=>this.showPopup()});e.appendChild(r);const a=document.createElement("div");return a.classList.add("simple-multi-language-content"),e.appendChild(a),this.container=e,this.renderContent(e),this.languageChangeUnsubscribe=Ae.onLanguageChange(n=>{this.container&&this.renderContent(this.container)}),this.resizeHandler=()=>{if(!this.container)return;this.container.querySelectorAll(".simple-language-textarea").forEach(i=>{const s=i.getAttribute("data-full-placeholder")||"";s&&Jr(i,s)})},window.addEventListener("resize",this.resizeHandler),e}setValue(e){console.log("setValue----------------- "+e),(!e.$id||e.$id!=this.$id)&&(e.$id=this.$id),super.setValue(e),this.container&&this.props.languages.forEach(r=>{var a,n,i;if(this.props.multiImg){const s=this.uploadSettings.get(r);if(s){const o=s.onChange;s.onChange=void 0;try{s.setValue((e==null?void 0:e[r])||"")}finally{s.onChange=o}}}else{const s=[(a=this.container)==null?void 0:a.querySelector(`#textarea-${r}`),(n=this.popup)==null?void 0:n.querySelector(`#textarea-${r}`)].filter(Boolean);for(const o of s){const l=(i=o.__isUserTyping)==null?void 0:i.call(o),c=(e==null?void 0:e[r])||"";if(!l&&o.value!==c){o.value=c,Xs(o,3);const f=o.getAttribute("data-full-placeholder")||"";f&&Jr(o,f)}}}})}static exportAllToExcel(e="translations.xlsx"){const r=[],a=new Set,n=new Map;if(this.instances.forEach((s,o)=>{if(!s.value)return;const c=o.split(" > ")[0]||"",f=s.props.title||"",h=`${c}:${f}`;n.set(h,(n.get(h)||0)+1)}),this.instances.forEach((s,o)=>{if(!s.value)return;s.props.languages.forEach(d=>a.add(d));const l={};s.props.languages.forEach(d=>{var g;l[d]=((g=s.value)==null?void 0:g[d])||""});const c=o.split(" > "),f=c[0]||"",h=c[c.length-1]||"",u=s.props.title||"",p=`${f}:${u}`;let m;u&&n.get(p)>1?m=`${u} (${h})`:u?m=u:m=h,r.push({id:o,title:s.props.title||o,settingTitle:m,value:l})}),r.length===0){console.warn("No translations to export");return}const i=Array.from(a).sort();ts.exportToExcel(r,i,e)}static async importFromExcel(e){const r=new Set;this.instances.forEach(n=>{n.props.languages.forEach(i=>r.add(i))});const a=Array.from(r).sort();try{const n=await ts.importFromExcel(e,a);let i=0;n.forEach(s=>{const o=s.id.split(" > "),l=o[0]||"";let c=s.settingTitle||o[o.length-1]||"",f;const h=c.match(/^(.+)\s*\(([^)]+)\)$/);h&&(c=h[1].trim(),f=h[2].trim());let u=this.instances.get(s.id);if(!u&&f){const p=`${l} > ${f}`;u=this.instances.get(p)}u||(u=this.findInstanceByComponentAndTitle(l,c)),u||(u=this.findInstanceByLeaf(f||c)),u?(u.setValue(s.value),i++):console.warn(`No matching component found for translation "${l} > ${c}". Ensure the Excel uses the setting title or full component path.`)}),console.log(`Successfully imported ${i} translations`)}catch(n){throw console.error("Failed to import translations:",n),n}}static getAllInstances(){return new Map(this.instances)}static clearRegistry(){this.instances.clear()}static findInstanceByLeaf(e){const r=(e||"").trim().toLowerCase();if(!r)return;const a=[];if(this.instances.forEach((n,i)=>{if((n.props.title||"").trim().toLowerCase()===r){a.push(n);return}const o=i.split(">");o[o.length-1].trim().toLowerCase()===r&&a.push(n)}),a.length===1)return a[0];a.length>1&&console.warn(`Multiple components matched the title "${e}". Please use the full component path in the Excel file to disambiguate.`)}static findInstanceByComponentAndTitle(e,r){const a=(e||"").trim().toLowerCase(),n=(r||"").trim().toLowerCase();if(!n)return;const i=[];if(this.instances.forEach((s,o)=>{const l=o.toLowerCase();if(!(a?l.startsWith(a):!0))return;(s.props.title||"").trim().toLowerCase()===n&&i.push(s)}),i.length===1)return i[0];if(i.length>1)return console.warn(`Multiple components matched "${e} > ${r}". Please ensure unique titles within each component.`),i[0]}setComponentPath(e){this.componentPath&&Qt.instances.get(this.componentPath)===this&&Qt.instances.delete(this.componentPath),this.componentPath=e,Qt.instances.set(e,this)}getComponentPath(){return this.componentPath}cleanup(){this.messageHandler&&(window.removeEventListener("message",this.messageHandler),this.messageHandler=void 0),this.resizeHandler&&(window.removeEventListener("resize",this.resizeHandler),this.resizeHandler=void 0),this.languageChangeUnsubscribe&&(this.languageChangeUnsubscribe(),this.languageChangeUnsubscribe=void 0),this.closePopup(),this.instanceId&&this.messageHandler&&(Qt.messageListeners.get(this.instanceId)===this.messageHandler&&Qt.messageListeners.delete(this.instanceId),window.removeEventListener("message",this.messageHandler),this.messageHandler=void 0)}};Qt.instances=new Map,Qt.messageListeners=new Map;let qr=Qt;class D3{constructor(e={}){this.container=null,this.options=e}draw(){const e=document.createElement("div");e.className="translation-manager";const r=document.createElement("h3");r.className="translation-manager-title",r.textContent="Translation Management",e.appendChild(r);const a=document.createElement("div");a.className="translation-manager-buttons";const n=document.createElement("button");n.type="button",n.className="translation-manager-button export-button",n.innerHTML=`
|
|
588
|
+
</svg>`,es="Enter text in {language}...",N3="Enter text in ",xe=(t,e,r)=>({label:e,placeholder:`${N3}${t}`}),Hc={en:xe("en","English"),ka:xe("ka","ქართული"),de:xe("de","Deutsch"),fr:xe("fr","Français"),es:xe("es","Español"),it:xe("it","Italiano"),pt:xe("pt","Português"),nl:xe("nl","Nederlands"),sv:xe("sv","Svenska"),no:xe("no","Norsk"),da:xe("da","Dansk"),fi:xe("fi","Suomi"),pl:xe("pl","Polski"),cs:xe("cs","Čeština"),sk:xe("sk","Slovenčina"),hu:xe("hu","Magyar"),ro:xe("ro","Română"),bg:xe("bg","Български"),uk:xe("uk","Українська"),ru:xe("ru","Русский"),sr:xe("sr","Српски"),hr:xe("hr","Hrvatski"),sl:xe("sl","Slovenščina"),el:xe("el","Ελληνικά"),tr:xe("tr","Türkçe"),ar:xe("ar","العربية"),he:xe("he","עברית"),fa:xe("fa","فارسی"),ur:xe("ur","اردو"),hi:xe("hi","हिन्दी"),bn:xe("bn","বাংলা"),ta:xe("ta","தமிழ்"),te:xe("te","తెలుగు"),mr:xe("mr","मराठी"),gu:xe("gu","ગુજરાતી"),pa:xe("pa","ਪੰਜਾਬੀ"),th:xe("th","ไทย"),vi:xe("vi","TiếngViệt"),id:xe("id","BahasaIndonesia"),ms:xe("ms","BahasaMelayu"),fil:xe("fil","Filipino"),zh:xe("zh","中文"),ja:xe("ja","日本語"),ko:xe("ko","한국어"),sw:xe("sw","Kiswahili"),am:xe("am","አማርኛ"),yo:xe("yo","Yorùbá"),zu:xe("zu","IsiZulu")};function Uc(t){var r,a;const e=Hc[((r=t==null?void 0:t.toLowerCase)==null?void 0:r.call(t))||""];return e!=null&&e.label?e.label:((a=t==null?void 0:t.toUpperCase)==null?void 0:a.call(t))||String(t)}function Wn(t,e=es){var n;const r=Hc[((n=t==null?void 0:t.toLowerCase)==null?void 0:n.call(t))||""];if(r!=null&&r.placeholder)return r.placeholder;const a=Uc(t);return e.includes("{language}")?e.replace("{language}",a):e}function M3(t){const e=document.createElement("div");e.classList.add("simple-multi-language-title");const r=document.createElement("span");r.textContent=t.title??"";const a=document.createElement("button");return a.classList.add("multi-language-eye-icon"),a.innerHTML=A3,a.addEventListener("click",n=>{n.preventDefault(),t.onEyeIconClick()}),e.appendChild(r),e.appendChild(a),e}let Pi;function v0(t,e){Pi||(Pi=document.createElement("canvas"));const r=Pi.getContext("2d");if(!r)return t.length*10;const a=`${e.fontStyle} ${e.fontWeight} ${e.fontSize} ${e.fontFamily}`.trim();return r.font=a,r.measureText(t).width}function Jr(t,e){const r=window.getComputedStyle(t),a=parseFloat(r.paddingLeft)||0,n=parseFloat(r.paddingRight)||0,i=parseFloat(r.borderLeftWidth)||0,s=parseFloat(r.borderRightWidth)||0,o=Math.max(0,t.clientWidth-a-n-i-s);if(o<=0){t.placeholder=e;return}if(v0(e,r)<=o){t.placeholder=e;return}const c="...";let f=0,h=e.length,u=0;for(;f<=h;){const m=Math.floor((f+h)/2),d=e.slice(0,m).trimEnd()+c;v0(d,r)<=o?(u=m,f=m+1):h=m-1}const p=e.slice(0,u).trimEnd()+c;t.placeholder=p}function Xs(t,e=3){t.style.height="auto";const r=window.getComputedStyle(t),a=parseFloat(r.lineHeight)||20,n=parseFloat(r.paddingTop)+parseFloat(r.paddingBottom),i=parseFloat(r.borderTopWidth)+parseFloat(r.borderBottomWidth),s=a*e+n+i,o=Math.min(t.scrollHeight||55,s);t.style.height=`${o}px`,t.scrollHeight>s?t.style.overflowY="auto":t.style.overflowY="hidden"}function O3(t,e=3){requestAnimationFrame(()=>{t.offsetHeight,Xs(t,e);const r=t.getAttribute("data-full-placeholder");r&&Jr(t,r)})}function Wc(t){const e=document.createElement("div");e.classList.add("simple-multi-language-row");const r=document.createElement("label");if(r.classList.add("simple-language-label"),r.textContent=Uc(t.languageCode),r.setAttribute("for",`textarea-${t.languageCode}`),e.appendChild(r),t.multiImg&&t.uploadSetting){const a=t.uploadSetting.draw();a.classList.add("simple-language-upload"),e.appendChild(a)}else{const a=document.createElement("textarea");a.id=`textarea-${t.languageCode}`,a.classList.add("simple-language-textarea"),t.isPopupMode&&a.classList.add("popup-mode"),a.value=t.value||"",a.rows=1,a.style.overflowY="hidden",a.setAttribute("data-full-placeholder",t.placeholder),Jr(a,t.placeholder),t.dataTestId&&a.setAttribute("data-test-id",t.dataTestId);const n=t.maxRows??3;let i=!1,s=!1,o=null;a.addEventListener("compositionstart",()=>{s=!0}),a.addEventListener("compositionend",()=>{s=!1}),a.addEventListener("input",l=>{const c=l.target;i=!0,o&&clearTimeout(o),o=setTimeout(()=>{i=!1,o=null},300),t.onInput(t.languageCode,c.value),Xs(c,n);const f=a.getAttribute("data-full-placeholder")||"";f&&Jr(a,f)}),a.__isUserTyping=()=>i||s,e.appendChild(a),O3(a,n)}return e}function P3(t){const e=document.createElement("div");e.classList.add("multi-language-popup-overlay");const r=document.createElement("div");r.classList.add("multi-language-popup");const a=document.createElement("div");a.classList.add("multi-language-popup-header");const n=document.createElement("h3");n.classList.add("multi-language-popup-title"),n.textContent="All Languages";const i=document.createElement("button");i.classList.add("multi-language-close-button"),i.innerHTML=I3,i.addEventListener("click",()=>t.onClose()),a.appendChild(n),a.appendChild(i),r.appendChild(a);const s=document.createElement("div");s.classList.add("multi-language-popup-content"),t.languages.forEach(c=>{var d;const f=((d=t.values)==null?void 0:d[c])||"",h=Wn(c,t.placeholder),u=t.uploadSettings.get(c),p=t.dataTestPath?`${t.dataTestPath}_${c}`:void 0,m=Wc({languageCode:c,value:f,placeholder:h,isDefaultLanguage:!1,isPopupMode:!0,multiImg:t.multiImg,onInput:t.onInput,uploadSetting:u,dataTestId:p});s.appendChild(m)}),r.appendChild(s);const o=document.createElement("div");o.classList.add("multi-language-popup-footer");const l=document.createElement("button");return l.classList.add("multi-language-done-button"),l.textContent="Done",l.addEventListener("click",()=>t.onClose()),o.appendChild(l),r.appendChild(o),e.appendChild(r),e.addEventListener("mousedown",c=>{c.target===e&&t.onClose()}),e}class ts{static getComponentGroup(e){var s;const r=(s=e.group)==null?void 0:s.trim();if(r)return r;const a=(e.id||"").trim(),n=(e.title||"").trim();if(a&&n){const o=` > ${n}`;if(a.endsWith(o))return a.slice(0,a.length-o.length)||a}return a.split(" > ")[0]||"unknown"}static exportToExcel(e,r,a="translations.xlsx"){const n={};e.forEach(h=>{const u=this.getComponentGroup(h);n[u]||(n[u]=[]),n[u].push(h)});const i=[],s=["Key","Component","Title",...r];i.push(s),i.push([]),Object.keys(n).sort().forEach((h,u)=>{const p=n[h];p.sort((d,g)=>(d.settingTitle||d.title||"").localeCompare(g.settingTitle||g.title||"")),u>0&&i.push([]);const m=["",h,""];r.forEach(()=>m.push("")),i.push(m),p.forEach(d=>{const g=d.settingTitle||this.extractSettingKey(d.title||d.id),w=[d.keyPath||this.extractSettingKey(d.title||d.id),"",g];r.forEach(x=>{w.push(d.value[x]||"")}),i.push(w)})});const l=er.aoa_to_sheet(i),c=[{wch:35},{wch:20},{wch:25},...r.map(()=>({wch:25}))];l["!cols"]=c;const f=er.book_new();er.book_append_sheet(f,l,"Translations"),qi(f,a)}static extractSettingKey(e){return e?e.replace(/ > /g,"."):""}static async importFromExcel(e,r){return new Promise((a,n)=>{const i=new FileReader;i.onload=s=>{var o;try{const l=(o=s.target)==null?void 0:o.result,c=ai(l,{type:"binary"}),f=c.SheetNames[0],h=c.Sheets[f],u=er.sheet_to_json(h,{header:1});if(u.length<2){n(new Error("Excel file is empty or invalid"));return}const p=u[0],m=p.indexOf("Component"),d=p.indexOf("Title"),g=p.indexOf("Key"),v=p.indexOf("Component Path");if(d===-1&&v===-1){n(new Error("Excel file must have 'Title' or 'Component Path' column"));return}const w={};r.forEach(I=>{const L=p.indexOf(I);L!==-1&&(w[I]=L)});const x=[];let b="";for(let I=1;I<u.length;I++){const L=u[I];if(!(!L||L.length===0||L.every(y=>!y||String(y).trim()==="")))if(m!==-1&&d!==-1){const y=L[m],P=typeof y=="string"?y.trim():y!=null?String(y).trim():"";P&&(b=P);const N=L[d],z=typeof N=="string"?N.trim():N!=null?String(N).trim():"",B=g!==-1?L[g]:void 0,D=typeof B=="string"?B.trim():B!=null?String(B).trim():"";if(!z&&!D)continue;const J=(D||z).replace(/\./g," > "),le=b?`${b} > ${J}`:J,ne={};r.forEach(he=>{const oe=w[he];if(oe!==void 0){const Fe=L[oe];ne[he]=Fe!=null?String(Fe):""}}),x.push({id:le,title:J,settingTitle:z||D,keyPath:D||void 0,value:ne})}else{const y=L[v!==-1?v:0],P=typeof y=="string"?y.trim():"";if(!P)continue;const N={};r.forEach(z=>{const B=w[z];if(B!==void 0){const D=L[B];N[z]=D!=null?String(D):""}}),x.push({id:P,title:P,value:N})}}a(x)}catch(l){n(l)}},i.onerror=()=>{n(new Error("Failed to read file"))},i.readAsBinaryString(e)})}static isMultiLanguageValue(e){if(!e||typeof e!="object"||Array.isArray(e))return!1;const r=Object.keys(e),a=/^[a-z]{2}(-[a-z]{2})?$/i,n=r.filter(s=>!s.startsWith("$"));if(n.length===0)return!1;const i=n.filter(s=>a.test(s)&&typeof e[s]=="string");return i.length>0&&i.length>=n.length*.5}static extractMultiLanguageValues(e,r,a="",n){const i=[];for(const[s,o]of Object.entries(e)){const l=a?`${a} > ${s}`:s,c=`${r} > ${l}`;if(this.isMultiLanguageValue(o)){const h=(n?n(c):void 0)||l.replace(/ > /g,"."),u={};for(const[p,m]of Object.entries(o))!p.startsWith("$")&&typeof m=="string"&&(u[p]=m);i.push({id:c,title:l,settingTitle:h,group:r,keyPath:l.replace(/ > /g,"."),value:u})}else if(o&&typeof o=="object"&&!Array.isArray(o)){const f=this.extractMultiLanguageValues(o,r,l,n);i.push(...f)}else Array.isArray(o)&&o.forEach((f,h)=>{if(f&&typeof f=="object"){const u=this.extractMultiLanguageValues(f,r,`${l}[${h}]`,n);i.push(...u)}})}return i}static exportFromComponentInstances(e,r="translations.xlsx",a,n){const i=[],s=!!(n&&n.length),o=new Set(n||[]);if(e.forEach(c=>{if(!c.currentSettings)return;this.extractMultiLanguageValues(c.currentSettings,c.component,"",a).forEach(h=>{i.push(h),s||Object.keys(h.value).forEach(u=>o.add(u))})}),i.length===0){console.warn("No translations found in the provided components");return}const l=Array.from(o).sort();this.exportToExcel(i,l,r)}static async importToComponentInstances(e,r,a,n){const i=!!(n&&n.length),s=new Set(n||[]);r.forEach(h=>{if(!h.currentSettings)return;this.extractMultiLanguageValues(h.currentSettings,h.component).forEach(p=>{i||Object.keys(p.value).forEach(m=>s.add(m))})});const o=Array.from(s).sort(),l=await this.importFromExcel(e,o);a&&l.forEach(h=>{const u=(h.id||"").split(" > "),p=u[0]||"",m=(h.keyPath||h.settingTitle||h.title||u[u.length-1]||"").trim();if(!p||!m)return;const d=a(p,m);d&&(h.id=`${p} > ${d}`,h.title=d)});const c=new Map;return l.forEach(h=>{c.set(h.id,h.value)}),r.map(h=>{const u=this.updateSettingsWithTranslations(JSON.parse(JSON.stringify(h.currentSettings)),h.component,c);return{...h,currentSettings:u}})}static updateSettingsWithTranslations(e,r,a,n=""){const i={};for(const[s,o]of Object.entries(e)){const l=n?`${n} > ${s}`:s,c=`${r} > ${l}`;if(this.isMultiLanguageValue(o)){const f=a.get(c);if(f){const h={...f};for(const[u,p]of Object.entries(o))u.startsWith("$")&&(h[u]=p);i[s]=h}else i[s]=o}else o&&typeof o=="object"&&!Array.isArray(o)?i[s]=this.updateSettingsWithTranslations(o,r,a,l):Array.isArray(o)?i[s]=o.map((f,h)=>f&&typeof f=="object"?this.updateSettingsWithTranslations(f,r,a,`${l}[${h}]`):f):i[s]=o}return i}}const Qt=class Qt extends Ae{constructor(e){super(e),this.inputType={},this.container=null,this.defaultLanguage="",this.uploadSettings=new Map,this.popup=null,this.componentPath="",this.$id="",this.isDerty=!1,this.instanceId=$n(),this.componentPath=e.title||this.instanceId,e.default?this.value=e.default:this.value||(this.value={}),this.value.$id=this.$id=$n(),this.messageHandler=n=>{const{type:i,data:s}=n.data||{};i==="TEXT_ELEMENT_CLICKED"&&s.$id==this.$id&&this.showPopup()};const r=Qt.messageListeners.get(this.instanceId);r&&window.removeEventListener("message",r),Qt.messageListeners.set(this.instanceId,this.messageHandler),window.addEventListener("message",this.messageHandler),this.defaultLanguage=this.resolveDefaultLanguage();const a=e.multiImg?e.defaultValue||"":e.defaultValue||Wn(this.defaultLanguage);e.languages.forEach(n=>{var i,s;n in(this.value||{})||(this.value||(this.value={}),n===this.defaultLanguage&&a?this.value[n]=((i=e.default)==null?void 0:i[n])||a:this.value[n]=((s=e.default)==null?void 0:s[n])||"")})}normalizeLanguageCode(e){return(e||"").trim().toLowerCase()}findLanguageMatch(e){const r=this.normalizeLanguageCode(e);return this.props.languages.find(a=>this.normalizeLanguageCode(a)===r)}resolveDefaultLanguage(){const e=this.findLanguageMatch(Ae.DefaultLanguage),r=Ae.HasExplicitCurrentLanguage()&&Ae.CurrentLanguage()?this.findLanguageMatch(Ae.CurrentLanguage()):void 0;return e||r||this.props.languages[0]}createTextareaRowForLanguage(e,r=!1){var o;const a=((o=this.value)==null?void 0:o[e])||"",n=Wn(e,this.props.placeholder||es),i=this.uploadSettings.get(e);if(this.props.multiImg&&!i){const l=new mn({defaultUrl:a||"",title:"",id:`${this.id}_upload_${e}`});l.setOnChange(c=>{this.updateLanguageValue(e,c),e===this.defaultLanguage&&this.updateOtherLanguagePlaceholders(c)}),this.uploadSettings.set(e,l)}const s=this.getDataPropsPath()?`${this.getDataPropsPath()}_${e}`:void 0;return Wc({languageCode:e,value:a,placeholder:n,isDefaultLanguage:e===this.defaultLanguage,isPopupMode:r,multiImg:this.props.multiImg||!1,onInput:(l,c)=>{this.updateLanguageValue(l,c),l===this.defaultLanguage&&this.updateOtherLanguagePlaceholders(c)},uploadSetting:this.uploadSettings.get(e),dataTestId:s})}updateLanguageValue(e,r){this.value||(this.value={});const a={...this.value,[e]:r};this.setValue(a)}updateOtherLanguagePlaceholders(e){!this.container&&!this.popup||this.props.languages.forEach(r=>{if(r===this.defaultLanguage)return;const a=e||Wn(r,this.props.placeholder||es);[this.container,this.popup].forEach(n=>{const i=n==null?void 0:n.querySelector(`#textarea-${r}`);i&&(!i.value||i.value.trim()==="")&&(i.setAttribute("data-full-placeholder",a),Jr(i,a))})})}renderContent(e){const r=e.querySelector(".simple-multi-language-content");if(!r)return;r.innerHTML="";const a=Ae.HasExplicitCurrentLanguage(),n=Ae.CurrentLanguage();if(!a||!n||!this.props.languages.includes(n))this.props.languages.forEach(i=>{const s=this.createTextareaRowForLanguage(i,!1);r.appendChild(s)});else{const i=this.createTextareaRowForLanguage(n,!1);r.appendChild(i);const s=r.querySelector(".simple-language-textarea");if(s){const o=s.getAttribute("data-full-placeholder")||"";o&&Jr(s,o)}}}showPopup(){var e;this.popup||(this.props.multiImg&&this.props.languages.forEach(r=>{var a;if(!this.uploadSettings.has(r)){const n=((a=this.value)==null?void 0:a[r])||"",i=new mn({defaultUrl:n,title:"",id:`${this.id}_upload_${r}`});i.setOnChange(s=>{this.updateLanguageValue(r,s),r===this.defaultLanguage&&this.updateOtherLanguagePlaceholders(s)}),this.uploadSettings.set(r,i)}}),this.popup=P3({languages:this.props.languages,values:this.value||{},placeholder:this.props.placeholder,multiImg:this.props.multiImg||!1,onClose:()=>this.closePopup(),onInput:(r,a)=>{this.updateLanguageValue(r,a),r===this.defaultLanguage&&this.updateOtherLanguagePlaceholders(a)},uploadSettings:this.uploadSettings,dataTestPath:this.getDataPropsPath()}),document.body.appendChild(this.popup),this.updateOtherLanguagePlaceholders(((e=this.value)==null?void 0:e[this.defaultLanguage])||""))}closePopup(){this.popup&&(document.body.removeChild(this.popup),this.popup=null)}draw(){const e=document.createElement("div");e.classList.add("simple-multi-language-wrapper"),this.defaultLanguage=this.resolveDefaultLanguage();const r=M3({title:this.props.title??"",onEyeIconClick:()=>this.showPopup()});e.appendChild(r);const a=document.createElement("div");return a.classList.add("simple-multi-language-content"),e.appendChild(a),this.container=e,this.renderContent(e),this.languageChangeUnsubscribe=Ae.onLanguageChange(n=>{this.container&&this.renderContent(this.container)}),this.resizeHandler=()=>{if(!this.container)return;this.container.querySelectorAll(".simple-language-textarea").forEach(i=>{const s=i.getAttribute("data-full-placeholder")||"";s&&Jr(i,s)})},window.addEventListener("resize",this.resizeHandler),e}setValue(e){console.log("setValue----------------- "+e),(!e.$id||e.$id!=this.$id)&&(e.$id=this.$id),super.setValue(e),this.container&&this.props.languages.forEach(r=>{var a,n,i;if(this.props.multiImg){const s=this.uploadSettings.get(r);if(s){const o=s.onChange;s.onChange=void 0;try{s.setValue((e==null?void 0:e[r])||"")}finally{s.onChange=o}}}else{const s=[(a=this.container)==null?void 0:a.querySelector(`#textarea-${r}`),(n=this.popup)==null?void 0:n.querySelector(`#textarea-${r}`)].filter(Boolean);for(const o of s){const l=(i=o.__isUserTyping)==null?void 0:i.call(o),c=(e==null?void 0:e[r])||"";if(!l&&o.value!==c){o.value=c,Xs(o,3);const f=o.getAttribute("data-full-placeholder")||"";f&&Jr(o,f)}}}})}static exportAllToExcel(e="translations.xlsx"){const r=[],a=new Set,n=new Map;if(this.instances.forEach((s,o)=>{if(!s.value)return;const c=o.split(" > ")[0]||"",f=s.props.title||"",h=`${c}:${f}`;n.set(h,(n.get(h)||0)+1)}),this.instances.forEach((s,o)=>{if(!s.value)return;s.props.languages.forEach(v=>a.add(v));const l={};s.props.languages.forEach(v=>{var w;l[v]=((w=s.value)==null?void 0:w[v])||""});const c=o.split(" > "),f=c[0]||"",h=c[c.length-1]||"",u=s.props.title||"",p=`${f}:${u}`,m=c.slice(1,-1),d=u||h;let g;m.length>0?g=[...m,d].join(" > "):u&&n.get(p)>1?g=`${u} (${h})`:g=d,r.push({id:o,title:s.props.title||o,settingTitle:g,value:l})}),r.length===0){console.warn("No translations to export");return}const i=Array.from(a).sort();ts.exportToExcel(r,i,e)}static async importFromExcel(e){const r=new Set;this.instances.forEach(n=>{n.props.languages.forEach(i=>r.add(i))});const a=Array.from(r).sort();try{const n=await ts.importFromExcel(e,a);let i=0;n.forEach(s=>{const o=s.id.split(" > "),l=o[0]||"";let c=s.settingTitle||o[o.length-1]||"",f;const h=c.match(/^(.+)\s*\(([^)]+)\)$/);h&&(c=h[1].trim(),f=h[2].trim());let u=this.instances.get(s.id);if(!u&&f){const p=`${l} > ${f}`;u=this.instances.get(p)}u||(u=this.findInstanceByComponentAndTitle(l,c)),u||(u=this.findInstanceByLeaf(f||c)),u?(u.setValue(s.value),i++):console.warn(`No matching component found for translation "${l} > ${c}". Ensure the Excel uses the setting title or full component path.`)}),console.log(`Successfully imported ${i} translations`)}catch(n){throw console.error("Failed to import translations:",n),n}}static getAllInstances(){return new Map(this.instances)}static clearRegistry(){this.instances.clear()}static findInstanceByLeaf(e){const r=(e||"").trim().toLowerCase();if(!r)return;const a=[];if(this.instances.forEach((n,i)=>{if((n.props.title||"").trim().toLowerCase()===r){a.push(n);return}const o=i.split(">");o[o.length-1].trim().toLowerCase()===r&&a.push(n)}),a.length===1)return a[0];a.length>1&&console.warn(`Multiple components matched the title "${e}". Please use the full component path in the Excel file to disambiguate.`)}static findInstanceByComponentAndTitle(e,r){const a=(e||"").trim().toLowerCase(),n=(r||"").trim().toLowerCase();if(!n)return;const i=[];if(this.instances.forEach((s,o)=>{const l=o.toLowerCase();if(!(a?l.startsWith(a):!0))return;(s.props.title||"").trim().toLowerCase()===n&&i.push(s)}),i.length===1)return i[0];if(i.length>1)return console.warn(`Multiple components matched "${e} > ${r}". Please ensure unique titles within each component.`),i[0]}setComponentPath(e){this.componentPath&&Qt.instances.get(this.componentPath)===this&&Qt.instances.delete(this.componentPath),this.componentPath=e,Qt.instances.set(e,this)}getComponentPath(){return this.componentPath}cleanup(){this.messageHandler&&(window.removeEventListener("message",this.messageHandler),this.messageHandler=void 0),this.resizeHandler&&(window.removeEventListener("resize",this.resizeHandler),this.resizeHandler=void 0),this.languageChangeUnsubscribe&&(this.languageChangeUnsubscribe(),this.languageChangeUnsubscribe=void 0),this.closePopup(),this.instanceId&&this.messageHandler&&(Qt.messageListeners.get(this.instanceId)===this.messageHandler&&Qt.messageListeners.delete(this.instanceId),window.removeEventListener("message",this.messageHandler),this.messageHandler=void 0)}};Qt.instances=new Map,Qt.messageListeners=new Map;let qr=Qt;class D3{constructor(e={}){this.container=null,this.options=e}draw(){const e=document.createElement("div");e.className="translation-manager";const r=document.createElement("h3");r.className="translation-manager-title",r.textContent="Translation Management",e.appendChild(r);const a=document.createElement("div");a.className="translation-manager-buttons";const n=document.createElement("button");n.type="button",n.className="translation-manager-button export-button",n.innerHTML=`
|
|
589
589
|
<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
590
590
|
<path d="M8 2V10M8 10L11 7M8 10L5 7M3 12V13C3 13.5523 3.44772 14 4 14H12C12.5523 14 13 13.5523 13 13V12" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round"/>
|
|
591
591
|
</svg>
|
|
@@ -30313,8 +30313,13 @@ const Zt = class Zt extends Ae {
|
|
|
30313
30313
|
const { type: i, data: s } = n.data || {};
|
|
30314
30314
|
i === "TEXT_ELEMENT_CLICKED" && s.$id == this.$id && this.showPopup();
|
|
30315
30315
|
};
|
|
30316
|
-
const r = Zt.messageListeners.get(
|
|
30317
|
-
|
|
30316
|
+
const r = Zt.messageListeners.get(
|
|
30317
|
+
this.instanceId
|
|
30318
|
+
);
|
|
30319
|
+
r && window.removeEventListener("message", r), Zt.messageListeners.set(
|
|
30320
|
+
this.instanceId,
|
|
30321
|
+
this.messageHandler
|
|
30322
|
+
), window.addEventListener("message", this.messageHandler), this.defaultLanguage = this.resolveDefaultLanguage();
|
|
30318
30323
|
const a = e.multiImg ? e.defaultValue || "" : e.defaultValue || Hn(this.defaultLanguage);
|
|
30319
30324
|
e.languages.forEach((n) => {
|
|
30320
30325
|
var i, s;
|
|
@@ -30326,7 +30331,9 @@ const Zt = class Zt extends Ae {
|
|
|
30326
30331
|
}
|
|
30327
30332
|
findLanguageMatch(e) {
|
|
30328
30333
|
const r = this.normalizeLanguageCode(e);
|
|
30329
|
-
return this.props.languages.find(
|
|
30334
|
+
return this.props.languages.find(
|
|
30335
|
+
(a) => this.normalizeLanguageCode(a) === r
|
|
30336
|
+
);
|
|
30330
30337
|
}
|
|
30331
30338
|
resolveDefaultLanguage() {
|
|
30332
30339
|
const e = this.findLanguageMatch(Ae.DefaultLanguage), r = Ae.HasExplicitCurrentLanguage() && Ae.CurrentLanguage() ? this.findLanguageMatch(Ae.CurrentLanguage()) : void 0;
|
|
@@ -30334,7 +30341,10 @@ const Zt = class Zt extends Ae {
|
|
|
30334
30341
|
}
|
|
30335
30342
|
createTextareaRowForLanguage(e, r = !1) {
|
|
30336
30343
|
var o;
|
|
30337
|
-
const a = ((o = this.value) == null ? void 0 : o[e]) || "", n = Hn(
|
|
30344
|
+
const a = ((o = this.value) == null ? void 0 : o[e]) || "", n = Hn(
|
|
30345
|
+
e,
|
|
30346
|
+
this.props.placeholder || Qi
|
|
30347
|
+
), i = this.uploadSettings.get(e);
|
|
30338
30348
|
if (this.props.multiImg && !i) {
|
|
30339
30349
|
const l = new ai({
|
|
30340
30350
|
defaultUrl: a || "",
|
|
@@ -30368,15 +30378,22 @@ const Zt = class Zt extends Ae {
|
|
|
30368
30378
|
updateOtherLanguagePlaceholders(e) {
|
|
30369
30379
|
!this.container && !this.popup || this.props.languages.forEach((r) => {
|
|
30370
30380
|
if (r === this.defaultLanguage) return;
|
|
30371
|
-
const a = e || Hn(
|
|
30381
|
+
const a = e || Hn(
|
|
30382
|
+
r,
|
|
30383
|
+
this.props.placeholder || Qi
|
|
30384
|
+
);
|
|
30372
30385
|
[this.container, this.popup].forEach((n) => {
|
|
30373
|
-
const i = n == null ? void 0 : n.querySelector(
|
|
30386
|
+
const i = n == null ? void 0 : n.querySelector(
|
|
30387
|
+
`#textarea-${r}`
|
|
30388
|
+
);
|
|
30374
30389
|
i && (!i.value || i.value.trim() === "") && (i.setAttribute("data-full-placeholder", a), Kr(i, a));
|
|
30375
30390
|
});
|
|
30376
30391
|
});
|
|
30377
30392
|
}
|
|
30378
30393
|
renderContent(e) {
|
|
30379
|
-
const r = e.querySelector(
|
|
30394
|
+
const r = e.querySelector(
|
|
30395
|
+
".simple-multi-language-content"
|
|
30396
|
+
);
|
|
30380
30397
|
if (!r) return;
|
|
30381
30398
|
r.innerHTML = "";
|
|
30382
30399
|
const a = Ae.HasExplicitCurrentLanguage(), n = Ae.CurrentLanguage();
|
|
@@ -30388,7 +30405,9 @@ const Zt = class Zt extends Ae {
|
|
|
30388
30405
|
else {
|
|
30389
30406
|
const i = this.createTextareaRowForLanguage(n, !1);
|
|
30390
30407
|
r.appendChild(i);
|
|
30391
|
-
const s = r.querySelector(
|
|
30408
|
+
const s = r.querySelector(
|
|
30409
|
+
".simple-language-textarea"
|
|
30410
|
+
);
|
|
30392
30411
|
if (s) {
|
|
30393
30412
|
const o = s.getAttribute("data-full-placeholder") || "";
|
|
30394
30413
|
o && Kr(s, o);
|
|
@@ -30420,7 +30439,9 @@ const Zt = class Zt extends Ae {
|
|
|
30420
30439
|
},
|
|
30421
30440
|
uploadSettings: this.uploadSettings,
|
|
30422
30441
|
dataTestPath: this.getDataPropsPath()
|
|
30423
|
-
}), document.body.appendChild(this.popup), this.updateOtherLanguagePlaceholders(
|
|
30442
|
+
}), document.body.appendChild(this.popup), this.updateOtherLanguagePlaceholders(
|
|
30443
|
+
((e = this.value) == null ? void 0 : e[this.defaultLanguage]) || ""
|
|
30444
|
+
));
|
|
30424
30445
|
}
|
|
30425
30446
|
closePopup() {
|
|
30426
30447
|
this.popup && (document.body.removeChild(this.popup), this.popup = null);
|
|
@@ -30438,7 +30459,9 @@ const Zt = class Zt extends Ae {
|
|
|
30438
30459
|
this.container && this.renderContent(this.container);
|
|
30439
30460
|
}), this.resizeHandler = () => {
|
|
30440
30461
|
if (!this.container) return;
|
|
30441
|
-
this.container.querySelectorAll(
|
|
30462
|
+
this.container.querySelectorAll(
|
|
30463
|
+
".simple-language-textarea"
|
|
30464
|
+
).forEach((i) => {
|
|
30442
30465
|
const s = i.getAttribute("data-full-placeholder") || "";
|
|
30443
30466
|
s && Kr(i, s);
|
|
30444
30467
|
});
|
|
@@ -30482,18 +30505,18 @@ const Zt = class Zt extends Ae {
|
|
|
30482
30505
|
n.set(h, (n.get(h) || 0) + 1);
|
|
30483
30506
|
}), this.instances.forEach((s, o) => {
|
|
30484
30507
|
if (!s.value) return;
|
|
30485
|
-
s.props.languages.forEach((
|
|
30508
|
+
s.props.languages.forEach((v) => a.add(v));
|
|
30486
30509
|
const l = {};
|
|
30487
|
-
s.props.languages.forEach((
|
|
30488
|
-
var
|
|
30489
|
-
l[
|
|
30510
|
+
s.props.languages.forEach((v) => {
|
|
30511
|
+
var w;
|
|
30512
|
+
l[v] = ((w = s.value) == null ? void 0 : w[v]) || "";
|
|
30490
30513
|
});
|
|
30491
|
-
const c = o.split(" > "), f = c[0] || "", h = c[c.length - 1] || "", u = s.props.title || "", p = `${f}:${u}
|
|
30492
|
-
let
|
|
30493
|
-
u && n.get(p) > 1 ?
|
|
30514
|
+
const c = o.split(" > "), f = c[0] || "", h = c[c.length - 1] || "", u = s.props.title || "", p = `${f}:${u}`, m = c.slice(1, -1), d = u || h;
|
|
30515
|
+
let g;
|
|
30516
|
+
m.length > 0 ? g = [...m, d].join(" > ") : u && n.get(p) > 1 ? g = `${u} (${h})` : g = d, r.push({
|
|
30494
30517
|
id: o,
|
|
30495
30518
|
title: s.props.title || o,
|
|
30496
|
-
settingTitle:
|
|
30519
|
+
settingTitle: g,
|
|
30497
30520
|
value: l
|
|
30498
30521
|
});
|
|
30499
30522
|
}), r.length === 0) {
|
|
@@ -30510,7 +30533,10 @@ const Zt = class Zt extends Ae {
|
|
|
30510
30533
|
});
|
|
30511
30534
|
const a = Array.from(r).sort();
|
|
30512
30535
|
try {
|
|
30513
|
-
const n = await x0.importFromExcel(
|
|
30536
|
+
const n = await x0.importFromExcel(
|
|
30537
|
+
e,
|
|
30538
|
+
a
|
|
30539
|
+
);
|
|
30514
30540
|
let i = 0;
|
|
30515
30541
|
n.forEach((s) => {
|
|
30516
30542
|
const o = s.id.split(" > "), l = o[0] || "";
|
|
@@ -30522,7 +30548,10 @@ const Zt = class Zt extends Ae {
|
|
|
30522
30548
|
const p = `${l} > ${f}`;
|
|
30523
30549
|
u = this.instances.get(p);
|
|
30524
30550
|
}
|
|
30525
|
-
u || (u = this.findInstanceByComponentAndTitle(
|
|
30551
|
+
u || (u = this.findInstanceByComponentAndTitle(
|
|
30552
|
+
l,
|
|
30553
|
+
c
|
|
30554
|
+
)), u || (u = this.findInstanceByLeaf(f || c)), u ? (u.setValue(s.value), i++) : console.warn(
|
|
30526
30555
|
`No matching component found for translation "${l} > ${c}". Ensure the Excel uses the setting title or full component path.`
|
|
30527
30556
|
);
|
|
30528
30557
|
}), console.log(`Successfully imported ${i} translations`);
|
package/package.json
CHANGED