import { ComposableStyles } from '@microsoft/fast-element'; import { Constructable } from '@microsoft/fast-element'; import { ExecutionContext } from '@microsoft/fast-element'; import { FASTElement } from '@microsoft/fast-element'; import { HTMLDirective } from '@microsoft/fast-element'; import { ViewTemplate } from '@microsoft/fast-element'; /** * @internal */ export declare const childRouteParameter = "fast-child-route"; /** * @alpha */ export declare type CommandFallbackRouteDefinition = HasCommand & SupportsSettings & HasTitle; /** * @alpha */ export declare type CommandRouteDefinition = PathedRouteDefinition & HasCommand & HasTitle; /** * @alpha */ export declare class ConfigurableRoute implements Route { readonly path: string; readonly name: string; readonly caseSensitive: boolean; constructor(path: string, name: string, caseSensitive: boolean); } /** * @alpha */ export declare type ContributorOptions = { lifecycle?: boolean; parameters?: boolean; }; /** * @alpha */ export declare type ConverterObject = { convert: RouteParameterConverter; }; /** * @alpha */ export declare class DefaultLinkHandler implements LinkHandler { private handler; connect(): void; disconnect(): void; private getEventInfo; private findClosestAnchor; private targetIsThisWindow; } /** * @alpha */ export declare class DefaultNavigationProcess { private phases; run(router: Router, message: NavigationMessage): Promise; commit(phase: NavigationPhaseImpl): void; } /** * @alpha */ export declare class DefaultNavigationQueue implements NavigationQueue, NavigationHandler { private queue; private promise; private resolve; connect(): void; disconnect(): void; receive(): Promise; enqueue(msg: NavigationMessage): void; private tryDequeue; handleEvent(event: PopStateEvent): void; } /** * @alpha */ export declare class DefaultRouter implements Router { readonly host: HTMLElement; private parentRouter; private contributors; private navigationQueue; private linkHandler; private newView; private newRoute; private childCommandContributor; private childRoute; private isConnected; private routerConfig; private view; route: RecognizedRoute | null; constructor(host: HTMLElement); get config(): RouterConfiguration | null; set config(value: RouterConfiguration | null); get parent(): Router | null; get level(): number; shouldRender(route: RecognizedRoute): boolean; beginRender(route: RecognizedRoute, command: RenderCommand): Promise<{ commit: any; rollback: any; }>; connect(): void; disconnect(): void; addContributor(contributor: NavigationContributor): void; removeContributor(contributor: NavigationContributor): void; private tryConnect; private onNavigationMessage; private renderOperationCommit; private renderOperationRollback; private navigate; private leave; private construct; private enter; private commit; private tunnel; } /** * @alpha */ export declare class DefaultRouteRecognizer implements RouteRecognizer { private names; private paths; private readonly rootState; add(routeOrRoutes: Route | readonly Route[], settings?: TSettings): void; private $add; recognize(path: string, converters?: Readonly>): Promise | null>; /** * Generate a path and query string from a route name and params object. * * @param name - The name of the route to generate from. * @param params - The route params to use when populating the pattern. * Properties not required by the pattern will be appended to the query string. * @returns The generated absolute path and query string. */ generateFromName(name: string, params: object): string | null; /** * Generate a path and query string from a route path and params object. * * @param path - The path of the route to generate from. * @param params - The route params to use when populating the pattern. * Properties not required by the pattern will be appended to the query string. * @returns The generated absolute path and query string. */ generateFromPath(path: string, params: object): string | null; private generate; } /** * @alpha */ export declare type DefinitionCallback = () => Promise | FallbackRouteDefinition; /** * @alpha */ export declare type ElementFallbackRouteDefinition = LayoutAndTransitionRouteDefinition & HasElement & SupportsSettings & HasTitle; /** * @alpha */ export declare type ElementRouteDefinition = NavigableRouteDefinition & HasElement; /** * @alpha */ export declare class Endpoint { readonly route: ConfigurableRoute; readonly paramNames: readonly string[]; readonly paramTypes: readonly string[]; readonly settings: TSettings | null; constructor(route: ConfigurableRoute, paramNames: readonly string[], paramTypes: readonly string[], settings: TSettings | null); get path(): string; } /** * @alpha */ export declare type FallbackRouteDefinition = ElementFallbackRouteDefinition | TemplateFallbackRouteDefinition | Pick, "redirect"> | CommandFallbackRouteDefinition; /** * @alpha */ export declare type FASTElementConstructor = new () => FASTElement; /** * @alpha */ export declare class FASTElementLayout implements Layout { private readonly template; private runBeforeCommit; private styles; constructor(template?: ViewTemplate | null, styles?: ComposableStyles | ComposableStyles[] | null, runBeforeCommit?: boolean); beforeCommit(routerElement: HTMLElement): Promise; afterCommit(routerElement: HTMLElement): Promise; private apply; } /** * @alpha */ export declare class FASTRouter extends FASTRouter_base { } declare const FASTRouter_base: new () => FASTElement & RouterElement; /** * @alpha */ export declare type HasCommand = { command: NavigationCommand; }; /** * @alpha */ export declare type HasElement = { element: string | FASTElementConstructor | HTMLElement | (() => Promise); }; /** * @alpha */ export declare type HasTemplate = { template: ViewTemplate | (() => Promise); }; /** * @alpha */ export declare type HasTitle = { title?: string; }; /** * @alpha */ export declare type IgnorableRouteDefinition = PathedRouteDefinition; /** * @alpha */ export declare class Ignore implements NavigationCommand { createContributor(): Promise<{ navigate(phase: NavigationPhase): Promise; }>; } /** * @alpha */ export declare function isFASTElementHost(host: HTMLElement): host is HTMLElement & FASTElement; /** * @alpha */ export declare function isNavigationPhaseContributor(object: any, phase: T): object is Record; /** * @alpha */ export declare interface Layout { beforeCommit(routerElement: HTMLElement): Promise; afterCommit(routerElement: HTMLElement): Promise; } /** * @alpha */ export declare const Layout: Readonly<{ default: Readonly; }>; /** * @alpha */ export declare type LayoutAndTransitionRouteDefinition = { layout?: Layout | ViewTemplate; transition?: Transition; }; /** * @alpha */ export declare interface LinkHandler { connect(): void; disconnect(): void; } /** * @alpha */ export declare type MappableRouteDefinition = RenderableRouteDefinition | RedirectRouteDefinition | CommandRouteDefinition | ParentRouteDefinition; /** * @alpha */ export declare type NavigableRouteDefinition = PathedRouteDefinition & LayoutAndTransitionRouteDefinition & HasTitle & { childRouters?: boolean; }; /** * @alpha */ export declare interface NavigationCommand { createContributor(router: Router, route: RecognizedRoute): Promise; } /** * @alpha */ export declare interface NavigationCommitPhase extends Omit, "cancel" | "canceled" | "onCancel"> { setTitle(title: string): any; } /** * @alpha */ export declare type NavigationCommitPhaseHook = (phase: NavigationCommitPhase) => Promise | any; /** * @alpha */ export declare type NavigationContributor = Partial, NavigationPhaseHook>> & { commit?: NavigationCommitPhaseHook; }; /** * @alpha */ export declare function navigationContributor(options?: ContributorOptions): HTMLDirective; /** * @alpha */ export declare interface NavigationHandler { enqueue(msg: NavigationMessage): void; } /** * @alpha */ export declare const NavigationHandler: Readonly<{ register(handler: NavigationHandler): void; unregister(handler: NavigationHandler): void; }>; /** * @alpha */ export declare class NavigationMessage { path: string; constructor(path: string); } /** * @alpha */ export declare interface NavigationPhase { readonly name: NavigationPhaseName; readonly route: RecognizedRoute; readonly router: Router; readonly canceled: boolean; cancel(callback?: NavigationPhaseFollowupAction): void; onCancel(callback: NavigationPhaseFollowupAction): void; onCommit(callback: NavigationPhaseFollowupAction): void; evaluateContributor(contributor: any, route?: RecognizedRoute, router?: Router): Promise; } /** * @alpha */ export declare type NavigationPhaseFollowupAction = () => Promise | any; /** * @alpha */ export declare type NavigationPhaseHook = (phase: NavigationPhase) => Promise | any; declare class NavigationPhaseImpl implements NavigationCommitPhase { readonly name: NavigationPhaseName; private readonly commitActions; private readonly cancelActions; private routes; private routers; canceled: boolean; titles: Array>; get route(): RecognizedRoute; get router(): Router; constructor(name: NavigationPhaseName, route: RecognizedRoute, router: Router, commitActions: NavigationPhaseFollowupAction[], cancelActions: NavigationPhaseFollowupAction[]); cancel(callback?: NavigationPhaseFollowupAction): void; onCommit(callback: NavigationPhaseFollowupAction): void; onCancel(callback: NavigationPhaseFollowupAction): void; setTitle(title: string): void; evaluateContributor(contributor: any, route?: RecognizedRoute, router?: Router): Promise; } /** * @alpha */ export declare type NavigationPhaseName = "navigate" | "leave" | "construct" | "enter" | "commit"; /** * @alpha */ export declare interface NavigationProcess { run(router: Router, message: NavigationMessage): Promise; } /** * @alpha */ export declare interface NavigationQueue { connect(): void; disconnect(): void; receive(): Promise; } /** * @alpha */ export declare type ParameterConverter = RouteParameterConverter | ConverterObject | Constructable; /** * @alpha */ export declare type ParentRouteDefinition = PathedRouteDefinition & LayoutAndTransitionRouteDefinition & { children: MappableRouteDefinition[]; }; /** * @alpha */ export declare type PathedRouteDefinition = SupportsSettings & Route; /** * @alpha */ export declare const QueryString: Readonly<{ readonly current: string; /** * Generate a query string from an object. * * @param params - Object containing the keys and values to be used. * @param traditional - Boolean Use the old URI template standard (RFC6570) * @returns The generated query string, excluding leading '?'. */ build(params: Object, traditional?: boolean | undefined): string; /** * Separate the query string from the path and returns the two parts. * @param path - The path to separate. */ separate(path: string): Readonly<{ path: string; queryString: string; }>; /** * Parse a query string. * * @param queryString - The query string to parse. * @returns Object with keys and values mapped from the query string. */ parse(queryString: string): Readonly>; }>; /** * @alpha */ export declare class RecognizedRoute { readonly endpoint: Endpoint; readonly params: Readonly>; readonly typedParams: Readonly>; readonly queryParams: Readonly>; readonly allParams: Readonly>; readonly allTypedParams: Readonly>; constructor(endpoint: Endpoint, params: Readonly>, typedParams: Readonly>, queryParams: Readonly>); get settings(): TSettings | null; } /** * @alpha */ export declare class Redirect implements NavigationCommand { private redirect; constructor(redirect: string); createContributor(): Promise<{ navigate(phase: NavigationPhase): Promise; }>; } /** * @alpha */ export declare type RedirectRouteDefinition = PathedRouteDefinition & { redirect: string; }; /** * @alpha */ export declare class Render implements RenderCommand { private owner; createView: () => Promise; private _layout; private _transition; title: string; constructor(owner: RouterConfiguration, createView: () => Promise); get transition(): Transition; set transition(value: Transition); get layout(): Layout; set layout(value: Layout); createContributor(router: Router, route: RecognizedRoute): Promise; static fromDefinition(owner: RouterConfiguration, definition: ElementRouteDefinition | TemplateRouteDefinition | ElementFallbackRouteDefinition | TemplateFallbackRouteDefinition): Render; } /** * @alpha */ export declare type RenderableRouteDefinition = ElementRouteDefinition | TemplateRouteDefinition; /** * @alpha */ export declare interface RenderCommand extends NavigationCommand { layout: Layout; transition: Transition; createView(): Promise; } declare class RenderContributor { private router; private route; private command; private operation; constructor(router: Router, route: RecognizedRoute, command: Render); construct(phase: NavigationPhase): Promise; commit(phase: NavigationCommitPhase): Promise; } /** * @alpha */ export declare interface RenderOperation { commit(): Promise; rollback(): Promise; } /** * @alpha */ export declare interface Route { readonly path: string; readonly name?: string; readonly caseSensitive?: boolean; } /** * @alpha */ export declare const Route: Readonly<{ path: Readonly<{ readonly current: string; generateRoute(relativeTo: HTMLElement | Router, path: string, params?: Object): Promise; push(path: string, trigger?: boolean): void; replace(path: string, trigger?: boolean): void; trigger(path: string): void; }>; name: Readonly<{ generateRoute(relativeTo: HTMLElement | Router, name: string, params?: Object): Promise; push(relativeTo: HTMLElement | Router, name: string, params?: Object, trigger?: boolean): Promise; replace(relativeTo: HTMLElement | Router, name: string, params?: Object, trigger?: boolean): Promise; trigger(relativeTo: HTMLElement | Router, name: string, params?: Object): Promise; }>; }>; /** * @alpha */ export declare class RouteCollection { private owner; private _recognizer; private pathToCommand; private fallbackCommand; private fallbackSettings; private converters; constructor(owner: RouterConfiguration); private get recognizer(); ignore(definitionOrString: IgnorableRouteDefinition | string): void; map(...routes: MappableRouteDefinition[]): void; fallback(definitionOrCallback: FallbackRouteDefinition | DefinitionCallback): void; converter(name: string, converter: ParameterConverter): void; recognize(path: string): Promise | null>; /** * Generate a path and query string from a route name and params object. * * @param name - The name of the route to generate from. * @param params - The route params to use when populating the pattern. * Properties not required by the pattern will be appended to the query string. * @returns The generated absolute path and query string. */ generateFromName(name: string, params: object): string | null; /** * Generate a path and query string from a route path and params object. * * @param path - The path of the route to generate from. * @param params - The route params to use when populating the pattern. * Properties not required by the pattern will be appended to the query string. * @returns The generated absolute path and query string. */ generateFromPath(path: string, params: object): string | null; private aggregateConverters; } /** * @alpha */ export declare type RouteMatch = { route: RecognizedRoute; command: NavigationCommand; }; /** * @alpha */ export declare type RouteParameterConverter = (value: string | undefined) => any | Promise; /** * @alpha */ export declare interface Router { readonly level: number; readonly parent: Router | null; readonly route: RecognizedRoute | null; config: RouterConfiguration | null; connect(): void; disconnect(): void; shouldRender(route: RecognizedRoute): boolean; beginRender(route: RecognizedRoute, command: RenderCommand): Promise; addContributor(contributor: NavigationContributor): void; removeContributor(contributor: NavigationContributor): void; } /** * @alpha */ export declare const Router: Readonly<{ getOrCreateFor(element: HTMLElement): Router | DefaultRouter; find(element: HTMLElement): Router | null; from(BaseType: TBase): new () => InstanceType & RouterElement; }>; /** * @alpha */ export declare abstract class RouterConfiguration { private isConfigured; readonly routes: RouteCollection; readonly contributors: NavigationContributor[]; defaultLayout: Layout; defaultTransition: Readonly; title: string; parent: RouterConfiguration | null; createNavigationQueue(): NavigationQueue; createLinkHandler(): LinkHandler; createNavigationProcess(): NavigationProcess; createEventSink(): RoutingEventSink; createTitleBuilder(): TitleBuilder; createRouteRecognizer(): RouteRecognizer; construct(Type: Constructable): T; recognizeRoute(path: string): Promise | null>; /** * Generate a path and query string from a route name and params object. * * @param name - The name of the route to generate from. * @param params - The route params to use when populating the pattern. * Properties not required by the pattern will be appended to the query string. * @returns The generated absolute path and query string. */ generateRouteFromName(name: string, params: object): Promise; /** * Generate a path and query string from a route path and params object. * * @param path - The path of the route to generate from. * @param params - The route params to use when populating the pattern. * Properties not required by the pattern will be appended to the query string. * @returns The generated absolute path and query string. */ generateRouteFromPath(path: string, params: object): Promise; findContributors(phase: T): Record>[]; protected abstract configure(): Promise | void; protected cached(ElementType: new () => HTMLElement): () => Promise; private ensureConfigured; } /** * @alpha */ export declare interface RouteRecognizer { add(routeOrRoutes: Route | readonly Route[], settings?: TSettings): void; recognize(path: string, converters?: Readonly>): Promise | null>; generateFromName(name: string, params: object): string | null; generateFromPath(path: string, params: object): string | null; } /** * @alpha */ export declare interface RouterElement extends HTMLElement { readonly [routerProperty]: Router; config: RouterConfiguration | null; connectedCallback(): any; disconnectedCallback(): any; } /** * @alpha */ export declare type RouterExecutionContext = ExecutionContext & { router: Router; }; /** * @alpha */ export declare const RouterExecutionContext: Readonly<{ create(router: Router): any; }>; declare const routerProperty = "$router"; /** * @alpha */ export declare interface RouteView { bind(allTypedParams: Readonly>, context: RouterExecutionContext): void; appendTo(host: HTMLElement): void; dispose(): void; } /** * @alpha */ declare interface RoutingEventSink { onUnhandledNavigationMessage(router: Router, message: NavigationMessage): void; onNavigationBegin(router: Router, route: RecognizedRoute, command: NavigationCommand): void; onPhaseBegin(phase: NavigationPhase): void; onPhaseEnd(phase: NavigationPhase): void; onNavigationEnd(router: Router, route: RecognizedRoute, command: NavigationCommand): void; } /** * @alpha */ export declare type SupportsSettings = { settings?: TSettings; }; /** * @alpha */ export declare type TemplateFallbackRouteDefinition = LayoutAndTransitionRouteDefinition & HasTemplate & SupportsSettings & HasTitle; /** * @alpha */ export declare type TemplateRouteDefinition = NavigableRouteDefinition & HasTemplate; /** * @alpha */ declare interface TitleBuilder { joinTitles(parentTitle: string, childTitle: string): string; buildTitle(rootTitle: string, routeTitles: string[][]): string; } /** * @alpha */ export declare interface Transition { begin(host: HTMLElement, prev: RouteView | null, next: RouteView): Promise; rollback(host: HTMLElement, prev: RouteView | null, next: RouteView): Promise; commit(host: HTMLElement, prev: RouteView | null, next: RouteView): Promise; } /** * @alpha */ export declare const Transition: Readonly<{ default: Readonly; }>; export { }