import { type PropertyValueMap, type TemplateResult } from "lit"; import { Router as Mux } from "sharekit"; import { GlobalStyle } from "../../internal/global-style.js"; interface RouteState { pathname: string; params: Record; path: string; } interface RouteResult extends RouteState { component: unknown; } interface RouteItem { [key: PropertyKey]: unknown; path: string; render?: (state?: RouteState) => unknown; component?: unknown; } declare const routerTypes: { readonly field: "field"; readonly slotted: "slotted"; readonly united: "united"; }; type RouterType = keyof typeof routerTypes; /** * {@linkcode Router} has basic routing control. * * To switch routes, use `router-link component`. * * It has two methods to collect routes. * * 1. From field `routes`, an array, each elements require "path". * 2. From child elements, which have the slot attribute for matching routes. * * If only the method 1 is used, set `type` to `"field"`. * * If only the method 2 is used, set `type` to `"slotted"`. * * `type` defaults to `"united"`, which will try method 1, then method 2. * * If no routes are matched, the default value (no named slot) will be rendered. * * @slot - Display slot when there is no match. * @slot * - Matching slot will be displayed. * @category navigation */ declare class Router extends GlobalStyle { static routerInstances: Set; private __fieldRoute; private __slottedRoute; private __cacheRecord; private __routes; /** * Render result. */ component: unknown | TemplateResult; /** * Dynamic parameters record. */ params?: Record; /** * Value of matched path in routes. */ path?: string; /** * Current pathname (equals to location.pathname). */ pathname: string; /** * Rendered content when there is no match. */ default: TemplateResult; /** * The type of routing sources. * * If field, it won't collect the slot attribute of the child elements. * * This property should not be changed after the rendering is complete. */ type: RouterType; /** * Cache accessed records. * * Emptied at each re-collection. */ cache: boolean; set routes(value: RouteItem[]); get routes(): RouteItem[]; clear(): void; protected render(): unknown; connectedCallback(): void; disconnectedCallback(): void; useRouter(): RouteResult; protected updated(changedProperties: PropertyValueMap): void; /** * Get component from {@linkcode routes} by query. */ fieldComponent(query?: string): unknown; /** * Get component from slotted elements by query. */ slottedComponent(query?: string): TemplateResult<1>; /** * Reset the route tree, clear cache, collect routes from child elements. */ collectSlottedRoutes(): void; /** * Reset the route tree, clear cache, collect routes from value. */ collectFieldRoutes(value: typeof this.routes): void; static updateAll(): void; search(pathname: string): Mux; handlePopstate: () => void; } export default Router; export { Router };