{"version":3,"file":"index.js","names":[],"sources":["../src/horizontal-rule.ts","../src/index.ts"],"sourcesContent":["import { canInsertNode, isNodeSelection, mergeAttributes, Node, nodeInputRule } from '@tiptap/core'\nimport { NodeSelection, TextSelection } from '@tiptap/pm/state'\n\nexport interface HorizontalRuleOptions {\n /**\n * The HTML attributes for a horizontal rule node.\n * @default {}\n * @example { class: 'foo' }\n */\n HTMLAttributes: Record\n /**\n * The default type to insert after the horizontal rule.\n * @default \"paragraph\"\n * @example \"heading\"\n */\n nextNodeType: string\n}\n\ndeclare module '@tiptap/core' {\n interface Commands {\n horizontalRule: {\n /**\n * Add a horizontal rule\n * @example editor.commands.setHorizontalRule()\n */\n setHorizontalRule: () => ReturnType\n }\n }\n}\n\n/**\n * This extension allows you to insert horizontal rules.\n * @see https://www.tiptap.dev/api/nodes/horizontal-rule\n */\nexport const HorizontalRule = Node.create({\n name: 'horizontalRule',\n\n addOptions() {\n return {\n HTMLAttributes: {},\n nextNodeType: 'paragraph',\n }\n },\n\n group: 'block',\n\n parseHTML() {\n return [{ tag: 'hr' }]\n },\n\n renderHTML({ HTMLAttributes }) {\n return ['hr', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes)]\n },\n\n markdownTokenName: 'hr',\n\n parseMarkdown: (token, helpers) => {\n return helpers.createNode('horizontalRule')\n },\n\n renderMarkdown: () => {\n return '---'\n },\n\n addCommands() {\n return {\n setHorizontalRule:\n () =>\n ({ chain, state }) => {\n // Check if we can insert the node at the current selection\n if (!canInsertNode(state, state.schema.nodes[this.name])) {\n return false\n }\n\n const { selection } = state\n const { $to: $originTo } = selection\n\n const currentChain = chain()\n\n if (isNodeSelection(selection)) {\n currentChain.insertContentAt($originTo.pos, {\n type: this.name,\n })\n } else {\n currentChain.insertContent({ type: this.name })\n }\n\n return (\n currentChain\n // set cursor after horizontal rule\n .command(({ state: chainState, tr, dispatch }) => {\n if (dispatch) {\n const { $to } = tr.selection\n const posAfter = $to.end()\n\n if ($to.nodeAfter) {\n if ($to.nodeAfter.isTextblock) {\n tr.setSelection(TextSelection.create(tr.doc, $to.pos + 1))\n } else if ($to.nodeAfter.isBlock) {\n tr.setSelection(NodeSelection.create(tr.doc, $to.pos))\n } else {\n tr.setSelection(TextSelection.create(tr.doc, $to.pos))\n }\n } else {\n // add node after horizontal rule if it’s the end of the document\n const nodeType =\n chainState.schema.nodes[this.options.nextNodeType] ||\n $to.parent.type.contentMatch.defaultType\n const node = nodeType?.create()\n\n if (node) {\n tr.insert(posAfter, node)\n tr.setSelection(TextSelection.create(tr.doc, posAfter + 1))\n }\n }\n\n tr.scrollIntoView()\n }\n\n return true\n })\n .run()\n )\n },\n }\n },\n\n addInputRules() {\n return [\n nodeInputRule({\n find: /^(?:---|—-|___\\s|\\*\\*\\*\\s)$/,\n type: this.type,\n }),\n ]\n },\n})\n","import { HorizontalRule } from './horizontal-rule.js'\n\nexport * from './horizontal-rule.js'\n\nexport default HorizontalRule\n"],"mappings":";;;;;;;AAkCA,MAAa,iBAAiB,KAAK,OAA8B;CAC/D,MAAM;CAEN,aAAa;EACX,OAAO;GACL,gBAAgB,CAAC;GACjB,cAAc;EAChB;CACF;CAEA,OAAO;CAEP,YAAY;EACV,OAAO,CAAC,EAAE,KAAK,KAAK,CAAC;CACvB;CAEA,WAAW,EAAE,kBAAkB;EAC7B,OAAO,CAAC,MAAM,gBAAgB,KAAK,QAAQ,gBAAgB,cAAc,CAAC;CAC5E;CAEA,mBAAmB;CAEnB,gBAAgB,OAAO,YAAY;EACjC,OAAO,QAAQ,WAAW,gBAAgB;CAC5C;CAEA,sBAAsB;EACpB,OAAO;CACT;CAEA,cAAc;EACZ,OAAO,EACL,0BAEG,EAAE,OAAO,YAAY;GAEpB,IAAI,CAAC,cAAc,OAAO,MAAM,OAAO,MAAM,KAAK,KAAK,GACrD,OAAO;GAGT,MAAM,EAAE,cAAc;GACtB,MAAM,EAAE,KAAK,cAAc;GAE3B,MAAM,eAAe,MAAM;GAE3B,IAAI,gBAAgB,SAAS,G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