import { Observable, Subject } from 'rxjs'; import { AnyVirtualDOM } from '@youwol/rx-vdom'; import { Navigation, NavigationCommon, NavNodeBase } from './navigation.node'; import { ImmutableTree } from '@youwol/rx-tree-views'; /** * Gathers the resolved elements when navigating to a specific path. */ export type Destination = { /** * The table of content view. */ tableOfContent?: HTMLElement | AnyVirtualDOM; /** * The main page view. */ html: HTMLElement | AnyVirtualDOM; /** * The typedocNodes's ID if provided in the URL. */ sectionId?: string; }; /** * A simple proxy for mocking browser navigation to new URL. * Can be useful in testing or documenting contexts where actual re-location is not desirable. */ export interface MockBrowserLocation { /** * Initial path. */ initialPath: string; /** * History of navigation. */ history?: { url: string; data: unknown; }[]; } export declare const headingPrefixId = "mk-head-"; /** * Represents the router of the application. */ export declare class Router { /** * The base path on which the router is defined. * * If the application is served from `https://my-domain/my-app/version` it is `/my-app/version`. */ readonly basePath: string; /** * When using a dynamic definition of the routes (see {@link Navigation}), * it may be the case that the routes are not yet available when navigating to a page. * Attempt to re-navigate to the page is executed every `retryNavPeriod` second. */ readonly retryNavPeriod: number; /** * Definition of the navigation. */ readonly navigation: Navigation; /** * Handles navigation redirections. * * This function is invoked whenever a specific path is requested for navigation. * It allows modifying the target path before the navigation occurs. * * @param target - The requested path that the user intends to navigate to. * @returns The modified path to navigate to, or the original path if no changes are needed. * If `undefined` is returned, the navigation will be canceled. */ readonly redirects: (target: string) => Promise; /** * Observable that emit the current main HTML page. */ readonly currentHtml$: Subject; /** * Observable that emit the current page. */ readonly currentPage$: Subject; /** * Observable that emit the current navigation node. */ readonly currentNode$: Subject; /** * Observable that emit the current navigation path. */ readonly currentPath$: Subject; /** * Encapsulates the state of the navigation view (node selected, expanded, *etc.*) */ readonly explorerState: ImmutableTree.State; scrollableElement: HTMLElement; readonly htmlUpdated$: Subject; readonly status: Record<'Warning' | 'Error', { [k: string]: unknown[]; }>; private navUpdates; private navResolved; /** * If this attribute is set, navigation to nodes do not trigger browser re-location. * * See {@link MockBrowserLocation}. */ readonly mockBrowserLocation?: MockBrowserLocation; /** * Initialize a router instance. * * @param params See corresponding documentation in the class's attributes. * @param params.navigation See {@link Router.navigation}. * @param params.basePath Deprecated should not be used. * @param params.retryNavPeriod See {@link Router.retryNavPeriod}. * @param params.redirects See {@link Router.redirects}. * @param params.mockBrowserLocation See {@link Router.mockBrowserLocation}. */ constructor(params: { navigation: Navigation; basePath?: string; retryNavPeriod?: number; redirects?: (target: string) => Promise; mockBrowserLocation?: { initialPath: string; }; }); /** * Returns the current navigation path. */ getCurrentPath(): string; /** * Returns the parent path of the current navigation path. */ getParentPath(): string; navigateTo({ path }: { path: string; }): void; /** * Navigate to a specific path. * * @param path The path to navigate to. */ private awaitNavigateTo; /** * Navigate to the parent node. */ navigateToParent(): void; /** * Scroll the main HTML content to focus on an HTML element. * * @param target The target HTML element, or its id. */ scrollTo(target: string | HTMLElement): void; refresh({ resolverPath, path, redirectTo, }: { resolverPath: string; path?: string; redirectTo?: string; }): void; /** * Retrieves the navigation node corresponding to a given path, or `undefined` if it does not exist. * * @param path The target path. */ getNav({ path, }: { path: string; }): Observable | undefined; private expand; setDisplayedPage({ page }: { page: HTMLElement; }): void; /** * Clients need to invoke this function when dynamic change on the current main HTML page have occurred after the * initial rendering. Other views dependening on it (*e.g.* the table of content) will refresh as well. */ emitHtmlUpdated(): void; private bindReactiveNavs; private bindPromiseNavs; }