"use strict"; Object.defineProperty(exports, "__esModule", { value: !0 }); var previewKitCompat = require("@sanity/preview-kit-compat"), require$$0 = require("react"), context = require("./_chunks-cjs/context.cjs"); function _interopDefaultCompat(e) { return e && typeof e == "object" && "default" in e ? e : { default: e }; } var require$$0__default = /* @__PURE__ */ _interopDefaultCompat(require$$0); function getDefaultExportFromCjs(x) { return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, "default") ? x.default : x; } var reactFastCompare, hasRequiredReactFastCompare; function requireReactFastCompare() { if (hasRequiredReactFastCompare) return reactFastCompare; hasRequiredReactFastCompare = 1; var hasElementType = typeof Element < "u", hasMap = typeof Map == "function", hasSet = typeof Set == "function", hasArrayBuffer = typeof ArrayBuffer == "function" && !!ArrayBuffer.isView; function equal(a, b) { if (a === b) return !0; if (a && b && typeof a == "object" && typeof b == "object") { if (a.constructor !== b.constructor) return !1; var length, i, keys; if (Array.isArray(a)) { if (length = a.length, length != b.length) return !1; for (i = length; i-- !== 0; ) if (!equal(a[i], b[i])) return !1; return !0; } var it; if (hasMap && a instanceof Map && b instanceof Map) { if (a.size !== b.size) return !1; for (it = a.entries(); !(i = it.next()).done; ) if (!b.has(i.value[0])) return !1; for (it = a.entries(); !(i = it.next()).done; ) if (!equal(i.value[1], b.get(i.value[0]))) return !1; return !0; } if (hasSet && a instanceof Set && b instanceof Set) { if (a.size !== b.size) return !1; for (it = a.entries(); !(i = it.next()).done; ) if (!b.has(i.value[0])) return !1; return !0; } if (hasArrayBuffer && ArrayBuffer.isView(a) && ArrayBuffer.isView(b)) { if (length = a.length, length != b.length) return !1; for (i = length; i-- !== 0; ) if (a[i] !== b[i]) return !1; return !0; } if (a.constructor === RegExp) return a.source === b.source && a.flags === b.flags; if (a.valueOf !== Object.prototype.valueOf && typeof a.valueOf == "function" && typeof b.valueOf == "function") return a.valueOf() === b.valueOf(); if (a.toString !== Object.prototype.toString && typeof a.toString == "function" && typeof b.toString == "function") return a.toString() === b.toString(); if (keys = Object.keys(a), length = keys.length, length !== Object.keys(b).length) return !1; for (i = length; i-- !== 0; ) if (!Object.prototype.hasOwnProperty.call(b, keys[i])) return !1; if (hasElementType && a instanceof Element) return !1; for (i = length; i-- !== 0; ) if (!((keys[i] === "_owner" || keys[i] === "__v" || keys[i] === "__o") && a.$$typeof) && !equal(a[keys[i]], b[keys[i]])) return !1; return !0; } return a !== a && b !== b; } return reactFastCompare = function(a, b) { try { return equal(a, b); } catch (error) { if ((error.message || "").match(/stack|recursion/i)) return console.warn("react-fast-compare cannot handle circular refs"), !1; throw error; } }, reactFastCompare; } var reactFastCompareExports = requireReactFastCompare(), isFastEqual = /* @__PURE__ */ getDefaultExportFromCjs(reactFastCompareExports), withSelector = { exports: {} }, useSyncExternalStoreWithSelector_production_min = {}; /** * @license React * use-sync-external-store-with-selector.production.min.js * * Copyright (c) Facebook, Inc. and its affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ var hasRequiredUseSyncExternalStoreWithSelector_production_min; function requireUseSyncExternalStoreWithSelector_production_min() { if (hasRequiredUseSyncExternalStoreWithSelector_production_min) return useSyncExternalStoreWithSelector_production_min; hasRequiredUseSyncExternalStoreWithSelector_production_min = 1; var g = require$$0__default.default; function n(a, b) { return a === b && (a !== 0 || 1 / a === 1 / b) || a !== a && b !== b; } var p = typeof Object.is == "function" ? Object.is : n, q = g.useSyncExternalStore, r = g.useRef, t = g.useEffect, u = g.useMemo, v = g.useDebugValue; return useSyncExternalStoreWithSelector_production_min.useSyncExternalStoreWithSelector = function(a, b, e, l, h) { var c = r(null); if (c.current === null) { var f = { hasValue: !1, value: null }; c.current = f; } else f = c.current; c = u(function() { function a2(a3) { if (!c2) { if (c2 = !0, d2 = a3, a3 = l(a3), h !== void 0 && f.hasValue) { var b2 = f.value; if (h(b2, a3)) return k = b2; } return k = a3; } if (b2 = k, p(d2, a3)) return b2; var e2 = l(a3); return h !== void 0 && h(b2, e2) ? b2 : (d2 = a3, k = e2); } var c2 = !1, d2, k, m = e === void 0 ? null : e; return [function() { return a2(b()); }, m === null ? void 0 : function() { return a2(m()); }]; }, [b, e, l, h]); var d = q(a, c[0], c[1]); return t(function() { f.hasValue = !0, f.value = d; }, [d]), v(d), d; }, useSyncExternalStoreWithSelector_production_min; } var useSyncExternalStoreWithSelector_development = {}; /** * @license React * use-sync-external-store-with-selector.development.js * * Copyright (c) Facebook, Inc. and its affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ var hasRequiredUseSyncExternalStoreWithSelector_development; function requireUseSyncExternalStoreWithSelector_development() { return hasRequiredUseSyncExternalStoreWithSelector_development || (hasRequiredUseSyncExternalStoreWithSelector_development = 1, process.env.NODE_ENV !== "production" && function() { typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ < "u" && typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart == "function" && __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(new Error()); var React = require$$0__default.default; function is(x, y) { return x === y && (x !== 0 || 1 / x === 1 / y) || x !== x && y !== y; } var objectIs = typeof Object.is == "function" ? Object.is : is, useSyncExternalStore = React.useSyncExternalStore, useRef = React.useRef, useEffect = React.useEffect, useMemo = React.useMemo, useDebugValue = React.useDebugValue; function useSyncExternalStoreWithSelector(subscribe, getSnapshot, getServerSnapshot, selector, isEqual) { var instRef = useRef(null), inst; instRef.current === null ? (inst = { hasValue: !1, value: null }, instRef.current = inst) : inst = instRef.current; var _useMemo = useMemo(function() { var hasMemo = !1, memoizedSnapshot, memoizedSelection, memoizedSelector = function(nextSnapshot) { if (!hasMemo) { hasMemo = !0, memoizedSnapshot = nextSnapshot; var _nextSelection = selector(nextSnapshot); if (isEqual !== void 0 && inst.hasValue) { var currentSelection = inst.value; if (isEqual(currentSelection, _nextSelection)) return memoizedSelection = currentSelection, currentSelection; } return memoizedSelection = _nextSelection, _nextSelection; } var prevSnapshot = memoizedSnapshot, prevSelection = memoizedSelection; if (objectIs(prevSnapshot, nextSnapshot)) return prevSelection; var nextSelection = selector(nextSnapshot); return isEqual !== void 0 && isEqual(prevSelection, nextSelection) ? prevSelection : (memoizedSnapshot = nextSnapshot, memoizedSelection = nextSelection, nextSelection); }, maybeGetServerSnapshot = getServerSnapshot === void 0 ? null : getServerSnapshot, getSnapshotWithSelector = function() { return memoizedSelector(getSnapshot()); }, getServerSnapshotWithSelector = maybeGetServerSnapshot === null ? void 0 : function() { return memoizedSelector(maybeGetServerSnapshot()); }; return [getSnapshotWithSelector, getServerSnapshotWithSelector]; }, [getSnapshot, getServerSnapshot, selector, isEqual]), getSelection = _useMemo[0], getServerSelection = _useMemo[1], value = useSyncExternalStore(subscribe, getSelection, getServerSelection); return useEffect(function() { inst.hasValue = !0, inst.value = value; }, [value]), useDebugValue(value), value; } useSyncExternalStoreWithSelector_development.useSyncExternalStoreWithSelector = useSyncExternalStoreWithSelector, typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ < "u" && typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop == "function" && __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(new Error()); }()), useSyncExternalStoreWithSelector_development; } var hasRequiredWithSelector; function requireWithSelector() { return hasRequiredWithSelector || (hasRequiredWithSelector = 1, process.env.NODE_ENV === "production" ? withSelector.exports = requireUseSyncExternalStoreWithSelector_production_min() : withSelector.exports = requireUseSyncExternalStoreWithSelector_development()), withSelector.exports; } var withSelectorExports = requireWithSelector(); function useLiveQuery(initialData, query, queryParams, options) { const { isEqual = isFastEqual } = options || {}, defineStore = require$$0.useContext(context.defineStoreContext), params = previewKitCompat.useQueryParams(queryParams), noStore = require$$0.useMemo( () => ({ subscribe: () => () => { }, getSnapshot: () => initialData }), [initialData] ), store = require$$0.useMemo( () => defineStore?.(initialData, query, params) || { subscribe: () => () => { }, getSnapshot: () => initialData }, [defineStore, initialData, params, query] ), [serverSnapshot] = require$$0.useState(() => { if (initialData === void 0) throw new Error( "initialSnapshot can't be undefined, if you don't want an initial value use null instead" ); try { return JSON.parse(JSON.stringify(initialData)); } catch (error) { return console.warn( "Failed to deep clone initialSnapshot, this is likely an error and an indication that the snapshot isn't JSON serializable", { initialSnapshot: initialData, error } ), initialData; } }), getServerSnapshot = require$$0.useCallback(() => serverSnapshot, [serverSnapshot]), selector = require$$0.useCallback((snapshot2) => snapshot2, []), snapshot = withSelectorExports.useSyncExternalStoreWithSelector( store?.subscribe || noStore.subscribe, store?.getSnapshot || noStore.getSnapshot, getServerSnapshot, selector, isEqual ), enabled = defineStore !== null; return [snapshot, enabled && serverSnapshot === snapshot, enabled]; } function useIsEnabled() { return require$$0.useContext(context.defineStoreContext) !== null; } const LiveQueryProvider = require$$0.lazy( () => Promise.resolve().then(function() { return require("./_chunks-cjs/LiveQueryProvider.cjs"); }) ); exports.LiveQueryProvider = LiveQueryProvider; exports.default = LiveQueryProvider; exports.useIsEnabled = useIsEnabled; exports.useLiveQuery = useLiveQuery; //# sourceMappingURL=index.cjs.map