Skip to content

Commit

Permalink
fix content loss
Browse files Browse the repository at this point in the history
  • Loading branch information
ellatrix committed Aug 15, 2024
1 parent 2fdd3cb commit 67b563a
Showing 1 changed file with 27 additions and 15 deletions.
42 changes: 27 additions & 15 deletions packages/block-library/src/media-text/transforms.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,25 @@
*/
import { createBlock } from '@wordpress/blocks';

function transform(
{ mediaType, mediaPosition, mediaAlt, mediaId, mediaUrl, anchor },
innerBlocks
) {
const output = [ ...innerBlocks ];
if ( mediaType ) {
const action = mediaPosition === 'right' ? 'push' : 'unshift';
output[ action ](
createBlock( `core/${ mediaType }`, {
alt: mediaAlt,
id: mediaId,
url: mediaUrl,
anchor,
} )
);
}
return output;
}

const transforms = {
from: [
{
Expand Down Expand Up @@ -102,26 +121,19 @@ const transforms = {
type: 'block',
blocks: [ 'core/image' ],
isMatch: ( { mediaType } ) => mediaType === 'image',
transform: ( { mediaAlt, mediaId, mediaUrl, anchor } ) => {
return createBlock( 'core/image', {
alt: mediaAlt,
id: mediaId,
url: mediaUrl,
anchor,
} );
},
transform,
},
{
type: 'block',
blocks: [ 'core/video' ],
isMatch: ( { mediaType } ) => mediaType === 'video',
transform: ( { mediaId, mediaUrl, anchor } ) => {
return createBlock( 'core/video', {
id: mediaId,
src: mediaUrl,
anchor,
} );
},
transform,
},
{
type: 'block',
// To do: ideally this should be '*', and quote should also use '*'.
blocks: [ 'core/paragraph' ],
transform,
},
{
type: 'block',
Expand Down

0 comments on commit 67b563a

Please sign in to comment.