UNPKG

@wordpress/block-library

Version:
103 lines (89 loc) 3.65 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _element = require("@wordpress/element"); var _i18n = require("@wordpress/i18n"); var _blocks = require("@wordpress/blocks"); var _blockEditor = require("@wordpress/block-editor"); var _data = require("@wordpress/data"); /** * WordPress dependencies */ const name = 'core/paragraph'; const allowedParentBlockAlignments = ['left', 'center', 'right']; function ParagraphBlock(_ref) { var _style$baseColors, _style$baseColors$col, _style$baseColors2, _style$baseColors2$co, _style$baseColors3, _style$baseColors3$el, _style$baseColors3$el2, _style$baseColors3$el3; let { attributes, mergeBlocks, onReplace, setAttributes, style, clientId, parentBlockAlignment } = _ref; const isRTL = (0, _data.useSelect)(select => { return !!select(_blockEditor.store).getSettings().isRTL; }, []); const { align, content, placeholder } = attributes; const styles = { ...((style === null || style === void 0 ? void 0 : style.baseColors) && { color: (_style$baseColors = style.baseColors) === null || _style$baseColors === void 0 ? void 0 : (_style$baseColors$col = _style$baseColors.color) === null || _style$baseColors$col === void 0 ? void 0 : _style$baseColors$col.text, placeholderColor: style.color || ((_style$baseColors2 = style.baseColors) === null || _style$baseColors2 === void 0 ? void 0 : (_style$baseColors2$co = _style$baseColors2.color) === null || _style$baseColors2$co === void 0 ? void 0 : _style$baseColors2$co.text), linkColor: (_style$baseColors3 = style.baseColors) === null || _style$baseColors3 === void 0 ? void 0 : (_style$baseColors3$el = _style$baseColors3.elements) === null || _style$baseColors3$el === void 0 ? void 0 : (_style$baseColors3$el2 = _style$baseColors3$el.link) === null || _style$baseColors3$el2 === void 0 ? void 0 : (_style$baseColors3$el3 = _style$baseColors3$el2.color) === null || _style$baseColors3$el3 === void 0 ? void 0 : _style$baseColors3$el3.text }), ...style }; const onAlignmentChange = (0, _element.useCallback)(nextAlign => { setAttributes({ align: nextAlign }); }, []); const parentTextAlignment = allowedParentBlockAlignments.includes(parentBlockAlignment) ? parentBlockAlignment : undefined; const textAlignment = align || parentTextAlignment; return (0, _element.createElement)(_element.Fragment, null, (0, _element.createElement)(_blockEditor.BlockControls, { group: "block" }, (0, _element.createElement)(_blockEditor.AlignmentControl, { value: align, isRTL: isRTL, onChange: onAlignmentChange })), (0, _element.createElement)(_blockEditor.RichText, { identifier: "content", tagName: "p", value: content, deleteEnter: true, style: styles, onChange: nextContent => { setAttributes({ content: nextContent }); }, onSplit: (value, isOriginal) => { let newAttributes; if (isOriginal || value) { newAttributes = { ...attributes, content: value }; } const block = (0, _blocks.createBlock)(name, newAttributes); if (isOriginal) { block.clientId = clientId; } return block; }, onMerge: mergeBlocks, onReplace: onReplace, onRemove: onReplace ? () => onReplace([]) : undefined, placeholder: placeholder || (0, _i18n.__)('Start writing…'), textAlign: textAlignment, __unstableEmbedURLOnPaste: true })); } var _default = ParagraphBlock; exports.default = _default; //# sourceMappingURL=edit.native.js.map