From 170ec4be5b3c8362890ca3100a223b505f788381 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20K=C3=BChn?= Date: Mon, 13 Dec 2021 13:32:19 +0100 Subject: [PATCH] =?UTF-8?q?fix:=20don=E2=80=99t=20check=20for=20active=20n?= =?UTF-8?q?ode=20in=20wrapIn=20command,=20fix=20#1059?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- demos/src/Nodes/Blockquote/React/index.jsx | 21 +++++++++++++-------- demos/src/Nodes/Blockquote/Vue/index.vue | 4 ++-- packages/core/src/commands/toggleWrap.ts | 7 +++---- packages/core/src/commands/wrapIn.ts | 6 ------ 4 files changed, 18 insertions(+), 20 deletions(-) diff --git a/demos/src/Nodes/Blockquote/React/index.jsx b/demos/src/Nodes/Blockquote/React/index.jsx index 1413a3f0..8c326097 100644 --- a/demos/src/Nodes/Blockquote/React/index.jsx +++ b/demos/src/Nodes/Blockquote/React/index.jsx @@ -8,13 +8,18 @@ import './styles.scss' export default () => { const editor = useEditor({ - extensions: [Document, Paragraph, Text, Blockquote], + extensions: [ + Document, + Paragraph, + Text, + Blockquote, + ], content: ` -
- Nothing is impossible, the word itself says “I’m possible!” -
-

Audrey Hepburn

- `, +
+ Nothing is impossible, the word itself says “I’m possible!” +
+

Audrey Hepburn

+ `, }) if (!editor) { @@ -31,13 +36,13 @@ export default () => { diff --git a/demos/src/Nodes/Blockquote/Vue/index.vue b/demos/src/Nodes/Blockquote/Vue/index.vue index 207ad5d1..7c173527 100644 --- a/demos/src/Nodes/Blockquote/Vue/index.vue +++ b/demos/src/Nodes/Blockquote/Vue/index.vue @@ -3,10 +3,10 @@ - - diff --git a/packages/core/src/commands/toggleWrap.ts b/packages/core/src/commands/toggleWrap.ts index 799a61e1..08693c15 100644 --- a/packages/core/src/commands/toggleWrap.ts +++ b/packages/core/src/commands/toggleWrap.ts @@ -1,4 +1,3 @@ -import { wrapIn, lift } from 'prosemirror-commands' import { NodeType } from 'prosemirror-model' import { RawCommands } from '../types' import { isNodeActive } from '../helpers/isNodeActive' @@ -15,13 +14,13 @@ declare module '@tiptap/core' { } } -export const toggleWrap: RawCommands['toggleWrap'] = (typeOrName, attributes = {}) => ({ state, dispatch }) => { +export const toggleWrap: RawCommands['toggleWrap'] = (typeOrName, attributes = {}) => ({ state, commands }) => { const type = getNodeType(typeOrName, state.schema) const isActive = isNodeActive(state, type, attributes) if (isActive) { - return lift(state, dispatch) + return commands.lift(type) } - return wrapIn(type, attributes)(state, dispatch) + return commands.wrapIn(type, attributes) } diff --git a/packages/core/src/commands/wrapIn.ts b/packages/core/src/commands/wrapIn.ts index f7d60fa5..ffcd227c 100644 --- a/packages/core/src/commands/wrapIn.ts +++ b/packages/core/src/commands/wrapIn.ts @@ -1,7 +1,6 @@ import { wrapIn as originalWrapIn } from 'prosemirror-commands' import { NodeType } from 'prosemirror-model' import { RawCommands } from '../types' -import { isNodeActive } from '../helpers/isNodeActive' import { getNodeType } from '../helpers/getNodeType' declare module '@tiptap/core' { @@ -17,11 +16,6 @@ declare module '@tiptap/core' { export const wrapIn: RawCommands['wrapIn'] = (typeOrName, attributes = {}) => ({ state, dispatch }) => { const type = getNodeType(typeOrName, state.schema) - const isActive = isNodeActive(state, type, attributes) - - if (isActive) { - return false - } return originalWrapIn(type, attributes)(state, dispatch) }