reactjs-tiptap-editor
Version:
A modern WYSIWYG rich text editor based on tiptap and shadcn ui for React
109 lines (108 loc) • 2.87 kB
JavaScript
import { N as m, w as h, m as k } from "./clsx-DaPvp9ji.js";
import { h as a } from "./jsx-runtime-CT7Pcg-t.js";
import { jsx as d, Fragment as g } from "react/jsx-runtime";
import { u as f, d as b, A as q } from "./index-RcSPeQHn.js";
import "react";
import "./theme.js";
var v = /^\s*>\s$/, B = m.create({
name: "blockquote",
addOptions() {
return {
HTMLAttributes: {}
};
},
content: "block+",
group: "block",
defining: !0,
parseHTML() {
return [{ tag: "blockquote" }];
},
renderHTML({ HTMLAttributes: t }) {
return /* @__PURE__ */ a("blockquote", { ...k(this.options.HTMLAttributes, t), children: /* @__PURE__ */ a("slot", {}) });
},
parseMarkdown: (t, o) => o.createNode("blockquote", void 0, o.parseChildren(t.tokens || [])),
renderMarkdown: (t, o) => {
if (!t.content)
return "";
const e = ">", n = [];
return t.content.forEach((i) => {
const c = o.renderChildren([i]).split(`
`).map((r) => r.trim() === "" ? e : `${e} ${r}`);
n.push(c.join(`
`));
}), n.join(`
${e}
`);
},
addCommands() {
return {
setBlockquote: () => ({ commands: t }) => t.wrapIn(this.name),
toggleBlockquote: () => ({ commands: t }) => t.toggleWrap(this.name),
unsetBlockquote: () => ({ commands: t }) => t.lift(this.name)
};
},
addKeyboardShortcuts() {
return {
"Mod-Shift-b": () => this.editor.commands.toggleBlockquote()
};
},
addInputRules() {
return [
h({
find: v,
type: this.type
})
];
}
});
function H() {
const t = f(A.name), {
icon: o = void 0,
tooltip: e = void 0,
shortcutKeys: n = void 0,
tooltipOptions: i = {},
action: s = void 0,
isActive: u = void 0
} = (t == null ? void 0 : t.componentProps) ?? {}, { dataState: c, disabled: r, update: l } = b(u), p = () => {
r || s && (s(), l());
};
return t ? /* @__PURE__ */ d(
q,
{
action: p,
dataState: c,
disabled: r,
icon: o,
shortcutKeys: n,
tooltip: e,
tooltipOptions: i
}
) : /* @__PURE__ */ d(g, {});
}
const A = /* @__PURE__ */ B.extend({
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
//@ts-expect-error
addOptions() {
var t;
return {
...(t = this.parent) == null ? void 0 : t.call(this),
HTMLAttributes: {
class: "blockquote"
},
button: ({ editor: o, t: e, extension: n }) => ({
componentProps: {
action: () => o.commands.toggleBlockquote(),
isActive: () => o.isActive("blockquote"),
disabled: !o.can().toggleBlockquote(),
icon: "TextQuote",
shortcutKeys: n.options.shortcutKeys ?? ["shift", "mod", "B"],
tooltip: e("editor.blockquote.tooltip")
}
})
};
}
});
export {
A as Blockquote,
H as RichTextBlockquote
};