From efdf45de4c5c1c39ba67ad08f1b138f54ee7c0ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20Ku=CC=88hn?= Date: Sat, 29 Sep 2018 22:49:38 +0200 Subject: [PATCH] add command for adding images --- examples/Components/Routes/Images/index.vue | 23 +++++++++++++++++++ examples/assets/images/icons/image.svg | 1 + packages/tiptap-extensions/src/nodes/Image.js | 10 ++++++++ 3 files changed, 34 insertions(+) create mode 100644 examples/assets/images/icons/image.svg diff --git a/examples/Components/Routes/Images/index.vue b/examples/Components/Routes/Images/index.vue index 58300586..648d735c 100644 --- a/examples/Components/Routes/Images/index.vue +++ b/examples/Components/Routes/Images/index.vue @@ -2,6 +2,19 @@
+ +

Images @@ -17,6 +30,7 @@ \ No newline at end of file diff --git a/examples/assets/images/icons/image.svg b/examples/assets/images/icons/image.svg new file mode 100644 index 00000000..8e1a8f4f --- /dev/null +++ b/examples/assets/images/icons/image.svg @@ -0,0 +1 @@ +paginate-filter-picture-alternate \ No newline at end of file diff --git a/packages/tiptap-extensions/src/nodes/Image.js b/packages/tiptap-extensions/src/nodes/Image.js index e01fcb53..59bf4fed 100644 --- a/packages/tiptap-extensions/src/nodes/Image.js +++ b/packages/tiptap-extensions/src/nodes/Image.js @@ -34,6 +34,16 @@ export default class ImageNode extends Node { } } + command({ type, attrs }) { + return (state, dispatch) => { + const { selection } = state + const position = selection.$cursor ? selection.$cursor.pos : selection.$to.pos + const node = type.create(attrs) + const transaction = state.tr.insert(position, node) + dispatch(transaction) + } + } + get plugins() { return [ new Plugin({