import{V as o,a as l}from"./vue.runtime.esm-BF-IvmLA.chunk.mjs";import{k as u,i as p}from"./Wrapper-C2o3LOYL.chunk.mjs";import{E as f}from"./Editor-BtuNWoZQ.chunk.mjs";import{t as h,c as y}from"./NcLoadingIcon-CVPmhDs9.chunk.mjs";import{g,c as w,N as E}from"./NcNoteCard-CwNXZ4vV-CGCPj_4W.chunk.mjs";import d from"./MarkdownContentEditor-76NLDNGz.chunk.mjs";import{P as s}from"./PlainTextReader-DJxsOGgX.chunk.mjs";import{n as c}from"./NcCheckboxRadioSwitch-D4IV4zWy-C7R54kfi.chunk.mjs";import"./index-BBRfwPzy.chunk.mjs";import"./emoji-picker-C0wQOMkK.chunk.mjs";import"./logger-Cig2S1Ru.chunk.mjs";import"./index-zDAq7SQt.chunk.mjs";import"./index-Dl858C8_.chunk.mjs";import"./preload-helper-BorfeO-5.chunk.mjs";import"./MediaHandler.provider-JHoeYdEY.chunk.mjs";import"./MenuBar-C0eCsSWq.chunk.mjs";import"./BaseReader-Bk1PPXAR.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(m=>{n.onload=()=>{m(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=c(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=[],_=c($,V,k,!1,null,"05c92cba");const a=_.exports;let r;const J=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{J as default};
//# sourceMappingURL=ViewerView-D28Ah4x2.chunk.mjs.map
