import{t as r,c as d}from"./NcLoadingIcon-CBTC2zMe.chunk.mjs";import{u as s,s as o}from"./index-CdM8BgQf.chunk.mjs";import{l as n}from"./index-D3wiQe9-.chunk.mjs";import{a as l}from"./index-DCzdQJ7L.chunk.mjs";import{g as c,i as p}from"./NcNoteCard-CwNXZ4vV-Dyi378DT.chunk.mjs";import{E as u}from"./Editor-h9EWaODT.chunk.mjs";import{R as f}from"./RichTextReader-2fv-N0Lj.chunk.mjs";import{n as m}from"./NcCheckboxRadioSwitch-CgbTELjq-BFpDVXaF.chunk.mjs";import"./vue.runtime.esm-B7-PK3p1.chunk.mjs";import"./emoji-picker-hi3Hwbeu.chunk.mjs";import"./index-Bnw2WuIx.chunk.mjs";import"./preload-helper-BorfeO-5.chunk.mjs";import"./index-kwZOOyqh.chunk.mjs";import"./Wrapper-g9rQ14Xc.chunk.mjs";import"./logger-DS8A9d_w.chunk.mjs";import"./MediaHandler.provider-BoQN9QHH.chunk.mjs";import"./MenuBar-yxPsXXVM.chunk.mjs";import"./BaseReader-CX01F9DF.chunk.mjs";const h=p(),k=l("apps/text"+(h?"/public":"")+"/workspace",2),R=r("text","Readme")+"."+n("text","default_file_extension"),a=[R,"Readme.md","README.md","readme.md"],w={name:"RichWorkspace",components:{RichTextReader:f,Editor:u},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 .text-editor__main").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()},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),d.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}}):e._e()],1):e._e()},W=[],v=m(w,y,W,!1,null,"7770fa77");const O=v.exports;export{O as default}; //# sourceMappingURL=RichWorkspace-DxvaiVeF.chunk.mjs.map