UNPKG

@wordpress/block-editor

Version:
25 lines (24 loc) 741 B
// packages/block-editor/src/components/list-view/use-list-view-block-indexes.js import { useMemo } from "@wordpress/element"; function useListViewBlockIndexes(blocks) { const blockIndexes = useMemo(() => { const indexes = {}; let currentGlobalIndex = 0; const traverseBlocks = (blockList) => { blockList.forEach((block) => { indexes[block.clientId] = currentGlobalIndex; currentGlobalIndex++; if (block.innerBlocks.length > 0) { traverseBlocks(block.innerBlocks); } }); }; traverseBlocks(blocks); return indexes; }, [blocks]); return blockIndexes; } export { useListViewBlockIndexes as default }; //# sourceMappingURL=use-list-view-block-indexes.mjs.map