@wordpress/block-library
Version:
Block library for the WordPress editor.
84 lines (82 loc) • 3.19 kB
JavaScript
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = MissingEdit;
var _i18n = require("@wordpress/i18n");
var _element = require("@wordpress/element");
var _components = require("@wordpress/components");
var _blocks = require("@wordpress/blocks");
var _data = require("@wordpress/data");
var _blockEditor = require("@wordpress/block-editor");
var _dom = require("@wordpress/dom");
var _jsxRuntime = require("react/jsx-runtime");
/**
* WordPress dependencies
*/
function MissingEdit({
attributes,
clientId
}) {
const {
originalName,
originalUndelimitedContent
} = attributes;
const hasContent = !!originalUndelimitedContent;
const {
hasFreeformBlock,
hasHTMLBlock
} = (0, _data.useSelect)(select => {
const {
canInsertBlockType,
getBlockRootClientId
} = select(_blockEditor.store);
return {
hasFreeformBlock: canInsertBlockType('core/freeform', getBlockRootClientId(clientId)),
hasHTMLBlock: canInsertBlockType('core/html', getBlockRootClientId(clientId))
};
}, [clientId]);
const {
replaceBlock
} = (0, _data.useDispatch)(_blockEditor.store);
function convertToHTML() {
replaceBlock(clientId, (0, _blocks.createBlock)('core/html', {
content: originalUndelimitedContent
}));
}
const actions = [];
let messageHTML;
const convertToHtmlButton = /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Button, {
__next40pxDefaultSize: true,
onClick: convertToHTML,
variant: "primary",
children: (0, _i18n.__)('Keep as HTML')
}, "convert");
if (hasContent && !hasFreeformBlock && !originalName) {
if (hasHTMLBlock) {
messageHTML = (0, _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, you can refresh the page to use the Classic block.');
actions.push(convertToHtmlButton);
} else {
messageHTML = (0, _i18n.__)('It appears you are trying to use the deprecated Classic block. You can leave this block intact, or remove it entirely. Alternatively, you can refresh the page to use the Classic block.');
}
} else if (hasContent && hasHTMLBlock) {
messageHTML = (0, _i18n.sprintf)(/* translators: %s: block name */
(0, _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, _i18n.sprintf)(/* translators: %s: block name */
(0, _i18n.__)('Your site doesn’t include support for the "%s" block. You can leave it as-is or remove it.'), originalName);
}
return /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
...(0, _blockEditor.useBlockProps)({
className: 'has-warning'
}),
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_blockEditor.Warning, {
actions: actions,
children: messageHTML
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_element.RawHTML, {
children: (0, _dom.safeHTML)(originalUndelimitedContent)
})]
});
}
//# sourceMappingURL=edit.js.map
;