add new commands to all extensions

This commit is contained in:
Philipp Kühn 2018-10-28 21:59:08 +01:00
parent d2519c2953
commit dcba6686dc
16 changed files with 37 additions and 38 deletions

View File

@ -1,6 +1,5 @@
import { Extension } from 'tiptap'
import { history, undo, redo } from 'prosemirror-history'
import { setBlockType, textblockTypeInputRule, toggleBlockType } from 'tiptap-commands'
export default class History extends Extension {

View File

@ -32,8 +32,8 @@ export default class Bold extends Mark {
}
}
command({ type }) {
return toggleMark(type)
commands({ type }) {
return () => toggleMark(type)
}
inputRules({ type }) {

View File

@ -22,8 +22,8 @@ export default class Code extends Mark {
}
}
command({ type }) {
return toggleMark(type)
commands({ type }) {
return () => toggleMark(type)
}
inputRules({ type }) {

View File

@ -24,8 +24,8 @@ export default class Italic extends Mark {
}
}
command({ type }) {
return toggleMark(type)
commands({ type }) {
return () => toggleMark(type)
}
inputRules({ type }) {

View File

@ -30,12 +30,14 @@ export default class Link extends Mark {
}
}
command({ type, attrs }) {
if (attrs.href) {
return updateMark(type, attrs)
}
commands({ type }) {
return attrs => {
if (attrs.href) {
return updateMark(type, attrs)
}
return removeMark(type)
return removeMark(type)
}
}
}

View File

@ -34,8 +34,8 @@ export default class Strike extends Mark {
}
}
command({ type }) {
return toggleMark(type)
commands({ type }) {
return () => toggleMark(type)
}
inputRules({ type }) {

View File

@ -28,8 +28,8 @@ export default class Underline extends Mark {
}
}
command({ type }) {
return toggleMark(type)
commands({ type }) {
return () => toggleMark(type)
}
}

View File

@ -20,8 +20,8 @@ export default class Blockquote extends Node {
}
}
command({ type, schema }) {
return toggleWrap(type, schema.nodes.paragraph)
commands({ type, schema }) {
return () => toggleWrap(type, schema.nodes.paragraph)
}
keys({ type }) {

View File

@ -18,8 +18,8 @@ export default class Bullet extends Node {
}
}
command({ type, schema }) {
return toggleList(type, schema.nodes.list_item)
commands({ type, schema }) {
return () => toggleList(type, schema.nodes.list_item)
}
keys({ type, schema }) {

View File

@ -22,8 +22,8 @@ export default class CodeBlock extends Node {
}
}
command({ type, schema }) {
return toggleBlockType(type, schema.nodes.paragraph)
commands({ type, schema }) {
return () => toggleBlockType(type, schema.nodes.paragraph)
}
keys({ type }) {

View File

@ -99,8 +99,8 @@ export default class CodeBlockHighlight extends Node {
}
}
command({ type, schema }) {
return toggleBlockType(type, schema.nodes.paragraph)
commands({ type, schema }) {
return () => toggleBlockType(type, schema.nodes.paragraph)
}
keys({ type }) {

View File

@ -33,8 +33,8 @@ export default class Heading extends Node {
}
}
command({ type, schema, attrs }) {
return toggleBlockType(type, schema.nodes.paragraph, attrs)
commands({ type, schema }) {
return attrs => toggleBlockType(type, schema.nodes.paragraph, attrs)
}
keys({ type }) {
@ -47,13 +47,11 @@ export default class Heading extends Node {
}
inputRules({ type }) {
return this.options.levels.map(level => {
return textblockTypeInputRule(
return this.options.levels.map(level => textblockTypeInputRule(
new RegExp(`^(#{1,${level}})\\s$`),
type,
match => ({ level }),
)
})
))
}
}

View File

@ -34,8 +34,8 @@ export default class Image extends Node {
}
}
command({ type, attrs }) {
return (state, dispatch) => {
commands({ type }) {
return attrs => (state, dispatch) => {
const { selection } = state
const position = selection.$cursor ? selection.$cursor.pos : selection.$to.pos
const node = type.create(attrs)

View File

@ -28,8 +28,8 @@ export default class OrderedList extends Node {
}
}
command({ type, schema }) {
return toggleList(type, schema.nodes.list_item)
commands({ type, schema }) {
return () => toggleList(type, schema.nodes.list_item)
}
keys({ type, schema }) {

View File

@ -19,8 +19,8 @@ export default class TodoList extends Node {
}
}
command({ type }) {
return wrapInList(type)
commands({ type }) {
return () => wrapInList(type)
}
inputRules({ type }) {

View File

@ -19,8 +19,8 @@ export default class Paragraph extends Node {
}
}
command({ type }) {
return setBlockType(type)
commands({ type }) {
return () => setBlockType(type)
}
}