UNPKG

@wordpress/block-editor

Version:
30 lines (28 loc) 777 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = useListViewBlockIndexes; var _element = require("@wordpress/element"); /** * WordPress dependencies */ function useListViewBlockIndexes(blocks) { const blockIndexes = (0, _element.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; } //# sourceMappingURL=use-list-view-block-indexes.js.map