import { ImmutableTree } from '@youwol/rx-tree-views'; import { Router } from './router'; import { Observable } from 'rxjs'; import { AnyVirtualDOM, AttributeLike, ChildrenLike, ChildLike } from '@youwol/rx-vdom'; /** * Defines attributes regarding the visual rendering of the node if the navigation view. */ export type Decoration = { /** * Optional class added as wrapper to the HTML element representing the node. */ wrapperClass?: AttributeLike; /** * Optional icon, inserted before the node's name. */ icon?: ChildLike; /** * Optional actions, inserted after the node's name. */ actions?: ChildrenLike; }; /** * Fully resolved navigation node when using {@link CatchAllNav}. * In practical usage, consumers of the library only needs to provide {@link NavNodeInput}. */ export type NavNodeParams = { /** * Id of the node. */ id: string; /** * Name of the node. */ name: string; /** * Hyperlink reference. */ href: string; /** * Optional data associated to the node. */ data?: unknown; /** * Optional children. */ children?: NavNodeBase[] | Observable; /** * Optional decoration. */ decoration?: Decoration; }; export declare class NavNodeBase extends ImmutableTree.Node { readonly name: string; readonly href: string; readonly data: unknown; readonly decoration?: Decoration; protected constructor(parameters: NavNodeParams); } export declare class NavNode extends NavNodeBase { constructor(parameters: NavNodeParams); } export declare class NavNodePromise extends NavNodeBase { constructor({ href }: { href: string; }); } /** * Arguments defining the children part of a navigation node when using dynamic {@link CatchAllNav}. */ export type NavNodeInput = Omit & { /** * Whether the node is a leaf (no children expected). */ leaf?: boolean; }; export declare function createNavNode({ hrefBase, path, node, asyncChildren, router, }: { hrefBase: string; path: string; node: NavNodeInput; asyncChildren: LazyNavResolver; router: Router; }): any; export declare function createImplicitChildren$({ resolver, hrefBase, withExplicit, router, path, }: { resolver: LazyNavResolver; path: string; hrefBase: string; withExplicit: NavNode[]; router: Router; }): any; export declare function createChildren({ navigation, hRefBase, router, reactiveNavs, promiseNavs, }: { navigation: Navigation; hRefBase: string; router: Router; reactiveNavs: { [_href: string]: Observable; }; promiseNavs: { [_href: string]: Promise; }; }): any; export declare function createRootNode({ navigation, router, hrefBase, }: { navigation: Navigation; router: Router; hrefBase?: string; }): { rootNode: NavNode; reactiveNavs: { [k: string]: ReactiveLazyNavResolver; }; promiseNavs: { [k: string]: Promise; }; }; /** * Represents something resolvable. * * Important: * When an observable is provided, only its **first emission** is accounted. */ export type Resolvable = T | Promise | Observable; /** * The common part of a navigation node, whether it is static or dynamic. */ export type NavigationCommon = { /** * This function represents the view of the main content. * * @param router Router instance. * @returns A resolvable view */ html: ({ router }: { router: any; }) => Resolvable; /** * This function represents the view of the table of content in the page. * * @param p arguments of the view generator: * * html : Content of the HTML page * * router : Router instance. * @returns A promise on the view */ tableOfContent?: (p: { html: HTMLElement; router: Router; }) => Promise; }; /** * Node definition when using implicit 'catch-all' sub-navigation resolver, * see {@link Navigation}. */ export type CatchAllNav = Resolvable; /** * Represents a lazy navigation resolver, used when the navigation is only known at runtime. * * It is a function that takes the target path and router's instance as parameters, and returns * the instance of {@link CatchAllNav} that explicits node attributes (`name`, `id`, `children`, *etc.*). */ export type LazyNavResolver = (p: { path: string; router: Router; }) => CatchAllNav; /** * Represents a reactive lazy navigation resolver, used when changes in a navigation node children are expected * (within {@link Navigation}). */ export type ReactiveLazyNavResolver = Observable; /** * Key representing an implicit 'catch-all' navigation referenced in {@link Navigation}. * */ export declare const CatchAllKey = "..."; /** * Represents a node in the navigation. */ export type Navigation = NavigationCommon & { /** * Name of the node. */ name: string; /** * Decoration configuration for the node. */ decoration?: Decoration; /** * Dynamic 'catch-all' sub-navigation resolver, used when the navigation is only known at runtime. * * The sub-paths defined in it can also be made reaction (using {@link ReactiveLazyNavResolver}) * if changes in organisation over time are expected. */ [CatchAllKey]?: LazyNavResolver | ReactiveLazyNavResolver; /** * Static sub-navigation resolver. */ [key: `/${string}`]: Navigation | Promise; }; /** * Sanitize an input navigation path: * * Remove starting '/' (multiple too) * * Correct for empty path sequence, *e.g.* `foo//bar/.baz` -> `foo/bar.baz` * * @param path The input path. * @returns The sanitized path. */ export declare function sanitizeNavPath(path: string): string;