@@ -51,13 +51,17 @@ export class SelectionManager<T extends IGridDataEntry> {
5151 hasValue$ = this . _hasValue$ . pipe ( distinctUntilChanged ( ) ) ;
5252
5353 private _selection = new Map < number | string , T > ( ) ;
54+ private _indeterminate = new Map < number | string , T > ( ) ;
5455
5556 private _selectionSnapshot = new Map < number | string , T > ( ) ;
57+ private _indeterminateSnapshot = new Map < number | string , T > ( ) ;
5658
5759 private _deselectedToEmit : T [ ] = [ ] ;
5860
5961 private _selectedToEmit : T [ ] = [ ] ;
6062
63+ private _indeterminateToEmit : T [ ] = [ ] ;
64+
6165 private _disableSelectionByEntry ! : ( entry : T ) => null | string ;
6266
6367 constructor (
@@ -77,6 +81,9 @@ export class SelectionManager<T extends IGridDataEntry> {
7781 deselect = ( ...values : T [ ] ) : void =>
7882 this . _updateState ( this . _unmarkSelected , values ) ;
7983
84+ setIndeterminate = ( ...values : T [ ] ) : void =>
85+ this . _updateState ( this . _markIndeterminate , values ) ;
86+
8087 toggle ( value : T ) : void {
8188 // eslint-disable-next-line @typescript-eslint/no-unused-expressions
8289 this . isSelected ( value ) ? this . deselect ( value ) : this . select ( value ) ;
@@ -85,13 +92,18 @@ export class SelectionManager<T extends IGridDataEntry> {
8592 clear ( ) : void {
8693 this . _selection . forEach ( v => this . _unmarkSelected ( v ) ) ;
8794 this . _selection . clear ( ) ;
95+ this . _indeterminate . clear ( ) ;
8896 this . _emitChangeEvent ( ) ;
8997 }
9098
9199 isSelected ( value : T ) : boolean {
92100 return this . _selection . has ( value . id ) ;
93101 }
94102
103+ isIndeterminate ( value : T ) : boolean {
104+ return this . _indeterminate . has ( value . id ) ;
105+ }
106+
95107 isEmpty ( ) : boolean {
96108 return this . _selection . size === 0 ;
97109 }
@@ -102,11 +114,14 @@ export class SelectionManager<T extends IGridDataEntry> {
102114
103115 snapshot ( ) {
104116 this . _selectionSnapshot = cloneDeep ( this . _selection ) ;
117+ this . _indeterminateSnapshot = cloneDeep ( this . _indeterminate ) ;
105118 }
106119
107120 destroy ( ) {
108121 this . _selection . clear ( ) ;
109122 this . _selectionSnapshot . clear ( ) ;
123+ this . _indeterminate . clear ( ) ;
124+ this . _indeterminateSnapshot . clear ( ) ;
110125 this . _hasValue$ . next ( false ) ;
111126 }
112127
@@ -125,10 +140,12 @@ export class SelectionManager<T extends IGridDataEntry> {
125140 source : { } as SelectionModel < T > ,
126141 added : this . _selectedToEmit ,
127142 removed : this . _deselectedToEmit ,
143+ indeterminate : this . _indeterminateToEmit ,
128144 } as SelectionChange < T > ) ;
129145
130146 this . _deselectedToEmit = [ ] ;
131147 this . _selectedToEmit = [ ] ;
148+ this . _indeterminateToEmit = [ ] ;
132149 }
133150 }
134151
@@ -145,10 +162,21 @@ export class SelectionManager<T extends IGridDataEntry> {
145162 private _unmarkSelected = ( value : T ) => {
146163 if ( this . isSelected ( value ) ) {
147164 this . _selection . delete ( value . id ) ;
165+ this . _indeterminate . delete ( value . id ) ;
148166
149167 if ( this . _emitChanges ) {
150168 this . _deselectedToEmit . push ( value ) ;
151169 }
152170 }
153171 } ;
172+
173+ private _markIndeterminate = ( value : T ) => {
174+ if ( ! this . isIndeterminate ( value ) ) {
175+ this . _indeterminate . set ( value . id , cloneDeep ( value ) ) ;
176+
177+ if ( this . _emitChanges ) {
178+ this . _indeterminateToEmit . push ( value ) ;
179+ }
180+ }
181+ } ;
154182}
0 commit comments