55 fieldAffectsData ,
66 fieldHasSubFields ,
77 fieldShouldBeLocalized ,
8+ tabHasName ,
89} from '../fields/config/types.js'
910
1011const traverseArrayOrBlocksField = ( {
@@ -16,6 +17,7 @@ const traverseArrayOrBlocksField = ({
1617 fillEmpty,
1718 leavesFirst,
1819 parentIsLocalized,
20+ parentPath,
1921 parentRef,
2022} : {
2123 callback : TraverseFieldsCallback
@@ -26,6 +28,7 @@ const traverseArrayOrBlocksField = ({
2628 fillEmpty : boolean
2729 leavesFirst : boolean
2830 parentIsLocalized : boolean
31+ parentPath ?: string
2932 parentRef ?: unknown
3033} ) => {
3134 if ( fillEmpty ) {
@@ -38,6 +41,7 @@ const traverseArrayOrBlocksField = ({
3841 isTopLevel : false ,
3942 leavesFirst,
4043 parentIsLocalized : parentIsLocalized || field . localized ,
44+ parentPath : `${ parentPath } ${ field . name } .` ,
4145 parentRef,
4246 } )
4347 }
@@ -55,6 +59,7 @@ const traverseArrayOrBlocksField = ({
5559 isTopLevel : false ,
5660 leavesFirst,
5761 parentIsLocalized : parentIsLocalized || field . localized ,
62+ parentPath : `${ parentPath } ${ field . name } .` ,
5863 parentRef,
5964 } )
6065 }
@@ -88,6 +93,7 @@ const traverseArrayOrBlocksField = ({
8893 isTopLevel : false ,
8994 leavesFirst,
9095 parentIsLocalized : parentIsLocalized || field . localized ,
96+ parentPath : `${ parentPath } ${ field . name } .` ,
9197 parentRef,
9298 ref,
9399 } )
@@ -105,6 +111,7 @@ export type TraverseFieldsCallback = (args: {
105111 */
106112 next ?: ( ) => void
107113 parentIsLocalized : boolean
114+ parentPath : string
108115 /**
109116 * The parent reference object
110117 */
@@ -130,6 +137,7 @@ type TraverseFieldsArgs = {
130137 */
131138 leavesFirst ?: boolean
132139 parentIsLocalized ?: boolean
140+ parentPath ?: string
133141 parentRef ?: Record < string , unknown > | unknown
134142 ref ?: Record < string , unknown > | unknown
135143}
@@ -152,6 +160,7 @@ export const traverseFields = ({
152160 isTopLevel = true ,
153161 leavesFirst = false ,
154162 parentIsLocalized,
163+ parentPath = '' ,
155164 parentRef = { } ,
156165 ref = { } ,
157166} : TraverseFieldsArgs ) : void => {
@@ -172,12 +181,19 @@ export const traverseFields = ({
172181 if (
173182 ! leavesFirst &&
174183 callback &&
175- callback ( { field, next, parentIsLocalized : parentIsLocalized ! , parentRef, ref } )
184+ callback ( { field, next, parentIsLocalized : parentIsLocalized ! , parentPath , parentRef, ref } )
176185 ) {
177186 return true
178187 } else if ( leavesFirst ) {
179188 callbackStack . push ( ( ) =>
180- callback ( { field, next, parentIsLocalized : parentIsLocalized ! , parentRef, ref } ) ,
189+ callback ( {
190+ field,
191+ next,
192+ parentIsLocalized : parentIsLocalized ! ,
193+ parentPath,
194+ parentRef,
195+ ref,
196+ } ) ,
181197 )
182198 }
183199
@@ -220,6 +236,7 @@ export const traverseFields = ({
220236 field : { ...tab , type : 'tab' } ,
221237 next,
222238 parentIsLocalized : parentIsLocalized ! ,
239+ parentPath,
223240 parentRef : currentParentRef ,
224241 ref : tabRef ,
225242 } )
@@ -231,6 +248,7 @@ export const traverseFields = ({
231248 field : { ...tab , type : 'tab' } ,
232249 next,
233250 parentIsLocalized : parentIsLocalized ! ,
251+ parentPath,
234252 parentRef : currentParentRef ,
235253 ref : tabRef ,
236254 } ) ,
@@ -254,6 +272,7 @@ export const traverseFields = ({
254272 isTopLevel : false ,
255273 leavesFirst,
256274 parentIsLocalized : true ,
275+ parentPath : `${ parentPath } ${ tab . name } .` ,
257276 parentRef : currentParentRef ,
258277 ref : tabRef [ key as keyof typeof tabRef ] ,
259278 } )
@@ -268,6 +287,7 @@ export const traverseFields = ({
268287 field : { ...tab , type : 'tab' } ,
269288 next,
270289 parentIsLocalized : parentIsLocalized ! ,
290+ parentPath,
271291 parentRef : currentParentRef ,
272292 ref : tabRef ,
273293 } )
@@ -279,6 +299,7 @@ export const traverseFields = ({
279299 field : { ...tab , type : 'tab' } ,
280300 next,
281301 parentIsLocalized : parentIsLocalized ! ,
302+ parentPath,
282303 parentRef : currentParentRef ,
283304 ref : tabRef ,
284305 } ) ,
@@ -296,6 +317,7 @@ export const traverseFields = ({
296317 isTopLevel : false ,
297318 leavesFirst,
298319 parentIsLocalized : false ,
320+ parentPath : tabHasName ( tab ) ? `${ parentPath } ${ tab . name } ` : parentPath ,
299321 parentRef : currentParentRef ,
300322 ref : tabRef ,
301323 } )
@@ -352,6 +374,7 @@ export const traverseFields = ({
352374 isTopLevel : false ,
353375 leavesFirst,
354376 parentIsLocalized : true ,
377+ parentPath : field . name ? `${ parentPath } ${ field . name } ` : parentPath ,
355378 parentRef : currentParentRef ,
356379 ref : currentRef [ key as keyof typeof currentRef ] ,
357380 } )
@@ -426,6 +449,7 @@ export const traverseFields = ({
426449 isTopLevel : false ,
427450 leavesFirst,
428451 parentIsLocalized,
452+ parentPath,
429453 parentRef : currentParentRef ,
430454 ref : currentRef ,
431455 } )
0 commit comments