I have blocks in container like below

if i remove one block (ex: 1) it should arrange like below
assume i have all blocks coordinates like width, height of each block and x1,y1, x2, y2 from top i tried using recursive loops to find out all items below the deleted one and recursively move all items to move up.but its not working as expected as i need to consider collision (ex: if any block try to move up it should not collide with other blocks, ifcollision occur it should be in same place instead of moving up) any pointers to solution great help for me
You can declare an index for each block declaring position and width size for example for the first block you can store {x:1, y:1, w:2} ( x is position from left and y is position from top and w is block width which can be specified from your smallest block ) and every time that a block is removed you can rerender like : if a block with {x:1, y:1, w:2} is removed you search all the blocks and make a condition that if block.x and block.x + block.w is in (x .. x + w) range and block.y = y + 1 then you should replace this blocks absolute top postion with old top position - block height. I can help you rewrite the code better if you share your code.