( subBlocks: Record<string, SubBlockState>, subBlockValues: Record<string, unknown>, oldBlockId: string, newBlockId: string )
| 420 | * Mutates both `subBlocks` and `subBlockValues` in place (callers must pass cloned data). |
| 421 | */ |
| 422 | export function remapConditionIds( |
| 423 | subBlocks: Record<string, SubBlockState>, |
| 424 | subBlockValues: Record<string, unknown>, |
| 425 | oldBlockId: string, |
| 426 | newBlockId: string |
| 427 | ): void { |
| 428 | for (const [subBlockId, subBlock] of Object.entries(subBlocks)) { |
| 429 | if (subBlock.type !== 'condition-input' && subBlock.type !== 'router-input') continue |
| 430 | |
| 431 | const value = subBlockValues[subBlockId] ?? subBlock.value |
| 432 | if (typeof value !== 'string') continue |
| 433 | |
| 434 | try { |
| 435 | const parsed = JSON.parse(value) |
| 436 | if (!Array.isArray(parsed)) continue |
| 437 | |
| 438 | if (remapConditionBlockIds(parsed, oldBlockId, newBlockId)) { |
| 439 | const newValue = JSON.stringify(parsed) |
| 440 | subBlock.value = newValue |
| 441 | subBlockValues[subBlockId] = newValue |
| 442 | } |
| 443 | } catch { |
| 444 | // Not valid JSON, skip |
| 445 | } |
| 446 | } |
| 447 | } |
| 448 | |
| 449 | export function regenerateBlockIds( |
| 450 | blocks: Record<string, BlockState>, |
no test coverage detected