@rxap/material-table-system 13.0.3 → 13.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5,7 +5,7 @@ import * as i1 from '@angular/cdk/portal';
5
5
  import { TemplatePortal, PortalModule } from '@angular/cdk/portal';
6
6
  import { Required, clone, DeleteEmptyProperties, equals, coerceBoolean, coerceArray } from '@rxap/utilities';
7
7
  import { trigger, state, style, transition, animate, sequence } from '@angular/animations';
8
- import { BehaviorSubject, EMPTY, ReplaySubject, Subscription, Subject, isObservable, of } from 'rxjs';
8
+ import { BehaviorSubject, Subject, EMPTY, ReplaySubject, Subscription, isObservable, of } from 'rxjs';
9
9
  import { map, filter, tap, distinctUntilChanged, debounceTime, delay, startWith } from 'rxjs/operators';
10
10
  import * as i2 from '@angular/common';
11
11
  import { CommonModule } from '@angular/common';
@@ -13,7 +13,6 @@ import * as i2$1 from '@angular/material/button';
13
13
  import { MatButtonModule, MatButton } from '@angular/material/button';
14
14
  import * as i1$1 from '@angular/material/icon';
15
15
  import { MatIconModule } from '@angular/material/icon';
16
- import { SelectionModel } from '@angular/cdk/collections';
17
16
  import * as i1$2 from '@angular/material/checkbox';
18
17
  import { MatCheckboxModule } from '@angular/material/checkbox';
19
18
  import * as i4 from '@angular/cdk/table';
@@ -294,13 +293,227 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.3", ngImpor
294
293
 
295
294
  const RXAP_MATERIAL_TABLE_SYSTEM_SELECT_ROW_OPTIONS = new InjectionToken('rxap-material/table-system/select-row/options');
296
295
 
