index.d.ts 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  1. import * as i0 from '@angular/core';
  2. import { InjectionToken } from '@angular/core';
  3. import { IterableChangeRecord } from '@angular/core';
  4. import { IterableChanges } from '@angular/core';
  5. import { Observable } from 'rxjs';
  6. import { OnDestroy } from '@angular/core';
  7. import { Subject } from 'rxjs';
  8. import { TemplateRef } from '@angular/core';
  9. import { ViewContainerRef } from '@angular/core';
  10. /** DataSource wrapper for a native array. */
  11. export declare class ArrayDataSource<T> extends DataSource<T> {
  12. private _data;
  13. constructor(_data: readonly T[] | Observable<readonly T[]>);
  14. connect(): Observable<readonly T[]>;
  15. disconnect(): void;
  16. }
  17. /**
  18. * Interface for any component that provides a view of some data collection and wants to provide
  19. * information regarding the view and any changes made.
  20. */
  21. export declare interface CollectionViewer {
  22. /**
  23. * A stream that emits whenever the `CollectionViewer` starts looking at a new portion of the
  24. * data. The `start` index is inclusive, while the `end` is exclusive.
  25. */
  26. viewChange: Observable<ListRange>;
  27. }
  28. export declare abstract class DataSource<T> {
  29. /**
  30. * Connects a collection viewer (such as a data-table) to this data source. Note that
  31. * the stream provided will be accessed during change detection and should not directly change
  32. * values that are bound in template views.
  33. * @param collectionViewer The component that exposes a view over the data provided by this
  34. * data source.
  35. * @returns Observable that emits a new value when the data changes.
  36. */
  37. abstract connect(collectionViewer: CollectionViewer): Observable<readonly T[]>;
  38. /**
  39. * Disconnects a collection viewer (such as a data-table) from this data source. Can be used
  40. * to perform any clean-up or tear-down operations when a view is being destroyed.
  41. *
  42. * @param collectionViewer The component that exposes a view over the data provided by this
  43. * data source.
  44. */
  45. abstract disconnect(collectionViewer: CollectionViewer): void;
  46. }
  47. /**
  48. * A repeater that destroys views when they are removed from a
  49. * {@link ViewContainerRef}. When new items are inserted into the container,
  50. * the repeater will always construct a new embedded view for each item.
  51. *
  52. * @template T The type for the embedded view's $implicit property.
  53. * @template R The type for the item in each IterableDiffer change record.
  54. * @template C The type for the context passed to each embedded view.
  55. */
  56. export declare class _DisposeViewRepeaterStrategy<T, R, C extends _ViewRepeaterItemContext<T>> implements _ViewRepeater<T, R, C> {
  57. applyChanges(changes: IterableChanges<R>, viewContainerRef: ViewContainerRef, itemContextFactory: _ViewRepeaterItemContextFactory<T, R, C>, itemValueResolver: _ViewRepeaterItemValueResolver<T, R>, itemViewChanged?: _ViewRepeaterItemChanged<R, C>): void;
  58. detach(): void;
  59. }
  60. /**
  61. * Returns an error that reports that multiple values are passed into a selection model
  62. * with a single value.
  63. * @docs-private
  64. */
  65. export declare function getMultipleValuesInSingleSelectionError(): Error;
  66. /** Checks whether an object is a data source. */
  67. export declare function isDataSource(value: any): value is DataSource<any>;
  68. /** Represents a range of numbers with a specified start and end. */
  69. export declare type ListRange = {
  70. start: number;
  71. end: number;
  72. };
  73. /**
  74. * A repeater that caches views when they are removed from a
  75. * {@link ViewContainerRef}. When new items are inserted into the container,
  76. * the repeater will reuse one of the cached views instead of creating a new
  77. * embedded view. Recycling cached views reduces the quantity of expensive DOM
  78. * inserts.
  79. *
  80. * @template T The type for the embedded view's $implicit property.
  81. * @template R The type for the item in each IterableDiffer change record.
  82. * @template C The type for the context passed to each embedded view.
  83. */
  84. export declare class _RecycleViewRepeaterStrategy<T, R, C extends _ViewRepeaterItemContext<T>> implements _ViewRepeater<T, R, C> {
  85. /**
  86. * The size of the cache used to store unused views.
  87. * Setting the cache size to `0` will disable caching. Defaults to 20 views.
  88. */
  89. viewCacheSize: number;
  90. /**
  91. * View cache that stores embedded view instances that have been previously stamped out,
  92. * but don't are not currently rendered. The view repeater will reuse these views rather than
  93. * creating brand new ones.
  94. *
  95. * TODO(michaeljamesparsons) Investigate whether using a linked list would improve performance.
  96. */
  97. private _viewCache;
  98. /** Apply changes to the DOM. */
  99. applyChanges(changes: IterableChanges<R>, viewContainerRef: ViewContainerRef, itemContextFactory: _ViewRepeaterItemContextFactory<T, R, C>, itemValueResolver: _ViewRepeaterItemValueResolver<T, R>, itemViewChanged?: _ViewRepeaterItemChanged<R, C>): void;
  100. detach(): void;
  101. /**
  102. * Inserts a view for a new item, either from the cache or by creating a new
  103. * one. Returns `undefined` if the item was inserted into a cached view.
  104. */
  105. private _insertView;
  106. /** Detaches the view at the given index and inserts into the view cache. */
  107. private _detachAndCacheView;
  108. /** Moves view at the previous index to the current index. */
  109. private _moveView;
  110. /**
  111. * Cache the given detached view. If the cache is full, the view will be
  112. * destroyed.
  113. */
  114. private _maybeCacheView;
  115. /** Inserts a recycled view from the cache at the given index. */
  116. private _insertViewFromCache;
  117. }
  118. /**
  119. * Event emitted when the value of a MatSelectionModel has changed.
  120. * @docs-private
  121. */
  122. export declare interface SelectionChange<T> {
  123. /** Model that dispatched the event. */
  124. source: SelectionModel<T>;
  125. /** Options that were added to the model. */
  126. added: T[];
  127. /** Options that were removed from the model. */
  128. removed: T[];
  129. }
  130. /**
  131. * Class to be used to power selecting one or more options from a list.
  132. */
  133. export declare class SelectionModel<T> {
  134. private _multiple;
  135. private _emitChanges;
  136. compareWith?: ((o1: T, o2: T) => boolean) | undefined;
  137. /** Currently-selected values. */
  138. private _selection;
  139. /** Keeps track of the deselected options that haven't been emitted by the change event. */
  140. private _deselectedToEmit;
  141. /** Keeps track of the selected options that haven't been emitted by the change event. */
  142. private _selectedToEmit;
  143. /** Cache for the array value of the selected items. */
  144. private _selected;
  145. /** Selected values. */
  146. get selected(): T[];
  147. /** Event emitted when the value has changed. */
  148. readonly changed: Subject<SelectionChange<T>>;
  149. constructor(_multiple?: boolean, initiallySelectedValues?: T[], _emitChanges?: boolean, compareWith?: ((o1: T, o2: T) => boolean) | undefined);
  150. /**
  151. * Selects a value or an array of values.
  152. * @param values The values to select
  153. * @return Whether the selection changed as a result of this call
  154. * @breaking-change 16.0.0 make return type boolean
  155. */
  156. select(...values: T[]): boolean | void;
  157. /**
  158. * Deselects a value or an array of values.
  159. * @param values The values to deselect
  160. * @return Whether the selection changed as a result of this call
  161. * @breaking-change 16.0.0 make return type boolean
  162. */
  163. deselect(...values: T[]): boolean | void;
  164. /**
  165. * Sets the selected values
  166. * @param values The new selected values
  167. * @return Whether the selection changed as a result of this call
  168. * @breaking-change 16.0.0 make return type boolean
  169. */
  170. setSelection(...values: T[]): boolean | void;
  171. /**
  172. * Toggles a value between selected and deselected.
  173. * @param value The value to toggle
  174. * @return Whether the selection changed as a result of this call
  175. * @breaking-change 16.0.0 make return type boolean
  176. */
  177. toggle(value: T): boolean | void;
  178. /**
  179. * Clears all of the selected values.
  180. * @param flushEvent Whether to flush the changes in an event.
  181. * If false, the changes to the selection will be flushed along with the next event.
  182. * @return Whether the selection changed as a result of this call
  183. * @breaking-change 16.0.0 make return type boolean
  184. */
  185. clear(flushEvent?: boolean): boolean | void;
  186. /**
  187. * Determines whether a value is selected.
  188. */
  189. isSelected(value: T): boolean;
  190. /**
  191. * Determines whether the model does not have a value.
  192. */
  193. isEmpty(): boolean;
  194. /**
  195. * Determines whether the model has a value.
  196. */
  197. hasValue(): boolean;
  198. /**
  199. * Sorts the selected values based on a predicate function.
  200. */
  201. sort(predicate?: (a: T, b: T) => number): void;
  202. /**
  203. * Gets whether multiple values can be selected.
  204. */
  205. isMultipleSelection(): boolean;
  206. /** Emits a change event and clears the records of selected and deselected values. */
  207. private _emitChangeEvent;
  208. /** Selects a value. */
  209. private _markSelected;
  210. /** Deselects a value. */
  211. private _unmarkSelected;
  212. /** Clears out the selected values. */
  213. private _unmarkAll;
  214. /**
  215. * Verifies the value assignment and throws an error if the specified value array is
  216. * including multiple values while the selection model is not supporting multiple values.
  217. */
  218. private _verifyValueAssignment;
  219. /** Whether there are queued up change to be emitted. */
  220. private _hasQueuedChanges;
  221. /** Returns a value that is comparable to inputValue by applying compareWith function, returns the same inputValue otherwise. */
  222. private _getConcreteValue;
  223. }
  224. /**
  225. * Interface for a class that can flatten hierarchical structured data and re-expand the flattened
  226. * data back into its original structure. Should be used in conjunction with the cdk-tree.
  227. */
  228. export declare interface TreeDataNodeFlattener<T> {
  229. /** Transforms a set of hierarchical structured data into a flattened data array. */
  230. flattenNodes(structuredData: any[]): T[];
  231. /**
  232. * Expands a flattened array of data into its hierarchical form using the provided expansion
  233. * model.
  234. */
  235. expandFlattenedNodes(nodes: T[], expansionModel: SelectionModel<T>): T[];
  236. /**
  237. * Put node descendants of node in array.
  238. * If `onlyExpandable` is true, then only process expandable descendants.
  239. */
  240. nodeDescendents(node: T, nodes: T[], onlyExpandable: boolean): void;
  241. }
  242. /**
  243. * Class to coordinate unique selection based on name.
  244. * Intended to be consumed as an Angular service.
  245. * This service is needed because native radio change events are only fired on the item currently
  246. * being selected, and we still need to uncheck the previous selection.
  247. *
  248. * This service does not *store* any IDs and names because they may change at any time, so it is
  249. * less error-prone if they are simply passed through when the events occur.
  250. */
  251. export declare class UniqueSelectionDispatcher implements OnDestroy {
  252. private _listeners;
  253. /**
  254. * Notify other items that selection for the given name has been set.
  255. * @param id ID of the item.
  256. * @param name Name of the item.
  257. */
  258. notify(id: string, name: string): void;
  259. /**
  260. * Listen for future changes to item selection.
  261. * @return Function used to deregister listener
  262. */
  263. listen(listener: UniqueSelectionDispatcherListener): () => void;
  264. ngOnDestroy(): void;
  265. static ɵfac: i0.ɵɵFactoryDeclaration<UniqueSelectionDispatcher, never>;
  266. static ɵprov: i0.ɵɵInjectableDeclaration<UniqueSelectionDispatcher>;
  267. }
  268. export declare type UniqueSelectionDispatcherListener = (id: string, name: string) => void;
  269. /**
  270. * Injection token for {@link _ViewRepeater}. This token is for use by Angular Material only.
  271. * @docs-private
  272. */
  273. export declare const _VIEW_REPEATER_STRATEGY: InjectionToken<_ViewRepeater<unknown, unknown, _ViewRepeaterItemContext<unknown>>>;
  274. /**
  275. * Describes a strategy for rendering items in a {@link ViewContainerRef}.
  276. *
  277. * @template T The type for the embedded view's $implicit property.
  278. * @template R The type for the item in each IterableDiffer change record.
  279. * @template C The type for the context passed to each embedded view.
  280. */
  281. export declare interface _ViewRepeater<T, R, C extends _ViewRepeaterItemContext<T>> {
  282. applyChanges(changes: IterableChanges<R>, viewContainerRef: ViewContainerRef, itemContextFactory: _ViewRepeaterItemContextFactory<T, R, C>, itemValueResolver: _ViewRepeaterItemValueResolver<T, R>, itemViewChanged?: _ViewRepeaterItemChanged<R, C>): void;
  283. detach(): void;
  284. }
  285. /**
  286. * Meta data describing the state of a view after it was updated by a
  287. * {@link _ViewRepeater}.
  288. *
  289. * @template R The type for the item in each IterableDiffer change record.
  290. * @template C The type for the context passed to each embedded view.
  291. */
  292. export declare interface _ViewRepeaterItemChange<R, C> {
  293. /** The view's context after it was changed. */
  294. context?: C;
  295. /** Indicates how the view was changed. */
  296. operation: _ViewRepeaterOperation;
  297. /** The view's corresponding change record. */
  298. record: IterableChangeRecord<R>;
  299. }
  300. /**
  301. * Type for a callback to be executed after a view has changed.
  302. *
  303. * @template R The type for the item in each IterableDiffer change record.
  304. * @template C The type for the context passed to each embedded view.
  305. */
  306. export declare type _ViewRepeaterItemChanged<R, C> = (change: _ViewRepeaterItemChange<R, C>) => void;
  307. /**
  308. * The context for an embedded view in the repeater's view container.
  309. *
  310. * @template T The type for the embedded view's $implicit property.
  311. */
  312. export declare interface _ViewRepeaterItemContext<T> {
  313. $implicit?: T;
  314. }
  315. /**
  316. * A factory that derives the embedded view context for an item in a view
  317. * container.
  318. *
  319. * @template T The type for the embedded view's $implicit property.
  320. * @template R The type for the item in each IterableDiffer change record.
  321. * @template C The type for the context passed to each embedded view.
  322. */
  323. export declare type _ViewRepeaterItemContextFactory<T, R, C extends _ViewRepeaterItemContext<T>> = (record: IterableChangeRecord<R>, adjustedPreviousIndex: number | null, currentIndex: number | null) => _ViewRepeaterItemInsertArgs<C>;
  324. /**
  325. * The arguments needed to construct an embedded view for an item in a view
  326. * container.
  327. *
  328. * @template C The type for the context passed to each embedded view.
  329. */
  330. export declare interface _ViewRepeaterItemInsertArgs<C> {
  331. templateRef: TemplateRef<C>;
  332. context?: C;
  333. index?: number;
  334. }
  335. /**
  336. * Extracts the value of an item from an {@link IterableChangeRecord}.
  337. *
  338. * @template T The type for the embedded view's $implicit property.
  339. * @template R The type for the item in each IterableDiffer change record.
  340. */
  341. export declare type _ViewRepeaterItemValueResolver<T, R> = (record: IterableChangeRecord<R>) => T;
  342. /** Indicates how a view was changed by a {@link _ViewRepeater}. */
  343. export declare const enum _ViewRepeaterOperation {
  344. /** The content of an existing view was replaced with another item. */
  345. REPLACED = 0,
  346. /** A new view was created with `createEmbeddedView`. */
  347. INSERTED = 1,
  348. /** The position of a view changed, but the content remains the same. */
  349. MOVED = 2,
  350. /** A view was detached from the view container. */
  351. REMOVED = 3
  352. }
  353. export { }