@wordpress/block-editor
Version:
56 lines (51 loc) • 1.89 kB
JavaScript
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = useSelectedBlockToolProps;
var _data = require("@wordpress/data");
var _store = require("../../store");
/**
* WordPress dependencies
*/
/**
* Internal dependencies
*/
/**
* Returns props for the selected block tools and empty block inserter.
*
* @param {string} clientId Selected block client ID.
*/
function useSelectedBlockToolProps(clientId) {
const selectedBlockProps = (0, _data.useSelect)(select => {
const {
getBlockRootClientId,
getBlockParents,
__experimentalGetBlockListSettingsForBlocks,
isBlockInsertionPointVisible,
getBlockInsertionPoint,
getBlockOrder,
hasMultiSelection,
getLastMultiSelectedBlockClientId
} = select(_store.store);
const blockParentsClientIds = getBlockParents(clientId);
// Get Block List Settings for all ancestors of the current Block clientId.
const parentBlockListSettings = __experimentalGetBlockListSettingsForBlocks(blockParentsClientIds);
// Get the clientId of the topmost parent with the capture toolbars setting.
const capturingClientId = blockParentsClientIds.find(parentClientId => parentBlockListSettings[parentClientId]?.__experimentalCaptureToolbars);
let isInsertionPointVisible = false;
if (isBlockInsertionPointVisible()) {
const insertionPoint = getBlockInsertionPoint();
const order = getBlockOrder(insertionPoint.rootClientId);
isInsertionPointVisible = order[insertionPoint.index] === clientId;
}
return {
capturingClientId,
isInsertionPointVisible,
lastClientId: hasMultiSelection() ? getLastMultiSelectedBlockClientId() : null,
rootClientId: getBlockRootClientId(clientId)
};
}, [clientId]);
return selectedBlockProps;
}
//# sourceMappingURL=use-selected-block-tool-props.js.map
;