@@ -51,13 +51,17 @@ export class SelectionManager<T extends IGridDataEntry> {
51
51
hasValue$ = this . _hasValue$ . pipe ( distinctUntilChanged ( ) ) ;
52
52
53
53
private _selection = new Map < number | string , T > ( ) ;
54
+ private _indeterminate = new Map < number | string , T > ( ) ;
54
55
55
56
private _selectionSnapshot = new Map < number | string , T > ( ) ;
57
+ private _indeterminateSnapshot = new Map < number | string , T > ( ) ;
56
58
57
59
private _deselectedToEmit : T [ ] = [ ] ;
58
60
59
61
private _selectedToEmit : T [ ] = [ ] ;
60
62
63
+ private _indeterminateToEmit : T [ ] = [ ] ;
64
+
61
65
private _disableSelectionByEntry ! : ( entry : T ) => null | string ;
62
66
63
67
constructor (
@@ -77,6 +81,9 @@ export class SelectionManager<T extends IGridDataEntry> {
77
81
deselect = ( ...values : T [ ] ) : void =>
78
82
this . _updateState ( this . _unmarkSelected , values ) ;
79
83
84
+ setIndeterminate = ( ...values : T [ ] ) : void =>
85
+ this . _updateState ( this . _markIndeterminate , values ) ;
86
+
80
87
toggle ( value : T ) : void {
81
88
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
82
89
this . isSelected ( value ) ? this . deselect ( value ) : this . select ( value ) ;
@@ -85,13 +92,18 @@ export class SelectionManager<T extends IGridDataEntry> {
85
92
clear ( ) : void {
86
93
this . _selection . forEach ( v => this . _unmarkSelected ( v ) ) ;
87
94
this . _selection . clear ( ) ;
95
+ this . _indeterminate . clear ( ) ;
88
96
this . _emitChangeEvent ( ) ;
89
97
}
90
98
91
99
isSelected ( value : T ) : boolean {
92
100
return this . _selection . has ( value . id ) ;
93
101
}
94
102
103
+ isIndeterminate ( value : T ) : boolean {
104
+ return this . _indeterminate . has ( value . id ) ;
105
+ }
106
+
95
107
isEmpty ( ) : boolean {
96
108
return this . _selection . size === 0 ;
97
109
}
@@ -102,11 +114,14 @@ export class SelectionManager<T extends IGridDataEntry> {
102
114
103
115
snapshot ( ) {
104
116
this . _selectionSnapshot = cloneDeep ( this . _selection ) ;
117
+ this . _indeterminateSnapshot = cloneDeep ( this . _indeterminate ) ;
105
118
}
106
119
107
120
destroy ( ) {
108
121
this . _selection . clear ( ) ;
109
122
this . _selectionSnapshot . clear ( ) ;
123
+ this . _indeterminate . clear ( ) ;
124
+ this . _indeterminateSnapshot . clear ( ) ;
110
125
this . _hasValue$ . next ( false ) ;
111
126
}
112
127
@@ -125,10 +140,12 @@ export class SelectionManager<T extends IGridDataEntry> {
125
140
source : { } as SelectionModel < T > ,
126
141
added : this . _selectedToEmit ,
127
142
removed : this . _deselectedToEmit ,
143
+ indeterminate : this . _indeterminateToEmit ,
128
144
} as SelectionChange < T > ) ;
129
145
130
146
this . _deselectedToEmit = [ ] ;
131
147
this . _selectedToEmit = [ ] ;
148
+ this . _indeterminateToEmit = [ ] ;
132
149
}
133
150
}
134
151
@@ -145,10 +162,21 @@ export class SelectionManager<T extends IGridDataEntry> {
145
162
private _unmarkSelected = ( value : T ) => {
146
163
if ( this . isSelected ( value ) ) {
147
164
this . _selection . delete ( value . id ) ;
165
+ this . _indeterminate . delete ( value . id ) ;
148
166
149
167
if ( this . _emitChanges ) {
150
168
this . _deselectedToEmit . push ( value ) ;
151
169
}
152
170
}
153
171
} ;
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
+ } ;
154
182
}
0 commit comments