@@ -32,7 +32,7 @@ function inspectMetadata (value: object) {
3232const PreObjectType : FC < DataItemProps < object > > = ( props ) => {
3333 const metadataColor = useJsonViewerStore ( store => store . colorspace . base04 )
3434 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 ] )
3636 const isEmptyValue = useMemo ( ( ) => getValueSize ( props . value ) === 0 , [ props . value ] )
3737 const sizeOfValue = useMemo ( ( ) => inspectMetadata ( props . value ) , [ props . value ] )
3838 const displaySize = useJsonViewerStore ( store => store . displaySize )
@@ -46,7 +46,7 @@ const PreObjectType: FC<DataItemProps<object>> = (props) => {
4646 letterSpacing : 0.5
4747 } }
4848 >
49- { isArray ? arrayLb : objectLb }
49+ { isArrayLike ? arrayLb : objectLb }
5050 { shouldDisplaySize && props . inspect && ! isEmptyValue && (
5151 < Box
5252 component = 'span'
@@ -70,7 +70,14 @@ const PreObjectType: FC<DataItemProps<object>> = (props) => {
7070 mx : 0.5
7171 } }
7272 />
73- { isTrap }
73+ < DataBox
74+ sx = { {
75+ cursor : 'pointer' ,
76+ userSelect : 'none'
77+ } }
78+ >
79+ { isTrap }
80+ </ DataBox >
7481 </ >
7582 ) }
7683 </ Box >
@@ -80,7 +87,7 @@ const PreObjectType: FC<DataItemProps<object>> = (props) => {
8087const PostObjectType : FC < DataItemProps < object > > = ( props ) => {
8188 const metadataColor = useJsonViewerStore ( store => store . colorspace . base04 )
8289 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 ] )
8491 const isEmptyValue = useMemo ( ( ) => getValueSize ( props . value ) === 0 , [ props . value ] )
8592 const sizeOfValue = useMemo ( ( ) => inspectMetadata ( props . value ) , [ props . value ] )
8693 const displaySize = useJsonViewerStore ( store => store . displaySize )
@@ -97,7 +104,7 @@ const PostObjectType: FC<DataItemProps<object>> = (props) => {
97104 opacity : 0.8
98105 } }
99106 >
100- { isArray ? arrayRb : objectRb }
107+ { isArrayLike ? arrayRb : objectRb }
101108 { shouldDisplaySize && ( isEmptyValue || ! props . inspect )
102109 ? (
103110 < Box
@@ -138,6 +145,8 @@ const ObjectType: FC<DataItemProps<object>> = (props) => {
138145 if ( iterator && ! Array . isArray ( value ) ) {
139146 const elements = [ ]
140147 if ( value instanceof Map ) {
148+ const lastIndex = value . size - 1
149+ let index = 0
141150 value . forEach ( ( value , k ) => {
142151 // fixme: key might be a object, array, or any value for the `Map<any, any>`
143152 const key = k . toString ( )
@@ -149,31 +158,41 @@ const ObjectType: FC<DataItemProps<object>> = (props) => {
149158 value = { value }
150159 prevValue = { props . prevValue instanceof Map ? props . prevValue . get ( k ) : undefined }
151160 editable = { false }
161+ last = { index === lastIndex }
152162 />
153163 )
164+ index ++
154165 } )
155166 } else {
156167 // iterate with iterator func
157168 const iterator = value [ Symbol . iterator ] ( )
158169 let result = iterator . next ( )
159170 let count = 0
160- while ( ! result . done ) {
171+ while ( true ) {
172+ const nextResult = iterator . next ( )
161173 elements . push (
162174 < DataKeyPair
163175 key = { count }
164176 path = { [ ...props . path , `iterator:${ count } ` ] }
165177 value = { result . value }
166178 nestedIndex = { count }
167179 editable = { false }
180+ last = { nextResult . done ?? false }
168181 />
169182 )
183+
184+ if ( nextResult . done ) {
185+ break
186+ }
187+
170188 count ++
171- result = iterator . next ( )
189+ result = nextResult
172190 }
173191 }
174192 return elements
175193 }
176194 if ( Array . isArray ( value ) ) {
195+ const lastIndex = value . length - 1
177196 // unknown[]
178197 if ( value . length <= groupArraysAfterLength ) {
179198 const elements = value . slice ( 0 , displayLength ) . map ( ( value , _index ) => {
@@ -185,6 +204,7 @@ const ObjectType: FC<DataItemProps<object>> = (props) => {
185204 path = { path }
186205 value = { value }
187206 prevValue = { Array . isArray ( props . prevValue ) ? props . prevValue [ index ] : undefined }
207+ last = { _index === lastIndex }
188208 />
189209 )
190210 } )
@@ -213,6 +233,7 @@ const ObjectType: FC<DataItemProps<object>> = (props) => {
213233 const elements : unknown [ ] [ ] = segmentArray ( value , groupArraysAfterLength )
214234 const prevElements = Array . isArray ( props . prevValue ) ? segmentArray ( props . prevValue , groupArraysAfterLength ) : undefined
215235
236+ const elementsLastIndex = elements . length - 1
216237 return elements . map ( ( list , index ) => {
217238 return (
218239 < DataKeyPair
@@ -221,6 +242,7 @@ const ObjectType: FC<DataItemProps<object>> = (props) => {
221242 value = { list }
222243 nestedIndex = { index }
223244 prevValue = { prevElements ?. [ index ] }
245+ last = { index === elementsLastIndex }
224246 />
225247 )
226248 } )
@@ -232,10 +254,17 @@ const ObjectType: FC<DataItemProps<object>> = (props) => {
232254 ? entries . sort ( ( [ a ] , [ b ] ) => a . localeCompare ( b ) )
233255 : entries . sort ( ( [ a ] , [ b ] ) => objectSortKeys ( a , b ) )
234256 }
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 ) => {
236259 const path = [ ...props . path , key ]
237260 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+ />
239268 )
240269 } )
241270 if ( entries . length > displayLength ) {
0 commit comments