* Extract images from ContentBlockParam[] and convert to PastedContent format. * Returns empty array for string values or if no images found.
( value: string | ContentBlockParam[], startId: number, )
| 388 | * Returns empty array for string values or if no images found. |
| 389 | */ |
| 390 | function extractImagesFromValue( |
| 391 | value: string | ContentBlockParam[], |
| 392 | startId: number, |
| 393 | ): PastedContent[] { |
| 394 | if (typeof value === 'string') { |
| 395 | return [] |
| 396 | } |
| 397 | |
| 398 | const images: PastedContent[] = [] |
| 399 | let imageIndex = 0 |
| 400 | for (const block of value) { |
| 401 | if (block.type === 'image' && block.source.type === 'base64') { |
| 402 | images.push({ |
| 403 | id: startId + imageIndex, |
| 404 | type: 'image', |
| 405 | content: block.source.data, |
| 406 | mediaType: block.source.media_type, |
| 407 | filename: `image${imageIndex + 1}`, |
| 408 | }) |
| 409 | imageIndex++ |
| 410 | } |
| 411 | } |
| 412 | return images |
| 413 | } |
| 414 | |
| 415 | export type PopAllEditableResult = { |
| 416 | text: string |