import { useEffect } from "react";
import { RichText } from "../../../../../controls/rich-text-v2";
import { useIsInBuilder } from "../../../hooks/use-is-in-builder";
function isChangeWithinPreviousSec(change) {
  return performance.now() - (change?.time ?? 0) < 1e3;
}
function useSyncRemoteChanges(editor, data) {
  const isInBuilder = useIsInBuilder();
  useEffect(() => {
    if (!isChangeWithinPreviousSec(editor.localChanges.get(data?.key ?? "")) && data && isInBuilder) {
      editor.children = RichText.dataToNodes(data);
      editor.selection = editor?.localChanges.get(data.key)?.selection ?? null;
      editor.onChange();
    }
  }, [editor, data]);
}
export {
  useSyncRemoteChanges
};
//# sourceMappingURL=useRemoteChanges.js.map