import type { Plugin } from "@puckeditor/core"; import type { PuckData } from "@pantheon-systems/css-client"; export interface DocumentSyncSnapshot { /** * Identity of the document this data actually *is* (`${branchId}:${documentId}`), * derived from the payload's own origin. It must never be built from the live * branchId: that flips the moment a switch starts, so it names the document * being requested rather than the one in hand, and publishing a new key beside * the outgoing branch's data made the canvas render a branch behind. */ syncKey: string | null; data: PuckData | null; } export interface DocumentSyncStore { publish(snapshot: DocumentSyncSnapshot): void; subscribe(onChange: VoidFunction): VoidFunction; getSnapshot(): DocumentSyncSnapshot; /** Records which document the Puck canvas currently shows */ markApplied(syncKey: string): void; /** Sync key of the document the canvas shows; BLANK_SYNC_KEY before the first */ getAppliedKey(): string; } /** * Applied key while Puck still shows the blank data it mounted with. * * A distinct sentinel rather than null because "no document yet" and "the * document Puck was mounted with" are different states, and conflating them * dropped the first real payload: Puck mounts with empty data and the branch is * restored from storage after mount, so the assumption that the first observed * document was already on the canvas never held. * * Contains no colon, so it can never collide with a documentSyncKey. */ export declare const BLANK_SYNC_KEY = "blank"; /** * Sync-key format for a loaded document. Shared so the publisher * (useP1Editor) and readers of the applied key (ContextSyncBridge, the * write-back guard) can never disagree about what identifies a document. */ export declare function documentSyncKey(branchId: string | null | undefined, documentId: string): string; /** * Guarantee a complete PuckData shape before handing data to Puck. Puck's * walkAppState reads data.root.props while rebuilding indexes, so a page whose * root or content hasn't settled yet (as can happen mid document-switch) would * otherwise crash with "Cannot read properties of undefined (reading 'props')". * Settled data passes through by reference unchanged; a non-object (a bug * upstream — data should already be parsed) collapses to a blank page rather * than being spread character-by-character. */ export declare function normalizeSyncData(data: PuckData): PuckData; export declare function createDocumentSyncStore(): DocumentSyncStore; export declare function createDocumentSyncPlugin(store: DocumentSyncStore): Plugin;