@ws-ui/localization-editor 1.11.7-rc4 → 1.11.7-rc5

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/index.cjs.js CHANGED
@@ -119,7 +119,7 @@ Defaulting to 2020, but this will stop working in the future.`)),p.ecmaVersion=1
119
119
  `,{webforms:u,i18n:c}=e;return u&&Object.keys(u).forEach(h=>{const g=xe.get(u,`${h}`);Object.keys(g).forEach(w=>{const{props:S,resolverName:y}=xe.get(g,w);Array.isArray(S)&&S.forEach(({__dataPath:k,__default:v,..._})=>{const A=s();o(A,"keys",`webforms.${h}.${w}.${k}`),o(A,"__t",lh(v)),o(A,"resolverName",y),Object.keys(_).forEach(x=>{let f=x;x.startsWith("states:")&&(f=x.replace("states:",""),f=f.replace("i18n:","")),o(A,f,lh(_[x]))}),r+=l(A)})})}),c&&Object.keys(c).forEach(h=>{const g=xe.get(c,h);g&&Object.keys(g).forEach(w=>{const S=xe.get(g,w),y=s();o(y,"keys",`i18n.${h}.${w}`),o(y,w==="default"?"key_default":w,S),r+=l(y)})}),l(i)+r},Si=(e,t)=>{let n=e;return t.bold&&(n=`**${n}**`),t.italic&&(n=`*${n}*`),t.underlined&&(n=`<u>${n}</u>`),t.strikethrough&&(n=`~~${n}~~`),n},_i={datasource:e=>{const{datasource:t,dsType:n,format:r,children:i}=e;let s,o="";return i&&i[0]&&(s=i[0],o=`<ds datasource='${t}' dsType='${n}' format='${r}'>${Si(s.text,s)}</ds>`),o},link:e=>{const{url:t,target:n,datasource:r,isDatasource:i,children:s}=e;let o="";if(s&&s[0]){const{text:l,...u}=s[0];o=`<link datasource='${r}' isDatasource='${i}' url='${t}' target='${n}'>${Si(l,u)}</link>`}return o},i18n:e=>{const{children:t,__i18n:n}=e;let r="";if(t&&t[0]){const{text:i,...s}=t[0];r=`<i18n __i18n='${n}'>${Si(i,s)}</i18n>`}return r},defaultElement:e=>{const{text:t}=e;return Si(t,e)}},MI=e=>{const{type:t,text:n}=e;if(!t&&!n)return"<e/>";switch(t){case"datasource":return _i.datasource(e);case"link":return _i.link(e);case"i18n":return _i.i18n(e);default:return _i.defaultElement(e)}},jI=e=>e.map(t=>{const{children:n}=t;return n?n.map(r=>MI(r)).join(""):""}).filter(Boolean).join(`
120
120
 
121
121
  `),FI=e=>{const t=/<\/?[a-zA-Z][^>]*>/g;let n="",r=0;for(const s of e.matchAll(t)){const o=s.index,l=o+s[0].length,u=e.slice(r,o).replace(/</g,"&lt;").replace(/>/g,"&gt;");n+=u+s[0],r=l}const i=e.slice(r).replace(/</g,"&lt;").replace(/>/g,"&gt;");return n+=i,n=n.replace(/\[object Object\]/g,""),n},zI=e=>{let t="",n=!1;for(let r=0;r<e.length;r++){const i=e[r];if(i==='"')if(n)if(r+1<e.length&&e[r+1]==='"')t+='""',r++;else{let s=r+1;for(;s<e.length&&(e[s]===" "||e[s]===" ");)s++;s>=e.length||e[s]===","||e[s]===`
122
- `||e[s]==="\r"?(n=!1,t+='"'):t+='""'}else n=!0,t+='"';else t+=i}return t},ba=e=>{const t=FI(e),n=rE().use(DI,{singleTilde:!0}).use(Hk).parse(t),r=(s,o,l)=>{var h;const{type:u,value:c}=s;let d={};if(u==="root"){const{children:g}=s;return g.map(m=>r(m,o)).flat()}if(o){if(u==="list"){const{children:g}=s;return g.map(m=>r(m,d,l)).flat()}else if(u==="listItem"){const{children:g}=s;return g.map(m=>{const w=l!=null&&l.prefix?l.prefix:m.type==="list"?" - ":"* ",S=r(m,d,{prefix:w});return S.type==="paragraph"&&S.children&&(S.children.length>1?S.children=[{text:w},...S.children]:S.children=S.children.map(y=>(y.text&&(y.text=`${w}${y.text}`),y))),S}).flat()}else if(u==="paragraph"){d={type:"paragraph",children:[]};const{children:g}=s,m=g.map(w=>r(w,d));d.children=m}else if(u==="mdxJsxTextElement"){const{name:g}=s;if(g==="ds"){d={type:"datasource",children:[]};const{children:m,attributes:w}=s;if(m){const S=r(m[0],d);d.children=[S]}if(w){const S=w.reduce((y,k)=>({...y,[k.name]:k.value}),{});d={...d,...S}}}else if(g==="i18n"){d={type:"i18n",children:""};const{children:m,attributes:w}=s;if(m){const S=r(m[0],d);d.children=[S]}if(w){const S=w.reduce((y,k)=>({...y,[k.name]:k.value}),{});d={...d,...S}}}else if(g==="u"){d={underlined:!0};const{children:m}=s;if(m){const w=r(m[0],d);d={...d,...w}}}else if(g==="link"){d={type:"link",children:[]};const{children:m,attributes:w}=s;if(m){const S=r(m[0],d);d.children=[S]}if(w){const S=w.reduce((y,k)=>({...y,[k.name]:k.value}),{});d={...d,...S}}}else g==="e"&&(d={text:""})}else if(u==="text")d={text:c};else if(u==="strong"){d={bold:!0};const{children:g}=s;if(g){const m=r(g[0],d);d={...d,...m}}}else if(u==="emphasis"){d={italic:!0};const{children:g}=s;if(g){const m=r(g[0],d);d={...d,...m}}}else if(u==="delete"){d={strikethrough:!0};const{children:g}=s;if(g){const m=r(g[0],d);d={...d,...m}}}else if(u==="link"){const{children:g}=s;d={text:((h=g[0])==null?void 0:h.value)||""}}}else return;return d};return r(n,[])},BI=e=>{const[,t,n,r,...i]=e.split(".");return{webformName:t,componentId:n,propName:r,restOfPropPath:i.join(".")}},bl=()=>document.querySelector(`.${io.LOCALIZATION_EDITOR_SCOPE_CLASS}`)||document.body,Mg=({container:e,...t})=>C.jsx(ve.Portal,{...t,container:e||bl()}),jg=({children:e,isOpen:t,onClose:n,title:r})=>C.jsx(Mg,{children:C.jsx(Ar.Transition,{appear:!0,show:t,as:D.Fragment,children:C.jsxs(Ar.Dialog,{as:"div",className:"relative z-[1000]",onClose:n,children:[C.jsx(Ar.Transition.Child,{as:D.Fragment,enter:"ease-out duration-300",enterFrom:"opacity-0",enterTo:"opacity-100",leave:"ease-in duration-200",leaveFrom:"opacity-100",leaveTo:"opacity-0",children:C.jsx("div",{className:"fixed inset-0 bg-black bg-opacity-75"})}),C.jsx("div",{className:"fixed inset-0 overflow-y-auto",children:C.jsx("div",{className:"flex min-h-full items-center justify-center p-4 text-center",children:C.jsx(Ar.Transition.Child,{as:D.Fragment,enter:"ease-out duration-300",enterFrom:"opacity-0 scale-95",enterTo:"opacity-100 scale-100",leave:"ease-in duration-200",leaveFrom:"opacity-100 scale-100",leaveTo:"opacity-0 scale-95",children:C.jsxs(Ar.Dialog.Panel,{className:"w-full space-y-2 max-w-md transform overflow-hidden rounded border border-grey-50 bg-grey-900 px-5 py-4 text-left align-middle text-white shadow-xl transition-all",children:[C.jsxs("div",{className:"flex flex-col items-center justify-center space-y-2",children:[C.jsx(ot.FdDownload,{className:"h-6 w-6"}),C.jsx("h3",{className:"mt-4 text-sm font-bold",children:r})]}),C.jsx("div",{className:"space-y-2",children:e})]})})})})]})})}),uh={DROP_EVENT_ERROR:"Not Suported File type! Only .json and .csv are Supported.",DROP_VALID_FILE:"Drop or Add a File !"},HI=({disable:e,enable:t})=>{const n=Fn(),{state:{file:r,isOpen:i,supprtedExtension:s,error:o,content:l},actions:u}=ve.useStateObject({file:null,error:"",isOpen:!1,fileType:"",supprtedExtension:[".json",".csv"],content:{}}),[c,d]=D.useState(!1),h=n.getWebformTabs(),{getRootProps:g,getInputProps:m,isDragActive:w}=Jm.useDropzone({async onDropAccepted([L]){if(s.find(N=>L.name.endsWith(N))){u.setError(""),u.setFile(L);const N=await k(L),$=L.name.split(".").pop()||"";let U;try{U=R(N,$)}catch{u.setError("Invalid File");return}u.setContent(U||{});const J={type:"object",anyOf:[{required:["webforms"]},{required:["i18n"]}]};new Ym.Validator().validate(U,J).valid||u.setError("Invalid File")}else u.setError(uh.DROP_EVENT_ERROR)},accept:{"application/*":s},multiple:!1}),S=()=>{u.setFileType(""),u.setError(""),u.setFile(null)},y=()=>{u.setIsOpen(!1),S()},k=L=>new Promise(N=>{const $=new FileReader;$.onload=()=>N($.result),$.readAsText(L)}),v=async(L,N,$)=>{if($){const U=`WebForms/${N}.WebForm`;await n.actions.setTabContent({path:U,content:L.content}),ve.webformSubject.next({path:U,action:ve.WebformActions.RECOMPUTE,payload:L.content.components})}else{const U={...L};await ve.saveContent({verb:ve.DesignerRequestVerb.SAVE_CONTENT,content:U.content,path:`WebForms/${N}.WebForm`})}},_=(L,N)=>{const{content:{components:$}}=xe.cloneDeep(L);if(!$)return L;const U=(Q,Z,q,K)=>{if(Array.isArray(Q))Q.forEach((ie,E)=>{let M="";q==="Text"?M=Array.isArray(ie)?`${Z}.[${E}].children`:`${Z}.[${E}]`:M=`${Z}.[${E}]`,U(ie,M,q,K)});else if(xe.isObject(Q))if(Object.keys(Q).length>1){const E=Object.keys(Q),M={};E.forEach(T=>{const B=xe.get(Q,T);if(T==="__t")xe.set(K,`props.${Z}`,B);else if(B&&T.startsWith("states:")){const z=T.split(":"),W=z.map((F,te)=>te+1===z.length?`i18n:${F}`:F).join(":");if(!K.custom)return;xe.set(M,`${W}.${Z}`,B)}else if(B){const z=`i18n:${T}`;if(!K.custom)return;xe.set(M,`${z}.${Z}`,B)}});const[H]=Z.split(".");Object.entries(M).forEach(([T,B])=>{const z=xe.get(K,`props.${H}`,{}),W=xe.get(K,`custom.${T}.${H}`);let F="";typeof W=="string"||typeof z=="string"?F=xe.get(B,H):F=xe.merge(W||xe.cloneDeep(z),xe.get(B,H)),xe.set(K,`custom.${T}.${H}`,F)})}else{const E=Object.entries(Q)[0],M=E[0],H=E[1];Z=`${Z}.${M}`,U(H,Z,q,K)}},J=Object.entries(N);for(let Q=0;Q<J.length;Q++){const[Z,q]=J[Q],{resolverName:K,...ie}=q,E=xe.get($,Z);if(E)if(K==="Text"){const{custom:M,props:H}=ie;xe.set($,Z,{...E,props:{...E.props,...H},custom:{...E.custom,...M}})}else Object.entries(ie).forEach(([M,H])=>{const T=xe.get($,Z);if(!T)return;const B=xe.cloneDeep(T);U(H,M,K,B),xe.set($,Z,B)})}const Y=xe.cloneDeep(L);return xe.set(Y,"content.components",$),Y},A=async(L,N,$)=>{const{webforms:U,i18n:J}=L;ve.i18nSubject.next({action:"set_content",payload:J});const Y=Q=>{const Z=Q+1===N.length?N.length:Q,q=Math.ceil(Z/N.length*100);ve.tasksManagerSubject.next({id:$,action:"update",type:"i18n",payload:{progress:q,status:q>=100?"finished":"ongoing"}})};for(let Q=0;Q<N.length;Q++){const Z=N[Q],q=h.find(H=>H.name===Z.name&&H.type==="webform"),K=!!q,ie=K?q:await ve.getNodeInfo({verb:ve.DesignerRequestVerb.GET_INFO,content:!0,path:`WebForms/${Z.name}.${Z.ext}`,as:"json"}),{name:E}=ie;if(!U[E]){Y(Q);continue}const M=_(ie,U[E]);await v(M,E,K),Y(Q)}},x=L=>{const N=zI(L),{data:$}=Gm.parse(N),U={};let J=[];return $.forEach((Y,Q)=>{if(Q===0){J=Y;return}let Z="",q="";Y.forEach((K,ie)=>{if(ie===0)Z=K;else if(ie===1)q=K;else if(Z.startsWith("i18n")){if(xe.has(U,Z)&&xe.get(U,Z))return;xe.set(U,Z,K)}else if(K){const{webformName:E,componentId:M,propName:H}=BI(Z);if(xe.set(U,`webforms.${E}.${M}.resolverName`,q),q==="Text"){const T=ba(K),B=J[ie];B==="__t"?xe.set(U,`webforms.${E}.${M}.props.${H}`,T):xe.set(U,`webforms.${E}.${M}.custom.i18n:${B}.${H}`,T)}else{let B=J[ie];if(B.includes(":")){const z=B.split(":");B=z.map((W,F)=>F===0?`states:${W}`:F===z.length-1?`i18n:${W}`:W).join(":")}xe.set(U,`${Z}.${B}`,K)}}})}),U},f=L=>{const N=JSON.parse(L),$={},{webforms:U,i18n:J}=N;return U&&Object.keys(U).forEach(Q=>{const Z=xe.get(U,Q);Object.keys(Z).forEach(K=>{const ie=xe.get(Z,K),{props:E,resolverName:M}=ie;xe.set($,`webforms.${Q}.${K}.resolverName`,M),Array.isArray(E)&&E.forEach(({__dataPath:H,__default:T,...B})=>{if(M==="Text"){const z=ba(T);xe.set($,`webforms.${Q}.${K}.props.doc`,z),Object.keys(B).forEach(W=>{const F=ba(B[W]);xe.set($,`webforms.${Q}.${K}.custom.i18n:${W}.doc`,F)})}else xe.set($,`webforms.${Q}.${K}.${H}.__t`,T),Object.keys(B).forEach(z=>{let W=z;if(W.includes(":")){const F=W.split(":");W=F.map((te,ee)=>ee===0?`states:${te}`:ee===F.length-1?`i18n:${te}`:te).join(":")}xe.set($,`webforms.${Q}.${K}.${H}.${W}`,B[z])})})})}),J&&Object.keys(J).forEach(Q=>{const Z=xe.get(J,Q);Z&&Object.keys(Z).forEach(K=>{const ie=xe.get(Z,K);xe.set($,`i18n.${Q}.${K}`,ie)})}),$},R=(L,N)=>{switch(N){case"csv":return x(L);case"json":return f(L)}},V=async()=>{if(r){const L=no.generate().toString();try{ve.tasksManagerSubject.next({id:L,action:"add",type:"i18n",payload:{date:new Date().toISOString(),progress:0,name:"Import i18n",status:"ongoing"}});const N=await Vg();await A(l,N,L)}catch(N){ve.tasksManagerSubject.next({id:L,type:"i18n",action:"update",payload:{status:"canceled"}}),ve.tasksManagerSubject.next({id:L,type:"i18n",action:"error",payload:{errorMessage:N.message||"Import file error"}})}}};return t?C.jsxs(C.Fragment,{children:[C.jsx(At,{label:"Import",isOpen:c,children:C.jsx("button",{disabled:e,className:yt("flex h-full flex-row items-center rounded p-1 disabled:opacity-50",{"cursor-not-allowed":e},{"hover:bg-primary-hover":!e}),onMouseEnter:()=>d(!0),onMouseLeave:()=>d(!1),onClick:()=>{u.setIsOpen(!0),d(!1),S()},children:C.jsx(ot.FdDownload,{className:"h-4 w-4"})})}),C.jsxs(jg,{isOpen:i,onClose:y,title:"Import",children:[C.jsx("div",{className:"mt-4 space-y-2",children:C.jsxs("div",{...g(),children:[C.jsx("input",{...m()}),C.jsx("div",{className:yt("min-h-[100px] rounded border border-dashed text-center text-sm",{"border-purple-500":w,"flex items-center justify-center":r}),children:r?C.jsx("p",{children:r.name}):C.jsxs("div",{className:"flex min-h-[100px] w-full flex-col items-center justify-center text-grey-100",children:[C.jsx("p",{className:"max-w-md px-2 text-center text-xs ",children:'Drag and drop the file with ".json" or ".csv" extension here or click to select it from your computer.'}),C.jsx(ot.FdDownload,{className:"mt-2 h-6 w-6 text-grey-200"})]})}),o&&C.jsx("div",{className:"flex items-center justify-center p-2",children:C.jsx("p",{className:"text-xs text-red-400",children:o})})]})}),C.jsxs("div",{className:"mt-4 flex items-center justify-between gap-4",children:[C.jsxs("div",{className:"flex flex-row space-x-1 justify-center items-center text-purple-600 hover:underline cursor-pointer",onClick:()=>{window.open("https://developer.4d.com/qodly/4DQodlyPro/localization#exporting-and-importing-translations","_blank")},children:[C.jsx("p",{className:"text-xs",children:"How to Import an i18n File"}),C.jsx(ot.FdOutload,{className:"ml-1 h-4 w-4 text-grey-50"})]}),C.jsxs("div",{className:"flex items-center space-x-2",children:[C.jsx("button",{onClick:y,className:"rounded border w-16 border-white px-2 py-1 text-xs font-medium text-grey-50 hover:bg-white hover:border-white hover:font-bold hover:text-primary-dark",children:"Cancel"}),C.jsx("button",{onClick:()=>{!o&&r?(u.setIsOpen(!1),V()):r||u.setError(uh.DROP_VALID_FILE)},className:"rounded w-16 px-2 py-1 text-xs font-medium text-grey-50 bg-primary-dark hover:border-white hover:border hover:bg-primary-hover hover:text-white hover:font-bold",children:"Import"})]})]})]})]}):C.jsx(C.Fragment,{})};var Ei={exports:{}},Ii={exports:{}},tt={};/** @license React v16.13.1
122
+ `||e[s]==="\r"?(n=!1,t+='"'):t+='""'}else n=!0,t+='"';else t+=i}return t},ba=e=>{const t=FI(e),n=rE().use(DI,{singleTilde:!0}).use(Hk).parse(t),r=(s,o,l)=>{var h;const{type:u,value:c}=s;let d={};if(u==="root"){const{children:g}=s;return g.map(m=>r(m,o)).flat()}if(o){if(u==="list"){const{children:g}=s;return g.map(m=>r(m,d,l)).flat()}else if(u==="listItem"){const{children:g}=s;return g.map(m=>{const w=l!=null&&l.prefix?l.prefix:m.type==="list"?" - ":"* ",S=r(m,d,{prefix:w});return S.type==="paragraph"&&S.children&&(S.children.length>1?S.children=[{text:w},...S.children]:S.children=S.children.map(y=>(y.text&&(y.text=`${w}${y.text}`),y))),S}).flat()}else if(u==="paragraph"){d={type:"paragraph",children:[]};const{children:g}=s,m=g.map(w=>r(w,d));d.children=m}else if(u==="mdxJsxTextElement"){const{name:g}=s;if(g==="ds"){d={type:"datasource",children:[]};const{children:m,attributes:w}=s;if(m){const S=r(m[0],d);d.children=[S]}if(w){const S=w.reduce((y,k)=>({...y,[k.name]:k.value}),{});d={...d,...S}}}else if(g==="i18n"){d={type:"i18n",children:""};const{children:m,attributes:w}=s;if(m){const S=r(m[0],d);d.children=[S]}if(w){const S=w.reduce((y,k)=>({...y,[k.name]:k.value}),{});d={...d,...S}}}else if(g==="u"){d={underlined:!0};const{children:m}=s;if(m){const w=r(m[0],d);d={...d,...w}}}else if(g==="link"){d={type:"link",children:[]};const{children:m,attributes:w}=s;if(m){const S=r(m[0],d);d.children=[S]}if(w){const S=w.reduce((y,k)=>({...y,[k.name]:k.value}),{});d={...d,...S}}}else g==="e"&&(d={text:""})}else if(u==="text")d={text:c};else if(u==="strong"){d={bold:!0};const{children:g}=s;if(g){const m=r(g[0],d);d={...d,...m}}}else if(u==="emphasis"){d={italic:!0};const{children:g}=s;if(g){const m=r(g[0],d);d={...d,...m}}}else if(u==="delete"){d={strikethrough:!0};const{children:g}=s;if(g){const m=r(g[0],d);d={...d,...m}}}else if(u==="link"){const{children:g}=s;d={text:((h=g[0])==null?void 0:h.value)||""}}}else return;return d};return r(n,[])},BI=e=>{const[,t,n,r,...i]=e.split(".");return{webformName:t,componentId:n,propName:r,restOfPropPath:i.join(".")}},bl=()=>document.querySelector(`.${io.LOCALIZATION_EDITOR_SCOPE_CLASS}`)||document.body,Mg=({container:e,...t})=>C.jsx(ve.Portal,{...t,container:e||bl()}),jg=({children:e,isOpen:t,onClose:n,title:r})=>C.jsx(Mg,{children:C.jsx(Ar.Transition,{appear:!0,show:t,as:D.Fragment,children:C.jsxs(Ar.Dialog,{as:"div",className:"absolute w-full h-full inset-0 scale-1 z-[1000]",onClose:n,children:[C.jsx(Ar.Transition.Child,{as:D.Fragment,enter:"ease-out duration-300",enterFrom:"opacity-0",enterTo:"opacity-100",leave:"ease-in duration-200",leaveFrom:"opacity-100",leaveTo:"opacity-0",children:C.jsx("div",{className:"fixed inset-0 bg-black bg-opacity-75"})}),C.jsx("div",{className:"fixed inset-0 overflow-y-auto",children:C.jsx("div",{className:"flex min-h-full items-center justify-center p-4 text-center",children:C.jsx(Ar.Transition.Child,{as:D.Fragment,enter:"ease-out duration-300",enterFrom:"opacity-0 scale-95",enterTo:"opacity-100 scale-100",leave:"ease-in duration-200",leaveFrom:"opacity-100 scale-100",leaveTo:"opacity-0 scale-95",children:C.jsxs(Ar.Dialog.Panel,{className:"w-full space-y-2 max-w-md transform overflow-hidden rounded border border-grey-50 bg-grey-900 px-5 py-4 text-left align-middle text-white shadow-xl transition-all",children:[C.jsxs("div",{className:"flex flex-col items-center justify-center space-y-2",children:[C.jsx(ot.FdDownload,{className:"h-6 w-6"}),C.jsx("h3",{className:"mt-4 text-sm font-bold",children:r})]}),C.jsx("div",{className:"space-y-2",children:e})]})})})})]})})}),uh={DROP_EVENT_ERROR:"Not Suported File type! Only .json and .csv are Supported.",DROP_VALID_FILE:"Drop or Add a File !"},HI=({disable:e,enable:t})=>{const n=Fn(),{state:{file:r,isOpen:i,supprtedExtension:s,error:o,content:l},actions:u}=ve.useStateObject({file:null,error:"",isOpen:!1,fileType:"",supprtedExtension:[".json",".csv"],content:{}}),[c,d]=D.useState(!1),h=n.getWebformTabs(),{getRootProps:g,getInputProps:m,isDragActive:w}=Jm.useDropzone({async onDropAccepted([L]){if(s.find(N=>L.name.endsWith(N))){u.setError(""),u.setFile(L);const N=await k(L),$=L.name.split(".").pop()||"";let U;try{U=R(N,$)}catch{u.setError("Invalid File");return}u.setContent(U||{});const J={type:"object",anyOf:[{required:["webforms"]},{required:["i18n"]}]};new Ym.Validator().validate(U,J).valid||u.setError("Invalid File")}else u.setError(uh.DROP_EVENT_ERROR)},accept:{"application/*":s},multiple:!1}),S=()=>{u.setFileType(""),u.setError(""),u.setFile(null)},y=()=>{u.setIsOpen(!1),S()},k=L=>new Promise(N=>{const $=new FileReader;$.onload=()=>N($.result),$.readAsText(L)}),v=async(L,N,$)=>{if($){const U=`WebForms/${N}.WebForm`;await n.actions.setTabContent({path:U,content:L.content}),ve.webformSubject.next({path:U,action:ve.WebformActions.RECOMPUTE,payload:L.content.components})}else{const U={...L};await ve.saveContent({verb:ve.DesignerRequestVerb.SAVE_CONTENT,content:U.content,path:`WebForms/${N}.WebForm`})}},_=(L,N)=>{const{content:{components:$}}=xe.cloneDeep(L);if(!$)return L;const U=(Q,Z,q,K)=>{if(Array.isArray(Q))Q.forEach((ie,E)=>{let M="";q==="Text"?M=Array.isArray(ie)?`${Z}.[${E}].children`:`${Z}.[${E}]`:M=`${Z}.[${E}]`,U(ie,M,q,K)});else if(xe.isObject(Q))if(Object.keys(Q).length>1){const E=Object.keys(Q),M={};E.forEach(T=>{const B=xe.get(Q,T);if(T==="__t")xe.set(K,`props.${Z}`,B);else if(B&&T.startsWith("states:")){const z=T.split(":"),W=z.map((F,te)=>te+1===z.length?`i18n:${F}`:F).join(":");if(!K.custom)return;xe.set(M,`${W}.${Z}`,B)}else if(B){const z=`i18n:${T}`;if(!K.custom)return;xe.set(M,`${z}.${Z}`,B)}});const[H]=Z.split(".");Object.entries(M).forEach(([T,B])=>{const z=xe.get(K,`props.${H}`,{}),W=xe.get(K,`custom.${T}.${H}`);let F="";typeof W=="string"||typeof z=="string"?F=xe.get(B,H):F=xe.merge(W||xe.cloneDeep(z),xe.get(B,H)),xe.set(K,`custom.${T}.${H}`,F)})}else{const E=Object.entries(Q)[0],M=E[0],H=E[1];Z=`${Z}.${M}`,U(H,Z,q,K)}},J=Object.entries(N);for(let Q=0;Q<J.length;Q++){const[Z,q]=J[Q],{resolverName:K,...ie}=q,E=xe.get($,Z);if(E)if(K==="Text"){const{custom:M,props:H}=ie;xe.set($,Z,{...E,props:{...E.props,...H},custom:{...E.custom,...M}})}else Object.entries(ie).forEach(([M,H])=>{const T=xe.get($,Z);if(!T)return;const B=xe.cloneDeep(T);U(H,M,K,B),xe.set($,Z,B)})}const Y=xe.cloneDeep(L);return xe.set(Y,"content.components",$),Y},A=async(L,N,$)=>{const{webforms:U,i18n:J}=L;ve.i18nSubject.next({action:"set_content",payload:J});const Y=Q=>{const Z=Q+1===N.length?N.length:Q,q=Math.ceil(Z/N.length*100);ve.tasksManagerSubject.next({id:$,action:"update",type:"i18n",payload:{progress:q,status:q>=100?"finished":"ongoing"}})};for(let Q=0;Q<N.length;Q++){const Z=N[Q],q=h.find(H=>H.name===Z.name&&H.type==="webform"),K=!!q,ie=K?q:await ve.getNodeInfo({verb:ve.DesignerRequestVerb.GET_INFO,content:!0,path:`WebForms/${Z.name}.${Z.ext}`,as:"json"}),{name:E}=ie;if(!U[E]){Y(Q);continue}const M=_(ie,U[E]);await v(M,E,K),Y(Q)}},x=L=>{const N=zI(L),{data:$}=Gm.parse(N),U={};let J=[];return $.forEach((Y,Q)=>{if(Q===0){J=Y;return}let Z="",q="";Y.forEach((K,ie)=>{if(ie===0)Z=K;else if(ie===1)q=K;else if(Z.startsWith("i18n")){if(xe.has(U,Z)&&xe.get(U,Z))return;xe.set(U,Z,K)}else if(K){const{webformName:E,componentId:M,propName:H}=BI(Z);if(xe.set(U,`webforms.${E}.${M}.resolverName`,q),q==="Text"){const T=ba(K),B=J[ie];B==="__t"?xe.set(U,`webforms.${E}.${M}.props.${H}`,T):xe.set(U,`webforms.${E}.${M}.custom.i18n:${B}.${H}`,T)}else{let B=J[ie];if(B.includes(":")){const z=B.split(":");B=z.map((W,F)=>F===0?`states:${W}`:F===z.length-1?`i18n:${W}`:W).join(":")}xe.set(U,`${Z}.${B}`,K)}}})}),U},f=L=>{const N=JSON.parse(L),$={},{webforms:U,i18n:J}=N;return U&&Object.keys(U).forEach(Q=>{const Z=xe.get(U,Q);Object.keys(Z).forEach(K=>{const ie=xe.get(Z,K),{props:E,resolverName:M}=ie;xe.set($,`webforms.${Q}.${K}.resolverName`,M),Array.isArray(E)&&E.forEach(({__dataPath:H,__default:T,...B})=>{if(M==="Text"){const z=ba(T);xe.set($,`webforms.${Q}.${K}.props.doc`,z),Object.keys(B).forEach(W=>{const F=ba(B[W]);xe.set($,`webforms.${Q}.${K}.custom.i18n:${W}.doc`,F)})}else xe.set($,`webforms.${Q}.${K}.${H}.__t`,T),Object.keys(B).forEach(z=>{let W=z;if(W.includes(":")){const F=W.split(":");W=F.map((te,ee)=>ee===0?`states:${te}`:ee===F.length-1?`i18n:${te}`:te).join(":")}xe.set($,`webforms.${Q}.${K}.${H}.${W}`,B[z])})})})}),J&&Object.keys(J).forEach(Q=>{const Z=xe.get(J,Q);Z&&Object.keys(Z).forEach(K=>{const ie=xe.get(Z,K);xe.set($,`i18n.${Q}.${K}`,ie)})}),$},R=(L,N)=>{switch(N){case"csv":return x(L);case"json":return f(L)}},V=async()=>{if(r){const L=no.generate().toString();try{ve.tasksManagerSubject.next({id:L,action:"add",type:"i18n",payload:{date:new Date().toISOString(),progress:0,name:"Import i18n",status:"ongoing"}});const N=await Vg();await A(l,N,L)}catch(N){ve.tasksManagerSubject.next({id:L,type:"i18n",action:"update",payload:{status:"canceled"}}),ve.tasksManagerSubject.next({id:L,type:"i18n",action:"error",payload:{errorMessage:N.message||"Import file error"}})}}};return t?C.jsxs(C.Fragment,{children:[C.jsx(At,{label:"Import",isOpen:c,children:C.jsx("button",{disabled:e,className:yt("flex h-full flex-row items-center rounded p-1 disabled:opacity-50",{"cursor-not-allowed":e},{"hover:bg-primary-hover":!e}),onMouseEnter:()=>d(!0),onMouseLeave:()=>d(!1),onClick:()=>{u.setIsOpen(!0),d(!1),S()},children:C.jsx(ot.FdDownload,{className:"h-4 w-4"})})}),C.jsxs(jg,{isOpen:i,onClose:y,title:"Import",children:[C.jsx("div",{className:"mt-4 space-y-2",children:C.jsxs("div",{...g(),children:[C.jsx("input",{...m()}),C.jsx("div",{className:yt("min-h-[100px] rounded border border-dashed text-center text-sm",{"border-purple-500":w,"flex items-center justify-center":r}),children:r?C.jsx("p",{children:r.name}):C.jsxs("div",{className:"flex min-h-[100px] w-full flex-col items-center justify-center text-grey-100",children:[C.jsx("p",{className:"max-w-md px-2 text-center text-xs ",children:'Drag and drop the file with ".json" or ".csv" extension here or click to select it from your computer.'}),C.jsx(ot.FdDownload,{className:"mt-2 h-6 w-6 text-grey-200"})]})}),o&&C.jsx("div",{className:"flex items-center justify-center p-2",children:C.jsx("p",{className:"text-xs text-red-400",children:o})})]})}),C.jsxs("div",{className:"mt-4 flex items-center justify-between gap-4",children:[C.jsxs("div",{className:"flex flex-row space-x-1 justify-center items-center text-purple-600 hover:underline cursor-pointer",onClick:()=>{window.open("https://developer.4d.com/qodly/4DQodlyPro/localization#exporting-and-importing-translations","_blank")},children:[C.jsx("p",{className:"text-xs",children:"How to Import an i18n File"}),C.jsx(ot.FdOutload,{className:"ml-1 h-4 w-4 text-grey-50"})]}),C.jsxs("div",{className:"flex items-center space-x-2",children:[C.jsx("button",{onClick:y,className:"rounded border w-16 border-white px-2 py-1 text-xs font-medium text-grey-50 hover:bg-white hover:border-white hover:font-bold hover:text-primary-dark",children:"Cancel"}),C.jsx("button",{onClick:()=>{!o&&r?(u.setIsOpen(!1),V()):r||u.setError(uh.DROP_VALID_FILE)},className:"rounded w-16 px-2 py-1 text-xs font-medium text-grey-50 bg-primary-dark hover:border-white hover:border hover:bg-primary-hover hover:text-white hover:font-bold",children:"Import"})]})]})]})]}):C.jsx(C.Fragment,{})};var Ei={exports:{}},Ii={exports:{}},tt={};/** @license React v16.13.1
123
123
  * react-is.production.min.js
124
124
  *
125
125
  * Copyright (c) Facebook, Inc. and its affiliates.