utils.js
32 lines
| 1 | export function updateUniqueIds( blocks ) { |
| 2 | return blocks.map( ( block ) => { |
| 3 | // Check if the block has a uniqueId attribute |
| 4 | if ( block.attributes && block.attributes.uniqueId ) { |
| 5 | // Generate a new uniqueId |
| 6 | const newUniqueId = block.clientId.substr( 2, 9 ).replace( '-', '' ); |
| 7 | |
| 8 | // Update the block's uniqueId attribute |
| 9 | block.attributes.uniqueId = newUniqueId; |
| 10 | } |
| 11 | // Recursively update uniqueIds for innerBlocks if they exist |
| 12 | if ( block.innerBlocks && block.innerBlocks.length > 0 ) { |
| 13 | block.innerBlocks = updateUniqueIds( block.innerBlocks ); |
| 14 | } |
| 15 | return block; |
| 16 | } ); |
| 17 | } |
| 18 | |
| 19 | export function isEmptyContentBlock( selectedBlock ) { |
| 20 | if ( 'core/paragraph' === selectedBlock?.name ) { |
| 21 | const currentContent = selectedBlock?.attributes?.content; |
| 22 | |
| 23 | if ( 'string' === typeof currentContent ) { |
| 24 | return ! currentContent.trim(); |
| 25 | } else if ( 'object' === typeof currentContent ) { |
| 26 | return ! currentContent?.text.trim(); |
| 27 | } |
| 28 | } |
| 29 | |
| 30 | return false; |
| 31 | } |
| 32 |