@@ -32,7 +32,7 @@ function inspectMetadata (value: object) {
32
32
const PreObjectType : FC < DataItemProps < object > > = ( props ) => {
33
33
const metadataColor = useJsonViewerStore ( store => store . colorspace . base04 )
34
34
const textColor = useTextColor ( )
35
- const isArray = useMemo ( ( ) => Array . isArray ( props . value ) , [ props . value ] )
35
+ const isArrayLike = useMemo ( ( ) => Array . isArray ( props . value ) || ( props . value instanceof Set ) , [ props . value ] )
36
36
const isEmptyValue = useMemo ( ( ) => getValueSize ( props . value ) === 0 , [ props . value ] )
37
37
const sizeOfValue = useMemo ( ( ) => inspectMetadata ( props . value ) , [ props . value ] )
38
38
const displaySize = useJsonViewerStore ( store => store . displaySize )
@@ -46,7 +46,7 @@ const PreObjectType: FC<DataItemProps<object>> = (props) => {
46
46
letterSpacing : 0.5
47
47
} }
48
48
>
49
- { isArray ? arrayLb : objectLb }
49
+ { isArrayLike ? arrayLb : objectLb }
50
50
{ shouldDisplaySize && props . inspect && ! isEmptyValue && (
51
51
< Box
52
52
component = 'span'
@@ -70,7 +70,14 @@ const PreObjectType: FC<DataItemProps<object>> = (props) => {
70
70
mx : 0.5
71
71
} }
72
72
/>
73
- { isTrap }
73
+ < DataBox
74
+ sx = { {
75
+ cursor : 'pointer' ,
76
+ userSelect : 'none'
77
+ } }
78
+ >
79
+ { isTrap }
80
+ </ DataBox >
74
81
</ >
75
82
) }
76
83
</ Box >
@@ -80,7 +87,7 @@ const PreObjectType: FC<DataItemProps<object>> = (props) => {
80
87
const PostObjectType : FC < DataItemProps < object > > = ( props ) => {
81
88
const metadataColor = useJsonViewerStore ( store => store . colorspace . base04 )
82
89
const textColor = useTextColor ( )
83
- const isArray = useMemo ( ( ) => Array . isArray ( props . value ) , [ props . value ] )
90
+ const isArrayLike = useMemo ( ( ) => Array . isArray ( props . value ) || ( props . value instanceof Set ) , [ props . value ] )
84
91
const isEmptyValue = useMemo ( ( ) => getValueSize ( props . value ) === 0 , [ props . value ] )
85
92
const sizeOfValue = useMemo ( ( ) => inspectMetadata ( props . value ) , [ props . value ] )
86
93
const displaySize = useJsonViewerStore ( store => store . displaySize )
@@ -97,7 +104,7 @@ const PostObjectType: FC<DataItemProps<object>> = (props) => {
97
104
opacity : 0.8
98
105
} }
99
106
>
100
- { isArray ? arrayRb : objectRb }
107
+ { isArrayLike ? arrayRb : objectRb }
101
108
{ shouldDisplaySize && ( isEmptyValue || ! props . inspect )
102
109
? (
103
110
< Box
@@ -138,6 +145,8 @@ const ObjectType: FC<DataItemProps<object>> = (props) => {
138
145
if ( iterator && ! Array . isArray ( value ) ) {
139
146
const elements = [ ]
140
147
if ( value instanceof Map ) {
148
+ const lastIndex = value . size - 1
149
+ let index = 0
141
150
value . forEach ( ( value , k ) => {
142
151
// fixme: key might be a object, array, or any value for the `Map<any, any>`
143
152
const key = k . toString ( )
@@ -149,31 +158,41 @@ const ObjectType: FC<DataItemProps<object>> = (props) => {
149
158
value = { value }
150
159
prevValue = { props . prevValue instanceof Map ? props . prevValue . get ( k ) : undefined }
151
160
editable = { false }
161
+ last = { index === lastIndex }
152
162
/>
153
163
)
164
+ index ++
154
165
} )
155
166
} else {
156
167
// iterate with iterator func
157
168
const iterator = value [ Symbol . iterator ] ( )
158
169
let result = iterator . next ( )
159
170
let count = 0
160
- while ( ! result . done ) {
171
+ while ( true ) {
172
+ const nextResult = iterator . next ( )
161
173
elements . push (
162
174
< DataKeyPair
163
175
key = { count }
164
176
path = { [ ...props . path , `iterator:${ count } ` ] }
165
177
value = { result . value }
166
178
nestedIndex = { count }
167
179
editable = { false }
180
+ last = { nextResult . done ?? false }
168
181
/>
169
182
)
183
+
184
+ if ( nextResult . done ) {
185
+ break
186
+ }
187
+
170
188
count ++
171
- result = iterator . next ( )
189
+ result = nextResult
172
190
}
173
191
}
174
192
return elements
175
193
}
176
194
if ( Array . isArray ( value ) ) {
195
+ const lastIndex = value . length - 1
177
196
// unknown[]
178
197
if ( value . length <= groupArraysAfterLength ) {
179
198
const elements = value . slice ( 0 , displayLength ) . map ( ( value , _index ) => {
@@ -185,6 +204,7 @@ const ObjectType: FC<DataItemProps<object>> = (props) => {
185
204
path = { path }
186
205
value = { value }
187
206
prevValue = { Array . isArray ( props . prevValue ) ? props . prevValue [ index ] : undefined }
207
+ last = { _index === lastIndex }
188
208
/>
189
209
)
190
210
} )
@@ -213,6 +233,7 @@ const ObjectType: FC<DataItemProps<object>> = (props) => {
213
233
const elements : unknown [ ] [ ] = segmentArray ( value , groupArraysAfterLength )
214
234
const prevElements = Array . isArray ( props . prevValue ) ? segmentArray ( props . prevValue , groupArraysAfterLength ) : undefined
215
235
236
+ const elementsLastIndex = elements . length - 1
216
237
return elements . map ( ( list , index ) => {
217
238
return (
218
239
< DataKeyPair
@@ -221,6 +242,7 @@ const ObjectType: FC<DataItemProps<object>> = (props) => {
221
242
value = { list }
222
243
nestedIndex = { index }
223
244
prevValue = { prevElements ?. [ index ] }
245
+ last = { index === elementsLastIndex }
224
246
/>
225
247
)
226
248
} )
@@ -232,10 +254,17 @@ const ObjectType: FC<DataItemProps<object>> = (props) => {
232
254
? entries . sort ( ( [ a ] , [ b ] ) => a . localeCompare ( b ) )
233
255
: entries . sort ( ( [ a ] , [ b ] ) => objectSortKeys ( a , b ) )
234
256
}
235
- const elements = entries . slice ( 0 , displayLength ) . map ( ( [ key , value ] ) => {
257
+ const lastIndex = entries . length - 1
258
+ const elements = entries . slice ( 0 , displayLength ) . map ( ( [ key , value ] , index ) => {
236
259
const path = [ ...props . path , key ]
237
260
return (
238
- < DataKeyPair key = { key } path = { path } value = { value } prevValue = { ( props . prevValue as any ) ?. [ key ] } />
261
+ < DataKeyPair
262
+ key = { key }
263
+ path = { path }
264
+ value = { value }
265
+ prevValue = { ( props . prevValue as any ) ?. [ key ] }
266
+ last = { index === lastIndex }
267
+ />
239
268
)
240
269
} )
241
270
if ( entries . length > displayLength ) {
0 commit comments