reactjs-tiptap-editor
Version:
A modern WYSIWYG rich text editor based on tiptap and shadcn ui for React
106 lines (105 loc) • 3 kB
JavaScript
import { E as w } from "./clsx-DaPvp9ji.js";
import { Packer as x, WidthType as b } from "docx";
import { defaultNodes as n, DocxSerializer as h, defaultMarks as B } from "prosemirror-docx";
import { jsx as d, Fragment as v } from "react/jsx-runtime";
import { u as y, d as E, A as g } from "./index-RcSPeQHn.js";
import { useState as k } from "react";
import "./theme.js";
const W = typeof window < "u";
function A(e, o) {
if (W) {
const r = window.URL.createObjectURL(e), t = document.createElement("a");
return t.href = r, t.download = o, t.click(), window.URL.revokeObjectURL(r), Promise.resolve();
}
return console.error("Download is not supported in Node.js"), Promise.resolve();
}
function D() {
const e = y(R.name), [o, r] = k(!1), {
icon: t = void 0,
tooltip: s = void 0,
shortcutKeys: i = void 0,
tooltipOptions: l = {},
action: a = void 0,
isActive: p = void 0
} = (e == null ? void 0 : e.componentProps) ?? {}, { dataState: u, disabled: c, update: m } = E(p), f = async () => {
c || o || a && (r(!0), await a(), m(), r(!1));
};
return e ? /* @__PURE__ */ d(
g,
{
action: f,
dataState: u,
disabled: c || o,
icon: o ? "Loader" : t,
shortcutKeys: i,
tooltip: s,
tooltipOptions: l
}
) : /* @__PURE__ */ d(v, {});
}
const L = {
...n,
hardBreak: n.hard_break,
codeBlock: n.code_block,
orderedList: n.ordered_list,
listItem: n.list_item,
bulletList: n.bullet_list,
horizontalRule: n.horizontal_rule,
// Requirement Buffer on browser
image(e, o) {
e.renderInline(o), e.closeBlock(o);
},
table(e, o) {
e.table(o, {
tableOptions: {
width: {
size: 100,
type: b.PERCENTAGE
}
}
});
}
}, z = /* @__PURE__ */ new h(L, B), R = /* @__PURE__ */ w.create({
name: "exportWord",
//@ts-expect-error
addOptions() {
var e;
return {
...(e = this.parent) == null ? void 0 : e.call(this),
button: ({ editor: o, t: r }) => ({
componentProps: {
icon: "ExportWord",
action: () => {
var t;
return o == null ? void 0 : o.commands.exportToWord((t = o == null ? void 0 : o.state) == null ? void 0 : t.doc);
},
tooltip: r("editor.exportWord.tooltip"),
isActive: () => !1,
disabled: !1
}
})
};
},
// @ts-expect-error
addCommands() {
return {
exportToWord: (e) => async () => {
try {
const o = {
getImageBuffer: async (t) => {
const i = await (await fetch(t)).arrayBuffer();
return new Uint8Array(i);
}
}, r = z.serialize(e, o);
return x.toBlob(r).then((t) => A(new Blob([t]), "richtext-export-document.docx")), !0;
} catch (o) {
return console.error("Error exporting to Word:", o), !1;
}
}
};
}
});
export {
R as ExportWord,
D as RichTextExportWord
};