(function ( wpI18n, wpHooks, wpEditor, wpComponents ) { const { addFilter } = wpHooks; const { __ } = wpI18n; const { InspectorControls } = wpEditor; const { PanelBody, Button } = wpComponents; // Register extra attributes to separator blocks addFilter( 'blocks.registerBlockType', 'advgb/registerExtraSeparatorAttrs', function ( settings ) { if (settings.name === 'core/separator') { settings.attributes = Object.assign( settings.attributes, { borderColor: { type: 'string', }, borderSize: { type: 'number', }, borderStyle: { type: 'string', }, borderWidth: { type: 'number', }, } ); } return settings; } ); // Add option to select styles for separator addFilter( 'editor.BlockEdit', 'advgb/customSeparatorStyles', function ( BlockEdit ) { return ( props ) => { if (props.name === "core/separator") { const { attributes, clientId } = props; const { borderColor, borderSize, borderStyle, borderWidth } = attributes; return ( [ ,

{ __( 'We recommend to clear all custom styles as soon as possible to avoid block error validation,' + ' because we will remove this feature in very next version.' ) }

, ] ) } return ; } } ); // Apply custom styles on front-end addFilter( 'blocks.getSaveContent.extraProps', 'advgb/saveSeparatorStyles', function ( extraProps, blockType, attributes ) { if (blockType.name === 'core/separator') { const { borderColor, borderSize, borderStyle, borderWidth } = attributes; extraProps = Object.assign( extraProps, { style: { borderBottomColor: borderColor, borderBottomWidth: borderWidth ? borderWidth + 'px' : undefined, borderBottomStyle: borderStyle, maxWidth: borderSize ? borderSize + 'px' : undefined, } } ) } return extraProps; } ); })( wp.i18n, wp.hooks, wp.editor, wp.components );