scrollsequence
/
includes
/
carbonfields
/
htmlburger
/
carbon-fields
/
packages
/
blocks
/
fields
/
association
/
index.js
index.js in Scrollsequence – Cinematic Scroll Image Animation Plugin 1.5.5, at includes/carbonfields/htmlburger/carbon-fields/packages/blocks/fields/association/index.js
| 1 | /** |
| 2 | * External dependencies. |
| 3 | */ |
| 4 | import { addFilter } from '@wordpress/hooks'; |
| 5 | import { select } from '@wordpress/data'; |
| 6 | import { get, find } from 'lodash'; |
| 7 | |
| 8 | /** |
| 9 | * Carbon Fields dependencies. |
| 10 | */ |
| 11 | import { withProps } from '@carbon-fields/core'; |
| 12 | |
| 13 | /** |
| 14 | * Internal dependencies. |
| 15 | */ |
| 16 | import './style.scss'; |
| 17 | |
| 18 | addFilter( 'carbon-fields.association.block', 'carbon-fields/blocks', withProps( ( props ) => { |
| 19 | return { |
| 20 | hierarchyResolver() { |
| 21 | // Get the block that contains the field. |
| 22 | const block = select( 'core/block-editor' ).getBlock( props.blockId ); |
| 23 | |
| 24 | // Get the path. |
| 25 | const path = props.id.split( '__' ); |
| 26 | |
| 27 | // Remove the chunk that contains the block identifier. |
| 28 | path.shift(); |
| 29 | |
| 30 | // Get the hierarchy. |
| 31 | let hierarchy = path.shift(); |
| 32 | let accessor = `data.${ hierarchy }`; |
| 33 | |
| 34 | // Visit every branch in the tree so we can get the full hierarchy. |
| 35 | while ( path.length > 0 ) { |
| 36 | const chunk = path.shift(); |
| 37 | const isGroup = chunk.indexOf( 'cf-' ) === 0; |
| 38 | |
| 39 | if ( isGroup ) { |
| 40 | const groups = get( block.attributes, `${ accessor }` ); |
| 41 | const group = find( groups, [ '_id', chunk ] ); |
| 42 | const groupIndex = groups.indexOf( group ); |
| 43 | |
| 44 | accessor = `${ accessor }.${ groupIndex }`; |
| 45 | hierarchy = `${ hierarchy }[${ groupIndex }]:${ group._type }/`; |
| 46 | } else { |
| 47 | accessor = `${ accessor }.${ chunk }`; |
| 48 | hierarchy = `${ hierarchy }${ chunk }`; |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | return hierarchy; |
| 53 | } |
| 54 | }; |
| 55 | } ) ); |
| 56 |