@ws-ui/store 0.0.29 → 0.0.31

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
@@ -96,7 +96,7 @@ The error may be correlated with this previous error:
96
96
  `:`Class extends Entity
97
97
  `};case"model":return{name:"DataStore",content:i?`extends DataStoreImplementation
98
98
  `:`Class extends DataStoreImplementation
99
- `}}};e.type==="dataclass"&&!e.toCreate?p=[{...g("dataclass")},{...g("collection")},{...g("entity")}]:e.type==="dataclass"&&e.toCreate?p=[{...g(e.toCreate)}]:p=[{...g("model")}],p=p.filter(_=>!d.find(({name:E,ext:x})=>E===_.name&&x===(i?"4qs":"4dm"))),await Promise.all(p.map(async({name:_,content:E})=>{await r(Kn({type:b.FileFolderType.CLASS,path:s,fileName:_,parentNode:c,content:E,qodly:a.settings.server.qodly}))})),await r(Sr(s))}),Sr=Q("explorer/fetchFolderContent",async(e,{rejectWithValue:r})=>{try{return(await b.getNodeInfo({verb:b.DesignerRequestVerb.GET_INFO,path:e})).map(a=>{const s=`${e}/${a.name}`,{editor:i,supportedEditors:c}=gr(`${s}${a.ext?`.${a.ext.toLowerCase()}`:""}`);return{name:a.name,size:a.size,type:a.type,date:`${a.date}`,flags:{},error:null,path:s,ext:a.ext,config:a.type==="folder"?{}:{editor:i,supportedEditors:c}}})}catch{return r("Failed loading file content please Reload")}},{getPendingMeta:()=>{}}),Ia=Q("explorer/fetchFolderContentWithoutExpanding",async(e,{rejectWithValue:r})=>{try{return(await b.getNodeInfo({verb:b.DesignerRequestVerb.GET_INFO,path:e})).map(a=>{const s=`${e}/${a.name}`,{editor:i,supportedEditors:c}=gr(`${s}${a.ext?`.${a.ext.toLowerCase()}`:""}`);return{name:a.name,size:a.size,type:a.type,date:`${a.date}`,flags:{},error:null,path:s,ext:a.ext,config:a.type==="folder"?{}:{editor:i,supportedEditors:c}}})}catch{return r("Failed loading file content please Reload")}},{getPendingMeta:()=>{}});function oD(e){const r=e.split(".");return r.pop(),{name:r.join("."),ext:e.split(".")[e.split(".").length-1]}}const sD=Q("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}}}),iD=Q("explorer/uploadFile",async({file:e,path:r,parentNode:t},{dispatch:a})=>{const{editor:s,supportedEditors:i}=gr(r),{name:c,ext:l}=oD(e.name);a(Kg({parent:t,child:{name:c,path:`${r}/${e.name}?t=${Date.now()}`,type:e.type,error:null,flags:{loading:!0},config:{editor:s,supportedEditors:i},ext:l}}));try{const d=await fetch(`/rest/$upload?$sharedFolder=true&$filename=${e.name}&$path=${r}`,{method:"POST",headers:{"Content-Type":e.type},body:e});return d.status>=300?(a(pc({parent:t,child:{name:c,path:`${r}/${e.name}`,type:e.type,error:{message:"error uploading file"},flags:{},config:{editor:s,supportedEditors:i},ext:l}})),d.status!==413&&b.toastSubject.next({message:"error uploading file",kind:"danger"})):await a(Sr(t.path)),{status:d.status,fileName:e.name}}catch{return a(pc({parent:t,child:{name:c,path:`${r}/${e.name}`,type:e.type,error:{message:"error uploading file"},flags:{},config:{editor:s,supportedEditors:i},ext:l}})),b.toastSubject.next({message:"error uploading file",kind:"danger"}),{status:500,fileName:e.name}}}),Kn=Q("explorer/createNewFile",async({fileName:e,type:r,path:t,parentNode:a,content:s},{dispatch:i,rejectWithValue:c,getState:l})=>{const{server:{qodly:d},project:p}=l().settings;try{const g=await b.setFileContent({name:Xg(e,r,d),content:s||Jg(r,p),path:t,asText:[b.FileFolderType.CLASS,b.FileFolderType.METHOD].includes(r)});return a.error&&(a.flags.expanded?await i(Sr(a.path)):await i(Ia(a.path))),{qodly:d,file:g,parentNode:a}}catch{return c("failed to create folder")}});function Qg(e,r){const{qodly:t=!0,withExtension:a=!0}=r||{},s=b.getFileExtentionFromType(e.type,t);let i="";switch(e.type){case b.FileFolderType.WEBFORM:i=`${b.FolderRootPath.WEBFORMS}/${e.name}`;break;case b.FileFolderType.METHOD:i=`${b.FolderRootPath.METHODS}/${e.name}`;break;case b.FileFolderType.CLASS:i=`${b.FolderRootPath.CLASSES}/${e.name}`;break;default:return""}return`${i}${a?`.${s}`:""}`}const uD=Q("explorer/createNewFileAndOpen",async(e,{dispatch:r,getState:t})=>{const a=await r(Kn(e)).unwrap(),{qodly:s}=t().settings.server;if(a){const{file:i}=a,c=Qg(i,{withExtension:!1,qodly:s}),{editor:l}=gr(c);await r(Fa({file:{name:e.fileName,type:i.type,path:c,editor:l,date:new Date().toISOString()}}))}}),ts=Q("explorer/createNewNode",async({fileName:e,path:r,parentNode:t},{rejectWithValue:a})=>{try{return{file:await b.createFolder({verb:b.DesignerRequestVerb.CREATE_FOLDER,path:`${r}/${e}`,recursive:!0}),parentNode:t}}catch{return b.toastSubject.next({message:"failed to create folder",kind:"danger"}),a("failed to create folder")}}),Ys=async(e,r=!0)=>{try{const t=e.path.split(".").at(-1),a=await b.getNodeInfo({verb:b.DesignerRequestVerb.GET_INFO,path:e.path,content:!0,as:Th(t)?"json":"text"}),s={editor:e.editor},i=b.getTypeFromExtension(e.path);i===b.FileFolderType.METHOD&&(s.attributes=b.parseAttributes(a.content),a.content=b.addAttributesToContent(a.content,{}));const{content:c,date:l,ext:d}=a;return{date:l,view:{panel:{isOpen:!1,type:"",current:""}},flags:{enabled:["WebForm","MForm"].includes(d),confirmed:r},extra:s,name:e.name,path:e.path,type:i,initialContent:c,content:c}}catch(t){const{data:a}=t;if(a.__ERROR.find(s=>s.errCode===b.ERROR_CODES.FILE_NOT_FOUND))switch(e.path){case b.ROLES_TAB_PATH:{const s={permissions:{allowed:[]},privileges:[],roles:[]};return{date:new Date().toISOString(),flags:{},extra:{editor:{key:"editors:roles"}},name:"Roles & Privileges",path:e.path,type:b.FileFolderType.ROLES,initialContent:s,content:s}}case b.SETTINGS_TAB_PATH:{const s={};return{date:new Date().toISOString(),flags:{},extra:{editor:{key:"editors:settings"}},name:"Settings",path:e.path,type:b.FileFolderType.SETTINGS,initialContent:s,content:s}}}throw t}},Fa=Q("explorer/openFile",async({file:e,inactive:r,flags:t={}},{getState:a,dispatch:s})=>{const{root:{tabs:i},roles:c,debugger:{sessions:l}}=a(),d=i.find(({path:m})=>e.path===m);if(d){const m={...d,extra:{...d==null?void 0:d.extra,editor:e.editor},flags:{...d==null?void 0:d.flags,...t}};return s(Dt(m)),m}if(e.path.startsWith("Debugger")){const m=l.find(_=>`Debugger/${_.threadId}`===e.path);if(m){const{source:{content:_},source:E}=m.currentStackFrame,x={name:e.name,type:b.FileFolderType.DEBUGGER,date:new Date().toISOString(),path:e.path,content:_,view:{panel:{isOpen:!1,type:"",current:""}},initialContent:_,flags:{confirmed:!0},extra:{source:E,editor:e.editor}};return s(Dt(x)),x}}let p=null;try{p=await Ys(e,t.confirmed)}catch(m){const{data:_}=m;if(_.__ERROR.find(E=>[b.ERROR_CODES.JSON_MALFORMED,b.ERROR_CODES.JSON_MALFORMED_AT_LINE].includes(E.errCode))){const{confirmed:E}=await s(sr({title:"Corrupt file",type:kt.CONFIRM,color:Tr.WARNING,message:"Open in code editor ?"})).unwrap();if(E){const x=await b.getNodeInfo({verb:b.DesignerRequestVerb.GET_INFO,path:e.path,content:!0,as:"text"}),{content:C,date:I,ext:P}=x;p={date:I,view:{panel:{isOpen:!1,type:"",current:""}},flags:{enabled:["WebForm","MForm"].includes(P),confirmed:!0},extra:{editor:b.EDITOR.Code},name:e.name,path:e.path,type:b.getTypeFromExtension(e.path),initialContent:C,content:C}}}}return p&&(e.path===b.ROLES_TAB_PATH&&!c.flags.touched?s(Yc({content:p.content,date:p.date})):e.path===b.SETTINGS_TAB_PATH&&s(zs({path:"project",value:p.content})),s((r?Fv:Dt)(p)),p)}),Jc=Q("explorer/openFileAtLine",async({file:e},{getState:r,dispatch:t})=>{const{tabs:a}=r().root,s=a.find(({path:c})=>e.path===c);if(s){const c={...s,extra:{...s==null?void 0:s.extra,editor:e.editor}};return t(Dt(c)),c}const i=await Ys(e);return t(Dt(i)),i}),ev=Q("explorer/injectContentAtLine",async(e,{getState:r,dispatch:t,rejectWithValue:a})=>{const s=r();e.path.split("/").pop();const c=ft(s.explorer,e.path);if(!c)return a(`Error while trying to inject content in file ${e.path}`);const l=await Ys({name:c.name,date:c.date||new Date().toISOString(),path:`${c.path}.${c.ext}`,type:b.FileFolderType.CLASS,editor:c.config.editor});return await t(Dt(l)),{...e,path:`${c.path}.${c.ext}`}}),tv=Q("explorer/openFileAtSelection",async({file:e},{getState:r,dispatch:t})=>{const{tabs:a}=r().root,s=a.find(({path:c})=>e.path===c);if(s){const c={...s,extra:{...s==null?void 0:s.extra,editor:e.editor}};return t(Dt(c)),c}const i=await Ys(e);return t(Dt(i)),i}),gc=Q("explorer/deleteFile",async e=>{const{name:r,type:t,path:a,flags:s}=e;if(s.error)return{deleted:!0,node:e};const i=a.split("/");return i.pop(),{deleted:await b.dropFile({root:b.FolderRootType.ROOT,type:Zg(t),verb:b.DesignerRequestVerb.DROP,name:r,path:i.join("/")}),node:e}}),cD=Q("explorer/deleteFolder",async e=>{const{path:r,flags:t}=e;if(t.error)return{deleted:!0,node:e};const{deleted:a}=await b.removeItem({force:!0,path:r,verb:b.DesignerRequestVerb.REMOVE_ITEM});return{deleted:a,node:e}}),lD=Q("explorer/removeFileNode",async(e,{getState:r,dispatch:t})=>{const a=`${e.path}.${e.ext}`;if(await b.removeItem({verb:b.DesignerRequestVerb.REMOVE_ITEM,path:a,force:!0}),e.path==="Classes/DataStore"&&setTimeout(()=>{t(On())},As),e.ext){const{tabs:s}=r().root,i=s.findIndex(c=>c.path===a);i>=0&&t(ol(i))}return{deleted:!0,node:e}}),Jn=Q("explorer/renameFile",async({file:e,newname:r})=>{if(e.type!=="folder"){const a=e.path.split("/");a.pop();const s=`${a.join("/")}/${e.name}.${e.ext}`,i=`${a.join("/")}/${r}.${e.ext}`;return await b.moveItem({verb:b.DesignerRequestVerb.MOVE_ITEM,path:s,newpath:i}),{old:{...e,path:s},new:{...e,name:r,path:i}}}const t=e.path.split("/");return t.pop(),await b.moveItem({verb:b.DesignerRequestVerb.MOVE_ITEM,path:`${t.join("/")}/${e.name}`,newpath:`${t.join("/")}/${r}`}),{old:e,new:{...e,name:r,path:`${t.join("/")}/${r}`}}}),$a=Q("explorer/relocateNode",async({draggedNode:e,newLocation:r},{rejectWithValue:t})=>{try{await b.moveItem({verb:b.DesignerRequestVerb.MOVE_ITEM,path:`${e.path}.${e.ext}`,newpath:`${r.path}/${e.name}.${e.ext}`})}catch{return t("can't move item")}}),rs=Q("explorer/duplicateNode",async({node:e,duplicateName:r},{rejectWithValue:t,fulfillWithValue:a,getState:s})=>{const i=e.path.split("/");i.pop();try{const{tabs:c}=s().root,l=c.find(({path:m})=>m===`${e.path}${e.ext?`.${e.ext}`:""}`),d=["4dm","4qm","4qs"].includes(e.ext),{content:p}=l||await b.getNodeInfo({verb:b.DesignerRequestVerb.GET_INFO,path:`${e.path}.${e.ext}`,content:!0,as:d?"text":"json"}),g=await b.setFileContent({name:`${r}.${e.ext}`,content:p,path:i.join("/"),asText:d});return a({node:{...g,path:i.join("/")}})}catch{return t("failed to duplicate file")}}),fD=Q("explorer/executeMethod",async({methodName:e,params:r=[],resultingDataSource:t={},namespace:a=""},{rejectWithValue:s})=>{var i,c;try{const d=await window.Method4D.buildMethod({methodName:e,parameters:r,resultingDataSource:t},{namespace:a},null).callServerSide({id:"",serverSideRef:""},"onclick",{});return d!=null&&d.__NOTIFICATION?b.toastSubject.next({message:`${((i=d.__NOTIFICATION)==null?void 0:i.message)||""}`,kind:`${((c=d.__NOTIFICATION)==null?void 0:c.type)||"info"}`}):b.toastSubject.next({message:"Method executed Successfully",kind:"message"}),d}catch(l){return b.toastSubject.next({message:l.message||`Error executing the method "**${e}**"`,kind:"danger",markdown:!0}),s("can't execute method")}}),dD=Q("files/fetchFiles",async()=>b.getFolders(b.FolderRootType.WEBFORMS,b.FolderRootType.METHODS,b.FolderRootType.CLASSES)),Xc=Q("tabs/renameDatasource",async(e,{dispatch:r,getState:t})=>{var E,x;const a=!!e.datasourceNamespace,{confirmed:s}=await r(sr({message:"Are you sure you want to rename the datasource?",title:"Rename Datasource",type:kt.CONFIRM,color:Tr.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(!s)return null;const{autoUpdateReferences:i,datasourceId:c,datasourceNamespace:l,value:d,path:p}=e,g=t();let m=[];if(a){const C=g.sharedDatasources.sources[l]||[];m.push(...C)}else if(p){const C=g.root.tabs.find(b.by("path",p));if(m=(x=(E=C==null?void 0:C.content)==null?void 0:E.metadata)==null?void 0:x.datasources,!m)return null}const _=new RegExp(`^${c}\\b`,"");if(m=m.map(C=>{const I=(b.isObjectDatasource(C)||!b.isSimpleDatasource(C))&&C.from&&_.test(C.from),P=C.events?C.events.map(j=>{var M,k,O,Y;switch(j==null?void 0:j.type){case"method":{const H=j;return H.params?{...H,params:H.params.map(z=>{var te;return{...z,datasource:(te=z.datasource)==null?void 0:te.replace(new RegExp(`^${c}`,""),d)}}),returns:(M=H.returns)!=null&&M.datasource?{...H.returns,datasource:(k=H.returns.datasource)==null?void 0:k.replace(new RegExp(`^${c}`,""),d)}:H.returns}:H}case"simple-action":{const H=j;return H.datasource?{...H,datasource:{...H.datasource,name:(O=H.datasource.name)==null?void 0:O.replace(new RegExp(`^${c}`,""),d),from:(Y=H.datasource.from)==null?void 0:Y.replace(new RegExp(`^${c}`,""),d)}}:H}default:return j}}):C.events;return C.id===c?{...C,id:d,events:P}:I&&C.from?{...C,from:C.from.replace(new RegExp(`^${c}`,""),d),events:P}:{...C,events:P}}),i){const C=a?`${l}:${c}`:`${c}`,I=a?`${l}:${d}`:`${d}`;b.datasourcesSubject.next({path:p??"",action:b.DatasourcesActions.RENAME,old_reference:C,new_reference:I,is_shared:a})}return{path:p,namespace:l,datasources:m}}),Zc=Q("tabs/edit-datasource",(e,{getState:r})=>{var i,c;const t=r();let a=[];if(e.namespace)a=t.sharedDatasources.sources[e.namespace];else{const l=t.root.tabs.find(b.by("path",e.path));l&&(a=((c=(i=l.content)==null?void 0:i.metadata)==null?void 0:c.datasources)||[])}return a.map(l=>l.id===e.datasourceId?Object.assign({},l,{[e.propertyKey]:e.value}):l)}),rv=Q("tabs/fetchChanges",async(e,{getState:r})=>{const a=sa(r()).filter(s=>[b.FileFolderType.METHOD,b.FileFolderType.CLASS].includes(s.type));return b.getFilesInfo(...a.map(s=>{const[i]=s.path.split("/").filter(Boolean);return{name:s.name,type:s.type,root:i,path:"."}}))}),pD=Q("files/saveAll",async(e,{getState:r,dispatch:t})=>{const a=Nc(r());for(const s of a)t(Xn({tab:s}))}),Qc=Q("files/tryCloseTab",async(e,{getState:r,dispatch:t})=>{const{tabs:a}=r().root,s=a.findIndex(c=>c.path===e);if(s===-1)return!1;const i=a[s];if(i!=null&&i.flags.touched){const{confirmed:c}=await t(sr({title:Ps(i),message:"Your unsaved changes will be lost. Proceed anyway?",type:kt.CONFIRM,color:Tr.WARNING,icon:"AiFillWarning"})).unwrap();if(!c)return!1}return t(ol(s)),i.path===b.ROLES_TAB_PATH&&i.flags.touched&&(async()=>{const l=await b.getNodeInfo({verb:b.DesignerRequestVerb.GET_INFO,path:b.ROLES_TAB_PATH,content:!0,as:"json"});t(Yc({content:l.content,date:l.date}))})(),!0}),hD=Q("files/tryCloseOtherTabs",async(e,{getState:r,dispatch:t})=>{const{tabs:a}=r().root;if(a.some(i=>i.path!==e&&i.flags.touched===!0)){const{confirmed:i}=await t(sr({title:"Closing other tabs",message:"Your changes will be lost if you do not save them. Close anyway?",type:kt.CONFIRM,color:Tr.WARNING,icon:"AiFillWarning"})).unwrap();if(!i)return}t(Pv(e))}),gD=Q("files/tryCloseAllTabs",async(e,{getState:r,dispatch:t})=>{const{tabs:a}=r().root;if(a.some(i=>i.flags.touched===!0)){const{confirmed:i}=await t(sr({title:"Closing all tabs",message:"Your changes will be lost if you do not save them. Close anyway?",type:kt.CONFIRM,color:Tr.WARNING,icon:"AiFillWarning"})).unwrap();if(!i)return}t(Ov())}),vD=Q("files/tryCloseRightTabs",async(e,{getState:r,dispatch:t})=>{const{tabs:a}=r().root;let s=!1;for(let i=a.length-1;i>e;i-=1)if(a[i].flags.touched){s=!0;break}if(s){const{confirmed:i}=await t(sr({title:"Closing right tabs",message:"Your changes will be lost if you do not save them. Close anyway?",type:kt.CONFIRM,color:Tr.WARNING,icon:"AiFillWarning"})).unwrap();if(!i)return}t(Av(e))}),mD=Q("files/tryCloseLeftTabs",async(e,{getState:r,dispatch:t})=>{const{tabs:a}=r().root;let s=!1;for(let i=0;i<e;i+=1)if(a[i].flags.touched){s=!0;break}if(s){const{confirmed:i}=await t(sr({title:"Closing left tabs",message:"Your changes will be lost if you do not save them. Close anyway?",type:kt.CONFIRM,color:Tr.WARNING,icon:"AiFillWarning"})).unwrap();if(!i)return}t(Dv(e))}),vc=Q("files/reloadTab",async(e,{dispatch:r})=>{if(e.flags.touched){const{confirmed:s}=await r(sr({title:Ps(e),message:"Changes made to the file will be lost. Continue?",type:kt.CONFIRM,color:Tr.WARNING,icon:"AiFillWarning"})).unwrap();if(!s)return}const t=zh(e.path),a=await b.getNodeInfo({verb:b.DesignerRequestVerb.GET_INFO,path:e.path,content:!0,as:t});if(e.path===b.ROLES_TAB_PATH){const{roles:s,privileges:i}=Hs(a.content);r(Vc({roles:s,privileges:i}))}else if(e.path===b.SETTINGS_TAB_PATH){const{content:s}=a;r(zs({path:"project",value:s}))}else{const{content:s}=a;e.type===b.FileFolderType.WEBFORM?b.webformSubject.next({path:e.path,action:b.WebformActions.RELOAD,payload:s.components}):e.type===b.FileFolderType.MODEL&&Qh.next({action:"reload",payload:s})}return a}),Xn=Q("files/saveTab",async({tab:e},{dispatch:r,getState:t})=>{const{path:a,content:s}=e;if(e.type===b.FileFolderType.DEBUGGER)return{...e,errors:[]};a.split("/").pop();const c=await b.getFilesInfo({path:a});if(c.files[0]){const g=new Date(e.date),m=new Date(c.files[0].date);if(g.getTime()<m.getTime()){const{confirmed:_}=await r(sr({title:Ps(e),message:"New content has been found on the server. Are you sure you want to continue?",type:kt.CONFIRM,icon:"FaSave"})).unwrap();if(!_)return r(Rv({path:a,flags:{old:!0}})),null}}const l=await b.saveContent({verb:b.DesignerRequestVerb.SAVE_CONTENT,content:yD(e,t()),path:a});(e.type===b.FileFolderType.CLASS||e.type===b.FileFolderType.MODEL)&&setTimeout(()=>{r(On())},As);const d=(l.modelErrors||[]).map(g=>g.message),p=(l.permissionsErrors||[]).map(g=>g.message);return{...e,content:s,date:l.date,initialContent:s,errors:d.length>0||p.length>0?[{title:"Model errors",messages:d},{title:"Permissions errors",messages:p}]:[]}}),yD=(e,r)=>{switch(!0){case e.path==="settings.json":case e.path===b.SETTINGS_TAB_PATH:return r.settings.project;case e.type===b.FileFolderType.ROLES:return Gs(r.roles);case e.type===b.FileFolderType.MODEL:return e.content||{toJSON:!0,dataClasses:[],extraProperties:{}};default:return e.content}},Hp=async e=>{if(e.type===b.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 b.getFile({root:r,type:e.type,verb:b.DesignerRequestVerb.GET,name:e.name}),a={};t.type===b.FileFolderType.METHOD&&(a.attributes=b.parseAttributes(t.content));const{date:s,name:i,type:c,content:l}=t;return{date:s,flags:{enabled:e.type===b.FileFolderType.WEBFORM},extra:a,view:{panel:{isOpen:!1,type:"",current:""}},name:i,path:e.path,type:c,initialContent:l,content:c===b.FileFolderType.MODEL?wh(l):l}},nv=Q("files/tryInjectMethod",async({type:e,dataclass:r},{getState:t,dispatch:a})=>{const{root:{tabs:s},settings:{server:{qodly:i}}}=t(),c=b.getFileExtentionFromType("class",i);let l="",d="",p=null;if(!r)l="DataStore",d=`Classes/DataStore.${c}`;else switch(e){case"dataclass":l=r,d=`Classes/${r}.${c}`;break;case"collection":l=`${r}Selection`,d=`Classes/${r}Selection.${c}`;break;case"entity":l=`${r}Entity`,d=`Classes/${r}Entity.${c}`;break;default:return p}const g=s.find(b.by("path",d));if(g)return a(Dt(g)),g;try{p=await Hp({name:l,date:new Date().toISOString(),path:`class/${l}.${c}`,type:b.FileFolderType.CLASS})}catch{r?await a(hc({type:"dataclass",className:r,collectionName:`${r}Selection`,toCreate:e})):await a(hc({type:"model"}))}return p=await Hp({name:l,date:new Date().toISOString(),path:`class/${l}.${c}`,type:b.FileFolderType.CLASS}),p.path=d,a(Dt(p)),p}),bD=Q("roles/open",async(e,{dispatch:r,getState:t})=>{const{tabs:a}=t().root,s=a.find(i=>i.path===b.ROLES_TAB_PATH);if(s)return r(Dt(s)),s;r(Ss())});function Gp(e,r){const{line:t,offset:a,type:s="saved"}=r;e.breakpoints[s].locations.push({line:t}),He.isNumber(a)&&(e.breakpoints[s].offset=a)}function qp(e,r,t,a){e.breakpoints[t].locations=r,He.isNumber(a)&&(e.breakpoints[t].offset=a)}function zp({filePath:e,fileType:r,methodName:t,className:a,ext:s,source:i}){return{filePath:e,fileType:r,methodName:t,className:a,ext:s,source:i,breakpoints:{draft:{locations:[],offset:0},saved:{locations:[],offset:0}}}}function Yp(e,r,t){let a=!1;const s=e.map(i=>i[t]!==r[t]?i:(a=!0,{...i,...r}));return a?s:[...s,r]}function Xo(e){return e.map(({label:r})=>({label:r}))}const av=or({name:"debugger",initialState:()=>{var r,t;const{debugger:e={meta:{state:Mr.DETACHED},list:[],sessions:[],expressions:[]}}=ea();return{meta:{...e.meta,state:((r=e.meta)==null?void 0:r.state)===Mr.ATTACHED?(t=e.meta)==null?void 0:t.state:Mr.DETACHED},list:e.list||[],sessions:e.sessions||[],expressions:e.expressions||[]}},reducers:{addBreakpointDecoration(e,r){const{filePath:t,fileType:a,methodName:s,className:i,ext:c,source:l,breakpoint:d}=r.payload,p=Rn(e.list,t,s,i);if(p)Gp(p,d);else{if(a===b.FileFolderType.CLASS&&d.offset===void 0)throw new Error(`Cannot add a breakpoint on a function without offset. Try editing the ${i} class.`);const g=zp({filePath:t,fileType:a,methodName:s,className:i,ext:c,source:l});Gp(g,d),e.list.push(g)}},removeBreakpointDecoration(e,r){const{filePath:t,methodName:a,line:s,offset:i=0,type:c="saved"}=r.payload;if(t.startsWith("Classes/")){const l=e.list.filter(d=>d.filePath===t);if(l.length>0){const d=s+i;l.forEach(p=>{const g=p.breakpoints[c].offset||0;p.breakpoints[c].locations=p.breakpoints[c].locations.filter(m=>m.line+g!==d),c==="saved"&&(p.breakpoints.draft.locations=p.breakpoints.draft.locations.filter(m=>m.line+g!==d))})}}else{const l=Rn(e.list,t,a);l&&(l.breakpoints[c].locations=l.breakpoints[c].locations.filter(d=>d.line!==s),c==="saved"&&(l.breakpoints.draft.locations=l.breakpoints.draft.locations.filter(d=>d.line!==s)))}},setBreakpointsDecoration(e,r){const{filePath:t,fileType:a,methodName:s,className:i,ext:c,source:l,breakpoints:d,offset:p,type:g="saved",clearDraft:m}=r.payload,_=Rn(e.list,t,s);if(_)qp(_,d,g,p),m&&g!=="draft"&&(_.breakpoints.draft.locations=[]);else{const E=zp({filePath:t,fileType:a,methodName:s,className:i,ext:c,source:l});qp(E,d,g,p),e.list.push(E)}},clearBreakpoints(e,r){const{filePath:t,type:a="saved"}=r.payload;e.list=e.list.map(s=>({...s,breakpoints:s.filePath===t?{draft:!a||a==="draft"?{locations:[],offset:0}:s.breakpoints.draft,saved:!a||a==="saved"?{locations:[],offset:0}:s.breakpoints.saved}:s.breakpoints}))},setActiveLine(e,r){const{threadId:t,line:a,highlight:s}=r.payload,i=st(e.sessions,t);i&&(i.activeLine=a,s&&(i.highlightedLines={start:a,end:a}))},addExpression(e,r){const{threadId:t,label:a,save:s}=r.payload,i=st(e.sessions,t);i&&i.stopped&&(i.expressions=[...i.expressions||[],{label:a}],s&&(e.expressions=Xo(i.expressions)))},removeExpression(e,r){const{threadId:t,index:a,save:s}=r.payload,i=st(e.sessions,t);i&&(i.expressions=i.expressions.filter((c,l)=>l!==a),s&&(e.expressions=Xo(i.expressions)))},removeAllExpressions(e,r){const{threadId:t,save:a}=r.payload,s=st(e.sessions,t);s&&(s.expressions=[],a&&(e.expressions=[]))},renameExpression(e,r){const{threadId:t,index:a,replacement:s,save:i}=r.payload,c=st(e.sessions,t);c&&c.expressions[a]&&(c.expressions[a].label=s,i&&(e.expressions=Xo(c.expressions)))},setExpression(e,r){const{threadId:t,expression:a}=r.payload,s=st(e.sessions,t);if(s){const i=a.index>=0?a.index:s.expressions.length>0?s.expressions.length-1:0,c=s.expressions[i];c?(c.result=a.result,c.nakedResult=a.nakedResult,c.variablesReference=a.variablesReference||0,c.presentationHint=a.presentationHint):s.expressions.push(a)}},updateExpressionAt(e,r){const{threadId:t,index:a,value:s}=r.payload,i=st(e.sessions,t);if(i){const c=i.expressions[a];c&&(c.result=`"${s}"`,c.nakedResult=s)}},saveExpressions(e,r){const{expressions:t}=r.payload;e.expressions=Xo(t)},addSession(e,r){const{threadId:t,channelId:a,stackFrames:s,exceptions:i=[]}=r.payload,c=st(e.sessions,t),l=s[0],{expressions:d=[]}=e;if(c)c.expressions=d;else{const p=Dc(t);e.sessions.push({tabPath:p,threadId:t,channelId:a,stackFrames:s,currentStackFrame:l,exceptions:i,expressions:d,variables:{callchain:[],expressions:[]},highlightedLines:null,activeLine:null,stopped:!0})}},updateSession(e,r){const{threadId:t,changes:a}=r.payload;e.sessions=e.sessions.map(s=>s.threadId===t?{...s,...a}:s)},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:s}=r.payload;e.sessions=e.sessions.map(i=>{var c;return i.threadId===t?{...i,variables:{...i.variables,callchain:Yp((c=i.variables)==null?void 0:c.callchain,{frameId:a,items:s},"frameId")}}:i})},setExpressionVariables(e,r){const{threadId:t,variablesReference:a,variables:s}=r.payload;e.sessions=e.sessions.map(i=>{var c;return i.threadId===t?{...i,variables:{...i.variables,expressions:Yp((c=i.variables)==null?void 0:c.expressions,{variablesReference:a,items:s},"variablesReference")}}:i})},setSourceContent(e,r){const{threadId:t,content:a}=r.payload,s=st(e.sessions,t);s&&(s.currentStackFrame.source={...s.currentStackFrame.source,content:a})},setDebuggerMeta(e,r){if(r.payload.state===Mr.ERROR){e.meta.error={...e.meta.error,time:Date.now()};const{override:t,error:a={code:null,reason:"",type:ds.SOCKET_ERROR}}=r.payload;if((t||e.meta.state!==Mr.ERROR)&&(e.meta.error={...e.meta.error,...a}),(a==null?void 0:a.type)===ds.SOCKET_CLOSURE&&!(a!=null&&a.reason)&&e.meta.state===Mr.DETACHED)return}e.meta.state=r.payload.state}},extraReducers:e=>{e.addCase(sv.fulfilled,r=>{r.sessions=[]})}}),{addBreakpointDecoration:_D,removeBreakpointDecoration:ED,setBreakpointsDecoration:SD,clearBreakpoints:wD,setActiveLine:TD,addExpression:xD,renameExpression:CD,removeExpression:RD,removeAllExpressions:OD,setExpression:AD,updateExpressionAt:PD,saveExpressions:DD,addSession:ID,updateSession:FD,removeSession:$D,removeSessionByIndex:MD,setSessions:ov,setCallChainVariables:ND,setExpressionVariables:LD,setSourceContent:kD,setDebuggerMeta:jD}=av.actions,sv=Q("files/wipeDebuggerSessions",async(e,{getState:r,dispatch:t})=>{const{sessions:a}=r().debugger;for(const{threadId:s}of a){const i=Dc(s);t(Qc(i))}}),iv=Q("files/removeDebuggerSessionsNotIn",async(e,{getState:r,dispatch:t})=>{const{threadIds:a}=e,{sessions:s}=r().debugger,i=[],c=s.filter(l=>{const d=a.includes(l.threadId);return d||i.push(l.threadId),d});return t(ov(c)),{staleThreadIds:i}});var el=(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))(el||{}),Lr=(e=>(e.STORAGE="storage",e.RELATEDENTITY="relatedEntity",e.RELATEDENTITIES="relatedEntities",e.CALCULATED="calculated",e.COMPOSITION="composition",e.ALIAS="alias",e))(Lr||{});const BD=e=>["string","uuid","number","long"].includes(e.type),WD=[{label:"Storage",value:"storage"},{label:"Calculated",value:"calculated"}],UD=[{title:"UUID",kind:"storage",value:"uuid",calculatedType:"uuid",calculatedKind:"storage"},{title:"Long",kind:"storage",value:"long",calculatedType:"long",calculatedKind:"storage"}],HD=[{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"}],GD=[{label:"Expose as REST",value:"public"},{label:"Do not expose as REST",value:"publicOnServer"}],qD=[{label:"Expose as REST",value:"public"},{label:"Do not expose as REST",value:"publicOnServer"}],zD=[{label:"None",value:"none"},{label:"B-tree",value:"btree"},{label:"Cluster",value:"cluster"},{label:"Automatic",value:"auto"}],uv=Pt("model/add-dataclass"),cv=Pt("model/rename-dataclass"),lv=Pt("model/remove-dataclass"),fv=Pt("model/add-attribute"),YD=Pt("model/edit-attribute-property"),dv=Pt("model/remove-attribute"),pv=Pt("model/rename-attribute"),hv=Pt("model/edit-primary-key"),VD=Pt("model/edit-dataclass-property"),gv=Pt("model/rename-collection"),KD=(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 ns(e,r,t){const a=e;let s=0;for(;t[`${a}${s||""}`];)s++;return`${a}${s||""}`}const Ma=e=>e.kind===Lr.RELATEDENTITY,ws=e=>e.kind===Lr.RELATEDENTITIES,JD=e=>ws(e)||Ma(e),tl=Q("models/fetch",async()=>{try{return(await b.http(b.API_PREFIX,{method:"POST",body:JSON.stringify({verb:b.DesignerRequestVerb.GET_INFO,path:b.MODEL_TAB_PATH,as:"json",content:!0}),headers:new Headers({"Content-Type":"application/json"})})).content}catch(e){return e.message}}),Ts=Q("models/save",async(e,{getState:r,dispatch:t,rejectWithValue:a})=>{const{tabs:s}=r().root,i=s.find(c=>c.path===b.MODEL_TAB_PATH);if(!i)return a("Error while saving the model");try{const c=await b.http(b.API_PREFIX,{method:"POST",body:JSON.stringify({verb:"save",path:i.path,content:i.content}),headers:new Headers({"Content-Type":"application/json"})});return setTimeout(()=>{t(On())},As),{...c,path:i.path,content:e.content||{toJSON:!0,dataClasses:[],extraProperties:{}}}}catch{return a("Error while saving the model")}}),XD=Q("models/open",async(e,{dispatch:r,getState:t})=>{const{tabs:a}=t().root,s=a.find(i=>i.path==="models/main");if(s)return r(Dt(s)),s;r(tl())}),ZD=Q("model/rename-dataclass",async(e,{getState:r,dispatch:t})=>{var m,_;const{dataclassId:a,selectionId:s,name:i}=e;let c=r();const l=c.explorer.find(E=>E.path===b.FolderRootPath.CLASSES);if(!l)throw new Error("Classes folder was not found!");await t(Sr(l.path)),c=r();const d={class:{found:!1,newNameTaken:!1,file:null,filename_update:i},entity:{found:!1,newNameTaken:!1,file:null,filename_update:`${i}Entity`},selection:{found:!1,newNameTaken:!1,file:null,filename_update:`${i}Selection`}};(_=(m=c.explorer.find(E=>E.path===b.FolderRootPath.CLASSES))==null?void 0:m.children)==null||_.forEach(E=>{E.name===d.class.filename_update&&(d.class.newNameTaken=!0),E.name===d.entity.filename_update&&(d.entity.newNameTaken=!0),E.name===d.selection.filename_update&&(d.selection.newNameTaken=!0),E.name===a?(d.class.found=!0,d.class.file=E):E.name===`${a}Entity`?(d.entity.found=!0,d.entity.file=E):E.name===s&&(d.selection.found=!0,d.selection.file=E)});const p=Object.entries(d).reduce((E,x)=>{const[C,I]=x;return I.found?I.newNameTaken?[...E,{type:"error",message:`Cannot rename ${C} file to ${I.filename_update} because it already exists. The existing file will be used instead!`}]:E:[...E,{type:"warning",message:`${a} ${C} file was not found`}]},[]);p.length>0&&t(sr({message:"The following errors were encountered during dataclass rename:",views:{tips:p}}));const g=Object.values(d).filter(E=>E.found&&E.file&&!E.newNameTaken);await Promise.all(g.map(async E=>await t(Jn({file:E.file,newname:E.filename_update})))),g.length>0&&t(Sr("Classes"))}),Wa={DATACLASS_DELETE:"dataclass.delete",DATACLASS_DRAGGABLE:"dataclass.draggable"},QD={model:{dataClasses:{},collections:{},extraProperties:{}},draft:{dataClasses:{},collections:{},extraProperties:{}},flags:{[Wa.DATACLASS_DELETE]:!0,[Wa.DATACLASS_DRAGGABLE]:!0}},vv=or({name:"Models",initialState:QD,reducers:{setModelFlag(e,r){e.flags={...e.flags,...r.payload}}},extraReducers(e){e.addCase(uv,({draft:{dataClasses:r}},t)=>{var c,l;const{dataclassID:a}=t.payload,s=ns(a||"DataClass","className",r),i={className:s,collectionName:`${s}Selection`,attributes:[{name:"ID",kind:Lr.STORAGE,type:el.LONG,scope:"public",indexKind:"auto",unique:!0,primKey:!0,autosequence:!0}],name:s,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[i.name]=i}).addCase(lv,({draft:{dataClasses:r}},t)=>{const{dataclassID:a}=t.payload;r[a]&&(delete r[a],Object.values(r).forEach(i=>{i.attributes=i.attributes.filter(c=>c.type!==a&&c.type!==i.collectionName)}))}).addCase(cv,({draft:{dataClasses:r,collections:t}},a)=>{const{dataclassID:s,newName:i}=a.payload;if(!r[s]||r[i])return;const c=r[s].collectionName,l=ns(`${i}Selection`,"collectionName",t);Object.values(r).forEach(d=>{d.className===s&&(d.className=i,d.name=i,d.collectionName=l),d.attributes.forEach(p=>{p.type===s?(p.type=i,p.path=i):p.type===c&&(p.type=l)})})}).addCase(fv,({draft:{dataClasses:r}},t)=>{const{dataclassID:a,attributeName:s,attributeType:i,attributeKind:c,target:l}=t.payload;if(!r[a]||b.exists("name",s,r[a].attributes))return;const p={name:s,kind:c,type:i,exposed:!0,scope:"public"};if(c===Lr.RELATEDENTITY){if(!r[i])return;p.path=i;const m={name:ns(r[i].collectionName,"name",r[i].attributes),type:r[a].collectionName,kind:Lr.RELATEDENTITIES,reversePath:!0,path:s,scope:"public",exposed:!0};r[i].attributes.push(m)}else if(c===Lr.RELATEDENTITIES){const g=r[i];if(!g)return;const m=g.attributes.find(b.by("name",l));if(m){if(!Ma(m)||m.type!==r[a].className)return}else{p.path=l,p.reversePath=!0,p.type=i;const _={name:l,kind:Lr.RELATEDENTITY,scope:"public",path:g.className,type:g.className,exposed:!0};g.attributes.push(_)}}r[a].attributes.push(p)}).addCase(pv,({draft:{dataClasses:r}},t)=>{const{dataclassID:a,attributeID:s,newName:i}=t.payload,c=r[a].attributes.find(b.by("name",s)),l=r[a].attributes.find(b.by("name",i));!c||l||Object.values(r).forEach(({collectionName:d,attributes:p,className:g})=>{p.forEach(m=>{Ma(c)&&ws(m)&&m.type===d&&m.path===s&&(m.path=i),g===a&&m.name===s&&(m.name=i)})})}).addCase(dv,({draft:{dataClasses:r}},t)=>{const{dataclassID:a,attributeID:s}=t.payload;if(!r[a])return;const i=r[a].attributes.find(b.by("name",s));i&&(Ma(i)&&Object.values(r).forEach(c=>{c.attributes=c.attributes.filter(l=>!(ws(l)&&l.type===c.collectionName&&l.path===i.name))}),r[a].attributes=r[a].attributes.filter(b.outBy("name",s)))}).addCase(gv,({draft:{dataClasses:r,collections:t}},a)=>{const{dataclassID:s,collectionName:i}=a.payload;if(!r[s])return;const c=r[s].collectionName;t[i]||(r[s].collectionName=i,t[i]=r[s],delete t[c],Object.values(r).forEach(l=>l.attributes.forEach(d=>{d.type===c&&(d.type=i)})))}).addCase(hv,({draft:{dataClasses:r}},t)=>{const{dataclassID:a,newPrimKey:s}=t.payload;r[a]&&r[a].attributes.forEach(i=>{i.name===s?i.primKey=!0:i.primKey=!1})}),e.addCase(tl.fulfilled,(r,t)=>{var c;const a={},s={},i=t.payload.extraProperties||{};(c=t.payload.dataClasses)==null||c.forEach(l=>{a[l.name]=l,s[l.collectionName]=l}),r.draft.dataClasses=a,r.draft.collections=s,r.draft.extraProperties=i,r.model.dataClasses=a,r.model.collections=s,r.model.extraProperties=i}),e.addCase(Ts.pending,()=>{}).addCase(Ts.fulfilled,(r,t)=>{const a={},s={},i=t.payload.content.extraProperties||{};t.payload.content.dataClasses.forEach(c=>{a[c.name]=c,s[c.collectionName]=c}),r.draft.dataClasses=a,r.draft.collections=s,r.draft.extraProperties=i,r.model.dataClasses=a,r.model.collections=s,r.model.extraProperties=i})}}),{setModelFlag:eI}=vv.actions,tI=()=>Ur(e=>e.model.draft.dataClasses),rI=()=>Ur(e=>e.model.draft.collections),nI=e=>Ur(r=>r.model.draft.dataClasses[e]),aI=(e,r)=>Ur(t=>t.model.draft.dataClasses[e].attributes.find(b.by("name",r))),oI=()=>Ur(e=>e.model.draft.extraProperties),sI=()=>{const e=Ur(s=>s.model.flags),r=s=>s in e?e[s]:void 0,t=r(Wa.DATACLASS_DELETE),a=r(Wa.DATACLASS_DRAGGABLE);return{deleteDataclass:t,draggableDataclass:a,flags:e}},iI=vv.reducer;function Uu(e,r){const t=e.tabs.find(({path:a})=>a===b.SETTINGS_TAB_PATH);t&&(t.flags.touched=r)}const mv={SIDEBAR_SECTION_RESIZABLE:"sidebar.section.resizable"},yv={[mv.SIDEBAR_SECTION_RESIZABLE]:!0},bv=or({name:"webforms",initialState:()=>{const{webforms:e}=ea();return{...e,templates:{data:[],selectedGroup:""},datasources:{...Ac.webforms.datasources,...e==null?void 0:e.datasources},flags:yv}},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(s=>s.id===t?{...s,...a}:s)},removeComponent:(e,r)=>{const{payload:t}=r,a=e.components.findIndex(s=>s.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,s=e.templates.data.find(i=>i.group===t);s&&(s.components=a)},setDatasourcesTheme:(e,r)=>{e.datasources.theme=r.payload},setWebformsFlag(e,r){e.flags={...e.flags,...r.payload}}},extraReducers(e){e.addCase(xv.fulfilled,(r,t)=>{r.components=t.payload})}}),{toggleInspector:uI,inspect:cI,addComponent:_v,editComponent:Ev,removeComponent:Sv,setSelectedGroup:lI,setTemplatesData:wv,setTemplateData:Tv,setDatasourcesTheme:fI,setWebformsFlag:dI}=bv.actions,pI=bv.reducer,rl=He.curry((e,r)=>{var s,i;const t={...r.sharedDatasources.sources},a=(i=((s=r.root.tabs.find(b.by("path",e)))==null?void 0:s.content).metadata)==null?void 0:i.datasources;return a&&(t[e]=a),He.cloneDeep(t)}),hI=Q("webforms/fetchTemplates",async(e,{dispatch:r,getState:t})=>{const{data:a}=t().webforms.templates,s=t().settings.session["studio.tipsBaseUrl"]||"";if(!He.isEmpty(a))return a;try{const c=await(await fetch(`${s}/build/index.json?t=${Date.now()}`)).json();return r(wv(c)),c}catch{return[]}}),gI=Q("webforms/fetchTemplate",async({name:e},{dispatch:r,getState:t})=>{const{data:a}=t().webforms.templates,s=a.find(i=>i.group===e);if(s&&!He.isEmpty(s.components))return s.components;try{const c=await(await fetch(`${s==null?void 0:s.link}?t=${Date.now()}`)).json();return r(Tv({group:e,components:c})),c}catch{return[]}}),xv=Q("webforms/fetchCraftedComponents",async(e,{rejectWithValue:r})=>{try{return(await b.getNodeInfo({path:"WebForms/crafted_components.json",verb:b.DesignerRequestVerb.GET_INFO,content:!0,as:"json"})).content}catch{return r("Error while loading the crafted components")}}),vI=Q("webforms/addCraftedComponent",async(e,{dispatch:r,rejectWithValue:t,getState:a})=>{try{r(_v(e));const{webforms:{components:s}}=a();b.setCraftedComponents(s)}catch{return t("Error while adding the crafted component")}}),mI=Q("webforms/editCraftedComponent",async(e,{dispatch:r,rejectWithValue:t,getState:a})=>{try{r(Ev(e));const{webforms:{components:s}}=a();b.setCraftedComponents(s)}catch{return t("Error while editing the crafted component")}}),yI=Q("webforms/removeCraftedComponent",async(e,{dispatch:r,rejectWithValue:t,getState:a})=>{try{r(Sv(e));const{webforms:{components:s}}=a();b.setCraftedComponents(s)}catch{return t("Error while removing the crafted component")}}),nl=Q("datasources/add-datasource",async(e,{getState:r,rejectWithValue:t})=>{var a,s;try{const i=r(),c=e.datasource,l=!!c.namespace,d=[];if(l){const p={...i.sharedDatasources.sources,[c.namespace]:[...i.sharedDatasources.sources[c.namespace],c]};d.push(...p[c.namespace]),await b.setSharedSources(p)}else(((s=(a=i.root.tabs.find(b.by("path",e.path)).content)==null?void 0:a.metadata)==null?void 0:s.datasources)||[]).push(c);return{list:d,path:e.path,namespace:e.datasource.namespace}}catch{console.error("Error while adding the datasource",e.datasource.id),t("Error while adding the datasource")}}),al=Q("datasources/edit-datasource",async(e,{getState:r,rejectWithValue:t})=>{try{const{namespace:a,path:s}=e,i=r(),c=!!e.namespace,l=rl(s,i);let d=He.defaultTo(l[a||s],[]);return d=d.map(p=>p.id===e.id?{...p,[e.property]:e.value}:p),c&&await b.setSharedSources({...i.sharedDatasources.sources,[e.namespace]:d}),{list:d,path:e.path,namespace:e.namespace}}catch{t(`Error while editing datasource ${e.id}`)}}),bI=e=>e.type===Zn.fulfilled.type,Zn=Q("datasources/rename-datasource",async(e,{getState:r,rejectWithValue:t})=>{try{const a=r(),s=!!e.namespace,i=e.namespace||e.path,c=rl(e.path,a),l=He.defaultTo(c[i],[]),d=new RegExp(`^${e.id}\\b`,"");if(l.forEach(p=>{var m;const g=(b.isObjectDatasource(p)||!b.isSimpleDatasource(p))&&p.from&&d.test(p.from);e.updateRefs&&((m=p.events)==null||m.forEach(_=>{var E,x,C,I,P;switch(_.type){case"method":{const j=_;j.params.forEach(M=>{M.datasource&&Object.assign(M,{datasource:M.datasource.replace(new RegExp(`^${e.id}`,""),e.new_name)})}),j.returns&&Object.assign(j.returns,{datasource:(x=(E=j.returns)==null?void 0:E.datasource)==null?void 0:x.replace(new RegExp(`^${e.id}`,""),e.new_name)});return}case"simple-action":{const j=_;j.datasource&&Object.assign(j.datasource,{name:(C=j.datasource.name)==null?void 0:C.replace(new RegExp(`^${e.id}`,""),e.new_name),from:(I=j.datasource.from)==null?void 0:I.replace(new RegExp(`^${e.id}`,""),e.new_name),target:(P=j.datasource.target)==null?void 0:P.replace(new RegExp(`^${e.id}`,""),e.new_name)});return}default:return}})),p.id===e.id?p.id=e.new_name:g&&p.from&&(p.from=p.from.replace(new RegExp(`^${e.id}`,""),e.new_name))}),e.updateRefs){const p=b.getDatasourceId({id:e.id,namespace:e.namespace}),g=b.getDatasourceId({id:e.new_name,namespace:e.namespace});b.datasourcesSubject.next({path:e.path??"",action:b.DatasourcesActions.RENAME,old_reference:p,new_reference:g,is_shared:s})}return s&&await b.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}`)}}),Na=Q("datasources/delete-datasource",async(e,{getState:r,rejectWithValue:t})=>{try{const a=r(),s=!!e.namespace,i=e.namespace||e.path,l=rl(e.path,a)[i].filter(b.outById(e.id));return s&&await b.setSharedSources({...a.sharedDatasources.sources,[e.namespace]:l}),{list:l,path:e.path,namespace:e.namespace}}catch{return t(`Error while removing datasource ${e.id}`)}}),Ua=or({name:"root",initialState:()=>{const e=ea();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(s=>{s.path===t&&(s.view||(s.view={panel:{isOpen:!1,type:"",current:""}}),Object.assign(s.view.panel,a))})},addDataSource(e,r){var i;const{payload:{path:t,datasourceDef:a}}=r,s=e.tabs.find(c=>c.path===t);s&&(s.content.metadata.datasources=s.content.metadata.datasources||[],(i=s.content.metadata.datasources)!=null&&i.find(l=>l.id===a.id)||(s.content.metadata.datasources=[...s.content.metadata.datasources,{...a,events:[]}],s.flags={...s.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:b.SETTINGS_TAB_PATH,type:b.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((s,i)=>(i==null?void 0:i.weight)>((s==null?void 0:s.weight)||0)?i:s,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(s=>s.path===t?{...s,flags:{...s.flags,touched:!0,confirmed:!0},content:{...s.content,metadata:{...s.content.metadata,datasources:s.content.metadata.datasources.filter(i=>i.id!==a)}}}:s)},setDataSources(e,r){const{payload:{path:t,datasourceArr:a}}=r;e.tabs=e.tabs.map(s=>{var i;return s.path===t?{...s,flags:{...s.flags,touched:!0,confirmed:!0},content:{...s.content,metadata:{...(i=s.content)==null?void 0:i.metadata,datasources:a}}}:s})},setTabs(e,r){e.tabs=r.payload},closeTab(e,r){const t=r.payload;e.tabs.splice(t,1);const a=e.tabs.reduce((s,i)=>(i==null?void 0:i.weight)>((s==null?void 0:s.weight)||0)?i:s,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||Ua.caseReducers.setTabFlags(e,{type:r.type,payload:{path:r.payload,flags:{confirmed:!0}}}))},selectTab(e,r){const t=e.tabs.find(({path:s})=>s===r.payload);if(!t||e.activeTab===r.payload)return;const a=e.tabs.reduce((s,i)=>(i==null?void 0:i.weight)>((s==null?void 0:s.weight)||0)?i:s,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:i})=>t.path===i);a||(e.tabs.push(t),a=e.tabs[e.tabs.length-1]);const s=e.tabs.reduce((i,c)=>(c==null?void 0:c.weight)>((i==null?void 0:i.weight)||0)?c:i,null);a.weight=s?(s.weight||0)+1:1,a.extra={...a.extra,...t.extra}},selectTabByReference(e,r){const t=[b.FileFolderType.SETTINGS,b.FileFolderType.DEBUGGER],a=r.payload;let s=e.tabs.find(({path:i})=>a.path===i);if((t.includes(a.type)||s!=null&&s.flags.confirmed)&&(a.flags.confirmed=!0),!s){const i=e.tabs.findIndex(({flags:{confirmed:c}})=>c===!1);i!==-1&&!t.includes(a.type)?e.activeTab===e.tabs[i].path?(e.tabs[i]=a,s=e.tabs[i]):(e.tabs.push(a),s=e.tabs[e.tabs.length-1],e.tabs.splice(i,1)):(e.tabs.push(a),s=e.tabs[e.tabs.length-1])}if(e.activeTab!==a.path){const i=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,s.weight=((i==null?void 0:i.weight)||0)+1}s.extra={...s.extra,...a.extra},s.flags={...s.flags||{},...a.flags||{}}},setContent(e,r){const{path:t,content:a,contentPath:s}=r.payload;e.tabs=e.tabs.map(i=>{if(i.path!==t)return i;let c=!1,l=i.flags.confirmed;if(typeof a=="string")c=i.initialContent!==a,l=!l&&c?!0:l;else{const d=JSON.stringify(He.get(i.initialContent,s||"",i.initialContent)),p=JSON.stringify(He.get(a,s||"",a));c=d!==p,l=!l&&c?!0:l}return a&&typeof a=="object"&&(s?He.set(i.content,s,a):i.content=a),typeof a=="string"&&(i.content=a),{...i,flags:{...i.flags,touched:c,confirmed:l}}})},setTabFlags(e,r){const{path:t,flags:a}=r.payload;e.tabs=e.tabs.map(s=>s.path===t?{...s,flags:{...s.flags,...a}}:s)},setTabsFlags(e,r){const{tabs:t,flags:a}=r.payload;e.tabs=e.tabs.map(s=>t.includes(s.path)?{...s,flags:{...s.flags,...a}}:s)},setTabExtra(e,r){const{path:t,extra:a,flags:s}=r.payload;e.tabs=e.tabs.map(i=>i.path===t?{...i,extra:{...i.extra,...a},flags:s?{...i.flags,...s}:i.flags}:i)},addWebFormStyles(e,r){const{path:t,styles:a=[]}=r.payload,s=e.tabs.find(i=>i.path===t);if(s){const i=s.content.metadata.styles.map(({name:l})=>l),c=a.filter(({name:l})=>!i.includes(l));s.content.metadata.styles=[...s.content.metadata.styles,...c].map(({scope:l,...d})=>({...d}))}},changeTabEditor(e,r){return e.tabs=e.tabs.map(t=>t.path===r.payload.path?r.payload:t),e}},extraReducers:e=>{e.addCase(fc,(r,t)=>{if(t.payload.settingsKey==="studio.enablePreview"&&t.payload.value===!1){const a=r.tabs.find(({flags:{confirmed:s}})=>s===!1);a&&Ua.caseReducers.setTabFlags(r,{type:"",payload:{path:a.path,flags:{confirmed:!0}}})}}),e.addCase(ev.fulfilled,(r,t)=>{if(!t.payload)return;const{content:a,line:s,path:i}=t.payload,c=r.tabs.find(l=>l.path===i);if(c&&typeof c.content=="string"){const l=c.content.trim().split(`
99
+ `}}};e.type==="dataclass"&&!e.toCreate?p=[{...g("dataclass")},{...g("collection")},{...g("entity")}]:e.type==="dataclass"&&e.toCreate?p=[{...g(e.toCreate)}]:p=[{...g("model")}],p=p.filter(_=>!d.find(({name:E,ext:x})=>E===_.name&&x===(i?"4qs":"4dm"))),await Promise.all(p.map(async({name:_,content:E})=>{await r(Kn({type:b.FileFolderType.CLASS,path:s,fileName:_,parentNode:c,content:E,qodly:a.settings.server.qodly}))})),await r(Sr(s))}),Sr=Q("explorer/fetchFolderContent",async(e,{rejectWithValue:r})=>{try{return(await b.getNodeInfo({verb:b.DesignerRequestVerb.GET_INFO,path:e})).map(a=>{const s=`${e}/${a.name}`,{editor:i,supportedEditors:c}=gr(`${s}${a.ext?`.${a.ext.toLowerCase()}`:""}`);return{name:a.name,size:a.size,type:a.type,date:`${a.date}`,flags:{},error:null,path:s,ext:a.ext,config:a.type==="folder"?{}:{editor:i,supportedEditors:c}}})}catch{return r("Failed loading file content please Reload")}},{getPendingMeta:()=>{}}),Ia=Q("explorer/fetchFolderContentWithoutExpanding",async(e,{rejectWithValue:r})=>{try{return(await b.getNodeInfo({verb:b.DesignerRequestVerb.GET_INFO,path:e})).map(a=>{const s=`${e}/${a.name}`,{editor:i,supportedEditors:c}=gr(`${s}${a.ext?`.${a.ext.toLowerCase()}`:""}`);return{name:a.name,size:a.size,type:a.type,date:`${a.date}`,flags:{},error:null,path:s,ext:a.ext,config:a.type==="folder"?{}:{editor:i,supportedEditors:c}}})}catch{return r("Failed loading file content please Reload")}},{getPendingMeta:()=>{}});function oD(e){const r=e.split(".");return r.pop(),{name:r.join("."),ext:e.split(".")[e.split(".").length-1]}}const sD=Q("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}}}),iD=Q("explorer/uploadFile",async({file:e,path:r,parentNode:t},{dispatch:a})=>{const{editor:s,supportedEditors:i}=gr(r),{name:c,ext:l}=oD(e.name);a(Kg({parent:t,child:{name:c,path:`${r}/${e.name}?t=${Date.now()}`,type:e.type,error:null,flags:{loading:!0},config:{editor:s,supportedEditors:i},ext:l}}));try{const d=await fetch(`/rest/$upload?$sharedFolder=true&$filename=${e.name}&$path=${r}`,{method:"POST",headers:{"Content-Type":e.type},body:e});return d.status>=300?(a(pc({parent:t,child:{name:c,path:`${r}/${e.name}`,type:e.type,error:{message:"error uploading file"},flags:{},config:{editor:s,supportedEditors:i},ext:l}})),d.status!==413&&b.toastSubject.next({message:"error uploading file",kind:"danger"})):await a(Sr(t.path)),{status:d.status,fileName:e.name}}catch{return a(pc({parent:t,child:{name:c,path:`${r}/${e.name}`,type:e.type,error:{message:"error uploading file"},flags:{},config:{editor:s,supportedEditors:i},ext:l}})),b.toastSubject.next({message:"error uploading file",kind:"danger"}),{status:500,fileName:e.name}}}),Kn=Q("explorer/createNewFile",async({fileName:e,type:r,path:t,parentNode:a,content:s},{dispatch:i,rejectWithValue:c,getState:l})=>{const{server:{qodly:d},project:p}=l().settings;try{const g=await b.setFileContent({name:Xg(e,r,d),content:s||Jg(r,p),path:t,asText:[b.FileFolderType.CLASS,b.FileFolderType.METHOD].includes(r)});return a.error&&(a.flags.expanded?await i(Sr(a.path)):await i(Ia(a.path))),{qodly:d,file:g,parentNode:a}}catch{return c("failed to create folder")}});function Qg(e,r){const{qodly:t=!0,withExtension:a=!0}=r||{},s=b.getFileExtentionFromType(e.type,t);let i="";switch(e.type){case b.FileFolderType.WEBFORM:i=`${b.FolderRootPath.WEBFORMS}/${e.name}`;break;case b.FileFolderType.METHOD:i=`${b.FolderRootPath.METHODS}/${e.name}`;break;case b.FileFolderType.CLASS:i=`${b.FolderRootPath.CLASSES}/${e.name}`;break;default:return""}return`${i}${a?`.${s}`:""}`}const uD=Q("explorer/createNewFileAndOpen",async(e,{dispatch:r,getState:t})=>{const a=await r(Kn(e)).unwrap(),{qodly:s}=t().settings.server;if(a){const{file:i}=a,c=Qg(i,{withExtension:!1,qodly:s}),{editor:l}=gr(c);await r(Fa({file:{name:e.fileName,type:i.type,path:c,editor:l,date:new Date().toISOString()}}))}}),ts=Q("explorer/createNewNode",async({fileName:e,path:r,parentNode:t},{rejectWithValue:a})=>{try{return{file:await b.createFolder({verb:b.DesignerRequestVerb.CREATE_FOLDER,path:`${r}/${e}`,recursive:!0}),parentNode:t}}catch{return b.toastSubject.next({message:"failed to create folder",kind:"danger"}),a("failed to create folder")}}),Ys=async(e,r=!0)=>{try{const t=e.path.split(".").at(-1),a=await b.getNodeInfo({verb:b.DesignerRequestVerb.GET_INFO,path:e.path,content:!0,as:Th(t)?"json":"text"}),s={editor:e.editor},i=b.getTypeFromExtension(e.path);i===b.FileFolderType.METHOD&&(s.attributes=b.parseAttributes(a.content),a.content=b.addAttributesToContent(a.content,{}));const{content:c,date:l,ext:d}=a;return{date:l,view:{panel:{isOpen:!1,type:"",current:""}},flags:{enabled:["WebForm","MForm"].includes(d),confirmed:r},extra:s,name:e.name,path:e.path,type:i,initialContent:c,content:c}}catch(t){const{data:a}=t;if(a.__ERROR.find(s=>s.errCode===b.ERROR_CODES.FILE_NOT_FOUND))switch(e.path){case b.ROLES_TAB_PATH:{const s={permissions:{allowed:[]},privileges:[],roles:[]};return{date:new Date().toISOString(),flags:{},extra:{editor:{key:"editors:roles"}},name:"Roles & Privileges",path:e.path,type:b.FileFolderType.ROLES,initialContent:s,content:s}}case b.SETTINGS_TAB_PATH:{const s={};return{date:new Date().toISOString(),flags:{},extra:{editor:{key:"editors:settings"}},name:"Settings",path:e.path,type:b.FileFolderType.SETTINGS,initialContent:s,content:s}}}throw t}},Fa=Q("explorer/openFile",async({file:e,inactive:r,flags:t={}},{getState:a,dispatch:s})=>{const{root:{tabs:i},roles:c,debugger:{sessions:l}}=a(),d=i.find(({path:m})=>e.path===m);if(d){const m={...d,extra:{...d==null?void 0:d.extra,editor:e.editor},flags:{...d==null?void 0:d.flags,...t}};return s(Dt(m)),m}if(e.path.startsWith("Debugger")){const m=l.find(_=>`Debugger/${_.threadId}`===e.path);if(m){const{source:{content:_},source:E}=m.currentStackFrame,x={name:e.name,type:b.FileFolderType.DEBUGGER,date:new Date().toISOString(),path:e.path,content:_,view:{panel:{isOpen:!1,type:"",current:""}},initialContent:_,flags:{confirmed:!0},extra:{source:E,editor:e.editor}};return s(Dt(x)),x}}let p=null;try{p=await Ys(e,t.confirmed)}catch(m){const{data:_}=m;if(_.__ERROR.find(E=>[b.ERROR_CODES.JSON_MALFORMED,b.ERROR_CODES.JSON_MALFORMED_AT_LINE].includes(E.errCode))){const{confirmed:E}=await s(sr({title:"Corrupt file",type:kt.CONFIRM,color:Tr.WARNING,message:"Open in code editor ?"})).unwrap();if(E){const x=await b.getNodeInfo({verb:b.DesignerRequestVerb.GET_INFO,path:e.path,content:!0,as:"text"}),{content:C,date:I,ext:P}=x;p={date:I,view:{panel:{isOpen:!1,type:"",current:""}},flags:{enabled:["WebForm","MForm"].includes(P),confirmed:!0},extra:{editor:b.EDITOR.Code},name:e.name,path:e.path,type:b.getTypeFromExtension(e.path),initialContent:C,content:C}}}}return p&&(e.path===b.ROLES_TAB_PATH&&!c.flags.touched?s(Yc({content:p.content,date:p.date})):e.path===b.SETTINGS_TAB_PATH&&s(zs({path:"project",value:p.content})),s((r?Fv:Dt)(p)),p)}),Jc=Q("explorer/openFileAtLine",async({file:e},{getState:r,dispatch:t})=>{const{tabs:a}=r().root,s=a.find(({path:c})=>e.path===c);if(s){const c={...s,extra:{...s==null?void 0:s.extra,editor:e.editor}};return t(Dt(c)),c}const i=await Ys(e);return t(Dt(i)),i}),ev=Q("explorer/injectContentAtLine",async(e,{getState:r,dispatch:t,rejectWithValue:a})=>{const s=r();e.path.split("/").pop();const c=ft(s.explorer,e.path);if(!c)return a(`Error while trying to inject content in file ${e.path}`);const l=await Ys({name:c.name,date:c.date||new Date().toISOString(),path:`${c.path}.${c.ext}`,type:b.FileFolderType.CLASS,editor:c.config.editor});return await t(Dt(l)),{...e,path:`${c.path}.${c.ext}`}}),tv=Q("explorer/openFileAtSelection",async({file:e},{getState:r,dispatch:t})=>{const{tabs:a}=r().root,s=a.find(({path:c})=>e.path===c);if(s){const c={...s,extra:{...s==null?void 0:s.extra,editor:e.editor}};return t(Dt(c)),c}const i=await Ys(e);return t(Dt(i)),i}),gc=Q("explorer/deleteFile",async e=>{const{name:r,type:t,path:a,flags:s}=e;if(s.error)return{deleted:!0,node:e};const i=a.split("/");return i.pop(),{deleted:await b.dropFile({root:b.FolderRootType.ROOT,type:Zg(t),verb:b.DesignerRequestVerb.DROP,name:r,path:i.join("/")}),node:e}}),cD=Q("explorer/deleteFolder",async e=>{const{path:r,flags:t}=e;if(t.error)return{deleted:!0,node:e};const{deleted:a}=await b.removeItem({force:!0,path:r,verb:b.DesignerRequestVerb.REMOVE_ITEM});return{deleted:a,node:e}}),lD=Q("explorer/removeFileNode",async(e,{getState:r,dispatch:t})=>{const a=`${e.path}.${e.ext}`;if(await b.removeItem({verb:b.DesignerRequestVerb.REMOVE_ITEM,path:a,force:!0}),e.path==="Classes/DataStore"&&setTimeout(()=>{t(On())},As),e.ext){const{tabs:s}=r().root,i=s.findIndex(c=>c.path===a);i>=0&&t(ol(i))}return{deleted:!0,node:e}}),Jn=Q("explorer/renameFile",async({file:e,newname:r})=>{if(e.type!=="folder"){const a=e.path.split("/");a.pop();const s=`${a.join("/")}/${e.name}.${e.ext}`,i=`${a.join("/")}/${r}.${e.ext}`;return await b.moveItem({verb:b.DesignerRequestVerb.MOVE_ITEM,path:s,newpath:i}),{old:{...e,path:s},new:{...e,name:r,path:i}}}const t=e.path.split("/");return t.pop(),await b.moveItem({verb:b.DesignerRequestVerb.MOVE_ITEM,path:`${t.join("/")}/${e.name}`,newpath:`${t.join("/")}/${r}`}),{old:e,new:{...e,name:r,path:`${t.join("/")}/${r}`}}}),$a=Q("explorer/relocateNode",async({draggedNode:e,newLocation:r},{rejectWithValue:t})=>{try{await b.moveItem({verb:b.DesignerRequestVerb.MOVE_ITEM,path:`${e.path}.${e.ext}`,newpath:`${r.path}/${e.name}.${e.ext}`})}catch{return t("can't move item")}}),rs=Q("explorer/duplicateNode",async({node:e,duplicateName:r},{rejectWithValue:t,fulfillWithValue:a,getState:s})=>{const i=e.path.split("/");i.pop();try{const{tabs:c}=s().root,l=c.find(({path:m})=>m===`${e.path}${e.ext?`.${e.ext}`:""}`),d=["4dm","4qm","4qs"].includes(e.ext),{content:p}=l||await b.getNodeInfo({verb:b.DesignerRequestVerb.GET_INFO,path:`${e.path}.${e.ext}`,content:!0,as:d?"text":"json"}),g=await b.setFileContent({name:`${r}.${e.ext}`,content:p,path:i.join("/"),asText:d});return a({node:{...g,path:i.join("/")}})}catch{return t("failed to duplicate file")}}),fD=Q("explorer/executeMethod",async({methodName:e,params:r=[],resultingDataSource:t={},namespace:a=""},{rejectWithValue:s})=>{var i,c;try{const d=await window.Method4D.buildMethod({methodName:e,parameters:r,resultingDataSource:t},{namespace:a},null).callServerSide({id:"",serverSideRef:""},"onclick",{});return d!=null&&d.__NOTIFICATION?b.toastSubject.next({message:`${((i=d.__NOTIFICATION)==null?void 0:i.message)||""}`,kind:`${((c=d.__NOTIFICATION)==null?void 0:c.type)||"info"}`}):b.toastSubject.next({message:"Method executed Successfully",kind:"message"}),d}catch(l){return b.toastSubject.next({message:l.message||`Error executing the method "**${e}**"`,kind:"danger",markdown:!0}),s("can't execute method")}}),dD=Q("files/fetchFiles",async()=>b.getFolders(b.FolderRootType.WEBFORMS,b.FolderRootType.METHODS,b.FolderRootType.CLASSES)),Xc=Q("tabs/renameDatasource",async(e,{dispatch:r,getState:t})=>{var E,x;const a=!!e.datasourceNamespace,{confirmed:s}=await r(sr({message:"Are you sure you want to rename the datasource?",title:"Rename Datasource",type:kt.CONFIRM,color:Tr.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(!s)return null;const{autoUpdateReferences:i,datasourceId:c,datasourceNamespace:l,value:d,path:p}=e,g=t();let m=[];if(a){const C=g.sharedDatasources.sources[l]||[];m.push(...C)}else if(p){const C=g.root.tabs.find(b.by("path",p));if(m=(x=(E=C==null?void 0:C.content)==null?void 0:E.metadata)==null?void 0:x.datasources,!m)return null}const _=new RegExp(`^${c}\\b`,"");if(m=m.map(C=>{const I=(b.isObjectDatasource(C)||!b.isSimpleDatasource(C))&&C.from&&_.test(C.from),P=C.events?C.events.map(j=>{var M,k,O,Y;switch(j==null?void 0:j.type){case"method":{const H=j;return H.params?{...H,params:H.params.map(z=>{var te;return{...z,datasource:(te=z.datasource)==null?void 0:te.replace(new RegExp(`^${c}`,""),d)}}),returns:(M=H.returns)!=null&&M.datasource?{...H.returns,datasource:(k=H.returns.datasource)==null?void 0:k.replace(new RegExp(`^${c}`,""),d)}:H.returns}:H}case"simple-action":{const H=j;return H.datasource?{...H,datasource:{...H.datasource,name:(O=H.datasource.name)==null?void 0:O.replace(new RegExp(`^${c}`,""),d),from:(Y=H.datasource.from)==null?void 0:Y.replace(new RegExp(`^${c}`,""),d)}}:H}default:return j}}):C.events;return C.id===c?{...C,id:d,events:P}:I&&C.from?{...C,from:C.from.replace(new RegExp(`^${c}`,""),d),events:P}:{...C,events:P}}),i){const C=a?`${l}:${c}`:`${c}`,I=a?`${l}:${d}`:`${d}`;b.datasourcesSubject.next({path:p??"",action:b.DatasourcesActions.RENAME,old_reference:C,new_reference:I,is_shared:a})}return{path:p,namespace:l,datasources:m}}),Zc=Q("tabs/edit-datasource",(e,{getState:r})=>{var i,c;const t=r();let a=[];if(e.namespace)a=t.sharedDatasources.sources[e.namespace];else{const l=t.root.tabs.find(b.by("path",e.path));l&&(a=((c=(i=l.content)==null?void 0:i.metadata)==null?void 0:c.datasources)||[])}return a.map(l=>l.id===e.datasourceId?Object.assign({},l,{[e.propertyKey]:e.value}):l)}),rv=Q("tabs/fetchChanges",async(e,{getState:r})=>{const a=sa(r()).filter(s=>[b.FileFolderType.METHOD,b.FileFolderType.CLASS].includes(s.type));return b.getFilesInfo(...a.map(s=>{const[i]=s.path.split("/").filter(Boolean);return{name:s.name,type:s.type,root:i,path:"."}}))}),pD=Q("files/saveAll",async(e,{getState:r,dispatch:t})=>{const a=Nc(r());for(const s of a)t(Xn({tab:s}))}),Qc=Q("files/tryCloseTab",async(e,{getState:r,dispatch:t})=>{const{tabs:a}=r().root,s=a.findIndex(c=>c.path===e);if(s===-1)return!1;const i=a[s];if(i!=null&&i.flags.touched){const{confirmed:c}=await t(sr({title:Ps(i),message:"Your unsaved changes will be lost. Proceed anyway?",type:kt.CONFIRM,color:Tr.WARNING,icon:"AiFillWarning"})).unwrap();if(!c)return!1}return t(ol(s)),i.path===b.ROLES_TAB_PATH&&i.flags.touched&&(async()=>{const l=await b.getNodeInfo({verb:b.DesignerRequestVerb.GET_INFO,path:b.ROLES_TAB_PATH,content:!0,as:"json"});t(Yc({content:l.content,date:l.date}))})(),!0}),hD=Q("files/tryCloseOtherTabs",async(e,{getState:r,dispatch:t})=>{const{tabs:a}=r().root;if(a.some(i=>i.path!==e&&i.flags.touched===!0)){const{confirmed:i}=await t(sr({title:"Closing other tabs",message:"Your changes will be lost if you do not save them. Close anyway?",type:kt.CONFIRM,color:Tr.WARNING,icon:"AiFillWarning"})).unwrap();if(!i)return}t(Pv(e))}),gD=Q("files/tryCloseAllTabs",async(e,{getState:r,dispatch:t})=>{const{tabs:a}=r().root;if(a.some(i=>i.flags.touched===!0)){const{confirmed:i}=await t(sr({title:"Closing all tabs",message:"Your changes will be lost if you do not save them. Close anyway?",type:kt.CONFIRM,color:Tr.WARNING,icon:"AiFillWarning"})).unwrap();if(!i)return}t(Ov())}),vD=Q("files/tryCloseRightTabs",async(e,{getState:r,dispatch:t})=>{const{tabs:a}=r().root;let s=!1;for(let i=a.length-1;i>e;i-=1)if(a[i].flags.touched){s=!0;break}if(s){const{confirmed:i}=await t(sr({title:"Closing right tabs",message:"Your changes will be lost if you do not save them. Close anyway?",type:kt.CONFIRM,color:Tr.WARNING,icon:"AiFillWarning"})).unwrap();if(!i)return}t(Av(e))}),mD=Q("files/tryCloseLeftTabs",async(e,{getState:r,dispatch:t})=>{const{tabs:a}=r().root;let s=!1;for(let i=0;i<e;i+=1)if(a[i].flags.touched){s=!0;break}if(s){const{confirmed:i}=await t(sr({title:"Closing left tabs",message:"Your changes will be lost if you do not save them. Close anyway?",type:kt.CONFIRM,color:Tr.WARNING,icon:"AiFillWarning"})).unwrap();if(!i)return}t(Dv(e))}),vc=Q("files/reloadTab",async(e,{dispatch:r})=>{if(e.flags.touched){const{confirmed:s}=await r(sr({title:Ps(e),message:"Changes made to the file will be lost. Continue?",type:kt.CONFIRM,color:Tr.WARNING,icon:"AiFillWarning"})).unwrap();if(!s)return}const t=zh(e.path),a=await b.getNodeInfo({verb:b.DesignerRequestVerb.GET_INFO,path:e.path,content:!0,as:t});if(e.path===b.ROLES_TAB_PATH){const{roles:s,privileges:i}=Hs(a.content);r(Vc({roles:s,privileges:i}))}else if(e.path===b.SETTINGS_TAB_PATH){const{content:s}=a;r(zs({path:"project",value:s}))}else{const{content:s}=a;e.type===b.FileFolderType.WEBFORM?b.webformSubject.next({path:e.path,action:b.WebformActions.RELOAD,payload:s.components}):e.type===b.FileFolderType.MODEL&&Qh.next({action:"reload",payload:s})}return a}),Xn=Q("files/saveTab",async({tab:e},{dispatch:r,getState:t})=>{const{path:a,content:s}=e;if(e.type===b.FileFolderType.DEBUGGER)return{...e,errors:[]};a.split("/").pop();const c=await b.getFilesInfo({path:a});if(c.files[0]){const g=new Date(e.date),m=new Date(c.files[0].date);if(g.getTime()<m.getTime()){const{confirmed:_}=await r(sr({title:Ps(e),message:"New content has been found on the server. Are you sure you want to continue?",type:kt.CONFIRM,icon:"FaSave"})).unwrap();if(!_)return r(Rv({path:a,flags:{old:!0}})),null}}const l=await b.saveContent({verb:b.DesignerRequestVerb.SAVE_CONTENT,content:yD(e,t()),path:a});(e.type===b.FileFolderType.CLASS||e.type===b.FileFolderType.MODEL)&&setTimeout(()=>{r(On())},As);const d=(l.modelErrors||[]).map(g=>g.message),p=(l.permissionsErrors||[]).map(g=>g.message);return{...e,content:s,date:l.date,initialContent:s,errors:d.length>0||p.length>0?[{title:"Model errors",messages:d},{title:"Permissions errors",messages:p}]:[]}}),yD=(e,r)=>{switch(!0){case e.path==="settings.json":case e.path===b.SETTINGS_TAB_PATH:return r.settings.project;case e.type===b.FileFolderType.ROLES:return Gs(r.roles);case e.type===b.FileFolderType.MODEL:return e.content||{toJSON:!0,dataClasses:[],extraProperties:{}};default:return e.content}},Hp=async e=>{if(e.type===b.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 b.getFile({root:r,type:e.type,verb:b.DesignerRequestVerb.GET,name:e.name}),a={};t.type===b.FileFolderType.METHOD&&(a.attributes=b.parseAttributes(t.content));const{date:s,name:i,type:c,content:l}=t;return{date:s,flags:{enabled:e.type===b.FileFolderType.WEBFORM},extra:a,view:{panel:{isOpen:!1,type:"",current:""}},name:i,path:e.path,type:c,initialContent:l,content:c===b.FileFolderType.MODEL?wh(l):l}},nv=Q("files/tryInjectMethod",async({type:e,dataclass:r},{getState:t,dispatch:a})=>{const{root:{tabs:s},settings:{server:{qodly:i}}}=t(),c=b.getFileExtentionFromType("class",i);let l="",d="",p=null;if(!r)l="DataStore",d=`Classes/DataStore.${c}`;else switch(e){case"dataclass":l=r,d=`Classes/${r}.${c}`;break;case"collection":l=`${r}Selection`,d=`Classes/${r}Selection.${c}`;break;case"entity":l=`${r}Entity`,d=`Classes/${r}Entity.${c}`;break;default:return p}const g=s.find(b.by("path",d));if(g)return a(Dt(g)),g;try{p=await Hp({name:l,date:new Date().toISOString(),path:`class/${l}.${c}`,type:b.FileFolderType.CLASS})}catch{r?await a(hc({type:"dataclass",className:r,collectionName:`${r}Selection`,toCreate:e})):await a(hc({type:"model"}))}return p=await Hp({name:l,date:new Date().toISOString(),path:`class/${l}.${c}`,type:b.FileFolderType.CLASS}),p.path=d,a(Dt(p)),p}),bD=Q("roles/open",async(e,{dispatch:r,getState:t})=>{const{tabs:a}=t().root,s=a.find(i=>i.path===b.ROLES_TAB_PATH);if(s)return r(Dt(s)),s;r(Ss())});function Gp(e,r){const{line:t,offset:a,type:s="saved"}=r;e.breakpoints[s].locations.push({line:t}),He.isNumber(a)&&(e.breakpoints[s].offset=a)}function qp(e,r,t,a){e.breakpoints[t].locations=r,He.isNumber(a)&&(e.breakpoints[t].offset=a)}function zp({filePath:e,fileType:r,methodName:t,className:a,ext:s,source:i}){return{filePath:e,fileType:r,methodName:t,className:a,ext:s,source:i,breakpoints:{draft:{locations:[],offset:0},saved:{locations:[],offset:0}}}}function Yp(e,r,t){let a=!1;const s=e.map(i=>i[t]!==r[t]?i:(a=!0,{...i,...r}));return a?s:[...s,r]}function Xo(e){return e.map(({label:r})=>({label:r}))}const av=or({name:"debugger",initialState:()=>{var r,t;const{debugger:e={meta:{state:Mr.DETACHED},list:[],sessions:[],expressions:[]}}=ea();return{meta:{...e.meta,state:((r=e.meta)==null?void 0:r.state)===Mr.ATTACHED?(t=e.meta)==null?void 0:t.state:Mr.DETACHED},list:e.list||[],sessions:e.sessions||[],expressions:e.expressions||[]}},reducers:{addBreakpointDecoration(e,r){const{filePath:t,fileType:a,methodName:s,className:i,ext:c,source:l,breakpoint:d}=r.payload,p=Rn(e.list,t,s,i);if(p)Gp(p,d);else{if(a===b.FileFolderType.CLASS&&d.offset===void 0)throw new Error(`Cannot add a breakpoint on a function without offset. Try editing the ${i} class.`);const g=zp({filePath:t,fileType:a,methodName:s,className:i,ext:c,source:l});Gp(g,d),e.list.push(g)}},removeBreakpointDecoration(e,r){const{filePath:t,methodName:a,line:s,offset:i=0,type:c="saved"}=r.payload;if(t.startsWith("Classes/")){const l=e.list.filter(d=>d.filePath===t);if(l.length>0){const d=s+i;l.forEach(p=>{const g=p.breakpoints[c].offset||0;p.breakpoints[c].locations=p.breakpoints[c].locations.filter(m=>m.line+g!==d),c==="saved"&&(p.breakpoints.draft.locations=p.breakpoints.draft.locations.filter(m=>m.line+g!==d))})}}else{const l=Rn(e.list,t,a);l&&(l.breakpoints[c].locations=l.breakpoints[c].locations.filter(d=>d.line!==s),c==="saved"&&(l.breakpoints.draft.locations=l.breakpoints.draft.locations.filter(d=>d.line!==s)))}},setBreakpointsDecoration(e,r){const{filePath:t,fileType:a,methodName:s,className:i,ext:c,source:l,breakpoints:d,offset:p,type:g="saved",clearDraft:m}=r.payload,_=Rn(e.list,t,s);if(_)qp(_,d,g,p),m&&g!=="draft"&&(_.breakpoints.draft.locations=[]);else{const E=zp({filePath:t,fileType:a,methodName:s,className:i,ext:c,source:l});qp(E,d,g,p),e.list.push(E)}},clearBreakpoints(e,r){const{filePath:t,type:a="saved"}=r.payload;e.list=e.list.map(s=>({...s,breakpoints:s.filePath===t?{draft:!a||a==="draft"?{locations:[],offset:0}:s.breakpoints.draft,saved:!a||a==="saved"?{locations:[],offset:0}:s.breakpoints.saved}:s.breakpoints}))},setActiveLine(e,r){const{threadId:t,line:a,highlight:s}=r.payload,i=st(e.sessions,t);i&&(i.activeLine=a,s&&(i.highlightedLines={start:a,end:a}))},addExpression(e,r){const{threadId:t,label:a,save:s}=r.payload,i=st(e.sessions,t);i&&i.stopped&&(i.expressions=[...i.expressions||[],{label:a}],s&&(e.expressions=Xo(i.expressions)))},removeExpression(e,r){const{threadId:t,index:a,save:s}=r.payload,i=st(e.sessions,t);i&&(i.expressions=i.expressions.filter((c,l)=>l!==a),s&&(e.expressions=Xo(i.expressions)))},removeAllExpressions(e,r){const{threadId:t,save:a}=r.payload,s=st(e.sessions,t);s&&(s.expressions=[],a&&(e.expressions=[]))},renameExpression(e,r){const{threadId:t,index:a,replacement:s,save:i}=r.payload,c=st(e.sessions,t);c&&c.expressions[a]&&(c.expressions[a].label=s,i&&(e.expressions=Xo(c.expressions)))},setExpression(e,r){const{threadId:t,expression:a}=r.payload,s=st(e.sessions,t);if(s){const i=a.index>=0?a.index:s.expressions.length>0?s.expressions.length-1:0,c=s.expressions[i];c?(c.result=a.result,c.nakedResult=a.nakedResult,c.variablesReference=a.variablesReference||0,c.presentationHint=a.presentationHint):s.expressions.push(a)}},updateExpressionAt(e,r){const{threadId:t,index:a,value:s}=r.payload,i=st(e.sessions,t);if(i){const c=i.expressions[a];c&&(c.result=`"${s}"`,c.nakedResult=s)}},saveExpressions(e,r){const{expressions:t}=r.payload;e.expressions=Xo(t)},addSession(e,r){const{threadId:t,channelId:a,stackFrames:s,exceptions:i=[]}=r.payload,c=st(e.sessions,t),l=s[0],{expressions:d=[]}=e;if(c)c.expressions=d;else{const p=Dc(t);e.sessions.push({tabPath:p,threadId:t,channelId:a,stackFrames:s,currentStackFrame:l,exceptions:i,expressions:d,variables:{callchain:[],expressions:[]},highlightedLines:null,activeLine:null,stopped:!0})}},updateSession(e,r){const{threadId:t,changes:a}=r.payload;e.sessions=e.sessions.map(s=>s.threadId===t?{...s,...a}:s)},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:s}=r.payload;e.sessions=e.sessions.map(i=>{var c;return i.threadId===t?{...i,variables:{...i.variables,callchain:Yp((c=i.variables)==null?void 0:c.callchain,{frameId:a,items:s},"frameId")}}:i})},setExpressionVariables(e,r){const{threadId:t,variablesReference:a,variables:s}=r.payload;e.sessions=e.sessions.map(i=>{var c;return i.threadId===t?{...i,variables:{...i.variables,expressions:Yp((c=i.variables)==null?void 0:c.expressions,{variablesReference:a,items:s},"variablesReference")}}:i})},setSourceContent(e,r){const{threadId:t,content:a}=r.payload,s=st(e.sessions,t);s&&(s.currentStackFrame.source={...s.currentStackFrame.source,content:a})},setDebuggerMeta(e,r){if(r.payload.state===Mr.ERROR){e.meta.error={...e.meta.error,time:Date.now()};const{override:t,error:a={code:null,reason:"",type:ds.SOCKET_ERROR}}=r.payload;if((t||e.meta.state!==Mr.ERROR)&&(e.meta.error={...e.meta.error,...a}),(a==null?void 0:a.type)===ds.SOCKET_CLOSURE&&!(a!=null&&a.reason)&&e.meta.state===Mr.DETACHED)return}e.meta.state=r.payload.state}},extraReducers:e=>{e.addCase(sv.fulfilled,r=>{r.sessions=[]})}}),{addBreakpointDecoration:_D,removeBreakpointDecoration:ED,setBreakpointsDecoration:SD,clearBreakpoints:wD,setActiveLine:TD,addExpression:xD,renameExpression:CD,removeExpression:RD,removeAllExpressions:OD,setExpression:AD,updateExpressionAt:PD,saveExpressions:DD,addSession:ID,updateSession:FD,removeSession:$D,removeSessionByIndex:MD,setSessions:ov,setCallChainVariables:ND,setExpressionVariables:LD,setSourceContent:kD,setDebuggerMeta:jD}=av.actions,sv=Q("files/wipeDebuggerSessions",async(e,{getState:r,dispatch:t})=>{const{sessions:a}=r().debugger;for(const{threadId:s}of a){const i=Dc(s);t(Qc(i))}}),iv=Q("files/removeDebuggerSessionsNotIn",async(e,{getState:r,dispatch:t})=>{const{threadIds:a}=e,{sessions:s}=r().debugger,i=[],c=s.filter(l=>{const d=a.includes(l.threadId);return d||i.push(l.threadId),d});return t(ov(c)),{staleThreadIds:i}});var el=(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))(el||{}),Lr=(e=>(e.STORAGE="storage",e.RELATEDENTITY="relatedEntity",e.RELATEDENTITIES="relatedEntities",e.CALCULATED="calculated",e.COMPOSITION="composition",e.ALIAS="alias",e))(Lr||{});const BD=e=>["string","uuid","number","long"].includes(e.type),WD=[{label:"Storage",value:"storage"},{label:"Calculated",value:"calculated"}],UD=[{title:"UUID",kind:"storage",value:"uuid",calculatedType:"uuid",calculatedKind:"storage"},{title:"Long",kind:"storage",value:"long",calculatedType:"long",calculatedKind:"storage"}],HD=[{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"}],GD=[{label:"Expose as REST",value:"public"},{label:"Do not expose as REST",value:"publicOnServer"}],qD=[{label:"Expose as REST",value:"public"},{label:"Do not expose as REST",value:"publicOnServer"}],zD=[{label:"None",value:"none"},{label:"B-tree",value:"btree"},{label:"Cluster",value:"cluster"},{label:"Automatic",value:"auto"}],uv=Pt("model/add-dataclass"),cv=Pt("model/rename-dataclass"),lv=Pt("model/remove-dataclass"),fv=Pt("model/add-attribute"),YD=Pt("model/edit-attribute-property"),dv=Pt("model/remove-attribute"),pv=Pt("model/rename-attribute"),hv=Pt("model/edit-primary-key"),VD=Pt("model/edit-dataclass-property"),gv=Pt("model/rename-collection"),KD=(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 ns(e,r,t){const a=e;let s=0;for(;t[`${a}${s||""}`];)s++;return`${a}${s||""}`}const Ma=e=>e.kind===Lr.RELATEDENTITY,ws=e=>e.kind===Lr.RELATEDENTITIES,JD=e=>ws(e)||Ma(e),tl=Q("models/fetch",async()=>{try{return(await b.http(b.API_PREFIX,{method:"POST",body:JSON.stringify({verb:b.DesignerRequestVerb.GET_INFO,path:b.MODEL_TAB_PATH,as:"json",content:!0}),headers:new Headers({"Content-Type":"application/json"})})).content}catch(e){return e.message}}),Ts=Q("models/save",async(e,{getState:r,dispatch:t,rejectWithValue:a})=>{const{tabs:s}=r().root,i=s.find(c=>c.path===b.MODEL_TAB_PATH);if(!i)return a("Error while saving the model");try{const c=await b.http(b.API_PREFIX,{method:"POST",body:JSON.stringify({verb:"save",path:i.path,content:i.content}),headers:new Headers({"Content-Type":"application/json"})});return setTimeout(()=>{t(On())},As),{...c,path:i.path,content:e.content||{toJSON:!0,dataClasses:[],extraProperties:{}}}}catch{return a("Error while saving the model")}}),XD=Q("models/open",async(e,{dispatch:r,getState:t})=>{const{tabs:a}=t().root,s=a.find(i=>i.path==="models/main");if(s)return r(Dt(s)),s;r(tl())}),ZD=Q("model/rename-dataclass",async(e,{getState:r,dispatch:t})=>{var m,_;const{dataclassId:a,selectionId:s,name:i}=e;let c=r();const l=c.explorer.find(E=>E.path===b.FolderRootPath.CLASSES);if(!l)throw new Error("Classes folder was not found!");await t(Sr(l.path)),c=r();const d={class:{found:!1,newNameTaken:!1,file:null,filename_update:i},entity:{found:!1,newNameTaken:!1,file:null,filename_update:`${i}Entity`},selection:{found:!1,newNameTaken:!1,file:null,filename_update:`${i}Selection`}};(_=(m=c.explorer.find(E=>E.path===b.FolderRootPath.CLASSES))==null?void 0:m.children)==null||_.forEach(E=>{E.name===d.class.filename_update&&(d.class.newNameTaken=!0),E.name===d.entity.filename_update&&(d.entity.newNameTaken=!0),E.name===d.selection.filename_update&&(d.selection.newNameTaken=!0),E.name===a?(d.class.found=!0,d.class.file=E):E.name===`${a}Entity`?(d.entity.found=!0,d.entity.file=E):E.name===s&&(d.selection.found=!0,d.selection.file=E)});const p=Object.entries(d).reduce((E,x)=>{const[C,I]=x;return I.found?I.newNameTaken?[...E,{type:"error",message:`Cannot rename ${C} file to ${I.filename_update} because it already exists. The existing file will be used instead!`}]:E:[...E,{type:"warning",message:`${a} ${C} file was not found`}]},[]);p.length>0&&t(sr({message:"The following errors were encountered during dataclass rename:",views:{tips:p}}));const g=Object.values(d).filter(E=>E.found&&E.file&&!E.newNameTaken);await Promise.all(g.map(async E=>await t(Jn({file:E.file,newname:E.filename_update})))),g.length>0&&t(Sr("Classes"))}),Wa={DATACLASS_DELETE:"dataclass.delete",DATACLASS_DRAGGABLE:"dataclass.draggable"},QD={model:{dataClasses:{},collections:{},extraProperties:{}},draft:{dataClasses:{},collections:{},extraProperties:{}},flags:{[Wa.DATACLASS_DELETE]:!0,[Wa.DATACLASS_DRAGGABLE]:!0}},vv=or({name:"Models",initialState:QD,reducers:{setModelFlag(e,r){e.flags={...e.flags,...r.payload}}},extraReducers(e){e.addCase(uv,({draft:{dataClasses:r}},t)=>{var c,l;const{dataclassID:a}=t.payload,s=ns(a||"DataClass","className",r),i={className:s,collectionName:`${s}Selection`,attributes:[{name:"ID",kind:Lr.STORAGE,type:el.LONG,scope:"public",indexKind:"auto",unique:!0,primKey:!0,autosequence:!0}],name:s,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[i.name]=i}).addCase(lv,({draft:{dataClasses:r}},t)=>{const{dataclassID:a}=t.payload;r[a]&&(delete r[a],Object.values(r).forEach(i=>{i.attributes=i.attributes.filter(c=>c.type!==a&&c.type!==i.collectionName)}))}).addCase(cv,({draft:{dataClasses:r,collections:t}},a)=>{const{dataclassID:s,newName:i}=a.payload;if(!r[s]||r[i])return;const c=r[s].collectionName,l=ns(`${i}Selection`,"collectionName",t);Object.values(r).forEach(d=>{d.className===s&&(d.className=i,d.name=i,d.collectionName=l),d.attributes.forEach(p=>{p.type===s?(p.type=i,p.path=i):p.type===c&&(p.type=l)})})}).addCase(fv,({draft:{dataClasses:r}},t)=>{const{dataclassID:a,attributeName:s,attributeType:i,attributeKind:c,target:l}=t.payload;if(!r[a]||b.exists("name",s,r[a].attributes))return;const p={name:s,kind:c,type:i,exposed:!0,scope:"public"};if(c===Lr.RELATEDENTITY){if(!r[i])return;p.path=i;const m={name:ns(r[i].collectionName,"name",r[i].attributes),type:r[a].collectionName,kind:Lr.RELATEDENTITIES,reversePath:!0,path:s,scope:"public",exposed:!0};r[i].attributes.push(m)}else if(c===Lr.RELATEDENTITIES){const g=r[i];if(!g)return;const m=g.attributes.find(b.by("name",l));if(m){if(!Ma(m)||m.type!==r[a].className)return}else{p.path=l,p.reversePath=!0,p.type=i;const _={name:l,kind:Lr.RELATEDENTITY,scope:"public",path:g.className,type:g.className,exposed:!0};g.attributes.push(_)}}r[a].attributes.push(p)}).addCase(pv,({draft:{dataClasses:r}},t)=>{const{dataclassID:a,attributeID:s,newName:i}=t.payload,c=r[a].attributes.find(b.by("name",s)),l=r[a].attributes.find(b.by("name",i));!c||l||Object.values(r).forEach(({collectionName:d,attributes:p,className:g})=>{p.forEach(m=>{Ma(c)&&ws(m)&&m.type===d&&m.path===s&&(m.path=i),g===a&&m.name===s&&(m.name=i)})})}).addCase(dv,({draft:{dataClasses:r}},t)=>{const{dataclassID:a,attributeID:s}=t.payload;if(!r[a])return;const i=r[a].attributes.find(b.by("name",s));i&&(Ma(i)&&Object.values(r).forEach(c=>{c.attributes=c.attributes.filter(l=>!(ws(l)&&l.type===c.collectionName&&l.path===i.name))}),r[a].attributes=r[a].attributes.filter(b.outBy("name",s)))}).addCase(gv,({draft:{dataClasses:r,collections:t}},a)=>{const{dataclassID:s,collectionName:i}=a.payload;if(!r[s])return;const c=r[s].collectionName;t[i]||(r[s].collectionName=i,t[i]=r[s],delete t[c],Object.values(r).forEach(l=>l.attributes.forEach(d=>{d.type===c&&(d.type=i)})))}).addCase(hv,({draft:{dataClasses:r}},t)=>{const{dataclassID:a,newPrimKey:s}=t.payload;r[a]&&r[a].attributes.forEach(i=>{i.name===s?i.primKey=!0:i.primKey=!1})}),e.addCase(tl.fulfilled,(r,t)=>{var c;const a={},s={},i=t.payload.extraProperties||{};(c=t.payload.dataClasses)==null||c.forEach(l=>{a[l.name]=l,s[l.collectionName]=l}),r.draft.dataClasses=a,r.draft.collections=s,r.draft.extraProperties=i,r.model.dataClasses=a,r.model.collections=s,r.model.extraProperties=i}),e.addCase(Ts.pending,()=>{}).addCase(Ts.fulfilled,(r,t)=>{const a={},s={},i=t.payload.content.extraProperties||{};t.payload.content.dataClasses.forEach(c=>{a[c.name]=c,s[c.collectionName]=c}),r.draft.dataClasses=a,r.draft.collections=s,r.draft.extraProperties=i,r.model.dataClasses=a,r.model.collections=s,r.model.extraProperties=i})}}),{setModelFlag:eI}=vv.actions,tI=()=>Ur(e=>e.model.draft.dataClasses),rI=()=>Ur(e=>e.model.draft.collections),nI=e=>Ur(r=>r.model.draft.dataClasses[e]),aI=(e,r)=>Ur(t=>t.model.draft.dataClasses[e].attributes.find(b.by("name",r))),oI=()=>Ur(e=>e.model.draft.extraProperties),sI=()=>{const e=Ur(s=>s.model.flags),r=s=>s in e?e[s]:void 0,t=r(Wa.DATACLASS_DELETE),a=r(Wa.DATACLASS_DRAGGABLE);return{deleteDataclass:t,draggableDataclass:a,flags:e}},iI=vv.reducer;function Uu(e,r){const t=e.tabs.find(({path:a})=>a===b.SETTINGS_TAB_PATH);t&&(t.flags.touched=r)}const mv={SIDEBAR_SECTION_RESIZABLE:"sidebar.section.resizable"},yv={[mv.SIDEBAR_SECTION_RESIZABLE]:!0},bv=or({name:"webforms",initialState:()=>{const{webforms:e}=ea();return{...e,templates:{data:[],selectedGroup:""},datasources:{...Ac.webforms.datasources,...e==null?void 0:e.datasources},flags:yv}},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(s=>s.id===t?{...s,...a}:s)},removeComponent:(e,r)=>{const{payload:t}=r,a=e.components.findIndex(s=>s.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,s=e.templates.data.find(i=>i.group===t);s&&(s.components=a)},setDatasourcesTheme:(e,r)=>{e.datasources.theme=r.payload},setWebformsFlag(e,r){e.flags={...e.flags,...r.payload}}},extraReducers(e){e.addCase(xv.fulfilled,(r,t)=>{r.components=t.payload})}}),{toggleInspector:uI,inspect:cI,addComponent:_v,editComponent:Ev,removeComponent:Sv,setSelectedGroup:lI,setTemplatesData:wv,setTemplateData:Tv,setDatasourcesTheme:fI,setWebformsFlag:dI}=bv.actions,pI=bv.reducer,rl=He.curry((e,r)=>{var s,i;const t={...r.sharedDatasources.sources},a=(i=((s=r.root.tabs.find(b.by("path",e)))==null?void 0:s.content).metadata)==null?void 0:i.datasources;return a&&(t[e]=a),He.cloneDeep(t)}),hI=Q("webforms/fetchTemplates",async(e,{dispatch:r,getState:t})=>{const{data:a}=t().webforms.templates,s=t().settings.session["studio.tipsBaseUrl"]||"";if(!He.isEmpty(a))return a;try{const c=await(await fetch(`${s}/build/index.json?t=${Date.now()}`)).json();return r(wv(c)),c}catch{return[]}}),gI=Q("webforms/fetchTemplate",async({name:e},{dispatch:r,getState:t})=>{const{data:a}=t().webforms.templates,s=a.find(i=>i.group===e);if(s&&!He.isEmpty(s.components))return s.components;try{const c=await(await fetch(`${s==null?void 0:s.link}?t=${Date.now()}`)).json();return r(Tv({group:e,components:c})),c}catch{return[]}}),xv=Q("webforms/fetchCraftedComponents",async(e,{rejectWithValue:r})=>{try{return(await b.getNodeInfo({path:"WebForms/crafted_components.json",verb:b.DesignerRequestVerb.GET_INFO,content:!0,as:"json"})).content}catch{return r("Error while loading the crafted components")}}),vI=Q("webforms/addCraftedComponent",async(e,{dispatch:r,rejectWithValue:t,getState:a})=>{try{r(_v(e));const{webforms:{components:s}}=a();b.setCraftedComponents(s)}catch{return t("Error while adding the crafted component")}}),mI=Q("webforms/editCraftedComponent",async(e,{dispatch:r,rejectWithValue:t,getState:a})=>{try{r(Ev(e));const{webforms:{components:s}}=a();b.setCraftedComponents(s)}catch{return t("Error while editing the crafted component")}}),yI=Q("webforms/removeCraftedComponent",async(e,{dispatch:r,rejectWithValue:t,getState:a})=>{try{r(Sv(e));const{webforms:{components:s}}=a();b.setCraftedComponents(s)}catch{return t("Error while removing the crafted component")}}),nl=Q("datasources/add-datasource",async(e,{getState:r,rejectWithValue:t})=>{var a,s;try{const i=r(),c=e.datasource,l=!!c.namespace,d=[];if(l){const p={...i.sharedDatasources.sources,[c.namespace]:[...i.sharedDatasources.sources[c.namespace],c]};d.push(...p[c.namespace]),await b.setSharedSources(p)}else(((s=(a=i.root.tabs.find(b.by("path",e.path)).content)==null?void 0:a.metadata)==null?void 0:s.datasources)||[]).push(c);return{list:d,path:e.path,namespace:e.datasource.namespace}}catch{console.error("Error while adding the datasource",e.datasource.id),t("Error while adding the datasource")}}),al=Q("datasources/edit-datasource",async(e,{getState:r,rejectWithValue:t})=>{try{const{namespace:a,path:s}=e,i=r(),c=!!e.namespace,l=rl(s,i);let d=He.defaultTo(l[a||s],[]);return d=d.map(p=>p.id===e.id?{...p,[e.property]:e.value}:p),c&&await b.setSharedSources({...i.sharedDatasources.sources,[e.namespace]:d}),{list:d,path:e.path,namespace:e.namespace}}catch{t(`Error while editing datasource ${e.id}`)}}),bI=e=>e.type===Zn.fulfilled.type,Zn=Q("datasources/rename-datasource",async(e,{getState:r,rejectWithValue:t})=>{try{const a=r(),s=!!e.namespace,i=e.namespace||e.path,c=rl(e.path,a),l=He.defaultTo(c[i],[]),d=new RegExp(`^${e.id}\\b`,"");if(l.forEach(p=>{var m;const g=(b.isObjectDatasource(p)||!b.isSimpleDatasource(p))&&p.from&&d.test(p.from);e.updateRefs&&((m=p.events)==null||m.forEach(_=>{var E,x,C,I,P;switch(_.type){case"method":{const j=_;j.params.forEach(M=>{M.datasource&&Object.assign(M,{datasource:M.datasource.replace(new RegExp(`^${e.id}`,""),e.new_name)})}),j.returns&&Object.assign(j.returns,{datasource:(x=(E=j.returns)==null?void 0:E.datasource)==null?void 0:x.replace(new RegExp(`^${e.id}`,""),e.new_name)});return}case"simple-action":{const j=_;j.datasource&&Object.assign(j.datasource,{name:(C=j.datasource.name)==null?void 0:C.replace(new RegExp(`^${e.id}`,""),e.new_name),from:(I=j.datasource.from)==null?void 0:I.replace(new RegExp(`^${e.id}`,""),e.new_name),target:(P=j.datasource.target)==null?void 0:P.replace(new RegExp(`^${e.id}`,""),e.new_name)});return}default:return}})),p.id===e.id?p.id=e.new_name:g&&p.from&&(p.from=p.from.replace(new RegExp(`^${e.id}`,""),e.new_name))}),e.updateRefs){const p=b.getDatasourceId({id:e.id,namespace:e.namespace}),g=b.getDatasourceId({id:e.new_name,namespace:e.namespace});b.datasourcesSubject.next({path:e.path??"",action:b.DatasourcesActions.RENAME,old_reference:p,new_reference:g,is_shared:s})}return s&&await b.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}`)}}),Na=Q("datasources/delete-datasource",async(e,{getState:r,rejectWithValue:t})=>{try{const a=r(),s=!!e.namespace,i=e.namespace||e.path,l=rl(e.path,a)[i].filter(b.outById(e.id));return s&&await b.setSharedSources({...a.sharedDatasources.sources,[e.namespace]:l}),{list:l,path:e.path,namespace:e.namespace}}catch{return t(`Error while removing datasource ${e.id}`)}}),Ua=or({name:"root",initialState:()=>{const e=ea();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(s=>{s.path===t&&(s.view||(s.view={panel:{isOpen:!1,type:"",current:""}}),Object.assign(s.view.panel,a))})},addDataSource(e,r){var i;const{payload:{path:t,datasourceDef:a}}=r,s=e.tabs.find(c=>c.path===t);s&&(s.content.metadata.datasources=s.content.metadata.datasources||[],(i=s.content.metadata.datasources)!=null&&i.find(l=>l.id===a.id)||(s.content.metadata.datasources=[...s.content.metadata.datasources,{...a,events:[]}],s.flags={...s.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:b.SETTINGS_TAB_PATH,type:b.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((s,i)=>(i==null?void 0:i.weight)>((s==null?void 0:s.weight)||0)?i:s,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(s=>s.path===t?{...s,flags:{...s.flags,touched:!0,confirmed:!0},content:{...s.content,metadata:{...s.content.metadata,datasources:s.content.metadata.datasources.filter(i=>i.id!==a)}}}:s)},setDataSources(e,r){const{payload:{path:t,datasourceArr:a}}=r;e.tabs=e.tabs.map(s=>{var i;return s.path===t?{...s,flags:{...s.flags,touched:!0,confirmed:!0},content:{...s.content,metadata:{...(i=s.content)==null?void 0:i.metadata,datasources:a}}}:s})},setTabs(e,r){e.tabs=r.payload},closeTab(e,r){const t=r.payload;e.tabs.splice(t,1);const a=e.tabs.reduce((s,i)=>(i==null?void 0:i.weight)>((s==null?void 0:s.weight)||0)?i:s,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||Ua.caseReducers.setTabFlags(e,{type:r.type,payload:{path:r.payload,flags:{confirmed:!0}}}))},selectTab(e,r){const t=e.tabs.find(({path:s})=>s===r.payload);if(!t||e.activeTab===r.payload)return;const a=e.tabs.reduce((s,i)=>(i==null?void 0:i.weight)>((s==null?void 0:s.weight)||0)?i:s,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:i})=>t.path===i);a||(e.tabs.push(t),a=e.tabs[e.tabs.length-1]);const s=e.tabs.reduce((i,c)=>(c==null?void 0:c.weight)>((i==null?void 0:i.weight)||0)?c:i,null);a.weight=s?(s.weight||0)+1:1,a.extra={...a.extra,...t.extra}},selectTabByReference(e,r){const t=[b.FileFolderType.SETTINGS,b.FileFolderType.DEBUGGER],a=r.payload;let s=e.tabs.find(({path:i})=>a.path===i);if((t.includes(a.type)||s!=null&&s.flags.confirmed)&&(a.flags={...a.flags,confirmed:!0}),!s){const i=e.tabs.findIndex(({flags:{confirmed:c}})=>c===!1);i!==-1&&!t.includes(a.type)?e.activeTab===e.tabs[i].path?(e.tabs[i]=a,s=e.tabs[i]):(e.tabs.push(a),s=e.tabs[e.tabs.length-1],e.tabs.splice(i,1)):(e.tabs.push(a),s=e.tabs[e.tabs.length-1])}if(e.activeTab!==a.path){const i=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,s.weight=((i==null?void 0:i.weight)||0)+1}s.extra={...s.extra,...a.extra},s.flags={...s.flags||{},...a.flags||{}}},setContent(e,r){const{path:t,content:a,contentPath:s}=r.payload;e.tabs=e.tabs.map(i=>{if(i.path!==t)return i;let c=!1,l=i.flags.confirmed;if(typeof a=="string")c=i.initialContent!==a,l=!l&&c?!0:l;else{const d=JSON.stringify(He.get(i.initialContent,s||"",i.initialContent)),p=JSON.stringify(He.get(a,s||"",a));c=d!==p,l=!l&&c?!0:l}return a&&typeof a=="object"&&(s?He.set(i.content,s,a):i.content=a),typeof a=="string"&&(i.content=a),{...i,flags:{...i.flags,touched:c,confirmed:l}}})},setTabFlags(e,r){const{path:t,flags:a}=r.payload;e.tabs=e.tabs.map(s=>s.path===t?{...s,flags:{...s.flags,...a}}:s)},setTabsFlags(e,r){const{tabs:t,flags:a}=r.payload;e.tabs=e.tabs.map(s=>t.includes(s.path)?{...s,flags:{...s.flags,...a}}:s)},setTabExtra(e,r){const{path:t,extra:a,flags:s}=r.payload;e.tabs=e.tabs.map(i=>i.path===t?{...i,extra:{...i.extra,...a},flags:s?{...i.flags,...s}:i.flags}:i)},addWebFormStyles(e,r){const{path:t,styles:a=[]}=r.payload,s=e.tabs.find(i=>i.path===t);if(s){const i=s.content.metadata.styles.map(({name:l})=>l),c=a.filter(({name:l})=>!i.includes(l));s.content.metadata.styles=[...s.content.metadata.styles,...c].map(({scope:l,...d})=>({...d}))}},changeTabEditor(e,r){return e.tabs=e.tabs.map(t=>t.path===r.payload.path?r.payload:t),e}},extraReducers:e=>{e.addCase(fc,(r,t)=>{if(t.payload.settingsKey==="studio.enablePreview"&&t.payload.value===!1){const a=r.tabs.find(({flags:{confirmed:s}})=>s===!1);a&&Ua.caseReducers.setTabFlags(r,{type:"",payload:{path:a.path,flags:{confirmed:!0}}})}}),e.addCase(ev.fulfilled,(r,t)=>{if(!t.payload)return;const{content:a,line:s,path:i}=t.payload,c=r.tabs.find(l=>l.path===i);if(c&&typeof c.content=="string"){const l=c.content.trim().split(`
100
100
  `);l.splice(s,0,a),c.content=l.join(`
101
101
  `)}}),e.addCase(Xn.pending,(r,t)=>{const{tab:a}=t.meta.arg;switch(a.type){case b.FileFolderType.CLASS:case b.FileFolderType.METHOD:b.lspSubject.next({action:b.LspActions.WILL_SAVE,payload:{filePath:a.path}});break}}),e.addCase(Xn.fulfilled,(r,t)=>{if(!t.payload)return;const a=r.tabs.find(({path:s})=>{var i;return s===((i=t.payload)==null?void 0:i.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 b.FileFolderType.CLASS:case b.FileFolderType.METHOD:b.lspSubject.next({action:b.LspActions.DID_SAVE,payload:{filePath:a.path,content:a.content}});break}t.payload.errors.length>0&&b.toastSubject.next({kind:"error",message:t.payload.errors})}}),e.addCase(Xn.rejected,(r,t)=>{b.toastSubject.next({kind:"danger",message:"Cannot save file"})}),e.addCase(rv.fulfilled,(r,t)=>{const a=[...t.payload.files];r.tabs=r.tabs.map(s=>{if([b.FileFolderType.CLASS,b.FileFolderType.METHOD].includes(s.type)){const i=a.find(c=>c.name===s.name&&c.type===s.type);if(i){const c=new Date(s.date),l=new Date(i.date);if(c.getTime()!==l.getTime())return{...s,flags:{...s.flags,old:!0}}}}return s})}),e.addCase(vc.pending,(r,t)=>{r.tabs=r.tabs.map(a=>a.path===t.meta.arg.path?{...a,flags:{...a.flags,loading:!0}}:a)}),e.addCase(vc.fulfilled,(r,t)=>{const a=t.payload;if(a){const s=t.meta.arg;r.tabs=r.tabs.map(i=>{if(i.name===s.name&&i.type===s.type){const c=i.extra||{};return i.type===b.FileFolderType.METHOD?(c.attributes=b.parseAttributes(a.content),a.content=b.addAttributesToContent(a.content,{})):i.type===b.FileFolderType.SETTINGS&&(a.content={}),{...i,initialContent:a.content,content:a.content,date:a.date,flags:{},extra:c}}return i})}}),e.addCase(Jc.fulfilled,(r,t)=>{if(!t.payload)return;const{line:a,offset:s}=t.meta.arg,i=r.tabs.find(({path:c})=>{var l;return c===((l=t.payload)==null?void 0:l.path)});i&&(i.extra={...i.extra,initialLineInfo:{line:a,offset:s,lastModification:Date.now()}})}),e.addCase(tv.fulfilled,(r,t)=>{if(!t.payload)return;const{selection:a}=t.meta.arg,s=r.tabs.find(({path:i})=>{var c;return i===((c=t.payload)==null?void 0:c.path)});s&&(s.extra={...s.extra,initialSelectionInfo:{selection:a,lastModification:Date.now()}})}),e.addCase(Jn.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(gc.pending,(r,t)=>{const a=t.meta.arg,s=`${a.path}${a.ext?`.${a.ext}`:""}`;switch(a.ext){case"4dm":case"4qs":b.lspSubject.next({action:b.LspActions.WILL_DELETE,payload:{filePath:s}});break}}),e.addCase(gc.fulfilled,(r,t)=>{const{deleted:a,node:s}=t.payload;if(!a)return;const i=`${s.path}${s.ext?`.${s.ext}`:""}`;switch(s.ext){case"4dm":case"4qs":b.lspSubject.next({action:b.LspActions.DID_DELETE,payload:{filePath:i}});break}if(r.tabs=r.tabs.filter(c=>c.path!==i),r.recent=r.recent.filter(({path:c})=>i!==c),r.tabs.length){r.activeTab=r.tabs[r.tabs.length-1].path;return}r.activeTab=""}),e.addCase($a.fulfilled,(r,t)=>{const{draggedNode:a,newLocation:s}=t.meta.arg;if(r.tabs.find(i=>i.path===`${a.path}${a.ext?`.${a.ext}`:""}`))return r.tabs=r.tabs.map(i=>i.path===`${a.path}${a.ext?`.${a.ext}`:""}`?{...i,path:`${s.path}/${a.name}.${a.ext}`}:i),r.recent=r.recent.map(i=>i.path===`${a.path}${a.ext?`.${a.ext}`:""}`?{...i,path:`${s.path}/${a.name}.${a.ext}`}:i),r.activeTab=`${s.path}/${a.name}.${a.ext}`,r}),e.addCase(Ts.fulfilled,(r,t)=>{const a=r.tabs.find(s=>s.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(nv.fulfilled,(r,t)=>{var i;if(!((i=t.payload)!=null&&i.path))return;const a=r.tabs.find(b.by("path",t.payload.path));if(!a)return;a.content=a.content+`
102
102