/** * Phase 3.1: Puck-Yjs Binding Utility * * Bidirectional binding between Puck data and Yjs. * Prevents sync loops by using Yjs transaction origins. */ import * as Y from 'yjs'; /** * PuckData structure (simplified for binding purposes) */ export interface PuckData { content: PuckComponentData[]; root: PuckRootData; zones?: Record; } interface PuckComponentData { type: string; props: Record; } interface PuckRootData { props: Record; } /** * Incrementally patch a Y.Map to match a plain object. * Only touches keys/values that actually differ, minimising Yjs operations * (and therefore the size of the update binary that is broadcast). */ export declare function patchYMap(ymap: Y.Map, newObj: Record): void; /** * Incrementally patch a Y.Array to match a plain array. * Component items are matched by `props.id`, so moving, inserting or removing * one component only touches that component. Arrays whose items lack a unique * `props.id` are patched by position. */ export declare function patchYArray(yarr: Y.Array, newArr: unknown[]): void; /** * Convert a Puck data structure to a Yjs Y.Map. * When the root map already has data, uses incremental patching to minimise * the number of Yjs operations (reducing flicker and broadcast size). * * @param data - The PuckData to convert * @param root - The Y.Map to populate */ export declare function puckDataToYMap(data: PuckData, root: Y.Map): void; /** * Convert a Yjs Y.Map to PuckData. * * @param root - The Y.Map containing Puck data * @returns The PuckData structure */ export declare function yMapToPuckData(root: Y.Map): PuckData; /** * Create a bidirectional binding between Puck data and a Y.Doc. * * Uses transaction origins to prevent sync loops: * - Local changes use 'local' origin and don't trigger onRemoteUpdate * - Remote changes (any other origin) trigger onRemoteUpdate * * @param ydoc - The Y.Doc to bind to * @param onRemoteUpdate - Callback when remote changes arrive * @returns Binding interface with applyLocalChange and destroy methods */ export declare function createPuckYjsBinding(ydoc: Y.Doc, onRemoteUpdate: (data: PuckData) => void): { applyLocalChange: (data: PuckData) => void; destroy: () => void; }; export {};