* Creates an updated block with new collapsed state if different from current. * Returns null if no change is needed. * Thinking blocks use thinkingCollapseState; others use isCollapsed.
( block: CollapsibleBlock, collapsed: boolean, )
| 63 | * Thinking blocks use thinkingCollapseState; others use isCollapsed. |
| 64 | */ |
| 65 | function createUpdatedBlock( |
| 66 | block: CollapsibleBlock, |
| 67 | collapsed: boolean, |
| 68 | ): CollapsibleBlock | null { |
| 69 | if (isThinkingTextBlock(block)) { |
| 70 | const targetState: ThinkingCollapseState = collapsed ? 'hidden' : 'expanded' |
| 71 | if (block.thinkingCollapseState === targetState) { |
| 72 | return null |
| 73 | } |
| 74 | return { |
| 75 | ...block, |
| 76 | thinkingCollapseState: targetState, |
| 77 | userOpened: !collapsed ? true : block.userOpened, |
| 78 | } |
| 79 | } |
| 80 | const currentCollapsed = getBlockCollapsedState(block) |
| 81 | if (currentCollapsed === collapsed) { |
| 82 | return null |
| 83 | } |
| 84 | return { |
| 85 | ...block, |
| 86 | isCollapsed: collapsed, |
| 87 | userOpened: !collapsed ? true : block.userOpened, |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | /** |
| 92 | * Checks if any collapsible block in the given blocks array is expanded. |
no test coverage detected