import{V as o,a as l}from"./vue.runtime.esm-CbNPNm8f.chunk.mjs";import{k as u,i as p}from"./Wrapper-obocs1sV.chunk.mjs";import{E as f}from"./Editor-Cr_YdjKk.chunk.mjs";import{t as h,c as y}from"./NcLoadingIcon-Bdu4Z_fo.chunk.mjs";import{g,a as w}from"./dav-BTwUt5Rb.chunk.mjs";import{N as E}from"./NcNoteCard-CwNXZ4vV-CPnkYq5v.chunk.mjs";import d from"./MarkdownContentEditor-BwTzyQSN.chunk.mjs";import{P as s}from"./PlainTextReader-DQ-K7AxY.chunk.mjs";import{n as m}from"./NcCheckboxRadioSwitch-D4IV4zWy-Bb19W4wJ.chunk.mjs";import"./index-DxwFe63_.chunk.mjs";import"./logger-DrmDPXkr.chunk.mjs";import"./index-DtbbSwig.chunk.mjs";import"./index-xQwnxqUU.chunk.mjs";import"./emoji-picker-hi3Hwbeu.chunk.mjs";import"./index-D3wiQe9-.chunk.mjs";import"./preload-helper-BorfeO-5.chunk.mjs";import"./MediaHandler.provider-BUbYNN83.chunk.mjs";import"./MenuBar-BBhgnV0-.chunk.mjs";import"./BaseReader-DF7IocT4.chunk.mjs";const b={name:"SourceView",components:{NcButton:o.extend(E),PencilOutlineIcon:o.extend(u),PlainTextReader:o.extend(s),MarkdownContentEditor:o.extend(d)},inject:["isEmbedded"],props:{filename:{type:String,default:null},fileid:{type:Number,default:null},mime:{type:String,default:null},source:{type:String,default:void 0},isEncrypted:{type:Boolean,default:!1}},data(){return{content:""}},computed:{isMarkdown(){return this.mime==="text/markdown"||this.mime==="text/x-web-markdown"},readerComponent(){return this.isMarkdown?d:s}},watch:{source(){this.loadFileContent()}},mounted(){this.loadFileContent()},methods:{async loadFileContent(){if(this.isEncrypted)this.content=await this.fetchDecryptedContent(),this.contentLoaded=!0;else{const e=await y.get(this.source);this.content=e.data,this.contentLoaded=!0}this.$emit("loaded",!0)},async fetchDecryptedContent(){const e=await g().getFileContents(`${w()}${this.filename}`,{details:!0}),i=new Blob([e.data],{type:e.headers["content-type"]}),n=new FileReader;return n.readAsText(i),new Promise(c=>{n.onload=()=>{c(n.result)}})},t:h}};var v=function(){var e=this,i=e._self._c;return i("div",{staticClass:"text-editor source-viewer",attrs:{id:"editor-container","data-text-el":"editor-container"}},[i(e.readerComponent,{tag:"Component",attrs:{content:e.content,"file-id":e.fileid,"read-only":!0,"show-menu-bar":!1}}),e.isEmbedded?i("NcButton",{staticClass:"toggle-interactive",on:{click:function(n){return e.$emit("edit")}},scopedSlots:e._u([{key:"icon",fn:function(){return[i("PencilOutlineIcon")]},proxy:!0}],null,!1,139796693)},[e._v(" "+e._s(e.t("text","Edit"))+" ")]):e._e()],1)},x=[],S=m(b,v,x,!1,null,"d74488fe");const C=S.exports,$=l({name:"ViewerComponent",components:{SourceView:C,Editor:f},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:()=>p()},mime:{type:String,default:null},source:{type:String,default:void 0},isEmbedded:{type:Boolean,default:!1}},data(){return{hasToggledInteractiveEmbedding:!1}},computed:{useSourceView(){return this.source&&(this.fileVersion||!this.fileid||this.isEmbedded||this.isEncrypted)&&!this.hasToggledInteractiveEmbedding},isEncrypted(){return this.$attrs.e2EeIsEncrypted||!1}},mounted(){this.useSourceView||this.onLoaded()},methods:{async onLoaded(){this.$emit("update:loaded",!0)},toggleEdit(){this.hasToggledInteractiveEmbedding=!0},t}});var V=function(){var e=this,i=e._self._c;return e._self._setupProxy,e.useSourceView?i("SourceView",e._b({attrs:{fileid:e.fileid,filename:e.filename,"is-encrypted":e.isEncrypted,mime:e.mime,source:e.source},on:{loaded:e.onLoaded,edit:e.toggleEdit}},"SourceView",e.$attrs,!1)):i("Editor",{class:{"text-editor--embedding":e.isEmbedded},attrs:{"file-id":e.fileid,"relative-path":e.filename,active:e.active||e.isEmbedded,autofocus:e.autofocus,"share-token":e.shareToken,mime:e.mime}})},k=[],_=m($,V,k,!1,null,"9bf8fd76");const a=_.exports;let r;const Q=l({name:"ViewerView",render:e=>e("div"),props:a.props,mounted(){r=new o({render:e=>e(a,{attrs:this.$attrs,props:this.$props,on:this.$listeners})}),r.$mount(this.$el)},beforeDestroy(){r.$destroy()}});export{Q as default};
//# sourceMappingURL=ViewerView-f3iChIxa.chunk.mjs.map
