UNPKG

20.4 kBTypeScriptView Raw
1import { Message } from '@phosphor/messaging';
2import { MenuPath, SelectionService } from '../../common';
3import { ContextMenuRenderer } from '../context-menu-renderer';
4import { StatefulWidget } from '../shell';
5import { Widget } from '../widgets';
6import { TreeNode, CompositeTreeNode } from './tree';
7import { TreeModel } from './tree-model';
8import { ExpandableTreeNode } from './tree-expansion';
9import { SelectableTreeNode } from './tree-selection';
10import { TreeDecoratorService, TreeDecoration } from './tree-decorator';
11import { ReactWidget } from '../widgets/react-widget';
12import * as React from 'react';
13import { VirtuosoHandle } from 'react-virtuoso';
14import { SearchBox, SearchBoxFactory } from './search-box';
15import { TreeSearch } from './tree-search';
16import { MaybePromise } from '../../common/types';
17import { LabelProvider } from '../label-provider';
18import { CorePreferences } from '../core-preferences';
19import { TreeFocusService } from './tree-focus-service';
20export declare const TREE_CLASS = "theia-Tree";
21export declare const TREE_CONTAINER_CLASS = "theia-TreeContainer";
22export declare const TREE_NODE_CLASS = "theia-TreeNode";
23export declare const TREE_NODE_CONTENT_CLASS = "theia-TreeNodeContent";
24export declare const TREE_NODE_INFO_CLASS = "theia-TreeNodeInfo";
25export declare const TREE_NODE_TAIL_CLASS = "theia-TreeNodeTail";
26export declare const TREE_NODE_SEGMENT_CLASS = "theia-TreeNodeSegment";
27export declare const TREE_NODE_SEGMENT_GROW_CLASS = "theia-TreeNodeSegmentGrow";
28export declare const EXPANDABLE_TREE_NODE_CLASS = "theia-ExpandableTreeNode";
29export declare const COMPOSITE_TREE_NODE_CLASS = "theia-CompositeTreeNode";
30export declare const TREE_NODE_CAPTION_CLASS = "theia-TreeNodeCaption";
31export declare const TREE_NODE_INDENT_GUIDE_CLASS = "theia-tree-node-indent";
32export declare const TreeProps: unique symbol;
33/**
34 * Representation of tree properties.
35 */
36export interface TreeProps {
37 /**
38 * The path of the context menu that one can use to contribute context menu items to the tree widget.
39 */
40 readonly contextMenuPath?: MenuPath;
41 /**
42 * The size of the padding (in pixels) per hierarchy depth. The root element won't have left padding but
43 * the padding for the children will be calculated as `leftPadding * hierarchyDepth` and so on.
44 */
45 readonly leftPadding: number;
46 readonly expansionTogglePadding: number;
47 /**
48 * `true` if the tree widget support multi-selection. Otherwise, `false`. Defaults to `false`.
49 */
50 readonly multiSelect?: boolean;
51 /**
52 * `true` if the tree widget support searching. Otherwise, `false`. Defaults to `false`.
53 */
54 readonly search?: boolean;
55 /**
56 * `true` if the tree widget should be virtualized searching. Otherwise, `false`. Defaults to `true`.
57 */
58 readonly virtualized?: boolean;
59 /**
60 * `true` if the selected node should be auto scrolled only if the widget is active. Otherwise, `false`. Defaults to `false`.
61 */
62 readonly scrollIfActive?: boolean;
63 /**
64 * `true` if a tree widget contributes to the global selection. Defaults to `false`.
65 */
66 readonly globalSelection?: boolean;
67 /**
68 * `true` if the tree widget supports expansion only when clicking the expansion toggle. Defaults to `false`.
69 */
70 readonly expandOnlyOnExpansionToggleClick?: boolean;
71}
72/**
73 * Representation of node properties.
74 */
75export interface NodeProps {
76 /**
77 * A root relative number representing the hierarchical depth of the actual node. Root is `0`, its children have `1` and so on.
78 */
79 readonly depth: number;
80}
81/**
82 * The default tree properties.
83 */
84export declare const defaultTreeProps: TreeProps;
85export declare namespace TreeWidget {
86 /**
87 * Bare minimum common interface of the keyboard and the mouse event with respect to the key maskings.
88 */
89 interface ModifierAwareEvent {
90 /**
91 * Determines if the modifier aware event has the `meta` key masking.
92 */
93 readonly metaKey: boolean;
94 /**
95 * Determines if the modifier aware event has the `ctrl` key masking.
96 */
97 readonly ctrlKey: boolean;
98 /**
99 * Determines if the modifier aware event has the `shift` key masking.
100 */
101 readonly shiftKey: boolean;
102 }
103}
104export declare class TreeWidget extends ReactWidget implements StatefulWidget {
105 readonly props: TreeProps;
106 readonly model: TreeModel;
107 protected readonly contextMenuRenderer: ContextMenuRenderer;
108 protected searchBox: SearchBox;
109 protected searchHighlights: Map<string, TreeDecoration.CaptionHighlight>;
110 protected readonly decoratorService: TreeDecoratorService;
111 protected readonly treeSearch: TreeSearch;
112 protected readonly searchBoxFactory: SearchBoxFactory;
113 protected readonly focusService: TreeFocusService;
114 protected decorations: Map<string, TreeDecoration.Data[]>;
115 protected readonly selectionService: SelectionService;
116 protected readonly labelProvider: LabelProvider;
117 protected readonly corePreferences: CorePreferences;
118 protected shouldScrollToRow: boolean;
119 constructor(props: TreeProps, model: TreeModel, contextMenuRenderer: ContextMenuRenderer);
120 protected init(): void;
121 /**
122 * Update the global selection for the tree.
123 */
124 protected updateGlobalSelection(): void;
125 protected rows: Map<string, TreeWidget.NodeRow>;
126 protected updateRows: any;
127 protected doUpdateRows(): void;
128 protected getDepthForNode(node: TreeNode, depths: Map<CompositeTreeNode | undefined, number>): number;
129 protected toNodeRow(node: TreeNode, index: number, depth: number): TreeWidget.NodeRow;
130 protected shouldDisplayNode(node: TreeNode): boolean;
131 /**
132 * Row index to ensure visibility.
133 * - Used to forcefully scroll if necessary.
134 */
135 protected scrollToRow: number | undefined;
136 /**
137 * Update the `scrollToRow`.
138 * @param updateOptions the tree widget force update options.
139 */
140 protected updateScrollToRow(): void;
141 protected scheduleUpdateScrollToRow: any;
142 /**
143 * Get the `scrollToRow`.
144 *
145 * @returns the `scrollToRow` if available.
146 */
147 protected getScrollToRow(): number | undefined;
148 /**
149 * Update tree decorations.
150 * - Updating decorations are debounced in order to limit the number of expensive updates.
151 */
152 protected readonly updateDecorations: any;
153 protected doUpdateDecorations(): Promise<void>;
154 protected onActivateRequest(msg: Message): void;
155 /**
156 * Actually focus the tree node.
157 */
158 protected doFocus(): void;
159 /**
160 * Get the tree node to focus.
161 *
162 * @returns the node to focus if available.
163 */
164 protected getNodeToFocus(): SelectableTreeNode | undefined;
165 protected onUpdateRequest(msg: Message): void;
166 protected onResize(msg: Widget.ResizeMessage): void;
167 protected render(): React.ReactNode;
168 /**
169 * Create the container attributes for the widget.
170 */
171 protected createContainerAttributes(): React.HTMLAttributes<HTMLElement>;
172 /**
173 * Get the container tree node.
174 *
175 * @returns the tree node for the container if available.
176 */
177 protected getContainerTreeNode(): TreeNode | undefined;
178 protected ScrollingRowRenderer: React.FC<{
179 rows: TreeWidget.NodeRow[];
180 }>;
181 protected view: TreeWidget.View | undefined;
182 /**
183 * Render the tree widget.
184 * @param model the tree model.
185 */
186 protected renderTree(model: TreeModel): React.ReactNode;
187 scrollArea: Element;
188 /**
189 * Scroll to the selected tree node.
190 */
191 protected scrollToSelected(): void;
192 /**
193 * Render the node row.
194 */
195 protected readonly renderNodeRow: (row: TreeWidget.NodeRow) => React.ReactNode;
196 /**
197 * Actually render the node row.
198 */
199 protected doRenderNodeRow({ node, depth }: TreeWidget.NodeRow): React.ReactNode;
200 /**
201 * Render the tree node given the node properties.
202 * @param node the tree node.
203 * @param props the node properties.
204 */
205 protected renderIcon(node: TreeNode, props: NodeProps): React.ReactNode;
206 /**
207 * Toggle the node.
208 */
209 protected readonly toggle: (event: React.MouseEvent<HTMLElement>) => void;
210 /**
211 * Actually toggle the tree node.
212 * @param event the mouse click event.
213 */
214 protected doToggle(event: React.MouseEvent<HTMLElement>): void;
215 /**
216 * Render the node expansion toggle.
217 * @param node the tree node.
218 * @param props the node properties.
219 */
220 protected renderExpansionToggle(node: TreeNode, props: NodeProps): React.ReactNode;
221 /**
222 * Render the tree node caption given the node properties.
223 * @param node the tree node.
224 * @param props the node properties.
225 */
226 protected renderCaption(node: TreeNode, props: NodeProps): React.ReactNode;
227 protected getCaptionAttributes(node: TreeNode, props: NodeProps): React.Attributes & React.HTMLAttributes<HTMLElement>;
228 protected getCaptionChildren(node: TreeNode, props: NodeProps): React.ReactNode;
229 /**
230 * Update the node given the caption and highlight.
231 * @param caption the caption.
232 * @param highlight the tree decoration caption highlight.
233 */
234 protected toReactNode(caption: string, highlight: TreeDecoration.CaptionHighlight): React.ReactNode[];
235 /**
236 * Decorate the tree caption.
237 * @param node the tree node.
238 * @param attrs the additional attributes.
239 */
240 protected decorateCaption(node: TreeNode, attrs: React.HTMLAttributes<HTMLElement>): React.Attributes & React.HTMLAttributes<HTMLElement>;
241 /**
242 * Determine if the tree node contains trailing suffixes.
243 * @param node the tree node.
244 *
245 * @returns `true` if the tree node contains trailing suffices.
246 */
247 protected hasTrailingSuffixes(node: TreeNode): boolean;
248 /**
249 * Apply font styles to the tree.
250 * @param original the original css properties.
251 * @param fontData the optional `fontData`.
252 */
253 protected applyFontStyles(original: React.CSSProperties, fontData: TreeDecoration.FontData | undefined): React.CSSProperties;
254 /**
255 * Render caption affixes for the given tree node.
256 * @param node the tree node.
257 * @param props the node properties.
258 * @param affixKey the affix key.
259 */
260 protected renderCaptionAffixes(node: TreeNode, props: NodeProps, affixKey: 'captionPrefixes' | 'captionSuffixes'): React.ReactNode;
261 /**
262 * Decorate the tree node icon.
263 * @param node the tree node.
264 * @param icon the icon.
265 */
266 protected decorateIcon(node: TreeNode, icon: React.ReactNode): React.ReactNode;
267 /**
268 * Render the tree node tail decorations.
269 * @param node the tree node.
270 * @param props the node properties.
271 */
272 protected renderTailDecorations(node: TreeNode, props: NodeProps): React.ReactNode;
273 protected renderTailDecorationsForNode(node: TreeNode, props: NodeProps, tailDecorations: TreeDecoration.TailDecoration.AnyPartial[]): React.ReactNode;
274 /**
275 * Determine the classes to use for an icon
276 * - Assumes a Font Awesome name when passed a single string, otherwise uses the passed string array
277 * @param iconName the icon name or list of icon names.
278 * @param additionalClasses additional CSS classes.
279 *
280 * @returns the icon class name.
281 */
282 protected getIconClass(iconName: string | string[], additionalClasses?: string[]): string;
283 /**
284 * Render indent for the file tree based on the depth
285 * @param node the tree node.
286 * @param depth the depth of the tree node.
287 */
288 protected renderIndent(node: TreeNode, props: NodeProps): React.ReactNode;
289 protected needsActiveIndentGuideline(node: TreeNode): boolean;
290 /**
291 * Render the node given the tree node and node properties.
292 * @param node the tree node.
293 * @param props the node properties.
294 */
295 protected renderNode(node: TreeNode, props: NodeProps): React.ReactNode;
296 /**
297 * Create node attributes for the tree node given the node properties.
298 * @param node the tree node.
299 * @param props the node properties.
300 */
301 protected createNodeAttributes(node: TreeNode, props: NodeProps): React.Attributes & React.HTMLAttributes<HTMLElement>;
302 /**
303 * Create the node class names.
304 * @param node the tree node.
305 * @param props the node properties.
306 *
307 * @returns the list of tree node class names.
308 */
309 protected createNodeClassNames(node: TreeNode, props: NodeProps): string[];
310 protected rowIsSelected(node: TreeNode, props: NodeProps): boolean;
311 /**
312 * Get the default node style.
313 * @param node the tree node.
314 * @param props the node properties.
315 *
316 * @returns the CSS properties if available.
317 */
318 protected getDefaultNodeStyle(node: TreeNode, props: NodeProps): React.CSSProperties | undefined;
319 protected getPaddingLeft(node: TreeNode, props: NodeProps): number;
320 /**
321 * If the node is a composite, a toggle will be rendered.
322 * Otherwise we need to add the width and the left, right padding => 18px
323 */
324 protected needsExpansionTogglePadding(node: TreeNode): boolean;
325 /**
326 * Create the tree node style.
327 * @param node the tree node.
328 * @param props the node properties.
329 */
330 protected createNodeStyle(node: TreeNode, props: NodeProps): React.CSSProperties | undefined;
331 /**
332 * Decorate the node style.
333 * @param node the tree node.
334 * @param style the optional CSS properties.
335 *
336 * @returns the CSS styles if available.
337 */
338 protected decorateNodeStyle(node: TreeNode, style: React.CSSProperties | undefined): React.CSSProperties | undefined;
339 /**
340 * Determine if the tree node is expandable.
341 * @param node the tree node.
342 *
343 * @returns `true` if the tree node is expandable.
344 */
345 protected isExpandable(node: TreeNode): node is ExpandableTreeNode;
346 /**
347 * Get the tree node decorations.
348 * @param node the tree node.
349 *
350 * @returns the list of tree decoration data.
351 */
352 protected getDecorations(node: TreeNode): TreeDecoration.Data[];
353 /**
354 * Get the tree decoration data for the given key.
355 * @param node the tree node.
356 * @param key the tree decoration data key.
357 *
358 * @returns the tree decoration data at the given key.
359 */
360 protected getDecorationData<K extends keyof TreeDecoration.Data>(node: TreeNode, key: K): Required<Pick<TreeDecoration.Data, K>>[K][];
361 /**
362 * Store the last scroll state.
363 */
364 protected lastScrollState: {
365 /**
366 * The scroll top value.
367 */
368 scrollTop: number;
369 /**
370 * The scroll left value.
371 */
372 scrollLeft: number;
373 } | undefined;
374 /**
375 * Get the scroll container.
376 */
377 protected getScrollContainer(): MaybePromise<HTMLElement>;
378 protected onAfterAttach(msg: Message): void;
379 /**
380 * Handle the `left arrow` keyboard event.
381 * @param event the `left arrow` keyboard event.
382 */
383 protected handleLeft(event: KeyboardEvent): Promise<void>;
384 /**
385 * Handle the `right arrow` keyboard event.
386 * @param event the `right arrow` keyboard event.
387 */
388 protected handleRight(event: KeyboardEvent): Promise<void>;
389 /**
390 * Handle the `up arrow` keyboard event.
391 * @param event the `up arrow` keyboard event.
392 */
393 protected handleUp(event: KeyboardEvent): void;
394 /**
395 * Handle the `down arrow` keyboard event.
396 * @param event the `down arrow` keyboard event.
397 */
398 protected handleDown(event: KeyboardEvent): void;
399 /**
400 * Handle the `enter key` keyboard event.
401 * - `enter` opens the tree node.
402 * @param event the `enter key` keyboard event.
403 */
404 protected handleEnter(event: KeyboardEvent): void;
405 /**
406 * Handle the `space key` keyboard event.
407 * - By default should be similar to a single-click action.
408 * @param event the `space key` keyboard event.
409 */
410 protected handleSpace(event: KeyboardEvent): void;
411 protected handleEscape(event: KeyboardEvent): void;
412 /**
413 * Handle the single-click mouse event.
414 * @param node the tree node if available.
415 * @param event the mouse single-click event.
416 */
417 protected handleClickEvent(node: TreeNode | undefined, event: React.MouseEvent<HTMLElement>): void;
418 /**
419 * The effective handler of an unmodified single-click event.
420 */
421 protected tapNode(node?: TreeNode): void;
422 /**
423 * Handle the double-click mouse event.
424 * @param node the tree node if available.
425 * @param event the double-click mouse event.
426 */
427 protected handleDblClickEvent(node: TreeNode | undefined, event: React.MouseEvent<HTMLElement>): void;
428 /**
429 * Handle the context menu click event.
430 * - The context menu click event is triggered by the right-click.
431 * @param node the tree node if available.
432 * @param event the right-click mouse event.
433 */
434 protected handleContextMenuEvent(node: TreeNode | undefined, event: React.MouseEvent<HTMLElement>): void;
435 /**
436 * Handle the double-click mouse event on the expansion toggle.
437 */
438 protected readonly handleExpansionToggleDblClickEvent: (event: React.MouseEvent<HTMLElement>) => void;
439 /**
440 * Actually handle the double-click mouse event on the expansion toggle.
441 * @param event the double-click mouse event.
442 */
443 protected doHandleExpansionToggleDblClickEvent(event: React.MouseEvent<HTMLElement>): void;
444 /**
445 * Convert the tree node to context menu arguments.
446 * @param node the selectable tree node.
447 */
448 protected toContextMenuArgs(node: SelectableTreeNode): any[] | undefined;
449 /**
450 * Determine if the tree modifier aware event has a `ctrlcmd` mask.
451 * @param event the tree modifier aware event.
452 *
453 * @returns `true` if the tree modifier aware event contains the `ctrlcmd` mask.
454 */
455 protected hasCtrlCmdMask(event: TreeWidget.ModifierAwareEvent): boolean;
456 /**
457 * Determine if the tree modifier aware event has a `shift` mask.
458 * @param event the tree modifier aware event.
459 *
460 * @returns `true` if the tree modifier aware event contains the `shift` mask.
461 */
462 protected hasShiftMask(event: TreeWidget.ModifierAwareEvent): boolean;
463 /**
464 * Deflate the tree node for storage.
465 * @param node the tree node.
466 */
467 protected deflateForStorage(node: TreeNode): object;
468 /**
469 * Inflate the tree node from storage.
470 * @param node the tree node.
471 * @param parent the optional tree node.
472 */
473 protected inflateFromStorage(node: any, parent?: TreeNode): TreeNode;
474 /**
475 * Store the tree state.
476 */
477 storeState(): object;
478 /**
479 * Restore the state.
480 * @param oldState the old state object.
481 */
482 restoreState(oldState: object): void;
483 protected toNodeIcon(node: TreeNode): string;
484 protected toNodeName(node: TreeNode): string;
485 protected toNodeDescription(node: TreeNode): string;
486 protected getDepthPadding(depth: number): number;
487}
488export declare namespace TreeWidget {
489 /**
490 * Representation of a tree node row.
491 */
492 interface NodeRow {
493 /**
494 * The node row index.
495 */
496 index: number;
497 /**
498 * The actual node.
499 */
500 node: TreeNode;
501 /**
502 * A root relative number representing the hierarchical depth of the actual node. Root is `0`, its children have `1` and so on.
503 */
504 depth: number;
505 }
506 /**
507 * Representation of the tree view properties.
508 */
509 interface ViewProps {
510 /**
511 * The width property.
512 */
513 width: number;
514 /**
515 * The height property.
516 */
517 height: number;
518 /**
519 * The scroll to row value.
520 */
521 scrollToRow?: number;
522 /**
523 * The list of node rows.
524 */
525 rows: NodeRow[];
526 renderNodeRow: (row: NodeRow) => React.ReactNode;
527 }
528 class View extends React.Component<ViewProps> {
529 list: VirtuosoHandle | undefined;
530 render(): React.ReactNode;
531 }
532}
533//# sourceMappingURL=tree-widget.d.ts.map
\No newline at end of file