import type { ReaderDocument, SourceBlock, } from "./documentTypes"; export const PRESS_TREE_MDX_SOURCE_TYPE = "openpress-press-tree-mdx"; export function isReactMdxDocument(document: Pick | null | undefined) { return document?.source?.type === PRESS_TREE_MDX_SOURCE_TYPE; } export function getSourceBlockMap( document: Pick | null | undefined, ): Record { if (!isReactMdxDocument(document)) return {}; const blockMap = document?.source?.blockMap; if (!blockMap || typeof blockMap !== "object") return {}; return blockMap; } export function getSourceBlock( document: Pick | null | undefined, blockId: string | null | undefined, ): SourceBlock | null { if (!blockId) return null; return getSourceBlockMap(document)[blockId] ?? null; }