UNPKG

@ariakit/react

Version:

Toolkit for building accessible web apps with React

803 lines (760 loc) 31.5 kB
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } var _LZ6L3ECGcjs = require('./LZ6L3ECG.cjs'); // ../../node_modules/.pnpm/use-sync-external-store@1.6.0_react@19.2.7/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.production.js var require_use_sync_external_store_shim_production = _LZ6L3ECGcjs.__commonJS.call(void 0, { "../../node_modules/.pnpm/use-sync-external-store@1.6.0_react@19.2.7/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.production.js"(exports) { "use strict"; var React2 = _LZ6L3ECGcjs.__require.call(void 0, "react"); function is(x, y) { return x === y && (0 !== x || 1 / x === 1 / y) || x !== x && y !== y; } var objectIs = "function" === typeof Object.is ? Object.is : is; var useState2 = React2.useState; var useEffect = React2.useEffect; var useLayoutEffect = React2.useLayoutEffect; var useDebugValue = React2.useDebugValue; function useSyncExternalStore$2(subscribe2, getSnapshot) { var value = getSnapshot(), _useState = useState2({ inst: { value, getSnapshot } }), inst = _useState[0].inst, forceUpdate = _useState[1]; useLayoutEffect( function() { inst.value = value; inst.getSnapshot = getSnapshot; checkIfSnapshotChanged(inst) && forceUpdate({ inst }); }, [subscribe2, value, getSnapshot] ); useEffect( function() { checkIfSnapshotChanged(inst) && forceUpdate({ inst }); return subscribe2(function() { checkIfSnapshotChanged(inst) && forceUpdate({ inst }); }); }, [subscribe2] ); useDebugValue(value); return value; } function checkIfSnapshotChanged(inst) { var latestGetSnapshot = inst.getSnapshot; inst = inst.value; try { var nextValue = latestGetSnapshot(); return !objectIs(inst, nextValue); } catch (error) { return true; } } function useSyncExternalStore$1(subscribe2, getSnapshot) { return getSnapshot(); } var shim = "undefined" === typeof window || "undefined" === typeof window.document || "undefined" === typeof window.document.createElement ? useSyncExternalStore$1 : useSyncExternalStore$2; exports.useSyncExternalStore = void 0 !== React2.useSyncExternalStore ? React2.useSyncExternalStore : shim; } }); // ../../node_modules/.pnpm/use-sync-external-store@1.6.0_react@19.2.7/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.development.js var require_use_sync_external_store_shim_development = _LZ6L3ECGcjs.__commonJS.call(void 0, { "../../node_modules/.pnpm/use-sync-external-store@1.6.0_react@19.2.7/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.development.js"(exports) { "use strict"; "production" !== process.env.NODE_ENV && (function() { function is(x, y) { return x === y && (0 !== x || 1 / x === 1 / y) || x !== x && y !== y; } function useSyncExternalStore$2(subscribe2, getSnapshot) { didWarnOld18Alpha || void 0 === React2.startTransition || (didWarnOld18Alpha = true, console.error( "You are using an outdated, pre-release alpha of React 18 that does not support useSyncExternalStore. The use-sync-external-store shim will not work correctly. Upgrade to a newer pre-release." )); var value = getSnapshot(); if (!didWarnUncachedGetSnapshot) { var cachedValue = getSnapshot(); objectIs(value, cachedValue) || (console.error( "The result of getSnapshot should be cached to avoid an infinite loop" ), didWarnUncachedGetSnapshot = true); } cachedValue = useState2({ inst: { value, getSnapshot } }); var inst = cachedValue[0].inst, forceUpdate = cachedValue[1]; useLayoutEffect( function() { inst.value = value; inst.getSnapshot = getSnapshot; checkIfSnapshotChanged(inst) && forceUpdate({ inst }); }, [subscribe2, value, getSnapshot] ); useEffect( function() { checkIfSnapshotChanged(inst) && forceUpdate({ inst }); return subscribe2(function() { checkIfSnapshotChanged(inst) && forceUpdate({ inst }); }); }, [subscribe2] ); useDebugValue(value); return value; } function checkIfSnapshotChanged(inst) { var latestGetSnapshot = inst.getSnapshot; inst = inst.value; try { var nextValue = latestGetSnapshot(); return !objectIs(inst, nextValue); } catch (error) { return true; } } function useSyncExternalStore$1(subscribe2, getSnapshot) { return getSnapshot(); } "undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ && "function" === typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart && __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error()); var React2 = _LZ6L3ECGcjs.__require.call(void 0, "react"), objectIs = "function" === typeof Object.is ? Object.is : is, useState2 = React2.useState, useEffect = React2.useEffect, useLayoutEffect = React2.useLayoutEffect, useDebugValue = React2.useDebugValue, didWarnOld18Alpha = false, didWarnUncachedGetSnapshot = false, shim = "undefined" === typeof window || "undefined" === typeof window.document || "undefined" === typeof window.document.createElement ? useSyncExternalStore$1 : useSyncExternalStore$2; exports.useSyncExternalStore = void 0 !== React2.useSyncExternalStore ? React2.useSyncExternalStore : shim; "undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ && "function" === typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop && __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error()); })(); } }); // ../../node_modules/.pnpm/use-sync-external-store@1.6.0_react@19.2.7/node_modules/use-sync-external-store/shim/index.js var require_shim = _LZ6L3ECGcjs.__commonJS.call(void 0, { "../../node_modules/.pnpm/use-sync-external-store@1.6.0_react@19.2.7/node_modules/use-sync-external-store/shim/index.js"(exports, module) { "use strict"; if (process.env.NODE_ENV === "production") { module.exports = require_use_sync_external_store_shim_production(); } else { module.exports = require_use_sync_external_store_shim_development(); } } }); // ../ariakit-store/dist/index.js function getInternal(store, key) { const internals = store.__unstableInternals; _LZ6L3ECGcjs.invariant.call(void 0, internals, "Invalid store"); return internals[key]; } function hasUpdatedKey(keys, updatedKey) { if (!keys) return true; for (const currentKey of keys) if (updatedKey instanceof Set) { if (updatedKey.has(currentKey)) return true; } else if (currentKey === updatedKey) return true; return false; } function isSameValue(value, other) { return value === other || value !== value && other !== other; } function getCleanupPrevState(prevState, state, stateBeforeCleanup, updatedKey) { let cleanupPrevState; for (const key of _LZ6L3ECGcjs.getKeys.call(void 0, state)) { if (isSameValue(state[key], stateBeforeCleanup[key])) continue; if (updatedKey !== void 0 && hasUpdatedKey([key], updatedKey)) continue; cleanupPrevState != null ? cleanupPrevState : cleanupPrevState = { ...prevState }; cleanupPrevState[key] = state[key]; } return cleanupPrevState; } var MAX_REPAIR_PASSES = 100; function addKeyedListener(map, keys, listener) { if (!keys) return; for (const key of keys) { let listeners = map.get(key); if (!listeners) { listeners = /* @__PURE__ */ new Set(); map.set(key, listeners); } listeners.add(listener); } } function deleteKeyedListener(map, keys, listener) { if (!map) return; if (!keys) return; for (const key of keys) { const listeners = map.get(key); if (!listeners) continue; listeners.delete(listener); if (!listeners.size) map.delete(key); } } function getFastPathNotifiedListeners(frame) { const notifiedListeners = /* @__PURE__ */ new Set(); const currentListener = frame.currentListener; if (!currentListener) return notifiedListeners; for (const listener of frame.keyedListeners) { notifiedListeners.add(listener); if (listener === currentListener) return notifiedListeners; } notifiedListeners.clear(); notifiedListeners.add(currentListener); return notifiedListeners; } function preserveFastPathNotifiedListeners(frame) { var _a; (_a = frame.notifiedListeners) != null ? _a : frame.notifiedListeners = getFastPathNotifiedListeners(frame); } function hasFastPathPassedListener(frame, listener) { if (!frame.currentListener) return false; let foundCurrentKeyedListener = false; for (const currentListener of frame.keyedListeners) { if (currentListener === frame.currentListener) { foundCurrentKeyedListener = true; continue; } if (!foundCurrentKeyedListener) continue; if (currentListener === listener) return false; } let foundListener = false; for (const currentListener of frame.group.listeners) { if (currentListener === frame.currentListener) return foundListener; if (currentListener === listener) foundListener = true; } return false; } function preserveFastPathFrames(fastPathFrames, group, listener) { var _a; for (const frame of fastPathFrames) { if (frame.group !== group) continue; if (frame.recovering) continue; if (listener && !frame.keyedListeners.has(listener)) continue; preserveFastPathNotifiedListeners(frame); for (const currentListener of frame.group.listeners) { if (currentListener === frame.currentListener) break; if (!hasFastPathPassedListener(frame, currentListener)) continue; (_a = frame.notifiedListeners) == null ? void 0 : _a.add(currentListener); } } } function preserveFastPathPassedListeners(fastPathFrames, group, listener) { var _a; for (const frame of fastPathFrames) { if (frame.group !== group) continue; if (frame.recovering) continue; if (!hasFastPathPassedListener(frame, listener)) continue; preserveFastPathNotifiedListeners(frame); (_a = frame.notifiedListeners) == null ? void 0 : _a.add(listener); } } function preserveFastPathPassedKeyedListeners({ fastPathFrames, group, keys, listener }) { var _a; const wasRegistered = group.listeners.has(listener); for (const frame of fastPathFrames) { if (frame.group !== group) continue; if (frame.recovering) continue; if (!keys.includes(frame.updatedKey)) continue; if (hasFastPathPassedListener(frame, listener)) { preserveFastPathNotifiedListeners(frame); (_a = frame.notifiedListeners) == null ? void 0 : _a.add(listener); } else if (wasRegistered) { preserveFastPathNotifiedListeners(frame); frame.recoverToLive = true; } } } function clearFastPathNotifiedListener(fastPathFrames, group, listener) { var _a; for (const frame of fastPathFrames) { if (frame.group !== group) continue; (_a = frame.notifiedListeners) == null ? void 0 : _a.delete(listener); } } function addFastPathKeyedListener({ fastPathFrames, group, keys, listener }) { for (const frame of fastPathFrames) { if (frame.group !== group) continue; if (frame.recovering) continue; if (!keys.includes(frame.updatedKey)) continue; frame.keyedListeners.add(listener); } } function runPendingCleanup(group, listener) { if (!group.disposables.size) return; const cleanup = group.disposables.get(listener); if (!cleanup) return; group.disposables.delete(listener); cleanup(); } function setListenerCleanup(group, listener, cleanup) { const currentCleanup = group.disposables.get(listener); if (!currentCleanup) { group.disposables.set(listener, cleanup); return; } group.disposables.set(listener, () => { currentCleanup(); cleanup(); }); } function notifyStoreListener(group, listener, state, prevState, getState, updatedKey) { var _a, _b, _c; if ((_a = group.suspendCounts) == null ? void 0 : _a.has(listener)) return; const { disposables } = group; const cleanup = disposables.size ? disposables.get(listener) : void 0; if (cleanup) { disposables.delete(listener); const stateBeforeCleanup = state; cleanup(); state = (_b = getState == null ? void 0 : getState()) != null ? _b : state; if (state !== stateBeforeCleanup) prevState = (_c = getCleanupPrevState(prevState, state, stateBeforeCleanup, updatedKey)) != null ? _c : prevState; } const result = listener(state, prevState); if (result) setListenerCleanup(group, listener, result); } function runLiveListeners({ group, getState, prevState, updatedKey, notifiedListeners }) { const allKeysListeners = group.allKeysListeners; for (const listener of group.listeners) { if (notifiedListeners == null ? void 0 : notifiedListeners.has(listener)) continue; if (!(allKeysListeners == null ? void 0 : allKeysListeners.has(listener))) { if (!hasUpdatedKey(group.listenerKeys.get(listener), updatedKey)) continue; } notifiedListeners == null ? void 0 : notifiedListeners.add(listener); notifyStoreListener(group, listener, getState(), prevState, getState, updatedKey); } } function createStore(initialState, ...stores) { let state = initialState; let prevStateBatch = state; let destroy = _LZ6L3ECGcjs.noop; let batchPending = false; let inDispatch = false; let updatedKeys = /* @__PURE__ */ new Set(); const instances = /* @__PURE__ */ new Set(); const setups = /* @__PURE__ */ new Set(); const syncListenerGroup = { listeners: /* @__PURE__ */ new Set(), disposables: /* @__PURE__ */ new Map(), listenerKeys: /* @__PURE__ */ new WeakMap() }; const batchListenerGroup = { listeners: /* @__PURE__ */ new Set(), disposables: /* @__PURE__ */ new Map(), listenerKeys: /* @__PURE__ */ new WeakMap() }; const storeSetup = (callback) => { setups.add(callback); return () => setups.delete(callback); }; const storeInit = () => { var _a, _b; const initializedInstances = instances.size; const instance = /* @__PURE__ */ Symbol(); instances.add(instance); const maybeDestroy = () => { if (!instances.delete(instance)) return; if (instances.size) return; destroy(); }; if (initializedInstances) return maybeDestroy; const stateKeys = _LZ6L3ECGcjs.getKeys.call(void 0, state); const desyncs = []; for (const store of stores) { const storeState = (_a = store == null ? void 0 : store.getState) == null ? void 0 : _a.call(store); if (!storeState) continue; const keys = stateKeys.filter((key) => _LZ6L3ECGcjs.hasOwnProperty.call(void 0, storeState, key)); if (!keys.length) continue; if (stores.length === 1 || keys.length === stateKeys.length) { for (const key of keys) desyncs.push(sync(store, [key], (state2) => { setState(key, state2[key], true); })); continue; } desyncs.push(subscribe(store, keys, (state2, prevState) => { for (const key of keys) { if (state2[key] === prevState[key]) continue; setState(key, state2[key], true); } })); for (const key of keys) { const liveState = (_b = store == null ? void 0 : store.getState) == null ? void 0 : _b.call(store); if (!liveState) continue; setState(key, liveState[key], true); } } const teardowns = []; for (const setup2 of setups) teardowns.push(setup2()); const cleanups = stores.map(init); destroy = _LZ6L3ECGcjs.chain.call(void 0, ...desyncs, ...teardowns, ...cleanups); return maybeDestroy; }; const deleteListenerIndexes = (group, listener, keys) => { var _a; if (keys === void 0) return; if (keys) deleteKeyedListener(group.listenersByKey, keys, listener); else (_a = group.allKeysListeners) == null ? void 0 : _a.delete(listener); }; const fastPathFrames = []; const registerListener = (keys, listener, group = syncListenerGroup) => { var _a, _b; const listenerKeysValue = keys ? [...keys] : null; const wasRegistered = group.listeners.has(listener); if (!wasRegistered) clearFastPathNotifiedListener(fastPathFrames, group, listener); if (!listenerKeysValue) { if (wasRegistered) preserveFastPathFrames(fastPathFrames, group); preserveFastPathPassedListeners(fastPathFrames, group, listener); } else preserveFastPathPassedKeyedListeners({ fastPathFrames, group, keys: listenerKeysValue, listener }); if (wasRegistered) { preserveFastPathFrames(fastPathFrames, group, listener); deleteListenerIndexes(group, listener, group.listenerKeys.get(listener)); } group.listeners.add(listener); if (listenerKeysValue) { (_a = group.listenersByKey) != null ? _a : group.listenersByKey = /* @__PURE__ */ new Map(); addKeyedListener(group.listenersByKey, listenerKeysValue, listener); addFastPathKeyedListener({ fastPathFrames, group, keys: listenerKeysValue, listener }); } else { (_b = group.allKeysListeners) != null ? _b : group.allKeysListeners = /* @__PURE__ */ new Set(); group.allKeysListeners.add(listener); } group.listenerKeys.set(listener, listenerKeysValue); return () => { const cleanup = group.disposables.get(listener); group.disposables.delete(listener); preserveFastPathFrames(fastPathFrames, group, listener); const currentKeys = group.listenerKeys.get(listener); deleteListenerIndexes(group, listener, listenerKeysValue); if (currentKeys !== listenerKeysValue) deleteListenerIndexes(group, listener, currentKeys); group.listenerKeys.delete(listener); group.listeners.delete(listener); cleanup == null ? void 0 : cleanup(); }; }; const storeSubscribe = (keys, listener) => registerListener(keys, listener); const runInitialListener = (group, listener, prevState) => { var _a, _b; const shouldSuspend = group.listeners.has(listener); if (shouldSuspend) { (_a = group.suspendCounts) != null ? _a : group.suspendCounts = /* @__PURE__ */ new Map(); const count = (_b = group.suspendCounts.get(listener)) != null ? _b : 0; group.suspendCounts.set(listener, count + 1); } let cleanupPrevState; try { const stateBeforeCleanups = state; runPendingCleanup(group, listener); if (state !== stateBeforeCleanups) cleanupPrevState = getCleanupPrevState(prevState, state, stateBeforeCleanups); const cleanup = listener(state, cleanupPrevState != null ? cleanupPrevState : prevState); if (cleanup) setListenerCleanup(group, listener, cleanup); } finally { if (shouldSuspend) { const suspendCounts = group.suspendCounts; const count = suspendCounts == null ? void 0 : suspendCounts.get(listener); if (count && count > 1) suspendCounts == null ? void 0 : suspendCounts.set(listener, count - 1); else suspendCounts == null ? void 0 : suspendCounts.delete(listener); if (!(suspendCounts == null ? void 0 : suspendCounts.size)) delete group.suspendCounts; } } }; const storeSync = (keys, listener) => { runInitialListener(syncListenerGroup, listener, state); return registerListener(keys, listener); }; const storeBatch = (keys, listener) => { if (!batchListenerGroup.listeners.size && !inDispatch) prevStateBatch = state; runInitialListener(batchListenerGroup, listener, prevStateBatch); return registerListener(keys, listener, batchListenerGroup); }; const storePick = (keys) => createStore(_LZ6L3ECGcjs.pick.call(void 0, state, keys), finalStore); const storeOmit = (keys) => createStore(_LZ6L3ECGcjs.omit.call(void 0, state, keys), finalStore); const getState = () => state; const runListeners = (group, prevState, updatedKey) => { var _a, _b, _c, _d, _e, _f; if (!(updatedKey instanceof Set) && !((_a = group.allKeysListeners) == null ? void 0 : _a.size)) { const keyedListeners = (_b = group.listenersByKey) == null ? void 0 : _b.get(updatedKey); if (!keyedListeners) return; const frame = { group, keyedListeners, updatedKey, currentListener: null }; fastPathFrames.push(frame); try { for (const listener of keyedListeners) { if ((_c = frame.notifiedListeners) == null ? void 0 : _c.has(listener)) continue; frame.currentListener = listener; (_d = frame.notifiedListeners) == null ? void 0 : _d.add(listener); notifyStoreListener(group, listener, state, prevState, getState, updatedKey); if (!((_e = group.allKeysListeners) == null ? void 0 : _e.size) && !frame.recoverToLive) continue; const notifiedListeners = (_f = frame.notifiedListeners) != null ? _f : getFastPathNotifiedListeners(frame); frame.notifiedListeners = notifiedListeners; frame.recovering = true; runLiveListeners({ group, getState, prevState, updatedKey, notifiedListeners }); return; } } finally { fastPathFrames.pop(); } return; } runLiveListeners({ group, getState, prevState, updatedKey }); }; const setState = (key, value, fromStores = false) => { var _a, _b; if (!_LZ6L3ECGcjs.hasOwnProperty.call(void 0, state, key)) return; const currentValue = state[key]; const nextValue = typeof value === "function" ? value(currentValue) : value; if (isSameValue(nextValue, currentValue)) return; const wasInDispatch = inDispatch; inDispatch = true; const prevState = state; const nextState = { ...state, [key]: nextValue }; state = nextState; let superseded = false; try { if (!fromStores && stores.length) { for (const store of stores) { (_a = store == null ? void 0 : store.setState) == null ? void 0 : _a.call(store, key, nextValue); if (isSameValue(state[key], nextValue)) continue; superseded = true; break; } if (superseded) { let pass = 0; for (; pass < MAX_REPAIR_PASSES; pass += 1) { let changed = false; for (const store of stores) { const previousValue = state[key]; (_b = store == null ? void 0 : store.setState) == null ? void 0 : _b.call(store, key, previousValue); if (!isSameValue(state[key], previousValue)) changed = true; } if (!changed) break; } if (process.env.NODE_ENV !== "production" && pass === MAX_REPAIR_PASSES) console.warn("Parent stores did not converge after a superseded fan-out; a parent listener may be rewriting this key in a cycle."); } } if (!superseded) runListeners(syncListenerGroup, state === nextState ? prevState : { ...state, [key]: prevState[key] }, key); } finally { inDispatch = wasInDispatch; } if (!batchListenerGroup.listeners.size) { if (!inDispatch) prevStateBatch = state; return; } updatedKeys.add(key); if (batchPending) return; batchPending = true; queueMicrotask(() => { batchPending = false; const snapshot = state; const updatedKeysSnapshot = updatedKeys; updatedKeys = /* @__PURE__ */ new Set(); const prevStateBatchBefore = prevStateBatch; runListeners(batchListenerGroup, prevStateBatchBefore, updatedKeysSnapshot); if (prevStateBatch === prevStateBatchBefore) prevStateBatch = snapshot; }); }; const finalStore = { getState, setState, __unstableInternals: { setup: storeSetup, init: storeInit, subscribe: storeSubscribe, sync: storeSync, batch: storeBatch, pick: storePick, omit: storeOmit } }; return finalStore; } function setup(store, ...args) { if (!store) return; return getInternal(store, "setup")(...args); } function init(store, ...args) { if (!store) return; return getInternal(store, "init")(...args); } function subscribe(store, ...args) { if (!store) return; return getInternal(store, "subscribe")(...args); } function sync(store, ...args) { if (!store) return; return getInternal(store, "sync")(...args); } function batch(store, ...args) { if (!store) return; return getInternal(store, "batch")(...args); } function omit2(store, ...args) { if (!store) return; return getInternal(store, "omit")(...args); } function pick2(store, ...args) { if (!store) return; return getInternal(store, "pick")(...args); } function mergeStore(...stores) { var _a; const initialState = {}; for (const store2 of stores) { const nextState = (_a = store2 == null ? void 0 : store2.getState) == null ? void 0 : _a.call(store2); if (nextState) Object.assign(initialState, nextState); } const store = createStore(initialState, ...stores); return Object.assign({}, ...stores, store); } function throwOnConflictingProps(props, store) { if (process.env.NODE_ENV === "production") return; if (!store) return; const defaultKeys = Object.entries(props).filter(([key, value]) => key.startsWith("default") && value !== void 0).map(([key]) => { var _a; const stateKey = key.replace("default", ""); return `${((_a = stateKey[0]) == null ? void 0 : _a.toLowerCase()) || ""}${stateKey.slice(1)}`; }); if (!defaultKeys.length) return; const storeState = store.getState(); if (!defaultKeys.filter((key) => _LZ6L3ECGcjs.hasOwnProperty.call(void 0, storeState, key)).length) return; throw new Error(`Passing a store prop in conjunction with a default state is not supported. const store = useSelectStore(); <SelectProvider store={store} defaultValue="Apple" /> ^ ^ Instead, pass the default state to the topmost store: const store = useSelectStore({ defaultValue: "Apple" }); <SelectProvider store={store} /> See https://github.com/ariakit/ariakit/pull/2745 for more details. If there's a particular need for this, please submit a feature request at https://github.com/ariakit/ariakit `); } // ../ariakit-react-store/dist/index.js var import_shim = _LZ6L3ECGcjs.__toESM.call(void 0, require_shim(), 1); var _react = require('react'); var React = _interopRequireWildcard(_react); var noopSubscribe = () => () => { }; function useStoreState(store, keyOrSelector = _LZ6L3ECGcjs.identity) { const storeSubscribe = React.useCallback((callback) => { if (!store) return noopSubscribe(); return subscribe(store, null, callback); }, [store]); const getSnapshot = () => { const key = typeof keyOrSelector === "string" ? keyOrSelector : null; const selector = typeof keyOrSelector === "function" ? keyOrSelector : null; const state = store == null ? void 0 : store.getState(); if (selector) return selector(state); if (!state) return; if (!key) return; if (!_LZ6L3ECGcjs.hasOwnProperty.call(void 0, state, key)) return; return state[key]; }; return (0, import_shim.useSyncExternalStore)(storeSubscribe, getSnapshot, getSnapshot); } function useStoreStateObject(store, object) { const objRef = React.useRef({}); const storeSubscribe = React.useCallback((callback) => { if (!store) return noopSubscribe(); return subscribe(store, null, callback); }, [store]); const getSnapshot = () => { const state = store == null ? void 0 : store.getState(); let updated = false; const obj = objRef.current; for (const prop in object) { const keyOrSelector = object[prop]; if (typeof keyOrSelector === "function") { const value = keyOrSelector(state); if (!Object.is(value, obj[prop])) { obj[prop] = value; updated = true; } } if (typeof keyOrSelector === "string") { if (!state) continue; if (!_LZ6L3ECGcjs.hasOwnProperty.call(void 0, state, keyOrSelector)) continue; const value = state[keyOrSelector]; if (!Object.is(value, obj[prop])) { obj[prop] = value; updated = true; } } } if (updated) objRef.current = { ...obj }; return objRef.current; }; return (0, import_shim.useSyncExternalStore)(storeSubscribe, getSnapshot, getSnapshot); } function useStoreProps(store, props, key, setKey) { const value = _LZ6L3ECGcjs.hasOwnProperty.call(void 0, props, key) ? props[key] : void 0; const propsRef = _LZ6L3ECGcjs.useLiveRef.call(void 0, { value, setValue: setKey ? props[setKey] : void 0 }); _LZ6L3ECGcjs.useSafeLayoutEffect.call(void 0, () => { return sync(store, [key], (state, prev) => { const { value: value2, setValue } = propsRef.current; if (!setValue) return; if (state[key] === prev[key]) return; if (state[key] === value2) return; setValue(state[key]); }); }, [store, key]); _LZ6L3ECGcjs.useSafeLayoutEffect.call(void 0, () => { if (value === void 0) return; store.setState(key, value); return batch(store, [key], () => { if (value === void 0) return; store.setState(key, value); }); }); } function useStore(createStore2, props) { const [store, setStore] = React.useState(() => createStore2(props)); _LZ6L3ECGcjs.useSafeLayoutEffect.call(void 0, () => init(store), [store]); const useState2 = React.useCallback((keyOrSelector) => useStoreState(store, keyOrSelector), [store]); return [React.useMemo(() => ({ ...store, useState: useState2 }), [store, useState2]), _LZ6L3ECGcjs.useEvent.call(void 0, () => { setStore((store2) => createStore2({ ...props, ...store2.getState() })); })]; } exports.createStore = createStore; exports.setup = setup; exports.init = init; exports.subscribe = subscribe; exports.sync = sync; exports.batch = batch; exports.omit = omit2; exports.pick = pick2; exports.mergeStore = mergeStore; exports.throwOnConflictingProps = throwOnConflictingProps; exports.useStoreState = useStoreState; exports.useStoreStateObject = useStoreStateObject; exports.useStoreProps = useStoreProps; exports.useStore = useStore; /*! Bundled license information: use-sync-external-store/cjs/use-sync-external-store-shim.production.js: (** * @license React * use-sync-external-store-shim.production.js * * Copyright (c) Meta Platforms, Inc. and affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. *) use-sync-external-store/cjs/use-sync-external-store-shim.development.js: (** * @license React * use-sync-external-store-shim.development.js * * Copyright (c) Meta Platforms, Inc. and affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. *) */