add (broken) focus example

This commit is contained in:
Hans Pagel
2020-08-19 18:12:36 +02:00
parent 0a6b2e0239
commit 6f0ddebe04
4 changed files with 102 additions and 1 deletions

View File

@@ -0,0 +1,13 @@
context('read-only', () => {
beforeEach(() => {
cy.visit('/examples/focus')
})
describe('editable', () => {
it('should have class', () => {
cy.get('.ProseMirror').window().then(window => {
cy.get('.ProseMirror p:first').should('have.class', 'has-focus')
})
})
})
})

View File

@@ -0,0 +1,82 @@
<template>
<div class="editor">
<editor-content :editor="editor" />
</div>
</template>
<script>
import { Editor, EditorContent } from '@tiptap/vue-starter-kit'
import Document from '@tiptap/extension-document'
import Paragraph from '@tiptap/extension-paragraph'
import Text from '@tiptap/extension-text'
import History from '@tiptap/extension-history'
import Bold from '@tiptap/extension-bold'
import Italic from '@tiptap/extension-italic'
import Code from '@tiptap/extension-code'
import CodeBlock from '@tiptap/extension-codeblock'
import Heading from '@tiptap/extension-heading'
// import Focus from '@tiptap/extension-focus'
export default {
components: {
EditorContent,
},
data() {
return {
editor: null,
}
},
mounted() {
this.editor = new Editor({
extensions: [
new Document(),
new History(),
new Paragraph(),
new Text(),
new Bold(),
new Italic(),
new Code(),
new CodeBlock(),
new Heading(),
// new Focus({
// className: 'has-focus',
// nested: true,
// }),
],
// autoFocus: true,
content: `
<p>
With the focus extension you can add custom classes to focused nodes. Default options:
</p>
<pre><code>{\n className: 'has-focus',\n nested: true,\n}</code></pre>
<ul>
<li>
When set <code>nested</code> to <code>true</code> also nested elements like this list item will be captured.
</li>
<li>
Otherwise only the wrapping list will get this class.
</li>
</ul>
`,
})
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,4 @@
.has-focus {
border-radius: 3px;
box-shadow: 0 0 0 3px #3ea4ffe6;
}

View File

@@ -1 +1,3 @@
# Focus
# Focus
<demo name="Focus" highlight="18,43-46,48" />