mirror of
https://github.com/oxynote/oxynote.git
synced 2026-10-17 10:59:20 +02:00
25 lines
631 B
TypeScript
25 lines
631 B
TypeScript
import type { Node as PMNode } from "@tiptap/pm/model"
|
|
import { MERMAID_BLOCK_NAME } from "./node-names"
|
|
|
|
// block types whose node view draws asynchronously after mounting.
|
|
const ASYNC_RENDER_BLOCK_NAMES: readonly string[] = [MERMAID_BLOCK_NAME]
|
|
|
|
// the uids of every asynchronously rendered block in a document, in
|
|
// document order
|
|
export function asyncRenderBlockUids(doc: PMNode): string[] {
|
|
const uids: string[] = []
|
|
|
|
doc.descendants((node) => {
|
|
const uid: unknown = node.attrs.uid
|
|
|
|
if (
|
|
ASYNC_RENDER_BLOCK_NAMES.includes(node.type.name) &&
|
|
typeof uid === "string"
|
|
) {
|
|
uids.push(uid)
|
|
}
|
|
})
|
|
|
|
return uids
|
|
}
|