mirror of
https://github.com/ueberdosis/tiptap.git
synced 2025-08-06 13:38:49 +08:00
add isNodeEmpty helper method
This commit is contained in:
parent
59b031c27c
commit
43320e51c7
@ -7,6 +7,7 @@ import getMarkAttributes from './helpers/getMarkAttributes'
|
||||
import isActive from './helpers/isActive'
|
||||
import removeElement from './utilities/removeElement'
|
||||
import getHTMLFromFragment from './helpers/getHTMLFromFragment'
|
||||
import isNodeEmpty from './helpers/isNodeEmpty'
|
||||
import createStyleTag from './utilities/createStyleTag'
|
||||
import CommandManager from './CommandManager'
|
||||
import ExtensionManager from './ExtensionManager'
|
||||
@ -415,11 +416,8 @@ export class Editor extends EventEmitter {
|
||||
/**
|
||||
* Check if there is no content.
|
||||
*/
|
||||
public isEmpty(): boolean {
|
||||
const defaultContent = this.state.doc.type.createAndFill()?.toJSON()
|
||||
const content = this.getJSON()
|
||||
|
||||
return JSON.stringify(defaultContent) === JSON.stringify(content)
|
||||
public get isEmpty(): boolean {
|
||||
return isNodeEmpty(this.state.doc)
|
||||
}
|
||||
|
||||
/**
|
||||
|
8
packages/core/src/helpers/isNodeEmpty.ts
Normal file
8
packages/core/src/helpers/isNodeEmpty.ts
Normal file
@ -0,0 +1,8 @@
|
||||
import { Node as ProseMirrorNode } from 'prosemirror-model'
|
||||
|
||||
export default function isNodeEmpty(node: ProseMirrorNode): boolean {
|
||||
const defaultContent = node.type.createAndFill()?.toJSON()
|
||||
const content = node.toJSON()
|
||||
|
||||
return JSON.stringify(defaultContent) === JSON.stringify(content)
|
||||
}
|
@ -18,6 +18,7 @@ export { default as getMarkAttributes } from './helpers/getMarkAttributes'
|
||||
export { default as isActive } from './helpers/isActive'
|
||||
export { default as isMarkActive } from './helpers/isMarkActive'
|
||||
export { default as isNodeActive } from './helpers/isNodeActive'
|
||||
export { default as isNodeEmpty } from './helpers/isNodeEmpty'
|
||||
export { default as isNodeSelection } from './helpers/isNodeSelection'
|
||||
export { default as isTextSelection } from './helpers/isTextSelection'
|
||||
export { default as findParentNodeClosestToPos } from './helpers/findParentNodeClosestToPos'
|
||||
|
Loading…
Reference in New Issue
Block a user