UNPKG

@wordpress/block-library

Version:
238 lines (231 loc) 7.91 kB
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty"; import _objectSpread from "@babel/runtime/helpers/esm/objectSpread"; import { createElement } from "@wordpress/element"; /** * External dependencies */ import classnames from 'classnames'; import { isFinite, omit } from 'lodash'; /** * WordPress dependencies */ import { __ } from '@wordpress/i18n'; import { RawHTML } from '@wordpress/element'; import { getColorClassName, getFontSizeClass, RichText } from '@wordpress/block-editor'; import { getPhrasingContentSchema } from '@wordpress/blocks'; import { Path, SVG } from '@wordpress/components'; /** * Internal dependencies */ import edit from './edit'; var supports = { className: false }; var schema = { content: { type: 'string', source: 'html', selector: 'p', default: '' }, align: { type: 'string' }, dropCap: { type: 'boolean', default: false }, placeholder: { type: 'string' }, textColor: { type: 'string' }, customTextColor: { type: 'string' }, backgroundColor: { type: 'string' }, customBackgroundColor: { type: 'string' }, fontSize: { type: 'string' }, customFontSize: { type: 'number' }, direction: { type: 'string', enum: ['ltr', 'rtl'] } }; export var name = 'core/paragraph'; export var settings = { title: __('Paragraph'), description: __('Start with the building block of all narrative.'), icon: createElement(SVG, { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24" }, createElement(Path, { d: "M11 5v7H9.5C7.6 12 6 10.4 6 8.5S7.6 5 9.5 5H11m8-2H9.5C6.5 3 4 5.5 4 8.5S6.5 14 9.5 14H11v7h2V5h2v16h2V5h2V3z" })), category: 'common', keywords: [__('text')], supports: supports, attributes: schema, transforms: { from: [{ type: 'raw', // Paragraph is a fallback and should be matched last. priority: 20, selector: 'p', schema: { p: { children: getPhrasingContentSchema() } } }] }, deprecated: [{ supports: supports, attributes: _objectSpread({}, schema, { width: { type: 'string' } }), save: function save(_ref) { var _classnames; var attributes = _ref.attributes; var width = attributes.width, align = attributes.align, content = attributes.content, dropCap = attributes.dropCap, backgroundColor = attributes.backgroundColor, textColor = attributes.textColor, customBackgroundColor = attributes.customBackgroundColor, customTextColor = attributes.customTextColor, fontSize = attributes.fontSize, customFontSize = attributes.customFontSize; var textClass = getColorClassName('color', textColor); var backgroundClass = getColorClassName('background-color', backgroundColor); var fontSizeClass = fontSize && "is-".concat(fontSize, "-text"); var className = classnames((_classnames = {}, _defineProperty(_classnames, "align".concat(width), width), _defineProperty(_classnames, 'has-background', backgroundColor || customBackgroundColor), _defineProperty(_classnames, 'has-drop-cap', dropCap), _defineProperty(_classnames, fontSizeClass, fontSizeClass), _defineProperty(_classnames, textClass, textClass), _defineProperty(_classnames, backgroundClass, backgroundClass), _classnames)); var styles = { backgroundColor: backgroundClass ? undefined : customBackgroundColor, color: textClass ? undefined : customTextColor, fontSize: fontSizeClass ? undefined : customFontSize, textAlign: align }; return createElement(RichText.Content, { tagName: "p", style: styles, className: className ? className : undefined, value: content }); } }, { supports: supports, attributes: omit(_objectSpread({}, schema, { fontSize: { type: 'number' } }), 'customFontSize', 'customTextColor', 'customBackgroundColor'), save: function save(_ref2) { var _classnames2; var attributes = _ref2.attributes; var width = attributes.width, align = attributes.align, content = attributes.content, dropCap = attributes.dropCap, backgroundColor = attributes.backgroundColor, textColor = attributes.textColor, fontSize = attributes.fontSize; var className = classnames((_classnames2 = {}, _defineProperty(_classnames2, "align".concat(width), width), _defineProperty(_classnames2, 'has-background', backgroundColor), _defineProperty(_classnames2, 'has-drop-cap', dropCap), _classnames2)); var styles = { backgroundColor: backgroundColor, color: textColor, fontSize: fontSize, textAlign: align }; return createElement("p", { style: styles, className: className ? className : undefined }, content); }, migrate: function migrate(attributes) { return omit(_objectSpread({}, attributes, { customFontSize: isFinite(attributes.fontSize) ? attributes.fontSize : undefined, customTextColor: attributes.textColor && '#' === attributes.textColor[0] ? attributes.textColor : undefined, customBackgroundColor: attributes.backgroundColor && '#' === attributes.backgroundColor[0] ? attributes.backgroundColor : undefined }), ['fontSize', 'textColor', 'backgroundColor']); } }, { supports: supports, attributes: _objectSpread({}, schema, { content: { type: 'string', source: 'html', default: '' } }), save: function save(_ref3) { var attributes = _ref3.attributes; return createElement(RawHTML, null, attributes.content); }, migrate: function migrate(attributes) { return attributes; } }], merge: function merge(attributes, attributesToMerge) { return { content: (attributes.content || '') + (attributesToMerge.content || '') }; }, getEditWrapperProps: function getEditWrapperProps(attributes) { var width = attributes.width; if (['wide', 'full', 'left', 'right'].indexOf(width) !== -1) { return { 'data-align': width }; } }, edit: edit, save: function save(_ref4) { var _classnames3; var attributes = _ref4.attributes; var align = attributes.align, content = attributes.content, dropCap = attributes.dropCap, backgroundColor = attributes.backgroundColor, textColor = attributes.textColor, customBackgroundColor = attributes.customBackgroundColor, customTextColor = attributes.customTextColor, fontSize = attributes.fontSize, customFontSize = attributes.customFontSize, direction = attributes.direction; var textClass = getColorClassName('color', textColor); var backgroundClass = getColorClassName('background-color', backgroundColor); var fontSizeClass = getFontSizeClass(fontSize); var className = classnames((_classnames3 = { 'has-text-color': textColor || customTextColor, 'has-background': backgroundColor || customBackgroundColor, 'has-drop-cap': dropCap }, _defineProperty(_classnames3, fontSizeClass, fontSizeClass), _defineProperty(_classnames3, textClass, textClass), _defineProperty(_classnames3, backgroundClass, backgroundClass), _classnames3)); var styles = { backgroundColor: backgroundClass ? undefined : customBackgroundColor, color: textClass ? undefined : customTextColor, fontSize: fontSizeClass ? undefined : customFontSize, textAlign: align }; return createElement(RichText.Content, { tagName: "p", style: styles, className: className ? className : undefined, value: content, dir: direction }); } }; //# sourceMappingURL=index.js.map