import{v as c,c as l}from"./index-BGFdrNqh.chunk.mjs";import{s as o,u as a}from"./modulepreload-polyfill-DE-oIJqv.chunk.mjs";import{g as d}from"./Editor.singleton-C6k3N5XS.chunk.mjs";import{R as p}from"./RichTextReader-CUvRmd77.chunk.mjs";import{l as f}from"./index-DfiDB3im.chunk.mjs";import{n as u}from"./_plugin-vue2_normalizer-Ek9LosZJ.chunk.mjs";import"./vue.runtime.esm-DO2cz8pp.chunk.mjs";import"./emoji-picker-KVqjnXYv.chunk.mjs";import"./BaseReader-B04z_9lh.chunk.mjs";import"./RichText-Bl8j_FW5.chunk.mjs";import"./public-BYOpgJit.chunk.mjs";import"./index-Ct2iTpP3.chunk.mjs";import"./MediaHandler.provider-DkklcpwC.chunk.mjs";import"./logger-BOSm1sVH.chunk.mjs";import"./index-Bc2S5k6V.chunk.mjs";import"./_plugin-vue2_normalizer-CQ6iBklL-hCHD4uyV.chunk.mjs";const h=!!document.getElementById("isPublic"),m=c("apps/text"+(h?"/public":"")+"/workspace",2),k=t("text","Readme")+"."+f("text","default_file_extension"),n=[k,"Readme.md","README.md","readme.md"],R={name:"RichWorkspace",components:{RichTextReader:p,Editor:d},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,hideMenu:!0,darkTheme:OCA.Accessibility&&OCA.Accessibility.theme==="dark",enabled:OCA.Text.RichWorkspaceEnabled}},computed:{shareToken(){return document.getElementById("sharingToken")?.value}},watch:{path(){this.getFileInfo()},focus(e){e||document.querySelector("#rich-workspace .text-editor__main").scrollTo(0,0)},hasRichWorkspace(e){this.localHasRichWorkspace=e}},mounted(){this.localHasRichWorkspace=this.hasRichWorkspace,this.enabled&&this.hasRichWorkspace&&this.getFileInfo(),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(){a("Text::showRichWorkspace",this.showRichWorkspace),a("Text::hideRichWorkspace",this.hideRichWorkspace),a("files:node:created",this.onFileCreated),a("files:node:deleted",this.onFileDeleted),a("files:node:renamed",this.onFileRenamed),this.unlistenKeydownEvents()},methods:{onFocus(){this.focus=!0,this.hideMenu=!1,this.unlistenKeydownEvents()},reset(){this.localHasRichWorkspace=!1,this.file=null,this.focus=!1,this.$nextTick(()=>{this.creating=!1,this.getFileInfo()})},getFileInfo(e){if(!this.enabled)return;this.file=null,this.ready=!1,this.loaded=!0,this.autofocus=!1;const i={path:this.path};return h&&(i.shareToken=this.shareToken),l.get(m,{params:i}).then(s=>{const r=s.data.ocs.data;return this.folder=r.folder||null,this.file=r.file,this.editing=!0,this.loaded=!0,this.autofocus=e||!1,this.localHasRichWorkspace=!0,!0}).catch(s=>(s.response.data.ocs&&s.response.data.ocs.data.folder?this.folder=s.response.data.ocs.data.folder:this.folder=null,this.file=null,this.loaded=!0,this.ready=!0,this.creating=!1,!1))},showRichWorkspace(e){this.enabled=!0,this.getFileInfo(e?.autofocus||!1)},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){n.includes(e.basename)&&(this.localHasRichWorkspace=!0,this.getFileInfo(!0))},onFileDeleted(e){e.path===this.file?.path&&(this.localHasRichWorkspace=!1)},onFileRenamed(e){n.includes(e.basename)?this.localHasRichWorkspace=!0:e.fileid===this.file?.id&&e.path!==this.file?.path&&(this.localHasRichWorkspace=!1)}}};var y=function(){var e=this,i=e._self._c;return e.enabled&&e.localHasRichWorkspace?i("div",{class:{focus:e.focus,dark:e.darkTheme},attrs:{id:"rich-workspace"}},[!e.loaded||!e.ready?i("RichTextReader",{staticClass:"rich-workspace--preview",attrs:{content:e.content}}):e._e(),e.file?i("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(s){e.ready=!0},focus:e.onFocus,error:e.reset}}):e._e()],1):e._e()},w=[],W=u(R,y,w,!1,null,"22e74aad");const O=W.exports;export{O as default};
//# sourceMappingURL=RichWorkspace-BxU39S7r.chunk.mjs.map
