@@ -18,27 +18,29 @@ import { DataBox } from './mui/DataBox'
18
18
19
19
export type DataKeyPairProps = {
20
20
value : unknown
21
- nested ?: boolean
21
+ nestedIndex ?: number
22
22
path : ( string | number ) [ ]
23
23
}
24
24
25
- const IconBox = styled ( props => < Box { ...props } component = 'span' /> ) `
25
+ const IconBox = styled ( props => < Box { ...props } component = 'span' /> ) `
26
26
cursor: pointer;
27
27
padding-left: 0.7rem;
28
28
` as typeof Box
29
29
30
30
export const DataKeyPair : React . FC < DataKeyPairProps > = ( props ) => {
31
- const { value, path } = props
31
+ const { value, path, nestedIndex } = props
32
32
const [ tempValue , setTempValue ] = useState ( value )
33
33
const depth = path . length
34
34
const key = path [ depth - 1 ]
35
35
const hoverPath = useJsonViewerStore ( store => store . hoverPath )
36
36
const isHover = useMemo ( ( ) => {
37
- return hoverPath && path . every ( ( value , index ) => value === hoverPath [ index ] )
38
- } , [ hoverPath , path ] )
37
+ return hoverPath && path . every (
38
+ ( value , index ) => value === hoverPath . path [ index ] && nestedIndex ===
39
+ hoverPath . nestedIndex )
40
+ } , [ hoverPath , path , nestedIndex ] )
39
41
const setHover = useJsonViewerStore ( store => store . setHover )
40
42
const root = useJsonViewerStore ( store => store . value )
41
- const [ inspect , setInspect ] = useInspect ( path , value )
43
+ const [ inspect , setInspect ] = useInspect ( path , value , nestedIndex )
42
44
const [ editing , setEditing ] = useState ( false )
43
45
const onChange = useJsonViewerStore ( store => store . onChange )
44
46
const keyColor = useTextColor ( )
@@ -106,18 +108,18 @@ export const DataKeyPair: React.FC<DataKeyPairProps> = (props) => {
106
108
{
107
109
copied
108
110
? (
109
- < CheckIcon
110
- sx = { {
111
- fontSize : '.8rem'
112
- } }
113
- />
111
+ < CheckIcon
112
+ sx = { {
113
+ fontSize : '.8rem'
114
+ } }
115
+ />
114
116
)
115
117
: (
116
- < ContentCopyIcon
117
- sx = { {
118
- fontSize : '.8rem'
119
- } }
120
- />
118
+ < ContentCopyIcon
119
+ sx = { {
120
+ fontSize : '.8rem'
121
+ } }
122
+ />
121
123
)
122
124
}
123
125
</ IconBox >
@@ -146,9 +148,9 @@ export const DataKeyPair: React.FC<DataKeyPairProps> = (props) => {
146
148
const KeyRenderer = useJsonViewerStore ( store => store . keyRenderer )
147
149
return (
148
150
< Box className = 'data-key-pair'
149
- onMouseEnter = {
150
- useCallback ( ( ) => setHover ( path ) , [ setHover , path ] )
151
- }
151
+ onMouseEnter = {
152
+ useCallback ( ( ) => setHover ( path , nestedIndex ) , [ setHover , path , nestedIndex ] )
153
+ }
152
154
>
153
155
< DataBox
154
156
component = 'span'
@@ -171,15 +173,15 @@ export const DataKeyPair: React.FC<DataKeyPairProps> = (props) => {
171
173
{
172
174
KeyRenderer . when ( downstreamProps )
173
175
? < KeyRenderer { ...downstreamProps } />
174
- : ! props . nested && (
175
- isNumberKey
176
- ? < Box component = 'span'
177
- style = { { color : numberKeyColor } } > { displayKey } </ Box >
178
- : < > "{ displayKey } "</ >
179
- )
176
+ : nestedIndex === undefined && (
177
+ isNumberKey
178
+ ? < Box component = 'span'
179
+ style = { { color : numberKeyColor } } > { displayKey } </ Box >
180
+ : < > "{ displayKey } "</ >
181
+ )
180
182
}
181
183
{
182
- ! props . nested && (
184
+ nestedIndex === undefined && (
183
185
< DataBox sx = { { mx : 0.5 } } > :</ DataBox >
184
186
)
185
187
}
@@ -188,11 +190,11 @@ export const DataKeyPair: React.FC<DataKeyPairProps> = (props) => {
188
190
</ DataBox >
189
191
{
190
192
editing
191
- ? ( Editor && < Editor value = { tempValue } setValue = { setTempValue } /> )
193
+ ? ( Editor && < Editor value = { tempValue } setValue = { setTempValue } /> )
192
194
: ( Component )
193
195
? < Component { ...downstreamProps } />
194
196
: < Box component = 'span'
195
- className = 'data-value-fallback' > { `fallback: ${ value } ` } </ Box >
197
+ className = 'data-value-fallback' > { `fallback: ${ value } ` } </ Box >
196
198
}
197
199
{ PostComponent && < PostComponent { ...downstreamProps } /> }
198
200
{ ( isHover && expandable && ! inspect ) && actionIcons }
0 commit comments