Add GenerateText demo for React

This commit is contained in:
svenadlung 2021-11-16 20:28:31 +01:00
parent 152b0d328e
commit d6286e5d5c
3 changed files with 84 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("GuideContent/GenerateText", source);
</script>
</body>
</html>

View File

@ -0,0 +1,62 @@
import React, { useMemo } from 'react'
import { generateText } from '@tiptap/core'
import Document from '@tiptap/extension-document'
import Paragraph from '@tiptap/extension-paragraph'
import Text from '@tiptap/extension-text'
import HardBreak from '@tiptap/extension-hard-break'
const json = {
type: 'doc',
content: [
{
type: 'paragraph',
content: [
{
type: 'text',
text: 'This is a paragraph.',
},
],
},
{
type: 'paragraph',
content: [
{
type: 'text',
text: 'Here is another paragraph …',
},
{
type: 'hardBreak',
},
{
type: 'text',
text: '… with an hard break.',
},
],
},
],
}
export default () => {
const output = useMemo(() => {
return generateText(
json,
[
Document,
Paragraph,
Text,
HardBreak,
// other extensions
],
{
// define a custom block separator if you want to
blockSeparator: '\n\n',
},
)
}, [json])
return (
<pre>
<code>{output}</code>
</pre>
)
}

View File

@ -0,0 +1,7 @@
context('/src/GuideContent/GenerateText/React/', () => {
before(() => {
cy.visit('/src/GuideContent/GenerateText/React/')
})
// TODO: Write tests
})