@wordpress/block-editor
Version:
57 lines (52 loc) • 1.86 kB
JavaScript
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = useUnsupportedBlockEditor;
var _data = require("@wordpress/data");
var _blocks = require("@wordpress/blocks");
var _store = require("../../store");
/**
* WordPress dependencies
*/
/**
* Internal dependencies
*/
// Blocks that can't be edited through the Unsupported block editor identified by their name.
const UBE_INCOMPATIBLE_BLOCKS = ['core/block'];
/**
* Hook that retrieves the settings to determine if the
* Unsupported Block Editor can be used in a specific block.
*
* @param {string} clientId Client ID of block.
* @return {Object} Unsupported block editor settings.
*/
function useUnsupportedBlockEditor(clientId) {
return (0, _data.useSelect)(select => {
const {
getBlock,
getSettings
} = select(_store.store);
const {
capabilities
} = getSettings();
const block = getBlock(clientId);
const blockAttributes = block?.attributes || {};
const blockDetails = {
blockName: block?.name,
blockContent: (0, _blocks.serialize)(block ? [block] : [])
};
// If the block is unsupported, use the `original` attributes to identify the block's name.
if (blockDetails.blockName === 'core/missing') {
blockDetails.blockName = blockAttributes.originalName;
blockDetails.blockContent = blockDetails.blockName === 'core/freeform' ? blockAttributes.content : block?.originalContent;
}
return {
isUnsupportedBlockEditorSupported: capabilities?.unsupportedBlockEditor === true,
canEnableUnsupportedBlockEditor: capabilities?.canEnableUnsupportedBlockEditor === true,
isEditableInUnsupportedBlockEditor: !UBE_INCOMPATIBLE_BLOCKS.includes(blockDetails.blockName),
...blockDetails
};
}, [clientId]);
}
//# sourceMappingURL=index.native.js.map
;