Skip to content

Commit

Permalink
Merge branch 'develop' into dependabot/github_actions/actions/cache-4…
Browse files Browse the repository at this point in the history
….1.1
  • Loading branch information
nperez0111 authored Oct 25, 2024
2 parents ba829d3 + f323e5b commit b2bbaae
Show file tree
Hide file tree
Showing 143 changed files with 1,106 additions and 561 deletions.
5 changes: 0 additions & 5 deletions .changeset/five-melons-compete.md

This file was deleted.

5 changes: 5 additions & 0 deletions .changeset/fresh-coats-relate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@tiptap/core": minor
---

Previously, only a json representation of the node could be inserted into the editor. This change allows for the insertion of Prosemirror `Node`s and `Fragment`s directly into the editor through the `insertContentAt`, `setContent` and `insertContent` commands.
5 changes: 5 additions & 0 deletions .changeset/funny-otters-protect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@tiptap/core": patch
---

Addresses a bug with `insertContentAt`'s `simulatedPasteRules` option where it could only accept text and not Prosemirror `Node` and `Content`
5 changes: 0 additions & 5 deletions .changeset/khaki-timers-jump.md

This file was deleted.

5 changes: 0 additions & 5 deletions .changeset/nervous-bats-film.md

This file was deleted.

5 changes: 0 additions & 5 deletions .changeset/slow-peaches-film.md

This file was deleted.

5 changes: 0 additions & 5 deletions .changeset/sweet-feet-dream.md

This file was deleted.

5 changes: 0 additions & 5 deletions .changeset/sweet-masks-smash.md

This file was deleted.

5 changes: 0 additions & 5 deletions .changeset/thirty-apes-boil.md

This file was deleted.

7 changes: 0 additions & 7 deletions .changeset/violet-cameras-brush.md

This file was deleted.

2 changes: 2 additions & 0 deletions demos/src/Commands/InsertContent/React/index.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import './styles.scss'

