reactjs-tiptap-editor
Version:
A modern WYSIWYG rich text editor based on tiptap and shadcn ui for React
114 lines (113 loc) • 2.79 kB
JavaScript
import { M as m, e as k, f as l, m as g } from "./clsx-DaPvp9ji.js";
import { jsx as n, Fragment as h } from "react/jsx-runtime";
import { u as f, d as M, A as S } from "./index-RcSPeQHn.js";
import "react";
import "./theme.js";
var v = /(?:^|\s)(~~(?!\s+~~)((?:[^~]+))~~(?!\s+~~))$/, A = /(?:^|\s)(~~(?!\s+~~)((?:[^~]+))~~(?!\s+~~))/g, y = m.create({
name: "strike",
addOptions() {
return {
HTMLAttributes: {}
};
},
parseHTML() {
return [
{
tag: "s"
},
{
tag: "del"
},
{
tag: "strike"
},
{
style: "text-decoration",
consuming: !1,
getAttrs: (t) => t.includes("line-through") ? {} : !1
}
];
},
renderHTML({ HTMLAttributes: t }) {
return ["s", g(this.options.HTMLAttributes, t), 0];
},
markdownTokenName: "del",
parseMarkdown: (t, e) => e.applyMark("strike", e.parseInline(t.tokens || [])),
renderMarkdown: (t, e) => `~~${e.renderChildren(t)}~~`,
addCommands() {
return {
setStrike: () => ({ commands: t }) => t.setMark(this.name),
toggleStrike: () => ({ commands: t }) => t.toggleMark(this.name),
unsetStrike: () => ({ commands: t }) => t.unsetMark(this.name)
};
},
addKeyboardShortcuts() {
return {
"Mod-Shift-s": () => this.editor.commands.toggleStrike()
};
},
addInputRules() {
return [
l({
find: v,
type: this.type
})
];
},
addPasteRules() {
return [
k({
find: A,
type: this.type
})
];
}
});
function L() {
const t = f(x.name), {
icon: e = void 0,
tooltip: r = void 0,
shortcutKeys: s = void 0,
tooltipOptions: a = {},
action: i = void 0,
isActive: d = void 0
} = (t == null ? void 0 : t.componentProps) ?? {}, { dataState: u, disabled: o, update: p } = M(d), c = () => {
o || i && (i(), p());
};
return t ? /* @__PURE__ */ n(
S,
{
action: c,
dataState: u,
disabled: o,
icon: e,
shortcutKeys: s,
tooltip: r,
tooltipOptions: a
}
) : /* @__PURE__ */ n(h, {});
}
const x = /* @__PURE__ */ y.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),
button: ({ editor: e, t: r, extension: s }) => ({
componentProps: {
action: () => e.commands.toggleStrike(),
isActive: () => e.isActive("strike") || !1,
disabled: !1,
icon: "Strikethrough",
shortcutKeys: s.options.shortcutKeys ?? ["shift", "mod", "S"],
tooltip: r("editor.strike.tooltip")
}
})
};
}
});
export {
L as RichTextStrike,
x as Strike
};