scrollsequence
/
includes
/
carbonfields
/
htmlburger
/
carbon-fields
/
packages
/
blocks
/
index.js
index.js in Scrollsequence – Cinematic Scroll Image Animation Plugin 1.5.5, at includes/carbonfields/htmlburger/carbon-fields/packages/blocks/index.js
| 1 | /* eslint no-console: [ 'error', { allow: [ 'error' ] } ] */ |
| 2 | |
| 3 | /** |
| 4 | * External dependencies. |
| 5 | */ |
| 6 | import { dispatch } from '@wordpress/data'; |
| 7 | import { registerBlockType } from '@wordpress/blocks'; |
| 8 | import { setLocaleData } from '@wordpress/i18n'; |
| 9 | import { |
| 10 | get, |
| 11 | kebabCase, |
| 12 | isPlainObject |
| 13 | } from 'lodash'; |
| 14 | |
| 15 | /** |
| 16 | * Internal dependencies. |
| 17 | */ |
| 18 | import './fields'; |
| 19 | import './store'; |
| 20 | import BlockEdit from './components/block-edit'; |
| 21 | import BlockSave from './components/block-save'; |
| 22 | import transformFieldsToAttributes from './utils/transform-fields-to-attributes'; |
| 23 | |
| 24 | /** |
| 25 | * Sets the locale data for the package type |
| 26 | */ |
| 27 | setLocaleData( window.cf.config.locale, 'carbon-fields-ui' ); |
| 28 | |
| 29 | /** |
| 30 | * Register the blocks. |
| 31 | */ |
| 32 | const containerDefinitions = {}; |
| 33 | const fieldDefinitions = {}; |
| 34 | |
| 35 | get( window.cf, 'preloaded.blocks', [] ).forEach( ( container ) => { |
| 36 | const name = kebabCase( container.id ).replace( 'carbon-fields-container-', '' ); |
| 37 | const fields = transformFieldsToAttributes( container.fields ); |
| 38 | |
| 39 | const getBlockSetting = ( key, def = null ) => get( container, `settings.${ key }`, def ); |
| 40 | |
| 41 | containerDefinitions[ name ] = container; |
| 42 | fieldDefinitions[ name ] = container.fields.map( ( field ) => ( { ...field } ) ); |
| 43 | |
| 44 | registerBlockType( `carbon-fields/${ name }`, { |
| 45 | title: container.title, |
| 46 | icon: getBlockSetting( 'icon' ), |
| 47 | parent: getBlockSetting( 'parent', [] ), |
| 48 | category: getBlockSetting( 'category.slug' ), |
| 49 | keywords: getBlockSetting( 'keywords', [] ), |
| 50 | description: getBlockSetting( 'description', '' ), |
| 51 | attributes: { |
| 52 | data: { |
| 53 | type: 'object', |
| 54 | default: fields |
| 55 | } |
| 56 | }, |
| 57 | supports: { |
| 58 | tabs: isPlainObject( getBlockSetting( 'tabs' ) ), |
| 59 | preview: getBlockSetting( 'preview' ), |
| 60 | innerBlocks: getBlockSetting( 'inner_blocks.enabled' ), |
| 61 | alignWide: false, |
| 62 | anchor: false, |
| 63 | html: false |
| 64 | }, |
| 65 | edit: BlockEdit, |
| 66 | save: BlockSave, |
| 67 | example: true, |
| 68 | } ); |
| 69 | } ); |
| 70 | |
| 71 | /** |
| 72 | * Load the definitions in store. |
| 73 | */ |
| 74 | dispatch( 'carbon-fields/blocks' ).setupContainerDefinitions( containerDefinitions ); |
| 75 | dispatch( 'carbon-fields/blocks' ).setupFieldDefinitions( fieldDefinitions ); |
| 76 |