import { Color } from '@tiptap/extension-color'
import Link from '@tiptap/extension-link'
import ListItem from '@tiptap/extension-list-item'
import TextStyle from '@tiptap/extension-text-style'
import { EditorProvider, useCurrentEditor } from '@tiptap/react'
Expand Down Expand Up @@ -48,6 +49,7 @@ const MenuBar = () => {
const extensions = [
Color.configure({ types: [TextStyle.name, ListItem.name] }),
TextStyle.configure({ types: [ListItem.name] }),
Link,
StarterKit.configure({
bulletList: {
keepMarks: true,
Expand Down
26 changes: 25 additions & 1 deletion demos/src/Commands/InsertContent/React/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ context('/src/Commands/InsertContent/React/', () => {
cy.get('button[data-test-id="html-content"]').click()

// check if the content html is correct
cy.get('.tiptap').should('contain.html', '<h1>Tiptap</h1><p><strong>Hello World</strong></p><p>This is a paragraph<br>with a break.</p><p>And this is some additional string content.</p>')
cy.get('.tiptap').should('contain.html', '<h1><a target="_blank" rel="noopener noreferrer nofollow" href="https://tiptap.dev/">Tiptap</a></h1><p><strong>Hello World</strong></p><p>This is a paragraph<br>with a break.</p><p>And this is some additional string content.</p>')
})

it('should keep spaces inbetween tags in html content', () => {
Expand Down Expand Up @@ -91,4 +91,28 @@ context('/src/Commands/InsertContent/React/', () => {
})
})

it('should respect editor.options.parseOptions if defined to be `false`', () => {
cy.get('.tiptap').then(([{ editor }]) => {
editor.options.parseOptions = { preserveWhitespace: false }
editor.commands.insertContent('\n<h1>Tiptap</h1><p><strong>Hello\n World</strong>\n</p>\n')
cy.get('.tiptap').should('contain.html', '<h1>Tiptap</h1><p><strong>Hello World</strong></p>')
})
})

it('should respect editor.options.parseOptions if defined to be `full`', () => {
cy.get('.tiptap').then(([{ editor }]) => {
editor.options.parseOptions = { preserveWhitespace: 'full' }
editor.commands.insertContent('\n<h1>Tiptap</h1><p><strong>Hello\n World</strong>\n</p>\n')
cy.get('.tiptap').should('contain.html', '<h1>Tiptap</h1><p><strong>Hello\n World</strong></p>')
})
})

it('should respect editor.options.parseOptions if defined to be `true`', () => {
cy.get('.tiptap').then(([{ editor }]) => {
editor.options.parseOptions = { preserveWhitespace: true }
editor.commands.insertContent('<h1>Tiptap</h1><p><strong>Hello\n World</strong>\n</p>')
cy.get('.tiptap').should('contain.html', '<h1>Tiptap</h1><p><strong>Hello World</strong></p>')
})
})

})
21 changes: 21 additions & 0 deletions demos/src/Commands/SetContent/React/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,27 @@ context('/src/Commands/SetContent/React/', () => {
})
})

it('should insert raw JSON content', () => {
cy.get('.tiptap').then(([{ editor }]) => {
editor.commands.setContent({ type: 'paragraph', content: [{ type: 'text', text: 'Hello World.' }] })
cy.get('.tiptap').should('contain.html', '<p>Hello World.</p>')
})
})

it('should insert a Prosemirror Node as content', () => {
cy.get('.tiptap').then(([{ editor }]) => {
editor.commands.setContent(editor.schema.node('paragraph', null, editor.schema.text('Hello World.')))
cy.get('.tiptap').should('contain.html', '<p>Hello World.</p>')
})
})

it('should insert a Prosemirror Fragment as content', () => {
cy.get('.tiptap').then(([{ editor }]) => {
editor.commands.setContent(editor.schema.node('doc', null, editor.schema.node('paragraph', null, editor.schema.text('Hello World.'))).content)
cy.get('.tiptap').should('contain.html', '<p>Hello World.</p>')
})
})

it('should emit updates', () => {
cy.get('.tiptap').then(([{ editor }]) => {
let updateCount = 0
Expand Down
33 changes: 21 additions & 12 deletions demos/src/Demos/CollaborationSplitPane/React/Editor.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,19 +72,23 @@ const getRandomColor = () => getRandomElement(colors)
const getRandomName = () => getRandomElement(names)

const getInitialUser = () => {
return (
{
name: getRandomName(),
color: getRandomColor(),
}
)
return {
name: getRandomName(),
color: getRandomColor(),
}
}

const Editor = ({ ydoc, provider, room }) => {
const Editor = ({
ydoc, provider, room,
}) => {
const [status, setStatus] = useState('connecting')
const [currentUser, setCurrentUser] = useState(getInitialUser)

const editor = useEditor({
enableContentCheck: true,
onContentError: ({ disableCollaboration }) => {
disableCollaboration()
},
onCreate: ({ editor: currentEditor }) => {
provider.on('synced', () => {
if (currentEditor.isEmpty) {
Expand All @@ -99,13 +103,13 @@ const Editor = ({ ydoc, provider, room }) => {
Highlight,
TaskList,
TaskItem,
CharacterCount.configure({
CharacterCount.extend().configure({
limit: 10000,
}),
Collaboration.configure({
Collaboration.extend().configure({
document: ydoc,
}),
CollaborationCursor.configure({
CollaborationCursor.extend().configure({
provider,
}),
],
Expand Down Expand Up @@ -183,15 +187,20 @@ const Editor = ({ ydoc, provider, room }) => {

<EditorContent editor={editor} className="main-group" />

<div className="collab-status-group" data-state={status === 'connected' ? 'online' : 'offline'}>
<div
className="collab-status-group"
data-state={status === 'connected' ? 'online' : 'offline'}
>
<label>
{status === 'connected'
? `${editor.storage.collaborationCursor.users.length} user${
editor.storage.collaborationCursor.users.length === 1 ? '' : 's'
} online in ${room}`
: 'offline'}
</label>
<button style={{ '--color': currentUser.color }} onClick={setName}>{currentUser.name}</button>
<button style={{ '--color': currentUser.color }} onClick={setName}>
{currentUser.name}
</button>
</div>
</div>
)
Expand Down
2 changes: 1 addition & 1 deletion demos/src/Demos/CollaborationSplitPane/React/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const appId = '7j9y6m10'
const room = `room.${new Date()
.getFullYear()
.toString()
.slice(-2)}${new Date().getMonth() + 1}${new Date().getDate()}`
.slice(-2)}${new Date().getMonth() + 1}${new Date().getDate()}-ok`

// ydoc and provider for Editor A
const ydocA = new Y.Doc()
Expand Down
8 changes: 4 additions & 4 deletions demos/src/Examples/Transition/Vue/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,23 @@ context('/src/Examples/Transition/Vue/', () => {
it('should not have an active tiptap instance but a button', () => {
cy.get('.tiptap').should('not.exist')

cy.get('button').should('exist')
cy.get('#toggle-editor').should('exist')
})

it('clicking the button should show the editor', () => {
cy.get('button').click()
cy.get('#toggle-editor').click()

cy.get('.tiptap').should('exist')
cy.get('.tiptap').should('be.visible')
})

it('clicking the button again should hide the editor', () => {
cy.get('button').click()
cy.get('#toggle-editor').click()

cy.get('.tiptap').should('exist')
cy.get('.tiptap').should('be.visible')

cy.get('button').click()
cy.get('#toggle-editor').click()

cy.get('.tiptap').should('not.exist')
})
Expand Down
7 changes: 6 additions & 1 deletion demos/src/Examples/Transition/Vue/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,12 @@ const showEditor = ref(false)

<template>
<div>
<button type="button" @click="showEditor = !showEditor" style="margin-bottom: 1rem;">
<button
type="button"
@click="showEditor = !showEditor"
style="margin-bottom: 1rem;"
id="toggle-editor"
>
{{ showEditor ? 'Hide editor' : 'Show editor' }}
</button>

Expand Down
1 change: 0 additions & 1 deletion demos/src/Nodes/CodeBlockLowlight/React/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
.hljs-template-variable,
.hljs-attribute,
.hljs-tag,
.hljs-name,
.hljs-regexp,
.hljs-link,
.hljs-name,
Expand Down
Loading

0 comments on commit b2bbaae

Please sign in to comment.