import { TargetState, UIRouter } from "@uirouter/core"; import { nothing, ReactiveController, ReactiveControllerHost } from "lit"; import type { SrefTargetParams } from "./sref-active.js"; import { AriaCurrentValue, AriaCurrentValues, SrefStatus, TransEvt } from "./ui-sref-active.js"; /** * Options for {@link SrefStatusController}: which state to watch, plus the * router to watch it in. * * @category controllers */ export interface SrefStatusControllerOptions extends SrefTargetParams { /** * The {@link UIRouter} instance to observe. * * When omitted, the controller discovers the router from an ancestor * <ui-router> (or <ui-view>) via the * `ui-router-context` event when the host connects. * * Passing it explicitly also moves the first status computation into the * constructor, so the status is there for the very first render and needs * no DOM — the hand-off an element-less environment has no other way to * make. */ router?: UIRouter; } /** * A Lit * {@link https://lit.dev/docs/composition/controllers/ | ReactiveController} * that exposes a state's {@link SrefStatus} — `active`, `exact`, `entering`, * `exiting` — to its host, so the host's own template decides what to do * with it. * * This is the composition path {@link srefActiveClass} cannot offer: a * `class` attribute holds one toggling directive, so `srefActiveClass` and * {@link https://lit.dev/docs/templates/directives/#classmap | classMap} * cannot share it. Read the flags here instead and pass them to `classMap`, * to `aria-current`, to a `?disabled`, to anything. * * The controller registers its hooks when the host connects and deregisters * them on `hostDisconnected`, so nothing leaks when hosts come and go. It * calls `host.requestUpdate()` only when one of the four flags or the watched * targets actually changed, so transitions that leave the link alone cost no * render. * * @example Composing with classMap and aria-current * ```ts * import { html, LitElement } from 'lit'; * import { classMap } from 'lit/directives/class-map.js'; * import { srefHref, SrefStatusController } from 'lit-ui-router'; * * class NavLink extends LitElement { * private users = new SrefStatusController(this, { state: 'users' }); * * render() { * return html`Users`; * } * } * ``` * * @example With an explicit router instance * ```ts * // status is computed in the constructor, before the host ever connects * const status = new SrefStatusController(host, { state: 'users', router }); * ``` * * @example Re-target from a property setter * ```ts * class NavLink extends LitElement { * private status = new SrefStatusController(this); * * @property() set state(state: string) { * this.status.retarget({ state }); * } * } * ``` * * @example Container mode: watch the links in the host's template * ```ts * class NavSection extends LitElement { * // no `state`: every srefHref link below feeds this controller * private section = new SrefStatusController(this); * * render() { * return html`
  • * Users * New *
  • `; * } * } * ``` * * @see {@link srefActiveClass} * @see {@link srefAriaCurrent} * @see {@link SrefStatus} * * @category controllers */ export declare class SrefStatusController implements ReactiveController { private readonly host; private options; private readonly targets; private readonly deregisterFns; private _status; /** whether a status has ever been computed, so the first one always renders */ private computed; /** bumped on disconnect, so a settlement subscribed before it stays quiet */ private _connection; constructor(host: ReactiveControllerHost & Element, options?: SrefStatusControllerOptions); /** * The observed {@link UIRouter} instance. * * `undefined` until provided via * {@link SrefStatusControllerOptions.router} or discovered from an ancestor * <ui-router> on connect. */ get router(): UIRouter | undefined; /** * The merged {@link SrefStatus} of every watched target, or `undefined` while * there is no router or no target. */ get status(): SrefStatus | undefined; /** The target state, or a child of it, is active. */ get active(): boolean; /** The target state is itself the active state. */ get exact(): boolean; /** A transition in flight is entering the target state. */ get entering(): boolean; /** A transition in flight is exiting the target state. */ get exiting(): boolean; /** The states being watched: the named one, or the enclosed links'. */ get targetStates(): TargetState[]; /** * Points the controller at another state — for a host that takes the state * as a property. Replaces `state`, `params` and `options` wholesale, keeps * the router, and refreshes. */ retarget(params: SrefTargetParams): void; /** * The `aria-current` token for the current status, or `nothing` to leave * the attribute off — {@link srefAriaCurrent}'s rules, as a value to bind: * `'page'` while the exact state is active, nothing otherwise. * * @param value another token, or `{ exact, active }` to mark an active * ancestor too. See {@link AriaCurrentValues}. */ ariaCurrent(value?: AriaCurrentValue | AriaCurrentValues): AriaCurrentValue | typeof nothing; /** @internal */ hostConnected(): void; /** @internal */ hostDisconnected(): void; /** * Recomputes the status and re-renders the host, but only if a flag or a * watched target moved. * * @internal */ refresh(event?: TransEvt): void; /** the new status, and whether the host needs to see it */ private compute; private readonly onUiSrefTargetEvent; private readonly onUiSrefTargetRemovedEvent; private readonly onStatesChanged; private readonly onTransitionStart; } //# sourceMappingURL=sref-status-controller.d.ts.map