velaris-richtext-editor
Version:
A modern WYSIWYG rich text editor based on tiptap and shadcn ui for React
68 lines (67 loc) • 1.93 kB
JavaScript
import { E as c } from "./index-Drmyqk9P.js";
import { A as d } from "./RichTextEditor-BbtoCmQU.js";
function s(n) {
const t = document.createElement("iframe");
t.setAttribute("style", "position: absolute; width: 0; height: 0; top: 0; left: 0;"), document.body.appendChild(t), t.textContent = `
<!DOCTYPE html>
<html lang="en">
<head>
<title>Echo Editor</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body class="is-print">
<div class="tiptap ProseMirror" translate="no" aria-expanded="false">
${n}
</div>
</body>
</html>
`;
const e = t.contentWindow, o = t.contentDocument || t.contentWindow && t.contentWindow.document, i = document.createElement("link");
i.rel = "stylesheet", i.href = "https://cdn.jsdelivr.net/npm/reactjs-tiptap-editor@latest/lib/style.css", o.head.appendChild(i), o && (o.open(), o.write(n), o.close()), e && t.addEventListener("load", function() {
try {
setTimeout(() => {
e.focus();
try {
e.document.execCommand("print", !1) || e.print();
} catch {
e.print();
}
e.close();
}, 10);
} catch (r) {
console.error(r);
}
setTimeout(() => {
document.body.removeChild(t);
}, 100);
});
}
function a(n) {
const t = n.getHTML();
return t ? (s(t), !0) : !1;
}
const m = /* @__PURE__ */ c.create({
name: "exportPdf",
addOptions() {
var n;
return {
...(n = this.parent) == null ? void 0 : n.call(this),
button: ({ editor: t, t: e }) => ({
component: d,
componentProps: {
action: () => {
a(t);
},
icon: "ExportPdf",
tooltip: e("editor.exportPdf.tooltip"),
isActive: () => !1,
disabled: !1
}
})
};
}
});
export {
m as ExportPdf
};