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