move examples to own directory, add demo component to all example pages

This commit is contained in:
Hans Pagel
2020-08-20 17:31:27 +02:00
parent f13212b362
commit 854a0382b6
30 changed files with 57 additions and 21 deletions

View File

@@ -0,0 +1,29 @@
context('read-only', () => {
beforeEach(() => {
cy.visit('/examples/read-only')
})
describe('editable', () => {
it('should be read-only', () => {
cy.get('.ProseMirror').window().then(window => {
cy.get('#editable').uncheck()
const { editor } = window
editor.insertText('Edited: ')
cy.get('.ProseMirror p:first').should('not.contain', 'Edited: ')
})
})
it('should be editable', () => {
cy.get('.ProseMirror').window().then(window => {
cy.get('#editable').check()
const { editor } = window
editor.insertText('Edited: ')
cy.get('.ProseMirror p:first').should('contain', 'Edited: ')
})
})
})
})

View File

@@ -0,0 +1,54 @@
<template>
<div class="editor">
<div class="checkbox">
<input type="checkbox" id="editable" v-model="editable" />
<label for="editable">editable</label>
</div>
<editor-content :editor="editor" />
</div>
</template>
<script>
import { Editor, EditorContent, defaultExtensions } from '@tiptap/vue-starter-kit'
export default {
components: {
EditorContent,
},
data() {
return {
editor: null,
editable: false,
}
},
mounted() {
this.editor = new Editor({
editable: this.editable,
content: `
<p>
This text is <strong>read-only</strong>. You are not able to edit something. <a href="https://ueber.io/">Links to fancy websites</a> are still working.
</p>
`,
extensions: defaultExtensions(),
})
window.editor = this.editor
},
watch: {
editable() {
this.editor.setOptions({
editable: this.editable,
})
},
},
beforeDestroy() {
this.editor.destroy()
},
}
</script>
<style lang="scss" src="./style.scss">

View File

@@ -0,0 +1,7 @@
.checkbox {
margin-bottom: 1rem;
input[type="checkbox"] {
margin-right: 0.5rem;
}
}