add horizontal rule extension
This commit is contained in:
28
packages/extension-horizontal-rule/index.ts
Normal file
28
packages/extension-horizontal-rule/index.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import { Node, nodeInputRule } from '@tiptap/core'
|
||||
|
||||
declare module '@tiptap/core/src/Editor' {
|
||||
interface Editor {
|
||||
horizontalRule(): Editor,
|
||||
}
|
||||
}
|
||||
|
||||
export default new Node()
|
||||
.name('horizontalRule')
|
||||
.schema(() => ({
|
||||
group: 'block',
|
||||
parseDOM: [{ tag: 'hr' }],
|
||||
toDOM: () => ['hr'],
|
||||
}))
|
||||
.commands(({ editor, type }) => ({
|
||||
horizontalRule: next => () => {
|
||||
const { state, view } = editor
|
||||
const { dispatch } = view
|
||||
|
||||
dispatch(state.tr.replaceSelectionWith(type.create()))
|
||||
next()
|
||||
},
|
||||
}))
|
||||
.inputRules(({ type }) => [
|
||||
nodeInputRule(/^(?:---|___\s|\*\*\*\s)$/, type),
|
||||
])
|
||||
.create()
|
||||
18
packages/extension-horizontal-rule/package.json
Normal file
18
packages/extension-horizontal-rule/package.json
Normal file
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"name": "@tiptap/extension-horizontal-rule",
|
||||
"version": "1.0.0",
|
||||
"source": "index.ts",
|
||||
"main": "dist/tiptap-extension-horizontal-rule.js",
|
||||
"umd:main": "dist/tiptap-extension-horizontal-rule.umd.js",
|
||||
"module": "dist/tiptap-extension-horizontal-rule.mjs",
|
||||
"unpkg": "dist/tiptap-extension-horizontal-rule.js",
|
||||
"jsdelivr": "dist/tiptap-extension-horizontal-rule.js",
|
||||
"files": [
|
||||
"src",
|
||||
"dist"
|
||||
],
|
||||
"peerDependencies": {
|
||||
"@tiptap/core": "2.x",
|
||||
"prosemirror-commands": "^1.1.3"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user