@@ -15,7 +15,7 @@ import {
15
15
} from './utils/domUtils' ;
16
16
import { BindingEventService , VirtualScroll } from './services' ;
17
17
import { MultipleSelectOption } from './interfaces/multipleSelectOption.interface' ;
18
- import { MultipleSelectLocales , OptGroupRowData , OptionRowData } from './interfaces' ;
18
+ import { MultipleSelectLocales , OptGroupRowData , OptionDataObject , OptionRowData } from './interfaces' ;
19
19
20
20
export class MultipleSelectInstance {
21
21
protected _bindEventService : BindingEventService ;
@@ -25,7 +25,7 @@ export class MultipleSelectInstance {
25
25
protected closeElm ?: HTMLElement | null ;
26
26
protected filterText = '' ;
27
27
protected updateData : any [ ] = [ ] ;
28
- protected data : OptionRowData [ ] = [ ] ;
28
+ protected data ?: Array < OptionRowData | OptGroupRowData > = [ ] ;
29
29
protected dataTotal ?: any ;
30
30
protected dropElm ! : HTMLDivElement ;
31
31
protected okButtonElm ?: HTMLButtonElement ;
@@ -253,7 +253,7 @@ export class MultipleSelectInstance {
253
253
}
254
254
255
255
protected initData ( ) {
256
- const data : any [ ] = [ ] ;
256
+ const data : Array < OptionRowData > = [ ] ;
257
257
258
258
if ( this . options . data ) {
259
259
if ( Array . isArray ( this . options . data ) ) {
@@ -267,10 +267,10 @@ export class MultipleSelectInstance {
267
267
return it ;
268
268
} ) ;
269
269
} else if ( typeof this . options . data === 'object' ) {
270
- for ( const [ value , text ] of Object . entries ( this . options . data ) ) {
270
+ for ( const [ value , text ] of Object . entries ( this . options . data as OptionDataObject ) ) {
271
271
data . push ( {
272
272
value,
273
- text,
273
+ text : ` ${ text } ` ,
274
274
} ) ;
275
275
}
276
276
this . data = data ;
@@ -288,7 +288,7 @@ export class MultipleSelectInstance {
288
288
this . fromHtml = true ;
289
289
}
290
290
291
- this . dataTotal = setDataKeys ( this . data ) ;
291
+ this . dataTotal = setDataKeys ( this . data || [ ] ) ;
292
292
}
293
293
294
294
protected initRow ( elm : HTMLOptionElement , groupDisabled ?: boolean ) {
@@ -361,7 +361,7 @@ export class MultipleSelectInstance {
361
361
362
362
let length = 0 ;
363
363
for ( const option of this . data || [ ] ) {
364
- if ( option . type === 'optgroup' ) {
364
+ if ( ( option as OptGroupRowData ) . type === 'optgroup' ) {
365
365
length += ( option as OptGroupRowData ) . children . length ;
366
366
} else {
367
367
length += 1 ;
@@ -436,8 +436,8 @@ export class MultipleSelectInstance {
436
436
if ( this . updateDataStart < 0 ) {
437
437
this . updateDataStart = 0 ;
438
438
}
439
- if ( this . updateDataEnd > this . data . length ) {
440
- this . updateDataEnd = this . data . length ;
439
+ if ( this . updateDataEnd > ( this . data ? .length ?? 0 ) ) {
440
+ this . updateDataEnd = this . data ? .length ?? 0 ;
441
441
}
442
442
}
443
443
} ;
@@ -476,7 +476,7 @@ export class MultipleSelectInstance {
476
476
const rows = [ ] ;
477
477
478
478
this . updateData = [ ] ;
479
- this . data . forEach ( ( row ) => {
479
+ this . data ? .forEach ( ( row ) => {
480
480
rows . push ( ...this . initListItem ( row ) ) ;
481
481
} ) ;
482
482
@@ -572,7 +572,7 @@ export class MultipleSelectInstance {
572
572
let selectedTotal = 0 ;
573
573
574
574
for ( const row of this . data || [ ] ) {
575
- if ( row . type === 'optgroup' ) {
575
+ if ( ( row as OptGroupRowData ) . type === 'optgroup' ) {
576
576
const selectedCount = ( row as OptGroupRowData ) . children . filter ( ( child ) => {
577
577
return child && child . selected && ! child . disabled && child . visible ;
578
578
} ) . length ;
@@ -593,9 +593,9 @@ export class MultipleSelectInstance {
593
593
}
594
594
595
595
this . allSelected =
596
- this . data . filter ( ( row : OptionRowData ) => {
596
+ this . data ? .filter ( ( row : OptionRowData | OptGroupRowData ) => {
597
597
return row . selected && ! row . disabled && row . visible ;
598
- } ) . length === this . data . filter ( ( row ) => ! row . disabled && row . visible && ! row . divider ) . length ;
598
+ } ) . length === this . data ? .filter ( ( row ) => ! row . disabled && row . visible && ! row . divider ) . length ;
599
599
600
600
if ( ! ignoreTrigger ) {
601
601
if ( this . allSelected ) {
@@ -806,7 +806,7 @@ export class MultipleSelectInstance {
806
806
this . noResultsElm . style . display = 'none' ;
807
807
}
808
808
809
- if ( ! this . data . length ) {
809
+ if ( ! this . data ? .length ) {
810
810
if ( this . selectAllElm ?. parentElement ) {
811
811
this . selectAllElm . parentElement . style . display = 'none' ;
812
812
}
@@ -849,7 +849,7 @@ export class MultipleSelectInstance {
849
849
const multElms = this . dropElm . querySelectorAll < HTMLDivElement > ( '.multiple' ) ;
850
850
multElms . forEach ( ( multElm ) => ( multElm . style . width = `${ this . options . multipleWidth } px` ) ) ;
851
851
852
- if ( this . data . length && this . options . filter ) {
852
+ if ( this . data ? .length && this . options . filter ) {
853
853
if ( this . searchInputElm ) {
854
854
this . searchInputElm . value = '' ;
855
855
this . searchInputElm . focus ( ) ;
@@ -988,7 +988,7 @@ export class MultipleSelectInstance {
988
988
}
989
989
}
990
990
991
- const noResult = this . data . filter ( ( row ) => row . visible ) . length === 0 ;
991
+ const noResult = this . data ? .filter ( ( row ) => row . visible ) . length === 0 ;
992
992
993
993
if ( this . selectAllElm ) {
994
994
this . selectAllElm . checked = this . allSelected ;
@@ -1037,7 +1037,7 @@ export class MultipleSelectInstance {
1037
1037
getSelects ( type = 'value' ) {
1038
1038
const values = [ ] ;
1039
1039
for ( const row of this . data || [ ] ) {
1040
- if ( row . type === 'optgroup' ) {
1040
+ if ( ( row as OptGroupRowData ) . type === 'optgroup' ) {
1041
1041
const selectedChildren = ( row as OptGroupRowData ) . children . filter ( ( child ) => child ?. selected ) ;
1042
1042
if ( ! selectedChildren . length ) {
1043
1043
continue ;
@@ -1052,13 +1052,13 @@ export class MultipleSelectInstance {
1052
1052
} else {
1053
1053
const value = [ ] ;
1054
1054
value . push ( '[' ) ;
1055
- value . push ( row . label ) ;
1055
+ value . push ( ( row as OptGroupRowData ) . label ) ;
1056
1056
value . push ( `: ${ selectedChildren . map ( ( child : any ) => child [ type ] ) . join ( ', ' ) } ` ) ;
1057
1057
value . push ( ']' ) ;
1058
1058
values . push ( value . join ( '' ) ) ;
1059
1059
}
1060
1060
} else if ( row . selected ) {
1061
- values . push ( type === 'value' ? row . _value || row [ type ] : ( row as any ) [ type ] ) ;
1061
+ values . push ( type === 'value' ? row . _value || ( row as OptionRowData ) [ type ] : ( row as any ) [ type ] ) ;
1062
1062
}
1063
1063
}
1064
1064
return values ;
@@ -1085,7 +1085,7 @@ export class MultipleSelectInstance {
1085
1085
} ;
1086
1086
1087
1087
for ( const row of this . data || [ ] ) {
1088
- if ( row . type === 'optgroup' ) {
1088
+ if ( ( row as OptGroupRowData ) . type === 'optgroup' ) {
1089
1089
_setSelects ( ( row as OptGroupRowData ) . children ) ;
1090
1090
} else {
1091
1091
_setSelects ( [ row ] ) ;
@@ -1143,7 +1143,7 @@ export class MultipleSelectInstance {
1143
1143
1144
1144
protected _checkAll ( checked : boolean , ignoreUpdate ?: boolean ) {
1145
1145
for ( const row of this . data || [ ] ) {
1146
- if ( row . type === 'optgroup' ) {
1146
+ if ( ( row as OptGroupRowData ) . type === 'optgroup' ) {
1147
1147
this . _checkGroup ( row , checked , true ) ;
1148
1148
} else if ( ! row . disabled && ! row . divider && ( ignoreUpdate || row . visible ) ) {
1149
1149
row . selected = checked ;
@@ -1177,7 +1177,7 @@ export class MultipleSelectInstance {
1177
1177
return ;
1178
1178
}
1179
1179
for ( const row of this . data || [ ] ) {
1180
- if ( row . type === 'optgroup' ) {
1180
+ if ( ( row as OptGroupRowData ) . type === 'optgroup' ) {
1181
1181
for ( const child of ( row as OptGroupRowData ) . children ) {
1182
1182
if ( child ) {
1183
1183
if ( ! child . divider ) {
@@ -1221,9 +1221,9 @@ export class MultipleSelectInstance {
1221
1221
this . filterText = text ;
1222
1222
1223
1223
for ( const row of this . data || [ ] ) {
1224
- if ( row . type === 'optgroup' ) {
1224
+ if ( ( row as OptGroupRowData ) . type === 'optgroup' ) {
1225
1225
if ( this . options . filterGroup ) {
1226
- const rowLabel = `${ row ?. label ?? '' } ` ;
1226
+ const rowLabel = `${ ( row as OptGroupRowData ) ?. label ?? '' } ` ;
1227
1227
if ( row !== undefined && row !== null ) {
1228
1228
const visible = this . options . customFilter (
1229
1229
removeDiacritics ( rowLabel . toLowerCase ( ) ) ,
@@ -1242,7 +1242,7 @@ export class MultipleSelectInstance {
1242
1242
} else {
1243
1243
for ( const child of ( row as OptGroupRowData ) . children ) {
1244
1244
if ( child !== undefined && child !== null ) {
1245
- const childText = `${ child ?. text ?? '' } ` ;
1245
+ const childText = `${ ( child as OptionRowData ) ?. text ?? '' } ` ;
1246
1246
child . visible = this . options . customFilter (
1247
1247
removeDiacritics ( childText . toLowerCase ( ) ) ,
1248
1248
removeDiacritics ( text ) ,
@@ -1254,7 +1254,7 @@ export class MultipleSelectInstance {
1254
1254
row . visible = ( row as OptGroupRowData ) . children . filter ( ( child : any ) => child ?. visible ) . length > 0 ;
1255
1255
}
1256
1256
} else {
1257
- const rowText = `${ row ?. text ?? '' } ` ;
1257
+ const rowText = `${ ( row as OptionRowData ) ?. text ?? '' } ` ;
1258
1258
row . visible = this . options . customFilter (
1259
1259
removeDiacritics ( rowText . toLowerCase ( ) ) ,
1260
1260
removeDiacritics ( text ) ,
0 commit comments