@wordpress/block-editor
Version:
24 lines (23 loc) • 940 B
JavaScript
// packages/block-editor/src/components/grid/use-get-number-of-blocks-before-cell.js
import { useSelect } from "@wordpress/data";
import { store as blockEditorStore } from "../../store/index.mjs";
function useGetNumberOfBlocksBeforeCell(gridClientId, numColumns) {
const { getBlockOrder, getBlockAttributes } = useSelect(blockEditorStore);
const getNumberOfBlocksBeforeCell = (column, row) => {
const targetIndex = (row - 1) * numColumns + column - 1;
let count = 0;
for (const clientId of getBlockOrder(gridClientId)) {
const { columnStart, rowStart } = getBlockAttributes(clientId).style?.layout ?? {};
const cellIndex = (rowStart - 1) * numColumns + columnStart - 1;
if (cellIndex < targetIndex) {
count++;
}
}
return count;
};
return getNumberOfBlocksBeforeCell;
}
export {
useGetNumberOfBlocksBeforeCell
};
//# sourceMappingURL=use-get-number-of-blocks-before-cell.mjs.map