UNPKG

@wordpress/block-library

Version:
122 lines (109 loc) 2.77 kB
import { createElement } from "@wordpress/element"; /** * External dependencies */ import classnames from 'classnames'; /** * WordPress dependencies */ import { InnerBlocks, useBlockProps } from '@wordpress/block-editor'; /** * @param {Object} attributes Block's attributes. */ const migrateWithLayout = attributes => { if (!!attributes.layout) { return attributes; } const { contentJustification, orientation, ...updatedAttributes } = attributes; if (contentJustification || orientation) { Object.assign(updatedAttributes, { layout: { type: 'flex', ...(contentJustification && { justifyContent: contentJustification }), ...(orientation && { orientation }) } }); } return updatedAttributes; }; const deprecated = [{ attributes: { contentJustification: { type: 'string' }, orientation: { type: 'string', default: 'horizontal' } }, supports: { anchor: true, align: ['wide', 'full'], __experimentalExposeControlsToChildren: true, spacing: { blockGap: true, margin: ['top', 'bottom'], __experimentalDefaultControls: { blockGap: true } } }, isEligible: _ref => { let { contentJustification, orientation } = _ref; return !!contentJustification || !!orientation; }, migrate: migrateWithLayout, save(_ref2) { let { attributes: { contentJustification, orientation } } = _ref2; return createElement("div", useBlockProps.save({ className: classnames({ [`is-content-justification-${contentJustification}`]: contentJustification, 'is-vertical': orientation === 'vertical' }) }), createElement(InnerBlocks.Content, null)); } }, { supports: { align: ['center', 'left', 'right'], anchor: true }, save() { return createElement("div", null, createElement(InnerBlocks.Content, null)); }, isEligible(_ref3) { let { align } = _ref3; return align && ['center', 'left', 'right'].includes(align); }, migrate(attributes) { return migrateWithLayout({ ...attributes, align: undefined, // Floating Buttons blocks shouldn't have been supported in the // first place. Most users using them probably expected them to // act like content justification controls, so these blocks are // migrated to use content justification. // As for center-aligned Buttons blocks, the content justification // equivalent will create an identical end result in most cases. contentJustification: attributes.align }); } }]; export default deprecated; //# sourceMappingURL=deprecated.js.map