feat: add insertContent() command, deprecate insertText(), insertHTML() and insertNode()
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user