@wordpress/block-library
Version:
Block library for the WordPress editor.
111 lines (110 loc) • 4.96 kB
JavaScript
;
Object.defineProperties(exports, {
__esModule: { value: true },
[Symbol.toStringTag]: { value: "Module" }
});
// \0rolldown/runtime.js
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
key = keys[i];
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
get: ((k) => from[k]).bind(null, key),
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
});
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
value: mod,
enumerable: true
}) : target, mod));
let clsx = require("clsx");
clsx = __toESM(clsx);
let _wordpress_i18n = require("@wordpress/i18n");
let _wordpress_block_editor = require("@wordpress/block-editor");
let _wordpress_components = require("@wordpress/components");
let _wordpress_data = require("@wordpress/data");
let _wordpress_element = require("@wordpress/element");
let _wordpress_deprecated = require("@wordpress/deprecated");
_wordpress_deprecated = __toESM(_wordpress_deprecated);
let _wordpress_icons = require("@wordpress/icons");
let __deprecated_jsx = require("./deprecated.cjs");
let ___utils_caption_jsx = require("../utils/caption.cjs");
let react_jsx_runtime = require("react/jsx-runtime");
// packages/block-library/src/quote/edit.jsx
/**
* At the moment, deprecations don't handle create blocks from attributes
* (like when using CPT templates). For this reason, this hook is necessary
* to avoid breaking templates using the old quote block format.
*
* @param {Object} attributes Block attributes.
* @param {string} clientId Block client ID.
*/
const useMigrateOnLoad = (attributes, clientId) => {
const registry = (0, _wordpress_data.useRegistry)();
const { updateBlockAttributes, replaceInnerBlocks, selectBlock } = (0, _wordpress_data.useDispatch)(_wordpress_block_editor.store);
(0, _wordpress_element.useEffect)(() => {
if (!attributes.value) return;
const [newAttributes, newInnerBlocks] = (0, __deprecated_jsx.migrateToQuoteV2)(attributes);
(0, _wordpress_deprecated.default)("Value attribute on the quote block", {
since: "6.0",
version: "6.5",
alternative: "inner blocks"
});
const shouldReselectBlock = registry.select(_wordpress_block_editor.store).hasSelectedInnerBlock(clientId, true);
registry.batch(() => {
updateBlockAttributes(clientId, newAttributes);
replaceInnerBlocks(clientId, newInnerBlocks);
if (shouldReselectBlock) selectBlock(clientId);
});
}, [attributes.value]);
};
function QuoteEdit({ attributes, setAttributes, insertBlocksAfter, clientId, className, isSelected }) {
const { textAlign, allowedBlocks } = attributes;
const { hasInnerBlocks } = (0, _wordpress_data.useSelect)((select) => {
const { getBlockCount } = select(_wordpress_block_editor.store);
return { hasInnerBlocks: getBlockCount(clientId) > 0 };
}, [clientId]);
useMigrateOnLoad(attributes, clientId);
const blockProps = (0, _wordpress_block_editor.useBlockProps)({ className: (0, clsx.default)(className, { [`has-text-align-${textAlign}`]: textAlign }) });
const innerBlocksProps = (0, _wordpress_block_editor.useInnerBlocksProps)(blockProps, {
__experimentalCaptureToolbars: true,
renderAppender: hasInnerBlocks ? false : void 0,
allowedBlocks
});
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_block_editor.BlockControls, {
group: "block",
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_block_editor.AlignmentControl, {
value: textAlign,
onChange: (nextAlign) => {
setAttributes({ textAlign: nextAlign });
}
})
}), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_wordpress_components.BlockQuotation, {
...innerBlocksProps,
children: [innerBlocksProps.children, /* @__PURE__ */ (0, react_jsx_runtime.jsx)(___utils_caption_jsx.Caption, {
attributeKey: "citation",
tagName: "cite",
style: { display: "block" },
isSelected,
attributes,
setAttributes,
icon: _wordpress_icons.verse,
label: (0, _wordpress_i18n.__)("Quote citation"),
placeholder: (0, _wordpress_i18n.__)("Add citation"),
addLabel: (0, _wordpress_i18n.__)("Add citation"),
removeLabel: (0, _wordpress_i18n.__)("Remove citation"),
excludeElementClassName: true,
className: "wp-block-quote__citation",
insertBlocksAfter
})]
})] });
}
exports.default = QuoteEdit;
//# sourceMappingURL=edit.cjs.map