@wordpress/block-editor
Version:
47 lines (43 loc) • 1.21 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = useListViewCollapseItems;
var _element = require("@wordpress/element");
var _data = require("@wordpress/data");
var _store = require("../../store");
var _lockUnlock = require("../../lock-unlock");
/**
* WordPress dependencies
*/
/**
* Internal dependencies
*/
function useListViewCollapseItems({
collapseAll,
expand
}) {
const {
expandedBlock,
getBlockParents
} = (0, _data.useSelect)(select => {
const {
getBlockParents: _getBlockParents,
getExpandedBlock
} = (0, _lockUnlock.unlock)(select(_store.store));
return {
expandedBlock: getExpandedBlock(),
getBlockParents: _getBlockParents
};
}, []);
// Collapse all but the specified block when the expanded block client Id changes.
(0, _element.useEffect)(() => {
if (expandedBlock) {
const blockParents = getBlockParents(expandedBlock, false);
// Collapse all blocks and expand the block's parents.
collapseAll();
expand(blockParents);
}
}, [collapseAll, expand, expandedBlock, getBlockParents]);
}
//# sourceMappingURL=use-list-view-collapse-items.js.map