From 540b0656f3515cdba60fa670f5eda540d85a7e26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20Ku=CC=88hn?= Date: Fri, 20 Nov 2020 23:56:41 +0100 Subject: [PATCH] rename setBlockType to setNode --- docs/src/docPages/api/commands.md | 2 +- packages/core/src/commands/setBlockType.ts | 13 ------------- packages/core/src/commands/setNode.ts | 13 +++++++++++++ packages/core/src/commands/toggleBlockType.ts | 4 ++-- packages/core/src/extensions/commands.ts | 4 ++-- packages/extension-code-block/src/index.ts | 2 +- packages/extension-heading/src/index.ts | 2 +- 7 files changed, 20 insertions(+), 20 deletions(-) delete mode 100644 packages/core/src/commands/setBlockType.ts create mode 100644 packages/core/src/commands/setNode.ts diff --git a/docs/src/docPages/api/commands.md b/docs/src/docPages/api/commands.md index 2c4f5696..25f2dd31 100644 --- a/docs/src/docPages/api/commands.md +++ b/docs/src/docPages/api/commands.md @@ -110,7 +110,7 @@ Have a look at all of the core commands listed below. They should give you a goo | .extendMarkRange() | Extends the text selection to the current mark. | | .resetNodeAttributes() | Resets all node attributes to the default value. | | .selectParentNode() | Select the parent node. | -| .setBlockType() | Replace a given range with a node. | +| .setNode() | Replace a given range with a node. | | .setMark() | Add a mark with new attributes. | | .splitBlock() | Forks a new node from an existing node. | | .toggleBlockType() | Toggle a node with another node. | diff --git a/packages/core/src/commands/setBlockType.ts b/packages/core/src/commands/setBlockType.ts deleted file mode 100644 index 5f14af48..00000000 --- a/packages/core/src/commands/setBlockType.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { NodeType } from 'prosemirror-model' -import { setBlockType as originalSetBlockType } from 'prosemirror-commands' -import { Command } from '../types' -import getNodeType from '../utils/getNodeType' - -/** - * Replace a given range with a node. - */ -export const setBlockType = (typeOrName: string | NodeType, attrs = {}): Command => ({ state, dispatch }) => { - const type = getNodeType(typeOrName, state.schema) - - return originalSetBlockType(type, attrs)(state, dispatch) -} diff --git a/packages/core/src/commands/setNode.ts b/packages/core/src/commands/setNode.ts new file mode 100644 index 00000000..880e19d5 --- /dev/null +++ b/packages/core/src/commands/setNode.ts @@ -0,0 +1,13 @@ +import { NodeType } from 'prosemirror-model' +import { setBlockType } from 'prosemirror-commands' +import { Command } from '../types' +import getNodeType from '../utils/getNodeType' + +/** + * Replace a given range with a node. + */ +export const setNode = (typeOrName: string | NodeType, attrs = {}): Command => ({ state, dispatch }) => { + const type = getNodeType(typeOrName, state.schema) + + return setBlockType(type, attrs)(state, dispatch) +} diff --git a/packages/core/src/commands/toggleBlockType.ts b/packages/core/src/commands/toggleBlockType.ts index d8c23b0a..9ab8ea3b 100644 --- a/packages/core/src/commands/toggleBlockType.ts +++ b/packages/core/src/commands/toggleBlockType.ts @@ -12,8 +12,8 @@ export const toggleBlockType = (typeOrName: string | NodeType, toggleTypeOrName: const isActive = nodeIsActive(state, type, attrs) if (isActive) { - return commands.setBlockType(toggleType) + return commands.setNode(toggleType) } - return commands.setBlockType(type, attrs) + return commands.setNode(type, attrs) } diff --git a/packages/core/src/extensions/commands.ts b/packages/core/src/extensions/commands.ts index 38030a1b..6029e4f1 100644 --- a/packages/core/src/extensions/commands.ts +++ b/packages/core/src/extensions/commands.ts @@ -15,9 +15,9 @@ import * as resetNodeAttributes from '../commands/resetNodeAttributes' import * as scrollIntoView from '../commands/scrollIntoView' import * as selectAll from '../commands/selectAll' import * as selectParentNode from '../commands/selectParentNode' -import * as setBlockType from '../commands/setBlockType' import * as setContent from '../commands/setContent' import * as setMark from '../commands/setMark' +import * as setNode from '../commands/setNode' import * as sinkListItem from '../commands/sinkListItem' import * as splitBlock from '../commands/splitBlock' import * as splitListItem from '../commands/splitListItem' @@ -50,9 +50,9 @@ export const Commands = Extension.create({ ...scrollIntoView, ...selectAll, ...selectParentNode, - ...setBlockType, ...setContent, ...setMark, + ...setNode, ...sinkListItem, ...splitBlock, ...splitListItem, diff --git a/packages/extension-code-block/src/index.ts b/packages/extension-code-block/src/index.ts index 337f0b2c..679dab1e 100644 --- a/packages/extension-code-block/src/index.ts +++ b/packages/extension-code-block/src/index.ts @@ -78,7 +78,7 @@ const CodeBlock = Node.create({ * Set a code block */ setCodeBlock: (attributes?: { language: string }): Command => ({ commands }) => { - return commands.setBlockType('codeBlock', attributes) + return commands.setNode('codeBlock', attributes) }, /** * Toggle a code block diff --git a/packages/extension-heading/src/index.ts b/packages/extension-heading/src/index.ts index a9a1ee39..809afd23 100644 --- a/packages/extension-heading/src/index.ts +++ b/packages/extension-heading/src/index.ts @@ -60,7 +60,7 @@ const Heading = Node.create({ return false } - return commands.setBlockType('heading', attributes) + return commands.setNode('heading', attributes) }, /** * Toggle a heading node