import * as reactive from "@reactivedata/reactive" ; import { markRaw } from "@reactivedata/reactive" ; import { enableReactiveBindings , makeYDocObservable } from "@syncedstore/yjs-reactive-bindings" ; import * as Y from "yjs" ; import { Doc as SyncedDoc , Map as SyncedMap , Array as SyncedArray , Text as SyncedText , XmlFragment as SyncedXml , } from "yjs" ; import { crdtDoc , DocTypeDescription } from "./doc" ; export { enableMobxBindings , enableVueBindings } from "@syncedstore/yjs-reactive-bindings" ; export { Box , boxed } from "./boxed" ; export * from "./util" ; ignore export { Y } ; enableReactiveBindings ( reactive ) ; ignore export const INTERNAL_SYMBOL = Symbol ( "INTERNAL_SYMBOL" ) ; param object param handler returns export function observeDeep ( object , handler ) { const internal = getYjsValue ( object ) ; if ( ! internal ) { throw new Error ( "not a valid synced object" ) ; } if ( internal instanceof Y . Doc ) { internal . on ( "update" , handler ) ; return ( ) => { internal . off ( "update" , handler ) ; } ; } else { internal . observeDeep ( handler ) ; return ( ) => { internal . unobserveDeep ( handler ) ; } ; } } param object returns export function getYjsValue ( object ) { if ( typeof object !== "object" || object === null ) { return undefined ; } const ret = object [ INTERNAL_SYMBOL ] ; if ( ret ) { markRaw ( ret ) ; ( ret as any ) . __v_skip = true ; } return ret ; } param objectA param objectB returns export function areSame ( objectA , objectB ) { if ( objectA === objectB ) { return true ; } if ( typeof objectA === "object" && typeof objectB === "object" ) { const internalA = getYjsValue ( objectA ) ; const internalB = getYjsValue ( objectB ) ; if ( ! internalA || ! internalB ) { return false ; } return internalA === internalB ; } return false ; } param shape param doc returns export function syncedStore < T extends DocTypeDescription > ( shape , doc = new Y . Doc ( ) ) { makeYDocObservable ( doc ) ; return crdtDoc < T > ( doc , shape ) ; } ignore export { SyncedDoc , SyncedArray , SyncedMap , SyncedXml , SyncedText } ; export default syncedStore ;