import { type Patch } from 'mutative'; import * as Y from 'yjs'; import { JSONArray, JSONObject } from './types'; export type Snapshot = JSONObject | JSONArray; declare function defaultApplyPatch(target: Y.Map | Y.Array, patch: Patch): void; export type UpdateFn = (draft: S) => void; type PatchesOptions = true | { pathAsArray?: boolean; arrayLengthAssignment?: boolean; }; type SkippedOrigins = readonly unknown[] | ReadonlySet; export type ListenerFn = (snapshot: S) => void; export type UnsubscribeFn = () => void; export type SubscribeOptions = { /** * If true, the listener will be called immediately with the current snapshot. * @default false */ immediate?: boolean; }; export type Binder = { /** * Release the binder. */ unbind: () => void; /** * Return the latest snapshot. */ get: () => S; /** * Update the snapshot as well as the corresponding y.js data. * Same usage as `create` from `Mutative`. */ update: (fn: UpdateFn) => void; /** * Subscribe to snapshot update, fired when: * 1. User called update(fn). * 2. y.js source.observeDeep() fired. * @param fn Listener function that receives the new snapshot * @param options Optional configuration for subscription behavior */ subscribe: (fn: ListenerFn, options?: SubscribeOptions) => UnsubscribeFn; }; export type Options = { /** * Customize Mutative patch application. * Should apply patch to the target y.js data. * @param target The y.js data to be modified. * @param patch The patch that should be applied, please refer to 'Mutative' patch documentation. * @param applyPatch the default behavior to apply patch, call this to handle the normal case. */ applyPatch?: (target: Y.Map | Y.Array, patch: Patch, applyPatch: typeof defaultApplyPatch) => void; /** * Customize Mutative patches options. * @param options The options that should be applied, please refer to 'Mutative' patches options documentation. */ patchesOptions?: PatchesOptions; /** * Transaction origins whose Yjs events should be reconciled from the final * Yjs state instead of applied incrementally. * Use when binder.update() is called inside an outer doc.transact() with a * known origin. The nested Y.transact gets merged into the outer transaction, * so observeDeep fires with the outer origin instead of MUTATIVE_YJS_ORIGIN. */ skippedOrigins?: SkippedOrigins; }; export declare function bind(source: Y.Map | Y.Array, options?: Options): Binder; export {}; //# sourceMappingURL=bind.d.ts.map