UNPKG

11.6 kBTypeScriptView Raw
1import { Observable } from 'rxjs/Observable';
2import { FoldingType, RenamableNode, TreeModel } from './tree.types';
3import { NodeMenuItem } from './menu/node-menu.component';
4export declare class Tree {
5 private _children;
6 private _loadChildren;
7 private _childrenLoadingState;
8 private _childrenAsyncOnce;
9 node: TreeModel;
10 parent: Tree;
11 /**
12 * Check that value passed is not empty (it doesn't consist of only whitespace symbols).
13 * @param {string} value - A value that should be checked.
14 * @returns {boolean} - A flag indicating that value is empty or not.
15 * @static
16 */
17 static isValueEmpty(value: string): boolean;
18 /**
19 * Check whether a given value can be considered RenamableNode.
20 * @param {any} value - A value to check.
21 * @returns {boolean} - A flag indicating whether given value is Renamable node or not.
22 * @static
23 */
24 static isRenamable(value: any): value is RenamableNode;
25 private static cloneTreeShallow(origin);
26 private static applyNewValueToRenamable(value, newValue);
27 /**
28 * Build an instance of Tree from an object implementing TreeModel interface.
29 * @param {TreeModel} model - A model that is used to build a tree.
30 * @param {Tree} [parent] - An optional parent if you want to build a tree from the model that should be a child of an existing Tree instance.
31 * @param {boolean} [isBranch] - An option that makes a branch from created tree. Branch can have children.
32 */
33 constructor(node: TreeModel, parent?: Tree, isBranch?: boolean);
34 private buildTreeFromModel(model, parent, isBranch);
35 hasDeferredChildren(): boolean;
36 loadingChildrenRequested(): void;
37 /**
38 * Check whether children of the node are being loaded.
39 * Makes sense only for nodes that define `loadChildren` function.
40 * @returns {boolean} A flag indicating that children are being loaded.
41 */
42 childrenAreBeingLoaded(): boolean;
43 /**
44 * Check whether children of the node were loaded.
45 * Makes sense only for nodes that define `loadChildren` function.
46 * @returns {boolean} A flag indicating that children were loaded.
47 */
48 childrenWereLoaded(): boolean;
49 private canLoadChildren();
50 /**
51 * Check whether children of the node should be loaded and not loaded yet.
52 * Makes sense only for nodes that define `loadChildren` function.
53 * @returns {boolean} A flag indicating that children should be loaded for the current node.
54 */
55 childrenShouldBeLoaded(): boolean;
56 /**
57 * Get children of the current tree.
58 * @returns {Tree[]} The children of the current tree.
59 */
60 readonly children: Tree[];
61 /**
62 * By getting value from this property you start process of loading node's children using `loadChildren` function.
63 * Once children are loaded `loadChildren` function won't be called anymore and loaded for the first time children are emitted in case of subsequent calls.
64 * @returns {Observable<Tree[]>} An observable which emits children once they are loaded.
65 */
66 readonly childrenAsync: Observable<Tree[]>;
67 /**
68 * By calling this method you start process of loading node's children using `loadChildren` function.
69 */
70 reloadChildren(): void;
71 /**
72 * By calling this method you will remove all current children of a treee and create new.
73 */
74 setChildren(children: Array<TreeModel>): void;
75 /**
76 * Create a new node in the current tree.
77 * @param {boolean} isBranch - A flag that indicates whether a new node should be a "Branch". "Leaf" node will be created by default
78 * @param {TreeModel} model - Tree model of the new node which will be inserted. Empty node will be created by default and it will fire edit mode of this node
79 * @returns {Tree} A newly created child node.
80 */
81 createNode(isBranch: boolean, model?: TreeModel): Tree;
82 /**
83 * Get the value of the current node
84 * @returns {(string|RenamableNode)} The value of the node.
85 */
86 /**
87 * Set the value of the current node
88 * @param {(string|RenamableNode)} value - The new value of the node.
89 */
90 value: any;
91 checked: boolean;
92 readonly checkedChildren: Tree[];
93 selectionAllowed: boolean;
94 hasLoadedChildern(): boolean;
95 loadedChildrenAmount(): number;
96 checkedChildrenAmount(): number;
97 /**
98 * Add a sibling node for the current node. This won't work if the current node is a root.
99 * @param {Tree} sibling - A node that should become a sibling.
100 * @param [number] position - Position in which sibling will be inserted. By default it will be inserted at the last position in a parent.
101 * @returns {Tree} A newly inserted sibling, or null if you are trying to make a sibling for the root.
102 */
103 addSibling(sibling: Tree, position?: number): Tree;
104 /**
105 * Add a child node for the current node.
106 * @param {Tree} child - A node that should become a child.
107 * @param [number] position - Position in which child will be inserted. By default it will be inserted at the last position in a parent.
108 * @returns {Tree} A newly inserted child.
109 */
110 addChild(child: Tree, position?: number): Tree;
111 private _addChild(child, position?);
112 /**
113 * Swap position of the current node with the given sibling. If node passed as a parameter is not a sibling - nothing happens.
114 * @param {Tree} sibling - A sibling with which current node shold be swapped.
115 */
116 swapWithSibling(sibling: Tree): void;
117 /**
118 * Get a node's position in its parent.
119 * @returns {number} The position inside a parent.
120 */
121 readonly positionInParent: number;
122 /**
123 * Check whether or not this tree is static.
124 * @returns {boolean} A flag indicating whether or not this tree is static.
125 */
126 isStatic(): boolean;
127 /**
128 * Check whether or not this tree has a left menu.
129 * @returns {boolean} A flag indicating whether or not this tree has a left menu.
130 */
131 hasLeftMenu(): boolean;
132 /**
133 * Check whether or not this tree has a right menu.
134 * @returns {boolean} A flag indicating whether or not this tree has a right menu.
135 */
136 hasRightMenu(): boolean;
137 /**
138 * Check whether this tree is "Leaf" or not.
139 * @returns {boolean} A flag indicating whether or not this tree is a "Leaf".
140 */
141 isLeaf(): boolean;
142 /**
143 * Get menu items of the current tree.
144 * @returns {NodeMenuItem[]} The menu items of the current tree.
145 */
146 readonly menuItems: NodeMenuItem[];
147 /**
148 * Check whether or not this tree has a custom menu.
149 * @returns {boolean} A flag indicating whether or not this tree has a custom menu.
150 */
151 hasCustomMenu(): boolean;
152 /**
153 * Check whether this tree is "Branch" or not. "Branch" is a node that has children.
154 * @returns {boolean} A flag indicating whether or not this tree is a "Branch".
155 */
156 isBranch(): boolean;
157 /**
158 * Check whether this tree has children.
159 * @returns {boolean} A flag indicating whether or not this tree has children.
160 */
161 hasChildren(): boolean;
162 /**
163 * Check whether this tree is a root or not. The root is the tree (node) that doesn't have parent (or technically its parent is null).
164 * @returns {boolean} A flag indicating whether or not this tree is the root.
165 */
166 isRoot(): boolean;
167 /**
168 * Check whether provided tree is a sibling of the current tree. Sibling trees (nodes) are the trees that have the same parent.
169 * @param {Tree} tree - A tree that should be tested on a siblingness.
170 * @returns {boolean} A flag indicating whether or not provided tree is the sibling of the current one.
171 */
172 hasSibling(tree: Tree): boolean;
173 /**
174 * Check whether provided tree is a child of the current tree.
175 * This method tests that provided tree is a <strong>direct</strong> child of the current tree.
176 * @param {Tree} tree - A tree that should be tested (child candidate).
177 * @returns {boolean} A flag indicating whether provided tree is a child or not.
178 */
179 hasChild(tree: Tree): boolean;
180 /**
181 * Remove given tree from the current tree.
182 * The given tree will be removed only in case it is a direct child of the current tree (@see {@link hasChild}).
183 * @param {Tree} tree - A tree that should be removed.
184 */
185 removeChild(tree: Tree): void;
186 /**
187 * Remove current tree from its parent.
188 */
189 removeItselfFromParent(): void;
190 /**
191 * Switch folding type of the current tree. "Leaf" node cannot switch its folding type cause it doesn't have children, hence nothing to fold.
192 * If node is a "Branch" and it is expanded, then by invoking current method state of the tree should be switched to "collapsed" and vice versa.
193 */
194 switchFoldingType(): void;
195 /**
196 * Check that tree is expanded.
197 * @returns {boolean} A flag indicating whether current tree is expanded. Always returns false for the "Leaf" tree and for an empty tree.
198 */
199 isNodeExpanded(): boolean;
200 /**
201 * Check that tree is collapsed.
202 * @returns {boolean} A flag indicating whether current tree is collapsed. Always returns false for the "Leaf" tree and for an empty tree.
203 */
204 isNodeCollapsed(): boolean;
205 /**
206 * Set a current folding type: expanded, collapsed or leaf.
207 */
208 private _setFoldingType();
209 /**
210 * Get a current folding type: expanded, collapsed or leaf.
211 * @returns {FoldingType} A folding type of the current tree.
212 */
213 readonly foldingType: FoldingType;
214 /**
215 * Get a css class for element which displayes folding state - expanded, collapsed or leaf
216 * @returns {string} A string icontaining css class (classes)
217 */
218 readonly foldingCssClass: string;
219 private getCssClassesFromSettings();
220 /**
221 * Get a html template to render before every node's name.
222 * @returns {string} A string representing a html template.
223 */
224 readonly nodeTemplate: string;
225 private getTemplateFromSettings();
226 /**
227 * Get a html template to render for an element activatin left menu of a node.
228 * @returns {string} A string representing a html template.
229 */
230 readonly leftMenuTemplate: string;
231 disableCollapseOnInit(): void;
232 isCollapsedOnInit(): boolean;
233 keepNodesInDOM(): any;
234 /**
235 * Check that current tree is newly created (added by user via menu for example). Tree that was built from the TreeModel is not marked as new.
236 * @returns {boolean} A flag whether the tree is new.
237 */
238 isNew(): boolean;
239 id: number | string;
240 /**
241 * Mark current tree as new (@see {@link isNew}).
242 */
243 markAsNew(): void;
244 /**
245 * Check that current tree is being renamed (it is in the process of its value renaming initiated by a user).
246 * @returns {boolean} A flag whether the tree is being renamed.
247 */
248 isBeingRenamed(): boolean;
249 /**
250 * Mark current tree as being renamed (@see {@link isBeingRenamed}).
251 */
252 markAsBeingRenamed(): void;
253 /**
254 * Check that current tree is modified (for example it was renamed).
255 * @returns {boolean} A flag whether the tree is modified.
256 */
257 isModified(): boolean;
258 /**
259 * Mark current tree as modified (@see {@link isModified}).
260 */
261 markAsModified(): void;
262 /**
263 * Makes a clone of an underlying TreeModel instance
264 * @returns {TreeModel} a clone of an underlying TreeModel instance
265 */
266 toTreeModel(): TreeModel;
267}