mirror of
https://github.com/ueberdosis/tiptap.git
synced 2025-06-07 09:25:29 +08:00
Add HardBreak demo for React
This commit is contained in:
parent
b0f447236b
commit
5cc5965ec7
15
demos/src/Nodes/HardBreak/React/index.html
Normal file
15
demos/src/Nodes/HardBreak/React/index.html
Normal 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/HardBreak", source);
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
35
demos/src/Nodes/HardBreak/React/index.jsx
Normal file
35
demos/src/Nodes/HardBreak/React/index.jsx
Normal file
@ -0,0 +1,35 @@
|
||||
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 HardBreak from '@tiptap/extension-hard-break'
|
||||
|
||||
export default () => {
|
||||
const editor = useEditor({
|
||||
extensions: [Document, Paragraph, Text, HardBreak],
|
||||
content: `
|
||||
<p>
|
||||
This<br>
|
||||
is<br>
|
||||
a<br>
|
||||
single<br>
|
||||
paragraph<br>
|
||||
with<br>
|
||||
line<br>
|
||||
breaks.
|
||||
</p>
|
||||
`,
|
||||
})
|
||||
|
||||
if (!editor) {
|
||||
return null
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<button onClick={() => editor.chain().focus().setHardBreak().run()}>setHardBreak</button>
|
||||
<EditorContent editor={editor} />
|
||||
</>
|
||||
)
|
||||
}
|
49
demos/src/Nodes/HardBreak/React/index.spec.js
Normal file
49
demos/src/Nodes/HardBreak/React/index.spec.js
Normal file
@ -0,0 +1,49 @@
|
||||
context('/src/Nodes/HardBreak/React/', () => {
|
||||
before(() => {
|
||||
cy.visit('/src/Nodes/HardBreak/React/')
|
||||
})
|
||||
|
||||
beforeEach(() => {
|
||||
cy.get('.ProseMirror').then(([{ editor }]) => {
|
||||
editor.commands.setContent('<p>Example Text</p>')
|
||||
})
|
||||
})
|
||||
|
||||
it('should parse hard breaks correctly', () => {
|
||||
cy.get('.ProseMirror').then(([{ editor }]) => {
|
||||
editor.commands.setContent('<p>Example<br>Text</p>')
|
||||
expect(editor.getHTML()).to.eq('<p>Example<br>Text</p>')
|
||||
})
|
||||
})
|
||||
|
||||
it('should parse hard breaks with self-closing tag correctly', () => {
|
||||
cy.get('.ProseMirror').then(([{ editor }]) => {
|
||||
editor.commands.setContent('<p>Example<br />Text</p>')
|
||||
expect(editor.getHTML()).to.eq('<p>Example<br>Text</p>')
|
||||
})
|
||||
})
|
||||
|
||||
it('the button should add a line break', () => {
|
||||
cy.get('.ProseMirror br').should('not.exist')
|
||||
|
||||
cy.get('button:first').click()
|
||||
|
||||
cy.get('.ProseMirror br').should('exist')
|
||||
})
|
||||
|
||||
it('the default keyboard shortcut should add a line break', () => {
|
||||
cy.get('.ProseMirror br').should('not.exist')
|
||||
|
||||
cy.get('.ProseMirror').trigger('keydown', { shiftKey: true, key: 'Enter' })
|
||||
|
||||
cy.get('.ProseMirror br').should('exist')
|
||||
})
|
||||
|
||||
it('the alternative keyboard shortcut should add a line break', () => {
|
||||
cy.get('.ProseMirror br').should('not.exist')
|
||||
|
||||
cy.get('.ProseMirror').trigger('keydown', { modKey: true, key: 'Enter' })
|
||||
|
||||
cy.get('.ProseMirror br').should('exist')
|
||||
})
|
||||
})
|
Loading…
Reference in New Issue
Block a user