source: trip-planner-front/node_modules/@angular/cdk/fesm2015/collections.js@ fa375fe

Last change on this file since fa375fe was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 16.2 KB
Line 
1import { isObservable, of, Subject } from 'rxjs';
2import * as i0 from '@angular/core';
3import { Injectable, InjectionToken } from '@angular/core';
4
5/**
6 * @license
7 * Copyright Google LLC All Rights Reserved.
8 *
9 * Use of this source code is governed by an MIT-style license that can be
10 * found in the LICENSE file at https://angular.io/license
11 */
12class DataSource {
13}
14/** Checks whether an object is a data source. */
15function isDataSource(value) {
16 // Check if the value is a DataSource by observing if it has a connect function. Cannot
17 // be checked as an `instanceof DataSource` since people could create their own sources
18 // that match the interface, but don't extend DataSource.
19 return value && typeof value.connect === 'function';
20}
21
22/**
23 * @license
24 * Copyright Google LLC All Rights Reserved.
25 *
26 * Use of this source code is governed by an MIT-style license that can be
27 * found in the LICENSE file at https://angular.io/license
28 */
29/** DataSource wrapper for a native array. */
30class ArrayDataSource extends DataSource {
31 constructor(_data) {
32 super();
33 this._data = _data;
34 }
35 connect() {
36 return isObservable(this._data) ? this._data : of(this._data);
37 }
38 disconnect() { }
39}
40
41/**
42 * @license
43 * Copyright Google LLC All Rights Reserved.
44 *
45 * Use of this source code is governed by an MIT-style license that can be
46 * found in the LICENSE file at https://angular.io/license
47 */
48
49/**
50 * @license
51 * Copyright Google LLC All Rights Reserved.
52 *
53 * Use of this source code is governed by an MIT-style license that can be
54 * found in the LICENSE file at https://angular.io/license
55 */
56/**
57 * A repeater that destroys views when they are removed from a
58 * {@link ViewContainerRef}. When new items are inserted into the container,
59 * the repeater will always construct a new embedded view for each item.
60 *
61 * @template T The type for the embedded view's $implicit property.
62 * @template R The type for the item in each IterableDiffer change record.
63 * @template C The type for the context passed to each embedded view.
64 */
65class _DisposeViewRepeaterStrategy {
66 applyChanges(changes, viewContainerRef, itemContextFactory, itemValueResolver, itemViewChanged) {
67 changes.forEachOperation((record, adjustedPreviousIndex, currentIndex) => {
68 let view;
69 let operation;
70 if (record.previousIndex == null) {
71 const insertContext = itemContextFactory(record, adjustedPreviousIndex, currentIndex);
72 view = viewContainerRef.createEmbeddedView(insertContext.templateRef, insertContext.context, insertContext.index);
73 operation = 1 /* INSERTED */;
74 }
75 else if (currentIndex == null) {
76 viewContainerRef.remove(adjustedPreviousIndex);
77 operation = 3 /* REMOVED */;
78 }
79 else {
80 view = viewContainerRef.get(adjustedPreviousIndex);
81 viewContainerRef.move(view, currentIndex);
82 operation = 2 /* MOVED */;
83 }
84 if (itemViewChanged) {
85 itemViewChanged({
86 context: view === null || view === void 0 ? void 0 : view.context,
87 operation,
88 record,
89 });
90 }
91 });
92 }
93 detach() {
94 }
95}
96
97/**
98 * @license
99 * Copyright Google LLC All Rights Reserved.
100 *
101 * Use of this source code is governed by an MIT-style license that can be
102 * found in the LICENSE file at https://angular.io/license
103 */
104/**
105 * A repeater that caches views when they are removed from a
106 * {@link ViewContainerRef}. When new items are inserted into the container,
107 * the repeater will reuse one of the cached views instead of creating a new
108 * embedded view. Recycling cached views reduces the quantity of expensive DOM
109 * inserts.
110 *
111 * @template T The type for the embedded view's $implicit property.
112 * @template R The type for the item in each IterableDiffer change record.
113 * @template C The type for the context passed to each embedded view.
114 */
115class _RecycleViewRepeaterStrategy {
116 constructor() {
117 /**
118 * The size of the cache used to store unused views.
119 * Setting the cache size to `0` will disable caching. Defaults to 20 views.
120 */
121 this.viewCacheSize = 20;
122 /**
123 * View cache that stores embedded view instances that have been previously stamped out,
124 * but don't are not currently rendered. The view repeater will reuse these views rather than
125 * creating brand new ones.
126 *
127 * TODO(michaeljamesparsons) Investigate whether using a linked list would improve performance.
128 */
129 this._viewCache = [];
130 }
131 /** Apply changes to the DOM. */
132 applyChanges(changes, viewContainerRef, itemContextFactory, itemValueResolver, itemViewChanged) {
133 // Rearrange the views to put them in the right location.
134 changes.forEachOperation((record, adjustedPreviousIndex, currentIndex) => {
135 let view;
136 let operation;
137 if (record.previousIndex == null) { // Item added.
138 const viewArgsFactory = () => itemContextFactory(record, adjustedPreviousIndex, currentIndex);
139 view = this._insertView(viewArgsFactory, currentIndex, viewContainerRef, itemValueResolver(record));
140 operation = view ? 1 /* INSERTED */ : 0 /* REPLACED */;
141 }
142 else if (currentIndex == null) { // Item removed.
143 this._detachAndCacheView(adjustedPreviousIndex, viewContainerRef);
144 operation = 3 /* REMOVED */;
145 }
146 else { // Item moved.
147 view = this._moveView(adjustedPreviousIndex, currentIndex, viewContainerRef, itemValueResolver(record));
148 operation = 2 /* MOVED */;
149 }
150 if (itemViewChanged) {
151 itemViewChanged({
152 context: view === null || view === void 0 ? void 0 : view.context,
153 operation,
154 record,
155 });
156 }
157 });
158 }
159 detach() {
160 for (const view of this._viewCache) {
161 view.destroy();
162 }
163 this._viewCache = [];
164 }
165 /**
166 * Inserts a view for a new item, either from the cache or by creating a new
167 * one. Returns `undefined` if the item was inserted into a cached view.
168 */
169 _insertView(viewArgsFactory, currentIndex, viewContainerRef, value) {
170 const cachedView = this._insertViewFromCache(currentIndex, viewContainerRef);
171 if (cachedView) {
172 cachedView.context.$implicit = value;
173 return undefined;
174 }
175 const viewArgs = viewArgsFactory();
176 return viewContainerRef.createEmbeddedView(viewArgs.templateRef, viewArgs.context, viewArgs.index);
177 }
178 /** Detaches the view at the given index and inserts into the view cache. */
179 _detachAndCacheView(index, viewContainerRef) {
180 const detachedView = viewContainerRef.detach(index);
181 this._maybeCacheView(detachedView, viewContainerRef);
182 }
183 /** Moves view at the previous index to the current index. */
184 _moveView(adjustedPreviousIndex, currentIndex, viewContainerRef, value) {
185 const view = viewContainerRef.get(adjustedPreviousIndex);
186 viewContainerRef.move(view, currentIndex);
187 view.context.$implicit = value;
188 return view;
189 }
190 /**
191 * Cache the given detached view. If the cache is full, the view will be
192 * destroyed.
193 */
194 _maybeCacheView(view, viewContainerRef) {
195 if (this._viewCache.length < this.viewCacheSize) {
196 this._viewCache.push(view);
197 }
198 else {
199 const index = viewContainerRef.indexOf(view);
200 // The host component could remove views from the container outside of
201 // the view repeater. It's unlikely this will occur, but just in case,
202 // destroy the view on its own, otherwise destroy it through the
203 // container to ensure that all the references are removed.
204 if (index === -1) {
205 view.destroy();
206 }
207 else {
208 viewContainerRef.remove(index);
209 }
210 }
211 }
212 /** Inserts a recycled view from the cache at the given index. */
213 _insertViewFromCache(index, viewContainerRef) {
214 const cachedView = this._viewCache.pop();
215 if (cachedView) {
216 viewContainerRef.insert(cachedView, index);
217 }
218 return cachedView || null;
219 }
220}
221
222/**
223 * @license
224 * Copyright Google LLC All Rights Reserved.
225 *
226 * Use of this source code is governed by an MIT-style license that can be
227 * found in the LICENSE file at https://angular.io/license
228 */
229/**
230 * Class to be used to power selecting one or more options from a list.
231 */
232class SelectionModel {
233 constructor(_multiple = false, initiallySelectedValues, _emitChanges = true) {
234 this._multiple = _multiple;
235 this._emitChanges = _emitChanges;
236 /** Currently-selected values. */
237 this._selection = new Set();
238 /** Keeps track of the deselected options that haven't been emitted by the change event. */
239 this._deselectedToEmit = [];
240 /** Keeps track of the selected options that haven't been emitted by the change event. */
241 this._selectedToEmit = [];
242 /** Event emitted when the value has changed. */
243 this.changed = new Subject();
244 if (initiallySelectedValues && initiallySelectedValues.length) {
245 if (_multiple) {
246 initiallySelectedValues.forEach(value => this._markSelected(value));
247 }
248 else {
249 this._markSelected(initiallySelectedValues[0]);
250 }
251 // Clear the array in order to avoid firing the change event for preselected values.
252 this._selectedToEmit.length = 0;
253 }
254 }
255 /** Selected values. */
256 get selected() {
257 if (!this._selected) {
258 this._selected = Array.from(this._selection.values());
259 }
260 return this._selected;
261 }
262 /**
263 * Selects a value or an array of values.
264 */
265 select(...values) {
266 this._verifyValueAssignment(values);
267 values.forEach(value => this._markSelected(value));
268 this._emitChangeEvent();
269 }
270 /**
271 * Deselects a value or an array of values.
272 */
273 deselect(...values) {
274 this._verifyValueAssignment(values);
275 values.forEach(value => this._unmarkSelected(value));
276 this._emitChangeEvent();
277 }
278 /**
279 * Toggles a value between selected and deselected.
280 */
281 toggle(value) {
282 this.isSelected(value) ? this.deselect(value) : this.select(value);
283 }
284 /**
285 * Clears all of the selected values.
286 */
287 clear() {
288 this._unmarkAll();
289 this._emitChangeEvent();
290 }
291 /**
292 * Determines whether a value is selected.
293 */
294 isSelected(value) {
295 return this._selection.has(value);
296 }
297 /**
298 * Determines whether the model does not have a value.
299 */
300 isEmpty() {
301 return this._selection.size === 0;
302 }
303 /**
304 * Determines whether the model has a value.
305 */
306 hasValue() {
307 return !this.isEmpty();
308 }
309 /**
310 * Sorts the selected values based on a predicate function.
311 */
312 sort(predicate) {
313 if (this._multiple && this.selected) {
314 this._selected.sort(predicate);
315 }
316 }
317 /**
318 * Gets whether multiple values can be selected.
319 */
320 isMultipleSelection() {
321 return this._multiple;
322 }
323 /** Emits a change event and clears the records of selected and deselected values. */
324 _emitChangeEvent() {
325 // Clear the selected values so they can be re-cached.
326 this._selected = null;
327 if (this._selectedToEmit.length || this._deselectedToEmit.length) {
328 this.changed.next({
329 source: this,
330 added: this._selectedToEmit,
331 removed: this._deselectedToEmit
332 });
333 this._deselectedToEmit = [];
334 this._selectedToEmit = [];
335 }
336 }
337 /** Selects a value. */
338 _markSelected(value) {
339 if (!this.isSelected(value)) {
340 if (!this._multiple) {
341 this._unmarkAll();
342 }
343 this._selection.add(value);
344 if (this._emitChanges) {
345 this._selectedToEmit.push(value);
346 }
347 }
348 }
349 /** Deselects a value. */
350 _unmarkSelected(value) {
351 if (this.isSelected(value)) {
352 this._selection.delete(value);
353 if (this._emitChanges) {
354 this._deselectedToEmit.push(value);
355 }
356 }
357 }
358 /** Clears out the selected values. */
359 _unmarkAll() {
360 if (!this.isEmpty()) {
361 this._selection.forEach(value => this._unmarkSelected(value));
362 }
363 }
364 /**
365 * Verifies the value assignment and throws an error if the specified value array is
366 * including multiple values while the selection model is not supporting multiple values.
367 */
368 _verifyValueAssignment(values) {
369 if (values.length > 1 && !this._multiple && (typeof ngDevMode === 'undefined' || ngDevMode)) {
370 throw getMultipleValuesInSingleSelectionError();
371 }
372 }
373}
374/**
375 * Returns an error that reports that multiple values are passed into a selection model
376 * with a single value.
377 * @docs-private
378 */
379function getMultipleValuesInSingleSelectionError() {
380 return Error('Cannot pass multiple values into SelectionModel with single-value mode.');
381}
382
383/**
384 * @license
385 * Copyright Google LLC All Rights Reserved.
386 *
387 * Use of this source code is governed by an MIT-style license that can be
388 * found in the LICENSE file at https://angular.io/license
389 */
390/**
391 * Class to coordinate unique selection based on name.
392 * Intended to be consumed as an Angular service.
393 * This service is needed because native radio change events are only fired on the item currently
394 * being selected, and we still need to uncheck the previous selection.
395 *
396 * This service does not *store* any IDs and names because they may change at any time, so it is
397 * less error-prone if they are simply passed through when the events occur.
398 */
399class UniqueSelectionDispatcher {
400 constructor() {
401 this._listeners = [];
402 }
403 /**
404 * Notify other items that selection for the given name has been set.
405 * @param id ID of the item.
406 * @param name Name of the item.
407 */
408 notify(id, name) {
409 for (let listener of this._listeners) {
410 listener(id, name);
411 }
412 }
413 /**
414 * Listen for future changes to item selection.
415 * @return Function used to deregister listener
416 */
417 listen(listener) {
418 this._listeners.push(listener);
419 return () => {
420 this._listeners = this._listeners.filter((registered) => {
421 return listener !== registered;
422 });
423 };
424 }
425 ngOnDestroy() {
426 this._listeners = [];
427 }
428}
429UniqueSelectionDispatcher.ɵprov = i0.ɵɵdefineInjectable({ factory: function UniqueSelectionDispatcher_Factory() { return new UniqueSelectionDispatcher(); }, token: UniqueSelectionDispatcher, providedIn: "root" });
430UniqueSelectionDispatcher.decorators = [
431 { type: Injectable, args: [{ providedIn: 'root' },] }
432];
433
434/**
435 * @license
436 * Copyright Google LLC All Rights Reserved.
437 *
438 * Use of this source code is governed by an MIT-style license that can be
439 * found in the LICENSE file at https://angular.io/license
440 */
441
442/**
443 * @license
444 * Copyright Google LLC All Rights Reserved.
445 *
446 * Use of this source code is governed by an MIT-style license that can be
447 * found in the LICENSE file at https://angular.io/license
448 */
449/**
450 * Injection token for {@link _ViewRepeater}. This token is for use by Angular Material only.
451 * @docs-private
452 */
453const _VIEW_REPEATER_STRATEGY = new InjectionToken('_ViewRepeater');
454
455/**
456 * @license
457 * Copyright Google LLC All Rights Reserved.
458 *
459 * Use of this source code is governed by an MIT-style license that can be
460 * found in the LICENSE file at https://angular.io/license
461 */
462
463/**
464 * Generated bundle index. Do not edit.
465 */
466
467export { ArrayDataSource, DataSource, SelectionModel, UniqueSelectionDispatcher, _DisposeViewRepeaterStrategy, _RecycleViewRepeaterStrategy, _VIEW_REPEATER_STRATEGY, getMultipleValuesInSingleSelectionError, isDataSource };
468//# sourceMappingURL=collections.js.map
Note: See TracBrowser for help on using the repository browser.