UNPKG

mobx-keystone-yjs

Version:

Yjs bindings for mobx-keystone

37 lines (36 loc) 1.59 kB
import { PlainArray, PlainObject, PlainValue } from '../plainTypes'; import { YjsData } from './convertYjsDataToJson'; import * as Y from "yjs"; /** * Options for applying JSON data to Y.js data structures. */ export interface ApplyJsonToYjsOptions { /** * The mode to use when applying JSON data to Y.js data structures. * - `add`: Creates new Y.js containers for objects/arrays (default, backwards compatible) * - `merge`: Recursively merges values, preserving existing container references where possible */ mode?: "add" | "merge"; } /** * Converts a plain value to a Y.js data structure. * Objects are converted to Y.Maps, arrays to Y.Arrays, primitives are untouched. * Frozen values are a special case and they are kept as immutable plain values. */ export declare function convertJsonToYjsData(v: PlainValue): YjsData; /** * Applies a JSON array to a Y.Array, using the convertJsonToYjsData to convert the values. * * @param dest The destination Y.Array. * @param source The source JSON array. * @param options Options for applying the JSON data. */ export declare const applyJsonArrayToYArray: (dest: Y.Array<any>, source: PlainArray, options?: ApplyJsonToYjsOptions) => void; /** * Applies a JSON object to a Y.Map, using the convertJsonToYjsData to convert the values. * * @param dest The destination Y.Map. * @param source The source JSON object. * @param options Options for applying the JSON data. */ export declare const applyJsonObjectToYMap: (dest: Y.Map<any>, source: PlainObject, options?: ApplyJsonToYjsOptions) => void;