@wordpress/block-library
Version:
Block library for the WordPress editor.
94 lines (92 loc) • 2.77 kB
JavaScript
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _i18n = require("@wordpress/i18n");
var _blocks = require("@wordpress/blocks");
var _blockEditor = require("@wordpress/block-editor");
var _element = require("@wordpress/element");
var _data = require("@wordpress/data");
var _jsxRuntime = require("react/jsx-runtime");
/**
* WordPress dependencies
*/
const name = 'core/paragraph';
const allowedParentBlockAlignments = ['left', 'center', 'right'];
function ParagraphBlock({
attributes,
mergeBlocks,
onReplace,
setAttributes,
style,
clientId,
parentBlockAlignment
}) {
const isRTL = (0, _data.useSelect)(select => {
return !!select(_blockEditor.store).getSettings().isRTL;
}, []);
const {
align,
content,
placeholder
} = attributes;
const styles = {
...(style?.baseColors && {
color: style.baseColors?.color?.text,
placeholderColor: style.color || style.baseColors?.color?.text,
linkColor: style.baseColors?.elements?.link?.color?.text
}),
...style
};
const onAlignmentChange = (0, _element.useCallback)(nextAlign => {
setAttributes({
align: nextAlign
});
}, []);
const parentTextAlignment = allowedParentBlockAlignments.includes(parentBlockAlignment) ? parentBlockAlignment : undefined;
const textAlignment = align || parentTextAlignment;
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_blockEditor.BlockControls, {
group: "block",
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_blockEditor.AlignmentControl, {
value: align,
isRTL: isRTL,
onChange: onAlignmentChange
})
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_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 = exports.default = ParagraphBlock;
//# sourceMappingURL=edit.native.js.map
;