UNPKG

ng2-tree-hackaday

Version:

angular2 component for visualizing data that can be naturally represented as a tree

70 lines (58 loc) 1.91 kB
import * as _ from 'lodash'; export class FoldingType { public static Expanded: FoldingType = new FoldingType('node-expanded'); public static Collapsed: FoldingType = new FoldingType('node-collapsed'); public static Leaf: FoldingType = new FoldingType('node-leaf'); public constructor(private _cssClass: string) { } public get cssClass(): string { return this._cssClass; } } export type ChildrenLoadingFunction = (callback: (children: TreeModel[]) => void) => void; export interface TreeModel { isFolder?: boolean; value: string | RenamableNode; children?: TreeModel[]; loadChildren?: ChildrenLoadingFunction; settings?: TreeModelSettings; _status?: TreeStatus; _foldingType?: FoldingType; } export class TreeModelSettings { /** * "static" property when set to true makes it impossible to drag'n'drop tree or call a menu on it. * @name TreeModelSettings#static * @type boolean * @default false */ public static?: boolean; public static merge(sourceA: TreeModel, sourceB: TreeModel): TreeModelSettings { return _.defaults({}, _.get(sourceA, 'settings'), _.get(sourceB, 'settings'), {static: false}); } } export interface Ng2TreeSettings { /** * Indicates root visibility in the tree. When true - root is invisible. * @name Ng2TreeSettings#rootIsVisible * @type boolean */ rootIsVisible?: boolean; } export enum TreeStatus { New, Modified, IsBeingRenamed } export interface RenamableNode { /** * Set new value of the renamable node. Implementation of this method is up to user. * @param {string} name - A new value of the node. */ setName(name: string): void; /** * Get string representation of the node. Implementation of this method is up to user. * @returns {string} - A node string representation. */ toString(): string; }