UNPKG

@wordpress/block-library

Version:
118 lines (115 loc) 3.05 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _clsx = _interopRequireDefault(require("clsx")); var _blockEditor = require("@wordpress/block-editor"); var _jsxRuntime = require("react/jsx-runtime"); /** * External dependencies */ /** * WordPress dependencies */ /** * @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: ({ contentJustification, orientation }) => !!contentJustification || !!orientation, migrate: migrateWithLayout, save({ attributes: { contentJustification, orientation } }) { return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", { ..._blockEditor.useBlockProps.save({ className: (0, _clsx.default)({ [`is-content-justification-${contentJustification}`]: contentJustification, 'is-vertical': orientation === 'vertical' }) }), children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_blockEditor.InnerBlocks.Content, {}) }); } }, { supports: { align: ['center', 'left', 'right'], anchor: true }, save() { return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", { children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_blockEditor.InnerBlocks.Content, {}) }); }, isEligible({ align }) { 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 }); } }]; var _default = exports.default = deprecated; //# sourceMappingURL=deprecated.js.map