* Find a block by ID or ID prefix. Returns the block or undefined.
(blocks: DeepnoteBlock[], idOrPrefix: string)
| 15 | * Find a block by ID or ID prefix. Returns the block or undefined. |
| 16 | */ |
| 17 | function findBlock(blocks: DeepnoteBlock[], idOrPrefix: string): DeepnoteBlock | undefined { |
| 18 | const matches = blocks.filter(b => b.id === idOrPrefix || b.id.startsWith(idOrPrefix)) |
| 19 | if (matches.length > 1) { |
| 20 | throw new Error(`Ambiguous block ID prefix "${idOrPrefix}" matches multiple blocks`) |
| 21 | } |
| 22 | return matches[0] |
| 23 | } |
| 24 | |
| 25 | /** |
| 26 | * Find a block index by ID or ID prefix. Returns -1 if not found. |