UNPKG

@wordpress/block-library

Version:
247 lines (227 loc) 5.28 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _element = require("@wordpress/element"); var _classnames = _interopRequireDefault(require("classnames")); var _blockEditor = require("@wordpress/block-editor"); /** * External dependencies */ /** * WordPress dependencies */ const blockSupports = { className: false, anchor: true }; const blockAttributes = { align: { type: 'string' }, content: { type: 'string', source: 'html', selector: 'h1,h2,h3,h4,h5,h6', default: '' }, level: { type: 'number', default: 2 }, placeholder: { type: 'string' } }; const migrateCustomColors = attributes => { if (!attributes.customTextColor) { return attributes; } const style = { color: { text: attributes.customTextColor } }; const { customTextColor, ...restAttributes } = attributes; return { ...restAttributes, style }; }; const TEXT_ALIGN_OPTIONS = ['left', 'right', 'center']; const migrateTextAlign = attributes => { const { align, ...rest } = attributes; return TEXT_ALIGN_OPTIONS.includes(align) ? { ...rest, textAlign: align } : attributes; }; const deprecated = [{ supports: { align: ['wide', 'full'], anchor: true, className: false, color: { link: true }, fontSize: true, lineHeight: true, __experimentalSelector: { 'core/heading/h1': 'h1', 'core/heading/h2': 'h2', 'core/heading/h3': 'h3', 'core/heading/h4': 'h4', 'core/heading/h5': 'h5', 'core/heading/h6': 'h6' }, __unstablePasteTextInline: true }, attributes: blockAttributes, isEligible: _ref => { let { align } = _ref; return TEXT_ALIGN_OPTIONS.includes(align); }, migrate: migrateTextAlign, save(_ref2) { let { attributes } = _ref2; const { align, content, level } = attributes; const TagName = 'h' + level; const className = (0, _classnames.default)({ [`has-text-align-${align}`]: align }); return (0, _element.createElement)(TagName, _blockEditor.useBlockProps.save({ className }), (0, _element.createElement)(_blockEditor.RichText.Content, { value: content })); } }, { supports: blockSupports, attributes: { ...blockAttributes, customTextColor: { type: 'string' }, textColor: { type: 'string' } }, migrate: attributes => migrateCustomColors(migrateTextAlign(attributes)), save(_ref3) { let { attributes } = _ref3; const { align, content, customTextColor, level, textColor } = attributes; const tagName = 'h' + level; const textClass = (0, _blockEditor.getColorClassName)('color', textColor); const className = (0, _classnames.default)({ [textClass]: textClass, 'has-text-color': textColor || customTextColor, [`has-text-align-${align}`]: align }); return (0, _element.createElement)(_blockEditor.RichText.Content, { className: className ? className : undefined, tagName: tagName, style: { color: textClass ? undefined : customTextColor }, value: content }); } }, { attributes: { ...blockAttributes, customTextColor: { type: 'string' }, textColor: { type: 'string' } }, migrate: attributes => migrateCustomColors(migrateTextAlign(attributes)), save(_ref4) { let { attributes } = _ref4; const { align, content, customTextColor, level, textColor } = attributes; const tagName = 'h' + level; const textClass = (0, _blockEditor.getColorClassName)('color', textColor); const className = (0, _classnames.default)({ [textClass]: textClass, [`has-text-align-${align}`]: align }); return (0, _element.createElement)(_blockEditor.RichText.Content, { className: className ? className : undefined, tagName: tagName, style: { color: textClass ? undefined : customTextColor }, value: content }); }, supports: blockSupports }, { supports: blockSupports, attributes: { ...blockAttributes, customTextColor: { type: 'string' }, textColor: { type: 'string' } }, migrate: attributes => migrateCustomColors(migrateTextAlign(attributes)), save(_ref5) { let { attributes } = _ref5; const { align, level, content, textColor, customTextColor } = attributes; const tagName = 'h' + level; const textClass = (0, _blockEditor.getColorClassName)('color', textColor); const className = (0, _classnames.default)({ [textClass]: textClass }); return (0, _element.createElement)(_blockEditor.RichText.Content, { className: className ? className : undefined, tagName: tagName, style: { textAlign: align, color: textClass ? undefined : customTextColor }, value: content }); } }]; var _default = deprecated; exports.default = _default; //# sourceMappingURL=deprecated.js.map