@@ -3,15 +3,31 @@ import JsonNode from './json-node'
33import type { Collapsed , CustomizeCollapseStringUI , CustomizeNode , DisplaySize , Editable } from '../types'
44import { stringifyForCopying } from '../utils'
55
6- type OnEdit = ( params : { newValue : any ; oldValue : any ; depth : number ; src : any ; indexOrName : string | number ; parentType : 'object' | 'array' | null } ) => void
7- type OnDelete = ( params : { value : any ; indexOrName : string | number ; depth : number ; src : any ; parentType : 'object' | 'array' | null } ) => void
8- type OnAdd = ( params : { indexOrName : string | number ; depth : number ; src : any ; parentType : 'object' | 'array' } ) => void
6+ type OnEdit = ( params : {
7+ newValue : any
8+ oldValue : any
9+ depth : number
10+ src : any
11+ indexOrName : string | number
12+ parentType : 'object' | 'array' | null
13+ parentPath : string [ ]
14+ } ) => void
15+ type OnDelete = ( params : {
16+ value : any
17+ indexOrName : string | number
18+ depth : number
19+ src : any
20+ parentType : 'object' | 'array' | null
21+ parentPath : string [ ]
22+ } ) => void
23+ type OnAdd = ( params : { indexOrName : string | number ; depth : number ; src : any ; parentType : 'object' | 'array' ; parentPath : string [ ] } ) => void
924type OnChange = ( params : {
1025 indexOrName : string | number
1126 depth : number
1227 src : any
1328 parentType : 'object' | 'array' | null
1429 type : 'add' | 'edit' | 'delete'
30+ parentPath : string [ ]
1531} ) => void
1632type OnCollapse = ( params : { isCollapsing : boolean ; node : Record < string , any > | Array < any > ; indexOrName : string | number | undefined ; depth : number } ) => void
1733
@@ -57,21 +73,18 @@ export const JsonViewContext = createContext({
5773 | React . Component < { className : string ; style : React . CSSProperties } >
5874 | undefined ,
5975 EditComponent : undefined as
60- | React . FC < { onClick : ( event : React . MouseEvent ) => void ; className : string } >
61- | React . Component < { onClick : ( event : React . MouseEvent ) => void ; className : string } >
62- | undefined ,
76+ | React . FC < { onClick : ( event : React . MouseEvent ) => void ; className : string } >
77+ | React . Component < { onClick : ( event : React . MouseEvent ) => void ; className : string } >
78+ | undefined ,
6379 CancelComponent : undefined as
64- | React . FC < { onClick : ( event : React . MouseEvent ) => void ; className : string ; style : React . CSSProperties } >
65- | React . Component < { onClick : ( event : React . MouseEvent ) => void ; className : string ; style : React . CSSProperties } >
66- | undefined ,
80+ | React . FC < { onClick : ( event : React . MouseEvent ) => void ; className : string ; style : React . CSSProperties } >
81+ | React . Component < { onClick : ( event : React . MouseEvent ) => void ; className : string ; style : React . CSSProperties } >
82+ | undefined ,
6783 DoneComponent : undefined as
68- | React . FC < { onClick : ( event : React . MouseEvent ) => void ; className : string ; style : React . CSSProperties } >
69- | React . Component < { onClick : ( event : React . MouseEvent ) => void ; className : string ; style : React . CSSProperties } >
70- | undefined ,
71- CustomOperation : undefined as
72- | React . FC < { node : any } >
73- | React . Component < { node : any } >
74- | undefined ,
84+ | React . FC < { onClick : ( event : React . MouseEvent ) => void ; className : string ; style : React . CSSProperties } >
85+ | React . Component < { onClick : ( event : React . MouseEvent ) => void ; className : string ; style : React . CSSProperties } >
86+ | undefined ,
87+ CustomOperation : undefined as React . FC < { node : any } > | React . Component < { node : any } > | undefined
7588} )
7689
7790export interface JsonViewProps {
@@ -116,20 +129,18 @@ export interface JsonViewProps {
116129 CopiedComponent ?: React . FC < { className : string ; style : React . CSSProperties } > | React . Component < { className : string ; style : React . CSSProperties } >
117130
118131 EditComponent ?:
119- | React . FC < { onClick : ( event : React . MouseEvent ) => void ; className : string } >
120- | React . Component < { onClick : ( event : React . MouseEvent ) => void ; className : string } >
132+ | React . FC < { onClick : ( event : React . MouseEvent ) => void ; className : string } >
133+ | React . Component < { onClick : ( event : React . MouseEvent ) => void ; className : string } >
121134
122135 CancelComponent ?:
123- | React . FC < { onClick : ( event : React . MouseEvent ) => void ; className : string ; style : React . CSSProperties } >
124- | React . Component < { onClick : ( event : React . MouseEvent ) => void ; className : string ; style : React . CSSProperties } >
136+ | React . FC < { onClick : ( event : React . MouseEvent ) => void ; className : string ; style : React . CSSProperties } >
137+ | React . Component < { onClick : ( event : React . MouseEvent ) => void ; className : string ; style : React . CSSProperties } >
125138
126139 DoneComponent ?:
127- | React . FC < { onClick : ( event : React . MouseEvent ) => void ; className : string ; style : React . CSSProperties } >
128- | React . Component < { onClick : ( event : React . MouseEvent ) => void ; className : string ; style : React . CSSProperties } >
140+ | React . FC < { onClick : ( event : React . MouseEvent ) => void ; className : string ; style : React . CSSProperties } >
141+ | React . Component < { onClick : ( event : React . MouseEvent ) => void ; className : string ; style : React . CSSProperties } >
129142
130- CustomOperation ?:
131- | React . FC < { node : any } >
132- | React . Component < { node : any } >
143+ CustomOperation ?: React . FC < { node : any } > | React . Component < { node : any } >
133144}
134145
135146export default function JsonView ( {
@@ -174,7 +185,7 @@ export default function JsonView({
174185 EditComponent,
175186 CancelComponent,
176187 DoneComponent,
177- CustomOperation,
188+ CustomOperation
178189} : JsonViewProps ) {
179190 const [ _ , update ] = useState ( 0 )
180191 const forceUpdate = useCallback ( ( ) => update ( state => ++ state ) , [ ] )
@@ -219,15 +230,15 @@ export default function JsonView({
219230 EditComponent,
220231 CancelComponent,
221232 DoneComponent,
222- CustomOperation,
233+ CustomOperation
223234 } } >
224235 < code
225236 className = { 'json-view' + ( dark ? ' dark' : '' ) + ( theme && theme !== 'default' ? ' json-view_' + theme : '' ) + ( className ? ' ' + className : '' ) }
226237 style = { style } >
227238 < JsonNode
228239 node = { src }
229240 depth = { 1 }
230- editHandle = { ( indexOrName : number | string , newValue : any , oldValue : any ) => {
241+ editHandle = { ( indexOrName : number | string , newValue : any , oldValue : any , parentPath : string [ ] ) => {
231242 setSrc ( newValue )
232243 if ( onEdit )
233244 onEdit ( {
@@ -236,29 +247,33 @@ export default function JsonView({
236247 depth : 1 ,
237248 src,
238249 indexOrName : indexOrName ,
239- parentType : null
250+ parentType : null ,
251+ parentPath : parentPath
240252 } )
241- if ( onChange ) onChange ( { type : 'edit' , depth : 1 , src, indexOrName : indexOrName , parentType : null } )
253+ if ( onChange ) onChange ( { type : 'edit' , depth : 1 , src, indexOrName : indexOrName , parentType : null , parentPath : parentPath } )
242254 } }
243- deleteHandle = { ( ) => {
255+ deleteHandle = { ( indexOrName : number | string , parentPath : string [ ] ) => {
244256 setSrc ( undefined )
245257 if ( onDelete )
246258 onDelete ( {
247259 value : src ,
248260 depth : 1 ,
249261 src,
250- indexOrName : '' ,
251- parentType : null
262+ indexOrName : indexOrName ,
263+ parentType : null ,
264+ parentPath : parentPath
252265 } )
253266 if ( onChange )
254267 onChange ( {
255268 depth : 1 ,
256269 src,
257- indexOrName : '' ,
270+ indexOrName : indexOrName ,
258271 parentType : null ,
259- type : 'delete'
272+ type : 'delete' ,
273+ parentPath : parentPath
260274 } )
261275 } }
276+ parentPath = { [ ] }
262277 />
263278 </ code >
264279 </ JsonViewContext . Provider >
0 commit comments