add extension demos

This commit is contained in:
Philipp Kühn
2021-08-25 18:03:42 +02:00
parent 6ab708b1a2
commit 88804668ff
44 changed files with 1695 additions and 1 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('Extensions/Color', source)
</script>
</body>
</html>

View File

@@ -0,0 +1,53 @@
context('/demos/Extensions/Color', () => {
before(() => {
cy.visit('/demos/Extensions/Color')
})
beforeEach(() => {
cy.get('.ProseMirror').then(([{ editor }]) => {
editor.commands.setContent('<p>Example Text</p>')
})
cy.get('.ProseMirror').type('{selectall}')
})
it('should set the color of the selected text', () => {
cy.get('button:first')
.should('not.have.class', 'is-active')
.click()
.should('have.class', 'is-active')
cy.get('.ProseMirror')
.find('span')
.should('have.attr', 'style', 'color: #958DF1')
})
it('should remove the color of the selected text', () => {
cy.get('button:first')
.click()
cy.get('.ProseMirror span').should('exist')
cy.get('button:last')
.click()
cy.get('.ProseMirror span').should('not.exist')
})
it('should change text color with color picker', () => {
cy.get('input[type=color]')
.invoke('val', '#ff0000')
.trigger('input')
cy.get('.ProseMirror')
.find('span')
.should('have.attr', 'style', 'color: #ff0000')
})
it('should match text and color picker color values', () => {
cy.get('button:first')
.click()
cy.get('input[type=color]')
.should('have.value', '#958df1')
})
})

View File

@@ -0,0 +1,75 @@
<template>
<div v-if="editor">
<input
type="color"
@input="editor.chain().focus().setColor($event.target.value).run()"
:value="editor.getAttributes('textStyle').color"
>
<button @click="editor.chain().focus().setColor('#958DF1').run()" :class="{ 'is-active': editor.isActive('textStyle', { color: '#958DF1' })}">
purple
</button>
<button @click="editor.chain().focus().setColor('#F98181').run()" :class="{ 'is-active': editor.isActive('textStyle', { color: '#F98181' })}">
red
</button>
<button @click="editor.chain().focus().setColor('#FBBC88').run()" :class="{ 'is-active': editor.isActive('textStyle', { color: '#FBBC88' })}">
orange
</button>
<button @click="editor.chain().focus().setColor('#FAF594').run()" :class="{ 'is-active': editor.isActive('textStyle', { color: '#FAF594' })}">
yellow
</button>
<button @click="editor.chain().focus().setColor('#70CFF8').run()" :class="{ 'is-active': editor.isActive('textStyle', { color: '#70CFF8' })}">
blue
</button>
<button @click="editor.chain().focus().setColor('#94FADB').run()" :class="{ 'is-active': editor.isActive('textStyle', { color: '#94FADB' })}">
teal
</button>
<button @click="editor.chain().focus().setColor('#B9F18D').run()" :class="{ 'is-active': editor.isActive('textStyle', { color: '#B9F18D' })}">
green
</button>
<button @click="editor.chain().focus().unsetColor().run()">
remove color
</button>
<editor-content :editor="editor" />
</div>
</template>
<script>
import { Editor, EditorContent } from '@tiptap/vue-3'
import Document from '@tiptap/extension-document'
import Paragraph from '@tiptap/extension-paragraph'
import Text from '@tiptap/extension-text'
import TextStyle from '@tiptap/extension-text-style'
import { Color } from '@tiptap/extension-color'
export default {
components: {
EditorContent,
},
data() {
return {
editor: null,
}
},
mounted() {
this.editor = new Editor({
extensions: [
Document,
Paragraph,
Text,
TextStyle,
Color,
],
content: `
<p><span style="color: #958DF1">Oh, for some reason thats purple.</span></p>
`,
})
},
beforeDestroy() {
this.editor.destroy()
},
}
</script>