@ws-ui/store 0.1.2 → 0.1.3
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 +1 -1
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.es.js +1 -0
- package/dist/index.es.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs.js
CHANGED
|
@@ -126,7 +126,7 @@ Check the top-level render call using <`+I+">.")}return R}}function en(g,R){{if(
|
|
|
126
126
|
`:`Class extends DataStoreImplementation
|
|
127
127
|
`}}};e.type==="dataclass"&&!e.toCreate?p=[{...h("dataclass")},{...h("collection")},{...h("entity")}]:e.type==="dataclass"&&e.toCreate?p=[{...h(e.toCreate)}]:p=[{...h("model")}],p=p.filter(_=>!d.find(({name:S,ext:T})=>S===_.name&&T===(i?"4qs":"4dm"))),await Promise.all(p.map(async({name:_,content:S})=>{await n(ua({type:E.FileFolderType.CLASS,path:s,fileName:_,parentNode:c,content:S,qodly:a.settings.server.qodly}))})),await n(Ar(s))}),Ar=re("explorer/fetchFolderContent",async(e,{rejectWithValue:n})=>{try{return(await E.getNodeInfo({verb:E.DesignerRequestVerb.GET_INFO,path:e})).map(a=>{const s=`${e}/${a.name}`,{editor:i,supportedEditors:c}=Er(`${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 n("Failed loading file content please Reload")}},{getPendingMeta:()=>{}}),Ka=re("explorer/fetchFolderContentWithoutExpanding",async(e,{rejectWithValue:n})=>{try{return(await E.getNodeInfo({verb:E.DesignerRequestVerb.GET_INFO,path:e})).map(a=>{const s=`${e}/${a.name}`,{editor:i,supportedEditors:c}=Er(`${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 n("Failed loading file content please Reload")}},{getPendingMeta:()=>{}});function rD(e){const n=e.split(".");return n.pop(),{name:n.join("."),ext:e.split(".")[e.split(".").length-1]}}const nD=re("explorer/uploadFile",async e=>{const n=e.type.includes("image/")?"$rawPict=true":"$binary=true";try{const t=await fetch(`/rest/$upload?${n}`,{method:"POST",headers:{"Content-Type":e.type},body:e});return{status:t.status,data:await t.json()}}catch{return{status:500,data:null}}}),aD=re("explorer/uploadFile",async({file:e,path:n,parentNode:t},{dispatch:a})=>{const{editor:s,supportedEditors:i}=Er(n),{name:c,ext:l}=rD(e.name);a(Kg({parent:t,child:{name:c,path:`${n}/${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=${n}`,{method:"POST",headers:{"Content-Type":e.type},body:e});return d.status>=300?(a(dc({parent:t,child:{name:c,path:`${n}/${e.name}`,type:e.type,error:{message:"error uploading file"},flags:{},config:{editor:s,supportedEditors:i},ext:l}})),d.status!==413&&E.toastSubject.next({message:"error uploading file",kind:"danger"})):await a(Ar(t.path)),{status:d.status,fileName:e.name}}catch{return a(dc({parent:t,child:{name:c,path:`${n}/${e.name}`,type:e.type,error:{message:"error uploading file"},flags:{},config:{editor:s,supportedEditors:i},ext:l}})),E.toastSubject.next({message:"error uploading file",kind:"danger"}),{status:500,fileName:e.name}}}),ua=re("explorer/createNewFile",async({fileName:e,type:n,path:t,parentNode:a,content:s},{dispatch:i,rejectWithValue:c,getState:l})=>{const{server:{qodly:d},project:p}=l().settings;try{const h=await E.setFileContent({name:Xg(e,n,d),content:s||Jg(n,p),path:t,asText:[E.FileFolderType.CLASS,E.FileFolderType.METHOD].includes(n)});return a.error&&(a.flags.expanded?await i(Ar(a.path)):await i(Ka(a.path))),{qodly:d,file:h,parentNode:a}}catch{return c("failed to create folder")}});function Qg(e,n){const{qodly:t=!0,withExtension:a=!0}=n||{},s=E.getFileExtentionFromType(e.type,t);let i="";switch(e.type){case E.FileFolderType.WEBFORM:i=`${E.FolderRootPath.WEBFORMS}/${e.name}`;break;case E.FileFolderType.METHOD:i=`${E.FolderRootPath.METHODS}/${e.name}`;break;case E.FileFolderType.CLASS:i=`${E.FolderRootPath.CLASSES}/${e.name}`;break;default:return""}return`${i}${a?`.${s}`:""}`}const oD=re("explorer/createNewFileAndOpen",async(e,{dispatch:n,getState:t})=>{const a=await n(ua(e)).unwrap(),{qodly:s}=t().settings.server;if(a){const{file:i}=a,c=Qg(i,{withExtension:!1,qodly:s}),{editor:l}=Er(c);await n(Ja({file:{name:e.fileName,type:i.type,path:c,editor:l,date:new Date().toISOString()}}))}}),us=re("explorer/createNewNode",async({fileName:e,path:n,parentNode:t},{rejectWithValue:a})=>{try{return{file:await E.createFolder({verb:E.DesignerRequestVerb.CREATE_FOLDER,path:`${n}/${e}`,recursive:!0}),parentNode:t}}catch{return E.toastSubject.next({message:"failed to create folder",kind:"danger"}),a("failed to create folder")}}),Xs=async(e,n={})=>{try{const t=e.path.split(".").at(-1),a=await E.getNodeInfo({verb:E.DesignerRequestVerb.GET_INFO,path:e.path,content:!0,as:Ch(t)?"json":"text"}),s={editor:e.editor},i=E.getTypeFromExtension(e.path);i===E.FileFolderType.METHOD&&(s.attributes=E.parseAttributes(a.content),a.content=E.addAttributesToContent(a.content,{}));const{content:c,date:l,ext:d}=a;return n.confirmed===void 0&&(n.confirmed=!0),{date:l,view:{panel:{isOpen:!1,type:"",current:""}},flags:{enabled:["WebForm","MForm"].includes(d),confirmed:n.confirmed},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===E.ERROR_CODES.FILE_NOT_FOUND))switch(e.path){case E.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:E.FileFolderType.ROLES,initialContent:s,content:s}}case E.SETTINGS_TAB_PATH:{const s={};return{date:new Date().toISOString(),flags:{},extra:{editor:{key:"editors:settings"}},name:"Settings",path:e.path,type:E.FileFolderType.SETTINGS,initialContent:s,content:s}}}throw t}},Ja=re("explorer/openFile",async({file:e,inactive:n,isNew:t,flags:a={}},{getState:s,dispatch:i})=>{const{root:{tabs:c},roles:l,debugger:{sessions:d}}=s(),p=c.find(({path:_})=>e.path===_);if(p){const _={...p,extra:{...p==null?void 0:p.extra,editor:e.editor},flags:{...p==null?void 0:p.flags,...a}};return i(Lt(_)),_}if(e.path.startsWith("Debugger")){const _=d.find(S=>`Debugger/${S.threadId}`===e.path);if(_){const{source:{content:S},source:T}=_.currentStackFrame,x={name:e.name,type:E.FileFolderType.DEBUGGER,date:new Date().toISOString(),path:e.path,content:S,view:{panel:{isOpen:!1,type:"",current:""}},initialContent:S,flags:{confirmed:!0},extra:{source:T,editor:e.editor}};return i(Lt(x)),x}}let h=null;try{h=await Xs(e,a)}catch(_){const{data:S}=_;if(S.__ERROR.find(T=>[E.ERROR_CODES.JSON_MALFORMED,E.ERROR_CODES.JSON_MALFORMED_AT_LINE].includes(T.errCode))){const{confirmed:T}=await i(fr({title:"Corrupt file",type:Gt.CONFIRM,color:Dr.WARNING,message:"Open in code editor ?"})).unwrap();if(T){const x=await E.getNodeInfo({verb:E.DesignerRequestVerb.GET_INFO,path:e.path,content:!0,as:"text"}),{content:F,date:D,ext:W}=x;h={date:D,view:{panel:{isOpen:!1,type:"",current:""}},flags:{enabled:["WebForm","MForm"].includes(W),confirmed:!0},extra:{editor:E.EDITOR.Code},name:e.name,path:e.path,type:E.getTypeFromExtension(e.path),initialContent:F,content:F}}}}return h&&(e.path===E.ROLES_TAB_PATH&&!l.flags.touched?i(Yc({content:h.content,date:h.date})):e.path===E.SETTINGS_TAB_PATH&&i(Js({path:"project",value:h.content})),i((n?Ov:Lt)({...h,isNew:t})),h)}),Kc=re("explorer/openFileAtLine",async({file:e},{getState:n,dispatch:t})=>{const{tabs:a}=n().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(Lt(c)),c}const i=await Xs(e);return t(Lt(i)),i}),ev=re("explorer/injectContentAtLine",async(e,{getState:n,dispatch:t,rejectWithValue:a})=>{const s=n();e.path.split("/").pop();const c=vt(s.explorer,e.path);if(!c)return a(`Error while trying to inject content in file ${e.path}`);const l=await Xs({name:c.name,date:c.date||new Date().toISOString(),path:`${c.path}.${c.ext}`,type:E.FileFolderType.CLASS,editor:c.config.editor});return await t(Lt(l)),{...e,path:`${c.path}.${c.ext}`}}),tv=re("explorer/openFileAtSelection",async({file:e},{getState:n,dispatch:t})=>{const{tabs:a}=n().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(Lt(c)),c}const i=await Xs(e);return t(Lt(i)),i}),hc=re("explorer/deleteFile",async e=>{const{name:n,type:t,path:a,flags:s}=e;if(s.error)return{deleted:!0,node:e};const i=a.split("/");return i.pop(),{deleted:await E.dropFile({root:E.FolderRootType.ROOT,type:Zg(t),verb:E.DesignerRequestVerb.DROP,name:n,path:i.join("/")}),node:e}}),sD=re("explorer/deleteFolder",async e=>{const{path:n,flags:t}=e;if(t.error)return{deleted:!0,node:e};const{deleted:a}=await E.removeItem({force:!0,path:n,verb:E.DesignerRequestVerb.REMOVE_ITEM});return{deleted:a,node:e}}),iD=re("explorer/removeFileNode",async(e,{getState:n,dispatch:t})=>{const a=`${e.path}.${e.ext}`;if(await E.removeItem({verb:E.DesignerRequestVerb.REMOVE_ITEM,path:a,force:!0}),e.path==="Classes/DataStore"&&setTimeout(()=>{t(kn())},$s),e.ext){const{tabs:s}=n().root,i=s.findIndex(c=>c.path===a);i>=0&&t(nl(i))}return{deleted:!0,node:e}}),ca=re("explorer/renameFile",async({file:e,newname:n})=>{if(e.type!=="folder"){const a=e.path.split("/");a.pop();const s=`${a.join("/")}/${e.name}.${e.ext}`,i=`${a.join("/")}/${n}.${e.ext}`;return await E.moveItem({verb:E.DesignerRequestVerb.MOVE_ITEM,path:s,newpath:i}),{old:{...e,path:s},new:{...e,name:n,path:i}}}const t=e.path.split("/");return t.pop(),await E.moveItem({verb:E.DesignerRequestVerb.MOVE_ITEM,path:`${t.join("/")}/${e.name}`,newpath:`${t.join("/")}/${n}`}),{old:e,new:{...e,name:n,path:`${t.join("/")}/${n}`}}}),Xa=re("explorer/relocateNode",async({draggedNode:e,newLocation:n},{rejectWithValue:t})=>{try{await E.moveItem({verb:E.DesignerRequestVerb.MOVE_ITEM,path:`${e.path}.${e.ext}`,newpath:`${n.path}/${e.name}.${e.ext}`})}catch{return t("can't move item")}}),cs=re("explorer/duplicateNode",async({node:e,duplicateName:n},{rejectWithValue:t,fulfillWithValue:a,getState:s})=>{const i=e.path.split("/");i.pop();try{const{tabs:c}=s().root,l=c.find(({path:b})=>b===`${e.path}${e.ext?`.${e.ext}`:""}`),d=["4dm","4qm","4qs"].includes(e.ext),{content:p}=l||await E.getNodeInfo({verb:E.DesignerRequestVerb.GET_INFO,path:`${e.path}.${e.ext}`,content:!0,as:d?"text":"json"}),h=await E.setFileContent({name:`${n}.${e.ext}`,content:p,path:i.join("/"),asText:d});return a({node:{...h,path:i.join("/")}})}catch{return t("failed to duplicate file")}}),uD=re("explorer/executeMethod",async({methodName:e,params:n=[],resultingDataSource:t={},namespace:a=""},{rejectWithValue:s})=>{var i,c;try{const d=await window.Method4D.buildMethod({methodName:e,parameters:n,resultingDataSource:t},{namespace:a},null).callServerSide({id:"",serverSideRef:""},"onclick",{});return d!=null&&d.__NOTIFICATION?E.toastSubject.next({message:`${((i=d.__NOTIFICATION)==null?void 0:i.message)||""}`,kind:`${((c=d.__NOTIFICATION)==null?void 0:c.type)||"info"}`}):E.toastSubject.next({message:"Method executed Successfully",kind:"message"}),d}catch(l){return E.toastSubject.next({message:l.message||`Error executing the method "**${e}**"`,kind:"danger",markdown:!0}),s("can't execute method")}}),cD=re("files/fetchFiles",async()=>E.getFolders(E.FolderRootType.WEBFORMS,E.FolderRootType.METHODS,E.FolderRootType.CLASSES)),Jc=re("tabs/renameDatasource",async(e,{dispatch:n,getState:t})=>{var S,T;const a=!!e.datasourceNamespace,{confirmed:s}=await n(fr({message:"Are you sure you want to rename the datasource?",title:"Rename Datasource",type:Gt.CONFIRM,color:Dr.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,h=t();let b=[];if(a){const x=h.sharedDatasources.sources[l]||[];b.push(...x)}else if(p){const x=h.root.tabs.find(E.by("path",p));if(b=(T=(S=x==null?void 0:x.content)==null?void 0:S.metadata)==null?void 0:T.datasources,!b)return null}const _=new RegExp(`^${c}\\b`,"");if(b=b.map(x=>{const F=(E.isObjectDatasource(x)||!E.isSimpleDatasource(x))&&x.from&&_.test(x.from),D=x.events?x.events.map(W=>{var $,j,A,K;switch(W==null?void 0:W.type){case"method":{const G=W;return G.params?{...G,params:G.params.map(Y=>{var ie;return{...Y,datasource:(ie=Y.datasource)==null?void 0:ie.replace(new RegExp(`^${c}`,""),d)}}),returns:($=G.returns)!=null&&$.datasource?{...G.returns,datasource:(j=G.returns.datasource)==null?void 0:j.replace(new RegExp(`^${c}`,""),d)}:G.returns}:G}case"simple-action":{const G=W;return G.datasource?{...G,datasource:{...G.datasource,name:(A=G.datasource.name)==null?void 0:A.replace(new RegExp(`^${c}`,""),d),from:(K=G.datasource.from)==null?void 0:K.replace(new RegExp(`^${c}`,""),d)}}:G}default:return W}}):x.events;return x.id===c?{...x,id:d,events:D}:F&&x.from?{...x,from:x.from.replace(new RegExp(`^${c}`,""),d),events:D}:{...x,events:D}}),i){const x=a?`${l}:${c}`:`${c}`,F=a?`${l}:${d}`:`${d}`;E.datasourcesSubject.next({path:p??"",action:E.DatasourcesActions.RENAME,old_reference:x,new_reference:F,is_shared:a})}return{path:p,namespace:l,datasources:b}}),Xc=re("tabs/edit-datasource",(e,{getState:n})=>{var i,c;const t=n();let a=[];if(e.namespace)a=t.sharedDatasources.sources[e.namespace];else{const l=t.root.tabs.find(E.by("path",e.path));l&&(a=((c=(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=re("tabs/fetchChanges",async(e,{getState:n})=>{const a=ba(n()).filter(s=>[E.FileFolderType.METHOD,E.FileFolderType.CLASS].includes(s.type));return E.getFilesInfo(...a.map(s=>{const[i]=s.path.split("/").filter(Boolean);return{name:s.name,type:s.type,root:i,path:"."}}))}),lD=re("files/saveAll",async(e,{getState:n,dispatch:t})=>{const a=Mc(n());for(const s of a)t(la({tab:s}))}),Zc=re("files/tryCloseTab",async(e,{getState:n,dispatch:t})=>{const{tabs:a}=n().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(fr({title:Ms(i),message:"Your unsaved changes will be lost. Proceed anyway?",type:Gt.CONFIRM,color:Dr.WARNING,icon:"FdWarningDanger"})).unwrap();if(!c)return!1}return t(nl(s)),i.path===E.ROLES_TAB_PATH&&i.flags.touched&&(async()=>{const l=await E.getNodeInfo({verb:E.DesignerRequestVerb.GET_INFO,path:E.ROLES_TAB_PATH,content:!0,as:"json"});t(Yc({content:l.content,date:l.date}))})(),!0}),fD=re("files/tryCloseOtherTabs",async(e,{getState:n,dispatch:t})=>{const{tabs:a}=n().root;if(a.some(i=>i.path!==e&&i.flags.touched===!0)){const{confirmed:i}=await t(fr({title:"Closing other tabs",message:"Your changes will be lost if you do not save them. Close anyway?",type:Gt.CONFIRM,color:Dr.WARNING,icon:"FdWarningDanger"})).unwrap();if(!i)return}t(Cv(e))}),dD=re("files/tryCloseAllTabs",async(e,{getState:n,dispatch:t})=>{const{tabs:a}=n().root;if(a.some(i=>i.flags.touched===!0)){const{confirmed:i}=await t(fr({title:"Closing all tabs",message:"Your changes will be lost if you do not save them. Close anyway?",type:Gt.CONFIRM,color:Dr.WARNING,icon:"FdWarningDanger"})).unwrap();if(!i)return}t(wv())}),pD=re("files/tryCloseRightTabs",async(e,{getState:n,dispatch:t})=>{const{tabs:a}=n().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(fr({title:"Closing right tabs",message:"Your changes will be lost if you do not save them. Close anyway?",type:Gt.CONFIRM,color:Dr.WARNING,icon:"FdWarningDanger"})).unwrap();if(!i)return}t(Tv(e))}),hD=re("files/tryCloseLeftTabs",async(e,{getState:n,dispatch:t})=>{const{tabs:a}=n().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(fr({title:"Closing left tabs",message:"Your changes will be lost if you do not save them. Close anyway?",type:Gt.CONFIRM,color:Dr.WARNING,icon:"FdWarningDanger"})).unwrap();if(!i)return}t(xv(e))}),gc=re("files/reloadTab",async(e,{dispatch:n})=>{if(e.flags.touched){const{confirmed:s}=await n(fr({title:Ms(e),message:"Changes made to the file will be lost. Continue?",type:Gt.CONFIRM,color:Dr.WARNING,icon:"FdWarningDanger"})).unwrap();if(!s)return}const t=zh(e.path),a=await E.getNodeInfo({verb:E.DesignerRequestVerb.GET_INFO,path:e.path,content:!0,as:t});if(e.path===E.ROLES_TAB_PATH){const{roles:s,privileges:i}=Vs(a.content);n(zc({roles:s,privileges:i}))}else if(e.path===E.SETTINGS_TAB_PATH){const{content:s}=a;n(Js({path:"project",value:s}))}else{const{content:s}=a;e.type===E.FileFolderType.WEBFORM?E.webformSubject.next({path:e.path,action:E.WebformActions.RELOAD,payload:s.components}):e.type===E.FileFolderType.MODEL&&eg.next({action:"reload",payload:s})}return a}),la=re("files/saveTab",async({tab:e},{dispatch:n,getState:t})=>{const{path:a,content:s}=e;if(e.type===E.FileFolderType.DEBUGGER)return{...e,errors:[]};a.split("/").pop();const c=await E.getFilesInfo({path:a});if(c.files[0]){const h=new Date(e.date),b=new Date(c.files[0].date);if(h.getTime()<b.getTime()){const{confirmed:_}=await n(fr({title:Ms(e),message:"New content has been found on the server. Are you sure you want to continue?",type:Gt.CONFIRM,icon:"FdSave"})).unwrap();if(!_)return n(Sv({path:a,flags:{old:!0}})),null}}const l=await E.saveContent({verb:E.DesignerRequestVerb.SAVE_CONTENT,content:gD(e,t()),path:a});(e.type===E.FileFolderType.CLASS||e.type===E.FileFolderType.MODEL)&&setTimeout(()=>{n(kn())},$s);const d=(l.modelErrors||[]).map(h=>h.message),p=(l.permissionsErrors||[]).map(h=>h.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}]:[]}}),gD=(e,n)=>{switch(!0){case e.path==="settings.json":case e.path===E.SETTINGS_TAB_PATH:return n.settings.project;case e.type===E.FileFolderType.ROLES:return{...e.content,...Ks(n.roles)};case e.type===E.FileFolderType.MODEL:return e.content||{toJSON:!0,dataClasses:[],extraProperties:{}};default:return e.content}},Gp=async e=>{if(e.type===E.FileFolderType.DATA_EXPLORER)return{name:"Data Explorer",path:e.path,flags:{},view:{panel:{isOpen:!1,type:"",current:""}},type:e.type,date:new Date().toISOString()};const n=e.path.split("/").filter(Boolean)[0],t=await E.getFile({root:n,type:e.type,verb:E.DesignerRequestVerb.GET,name:e.name}),a={};t.type===E.FileFolderType.METHOD&&(a.attributes=E.parseAttributes(t.content));const{date:s,name:i,type:c,content:l}=t;return{date:s,flags:{enabled:e.type===E.FileFolderType.WEBFORM},extra:a,view:{panel:{isOpen:!1,type:"",current:""}},name:i,path:e.path,type:c,initialContent:l,content:c===E.FileFolderType.MODEL?Th(l):l}},nv=re("files/tryInjectMethod",async({type:e,dataclass:n},{getState:t,dispatch:a})=>{const{root:{tabs:s},settings:{server:{qodly:i}}}=t(),c=E.getFileExtentionFromType("class",i);let l="",d="",p=null;if(!n)l="DataStore",d=`Classes/DataStore.${c}`;else switch(e){case"dataclass":l=n,d=`Classes/${n}.${c}`;break;case"collection":l=`${n}Selection`,d=`Classes/${n}Selection.${c}`;break;case"entity":l=`${n}Entity`,d=`Classes/${n}Entity.${c}`;break;default:return p}const h=s.find(E.by("path",d));if(h)return a(Lt(h)),h;try{p=await Gp({name:l,date:new Date().toISOString(),path:`class/${l}.${c}`,type:E.FileFolderType.CLASS})}catch{n?await a(pc({type:"dataclass",className:n,collectionName:`${n}Selection`,toCreate:e})):await a(pc({type:"model"}))}return p=await Gp({name:l,date:new Date().toISOString(),path:`class/${l}.${c}`,type:E.FileFolderType.CLASS}),p.path=d,a(Lt(p)),p}),vD=re("roles/open",async(e,{dispatch:n,getState:t})=>{const{tabs:a}=t().root,s=a.find(i=>i.path===E.ROLES_TAB_PATH);if(s)return n(Lt(s)),s;n(Os())});function qp(e,n){const{line:t,offset:a,type:s="saved"}=n;e.breakpoints[s].locations.push({line:t}),Ke.isNumber(a)&&(e.breakpoints[s].offset=a)}function Yp(e,n,t,a){e.breakpoints[t].locations=n,Ke.isNumber(a)&&(e.breakpoints[t].offset=a)}function zp({filePath:e,fileType:n,methodName:t,className:a,ext:s,source:i}){return{filePath:e,fileType:n,methodName:t,className:a,ext:s,source:i,breakpoints:{draft:{locations:[],offset:0},saved:{locations:[],offset:0}}}}function Vp(e,n,t){let a=!1;const s=e.map(i=>i[t]!==n[t]?i:(a=!0,{...i,...n}));return a?s:[...s,n]}function as(e){return e.map(({label:n})=>({label:n}))}const av=lr({name:"debugger",initialState:()=>{var n,t;const{debugger:e={meta:{state:Gr.DETACHED},list:[],sessions:[],expressions:[]}}=pa();return{meta:{...e.meta,state:((n=e.meta)==null?void 0:n.state)===Gr.ATTACHED?(t=e.meta)==null?void 0:t.state:Gr.DETACHED},list:e.list||[],sessions:e.sessions||[],expressions:e.expressions||[]}},reducers:{addBreakpointDecoration(e,n){const{filePath:t,fileType:a,methodName:s,className:i,ext:c,source:l,breakpoint:d}=n.payload,p=jn(e.list,t,s,i);if(p)qp(p,d);else{if(a===E.FileFolderType.CLASS&&d.offset===void 0)throw new Error(`Cannot add a breakpoint on a function without offset. Try editing the ${i} class.`);const h=zp({filePath:t,fileType:a,methodName:s,className:i,ext:c,source:l});qp(h,d),e.list.push(h)}},removeBreakpointDecoration(e,n){const{filePath:t,methodName:a,line:s,offset:i=0,type:c="saved"}=n.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 h=p.breakpoints[c].offset||0;p.breakpoints[c].locations=p.breakpoints[c].locations.filter(b=>b.line+h!==d),c==="saved"&&(p.breakpoints.draft.locations=p.breakpoints.draft.locations.filter(b=>b.line+h!==d))})}}else{const l=jn(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,n){const{filePath:t,fileType:a,methodName:s,className:i,ext:c,source:l,breakpoints:d,offset:p,type:h="saved",clearDraft:b}=n.payload,_=jn(e.list,t,s);if(_)Yp(_,d,h,p),b&&h!=="draft"&&(_.breakpoints.draft.locations=[]);else{const S=zp({filePath:t,fileType:a,methodName:s,className:i,ext:c,source:l});Yp(S,d,h,p),e.list.push(S)}},clearBreakpoints(e,n){const{filePath:t,type:a="saved"}=n.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,n){const{threadId:t,line:a,highlight:s}=n.payload,i=ft(e.sessions,t);i&&(i.activeLine=a,s&&(i.highlightedLines={start:a,end:a}))},addExpression(e,n){const{threadId:t,label:a,save:s}=n.payload,i=ft(e.sessions,t);i&&i.stopped&&(i.expressions=[...i.expressions||[],{label:a}],s&&(e.expressions=as(i.expressions)))},removeExpression(e,n){const{threadId:t,index:a,save:s}=n.payload,i=ft(e.sessions,t);i&&(i.expressions=i.expressions.filter((c,l)=>l!==a),s&&(e.expressions=as(i.expressions)))},removeAllExpressions(e,n){const{threadId:t,save:a}=n.payload,s=ft(e.sessions,t);s&&(s.expressions=[],a&&(e.expressions=[]))},renameExpression(e,n){const{threadId:t,index:a,replacement:s,save:i}=n.payload,c=ft(e.sessions,t);c&&c.expressions[a]&&(c.expressions[a].label=s,i&&(e.expressions=as(c.expressions)))},setExpression(e,n){const{threadId:t,expression:a}=n.payload,s=ft(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,n){const{threadId:t,index:a,value:s}=n.payload,i=ft(e.sessions,t);if(i){const c=i.expressions[a];c&&(c.result=`"${s}"`,c.nakedResult=s)}},saveExpressions(e,n){const{expressions:t}=n.payload;e.expressions=as(t)},addSession(e,n){const{threadId:t,channelId:a,stackFrames:s,exceptions:i=[]}=n.payload,c=ft(e.sessions,t),l=s[0],{expressions:d=[]}=e;if(c)c.expressions=d;else{const p=Pc(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,n){const{threadId:t,changes:a}=n.payload;e.sessions=e.sessions.map(s=>s.threadId===t?{...s,...a}:s)},removeSession(e,n){const{threadId:t}=n.payload;e.sessions=e.sessions.filter(a=>a.threadId!==t)},removeSessionByIndex(e,n){const t=n.payload;e.sessions.splice(t,1)},setSessions(e,n){const t=n.payload;e.sessions=t},setCallChainVariables(e,n){const{threadId:t,frameId:a,variables:s}=n.payload;e.sessions=e.sessions.map(i=>{var c;return i.threadId===t?{...i,variables:{...i.variables,callchain:Vp((c=i.variables)==null?void 0:c.callchain,{frameId:a,items:s},"frameId")}}:i})},setExpressionVariables(e,n){const{threadId:t,variablesReference:a,variables:s}=n.payload;e.sessions=e.sessions.map(i=>{var c;return i.threadId===t?{...i,variables:{...i.variables,expressions:Vp((c=i.variables)==null?void 0:c.expressions,{variablesReference:a,items:s},"variablesReference")}}:i})},setSourceContent(e,n){const{threadId:t,content:a}=n.payload,s=ft(e.sessions,t);s&&(s.currentStackFrame.source={...s.currentStackFrame.source,content:a})},setDebuggerMeta(e,n){if(n.payload.state===Gr.ERROR){e.meta.error={...e.meta.error,time:Date.now()};const{override:t,error:a={code:null,reason:"",type:ms.SOCKET_ERROR}}=n.payload;if((t||e.meta.state!==Gr.ERROR)&&(e.meta.error={...e.meta.error,...a}),(a==null?void 0:a.type)===ms.SOCKET_CLOSURE&&!(a!=null&&a.reason)&&e.meta.state===Gr.DETACHED)return}e.meta.state=n.payload.state}},extraReducers:e=>{e.addCase(sv.fulfilled,n=>{n.sessions=[]})}}),{addBreakpointDecoration:yD,removeBreakpointDecoration:mD,setBreakpointsDecoration:bD,clearBreakpoints:_D,setActiveLine:ED,addExpression:SD,renameExpression:wD,removeExpression:TD,removeAllExpressions:CD,setExpression:xD,updateExpressionAt:RD,saveExpressions:OD,addSession:AD,updateSession:PD,removeSession:DD,removeSessionByIndex:ID,setSessions:ov,setCallChainVariables:FD,setExpressionVariables:$D,setSourceContent:MD,setDebuggerMeta:ND}=av.actions,sv=re("files/wipeDebuggerSessions",async(e,{getState:n,dispatch:t})=>{const{sessions:a}=n().debugger;for(const{threadId:s}of a){const i=Pc(s);t(Zc(i))}}),iv=re("files/removeDebuggerSessionsNotIn",async(e,{getState:n,dispatch:t})=>{const{threadIds:a}=e,{sessions:s}=n().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}}),Qc=re("models/fetch",async()=>{try{return(await E.http(E.API_PREFIX,{method:"POST",body:JSON.stringify({verb:E.DesignerRequestVerb.GET_INFO,path:E.MODEL_TAB_PATH,as:"json",content:!0}),headers:new Headers({"Content-Type":"application/json"})})).content}catch(e){return e.message}}),As=re("models/save",async(e,{getState:n,dispatch:t,rejectWithValue:a})=>{const{tabs:s}=n().root,i=s.find(c=>c.path===E.MODEL_TAB_PATH);if(!i)return a("Error while saving the model");try{const c=await E.http(E.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(kn())},$s),{...c,path:i.path,content:e.content||{toJSON:!0,dataClasses:[],extraProperties:{}}}}catch{return a("Error while saving the model")}}),LD=re("models/open",async(e,{dispatch:n,getState:t})=>{const{tabs:a}=t().root,s=a.find(i=>i.path==="models/main");if(s)return n(Lt(s)),s;n(Qc())}),jD=re("model/rename-dataclass",async(e,{getState:n,dispatch:t})=>{var b,_;const{dataclassId:a,selectionId:s,name:i}=e;let c=n();const l=c.explorer.find(S=>S.path===E.FolderRootPath.CLASSES);if(!l)throw new Error("Classes folder was not found!");await t(Ar(l.path)),c=n();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`}};(_=(b=c.explorer.find(S=>S.path===E.FolderRootPath.CLASSES))==null?void 0:b.children)==null||_.forEach(S=>{S.name===d.class.filename_update&&(d.class.newNameTaken=!0),S.name===d.entity.filename_update&&(d.entity.newNameTaken=!0),S.name===d.selection.filename_update&&(d.selection.newNameTaken=!0),S.name===a?(d.class.found=!0,d.class.file=S):S.name===`${a}Entity`?(d.entity.found=!0,d.entity.file=S):S.name===s&&(d.selection.found=!0,d.selection.file=S)});const p=Object.entries(d).reduce((S,T)=>{const[x,F]=T;return F.found?F.newNameTaken?[...S,{type:"error",message:`Cannot rename ${x} file to ${F.filename_update} because it already exists. The existing file will be used instead!`}]:S:[...S,{type:"warning",message:`${a} ${x} file was not found`}]},[]);p.length>0&&t(fr({message:"The following errors were encountered during dataclass rename:",views:{tips:p}}));const h=Object.values(d).filter(S=>S.found&&S.file&&!S.newNameTaken);await Promise.all(h.map(async S=>await t(ca({file:S.file,newname:S.filename_update})))),h.length>0&&t(Ar("Classes"))}),no={DATACLASS_DELETE:"dataclass.delete",DATACLASS_DRAGGABLE:"dataclass.draggable"},kD={model:{dataClasses:{},collections:{},extraProperties:{}},draft:{dataClasses:{},collections:{},extraProperties:{}},flags:{[no.DATACLASS_DELETE]:!0,[no.DATACLASS_DRAGGABLE]:!0}},uv=lr({name:"Models",initialState:kD,reducers:{setModelFlag(e,n){e.flags={...e.flags,...n.payload}}},extraReducers(e){e.addCase(Qc.fulfilled,(n,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}),n.draft.dataClasses=a,n.draft.collections=s,n.draft.extraProperties=i,n.model.dataClasses=a,n.model.collections=s,n.model.extraProperties=i}),e.addCase(As.pending,()=>{}).addCase(As.fulfilled,(n,t)=>{const a={},s={},i=t.payload.content.extraProperties||{};t.payload.content.dataClasses.forEach(c=>{a[c.name]=c,s[c.collectionName]=c}),n.draft.dataClasses=a,n.draft.collections=s,n.draft.extraProperties=i,n.model.dataClasses=a,n.model.collections=s,n.model.extraProperties=i})}}),{setModelFlag:BD}=uv.actions;var cv=(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))(cv||{}),Zs=(e=>(e.STORAGE="storage",e.RELATEDENTITY="relatedEntity",e.RELATEDENTITIES="relatedEntities",e.CALCULATED="calculated",e.COMPOSITION="composition",e.ALIAS="alias",e))(Zs||{});const WD=e=>["string","uuid","number","long"].includes(e.type),UD=[{label:"Storage",value:"storage"},{label:"Calculated",value:"calculated"}],HD=[{title:"UUID",kind:"storage",value:"uuid",calculatedType:"uuid",calculatedKind:"storage"},{title:"Long",kind:"storage",value:"long",calculatedType:"long",calculatedKind:"storage"}],GD=[{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"}],qD=[{label:"Expose as REST",value:"public"},{label:"Do not expose as REST",value:"publicOnServer"}],YD=[{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"}],VD=(e,n)=>({toJSON:!0,extraProperties:n,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 KD(e,n,t){const a=e;let s=0;for(;t[`${a}${s||""}`];)s++;return`${a}${s||""}`}const lv=e=>e.kind===Zs.RELATEDENTITY,fv=e=>e.kind===Zs.RELATEDENTITIES,JD=e=>fv(e)||lv(e),XD=()=>Xr(e=>e.model.draft.dataClasses),ZD=()=>Xr(e=>e.model.draft.collections),QD=e=>Xr(n=>n.model.draft.dataClasses[e]),eI=(e,n)=>Xr(t=>t.model.draft.dataClasses[e].attributes.find(E.by("name",n))),tI=()=>Xr(e=>e.model.draft.extraProperties),rI=()=>{const e=Xr(s=>s.model.flags),n=s=>s in e?e[s]:void 0,t=n(no.DATACLASS_DELETE),a=n(no.DATACLASS_DRAGGABLE);return{deleteDataclass:t,draggableDataclass:a,flags:e}},nI=uv.reducer;function Bu(e,n){const t=e.tabs.find(({path:a})=>a===E.SETTINGS_TAB_PATH);t&&(t.flags.touched=n)}const dv={SIDEBAR_SECTION_RESIZABLE:"sidebar.section.resizable"},pv={[dv.SIDEBAR_SECTION_RESIZABLE]:!0},hv=lr({name:"webforms",initialState:()=>{const{webforms:e}=pa();return{...e,templates:{data:[],selectedGroup:""},datasources:{...Oc.webforms.datasources,...e==null?void 0:e.datasources},flags:pv}},reducers:{toggleInspector:(e,n)=>{const{type:t}=n.payload;e.inspector[t].active=!e.inspector[t].active,e.inspector[t].active||(e.inspector[t].data=void 0)},inspect:(e,n)=>{const{type:t,data:a}=n.payload;e.inspector[t].active&&(e.inspector[t].data=a)},addComponent:(e,n)=>{e.components.push(n.payload)},editComponent:(e,n)=>{const{id:t,changes:a}=n.payload;e.components=e.components.map(s=>s.id===t?{...s,...a}:s)},removeComponent:(e,n)=>{const{payload:t}=n,a=e.components.findIndex(s=>s.id===t);a!==-1&&e.components.splice(a,1)},setSelectedGroup:(e,n)=>{e.templates.selectedGroup=n.payload.selectedGroup},setTemplatesData:(e,n)=>{e.templates.data=n.payload},setTemplateData:(e,n)=>{const{group:t,components:a}=n.payload,s=e.templates.data.find(i=>i.group===t);s&&(s.components=a)},setDatasourcesTheme:(e,n)=>{e.datasources.theme=n.payload},setWebformsFlag(e,n){e.flags={...e.flags,...n.payload}}},extraReducers(e){e.addCase(_v.fulfilled,(n,t)=>{n.components=t.payload})}}),{toggleInspector:aI,inspect:oI,addComponent:gv,editComponent:vv,removeComponent:yv,setSelectedGroup:sI,setTemplatesData:mv,setTemplateData:bv,setDatasourcesTheme:iI,setWebformsFlag:uI}=hv.actions,cI=hv.reducer,el=Ke.curry((e,n)=>{var s,i;const t={...n.sharedDatasources.sources},a=(i=((s=n.root.tabs.find(E.by("path",e)))==null?void 0:s.content).metadata)==null?void 0:i.datasources;return a&&(t[e]=a),Ke.cloneDeep(t)}),lI=re("webforms/fetchTemplates",async(e,{dispatch:n,getState:t})=>{const{data:a}=t().webforms.templates,s=t().settings.session["studio.tipsBaseUrl"]||"";if(!Ke.isEmpty(a))return a;try{const c=await(await fetch(`${s}/build/index.json?t=${Date.now()}`)).json();return n(mv(c)),c}catch{return[]}}),fI=re("webforms/fetchTemplate",async({name:e},{dispatch:n,getState:t})=>{const{data:a}=t().webforms.templates,s=a.find(i=>i.group===e);if(s&&!Ke.isEmpty(s.components))return s.components;try{const c=await(await fetch(`${s==null?void 0:s.link}?t=${Date.now()}`)).json();return n(bv({group:e,components:c})),c}catch{return[]}}),_v=re("webforms/fetchCraftedComponents",async(e,{rejectWithValue:n})=>{try{return(await E.getNodeInfo({path:"WebForms/crafted_components.json",verb:E.DesignerRequestVerb.GET_INFO,content:!0,as:"json"})).content}catch{return n("Error while loading the crafted components")}}),dI=re("webforms/addCraftedComponent",async(e,{dispatch:n,rejectWithValue:t,getState:a})=>{try{n(gv(e));const{webforms:{components:s}}=a();E.setCraftedComponents(s)}catch{return t("Error while adding the crafted component")}}),pI=re("webforms/editCraftedComponent",async(e,{dispatch:n,rejectWithValue:t,getState:a})=>{try{n(vv(e));const{webforms:{components:s}}=a();E.setCraftedComponents(s)}catch{return t("Error while editing the crafted component")}}),hI=re("webforms/removeCraftedComponent",async(e,{dispatch:n,rejectWithValue:t,getState:a})=>{try{n(yv(e));const{webforms:{components:s}}=a();E.setCraftedComponents(s)}catch{return t("Error while removing the crafted component")}}),tl=re("datasources/add-datasource",async(e,{getState:n,rejectWithValue:t})=>{var a,s;try{const i=n(),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 E.setSharedSources(p)}else(((s=(a=i.root.tabs.find(E.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")}}),rl=re("datasources/edit-datasource",async(e,{getState:n,rejectWithValue:t})=>{try{const{namespace:a,path:s}=e,i=n(),c=!!e.namespace,l=el(s,i);let d=Ke.defaultTo(l[a||s],[]);return d=d.map(p=>p.id===e.id?{...p,[e.property]:e.value}:p),c&&await E.setSharedSources({...i.sharedDatasources.sources,[e.namespace]:d}),{list:d,path:e.path,namespace:e.namespace}}catch{t(`Error while editing datasource ${e.id}`)}}),gI=e=>e.type===fa.fulfilled.type,fa=re("datasources/rename-datasource",async(e,{getState:n,rejectWithValue:t})=>{try{const a=n(),s=!!e.namespace,i=e.namespace||e.path,c=el(e.path,a),l=Ke.defaultTo(c[i],[]),d=new RegExp(`^${e.id}\\b`,"");if(l.forEach(p=>{var b;const h=(E.isObjectDatasource(p)||!E.isSimpleDatasource(p))&&p.from&&d.test(p.from);e.updateRefs&&((b=p.events)==null||b.forEach(_=>{var S,T,x,F,D;switch(_.type){case"method":{const W=_;W.params.forEach($=>{$.datasource&&Object.assign($,{datasource:$.datasource.replace(new RegExp(`^${e.id}`,""),e.new_name)})}),W.returns&&Object.assign(W.returns,{datasource:(T=(S=W.returns)==null?void 0:S.datasource)==null?void 0:T.replace(new RegExp(`^${e.id}`,""),e.new_name)});return}case"simple-action":{const W=_;W.datasource&&Object.assign(W.datasource,{name:(x=W.datasource.name)==null?void 0:x.replace(new RegExp(`^${e.id}`,""),e.new_name),from:(F=W.datasource.from)==null?void 0:F.replace(new RegExp(`^${e.id}`,""),e.new_name),target:(D=W.datasource.target)==null?void 0:D.replace(new RegExp(`^${e.id}`,""),e.new_name)});return}default:return}})),p.id===e.id?p.id=e.new_name:h&&p.from&&(p.from=p.from.replace(new RegExp(`^${e.id}`,""),e.new_name))}),e.updateRefs){const p=E.getDatasourceId({id:e.id,namespace:e.namespace}),h=E.getDatasourceId({id:e.new_name,namespace:e.namespace});E.datasourcesSubject.next({path:e.path??"",action:E.DatasourcesActions.RENAME,old_reference:p,new_reference:h,is_shared:s})}return s&&await E.setSharedSources({...a.sharedDatasources.sources,[e.namespace]:l}),{list:l,path:e.path,namespace:e.namespace}}catch{return t(`Error while renaming datasource ${e.namespace}:${e.id}`)}}),Za=re("datasources/delete-datasource",async(e,{getState:n,rejectWithValue:t})=>{try{const a=n(),s=!!e.namespace,i=e.namespace||e.path,l=el(e.path,a)[i].filter(E.outById(e.id));return s&&await E.setSharedSources({...a.sharedDatasources.sources,[e.namespace]:l}),{list:l,path:e.path,namespace:e.namespace}}catch{return t(`Error while removing datasource ${e.id}`)}}),ao=lr({name:"root",initialState:()=>{const e=pa();return{filesLoading:!1,tabs:e.tabs||[],activeTab:e.activeTab,recent:e.recent||[]}},reducers:{setPanelState(e,n){const{path:t,...a}=n.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,n){var i;const{payload:{path:t,datasourceDef:a}}=n,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 n={date:new Date().toISOString(),flags:{confirmed:!0},view:{panel:{isOpen:!1,type:"",current:""}},extra:{editor:{key:"editors:settings"}},name:"Settings",path:E.SETTINGS_TAB_PATH,type:E.FileFolderType.SETTINGS,initialContent:{},content:{}};let t=e.tabs.find(a=>a.path===n.path);if(t||(e.tabs.push(n),t=e.tabs[e.tabs.length-1]),e.activeTab!==n.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=n.path,t.weight=((a==null?void 0:a.weight)||0)+1}},removeDataSource(e,n){const{path:t,datasourceID:a}=n.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,n){const{payload:{path:t,datasourceArr:a}}=n;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,n){e.tabs=n.payload},closeTab(e,n){const t=n.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,n){e.tabs=e.tabs.filter(t=>t.path===n.payload),e.activeTab=n.payload},closeAllTabs(e){e.tabs=[],e.activeTab=""},closeRightTabs(e,n){e.tabs.splice(n.payload+1),e.activeTab=e.tabs[n.payload].path},closeLeftTabs(e,n){e.tabs.splice(0,n.payload)},closeSavedTabs(e){e.tabs=e.tabs.filter(({flags:{touched:t}})=>t);const n=e.tabs.reduce((t,a)=>(a==null?void 0:a.weight)>((t==null?void 0:t.weight)||0)?a:t,null);e.activeTab=(n==null?void 0:n.path)||""},confirmTab(e,n){const t=e.tabs.find(({path:a})=>a===n.payload);t&&(t.flags.confirmed||ao.caseReducers.setTabFlags(e,{type:n.type,payload:{path:n.payload,flags:{confirmed:!0}}}))},selectTab(e,n){const t=e.tabs.find(({path:s})=>s===n.payload);if(!t||e.activeTab===n.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=n.payload},openTabUnselected(e,n){const t=n.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,n){const t=[E.FileFolderType.DEBUGGER],{isNew:a,...s}=n.payload;let i=s,c=e.tabs.find(({path:l})=>i.path===l);if((t.includes(i.type)||c!=null&&c.flags.confirmed)&&(i={...i,flags:{...i.flags,confirmed:!0}}),!c){const l=e.tabs.findIndex(({flags:{confirmed:d}})=>d===!1);l!==-1&&!t.includes(i.type)&&!a?e.activeTab===e.tabs[l].path?(e.tabs[l]=i,c=e.tabs[l]):(e.tabs.push(i),c=e.tabs[e.tabs.length-1],e.tabs.splice(l,1)):(e.tabs.push(i),c=e.tabs[e.tabs.length-1])}if(e.activeTab!==i.path){const l=e.tabs.reduce((d,p)=>(p==null?void 0:p.weight)>((d==null?void 0:d.weight)||0)?p:d,null);e.activeTab=i.path,c.weight=((l==null?void 0:l.weight)||0)+1}c.extra={...c.extra,...i.extra},c.flags={...c.flags||{},...i.flags||{}}},setContent(e,n){const{path:t,content:a,contentPath:s}=n.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(Ke.get(i.initialContent,s||"",i.initialContent)),p=JSON.stringify(Ke.get(a,s||"",a));c=d!==p,l=!l&&c?!0:l}return a&&typeof a=="object"&&(s?Ke.set(i.content,s,a):i.content=a),typeof a=="string"&&(i.content=a),{...i,flags:{...i.flags,touched:c,confirmed:l}}})},setTabFlags(e,n){const{path:t,flags:a}=n.payload;e.tabs=e.tabs.map(s=>s.path===t?{...s,flags:{...s.flags,...a}}:s)},setTabsFlags(e,n){const{tabs:t,flags:a}=n.payload;e.tabs=e.tabs.map(s=>t.includes(s.path)?{...s,flags:{...s.flags,...a}}:s)},setTabExtra(e,n){const{path:t,extra:a,flags:s}=n.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,n){const{path:t,styles:a=[]}=n.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,n){return e.tabs=e.tabs.map(t=>t.path===n.payload.path?n.payload:t),e}},extraReducers:e=>{e.addCase(lc,(n,t)=>{if(t.payload.settingsKey==="studio.enablePreview"&&t.payload.value===!1){const a=n.tabs.find(({flags:{confirmed:s}})=>s===!1);a&&ao.caseReducers.setTabFlags(n,{type:"",payload:{path:a.path,flags:{confirmed:!0}}})}}),e.addCase(ev.fulfilled,(n,t)=>{if(!t.payload)return;const{content:a,line:s,path:i}=t.payload,c=n.tabs.find(l=>l.path===i);if(c&&typeof c.content=="string"){const l=c.content.trim().split(`
|
|
128
128
|
`);l.splice(s,0,a),c.content=l.join(`
|
|
129
|
-
`)}}),e.addCase(la.pending,(n,t)=>{const{tab:a}=t.meta.arg;switch(a.type){case E.FileFolderType.CLASS:case E.FileFolderType.METHOD:E.lspSubject.next({action:E.LspActions.WILL_SAVE,payload:{filePath:a.path}});break}}),e.addCase(la.fulfilled,(n,t)=>{if(!t.payload)return;const a=n.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 E.FileFolderType.CLASS:case E.FileFolderType.METHOD:E.lspSubject.next({action:E.LspActions.DID_SAVE,payload:{filePath:a.path,content:a.content}});break}t.payload.errors.length>0&&E.toastSubject.next({kind:"error",message:t.payload.errors})}}),e.addCase(la.rejected,(n,t)=>{E.toastSubject.next({kind:"danger",message:"Cannot save file"})}),e.addCase(rv.fulfilled,(n,t)=>{const a=[...t.payload.files];n.tabs=n.tabs.map(s=>{if([E.FileFolderType.CLASS,E.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(gc.pending,(n,t)=>{n.tabs=n.tabs.map(a=>a.path===t.meta.arg.path?{...a,flags:{...a.flags,loading:!0}}:a)}),e.addCase(gc.fulfilled,(n,t)=>{const a=t.payload;if(a){const s=t.meta.arg;n.tabs=n.tabs.map(i=>{if(i.name===s.name&&i.type===s.type){const c=i.extra||{};return i.type===E.FileFolderType.METHOD?(c.attributes=E.parseAttributes(a.content),a.content=E.addAttributesToContent(a.content,{})):i.type===E.FileFolderType.SETTINGS&&(a.content={}),{...i,initialContent:a.content,content:a.content,date:a.date,flags:{confirmed:i.flags.confirmed},extra:c}}return i})}}),e.addCase(Kc.fulfilled,(n,t)=>{if(!t.payload)return;const{line:a,offset:s}=t.meta.arg,i=n.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,(n,t)=>{if(!t.payload)return;const{selection:a}=t.meta.arg,s=n.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(ca.fulfilled,(n,t)=>{t.payload.new!==t.payload.old&&(n.tabs=[...n.tabs].map(a=>a.path===t.payload.old.path?{...a,path:t.payload.new.path,name:t.payload.new.name}:a),n.activeTab===t.payload.old.path&&(n.activeTab=t.payload.new.path))}),e.addCase(hc.pending,(n,t)=>{const a=t.meta.arg,s=`${a.path}${a.ext?`.${a.ext}`:""}`;switch(a.ext){case"4dm":case"4qs":E.lspSubject.next({action:E.LspActions.WILL_DELETE,payload:{filePath:s}});break}}),e.addCase(hc.fulfilled,(n,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":E.lspSubject.next({action:E.LspActions.DID_DELETE,payload:{filePath:i}});break}if(n.tabs=n.tabs.filter(c=>c.path!==i),n.recent=n.recent.filter(({path:c})=>i!==c),n.tabs.length){n.activeTab=n.tabs[n.tabs.length-1].path;return}n.activeTab=""}),e.addCase(Xa.fulfilled,(n,t)=>{const{draggedNode:a,newLocation:s}=t.meta.arg;if(n.tabs.find(i=>i.path===`${a.path}${a.ext?`.${a.ext}`:""}`))return n.tabs=n.tabs.map(i=>i.path===`${a.path}${a.ext?`.${a.ext}`:""}`?{...i,path:`${s.path}/${a.name}.${a.ext}`}:i),n.recent=n.recent.map(i=>i.path===`${a.path}${a.ext?`.${a.ext}`:""}`?{...i,path:`${s.path}/${a.name}.${a.ext}`}:i),n.activeTab=`${s.path}/${a.name}.${a.ext}`,n}),e.addCase(As.fulfilled,(n,t)=>{const a=n.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,(n,t)=>{var i;if(!((i=t.payload)!=null&&i.path))return;const a=n.tabs.find(E.by("path",t.payload.path));if(!a)return;a.content=a.content+`
|
|
129
|
+
`)}}),e.addCase(la.pending,(n,t)=>{const{tab:a}=t.meta.arg;switch(a.type){case E.FileFolderType.CLASS:case E.FileFolderType.METHOD:E.lspSubject.next({action:E.LspActions.WILL_SAVE,payload:{filePath:a.path}});break}}),e.addCase(la.fulfilled,(n,t)=>{if(!t.payload)return;const a=n.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 E.FileFolderType.CLASS:case E.FileFolderType.METHOD:E.lspSubject.next({action:E.LspActions.DID_SAVE,payload:{filePath:a.path,content:a.content}});break}t.payload.errors.length>0&&E.toastSubject.next({kind:"error",message:t.payload.errors})}}),e.addCase(la.rejected,(n,t)=>{E.toastSubject.next({kind:"danger",message:"Cannot save file"})}),e.addCase(rv.fulfilled,(n,t)=>{const a=[...t.payload.files];n.tabs=n.tabs.map(s=>{if([E.FileFolderType.CLASS,E.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(gc.pending,(n,t)=>{n.tabs=n.tabs.map(a=>a.path===t.meta.arg.path?{...a,flags:{...a.flags,loading:!0}}:a)}),e.addCase(gc.fulfilled,(n,t)=>{const a=t.payload;if(a){const s=t.meta.arg;n.tabs=n.tabs.map(i=>{if(i.name===s.name&&i.type===s.type){const c=i.extra||{};return i.type===E.FileFolderType.METHOD?(c.attributes=E.parseAttributes(a.content),a.content=E.addAttributesToContent(a.content,{})):i.type===E.FileFolderType.SETTINGS&&(a.content={}),{...i,initialContent:a.content,content:a.content,date:a.date,flags:{enabled:i.flags.enabled,confirmed:i.flags.confirmed},extra:c}}return i})}}),e.addCase(Kc.fulfilled,(n,t)=>{if(!t.payload)return;const{line:a,offset:s}=t.meta.arg,i=n.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,(n,t)=>{if(!t.payload)return;const{selection:a}=t.meta.arg,s=n.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(ca.fulfilled,(n,t)=>{t.payload.new!==t.payload.old&&(n.tabs=[...n.tabs].map(a=>a.path===t.payload.old.path?{...a,path:t.payload.new.path,name:t.payload.new.name}:a),n.activeTab===t.payload.old.path&&(n.activeTab=t.payload.new.path))}),e.addCase(hc.pending,(n,t)=>{const a=t.meta.arg,s=`${a.path}${a.ext?`.${a.ext}`:""}`;switch(a.ext){case"4dm":case"4qs":E.lspSubject.next({action:E.LspActions.WILL_DELETE,payload:{filePath:s}});break}}),e.addCase(hc.fulfilled,(n,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":E.lspSubject.next({action:E.LspActions.DID_DELETE,payload:{filePath:i}});break}if(n.tabs=n.tabs.filter(c=>c.path!==i),n.recent=n.recent.filter(({path:c})=>i!==c),n.tabs.length){n.activeTab=n.tabs[n.tabs.length-1].path;return}n.activeTab=""}),e.addCase(Xa.fulfilled,(n,t)=>{const{draggedNode:a,newLocation:s}=t.meta.arg;if(n.tabs.find(i=>i.path===`${a.path}${a.ext?`.${a.ext}`:""}`))return n.tabs=n.tabs.map(i=>i.path===`${a.path}${a.ext?`.${a.ext}`:""}`?{...i,path:`${s.path}/${a.name}.${a.ext}`}:i),n.recent=n.recent.map(i=>i.path===`${a.path}${a.ext?`.${a.ext}`:""}`?{...i,path:`${s.path}/${a.name}.${a.ext}`}:i),n.activeTab=`${s.path}/${a.name}.${a.ext}`,n}),e.addCase(As.fulfilled,(n,t)=>{const a=n.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,(n,t)=>{var i;if(!((i=t.payload)!=null&&i.path))return;const a=n.tabs.find(E.by("path",t.payload.path));if(!a)return;a.content=a.content+`
|
|
130
130
|
exposed Function ${t.meta.arg.name}()
|
|
131
131
|
`,a.flags={...a.flags,touched:!0,confirmed:!0};const s=a.content.split(`
|
|
132
132
|
`);a.extra={...a.extra,editor:E.EDITOR.Code,initialLineInfo:{line:s.length-1,lastModification:Date.now()}}}),e.addCase(Jc.fulfilled,(n,t)=>{var i,c;if(!((i=t.payload)!=null&&i.path)||(c=t.payload)!=null&&c.namespace)return;const a=t.payload.path,s=n.tabs.find(E.by("path",a));!s||!s.content||!s.content.metadata||(Object.assign(s.content.metadata,{datasources:t.payload.datasources}),s.flags.touched=!0,s.flags.confirmed=!0)}),e.addCase(Xc.fulfilled,(n,t)=>{const{payload:a,meta:{arg:s}}=t;s.namespace||n.tabs.forEach(i=>{i.path===s.path&&Object.assign(i.content,{metadata:{...i.content.metadata,datasources:a}})})}),e.addCase(iv.fulfilled,(n,t)=>{const{staleThreadIds:a}=t.payload;if(a.length===0)return;const s=a.map(i=>`Debugger/${i}`);if(n.tabs=n.tabs.filter(i=>!s.includes(i.path)),n.recent=n.recent.filter(({path:i})=>!s.includes(i)),n.tabs.length){n.activeTab=n.tabs[n.tabs.length-1].path;return}n.activeTab=""}),e.addCase(Vc.pending,n=>Bu(n,!1)),e.addMatcher(_r(lc),(n,t)=>{["project"].includes(t.payload.path)&&Bu(n,!0)}),e.addMatcher(_r(Js),(n,t)=>{Bu(n,!1)}),e.addMatcher(_r(Rv,Lt),(n,t)=>{const{payload:a}=t;let s;typeof a=="string"?s=n.tabs.find(({path:i})=>a===i):s=a,s&&(n.recent=[s,...n.recent.filter(({path:i})=>![s.path,"settings"].includes(i))])}),e.addMatcher(_r(qg,Gg),(n,t)=>{n.tabs=n.tabs.map(a=>a.path===E.ROLES_TAB_PATH?{...a,flags:{...a.flags,confirmed:!0,touched:!0}}:a)}),e.addMatcher(_r(zc),(n,t)=>{n.tabs=n.tabs.map(a=>a.path===E.ROLES_TAB_PATH?{...a,flags:{...a.flags,touched:!1}}:a)}),e.addMatcher(_r(tl.fulfilled,rl.fulfilled,Za.fulfilled,fa.fulfilled),(n,t)=>{var s,i,c;const a=n.tabs.find(E.by("path",((s=t.payload)==null?void 0:s.path)||t.meta.arg.path));!a||(i=t.payload)!=null&&i.namespace||(a.flags.touched=!0,a.flags.confirmed=!0,Object.assign(a.content,{metadata:{...a.content.metadata,datasources:(c=t.payload)==null?void 0:c.list}}))}),e.addMatcher(_r(Za.fulfilled,fa.fulfilled),(n,t)=>{var l;const a=n.tabs.find(E.by("path",((l=t.payload)==null?void 0:l.path)||t.meta.arg.path));if(!a)return;const{panel:s}=a.view,i=E.getDatasourceId({id:t.meta.arg.id,namespace:t.meta.arg.namespace});if(s.type==="datasource"&&s.current===i)switch(t.type){case Za.fulfilled.type:Object.assign(a.view.panel,{type:"component",current:yR});break;case fa.fulfilled.type:const d=E.getDatasourceId({id:t.meta.arg.new_name,namespace:t.meta.arg.namespace});Object.assign(a.view.panel,{type:"datasource",current:d});break}})}}),{setTabs:vI,closeTab:nl,setContent:Ev,setTabFlags:Sv,setTabsFlags:yI,setTabExtra:mI,closeAllTabs:wv,addDataSource:bI,closeRightTabs:Tv,closeOthers:Cv,closeLeftTabs:xv,closeSavedTabs:_I,setDataSources:EI,removeDataSource:SI,confirmTab:wI,selectTab:Rv,selectTabByReference:Lt,openTabUnselected:Ov,addWebFormStyles:TI,changeTabEditor:CI,openSettingsTab:xI,setPanelState:RI}=ao.actions,Av=ao.reducer,OI=av.reducer,kn=re("catalog/fetchCatalog",async(e,{rejectWithValue:n})=>{var t;try{const a=await E.getCatalog(),s=new Map,i=new Map;return(t=a==null?void 0:a.dataClasses)==null||t.forEach(({methods:c=[],...l})=>{if(l.uuid||Object.assign(l,{uuid:E.generateUUID()}),l.attributes){const p=["storage","relatedEntity"];l.attributes=l.attributes.map(h=>(p.includes(h.kind)&&!h.uuid&&Object.assign(h,{uuid:E.generateUUID()}),h))}const d={...l,methods:c};i.set(l.className,d),s.set(l.collectionName,d)}),{__BASEID:a.__BASEID,__UNIQID:a.__UNIQID,dataClassByCollectionName:Object.fromEntries(s.entries()),methods:a.methods||[],dataClasses:Object.fromEntries(i.entries())}}catch{return n("Error while loading the catalog")}}),AI=lr({name:"catalog",initialState:{state:"loading"},reducers:{},extraReducers(e){e.addCase(kn.pending,()=>({state:"loading"})).addCase(kn.fulfilled,(n,{payload:t})=>({state:"loaded",model:t})).addCase(kn.rejected,(n,t)=>({state:"error",error:t.payload||"Error while loading the catalog"}))}}),PI=AI.reducer,DI=Ng.reducer,ls=re("shared_datasources/fetchSharedSources",async(e,{rejectWithValue:n})=>{try{return await E.getSharedDatasources()}catch{return n("Error while loading the shared datasources")}}),Pv=re("shared_datasources/addSharedSource",async(e,{rejectWithValue:n,getState:t})=>{try{const a=JSON.parse(JSON.stringify(t().sharedDatasources));if(e.namespace)a.sources[e.namespace]?a.sources[e.namespace].push(e):a.sources[e.namespace]=[e];else return n("Namespace is required");return await E.setSharedSources(a.sources),a.sources}catch{return n("Error while saving the shared datasources")}}),Dv=re("shared_datasources/editSharedSource",async(e,{rejectWithValue:n,getState:t})=>{try{const a=t().sharedDatasources;if(!e.namespace)return n("Namespace is required");if(a.sources[e.namespace])a.sources[e.namespace]=a.sources[e.namespace].map(s=>s.id===e.id?{...e,id:s.id}:s);else return n("Namespace not found");return await E.setSharedSources(a.sources),a.sources}catch{return n("Error while saving the shared datasources")}}),Iv=re("shared_datasources/deleteSharedSource",async(e,{rejectWithValue:n,getState:t})=>{try{const a={...t().sharedDatasources};if(a.sources[e.namespace]){const s=a.sources[e.namespace].filter(i=>i.id!==e.id);if(s.length===0){const{[e.namespace]:i,...c}=a.sources;a.sources=c}else a.sources={...a.sources,[e.namespace]:s}}return await E.setSharedSources(a.sources),a.sources}catch{return n("Error while saving the shared datasources")}}),al=re("shared_datasources/updateSharedDatasources",async(e,{rejectWithValue:n,getState:t})=>{try{const a={...t().sharedDatasources};for(const s of e){if(!s.namespace)return n("Namespace is required");if(a.sources[s.namespace])a.sources[s.namespace]=a.sources[s.namespace].map(i=>i.id===s.id?s:i);else return n("Namespace not found")}return await E.setSharedSources(a.sources),a.sources}catch{return n("Error while saving the shared datasources")}}),II=re("shared_datasources/setDatasourceEvents",async({tabPath:e,name:n,namespace:t,events:a},{getState:s,dispatch:i})=>{var S,T,x;const{root:{tabs:c},sharedDatasources:l}=s(),d=((x=(T=(S=c.find(({path:F})=>F===e))==null?void 0:S.content)==null?void 0:T.metadata)==null?void 0:x.datasources)||[],p={local:!1,shared:!1},h=(F,D)=>F.id===n&&(!t&&!F.namespace||F.namespace===t)?(D==null||D(),{...F,events:a}):F,b=d.map(F=>h(F,()=>{p.local=!0})),_=Ke.flatten(Ke.values(l.sources)).map(F=>h(F,()=>{p.shared=!0}));p.local&&i(Ev({path:e,content:b,contentPath:"metadata.datasources"})),p.shared&&i(al(_))}),Fv=lr({name:"shared-datasources",initialState:{},reducers:{addEmptyNamespace(e,n){e.sources[n.payload.name]=[]}},extraReducers(e){e.addCase(ls.pending,n=>({state:"loading",sources:{}})).addCase(ls.fulfilled,(n,t)=>({state:"loaded",sources:t.payload})).addCase(ls.rejected,(n,t)=>({state:"error",sources:{},error:t.payload||"Error while loading the shared datasources"})).addCase(al.fulfilled,(n,t)=>({state:"loaded",sources:t.payload})).addCase(Xc.fulfilled,(n,t)=>{const{payload:a,meta:{arg:s}}=t;s.namespace&&Object.assign(n.sources,{[s.namespace]:a})}).addCase(Pv.fulfilled,(n,t)=>({...n,sources:t.payload})).addCase(Iv.fulfilled,(n,t)=>({...n,sources:t.payload})).addCase(Dv.fulfilled,(n,t)=>({...n,sources:t.payload})).addCase(Jc.fulfilled,(n,t)=>{if(!t.payload)return n;const{datasources:a,namespace:s}=t.payload;s&&n.sources[s]&&Object.assign(n.sources[s],{[s]:a})}).addMatcher(_r(tl.fulfilled,Za.fulfilled,rl.fulfilled,fa.fulfilled),(n,t)=>{if(!t.payload)return;const{namespace:a,list:s}=t.payload;a&&Object.assign(n.sources,{[a]:s})})}}),{addEmptyNamespace:FI}=Fv.actions,$I=Fv.reducer,MI=Vg.reducer,fs=re("shared_css/fetchSharedCSS",async(e,{rejectWithValue:n})=>{try{const{classes:t}=await E.getSharedCSS();return t}catch{return n("Error while loading the shared CSS")}}),NI=E.queue();async function LI(e){const n={verb:E.DesignerRequestVerb.SET_FILE_CONTENT,asText:!1,name:"shared_css.json",path:"",root:"shared",content:{classes:e.map(({scope:t,...a})=>({...a}))}};await NI(()=>E.http(E.API_PREFIX,{method:"POST",body:JSON.stringify(n),headers:new Headers({"Content-Type":"application/json"})}))}const $v=lr({name:"shared-css",initialState:()=>{const{sharedCSS:e}=pa();return e||{state:"loading",styles:[]}},reducers:{updateSharedCss:(e,n)=>(e.styles=n.payload.classes,LI(n.payload.classes),e),initSharedCss:(e,n)=>(e.styles=n.payload.classes,e)},extraReducers(e){e.addCase(fs.pending,n=>({...n,state:"loading"})).addCase(fs.fulfilled,(n,{payload:t})=>({state:"loaded",styles:t})).addCase(fs.rejected,(n,t)=>({...n,state:"error",error:t.payload||"Error while loading the shared css"}))}}),{updateSharedCss:jI,initSharedCss:kI}=$v.actions,BI=$v.reducer,WI={},UI=lr({name:"tabs",initialState:WI,reducers:{}}),HI=e=>z(ba,n=>{var t,a;return(a=(t=n.find(s=>s.path===e))==null?void 0:t.view)==null?void 0:a.panel});UI.reducer;const Mv=rh({root:Av,explorer:MI,debugger:OI,settings:zP,catalog:PI,roles:HP,sharedDatasources:$I,webforms:cI,modals:DI,sharedCSS:BI,model:nI});let Ga;const Nv=()=>(Ga||(Ga=US({reducer:Mv}),Ga.subscribe(tT(()=>{const{root:{activeTab:e,tabs:n,recent:t},roles:a,debugger:s,webforms:i,sharedCSS:c,settings:{session:l}}=Ga.getState();Sh({...l}),Eh({tabs:n,activeTab:e,recent:t,roles:a,debugger:s,webforms:i,sharedCSS:c})},1e3))),Ga);var vc={exports:{}},sa={};/** @license React v17.0.2
|