From f71e4df72e95718f87b0509a28556730e4770c89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20Ku=CC=88hn?= Date: Fri, 25 Sep 2020 14:26:16 +0200 Subject: [PATCH] remove replaceWithNode --- docs/src/docPages/api/commands.md | 2 +- packages/core/src/commands/index.ts | 1 - packages/core/src/commands/replaceWithNode.ts | 36 ------------------- 3 files changed, 1 insertion(+), 38 deletions(-) delete mode 100644 packages/core/src/commands/replaceWithNode.ts diff --git a/docs/src/docPages/api/commands.md b/docs/src/docPages/api/commands.md index 09b51714b..8d55c86e5 100644 --- a/docs/src/docPages/api/commands.md +++ b/docs/src/docPages/api/commands.md @@ -21,10 +21,10 @@ editor.chain().focus().bold().run() | ------------------- | ------------------------------------------ | | .removeMark() | Remove a mark in the current selection. | | .removeMarks() | Remove all marks in the current selection. | -| .replaceWithNode() | Replace a given range with a node. | | .selectParentNode() | Select the parent node. | | .toggleMark() | Toggle a mark on and off. | | .toggleBlockType() | Toggle a node with another node. | +| .setBlockType() | Replace a given range with a node. | | .updateMark() | Update a mark with new attributes. | ### Selection diff --git a/packages/core/src/commands/index.ts b/packages/core/src/commands/index.ts index 7ea3e789c..e1e7582d6 100644 --- a/packages/core/src/commands/index.ts +++ b/packages/core/src/commands/index.ts @@ -7,7 +7,6 @@ export { insertText } from './insertText' export { liftListItem } from './liftListItem' export { removeMark } from './removeMark' export { removeMarks } from './removeMarks' -export { replaceWithNode } from './replaceWithNode' export { scrollIntoView } from './scrollIntoView' export { selectAll } from './selectAll' export { selectParentNode } from './selectParentNode' diff --git a/packages/core/src/commands/replaceWithNode.ts b/packages/core/src/commands/replaceWithNode.ts deleted file mode 100644 index afd694766..000000000 --- a/packages/core/src/commands/replaceWithNode.ts +++ /dev/null @@ -1,36 +0,0 @@ -import { NodeType } from 'prosemirror-model' -import { Command } from '../Editor' -import getNodeType from '../utils/getNodeType' - -interface Range { - from: number, - to: number, -} - -type ReplaceWithNodeCommand = ( - typeOrName: NodeType, - attrs: {}, - range?: Range, -) => Command - -declare module '../Editor' { - interface Commands { - replaceWithNode: ReplaceWithNodeCommand, - } -} - -export const replaceWithNode: ReplaceWithNodeCommand = (typeOrName, attrs = {}, range) => ({ view, tr, state }) => { - const { $from, $to } = tr.selection - const type = getNodeType(typeOrName, state.schema) - const index = $from.index() - const from = range ? range.from : $from.pos - const to = range ? range.to : $to.pos - - if (!$from.parent.canReplaceWith(index, index, type)) { - return false - } - - view.dispatch(tr.replaceWith(from, to, type.create(attrs))) - - return true -}