UNPKG

reactjs-tiptap-editor

Version:

A modern WYSIWYG rich text editor based on tiptap and shadcn ui for React

125 lines (124 loc) 3.14 kB
import { M as g, e as i, f as o, m as y } from "./clsx-DaPvp9ji.js"; import { jsx as d, Fragment as f } from "react/jsx-runtime"; import { u as h, d as I, A as v } from "./index-RcSPeQHn.js"; import "react"; import "./theme.js"; var M = /(?:^|\s)(\*(?!\s+\*)((?:[^*]+))\*(?!\s+\*))$/, k = /(?:^|\s)(\*(?!\s+\*)((?:[^*]+))\*(?!\s+\*))/g, A = /(?:^|\s)(_(?!\s+_)((?:[^_]+))_(?!\s+_))$/, _ = /(?:^|\s)(_(?!\s+_)((?:[^_]+))_(?!\s+_))/g, x = g.create({ name: "italic", addOptions() { return { HTMLAttributes: {} }; }, parseHTML() { return [ { tag: "em" }, { tag: "i", getAttrs: (t) => t.style.fontStyle !== "normal" && null }, { style: "font-style=normal", clearMark: (t) => t.type.name === this.name }, { style: "font-style=italic" } ]; }, renderHTML({ HTMLAttributes: t }) { return ["em", y(this.options.HTMLAttributes, t), 0]; }, addCommands() { return { setItalic: () => ({ commands: t }) => t.setMark(this.name), toggleItalic: () => ({ commands: t }) => t.toggleMark(this.name), unsetItalic: () => ({ commands: t }) => t.unsetMark(this.name) }; }, markdownTokenName: "em", parseMarkdown: (t, e) => e.applyMark("italic", e.parseInline(t.tokens || [])), renderMarkdown: (t, e) => `*${e.renderChildren(t)}*`, addKeyboardShortcuts() { return { "Mod-i": () => this.editor.commands.toggleItalic(), "Mod-I": () => this.editor.commands.toggleItalic() }; }, addInputRules() { return [ o({ find: M, type: this.type }), o({ find: A, type: this.type }) ]; }, addPasteRules() { return [ i({ find: k, type: this.type }), i({ find: _, type: this.type }) ]; } }), R = x; function $() { const t = h(T.name), { icon: e = void 0, tooltip: r = void 0, shortcutKeys: s = void 0, tooltipOptions: l = {}, action: a = void 0, isActive: c = void 0 } = (t == null ? void 0 : t.componentProps) ?? {}, { dataState: u, disabled: n, update: m } = I(c), p = () => { n || a && (a(), m()); }; return t ? /* @__PURE__ */ d( v, { action: p, dataState: u, disabled: n, icon: e, shortcutKeys: s, tooltip: r, tooltipOptions: l } ) : /* @__PURE__ */ d(f, {}); } const T = /* @__PURE__ */ R.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 }) { return { componentProps: { action: () => e.commands.toggleItalic(), isActive: () => e.isActive("italic") || !1, disabled: !1, shortcutKeys: s.options.shortcutKeys ?? ["mod", "I"], icon: "Italic", tooltip: r("editor.italic.tooltip") } }; } }; } }); export { T as Italic, $ as RichTextItalic };