PluginProbe
Scrollsequence – Cinematic Scroll Image Animation Plugin / 1.5.5
Scrollsequence – Cinematic Scroll Image Animation Plugin v1.5.5
1.4.3 1.4.4 1.4.5 1.4.6 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.5.9 1.6.0 1.6.1 1.6.2 1.6.3 trunk 0.9.92 0.9.93 0.9.94 0.9.96 1.0.072 1.0.073 All 61 releases
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

56 lines 1.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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