From 86d570fb79b89a061cf1a5374a377ed6d9bca49e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20Ku=CC=88hn?= Date: Wed, 5 May 2021 20:50:01 +0200 Subject: [PATCH] feat: remove deprecated commands insertHTML, insertNode and insertText --- packages/core/src/commands/insertHTML.ts | 30 --------------------- packages/core/src/commands/insertNode.ts | 33 ------------------------ packages/core/src/commands/insertText.ts | 22 ---------------- packages/core/src/extensions/commands.ts | 9 ------- 4 files changed, 94 deletions(-) delete mode 100644 packages/core/src/commands/insertHTML.ts delete mode 100644 packages/core/src/commands/insertNode.ts delete mode 100644 packages/core/src/commands/insertText.ts diff --git a/packages/core/src/commands/insertHTML.ts b/packages/core/src/commands/insertHTML.ts deleted file mode 100644 index ceba9bb7..00000000 --- a/packages/core/src/commands/insertHTML.ts +++ /dev/null @@ -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 -} diff --git a/packages/core/src/commands/insertNode.ts b/packages/core/src/commands/insertNode.ts deleted file mode 100644 index a49e20ad..00000000 --- a/packages/core/src/commands/insertNode.ts +++ /dev/null @@ -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) => 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 -} diff --git a/packages/core/src/commands/insertText.ts b/packages/core/src/commands/insertText.ts deleted file mode 100644 index 56453aeb..00000000 --- a/packages/core/src/commands/insertText.ts +++ /dev/null @@ -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 -} diff --git a/packages/core/src/extensions/commands.ts b/packages/core/src/extensions/commands.ts index ea8dfb29..e1c1d129 100644 --- a/packages/core/src/extensions/commands.ts +++ b/packages/core/src/extensions/commands.ts @@ -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,