UNPKG

@angular/cdk

Version:

Angular Material Component Development Kit

537 lines (527 loc) 15.7 kB
import { Observable, of, Subject } from 'rxjs'; import { Injectable, ɵɵdefineInjectable } from '@angular/core'; /** * @fileoverview added by tsickle * Generated from: src/cdk/collections/data-source.ts * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** * @license * Copyright Google LLC All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ /** * @abstract * @template T */ class DataSource { } if (false) { /** * Connects a collection viewer (such as a data-table) to this data source. Note that * the stream provided will be accessed during change detection and should not directly change * values that are bound in template views. * @abstract * @param {?} collectionViewer The component that exposes a view over the data provided by this * data source. * @return {?} Observable that emits a new value when the data changes. */ DataSource.prototype.connect = function (collectionViewer) { }; /** * Disconnects a collection viewer (such as a data-table) from this data source. Can be used * to perform any clean-up or tear-down operations when a view is being destroyed. * * @abstract * @param {?} collectionViewer The component that exposes a view over the data provided by this * data source. * @return {?} */ DataSource.prototype.disconnect = function (collectionViewer) { }; } /** * Checks whether an object is a data source. * @param {?} value * @return {?} */ function isDataSource(value) { // Check if the value is a DataSource by observing if it has a connect function. Cannot // be checked as an `instanceof DataSource` since people could create their own sources // that match the interface, but don't extend DataSource. return value && typeof value.connect === 'function'; } /** * @fileoverview added by tsickle * Generated from: src/cdk/collections/array-data-source.ts * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** * DataSource wrapper for a native array. * @template T */ class ArrayDataSource extends DataSource { /** * @param {?} _data */ constructor(_data) { super(); this._data = _data; } /** * @return {?} */ connect() { return this._data instanceof Observable ? this._data : of(this._data); } /** * @return {?} */ disconnect() { } } if (false) { /** * @type {?} * @private */ ArrayDataSource.prototype._data; } /** * @fileoverview added by tsickle * Generated from: src/cdk/collections/collection-viewer.ts * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** * @license * Copyright Google LLC All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ /** * Interface for any component that provides a view of some data collection and wants to provide * information regarding the view and any changes made. * @record */ function CollectionViewer() { } if (false) { /** * A stream that emits whenever the `CollectionViewer` starts looking at a new portion of the * data. The `start` index is inclusive, while the `end` is exclusive. * @type {?} */ CollectionViewer.prototype.viewChange; } /** * @fileoverview added by tsickle * Generated from: src/cdk/collections/selection-model.ts * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** * Class to be used to power selecting one or more options from a list. * @template T */ class SelectionModel { /** * @param {?=} _multiple * @param {?=} initiallySelectedValues * @param {?=} _emitChanges */ constructor(_multiple = false, initiallySelectedValues, _emitChanges = true) { this._multiple = _multiple; this._emitChanges = _emitChanges; /** * Currently-selected values. */ this._selection = new Set(); /** * Keeps track of the deselected options that haven't been emitted by the change event. */ this._deselectedToEmit = []; /** * Keeps track of the selected options that haven't been emitted by the change event. */ this._selectedToEmit = []; /** * Event emitted when the value has changed. */ this.changed = new Subject(); if (initiallySelectedValues && initiallySelectedValues.length) { if (_multiple) { initiallySelectedValues.forEach((/** * @param {?} value * @return {?} */ value => this._markSelected(value))); } else { this._markSelected(initiallySelectedValues[0]); } // Clear the array in order to avoid firing the change event for preselected values. this._selectedToEmit.length = 0; } } /** * Selected values. * @return {?} */ get selected() { if (!this._selected) { this._selected = Array.from(this._selection.values()); } return this._selected; } /** * Selects a value or an array of values. * @param {...?} values * @return {?} */ select(...values) { this._verifyValueAssignment(values); values.forEach((/** * @param {?} value * @return {?} */ value => this._markSelected(value))); this._emitChangeEvent(); } /** * Deselects a value or an array of values. * @param {...?} values * @return {?} */ deselect(...values) { this._verifyValueAssignment(values); values.forEach((/** * @param {?} value * @return {?} */ value => this._unmarkSelected(value))); this._emitChangeEvent(); } /** * Toggles a value between selected and deselected. * @param {?} value * @return {?} */ toggle(value) { this.isSelected(value) ? this.deselect(value) : this.select(value); } /** * Clears all of the selected values. * @return {?} */ clear() { this._unmarkAll(); this._emitChangeEvent(); } /** * Determines whether a value is selected. * @param {?} value * @return {?} */ isSelected(value) { return this._selection.has(value); } /** * Determines whether the model does not have a value. * @return {?} */ isEmpty() { return this._selection.size === 0; } /** * Determines whether the model has a value. * @return {?} */ hasValue() { return !this.isEmpty(); } /** * Sorts the selected values based on a predicate function. * @param {?=} predicate * @return {?} */ sort(predicate) { if (this._multiple && this.selected) { (/** @type {?} */ (this._selected)).sort(predicate); } } /** * Gets whether multiple values can be selected. * @return {?} */ isMultipleSelection() { return this._multiple; } /** * Emits a change event and clears the records of selected and deselected values. * @private * @return {?} */ _emitChangeEvent() { // Clear the selected values so they can be re-cached. this._selected = null; if (this._selectedToEmit.length || this._deselectedToEmit.length) { this.changed.next({ source: this, added: this._selectedToEmit, removed: this._deselectedToEmit }); this._deselectedToEmit = []; this._selectedToEmit = []; } } /** * Selects a value. * @private * @param {?} value * @return {?} */ _markSelected(value) { if (!this.isSelected(value)) { if (!this._multiple) { this._unmarkAll(); } this._selection.add(value); if (this._emitChanges) { this._selectedToEmit.push(value); } } } /** * Deselects a value. * @private * @param {?} value * @return {?} */ _unmarkSelected(value) { if (this.isSelected(value)) { this._selection.delete(value); if (this._emitChanges) { this._deselectedToEmit.push(value); } } } /** * Clears out the selected values. * @private * @return {?} */ _unmarkAll() { if (!this.isEmpty()) { this._selection.forEach((/** * @param {?} value * @return {?} */ value => this._unmarkSelected(value))); } } /** * Verifies the value assignment and throws an error if the specified value array is * including multiple values while the selection model is not supporting multiple values. * @private * @param {?} values * @return {?} */ _verifyValueAssignment(values) { if (values.length > 1 && !this._multiple) { throw getMultipleValuesInSingleSelectionError(); } } } if (false) { /** * Currently-selected values. * @type {?} * @private */ SelectionModel.prototype._selection; /** * Keeps track of the deselected options that haven't been emitted by the change event. * @type {?} * @private */ SelectionModel.prototype._deselectedToEmit; /** * Keeps track of the selected options that haven't been emitted by the change event. * @type {?} * @private */ SelectionModel.prototype._selectedToEmit; /** * Cache for the array value of the selected items. * @type {?} * @private */ SelectionModel.prototype._selected; /** * Event emitted when the value has changed. * @type {?} */ SelectionModel.prototype.changed; /** * @type {?} * @private */ SelectionModel.prototype._multiple; /** * @type {?} * @private */ SelectionModel.prototype._emitChanges; } /** * Event emitted when the value of a MatSelectionModel has changed. * \@docs-private * @record * @template T */ function SelectionChange() { } if (false) { /** * Model that dispatched the event. * @type {?} */ SelectionChange.prototype.source; /** * Options that were added to the model. * @type {?} */ SelectionChange.prototype.added; /** * Options that were removed from the model. * @type {?} */ SelectionChange.prototype.removed; } /** * Returns an error that reports that multiple values are passed into a selection model * with a single value. * \@docs-private * @return {?} */ function getMultipleValuesInSingleSelectionError() { return Error('Cannot pass multiple values into SelectionModel with single-value mode.'); } /** * @fileoverview added by tsickle * Generated from: src/cdk/collections/unique-selection-dispatcher.ts * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** * Class to coordinate unique selection based on name. * Intended to be consumed as an Angular service. * This service is needed because native radio change events are only fired on the item currently * being selected, and we still need to uncheck the previous selection. * * This service does not *store* any IDs and names because they may change at any time, so it is * less error-prone if they are simply passed through when the events occur. */ class UniqueSelectionDispatcher { constructor() { this._listeners = []; } /** * Notify other items that selection for the given name has been set. * @param {?} id ID of the item. * @param {?} name Name of the item. * @return {?} */ notify(id, name) { for (let listener of this._listeners) { listener(id, name); } } /** * Listen for future changes to item selection. * @param {?} listener * @return {?} Function used to deregister listener */ listen(listener) { this._listeners.push(listener); return (/** * @return {?} */ () => { this._listeners = this._listeners.filter((/** * @param {?} registered * @return {?} */ (registered) => { return listener !== registered; })); }); } /** * @return {?} */ ngOnDestroy() { this._listeners = []; } } UniqueSelectionDispatcher.decorators = [ { type: Injectable, args: [{ providedIn: 'root' },] } ]; /** @nocollapse */ UniqueSelectionDispatcher.ɵprov = ɵɵdefineInjectable({ factory: function UniqueSelectionDispatcher_Factory() { return new UniqueSelectionDispatcher(); }, token: UniqueSelectionDispatcher, providedIn: "root" }); if (false) { /** * @type {?} * @private */ UniqueSelectionDispatcher.prototype._listeners; } /** * @fileoverview added by tsickle * Generated from: src/cdk/collections/tree-adapter.ts * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** * @license * Copyright Google LLC All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ /** * Interface for a class that can flatten hierarchical structured data and re-expand the flattened * data back into its original structure. Should be used in conjunction with the cdk-tree. * @record * @template T */ function TreeDataNodeFlattener() { } if (false) { /** * Transforms a set of hierarchical structured data into a flattened data array. * @param {?} structuredData * @return {?} */ TreeDataNodeFlattener.prototype.flattenNodes = function (structuredData) { }; /** * Expands a flattened array of data into its hierarchical form using the provided expansion * model. * @param {?} nodes * @param {?} expansionModel * @return {?} */ TreeDataNodeFlattener.prototype.expandFlattenedNodes = function (nodes, expansionModel) { }; /** * Put node descendants of node in array. * If `onlyExpandable` is true, then only process expandable descendants. * @param {?} node * @param {?} nodes * @param {?} onlyExpandable * @return {?} */ TreeDataNodeFlattener.prototype.nodeDescendents = function (node, nodes, onlyExpandable) { }; } /** * @fileoverview added by tsickle * Generated from: src/cdk/collections/public-api.ts * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** * Generated bundle index. Do not edit. */ export { ArrayDataSource, DataSource, SelectionModel, UniqueSelectionDispatcher, getMultipleValuesInSingleSelectionError, isDataSource }; //# sourceMappingURL=collections.js.map