@@ -7,6 +7,7 @@ import { useJsonViewerStore } from '../../stores/JsonViewerStore'
7
7
import type { DataItemProps } from '../../type'
8
8
import { DataKeyPair } from '../DataKeyPair'
9
9
import { CircularArrowsIcon } from '../icons/CircularArrowsIcon'
10
+ import { DataBox } from '../mui/DataBox'
10
11
11
12
const objectLb = '{'
12
13
const arrayLb = '['
@@ -82,23 +83,33 @@ export const PostObjectType: React.FC<DataItemProps<object>> = (props) => {
82
83
83
84
export const ObjectType : React . FC < DataItemProps < object > > = ( props ) => {
84
85
const keyColor = useTextColor ( )
86
+ const maxDisplayLength = useJsonViewerStore ( store => store . maxDisplayLength )
85
87
const groupArraysAfterLength = useJsonViewerStore (
86
88
store => store . groupArraysAfterLength )
87
89
const isTrap = useIsCycleReference ( props . path , props . value )
88
90
const elements = useMemo ( ( ) => {
89
91
if ( ! props . inspect ) {
90
92
return null
91
93
}
92
- if ( Array . isArray ( props . value ) ) {
93
- if ( props . value . length <= groupArraysAfterLength ) {
94
- return props . value . map ( ( value , index ) => {
94
+ const value : unknown [ ] | object = props . value
95
+ if ( Array . isArray ( value ) ) {
96
+ // unknown[]
97
+ if ( value . length <= groupArraysAfterLength ) {
98
+ const elements = value . slice ( 0 , maxDisplayLength ) . map ( ( value , index ) => {
95
99
const path = [ ...props . path , index ]
96
100
return (
97
101
< DataKeyPair key = { index } path = { path } value = { value } />
98
102
)
99
103
} )
104
+ if ( value . length > maxDisplayLength ) {
105
+ const rest = value . length - maxDisplayLength
106
+ elements . push (
107
+ < DataBox > hidden { rest } items</ DataBox >
108
+ )
109
+ }
110
+ return elements
100
111
}
101
- const value = props . value . reduce < unknown [ ] [ ] > ( ( array , value , index ) => {
112
+ const elements = value . reduce < unknown [ ] [ ] > ( ( array , value , index ) => {
102
113
const target = Math . floor ( index / groupArraysAfterLength )
103
114
if ( array [ target ] ) {
104
115
array [ target ] . push ( value )
@@ -108,21 +119,30 @@ export const ObjectType: React.FC<DataItemProps<object>> = (props) => {
108
119
return array
109
120
} , [ ] )
110
121
111
- return value . map ( ( list , index ) => {
122
+ return elements . map ( ( list , index ) => {
112
123
const path = [ ...props . path ]
113
124
return (
114
125
< DataKeyPair key = { index } path = { path } value = { list } nestedIndex = { index } />
115
126
)
116
127
} )
117
128
} else {
118
- return Object . entries ( props . value ) . map ( ( [ key , value ] ) => {
129
+ // object
130
+ const entries = Object . entries ( value )
131
+ const elements = entries . slice ( 0 , maxDisplayLength ) . map ( ( [ key , value ] ) => {
119
132
const path = [ ...props . path , key ]
120
133
return (
121
134
< DataKeyPair key = { key } path = { path } value = { value } />
122
135
)
123
136
} )
137
+ if ( entries . length > maxDisplayLength ) {
138
+ const rest = entries . length - maxDisplayLength
139
+ elements . push (
140
+ < DataBox > hidden { rest } items</ DataBox >
141
+ )
142
+ }
143
+ return elements
124
144
}
125
- } , [ props . inspect , props . value , props . path , groupArraysAfterLength ] )
145
+ } , [ props . inspect , props . value , props . path , groupArraysAfterLength , maxDisplayLength ] )
126
146
return (
127
147
< Box
128
148
className = 'data-object'
0 commit comments