import { defaultsDeep , get , omit } from './utils/fn.utils' ; import { NodeMenuItem } from './menu/node-menu.component' ; export class FoldingType { public static Expanded : FoldingType = new FoldingType ( 'node-expanded' ) ; public static Collapsed : FoldingType = new FoldingType ( 'node-collapsed' ) ; public static Empty : FoldingType = new FoldingType ( 'node-empty' ) ; public static Leaf : FoldingType = new FoldingType ( 'node-leaf' ) ; public constructor ( private _cssClass ) { } public get cssClass ( ) : string { return this . _cssClass ; } } export type ChildrenLoadingFunction = ( callback : ( children : TreeModel [ ] ) => void ) => void ; export interface TreeModel { value : string | RenamableNode ; id ? : string | number ; children ? : TreeModel [ ] ; loadChildren ? : ChildrenLoadingFunction ; settings ? : TreeModelSettings ; emitLoadNextLevel ? : boolean ; _status ? : TreeStatus ; _foldingType ? : FoldingType ; [ additionalData ] : any ; } export interface CssClasses { expanded ? : string ; collapsed ? : string ; empty ? : string ; leaf ? : string ; } export interface Templates { node ? : string ; leaf ? : string ; leftMenu ? : string ; } export class TreeModelSettings { public cssClasses ? : CssClasses ; public templates ? : Templates ; name type boolean default public leftMenu ? : boolean ; name type boolean default public rightMenu ? : boolean ; name type NodeMenuItem public menuItems ? : NodeMenuItem [ ] ; name type boolean default public static ? : boolean ; public isCollapsedOnInit ? : boolean ; public checked ? : boolean ; public selectionAllowed ? : boolean ; public static readonly NOT_CASCADING_SETTINGS = [ 'selectionAllowed' ] ; public static merge ( child , parent ) { const parentCascadingSettings = omit ( get ( parent , 'settings' ) , TreeModelSettings . NOT_CASCADING_SETTINGS ) ; return defaultsDeep ( { } , get ( child , 'settings' ) , parentCascadingSettings , { static : false , leftMenu : false , rightMenu : true , isCollapsedOnInit : false , checked : false , selectionAllowed : true } ) ; } } export class Ng2TreeSettings { name type boolean rootIsVisible ? = true ; showCheckboxes ? = false ; enableCheckboxes ? = true ; } export enum TreeStatus { New , Modified , IsBeingRenamed } export interface RenamableNode { param { string } name setName ( name ) : void ; returns { string } toString ( ) : string ; }