tree.d.ts 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /**
  2. * @license
  3. * Copyright Google LLC All Rights Reserved.
  4. *
  5. * Use of this source code is governed by an MIT-style license that can be
  6. * found in the LICENSE file at https://angular.io/license
  7. */
  8. import { FocusableOption } from '@angular/cdk/a11y';
  9. import { CollectionViewer, DataSource } from '@angular/cdk/collections';
  10. import { AfterContentChecked, ChangeDetectorRef, ElementRef, IterableDiffer, IterableDiffers, OnDestroy, OnInit, QueryList, ViewContainerRef, TrackByFunction } from '@angular/core';
  11. import { BehaviorSubject, Observable, Subject } from 'rxjs';
  12. import { TreeControl } from './control/tree-control';
  13. import { CdkTreeNodeDef } from './node';
  14. import { CdkTreeNodeOutlet } from './outlet';
  15. /**
  16. * CDK tree component that connects with a data source to retrieve data of type `T` and renders
  17. * dataNodes with hierarchy. Updates the dataNodes when new data is provided by the data source.
  18. */
  19. export declare class CdkTree<T> implements AfterContentChecked, CollectionViewer, OnDestroy, OnInit {
  20. private _differs;
  21. private _changeDetectorRef;
  22. /** Subject that emits when the component has been destroyed. */
  23. private _onDestroy;
  24. /** Differ used to find the changes in the data provided by the data source. */
  25. private _dataDiffer;
  26. /** Stores the node definition that does not have a when predicate. */
  27. private _defaultNodeDef;
  28. /** Data subscription */
  29. private _dataSubscription;
  30. /** Level of nodes */
  31. private _levels;
  32. /**
  33. * Provides a stream containing the latest data array to render. Influenced by the tree's
  34. * stream of view window (what dataNodes are currently on screen).
  35. * Data source can be an observable of data array, or a data array to render.
  36. */
  37. dataSource: DataSource<T> | Observable<T[]> | T[];
  38. private _dataSource;
  39. /** The tree controller */
  40. treeControl: TreeControl<T>;
  41. /**
  42. * Tracking function that will be used to check the differences in data changes. Used similarly
  43. * to `ngFor` `trackBy` function. Optimize node operations by identifying a node based on its data
  44. * relative to the function to know if a node should be added/removed/moved.
  45. * Accepts a function that takes two parameters, `index` and `item`.
  46. */
  47. trackBy: TrackByFunction<T>;
  48. _nodeOutlet: CdkTreeNodeOutlet;
  49. /** The tree node template for the tree */
  50. _nodeDefs: QueryList<CdkTreeNodeDef<T>>;
  51. /**
  52. * Stream containing the latest information on what rows are being displayed on screen.
  53. * Can be used by the data source to as a heuristic of what data should be provided.
  54. */
  55. viewChange: BehaviorSubject<{
  56. start: number;
  57. end: number;
  58. }>;
  59. constructor(_differs: IterableDiffers, _changeDetectorRef: ChangeDetectorRef);
  60. ngOnInit(): void;
  61. ngOnDestroy(): void;
  62. ngAfterContentChecked(): void;
  63. /**
  64. * Switch to the provided data source by resetting the data and unsubscribing from the current
  65. * render change subscription if one exists. If the data source is null, interpret this by
  66. * clearing the node outlet. Otherwise start listening for new data.
  67. */
  68. private _switchDataSource;
  69. /** Set up a subscription for the data provided by the data source. */
  70. private _observeRenderChanges;
  71. /** Check for changes made in the data and render each change (node added/removed/moved). */
  72. renderNodeChanges(data: T[] | ReadonlyArray<T>, dataDiffer?: IterableDiffer<T>, viewContainer?: ViewContainerRef, parentData?: T): void;
  73. /**
  74. * Finds the matching node definition that should be used for this node data. If there is only
  75. * one node definition, it is returned. Otherwise, find the node definition that has a when
  76. * predicate that returns true with the data. If none return true, return the default node
  77. * definition.
  78. */
  79. _getNodeDef(data: T, i: number): CdkTreeNodeDef<T>;
  80. /**
  81. * Create the embedded view for the data node template and place it in the correct index location
  82. * within the data node view container.
  83. */
  84. insertNode(nodeData: T, index: number, viewContainer?: ViewContainerRef, parentData?: T): void;
  85. }
  86. /**
  87. * Tree node for CdkTree. It contains the data in the tree node.
  88. */
  89. export declare class CdkTreeNode<T> implements FocusableOption, OnDestroy {
  90. protected _elementRef: ElementRef<HTMLElement>;
  91. protected _tree: CdkTree<T>;
  92. /**
  93. * The most recently created `CdkTreeNode`. We save it in static variable so we can retrieve it
  94. * in `CdkTree` and set the data to it.
  95. */
  96. static mostRecentTreeNode: CdkTreeNode<any> | null;
  97. /** Subject that emits when the component has been destroyed. */
  98. protected _destroyed: Subject<void>;
  99. /** Emits when the node's data has changed. */
  100. _dataChanges: Subject<void>;
  101. /** The tree node's data. */
  102. data: T;
  103. protected _data: T;
  104. readonly isExpanded: boolean;
  105. readonly level: number;
  106. /**
  107. * The role of the node should be 'group' if it's an internal node,
  108. * and 'treeitem' if it's a leaf node.
  109. */
  110. role: 'treeitem' | 'group';
  111. constructor(_elementRef: ElementRef<HTMLElement>, _tree: CdkTree<T>);
  112. ngOnDestroy(): void;
  113. /** Focuses the menu item. Implements for FocusableOption. */
  114. focus(): void;
  115. protected _setRoleFromData(): void;
  116. protected _setRoleFromChildren(children: T[]): void;
  117. }