Add Document demo for React

This commit is contained in:
Sven Adlung
2021-11-16 14:47:03 +01:00
parent 7f16b142cb
commit b0f447236b
3 changed files with 61 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("Nodes/Document", source);
</script>
</body>
</html>

View File

@@ -0,0 +1,20 @@
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'
export default () => {
const editor = useEditor({
extensions: [Document, Paragraph, Text],
content: `
<p>The Document extension is required. Though, you can write your own implementation, e. g. to give it custom name.</p>
`,
})
if (!editor) {
return null
}
return <EditorContent editor={editor} />
}

View File

@@ -0,0 +1,26 @@
context('/src/Nodes/Document/React/', () => {
before(() => {
cy.visit('/src/Nodes/Document/React/')
})
beforeEach(() => {
cy.get('.ProseMirror').then(([{ editor }]) => {
editor.commands.setContent('<p></p>')
})
})
it('should return the document in as json', () => {
cy.get('.ProseMirror').then(([{ editor }]) => {
const json = editor.getJSON()
expect(json).to.deep.equal({
type: 'doc',
content: [
{
type: 'paragraph',
},
],
})
})
})
})