import { InputSignalWithTransform, WritableSignal, InputSignal, Signal, InjectionToken, ProviderToken, FactoryProvider, InjectOptions, Injector, ElementRef } from '@angular/core'; import { Observable } from 'rxjs'; /** * This converts the state object to a writable state object. * This means that inputs become signals which are writable. */ type State = { [K in keyof T]: T[K] extends InputSignalWithTransform ? WritableSignal : T[K] extends InputSignal ? WritableSignal : T[K]; }; /** * This is similar to the state object, but we don't expose properties that are not * inputs. */ type CreatedState = { [K in keyof T]: T[K] extends InputSignalWithTransform ? WritableSignal : T[K] extends InputSignal ? WritableSignal : never; }; type InjectedState = Signal>; /** * Create a new injection token for the state. * @param description The description of the token */ declare function createStateToken(description: string): InjectionToken; interface CreateStateProviderOptions { /** * Whether we should check for the state in the parent injector. */ inherit?: boolean; } type StateInjectionOptions = { hoisted?: boolean; optional?: boolean; skipSelf?: boolean; } | undefined; /** * Create a new provider for the state. It first tries to inject the state from the parent injector, * as this allows for the state to be hoisted to a higher level in the component tree. This can * be useful to avoid issues where the injector can't be shared in some cases when ng-content is used. * @param token The token for the state */ declare function createStateProvider(token: ProviderToken): (options?: CreateStateProviderOptions) => FactoryProvider; type CreateStateInjectorOptions = { /** * Whether the state may not be immediately available. This can happen when the child is instantiated before the parent. */ deferred?: boolean; }; /** * Create a new state injector for the state. * @param token The token for the state */ declare function createStateInjector(token: ProviderToken>, options: { deferred: true; }): (injectOptions?: InjectOptions) => Signal | undefined>; declare function createStateInjector(token: ProviderToken>, options?: CreateStateInjectorOptions): (injectOptions?: InjectOptions) => Signal>; /** * Convert the original state object into a writable state object. * @param token The token for the state */ declare function createState(token: ProviderToken>>): (state: U) => CreatedState; interface CreatePrimitiveOptions { injector?: Injector; elementRef?: ElementRef; } type PrimitiveState unknown> = TFactory extends (props: unknown) => infer R ? R : TFactory extends (...args: any[]) => infer R ? R : never; type BasePrimitiveInjectionFn = { (): Signal; (options: StateInjectionOptions): Signal; (options?: StateInjectionOptions): Signal | Signal; }; type PrimitiveInjectionFn unknown> = TFactory extends (props: unknown) => infer R ? { (): Signal; (options: StateInjectionOptions): Signal; (options?: StateInjectionOptions): Signal | Signal; } : BasePrimitiveInjectionFn>; declare function createPrimitive unknown>(name: string, fn: TFactory, options?: CreatePrimitiveOptions): [ InjectionToken>>, TFactory, PrimitiveInjectionFn, (opts?: { inherit?: boolean; }) => FactoryProvider ]; /** * Wraps an external signal in a `linkedSignal` so it can be written to internally * while still re-syncing whenever the source input changes. * * Only use this when the primitive needs to mutate the value internally (e.g. a * setter, toggle, or other internal update) but must also remain in sync with the * input. If the value is read-only — passed straight through to bindings or exposed * to consumers without internal mutation — use the input signal directly instead. * * When `value` is `undefined`, falls back to a plain writable signal seeded with * `defaultValue`, supporting uncontrolled usage. * * @param value - The external signal to synchronize with * @param defaultValue - The default value to use when `value` is `undefined` * @returns A writable signal linked to the external signal */ declare function controlled(value: Signal): WritableSignal; declare function controlled(value: Signal | undefined, defaultValue: T): WritableSignal; interface ControlledStateOptions { /** * The controlled value signal. When defined (not `undefined`), the component * is in controlled mode and this value always wins. */ readonly value: Signal; /** * The default value signal for uncontrolled mode. */ readonly defaultValue?: Signal; /** * Callback fired when the value changes. */ readonly onChange?: (value: T) => void; } interface SetterOptions { /** * Whether to fire `onChange` and emit on the `change` observable. * Defaults to `true`. Set to `false` for cases like form `writeValue` * where the internal state should sync without notifying listeners. */ readonly emit?: boolean; } type ControlledState = [ value: Signal, set: (value: T, options?: SetterOptions) => void, change: Observable ]; declare function controlledState({ value, onChange, defaultValue, }: ControlledStateOptions): ControlledState; declare function attrBinding(element: ElementRef, attr: string, value: (() => string | number | boolean | null | undefined) | string | number | boolean | null | undefined): void; declare function styleBinding(element: ElementRef, style: string, value: (() => string | number | null) | string | number | null): void; declare function dataBinding(element: ElementRef, attr: string, value: (() => string | boolean | null) | string | boolean | null): void; declare function listener(element: HTMLElement | ElementRef | Document, event: K, handler: (event: HTMLElementEventMap[K]) => void, options?: { injector?: Injector; config?: AddEventListenerOptions | boolean; }): () => void; declare function listener(element: HTMLElement | ElementRef | Document, event: string, handler: (event: Event) => void, options?: { injector?: Injector; config?: AddEventListenerOptions | boolean; }): () => void; declare function onMount(callback: () => void): void; declare function onDestroy(callback: () => void): void; /** * Previously, with our state approach, we allowed signals to be written directly using their setters. * However, with our new approach, we want people to use the appropriate set method instead. This function takes in a writable * signal and returns a proxy that warns the user when set is called directly. */ declare function deprecatedSetter(signal: WritableSignal, methodName: string): WritableSignal; declare function deprecatedSetter(signal: Signal, methodName: string, setter: (value: T) => void): WritableSignal; /** * A utility function to inject an inherited state from a parent injector. This is useful for cases * where a primitive needs to inherit state from a parent primitive, such as in roving focus groups. * We could use inject with a forwardRef, but forwardRef returns an any - no thanks... */ declare function injectInheritedState(token: () => InjectionToken, injectOptions?: InjectOptions): T | null; interface Emitter { emit(value: T): void; asObservable(): Observable; } /** * An emitter is a simple wrapper around a Subject that ensures * that change detection is run when an event is emitted and that * the subject is automatically completed when the component is destroyed. */ declare function emitter({ injector, }?: { injector?: Injector; }): Emitter; export { attrBinding, controlled, controlledState, createPrimitive, createState, createStateInjector, createStateProvider, createStateToken, dataBinding, deprecatedSetter, emitter, injectInheritedState, listener, onDestroy, onMount, styleBinding }; export type { ControlledState, ControlledStateOptions, CreatePrimitiveOptions, CreateStateProviderOptions, CreatedState, Emitter, InjectedState, SetterOptions, State, StateInjectionOptions };