Files
claudia-docs-web/node_modules/@tiptap/extension-horizontal-rule/dist/index.cjs.map

1 line
5.6 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
{"version":3,"sources":["../src/index.ts","../src/horizontal-rule.ts"],"sourcesContent":["import { HorizontalRule } from './horizontal-rule.js'\n\nexport * from './horizontal-rule.js'\n\nexport default HorizontalRule\n","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<string, any>\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<ReturnType> {\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<HorizontalRuleOptions>({\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 its the end of the document\n const nodeType =\n chainState.schema.nodes[this.options.nextNodeType] || $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"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,kBAAqF;AACrF,mBAA6C;AAiCtC,IAAM,iBAAiB,iBAAK,OAA8B;AAAA,EAC/D,MAAM;AAAA,EAEN,aAAa;AACX,WAAO;AAAA,MACL,gBAAgB,CAAC;AAAA,MACjB,cAAc;AAAA,IAChB;AAAA,EACF;AAAA,EAEA,OAAO;AAAA,EAEP,YAAY;AACV,WAAO,CAAC,EAAE,KAAK,KAAK,CAAC;AAAA,EACvB;AAAA,EAEA,WAAW,EAAE,eAAe,GAAG;AAC7B,WAAO,CAAC,UAAM,6BAAgB,KAAK,QAAQ,gBAAgB,cAAc,CAAC;AAAA,EAC5E;AAAA,EAEA,mB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