import { Node as f, nodeInputRule as m, isNodeSelection as h, mergeAttributes as A } from "../../../../../@tiptap_core@2.14.0_@tiptap_pm@2.14.0/node_modules/@tiptap/core/dist/index.js";
import { TextSelection as r, NodeSelection as T } from "../../../../../prosemirror-state@1.4.3/node_modules/prosemirror-state/dist/index.js";
const H = f.create({
  name: "horizontalRule",
  addOptions() {
    return {
      HTMLAttributes: {}
    };
  },
  group: "block",
  parseHTML() {
    return [{ tag: "hr" }];
  },
  renderHTML({ HTMLAttributes: n }) {
    return ["hr", A(this.options.HTMLAttributes, n)];
  },
  addCommands() {
    return {
      setHorizontalRule: () => ({ chain: n, state: p }) => {
        const { selection: i } = p, { $from: c, $to: a } = i, o = n();
        return c.parentOffset === 0 ? o.insertContentAt({
          from: Math.max(c.pos - 1, 0),
          to: a.pos
        }, {
          type: this.name
        }) : h(i) ? o.insertContentAt(a.pos, {
          type: this.name
        }) : o.insertContent({ type: this.name }), o.command(({ tr: e, dispatch: u }) => {
          var s;
          if (u) {
            const { $to: t } = e.selection, l = t.end();
            if (t.nodeAfter)
              t.nodeAfter.isTextblock ? e.setSelection(r.create(e.doc, t.pos + 1)) : t.nodeAfter.isBlock ? e.setSelection(T.create(e.doc, t.pos)) : e.setSelection(r.create(e.doc, t.pos));
            else {
              const d = (s = t.parent.type.contentMatch.defaultType) === null || s === void 0 ? void 0 : s.create();
              d && (e.insert(l, d), e.setSelection(r.create(e.doc, l + 1)));
            }
            e.scrollIntoView();
          }
          return !0;
        }).run();
      }
    };
  },
  addInputRules() {
    return [
      m({
        find: /^(?:---|—-|___\s|\*\*\*\s)$/,
        type: this.type
      })
    ];
  }
});
export {
  H as HorizontalRule,
  H as default
};
//# sourceMappingURL=index.js.map
