import { RawParams, Transition, TransitionOptions } from "@uirouter/core"; import { noChange, nothing, AttributePart } from "lit"; import { PartInfo } from "lit/directive.js"; import type { DirectiveResult } from "lit/directive.js"; import type { ClassInfo } from "lit/directives/class-map.js"; import { AsyncDirective } from "lit/async-directive.js"; import { UIRouterLit } from "./core.js"; import { SrefTargets } from "./sref-status.js"; import { UiSrefTargetEvent } from "./ui-sref.js"; import { AriaCurrentValue, AriaCurrentValues, SrefStatus, TransEvt } from "./ui-sref-active.js"; import { UiView } from "./ui-view.js"; /** * Which state an attribute-part active directive watches. Name a state, or * leave it out to watch the {@link srefHref} links inside the element instead * (container mode, as {@link uiSrefActive} does). * * @category types */ export interface SrefTargetParams { /** The state name to check for active status */ state?: string; /** State parameters to match */ params?: RawParams; /** Transition options; `relative` defaults to the enclosing view's state */ options?: TransitionOptions; } /** * What {@link srefActiveClass} and {@link srefAriaCurrent} share: a target * (named, or gathered from enclosed links), the router subscriptions that * recompute its {@link SrefStatus}, and the push of each new value into the * attribute. * * `render()` is a function of `status` and the params alone. A server renderer * runs it without `update()`, so it seeds `status` from the call-scoped router * first; with no router in reach the value stays `noChange` and the attribute * is left as authored. * * @category directives */ export declare abstract class SrefStatusDirective extends AsyncDirective { protected readonly directiveName: string; /** @internal */ element: Element | null; /** @internal */ uiRouter: UIRouterLit | undefined; /** @internal */ parentView: UiView | null; /** the last params `update()` saw */ params: Params | undefined; /** merged status of every target, or `undefined` before there is one */ status: SrefStatus | undefined; /** * the named target, or the enclosed links' targets in container mode * @internal */ protected readonly targets: SrefTargets; private _firstUpdated; private _deregister; /** bumped on disconnect, so a settlement subscribed before it stays quiet */ private _connection; /** the attribute this directive is bound in, for warnings */ private readonly attributeName; /** * @param directiveName the public function's name, for errors and warnings * @internal */ constructor(partInfo: PartInfo, directiveName: string); /** the value for `status` and `params` as they stand */ abstract render(params: Params): unknown; /** * What `update()` and a status change hand to the part: `render()`, or * `noChange` once the directive keeps the DOM in sync itself. * * @internal */ protected abstract commit(): unknown; /** * The status to render: the one `update()` already computed, or — when * `update()` never ran, as in a server render — one seeded from the router * the enclosing `withRouterSync` scoped, by building the named target and * merging its status. Container mode has no links to merge and stays * `undefined`. * * A directive instance that only ever renders resolves this at most once. * * @internal */ protected getScopedStatus(params: Params): SrefStatus | undefined; /** @internal */ update(part: AttributePart, [params]: [Params]): unknown; /** @internal */ firstUpdated(): void; /** @internal */ onUiSrefTargetEvent: (event: UiSrefTargetEvent) => void; /** @internal */ onUiSrefTargetRemovedEvent: (event: Event) => void; /** * A `TargetState` pins its definition when built, so one made before its * state was registered stays non-existent: rebuild every target first. * * @internal */ onStatesChanged: () => void; /** @internal */ onTransitionStart: (trans: Transition) => void; /** * Recomputes `status` and pushes the result into the attribute. * * @internal */ refresh(event?: TransEvt): void; /** @internal */ disconnected(): void; /** @internal */ reconnected(): void; } /** * Parameters for {@link srefActiveClass}. * * @category types */ export interface SrefActiveClassParams extends SrefTargetParams { /** CSS classes to add when the state (or a child state) is active */ activeClasses?: string[]; /** CSS classes to add only when the exact state is active */ exactClasses?: string[]; /** * Other classes to toggle by their value's truthiness, as * {@link https://lit.dev/docs/templates/directives/#classmap | classMap} * takes them. A `class` attribute holds one toggling directive, so this is * where `classMap`'s argument goes when it shares the attribute with ours. * A name listed here and in `activeClasses` applies when either says so. */ classes?: ClassInfo; } /** * The attribute-part sibling of {@link UiSrefActiveDirective}'s class * handling, with the contract of lit's * {@link https://lit.dev/docs/templates/directives/#classmap | classMap}: * bound in `class`, alone or beside static classes, and toggling only the * classes it names. * * The first commit writes the whole class list — statics plus whichever of * ours apply — as `classMap` does, which is also what a server rendering * `render()` alone would emit. Every commit after that toggles names on * `classList`, so classes something else added to the element survive. * * @see {@link srefActiveClass} for the public API * * @category directives */ export declare class SrefActiveClassDirective extends SrefStatusDirective { /** classes the template wrote around the expression; never toggled */ private _staticClasses; /** our classes on the element as of the last commit; `undefined` before one */ private _previousClasses; /** @internal */ constructor(partInfo: PartInfo); /** each named class with whether it applies now */ private classInfo; /** * The classes that apply, space-padded to keep clear of the statics; or * `noChange` before a status exists. */ render(params: SrefActiveClassParams): string | typeof noChange; /** @internal */ update(part: AttributePart, args: [SrefActiveClassParams]): unknown; /** @internal */ protected commit(): unknown; } /** * Parameters for {@link srefAriaCurrent}. * * @category types */ export interface SrefAriaCurrentParams extends SrefTargetParams { /** * The token to write while the **exact** state is active — `'page'` by * default — or an object that also names one for an active ancestor: * `{ exact: 'page', active: 'location' }`. See {@link AriaCurrentValues}. */ value?: AriaCurrentValue | AriaCurrentValues; } /** * The attribute-part sibling of {@link UiSrefActiveDirective}'s * `aria-current` handling. * * @see {@link srefAriaCurrent} for the public API * * @category directives */ export declare class SrefAriaCurrentDirective extends SrefStatusDirective { /** whether a status was ever written, so losing every target clears it */ private _wrote; /** @internal */ constructor(partInfo: PartInfo); /** @internal */ protected commit(): unknown; /** * The token for the current status, `nothing` to remove the attribute, or * `noChange` before a status exists. */ render(params: SrefAriaCurrentParams): AriaCurrentValue | typeof nothing | typeof noChange; } /** * Toggles classes in a `class` attribute by the active state: the * attribute-part form of {@link uiSrefActive}'s classes. * * It follows lit's * {@link https://lit.dev/docs/templates/directives/#classmap | classMap}: it * must be bound in `class`, alone or next to static classes, and it only ever * toggles the classes it names. Name the state to watch, or leave `state` out * on a wrapper to watch the {@link srefHref} links inside it. * * It cannot share the attribute with `classMap` — lit rewrites the whole * value when either expression changes, so one directive has to own it. Pass * what `classMap` would have taken as `classes` instead. For a component that * wants plain `classMap` and its own bindings, use * {@link SrefStatusController}. * * Unlike `uiSrefActive`, this writes no `aria-current` — a `class` binding * cannot reach another attribute. Bind {@link srefAriaCurrent} beside it. * * @example * ```ts * import { srefHref, srefActiveClass } from 'lit-ui-router'; * import { html } from 'lit'; * * html` * Users * ` * ``` * * @example In place of classMap * ```ts * html`Users` * ``` * * @example Container mode * ```ts * html`
  • * Users *
  • ` * ``` * * @see {@link uiSrefActive} * @see {@link srefAriaCurrent} * @see {@link SrefStatusController} * * @category directives */ export declare const srefActiveClass: (params: SrefActiveClassParams) => DirectiveResult; /** * Binds `aria-current` to the active state: the attribute-part form of * {@link uiSrefActive}'s `aria-current`. * * Binding the attribute is the opt-in, so there is none of `uiSrefActive`'s * link detection or takeover: the value is `'page'` while the exact state is * active and the attribute is absent otherwise, whatever the element. Pass * `value` for another token, or `{ exact, active }` to mark an ancestor too. * * @example * ```ts * import { srefHref, srefAriaCurrent } from 'lit-ui-router'; * import { html } from 'lit'; * * html` * Payment * ` * ``` * * @see {@link uiSrefActive} * @see {@link srefActiveClass} * @see {@link SrefStatusController} * * @category directives */ export declare const srefAriaCurrent: (params: SrefAriaCurrentParams) => DirectiveResult; //# sourceMappingURL=sref-active.d.ts.map