UNPKG

jodit-pro

Version:

PRO Version of Jodit Editor

3 lines (2 loc) 1.7 kB
var m=Object.defineProperty;var p=(c,e)=>m(c,"name",{value:e,configurable:!0});import"./config.js";import{Dom as f}from"jodit/esm/core/dom/index.js";import{ConfigDeepFlatten as u}from"jodit/esm/core/helpers/utils/config-proto.js";import{previewBox as g}from"jodit/esm/core/helpers/utils/print.js";import{Plugin as h}from"jodit/esm/core/plugin/index.js";import{Ajax as b}from"jodit/esm/core/request/ajax.js";import{generateCriticalCSS as x}from"jodit/esm/plugins/print/lib/generate-critical-css.js";import{JoditPro as y}from"../../jodit-pro.js";const n=class n extends h{constructor(){super(...arguments),this.buttons=[{name:"exportDocs",group:"media"}]}afterInit(e){e.registerCommand("exportToPDF",async()=>{var o;const r=new b({...(o=e.o.exportDocs.ajax)!==null&&o!==void 0?o:e.o.filebrowser.ajax,method:"POST",responseType:"blob",onProgress(s){e.progressbar.show().progress(s)},data:{action:"generatePdf",html:n.getValue(e),options:u(e.o.exportDocs.pdf).options}});e.e.on("beforeDestruct",r.destruct);try{const l=await(await r.send()).blob(),t=this.j.create.a(),i="document.pdf";t.href=URL.createObjectURL(l),t.download=i,t.click(),f.safeRemove(t),URL.revokeObjectURL(t.href)}catch(s){s.message&&e.alert(s.message)}finally{e.progressbar.progress(100),await e.async.delay(200),e.progressbar.hide()}})}static getValue(e){const[o]=g(e),r=[];return e.o.exportDocs.pdf.externalFonts.forEach(s=>{/^</.test(s)?r.push(s):r.push(`<link rel="stylesheet" href="${s}">`)}),r.push(`<style>${x(e)}</style>`),r.push(`<style>${e.o.exportDocs.css}</style>`),r.push(o.innerHTML),r.join(` `)}beforeDestruct(){}};p(n,"ExportDocs");let a=n;a.requires=["license"],y.plugins.add("exportDocs",a);export{a as ExportDocs};