UNPKG

react-layouts-builder

Version:

Lightweight and powerfull react layouts drag and drop

37 lines (28 loc) 992 B
import { removeEmptyChildren } from '../helpers/moveContainer.js'; function removeBlockFromLayout(layouts, id) { var _a, _b; if (layouts.childrens) { for (var i = 0; i < layouts.childrens.length; i++) { var child = layouts.childrens[i]; var blockId = ((_a = child.block) === null || _a === void 0 ? void 0 : _a['@id']) || ((_b = child.block) === null || _b === void 0 ? void 0 : _b.id); if (blockId === id) { layouts.childrens.splice(i, 1); return layouts; } else if (child.childrens) { var removed = removeBlockFromLayout(child, id); if (removed) { if (removed.childrens && removed.childrens.length === 0) { delete removed.childrens; } return layouts; } } } } return null; } var removeBlock = function removeBlock(layouts, blockId) { var layout = removeBlockFromLayout(layouts, blockId); return removeEmptyChildren(layout); }; export { removeBlock };