Merge branch 'main' of github.com:ueberdosis/tiptap-next into main
This commit is contained in:
@@ -22,7 +22,9 @@
|
|||||||
"dist"
|
"dist"
|
||||||
],
|
],
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
"@tiptap/core": "^2.0.0-beta.1",
|
"@tiptap/core": "^2.0.0-beta.1"
|
||||||
"prosemirror-commands": "^1.1.3"
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"prosemirror-state": "^1.3.4"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import {
|
|||||||
nodeInputRule,
|
nodeInputRule,
|
||||||
mergeAttributes,
|
mergeAttributes,
|
||||||
} from '@tiptap/core'
|
} from '@tiptap/core'
|
||||||
|
import { TextSelection } from 'prosemirror-state'
|
||||||
|
|
||||||
export interface HorizontalRuleOptions {
|
export interface HorizontalRuleOptions {
|
||||||
HTMLAttributes: {
|
HTMLAttributes: {
|
||||||
@@ -46,6 +47,22 @@ export const HorizontalRule = Node.create<HorizontalRuleOptions>({
|
|||||||
setHorizontalRule: () => ({ tr, dispatch }) => {
|
setHorizontalRule: () => ({ tr, dispatch }) => {
|
||||||
if (dispatch) {
|
if (dispatch) {
|
||||||
tr.replaceSelectionWith(this.type.create())
|
tr.replaceSelectionWith(this.type.create())
|
||||||
|
|
||||||
|
const { parent, pos } = tr.selection.$from
|
||||||
|
const posAfter = pos + 1
|
||||||
|
const nodeAfter = tr.doc.nodeAt(posAfter)
|
||||||
|
|
||||||
|
// end of document
|
||||||
|
if (!nodeAfter) {
|
||||||
|
const node = parent.type.contentMatch.defaultType?.create()
|
||||||
|
|
||||||
|
if (node) {
|
||||||
|
tr.insert(posAfter, node)
|
||||||
|
tr.setSelection(TextSelection.create(tr.doc, posAfter))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
tr.scrollIntoView()
|
||||||
}
|
}
|
||||||
|
|
||||||
return true
|
return true
|
||||||
|
|||||||
Reference in New Issue
Block a user