import { Store } from './Store'; /** * A Store that supports controlled state keys, non-reactive values and provides utility methods for React. * * **Diverges from Base UI deliberately.** Upstream hangs the React glue off the class as * methods (`store.useState(...)`, `store.useControlledProp(...)`). A class body is not a * render scope as far as any Rules-of-Hooks linter is concerned, so every one of those * methods reads as a hook called outside a component. The hooks therefore live at module * scope in this file and take the store as their first argument — same behaviour, same * call order, but the linter can now see that they are ordinary custom hooks. Port * upstream store *state* verbatim; wire it up with the functions below. */ export declare class ReactStore, Selectors extends Record> = Record> extends Store { /** * Creates a new ReactStore instance. * * @param state Initial state of the store. * @param context Non-reactive context values. * @param selectors Optional selectors for use with `useStoreState`. */ constructor(state: State, context?: Context, selectors?: Selectors); /** * Non-reactive values such as refs, callbacks, etc. */ readonly context: Context; /** * @internal Read by `useStoreState`, which lives at module scope and so cannot reach a * `private` member. Not part of the public API. */ readonly selectors: Selectors | undefined; /** Gets the current value from the store using a selector with the provided key. * * @param key Key of the selector to use. */ select(key: Key, ...args: SelectorArgs): ReturnType; /** * Observes changes derived from the store's selectors and calls the listener when the selected value changes. * * @param key Key of the selector to observe. * @param listener Listener function called when the selector result changes. */ observe(selector: Key, listener: (newValue: ReturnType, oldValue: ReturnType, store: this) => void): () => void; observe>(selector: Selector, listener: (newValue: ReturnType, oldValue: ReturnType, store: this) => void): () => void; } /** * Returns a value from the store's state using a selector function. * Used to subscribe to specific parts of the state. * This hook causes a rerender whenever the selected state changes. * * @param store The store to read from. * @param key Key of the selector to use. */ export declare function useStoreState>, Key extends keyof Selectors>(store: ReactStore, key: Key, ...args: SelectorArgs): ReturnType; /** * Synchronizes a single external value into the store. * * Note that the while the value in `state` is updated immediately, the value returned * by `useStoreState` is updated before the next render (similarly to React's `useState`). */ export declare function useSyncedValue(store: ReactStore, key: keyof State, value: Value): void; /** * Synchronizes a single external value into the store and * cleans it up (sets to `undefined`) on unmount. * * Note that the while the value in `state` is updated immediately, the value returned * by `useStoreState` is updated before the next render (similarly to React's `useState`). */ export declare function useSyncedValueWithCleanup>(store: ReactStore, key: Key, value: State[Key]): void; /** * Synchronizes multiple external values into the store. * * Note that the while the values in `state` are updated immediately, the values returned * by `useStoreState` are updated before the next render (similarly to React's `useState`). */ export declare function useSyncedValues(store: ReactStore, statePart: Partial): void; /** * Registers a controllable prop pair (`controlled`, `defaultValue`) for a specific key. If `controlled` * is non-undefined, the store's state at `key` is updated to match `controlled`. */ export declare function useControlledProp(store: ReactStore, key: keyof State, controlled: Value | undefined): void; /** * Wraps a function with `useStableCallback` to ensure it has a stable reference * and assigns it to the store's context. * * @param store The store whose context receives the callback. * @param key Key of the event callback. Must be a function in the context. * @param fn Function to assign. */ export declare function useContextCallback>(store: ReactStore, key: Key, fn: ContextFunction | undefined): void; /** * Returns a stable setter function for a specific key in the store's state. * It's commonly used to pass as a ref callback to React elements. * * @param store The store to set into. * @param key Key of the state to set. */ export declare function useStateSetter(store: ReactStore, key: keyof State): (value: Value) => void; type MaybeCallable = (...args: any[]) => any; type ContextFunctionKeys = { [Key in keyof Context]-?: Extract extends never ? never : Key; }[keyof Context]; type ContextFunction = Extract; type KeysAllowingUndefined = { [Key in keyof State]-?: undefined extends State[Key] ? Key : never; }[keyof State]; type ObserveSelector = (state: State) => any; type SelectorFunction = (state: State, ...args: any[]) => any; type Tail = T extends readonly [any, ...infer Rest] ? Rest : []; type SelectorArgs = Selector extends (...params: infer Params) => any ? Tail : never; export {}; //# sourceMappingURL=ReactStore.d.ts.map