( blocks: readonly T[], plan: PlanContentBlock )
| 61 | } |
| 62 | |
| 63 | export function replacePlanDraftWithPlan<T extends BlockWithType>( |
| 64 | blocks: readonly T[], |
| 65 | plan: PlanContentBlock |
| 66 | ): Array<T | PlanContentBlock> { |
| 67 | const nextBlocks = blocks.map(cloneBlock) as Array<T | PlanContentBlock> |
| 68 | for (let index = nextBlocks.length - 1; index >= 0; index--) { |
| 69 | const block = nextBlocks[index] |
| 70 | if (isPlanDraftBlock(block)) { |
| 71 | const displayText = block.text.trim() |
| 72 | nextBlocks[index] = { |
| 73 | ...toPlanContentBlock(plan), |
| 74 | ...(displayText ? { displayText } : {}), |
| 75 | } |
| 76 | return nextBlocks |
| 77 | } |
| 78 | } |
| 79 | nextBlocks.push(toPlanContentBlock(plan)) |
| 80 | return nextBlocks |
| 81 | } |
| 82 | |
| 83 | export function removePlanDraftBlocks<T extends BlockWithType>(blocks: readonly T[]): T[] { |
| 84 | return blocks.filter((block) => block.type !== 'plan_draft').map(cloneBlock) |
no test coverage detected