@clr/angular 17.11.8 → 17.11.10

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.
@@ -9,7 +9,7 @@ import { Subject, BehaviorSubject, Observable, fromEvent, isObservable, of, shar
9
9
  import * as i2 from '@angular/animations';
10
10
  import { animation, style, animate, trigger, transition, state, useAnimation, keyframes } from '@angular/animations';
11
11
  import * as i1 from '@angular/forms';
12
- import { FormControl, FormGroup, FormsModule, NG_VALIDATORS, NG_VALUE_ACCESSOR, SelectMultipleControlValueAccessor, DefaultValueAccessor } from '@angular/forms';
12
+ import { FormControl, FormGroup, FormsModule, NG_VALIDATORS, NG_VALUE_ACCESSOR, SelectMultipleControlValueAccessor } from '@angular/forms';
13
13
  import * as i1$1 from '@angular/router';
14
14
  import { RouterModule } from '@angular/router';
15
15
  import * as i1$2 from '@angular/cdk/a11y';
@@ -20974,8 +20974,9 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.2", ngImpor
20974
20974
  */
20975
20975
  let nbSelection = 0;
20976
20976
  class Selection {
20977
- constructor(_items, filters) {
20977
+ constructor(_items, filters, differs) {
20978
20978
  this._items = _items;
20979
+ this.differs = differs;
20979
20980
  this.preserveSelection = false;
20980
20981
  /**
20981
20982
  * Shift key state, for use in range selection.
@@ -20983,8 +20984,8 @@ class Selection {
20983
20984
  this.shiftPressed = false;
20984
20985
  /** @deprecated since 2.0, remove in 3.0 */
20985
20986
  this.rowSelectionMode = false;
20986
- this.prevSelectionRefs = []; // Refs of selected items
20987
20987
  this.lockedRefs = []; // Ref of locked items
20988
+ this._currentSelectionRefs = [];
20988
20989
  this.valueCollector = new Subject();
20989
20990
  this._selectionType = SelectionType.None;
20990
20991
  /**
@@ -20996,6 +20997,8 @@ class Selection {
20996
20997
  */
20997
20998
  this.subscriptions = [];
20998
20999
  this.id = 'clr-dg-selection' + nbSelection++;
21000
+ this.trackBy = _items.trackBy;
21001
+ this._differ = differs.find(this._current || []).create(this.trackBy);
20999
21002
  this.subscriptions.push(filters.change.subscribe(() => {
21000
21003
  if (!this._selectable || this.preserveSelection) {
21001
21004
  return;
@@ -21012,14 +21015,10 @@ class Selection {
21012
21015
  case SelectionType.Single: {
21013
21016
  let newSingle;
21014
21017
  let selectionUpdated = false;
21015
- // if the currentSingle has been set before data was loaded, we look up and save the ref from current data set
21016
- if (this.currentSingle && !this.prevSingleSelectionRef) {
21017
- this.prevSingleSelectionRef = _items.trackBy(this.currentSingle);
21018
- }
21019
21018
  updatedItems.forEach(item => {
21020
21019
  const ref = _items.trackBy(item);
21021
21020
  // If one of the updated items is the previously selectedSingle, set it as the new one
21022
- if (this.prevSingleSelectionRef === ref) {
21021
+ if (this.currentSingleSelectionRef === ref) {
21023
21022
  newSingle = item;
21024
21023
  selectionUpdated = true;
21025
21024
  }
@@ -21042,13 +21041,6 @@ class Selection {
21042
21041
  case SelectionType.Multi: {
21043
21042
  let leftOver = this.current.slice();
21044
21043
  let selectionUpdated = false;
21045
- // if the current has been set before data was loaded, we look up and save the ref from current data set
21046
- if (this.current.length > 0 && this.prevSelectionRefs.length !== this.current.length) {
21047
- this.prevSelectionRefs = [];
21048
- this.current.forEach(item => {
21049
- this.prevSelectionRefs.push(_items.trackBy(item));
21050
- });
21051
- }
21052
21044
  // Duplicate loop, when the issue is issue#2342 is revisited keep in mind that
21053
21045
  // we need to go over every updated item and check to see if there are valid to be
21054
21046
  // locked or not and update it. When only add items that are found in the lockedRefs back.
@@ -21067,7 +21059,7 @@ class Selection {
21067
21059
  updatedItems.forEach(item => {
21068
21060
  const ref = _items.trackBy(item);
21069
21061
  // Look in current selected refs array if item is selected, and update actual value
21070
- const selectedIndex = this.prevSelectionRefs.indexOf(ref);
21062
+ const selectedIndex = this.currentSelectionRefs.indexOf(ref);
21071
21063
  if (selectedIndex > -1) {
21072
21064
  leftOver[selectedIndex] = item;
21073
21065
  selectionUpdated = true;
@@ -21116,6 +21108,7 @@ class Selection {
21116
21108
  }
21117
21109
  set current(value) {
21118
21110
  this.updateCurrent(value, true);
21111
+ this.updateCurrentSelectionRefs();
21119
21112
  }
21120
21113
  get currentSingle() {
21121
21114
  return this._currentSingle;
@@ -21125,9 +21118,6 @@ class Selection {
21125
21118
  return;
21126
21119
  }
21127
21120
  this._currentSingle = value;
21128
- if (value) {
21129
- this.prevSingleSelectionRef = this._items.trackBy(value);
21130
- }
21131
21121
  this.emitChange();
21132
21122
  }
21133
21123
  // We do not want to expose the Subject itself, but the Observable which is read-only
@@ -21139,16 +21129,25 @@ class Selection {
21139
21129
  }
21140
21130
  // Refs of currently selected items
21141
21131
  get currentSelectionRefs() {
21142
- return this._current?.map(item => this._items.trackBy(item)) || [];
21132
+ return this._currentSelectionRefs;
21143
21133
  }
21144
21134
  // Ref of currently selected item
21145
21135
  get currentSingleSelectionRef() {
21146
21136
  return this._currentSingle && this._items.trackBy(this._currentSingle);
21147
21137
  }
21138
+ checkForChanges() {
21139
+ const changes = this._differ.diff(this._current);
21140
+ // @TODO move the trackBy from items to selection as it's used only here and is not needed in items
21141
+ if (this.trackBy !== this._items.trackBy) {
21142
+ this.trackBy = this._items.trackBy;
21143
+ }
21144
+ if (changes) {
21145
+ this.updateCurrentSelectionRefs();
21146
+ }
21147
+ }
21148
21148
  clearSelection() {
21149
21149
  this._current = [];
21150
- this.prevSelectionRefs = [];
21151
- this.prevSingleSelectionRef = null;
21150
+ this._currentSelectionRefs = [];
21152
21151
  this._currentSingle = null;
21153
21152
  this.emitChange();
21154
21153
  }
@@ -21288,17 +21287,15 @@ class Selection {
21288
21287
  */
21289
21288
  selectItem(item) {
21290
21289
  this.current = this.current.concat(item);
21291
- // Push selected ref onto array
21292
- this.prevSelectionRefs.push(this._items.trackBy(item));
21293
21290
  }
21294
21291
  /**
21295
21292
  * Deselects an item
21296
21293
  */
21297
21294
  deselectItem(indexOfItem) {
21298
21295
  this.current = this.current.slice(0, indexOfItem).concat(this.current.slice(indexOfItem + 1));
21299
- if (indexOfItem < this.prevSelectionRefs.length) {
21296
+ if (indexOfItem < this.currentSelectionRefs.length) {
21300
21297
  // Keep selected refs array in sync
21301
- const removedItems = this.prevSelectionRefs.splice(indexOfItem, 1);
21298
+ const removedItems = this.currentSelectionRefs[indexOfItem];
21302
21299
  // locked reference is no longer needed (if any)
21303
21300
  this.lockedRefs = this.lockedRefs.filter(locked => locked !== removedItems[0]);
21304
21301
  }
@@ -21317,12 +21314,15 @@ class Selection {
21317
21314
  this._change.next(this.current);
21318
21315
  }
21319
21316
  }
21317
+ updateCurrentSelectionRefs() {
21318
+ this._currentSelectionRefs = this._current?.map(item => this._items.trackBy(item)) || [];
21319
+ }
21320
21320
  }
21321
- Selection.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.2", ngImport: i0, type: Selection, deps: [{ token: Items }, { token: FiltersProvider }], target: i0.ɵɵFactoryTarget.Injectable });
21321
+ Selection.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.2", ngImport: i0, type: Selection, deps: [{ token: Items }, { token: FiltersProvider }, { token: i0.IterableDiffers }], target: i0.ɵɵFactoryTarget.Injectable });
21322
21322
  Selection.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.2", ngImport: i0, type: Selection });
21323
21323
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.2", ngImport: i0, type: Selection, decorators: [{
21324
21324
  type: Injectable
21325
- }], ctorParameters: function () { return [{ type: Items }, { type: FiltersProvider }]; } });
21325
+ }], ctorParameters: function () { return [{ type: Items }, { type: FiltersProvider }, { type: i0.IterableDiffers }]; } });
21326
21326
 
21327
21327
  /*
21328
21328
  * Copyright (c) 2016-2025 Broadcom. All Rights Reserved.
@@ -21394,14 +21394,26 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.2", ngImpor
21394
21394
  * This software is released under MIT license.
21395
21395
  * The full license information can be found in LICENSE in the root directory of this project.
21396
21396
  */
21397
- class ClrDatagridSingleSelectionValueAccessor extends DefaultValueAccessor {
21397
+ class ClrDatagridSingleSelectionValueAccessor {
21398
21398
  constructor(renderer, elementRef) {
21399
- super(renderer, elementRef, null);
21400
21399
  this.renderer = renderer;
21401
21400
  this.elementRef = elementRef;
21401
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
21402
+ this.onChange = () => { };
21403
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
21404
+ this.onTouched = () => { };
21405
+ }
21406
+ registerOnChange(fn) {
21407
+ this.onChange = fn;
21408
+ }
21409
+ registerOnTouched(fn) {
21410
+ this.onTouched = fn;
21411
+ }
21412
+ setDisabledState(isDisabled) {
21413
+ this.renderer.setProperty(this.elementRef.nativeElement, 'disabled', isDisabled);
21402
21414
  }
21403
21415
  writeValue(value) {
21404
- this.model = value;
21416
+ this.state = value;
21405
21417
  this.updateChecked();
21406
21418
  }
21407
21419
  keyOf(value) {
@@ -21411,7 +21423,7 @@ class ClrDatagridSingleSelectionValueAccessor extends DefaultValueAccessor {
21411
21423
  return value;
21412
21424
  }
21413
21425
  updateChecked() {
21414
- const model = this.keyOf(this.model);
21426
+ const model = this.keyOf(this.state);
21415
21427
  const value = this.keyOf(this.value);
21416
21428
  this.renderer.setProperty(this.elementRef.nativeElement, 'checked', model === value);
21417
21429
  }
@@ -21423,7 +21435,7 @@ ClrDatagridSingleSelectionValueAccessor.ɵdir = i0.ɵɵngDeclareDirective({ minV
21423
21435
  useExisting: forwardRef(() => ClrDatagridSingleSelectionValueAccessor),
21424
21436
  multi: true,
21425
21437
  },
21426
- ], usesInheritance: true, ngImport: i0 });
21438
+ ], ngImport: i0 });
21427
21439
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.2", ngImport: i0, type: ClrDatagridSingleSelectionValueAccessor, decorators: [{
21428
21440
  type: Directive,
21429
21441
  args: [{
@@ -21702,6 +21714,7 @@ class ClrDatagridRow {
21702
21714
  const newSelection = new Set(this.selection.current.concat(items.slice(Math.min(startIx, endIx), Math.max(startIx, endIx) + 1)));
21703
21715
  this.selection.clearSelection();
21704
21716
  this.selection.current.push(...newSelection);
21717
+ this.selection.checkForChanges();
21705
21718
  }
21706
21719
  else {
21707
21720
  // page number has changed or
@@ -22623,6 +22636,11 @@ class ClrDatagrid {
22623
22636
  }));
22624
22637
  });
22625
22638
  }
22639
+ ngDoCheck() {
22640
+ // we track for changes on selection.current because it can happen with pushing items
22641
+ // instead of overriding the variable
22642
+ this.selection.checkForChanges();
22643
+ }
22626
22644
  ngOnDestroy() {
22627
22645
  this._subscriptions.forEach((sub) => sub.unsubscribe());
22628
22646
  this._virtualScrollSubscriptions.forEach((sub) => sub.unsubscribe());