/
githubmirror
/
halo
Обзор
Документация
Войти
/
githubmirror
/
halo
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
ui/packages/editor/src/utils/is-node-empty.ts
46 строк
994 B
Takagi
feat: refactor the drag function and add support for the drag menu (#7861)
30 окт 2025, 10:38
Не верифицирован
30 окт 2025, 10:38
0f8ef82
Код
Авторство
О чём код?
import type { Node } from "@tiptap/pm/model"; export const isEmpty = (node: Node) => { return isNodeDefault(node) || isNodeContentEmpty(node); }; export const isNodeDefault = (node: Node) => { const defaultContent = node.type.createAndFill()?.toJSON(); const content = node.toJSON(); return JSON.stringify(defaultContent) === JSON.stringify(content); }; export const isNodeContentEmpty = (node: Node) => { if (node.isTextblock) { return node.textContent.length === 0; } if (node.childCount === 0) { return true; } let allChildrenEmpty = true; node.forEach((child) => { if (!isEmpty(child)) { allChildrenEmpty = false; } }); return allChildrenEmpty; }; export const isParagraphEmpty = (node: Node) => { if (node.type.name !== "paragraph") { return false; } return node.textContent.length === 0; }; export const isBlockEmpty = (node: Node) => { if (!node.isTextblock) { return false; } return isParagraphEmpty(node); };