import{t as h,c as r}from"./NcLoadingIcon-DmVcM0-B.chunk.mjs";import{u as s,s as o}from"./index-6AQ8QgJK.chunk.mjs";import{l as n}from"./index-Dl858C8_.chunk.mjs";import{v as l}from"./index-CCUE3e_p.chunk.mjs";import{g as c,i as u}from"./NcNoteCard-ChweF_5Q-5iiVgoP-.chunk.mjs";import{g as p}from"./Editor.singleton-BsNBhsn_.chunk.mjs";import{R as f}from"./RichTextReader-C_O2mTsO.chunk.mjs";import{n as m}from"./_plugin-vue2_normalizer-wd1ZAbRr.chunk.mjs";import"./emoji-picker-DwlFXcXb.chunk.mjs";import"./vue.runtime.esm-C9BcAUzb.chunk.mjs";import"./EditorOutline-DL171nAA.chunk.mjs";import"./logger-DVPLBGl3.chunk.mjs";import"./NcCheckboxRadioSwitch-ip_mRd2T-Df5K32Av.chunk.mjs";import"./MediaHandler.provider-HrSuJegm.chunk.mjs";import"./BaseReader-DGFMG8ex.chunk.mjs";const d=u(),k=l("apps/text"+(d?"/public":"")+"/workspace",2),R=h("text","Readme")+"."+n("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 .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 d&&(e.shareToken=this.shareToken),r.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:h}};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,"ddfd769f");const q=v.exports;export{q as default};
//# sourceMappingURL=RichWorkspace-BWnVIhxB.chunk.mjs.map
