UNPKG

reactjs-tiptap-editor

Version:

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

125 lines (124 loc) 3.27 kB
import { M as _, e as a, f as i, m as y } from "./clsx-DaPvp9ji.js"; import { h as d } from "./jsx-runtime-CT7Pcg-t.js"; import { u as f, d as M, A as l } from "./index-RcSPeQHn.js"; import { jsx as u, Fragment as v } from "react/jsx-runtime"; import "react"; import "./theme.js"; var B = /(?:^|\s)(\*\*(?!\s+\*\*)((?:[^*]+))\*\*(?!\s+\*\*))$/, k = /(?:^|\s)(\*\*(?!\s+\*\*)((?:[^*]+))\*\*(?!\s+\*\*))/g, b = /(?:^|\s)(__(?!\s+__)((?:[^_]+))__(?!\s+__))$/, A = /(?:^|\s)(__(?!\s+__)((?:[^_]+))__(?!\s+__))/g, R = _.create({ name: "bold", addOptions() { return { HTMLAttributes: {} }; }, parseHTML() { return [ { tag: "strong" }, { tag: "b", getAttrs: (t) => t.style.fontWeight !== "normal" && null }, { style: "font-weight=400", clearMark: (t) => t.type.name === this.name }, { style: "font-weight", getAttrs: (t) => /^(bold(er)?|[5-9]\d{2,})$/.test(t) && null } ]; }, renderHTML({ HTMLAttributes: t }) { return /* @__PURE__ */ d("strong", { ...y(this.options.HTMLAttributes, t), children: /* @__PURE__ */ d("slot", {}) }); }, markdownTokenName: "strong", parseMarkdown: (t, e) => e.applyMark("bold", e.parseInline(t.tokens || [])), renderMarkdown: (t, e) => `**${e.renderChildren(t)}**`, addCommands() { return { setBold: () => ({ commands: t }) => t.setMark(this.name), toggleBold: () => ({ commands: t }) => t.toggleMark(this.name), unsetBold: () => ({ commands: t }) => t.unsetMark(this.name) }; }, addKeyboardShortcuts() { return { "Mod-b": () => this.editor.commands.toggleBold(), "Mod-B": () => this.editor.commands.toggleBold() }; }, addInputRules() { return [ i({ find: B, type: this.type }), i({ find: b, type: this.type }) ]; }, addPasteRules() { return [ a({ find: k, type: this.type }), a({ find: A, type: this.type }) ]; } }); function K() { const t = f(x.name), { icon: e = void 0, tooltip: o = void 0, shortcutKeys: r = void 0, tooltipOptions: p = {}, action: n = void 0, isActive: m = void 0 } = (t == null ? void 0 : t.componentProps) ?? {}, { dataState: c, disabled: s, update: g } = M(m), h = () => { s || n && (n(), g()); }; return t ? /* @__PURE__ */ u( l, { action: h, dataState: c, disabled: s, icon: e, shortcutKeys: r, tooltip: o, tooltipOptions: p } ) : /* @__PURE__ */ u(v, {}); } const x = /* @__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: o, extension: r }) => ({ component: l, componentProps: { action: () => e.commands.toggleBold(), isActive: () => e.isActive("bold"), icon: "Bold", shortcutKeys: r.options.shortcutKeys ?? ["mod", "B"], tooltip: o("editor.bold.tooltip") } }) }; } }); export { x as Bold, K as RichTextBold };