import{v as c,c as l}from"./index-jVSJWteM.chunk.mjs";import{s as o,u as a}from"./modulepreload-polyfill-DCUwxYMh.chunk.mjs";import{g as d}from"./Editor.singleton-C1BgIBlo.chunk.mjs";import{R as p}from"./RichTextReader-CRBWPIiS.chunk.mjs";import{l as f}from"./index-CJ7wDv5l.chunk.mjs";import{n as u}from"./_plugin-vue2_normalizer-Dv5JCS6y.chunk.mjs";import"./vue.runtime.esm-BrouV0Mr.chunk.mjs";import"./emoji-picker-Coav-X6q.chunk.mjs";import"./BaseReader-udqi3-fi.chunk.mjs";import"./RichText-ChzG3aAL.chunk.mjs";import"./public-C42pM6E9.chunk.mjs";import"./index-BlLlZtv2.chunk.mjs";import"./MediaHandler.provider-i78Kd03y.chunk.mjs";import"./logger-YW53u4Eu.chunk.mjs";import"./index-DtTpkYe5.chunk.mjs";import"./_plugin-vue2_normalizer-CQ6iBklL-CXuhKXxu.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(){var e;return(e=document.getElementById("sharingToken"))==null?void 0:e.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==null?void 0: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){var i;e.path===((i=this.file)==null?void 0:i.path)&&(this.localHasRichWorkspace=!1)},onFileRenamed(e){var i,s;n.includes(e.basename)?this.localHasRichWorkspace=!0:e.fileid===((i=this.file)==null?void 0:i.id)&&e.path!==((s=this.file)==null?void 0:s.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};
