@@ -21,10 +21,19 @@ export type TreeSelectionStateObject =
21
21
22
22
type TreeSelectionStateConfigObject = {
23
23
treePaths : DeepMap < any , true > ;
24
+ strictCheckPaths : boolean ;
24
25
} ;
25
26
26
27
export type TreeSelectionStateConfigParam < _T = any > = {
27
- treePaths : TreeSelectionStateConfigObject [ 'treePaths' ] | [ any [ ] ] ;
28
+ treePaths : TreeSelectionStateConfigObject [ 'treePaths' ] | any [ ] [ ] ;
29
+ /**
30
+ * Defaults to true. If false, when checking if a given path is selected,
31
+ * it will not check if the path is in the treePaths, but will only check
32
+ * in the selectionMap.
33
+ *
34
+ * If true, will check for the path both in the treePaths and the selectionMap.
35
+ */
36
+ strictCheckPaths ?: boolean ;
28
37
} ;
29
38
export type GetTreeSelectionStateConfig < T > =
30
39
| TreeSelectionStateConfigParam < T >
@@ -210,9 +219,12 @@ export class TreeSelectionState<T = any> {
210
219
} ) ,
211
220
) ;
212
221
213
- this . disableCorrectnessChecks ( ) ;
222
+ this . disableStrictMode ( ) ;
214
223
this . update ( stateObject ) ;
215
- this . enableCorrectnessChecks ( ) ;
224
+
225
+ if ( this . config . strictCheckPaths ) {
226
+ this . enableStrictMode ( ) ;
227
+ }
216
228
}
217
229
setConfig ( getConfig : GetTreeSelectionStateConfig < T > ) {
218
230
const config = typeof getConfig === 'function' ? getConfig ( ) : getConfig ;
@@ -221,6 +233,7 @@ export class TreeSelectionState<T = any> {
221
233
treePaths : Array . isArray ( config . treePaths )
222
234
? new DeepMap ( config . treePaths . map ( ( path ) => [ path , true ] ) )
223
235
: config . treePaths ,
236
+ strictCheckPaths : config . strictCheckPaths ?? true ,
224
237
} ;
225
238
this . xcache ( ) ;
226
239
}
@@ -291,18 +304,18 @@ export class TreeSelectionState<T = any> {
291
304
} ) ;
292
305
}
293
306
294
- private correctnessChecks = false ;
307
+ private strictMode = false ;
295
308
296
- enableCorrectnessChecks ( ) {
297
- this . correctnessChecks = true ;
309
+ enableStrictMode ( ) {
310
+ this . strictMode = true ;
298
311
}
299
312
300
- disableCorrectnessChecks ( ) {
301
- this . correctnessChecks = false ;
313
+ disableStrictMode ( ) {
314
+ this . strictMode = false ;
302
315
}
303
316
304
317
isPathAvailable ( nodePath : NodePath ) {
305
- if ( ! this . correctnessChecks ) {
318
+ if ( ! this . strictMode ) {
306
319
return true ;
307
320
}
308
321
@@ -357,7 +370,7 @@ export class TreeSelectionState<T = any> {
357
370
} )
358
371
. sort ( shortestToLongest ) ;
359
372
360
- if ( this . correctnessChecks ) {
373
+ if ( this . strictMode ) {
361
374
childPaths = childPaths . filter ( ( path ) => this . isPathAvailable ( path ) ) ;
362
375
}
363
376
0 commit comments