feat: add insertContent() command, deprecate insertText(), insertHTML() and insertNode()

This commit is contained in:
Philipp Kühn
2021-04-07 11:53:37 +02:00
parent 63acc57305
commit b8d9b7d4c7
21 changed files with 198 additions and 113 deletions

View File

@@ -1,5 +1,11 @@
import { TextSelection } from 'prosemirror-state'
import { AnyObject, Command, RawCommands } from '../types'
import createDocument from '../helpers/createDocument'
import {
AnyObject,
Command,
RawCommands,
Content,
} from '../types'
declare module '@tiptap/core' {
interface Commands {
@@ -7,15 +13,18 @@ declare module '@tiptap/core' {
/**
* Replace the whole document with new content.
*/
setContent: (content: string, emitUpdate?: Boolean, parseOptions?: AnyObject) => Command,
setContent: (
content: Content,
emitUpdate?: Boolean,
parseOptions?: AnyObject,
) => Command,
}
}
}
export const setContent: RawCommands['setContent'] = (content, emitUpdate = false, parseOptions = {}) => ({ tr, editor, dispatch }) => {
const { createDocument } = editor
const { doc } = tr
const document = createDocument(content, parseOptions)
const document = createDocument(content, editor.schema, parseOptions)
const selection = TextSelection.create(doc, 0, doc.content.size)
if (dispatch) {