@@ -59,11 +59,15 @@ export const makeItemsProps = propsFactory({
59
59
valueComparator : Function as PropType < typeof deepEqual > ,
60
60
} , 'list-items' )
61
61
62
- export function transformItem ( props : Omit < ItemProps , 'items' > , item : any ) : ListItem {
62
+ const itemTypes = new Set ( [ 'item' , 'divider' , 'subheader' ] )
63
+
64
+ export function transformItem (
65
+ props : Pick < ItemProps , typeof transformItem . neededProps [ number ] > ,
66
+ item : any
67
+ ) : ListItem {
63
68
const title = getPropertyFromItem ( item , props . itemTitle , item )
64
69
const value = getPropertyFromItem ( item , props . itemValue , title )
65
70
const children = getPropertyFromItem ( item , props . itemChildren )
66
- const type = getPropertyFromItem ( item , props . itemType , 'item' )
67
71
const itemProps = props . itemProps === true
68
72
? typeof item === 'object' && item != null && ! Array . isArray ( item )
69
73
? 'children' in item
@@ -72,6 +76,11 @@ export function transformItem (props: Omit<ItemProps, 'items'>, item: any): List
72
76
: undefined
73
77
: getPropertyFromItem ( item , props . itemProps )
74
78
79
+ let type = getPropertyFromItem ( item , props . itemType , 'item' )
80
+ if ( ! itemTypes . has ( type ) ) {
81
+ type = 'item'
82
+ }
83
+
75
84
const _props = {
76
85
title,
77
86
value,
@@ -88,16 +97,20 @@ export function transformItem (props: Omit<ItemProps, 'items'>, item: any): List
88
97
}
89
98
}
90
99
91
- export function transformItems ( props : Omit < ItemProps , 'items' > , items : ItemProps [ 'items' ] ) {
92
- const _props = pick ( props , [
93
- 'itemTitle' ,
94
- 'itemValue' ,
95
- 'itemChildren' ,
96
- 'itemProps' ,
97
- 'itemType' ,
98
- 'returnObject' ,
99
- 'valueComparator' ,
100
- ] )
100
+ transformItem . neededProps = [
101
+ 'itemTitle' ,
102
+ 'itemValue' ,
103
+ 'itemChildren' ,
104
+ 'itemProps' ,
105
+ 'itemType' ,
106
+ ] as const
107
+
108
+ export function transformItems (
109
+ props : Pick < ItemProps , typeof transformItem . neededProps [ number ] > ,
110
+ items : ItemProps [ 'items' ]
111
+ ) {
112
+ // avoid reactive access in the loop
113
+ const _props = pick ( props , transformItem . neededProps )
101
114
102
115
const array : ListItem [ ] = [ ]
103
116
for ( const item of items ) {
@@ -144,15 +157,7 @@ export function useItems (props: ItemProps) {
144
157
const _returnObject = props . returnObject
145
158
const hasValueComparator = ! ! props . valueComparator
146
159
const valueComparator = props . valueComparator || deepEqual
147
- const _props = pick ( props , [
148
- 'itemTitle' ,
149
- 'itemValue' ,
150
- 'itemChildren' ,
151
- 'itemProps' ,
152
- 'itemType' ,
153
- 'returnObject' ,
154
- 'valueComparator' ,
155
- ] )
160
+ const _props = pick ( props , transformItem . neededProps )
156
161
157
162
const returnValue : ListItem [ ] = [ ]
158
163
main: for ( const v of value ) {
0 commit comments