@wordpress/block-library
Version:
Block library for the WordPress editor.
125 lines (108 loc) • 4.59 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _element = require("@wordpress/element");
var _i18n = require("@wordpress/i18n");
var _blockEditor = require("@wordpress/block-editor");
var _blocks = require("@wordpress/blocks");
var _figure = require("./figure");
var _blockquote = require("./blockquote");
/**
* WordPress dependencies
*/
/**
* Internal dependencies
*/
const getBackgroundColor = _ref => {
var _colorProps$style, _colorProps$style2;
let {
attributes,
colors,
style
} = _ref;
const {
backgroundColor
} = attributes;
const colorProps = (0, _blockEditor.__experimentalGetColorClassesAndStyles)(attributes);
const colorObject = (0, _blockEditor.getColorObjectByAttributeValues)(colors, backgroundColor);
return (colorObject === null || colorObject === void 0 ? void 0 : colorObject.color) || ((_colorProps$style = colorProps.style) === null || _colorProps$style === void 0 ? void 0 : _colorProps$style.backgroundColor) || ((_colorProps$style2 = colorProps.style) === null || _colorProps$style2 === void 0 ? void 0 : _colorProps$style2.background) || (style === null || style === void 0 ? void 0 : style.backgroundColor);
};
const getTextColor = _ref2 => {
var _colorProps$style3, _style$baseColors, _style$baseColors$col;
let {
attributes,
colors,
style
} = _ref2;
const colorProps = (0, _blockEditor.__experimentalGetColorClassesAndStyles)(attributes);
const colorObject = (0, _blockEditor.getColorObjectByAttributeValues)(colors, attributes.textColor);
return (colorObject === null || colorObject === void 0 ? void 0 : colorObject.color) || ((_colorProps$style3 = colorProps.style) === null || _colorProps$style3 === void 0 ? void 0 : _colorProps$style3.color) || (style === null || style === void 0 ? void 0 : style.color) || (style === null || style === void 0 ? void 0 : (_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);
};
const getBorderColor = props => {
var _wrapperProps$style;
const {
wrapperProps
} = props;
const defaultColor = getTextColor(props);
return (wrapperProps === null || wrapperProps === void 0 ? void 0 : (_wrapperProps$style = wrapperProps.style) === null || _wrapperProps$style === void 0 ? void 0 : _wrapperProps$style.borderColor) || defaultColor;
};
/**
* Internal dependencies
*/
function PullQuoteEdit(props) {
const {
attributes,
setAttributes,
isSelected,
insertBlocksAfter
} = props;
const {
textAlign,
citation,
value
} = attributes;
const blockProps = (0, _blockEditor.useBlockProps)({
backgroundColor: getBackgroundColor(props),
borderColor: getBorderColor(props)
});
const shouldShowCitation = !_blockEditor.RichText.isEmpty(citation) || isSelected;
return (0, _element.createElement)(_element.Fragment, null, (0, _element.createElement)(_blockEditor.BlockControls, {
group: "block"
}, (0, _element.createElement)(_blockEditor.AlignmentControl, {
value: textAlign,
onChange: nextAlign => {
setAttributes({
textAlign: nextAlign
});
}
})), (0, _element.createElement)(_figure.Figure, blockProps, (0, _element.createElement)(_blockquote.BlockQuote, {
textColor: getTextColor(props)
}, (0, _element.createElement)(_blockEditor.RichText, {
identifier: "value",
value: value,
onChange: nextValue => setAttributes({
value: nextValue
}),
"aria-label": (0, _i18n.__)('Pullquote text'),
placeholder: // translators: placeholder text used for the quote
(0, _i18n.__)('Add quote'),
textAlign: textAlign !== null && textAlign !== void 0 ? textAlign : 'center'
}), shouldShowCitation && (0, _element.createElement)(_blockEditor.RichText, {
identifier: "citation",
value: citation,
"aria-label": (0, _i18n.__)('Pullquote citation text'),
placeholder: // translators: placeholder text used for the citation
(0, _i18n.__)('Add citation'),
onChange: nextCitation => setAttributes({
citation: nextCitation
}),
__unstableMobileNoFocusOnMount: true,
textAlign: textAlign !== null && textAlign !== void 0 ? textAlign : 'center',
__unstableOnSplitAtEnd: () => insertBlocksAfter((0, _blocks.createBlock)((0, _blocks.getDefaultBlockName)()))
}))));
}
var _default = PullQuoteEdit;
exports.default = _default;
//# sourceMappingURL=edit.native.js.map