import * as i0 from '@angular/core'; import { TemplateRef, OnInit, OnDestroy, AfterContentInit } from '@angular/core'; import { SelectionModel } from '@angular/cdk/collections'; import { BehaviorSubject } from 'rxjs'; import * as i1 from '@angular/common'; import * as i2 from '@angular/forms'; import * as i3 from '@angular/cdk/scrolling'; /** * Representation of a node * T => data * string => id of a node * Element => dom element of a node * ITreeNodeHolder internal representation */ declare type INode = T | string | Element | ITreeNodeHolder; interface ITreeState { active: string; filter: ITreeFilter; expandedNodes: string[]; } interface ITreeFilter { term: string; } interface ITreeEdition { node: T; text: string; creation?: boolean; } /** * Keyboard event handlers */ interface ITreeKeyAction { /** * Original dom event (MouseEvent|KeyboardEvent). * If `event.preventDefault()` is not called, the typed character will be added/removed * to the current filter of the tree. */ event: KeyboardEvent; /** The node on which the action is called. (`null` for contextmenu on the tree itself ) */ node?: T; } /** Mouse event handlers */ interface ITreeMouseAction { /** original dom event (MouseEvent|KeyboardEvent) */ event: MouseEvent; /** The node on which the action is called. (`null` for contextmenu on the tree itself ) */ node?: T; } /** Maps mouse events, and key codes, to callbacks. */ interface ITreeActionMapping { keys?: { [k: string]: (e: ITreeKeyAction) => void; }; mouse?: { click?: (e: ITreeMouseAction) => void; rightClick?: (e: ITreeMouseAction) => void; }; } /** * Tree api. */ interface ITree { /** * Gets the selected nodes. */ selections(): T[]; /** * Gets the current focused node. */ focusedNode(): T | undefined; /** * Gets a value indicating whether `node` is selected. * @param node A reference to a node. * @throws {ReferenceError} if node is null. */ isSelected(node: INode): boolean; /** * Gets a value indicating whether `node` is the current focused node. * @param node A reference to a node. * @throws {ReferenceError} if node is null. */ isFocused(node: INode): boolean; /** * Gets a value indicating whether `node` is expanded. * @param node A reference to a node. * @throws {ReferenceError} if node is null. */ isExpanded(node: INode): boolean; /** * Sets `node` as the new focused node. * * Note: * The ancestors the of node will be expanded and the tree will scroll into the node. * @param node A reference to a node. */ focus(node: INode): void; /** Unfocus the current focused node */ unfocus(): void; /** * Expands the passed `node` with all its parents. * * Note: * This method will not select/focus the node. * * @param node A reference to a node. * @throws {ReferenceError} if node is null. */ expand(node: INode): void; /** * Expand the entire tree. */ expandAll(): void; /** * Collapses the given `node`. * * Note: * This method will not select/focus the node. * * @param node A reference to a node. * @throws {ReferenceError} if node is null. */ collapse(node: INode): void; /** * Collapse the entire tree */ collapseAll(): void; /** * Toggles the expanded/collapse state of the given node. * * Note: * This method will not select/focus the node. * * @param node A reference to a node. * @throws {ReferenceError} if node is null. */ toggle(node: INode): void; /** * Starts editing the given node. * @param node A reference to a node. * @param creation If true, an input will be displayed after the node to create a new child node. * @throws {ReferenceError} if `node` is null. */ startEdition(node: INode, creation?: boolean): void; /** * End the editing of the current node in a editing state. */ endEdition(): void; /** * Filter the tree using the given filter. * @param filter The filter to apply. */ search(filter: ITreeFilter): void; /** * Saves the tree as an object to be restored later * by calling `tree.restoreState()`. */ saveState(): ITreeState; /** * Restores the state of the tree from `state`. * @param state the state. */ restoreState(state: ITreeState): void; } /** * Adapter class to map a generic type T to an ITreeHolder * and attach event listeners to the tree instance. */ interface ITreeAdapter { /** * Unique identifier of the tree. * * This identifier is used to get a reference to the tree anywhere * by using `TreeService` class. */ id: string; /** Tree height (default 100%) */ treeHeight?: string; /** Item height (default 32) */ itemHeight?: number; /** * Function called to get the id of a node. */ idProvider: (node: T) => string; /** * Function called to get test whether a node is expandable. */ isExpandable: (node: T) => boolean; /** * Function called to get the display name of a node. */ nameProvider: (node: T) => string; /** * Function called to get the children of a node. */ childrenProvider: (node: T) => T[]; /** * Function called to get the display tooltip of a node. */ tooltipProvider?: (node: T) => string; /** * If enabled, this option will filter the tree * each time a keyboard key is pressed while the tree is focused. * * Note: * * The filter will be updated only if `preventDefault()` is not called * on the original KeyboardEvent by any of the event handlers. * */ enableKeyboardFiltering?: boolean; /** * Event called after a node is expanded in the tree. * @param e informations about the event. */ onDidExpand?: (e: T) => void; /** * Event called after a node is expanded in the tree. * @param e informations about the event. */ onDidCollapse?: (e: T) => void; /** * Event called after a node is edited in the tree. * @param e informations about the event. */ onDidEditName?: (e: ITreeEdition) => void; /** * Maps mouse events, and key codes, to callbacks. */ actions?: ITreeActionMapping; /** Should the tree keep the expands state when the nodes change? (default to `true`)*/ keepStateOnChangeNodes?: boolean; } /** Internal representation of a node */ interface ITreeNodeHolder { /** A unique key of this node. */ id: string; /** Reference to the original data. */ data: T; /** display name of the node */ name: string; /** Level in the tree (starts from 0). */ level: number; /** A value indicating whether the node is expandable */ expandable: boolean; /** Optional tooltip to show when the node is hovered */ tooltip?: string; padding: string; /** A value indicating whether the node is focused */ focused?: boolean; /** A value indicating whether the node is expanded */ expanded?: boolean; /** A value indicating whether the node is selected */ selected?: boolean; /** A value indicating whether the node is in creating state. */ creating?: boolean; /** A value indicating whether the node is in renaming state. */ renaming?: boolean; } declare class TreeFilter implements ITreeFilter { term: string; constructor(term?: string); } declare class TreeState implements ITreeState { active: string; expandedNodes: string[]; filter: ITreeFilter; constructor(active?: string, expandedNodes?: string[], filter?: ITreeFilter); } declare type Context = { $implicit: ITreeNodeHolder; }; /** Element that can be used as a template for a `TreeComponent` */ declare class TreeNodeDirective { readonly templateRef: TemplateRef>; static ngTemplateContextGuard(_: TreeNodeDirective, ctx: any): ctx is Context; static ɵfac: i0.ɵɵFactoryDeclaration, never>; static ɵdir: i0.ɵɵDirectiveDeclaration, "[treeNode], ui-tree-node", never, {}, {}, never, never, true, never>; } /** * Minimal flat-tree expansion control, replacing the deprecated `FlatTreeControl` * from `@angular/cdk/tree` (removed in a future Angular). The component owns and * renders the flat `dataNodes` list; expansion is tracked by node identity in a * `SelectionModel` (selected = expanded). */ declare class FlatTreeControl { /** The flattened tree nodes, in display order. */ dataNodes: T[]; /** Selected entries are the expanded nodes. */ readonly expansionModel: SelectionModel; isExpanded(node: T): boolean; expand(node: T): void; collapse(node: T): void; expandAll(): void; collapseAll(): void; } declare class TreeComponent implements ITree, OnInit, OnDestroy { private readonly elementRef; private readonly changeDetectorRef; readonly nodes: i0.InputSignal; readonly adapter: i0.InputSignal>; protected readonly nodeDirective: i0.Signal>; private readonly DATA_TREE_NODE_ID; private readonly nodesIndex; private readonly parentsIndex; private readonly hiddenNodes; private readonly selectedNodes; private isEmpty; private isShiftKeyPressed; private activeNode?; private stateBeforeSearching; protected editing: Partial>; protected readonly visibleNodes: BehaviorSubject[]>; readonly filter: ITreeFilter; readonly controler: FlatTreeControl>; protected get treeHeight(): string; constructor(); ngOnInit(): void; private syncFromInputs; ngOnDestroy(): void; selections(): T[]; focusedNode(): T | undefined; isFocused(node: INode): boolean; isExpanded(node: INode): boolean; isSelected(node: INode): boolean; focus(node: INode, render?: boolean): void; unfocus(): void; expand(node: INode, render?: boolean): void; expandAll(render?: boolean): void; collapse(node: INode, render?: boolean): void; collapseAll(render?: boolean): void; toggle(node: INode, render?: boolean): void; startEdition(node: INode, creation?: boolean): void; endEdition(): void; search(filter: ITreeFilter): void; saveState(): ITreeState; restoreState(state: ITreeState): void; protected _onEdit(event: Event): void; protected _clearFilter(): void; protected _isRenaming(node: INode): boolean; protected _isCreating(node: INode): boolean; keyup(): void; keydown($event: KeyboardEvent): void; mousedown($event: MouseEvent): void; contextmenu($event: MouseEvent): void; private onKeyDown; private onMouseDown; private onContextMenu; private isTreeContainsEvent; private triggerFilterEvent; private triggerKeyboardEvent; private render; private buildIndexes; private buildSearchPattern; /** * Gets the dom element associated to the given node. * @param e A node. */ private domNode; /** * Adds the given node to the selected nodes. * @param node The node to select. */ private select; /** * Removes the given node to the selected nodes. * @param node The node to unselect. */ private unselect; /** * Clears the selected nodes. */ private unselectAll; /** * Expands the ancestors of the given node. * @param node A node reference. */ private expandAncestors; /** * Call the given `action` for the ancestors of the given node. * @param node A node reference. * @param action A function to call for each ancestor. */ private iterateAncestors; /** * Moves the scrollbar to the given node. * @param node The node to show. */ private scrollInto; /** * Focus the node before of after `currEl` depending on the given `direction`. * @param currEl Current element * @param direction Navigation direction. */ private navigate; private findParent; private findHolderFromId; private findHolderFromData; private findHolderFromEvent; private findHolderFromElement; private findHolder; /** * Flattens the nested `nodes` into a depth-first list of holders, recursing into * the children of expandable nodes (mirrors the former MatTreeFlattener). The flat * list is what `FlatTreeControl` and the rest of the component operate on. */ private flattenNodes; private children; private transformer; static ɵfac: i0.ɵɵFactoryDeclaration, never>; static ɵcmp: i0.ɵɵComponentDeclaration, "ui-tree", never, { "nodes": { "alias": "nodes"; "required": false; "isSignal": true; }; "adapter": { "alias": "adapter"; "required": true; "isSignal": true; }; }, {}, ["nodeDirective"], never, true, never>; } declare class AutofocusDirective implements AfterContentInit { private readonly el; ngAfterContentInit(): void; static ɵfac: i0.ɵɵFactoryDeclaration; static ɵdir: i0.ɵɵDirectiveDeclaration; } declare class NgeUiTreeModule { static ɵfac: i0.ɵɵFactoryDeclaration; static ɵmod: i0.ɵɵNgModuleDeclaration; static ɵinj: i0.ɵɵInjectorDeclaration; } declare class TreeService { /** * Gets the tree identified by `id` if the tree is visible. * @param id Identifier of a tree. */ get(id: string): ITree | undefined; static ɵfac: i0.ɵɵFactoryDeclaration; static ɵprov: i0.ɵɵInjectableDeclaration; } export { NgeUiTreeModule, TreeComponent, TreeFilter, TreeNodeDirective, TreeService, TreeState }; export type { Context, INode, ITree, ITreeActionMapping, ITreeAdapter, ITreeEdition, ITreeFilter, ITreeKeyAction, ITreeMouseAction, ITreeNodeHolder, ITreeState };