Add Superscript demo for React

This commit is contained in:
svenadlung 2021-11-16 17:46:15 +01:00
parent 6ccbf8c7cb
commit 61603c8323
3 changed files with 100 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/react.ts";
import source from "@source";
setup("Marks/Superscript", source);
</script>
</body>
</html>

View File

@ -0,0 +1,46 @@
import React from 'react'
import { useEditor, EditorContent } from '@tiptap/react'
import Document from '@tiptap/extension-document'
import Paragraph from '@tiptap/extension-paragraph'
import Text from '@tiptap/extension-text'
import Superscript from '@tiptap/extension-superscript'
export default () => {
const editor = useEditor({
extensions: [Document, Paragraph, Text, Superscript],
content: `
<p>This is regular text.</p>
<p><sup>This is superscript.</sup></p>
<p><span style="vertical-align: super">And this.</span></p>
`,
})
if (!editor) {
return null
}
return (
<>
<button
onClick={() => editor.chain().focus().toggleSuperscript().run()}
className={editor.isActive('superscript') ? 'is-active' : ''}
>
toggleSuperscript
</button>
<button
onClick={() => editor.chain().focus().setSuperscript().run()}
disabled={editor.isActive('superscript')}
>
setSuperscript
</button>
<button
onClick={() => editor.chain().focus().unsetSuperscript().run()}
disabled={!editor.isActive('superscript')}
>
unsetSuperscript
</button>
<EditorContent editor={editor} />
</>
)
}

View File

@ -0,0 +1,39 @@
context('/src/Marks/Superscript/React/', () => {
before(() => {
cy.visit('/src/Marks/Superscript/React/')
})
beforeEach(() => {
cy.get('.ProseMirror').then(([{ editor }]) => {
editor.commands.setContent('<p>Example Text</p>')
cy.get('.ProseMirror').type('{selectall}')
})
})
it('should transform inline style to sup tags', () => {
cy.get('.ProseMirror').then(([{ editor }]) => {
editor.commands.setContent('<p><span style="vertical-align: super">Example Text</span></p>')
expect(editor.getHTML()).to.eq('<p><sup>Example Text</sup></p>')
})
})
it('sould omit inline style with a different vertical align', () => {
cy.get('.ProseMirror').then(([{ editor }]) => {
editor.commands.setContent('<p><span style="vertical-align: middle">Example Text</span></p>')
expect(editor.getHTML()).to.eq('<p>Example Text</p>')
})
})
it('the button should make the selected text bold', () => {
cy.get('button:first').click()
cy.get('.ProseMirror').find('sup').should('contain', 'Example Text')
})
it('the button should toggle the selected text bold', () => {
cy.get('button:first').click()
cy.get('.ProseMirror').type('{selectall}')
cy.get('button:first').click()
cy.get('.ProseMirror sup').should('not.exist')
})
})