@wordpress/block-library
Version:
Block library for the WordPress editor.
56 lines (55 loc) • 3.39 kB
JavaScript
;
Object.defineProperties(exports, {
__esModule: { value: true },
[Symbol.toStringTag]: { value: "Module" }
});
let _wordpress_i18n = require("@wordpress/i18n");
let _wordpress_element = require("@wordpress/element");
let _wordpress_components = require("@wordpress/components");
let _wordpress_blocks = require("@wordpress/blocks");
let _wordpress_data = require("@wordpress/data");
let _wordpress_block_editor = require("@wordpress/block-editor");
let _wordpress_dom = require("@wordpress/dom");
let react_jsx_runtime = require("react/jsx-runtime");
// packages/block-library/src/missing/edit.jsx
function MissingEdit({ attributes, clientId }) {
const { originalName, originalUndelimitedContent } = attributes;
const hasContent = !!originalUndelimitedContent;
const { hasFreeformBlock, hasHTMLBlock } = (0, _wordpress_data.useSelect)((select) => {
const { canInsertBlockType, getBlockRootClientId } = select(_wordpress_block_editor.store);
return {
hasFreeformBlock: canInsertBlockType("core/freeform", getBlockRootClientId(clientId)),
hasHTMLBlock: canInsertBlockType("core/html", getBlockRootClientId(clientId))
};
}, [clientId]);
const { replaceBlock } = (0, _wordpress_data.useDispatch)(_wordpress_block_editor.store);
function convertToHTML() {
replaceBlock(clientId, (0, _wordpress_blocks.createBlock)("core/html", {}, [], [originalUndelimitedContent]));
}
const actions = [];
let messageHTML;
const convertToHtmlButton = /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_components.Button, {
__next40pxDefaultSize: true,
onClick: convertToHTML,
variant: "primary",
children: (0, _wordpress_i18n.__)("Keep as HTML")
}, "convert");
if (hasContent && !hasFreeformBlock && (!originalName || originalName === "core/freeform")) {
if (hasHTMLBlock) {
messageHTML = (0, _wordpress_i18n.__)("It appears you are trying to use the deprecated Classic block. You can leave this block intact, convert its content to a Custom HTML block, or remove it entirely. Alternatively, if you have unsaved changes, you can save them and refresh to use the Classic block.");
actions.push(convertToHtmlButton);
} else messageHTML = (0, _wordpress_i18n.__)("It appears you are trying to use the deprecated Classic block. You can leave this block intact, or remove it entirely. Alternatively, if you have unsaved changes, you can save them and refresh to use the Classic block.");
} else if (hasContent && hasHTMLBlock) {
messageHTML = (0, _wordpress_i18n.sprintf)((0, _wordpress_i18n.__)("Your site doesn’t include support for the \"%s\" block. You can leave it as-is, convert it to custom HTML, or remove it."), originalName);
actions.push(convertToHtmlButton);
} else messageHTML = (0, _wordpress_i18n.sprintf)((0, _wordpress_i18n.__)("Your site doesn’t include support for the \"%s\" block. You can leave it as-is or remove it."), originalName);
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
...(0, _wordpress_block_editor.useBlockProps)({ className: "has-warning" }),
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_block_editor.Warning, {
actions,
children: messageHTML
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_element.RawHTML, { children: (0, _wordpress_dom.safeHTML)(originalUndelimitedContent) })]
});
}
exports.default = MissingEdit;
//# sourceMappingURL=edit.cjs.map