chore: Upgrade all of prosemirror (#5366)

Co-authored-by: Apoorv Mishra <apoorvmishra101092@gmail.com>
This commit is contained in:
Tom Moor
2023-05-24 22:24:05 -04:00
committed by GitHub
parent e340e568e2
commit d5341a486c
77 changed files with 875 additions and 675 deletions

View File

@@ -1,6 +1,5 @@
import { NodeType } from "prosemirror-model";
import { EditorState } from "prosemirror-state";
import { Dispatch } from "../types";
import { Command } from "prosemirror-state";
/**
* Converts the current node to a paragraph when pressing backspace at the
@@ -9,28 +8,28 @@ import { Dispatch } from "../types";
* @param type The node type
* @returns A prosemirror command.
*/
export default function backspaceToParagraph(type: NodeType) {
return (state: EditorState, dispatch: Dispatch) => {
export default function backspaceToParagraph(type: NodeType): Command {
return (state, dispatch) => {
const { $from, from, to, empty } = state.selection;
// if the selection has anything in it then use standard delete behavior
if (!empty) {
return null;
return false;
}
// check we're in a matching node
if ($from.parent.type !== type) {
return null;
return false;
}
// check if we're at the beginning of the heading
const $pos = state.doc.resolve(from - 1);
if ($pos.parent === $from.parent) {
return null;
return false;
}
// okay, replace it with a paragraph
dispatch(
dispatch?.(
state.tr
.setBlockType(from, to, type.schema.nodes.paragraph)
.scrollIntoView()