mirror of
https://github.com/ueberdosis/tiptap.git
synced 2025-01-18 06:03:22 +08:00
docs: add images example
This commit is contained in:
parent
8f4ae1fab1
commit
5fa89f3ea3
7
docs/src/demos/Examples/Images/index.spec.js
Normal file
7
docs/src/demos/Examples/Images/index.spec.js
Normal file
@ -0,0 +1,7 @@
|
||||
context('/demos/Examples/Images', () => {
|
||||
before(() => {
|
||||
cy.visit('/demos/Examples/Images')
|
||||
})
|
||||
|
||||
// TODO: Write tests
|
||||
})
|
79
docs/src/demos/Examples/Images/index.vue
Normal file
79
docs/src/demos/Examples/Images/index.vue
Normal file
@ -0,0 +1,79 @@
|
||||
<template>
|
||||
<div v-if="editor">
|
||||
<button @click="addImage">
|
||||
add image from URL
|
||||
</button>
|
||||
<editor-content :editor="editor" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { Editor } from '@tiptap/core'
|
||||
import { EditorContent } from '@tiptap/vue'
|
||||
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'
|
||||
|
||||
export default {
|
||||
components: {
|
||||
EditorContent,
|
||||
},
|
||||
|
||||
data() {
|
||||
return {
|
||||
editor: null,
|
||||
}
|
||||
},
|
||||
|
||||
methods: {
|
||||
addImage() {
|
||||
const url = window.prompt('URL')
|
||||
|
||||
if (url) {
|
||||
this.editor.chain().focus().setImage({ src: url }).run()
|
||||
}
|
||||
},
|
||||
},
|
||||
|
||||
mounted() {
|
||||
this.editor = new Editor({
|
||||
extensions: [
|
||||
Document,
|
||||
Paragraph,
|
||||
Text,
|
||||
Image,
|
||||
Dropcursor,
|
||||
],
|
||||
content: `
|
||||
<p>This is a basic example of implementing images. Drag to re-order.</p>
|
||||
<img src="https://source.unsplash.com/8xznAGy4HcY/800x400" />
|
||||
<img src="https://source.unsplash.com/K9QHL52rE2k/800x400" />
|
||||
`,
|
||||
})
|
||||
},
|
||||
|
||||
beforeDestroy() {
|
||||
this.editor.destroy()
|
||||
},
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss">
|
||||
/* Basic editor styles */
|
||||
.ProseMirror {
|
||||
> * + * {
|
||||
margin-top: 0.75em;
|
||||
}
|
||||
|
||||
img {
|
||||
max-width: 100%;
|
||||
height: auto;
|
||||
|
||||
&.ProseMirror-selectednode {
|
||||
outline: 3px solid #68CEF8;
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
@ -31,7 +31,9 @@ export default {
|
||||
addImage() {
|
||||
const url = window.prompt('URL')
|
||||
|
||||
this.editor.chain().focus().setImage({ src: url }).run()
|
||||
if (url) {
|
||||
this.editor.chain().focus().setImage({ src: url }).run()
|
||||
}
|
||||
},
|
||||
},
|
||||
|
||||
@ -68,6 +70,10 @@ export default {
|
||||
img {
|
||||
max-width: 100%;
|
||||
height: auto;
|
||||
|
||||
&.ProseMirror-selectednode {
|
||||
outline: 3px solid #68CEF8;
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
3
docs/src/docPages/examples/images.md
Normal file
3
docs/src/docPages/examples/images.md
Normal file
@ -0,0 +1,3 @@
|
||||
# Images
|
||||
|
||||
<demo name="Examples/Images" />
|
@ -43,6 +43,9 @@
|
||||
- title: Tables
|
||||
link: /examples/tables
|
||||
type: draft
|
||||
- title: Images
|
||||
link: /examples/images
|
||||
type: draft
|
||||
|
||||
- title: Guide
|
||||
items:
|
||||
|
Loading…
Reference in New Issue
Block a user