/** * Sanity Portable Text <-> the pivot document. * * Portable Text is a *flat* array. A nested list is not a tree: it is a run of * sibling blocks that each declare `listItem` and a `level`, and the nesting * only exists once a renderer groups them. A multi-paragraph quote is likewise * several blocks that happen to share `style: "blockquote"`. Both are rebuilt * into real trees on the way in and flattened again on the way out. * * Two things about the format make a lossless round trip possible, and both are * relied on here: * * - Every block, span and annotation carries a `_key`. Those keys are how the * Sanity dataset addresses content, so they are carried through the pivot * (`attrs._key`) and written back rather than regenerated. * - An unrecognised `_type` is just data. A block this converter does not know * is not an error and must not be dropped; it rides through as * `avocadoUnknownBlock` and comes back out byte-identical. */ import { type RichTextDoc } from "./doc.ts"; export type PortableTextSpan = { _type: string; _key?: string; text?: string; marks?: string[]; [key: string]: unknown; }; export type PortableTextMarkDef = { _type: string; _key: string; [key: string]: unknown; }; export type PortableTextBlock = { _type: string; _key?: string; style?: string; listItem?: string; level?: number; children?: PortableTextSpan[]; markDefs?: PortableTextMarkDef[]; [key: string]: unknown; }; /** Convert an array of Portable Text blocks into the pivot document. */ export declare function fromPortableText(blocks: unknown): RichTextDoc; export type ToPortableTextOptions = { /** * The blocks currently stored for this field. * * Supplying them is what turns a write into an update: an unchanged block is * re-emitted as the stored object itself, keys and unrecognised fields * included, so the CMS sees a diff of what actually changed. */ previous?: unknown; /** Prefix for generated `_key`s. Only used where no stored key exists. */ keyPrefix?: string; }; /** Convert the pivot document back to an array of Portable Text blocks. */ export declare function toPortableText(doc: RichTextDoc, options?: ToPortableTextOptions): PortableTextBlock[];