@ws-ui/store 0.0.32 → 0.0.34

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
@@ -124,7 +124,7 @@ Check the top-level render call using <`+I+">.")}return R}}function tn(g,R){{if(
124
124
  `:`Class extends Entity
125
125
  `};case"model":return{name:"DataStore",content:s?`extends DataStoreImplementation
126
126
  `:`Class extends DataStoreImplementation
127
- `}}};e.type==="dataclass"&&!e.toCreate?p=[{...h("dataclass")},{...h("collection")},{...h("entity")}]:e.type==="dataclass"&&e.toCreate?p=[{...h(e.toCreate)}]:p=[{...h("model")}],p=p.filter(_=>!f.find(({name:S,ext:T})=>S===_.name&&T===(s?"4qs":"4dm"))),await Promise.all(p.map(async({name:_,content:S})=>{await r(la({type:E.FileFolderType.CLASS,path:i,fileName:_,parentNode:c,content:S,qodly:a.settings.server.qodly}))})),await r(Pr(i))}),Pr=re("explorer/fetchFolderContent",async(e,{rejectWithValue:r})=>{try{return(await E.getNodeInfo({verb:E.DesignerRequestVerb.GET_INFO,path:e})).map(a=>{const i=`${e}/${a.name}`,{editor:s,supportedEditors:c}=Sr(`${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:s,supportedEditors:c}}})}catch{return r("Failed loading file content please Reload")}},{getPendingMeta:()=>{}}),Ja=re("explorer/fetchFolderContentWithoutExpanding",async(e,{rejectWithValue:r})=>{try{return(await E.getNodeInfo({verb:E.DesignerRequestVerb.GET_INFO,path:e})).map(a=>{const i=`${e}/${a.name}`,{editor:s,supportedEditors:c}=Sr(`${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:s,supportedEditors:c}}})}catch{return r("Failed loading file content please Reload")}},{getPendingMeta:()=>{}});function cD(e){const r=e.split(".");return r.pop(),{name:r.join("."),ext:e.split(".")[e.split(".").length-1]}}const lD=re("explorer/uploadFile",async e=>{const r=e.type.includes("image/")?"$rawPict=true":"$binary=true";try{const t=await fetch(`/rest/$upload?${r}`,{method:"POST",headers:{"Content-Type":e.type},body:e});return{status:t.status,data:await t.json()}}catch{return{status:500,data:null}}}),fD=re("explorer/uploadFile",async({file:e,path:r,parentNode:t},{dispatch:a})=>{const{editor:i,supportedEditors:s}=Sr(r),{name:c,ext:l}=cD(e.name);a(Qg({parent:t,child:{name:c,path:`${r}/${e.name}?t=${Date.now()}`,type:e.type,error:null,flags:{loading:!0},config:{editor:i,supportedEditors:s},ext:l}}));try{const f=await fetch(`/rest/$upload?$sharedFolder=true&$filename=${e.name}&$path=${r}`,{method:"POST",headers:{"Content-Type":e.type},body:e});return f.status>=300?(a(gc({parent:t,child:{name:c,path:`${r}/${e.name}`,type:e.type,error:{message:"error uploading file"},flags:{},config:{editor:i,supportedEditors:s},ext:l}})),f.status!==413&&E.toastSubject.next({message:"error uploading file",kind:"danger"})):await a(Pr(t.path)),{status:f.status,fileName:e.name}}catch{return a(gc({parent:t,child:{name:c,path:`${r}/${e.name}`,type:e.type,error:{message:"error uploading file"},flags:{},config:{editor:i,supportedEditors:s},ext:l}})),E.toastSubject.next({message:"error uploading file",kind:"danger"}),{status:500,fileName:e.name}}}),la=re("explorer/createNewFile",async({fileName:e,type:r,path:t,parentNode:a,content:i},{dispatch:s,rejectWithValue:c,getState:l})=>{const{server:{qodly:f},project:p}=l().settings;try{const h=await E.setFileContent({name:tv(e,r,f),content:i||ev(r,p),path:t,asText:[E.FileFolderType.CLASS,E.FileFolderType.METHOD].includes(r)});return a.error&&(a.flags.expanded?await s(Pr(a.path)):await s(Ja(a.path))),{qodly:f,file:h,parentNode:a}}catch{return c("failed to create folder")}});function nv(e,r){const{qodly:t=!0,withExtension:a=!0}=r||{},i=E.getFileExtentionFromType(e.type,t);let s="";switch(e.type){case E.FileFolderType.WEBFORM:s=`${E.FolderRootPath.WEBFORMS}/${e.name}`;break;case E.FileFolderType.METHOD:s=`${E.FolderRootPath.METHODS}/${e.name}`;break;case E.FileFolderType.CLASS:s=`${E.FolderRootPath.CLASSES}/${e.name}`;break;default:return""}return`${s}${a?`.${i}`:""}`}const dD=re("explorer/createNewFileAndOpen",async(e,{dispatch:r,getState:t})=>{const a=await r(la(e)).unwrap(),{qodly:i}=t().settings.server;if(a){const{file:s}=a,c=nv(s,{withExtension:!1,qodly:i}),{editor:l}=Sr(c);await r(Xa({file:{name:e.fileName,type:s.type,path:c,editor:l,date:new Date().toISOString()}}))}}),li=re("explorer/createNewNode",async({fileName:e,path:r,parentNode:t},{rejectWithValue:a})=>{try{return{file:await E.createFolder({verb:E.DesignerRequestVerb.CREATE_FOLDER,path:`${r}/${e}`,recursive:!0}),parentNode:t}}catch{return E.toastSubject.next({message:"failed to create folder",kind:"danger"}),a("failed to create folder")}}),ts=async(e,r=!0)=>{try{const t=e.path.split(".").at(-1),a=await E.getNodeInfo({verb:E.DesignerRequestVerb.GET_INFO,path:e.path,content:!0,as:Ah(t)?"json":"text"}),i={editor:e.editor},s=E.getTypeFromExtension(e.path);s===E.FileFolderType.METHOD&&(i.attributes=E.parseAttributes(a.content),a.content=E.addAttributesToContent(a.content,{}));const{content:c,date:l,ext:f}=a;return{date:l,view:{panel:{isOpen:!1,type:"",current:""}},flags:{enabled:["WebForm","MForm"].includes(f),confirmed:r},extra:i,name:e.name,path:e.path,type:s,initialContent:c,content:c}}catch(t){const{data:a}=t;if(a.__ERROR.find(i=>i.errCode===E.ERROR_CODES.FILE_NOT_FOUND))switch(e.path){case E.ROLES_TAB_PATH:{const i={permissions:{allowed:[]},privileges:[],roles:[]};return{date:new Date().toISOString(),flags:{},extra:{editor:{key:"editors:roles"}},name:"Roles & Privileges",path:e.path,type:E.FileFolderType.ROLES,initialContent:i,content:i}}case E.SETTINGS_TAB_PATH:{const i={};return{date:new Date().toISOString(),flags:{},extra:{editor:{key:"editors:settings"}},name:"Settings",path:e.path,type:E.FileFolderType.SETTINGS,initialContent:i,content:i}}}throw t}},Xa=re("explorer/openFile",async({file:e,inactive:r,flags:t={}},{getState:a,dispatch:i})=>{const{root:{tabs:s},roles:c,debugger:{sessions:l}}=a(),f=s.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,...t}};return i(jt(m)),m}if(e.path.startsWith("Debugger")){const m=l.find(_=>`Debugger/${_.threadId}`===e.path);if(m){const{source:{content:_},source:S}=m.currentStackFrame,T={name:e.name,type:E.FileFolderType.DEBUGGER,date:new Date().toISOString(),path:e.path,content:_,view:{panel:{isOpen:!1,type:"",current:""}},initialContent:_,flags:{confirmed:!0},extra:{source:S,editor:e.editor}};return i(jt(T)),T}}let p=null;try{p=await ts(e,t.confirmed)}catch(m){const{data:_}=m;if(_.__ERROR.find(S=>[E.ERROR_CODES.JSON_MALFORMED,E.ERROR_CODES.JSON_MALFORMED_AT_LINE].includes(S.errCode))){const{confirmed:S}=await i(dr({title:"Corrupt file",type:qt.CONFIRM,color:Ir.WARNING,message:"Open in code editor ?"})).unwrap();if(S){const T=await E.getNodeInfo({verb:E.DesignerRequestVerb.GET_INFO,path:e.path,content:!0,as:"text"}),{content:C,date:F,ext:D}=T;p={date:F,view:{panel:{isOpen:!1,type:"",current:""}},flags:{enabled:["WebForm","MForm"].includes(D),confirmed:!0},extra:{editor:E.EDITOR.Code},name:e.name,path:e.path,type:E.getTypeFromExtension(e.path),initialContent:C,content:C}}}}return p&&(e.path===E.ROLES_TAB_PATH&&!c.flags.touched?i(Kc({content:p.content,date:p.date})):e.path===E.SETTINGS_TAB_PATH&&i(es({path:"project",value:p.content})),i((r?Lv:jt)(p)),p)}),Zc=re("explorer/openFileAtLine",async({file:e},{getState:r,dispatch:t})=>{const{tabs:a}=r().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 t(jt(c)),c}const s=await ts(e);return t(jt(s)),s}),av=re("explorer/injectContentAtLine",async(e,{getState:r,dispatch:t,rejectWithValue:a})=>{const i=r();e.path.split("/").pop();const c=vt(i.explorer,e.path);if(!c)return a(`Error while trying to inject content in file ${e.path}`);const l=await ts({name:c.name,date:c.date||new Date().toISOString(),path:`${c.path}.${c.ext}`,type:E.FileFolderType.CLASS,editor:c.config.editor});return await t(jt(l)),{...e,path:`${c.path}.${c.ext}`}}),ov=re("explorer/openFileAtSelection",async({file:e},{getState:r,dispatch:t})=>{const{tabs:a}=r().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 t(jt(c)),c}const s=await ts(e);return t(jt(s)),s}),yc=re("explorer/deleteFile",async e=>{const{name:r,type:t,path:a,flags:i}=e;if(i.error)return{deleted:!0,node:e};const s=a.split("/");return s.pop(),{deleted:await E.dropFile({root:E.FolderRootType.ROOT,type:rv(t),verb:E.DesignerRequestVerb.DROP,name:r,path:s.join("/")}),node:e}}),pD=re("explorer/deleteFolder",async e=>{const{path:r,flags:t}=e;if(t.error)return{deleted:!0,node:e};const{deleted:a}=await E.removeItem({force:!0,path:r,verb:E.DesignerRequestVerb.REMOVE_ITEM});return{deleted:a,node:e}}),hD=re("explorer/removeFileNode",async(e,{getState:r,dispatch:t})=>{const a=`${e.path}.${e.ext}`;if(await E.removeItem({verb:E.DesignerRequestVerb.REMOVE_ITEM,path:a,force:!0}),e.path==="Classes/DataStore"&&setTimeout(()=>{t(Wn())},ji),e.ext){const{tabs:i}=r().root,s=i.findIndex(c=>c.path===a);s>=0&&t(sl(s))}return{deleted:!0,node:e}}),fa=re("explorer/renameFile",async({file:e,newname:r})=>{if(e.type!=="folder"){const a=e.path.split("/");a.pop();const i=`${a.join("/")}/${e.name}.${e.ext}`,s=`${a.join("/")}/${r}.${e.ext}`;return await E.moveItem({verb:E.DesignerRequestVerb.MOVE_ITEM,path:i,newpath:s}),{old:{...e,path:i},new:{...e,name:r,path:s}}}const t=e.path.split("/");return t.pop(),await E.moveItem({verb:E.DesignerRequestVerb.MOVE_ITEM,path:`${t.join("/")}/${e.name}`,newpath:`${t.join("/")}/${r}`}),{old:e,new:{...e,name:r,path:`${t.join("/")}/${r}`}}}),Za=re("explorer/relocateNode",async({draggedNode:e,newLocation:r},{rejectWithValue:t})=>{try{await E.moveItem({verb:E.DesignerRequestVerb.MOVE_ITEM,path:`${e.path}.${e.ext}`,newpath:`${r.path}/${e.name}.${e.ext}`})}catch{return t("can't move item")}}),fi=re("explorer/duplicateNode",async({node:e,duplicateName:r},{rejectWithValue:t,fulfillWithValue:a,getState:i})=>{const s=e.path.split("/");s.pop();try{const{tabs:c}=i().root,l=c.find(({path:m})=>m===`${e.path}${e.ext?`.${e.ext}`:""}`),f=["4dm","4qm","4qs"].includes(e.ext),{content:p}=l||await E.getNodeInfo({verb:E.DesignerRequestVerb.GET_INFO,path:`${e.path}.${e.ext}`,content:!0,as:f?"text":"json"}),h=await E.setFileContent({name:`${r}.${e.ext}`,content:p,path:s.join("/"),asText:f});return a({node:{...h,path:s.join("/")}})}catch{return t("failed to duplicate file")}}),gD=re("explorer/executeMethod",async({methodName:e,params:r=[],resultingDataSource:t={},namespace:a=""},{rejectWithValue:i})=>{var s,c;try{const f=await window.Method4D.buildMethod({methodName:e,parameters:r,resultingDataSource:t},{namespace:a},null).callServerSide({id:"",serverSideRef:""},"onclick",{});return f!=null&&f.__NOTIFICATION?E.toastSubject.next({message:`${((s=f.__NOTIFICATION)==null?void 0:s.message)||""}`,kind:`${((c=f.__NOTIFICATION)==null?void 0:c.type)||"info"}`}):E.toastSubject.next({message:"Method executed Successfully",kind:"message"}),f}catch(l){return E.toastSubject.next({message:l.message||`Error executing the method "**${e}**"`,kind:"danger",markdown:!0}),i("can't execute method")}}),vD=re("files/fetchFiles",async()=>E.getFolders(E.FolderRootType.WEBFORMS,E.FolderRootType.METHODS,E.FolderRootType.CLASSES)),Qc=re("tabs/renameDatasource",async(e,{dispatch:r,getState:t})=>{var S,T;const a=!!e.datasourceNamespace,{confirmed:i}=await r(dr({message:"Are you sure you want to rename the datasource?",title:"Rename Datasource",type:qt.CONFIRM,color:Ir.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:s,datasourceId:c,datasourceNamespace:l,value:f,path:p}=e,h=t();let m=[];if(a){const C=h.sharedDatasources.sources[l]||[];m.push(...C)}else if(p){const C=h.root.tabs.find(E.by("path",p));if(m=(T=(S=C==null?void 0:C.content)==null?void 0:S.metadata)==null?void 0:T.datasources,!m)return null}const _=new RegExp(`^${c}\\b`,"");if(m=m.map(C=>{const F=(E.isObjectDatasource(C)||!E.isSimpleDatasource(C))&&C.from&&_.test(C.from),D=C.events?C.events.map(W=>{var $,j,A,K;switch(W==null?void 0:W.type){case"method":{const G=W;return G.params?{...G,params:G.params.map(Y=>{var se;return{...Y,datasource:(se=Y.datasource)==null?void 0:se.replace(new RegExp(`^${c}`,""),f)}}),returns:($=G.returns)!=null&&$.datasource?{...G.returns,datasource:(j=G.returns.datasource)==null?void 0:j.replace(new RegExp(`^${c}`,""),f)}:G.returns}:G}case"simple-action":{const G=W;return G.datasource?{...G,datasource:{...G.datasource,name:(A=G.datasource.name)==null?void 0:A.replace(new RegExp(`^${c}`,""),f),from:(K=G.datasource.from)==null?void 0:K.replace(new RegExp(`^${c}`,""),f)}}:G}default:return W}}):C.events;return C.id===c?{...C,id:f,events:D}:F&&C.from?{...C,from:C.from.replace(new RegExp(`^${c}`,""),f),events:D}:{...C,events:D}}),s){const C=a?`${l}:${c}`:`${c}`,F=a?`${l}:${f}`:`${f}`;E.datasourcesSubject.next({path:p??"",action:E.DatasourcesActions.RENAME,old_reference:C,new_reference:F,is_shared:a})}return{path:p,namespace:l,datasources:m}}),el=re("tabs/edit-datasource",(e,{getState:r})=>{var s,c;const t=r();let a=[];if(e.namespace)a=t.sharedDatasources.sources[e.namespace];else{const l=t.root.tabs.find(E.by("path",e.path));l&&(a=((c=(s=l.content)==null?void 0:s.metadata)==null?void 0:c.datasources)||[])}return a.map(l=>l.id===e.datasourceId?Object.assign({},l,{[e.propertyKey]:e.value}):l)}),iv=re("tabs/fetchChanges",async(e,{getState:r})=>{const a=Ea(r()).filter(i=>[E.FileFolderType.METHOD,E.FileFolderType.CLASS].includes(i.type));return E.getFilesInfo(...a.map(i=>{const[s]=i.path.split("/").filter(Boolean);return{name:i.name,type:i.type,root:s,path:"."}}))}),yD=re("files/saveAll",async(e,{getState:r,dispatch:t})=>{const a=jc(r());for(const i of a)t(da({tab:i}))}),tl=re("files/tryCloseTab",async(e,{getState:r,dispatch:t})=>{const{tabs:a}=r().root,i=a.findIndex(c=>c.path===e);if(i===-1)return!1;const s=a[i];if(s!=null&&s.flags.touched){const{confirmed:c}=await t(dr({title:ki(s),message:"Your unsaved changes will be lost. Proceed anyway?",type:qt.CONFIRM,color:Ir.WARNING,icon:"FdWarningDanger"})).unwrap();if(!c)return!1}return t(sl(i)),s.path===E.ROLES_TAB_PATH&&s.flags.touched&&(async()=>{const l=await E.getNodeInfo({verb:E.DesignerRequestVerb.GET_INFO,path:E.ROLES_TAB_PATH,content:!0,as:"json"});t(Kc({content:l.content,date:l.date}))})(),!0}),mD=re("files/tryCloseOtherTabs",async(e,{getState:r,dispatch:t})=>{const{tabs:a}=r().root;if(a.some(s=>s.path!==e&&s.flags.touched===!0)){const{confirmed:s}=await t(dr({title:"Closing other tabs",message:"Your changes will be lost if you do not save them. Close anyway?",type:qt.CONFIRM,color:Ir.WARNING,icon:"FdWarningDanger"})).unwrap();if(!s)return}t($v(e))}),bD=re("files/tryCloseAllTabs",async(e,{getState:r,dispatch:t})=>{const{tabs:a}=r().root;if(a.some(s=>s.flags.touched===!0)){const{confirmed:s}=await t(dr({title:"Closing all tabs",message:"Your changes will be lost if you do not save them. Close anyway?",type:qt.CONFIRM,color:Ir.WARNING,icon:"FdWarningDanger"})).unwrap();if(!s)return}t(Iv())}),_D=re("files/tryCloseRightTabs",async(e,{getState:r,dispatch:t})=>{const{tabs:a}=r().root;let i=!1;for(let s=a.length-1;s>e;s-=1)if(a[s].flags.touched){i=!0;break}if(i){const{confirmed:s}=await t(dr({title:"Closing right tabs",message:"Your changes will be lost if you do not save them. Close anyway?",type:qt.CONFIRM,color:Ir.WARNING,icon:"FdWarningDanger"})).unwrap();if(!s)return}t(Fv(e))}),ED=re("files/tryCloseLeftTabs",async(e,{getState:r,dispatch:t})=>{const{tabs:a}=r().root;let i=!1;for(let s=0;s<e;s+=1)if(a[s].flags.touched){i=!0;break}if(i){const{confirmed:s}=await t(dr({title:"Closing left tabs",message:"Your changes will be lost if you do not save them. Close anyway?",type:qt.CONFIRM,color:Ir.WARNING,icon:"FdWarningDanger"})).unwrap();if(!s)return}t(Mv(e))}),mc=re("files/reloadTab",async(e,{dispatch:r})=>{if(e.flags.touched){const{confirmed:i}=await r(dr({title:ki(e),message:"Changes made to the file will be lost. Continue?",type:qt.CONFIRM,color:Ir.WARNING,icon:"FdWarningDanger"})).unwrap();if(!i)return}const t=Xh(e.path),a=await E.getNodeInfo({verb:E.DesignerRequestVerb.GET_INFO,path:e.path,content:!0,as:t});if(e.path===E.ROLES_TAB_PATH){const{roles:i,privileges:s}=Zi(a.content);r(Jc({roles:i,privileges:s}))}else if(e.path===E.SETTINGS_TAB_PATH){const{content:i}=a;r(es({path:"project",value:i}))}else{const{content:i}=a;e.type===E.FileFolderType.WEBFORM?E.webformSubject.next({path:e.path,action:E.WebformActions.RELOAD,payload:i.components}):e.type===E.FileFolderType.MODEL&&ag.next({action:"reload",payload:i})}return a}),da=re("files/saveTab",async({tab:e},{dispatch:r,getState:t})=>{const{path:a,content:i}=e;if(e.type===E.FileFolderType.DEBUGGER)return{...e,errors:[]};a.split("/").pop();const c=await E.getFilesInfo({path:a});if(c.files[0]){const h=new Date(e.date),m=new Date(c.files[0].date);if(h.getTime()<m.getTime()){const{confirmed:_}=await r(dr({title:ki(e),message:"New content has been found on the server. Are you sure you want to continue?",type:qt.CONFIRM,icon:"FdSave"})).unwrap();if(!_)return r(Dv({path:a,flags:{old:!0}})),null}}const l=await E.saveContent({verb:E.DesignerRequestVerb.SAVE_CONTENT,content:SD(e,t()),path:a});(e.type===E.FileFolderType.CLASS||e.type===E.FileFolderType.MODEL)&&setTimeout(()=>{r(Wn())},ji);const f=(l.modelErrors||[]).map(h=>h.message),p=(l.permissionsErrors||[]).map(h=>h.message);return{...e,content:i,date:l.date,initialContent:i,errors:f.length>0||p.length>0?[{title:"Model errors",messages:f},{title:"Permissions errors",messages:p}]:[]}}),SD=(e,r)=>{switch(!0){case e.path==="settings.json":case e.path===E.SETTINGS_TAB_PATH:return r.settings.project;case e.type===E.FileFolderType.ROLES:return Qi(r.roles);case e.type===E.FileFolderType.MODEL:return e.content||{toJSON:!0,dataClasses:[],extraProperties:{}};default:return e.content}},Vp=async e=>{if(e.type===E.FileFolderType.DATA_EXPLORER)return{name:"Data Explorer",path:e.path,flags:{},view:{panel:{isOpen:!1,type:"",current:""}},type:e.type,date:new Date().toISOString()};const r=e.path.split("/").filter(Boolean)[0],t=await E.getFile({root:r,type:e.type,verb:E.DesignerRequestVerb.GET,name:e.name}),a={};t.type===E.FileFolderType.METHOD&&(a.attributes=E.parseAttributes(t.content));const{date:i,name:s,type:c,content:l}=t;return{date:i,flags:{enabled:e.type===E.FileFolderType.WEBFORM},extra:a,view:{panel:{isOpen:!1,type:"",current:""}},name:s,path:e.path,type:c,initialContent:l,content:c===E.FileFolderType.MODEL?Oh(l):l}},sv=re("files/tryInjectMethod",async({type:e,dataclass:r},{getState:t,dispatch:a})=>{const{root:{tabs:i},settings:{server:{qodly:s}}}=t(),c=E.getFileExtentionFromType("class",s);let l="",f="",p=null;if(!r)l="DataStore",f=`Classes/DataStore.${c}`;else switch(e){case"dataclass":l=r,f=`Classes/${r}.${c}`;break;case"collection":l=`${r}Selection`,f=`Classes/${r}Selection.${c}`;break;case"entity":l=`${r}Entity`,f=`Classes/${r}Entity.${c}`;break;default:return p}const h=i.find(E.by("path",f));if(h)return a(jt(h)),h;try{p=await Vp({name:l,date:new Date().toISOString(),path:`class/${l}.${c}`,type:E.FileFolderType.CLASS})}catch{r?await a(vc({type:"dataclass",className:r,collectionName:`${r}Selection`,toCreate:e})):await a(vc({type:"model"}))}return p=await Vp({name:l,date:new Date().toISOString(),path:`class/${l}.${c}`,type:E.FileFolderType.CLASS}),p.path=f,a(jt(p)),p}),wD=re("roles/open",async(e,{dispatch:r,getState:t})=>{const{tabs:a}=t().root,i=a.find(s=>s.path===E.ROLES_TAB_PATH);if(i)return r(jt(i)),i;r(Di())});function Kp(e,r){const{line:t,offset:a,type:i="saved"}=r;e.breakpoints[i].locations.push({line:t}),Ke.isNumber(a)&&(e.breakpoints[i].offset=a)}function Jp(e,r,t,a){e.breakpoints[t].locations=r,Ke.isNumber(a)&&(e.breakpoints[t].offset=a)}function Xp({filePath:e,fileType:r,methodName:t,className:a,ext:i,source:s}){return{filePath:e,fileType:r,methodName:t,className:a,ext:i,source:s,breakpoints:{draft:{locations:[],offset:0},saved:{locations:[],offset:0}}}}function Zp(e,r,t){let a=!1;const i=e.map(s=>s[t]!==r[t]?s:(a=!0,{...s,...r}));return a?i:[...i,r]}function ii(e){return e.map(({label:r})=>({label:r}))}const uv=fr({name:"debugger",initialState:()=>{var r,t;const{debugger:e={meta:{state:qr.DETACHED},list:[],sessions:[],expressions:[]}}=ga();return{meta:{...e.meta,state:((r=e.meta)==null?void 0:r.state)===qr.ATTACHED?(t=e.meta)==null?void 0:t.state:qr.DETACHED},list:e.list||[],sessions:e.sessions||[],expressions:e.expressions||[]}},reducers:{addBreakpointDecoration(e,r){const{filePath:t,fileType:a,methodName:i,className:s,ext:c,source:l,breakpoint:f}=r.payload,p=Bn(e.list,t,i,s);if(p)Kp(p,f);else{if(a===E.FileFolderType.CLASS&&f.offset===void 0)throw new Error(`Cannot add a breakpoint on a function without offset. Try editing the ${s} class.`);const h=Xp({filePath:t,fileType:a,methodName:i,className:s,ext:c,source:l});Kp(h,f),e.list.push(h)}},removeBreakpointDecoration(e,r){const{filePath:t,methodName:a,line:i,offset:s=0,type:c="saved"}=r.payload;if(t.startsWith("Classes/")){const l=e.list.filter(f=>f.filePath===t);if(l.length>0){const f=i+s;l.forEach(p=>{const h=p.breakpoints[c].offset||0;p.breakpoints[c].locations=p.breakpoints[c].locations.filter(m=>m.line+h!==f),c==="saved"&&(p.breakpoints.draft.locations=p.breakpoints.draft.locations.filter(m=>m.line+h!==f))})}}else{const l=Bn(e.list,t,a);l&&(l.breakpoints[c].locations=l.breakpoints[c].locations.filter(f=>f.line!==i),c==="saved"&&(l.breakpoints.draft.locations=l.breakpoints.draft.locations.filter(f=>f.line!==i)))}},setBreakpointsDecoration(e,r){const{filePath:t,fileType:a,methodName:i,className:s,ext:c,source:l,breakpoints:f,offset:p,type:h="saved",clearDraft:m}=r.payload,_=Bn(e.list,t,i);if(_)Jp(_,f,h,p),m&&h!=="draft"&&(_.breakpoints.draft.locations=[]);else{const S=Xp({filePath:t,fileType:a,methodName:i,className:s,ext:c,source:l});Jp(S,f,h,p),e.list.push(S)}},clearBreakpoints(e,r){const{filePath:t,type:a="saved"}=r.payload;e.list=e.list.map(i=>({...i,breakpoints:i.filePath===t?{draft:!a||a==="draft"?{locations:[],offset:0}:i.breakpoints.draft,saved:!a||a==="saved"?{locations:[],offset:0}:i.breakpoints.saved}:i.breakpoints}))},setActiveLine(e,r){const{threadId:t,line:a,highlight:i}=r.payload,s=ft(e.sessions,t);s&&(s.activeLine=a,i&&(s.highlightedLines={start:a,end:a}))},addExpression(e,r){const{threadId:t,label:a,save:i}=r.payload,s=ft(e.sessions,t);s&&s.stopped&&(s.expressions=[...s.expressions||[],{label:a}],i&&(e.expressions=ii(s.expressions)))},removeExpression(e,r){const{threadId:t,index:a,save:i}=r.payload,s=ft(e.sessions,t);s&&(s.expressions=s.expressions.filter((c,l)=>l!==a),i&&(e.expressions=ii(s.expressions)))},removeAllExpressions(e,r){const{threadId:t,save:a}=r.payload,i=ft(e.sessions,t);i&&(i.expressions=[],a&&(e.expressions=[]))},renameExpression(e,r){const{threadId:t,index:a,replacement:i,save:s}=r.payload,c=ft(e.sessions,t);c&&c.expressions[a]&&(c.expressions[a].label=i,s&&(e.expressions=ii(c.expressions)))},setExpression(e,r){const{threadId:t,expression:a}=r.payload,i=ft(e.sessions,t);if(i){const s=a.index>=0?a.index:i.expressions.length>0?i.expressions.length-1:0,c=i.expressions[s];c?(c.result=a.result,c.nakedResult=a.nakedResult,c.variablesReference=a.variablesReference||0,c.presentationHint=a.presentationHint):i.expressions.push(a)}},updateExpressionAt(e,r){const{threadId:t,index:a,value:i}=r.payload,s=ft(e.sessions,t);if(s){const c=s.expressions[a];c&&(c.result=`"${i}"`,c.nakedResult=i)}},saveExpressions(e,r){const{expressions:t}=r.payload;e.expressions=ii(t)},addSession(e,r){const{threadId:t,channelId:a,stackFrames:i,exceptions:s=[]}=r.payload,c=ft(e.sessions,t),l=i[0],{expressions:f=[]}=e;if(c)c.expressions=f;else{const p=Fc(t);e.sessions.push({tabPath:p,threadId:t,channelId:a,stackFrames:i,currentStackFrame:l,exceptions:s,expressions:f,variables:{callchain:[],expressions:[]},highlightedLines:null,activeLine:null,stopped:!0})}},updateSession(e,r){const{threadId:t,changes:a}=r.payload;e.sessions=e.sessions.map(i=>i.threadId===t?{...i,...a}:i)},removeSession(e,r){const{threadId:t}=r.payload;e.sessions=e.sessions.filter(a=>a.threadId!==t)},removeSessionByIndex(e,r){const t=r.payload;e.sessions.splice(t,1)},setSessions(e,r){const t=r.payload;e.sessions=t},setCallChainVariables(e,r){const{threadId:t,frameId:a,variables:i}=r.payload;e.sessions=e.sessions.map(s=>{var c;return s.threadId===t?{...s,variables:{...s.variables,callchain:Zp((c=s.variables)==null?void 0:c.callchain,{frameId:a,items:i},"frameId")}}:s})},setExpressionVariables(e,r){const{threadId:t,variablesReference:a,variables:i}=r.payload;e.sessions=e.sessions.map(s=>{var c;return s.threadId===t?{...s,variables:{...s.variables,expressions:Zp((c=s.variables)==null?void 0:c.expressions,{variablesReference:a,items:i},"variablesReference")}}:s})},setSourceContent(e,r){const{threadId:t,content:a}=r.payload,i=ft(e.sessions,t);i&&(i.currentStackFrame.source={...i.currentStackFrame.source,content:a})},setDebuggerMeta(e,r){if(r.payload.state===qr.ERROR){e.meta.error={...e.meta.error,time:Date.now()};const{override:t,error:a={code:null,reason:"",type:Ei.SOCKET_ERROR}}=r.payload;if((t||e.meta.state!==qr.ERROR)&&(e.meta.error={...e.meta.error,...a}),(a==null?void 0:a.type)===Ei.SOCKET_CLOSURE&&!(a!=null&&a.reason)&&e.meta.state===qr.DETACHED)return}e.meta.state=r.payload.state}},extraReducers:e=>{e.addCase(lv.fulfilled,r=>{r.sessions=[]})}}),{addBreakpointDecoration:TD,removeBreakpointDecoration:xD,setBreakpointsDecoration:CD,clearBreakpoints:RD,setActiveLine:OD,addExpression:AD,renameExpression:PD,removeExpression:DD,removeAllExpressions:ID,setExpression:FD,updateExpressionAt:$D,saveExpressions:MD,addSession:ND,updateSession:LD,removeSession:jD,removeSessionByIndex:kD,setSessions:cv,setCallChainVariables:BD,setExpressionVariables:WD,setSourceContent:UD,setDebuggerMeta:HD}=uv.actions,lv=re("files/wipeDebuggerSessions",async(e,{getState:r,dispatch:t})=>{const{sessions:a}=r().debugger;for(const{threadId:i}of a){const s=Fc(i);t(tl(s))}}),fv=re("files/removeDebuggerSessionsNotIn",async(e,{getState:r,dispatch:t})=>{const{threadIds:a}=e,{sessions:i}=r().debugger,s=[],c=i.filter(l=>{const f=a.includes(l.threadId);return f||s.push(l.threadId),f});return t(cv(c)),{staleThreadIds:s}});var rl=(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))(rl||{}),zr=(e=>(e.STORAGE="storage",e.RELATEDENTITY="relatedEntity",e.RELATEDENTITIES="relatedEntities",e.CALCULATED="calculated",e.COMPOSITION="composition",e.ALIAS="alias",e))(zr||{});const GD=e=>["string","uuid","number","long"].includes(e.type),qD=[{label:"Storage",value:"storage"},{label:"Calculated",value:"calculated"}],YD=[{title:"UUID",kind:"storage",value:"uuid",calculatedType:"uuid",calculatedKind:"storage"},{title:"Long",kind:"storage",value:"long",calculatedType:"long",calculatedKind:"storage"}],zD=[{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"}],VD=[{label:"Expose as REST",value:"public"},{label:"Do not expose as REST",value:"publicOnServer"}],KD=[{label:"Expose as REST",value:"public"},{label:"Do not expose as REST",value:"publicOnServer"}],JD=[{label:"None",value:"none"},{label:"B-tree",value:"btree"},{label:"Cluster",value:"cluster"},{label:"Automatic",value:"auto"}],dv=Lt("model/add-dataclass"),pv=Lt("model/rename-dataclass"),hv=Lt("model/remove-dataclass"),gv=Lt("model/add-attribute"),XD=Lt("model/edit-attribute-property"),vv=Lt("model/remove-attribute"),yv=Lt("model/rename-attribute"),mv=Lt("model/edit-primary-key"),ZD=Lt("model/edit-dataclass-property"),bv=Lt("model/rename-collection"),QD=(e,r)=>({toJSON:!0,extraProperties:r,dataClasses:e.map(t=>{var a;return{...t.data,extraProperties:{position:{x:t.position.x,y:t.position.y},panelColor:(a=t.data.extraProperties)==null?void 0:a.panelColor}}})});function di(e,r,t){const a=e;let i=0;for(;t[`${a}${i||""}`];)i++;return`${a}${i||""}`}const Qa=e=>e.kind===zr.RELATEDENTITY,Ii=e=>e.kind===zr.RELATEDENTITIES,eI=e=>Ii(e)||Qa(e),nl=re("models/fetch",async()=>{try{return(await E.http(E.API_PREFIX,{method:"POST",body:JSON.stringify({verb:E.DesignerRequestVerb.GET_INFO,path:E.MODEL_TAB_PATH,as:"json",content:!0}),headers:new Headers({"Content-Type":"application/json"})})).content}catch(e){return e.message}}),Fi=re("models/save",async(e,{getState:r,dispatch:t,rejectWithValue:a})=>{const{tabs:i}=r().root,s=i.find(c=>c.path===E.MODEL_TAB_PATH);if(!s)return a("Error while saving the model");try{const c=await E.http(E.API_PREFIX,{method:"POST",body:JSON.stringify({verb:"save",path:s.path,content:s.content}),headers:new Headers({"Content-Type":"application/json"})});return setTimeout(()=>{t(Wn())},ji),{...c,path:s.path,content:e.content||{toJSON:!0,dataClasses:[],extraProperties:{}}}}catch{return a("Error while saving the model")}}),tI=re("models/open",async(e,{dispatch:r,getState:t})=>{const{tabs:a}=t().root,i=a.find(s=>s.path==="models/main");if(i)return r(jt(i)),i;r(nl())}),rI=re("model/rename-dataclass",async(e,{getState:r,dispatch:t})=>{var m,_;const{dataclassId:a,selectionId:i,name:s}=e;let c=r();const l=c.explorer.find(S=>S.path===E.FolderRootPath.CLASSES);if(!l)throw new Error("Classes folder was not found!");await t(Pr(l.path)),c=r();const f={class:{found:!1,newNameTaken:!1,file:null,filename_update:s},entity:{found:!1,newNameTaken:!1,file:null,filename_update:`${s}Entity`},selection:{found:!1,newNameTaken:!1,file:null,filename_update:`${s}Selection`}};(_=(m=c.explorer.find(S=>S.path===E.FolderRootPath.CLASSES))==null?void 0:m.children)==null||_.forEach(S=>{S.name===f.class.filename_update&&(f.class.newNameTaken=!0),S.name===f.entity.filename_update&&(f.entity.newNameTaken=!0),S.name===f.selection.filename_update&&(f.selection.newNameTaken=!0),S.name===a?(f.class.found=!0,f.class.file=S):S.name===`${a}Entity`?(f.entity.found=!0,f.entity.file=S):S.name===i&&(f.selection.found=!0,f.selection.file=S)});const p=Object.entries(f).reduce((S,T)=>{const[C,F]=T;return F.found?F.newNameTaken?[...S,{type:"error",message:`Cannot rename ${C} file to ${F.filename_update} because it already exists. The existing file will be used instead!`}]:S:[...S,{type:"warning",message:`${a} ${C} file was not found`}]},[]);p.length>0&&t(dr({message:"The following errors were encountered during dataclass rename:",views:{tips:p}}));const h=Object.values(f).filter(S=>S.found&&S.file&&!S.newNameTaken);await Promise.all(h.map(async S=>await t(fa({file:S.file,newname:S.filename_update})))),h.length>0&&t(Pr("Classes"))}),oo={DATACLASS_DELETE:"dataclass.delete",DATACLASS_DRAGGABLE:"dataclass.draggable"},nI={model:{dataClasses:{},collections:{},extraProperties:{}},draft:{dataClasses:{},collections:{},extraProperties:{}},flags:{[oo.DATACLASS_DELETE]:!0,[oo.DATACLASS_DRAGGABLE]:!0}},_v=fr({name:"Models",initialState:nI,reducers:{setModelFlag(e,r){e.flags={...e.flags,...r.payload}}},extraReducers(e){e.addCase(dv,({draft:{dataClasses:r}},t)=>{var c,l;const{dataclassID:a}=t.payload,i=di(a||"DataClass","className",r),s={className:i,collectionName:`${i}Selection`,attributes:[{name:"ID",kind:zr.STORAGE,type:rl.LONG,scope:"public",indexKind:"auto",unique:!0,primKey:!0,autosequence:!0}],name:i,scope:"public",extraProperties:{position:{x:((c=t.payload.position)==null?void 0:c.x)||0,y:((l=t.payload.position)==null?void 0:l.y)||0}}};r[s.name]=s}).addCase(hv,({draft:{dataClasses:r}},t)=>{const{dataclassID:a}=t.payload;r[a]&&(delete r[a],Object.values(r).forEach(s=>{s.attributes=s.attributes.filter(c=>c.type!==a&&c.type!==s.collectionName)}))}).addCase(pv,({draft:{dataClasses:r,collections:t}},a)=>{const{dataclassID:i,newName:s}=a.payload;if(!r[i]||r[s])return;const c=r[i].collectionName,l=di(`${s}Selection`,"collectionName",t);Object.values(r).forEach(f=>{f.className===i&&(f.className=s,f.name=s,f.collectionName=l),f.attributes.forEach(p=>{p.type===i?(p.type=s,p.path=s):p.type===c&&(p.type=l)})})}).addCase(gv,({draft:{dataClasses:r}},t)=>{const{dataclassID:a,attributeName:i,attributeType:s,attributeKind:c,target:l}=t.payload;if(!r[a]||E.exists("name",i,r[a].attributes))return;const p={name:i,kind:c,type:s,exposed:!0,scope:"public"};if(c===zr.RELATEDENTITY){if(!r[s])return;p.path=s;const m={name:di(r[s].collectionName,"name",r[s].attributes),type:r[a].collectionName,kind:zr.RELATEDENTITIES,reversePath:!0,path:i,scope:"public",exposed:!0};r[s].attributes.push(m)}else if(c===zr.RELATEDENTITIES){const h=r[s];if(!h)return;const m=h.attributes.find(E.by("name",l));if(m){if(!Qa(m)||m.type!==r[a].className)return}else{p.path=l,p.reversePath=!0,p.type=s;const _={name:l,kind:zr.RELATEDENTITY,scope:"public",path:h.className,type:h.className,exposed:!0};h.attributes.push(_)}}r[a].attributes.push(p)}).addCase(yv,({draft:{dataClasses:r}},t)=>{const{dataclassID:a,attributeID:i,newName:s}=t.payload,c=r[a].attributes.find(E.by("name",i)),l=r[a].attributes.find(E.by("name",s));!c||l||Object.values(r).forEach(({collectionName:f,attributes:p,className:h})=>{p.forEach(m=>{Qa(c)&&Ii(m)&&m.type===f&&m.path===i&&(m.path=s),h===a&&m.name===i&&(m.name=s)})})}).addCase(vv,({draft:{dataClasses:r}},t)=>{const{dataclassID:a,attributeID:i}=t.payload;if(!r[a])return;const s=r[a].attributes.find(E.by("name",i));s&&(Qa(s)&&Object.values(r).forEach(c=>{c.attributes=c.attributes.filter(l=>!(Ii(l)&&l.type===c.collectionName&&l.path===s.name))}),r[a].attributes=r[a].attributes.filter(E.outBy("name",i)))}).addCase(bv,({draft:{dataClasses:r,collections:t}},a)=>{const{dataclassID:i,collectionName:s}=a.payload;if(!r[i])return;const c=r[i].collectionName;t[s]||(r[i].collectionName=s,t[s]=r[i],delete t[c],Object.values(r).forEach(l=>l.attributes.forEach(f=>{f.type===c&&(f.type=s)})))}).addCase(mv,({draft:{dataClasses:r}},t)=>{const{dataclassID:a,newPrimKey:i}=t.payload;r[a]&&r[a].attributes.forEach(s=>{s.name===i?s.primKey=!0:s.primKey=!1})}),e.addCase(nl.fulfilled,(r,t)=>{var c;const a={},i={},s=t.payload.extraProperties||{};(c=t.payload.dataClasses)==null||c.forEach(l=>{a[l.name]=l,i[l.collectionName]=l}),r.draft.dataClasses=a,r.draft.collections=i,r.draft.extraProperties=s,r.model.dataClasses=a,r.model.collections=i,r.model.extraProperties=s}),e.addCase(Fi.pending,()=>{}).addCase(Fi.fulfilled,(r,t)=>{const a={},i={},s=t.payload.content.extraProperties||{};t.payload.content.dataClasses.forEach(c=>{a[c.name]=c,i[c.collectionName]=c}),r.draft.dataClasses=a,r.draft.collections=i,r.draft.extraProperties=s,r.model.dataClasses=a,r.model.collections=i,r.model.extraProperties=s})}}),{setModelFlag:aI}=_v.actions,oI=()=>Zr(e=>e.model.draft.dataClasses),iI=()=>Zr(e=>e.model.draft.collections),sI=e=>Zr(r=>r.model.draft.dataClasses[e]),uI=(e,r)=>Zr(t=>t.model.draft.dataClasses[e].attributes.find(E.by("name",r))),cI=()=>Zr(e=>e.model.draft.extraProperties),lI=()=>{const e=Zr(i=>i.model.flags),r=i=>i in e?e[i]:void 0,t=r(oo.DATACLASS_DELETE),a=r(oo.DATACLASS_DRAGGABLE);return{deleteDataclass:t,draggableDataclass:a,flags:e}},fI=_v.reducer;function Hu(e,r){const t=e.tabs.find(({path:a})=>a===E.SETTINGS_TAB_PATH);t&&(t.flags.touched=r)}const Ev={SIDEBAR_SECTION_RESIZABLE:"sidebar.section.resizable"},Sv={[Ev.SIDEBAR_SECTION_RESIZABLE]:!0},wv=fr({name:"webforms",initialState:()=>{const{webforms:e}=ga();return{...e,templates:{data:[],selectedGroup:""},datasources:{...Dc.webforms.datasources,...e==null?void 0:e.datasources},flags:Sv}},reducers:{toggleInspector:(e,r)=>{const{type:t}=r.payload;e.inspector[t].active=!e.inspector[t].active,e.inspector[t].active||(e.inspector[t].data=void 0)},inspect:(e,r)=>{const{type:t,data:a}=r.payload;e.inspector[t].active&&(e.inspector[t].data=a)},addComponent:(e,r)=>{e.components.push(r.payload)},editComponent:(e,r)=>{const{id:t,changes:a}=r.payload;e.components=e.components.map(i=>i.id===t?{...i,...a}:i)},removeComponent:(e,r)=>{const{payload:t}=r,a=e.components.findIndex(i=>i.id===t);a!==-1&&e.components.splice(a,1)},setSelectedGroup:(e,r)=>{e.templates.selectedGroup=r.payload.selectedGroup},setTemplatesData:(e,r)=>{e.templates.data=r.payload},setTemplateData:(e,r)=>{const{group:t,components:a}=r.payload,i=e.templates.data.find(s=>s.group===t);i&&(i.components=a)},setDatasourcesTheme:(e,r)=>{e.datasources.theme=r.payload},setWebformsFlag(e,r){e.flags={...e.flags,...r.payload}}},extraReducers(e){e.addCase(Av.fulfilled,(r,t)=>{r.components=t.payload})}}),{toggleInspector:dI,inspect:pI,addComponent:Tv,editComponent:xv,removeComponent:Cv,setSelectedGroup:hI,setTemplatesData:Rv,setTemplateData:Ov,setDatasourcesTheme:gI,setWebformsFlag:vI}=wv.actions,yI=wv.reducer,al=Ke.curry((e,r)=>{var i,s;const t={...r.sharedDatasources.sources},a=(s=((i=r.root.tabs.find(E.by("path",e)))==null?void 0:i.content).metadata)==null?void 0:s.datasources;return a&&(t[e]=a),Ke.cloneDeep(t)}),mI=re("webforms/fetchTemplates",async(e,{dispatch:r,getState:t})=>{const{data:a}=t().webforms.templates,i=t().settings.session["studio.tipsBaseUrl"]||"";if(!Ke.isEmpty(a))return a;try{const c=await(await fetch(`${i}/build/index.json?t=${Date.now()}`)).json();return r(Rv(c)),c}catch{return[]}}),bI=re("webforms/fetchTemplate",async({name:e},{dispatch:r,getState:t})=>{const{data:a}=t().webforms.templates,i=a.find(s=>s.group===e);if(i&&!Ke.isEmpty(i.components))return i.components;try{const c=await(await fetch(`${i==null?void 0:i.link}?t=${Date.now()}`)).json();return r(Ov({group:e,components:c})),c}catch{return[]}}),Av=re("webforms/fetchCraftedComponents",async(e,{rejectWithValue:r})=>{try{return(await E.getNodeInfo({path:"WebForms/crafted_components.json",verb:E.DesignerRequestVerb.GET_INFO,content:!0,as:"json"})).content}catch{return r("Error while loading the crafted components")}}),_I=re("webforms/addCraftedComponent",async(e,{dispatch:r,rejectWithValue:t,getState:a})=>{try{r(Tv(e));const{webforms:{components:i}}=a();E.setCraftedComponents(i)}catch{return t("Error while adding the crafted component")}}),EI=re("webforms/editCraftedComponent",async(e,{dispatch:r,rejectWithValue:t,getState:a})=>{try{r(xv(e));const{webforms:{components:i}}=a();E.setCraftedComponents(i)}catch{return t("Error while editing the crafted component")}}),SI=re("webforms/removeCraftedComponent",async(e,{dispatch:r,rejectWithValue:t,getState:a})=>{try{r(Cv(e));const{webforms:{components:i}}=a();E.setCraftedComponents(i)}catch{return t("Error while removing the crafted component")}}),ol=re("datasources/add-datasource",async(e,{getState:r,rejectWithValue:t})=>{var a,i;try{const s=r(),c=e.datasource,l=!!c.namespace,f=[];if(l){const p={...s.sharedDatasources.sources,[c.namespace]:[...s.sharedDatasources.sources[c.namespace],c]};f.push(...p[c.namespace]),await E.setSharedSources(p)}else(((i=(a=s.root.tabs.find(E.by("path",e.path)).content)==null?void 0:a.metadata)==null?void 0:i.datasources)||[]).push(c);return{list:f,path:e.path,namespace:e.datasource.namespace}}catch{console.error("Error while adding the datasource",e.datasource.id),t("Error while adding the datasource")}}),il=re("datasources/edit-datasource",async(e,{getState:r,rejectWithValue:t})=>{try{const{namespace:a,path:i}=e,s=r(),c=!!e.namespace,l=al(i,s);let f=Ke.defaultTo(l[a||i],[]);return f=f.map(p=>p.id===e.id?{...p,[e.property]:e.value}:p),c&&await E.setSharedSources({...s.sharedDatasources.sources,[e.namespace]:f}),{list:f,path:e.path,namespace:e.namespace}}catch{t(`Error while editing datasource ${e.id}`)}}),wI=e=>e.type===pa.fulfilled.type,pa=re("datasources/rename-datasource",async(e,{getState:r,rejectWithValue:t})=>{try{const a=r(),i=!!e.namespace,s=e.namespace||e.path,c=al(e.path,a),l=Ke.defaultTo(c[s],[]),f=new RegExp(`^${e.id}\\b`,"");if(l.forEach(p=>{var m;const h=(E.isObjectDatasource(p)||!E.isSimpleDatasource(p))&&p.from&&f.test(p.from);e.updateRefs&&((m=p.events)==null||m.forEach(_=>{var S,T,C,F,D;switch(_.type){case"method":{const W=_;W.params.forEach($=>{$.datasource&&Object.assign($,{datasource:$.datasource.replace(new RegExp(`^${e.id}`,""),e.new_name)})}),W.returns&&Object.assign(W.returns,{datasource:(T=(S=W.returns)==null?void 0:S.datasource)==null?void 0:T.replace(new RegExp(`^${e.id}`,""),e.new_name)});return}case"simple-action":{const W=_;W.datasource&&Object.assign(W.datasource,{name:(C=W.datasource.name)==null?void 0:C.replace(new RegExp(`^${e.id}`,""),e.new_name),from:(F=W.datasource.from)==null?void 0:F.replace(new RegExp(`^${e.id}`,""),e.new_name),target:(D=W.datasource.target)==null?void 0:D.replace(new RegExp(`^${e.id}`,""),e.new_name)});return}default:return}})),p.id===e.id?p.id=e.new_name:h&&p.from&&(p.from=p.from.replace(new RegExp(`^${e.id}`,""),e.new_name))}),e.updateRefs){const p=E.getDatasourceId({id:e.id,namespace:e.namespace}),h=E.getDatasourceId({id:e.new_name,namespace:e.namespace});E.datasourcesSubject.next({path:e.path??"",action:E.DatasourcesActions.RENAME,old_reference:p,new_reference:h,is_shared:i})}return i&&await E.setSharedSources({...a.sharedDatasources.sources,[e.namespace]:l}),{list:l,path:e.path,namespace:e.namespace}}catch{return t(`Error while renaming datasource ${e.namespace}:${e.id}`)}}),eo=re("datasources/delete-datasource",async(e,{getState:r,rejectWithValue:t})=>{try{const a=r(),i=!!e.namespace,s=e.namespace||e.path,l=al(e.path,a)[s].filter(E.outById(e.id));return i&&await E.setSharedSources({...a.sharedDatasources.sources,[e.namespace]:l}),{list:l,path:e.path,namespace:e.namespace}}catch{return t(`Error while removing datasource ${e.id}`)}}),io=fr({name:"root",initialState:()=>{const e=ga();return{filesLoading:!1,tabs:e.tabs||[],activeTab:e.activeTab,recent:e.recent||[]}},reducers:{setPanelState(e,r){const{path:t,...a}=r.payload;e.tabs.forEach(i=>{i.path===t&&(i.view||(i.view={panel:{isOpen:!1,type:"",current:""}}),Object.assign(i.view.panel,a))})},addDataSource(e,r){var s;const{payload:{path:t,datasourceDef:a}}=r,i=e.tabs.find(c=>c.path===t);i&&(i.content.metadata.datasources=i.content.metadata.datasources||[],(s=i.content.metadata.datasources)!=null&&s.find(l=>l.id===a.id)||(i.content.metadata.datasources=[...i.content.metadata.datasources,{...a,events:[]}],i.flags={...i.flags,touched:!0,confirmed:!0}))},openSettingsTab(e){const r={date:new Date().toISOString(),flags:{confirmed:!0},view:{panel:{isOpen:!1,type:"",current:""}},extra:{editor:{key:"editors:settings"}},name:"Settings",path:E.SETTINGS_TAB_PATH,type:E.FileFolderType.SETTINGS,initialContent:{},content:{}};let t=e.tabs.find(a=>a.path===r.path);if(t||(e.tabs.push(r),t=e.tabs[e.tabs.length-1]),e.activeTab!==r.path){const a=e.tabs.reduce((i,s)=>(s==null?void 0:s.weight)>((i==null?void 0:i.weight)||0)?s:i,null);e.activeTab=r.path,t.weight=((a==null?void 0:a.weight)||0)+1}},removeDataSource(e,r){const{path:t,datasourceID:a}=r.payload;e.tabs=e.tabs.map(i=>i.path===t?{...i,flags:{...i.flags,touched:!0,confirmed:!0},content:{...i.content,metadata:{...i.content.metadata,datasources:i.content.metadata.datasources.filter(s=>s.id!==a)}}}:i)},setDataSources(e,r){const{payload:{path:t,datasourceArr:a}}=r;e.tabs=e.tabs.map(i=>{var s;return i.path===t?{...i,flags:{...i.flags,touched:!0,confirmed:!0},content:{...i.content,metadata:{...(s=i.content)==null?void 0:s.metadata,datasources:a}}}:i})},setTabs(e,r){e.tabs=r.payload},closeTab(e,r){const t=r.payload;e.tabs.splice(t,1);const a=e.tabs.reduce((i,s)=>(s==null?void 0:s.weight)>((i==null?void 0:i.weight)||0)?s:i,null);e.activeTab=(a==null?void 0:a.path)||""},closeOthers(e,r){e.tabs=e.tabs.filter(t=>t.path===r.payload),e.activeTab=r.payload},closeAllTabs(e){e.tabs=[],e.activeTab=""},closeRightTabs(e,r){e.tabs.splice(r.payload+1),e.activeTab=e.tabs[r.payload].path},closeLeftTabs(e,r){e.tabs.splice(0,r.payload)},closeSavedTabs(e){e.tabs=e.tabs.filter(({flags:{touched:t}})=>t);const r=e.tabs.reduce((t,a)=>(a==null?void 0:a.weight)>((t==null?void 0:t.weight)||0)?a:t,null);e.activeTab=(r==null?void 0:r.path)||""},confirmTab(e,r){const t=e.tabs.find(({path:a})=>a===r.payload);t&&(t.flags.confirmed||io.caseReducers.setTabFlags(e,{type:r.type,payload:{path:r.payload,flags:{confirmed:!0}}}))},selectTab(e,r){const t=e.tabs.find(({path:i})=>i===r.payload);if(!t||e.activeTab===r.payload)return;const a=e.tabs.reduce((i,s)=>(s==null?void 0:s.weight)>((i==null?void 0:i.weight)||0)?s:i,null);t.weight=a?(a.weight||0)+1:1,e.activeTab=r.payload},openTabUnselected(e,r){const t=r.payload;let a=e.tabs.find(({path:s})=>t.path===s);a||(e.tabs.push(t),a=e.tabs[e.tabs.length-1]);const i=e.tabs.reduce((s,c)=>(c==null?void 0:c.weight)>((s==null?void 0:s.weight)||0)?c:s,null);a.weight=i?(i.weight||0)+1:1,a.extra={...a.extra,...t.extra}},selectTabByReference(e,r){const t=[E.FileFolderType.SETTINGS,E.FileFolderType.DEBUGGER],a=r.payload;let i=e.tabs.find(({path:s})=>a.path===s);if((t.includes(a.type)||i!=null&&i.flags.confirmed)&&(a.flags={...a.flags,confirmed:!0}),!i){const s=e.tabs.findIndex(({flags:{confirmed:c}})=>c===!1);s!==-1&&!t.includes(a.type)?e.activeTab===e.tabs[s].path?(e.tabs[s]=a,i=e.tabs[s]):(e.tabs.push(a),i=e.tabs[e.tabs.length-1],e.tabs.splice(s,1)):(e.tabs.push(a),i=e.tabs[e.tabs.length-1])}if(e.activeTab!==a.path){const s=e.tabs.reduce((c,l)=>(l==null?void 0:l.weight)>((c==null?void 0:c.weight)||0)?l:c,null);e.activeTab=a.path,i.weight=((s==null?void 0:s.weight)||0)+1}i.extra={...i.extra,...a.extra},i.flags={...i.flags||{},...a.flags||{}}},setContent(e,r){const{path:t,content:a,contentPath:i}=r.payload;e.tabs=e.tabs.map(s=>{if(s.path!==t)return s;let c=!1,l=s.flags.confirmed;if(typeof a=="string")c=s.initialContent!==a,l=!l&&c?!0:l;else{const f=JSON.stringify(Ke.get(s.initialContent,i||"",s.initialContent)),p=JSON.stringify(Ke.get(a,i||"",a));c=f!==p,l=!l&&c?!0:l}return a&&typeof a=="object"&&(i?Ke.set(s.content,i,a):s.content=a),typeof a=="string"&&(s.content=a),{...s,flags:{...s.flags,touched:c,confirmed:l}}})},setTabFlags(e,r){const{path:t,flags:a}=r.payload;e.tabs=e.tabs.map(i=>i.path===t?{...i,flags:{...i.flags,...a}}:i)},setTabsFlags(e,r){const{tabs:t,flags:a}=r.payload;e.tabs=e.tabs.map(i=>t.includes(i.path)?{...i,flags:{...i.flags,...a}}:i)},setTabExtra(e,r){const{path:t,extra:a,flags:i}=r.payload;e.tabs=e.tabs.map(s=>s.path===t?{...s,extra:{...s.extra,...a},flags:i?{...s.flags,...i}:s.flags}:s)},addWebFormStyles(e,r){const{path:t,styles:a=[]}=r.payload,i=e.tabs.find(s=>s.path===t);if(i){const s=i.content.metadata.styles.map(({name:l})=>l),c=a.filter(({name:l})=>!s.includes(l));i.content.metadata.styles=[...i.content.metadata.styles,...c].map(({scope:l,...f})=>({...f}))}},changeTabEditor(e,r){return e.tabs=e.tabs.map(t=>t.path===r.payload.path?r.payload:t),e}},extraReducers:e=>{e.addCase(pc,(r,t)=>{if(t.payload.settingsKey==="studio.enablePreview"&&t.payload.value===!1){const a=r.tabs.find(({flags:{confirmed:i}})=>i===!1);a&&io.caseReducers.setTabFlags(r,{type:"",payload:{path:a.path,flags:{confirmed:!0}}})}}),e.addCase(av.fulfilled,(r,t)=>{if(!t.payload)return;const{content:a,line:i,path:s}=t.payload,c=r.tabs.find(l=>l.path===s);if(c&&typeof c.content=="string"){const l=c.content.trim().split(`
127
+ `}}};e.type==="dataclass"&&!e.toCreate?p=[{...h("dataclass")},{...h("collection")},{...h("entity")}]:e.type==="dataclass"&&e.toCreate?p=[{...h(e.toCreate)}]:p=[{...h("model")}],p=p.filter(_=>!f.find(({name:S,ext:T})=>S===_.name&&T===(s?"4qs":"4dm"))),await Promise.all(p.map(async({name:_,content:S})=>{await r(la({type:E.FileFolderType.CLASS,path:i,fileName:_,parentNode:c,content:S,qodly:a.settings.server.qodly}))})),await r(Pr(i))}),Pr=re("explorer/fetchFolderContent",async(e,{rejectWithValue:r})=>{try{return(await E.getNodeInfo({verb:E.DesignerRequestVerb.GET_INFO,path:e})).map(a=>{const i=`${e}/${a.name}`,{editor:s,supportedEditors:c}=Sr(`${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:s,supportedEditors:c}}})}catch{return r("Failed loading file content please Reload")}},{getPendingMeta:()=>{}}),Ja=re("explorer/fetchFolderContentWithoutExpanding",async(e,{rejectWithValue:r})=>{try{return(await E.getNodeInfo({verb:E.DesignerRequestVerb.GET_INFO,path:e})).map(a=>{const i=`${e}/${a.name}`,{editor:s,supportedEditors:c}=Sr(`${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:s,supportedEditors:c}}})}catch{return r("Failed loading file content please Reload")}},{getPendingMeta:()=>{}});function cD(e){const r=e.split(".");return r.pop(),{name:r.join("."),ext:e.split(".")[e.split(".").length-1]}}const lD=re("explorer/uploadFile",async e=>{const r=e.type.includes("image/")?"$rawPict=true":"$binary=true";try{const t=await fetch(`/rest/$upload?${r}`,{method:"POST",headers:{"Content-Type":e.type},body:e});return{status:t.status,data:await t.json()}}catch{return{status:500,data:null}}}),fD=re("explorer/uploadFile",async({file:e,path:r,parentNode:t},{dispatch:a})=>{const{editor:i,supportedEditors:s}=Sr(r),{name:c,ext:l}=cD(e.name);a(Qg({parent:t,child:{name:c,path:`${r}/${e.name}?t=${Date.now()}`,type:e.type,error:null,flags:{loading:!0},config:{editor:i,supportedEditors:s},ext:l}}));try{const f=await fetch(`/rest/$upload?$sharedFolder=true&$filename=${e.name}&$path=${r}`,{method:"POST",headers:{"Content-Type":e.type},body:e});return f.status>=300?(a(gc({parent:t,child:{name:c,path:`${r}/${e.name}`,type:e.type,error:{message:"error uploading file"},flags:{},config:{editor:i,supportedEditors:s},ext:l}})),f.status!==413&&E.toastSubject.next({message:"error uploading file",kind:"danger"})):await a(Pr(t.path)),{status:f.status,fileName:e.name}}catch{return a(gc({parent:t,child:{name:c,path:`${r}/${e.name}`,type:e.type,error:{message:"error uploading file"},flags:{},config:{editor:i,supportedEditors:s},ext:l}})),E.toastSubject.next({message:"error uploading file",kind:"danger"}),{status:500,fileName:e.name}}}),la=re("explorer/createNewFile",async({fileName:e,type:r,path:t,parentNode:a,content:i},{dispatch:s,rejectWithValue:c,getState:l})=>{const{server:{qodly:f},project:p}=l().settings;try{const h=await E.setFileContent({name:tv(e,r,f),content:i||ev(r,p),path:t,asText:[E.FileFolderType.CLASS,E.FileFolderType.METHOD].includes(r)});return a.error&&(a.flags.expanded?await s(Pr(a.path)):await s(Ja(a.path))),{qodly:f,file:h,parentNode:a}}catch{return c("failed to create folder")}});function nv(e,r){const{qodly:t=!0,withExtension:a=!0}=r||{},i=E.getFileExtentionFromType(e.type,t);let s="";switch(e.type){case E.FileFolderType.WEBFORM:s=`${E.FolderRootPath.WEBFORMS}/${e.name}`;break;case E.FileFolderType.METHOD:s=`${E.FolderRootPath.METHODS}/${e.name}`;break;case E.FileFolderType.CLASS:s=`${E.FolderRootPath.CLASSES}/${e.name}`;break;default:return""}return`${s}${a?`.${i}`:""}`}const dD=re("explorer/createNewFileAndOpen",async(e,{dispatch:r,getState:t})=>{const a=await r(la(e)).unwrap(),{qodly:i}=t().settings.server;if(a){const{file:s}=a,c=nv(s,{withExtension:!1,qodly:i}),{editor:l}=Sr(c);await r(Xa({file:{name:e.fileName,type:s.type,path:c,editor:l,date:new Date().toISOString()}}))}}),li=re("explorer/createNewNode",async({fileName:e,path:r,parentNode:t},{rejectWithValue:a})=>{try{return{file:await E.createFolder({verb:E.DesignerRequestVerb.CREATE_FOLDER,path:`${r}/${e}`,recursive:!0}),parentNode:t}}catch{return E.toastSubject.next({message:"failed to create folder",kind:"danger"}),a("failed to create folder")}}),ts=async(e,r=!0)=>{try{const t=e.path.split(".").at(-1),a=await E.getNodeInfo({verb:E.DesignerRequestVerb.GET_INFO,path:e.path,content:!0,as:Ah(t)?"json":"text"}),i={editor:e.editor},s=E.getTypeFromExtension(e.path);s===E.FileFolderType.METHOD&&(i.attributes=E.parseAttributes(a.content),a.content=E.addAttributesToContent(a.content,{}));const{content:c,date:l,ext:f}=a;return{date:l,view:{panel:{isOpen:!1,type:"",current:""}},flags:{enabled:["WebForm","MForm"].includes(f),confirmed:r},extra:i,name:e.name,path:e.path,type:s,initialContent:c,content:c}}catch(t){const{data:a}=t;if(a.__ERROR.find(i=>i.errCode===E.ERROR_CODES.FILE_NOT_FOUND))switch(e.path){case E.ROLES_TAB_PATH:{const i={permissions:{allowed:[]},privileges:[],roles:[]};return{date:new Date().toISOString(),flags:{},extra:{editor:{key:"editors:roles"}},name:"Roles & Privileges",path:e.path,type:E.FileFolderType.ROLES,initialContent:i,content:i}}case E.SETTINGS_TAB_PATH:{const i={};return{date:new Date().toISOString(),flags:{},extra:{editor:{key:"editors:settings"}},name:"Settings",path:e.path,type:E.FileFolderType.SETTINGS,initialContent:i,content:i}}}throw t}},Xa=re("explorer/openFile",async({file:e,inactive:r,flags:t={}},{getState:a,dispatch:i})=>{const{root:{tabs:s},roles:c,debugger:{sessions:l}}=a(),f=s.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,...t}};return i(jt(m)),m}if(e.path.startsWith("Debugger")){const m=l.find(_=>`Debugger/${_.threadId}`===e.path);if(m){const{source:{content:_},source:S}=m.currentStackFrame,T={name:e.name,type:E.FileFolderType.DEBUGGER,date:new Date().toISOString(),path:e.path,content:_,view:{panel:{isOpen:!1,type:"",current:""}},initialContent:_,flags:{confirmed:!0},extra:{source:S,editor:e.editor}};return i(jt(T)),T}}let p=null;try{p=await ts(e,t.confirmed)}catch(m){const{data:_}=m;if(_.__ERROR.find(S=>[E.ERROR_CODES.JSON_MALFORMED,E.ERROR_CODES.JSON_MALFORMED_AT_LINE].includes(S.errCode))){const{confirmed:S}=await i(dr({title:"Corrupt file",type:qt.CONFIRM,color:Ir.WARNING,message:"Open in code editor ?"})).unwrap();if(S){const T=await E.getNodeInfo({verb:E.DesignerRequestVerb.GET_INFO,path:e.path,content:!0,as:"text"}),{content:C,date:F,ext:D}=T;p={date:F,view:{panel:{isOpen:!1,type:"",current:""}},flags:{enabled:["WebForm","MForm"].includes(D),confirmed:!0},extra:{editor:E.EDITOR.Code},name:e.name,path:e.path,type:E.getTypeFromExtension(e.path),initialContent:C,content:C}}}}return p&&(e.path===E.ROLES_TAB_PATH&&!c.flags.touched?i(Kc({content:p.content,date:p.date})):e.path===E.SETTINGS_TAB_PATH&&i(es({path:"project",value:p.content})),i((r?Lv:jt)(p)),p)}),Zc=re("explorer/openFileAtLine",async({file:e},{getState:r,dispatch:t})=>{const{tabs:a}=r().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 t(jt(c)),c}const s=await ts(e);return t(jt(s)),s}),av=re("explorer/injectContentAtLine",async(e,{getState:r,dispatch:t,rejectWithValue:a})=>{const i=r();e.path.split("/").pop();const c=vt(i.explorer,e.path);if(!c)return a(`Error while trying to inject content in file ${e.path}`);const l=await ts({name:c.name,date:c.date||new Date().toISOString(),path:`${c.path}.${c.ext}`,type:E.FileFolderType.CLASS,editor:c.config.editor});return await t(jt(l)),{...e,path:`${c.path}.${c.ext}`}}),ov=re("explorer/openFileAtSelection",async({file:e},{getState:r,dispatch:t})=>{const{tabs:a}=r().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 t(jt(c)),c}const s=await ts(e);return t(jt(s)),s}),yc=re("explorer/deleteFile",async e=>{const{name:r,type:t,path:a,flags:i}=e;if(i.error)return{deleted:!0,node:e};const s=a.split("/");return s.pop(),{deleted:await E.dropFile({root:E.FolderRootType.ROOT,type:rv(t),verb:E.DesignerRequestVerb.DROP,name:r,path:s.join("/")}),node:e}}),pD=re("explorer/deleteFolder",async e=>{const{path:r,flags:t}=e;if(t.error)return{deleted:!0,node:e};const{deleted:a}=await E.removeItem({force:!0,path:r,verb:E.DesignerRequestVerb.REMOVE_ITEM});return{deleted:a,node:e}}),hD=re("explorer/removeFileNode",async(e,{getState:r,dispatch:t})=>{const a=`${e.path}.${e.ext}`;if(await E.removeItem({verb:E.DesignerRequestVerb.REMOVE_ITEM,path:a,force:!0}),e.path==="Classes/DataStore"&&setTimeout(()=>{t(Wn())},ji),e.ext){const{tabs:i}=r().root,s=i.findIndex(c=>c.path===a);s>=0&&t(sl(s))}return{deleted:!0,node:e}}),fa=re("explorer/renameFile",async({file:e,newname:r})=>{if(e.type!=="folder"){const a=e.path.split("/");a.pop();const i=`${a.join("/")}/${e.name}.${e.ext}`,s=`${a.join("/")}/${r}.${e.ext}`;return await E.moveItem({verb:E.DesignerRequestVerb.MOVE_ITEM,path:i,newpath:s}),{old:{...e,path:i},new:{...e,name:r,path:s}}}const t=e.path.split("/");return t.pop(),await E.moveItem({verb:E.DesignerRequestVerb.MOVE_ITEM,path:`${t.join("/")}/${e.name}`,newpath:`${t.join("/")}/${r}`}),{old:e,new:{...e,name:r,path:`${t.join("/")}/${r}`}}}),Za=re("explorer/relocateNode",async({draggedNode:e,newLocation:r},{rejectWithValue:t})=>{try{await E.moveItem({verb:E.DesignerRequestVerb.MOVE_ITEM,path:`${e.path}.${e.ext}`,newpath:`${r.path}/${e.name}.${e.ext}`})}catch{return t("can't move item")}}),fi=re("explorer/duplicateNode",async({node:e,duplicateName:r},{rejectWithValue:t,fulfillWithValue:a,getState:i})=>{const s=e.path.split("/");s.pop();try{const{tabs:c}=i().root,l=c.find(({path:m})=>m===`${e.path}${e.ext?`.${e.ext}`:""}`),f=["4dm","4qm","4qs"].includes(e.ext),{content:p}=l||await E.getNodeInfo({verb:E.DesignerRequestVerb.GET_INFO,path:`${e.path}.${e.ext}`,content:!0,as:f?"text":"json"}),h=await E.setFileContent({name:`${r}.${e.ext}`,content:p,path:s.join("/"),asText:f});return a({node:{...h,path:s.join("/")}})}catch{return t("failed to duplicate file")}}),gD=re("explorer/executeMethod",async({methodName:e,params:r=[],resultingDataSource:t={},namespace:a=""},{rejectWithValue:i})=>{var s,c;try{const f=await window.Method4D.buildMethod({methodName:e,parameters:r,resultingDataSource:t},{namespace:a},null).callServerSide({id:"",serverSideRef:""},"onclick",{});return f!=null&&f.__NOTIFICATION?E.toastSubject.next({message:`${((s=f.__NOTIFICATION)==null?void 0:s.message)||""}`,kind:`${((c=f.__NOTIFICATION)==null?void 0:c.type)||"info"}`}):E.toastSubject.next({message:"Method executed Successfully",kind:"message"}),f}catch(l){return E.toastSubject.next({message:l.message||`Error executing the method "**${e}**"`,kind:"danger",markdown:!0}),i("can't execute method")}}),vD=re("files/fetchFiles",async()=>E.getFolders(E.FolderRootType.WEBFORMS,E.FolderRootType.METHODS,E.FolderRootType.CLASSES)),Qc=re("tabs/renameDatasource",async(e,{dispatch:r,getState:t})=>{var S,T;const a=!!e.datasourceNamespace,{confirmed:i}=await r(dr({message:"Are you sure you want to rename the datasource?",title:"Rename Datasource",type:qt.CONFIRM,color:Ir.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:s,datasourceId:c,datasourceNamespace:l,value:f,path:p}=e,h=t();let m=[];if(a){const C=h.sharedDatasources.sources[l]||[];m.push(...C)}else if(p){const C=h.root.tabs.find(E.by("path",p));if(m=(T=(S=C==null?void 0:C.content)==null?void 0:S.metadata)==null?void 0:T.datasources,!m)return null}const _=new RegExp(`^${c}\\b`,"");if(m=m.map(C=>{const F=(E.isObjectDatasource(C)||!E.isSimpleDatasource(C))&&C.from&&_.test(C.from),D=C.events?C.events.map(W=>{var $,j,A,K;switch(W==null?void 0:W.type){case"method":{const G=W;return G.params?{...G,params:G.params.map(Y=>{var se;return{...Y,datasource:(se=Y.datasource)==null?void 0:se.replace(new RegExp(`^${c}`,""),f)}}),returns:($=G.returns)!=null&&$.datasource?{...G.returns,datasource:(j=G.returns.datasource)==null?void 0:j.replace(new RegExp(`^${c}`,""),f)}:G.returns}:G}case"simple-action":{const G=W;return G.datasource?{...G,datasource:{...G.datasource,name:(A=G.datasource.name)==null?void 0:A.replace(new RegExp(`^${c}`,""),f),from:(K=G.datasource.from)==null?void 0:K.replace(new RegExp(`^${c}`,""),f)}}:G}default:return W}}):C.events;return C.id===c?{...C,id:f,events:D}:F&&C.from?{...C,from:C.from.replace(new RegExp(`^${c}`,""),f),events:D}:{...C,events:D}}),s){const C=a?`${l}:${c}`:`${c}`,F=a?`${l}:${f}`:`${f}`;E.datasourcesSubject.next({path:p??"",action:E.DatasourcesActions.RENAME,old_reference:C,new_reference:F,is_shared:a})}return{path:p,namespace:l,datasources:m}}),el=re("tabs/edit-datasource",(e,{getState:r})=>{var s,c;const t=r();let a=[];if(e.namespace)a=t.sharedDatasources.sources[e.namespace];else{const l=t.root.tabs.find(E.by("path",e.path));l&&(a=((c=(s=l.content)==null?void 0:s.metadata)==null?void 0:c.datasources)||[])}return a.map(l=>l.id===e.datasourceId?Object.assign({},l,{[e.propertyKey]:e.value}):l)}),iv=re("tabs/fetchChanges",async(e,{getState:r})=>{const a=Ea(r()).filter(i=>[E.FileFolderType.METHOD,E.FileFolderType.CLASS].includes(i.type));return E.getFilesInfo(...a.map(i=>{const[s]=i.path.split("/").filter(Boolean);return{name:i.name,type:i.type,root:s,path:"."}}))}),yD=re("files/saveAll",async(e,{getState:r,dispatch:t})=>{const a=jc(r());for(const i of a)t(da({tab:i}))}),tl=re("files/tryCloseTab",async(e,{getState:r,dispatch:t})=>{const{tabs:a}=r().root,i=a.findIndex(c=>c.path===e);if(i===-1)return!1;const s=a[i];if(s!=null&&s.flags.touched){const{confirmed:c}=await t(dr({title:ki(s),message:"Your unsaved changes will be lost. Proceed anyway?",type:qt.CONFIRM,color:Ir.WARNING,icon:"FdWarningDanger"})).unwrap();if(!c)return!1}return t(sl(i)),s.path===E.ROLES_TAB_PATH&&s.flags.touched&&(async()=>{const l=await E.getNodeInfo({verb:E.DesignerRequestVerb.GET_INFO,path:E.ROLES_TAB_PATH,content:!0,as:"json"});t(Kc({content:l.content,date:l.date}))})(),!0}),mD=re("files/tryCloseOtherTabs",async(e,{getState:r,dispatch:t})=>{const{tabs:a}=r().root;if(a.some(s=>s.path!==e&&s.flags.touched===!0)){const{confirmed:s}=await t(dr({title:"Closing other tabs",message:"Your changes will be lost if you do not save them. Close anyway?",type:qt.CONFIRM,color:Ir.WARNING,icon:"FdWarningDanger"})).unwrap();if(!s)return}t($v(e))}),bD=re("files/tryCloseAllTabs",async(e,{getState:r,dispatch:t})=>{const{tabs:a}=r().root;if(a.some(s=>s.flags.touched===!0)){const{confirmed:s}=await t(dr({title:"Closing all tabs",message:"Your changes will be lost if you do not save them. Close anyway?",type:qt.CONFIRM,color:Ir.WARNING,icon:"FdWarningDanger"})).unwrap();if(!s)return}t(Iv())}),_D=re("files/tryCloseRightTabs",async(e,{getState:r,dispatch:t})=>{const{tabs:a}=r().root;let i=!1;for(let s=a.length-1;s>e;s-=1)if(a[s].flags.touched){i=!0;break}if(i){const{confirmed:s}=await t(dr({title:"Closing right tabs",message:"Your changes will be lost if you do not save them. Close anyway?",type:qt.CONFIRM,color:Ir.WARNING,icon:"FdWarningDanger"})).unwrap();if(!s)return}t(Fv(e))}),ED=re("files/tryCloseLeftTabs",async(e,{getState:r,dispatch:t})=>{const{tabs:a}=r().root;let i=!1;for(let s=0;s<e;s+=1)if(a[s].flags.touched){i=!0;break}if(i){const{confirmed:s}=await t(dr({title:"Closing left tabs",message:"Your changes will be lost if you do not save them. Close anyway?",type:qt.CONFIRM,color:Ir.WARNING,icon:"FdWarningDanger"})).unwrap();if(!s)return}t(Mv(e))}),mc=re("files/reloadTab",async(e,{dispatch:r})=>{if(e.flags.touched){const{confirmed:i}=await r(dr({title:ki(e),message:"Changes made to the file will be lost. Continue?",type:qt.CONFIRM,color:Ir.WARNING,icon:"FdWarningDanger"})).unwrap();if(!i)return}const t=Xh(e.path),a=await E.getNodeInfo({verb:E.DesignerRequestVerb.GET_INFO,path:e.path,content:!0,as:t});if(e.path===E.ROLES_TAB_PATH){const{roles:i,privileges:s}=Zi(a.content);r(Jc({roles:i,privileges:s}))}else if(e.path===E.SETTINGS_TAB_PATH){const{content:i}=a;r(es({path:"project",value:i}))}else{const{content:i}=a;e.type===E.FileFolderType.WEBFORM?E.webformSubject.next({path:e.path,action:E.WebformActions.RELOAD,payload:i.components}):e.type===E.FileFolderType.MODEL&&ag.next({action:"reload",payload:i})}return a}),da=re("files/saveTab",async({tab:e},{dispatch:r,getState:t})=>{const{path:a,content:i}=e;if(e.type===E.FileFolderType.DEBUGGER)return{...e,errors:[]};a.split("/").pop();const c=await E.getFilesInfo({path:a});if(c.files[0]){const h=new Date(e.date),m=new Date(c.files[0].date);if(h.getTime()<m.getTime()){const{confirmed:_}=await r(dr({title:ki(e),message:"New content has been found on the server. Are you sure you want to continue?",type:qt.CONFIRM,icon:"FdSave"})).unwrap();if(!_)return r(Dv({path:a,flags:{old:!0}})),null}}const l=await E.saveContent({verb:E.DesignerRequestVerb.SAVE_CONTENT,content:SD(e,t()),path:a});(e.type===E.FileFolderType.CLASS||e.type===E.FileFolderType.MODEL)&&setTimeout(()=>{r(Wn())},ji);const f=(l.modelErrors||[]).map(h=>h.message),p=(l.permissionsErrors||[]).map(h=>h.message);return{...e,content:i,date:l.date,initialContent:i,errors:f.length>0||p.length>0?[{title:"Model errors",messages:f},{title:"Permissions errors",messages:p}]:[]}}),SD=(e,r)=>{switch(!0){case e.path==="settings.json":case e.path===E.SETTINGS_TAB_PATH:return r.settings.project;case e.type===E.FileFolderType.ROLES:return Qi(r.roles);case e.type===E.FileFolderType.MODEL:return e.content||{toJSON:!0,dataClasses:[],extraProperties:{}};default:return e.content}},Vp=async e=>{if(e.type===E.FileFolderType.DATA_EXPLORER)return{name:"Data Explorer",path:e.path,flags:{},view:{panel:{isOpen:!1,type:"",current:""}},type:e.type,date:new Date().toISOString()};const r=e.path.split("/").filter(Boolean)[0],t=await E.getFile({root:r,type:e.type,verb:E.DesignerRequestVerb.GET,name:e.name}),a={};t.type===E.FileFolderType.METHOD&&(a.attributes=E.parseAttributes(t.content));const{date:i,name:s,type:c,content:l}=t;return{date:i,flags:{enabled:e.type===E.FileFolderType.WEBFORM},extra:a,view:{panel:{isOpen:!1,type:"",current:""}},name:s,path:e.path,type:c,initialContent:l,content:c===E.FileFolderType.MODEL?Oh(l):l}},sv=re("files/tryInjectMethod",async({type:e,dataclass:r},{getState:t,dispatch:a})=>{const{root:{tabs:i},settings:{server:{qodly:s}}}=t(),c=E.getFileExtentionFromType("class",s);let l="",f="",p=null;if(!r)l="DataStore",f=`Classes/DataStore.${c}`;else switch(e){case"dataclass":l=r,f=`Classes/${r}.${c}`;break;case"collection":l=`${r}Selection`,f=`Classes/${r}Selection.${c}`;break;case"entity":l=`${r}Entity`,f=`Classes/${r}Entity.${c}`;break;default:return p}const h=i.find(E.by("path",f));if(h)return a(jt(h)),h;try{p=await Vp({name:l,date:new Date().toISOString(),path:`class/${l}.${c}`,type:E.FileFolderType.CLASS})}catch{r?await a(vc({type:"dataclass",className:r,collectionName:`${r}Selection`,toCreate:e})):await a(vc({type:"model"}))}return p=await Vp({name:l,date:new Date().toISOString(),path:`class/${l}.${c}`,type:E.FileFolderType.CLASS}),p.path=f,a(jt(p)),p}),wD=re("roles/open",async(e,{dispatch:r,getState:t})=>{const{tabs:a}=t().root,i=a.find(s=>s.path===E.ROLES_TAB_PATH);if(i)return r(jt(i)),i;r(Di())});function Kp(e,r){const{line:t,offset:a,type:i="saved"}=r;e.breakpoints[i].locations.push({line:t}),Ke.isNumber(a)&&(e.breakpoints[i].offset=a)}function Jp(e,r,t,a){e.breakpoints[t].locations=r,Ke.isNumber(a)&&(e.breakpoints[t].offset=a)}function Xp({filePath:e,fileType:r,methodName:t,className:a,ext:i,source:s}){return{filePath:e,fileType:r,methodName:t,className:a,ext:i,source:s,breakpoints:{draft:{locations:[],offset:0},saved:{locations:[],offset:0}}}}function Zp(e,r,t){let a=!1;const i=e.map(s=>s[t]!==r[t]?s:(a=!0,{...s,...r}));return a?i:[...i,r]}function ii(e){return e.map(({label:r})=>({label:r}))}const uv=fr({name:"debugger",initialState:()=>{var r,t;const{debugger:e={meta:{state:qr.DETACHED},list:[],sessions:[],expressions:[]}}=ga();return{meta:{...e.meta,state:((r=e.meta)==null?void 0:r.state)===qr.ATTACHED?(t=e.meta)==null?void 0:t.state:qr.DETACHED},list:e.list||[],sessions:e.sessions||[],expressions:e.expressions||[]}},reducers:{addBreakpointDecoration(e,r){const{filePath:t,fileType:a,methodName:i,className:s,ext:c,source:l,breakpoint:f}=r.payload,p=Bn(e.list,t,i,s);if(p)Kp(p,f);else{if(a===E.FileFolderType.CLASS&&f.offset===void 0)throw new Error(`Cannot add a breakpoint on a function without offset. Try editing the ${s} class.`);const h=Xp({filePath:t,fileType:a,methodName:i,className:s,ext:c,source:l});Kp(h,f),e.list.push(h)}},removeBreakpointDecoration(e,r){const{filePath:t,methodName:a,line:i,offset:s=0,type:c="saved"}=r.payload;if(t.startsWith("Classes/")){const l=e.list.filter(f=>f.filePath===t);if(l.length>0){const f=i+s;l.forEach(p=>{const h=p.breakpoints[c].offset||0;p.breakpoints[c].locations=p.breakpoints[c].locations.filter(m=>m.line+h!==f),c==="saved"&&(p.breakpoints.draft.locations=p.breakpoints.draft.locations.filter(m=>m.line+h!==f))})}}else{const l=Bn(e.list,t,a);l&&(l.breakpoints[c].locations=l.breakpoints[c].locations.filter(f=>f.line!==i),c==="saved"&&(l.breakpoints.draft.locations=l.breakpoints.draft.locations.filter(f=>f.line!==i)))}},setBreakpointsDecoration(e,r){const{filePath:t,fileType:a,methodName:i,className:s,ext:c,source:l,breakpoints:f,offset:p,type:h="saved",clearDraft:m}=r.payload,_=Bn(e.list,t,i);if(_)Jp(_,f,h,p),m&&h!=="draft"&&(_.breakpoints.draft.locations=[]);else{const S=Xp({filePath:t,fileType:a,methodName:i,className:s,ext:c,source:l});Jp(S,f,h,p),e.list.push(S)}},clearBreakpoints(e,r){const{filePath:t,type:a="saved"}=r.payload;e.list=e.list.map(i=>({...i,breakpoints:i.filePath===t?{draft:!a||a==="draft"?{locations:[],offset:0}:i.breakpoints.draft,saved:!a||a==="saved"?{locations:[],offset:0}:i.breakpoints.saved}:i.breakpoints}))},setActiveLine(e,r){const{threadId:t,line:a,highlight:i}=r.payload,s=ft(e.sessions,t);s&&(s.activeLine=a,i&&(s.highlightedLines={start:a,end:a}))},addExpression(e,r){const{threadId:t,label:a,save:i}=r.payload,s=ft(e.sessions,t);s&&s.stopped&&(s.expressions=[...s.expressions||[],{label:a}],i&&(e.expressions=ii(s.expressions)))},removeExpression(e,r){const{threadId:t,index:a,save:i}=r.payload,s=ft(e.sessions,t);s&&(s.expressions=s.expressions.filter((c,l)=>l!==a),i&&(e.expressions=ii(s.expressions)))},removeAllExpressions(e,r){const{threadId:t,save:a}=r.payload,i=ft(e.sessions,t);i&&(i.expressions=[],a&&(e.expressions=[]))},renameExpression(e,r){const{threadId:t,index:a,replacement:i,save:s}=r.payload,c=ft(e.sessions,t);c&&c.expressions[a]&&(c.expressions[a].label=i,s&&(e.expressions=ii(c.expressions)))},setExpression(e,r){const{threadId:t,expression:a}=r.payload,i=ft(e.sessions,t);if(i){const s=a.index>=0?a.index:i.expressions.length>0?i.expressions.length-1:0,c=i.expressions[s];c?(c.result=a.result,c.nakedResult=a.nakedResult,c.variablesReference=a.variablesReference||0,c.presentationHint=a.presentationHint):i.expressions.push(a)}},updateExpressionAt(e,r){const{threadId:t,index:a,value:i}=r.payload,s=ft(e.sessions,t);if(s){const c=s.expressions[a];c&&(c.result=`"${i}"`,c.nakedResult=i)}},saveExpressions(e,r){const{expressions:t}=r.payload;e.expressions=ii(t)},addSession(e,r){const{threadId:t,channelId:a,stackFrames:i,exceptions:s=[]}=r.payload,c=ft(e.sessions,t),l=i[0],{expressions:f=[]}=e;if(c)c.expressions=f;else{const p=Fc(t);e.sessions.push({tabPath:p,threadId:t,channelId:a,stackFrames:i,currentStackFrame:l,exceptions:s,expressions:f,variables:{callchain:[],expressions:[]},highlightedLines:null,activeLine:null,stopped:!0})}},updateSession(e,r){const{threadId:t,changes:a}=r.payload;e.sessions=e.sessions.map(i=>i.threadId===t?{...i,...a}:i)},removeSession(e,r){const{threadId:t}=r.payload;e.sessions=e.sessions.filter(a=>a.threadId!==t)},removeSessionByIndex(e,r){const t=r.payload;e.sessions.splice(t,1)},setSessions(e,r){const t=r.payload;e.sessions=t},setCallChainVariables(e,r){const{threadId:t,frameId:a,variables:i}=r.payload;e.sessions=e.sessions.map(s=>{var c;return s.threadId===t?{...s,variables:{...s.variables,callchain:Zp((c=s.variables)==null?void 0:c.callchain,{frameId:a,items:i},"frameId")}}:s})},setExpressionVariables(e,r){const{threadId:t,variablesReference:a,variables:i}=r.payload;e.sessions=e.sessions.map(s=>{var c;return s.threadId===t?{...s,variables:{...s.variables,expressions:Zp((c=s.variables)==null?void 0:c.expressions,{variablesReference:a,items:i},"variablesReference")}}:s})},setSourceContent(e,r){const{threadId:t,content:a}=r.payload,i=ft(e.sessions,t);i&&(i.currentStackFrame.source={...i.currentStackFrame.source,content:a})},setDebuggerMeta(e,r){if(r.payload.state===qr.ERROR){e.meta.error={...e.meta.error,time:Date.now()};const{override:t,error:a={code:null,reason:"",type:Ei.SOCKET_ERROR}}=r.payload;if((t||e.meta.state!==qr.ERROR)&&(e.meta.error={...e.meta.error,...a}),(a==null?void 0:a.type)===Ei.SOCKET_CLOSURE&&!(a!=null&&a.reason)&&e.meta.state===qr.DETACHED)return}e.meta.state=r.payload.state}},extraReducers:e=>{e.addCase(lv.fulfilled,r=>{r.sessions=[]})}}),{addBreakpointDecoration:TD,removeBreakpointDecoration:xD,setBreakpointsDecoration:CD,clearBreakpoints:RD,setActiveLine:OD,addExpression:AD,renameExpression:PD,removeExpression:DD,removeAllExpressions:ID,setExpression:FD,updateExpressionAt:$D,saveExpressions:MD,addSession:ND,updateSession:LD,removeSession:jD,removeSessionByIndex:kD,setSessions:cv,setCallChainVariables:BD,setExpressionVariables:WD,setSourceContent:UD,setDebuggerMeta:HD}=uv.actions,lv=re("files/wipeDebuggerSessions",async(e,{getState:r,dispatch:t})=>{const{sessions:a}=r().debugger;for(const{threadId:i}of a){const s=Fc(i);t(tl(s))}}),fv=re("files/removeDebuggerSessionsNotIn",async(e,{getState:r,dispatch:t})=>{const{threadIds:a}=e,{sessions:i}=r().debugger,s=[],c=i.filter(l=>{const f=a.includes(l.threadId);return f||s.push(l.threadId),f});return t(cv(c)),{staleThreadIds:s}});var rl=(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))(rl||{}),zr=(e=>(e.STORAGE="storage",e.RELATEDENTITY="relatedEntity",e.RELATEDENTITIES="relatedEntities",e.CALCULATED="calculated",e.COMPOSITION="composition",e.ALIAS="alias",e))(zr||{});const GD=e=>["string","uuid","number","long"].includes(e.type),qD=[{label:"Storage",value:"storage"},{label:"Calculated",value:"calculated"}],YD=[{title:"UUID",kind:"storage",value:"uuid",calculatedType:"uuid",calculatedKind:"storage"},{title:"Long",kind:"storage",value:"long",calculatedType:"long",calculatedKind:"storage"}],zD=[{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"}],VD=[{label:"Expose as REST",value:"public"},{label:"Do not expose as REST",value:"publicOnServer"}],KD=[{label:"Expose as REST",value:"public"},{label:"Do not expose as REST",value:"publicOnServer"}],JD=[{label:"None",value:"none"},{label:"B-tree",value:"btree"},{label:"Cluster",value:"cluster"},{label:"Automatic",value:"auto"}],dv=Lt("model/add-dataclass"),pv=Lt("model/rename-dataclass"),hv=Lt("model/remove-dataclass"),gv=Lt("model/add-attribute"),XD=Lt("model/edit-attribute-property"),vv=Lt("model/remove-attribute"),yv=Lt("model/rename-attribute"),mv=Lt("model/edit-primary-key"),ZD=Lt("model/edit-dataclass-property"),bv=Lt("model/rename-collection"),QD=(e,r)=>({toJSON:!0,extraProperties:r,dataClasses:e.map(t=>{var a;return{...t.data,extraProperties:{position:{x:t.position.x,y:t.position.y},panelColor:(a=t.data.extraProperties)==null?void 0:a.panelColor}}})});function di(e,r,t){const a=e;let i=0;for(;t[`${a}${i||""}`];)i++;return`${a}${i||""}`}const Qa=e=>e.kind===zr.RELATEDENTITY,Ii=e=>e.kind===zr.RELATEDENTITIES,eI=e=>Ii(e)||Qa(e),nl=re("models/fetch",async()=>{try{return(await E.http(E.API_PREFIX,{method:"POST",body:JSON.stringify({verb:E.DesignerRequestVerb.GET_INFO,path:E.MODEL_TAB_PATH,as:"json",content:!0}),headers:new Headers({"Content-Type":"application/json"})})).content}catch(e){return e.message}}),Fi=re("models/save",async(e,{getState:r,dispatch:t,rejectWithValue:a})=>{const{tabs:i}=r().root,s=i.find(c=>c.path===E.MODEL_TAB_PATH);if(!s)return a("Error while saving the model");try{const c=await E.http(E.API_PREFIX,{method:"POST",body:JSON.stringify({verb:"save",path:s.path,content:s.content}),headers:new Headers({"Content-Type":"application/json"})});return setTimeout(()=>{t(Wn())},ji),{...c,path:s.path,content:e.content||{toJSON:!0,dataClasses:[],extraProperties:{}}}}catch{return a("Error while saving the model")}}),tI=re("models/open",async(e,{dispatch:r,getState:t})=>{const{tabs:a}=t().root,i=a.find(s=>s.path==="models/main");if(i)return r(jt(i)),i;r(nl())}),rI=re("model/rename-dataclass",async(e,{getState:r,dispatch:t})=>{var m,_;const{dataclassId:a,selectionId:i,name:s}=e;let c=r();const l=c.explorer.find(S=>S.path===E.FolderRootPath.CLASSES);if(!l)throw new Error("Classes folder was not found!");await t(Pr(l.path)),c=r();const f={class:{found:!1,newNameTaken:!1,file:null,filename_update:s},entity:{found:!1,newNameTaken:!1,file:null,filename_update:`${s}Entity`},selection:{found:!1,newNameTaken:!1,file:null,filename_update:`${s}Selection`}};(_=(m=c.explorer.find(S=>S.path===E.FolderRootPath.CLASSES))==null?void 0:m.children)==null||_.forEach(S=>{S.name===f.class.filename_update&&(f.class.newNameTaken=!0),S.name===f.entity.filename_update&&(f.entity.newNameTaken=!0),S.name===f.selection.filename_update&&(f.selection.newNameTaken=!0),S.name===a?(f.class.found=!0,f.class.file=S):S.name===`${a}Entity`?(f.entity.found=!0,f.entity.file=S):S.name===i&&(f.selection.found=!0,f.selection.file=S)});const p=Object.entries(f).reduce((S,T)=>{const[C,F]=T;return F.found?F.newNameTaken?[...S,{type:"error",message:`Cannot rename ${C} file to ${F.filename_update} because it already exists. The existing file will be used instead!`}]:S:[...S,{type:"warning",message:`${a} ${C} file was not found`}]},[]);p.length>0&&t(dr({message:"The following errors were encountered during dataclass rename:",views:{tips:p}}));const h=Object.values(f).filter(S=>S.found&&S.file&&!S.newNameTaken);await Promise.all(h.map(async S=>await t(fa({file:S.file,newname:S.filename_update})))),h.length>0&&t(Pr("Classes"))}),oo={DATACLASS_DELETE:"dataclass.delete",DATACLASS_DRAGGABLE:"dataclass.draggable"},nI={model:{dataClasses:{},collections:{},extraProperties:{}},draft:{dataClasses:{},collections:{},extraProperties:{}},flags:{[oo.DATACLASS_DELETE]:!0,[oo.DATACLASS_DRAGGABLE]:!0}},_v=fr({name:"Models",initialState:nI,reducers:{setModelFlag(e,r){e.flags={...e.flags,...r.payload}}},extraReducers(e){e.addCase(dv,({draft:{dataClasses:r}},t)=>{var c,l;const{dataclassID:a}=t.payload,i=di(a||"DataClass","className",r),s={className:i,collectionName:`${i}Selection`,attributes:[{name:"ID",kind:zr.STORAGE,type:rl.LONG,scope:"public",indexKind:"auto",unique:!0,primKey:!0,autosequence:!0}],name:i,scope:"public",extraProperties:{position:{x:((c=t.payload.position)==null?void 0:c.x)||0,y:((l=t.payload.position)==null?void 0:l.y)||0}}};r[s.name]=s}).addCase(hv,({draft:{dataClasses:r}},t)=>{const{dataclassID:a}=t.payload;r[a]&&(delete r[a],Object.values(r).forEach(s=>{s.attributes=s.attributes.filter(c=>c.type!==a&&c.type!==s.collectionName)}))}).addCase(pv,({draft:{dataClasses:r,collections:t}},a)=>{const{dataclassID:i,newName:s}=a.payload;if(!r[i]||r[s])return;const c=r[i].collectionName,l=di(`${s}Selection`,"collectionName",t);Object.values(r).forEach(f=>{f.className===i&&(f.className=s,f.name=s,f.collectionName=l),f.attributes.forEach(p=>{p.type===i?(p.type=s,p.path=s):p.type===c&&(p.type=l)})})}).addCase(gv,({draft:{dataClasses:r}},t)=>{const{dataclassID:a,attributeName:i,attributeType:s,attributeKind:c,target:l}=t.payload;if(!r[a]||E.exists("name",i,r[a].attributes))return;const p={name:i,kind:c,type:s,exposed:!0,scope:"public"};if(c===zr.RELATEDENTITY){if(!r[s])return;p.path=s;const m={name:di(r[s].collectionName,"name",r[s].attributes),type:r[a].collectionName,kind:zr.RELATEDENTITIES,reversePath:!0,path:i,scope:"public",exposed:!0};r[s].attributes.push(m)}else if(c===zr.RELATEDENTITIES){const h=r[s];if(!h)return;const m=h.attributes.find(E.by("name",l));if(m){if(!Qa(m)||m.type!==r[a].className)return}else{p.path=l,p.reversePath=!0,p.type=s;const _={name:l,kind:zr.RELATEDENTITY,scope:"public",path:h.className,type:h.className,exposed:!0};h.attributes.push(_)}}r[a].attributes.push(p)}).addCase(yv,({draft:{dataClasses:r}},t)=>{const{dataclassID:a,attributeID:i,newName:s}=t.payload,c=r[a].attributes.find(E.by("name",i)),l=r[a].attributes.find(E.by("name",s));!c||l||Object.values(r).forEach(({collectionName:f,attributes:p,className:h})=>{p.forEach(m=>{Qa(c)&&Ii(m)&&m.type===f&&m.path===i&&(m.path=s),h===a&&m.name===i&&(m.name=s)})})}).addCase(vv,({draft:{dataClasses:r}},t)=>{const{dataclassID:a,attributeID:i}=t.payload;if(!r[a])return;const s=r[a].attributes.find(E.by("name",i));s&&(Qa(s)&&Object.values(r).forEach(c=>{c.attributes=c.attributes.filter(l=>!(Ii(l)&&l.type===c.collectionName&&l.path===s.name))}),r[a].attributes=r[a].attributes.filter(E.outBy("name",i)))}).addCase(bv,({draft:{dataClasses:r,collections:t}},a)=>{const{dataclassID:i,collectionName:s}=a.payload;if(!r[i])return;const c=r[i].collectionName;t[s]||(r[i].collectionName=s,t[s]=r[i],delete t[c],Object.values(r).forEach(l=>l.attributes.forEach(f=>{f.type===c&&(f.type=s)})))}).addCase(mv,({draft:{dataClasses:r}},t)=>{const{dataclassID:a,newPrimKey:i}=t.payload;r[a]&&r[a].attributes.forEach(s=>{s.name===i?s.primKey=!0:s.primKey=!1})}),e.addCase(nl.fulfilled,(r,t)=>{var c;const a={},i={},s=t.payload.extraProperties||{};(c=t.payload.dataClasses)==null||c.forEach(l=>{a[l.name]=l,i[l.collectionName]=l}),r.draft.dataClasses=a,r.draft.collections=i,r.draft.extraProperties=s,r.model.dataClasses=a,r.model.collections=i,r.model.extraProperties=s}),e.addCase(Fi.pending,()=>{}).addCase(Fi.fulfilled,(r,t)=>{const a={},i={},s=t.payload.content.extraProperties||{};t.payload.content.dataClasses.forEach(c=>{a[c.name]=c,i[c.collectionName]=c}),r.draft.dataClasses=a,r.draft.collections=i,r.draft.extraProperties=s,r.model.dataClasses=a,r.model.collections=i,r.model.extraProperties=s})}}),{setModelFlag:aI}=_v.actions,oI=()=>Zr(e=>e.model.draft.dataClasses),iI=()=>Zr(e=>e.model.draft.collections),sI=e=>Zr(r=>r.model.draft.dataClasses[e]),uI=(e,r)=>Zr(t=>t.model.draft.dataClasses[e].attributes.find(E.by("name",r))),cI=()=>Zr(e=>e.model.draft.extraProperties),lI=()=>{const e=Zr(i=>i.model.flags),r=i=>i in e?e[i]:void 0,t=r(oo.DATACLASS_DELETE),a=r(oo.DATACLASS_DRAGGABLE);return{deleteDataclass:t,draggableDataclass:a,flags:e}},fI=_v.reducer;function Hu(e,r){const t=e.tabs.find(({path:a})=>a===E.SETTINGS_TAB_PATH);t&&(t.flags.touched=r)}const Ev={SIDEBAR_SECTION_RESIZABLE:"sidebar.section.resizable"},Sv={[Ev.SIDEBAR_SECTION_RESIZABLE]:!0},wv=fr({name:"webforms",initialState:()=>{const{webforms:e}=ga();return{...e,templates:{data:[],selectedGroup:""},datasources:{...Dc.webforms.datasources,...e==null?void 0:e.datasources},flags:Sv}},reducers:{toggleInspector:(e,r)=>{const{type:t}=r.payload;e.inspector[t].active=!e.inspector[t].active,e.inspector[t].active||(e.inspector[t].data=void 0)},inspect:(e,r)=>{const{type:t,data:a}=r.payload;e.inspector[t].active&&(e.inspector[t].data=a)},addComponent:(e,r)=>{e.components.push(r.payload)},editComponent:(e,r)=>{const{id:t,changes:a}=r.payload;e.components=e.components.map(i=>i.id===t?{...i,...a}:i)},removeComponent:(e,r)=>{const{payload:t}=r,a=e.components.findIndex(i=>i.id===t);a!==-1&&e.components.splice(a,1)},setSelectedGroup:(e,r)=>{e.templates.selectedGroup=r.payload.selectedGroup},setTemplatesData:(e,r)=>{e.templates.data=r.payload},setTemplateData:(e,r)=>{const{group:t,components:a}=r.payload,i=e.templates.data.find(s=>s.group===t);i&&(i.components=a)},setDatasourcesTheme:(e,r)=>{e.datasources.theme=r.payload},setWebformsFlag(e,r){e.flags={...e.flags,...r.payload}}},extraReducers(e){e.addCase(Av.fulfilled,(r,t)=>{r.components=t.payload})}}),{toggleInspector:dI,inspect:pI,addComponent:Tv,editComponent:xv,removeComponent:Cv,setSelectedGroup:hI,setTemplatesData:Rv,setTemplateData:Ov,setDatasourcesTheme:gI,setWebformsFlag:vI}=wv.actions,yI=wv.reducer,al=Ke.curry((e,r)=>{var i,s;const t={...r.sharedDatasources.sources},a=(s=((i=r.root.tabs.find(E.by("path",e)))==null?void 0:i.content).metadata)==null?void 0:s.datasources;return a&&(t[e]=a),Ke.cloneDeep(t)}),mI=re("webforms/fetchTemplates",async(e,{dispatch:r,getState:t})=>{const{data:a}=t().webforms.templates,i=t().settings.session["studio.tipsBaseUrl"]||"";if(!Ke.isEmpty(a))return a;try{const c=await(await fetch(`${i}/build/index.json?t=${Date.now()}`)).json();return r(Rv(c)),c}catch{return[]}}),bI=re("webforms/fetchTemplate",async({name:e},{dispatch:r,getState:t})=>{const{data:a}=t().webforms.templates,i=a.find(s=>s.group===e);if(i&&!Ke.isEmpty(i.components))return i.components;try{const c=await(await fetch(`${i==null?void 0:i.link}?t=${Date.now()}`)).json();return r(Ov({group:e,components:c})),c}catch{return[]}}),Av=re("webforms/fetchCraftedComponents",async(e,{rejectWithValue:r})=>{try{return(await E.getNodeInfo({path:"WebForms/crafted_components.json",verb:E.DesignerRequestVerb.GET_INFO,content:!0,as:"json"})).content}catch{return r("Error while loading the crafted components")}}),_I=re("webforms/addCraftedComponent",async(e,{dispatch:r,rejectWithValue:t,getState:a})=>{try{r(Tv(e));const{webforms:{components:i}}=a();E.setCraftedComponents(i)}catch{return t("Error while adding the crafted component")}}),EI=re("webforms/editCraftedComponent",async(e,{dispatch:r,rejectWithValue:t,getState:a})=>{try{r(xv(e));const{webforms:{components:i}}=a();E.setCraftedComponents(i)}catch{return t("Error while editing the crafted component")}}),SI=re("webforms/removeCraftedComponent",async(e,{dispatch:r,rejectWithValue:t,getState:a})=>{try{r(Cv(e));const{webforms:{components:i}}=a();E.setCraftedComponents(i)}catch{return t("Error while removing the crafted component")}}),ol=re("datasources/add-datasource",async(e,{getState:r,rejectWithValue:t})=>{var a,i;try{const s=r(),c=e.datasource,l=!!c.namespace,f=[];if(l){const p={...s.sharedDatasources.sources,[c.namespace]:[...s.sharedDatasources.sources[c.namespace],c]};f.push(...p[c.namespace]),await E.setSharedSources(p)}else(((i=(a=s.root.tabs.find(E.by("path",e.path)).content)==null?void 0:a.metadata)==null?void 0:i.datasources)||[]).push(c);return{list:f,path:e.path,namespace:e.datasource.namespace}}catch{console.error("Error while adding the datasource",e.datasource.id),t("Error while adding the datasource")}}),il=re("datasources/edit-datasource",async(e,{getState:r,rejectWithValue:t})=>{try{const{namespace:a,path:i}=e,s=r(),c=!!e.namespace,l=al(i,s);let f=Ke.defaultTo(l[a||i],[]);return f=f.map(p=>p.id===e.id?{...p,[e.property]:e.value}:p),c&&await E.setSharedSources({...s.sharedDatasources.sources,[e.namespace]:f}),{list:f,path:e.path,namespace:e.namespace}}catch{t(`Error while editing datasource ${e.id}`)}}),wI=e=>e.type===pa.fulfilled.type,pa=re("datasources/rename-datasource",async(e,{getState:r,rejectWithValue:t})=>{try{const a=r(),i=!!e.namespace,s=e.namespace||e.path,c=al(e.path,a),l=Ke.defaultTo(c[s],[]),f=new RegExp(`^${e.id}\\b`,"");if(l.forEach(p=>{var m;const h=(E.isObjectDatasource(p)||!E.isSimpleDatasource(p))&&p.from&&f.test(p.from);e.updateRefs&&((m=p.events)==null||m.forEach(_=>{var S,T,C,F,D;switch(_.type){case"method":{const W=_;W.params.forEach($=>{$.datasource&&Object.assign($,{datasource:$.datasource.replace(new RegExp(`^${e.id}`,""),e.new_name)})}),W.returns&&Object.assign(W.returns,{datasource:(T=(S=W.returns)==null?void 0:S.datasource)==null?void 0:T.replace(new RegExp(`^${e.id}`,""),e.new_name)});return}case"simple-action":{const W=_;W.datasource&&Object.assign(W.datasource,{name:(C=W.datasource.name)==null?void 0:C.replace(new RegExp(`^${e.id}`,""),e.new_name),from:(F=W.datasource.from)==null?void 0:F.replace(new RegExp(`^${e.id}`,""),e.new_name),target:(D=W.datasource.target)==null?void 0:D.replace(new RegExp(`^${e.id}`,""),e.new_name)});return}default:return}})),p.id===e.id?p.id=e.new_name:h&&p.from&&(p.from=p.from.replace(new RegExp(`^${e.id}`,""),e.new_name))}),e.updateRefs){const p=E.getDatasourceId({id:e.id,namespace:e.namespace}),h=E.getDatasourceId({id:e.new_name,namespace:e.namespace});E.datasourcesSubject.next({path:e.path??"",action:E.DatasourcesActions.RENAME,old_reference:p,new_reference:h,is_shared:i})}return i&&await E.setSharedSources({...a.sharedDatasources.sources,[e.namespace]:l}),{list:l,path:e.path,namespace:e.namespace}}catch{return t(`Error while renaming datasource ${e.namespace}:${e.id}`)}}),eo=re("datasources/delete-datasource",async(e,{getState:r,rejectWithValue:t})=>{try{const a=r(),i=!!e.namespace,s=e.namespace||e.path,l=al(e.path,a)[s].filter(E.outById(e.id));return i&&await E.setSharedSources({...a.sharedDatasources.sources,[e.namespace]:l}),{list:l,path:e.path,namespace:e.namespace}}catch{return t(`Error while removing datasource ${e.id}`)}}),io=fr({name:"root",initialState:()=>{const e=ga();return{filesLoading:!1,tabs:e.tabs||[],activeTab:e.activeTab,recent:e.recent||[]}},reducers:{setPanelState(e,r){const{path:t,...a}=r.payload;e.tabs.forEach(i=>{i.path===t&&(i.view||(i.view={panel:{isOpen:!1,type:"",current:""}}),Object.assign(i.view.panel,a))})},addDataSource(e,r){var s;const{payload:{path:t,datasourceDef:a}}=r,i=e.tabs.find(c=>c.path===t);i&&(i.content.metadata.datasources=i.content.metadata.datasources||[],(s=i.content.metadata.datasources)!=null&&s.find(l=>l.id===a.id)||(i.content.metadata.datasources=[...i.content.metadata.datasources,{...a,events:[]}],i.flags={...i.flags,touched:!0,confirmed:!0}))},openSettingsTab(e){const r={date:new Date().toISOString(),flags:{confirmed:!0},view:{panel:{isOpen:!1,type:"",current:""}},extra:{editor:{key:"editors:settings"}},name:"Settings",path:E.SETTINGS_TAB_PATH,type:E.FileFolderType.SETTINGS,initialContent:{},content:{}};let t=e.tabs.find(a=>a.path===r.path);if(t||(e.tabs.push(r),t=e.tabs[e.tabs.length-1]),e.activeTab!==r.path){const a=e.tabs.reduce((i,s)=>(s==null?void 0:s.weight)>((i==null?void 0:i.weight)||0)?s:i,null);e.activeTab=r.path,t.weight=((a==null?void 0:a.weight)||0)+1}},removeDataSource(e,r){const{path:t,datasourceID:a}=r.payload;e.tabs=e.tabs.map(i=>i.path===t?{...i,flags:{...i.flags,touched:!0,confirmed:!0},content:{...i.content,metadata:{...i.content.metadata,datasources:i.content.metadata.datasources.filter(s=>s.id!==a)}}}:i)},setDataSources(e,r){const{payload:{path:t,datasourceArr:a}}=r;e.tabs=e.tabs.map(i=>{var s;return i.path===t?{...i,flags:{...i.flags,touched:!0,confirmed:!0},content:{...i.content,metadata:{...(s=i.content)==null?void 0:s.metadata,datasources:a}}}:i})},setTabs(e,r){e.tabs=r.payload},closeTab(e,r){const t=r.payload;e.tabs.splice(t,1);const a=e.tabs.reduce((i,s)=>(s==null?void 0:s.weight)>((i==null?void 0:i.weight)||0)?s:i,null);e.activeTab=(a==null?void 0:a.path)||""},closeOthers(e,r){e.tabs=e.tabs.filter(t=>t.path===r.payload),e.activeTab=r.payload},closeAllTabs(e){e.tabs=[],e.activeTab=""},closeRightTabs(e,r){e.tabs.splice(r.payload+1),e.activeTab=e.tabs[r.payload].path},closeLeftTabs(e,r){e.tabs.splice(0,r.payload)},closeSavedTabs(e){e.tabs=e.tabs.filter(({flags:{touched:t}})=>t);const r=e.tabs.reduce((t,a)=>(a==null?void 0:a.weight)>((t==null?void 0:t.weight)||0)?a:t,null);e.activeTab=(r==null?void 0:r.path)||""},confirmTab(e,r){const t=e.tabs.find(({path:a})=>a===r.payload);t&&(t.flags.confirmed||io.caseReducers.setTabFlags(e,{type:r.type,payload:{path:r.payload,flags:{confirmed:!0}}}))},selectTab(e,r){const t=e.tabs.find(({path:i})=>i===r.payload);if(!t||e.activeTab===r.payload)return;const a=e.tabs.reduce((i,s)=>(s==null?void 0:s.weight)>((i==null?void 0:i.weight)||0)?s:i,null);t.weight=a?(a.weight||0)+1:1,e.activeTab=r.payload},openTabUnselected(e,r){const t=r.payload;let a=e.tabs.find(({path:s})=>t.path===s);a||(e.tabs.push(t),a=e.tabs[e.tabs.length-1]);const i=e.tabs.reduce((s,c)=>(c==null?void 0:c.weight)>((s==null?void 0:s.weight)||0)?c:s,null);a.weight=i?(i.weight||0)+1:1,a.extra={...a.extra,...t.extra}},selectTabByReference(e,r){const t=[E.FileFolderType.DEBUGGER],a=r.payload;let i=e.tabs.find(({path:s})=>a.path===s);if((t.includes(a.type)||i!=null&&i.flags.confirmed)&&(a.flags={...a.flags,confirmed:!0}),!i){const s=e.tabs.findIndex(({flags:{confirmed:c}})=>c===!1);s!==-1&&!t.includes(a.type)?e.activeTab===e.tabs[s].path?(e.tabs[s]=a,i=e.tabs[s]):(e.tabs.push(a),i=e.tabs[e.tabs.length-1],e.tabs.splice(s,1)):(e.tabs.push(a),i=e.tabs[e.tabs.length-1])}if(e.activeTab!==a.path){const s=e.tabs.reduce((c,l)=>(l==null?void 0:l.weight)>((c==null?void 0:c.weight)||0)?l:c,null);e.activeTab=a.path,i.weight=((s==null?void 0:s.weight)||0)+1}i.extra={...i.extra,...a.extra},i.flags={...i.flags||{},...a.flags||{}}},setContent(e,r){const{path:t,content:a,contentPath:i}=r.payload;e.tabs=e.tabs.map(s=>{if(s.path!==t)return s;let c=!1,l=s.flags.confirmed;if(typeof a=="string")c=s.initialContent!==a,l=!l&&c?!0:l;else{const f=JSON.stringify(Ke.get(s.initialContent,i||"",s.initialContent)),p=JSON.stringify(Ke.get(a,i||"",a));c=f!==p,l=!l&&c?!0:l}return a&&typeof a=="object"&&(i?Ke.set(s.content,i,a):s.content=a),typeof a=="string"&&(s.content=a),{...s,flags:{...s.flags,touched:c,confirmed:l}}})},setTabFlags(e,r){const{path:t,flags:a}=r.payload;e.tabs=e.tabs.map(i=>i.path===t?{...i,flags:{...i.flags,...a}}:i)},setTabsFlags(e,r){const{tabs:t,flags:a}=r.payload;e.tabs=e.tabs.map(i=>t.includes(i.path)?{...i,flags:{...i.flags,...a}}:i)},setTabExtra(e,r){const{path:t,extra:a,flags:i}=r.payload;e.tabs=e.tabs.map(s=>s.path===t?{...s,extra:{...s.extra,...a},flags:i?{...s.flags,...i}:s.flags}:s)},addWebFormStyles(e,r){const{path:t,styles:a=[]}=r.payload,i=e.tabs.find(s=>s.path===t);if(i){const s=i.content.metadata.styles.map(({name:l})=>l),c=a.filter(({name:l})=>!s.includes(l));i.content.metadata.styles=[...i.content.metadata.styles,...c].map(({scope:l,...f})=>({...f}))}},changeTabEditor(e,r){return e.tabs=e.tabs.map(t=>t.path===r.payload.path?r.payload:t),e}},extraReducers:e=>{e.addCase(pc,(r,t)=>{if(t.payload.settingsKey==="studio.enablePreview"&&t.payload.value===!1){const a=r.tabs.find(({flags:{confirmed:i}})=>i===!1);a&&io.caseReducers.setTabFlags(r,{type:"",payload:{path:a.path,flags:{confirmed:!0}}})}}),e.addCase(av.fulfilled,(r,t)=>{if(!t.payload)return;const{content:a,line:i,path:s}=t.payload,c=r.tabs.find(l=>l.path===s);if(c&&typeof c.content=="string"){const l=c.content.trim().split(`
128
128
  `);l.splice(i,0,a),c.content=l.join(`
129
129
  `)}}),e.addCase(da.pending,(r,t)=>{const{tab:a}=t.meta.arg;switch(a.type){case E.FileFolderType.CLASS:case E.FileFolderType.METHOD:E.lspSubject.next({action:E.LspActions.WILL_SAVE,payload:{filePath:a.path}});break}}),e.addCase(da.fulfilled,(r,t)=>{if(!t.payload)return;const a=r.tabs.find(({path:i})=>{var s;return i===((s=t.payload)==null?void 0:s.path)});if(a){switch(a.content=t.payload.content,a.date=t.payload.date,a.initialContent=t.payload.initialContent,a.flags.touched=!1,a.flags.confirmed=!0,a.flags.old=!1,a.type){case E.FileFolderType.CLASS:case E.FileFolderType.METHOD:E.lspSubject.next({action:E.LspActions.DID_SAVE,payload:{filePath:a.path,content:a.content}});break}t.payload.errors.length>0&&E.toastSubject.next({kind:"error",message:t.payload.errors})}}),e.addCase(da.rejected,(r,t)=>{E.toastSubject.next({kind:"danger",message:"Cannot save file"})}),e.addCase(iv.fulfilled,(r,t)=>{const a=[...t.payload.files];r.tabs=r.tabs.map(i=>{if([E.FileFolderType.CLASS,E.FileFolderType.METHOD].includes(i.type)){const s=a.find(c=>c.name===i.name&&c.type===i.type);if(s){const c=new Date(i.date),l=new Date(s.date);if(c.getTime()!==l.getTime())return{...i,flags:{...i.flags,old:!0}}}}return i})}),e.addCase(mc.pending,(r,t)=>{r.tabs=r.tabs.map(a=>a.path===t.meta.arg.path?{...a,flags:{...a.flags,loading:!0}}:a)}),e.addCase(mc.fulfilled,(r,t)=>{const a=t.payload;if(a){const i=t.meta.arg;r.tabs=r.tabs.map(s=>{if(s.name===i.name&&s.type===i.type){const c=s.extra||{};return s.type===E.FileFolderType.METHOD?(c.attributes=E.parseAttributes(a.content),a.content=E.addAttributesToContent(a.content,{})):s.type===E.FileFolderType.SETTINGS&&(a.content={}),{...s,initialContent:a.content,content:a.content,date:a.date,flags:{},extra:c}}return s})}}),e.addCase(Zc.fulfilled,(r,t)=>{if(!t.payload)return;const{line:a,offset:i}=t.meta.arg,s=r.tabs.find(({path:c})=>{var l;return c===((l=t.payload)==null?void 0:l.path)});s&&(s.extra={...s.extra,initialLineInfo:{line:a,offset:i,lastModification:Date.now()}})}),e.addCase(ov.fulfilled,(r,t)=>{if(!t.payload)return;const{selection:a}=t.meta.arg,i=r.tabs.find(({path:s})=>{var c;return s===((c=t.payload)==null?void 0:c.path)});i&&(i.extra={...i.extra,initialSelectionInfo:{selection:a,lastModification:Date.now()}})}),e.addCase(fa.fulfilled,(r,t)=>{t.payload.new!==t.payload.old&&(r.tabs=[...r.tabs].map(a=>a.path===t.payload.old.path?{...a,path:t.payload.new.path,name:t.payload.new.name}:a),r.activeTab===t.payload.old.path&&(r.activeTab=t.payload.new.path))}),e.addCase(yc.pending,(r,t)=>{const a=t.meta.arg,i=`${a.path}${a.ext?`.${a.ext}`:""}`;switch(a.ext){case"4dm":case"4qs":E.lspSubject.next({action:E.LspActions.WILL_DELETE,payload:{filePath:i}});break}}),e.addCase(yc.fulfilled,(r,t)=>{const{deleted:a,node:i}=t.payload;if(!a)return;const s=`${i.path}${i.ext?`.${i.ext}`:""}`;switch(i.ext){case"4dm":case"4qs":E.lspSubject.next({action:E.LspActions.DID_DELETE,payload:{filePath:s}});break}if(r.tabs=r.tabs.filter(c=>c.path!==s),r.recent=r.recent.filter(({path:c})=>s!==c),r.tabs.length){r.activeTab=r.tabs[r.tabs.length-1].path;return}r.activeTab=""}),e.addCase(Za.fulfilled,(r,t)=>{const{draggedNode:a,newLocation:i}=t.meta.arg;if(r.tabs.find(s=>s.path===`${a.path}${a.ext?`.${a.ext}`:""}`))return r.tabs=r.tabs.map(s=>s.path===`${a.path}${a.ext?`.${a.ext}`:""}`?{...s,path:`${i.path}/${a.name}.${a.ext}`}:s),r.recent=r.recent.map(s=>s.path===`${a.path}${a.ext?`.${a.ext}`:""}`?{...s,path:`${i.path}/${a.name}.${a.ext}`}:s),r.activeTab=`${i.path}/${a.name}.${a.ext}`,r}),e.addCase(Fi.fulfilled,(r,t)=>{const a=r.tabs.find(i=>i.path===t.payload.path);a&&(a.flags.touched=!1,a.flags.confirmed=!0,a.date=t.payload.date,a.content=t.payload.content,a.initialContent=t.payload.content)}),e.addCase(sv.fulfilled,(r,t)=>{var s;if(!((s=t.payload)!=null&&s.path))return;const a=r.tabs.find(E.by("path",t.payload.path));if(!a)return;a.content=a.content+`
130
130