import { AtomicoElement, AtomicoThis, Nullable } from "./dom.js"; import { EventInit } from "./schema.js"; type GetInitialState = InitialState extends ( ...args: any[] ) => infer Value ? Value : InitialState; export type State = [State, SetState]; /** * Current will take its value immediately after rendering * The whole object is persistent between renders and mutable */ export class Ref { current: Current extends AtomicoElement ? InstanceType : Current; readonly on: (fn: (value: Current) => any, id?: any) => () => void; [index: string | number | symbol]: any; } /** * wrapper for SetState */ export type SetState = ( state: State | ((reduce: State) => State) ) => void; /** * Used by UseProp and UseState, construct return types */ export type ReturnUseState = State>; export type UseState = ( initialState?: OptionalInitialState | (() => OptionalInitialState) ) => ReturnUseState>; type EffectCallback = () => void | (() => any); /** * UseEffect */ export type UseEffect = ( effect: EffectCallback, args?: Args[] ) => void; /** * UseLayoutEffect */ export type UseLayoutEffect = UseEffect; /** * UseLayoutEffect */ export type UseInsertionEffect = UseEffect; /** * UseLayoutEffect */ export type UseRefEffect = (effect: EffectCallback, args: Ref[]) => void; /** * UseMemo */ export type UseMemo = any>( callback: CallbackMemo, args?: any[] ) => ReturnType; /** * UseCallback */ export type UseCallback = any>( callback: CallbackMemo, args?: any[] ) => CallbackMemo; /** * UseEvent */ export type UseEvent = ( eventType: string, options?: Omit ) => (detail?: Detail) => boolean; /** * UseProp */ type SetProp = ( state: Nullable | ((reduce?: State) => Nullable) ) => void; /** * Used by UseProp and UseState, construct return types */ export type ReturnUseProp = State< Value | undefined, SetState >; export type UseProp = (prop: string) => ReturnUseProp; /** * UseHook */ export type UseHook = any>( render: Render, effect?: ( value: ReturnType, unmounted: boolean ) => ReturnType, tag?: symbol ) => ReturnType; /** * UseRef */ export type UseRef = (current?: Current) => Ref; export type UseHost = () => Required>; export type UseUpdate = () => () => void; export type ReturnPromise = | { pending: true; fulfilled?: false; rejected?: false; aborted?: false; result?: never; } | { fulfilled: true; result: result; rejected?: false; aborted?: false; pending?: false; } | { rejected: true; pending?: false; fulfilled?: false; aborted?: false; result?: unknown; } | { aborted: true; result: DOMException; rejected?: false; pending?: false; fulfilled?: false; } | { rejected?: undefined; pending?: undefined; fulfilled?: undefined; aborted?: undefined; result?: undefined; }; export type UsePromise = Promise>( callback: Callback, args: Parameters, autorun?: boolean ) => ReturnPromise>>; /** * UseReducer */ type UseReducerGetState< Reducer extends (arg: any, actions?: any) => any, InitState > = InitState extends null | undefined ? ReturnType : ReturnType | InitState; export type UseReducer = < Reducer extends (state: any, actions: any) => any, InitState extends ReturnType, Init extends (state: InitState) => ReturnType >( reducer: Reducer, initArg?: InitState, init?: Init ) => [ ReturnType, ( actions: Reducer extends (state: any, actions: infer Actions) => any ? Actions : any ) => void ]; export type ReturnUseSuspense = | { pending: true; fulfilled?: false; rejected?: false; aborted?: false; } | { pending?: false; fulfilled: true; rejected?: false; aborted?: false; } | { pending?: false; fulfilled?: false; rejected?: true; aborted?: true; }; /** * @param fps - allows to delay in FPS the update of states */ export type UseSuspense = (fps?: number) => ReturnUseSuspense; export type UseAsync = Promise>( callback: Callback, args: Parameters ) => Awaited>; export type UseAbortController = ( args: Args ) => AbortController; /** * Returns an ID as a string, this ID can have 2 prefixes * `s`erver and `c`lient * @example * ```tsx * const id = useId(); * * ``` */ export type UseId = () => string;