/** * @typedef {Object} Assignment * @property {string} name of item the assignment is targeting * @property {string} url fragment to be assigned to the item */ /** * @typedef {Object} ParseNamedOutletAssignment * @property {string} elementTag * @property {Map} data * @property {Object} options * @property {string} options.import */ /** * @typedef {Object} NamedMatch * @property {string} name of the route or outlet to assign to * @property {string} url - The assignment url that was matched and consumed * @property {string} urlEscaped - The url that was matched and consumed escaped of certain characters that will break the url on servers. * @property {boolean} cancelled - If a failed attempt at assignment was made * @property {ParseNamedOutletAssignment} namedOutlet - Any named outlet assignments found */ /** * Registry for named routers and outlets. * Simplifies nested routing by being able to target specific routers and outlets in a link. * Can act as a message bus of sorts. Named items being the handlers and assignments as the messages. */ export class NamedRouting { /** * Adds a router or outlet to the registry * @param {import('./models').NamedRoutingHandler} item to add */ static addNamedItem(item: import('./models').NamedRoutingHandler): Promise; /** Removes an item by name from the registry if it exists. */ static removeNamedItem(name: any): void; /** Gets an item by name from the registry */ static getNamedItem(name: any): any; /** Gets an assignment from the registry */ static getAssignment(name: any): Assignment; /** * Add an assignment to the registry. Will override an assignment if one already exists with the same name. * @param {string} name the name of the named item to target with the assignment * @param {string} url to assign to the named item * @returns {Promise} when assignment is completed. false is returned if the assignment was cancelled for some reason. */ static addAssignment(name: string, url: string): Promise; /** Removes an assignment from the registry */ static removeAssignment(name: any): boolean; /** @returns {string} Serializes the current assignments into URL representation. */ static generateNamedItemsUrl(): string; /** Serializes an assignment for URL. */ static generateUrlFragment(assignment: any): string; /** * Parses a URL section and tries to get a named item from it. * @param {string} url containing the assignment and the named item * @param {boolean} [suppressAdding] of the assignment and only return the match in a dry run * @returns {Promise} null if not able to parse. If we are adding the named item then the promise is resolved when item is added and any routing has taken place. */ static parseNamedItem(url: string, suppressAdding?: boolean): Promise; /** * Takes a url for a named outlet assignment and parses * @param {string} url * @returns {ParseNamedOutletAssignment|null} null is returned if the url could not be parsed into a named outlet assignment */ static parseNamedOutletUrl(url: string): ParseNamedOutletAssignment | null; /** * @param {string} importStyleTagName * @param {string} elementTag * @returns {string} the custom element import path inferred from the import style string */ static inferCustomElementImportPath(importStyleTagName: string, elementTag: string): string; /** * @param {string} elementTag * @returns {string} the custom element tag name inferred from import style string */ static inferCustomElementTagName(elementTag: string): string; /** * Pre-fetches an import module so that it is available when the link is activated * @param {NamedMatch} namedAssignment item assignment * @returns {Promise} resolves when the import is completed */ static prefetchNamedOutletImports(namedAssignment: NamedMatch): Promise; /** * Imports a script for a customer element once the page has loaded * @param {string} importSrc * @param {string} tagName */ static prefetchImport(importSrc: string, tagName: string): Promise; /** * Imports a script for a customer element * @param {string} importSrc * @param {string} tagName */ static importCustomElement(importSrc: string, tagName: string): Promise; /** * */ static pageReady(): any; /** * Called just before leaving for another route. * Fires an event 'routeOnLeave' that can be cancelled by preventing default on the event. * @fires RouteElement#onRouteLeave * @param {*} newRoute - the new route being navigated to * @returns bool - if the currently active route can be left */ static canLeave(newRoute: any): boolean; } export namespace NamedRouting { const pageReadyPromise: any; const registry: {}; const assignments: { [k: string]: Assignment; }; } export type Assignment = { /** * of item the assignment is targeting */ name: string; /** * fragment to be assigned to the item */ url: string; }; export type ParseNamedOutletAssignment = { elementTag: string; data: Map; options: { import: string; }; }; export type NamedMatch = { /** * of the route or outlet to assign to */ name: string; /** * - The assignment url that was matched and consumed */ url: string; /** * - The url that was matched and consumed escaped of certain characters that will break the url on servers. */ urlEscaped: string; /** * - If a failed attempt at assignment was made */ cancelled: boolean; /** * - Any named outlet assignments found */ namedOutlet: ParseNamedOutletAssignment; };