import{t as r,c as n}from"./NcLoadingIcon-Bdu4Z_fo.chunk.mjs";import{u as s,s as o}from"./index-xQwnxqUU.chunk.mjs";import{l as d}from"./index-D3wiQe9-.chunk.mjs";import{a as l}from"./index-DxwFe63_.chunk.mjs";import{i as c,j as u}from"./Wrapper-obocs1sV.chunk.mjs";import{E as p}from"./Editor-Cr_YdjKk.chunk.mjs";import{R as f}from"./RichTextReader-BxcwtBrb.chunk.mjs";import{n as m}from"./NcCheckboxRadioSwitch-D4IV4zWy-Bb19W4wJ.chunk.mjs";import"./vue.runtime.esm-CbNPNm8f.chunk.mjs";import"./emoji-picker-hi3Hwbeu.chunk.mjs";import"./logger-DrmDPXkr.chunk.mjs";import"./index-DtbbSwig.chunk.mjs";import"./preload-helper-BorfeO-5.chunk.mjs";import"./NcNoteCard-CwNXZ4vV-CPnkYq5v.chunk.mjs";import"./MediaHandler.provider-BUbYNN83.chunk.mjs";import"./dav-BTwUt5Rb.chunk.mjs";import"./MenuBar-BBhgnV0-.chunk.mjs";import"./BaseReader-DF7IocT4.chunk.mjs";const h=u(),k=l("apps/text"+(h?"/public":"")+"/workspace",2),R=r("text","Readme")+"."+d("text","default_file_extension"),a=[R,"Readme.md","README.md","readme.md"],w={name:"RichWorkspace",components:{RichTextReader:f,Editor:p},props:{content:{type:String,default:""},path:{type:String,required:!0},active:{type:Boolean,default:!0},hasRichWorkspace:{type:Boolean,default:!1}},data(){return{localHasRichWorkspace:!1,focus:!1,folder:null,file:null,loaded:!1,ready:!1,autofocus:!1,shouldAutofocus:!1,hideMenu:!0,darkTheme:window?.OCA?.Accessibility?.theme==="dark",enabled:window?.OCA?.Text?.RichWorkspaceEnabled}},computed:{shareToken(){return c()},shouldRender(){return this.enabled&&this.localHasRichWorkspace}},watch:{path(){this.reset()},ready(){this.shouldAutofocus=!1},focus(e){e||document.querySelector("#rich-workspace .editor__content-wrapper")?.scrollTo(0,0)},shouldRender(e){e&&this.getFileInfo()},hasRichWorkspace(e){this.localHasRichWorkspace=e}},mounted(){this.localHasRichWorkspace=this.hasRichWorkspace,o("Text::showRichWorkspace",this.showRichWorkspace),o("Text::hideRichWorkspace",this.hideRichWorkspace),o("files:node:created",this.onFileCreated),o("files:node:deleted",this.onFileDeleted),o("files:node:renamed",this.onFileRenamed),this.listenKeydownEvents()},beforeDestroy(){s("Text::showRichWorkspace",this.showRichWorkspace),s("Text::hideRichWorkspace",this.hideRichWorkspace),s("files:node:created",this.onFileCreated),s("files:node:deleted",this.onFileDeleted),s("files:node:renamed",this.onFileRenamed),this.unlistenKeydownEvents()},methods:{onFocus(){this.focus=!0,this.hideMenu=!1,this.unlistenKeydownEvents()},onBlur(e){this.$el.contains(e?.relatedTarget)||(this.focus=!1,this.hideMenu=!0)},reset(){this.file=null,this.focus=!1,this.shouldAutofocus=!1,this.$nextTick(()=>{this.shouldRender&&this.getFileInfo()})},getFileInfo(){this.file=null,this.ready=!1,this.loaded=!0;const e={path:this.path};return h&&(e.shareToken=this.shareToken),n.get(k,{params:e}).then(t=>{const i=t.data.ocs.data;return this.folder=i.folder||null,this.file=i.file,this.editing=!0,this.loaded=!0,this.autofocus=this.shouldAutofocus,!0}).catch(t=>(t.response.data.ocs&&t.response.data.ocs.data.folder?this.folder=t.response.data.ocs.data.folder:this.folder=null,this.file=null,this.loaded=!0,this.ready=!0,!1))},showRichWorkspace(e){this.enabled=!0},hideRichWorkspace(){this.enabled=!1},listenKeydownEvents(){window.addEventListener("keydown",this.onKeydown)},unlistenKeydownEvents(){window.removeEventListener("keydown",this.onKeydown)},onKeydown(e){e.key==="Tab"&&(this.hideMenu=!1)},onFileCreated(e){a.includes(e.basename)&&(this.shouldAutofocus=this.enabled,this.localHasRichWorkspace=!0)},onFileDeleted(e){e.path===this.file?.path&&(this.localHasRichWorkspace=!1)},onFileRenamed(e){a.includes(e.basename)?this.localHasRichWorkspace=!0:e.fileid===this.file?.id&&e.path!==this.file?.path&&(this.localHasRichWorkspace=!1)},t:r}};var y=function(){var e=this,t=e._self._c;return e.shouldRender?t("div",{class:{focus:e.focus,dark:e.darkTheme},attrs:{id:"rich-workspace"}},[!e.loaded||!e.ready?t("RichTextReader",{staticClass:"rich-workspace--preview",attrs:{content:e.content}}):e._e(),e.file?t("Editor",{directives:[{name:"show",rawName:"v-show",value:e.ready,expression:"ready"}],key:e.file.path,attrs:{"file-id":e.file.id,"relative-path":e.file.path,"share-token":e.shareToken,mime:e.file.mimetype,autofocus:e.autofocus,"hide-menu":e.hideMenu,active:"","rich-workspace":""},on:{ready:function(i){e.ready=!0},focus:e.onFocus,blur:e.onBlur}}):e._e()],1):e._e()},W=[],v=m(w,y,W,!1,null,"6c0a4412");const O=v.exports;export{O as default};
//# sourceMappingURL=RichWorkspace-Cl-fK0Y8.chunk.mjs.map
