-
Notifications
You must be signed in to change notification settings - Fork 189
/
tree.types.ts
147 lines (119 loc) · 3.88 KB
/
tree.types.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
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: string) {}
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: string]: any;
}
export interface CssClasses {
/* The class or classes that should be added to the expanded node */
expanded?: string;
/* The class or classes that should be added to the collapsed node */
collapsed?: string;
/* The class or classes that should be added to the empty node */
empty?: string;
/* The class or classes that should be added to the expanded to the leaf */
leaf?: string;
}
export interface Templates {
/* A template for a node */
node?: string;
/* A template for a leaf node */
leaf?: string;
/* A template for left menu html element */
leftMenu?: string;
}
export class TreeModelSettings {
/* cssClasses - set custom css classes which will be used for a tree */
public cssClasses?: CssClasses;
/* Templates - set custom html templates to be used in a tree */
public templates?: Templates;
/**
* "leftMenu" property when set to true makes left menu available.
* @name TreeModelSettings#leftMenu
* @type boolean
* @default false
*/
public leftMenu?: boolean;
/**
* "rightMenu" property when set to true makes right menu available.
* @name TreeModelSettings#rightMenu
* @type boolean
* @default true
*/
public rightMenu?: boolean;
/**
* "menu" property when set will be available as custom context menu.
* @name TreeModelSettings#MenuItems
* @type NodeMenuItem
*/
public menuItems?: NodeMenuItem[];
/**
* "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 isCollapsedOnInit?: boolean;
public checked?: boolean;
public selectionAllowed?: boolean;
public keepNodesInDOM?: boolean;
public static readonly NOT_CASCADING_SETTINGS = ['selectionAllowed'];
public static merge(child: TreeModel, parent: TreeModel): TreeModelSettings {
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,
keepNodesInDOM: false,
selectionAllowed: true
});
}
}
export class Ng2TreeSettings {
/**
* Indicates root visibility in the tree. When true - root is invisible.
* @name Ng2TreeSettings#rootIsVisible
* @type boolean
*/
rootIsVisible? = true;
showCheckboxes? = false;
enableCheckboxes? = true;
}
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;
}