@ws-ui/store 0.0.6 → 0.0.7

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
@@ -275,7 +275,7 @@ globstar while`,n,b,r,E,O),this.matchOne(n.slice(b),r.slice(E),a))return this.de
275
275
  `:`Class extends Entity
276
276
  `};case"model":return{name:"DataStore",content:u?`extends DataStoreImplementation
277
277
  `:`Class extends DataStoreImplementation
278
- `}}};e.type==="dataclass"&&!e.toCreate?h=[{...m("dataclass")},{...m("collection")},{...m("entity")}]:e.type==="dataclass"&&e.toCreate?h=[{...m(e.toCreate)}]:h=[{...m("model")}],h=h.filter(E=>!p.find(({name:O,ext:R})=>O===E.name&&R===(u?"4qs":"4dm"))),await Promise.all(h.map(async({name:E,content:O})=>{await n(qs({type:le.CLASS,path:i,fileName:E,parentNode:c,content:O,qodly:a.settings.server.qodly}))})),await n(Po(i))}),Po=xe("explorer/fetchFolderContent",async(e,{rejectWithValue:n})=>{try{return(await ni({verb:Zt.GET_INFO,path:e})).map(a=>{const i=`${e}/${a.name}`,{editor:u,supportedEditors:c}=bo(`${i}${a.ext?`.${a.ext.toLowerCase()}`:""}`);return{name:a.name,size:a.size,type:a.type,date:`${a.date}`,flags:{},error:null,path:i,ext:a.ext,config:a.type==="folder"?{}:{editor:u,supportedEditors:c}}})}catch{return n("Failed loading file content please Reload")}},{getPendingMeta:()=>{}}),zl=xe("explorer/fetchFolderContentWithoutExpanding",async(e,{rejectWithValue:n})=>{try{return(await ni({verb:Zt.GET_INFO,path:e})).map(a=>{const i=`${e}/${a.name}`,{editor:u,supportedEditors:c}=bo(`${i}${a.ext?`.${a.ext.toLowerCase()}`:""}`);return{name:a.name,size:a.size,type:a.type,date:`${a.date}`,flags:{},error:null,path:i,ext:a.ext,config:a.type==="folder"?{}:{editor:u,supportedEditors:c}}})}catch{return n("Failed loading file content please Reload")}},{getPendingMeta:()=>{}});function S6(e){const n=e.split(".");return n.pop(),{name:n.join("."),ext:e.split(".")[e.split(".").length-1]}}const O6=xe("explorer/uploadFile",async e=>{const n=e.type.includes("image/")?"$rawPict=true":"$binary=true";try{const r=await fetch(`/rest/$upload?${n}`,{method:"POST",headers:{"Content-Type":e.type},body:e});return{status:r.status,data:await r.json()}}catch{return{status:500,data:null}}}),T6=xe("explorer/uploadFile",async({file:e,path:n,parentNode:r},{dispatch:a})=>{const{editor:i,supportedEditors:u}=bo(n),{name:c,ext:f}=S6(e.name);a(lC({parent:r,child:{name:c,path:`${n}/${e.name}?t=${Date.now()}`,type:e.type,error:null,flags:{loading:!0},config:{editor:i,supportedEditors:u},ext:f}}));try{const p=await fetch(`/rest/$upload?$sharedFolder=true&$filename=${e.name}&$path=${n}`,{method:"POST",headers:{"Content-Type":e.type},body:e});return p.status>=300?(a(s_({parent:r,child:{name:c,path:`${n}/${e.name}`,type:e.type,error:{message:"error uploading file"},flags:{},config:{editor:i,supportedEditors:u},ext:f}})),p.status!==413&&Ao.next({message:"error uploading file",kind:"danger"})):await a(Po(r.path)),{status:p.status,fileName:e.name}}catch{return a(s_({parent:r,child:{name:c,path:`${n}/${e.name}`,type:e.type,error:{message:"error uploading file"},flags:{},config:{editor:i,supportedEditors:u},ext:f}})),Ao.next({message:"error uploading file",kind:"danger"}),{status:500,fileName:e.name}}}),qs=xe("explorer/createNewFile",async({fileName:e,type:n,path:r,parentNode:a,content:i},{dispatch:u,rejectWithValue:c,getState:f})=>{const{qodly:p}=f().settings.server;try{const h=await Gd({name:dC(e,n,p),content:i||fC(n),path:r,asText:[le.CLASS,le.METHOD].includes(n)});return a.error&&(a.flags.expanded?await u(Po(a.path)):await u(zl(a.path))),{qodly:p,file:h,parentNode:a}}catch{return c("failed to create folder")}});function hC(e,n){const{qodly:r=!0,withExtension:a=!0}=n||{},i=Ws(e.type,r);let u="";switch(e.type){case le.WEBFORM:u=`${Wt.WEBFORMS}/${e.name}`;break;case le.METHOD:u=`${Wt.METHODS}/${e.name}`;break;case le.CLASS:u=`${Wt.CLASSES}/${e.name}`;break;default:return""}return`${u}${a?`.${i}`:""}`}const x6=xe("explorer/createNewFileAndOpen",async(e,{dispatch:n,getState:r})=>{const a=await n(qs(e)).unwrap(),{qodly:i}=r().settings.server;if(a){const{file:u}=a,c=hC(u,{withExtension:!1,qodly:i}),{editor:f}=bo(c);await n(Hl({file:{name:e.fileName,type:u.type,path:c,editor:f,date:new Date().toISOString()}}))}}),qf=xe("explorer/createNewNode",async({fileName:e,path:n,parentNode:r},{rejectWithValue:a})=>{try{return{file:await yk({verb:Zt.CREATE_FOLDER,path:`${n}/${e}`,recursive:!0}),parentNode:r}}catch{return Ao.next({message:"failed to create folder",kind:"danger"}),a("failed to create folder")}}),up=async e=>{try{const n=e.path.split(".").at(-1),r=await ni({verb:Zt.GET_INFO,path:e.path,content:!0,as:kT(n)?"json":"text"}),a={editor:e.editor},i=mT(e.path);i===le.METHOD&&(a.attributes=z_(r.content),r.content=wT(r.content,{}));const{content:u,date:c,ext:f}=r;return{date:c,view:{panel:{isOpen:!1,type:"",current:""}},flags:{enabled:["WebForm","MForm"].includes(f)},extra:a,name:e.name,path:e.path,type:i,initialContent:u,content:u}}catch(n){const{data:r}=n;if(r.__ERROR.find(a=>a.errCode===TT.FILE_NOT_FOUND))switch(e.path){case Ur:{const a={permissions:{allowed:[]},privileges:[],roles:[]};return{date:new Date().toISOString(),flags:{},extra:{editor:{key:"editors:roles"}},name:"Roles & Privileges",path:e.path,type:le.ROLES,initialContent:a,content:a}}case oi:{const a={};return{date:new Date().toISOString(),flags:{},extra:{editor:{key:"editors:settings"}},name:"Settings",path:e.path,type:le.SETTINGS,initialContent:a,content:a}}}throw n}},Hl=xe("explorer/openFile",async({file:e,inactive:n},{getState:r,dispatch:a})=>{const{root:{tabs:i},roles:u}=r(),c=i.find(({path:h})=>e.path===h);if(c){const h={...c,extra:{...c==null?void 0:c.extra,editor:e.editor}};return a(wn(h)),h}if(e.path.startsWith("Debugger")){const h=r().debugger.sessions.find(m=>`Debugger/${m.threadId}`===e.path);if(h){const{source:{content:m},source:b}=h.currentStackFrame,E={name:e.name,type:le.DEBUGGER,date:new Date().toISOString(),path:e.path,content:m,view:{panel:{isOpen:!1,type:"",current:""}},initialContent:m,flags:{},extra:{source:b,editor:e.editor}};return a(wn(E)),E}}const f=await up(e);return e.path===Ur&&!u.flags.touched?a(uw({content:f.content,date:f.date})):e.path===oi&&a(sp({path:"project",value:f.content})),a((n?KC:wn)(f)),f}),fw=xe("explorer/openFileAtLine",async({file:e},{getState:n,dispatch:r})=>{const{tabs:a}=n().root,i=a.find(({path:c})=>e.path===c);if(i){const c={...i,extra:{...i==null?void 0:i.extra,editor:e.editor}};return r(wn(c)),c}const u=await up(e);return r(wn(u)),u}),vC=xe("explorer/injectContentAtLine",async(e,{getState:n,dispatch:r,rejectWithValue:a})=>{const i=n();e.path.split("/").pop();const c=Tr(i.explorer,e.path);if(!c)return a(`Error while trying to inject content in file ${e.path}`);const f=await up({name:c.name,date:c.date||new Date().toISOString(),path:`${c.path}.${c.ext}`,type:le.CLASS,editor:c.config.editor});return await r(wn(f)),{...e,path:`${c.path}.${c.ext}`}}),gC=xe("explorer/openFileAtSelection",async({file:e},{getState:n,dispatch:r})=>{const{tabs:a}=n().root,i=a.find(({path:c})=>e.path===c);if(i){const c={...i,extra:{...i==null?void 0:i.extra,editor:e.editor}};return r(wn(c)),c}const u=await up(e);return r(wn(u)),u}),c_=xe("explorer/deleteFile",async e=>{const{name:n,type:r,path:a,flags:i}=e;if(i.error)return{deleted:!0,node:e};const u=a.split("/");return u.pop(),{deleted:await dk({root:Hs.ROOT,type:pC(r),verb:Zt.DROP,name:n,path:u.join("/")}),node:e}}),C6=xe("explorer/deleteFolder",async e=>{const{path:n,flags:r}=e;if(r.error)return{deleted:!0,node:e};const{deleted:a}=await OT({force:!0,path:n,verb:Zt.REMOVE_ITEM});return{deleted:a,node:e}}),R6=xe("explorer/removeFileNode",async e=>{const{ext:n,path:r}=e;return await OT({verb:Zt.REMOVE_ITEM,path:`${r}.${n}`,force:!0}),r==="Classes/DataStore"&&vf(),{deleted:!0,node:e}}),Vs=xe("explorer/renameFile",async({file:e,newname:n})=>{if(e.type!=="folder"){const a=e.path.split("/");a.pop();const i=`${a.join("/")}/${e.name}.${e.ext}`,u=`${a.join("/")}/${n}.${e.ext}`;return await B1({verb:Zt.MOVE_ITEM,path:i,newpath:u}),{old:{...e,path:i},new:{...e,name:n,path:u}}}const r=e.path.split("/");return r.pop(),await B1({verb:Zt.MOVE_ITEM,path:`${r.join("/")}/${e.name}`,newpath:`${r.join("/")}/${n}`}),{old:e,new:{...e,name:n,path:`${r.join("/")}/${n}`}}}),Gl=xe("explorer/relocateNode",async({draggedNode:e,newLocation:n},{rejectWithValue:r})=>{try{await B1({verb:Zt.MOVE_ITEM,path:`${e.path}.${e.ext}`,newpath:`${n.path}/${e.name}.${e.ext}`})}catch{return r("can't move item")}}),Vf=xe("explorer/duplicateNode",async({node:e,duplicateName:n},{rejectWithValue:r,fulfillWithValue:a,getState:i})=>{const u=e.path.split("/");u.pop();try{const{tabs:c}=i().root,f=c.find(({path:b})=>b===`${e.path}${e.ext?`.${e.ext}`:""}`),p=["4dm","4qm","4qs"].includes(e.ext),{content:h}=f||await ni({verb:Zt.GET_INFO,path:`${e.path}.${e.ext}`,content:!0,as:p?"text":"json"}),m=await Gd({name:`${n}.${e.ext}`,content:h,path:u.join("/"),asText:p});return a({node:{...m,path:u.join("/")}})}catch{return r("failed to duplicate file")}}),A6=xe("explorer/executeMethod",async({methodName:e,params:n=[],resultingDataSource:r={},namespace:a=""},{rejectWithValue:i})=>{var u,c;try{const p=await window.Method4D.buildMethod({methodName:e,parameters:n,resultingDataSource:r},{namespace:a},null).callServerSide({id:"",serverSideRef:""},"onclick",{});return p!=null&&p.__NOTIFICATION?Ao.next({message:`${((u=p.__NOTIFICATION)==null?void 0:u.message)||""}`,kind:`${((c=p.__NOTIFICATION)==null?void 0:c.type)||"info"}`}):Ao.next({message:"Method executed Successfully",kind:"message"}),p}catch(f){return Ao.next({message:f.message||`Error executing the method "**${e}**"`,kind:"danger",markdown:!0}),i("can't execute method")}}),P6=xe("files/fetchFiles",async()=>lk(Hs.WEBFORMS,Hs.METHODS,Hs.CLASSES)),dw=xe("tabs/renameDatasource",async(e,{dispatch:n,getState:r})=>{var O,R;const a=!!e.datasourceNamespace,{confirmed:i}=await n(Eo({message:"Are you sure you want to rename the datasource?",title:"Rename Datasource",type:Hn.CONFIRM,color:Ga.WARNING,views:{toggles:{},tips:a?[{type:"warning",message:"The datasource property of components bound with this datasource will also be updated on opened web forms only"},{type:"warning",message:"The origin of some other datasources might be also renamed (if this datasource is the origin of other datasources)"}]:[{type:"warning",message:"The datasource property of components bound with this datasource will also be updated"},{type:"warning",message:"The origin of some other datasources might be also renamed (if this datasource is the origin of other datasources)"}]}})).unwrap();if(!i)return null;const{autoUpdateReferences:u,datasourceId:c,datasourceNamespace:f,value:p,path:h}=e,m=r();let b=[];if(a){const C=m.sharedDatasources.sources[f]||[];b.push(...C)}else if(h){const C=m.root.tabs.find(bn("path",h));if(b=(R=(O=C==null?void 0:C.content)==null?void 0:O.metadata)==null?void 0:R.datasources,!b)return null}const E=new RegExp(`^${c}\\b`,"");if(b=b.map(C=>{const k=(U_(C)||!bT(C))&&C.from&&E.test(C.from),j=C.events?C.events.map(F=>{var D,M,S,q;switch(F==null?void 0:F.type){case"method":{const U=F;return U.params?{...U,params:U.params.map(V=>{var Ee;return{...V,datasource:(Ee=V.datasource)==null?void 0:Ee.replace(new RegExp(`^${c}`,""),p)}}),returns:(D=U.returns)!=null&&D.datasource?{...U.returns,datasource:(M=U.returns.datasource)==null?void 0:M.replace(new RegExp(`^${c}`,""),p)}:U.returns}:U}case"simple-action":{const U=F;return U.datasource?{...U,datasource:{...U.datasource,name:(S=U.datasource.name)==null?void 0:S.replace(new RegExp(`^${c}`,""),p),from:(q=U.datasource.from)==null?void 0:q.replace(new RegExp(`^${c}`,""),p)}}:U}default:return F}}):C.events;return C.id===c?{...C,id:p,events:j}:k&&C.from?{...C,from:C.from.replace(new RegExp(`^${c}`,""),p),events:j}:{...C,events:j}}),u){const C=a?`${f}:${c}`:`${c}`,k=a?`${f}:${p}`:`${p}`;hT.next({path:h??"",action:F_.RENAME,old_reference:C,new_reference:k,is_shared:a})}return{path:h,namespace:f,datasources:b}}),pw=xe("tabs/edit-datasource",(e,{getState:n})=>{var u,c;const r=n();let a=[];if(e.namespace)a=r.sharedDatasources.sources[e.namespace];else{const f=r.root.tabs.find(bn("path",e.path));f&&(a=((c=(u=f.content)==null?void 0:u.metadata)==null?void 0:c.datasources)||[])}return a.map(f=>f.id===e.datasourceId?Object.assign({},f,{[e.propertyKey]:e.value}):f)}),mC=xe("tabs/fetchChanges",async(e,{getState:n})=>{const a=cu(n()).filter(i=>[le.METHOD,le.CLASS].includes(i.type));return ST(...a.map(i=>{const[u]=i.path.split("/").filter(Boolean);return{name:i.name,type:i.type,root:u,path:"."}}))}),D6=xe("files/saveAll",async(e,{getState:n,dispatch:r})=>{const a=Z_(n());for(const i of a)r(Ys({tab:i}))}),hw=xe("files/tryCloseTab",async(e,{getState:n,dispatch:r})=>{const{tabs:a}=n().root,i=a.findIndex(c=>c.path===e);if(i===-1)return!1;const u=a[i];if(u!=null&&u.flags.touched){const{confirmed:c}=await r(Eo({title:qd(u),message:"Your unsaved changes will be lost. Proceed anyway?",type:Hn.CONFIRM,color:Ga.WARNING,icon:"AiFillWarning"})).unwrap();if(!c)return!1}return r(UC(i)),u.path===Ur&&u.flags.touched&&(async()=>{const f=await ni({verb:Zt.GET_INFO,path:Ur,content:!0,as:"json"});r(uw({content:f.content,date:f.date}))})(),!0}),I6=xe("files/tryCloseOtherTabs",async(e,{getState:n,dispatch:r})=>{const{tabs:a}=n().root;if(a.some(u=>u.path!==e&&u.flags.touched===!0)){const{confirmed:u}=await r(Eo({title:"Closing other tabs",message:"Your changes will be lost if you do not save them. Close anyway?",type:Hn.CONFIRM,color:Ga.WARNING,icon:"AiFillWarning"})).unwrap();if(!u)return}r(qC(e))}),M6=xe("files/tryCloseAllTabs",async(e,{getState:n,dispatch:r})=>{const{tabs:a}=n().root;if(a.some(u=>u.flags.touched===!0)){const{confirmed:u}=await r(Eo({title:"Closing all tabs",message:"Your changes will be lost if you do not save them. Close anyway?",type:Hn.CONFIRM,color:Ga.WARNING,icon:"AiFillWarning"})).unwrap();if(!u)return}r(HC())}),k6=xe("files/tryCloseRightTabs",async(e,{getState:n,dispatch:r})=>{const{tabs:a}=n().root;let i=!1;for(let u=a.length-1;u>e;u-=1)if(a[u].flags.touched){i=!0;break}if(i){const{confirmed:u}=await r(Eo({title:"Closing right tabs",message:"Your changes will be lost if you do not save them. Close anyway?",type:Hn.CONFIRM,color:Ga.WARNING,icon:"AiFillWarning"})).unwrap();if(!u)return}r(GC(e))}),$6=xe("files/tryCloseLeftTabs",async(e,{getState:n,dispatch:r})=>{const{tabs:a}=n().root;let i=!1;for(let u=0;u<e;u+=1)if(a[u].flags.touched){i=!0;break}if(i){const{confirmed:u}=await r(Eo({title:"Closing left tabs",message:"Your changes will be lost if you do not save them. Close anyway?",type:Hn.CONFIRM,color:Ga.WARNING,icon:"AiFillWarning"})).unwrap();if(!u)return}r(VC(e))}),l_=xe("files/reloadTab",async(e,{dispatch:n})=>{if(e.flags.touched){const{confirmed:i}=await n(Eo({title:qd(e),message:"Changes made to the file will be lost. Continue?",type:Hn.CONFIRM,color:Ga.WARNING,icon:"AiFillWarning"})).unwrap();if(!i)return}const r=px(e.path),a=await ni({verb:Zt.GET_INFO,path:e.path,content:!0,as:r});if(e.path===Ur){const{roles:i,privileges:u}=ap(a.content);n(cw({roles:i,privileges:u})),n(ww({path:e.path,flags:{old:!1}}))}else if(e.path===oi){const{content:i}=a;n(sp({path:"project",value:i}))}else{const{content:i}=a;return e.type===le.WEBFORM?KM.next({path:e.path,action:pT.RELOAD,payload:i.components}):e.type===le.MODEL&&_x.next({action:"reload",payload:i}),a}}),Ys=xe("files/saveTab",async({tab:e},{dispatch:n,getState:r})=>{const{path:a,content:i}=e;if(e.type===le.DEBUGGER)return{...e,errors:[]};a.split("/").pop();const c=await ST({path:a});if(c.files[0]){const m=new Date(e.date),b=new Date(c.files[0].date);if(m.getTime()<b.getTime()){const{confirmed:E}=await n(Eo({title:qd(e),message:"New content has been found on the server. Are you sure you want to continue?",type:Hn.CONFIRM,icon:"FaSave"})).unwrap();if(!E)return n(ww({path:a,flags:{old:!0}})),null}}const f=await bk({verb:Zt.SAVE_CONTENT,content:N6(e,r()),path:a});(e.type===le.CLASS||e.type===le.MODEL)&&vf();const p=(f.modelErrors||[]).map(m=>m.message),h=(f.permissionsErrors||[]).map(m=>m.message);return{...e,content:i,date:f.date,initialContent:i,errors:p.length>0||h.length>0?[{title:"Model errors",messages:p},{title:"Permissions errors",messages:h}]:[]}}),N6=(e,n)=>{switch(!0){case e.path==="settings.json":case e.path===oi:return n.settings.project;case e.type===le.ROLES:return aw(n.roles);case e.type===le.MODEL:return e.content||{toJSON:!0,dataClasses:[],extraProperties:{}};default:return e.content}},jS=async e=>{if(e.type===le.DATA_EXPLORER)return{name:"Data Explorer",path:e.path,flags:{},view:{panel:{isOpen:!1,type:"",current:""}},type:e.type,date:new Date().toISOString()};const n=e.path.split("/").filter(Boolean)[0],r=await fk({root:n,type:e.type,verb:Zt.GET,name:e.name}),a={};r.type===le.METHOD&&(a.attributes=z_(r.content));const{date:i,name:u,type:c,content:f}=r;return{date:i,flags:{enabled:e.type===le.WEBFORM},extra:a,view:{panel:{isOpen:!1,type:"",current:""}},name:u,path:e.path,type:c,initialContent:f,content:c===le.MODEL?MT(f):f}},yC=xe("files/tryInjectMethod",async({type:e,dataclass:n},{getState:r,dispatch:a})=>{const{root:{tabs:i},settings:{server:{qodly:u}}}=r(),c=Ws("class",u);let f="",p="",h=null;if(!n)f="DataStore",p=`Classes/DataStore.${c}`;else switch(e){case"dataclass":f=n,p=`Classes/${n}.${c}`;break;case"collection":f=`${n}Selection`,p=`Classes/${n}Selection.${c}`;break;case"entity":f=`${n}Entity`,p=`Classes/${n}Entity.${c}`;break;default:return h}const m=i.find(bn("path",p));if(m)return a(wn(m)),m;try{h=await jS({name:f,date:new Date().toISOString(),path:`class/${f}.${c}`,type:le.CLASS})}catch{n?await a(u_({type:"dataclass",className:n,collectionName:`${n}Selection`,toCreate:e})):await a(u_({type:"model"}))}return h=await jS({name:f,date:new Date().toISOString(),path:`class/${f}.${c}`,type:le.CLASS}),h.path=p,a(wn(h)),h}),j6=xe("roles/open",async(e,{dispatch:n,getState:r})=>{const{tabs:a}=r().root,i=a.find(u=>u.path===Ur);if(i)return n(wn(i)),i;n(Sd())}),{debugger:Ls={meta:{state:Na.DETACHED},list:[],sessions:[],expressions:[]}}=nu();var HS,GS;const L6={meta:{...Ls.meta,state:((HS=Ls.meta)==null?void 0:HS.state)===Na.ATTACHED?(GS=Ls.meta)==null?void 0:GS.state:Na.DETACHED},list:Ls.list||[],sessions:Ls.sessions||[],expressions:Ls.expressions||[]};function LS(e,n){const{line:r,offset:a,type:i="saved"}=n;e.breakpoints[i].locations.push({line:r}),Bt.isNumber(a)&&(e.breakpoints[i].offset=a)}function FS(e,n,r,a){e.breakpoints[r].locations=n,Bt.isNumber(a)&&(e.breakpoints[r].offset=a)}function WS({filePath:e,fileType:n,methodName:r,className:a,ext:i,source:u}){return{filePath:e,fileType:n,methodName:r,className:a,ext:i,source:u,breakpoints:{draft:{locations:[],offset:0},saved:{locations:[],offset:0}}}}function BS(e,n,r){let a=!1;const i=e.map(u=>u[r]!==n[r]?u:(a=!0,{...u,...n}));return a?i:[...i,n]}function kf(e){return e.map(({label:n})=>({label:n}))}const bC=qn({name:"debugger",initialState:L6,reducers:{addBreakpointDecoration(e,n){const{filePath:r,fileType:a,methodName:i,className:u,ext:c,source:f,breakpoint:p}=n.payload,h=Ps(e.list,r,i,u);if(h)LS(h,p);else{if(a===le.CLASS&&p.offset===void 0)throw new Error(`Cannot add a breakpoint on a function without offset. Try editing the ${u} class.`);const m=WS({filePath:r,fileType:a,methodName:i,className:u,ext:c,source:f});LS(m,p),e.list.push(m)}},removeBreakpointDecoration(e,n){const{filePath:r,methodName:a,line:i,offset:u=0,type:c="saved"}=n.payload;if(r.startsWith("Classes/")){const f=e.list.filter(p=>p.filePath===r);if(f.length>0){const p=i+u;f.forEach(h=>{const m=h.breakpoints[c].offset||0;h.breakpoints[c].locations=h.breakpoints[c].locations.filter(b=>b.line+m!==p),c==="saved"&&(h.breakpoints.draft.locations=h.breakpoints.draft.locations.filter(b=>b.line+m!==p))})}}else{const f=Ps(e.list,r,a);f&&(f.breakpoints[c].locations=f.breakpoints[c].locations.filter(p=>p.line!==i),c==="saved"&&(f.breakpoints.draft.locations=f.breakpoints.draft.locations.filter(p=>p.line!==i)))}},setBreakpointsDecoration(e,n){const{filePath:r,fileType:a,methodName:i,className:u,ext:c,source:f,breakpoints:p,offset:h,type:m="saved",clearDraft:b}=n.payload,E=Ps(e.list,r,i);if(E)FS(E,p,m,h),b&&m!=="draft"&&(E.breakpoints.draft.locations=[]);else{const O=WS({filePath:r,fileType:a,methodName:i,className:u,ext:c,source:f});FS(O,p,m,h),e.list.push(O)}},clearBreakpoints(e,n){const{filePath:r,type:a="saved"}=n.payload;e.list=e.list.map(i=>({...i,breakpoints:i.filePath===r?{draft:!a||a==="draft"?{locations:[],offset:0}:i.breakpoints.draft,saved:!a||a==="saved"?{locations:[],offset:0}:i.breakpoints.saved}:i.breakpoints}))},setActiveLine(e,n){const{threadId:r,line:a,highlight:i}=n.payload,u=dr(e.sessions,r);u&&(u.activeLine=a,i&&(u.highlightedLines={start:a,end:a}))},addExpression(e,n){const{threadId:r,label:a,save:i}=n.payload,u=dr(e.sessions,r);u&&u.stopped&&(u.expressions=[...u.expressions||[],{label:a}],i&&(e.expressions=kf(u.expressions)))},removeExpression(e,n){const{threadId:r,index:a,save:i}=n.payload,u=dr(e.sessions,r);u&&(u.expressions=u.expressions.filter((c,f)=>f!==a),i&&(e.expressions=kf(u.expressions)))},removeAllExpressions(e,n){const{threadId:r,save:a}=n.payload,i=dr(e.sessions,r);i&&(i.expressions=[],a&&(e.expressions=[]))},renameExpression(e,n){const{threadId:r,index:a,replacement:i,save:u}=n.payload,c=dr(e.sessions,r);c&&c.expressions[a]&&(c.expressions[a].label=i,u&&(e.expressions=kf(c.expressions)))},setExpression(e,n){const{threadId:r,expression:a}=n.payload,i=dr(e.sessions,r);if(i){const u=a.index>=0?a.index:i.expressions.length>0?i.expressions.length-1:0,c=i.expressions[u];c?(c.result=a.result,c.nakedResult=a.nakedResult,c.variablesReference=a.variablesReference||0,c.presentationHint=a.presentationHint):i.expressions.push(a)}},updateExpressionAt(e,n){const{threadId:r,index:a,value:i}=n.payload,u=dr(e.sessions,r);if(u){const c=u.expressions[a];c&&(c.result=`"${i}"`,c.nakedResult=i)}},saveExpressions(e,n){const{expressions:r}=n.payload;e.expressions=kf(r)},addSession(e,n){const{threadId:r,channelId:a,stackFrames:i,exceptions:u=[]}=n.payload,c=dr(e.sessions,r),f=i[0],{expressions:p=[]}=e;if(c)c.expressions=p;else{const h=V_(r);e.sessions.push({tabPath:h,threadId:r,channelId:a,stackFrames:i,currentStackFrame:f,exceptions:u,expressions:p,variables:{callchain:[],expressions:[]},highlightedLines:null,activeLine:null,stopped:!0})}},updateSession(e,n){const{threadId:r,changes:a}=n.payload;e.sessions=e.sessions.map(i=>i.threadId===r?{...i,...a}:i)},removeSession(e,n){const{threadId:r}=n.payload;e.sessions=e.sessions.filter(a=>a.threadId!==r)},removeSessionByIndex(e,n){const r=n.payload;e.sessions.splice(r,1)},setSessions(e,n){const r=n.payload;e.sessions=r},setCallChainVariables(e,n){const{threadId:r,frameId:a,variables:i}=n.payload;e.sessions=e.sessions.map(u=>{var c;return u.threadId===r?{...u,variables:{...u.variables,callchain:BS((c=u.variables)==null?void 0:c.callchain,{frameId:a,items:i},"frameId")}}:u})},setExpressionVariables(e,n){const{threadId:r,variablesReference:a,variables:i}=n.payload;e.sessions=e.sessions.map(u=>{var c;return u.threadId===r?{...u,variables:{...u.variables,expressions:BS((c=u.variables)==null?void 0:c.expressions,{variablesReference:a,items:i},"variablesReference")}}:u})},setSourceContent(e,n){const{threadId:r,content:a}=n.payload,i=dr(e.sessions,r);i&&(i.currentStackFrame.source={...i.currentStackFrame.source,content:a})},setDebuggerMeta(e,n){if(n.payload.state===Na.ERROR){e.meta.error={...e.meta.error,time:Date.now()};const{override:r,error:a={code:null,reason:"",type:pd.SOCKET_ERROR}}=n.payload;if((r||e.meta.state!==Na.ERROR)&&(e.meta.error={...e.meta.error,...a}),(a==null?void 0:a.type)===pd.SOCKET_CLOSURE&&!(a!=null&&a.reason)&&e.meta.state===Na.DETACHED)return}e.meta.state=n.payload.state}},extraReducers:e=>{e.addCase(wC.fulfilled,n=>{n.sessions=[]})}}),{addBreakpointDecoration:F6,removeBreakpointDecoration:W6,setBreakpointsDecoration:B6,clearBreakpoints:U6,setActiveLine:z6,addExpression:H6,renameExpression:G6,removeExpression:q6,removeAllExpressions:V6,setExpression:Y6,updateExpressionAt:K6,saveExpressions:X6,addSession:J6,updateSession:Z6,removeSession:Q6,removeSessionByIndex:eF,setSessions:_C,setCallChainVariables:tF,setExpressionVariables:rF,setSourceContent:nF,setDebuggerMeta:oF}=bC.actions,wC=xe("files/wipeDebuggerSessions",async(e,{getState:n,dispatch:r})=>{const{sessions:a}=n().debugger;for(const{threadId:i}of a){const u=V_(i);r(hw(u))}}),EC=xe("files/removeDebuggerSessionsNotIn",async(e,{getState:n,dispatch:r})=>{const{threadIds:a}=e,{sessions:i}=n().debugger,u=[],c=i.filter(f=>{const p=a.includes(f.threadId);return p||u.push(f.threadId),p});return r(_C(c)),{staleThreadIds:u}});var vw=(e=>(e.UUID="uuid",e.STRING="string",e.TEXT="text",e.DATE="date",e.TIME="duration",e.BOOLEAN="bool",e.BYTE="byte",e.INTEGER="word",e.LONG="long",e.LONG64="long64",e.FLOAT="number",e.BLOB="blob",e.IMAGE="image",e.OBJECT="object",e))(vw||{}),Ia=(e=>(e.STORAGE="storage",e.RELATEDENTITY="relatedEntity",e.RELATEDENTITIES="relatedEntities",e.CALCULATED="calculated",e.COMPOSITION="composition",e.ALIAS="alias",e))(Ia||{});const aF=e=>["string","uuid","number","long"].includes(e.type),iF=[{label:"Storage",value:"storage"},{label:"Calculated",value:"calculated"}],sF=[{title:"UUID",kind:"storage",value:"uuid",calculatedType:"uuid",calculatedKind:"storage"},{title:"Long",kind:"storage",value:"long",calculatedType:"long",calculatedKind:"storage"}],uF=[{title:"String",kind:"storage",value:"string",calculatedType:"string",calculatedKind:"storage"},{title:"Text",kind:"storage",value:"text",calculatedType:"text",calculatedKind:"storage"},{title:"UUID",kind:"storage",value:"uuid",calculatedType:"uuid",calculatedKind:"storage"},{title:"Date",kind:"storage",value:"date",calculatedType:"date",calculatedKind:"storage"},{title:"Duration",kind:"storage",value:"duration",calculatedType:"duration",calculatedKind:"storage"},{title:"Bool",kind:"storage",value:"bool",calculatedType:"bool",calculatedKind:"storage"},{title:"Byte",kind:"storage",value:"byte",calculatedType:"byte",calculatedKind:"storage"},{title:"Word",kind:"storage",value:"word",calculatedType:"word",calculatedKind:"storage"},{title:"Number",kind:"storage",value:"number",calculatedType:"number",calculatedKind:"storage"},{title:"Long",kind:"storage",value:"long",calculatedType:"long",calculatedKind:"storage"},{title:"Object",kind:"storage",value:"object",calculatedType:"object",calculatedKind:"storage"},{title:"Image",kind:"storage",value:"image",calculatedType:"image",calculatedKind:"storage"},{title:"Blob",kind:"storage",value:"blob",calculatedType:"blob",calculatedKind:"storage"}],cF=[{label:"Expose as REST",value:"public"},{label:"Do not expose as REST",value:"publicOnServer"}],lF=[{label:"Expose as REST",value:"public"},{label:"Do not expose as REST",value:"publicOnServer"}],fF=[{label:"None",value:"none"},{label:"B-tree",value:"btree"},{label:"Cluster",value:"cluster"},{label:"Automatic",value:"auto"}],SC=_n("model/add-dataclass"),OC=_n("model/rename-dataclass"),TC=_n("model/remove-dataclass"),xC=_n("model/add-attribute"),dF=_n("model/edit-attribute-property"),CC=_n("model/remove-attribute"),RC=_n("model/rename-attribute"),AC=_n("model/edit-primary-key"),pF=_n("model/edit-dataclass-property"),PC=_n("model/rename-collection"),hF=(e,n)=>({toJSON:!0,extraProperties:n,dataClasses:e.map(r=>{var a;return{...r.data,extraProperties:{position:{x:r.position.x,y:r.position.y},panelColor:(a=r.data.extraProperties)==null?void 0:a.panelColor}}})});function Yf(e,n,r){const a=e;let i=0;for(;r[`${a}${i||""}`];)i++;return`${a}${i||""}`}const ql=e=>e.kind===Ia.RELATEDENTITY,Od=e=>e.kind===Ia.RELATEDENTITIES,vF=e=>Od(e)||ql(e),gw=xe("models/fetch",async()=>{try{return(await hr(en,{method:"POST",body:JSON.stringify({verb:Zt.GET_INFO,path:B_,as:"json",content:!0}),headers:new Headers({"Content-Type":"application/json"})})).content}catch(e){return e.message}}),Td=xe("models/save",async(e,{getState:n,rejectWithValue:r})=>{const{tabs:a}=n().root,i=a.find(u=>u.path===B_);if(!i)return r("Error while saving the model");try{const u=await hr(en,{method:"POST",body:JSON.stringify({verb:"save",path:i.path,content:i.content}),headers:new Headers({"Content-Type":"application/json"})});return vf(),{...u,path:i.path,content:e.content||{toJSON:!0,dataClasses:[],extraProperties:{}}}}catch{return r("Error while saving the model")}}),gF=xe("models/open",async(e,{dispatch:n,getState:r})=>{const{tabs:a}=r().root,i=a.find(u=>u.path==="models/main");if(i)return n(wn(i)),i;n(gw())}),mF=xe("model/rename-dataclass",async(e,{getState:n,dispatch:r})=>{var b,E;const{dataclassId:a,selectionId:i,name:u}=e;let c=n();const f=c.explorer.find(O=>O.path===Wt.CLASSES);if(!f)throw new Error("Classes folder was not found!");await r(Po(f.path)),c=n();const p={class:{found:!1,newNameTaken:!1,file:null,filename_update:u},entity:{found:!1,newNameTaken:!1,file:null,filename_update:`${u}Entity`},selection:{found:!1,newNameTaken:!1,file:null,filename_update:`${u}Selection`}};(E=(b=c.explorer.find(O=>O.path===Wt.CLASSES))==null?void 0:b.children)==null||E.forEach(O=>{O.name===p.class.filename_update&&(p.class.newNameTaken=!0),O.name===p.entity.filename_update&&(p.entity.newNameTaken=!0),O.name===p.selection.filename_update&&(p.selection.newNameTaken=!0),O.name===a?(p.class.found=!0,p.class.file=O):O.name===`${a}Entity`?(p.entity.found=!0,p.entity.file=O):O.name===i&&(p.selection.found=!0,p.selection.file=O)});const h=Object.entries(p).reduce((O,R)=>{const[C,k]=R;return k.found?k.newNameTaken?[...O,{type:"error",message:`Cannot rename ${C} file to ${k.filename_update} because it already exists. The existing file will be used instead!`}]:O:[...O,{type:"warning",message:`${a} ${C} file was not found`}]},[]);h.length>0&&r(Eo({message:"The following errors were encountered during dataclass rename:",views:{tips:h}}));const m=Object.values(p).filter(O=>O.found&&O.file&&!O.newNameTaken);await Promise.all(m.map(async O=>await r(Vs({file:O.file,newname:O.filename_update})))),m.length>0&&r(Po("Classes"))}),nf={DATACLASS_DELETE:"dataclass.delete",DATACLASS_DRAGGABLE:"dataclass.draggable"},yF={model:{dataClasses:{},collections:{},extraProperties:{}},draft:{dataClasses:{},collections:{},extraProperties:{}},flags:{[nf.DATACLASS_DELETE]:!0,[nf.DATACLASS_DRAGGABLE]:!0}},DC=qn({name:"Models",initialState:yF,reducers:{setModelFlag(e,n){e.flags={...e.flags,...n.payload}}},extraReducers(e){e.addCase(SC,({draft:{dataClasses:n}},r)=>{var c,f;const{dataclassID:a}=r.payload,i=Yf(a||"DataClass","className",n),u={className:i,collectionName:`${i}Selection`,attributes:[{name:"ID",kind:Ia.STORAGE,type:vw.LONG,scope:"public",indexKind:"auto",unique:!0,primKey:!0,autosequence:!0}],name:i,scope:"public",extraProperties:{position:{x:((c=r.payload.position)==null?void 0:c.x)||0,y:((f=r.payload.position)==null?void 0:f.y)||0}}};n[u.name]=u}).addCase(TC,({draft:{dataClasses:n}},r)=>{const{dataclassID:a}=r.payload;n[a]&&(delete n[a],Object.values(n).forEach(u=>{u.attributes=u.attributes.filter(c=>c.type!==a&&c.type!==u.collectionName)}))}).addCase(OC,({draft:{dataClasses:n,collections:r}},a)=>{const{dataclassID:i,newName:u}=a.payload;if(!n[i]||n[u])return;const c=n[i].collectionName,f=Yf(`${u}Selection`,"collectionName",r);Object.values(n).forEach(p=>{p.className===i&&(p.className=u,p.name=u,p.collectionName=f),p.attributes.forEach(h=>{h.type===i?(h.type=u,h.path=u):h.type===c&&(h.type=f)})})}).addCase(xC,({draft:{dataClasses:n}},r)=>{const{dataclassID:a,attributeName:i,attributeType:u,attributeKind:c,target:f}=r.payload;if(!n[a]||ek("name",i,n[a].attributes))return;const h={name:i,kind:c,type:u,exposed:!0,scope:"public"};if(c===Ia.RELATEDENTITY){if(!n[u])return;h.path=u;const b={name:Yf(n[u].collectionName,"name",n[u].attributes),type:n[a].collectionName,kind:Ia.RELATEDENTITIES,reversePath:!0,path:i,scope:"public",exposed:!0};n[u].attributes.push(b)}else if(c===Ia.RELATEDENTITIES){const m=n[u];if(!m)return;const b=m.attributes.find(bn("name",f));if(b){if(!ql(b)||b.type!==n[a].className)return}else{h.path=f,h.reversePath=!0,h.type=u;const E={name:f,kind:Ia.RELATEDENTITY,scope:"public",path:m.className,type:m.className,exposed:!0};m.attributes.push(E)}}n[a].attributes.push(h)}).addCase(RC,({draft:{dataClasses:n}},r)=>{const{dataclassID:a,attributeID:i,newName:u}=r.payload,c=n[a].attributes.find(bn("name",i)),f=n[a].attributes.find(bn("name",u));!c||f||Object.values(n).forEach(({collectionName:p,attributes:h,className:m})=>{h.forEach(b=>{ql(c)&&Od(b)&&b.type===p&&b.path===i&&(b.path=u),m===a&&b.name===i&&(b.name=u)})})}).addCase(CC,({draft:{dataClasses:n}},r)=>{const{dataclassID:a,attributeID:i}=r.payload;if(!n[a])return;const u=n[a].attributes.find(bn("name",i));u&&(ql(u)&&Object.values(n).forEach(c=>{c.attributes=c.attributes.filter(f=>!(Od(f)&&f.type===c.collectionName&&f.path===u.name))}),n[a].attributes=n[a].attributes.filter(JM("name",i)))}).addCase(PC,({draft:{dataClasses:n,collections:r}},a)=>{const{dataclassID:i,collectionName:u}=a.payload;if(!n[i])return;const c=n[i].collectionName;r[u]||(n[i].collectionName=u,r[u]=n[i],delete r[c],Object.values(n).forEach(f=>f.attributes.forEach(p=>{p.type===c&&(p.type=u)})))}).addCase(AC,({draft:{dataClasses:n}},r)=>{const{dataclassID:a,newPrimKey:i}=r.payload;n[a]&&n[a].attributes.forEach(u=>{u.name===i?u.primKey=!0:u.primKey=!1})}),e.addCase(gw.fulfilled,(n,r)=>{var c;const a={},i={},u=r.payload.extraProperties||{};(c=r.payload.dataClasses)==null||c.forEach(f=>{a[f.name]=f,i[f.collectionName]=f}),n.draft.dataClasses=a,n.draft.collections=i,n.draft.extraProperties=u,n.model.dataClasses=a,n.model.collections=i,n.model.extraProperties=u}),e.addCase(Td.pending,()=>{}).addCase(Td.fulfilled,(n,r)=>{const a={},i={},u=r.payload.content.extraProperties||{};r.payload.content.dataClasses.forEach(c=>{a[c.name]=c,i[c.collectionName]=c}),n.draft.dataClasses=a,n.draft.collections=i,n.draft.extraProperties=u,n.model.dataClasses=a,n.model.collections=i,n.model.extraProperties=u})}}),{setModelFlag:bF}=DC.actions,_F=()=>Ua(e=>e.model.draft.dataClasses),wF=()=>Ua(e=>e.model.draft.collections),EF=e=>Ua(n=>n.model.draft.dataClasses[e]),SF=(e,n)=>Ua(r=>r.model.draft.dataClasses[e].attributes.find(bn("name",n))),OF=()=>Ua(e=>e.model.draft.extraProperties),TF=()=>{const e=Ua(i=>i.model.flags),n=i=>i in e?e[i]:void 0,r=n(nf.DATACLASS_DELETE),a=n(nf.DATACLASS_DRAGGABLE);return{deleteDataclass:r,draggableDataclass:a,flags:e}},xF=DC.reducer;function m1(e,n){const r=e.tabs.find(({path:a})=>a===oi);r&&(r.flags.touched=n)}const IC={SIDEBAR_SECTION_RESIZABLE:"sidebar.section.resizable"},{webforms:$f}=nu(),MC={[IC.SIDEBAR_SECTION_RESIZABLE]:!0},kC={...$f,templates:{data:[],selectedGroup:""},datasources:{...G_.webforms.datasources,...$f==null?void 0:$f.datasources},flags:MC},$C=qn({name:"webforms",initialState:kC,reducers:{toggleInspector:(e,n)=>{const{type:r}=n.payload;e.inspector[r].active=!e.inspector[r].active,e.inspector[r].active||(e.inspector[r].data=void 0)},inspect:(e,n)=>{const{type:r,data:a}=n.payload;e.inspector[r].active&&(e.inspector[r].data=a)},addComponent:(e,n)=>{e.components.push(n.payload)},editComponent:(e,n)=>{const{id:r,changes:a}=n.payload;e.components=e.components.map(i=>i.id===r?{...i,...a}:i)},removeComponent:(e,n)=>{const{payload:r}=n,a=e.components.findIndex(i=>i.id===r);a!==-1&&e.components.splice(a,1)},setSelectedGroup:(e,n)=>{e.templates.selectedGroup=n.payload.selectedGroup},setTemplatesData:(e,n)=>{e.templates.data=n.payload},setTemplateData:(e,n)=>{const{group:r,components:a}=n.payload,i=e.templates.data.find(u=>u.group===r);i&&(i.components=a)},setDatasourcesTheme:(e,n)=>{e.datasources.theme=n.payload},setWebformsFlag(e,n){e.flags={...e.flags,...n.payload}}},extraReducers(e){e.addCase(BC.fulfilled,(n,r)=>{n.components=r.payload})}}),{toggleInspector:CF,inspect:RF,addComponent:NC,editComponent:jC,removeComponent:LC,setSelectedGroup:AF,setTemplatesData:FC,setTemplateData:WC,setDatasourcesTheme:PF,setWebformsFlag:DF}=$C.actions,IF=$C.reducer,mw=Bt.curry((e,n)=>{var i,u;const r={...n.sharedDatasources.sources},a=(u=((i=n.root.tabs.find(bn("path",e)))==null?void 0:i.content).metadata)==null?void 0:u.datasources;return a&&(r[e]=a),Bt.cloneDeep(r)}),MF=xe("webforms/fetchTemplates",async(e,{dispatch:n,getState:r})=>{const{data:a}=r().webforms.templates;if(!Bt.isEmpty(a))return a;try{const u=await(await fetch(`https://raw.githubusercontent.com/4d/Web-studio-TIPS/gh-build/build/index.json?t=${Date.now()}`)).json();return n(FC(u)),u}catch{return[]}}),kF=xe("webforms/fetchTemplate",async({name:e},{dispatch:n,getState:r})=>{const{data:a}=r().webforms.templates,i=a.find(u=>u.group===e);if(i&&!Bt.isEmpty(i.components))return i.components;try{const c=await(await fetch(`${i==null?void 0:i.link}?t=${Date.now()}`)).json();return n(WC({group:e,components:c})),c}catch{return[]}}),BC=xe("webforms/fetchCraftedComponents",async(e,{rejectWithValue:n})=>{try{return(await ni({path:"WebForms/crafted_components.json",verb:Zt.GET_INFO,content:!0,as:"json"})).content}catch{return n("Error while loading the crafted components")}}),$F=xe("webforms/addCraftedComponent",async(e,{dispatch:n,rejectWithValue:r,getState:a})=>{try{n(NC(e));const{webforms:{components:i}}=a();H_(i)}catch{return r("Error while adding the crafted component")}}),NF=xe("webforms/editCraftedComponent",async(e,{dispatch:n,rejectWithValue:r,getState:a})=>{try{n(jC(e));const{webforms:{components:i}}=a();H_(i)}catch{return r("Error while editing the crafted component")}}),jF=xe("webforms/removeCraftedComponent",async(e,{dispatch:n,rejectWithValue:r,getState:a})=>{try{n(LC(e));const{webforms:{components:i}}=a();H_(i)}catch{return r("Error while removing the crafted component")}}),yw=xe("datasources/add-datasource",async(e,{getState:n,rejectWithValue:r})=>{var a,i;try{const u=n(),c=e.datasource,f=!!c.namespace,p=[];if(f){const h={...u.sharedDatasources.sources,[c.namespace]:[...u.sharedDatasources.sources[c.namespace],c]};p.push(...h[c.namespace]),await ri(h)}else(((i=(a=u.root.tabs.find(bn("path",e.path)).content)==null?void 0:a.metadata)==null?void 0:i.datasources)||[]).push(c);return{list:p,path:e.path,namespace:e.datasource.namespace}}catch{console.error("Error while adding the datasource",e.datasource.id),r("Error while adding the datasource")}}),bw=xe("datasources/edit-datasource",async(e,{getState:n,rejectWithValue:r})=>{try{const{namespace:a,path:i}=e,u=n(),c=!!e.namespace,f=mw(i,u);let p=Bt.defaultTo(f[a||i],[]);return p=p.map(h=>h.id===e.id?{...h,[e.property]:e.value}:h),c&&await ri({...u.sharedDatasources.sources,[e.namespace]:p}),{list:p,path:e.path,namespace:e.namespace}}catch{r(`Error while editing datasource ${e.id}`)}}),LF=e=>e.type===Ks.fulfilled.type,Ks=xe("datasources/rename-datasource",async(e,{getState:n,rejectWithValue:r})=>{try{const a=n(),i=!!e.namespace,u=e.namespace||e.path,c=mw(e.path,a),f=Bt.defaultTo(c[u],[]),p=new RegExp(`^${e.id}\\b`,"");if(f.forEach(h=>{var b;const m=(U_(h)||!bT(h))&&h.from&&p.test(h.from);e.updateRefs&&((b=h.events)==null||b.forEach(E=>{var O,R,C,k,j;switch(E.type){case"method":{const F=E;F.params.forEach(D=>{D.datasource&&Object.assign(D,{datasource:D.datasource.replace(new RegExp(`^${e.id}`,""),e.new_name)})}),F.returns&&Object.assign(F.returns,{datasource:(R=(O=F.returns)==null?void 0:O.datasource)==null?void 0:R.replace(new RegExp(`^${e.id}`,""),e.new_name)});return}case"simple-action":{const F=E;F.datasource&&Object.assign(F.datasource,{name:(C=F.datasource.name)==null?void 0:C.replace(new RegExp(`^${e.id}`,""),e.new_name),from:(k=F.datasource.from)==null?void 0:k.replace(new RegExp(`^${e.id}`,""),e.new_name),target:(j=F.datasource.target)==null?void 0:j.replace(new RegExp(`^${e.id}`,""),e.new_name)});return}default:return}})),h.id===e.id?h.id=e.new_name:m&&h.from&&(h.from=h.from.replace(new RegExp(`^${e.id}`,""),e.new_name))}),e.updateRefs){const h=fd({id:e.id,namespace:e.namespace}),m=fd({id:e.new_name,namespace:e.namespace});hT.next({path:e.path??"",action:F_.RENAME,old_reference:h,new_reference:m,is_shared:i})}return i&&await ri({...a.sharedDatasources.sources,[e.namespace]:f}),{list:f,path:e.path,namespace:e.namespace}}catch{return r(`Error while renaming datasource ${e.namespace}:${e.id}`)}}),Vl=xe("datasources/delete-datasource",async(e,{getState:n,rejectWithValue:r})=>{try{const a=n(),i=!!e.namespace,u=e.namespace||e.path,f=mw(e.path,a)[u].filter(ZM(e.id));return i&&await ri({...a.sharedDatasources.sources,[e.namespace]:f}),{list:f,path:e.path,namespace:e.namespace}}catch{return r(`Error while removing datasource ${e.id}`)}}),y1=nu(),FF={filesLoading:!1,tabs:y1.tabs||[],activeTab:y1.activeTab,recent:y1.recent||[]},_w=qn({name:"root",initialState:FF,reducers:{setPanelState(e,n){const{path:r,...a}=n.payload;e.tabs.forEach(i=>{i.path===r&&(i.view||(i.view={panel:{isOpen:!1,type:"",current:""}}),Object.assign(i.view.panel,a))})},addDataSource(e,n){var u;const{payload:{path:r,datasourceDef:a}}=n,i=e.tabs.find(c=>c.path===r);i&&(i.content.metadata.datasources=i.content.metadata.datasources||[],(u=i.content.metadata.datasources)!=null&&u.find(f=>f.id===a.id)||(i.content.metadata.datasources=[...i.content.metadata.datasources,{...a,events:[]}],i.flags={...i.flags,touched:!0}))},openSettingsTab(e){const n={date:new Date().toISOString(),flags:{},view:{panel:{isOpen:!1,type:"",current:""}},extra:{editor:{key:"editors:settings"}},name:"Settings",path:oi,type:le.SETTINGS,initialContent:{},content:{}};let r=e.tabs.find(a=>a.path===n.path);if(r||(e.tabs.push(n),r=e.tabs[e.tabs.length-1]),e.activeTab!==n.path){const a=e.tabs.reduce((i,u)=>(u==null?void 0:u.weight)>((i==null?void 0:i.weight)||0)?u:i,null);e.activeTab=n.path,r.weight=((a==null?void 0:a.weight)||0)+1}},removeDataSource(e,n){const{path:r,datasourceID:a}=n.payload;e.tabs=e.tabs.map(i=>i.path===r?{...i,flags:{...i.flags,touched:!0},content:{...i.content,metadata:{...i.content.metadata,datasources:i.content.metadata.datasources.filter(u=>u.id!==a)}}}:i)},setDataSources(e,n){const{payload:{path:r,datasourceArr:a}}=n;e.tabs=e.tabs.map(i=>{var u;return i.path===r?{...i,flags:{...i.flags,touched:!0},content:{...i.content,metadata:{...(u=i.content)==null?void 0:u.metadata,datasources:a}}}:i})},setTabs(e,n){e.tabs=n.payload},closeTab(e,n){const r=n.payload;e.tabs.splice(r,1);const a=e.tabs.reduce((i,u)=>(u==null?void 0:u.weight)>((i==null?void 0:i.weight)||0)?u:i,null);e.activeTab=(a==null?void 0:a.path)||""},closeOthers(e,n){e.tabs=e.tabs.filter(r=>r.path===n.payload),e.activeTab=n.payload},closeAllTabs(e){e.tabs=[],e.activeTab=""},closeRightTabs(e,n){e.tabs.splice(n.payload+1),e.activeTab=e.tabs[n.payload].path},closeLeftTabs(e,n){e.tabs.splice(0,n.payload)},closeSavedTabs(e){e.tabs=e.tabs.filter(({flags:{touched:r}})=>r);const n=e.tabs.reduce((r,a)=>(a==null?void 0:a.weight)>((r==null?void 0:r.weight)||0)?a:r,null);e.activeTab=(n==null?void 0:n.path)||""},selectTab(e,n){const r=e.tabs.find(({path:i})=>i===n.payload);if(!r||e.activeTab===n.payload)return;const a=e.tabs.reduce((i,u)=>(u==null?void 0:u.weight)>((i==null?void 0:i.weight)||0)?u:i,null);r.weight=a?(a.weight||0)+1:1,e.activeTab=n.payload},openTabUnselected(e,n){const r=n.payload;let a=e.tabs.find(({path:u})=>r.path===u);a||(e.tabs.push(r),a=e.tabs[e.tabs.length-1]);const i=e.tabs.reduce((u,c)=>(c==null?void 0:c.weight)>((u==null?void 0:u.weight)||0)?c:u,null);a.weight=i?(i.weight||0)+1:1,a.extra={...a.extra,...r.extra}},selectTabByReference(e,n){const r=n.payload;let a=e.tabs.find(({path:i})=>r.path===i);if(a||(e.tabs.push(r),a=e.tabs[e.tabs.length-1]),e.activeTab!==r.path){const i=e.tabs.reduce((u,c)=>(c==null?void 0:c.weight)>((u==null?void 0:u.weight)||0)?c:u,null);e.activeTab=r.path,a.weight=((i==null?void 0:i.weight)||0)+1}a.extra={...a.extra,...r.extra}},setContent(e,n){const{path:r,content:a,contentPath:i}=n.payload;e.tabs=e.tabs.map(u=>{if(u.path!==r)return u;let c=!1;if(typeof a=="string")c=u.initialContent!==a;else{const f=JSON.stringify(Bt.get(u.initialContent,i||"",u.initialContent)),p=JSON.stringify(Bt.get(a,i||"",a));c=f!==p}return a&&typeof a=="object"&&(i?Bt.set(u.content,i,a):u.content=a),typeof a=="string"&&(u.content=a),{...u,flags:{...u.flags,touched:c}}})},setTabFlags(e,n){const{path:r,flags:a}=n.payload;e.tabs=e.tabs.map(i=>i.path===r?{...i,flags:{...i.flags,...a}}:i)},setTabsFlags(e,n){const{tabs:r,flags:a}=n.payload;e.tabs=e.tabs.map(i=>r.includes(i.path)?{...i,flags:{...i.flags,...a}}:i)},setTabExtra(e,n){const{path:r,extra:a,flags:i}=n.payload;e.tabs=e.tabs.map(u=>u.path===r?{...u,extra:{...u.extra,...a},flags:i?{...u.flags,...i}:u.flags}:u)},addWebFormStyles(e,n){const{path:r,styles:a=[]}=n.payload,i=e.tabs.find(u=>u.path===r);if(i){const u=i.content.metadata.styles.map(({name:f})=>f),c=a.filter(({name:f})=>!u.includes(f));i.content.metadata.styles=[...i.content.metadata.styles,...c].map(({scope:f,...p})=>({...p}))}},changeTabEditor(e,n){return e.tabs=e.tabs.map(r=>r.path===n.payload.path?n.payload:r),e}},extraReducers:e=>{e.addCase(vC.fulfilled,(n,r)=>{if(!r.payload)return;const{content:a,line:i,path:u}=r.payload,c=n.tabs.find(f=>f.path===u);if(c&&typeof c.content=="string"){const f=c.content.trim().split(`
278
+ `}}};e.type==="dataclass"&&!e.toCreate?h=[{...m("dataclass")},{...m("collection")},{...m("entity")}]:e.type==="dataclass"&&e.toCreate?h=[{...m(e.toCreate)}]:h=[{...m("model")}],h=h.filter(E=>!p.find(({name:O,ext:R})=>O===E.name&&R===(u?"4qs":"4dm"))),await Promise.all(h.map(async({name:E,content:O})=>{await n(qs({type:le.CLASS,path:i,fileName:E,parentNode:c,content:O,qodly:a.settings.server.qodly}))})),await n(Po(i))}),Po=xe("explorer/fetchFolderContent",async(e,{rejectWithValue:n})=>{try{return(await ni({verb:Zt.GET_INFO,path:e})).map(a=>{const i=`${e}/${a.name}`,{editor:u,supportedEditors:c}=bo(`${i}${a.ext?`.${a.ext.toLowerCase()}`:""}`);return{name:a.name,size:a.size,type:a.type,date:`${a.date}`,flags:{},error:null,path:i,ext:a.ext,config:a.type==="folder"?{}:{editor:u,supportedEditors:c}}})}catch{return n("Failed loading file content please Reload")}},{getPendingMeta:()=>{}}),zl=xe("explorer/fetchFolderContentWithoutExpanding",async(e,{rejectWithValue:n})=>{try{return(await ni({verb:Zt.GET_INFO,path:e})).map(a=>{const i=`${e}/${a.name}`,{editor:u,supportedEditors:c}=bo(`${i}${a.ext?`.${a.ext.toLowerCase()}`:""}`);return{name:a.name,size:a.size,type:a.type,date:`${a.date}`,flags:{},error:null,path:i,ext:a.ext,config:a.type==="folder"?{}:{editor:u,supportedEditors:c}}})}catch{return n("Failed loading file content please Reload")}},{getPendingMeta:()=>{}});function S6(e){const n=e.split(".");return n.pop(),{name:n.join("."),ext:e.split(".")[e.split(".").length-1]}}const O6=xe("explorer/uploadFile",async e=>{const n=e.type.includes("image/")?"$rawPict=true":"$binary=true";try{const r=await fetch(`/rest/$upload?${n}`,{method:"POST",headers:{"Content-Type":e.type},body:e});return{status:r.status,data:await r.json()}}catch{return{status:500,data:null}}}),T6=xe("explorer/uploadFile",async({file:e,path:n,parentNode:r},{dispatch:a})=>{const{editor:i,supportedEditors:u}=bo(n),{name:c,ext:f}=S6(e.name);a(lC({parent:r,child:{name:c,path:`${n}/${e.name}?t=${Date.now()}`,type:e.type,error:null,flags:{loading:!0},config:{editor:i,supportedEditors:u},ext:f}}));try{const p=await fetch(`/rest/$upload?$sharedFolder=true&$filename=${e.name}&$path=${n}`,{method:"POST",headers:{"Content-Type":e.type},body:e});return p.status>=300?(a(s_({parent:r,child:{name:c,path:`${n}/${e.name}`,type:e.type,error:{message:"error uploading file"},flags:{},config:{editor:i,supportedEditors:u},ext:f}})),p.status!==413&&Ao.next({message:"error uploading file",kind:"danger"})):await a(Po(r.path)),{status:p.status,fileName:e.name}}catch{return a(s_({parent:r,child:{name:c,path:`${n}/${e.name}`,type:e.type,error:{message:"error uploading file"},flags:{},config:{editor:i,supportedEditors:u},ext:f}})),Ao.next({message:"error uploading file",kind:"danger"}),{status:500,fileName:e.name}}}),qs=xe("explorer/createNewFile",async({fileName:e,type:n,path:r,parentNode:a,content:i},{dispatch:u,rejectWithValue:c,getState:f})=>{const{qodly:p}=f().settings.server;try{const h=await Gd({name:dC(e,n,p),content:i||fC(n),path:r,asText:[le.CLASS,le.METHOD].includes(n)});return a.error&&(a.flags.expanded?await u(Po(a.path)):await u(zl(a.path))),{qodly:p,file:h,parentNode:a}}catch{return c("failed to create folder")}});function hC(e,n){const{qodly:r=!0,withExtension:a=!0}=n||{},i=Ws(e.type,r);let u="";switch(e.type){case le.WEBFORM:u=`${Wt.WEBFORMS}/${e.name}`;break;case le.METHOD:u=`${Wt.METHODS}/${e.name}`;break;case le.CLASS:u=`${Wt.CLASSES}/${e.name}`;break;default:return""}return`${u}${a?`.${i}`:""}`}const x6=xe("explorer/createNewFileAndOpen",async(e,{dispatch:n,getState:r})=>{const a=await n(qs(e)).unwrap(),{qodly:i}=r().settings.server;if(a){const{file:u}=a,c=hC(u,{withExtension:!1,qodly:i}),{editor:f}=bo(c);await n(Hl({file:{name:e.fileName,type:u.type,path:c,editor:f,date:new Date().toISOString()}}))}}),qf=xe("explorer/createNewNode",async({fileName:e,path:n,parentNode:r},{rejectWithValue:a})=>{try{return{file:await yk({verb:Zt.CREATE_FOLDER,path:`${n}/${e}`,recursive:!0}),parentNode:r}}catch{return Ao.next({message:"failed to create folder",kind:"danger"}),a("failed to create folder")}}),up=async e=>{try{const n=e.path.split(".").at(-1),r=await ni({verb:Zt.GET_INFO,path:e.path,content:!0,as:kT(n)?"json":"text"}),a={editor:e.editor},i=mT(e.path);i===le.METHOD&&(a.attributes=z_(r.content),r.content=wT(r.content,{}));const{content:u,date:c,ext:f}=r;return{date:c,view:{panel:{isOpen:!1,type:"",current:""}},flags:{enabled:["WebForm","MForm"].includes(f)},extra:a,name:e.name,path:e.path,type:i,initialContent:u,content:u}}catch(n){const{data:r}=n;if(r.__ERROR.find(a=>a.errCode===TT.FILE_NOT_FOUND))switch(e.path){case Ur:{const a={permissions:{allowed:[]},privileges:[],roles:[]};return{date:new Date().toISOString(),flags:{},extra:{editor:{key:"editors:roles"}},name:"Roles & Privileges",path:e.path,type:le.ROLES,initialContent:a,content:a}}case oi:{const a={};return{date:new Date().toISOString(),flags:{},extra:{editor:{key:"editors:settings"}},name:"Settings",path:e.path,type:le.SETTINGS,initialContent:a,content:a}}}throw n}},Hl=xe("explorer/openFile",async({file:e,inactive:n,flags:r={}},{getState:a,dispatch:i})=>{const{root:{tabs:u},roles:c}=a(),f=u.find(({path:m})=>e.path===m);if(f){const m={...f,extra:{...f==null?void 0:f.extra,editor:e.editor},flags:{...f==null?void 0:f.flags,...r}};return i(wn(m)),m}if(e.path.startsWith("Debugger")){const m=a().debugger.sessions.find(b=>`Debugger/${b.threadId}`===e.path);if(m){const{source:{content:b},source:E}=m.currentStackFrame,O={name:e.name,type:le.DEBUGGER,date:new Date().toISOString(),path:e.path,content:b,view:{panel:{isOpen:!1,type:"",current:""}},initialContent:b,flags:{},extra:{source:E,editor:e.editor}};return i(wn(O)),O}}const p=await up(e);return e.path===Ur&&!c.flags.touched?i(uw({content:p.content,date:p.date})):e.path===oi&&i(sp({path:"project",value:p.content})),i((n?KC:wn)(p)),p}),fw=xe("explorer/openFileAtLine",async({file:e},{getState:n,dispatch:r})=>{const{tabs:a}=n().root,i=a.find(({path:c})=>e.path===c);if(i){const c={...i,extra:{...i==null?void 0:i.extra,editor:e.editor}};return r(wn(c)),c}const u=await up(e);return r(wn(u)),u}),vC=xe("explorer/injectContentAtLine",async(e,{getState:n,dispatch:r,rejectWithValue:a})=>{const i=n();e.path.split("/").pop();const c=Tr(i.explorer,e.path);if(!c)return a(`Error while trying to inject content in file ${e.path}`);const f=await up({name:c.name,date:c.date||new Date().toISOString(),path:`${c.path}.${c.ext}`,type:le.CLASS,editor:c.config.editor});return await r(wn(f)),{...e,path:`${c.path}.${c.ext}`}}),gC=xe("explorer/openFileAtSelection",async({file:e},{getState:n,dispatch:r})=>{const{tabs:a}=n().root,i=a.find(({path:c})=>e.path===c);if(i){const c={...i,extra:{...i==null?void 0:i.extra,editor:e.editor}};return r(wn(c)),c}const u=await up(e);return r(wn(u)),u}),c_=xe("explorer/deleteFile",async e=>{const{name:n,type:r,path:a,flags:i}=e;if(i.error)return{deleted:!0,node:e};const u=a.split("/");return u.pop(),{deleted:await dk({root:Hs.ROOT,type:pC(r),verb:Zt.DROP,name:n,path:u.join("/")}),node:e}}),C6=xe("explorer/deleteFolder",async e=>{const{path:n,flags:r}=e;if(r.error)return{deleted:!0,node:e};const{deleted:a}=await OT({force:!0,path:n,verb:Zt.REMOVE_ITEM});return{deleted:a,node:e}}),R6=xe("explorer/removeFileNode",async e=>{const{ext:n,path:r}=e;return await OT({verb:Zt.REMOVE_ITEM,path:`${r}.${n}`,force:!0}),r==="Classes/DataStore"&&vf(),{deleted:!0,node:e}}),Vs=xe("explorer/renameFile",async({file:e,newname:n})=>{if(e.type!=="folder"){const a=e.path.split("/");a.pop();const i=`${a.join("/")}/${e.name}.${e.ext}`,u=`${a.join("/")}/${n}.${e.ext}`;return await B1({verb:Zt.MOVE_ITEM,path:i,newpath:u}),{old:{...e,path:i},new:{...e,name:n,path:u}}}const r=e.path.split("/");return r.pop(),await B1({verb:Zt.MOVE_ITEM,path:`${r.join("/")}/${e.name}`,newpath:`${r.join("/")}/${n}`}),{old:e,new:{...e,name:n,path:`${r.join("/")}/${n}`}}}),Gl=xe("explorer/relocateNode",async({draggedNode:e,newLocation:n},{rejectWithValue:r})=>{try{await B1({verb:Zt.MOVE_ITEM,path:`${e.path}.${e.ext}`,newpath:`${n.path}/${e.name}.${e.ext}`})}catch{return r("can't move item")}}),Vf=xe("explorer/duplicateNode",async({node:e,duplicateName:n},{rejectWithValue:r,fulfillWithValue:a,getState:i})=>{const u=e.path.split("/");u.pop();try{const{tabs:c}=i().root,f=c.find(({path:b})=>b===`${e.path}${e.ext?`.${e.ext}`:""}`),p=["4dm","4qm","4qs"].includes(e.ext),{content:h}=f||await ni({verb:Zt.GET_INFO,path:`${e.path}.${e.ext}`,content:!0,as:p?"text":"json"}),m=await Gd({name:`${n}.${e.ext}`,content:h,path:u.join("/"),asText:p});return a({node:{...m,path:u.join("/")}})}catch{return r("failed to duplicate file")}}),A6=xe("explorer/executeMethod",async({methodName:e,params:n=[],resultingDataSource:r={},namespace:a=""},{rejectWithValue:i})=>{var u,c;try{const p=await window.Method4D.buildMethod({methodName:e,parameters:n,resultingDataSource:r},{namespace:a},null).callServerSide({id:"",serverSideRef:""},"onclick",{});return p!=null&&p.__NOTIFICATION?Ao.next({message:`${((u=p.__NOTIFICATION)==null?void 0:u.message)||""}`,kind:`${((c=p.__NOTIFICATION)==null?void 0:c.type)||"info"}`}):Ao.next({message:"Method executed Successfully",kind:"message"}),p}catch(f){return Ao.next({message:f.message||`Error executing the method "**${e}**"`,kind:"danger",markdown:!0}),i("can't execute method")}}),P6=xe("files/fetchFiles",async()=>lk(Hs.WEBFORMS,Hs.METHODS,Hs.CLASSES)),dw=xe("tabs/renameDatasource",async(e,{dispatch:n,getState:r})=>{var O,R;const a=!!e.datasourceNamespace,{confirmed:i}=await n(Eo({message:"Are you sure you want to rename the datasource?",title:"Rename Datasource",type:Hn.CONFIRM,color:Ga.WARNING,views:{toggles:{},tips:a?[{type:"warning",message:"The datasource property of components bound with this datasource will also be updated on opened web forms only"},{type:"warning",message:"The origin of some other datasources might be also renamed (if this datasource is the origin of other datasources)"}]:[{type:"warning",message:"The datasource property of components bound with this datasource will also be updated"},{type:"warning",message:"The origin of some other datasources might be also renamed (if this datasource is the origin of other datasources)"}]}})).unwrap();if(!i)return null;const{autoUpdateReferences:u,datasourceId:c,datasourceNamespace:f,value:p,path:h}=e,m=r();let b=[];if(a){const C=m.sharedDatasources.sources[f]||[];b.push(...C)}else if(h){const C=m.root.tabs.find(bn("path",h));if(b=(R=(O=C==null?void 0:C.content)==null?void 0:O.metadata)==null?void 0:R.datasources,!b)return null}const E=new RegExp(`^${c}\\b`,"");if(b=b.map(C=>{const k=(U_(C)||!bT(C))&&C.from&&E.test(C.from),j=C.events?C.events.map(F=>{var D,M,S,q;switch(F==null?void 0:F.type){case"method":{const U=F;return U.params?{...U,params:U.params.map(V=>{var Ee;return{...V,datasource:(Ee=V.datasource)==null?void 0:Ee.replace(new RegExp(`^${c}`,""),p)}}),returns:(D=U.returns)!=null&&D.datasource?{...U.returns,datasource:(M=U.returns.datasource)==null?void 0:M.replace(new RegExp(`^${c}`,""),p)}:U.returns}:U}case"simple-action":{const U=F;return U.datasource?{...U,datasource:{...U.datasource,name:(S=U.datasource.name)==null?void 0:S.replace(new RegExp(`^${c}`,""),p),from:(q=U.datasource.from)==null?void 0:q.replace(new RegExp(`^${c}`,""),p)}}:U}default:return F}}):C.events;return C.id===c?{...C,id:p,events:j}:k&&C.from?{...C,from:C.from.replace(new RegExp(`^${c}`,""),p),events:j}:{...C,events:j}}),u){const C=a?`${f}:${c}`:`${c}`,k=a?`${f}:${p}`:`${p}`;hT.next({path:h??"",action:F_.RENAME,old_reference:C,new_reference:k,is_shared:a})}return{path:h,namespace:f,datasources:b}}),pw=xe("tabs/edit-datasource",(e,{getState:n})=>{var u,c;const r=n();let a=[];if(e.namespace)a=r.sharedDatasources.sources[e.namespace];else{const f=r.root.tabs.find(bn("path",e.path));f&&(a=((c=(u=f.content)==null?void 0:u.metadata)==null?void 0:c.datasources)||[])}return a.map(f=>f.id===e.datasourceId?Object.assign({},f,{[e.propertyKey]:e.value}):f)}),mC=xe("tabs/fetchChanges",async(e,{getState:n})=>{const a=cu(n()).filter(i=>[le.METHOD,le.CLASS].includes(i.type));return ST(...a.map(i=>{const[u]=i.path.split("/").filter(Boolean);return{name:i.name,type:i.type,root:u,path:"."}}))}),D6=xe("files/saveAll",async(e,{getState:n,dispatch:r})=>{const a=Z_(n());for(const i of a)r(Ys({tab:i}))}),hw=xe("files/tryCloseTab",async(e,{getState:n,dispatch:r})=>{const{tabs:a}=n().root,i=a.findIndex(c=>c.path===e);if(i===-1)return!1;const u=a[i];if(u!=null&&u.flags.touched){const{confirmed:c}=await r(Eo({title:qd(u),message:"Your unsaved changes will be lost. Proceed anyway?",type:Hn.CONFIRM,color:Ga.WARNING,icon:"AiFillWarning"})).unwrap();if(!c)return!1}return r(UC(i)),u.path===Ur&&u.flags.touched&&(async()=>{const f=await ni({verb:Zt.GET_INFO,path:Ur,content:!0,as:"json"});r(uw({content:f.content,date:f.date}))})(),!0}),I6=xe("files/tryCloseOtherTabs",async(e,{getState:n,dispatch:r})=>{const{tabs:a}=n().root;if(a.some(u=>u.path!==e&&u.flags.touched===!0)){const{confirmed:u}=await r(Eo({title:"Closing other tabs",message:"Your changes will be lost if you do not save them. Close anyway?",type:Hn.CONFIRM,color:Ga.WARNING,icon:"AiFillWarning"})).unwrap();if(!u)return}r(qC(e))}),M6=xe("files/tryCloseAllTabs",async(e,{getState:n,dispatch:r})=>{const{tabs:a}=n().root;if(a.some(u=>u.flags.touched===!0)){const{confirmed:u}=await r(Eo({title:"Closing all tabs",message:"Your changes will be lost if you do not save them. Close anyway?",type:Hn.CONFIRM,color:Ga.WARNING,icon:"AiFillWarning"})).unwrap();if(!u)return}r(HC())}),k6=xe("files/tryCloseRightTabs",async(e,{getState:n,dispatch:r})=>{const{tabs:a}=n().root;let i=!1;for(let u=a.length-1;u>e;u-=1)if(a[u].flags.touched){i=!0;break}if(i){const{confirmed:u}=await r(Eo({title:"Closing right tabs",message:"Your changes will be lost if you do not save them. Close anyway?",type:Hn.CONFIRM,color:Ga.WARNING,icon:"AiFillWarning"})).unwrap();if(!u)return}r(GC(e))}),$6=xe("files/tryCloseLeftTabs",async(e,{getState:n,dispatch:r})=>{const{tabs:a}=n().root;let i=!1;for(let u=0;u<e;u+=1)if(a[u].flags.touched){i=!0;break}if(i){const{confirmed:u}=await r(Eo({title:"Closing left tabs",message:"Your changes will be lost if you do not save them. Close anyway?",type:Hn.CONFIRM,color:Ga.WARNING,icon:"AiFillWarning"})).unwrap();if(!u)return}r(VC(e))}),l_=xe("files/reloadTab",async(e,{dispatch:n})=>{if(e.flags.touched){const{confirmed:i}=await n(Eo({title:qd(e),message:"Changes made to the file will be lost. Continue?",type:Hn.CONFIRM,color:Ga.WARNING,icon:"AiFillWarning"})).unwrap();if(!i)return}const r=px(e.path),a=await ni({verb:Zt.GET_INFO,path:e.path,content:!0,as:r});if(e.path===Ur){const{roles:i,privileges:u}=ap(a.content);n(cw({roles:i,privileges:u})),n(ww({path:e.path,flags:{old:!1}}))}else if(e.path===oi){const{content:i}=a;n(sp({path:"project",value:i}))}else{const{content:i}=a;return e.type===le.WEBFORM?KM.next({path:e.path,action:pT.RELOAD,payload:i.components}):e.type===le.MODEL&&_x.next({action:"reload",payload:i}),a}}),Ys=xe("files/saveTab",async({tab:e},{dispatch:n,getState:r})=>{const{path:a,content:i}=e;if(e.type===le.DEBUGGER)return{...e,errors:[]};a.split("/").pop();const c=await ST({path:a});if(c.files[0]){const m=new Date(e.date),b=new Date(c.files[0].date);if(m.getTime()<b.getTime()){const{confirmed:E}=await n(Eo({title:qd(e),message:"New content has been found on the server. Are you sure you want to continue?",type:Hn.CONFIRM,icon:"FaSave"})).unwrap();if(!E)return n(ww({path:a,flags:{old:!0}})),null}}const f=await bk({verb:Zt.SAVE_CONTENT,content:N6(e,r()),path:a});(e.type===le.CLASS||e.type===le.MODEL)&&vf();const p=(f.modelErrors||[]).map(m=>m.message),h=(f.permissionsErrors||[]).map(m=>m.message);return{...e,content:i,date:f.date,initialContent:i,errors:p.length>0||h.length>0?[{title:"Model errors",messages:p},{title:"Permissions errors",messages:h}]:[]}}),N6=(e,n)=>{switch(!0){case e.path==="settings.json":case e.path===oi:return n.settings.project;case e.type===le.ROLES:return aw(n.roles);case e.type===le.MODEL:return e.content||{toJSON:!0,dataClasses:[],extraProperties:{}};default:return e.content}},jS=async e=>{if(e.type===le.DATA_EXPLORER)return{name:"Data Explorer",path:e.path,flags:{},view:{panel:{isOpen:!1,type:"",current:""}},type:e.type,date:new Date().toISOString()};const n=e.path.split("/").filter(Boolean)[0],r=await fk({root:n,type:e.type,verb:Zt.GET,name:e.name}),a={};r.type===le.METHOD&&(a.attributes=z_(r.content));const{date:i,name:u,type:c,content:f}=r;return{date:i,flags:{enabled:e.type===le.WEBFORM},extra:a,view:{panel:{isOpen:!1,type:"",current:""}},name:u,path:e.path,type:c,initialContent:f,content:c===le.MODEL?MT(f):f}},yC=xe("files/tryInjectMethod",async({type:e,dataclass:n},{getState:r,dispatch:a})=>{const{root:{tabs:i},settings:{server:{qodly:u}}}=r(),c=Ws("class",u);let f="",p="",h=null;if(!n)f="DataStore",p=`Classes/DataStore.${c}`;else switch(e){case"dataclass":f=n,p=`Classes/${n}.${c}`;break;case"collection":f=`${n}Selection`,p=`Classes/${n}Selection.${c}`;break;case"entity":f=`${n}Entity`,p=`Classes/${n}Entity.${c}`;break;default:return h}const m=i.find(bn("path",p));if(m)return a(wn(m)),m;try{h=await jS({name:f,date:new Date().toISOString(),path:`class/${f}.${c}`,type:le.CLASS})}catch{n?await a(u_({type:"dataclass",className:n,collectionName:`${n}Selection`,toCreate:e})):await a(u_({type:"model"}))}return h=await jS({name:f,date:new Date().toISOString(),path:`class/${f}.${c}`,type:le.CLASS}),h.path=p,a(wn(h)),h}),j6=xe("roles/open",async(e,{dispatch:n,getState:r})=>{const{tabs:a}=r().root,i=a.find(u=>u.path===Ur);if(i)return n(wn(i)),i;n(Sd())}),{debugger:Ls={meta:{state:Na.DETACHED},list:[],sessions:[],expressions:[]}}=nu();var HS,GS;const L6={meta:{...Ls.meta,state:((HS=Ls.meta)==null?void 0:HS.state)===Na.ATTACHED?(GS=Ls.meta)==null?void 0:GS.state:Na.DETACHED},list:Ls.list||[],sessions:Ls.sessions||[],expressions:Ls.expressions||[]};function LS(e,n){const{line:r,offset:a,type:i="saved"}=n;e.breakpoints[i].locations.push({line:r}),Bt.isNumber(a)&&(e.breakpoints[i].offset=a)}function FS(e,n,r,a){e.breakpoints[r].locations=n,Bt.isNumber(a)&&(e.breakpoints[r].offset=a)}function WS({filePath:e,fileType:n,methodName:r,className:a,ext:i,source:u}){return{filePath:e,fileType:n,methodName:r,className:a,ext:i,source:u,breakpoints:{draft:{locations:[],offset:0},saved:{locations:[],offset:0}}}}function BS(e,n,r){let a=!1;const i=e.map(u=>u[r]!==n[r]?u:(a=!0,{...u,...n}));return a?i:[...i,n]}function kf(e){return e.map(({label:n})=>({label:n}))}const bC=qn({name:"debugger",initialState:L6,reducers:{addBreakpointDecoration(e,n){const{filePath:r,fileType:a,methodName:i,className:u,ext:c,source:f,breakpoint:p}=n.payload,h=Ps(e.list,r,i,u);if(h)LS(h,p);else{if(a===le.CLASS&&p.offset===void 0)throw new Error(`Cannot add a breakpoint on a function without offset. Try editing the ${u} class.`);const m=WS({filePath:r,fileType:a,methodName:i,className:u,ext:c,source:f});LS(m,p),e.list.push(m)}},removeBreakpointDecoration(e,n){const{filePath:r,methodName:a,line:i,offset:u=0,type:c="saved"}=n.payload;if(r.startsWith("Classes/")){const f=e.list.filter(p=>p.filePath===r);if(f.length>0){const p=i+u;f.forEach(h=>{const m=h.breakpoints[c].offset||0;h.breakpoints[c].locations=h.breakpoints[c].locations.filter(b=>b.line+m!==p),c==="saved"&&(h.breakpoints.draft.locations=h.breakpoints.draft.locations.filter(b=>b.line+m!==p))})}}else{const f=Ps(e.list,r,a);f&&(f.breakpoints[c].locations=f.breakpoints[c].locations.filter(p=>p.line!==i),c==="saved"&&(f.breakpoints.draft.locations=f.breakpoints.draft.locations.filter(p=>p.line!==i)))}},setBreakpointsDecoration(e,n){const{filePath:r,fileType:a,methodName:i,className:u,ext:c,source:f,breakpoints:p,offset:h,type:m="saved",clearDraft:b}=n.payload,E=Ps(e.list,r,i);if(E)FS(E,p,m,h),b&&m!=="draft"&&(E.breakpoints.draft.locations=[]);else{const O=WS({filePath:r,fileType:a,methodName:i,className:u,ext:c,source:f});FS(O,p,m,h),e.list.push(O)}},clearBreakpoints(e,n){const{filePath:r,type:a="saved"}=n.payload;e.list=e.list.map(i=>({...i,breakpoints:i.filePath===r?{draft:!a||a==="draft"?{locations:[],offset:0}:i.breakpoints.draft,saved:!a||a==="saved"?{locations:[],offset:0}:i.breakpoints.saved}:i.breakpoints}))},setActiveLine(e,n){const{threadId:r,line:a,highlight:i}=n.payload,u=dr(e.sessions,r);u&&(u.activeLine=a,i&&(u.highlightedLines={start:a,end:a}))},addExpression(e,n){const{threadId:r,label:a,save:i}=n.payload,u=dr(e.sessions,r);u&&u.stopped&&(u.expressions=[...u.expressions||[],{label:a}],i&&(e.expressions=kf(u.expressions)))},removeExpression(e,n){const{threadId:r,index:a,save:i}=n.payload,u=dr(e.sessions,r);u&&(u.expressions=u.expressions.filter((c,f)=>f!==a),i&&(e.expressions=kf(u.expressions)))},removeAllExpressions(e,n){const{threadId:r,save:a}=n.payload,i=dr(e.sessions,r);i&&(i.expressions=[],a&&(e.expressions=[]))},renameExpression(e,n){const{threadId:r,index:a,replacement:i,save:u}=n.payload,c=dr(e.sessions,r);c&&c.expressions[a]&&(c.expressions[a].label=i,u&&(e.expressions=kf(c.expressions)))},setExpression(e,n){const{threadId:r,expression:a}=n.payload,i=dr(e.sessions,r);if(i){const u=a.index>=0?a.index:i.expressions.length>0?i.expressions.length-1:0,c=i.expressions[u];c?(c.result=a.result,c.nakedResult=a.nakedResult,c.variablesReference=a.variablesReference||0,c.presentationHint=a.presentationHint):i.expressions.push(a)}},updateExpressionAt(e,n){const{threadId:r,index:a,value:i}=n.payload,u=dr(e.sessions,r);if(u){const c=u.expressions[a];c&&(c.result=`"${i}"`,c.nakedResult=i)}},saveExpressions(e,n){const{expressions:r}=n.payload;e.expressions=kf(r)},addSession(e,n){const{threadId:r,channelId:a,stackFrames:i,exceptions:u=[]}=n.payload,c=dr(e.sessions,r),f=i[0],{expressions:p=[]}=e;if(c)c.expressions=p;else{const h=V_(r);e.sessions.push({tabPath:h,threadId:r,channelId:a,stackFrames:i,currentStackFrame:f,exceptions:u,expressions:p,variables:{callchain:[],expressions:[]},highlightedLines:null,activeLine:null,stopped:!0})}},updateSession(e,n){const{threadId:r,changes:a}=n.payload;e.sessions=e.sessions.map(i=>i.threadId===r?{...i,...a}:i)},removeSession(e,n){const{threadId:r}=n.payload;e.sessions=e.sessions.filter(a=>a.threadId!==r)},removeSessionByIndex(e,n){const r=n.payload;e.sessions.splice(r,1)},setSessions(e,n){const r=n.payload;e.sessions=r},setCallChainVariables(e,n){const{threadId:r,frameId:a,variables:i}=n.payload;e.sessions=e.sessions.map(u=>{var c;return u.threadId===r?{...u,variables:{...u.variables,callchain:BS((c=u.variables)==null?void 0:c.callchain,{frameId:a,items:i},"frameId")}}:u})},setExpressionVariables(e,n){const{threadId:r,variablesReference:a,variables:i}=n.payload;e.sessions=e.sessions.map(u=>{var c;return u.threadId===r?{...u,variables:{...u.variables,expressions:BS((c=u.variables)==null?void 0:c.expressions,{variablesReference:a,items:i},"variablesReference")}}:u})},setSourceContent(e,n){const{threadId:r,content:a}=n.payload,i=dr(e.sessions,r);i&&(i.currentStackFrame.source={...i.currentStackFrame.source,content:a})},setDebuggerMeta(e,n){if(n.payload.state===Na.ERROR){e.meta.error={...e.meta.error,time:Date.now()};const{override:r,error:a={code:null,reason:"",type:pd.SOCKET_ERROR}}=n.payload;if((r||e.meta.state!==Na.ERROR)&&(e.meta.error={...e.meta.error,...a}),(a==null?void 0:a.type)===pd.SOCKET_CLOSURE&&!(a!=null&&a.reason)&&e.meta.state===Na.DETACHED)return}e.meta.state=n.payload.state}},extraReducers:e=>{e.addCase(wC.fulfilled,n=>{n.sessions=[]})}}),{addBreakpointDecoration:F6,removeBreakpointDecoration:W6,setBreakpointsDecoration:B6,clearBreakpoints:U6,setActiveLine:z6,addExpression:H6,renameExpression:G6,removeExpression:q6,removeAllExpressions:V6,setExpression:Y6,updateExpressionAt:K6,saveExpressions:X6,addSession:J6,updateSession:Z6,removeSession:Q6,removeSessionByIndex:eF,setSessions:_C,setCallChainVariables:tF,setExpressionVariables:rF,setSourceContent:nF,setDebuggerMeta:oF}=bC.actions,wC=xe("files/wipeDebuggerSessions",async(e,{getState:n,dispatch:r})=>{const{sessions:a}=n().debugger;for(const{threadId:i}of a){const u=V_(i);r(hw(u))}}),EC=xe("files/removeDebuggerSessionsNotIn",async(e,{getState:n,dispatch:r})=>{const{threadIds:a}=e,{sessions:i}=n().debugger,u=[],c=i.filter(f=>{const p=a.includes(f.threadId);return p||u.push(f.threadId),p});return r(_C(c)),{staleThreadIds:u}});var vw=(e=>(e.UUID="uuid",e.STRING="string",e.TEXT="text",e.DATE="date",e.TIME="duration",e.BOOLEAN="bool",e.BYTE="byte",e.INTEGER="word",e.LONG="long",e.LONG64="long64",e.FLOAT="number",e.BLOB="blob",e.IMAGE="image",e.OBJECT="object",e))(vw||{}),Ia=(e=>(e.STORAGE="storage",e.RELATEDENTITY="relatedEntity",e.RELATEDENTITIES="relatedEntities",e.CALCULATED="calculated",e.COMPOSITION="composition",e.ALIAS="alias",e))(Ia||{});const aF=e=>["string","uuid","number","long"].includes(e.type),iF=[{label:"Storage",value:"storage"},{label:"Calculated",value:"calculated"}],sF=[{title:"UUID",kind:"storage",value:"uuid",calculatedType:"uuid",calculatedKind:"storage"},{title:"Long",kind:"storage",value:"long",calculatedType:"long",calculatedKind:"storage"}],uF=[{title:"String",kind:"storage",value:"string",calculatedType:"string",calculatedKind:"storage"},{title:"Text",kind:"storage",value:"text",calculatedType:"text",calculatedKind:"storage"},{title:"UUID",kind:"storage",value:"uuid",calculatedType:"uuid",calculatedKind:"storage"},{title:"Date",kind:"storage",value:"date",calculatedType:"date",calculatedKind:"storage"},{title:"Duration",kind:"storage",value:"duration",calculatedType:"duration",calculatedKind:"storage"},{title:"Bool",kind:"storage",value:"bool",calculatedType:"bool",calculatedKind:"storage"},{title:"Byte",kind:"storage",value:"byte",calculatedType:"byte",calculatedKind:"storage"},{title:"Word",kind:"storage",value:"word",calculatedType:"word",calculatedKind:"storage"},{title:"Number",kind:"storage",value:"number",calculatedType:"number",calculatedKind:"storage"},{title:"Long",kind:"storage",value:"long",calculatedType:"long",calculatedKind:"storage"},{title:"Object",kind:"storage",value:"object",calculatedType:"object",calculatedKind:"storage"},{title:"Image",kind:"storage",value:"image",calculatedType:"image",calculatedKind:"storage"},{title:"Blob",kind:"storage",value:"blob",calculatedType:"blob",calculatedKind:"storage"}],cF=[{label:"Expose as REST",value:"public"},{label:"Do not expose as REST",value:"publicOnServer"}],lF=[{label:"Expose as REST",value:"public"},{label:"Do not expose as REST",value:"publicOnServer"}],fF=[{label:"None",value:"none"},{label:"B-tree",value:"btree"},{label:"Cluster",value:"cluster"},{label:"Automatic",value:"auto"}],SC=_n("model/add-dataclass"),OC=_n("model/rename-dataclass"),TC=_n("model/remove-dataclass"),xC=_n("model/add-attribute"),dF=_n("model/edit-attribute-property"),CC=_n("model/remove-attribute"),RC=_n("model/rename-attribute"),AC=_n("model/edit-primary-key"),pF=_n("model/edit-dataclass-property"),PC=_n("model/rename-collection"),hF=(e,n)=>({toJSON:!0,extraProperties:n,dataClasses:e.map(r=>{var a;return{...r.data,extraProperties:{position:{x:r.position.x,y:r.position.y},panelColor:(a=r.data.extraProperties)==null?void 0:a.panelColor}}})});function Yf(e,n,r){const a=e;let i=0;for(;r[`${a}${i||""}`];)i++;return`${a}${i||""}`}const ql=e=>e.kind===Ia.RELATEDENTITY,Od=e=>e.kind===Ia.RELATEDENTITIES,vF=e=>Od(e)||ql(e),gw=xe("models/fetch",async()=>{try{return(await hr(en,{method:"POST",body:JSON.stringify({verb:Zt.GET_INFO,path:B_,as:"json",content:!0}),headers:new Headers({"Content-Type":"application/json"})})).content}catch(e){return e.message}}),Td=xe("models/save",async(e,{getState:n,rejectWithValue:r})=>{const{tabs:a}=n().root,i=a.find(u=>u.path===B_);if(!i)return r("Error while saving the model");try{const u=await hr(en,{method:"POST",body:JSON.stringify({verb:"save",path:i.path,content:i.content}),headers:new Headers({"Content-Type":"application/json"})});return vf(),{...u,path:i.path,content:e.content||{toJSON:!0,dataClasses:[],extraProperties:{}}}}catch{return r("Error while saving the model")}}),gF=xe("models/open",async(e,{dispatch:n,getState:r})=>{const{tabs:a}=r().root,i=a.find(u=>u.path==="models/main");if(i)return n(wn(i)),i;n(gw())}),mF=xe("model/rename-dataclass",async(e,{getState:n,dispatch:r})=>{var b,E;const{dataclassId:a,selectionId:i,name:u}=e;let c=n();const f=c.explorer.find(O=>O.path===Wt.CLASSES);if(!f)throw new Error("Classes folder was not found!");await r(Po(f.path)),c=n();const p={class:{found:!1,newNameTaken:!1,file:null,filename_update:u},entity:{found:!1,newNameTaken:!1,file:null,filename_update:`${u}Entity`},selection:{found:!1,newNameTaken:!1,file:null,filename_update:`${u}Selection`}};(E=(b=c.explorer.find(O=>O.path===Wt.CLASSES))==null?void 0:b.children)==null||E.forEach(O=>{O.name===p.class.filename_update&&(p.class.newNameTaken=!0),O.name===p.entity.filename_update&&(p.entity.newNameTaken=!0),O.name===p.selection.filename_update&&(p.selection.newNameTaken=!0),O.name===a?(p.class.found=!0,p.class.file=O):O.name===`${a}Entity`?(p.entity.found=!0,p.entity.file=O):O.name===i&&(p.selection.found=!0,p.selection.file=O)});const h=Object.entries(p).reduce((O,R)=>{const[C,k]=R;return k.found?k.newNameTaken?[...O,{type:"error",message:`Cannot rename ${C} file to ${k.filename_update} because it already exists. The existing file will be used instead!`}]:O:[...O,{type:"warning",message:`${a} ${C} file was not found`}]},[]);h.length>0&&r(Eo({message:"The following errors were encountered during dataclass rename:",views:{tips:h}}));const m=Object.values(p).filter(O=>O.found&&O.file&&!O.newNameTaken);await Promise.all(m.map(async O=>await r(Vs({file:O.file,newname:O.filename_update})))),m.length>0&&r(Po("Classes"))}),nf={DATACLASS_DELETE:"dataclass.delete",DATACLASS_DRAGGABLE:"dataclass.draggable"},yF={model:{dataClasses:{},collections:{},extraProperties:{}},draft:{dataClasses:{},collections:{},extraProperties:{}},flags:{[nf.DATACLASS_DELETE]:!0,[nf.DATACLASS_DRAGGABLE]:!0}},DC=qn({name:"Models",initialState:yF,reducers:{setModelFlag(e,n){e.flags={...e.flags,...n.payload}}},extraReducers(e){e.addCase(SC,({draft:{dataClasses:n}},r)=>{var c,f;const{dataclassID:a}=r.payload,i=Yf(a||"DataClass","className",n),u={className:i,collectionName:`${i}Selection`,attributes:[{name:"ID",kind:Ia.STORAGE,type:vw.LONG,scope:"public",indexKind:"auto",unique:!0,primKey:!0,autosequence:!0}],name:i,scope:"public",extraProperties:{position:{x:((c=r.payload.position)==null?void 0:c.x)||0,y:((f=r.payload.position)==null?void 0:f.y)||0}}};n[u.name]=u}).addCase(TC,({draft:{dataClasses:n}},r)=>{const{dataclassID:a}=r.payload;n[a]&&(delete n[a],Object.values(n).forEach(u=>{u.attributes=u.attributes.filter(c=>c.type!==a&&c.type!==u.collectionName)}))}).addCase(OC,({draft:{dataClasses:n,collections:r}},a)=>{const{dataclassID:i,newName:u}=a.payload;if(!n[i]||n[u])return;const c=n[i].collectionName,f=Yf(`${u}Selection`,"collectionName",r);Object.values(n).forEach(p=>{p.className===i&&(p.className=u,p.name=u,p.collectionName=f),p.attributes.forEach(h=>{h.type===i?(h.type=u,h.path=u):h.type===c&&(h.type=f)})})}).addCase(xC,({draft:{dataClasses:n}},r)=>{const{dataclassID:a,attributeName:i,attributeType:u,attributeKind:c,target:f}=r.payload;if(!n[a]||ek("name",i,n[a].attributes))return;const h={name:i,kind:c,type:u,exposed:!0,scope:"public"};if(c===Ia.RELATEDENTITY){if(!n[u])return;h.path=u;const b={name:Yf(n[u].collectionName,"name",n[u].attributes),type:n[a].collectionName,kind:Ia.RELATEDENTITIES,reversePath:!0,path:i,scope:"public",exposed:!0};n[u].attributes.push(b)}else if(c===Ia.RELATEDENTITIES){const m=n[u];if(!m)return;const b=m.attributes.find(bn("name",f));if(b){if(!ql(b)||b.type!==n[a].className)return}else{h.path=f,h.reversePath=!0,h.type=u;const E={name:f,kind:Ia.RELATEDENTITY,scope:"public",path:m.className,type:m.className,exposed:!0};m.attributes.push(E)}}n[a].attributes.push(h)}).addCase(RC,({draft:{dataClasses:n}},r)=>{const{dataclassID:a,attributeID:i,newName:u}=r.payload,c=n[a].attributes.find(bn("name",i)),f=n[a].attributes.find(bn("name",u));!c||f||Object.values(n).forEach(({collectionName:p,attributes:h,className:m})=>{h.forEach(b=>{ql(c)&&Od(b)&&b.type===p&&b.path===i&&(b.path=u),m===a&&b.name===i&&(b.name=u)})})}).addCase(CC,({draft:{dataClasses:n}},r)=>{const{dataclassID:a,attributeID:i}=r.payload;if(!n[a])return;const u=n[a].attributes.find(bn("name",i));u&&(ql(u)&&Object.values(n).forEach(c=>{c.attributes=c.attributes.filter(f=>!(Od(f)&&f.type===c.collectionName&&f.path===u.name))}),n[a].attributes=n[a].attributes.filter(JM("name",i)))}).addCase(PC,({draft:{dataClasses:n,collections:r}},a)=>{const{dataclassID:i,collectionName:u}=a.payload;if(!n[i])return;const c=n[i].collectionName;r[u]||(n[i].collectionName=u,r[u]=n[i],delete r[c],Object.values(n).forEach(f=>f.attributes.forEach(p=>{p.type===c&&(p.type=u)})))}).addCase(AC,({draft:{dataClasses:n}},r)=>{const{dataclassID:a,newPrimKey:i}=r.payload;n[a]&&n[a].attributes.forEach(u=>{u.name===i?u.primKey=!0:u.primKey=!1})}),e.addCase(gw.fulfilled,(n,r)=>{var c;const a={},i={},u=r.payload.extraProperties||{};(c=r.payload.dataClasses)==null||c.forEach(f=>{a[f.name]=f,i[f.collectionName]=f}),n.draft.dataClasses=a,n.draft.collections=i,n.draft.extraProperties=u,n.model.dataClasses=a,n.model.collections=i,n.model.extraProperties=u}),e.addCase(Td.pending,()=>{}).addCase(Td.fulfilled,(n,r)=>{const a={},i={},u=r.payload.content.extraProperties||{};r.payload.content.dataClasses.forEach(c=>{a[c.name]=c,i[c.collectionName]=c}),n.draft.dataClasses=a,n.draft.collections=i,n.draft.extraProperties=u,n.model.dataClasses=a,n.model.collections=i,n.model.extraProperties=u})}}),{setModelFlag:bF}=DC.actions,_F=()=>Ua(e=>e.model.draft.dataClasses),wF=()=>Ua(e=>e.model.draft.collections),EF=e=>Ua(n=>n.model.draft.dataClasses[e]),SF=(e,n)=>Ua(r=>r.model.draft.dataClasses[e].attributes.find(bn("name",n))),OF=()=>Ua(e=>e.model.draft.extraProperties),TF=()=>{const e=Ua(i=>i.model.flags),n=i=>i in e?e[i]:void 0,r=n(nf.DATACLASS_DELETE),a=n(nf.DATACLASS_DRAGGABLE);return{deleteDataclass:r,draggableDataclass:a,flags:e}},xF=DC.reducer;function m1(e,n){const r=e.tabs.find(({path:a})=>a===oi);r&&(r.flags.touched=n)}const IC={SIDEBAR_SECTION_RESIZABLE:"sidebar.section.resizable"},{webforms:$f}=nu(),MC={[IC.SIDEBAR_SECTION_RESIZABLE]:!0},kC={...$f,templates:{data:[],selectedGroup:""},datasources:{...G_.webforms.datasources,...$f==null?void 0:$f.datasources},flags:MC},$C=qn({name:"webforms",initialState:kC,reducers:{toggleInspector:(e,n)=>{const{type:r}=n.payload;e.inspector[r].active=!e.inspector[r].active,e.inspector[r].active||(e.inspector[r].data=void 0)},inspect:(e,n)=>{const{type:r,data:a}=n.payload;e.inspector[r].active&&(e.inspector[r].data=a)},addComponent:(e,n)=>{e.components.push(n.payload)},editComponent:(e,n)=>{const{id:r,changes:a}=n.payload;e.components=e.components.map(i=>i.id===r?{...i,...a}:i)},removeComponent:(e,n)=>{const{payload:r}=n,a=e.components.findIndex(i=>i.id===r);a!==-1&&e.components.splice(a,1)},setSelectedGroup:(e,n)=>{e.templates.selectedGroup=n.payload.selectedGroup},setTemplatesData:(e,n)=>{e.templates.data=n.payload},setTemplateData:(e,n)=>{const{group:r,components:a}=n.payload,i=e.templates.data.find(u=>u.group===r);i&&(i.components=a)},setDatasourcesTheme:(e,n)=>{e.datasources.theme=n.payload},setWebformsFlag(e,n){e.flags={...e.flags,...n.payload}}},extraReducers(e){e.addCase(BC.fulfilled,(n,r)=>{n.components=r.payload})}}),{toggleInspector:CF,inspect:RF,addComponent:NC,editComponent:jC,removeComponent:LC,setSelectedGroup:AF,setTemplatesData:FC,setTemplateData:WC,setDatasourcesTheme:PF,setWebformsFlag:DF}=$C.actions,IF=$C.reducer,mw=Bt.curry((e,n)=>{var i,u;const r={...n.sharedDatasources.sources},a=(u=((i=n.root.tabs.find(bn("path",e)))==null?void 0:i.content).metadata)==null?void 0:u.datasources;return a&&(r[e]=a),Bt.cloneDeep(r)}),MF=xe("webforms/fetchTemplates",async(e,{dispatch:n,getState:r})=>{const{data:a}=r().webforms.templates;if(!Bt.isEmpty(a))return a;try{const u=await(await fetch(`https://raw.githubusercontent.com/4d/Web-studio-TIPS/gh-build/build/index.json?t=${Date.now()}`)).json();return n(FC(u)),u}catch{return[]}}),kF=xe("webforms/fetchTemplate",async({name:e},{dispatch:n,getState:r})=>{const{data:a}=r().webforms.templates,i=a.find(u=>u.group===e);if(i&&!Bt.isEmpty(i.components))return i.components;try{const c=await(await fetch(`${i==null?void 0:i.link}?t=${Date.now()}`)).json();return n(WC({group:e,components:c})),c}catch{return[]}}),BC=xe("webforms/fetchCraftedComponents",async(e,{rejectWithValue:n})=>{try{return(await ni({path:"WebForms/crafted_components.json",verb:Zt.GET_INFO,content:!0,as:"json"})).content}catch{return n("Error while loading the crafted components")}}),$F=xe("webforms/addCraftedComponent",async(e,{dispatch:n,rejectWithValue:r,getState:a})=>{try{n(NC(e));const{webforms:{components:i}}=a();H_(i)}catch{return r("Error while adding the crafted component")}}),NF=xe("webforms/editCraftedComponent",async(e,{dispatch:n,rejectWithValue:r,getState:a})=>{try{n(jC(e));const{webforms:{components:i}}=a();H_(i)}catch{return r("Error while editing the crafted component")}}),jF=xe("webforms/removeCraftedComponent",async(e,{dispatch:n,rejectWithValue:r,getState:a})=>{try{n(LC(e));const{webforms:{components:i}}=a();H_(i)}catch{return r("Error while removing the crafted component")}}),yw=xe("datasources/add-datasource",async(e,{getState:n,rejectWithValue:r})=>{var a,i;try{const u=n(),c=e.datasource,f=!!c.namespace,p=[];if(f){const h={...u.sharedDatasources.sources,[c.namespace]:[...u.sharedDatasources.sources[c.namespace],c]};p.push(...h[c.namespace]),await ri(h)}else(((i=(a=u.root.tabs.find(bn("path",e.path)).content)==null?void 0:a.metadata)==null?void 0:i.datasources)||[]).push(c);return{list:p,path:e.path,namespace:e.datasource.namespace}}catch{console.error("Error while adding the datasource",e.datasource.id),r("Error while adding the datasource")}}),bw=xe("datasources/edit-datasource",async(e,{getState:n,rejectWithValue:r})=>{try{const{namespace:a,path:i}=e,u=n(),c=!!e.namespace,f=mw(i,u);let p=Bt.defaultTo(f[a||i],[]);return p=p.map(h=>h.id===e.id?{...h,[e.property]:e.value}:h),c&&await ri({...u.sharedDatasources.sources,[e.namespace]:p}),{list:p,path:e.path,namespace:e.namespace}}catch{r(`Error while editing datasource ${e.id}`)}}),LF=e=>e.type===Ks.fulfilled.type,Ks=xe("datasources/rename-datasource",async(e,{getState:n,rejectWithValue:r})=>{try{const a=n(),i=!!e.namespace,u=e.namespace||e.path,c=mw(e.path,a),f=Bt.defaultTo(c[u],[]),p=new RegExp(`^${e.id}\\b`,"");if(f.forEach(h=>{var b;const m=(U_(h)||!bT(h))&&h.from&&p.test(h.from);e.updateRefs&&((b=h.events)==null||b.forEach(E=>{var O,R,C,k,j;switch(E.type){case"method":{const F=E;F.params.forEach(D=>{D.datasource&&Object.assign(D,{datasource:D.datasource.replace(new RegExp(`^${e.id}`,""),e.new_name)})}),F.returns&&Object.assign(F.returns,{datasource:(R=(O=F.returns)==null?void 0:O.datasource)==null?void 0:R.replace(new RegExp(`^${e.id}`,""),e.new_name)});return}case"simple-action":{const F=E;F.datasource&&Object.assign(F.datasource,{name:(C=F.datasource.name)==null?void 0:C.replace(new RegExp(`^${e.id}`,""),e.new_name),from:(k=F.datasource.from)==null?void 0:k.replace(new RegExp(`^${e.id}`,""),e.new_name),target:(j=F.datasource.target)==null?void 0:j.replace(new RegExp(`^${e.id}`,""),e.new_name)});return}default:return}})),h.id===e.id?h.id=e.new_name:m&&h.from&&(h.from=h.from.replace(new RegExp(`^${e.id}`,""),e.new_name))}),e.updateRefs){const h=fd({id:e.id,namespace:e.namespace}),m=fd({id:e.new_name,namespace:e.namespace});hT.next({path:e.path??"",action:F_.RENAME,old_reference:h,new_reference:m,is_shared:i})}return i&&await ri({...a.sharedDatasources.sources,[e.namespace]:f}),{list:f,path:e.path,namespace:e.namespace}}catch{return r(`Error while renaming datasource ${e.namespace}:${e.id}`)}}),Vl=xe("datasources/delete-datasource",async(e,{getState:n,rejectWithValue:r})=>{try{const a=n(),i=!!e.namespace,u=e.namespace||e.path,f=mw(e.path,a)[u].filter(ZM(e.id));return i&&await ri({...a.sharedDatasources.sources,[e.namespace]:f}),{list:f,path:e.path,namespace:e.namespace}}catch{return r(`Error while removing datasource ${e.id}`)}}),y1=nu(),FF={filesLoading:!1,tabs:y1.tabs||[],activeTab:y1.activeTab,recent:y1.recent||[]},_w=qn({name:"root",initialState:FF,reducers:{setPanelState(e,n){const{path:r,...a}=n.payload;e.tabs.forEach(i=>{i.path===r&&(i.view||(i.view={panel:{isOpen:!1,type:"",current:""}}),Object.assign(i.view.panel,a))})},addDataSource(e,n){var u;const{payload:{path:r,datasourceDef:a}}=n,i=e.tabs.find(c=>c.path===r);i&&(i.content.metadata.datasources=i.content.metadata.datasources||[],(u=i.content.metadata.datasources)!=null&&u.find(f=>f.id===a.id)||(i.content.metadata.datasources=[...i.content.metadata.datasources,{...a,events:[]}],i.flags={...i.flags,touched:!0}))},openSettingsTab(e){const n={date:new Date().toISOString(),flags:{},view:{panel:{isOpen:!1,type:"",current:""}},extra:{editor:{key:"editors:settings"}},name:"Settings",path:oi,type:le.SETTINGS,initialContent:{},content:{}};let r=e.tabs.find(a=>a.path===n.path);if(r||(e.tabs.push(n),r=e.tabs[e.tabs.length-1]),e.activeTab!==n.path){const a=e.tabs.reduce((i,u)=>(u==null?void 0:u.weight)>((i==null?void 0:i.weight)||0)?u:i,null);e.activeTab=n.path,r.weight=((a==null?void 0:a.weight)||0)+1}},removeDataSource(e,n){const{path:r,datasourceID:a}=n.payload;e.tabs=e.tabs.map(i=>i.path===r?{...i,flags:{...i.flags,touched:!0},content:{...i.content,metadata:{...i.content.metadata,datasources:i.content.metadata.datasources.filter(u=>u.id!==a)}}}:i)},setDataSources(e,n){const{payload:{path:r,datasourceArr:a}}=n;e.tabs=e.tabs.map(i=>{var u;return i.path===r?{...i,flags:{...i.flags,touched:!0},content:{...i.content,metadata:{...(u=i.content)==null?void 0:u.metadata,datasources:a}}}:i})},setTabs(e,n){e.tabs=n.payload},closeTab(e,n){const r=n.payload;e.tabs.splice(r,1);const a=e.tabs.reduce((i,u)=>(u==null?void 0:u.weight)>((i==null?void 0:i.weight)||0)?u:i,null);e.activeTab=(a==null?void 0:a.path)||""},closeOthers(e,n){e.tabs=e.tabs.filter(r=>r.path===n.payload),e.activeTab=n.payload},closeAllTabs(e){e.tabs=[],e.activeTab=""},closeRightTabs(e,n){e.tabs.splice(n.payload+1),e.activeTab=e.tabs[n.payload].path},closeLeftTabs(e,n){e.tabs.splice(0,n.payload)},closeSavedTabs(e){e.tabs=e.tabs.filter(({flags:{touched:r}})=>r);const n=e.tabs.reduce((r,a)=>(a==null?void 0:a.weight)>((r==null?void 0:r.weight)||0)?a:r,null);e.activeTab=(n==null?void 0:n.path)||""},selectTab(e,n){const r=e.tabs.find(({path:i})=>i===n.payload);if(!r||e.activeTab===n.payload)return;const a=e.tabs.reduce((i,u)=>(u==null?void 0:u.weight)>((i==null?void 0:i.weight)||0)?u:i,null);r.weight=a?(a.weight||0)+1:1,e.activeTab=n.payload},openTabUnselected(e,n){const r=n.payload;let a=e.tabs.find(({path:u})=>r.path===u);a||(e.tabs.push(r),a=e.tabs[e.tabs.length-1]);const i=e.tabs.reduce((u,c)=>(c==null?void 0:c.weight)>((u==null?void 0:u.weight)||0)?c:u,null);a.weight=i?(i.weight||0)+1:1,a.extra={...a.extra,...r.extra}},selectTabByReference(e,n){const r=n.payload;let a=e.tabs.find(({path:i})=>r.path===i);if(a||(e.tabs.push(r),a=e.tabs[e.tabs.length-1]),e.activeTab!==r.path){const i=e.tabs.reduce((u,c)=>(c==null?void 0:c.weight)>((u==null?void 0:u.weight)||0)?c:u,null);e.activeTab=r.path,a.weight=((i==null?void 0:i.weight)||0)+1}a.extra={...a.extra,...r.extra},a.flags={...a.flags||{},...r.flags||{}}},setContent(e,n){const{path:r,content:a,contentPath:i}=n.payload;e.tabs=e.tabs.map(u=>{if(u.path!==r)return u;let c=!1;if(typeof a=="string")c=u.initialContent!==a;else{const f=JSON.stringify(Bt.get(u.initialContent,i||"",u.initialContent)),p=JSON.stringify(Bt.get(a,i||"",a));c=f!==p}return a&&typeof a=="object"&&(i?Bt.set(u.content,i,a):u.content=a),typeof a=="string"&&(u.content=a),{...u,flags:{...u.flags,touched:c}}})},setTabFlags(e,n){const{path:r,flags:a}=n.payload;e.tabs=e.tabs.map(i=>i.path===r?{...i,flags:{...i.flags,...a}}:i)},setTabsFlags(e,n){const{tabs:r,flags:a}=n.payload;e.tabs=e.tabs.map(i=>r.includes(i.path)?{...i,flags:{...i.flags,...a}}:i)},setTabExtra(e,n){const{path:r,extra:a,flags:i}=n.payload;e.tabs=e.tabs.map(u=>u.path===r?{...u,extra:{...u.extra,...a},flags:i?{...u.flags,...i}:u.flags}:u)},addWebFormStyles(e,n){const{path:r,styles:a=[]}=n.payload,i=e.tabs.find(u=>u.path===r);if(i){const u=i.content.metadata.styles.map(({name:f})=>f),c=a.filter(({name:f})=>!u.includes(f));i.content.metadata.styles=[...i.content.metadata.styles,...c].map(({scope:f,...p})=>({...p}))}},changeTabEditor(e,n){return e.tabs=e.tabs.map(r=>r.path===n.payload.path?n.payload:r),e}},extraReducers:e=>{e.addCase(vC.fulfilled,(n,r)=>{if(!r.payload)return;const{content:a,line:i,path:u}=r.payload,c=n.tabs.find(f=>f.path===u);if(c&&typeof c.content=="string"){const f=c.content.trim().split(`
279
279
  `);f.splice(i,0,a),c.content=f.join(`
280
280
  `)}}),e.addCase(Ys.pending,(n,r)=>{const{tab:a}=r.meta.arg;switch(a.type){case le.CLASS:case le.METHOD:Xa.next({action:ka.WILL_SAVE,payload:{filePath:a.path}});break}}),e.addCase(Ys.fulfilled,(n,r)=>{if(!r.payload)return;const a=n.tabs.find(({path:i})=>{var u;return i===((u=r.payload)==null?void 0:u.path)});if(a){switch(a.content=r.payload.content,a.date=r.payload.date,a.initialContent=r.payload.initialContent,a.flags.touched=!1,a.flags.old=!1,a.type){case le.CLASS:case le.METHOD:Xa.next({action:ka.DID_SAVE,payload:{filePath:a.path,content:a.content}});break}r.payload.errors.length>0&&Ao.next({kind:"error",message:r.payload.errors})}}),e.addCase(Ys.rejected,(n,r)=>{Ao.next({kind:"danger",message:"Cannot save file"})}),e.addCase(mC.fulfilled,(n,r)=>{const a=[...r.payload.files];n.tabs=n.tabs.map(i=>{if([le.CLASS,le.METHOD].includes(i.type)){const u=a.find(c=>c.name===i.name&&c.type===i.type);if(u){const c=new Date(i.date),f=new Date(u.date);if(c.getTime()!==f.getTime())return{...i,flags:{...i.flags,old:!0}}}}return i})}),e.addCase(l_.pending,(n,r)=>{n.tabs=n.tabs.map(a=>a.path===r.meta.arg.path?{...a,flags:{...a.flags,loading:!0}}:a)}),e.addCase(l_.fulfilled,(n,r)=>{const a=r.payload;if(a){const i=r.meta.arg;n.tabs=n.tabs.map(u=>{if(u.name===i.name&&u.type===i.type){const c=u.extra||{};return i.type===le.METHOD&&(c.attributes=z_(a.content),a.content=wT(a.content,{})),{...u,initialContent:a.content,content:a.content,date:a.date,flags:{},extra:c}}return u})}}),e.addCase(fw.fulfilled,(n,r)=>{if(!r.payload)return;const{line:a,offset:i}=r.meta.arg,u=n.tabs.find(({path:c})=>{var f;return c===((f=r.payload)==null?void 0:f.path)});u&&(u.extra={...u.extra,initialLineInfo:{line:a,offset:i,lastModification:Date.now()}})}),e.addCase(gC.fulfilled,(n,r)=>{if(!r.payload)return;const{selection:a}=r.meta.arg,i=n.tabs.find(({path:u})=>{var c;return u===((c=r.payload)==null?void 0:c.path)});i&&(i.extra={...i.extra,initialSelectionInfo:{selection:a,lastModification:Date.now()}})}),e.addCase(Vs.fulfilled,(n,r)=>{r.payload.new!==r.payload.old&&(n.tabs=[...n.tabs].map(a=>a.path===r.payload.old.path?{...a,path:r.payload.new.path,name:r.payload.new.name}:a),n.activeTab===r.payload.old.path&&(n.activeTab=r.payload.new.path))}),e.addCase(c_.pending,(n,r)=>{const a=r.meta.arg,i=`${a.path}${a.ext?`.${a.ext}`:""}`;switch(a.ext){case"4dm":case"4qs":Xa.next({action:ka.WILL_DELETE,payload:{filePath:i}});break}}),e.addCase(c_.fulfilled,(n,r)=>{const{deleted:a,node:i}=r.payload;if(!a)return;const u=`${i.path}${i.ext?`.${i.ext}`:""}`;switch(i.ext){case"4dm":case"4qs":Xa.next({action:ka.DID_DELETE,payload:{filePath:u}});break}if(n.tabs=n.tabs.filter(c=>c.path!==u),n.recent=n.recent.filter(({path:c})=>u!==c),n.tabs.length){n.activeTab=n.tabs[n.tabs.length-1].path;return}n.activeTab=""}),e.addCase(Gl.fulfilled,(n,r)=>{const{draggedNode:a,newLocation:i}=r.meta.arg;if(n.tabs.find(u=>u.path===`${a.path}${a.ext?`.${a.ext}`:""}`))return n.tabs=n.tabs.map(u=>u.path===`${a.path}${a.ext?`.${a.ext}`:""}`?{...u,path:`${i.path}/${a.name}.${a.ext}`}:u),n.recent=n.recent.map(u=>u.path===`${a.path}${a.ext?`.${a.ext}`:""}`?{...u,path:`${i.path}/${a.name}.${a.ext}`}:u),n.activeTab=`${i.path}/${a.name}.${a.ext}`,n}),e.addCase(Td.fulfilled,(n,r)=>{const a=n.tabs.find(i=>i.path===r.payload.path);a&&(a.flags.touched=!1,a.date=r.payload.date,a.content=r.payload.content,a.initialContent=r.payload.content)}),e.addCase(yC.fulfilled,(n,r)=>{var u;if(!((u=r.payload)!=null&&u.path))return;const a=n.tabs.find(bn("path",r.payload.path));if(!a)return;a.content=a.content+`
281
281