fix toggle blockquotes

This commit is contained in:
Philipp Kühn
2018-10-10 15:08:37 +02:00
parent 27fa310937
commit fe210f68ed
3 changed files with 22 additions and 6 deletions

View File

@@ -0,0 +1,14 @@
import { wrapIn, lift } from 'prosemirror-commands'
import { nodeIsActive } from 'tiptap-utils'
export default function (type) {
return (state, dispatch, view) => {
const isActive = nodeIsActive(state, type)
if (isActive) {
return lift(state, dispatch)
}
return wrapIn(type)(state, dispatch, view)
}
}

View File

@@ -46,6 +46,7 @@ import setInlineBlockType from './commands/setInlineBlockType'
import splitToDefaultListItem from './commands/splitToDefaultListItem' import splitToDefaultListItem from './commands/splitToDefaultListItem'
import toggleBlockType from './commands/toggleBlockType' import toggleBlockType from './commands/toggleBlockType'
import toggleList from './commands/toggleList' import toggleList from './commands/toggleList'
import toggleWrap from './commands/toggleWrap'
import updateMark from './commands/updateMark' import updateMark from './commands/updateMark'
export { export {
@@ -95,5 +96,6 @@ export {
splitToDefaultListItem, splitToDefaultListItem,
toggleBlockType, toggleBlockType,
toggleList, toggleList,
toggleWrap,
updateMark, updateMark,
} }

View File

@@ -1,5 +1,5 @@
import { Node, Plugin } from 'tiptap' import { Node } from 'tiptap'
import { wrappingInputRule, wrapIn } from 'tiptap-commands' import { wrappingInputRule, toggleWrap } from 'tiptap-commands'
export default class BlockquoteNode extends Node { export default class BlockquoteNode extends Node {
@@ -9,7 +9,7 @@ export default class BlockquoteNode extends Node {
get schema() { get schema() {
return { return {
content: 'block+', content: 'block*',
group: 'block', group: 'block',
defining: true, defining: true,
draggable: false, draggable: false,
@@ -20,13 +20,13 @@ export default class BlockquoteNode extends Node {
} }
} }
command({ type }) { command({ type, schema }) {
return wrapIn(type) return toggleWrap(type, schema.nodes.paragraph)
} }
keys({ type }) { keys({ type }) {
return { return {
'Ctrl->': wrapIn(type), 'Ctrl->': toggleWrap(type),
} }
} }