From dcba6686dc9619ea90b109c372420bf6d462353f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20Ku=CC=88hn?= Date: Sun, 28 Oct 2018 21:59:08 +0100 Subject: [PATCH] add new commands to all extensions --- packages/tiptap-extensions/src/extensions/History.js | 1 - packages/tiptap-extensions/src/marks/Bold.js | 4 ++-- packages/tiptap-extensions/src/marks/Code.js | 4 ++-- packages/tiptap-extensions/src/marks/Italic.js | 4 ++-- packages/tiptap-extensions/src/marks/Link.js | 12 +++++++----- packages/tiptap-extensions/src/marks/Strike.js | 4 ++-- packages/tiptap-extensions/src/marks/Underline.js | 4 ++-- packages/tiptap-extensions/src/nodes/Blockquote.js | 4 ++-- packages/tiptap-extensions/src/nodes/BulletList.js | 4 ++-- packages/tiptap-extensions/src/nodes/CodeBlock.js | 4 ++-- .../src/nodes/CodeBlockHighlight.js | 4 ++-- packages/tiptap-extensions/src/nodes/Heading.js | 10 ++++------ packages/tiptap-extensions/src/nodes/Image.js | 4 ++-- packages/tiptap-extensions/src/nodes/OrderedList.js | 4 ++-- packages/tiptap-extensions/src/nodes/TodoList.js | 4 ++-- packages/tiptap/src/nodes/Paragraph.js | 4 ++-- 16 files changed, 37 insertions(+), 38 deletions(-) diff --git a/packages/tiptap-extensions/src/extensions/History.js b/packages/tiptap-extensions/src/extensions/History.js index 4afee336e..19a88d8a6 100644 --- a/packages/tiptap-extensions/src/extensions/History.js +++ b/packages/tiptap-extensions/src/extensions/History.js @@ -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 { diff --git a/packages/tiptap-extensions/src/marks/Bold.js b/packages/tiptap-extensions/src/marks/Bold.js index ae636d3df..50afd0172 100644 --- a/packages/tiptap-extensions/src/marks/Bold.js +++ b/packages/tiptap-extensions/src/marks/Bold.js @@ -32,8 +32,8 @@ export default class Bold extends Mark { } } - command({ type }) { - return toggleMark(type) + commands({ type }) { + return () => toggleMark(type) } inputRules({ type }) { diff --git a/packages/tiptap-extensions/src/marks/Code.js b/packages/tiptap-extensions/src/marks/Code.js index 4c245c4fb..a4a513b08 100644 --- a/packages/tiptap-extensions/src/marks/Code.js +++ b/packages/tiptap-extensions/src/marks/Code.js @@ -22,8 +22,8 @@ export default class Code extends Mark { } } - command({ type }) { - return toggleMark(type) + commands({ type }) { + return () => toggleMark(type) } inputRules({ type }) { diff --git a/packages/tiptap-extensions/src/marks/Italic.js b/packages/tiptap-extensions/src/marks/Italic.js index 542f91aef..6294a1916 100644 --- a/packages/tiptap-extensions/src/marks/Italic.js +++ b/packages/tiptap-extensions/src/marks/Italic.js @@ -24,8 +24,8 @@ export default class Italic extends Mark { } } - command({ type }) { - return toggleMark(type) + commands({ type }) { + return () => toggleMark(type) } inputRules({ type }) { diff --git a/packages/tiptap-extensions/src/marks/Link.js b/packages/tiptap-extensions/src/marks/Link.js index de973acb3..ceacd6ec6 100644 --- a/packages/tiptap-extensions/src/marks/Link.js +++ b/packages/tiptap-extensions/src/marks/Link.js @@ -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) + } } } diff --git a/packages/tiptap-extensions/src/marks/Strike.js b/packages/tiptap-extensions/src/marks/Strike.js index 537dc988e..784efa58e 100644 --- a/packages/tiptap-extensions/src/marks/Strike.js +++ b/packages/tiptap-extensions/src/marks/Strike.js @@ -34,8 +34,8 @@ export default class Strike extends Mark { } } - command({ type }) { - return toggleMark(type) + commands({ type }) { + return () => toggleMark(type) } inputRules({ type }) { diff --git a/packages/tiptap-extensions/src/marks/Underline.js b/packages/tiptap-extensions/src/marks/Underline.js index ca84e936c..aacfadf89 100644 --- a/packages/tiptap-extensions/src/marks/Underline.js +++ b/packages/tiptap-extensions/src/marks/Underline.js @@ -28,8 +28,8 @@ export default class Underline extends Mark { } } - command({ type }) { - return toggleMark(type) + commands({ type }) { + return () => toggleMark(type) } } diff --git a/packages/tiptap-extensions/src/nodes/Blockquote.js b/packages/tiptap-extensions/src/nodes/Blockquote.js index b4304cfcd..868155b63 100644 --- a/packages/tiptap-extensions/src/nodes/Blockquote.js +++ b/packages/tiptap-extensions/src/nodes/Blockquote.js @@ -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 }) { diff --git a/packages/tiptap-extensions/src/nodes/BulletList.js b/packages/tiptap-extensions/src/nodes/BulletList.js index 625bf0e1b..6ff0bfa57 100644 --- a/packages/tiptap-extensions/src/nodes/BulletList.js +++ b/packages/tiptap-extensions/src/nodes/BulletList.js @@ -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 }) { diff --git a/packages/tiptap-extensions/src/nodes/CodeBlock.js b/packages/tiptap-extensions/src/nodes/CodeBlock.js index cc9f2e3a9..ca7260e7b 100644 --- a/packages/tiptap-extensions/src/nodes/CodeBlock.js +++ b/packages/tiptap-extensions/src/nodes/CodeBlock.js @@ -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 }) { diff --git a/packages/tiptap-extensions/src/nodes/CodeBlockHighlight.js b/packages/tiptap-extensions/src/nodes/CodeBlockHighlight.js index 7c5ccd3b3..68b40eec6 100644 --- a/packages/tiptap-extensions/src/nodes/CodeBlockHighlight.js +++ b/packages/tiptap-extensions/src/nodes/CodeBlockHighlight.js @@ -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 }) { diff --git a/packages/tiptap-extensions/src/nodes/Heading.js b/packages/tiptap-extensions/src/nodes/Heading.js index 643e2bf3c..914d1d9ad 100644 --- a/packages/tiptap-extensions/src/nodes/Heading.js +++ b/packages/tiptap-extensions/src/nodes/Heading.js @@ -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 }), - ) - }) + )) } } diff --git a/packages/tiptap-extensions/src/nodes/Image.js b/packages/tiptap-extensions/src/nodes/Image.js index ef930e602..b8017ebd6 100644 --- a/packages/tiptap-extensions/src/nodes/Image.js +++ b/packages/tiptap-extensions/src/nodes/Image.js @@ -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) diff --git a/packages/tiptap-extensions/src/nodes/OrderedList.js b/packages/tiptap-extensions/src/nodes/OrderedList.js index 6de3a994e..deada26bb 100644 --- a/packages/tiptap-extensions/src/nodes/OrderedList.js +++ b/packages/tiptap-extensions/src/nodes/OrderedList.js @@ -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 }) { diff --git a/packages/tiptap-extensions/src/nodes/TodoList.js b/packages/tiptap-extensions/src/nodes/TodoList.js index d06d0472c..f844f5912 100644 --- a/packages/tiptap-extensions/src/nodes/TodoList.js +++ b/packages/tiptap-extensions/src/nodes/TodoList.js @@ -19,8 +19,8 @@ export default class TodoList extends Node { } } - command({ type }) { - return wrapInList(type) + commands({ type }) { + return () => wrapInList(type) } inputRules({ type }) { diff --git a/packages/tiptap/src/nodes/Paragraph.js b/packages/tiptap/src/nodes/Paragraph.js index e4aa59c37..4b6f03cd0 100644 --- a/packages/tiptap/src/nodes/Paragraph.js +++ b/packages/tiptap/src/nodes/Paragraph.js @@ -19,8 +19,8 @@ export default class Paragraph extends Node { } } - command({ type }) { - return setBlockType(type) + commands({ type }) { + return () => setBlockType(type) } }