From ab4bfe4a8cdf17bd9b72d37404ef7d1785b44df4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20Ku=CC=88hn?= Date: Fri, 25 Jun 2021 11:53:37 +0200 Subject: [PATCH] add react demo for images --- .../src/demos/Examples/Images/React/index.jsx | 42 +++++++++++++++++++ .../demos/Examples/Images/React/styles.scss | 15 +++++++ .../demos/Examples/Images/Vue/index.spec.js | 7 ++++ .../demos/Examples/Images/{ => Vue}/index.vue | 0 docs/src/demos/Examples/Images/index.spec.js | 7 ---- docs/src/docPages/examples/images.md | 5 ++- 6 files changed, 68 insertions(+), 8 deletions(-) create mode 100644 docs/src/demos/Examples/Images/React/index.jsx create mode 100644 docs/src/demos/Examples/Images/React/styles.scss create mode 100644 docs/src/demos/Examples/Images/Vue/index.spec.js rename docs/src/demos/Examples/Images/{ => Vue}/index.vue (100%) delete mode 100644 docs/src/demos/Examples/Images/index.spec.js diff --git a/docs/src/demos/Examples/Images/React/index.jsx b/docs/src/demos/Examples/Images/React/index.jsx new file mode 100644 index 00000000..52dc8c31 --- /dev/null +++ b/docs/src/demos/Examples/Images/React/index.jsx @@ -0,0 +1,42 @@ +import React from 'react' +import { useEditor, EditorContent } from '@tiptap/react' +import Document from '@tiptap/extension-document' +import Paragraph from '@tiptap/extension-paragraph' +import Text from '@tiptap/extension-text' +import Image from '@tiptap/extension-image' +import Dropcursor from '@tiptap/extension-dropcursor' +import './styles.scss' + +export default () => { + const editor = useEditor({ + extensions: [ + Document, + Paragraph, + Text, + Image, + Dropcursor, + ], + content: ` +

This is a basic example of implementing images. Drag to re-order.

+ + + `, + }) + + const addImage = () => { + const url = window.prompt('URL') + + if (url) { + editor.chain().focus().setImage({ src: url }).run() + } + } + + return ( +
+ + +
+ ) +} diff --git a/docs/src/demos/Examples/Images/React/styles.scss b/docs/src/demos/Examples/Images/React/styles.scss new file mode 100644 index 00000000..3678b51a --- /dev/null +++ b/docs/src/demos/Examples/Images/React/styles.scss @@ -0,0 +1,15 @@ +/* Basic editor styles */ +.ProseMirror { + > * + * { + margin-top: 0.75em; + } + + img { + max-width: 100%; + height: auto; + + &.ProseMirror-selectednode { + outline: 3px solid #68CEF8; + } + } +} diff --git a/docs/src/demos/Examples/Images/Vue/index.spec.js b/docs/src/demos/Examples/Images/Vue/index.spec.js new file mode 100644 index 00000000..ef29c3f1 --- /dev/null +++ b/docs/src/demos/Examples/Images/Vue/index.spec.js @@ -0,0 +1,7 @@ +context('/demos/Examples/Vue', () => { + before(() => { + cy.visit('/demos/Examples/Vue') + }) + + // TODO: Write tests +}) diff --git a/docs/src/demos/Examples/Images/index.vue b/docs/src/demos/Examples/Images/Vue/index.vue similarity index 100% rename from docs/src/demos/Examples/Images/index.vue rename to docs/src/demos/Examples/Images/Vue/index.vue diff --git a/docs/src/demos/Examples/Images/index.spec.js b/docs/src/demos/Examples/Images/index.spec.js deleted file mode 100644 index 40cfc04b..00000000 --- a/docs/src/demos/Examples/Images/index.spec.js +++ /dev/null @@ -1,7 +0,0 @@ -context('/demos/Examples/Images', () => { - before(() => { - cy.visit('/demos/Examples/Images') - }) - - // TODO: Write tests -}) diff --git a/docs/src/docPages/examples/images.md b/docs/src/docPages/examples/images.md index 3855995a..a88117b5 100644 --- a/docs/src/docPages/examples/images.md +++ b/docs/src/docPages/examples/images.md @@ -8,4 +8,7 @@ Though thousands of developers use tiptap every day, it’s still not our full-t [Become a sponsor on GitHub →](https://github.com/sponsors/ueberdosis) ::: - +