feat: remove deprecated commands insertHTML, insertNode and insertText
This commit is contained in:
@@ -1,30 +0,0 @@
|
||||
import { DOMParser } from 'prosemirror-model'
|
||||
import elementFromString from '../utilities/elementFromString'
|
||||
import selectionToInsertionEnd from '../helpers/selectionToInsertionEnd'
|
||||
import { Command, RawCommands } from '../types'
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface Commands {
|
||||
insertHTML: {
|
||||
/**
|
||||
* Insert a string of HTML at the current position.
|
||||
*/
|
||||
insertHTML: (value: string) => Command,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export const insertHTML: RawCommands['insertHTML'] = value => ({ tr, state, dispatch }) => {
|
||||
console.warn('[tiptap warn]: insertHTML() is deprecated. please use insertContent() instead.')
|
||||
|
||||
const { selection } = tr
|
||||
const element = elementFromString(value)
|
||||
const slice = DOMParser.fromSchema(state.schema).parseSlice(element)
|
||||
|
||||
if (dispatch) {
|
||||
tr.insert(selection.anchor, slice.content)
|
||||
selectionToInsertionEnd(tr, tr.steps.length - 1, -1)
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
import { NodeType } from 'prosemirror-model'
|
||||
import getNodeType from '../helpers/getNodeType'
|
||||
import { Command, RawCommands } from '../types'
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface Commands {
|
||||
insertNode: {
|
||||
/**
|
||||
* Insert a node at the current position.
|
||||
*/
|
||||
insertNode: (typeOrName: string | NodeType, attributes?: Record<string, any>) => Command,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export const insertNode: RawCommands['insertNode'] = (typeOrName, attributes = {}) => ({ tr, state, dispatch }) => {
|
||||
console.warn('[tiptap warn]: insertNode() is deprecated. please use insertContent() instead.')
|
||||
|
||||
const { selection } = tr
|
||||
const type = getNodeType(typeOrName, state.schema)
|
||||
|
||||
if (!type) {
|
||||
return false
|
||||
}
|
||||
|
||||
const node = type.create(attributes)
|
||||
|
||||
if (dispatch) {
|
||||
tr.insert(selection.anchor, node)
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
import { Command, RawCommands } from '../types'
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface Commands {
|
||||
insertText: {
|
||||
/**
|
||||
* Insert a string of text at the current position.
|
||||
*/
|
||||
insertText: (value: string) => Command,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export const insertText: RawCommands['insertText'] = value => ({ tr, dispatch }) => {
|
||||
console.warn('[tiptap warn]: insertText() is deprecated. please use insertContent() instead.')
|
||||
|
||||
if (dispatch) {
|
||||
tr.insertText(value)
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
Reference in New Issue
Block a user