UNPKG

velaris-richtext-editor

Version:

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

88 lines (87 loc) 2.47 kB
import { N as f, n as h, i as A, T as a, f as H, m as p } from "./index-Drmyqk9P.js"; import { A as T } from "./RichTextEditor-BbtoCmQU.js"; const y = f.create({ name: "horizontalRule", addOptions() { return { HTMLAttributes: {} }; }, group: "block", parseHTML() { return [{ tag: "hr" }]; }, renderHTML({ HTMLAttributes: o }) { return ["hr", p(this.options.HTMLAttributes, o)]; }, addCommands() { return { setHorizontalRule: () => ({ chain: o, state: n }) => { const { selection: s } = n, { $from: c, $to: l } = s, r = o(); return c.parentOffset === 0 ? r.insertContentAt({ from: Math.max(c.pos - 1, 0), to: l.pos }, { type: this.name }) : A(s) ? r.insertContentAt(l.pos, { type: this.name }) : r.insertContent({ type: this.name }), r.command(({ tr: e, dispatch: m }) => { var i; if (m) { const { $to: t } = e.selection, d = t.end(); if (t.nodeAfter) t.nodeAfter.isTextblock ? e.setSelection(a.create(e.doc, t.pos + 1)) : t.nodeAfter.isBlock ? e.setSelection(H.create(e.doc, t.pos)) : e.setSelection(a.create(e.doc, t.pos)); else { const u = (i = t.parent.type.contentMatch.defaultType) === null || i === void 0 ? void 0 : i.create(); u && (e.insert(d, u), e.setSelection(a.create(e.doc, d + 1))); } e.scrollIntoView(); } return !0; }).run(); } }; }, addInputRules() { return [ h({ find: /^(?:---|—-|___\s|\*\*\*\s)$/, type: this.type }) ]; } }), R = /* @__PURE__ */ y.extend({ renderHTML() { return [ "div", p(this.options.HTMLAttributes, { "data-type": this.name }), ["hr"] ]; }, addOptions() { var o; return { ...(o = this.parent) == null ? void 0 : o.call(this), button: ({ editor: n, t: s }) => ({ component: T, componentProps: { action: () => n.commands.setHorizontalRule(), disabled: !n.can().setHorizontalRule(), icon: "Minus", shortcutKeys: ["mod", "alt", "S"], tooltip: s("editor.horizontalrule.tooltip") } }) }; }, addKeyboardShortcuts() { return { "Mod-Alt-s": () => this.editor.commands.setHorizontalRule() }; } }); export { R as HorizontalRule };