mirror of
https://github.com/ueberdosis/tiptap.git
synced 2024-11-27 23:15:15 +08:00
fix: don’t check for active node in wrapIn command, fix #1059
This commit is contained in:
parent
20876f7481
commit
170ec4be5b
@ -8,7 +8,12 @@ import './styles.scss'
|
|||||||
|
|
||||||
export default () => {
|
export default () => {
|
||||||
const editor = useEditor({
|
const editor = useEditor({
|
||||||
extensions: [Document, Paragraph, Text, Blockquote],
|
extensions: [
|
||||||
|
Document,
|
||||||
|
Paragraph,
|
||||||
|
Text,
|
||||||
|
Blockquote,
|
||||||
|
],
|
||||||
content: `
|
content: `
|
||||||
<blockquote>
|
<blockquote>
|
||||||
Nothing is impossible, the word itself says “I’m possible!”
|
Nothing is impossible, the word itself says “I’m possible!”
|
||||||
@ -31,13 +36,13 @@ export default () => {
|
|||||||
</button>
|
</button>
|
||||||
<button
|
<button
|
||||||
onClick={() => editor.chain().focus().setBlockquote().run()}
|
onClick={() => editor.chain().focus().setBlockquote().run()}
|
||||||
disabled={editor.isActive('blockquote')}
|
disabled={!editor.can().setBlockquote()}
|
||||||
>
|
>
|
||||||
setBlockquote
|
setBlockquote
|
||||||
</button>
|
</button>
|
||||||
<button
|
<button
|
||||||
onClick={() => editor.chain().focus().unsetBlockquote().run()}
|
onClick={() => editor.chain().focus().unsetBlockquote().run()}
|
||||||
disabled={!editor.isActive('blockquote')}
|
disabled={!editor.can().unsetBlockquote()}
|
||||||
>
|
>
|
||||||
unsetBlockquote
|
unsetBlockquote
|
||||||
</button>
|
</button>
|
||||||
|
@ -3,10 +3,10 @@
|
|||||||
<button @click="editor.chain().focus().toggleBlockquote().run()" :class="{ 'is-active': editor.isActive('blockquote') }">
|
<button @click="editor.chain().focus().toggleBlockquote().run()" :class="{ 'is-active': editor.isActive('blockquote') }">
|
||||||
toggleBlockquote
|
toggleBlockquote
|
||||||
</button>
|
</button>
|
||||||
<button @click="editor.chain().focus().setBlockquote().run()" :disabled="editor.isActive('blockquote')">
|
<button @click="editor.chain().focus().setBlockquote().run()" :disabled="!editor.can().setBlockquote()">
|
||||||
setBlockquote
|
setBlockquote
|
||||||
</button>
|
</button>
|
||||||
<button @click="editor.chain().focus().unsetBlockquote().run()" :disabled="!editor.isActive('blockquote')">
|
<button @click="editor.chain().focus().unsetBlockquote().run()" :disabled="!editor.can().unsetBlockquote()">
|
||||||
unsetBlockquote
|
unsetBlockquote
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
import { wrapIn, lift } from 'prosemirror-commands'
|
|
||||||
import { NodeType } from 'prosemirror-model'
|
import { NodeType } from 'prosemirror-model'
|
||||||
import { RawCommands } from '../types'
|
import { RawCommands } from '../types'
|
||||||
import { isNodeActive } from '../helpers/isNodeActive'
|
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 type = getNodeType(typeOrName, state.schema)
|
||||||
const isActive = isNodeActive(state, type, attributes)
|
const isActive = isNodeActive(state, type, attributes)
|
||||||
|
|
||||||
if (isActive) {
|
if (isActive) {
|
||||||
return lift(state, dispatch)
|
return commands.lift(type)
|
||||||
}
|
}
|
||||||
|
|
||||||
return wrapIn(type, attributes)(state, dispatch)
|
return commands.wrapIn(type, attributes)
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
import { wrapIn as originalWrapIn } from 'prosemirror-commands'
|
import { wrapIn as originalWrapIn } from 'prosemirror-commands'
|
||||||
import { NodeType } from 'prosemirror-model'
|
import { NodeType } from 'prosemirror-model'
|
||||||
import { RawCommands } from '../types'
|
import { RawCommands } from '../types'
|
||||||
import { isNodeActive } from '../helpers/isNodeActive'
|
|
||||||
import { getNodeType } from '../helpers/getNodeType'
|
import { getNodeType } from '../helpers/getNodeType'
|
||||||
|
|
||||||
declare module '@tiptap/core' {
|
declare module '@tiptap/core' {
|
||||||
@ -17,11 +16,6 @@ declare module '@tiptap/core' {
|
|||||||
|
|
||||||
export const wrapIn: RawCommands['wrapIn'] = (typeOrName, attributes = {}) => ({ state, dispatch }) => {
|
export const wrapIn: RawCommands['wrapIn'] = (typeOrName, attributes = {}) => ({ state, dispatch }) => {
|
||||||
const type = getNodeType(typeOrName, state.schema)
|
const type = getNodeType(typeOrName, state.schema)
|
||||||
const isActive = isNodeActive(state, type, attributes)
|
|
||||||
|
|
||||||
if (isActive) {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
return originalWrapIn(type, attributes)(state, dispatch)
|
return originalWrapIn(type, attributes)(state, dispatch)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user