add GuideContent demos

This commit is contained in:
Philipp Kühn
2021-08-25 18:21:37 +02:00
parent b95c81baff
commit f99357b9a3
15 changed files with 674 additions and 0 deletions

View File

@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
</head>
<body>
<div id="app"></div>
<script type="module">
import setup from '../../../../setup/vue.ts'
import source from '@source'
setup('GuideContent/ReadOnly', source)
</script>
</body>
</html>

View File

@@ -0,0 +1,29 @@
context('/demos/Guide/Content/ReadOnly', () => {
before(() => {
cy.visit('/demos/Guide/Content/ReadOnly')
})
beforeEach(() => {
cy.get('.ProseMirror').then(([{ editor }]) => {
editor.commands.clearContent()
})
})
it('should be read-only', () => {
cy.get('.ProseMirror').then(([{ editor }]) => {
editor.setEditable(false)
cy.get('.ProseMirror').type('Edited: ')
cy.get('.ProseMirror p:first').should('not.contain', 'Edited: ')
})
})
it('should be editable', () => {
cy.get('.ProseMirror').then(([{ editor }]) => {
editor.setEditable(true)
cy.get('.ProseMirror').type('Edited: ')
cy.get('.ProseMirror p:first').should('contain', 'Edited: ')
})
})
})

View File

@@ -0,0 +1,76 @@
<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 } from '@tiptap/vue-3'
import StarterKit from '@tiptap/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>. No matter what you try, you are not able to edit something. Okay, if you toggle the checkbox above youll be able to edit the text.
</p>
<p>
If you want to check the state, you can call <code>editor.isEditable()</code>.
</p>
`,
extensions: [
StarterKit,
],
})
},
watch: {
editable() {
this.editor.setEditable(this.editable)
},
},
beforeDestroy() {
this.editor.destroy()
},
}
</script>
<style lang="scss">
/* Basic editor styles */
.ProseMirror {
> * + * {
margin-top: 0.75em;
}
}
.checkbox {
margin-bottom: 1rem;
input[type="checkbox"] {
margin-right: 0.5rem;
}
}
[contenteditable=false] {
color: #999;
cursor: not-allowed;
}
</style>