import { AtomicoThis, Nullable } from "./dom.js"; import { ReturnValidityState } from "./internal/hooks.js"; import { SchemaEventInit } from "./schema.js"; type GetInitialState = InitialState extends ( ...args: any[] ) => infer Value ? Value : InitialState; export type State = [State, SetState]; export type ElementTypes = Target extends abstract new ( ...args: any ) => infer This ? This : Target; /** * Current will take its value immediately after rendering * The whole object is persistent between renders and mutable */ export type Ref = { current?: ElementTypes; }; /** * 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; /** * 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 ) => ReturnType; /** * UseWhen */ export type UseWhen = ( id: symbol | string, callback: (param?: any) => any ) => void; /** * UseRef */ export type UseRef = (current?: Target) => Ref; export type UseHost = () => Required>; export type UseUpdate = () => () => void; export type ReturnPromise = | { pending: true; fulfilled?: false; rejected?: false; aborted?: false; result?: result; error?: unknown; startTime: number; endTime?: number; } | { fulfilled: true; result: result; error?: never; rejected?: false; aborted?: false; pending?: false; startTime: number; endTime: number; } | { rejected: true; pending?: false; fulfilled?: false; aborted?: false; result?: result; error: unknown; startTime: number; endTime: number; } | { aborted: true; result?: result; error: unknown; rejected?: false; pending?: false; fulfilled?: false; startTime: number; endTime: number; } | { rejected?: undefined; pending?: undefined; fulfilled?: undefined; aborted?: undefined; result?: undefined; error?: undefined; startTime?: undefined; endTime?: undefined; }; export type UsePromise = Promise>( callback: Callback, args: Parameters extends [] ? any[] : Parameters, options?: boolean | { autorun?: boolean; memo?: 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 extends [] ? any[] : 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; export type UseListener = ( ref: Ref, type: string, listener: (event: unknown) => any, options?: AddEventListenerOptions | boolean ) => void; export type UseSlot = ( ref: Ref, filter?: (child: Node) => boolean ) => ElementTypes[]; export type UseNodes = ( filter?: (node: Node) => boolean ) => ElementTypes[]; /** * Generate a second render, this render escapes the current * one and is useful for collaborative work between LightDOM and shadowDOM */ export type UseRender = (callback: () => any, args?: any[]) => void; export type UseFormSubmit = ( callback: (form: HTMLFormElement) => void, options?: AddEventListenerOptions ) => void; export type UseFormAssociated = ( callback: (form: HTMLFormElement) => void ) => void; export type UseFormDisabled = (callback: (disabled: boolean) => void) => void; export type UseFormReset = (callback: () => void) => void; export type UseInternals = () => ElementInternals; export type UseFormValue = ( prop: string ) => [string, (state: string | boolean | number) => void]; export type UseFormValidity = ( callback: () => ReturnValidityState, args: any[] ) => [string, ValidityState]; export type UseFormProps = ( propName?: string, propValue?: string ) => ReturnUseProp; export type UseParent = ( element: Element, composed?: boolean ) => Ref;