* Inserts a block into the content array of the parent block. If a position object is provided, the block will be inserted at the specified position.
(newBlock: Block, position?: { prevBlockId?: string | undefined, nextBlockId?: string | undefined })
| 95 | * Inserts a block into the content array of the parent block. If a position object is provided, the block will be inserted at the specified position. |
| 96 | */ |
| 97 | function insertBlock(newBlock: Block, position?: { prevBlockId?: string | undefined, nextBlockId?: string | undefined }) { |
| 98 | const updatedBlock = updateBlockData(blocksRef.current[newBlock.parent], { |
| 99 | content: insertBlockIdIntoContent(blocksRef.current[newBlock.parent].content, newBlock.id, { |
| 100 | prevBlockId: position?.prevBlockId, |
| 101 | nextBlockId: position?.nextBlockId |
| 102 | }) |
| 103 | }); |
| 104 | blocksRef.current[newBlock.parent] = updatedBlock; |
| 105 | blocksRef.current[newBlock.id] = newBlock; |
| 106 | |
| 107 | setBlocksOrder(prevState => [ |
| 108 | rootContent[0], |
| 109 | ...blocksRef.current[rootContent[0]].content |
| 110 | ]); |
| 111 | } |
| 112 | |
| 113 | function insertBlockV2(newBlock: Block, position?: { prevBlockId?: string | undefined, nextBlockId?: string | undefined }) { |
| 114 | const updatedBlock = updateBlockData(blocksRef.current[newBlock.parent], { |
no test coverage detected