UNPKG

@wordpress/block-library

Version:
295 lines (273 loc) 6.24 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports.migrateToQuoteV2 = exports.default = void 0; var _element = require("@wordpress/element"); var _classnames = _interopRequireDefault(require("classnames")); var _blocks = require("@wordpress/blocks"); var _blockEditor = require("@wordpress/block-editor"); /** * External dependencies */ /** * WordPress dependencies */ const migrateToQuoteV2 = attributes => { const { value, ...restAttributes } = attributes; return [{ ...restAttributes }, value ? (0, _blocks.parseWithAttributeSchema)(value, { type: 'array', source: 'query', selector: 'p', query: { content: { type: 'string', source: 'html' } } }).map(_ref => { let { content } = _ref; return (0, _blocks.createBlock)('core/paragraph', { content }); }) : (0, _blocks.createBlock)('core/paragraph')]; }; exports.migrateToQuoteV2 = migrateToQuoteV2; const v3 = { attributes: { value: { type: 'string', source: 'html', selector: 'blockquote', multiline: 'p', default: '', __experimentalRole: 'content' }, citation: { type: 'string', source: 'html', selector: 'cite', default: '', __experimentalRole: 'content' }, align: { type: 'string' } }, supports: { anchor: true, __experimentalSlashInserter: true, typography: { fontSize: true, lineHeight: true, __experimentalFontStyle: true, __experimentalFontWeight: true, __experimentalLetterSpacing: true, __experimentalTextTransform: true, __experimentalDefaultControls: { fontSize: true, fontAppearance: true } } }, save(_ref2) { let { attributes } = _ref2; const { align, value, citation } = attributes; const className = (0, _classnames.default)({ [`has-text-align-${align}`]: align }); return (0, _element.createElement)("blockquote", _blockEditor.useBlockProps.save({ className }), (0, _element.createElement)(_blockEditor.RichText.Content, { multiline: true, value: value }), !_blockEditor.RichText.isEmpty(citation) && (0, _element.createElement)(_blockEditor.RichText.Content, { tagName: "cite", value: citation })); }, migrate: migrateToQuoteV2 }; const v2 = { attributes: { value: { type: 'string', source: 'html', selector: 'blockquote', multiline: 'p', default: '' }, citation: { type: 'string', source: 'html', selector: 'cite', default: '' }, align: { type: 'string' } }, migrate: migrateToQuoteV2, save(_ref3) { let { attributes } = _ref3; const { align, value, citation } = attributes; return (0, _element.createElement)("blockquote", { style: { textAlign: align ? align : null } }, (0, _element.createElement)(_blockEditor.RichText.Content, { multiline: true, value: value }), !_blockEditor.RichText.isEmpty(citation) && (0, _element.createElement)(_blockEditor.RichText.Content, { tagName: "cite", value: citation })); } }; const v1 = { attributes: { value: { type: 'string', source: 'html', selector: 'blockquote', multiline: 'p', default: '' }, citation: { type: 'string', source: 'html', selector: 'cite', default: '' }, align: { type: 'string' }, style: { type: 'number', default: 1 } }, migrate(attributes) { if (attributes.style === 2) { const { style, ...restAttributes } = attributes; return migrateToQuoteV2({ ...restAttributes, className: attributes.className ? attributes.className + ' is-style-large' : 'is-style-large' }); } return migrateToQuoteV2(attributes); }, save(_ref4) { let { attributes } = _ref4; const { align, value, citation, style } = attributes; return (0, _element.createElement)("blockquote", { className: style === 2 ? 'is-large' : '', style: { textAlign: align ? align : null } }, (0, _element.createElement)(_blockEditor.RichText.Content, { multiline: true, value: value }), !_blockEditor.RichText.isEmpty(citation) && (0, _element.createElement)(_blockEditor.RichText.Content, { tagName: "cite", value: citation })); } }; const v0 = { attributes: { value: { type: 'string', source: 'html', selector: 'blockquote', multiline: 'p', default: '' }, citation: { type: 'string', source: 'html', selector: 'footer', default: '' }, align: { type: 'string' }, style: { type: 'number', default: 1 } }, migrate(attributes) { if (!isNaN(parseInt(attributes.style))) { const { style, ...restAttributes } = attributes; return migrateToQuoteV2({ ...restAttributes }); } return migrateToQuoteV2(attributes); }, save(_ref5) { let { attributes } = _ref5; const { align, value, citation, style } = attributes; return (0, _element.createElement)("blockquote", { className: `blocks-quote-style-${style}`, style: { textAlign: align ? align : null } }, (0, _element.createElement)(_blockEditor.RichText.Content, { multiline: true, value: value }), !_blockEditor.RichText.isEmpty(citation) && (0, _element.createElement)(_blockEditor.RichText.Content, { tagName: "footer", value: citation })); } }; /** * New deprecations need to be placed first * for them to have higher priority. * * Old deprecations may need to be updated as well. * * See block-deprecation.md */ var _default = [v3, v2, v1, v0]; exports.default = _default; //# sourceMappingURL=deprecated.js.map