import{a as d,V as l}from"./vue.runtime.esm-BeQ812EV.chunk.mjs";import{t as m,c}from"./NcLoadingIcon-cTopO8-o.chunk.mjs";import{g as u,c as p}from"./index-C_I6Z7S3.chunk.mjs";import{b as h,g as f}from"./NcNoteCard-CwNXZ4vV-D7CiCihS.chunk.mjs";import{l as w}from"./Wrapper-CGFHLFhQ.chunk.mjs";import{E as y}from"./Editor-McA25aml.chunk.mjs";import n from"./MarkdownContentEditor-DB0OCwOt.chunk.mjs";import{P as r}from"./PlainTextReader-CfVk8R3I.chunk.mjs";import{n as g}from"./_plugin-vue2_normalizer-wd1ZAbRr.chunk.mjs";import"./emoji-picker-B23JpFV7.chunk.mjs";import"./index-D3QPwoaU.chunk.mjs";import"./index-DxwFe63_.chunk.mjs";import"./index-D3wiQe9-.chunk.mjs";import"./logger-DztlavSi.chunk.mjs";import"./NcCheckboxRadioSwitch-D4IV4zWy-Cnxtub33.chunk.mjs";import"./MediaHandler.provider-DxrIedPV.chunk.mjs";import"./MenuBar-gNw66kVv.chunk.mjs";import"./index-BuYpjlUg.chunk.mjs";import"./BaseReader-DBZFqOaU.chunk.mjs";const E=d({name:"ViewerComponent",components:{NcButton:h,PencilOutlineIcon:w,PlainTextReader:r,MarkdownContentEditor:n,Editor:y},provide(){return{isEmbedded:this.isEmbedded}},inheritAttrs:!1,props:{filename:{type:String,default:null},fileid:{type:Number,default:null},active:{type:Boolean,default:!1},autofocus:{type:Boolean,default:!0},shareToken:{type:String,default:()=>f()},mime:{type:String,default:null},showOutlineOutside:{type:Boolean,default:!1},source:{type:String,default:void 0},isEmbedded:{type:Boolean,default:!1}},data(){return{content:"",hasToggledInteractiveEmbedding:!1}},computed:{useSourceView(){return this.source&&(this.fileVersion||!this.fileid||this.isEmbedded||this.isEncrypted)&&!this.hasToggledInteractiveEmbedding},isEncrypted(){return this.$attrs.e2EeIsEncrypted||!1},isMarkdown(){return this.mime==="text/markdown"||this.mime==="text/x-web-markdown"},readerComponent(){return this.isMarkdown?n:r}},watch:{source(){this.loadFileContent()}},mounted(){this.loadFileContent()},methods:{async loadFileContent(){if(this.useSourceView)if(this.isEncrypted)this.content=await this.fetchDecryptedContent(),this.contentLoaded=!0;else{const t=await c.get(this.source);this.content=t.data,this.contentLoaded=!0}this.$emit("update:loaded",!0)},toggleEdit(){this.hasToggledInteractiveEmbedding=!0},async fetchDecryptedContent(){const t=await u().getFileContents(`${p()}${this.filename}`,{details:!0}),e=new Blob([t.data],{type:t.headers["content-type"]}),i=new FileReader;return i.readAsText(e),new Promise(a=>{i.onload=()=>{a(i.result)}})},t:m}});var b=function(){var t=this,e=t._self._c;return t._self._setupProxy,t.useSourceView?e("div",{staticClass:"text-editor source-viewer",attrs:{id:"editor-container","data-text-el":"editor-container"}},[e(t.readerComponent,{tag:"Component",attrs:{content:t.content,"file-id":t.fileid,"read-only":!0,"show-menu-bar":!1}}),t.isEmbedded?e("NcButton",{staticClass:"toggle-interactive",on:{click:t.toggleEdit},scopedSlots:t._u([{key:"icon",fn:function(){return[e("PencilOutlineIcon")]},proxy:!0}],null,!1,139796693)},[t._v(" "+t._s(t.t("text","Edit"))+" ")]):t._e()],1):e("Editor",{class:{"text-editor--embedding":t.isEmbedded},attrs:{"file-id":t.fileid,"relative-path":t.filename,active:t.active||t.isEmbedded,autofocus:t.autofocus,"share-token":t.shareToken,mime:t.mime,"show-outline-outside":t.showOutlineOutside}})},v=[],x=g(E,b,v,!1,null,"fb013b56");const s=x.exports;let o;const q=d({name:"ViewerView",render:t=>t("div"),props:s.props,mounted(){o=new l({render:t=>t(s,{attrs:this.$attrs,props:this.$props,on:this.$listeners})}),o.$mount(this.$el)},beforeDestroy(){o.$destroy()}});export{q as default};
//# sourceMappingURL=ViewerView-CdEeOiL5.chunk.mjs.map
