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 { Extension } from 'tiptap'
import { history, undo, redo } from 'prosemirror-history' import { history, undo, redo } from 'prosemirror-history'
import { setBlockType, textblockTypeInputRule, toggleBlockType } from 'tiptap-commands'
export default class History extends Extension { export default class History extends Extension {

View File

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

View File

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

View File

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

View File

@ -30,12 +30,14 @@ export default class Link extends Mark {
} }
} }
command({ type, attrs }) { commands({ type }) {
if (attrs.href) { return attrs => {
return updateMark(type, 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 }) { commands({ type }) {
return toggleMark(type) return () => toggleMark(type)
} }
inputRules({ type }) { inputRules({ type }) {

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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