ultisuite-client/lib/drive/richtext-content.ts
R3D347HR4Y 8e420509a8
Some checks are pending
E2E / Playwright e2e (push) Waiting to run
imports docx 1
2026-06-10 00:27:44 +02:00

26 lines
759 B
TypeScript

type TipTapNode = {
type?: string
text?: string
content?: TipTapNode[]
}
/** True when TipTap JSON has no meaningful text (blank doc / empty paragraph). */
export function isEmptyTipTapDoc(content: Record<string, unknown> | null | undefined): boolean {
if (!content) return true
return !tipTapNodeHasText(content as TipTapNode)
}
function tipTapNodeHasText(node: TipTapNode | TipTapNode[] | null | undefined): boolean {
if (!node) return false
if (Array.isArray(node)) {
return node.some((child) => tipTapNodeHasText(child))
}
if (typeof node.text === "string" && node.text.trim() !== "") {
return true
}
if (Array.isArray(node.content)) {
return node.content.some((child) => tipTapNodeHasText(child))
}
return false
}