mirror of
https://github.com/ueberdosis/tiptap.git
synced 2024-11-24 03:39:01 +08:00
parent
068559d0ac
commit
84ebd511d2
5
.changeset/cuddly-pants-destroy.md
Normal file
5
.changeset/cuddly-pants-destroy.md
Normal file
@ -0,0 +1,5 @@
|
||||
---
|
||||
"@tiptap/core": patch
|
||||
---
|
||||
|
||||
Fix change criteria for isNodeEmpty to resolve #5415
|
@ -12,12 +12,12 @@ export function isNodeEmpty(
|
||||
return !node.text
|
||||
}
|
||||
|
||||
if (node.content.childCount === 0) {
|
||||
return true
|
||||
if (node.isAtom || node.isLeaf) {
|
||||
return false
|
||||
}
|
||||
|
||||
if (node.isLeaf) {
|
||||
return false
|
||||
if (node.content.childCount === 0) {
|
||||
return true
|
||||
}
|
||||
|
||||
if (checkChildren) {
|
||||
|
@ -3,9 +3,10 @@
|
||||
import { getSchema, isNodeEmpty } from '@tiptap/core'
|
||||
import Document from '@tiptap/extension-document'
|
||||
import Image from '@tiptap/extension-image'
|
||||
import Mention from '@tiptap/extension-mention'
|
||||
import StarterKit from '@tiptap/starter-kit'
|
||||
|
||||
const schema = getSchema([StarterKit])
|
||||
const schema = getSchema([StarterKit, Mention])
|
||||
const modifiedSchema = getSchema([StarterKit.configure({ document: false }), Document.extend({ content: 'heading block*' })])
|
||||
const imageSchema = getSchema([StarterKit.configure({ document: false }), Document.extend({ content: 'image block*' }), Image])
|
||||
|
||||
@ -26,6 +27,30 @@ describe('isNodeEmpty', () => {
|
||||
expect(isNodeEmpty(node)).to.eq(false)
|
||||
})
|
||||
|
||||
it('should return false when a paragraph has hardbreaks', () => {
|
||||
const node = schema.nodeFromJSON({
|
||||
type: 'paragraph',
|
||||
content: [{ type: 'hardBreak' }],
|
||||
})
|
||||
|
||||
expect(isNodeEmpty(node)).to.eq(false)
|
||||
})
|
||||
|
||||
it('should return false when a paragraph has a mention', () => {
|
||||
const node = schema.nodeFromJSON({
|
||||
type: 'paragraph',
|
||||
content: [{
|
||||
type: 'mention',
|
||||
attrs: {
|
||||
id: 'Winona Ryder',
|
||||
label: null,
|
||||
},
|
||||
}],
|
||||
})
|
||||
|
||||
expect(isNodeEmpty(node)).to.eq(false)
|
||||
})
|
||||
|
||||
it('should return true when a paragraph has no content', () => {
|
||||
const node = schema.nodeFromJSON({
|
||||
type: 'paragraph',
|
||||
@ -177,7 +202,7 @@ describe('isNodeEmpty', () => {
|
||||
],
|
||||
})
|
||||
|
||||
expect(isNodeEmpty(node)).to.eq(true)
|
||||
expect(isNodeEmpty(node)).to.eq(false)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user