Add BulletList demo for React
This commit is contained in:
15
demos/src/Nodes/BulletList/React/index.html
Normal file
15
demos/src/Nodes/BulletList/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/BulletList", source);
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
55
demos/src/Nodes/BulletList/React/index.jsx
Normal file
55
demos/src/Nodes/BulletList/React/index.jsx
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
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 BulletList from '@tiptap/extension-bullet-list'
|
||||||
|
import ListItem from '@tiptap/extension-list-item'
|
||||||
|
import './styles.scss'
|
||||||
|
|
||||||
|
export default () => {
|
||||||
|
const editor = useEditor({
|
||||||
|
extensions: [Document, Paragraph, Text, BulletList, ListItem],
|
||||||
|
content: `
|
||||||
|
<ul>
|
||||||
|
<li>A list item</li>
|
||||||
|
<li>And another one</li>
|
||||||
|
</ul>
|
||||||
|
`,
|
||||||
|
})
|
||||||
|
|
||||||
|
if (!editor) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<button
|
||||||
|
onClick={() => editor.chain().focus().toggleBulletList().run()}
|
||||||
|
className={editor.isActive('bulletList') ? 'is-active' : ''}
|
||||||
|
>
|
||||||
|
toggleBulletList
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
onClick={() => editor.chain().focus().splitListItem('listItem').run()}
|
||||||
|
disabled={!editor.can().splitListItem('listItem')}
|
||||||
|
>
|
||||||
|
splitListItem
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
onClick={() => editor.chain().focus().sinkListItem('listItem').run()}
|
||||||
|
disabled={!editor.can().sinkListItem('listItem')}
|
||||||
|
>
|
||||||
|
sinkListItem
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
onClick={() => editor.chain().focus().liftListItem('listItem').run()}
|
||||||
|
disabled={!editor.can().liftListItem('listItem')}
|
||||||
|
>
|
||||||
|
liftListItem
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<EditorContent editor={editor} />
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
||||||
115
demos/src/Nodes/BulletList/React/index.spec.js
Normal file
115
demos/src/Nodes/BulletList/React/index.spec.js
Normal file
@@ -0,0 +1,115 @@
|
|||||||
|
context('/src/Nodes/BulletList/React/', () => {
|
||||||
|
before(() => {
|
||||||
|
cy.visit('/src/Nodes/BulletList/React/')
|
||||||
|
})
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
cy.get('.ProseMirror').then(([{ editor }]) => {
|
||||||
|
editor.commands.setContent('<p>Example Text</p>')
|
||||||
|
cy.get('.ProseMirror').type('{selectall}')
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should parse unordered lists correctly', () => {
|
||||||
|
cy.get('.ProseMirror').then(([{ editor }]) => {
|
||||||
|
editor.commands.setContent('<ul><li><p>Example Text</p></li></ul>')
|
||||||
|
expect(editor.getHTML()).to.eq('<ul><li><p>Example Text</p></li></ul>')
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should parse unordered lists without paragraphs correctly', () => {
|
||||||
|
cy.get('.ProseMirror').then(([{ editor }]) => {
|
||||||
|
editor.commands.setContent('<ul><li>Example Text</li></ul>')
|
||||||
|
expect(editor.getHTML()).to.eq('<ul><li><p>Example Text</p></li></ul>')
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
it('the button should make the selected line a bullet list item', () => {
|
||||||
|
cy.get('.ProseMirror ul').should('not.exist')
|
||||||
|
|
||||||
|
cy.get('.ProseMirror ul li').should('not.exist')
|
||||||
|
|
||||||
|
cy.get('button:nth-child(1)').click()
|
||||||
|
|
||||||
|
cy.get('.ProseMirror').find('ul').should('contain', 'Example Text')
|
||||||
|
|
||||||
|
cy.get('.ProseMirror').find('ul li').should('contain', 'Example Text')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('the button should toggle the bullet list', () => {
|
||||||
|
cy.get('.ProseMirror ul').should('not.exist')
|
||||||
|
|
||||||
|
cy.get('button:nth-child(1)').click()
|
||||||
|
|
||||||
|
cy.get('.ProseMirror').find('ul').should('contain', 'Example Text')
|
||||||
|
|
||||||
|
cy.get('button:nth-child(1)').click()
|
||||||
|
|
||||||
|
cy.get('.ProseMirror ul').should('not.exist')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should leave the list with double enter', () => {
|
||||||
|
cy.get('.ProseMirror').then(([{ editor }]) => {
|
||||||
|
editor.commands.clearContent()
|
||||||
|
})
|
||||||
|
|
||||||
|
cy.get('.ProseMirror').type('- List Item 1{enter}{enter}Paragraph')
|
||||||
|
|
||||||
|
cy.get('.ProseMirror').find('li').its('length').should('eq', 1)
|
||||||
|
|
||||||
|
cy.get('.ProseMirror').find('p').should('contain', 'Paragraph')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should make the paragraph a bullet list keyboard shortcut is pressed', () => {
|
||||||
|
cy.get('.ProseMirror')
|
||||||
|
.trigger('keydown', { modKey: true, shiftKey: true, key: '8' })
|
||||||
|
.find('ul li')
|
||||||
|
.should('contain', 'Example Text')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should make a bullet list from an asterisk', () => {
|
||||||
|
cy.get('.ProseMirror').then(([{ editor }]) => {
|
||||||
|
editor.commands.clearContent()
|
||||||
|
})
|
||||||
|
|
||||||
|
cy.get('.ProseMirror').type('* List Item 1{enter}List Item 2')
|
||||||
|
|
||||||
|
cy.get('.ProseMirror').find('li:nth-child(1)').should('contain', 'List Item 1')
|
||||||
|
|
||||||
|
cy.get('.ProseMirror').find('li:nth-child(2)').should('contain', 'List Item 2')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should make a bullet list from a dash', () => {
|
||||||
|
cy.get('.ProseMirror').then(([{ editor }]) => {
|
||||||
|
editor.commands.clearContent()
|
||||||
|
})
|
||||||
|
|
||||||
|
cy.get('.ProseMirror').type('- List Item 1{enter}List Item 2')
|
||||||
|
|
||||||
|
cy.get('.ProseMirror').find('li:nth-child(1)').should('contain', 'List Item 1')
|
||||||
|
|
||||||
|
cy.get('.ProseMirror').find('li:nth-child(2)').should('contain', 'List Item 2')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should make a bullet list from a plus', () => {
|
||||||
|
cy.get('.ProseMirror').then(([{ editor }]) => {
|
||||||
|
editor.commands.clearContent()
|
||||||
|
})
|
||||||
|
|
||||||
|
cy.get('.ProseMirror').type('+ List Item 1{enter}List Item 2')
|
||||||
|
|
||||||
|
cy.get('.ProseMirror').find('li:nth-child(1)').should('contain', 'List Item 1')
|
||||||
|
|
||||||
|
cy.get('.ProseMirror').find('li:nth-child(2)').should('contain', 'List Item 2')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should remove the bullet list after pressing backspace', () => {
|
||||||
|
cy.get('.ProseMirror').then(([{ editor }]) => {
|
||||||
|
editor.commands.clearContent()
|
||||||
|
})
|
||||||
|
|
||||||
|
cy.get('.ProseMirror').type('* {backspace}Example')
|
||||||
|
|
||||||
|
cy.get('.ProseMirror').find('p').should('contain', '* Example')
|
||||||
|
})
|
||||||
|
})
|
||||||
11
demos/src/Nodes/BulletList/React/styles.scss
Normal file
11
demos/src/Nodes/BulletList/React/styles.scss
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
/* Basic editor styles */
|
||||||
|
.ProseMirror {
|
||||||
|
> * + * {
|
||||||
|
margin-top: 0.75em;
|
||||||
|
}
|
||||||
|
|
||||||
|
ul,
|
||||||
|
ol {
|
||||||
|
padding: 0 1rem;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user