UNPKG

@datalayer/lexical-loro

Version:

Collaborative editing solution for Lexical based on Loro CRDT

40 lines (39 loc) 1.3 kB
import { type LexicalEditor } from 'lexical'; /** * DiffMerge System for Lexical Editor * * This module provides sophisticated differential updates for Lexical editor states, * preventing wholesale state replacement that would destroy React decorator nodes * like YouTube embeds, counters, and other custom components. * * Key Features: * - Selective node updates (only changed content) * - Decorator node preservation (YouTube, Counter nodes remain untouched) * - Table structure support with cell-level updates * - Graceful fallback for unsupported operations * - Deep content comparison to minimize unnecessary updates * * Usage: * ```typescript * const success = applyDifferentialUpdate(editor, newState, 'collaboration'); * if (!success) { * // Fall back to setEditorState if differential update fails * editor.setEditorState(newState); * } * ``` */ interface EditorStateData { root: { type: 'root'; children: any[]; direction?: string | null; format?: number; indent?: number; version?: number; }; } /** * Main function to apply differential updates to the editor */ export declare function applyDifferentialUpdate(editor: LexicalEditor, newStateData: EditorStateData | any, source?: string): boolean; export {};