@wordpress/block-editor
Version:
40 lines (37 loc) • 1.16 kB
JavaScript
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.useGetNumberOfBlocksBeforeCell = useGetNumberOfBlocksBeforeCell;
var _data = require("@wordpress/data");
var _store = require("../../store");
/**
* WordPress dependencies
*/
/**
* Internal dependencies
*/
function useGetNumberOfBlocksBeforeCell(gridClientId, numColumns) {
const {
getBlockOrder,
getBlockAttributes
} = (0, _data.useSelect)(_store.store);
const getNumberOfBlocksBeforeCell = (column, row) => {
const targetIndex = (row - 1) * numColumns + column - 1;
let count = 0;
for (const clientId of getBlockOrder(gridClientId)) {
var _getBlockAttributes$s;
const {
columnStart,
rowStart
} = (_getBlockAttributes$s = getBlockAttributes(clientId).style?.layout) !== null && _getBlockAttributes$s !== void 0 ? _getBlockAttributes$s : {};
const cellIndex = (rowStart - 1) * numColumns + columnStart - 1;
if (cellIndex < targetIndex) {
count++;
}
}
return count;
};
return getNumberOfBlocksBeforeCell;
}
//# sourceMappingURL=use-get-number-of-blocks-before-cell.js.map
;