296
+ /**
297
+ * @license
298
+ * Copyright Google LLC All Rights Reserved.
299
+ *
300
+ * Use of this source code is governed by an MIT-style license that can be
301
+ * found in the LICENSE file at https://angular.io/license
302
+ */
303
+ /**
304
+ * Class to be used to power selecting one or more options from a list.
305
+ */
306
+ class SelectionModel {
307
+ constructor(_multiple = false, initiallySelectedValues, _emitChanges = true, compareWith) {
308
+ this._multiple = _multiple;
309
+ this._emitChanges = _emitChanges;
310
+ this.compareWith = compareWith;
311
+ /** Currently-selected values. */
312
+ this._selection = new Set();
313
+ /** Keeps track of the deselected options that haven't been emitted by the change event. */
314
+ this._deselectedToEmit = [];
315
+ /** Keeps track of the selected options that haven't been emitted by the change event. */
316
+ this._selectedToEmit = [];
317
+ /** Cache for the array value of the selected items. */
318
+ this._selected = null;
319
+ /** Event emitted when the value has changed. */
320
+ this.changed = new Subject();
321
+ if (initiallySelectedValues && initiallySelectedValues.length) {
322
+ if (_multiple) {
323
+ initiallySelectedValues.forEach(value => this._markSelected(value));
324
+ }
325
+ else {
326
+ this._markSelected(initiallySelectedValues[0]);
327
+ }
328
+ // Clear the array in order to avoid firing the change event for preselected values.
329
+ this._selectedToEmit.length = 0;
330
+ }
331
+ }
332
+ /** Selected values. */
333
+ get selected() {
334
+ if (!this._selected) {
335
+ this._selected = Array.from(this._selection.values());
336
+ }
337
+ return this._selected;
338
+ }
339
+ /**
340
+ * Selects a value or an array of values.
341
+ * @param values The values to select
342
+ * @return Whether the selection changed as a result of this call
343
+ * @breaking-change 16.0.0 make return type boolean
344
+ */
345
+ select(...values) {
346
+ this._verifyValueAssignment(values);
347
+ values.forEach(value => this._markSelected(value));
348
+ const changed = this._hasQueuedChanges();
349
+ this._emitChangeEvent();
350
+ return changed;
351
+ }
352
+ /**
353
+ * Deselects a value or an array of values.
354
+ * @param values The values to deselect
355
+ * @return Whether the selection changed as a result of this call
356
+ * @breaking-change 16.0.0 make return type boolean
357
+ */
358
+ deselect(...values) {
359
+ this._verifyValueAssignment(values);
360
+ values.forEach(value => this._unmarkSelected(value));
361
+ const changed = this._hasQueuedChanges();
362
+ this._emitChangeEvent();
363
+ return changed;
364
+ }
365
+ /**
366
+ * Sets the selected values
367
+ * @param values The new selected values
368
+ * @return Whether the selection changed as a result of this call
369
+ * @breaking-change 16.0.0 make return type boolean
370
+ */
371
+ setSelection(...values) {
372
+ this._verifyValueAssignment(values);
373
+ const oldValues = this.selected;
374
+ const newSelectedSet = new Set(values);
375
+ values.forEach(value => this._markSelected(value));
376
+ oldValues
377
+ .filter(value => !newSelectedSet.has(value))
378
+ .forEach(value => this._unmarkSelected(value));
379
+ const changed = this._hasQueuedChanges();
380
+ this._emitChangeEvent();
381
+ return changed;
382
+ }
383
+ /**
384
+ * Toggles a value between selected and deselected.
385
+ * @param value The value to toggle
386
+ * @return Whether the selection changed as a result of this call
387
+ * @breaking-change 16.0.0 make return type boolean
388
+ */
389
+ toggle(value) {
390
+ return this.isSelected(value) ? this.deselect(value) : this.select(value);
391
+ }
392
+ /**
393
+ * Clears all of the selected values.
394
+ * @param flushEvent Whether to flush the changes in an event.
395
+ * If false, the changes to the selection will be flushed along with the next event.
396
+ * @return Whether the selection changed as a result of this call
397
+ * @breaking-change 16.0.0 make return type boolean
398
+ */
399
+ clear(flushEvent = true) {
400
+ this._unmarkAll();
401
+ const changed = this._hasQueuedChanges();
402
+ if (flushEvent) {
403
+ this._emitChangeEvent();
404
+ }
405
+ return changed;
406
+ }
407
+ /**
408
+ * Determines whether a value is selected.
409
+ */
410
+ isSelected(value) {
411
+ if (this.compareWith) {
412
+ for (const otherValue of this._selection) {
413
+ if (this.compareWith(otherValue, value)) {
414
+ return true;
415
+ }
416
+ }
417
+ return false;
418
+ }
419
+ return this._selection.has(value);
420
+ }
421
+ /**
422
+ * Determines whether the model does not have a value.
423
+ */
424
+ isEmpty() {
425
+ return this._selection.size === 0;
426
+ }
427
+ /**
428
+ * Determines whether the model has a value.
429
+ */
430
+ hasValue() {
431
+ return !this.isEmpty();
432
+ }
433
+ /**
434
+ * Sorts the selected values based on a predicate function.
435
+ */
436
+ sort(predicate) {
437
+ if (this._multiple && this.selected) {
438
+ this._selected.sort(predicate);
439
+ }
440
+ }
441
+ /**
442
+ * Gets whether multiple values can be selected.
443
+ */
444
+ isMultipleSelection() {
445
+ return this._multiple;
446
+ }
447
+ /** Emits a change event and clears the records of selected and deselected values. */
448
+ _emitChangeEvent() {
449
+ // Clear the selected values so they can be re-cached.
450
+ this._selected = null;
451
+ if (this._selectedToEmit.length || this._deselectedToEmit.length) {
452
+ this.changed.next({
453
+ source: this,
454
+ added: this._selectedToEmit,
455
+ removed: this._deselectedToEmit,
456
+ });
457
+ this._deselectedToEmit = [];
458
+ this._selectedToEmit = [];
459
+ }
460
+ }
461
+ /** Selects a value. */
462
+ _markSelected(value) {
463
+ if (!this.isSelected(value)) {
464
+ if (!this._multiple) {
465
+ this._unmarkAll();
466
+ }
467
+ if (!this.isSelected(value)) {
468
+ this._selection.add(value);
469
+ }
470
+ if (this._emitChanges) {
471
+ this._selectedToEmit.push(value);
472
+ }
473
+ }
474
+ }
475
+ /** Deselects a value. */
476
+ _unmarkSelected(value) {
477
+ if (this.isSelected(value)) {
478
+ this._selection.delete(value);
479
+ if (this._emitChanges) {
480
+ this._deselectedToEmit.push(value);
481
+ }
482
+ }
483
+ }
484
+ /** Clears out the selected values. */
485
+ _unmarkAll() {
486
+ if (!this.isEmpty()) {
487
+ this._selection.forEach(value => this._unmarkSelected(value));
488
+ }
489
+ }
490
+ /**
491
+ * Verifies the value assignment and throws an error if the specified value array is
492
+ * including multiple values while the selection model is not supporting multiple values.
493
+ */
494
+ _verifyValueAssignment(values) {
495
+ if (values.length > 1 && !this._multiple && (typeof ngDevMode === 'undefined' || ngDevMode)) {
496
+ throw getMultipleValuesInSingleSelectionError();
497
+ }
498
+ }
499
+ /** Whether there are queued up change to be emitted. */
500
+ _hasQueuedChanges() {
501
+ return !!(this._deselectedToEmit.length || this._selectedToEmit.length);
502
+ }
503
+ }
504
+ /**
505
+ * Returns an error that reports that multiple values are passed into a selection model
506
+ * with a single value.
507
+ * @docs-private
508
+ */
509
+ function getMultipleValuesInSingleSelectionError() {
510
+ return Error('Cannot pass multiple values into SelectionModel with single-value mode.');
511
+ }
512
+
297
513
  class SelectRowService {
298
514
  constructor(options = null) {
299
515
  this.selectionModel = new SelectionModel(true);
300
- this.selectionModel = new SelectionModel(options === null || options === void 0 ? void 0 : options.multiple);
301
- if (options === null || options === void 0 ? void 0 : options.selected) {
302
- this.selectionModel.select(...options === null || options === void 0 ? void 0 : options.selected);
303
- }
516
+ this.selectionModel = new SelectionModel(options === null || options === void 0 ? void 0 : options.multiple, options === null || options === void 0 ? void 0 : options.selected, options === null || options === void 0 ? void 0 : options.emitChanges, options === null || options === void 0 ? void 0 : options.compareWith);
304
517
  this.selectedRows$ = this.selectionModel.changed.pipe(map(() => this.selectionModel.selected));
305
518
  }
306
519
  get selectedRows() {
@@ -624,7 +837,20 @@ class TableDataSourceDirective {
624
837
  this.dataSource.sort = (_d = this.matSort) !== null && _d !== void 0 ? _d : undefined;
625
838
  this.dataSource.filter = tableFilter;
626
839
  this.dataSource.parameters = this.parameters;
840
+ if (this.dataSource instanceof DynamicTableDataSource) {
841
+ this.dataSource.setPaginator(this.paginator, this.id);
842
+ this.dataSource.setSort(this.matSort, this.id);
843
+ this.dataSource.setFilter(tableFilter, this.id);
844
+ this.dataSource.setParameters(this.parameters, this.id);
845
+ }
627
846
  this._subscription.add(this.dataSource.loading$.pipe(tap(loading => this.loading$.next(!!loading))).subscribe());
847
+ // create the id property for the mat table component.
848
+ // the instance of the mat table component is used as viewer object
849
+ // with the set of the id property it is possible to use the same data source
850
+ // instance for multiple table component simultaneously
851
+ // on connect the data source can then use the correct paginator/matSort/tableFilter/parameters instance
852
+ // to create the TableEvent objects
853
+ Reflect.set(this.matTable, 'id', this.id);
628
854
  this.matTable.dataSource = pipeDataSource(this.dataSource, tap(rowList => rowList.forEach((element) => {
629
855
  element.__metadata__ = { loading$: new ToggleSubject() };
630
856
  })));