| 1 |
/** |
| 2 |
* WordPress Dependencies |
| 3 |
*/ |
| 4 |
import { addFilter } from '@wordpress/hooks'; |
| 5 |
|
| 6 |
/** |
| 7 |
* Internal dependencies |
| 8 |
*/ |
| 9 |
import { isBeyondwordsSupportedBlock } from './isBeyondwordsSupportedBlock'; |
| 10 |
|
| 11 |
/** |
| 12 |
* Register custom block attributes for BeyondWords. |
| 13 |
* |
| 14 |
* @since 4.0.4 Remove settings.attributes undefined check, to match official docs. |
| 15 |
* @since 6.0.1 Skip internal/UI blocks to prevent breaking the block inserter. |
| 16 |
* |
| 17 |
* @param {Object} settings Settings for the block. |
| 18 |
* @param {string} name Block name. |
| 19 |
* |
| 20 |
* @return {Object} settings Modified settings. |
| 21 |
*/ |
| 22 |
function addAttributes( settings, name ) { |
| 23 |
if ( ! isBeyondwordsSupportedBlock( name ) ) { |
| 24 |
return settings; |
| 25 |
} |
| 26 |
|
| 27 |
return { |
| 28 |
...settings, |
| 29 |
attributes: { |
| 30 |
...settings.attributes, |
| 31 |
beyondwordsAudio: { |
| 32 |
type: 'boolean', |
| 33 |
default: true, |
| 34 |
}, |
| 35 |
beyondwordsMarker: { |
| 36 |
type: 'string', |
| 37 |
default: '', |
| 38 |
}, |
| 39 |
}, |
| 40 |
}; |
| 41 |
} |
| 42 |
|
| 43 |
addFilter( |
| 44 |
'blocks.registerBlockType', |
| 45 |
'beyondwords/beyondwords-block-attributes', |
| 46 |
addAttributes |
| 47 |
); |
| 48 |
|