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
|
||||
}
|
||||
@@ -13,9 +13,6 @@ import * as first from '../commands/first'
|
||||
import * as focus from '../commands/focus'
|
||||
import * as insertContent from '../commands/insertContent'
|
||||
import * as insertContentAt from '../commands/insertContentAt'
|
||||
import * as insertHTML from '../commands/insertHTML'
|
||||
import * as insertNode from '../commands/insertNode'
|
||||
import * as insertText from '../commands/insertText'
|
||||
import * as joinBackward from '../commands/joinBackward'
|
||||
import * as joinForward from '../commands/joinForward'
|
||||
import * as keyboardShortcut from '../commands/keyboardShortcut'
|
||||
@@ -66,9 +63,6 @@ export { first }
|
||||
export { focus }
|
||||
export { insertContent }
|
||||
export { insertContentAt }
|
||||
export { insertHTML }
|
||||
export { insertNode }
|
||||
export { insertText }
|
||||
export { joinBackward }
|
||||
export { joinForward }
|
||||
export { keyboardShortcut }
|
||||
@@ -124,9 +118,6 @@ export const Commands = Extension.create({
|
||||
...focus,
|
||||
...insertContent,
|
||||
...insertContentAt,
|
||||
...insertHTML,
|
||||
...insertNode,
|
||||
...insertText,
|
||||
...joinBackward,
|
||||
...joinForward,
|
||||
...keyboardShortcut,
|
||||
|
||||
Reference in New Issue
Block a user