Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix conflict
  • Loading branch information
Glen Davies committed Oct 7, 2020
commit d0fec8504766bdee5a946ec63d06507394216e74
4 changes: 3 additions & 1 deletion packages/block-library/src/gallery/deprecated.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {

const deprecated = [


// {
// attributes: {
// images: {
Expand Down Expand Up @@ -517,6 +518,7 @@ const deprecated = [
// },
// },

//];
];


export default deprecated;
102 changes: 8 additions & 94 deletions packages/block-library/src/gallery/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,10 @@ class GalleryEdit extends Component {
constructor() {
super( ...arguments );

this.onSelectImage = this.onSelectImage.bind( this );
this.onSelectImages = this.onSelectImages.bind( this );
this.onDeselectImage = this.onDeselectImage.bind( this );
this.setLinkTo = this.setLinkTo.bind( this );
this.setColumnsNumber = this.setColumnsNumber.bind( this );
this.toggleImageCrop = this.toggleImageCrop.bind( this );
this.onMove = this.onMove.bind( this );
this.onMoveForward = this.onMoveForward.bind( this );
this.onMoveBackward = this.onMoveBackward.bind( this );
this.onRemoveImage = this.onRemoveImage.bind( this );
this.onUploadError = this.onUploadError.bind( this );
this.setImageAttributes = this.setImageAttributes.bind( this );
Expand Down Expand Up @@ -111,52 +106,6 @@ class GalleryEdit extends Component {
this.props.setAttributes( attributes );
}

onSelectImage( index ) {
return () => {
if ( this.state.selectedImage !== index ) {
this.setState( {
selectedImage: index,
} );
}
};
}

onDeselectImage( index ) {
return () => {
if ( this.state.selectedImage === index ) {
this.setState( {
selectedImage: null,
} );
}
};
}

onMove( oldIndex, newIndex ) {
const images = [ ...this.props.attributes.images ];
images.splice( newIndex, 1, this.props.attributes.images[ oldIndex ] );
images.splice( oldIndex, 1, this.props.attributes.images[ newIndex ] );
this.setState( { selectedImage: newIndex } );
this.setAttributes( { images } );
}

onMoveForward( oldIndex ) {
return () => {
if ( oldIndex === this.props.attributes.images.length - 1 ) {
return;
}
this.onMove( oldIndex, oldIndex + 1 );
};
}

onMoveBackward( oldIndex ) {
return () => {
if ( oldIndex === 0 ) {
return;
}
this.onMove( oldIndex, oldIndex - 1 );
};
}

onRemoveImage( index ) {
return () => {
const images = filter(
Expand All @@ -172,51 +121,21 @@ class GalleryEdit extends Component {
};
}

selectCaption( newImage, images, attachmentCaptions ) {
// The image id in both the images and attachmentCaptions arrays is a
// string, so ensure comparison works correctly by converting the
// newImage.id to a string.
const newImageId = toString( newImage.id );
const currentImage = find( images, { id: newImageId } );

const currentImageCaption = currentImage
? currentImage.caption
: newImage.caption;

if ( ! attachmentCaptions ) {
return currentImageCaption;
}

const attachment = find( attachmentCaptions, {
id: newImageId,
} );

// if the attachment caption is updated
if ( attachment && attachment.caption !== newImage.caption ) {
return newImage.caption;
}

return currentImageCaption;
}

onSelectImages( newImages ) {
const { clientId, insertBlocks } = this.props;
const { columns, images, sizeSlug, linkTo } = this.props.attributes;

const newBlocks = newImages.map( ( image ) => {
return createBlock( 'core/image', {
id: image.id,
caption: image.caption,
url: image.url,
link: image.link,
linkDestination: linkTo,
alt: image.alt,
} );
} );
const { columns, images, sizeSlug } = this.props.attributes;
const { attachmentCaptions } = this.state;
this.setState( {
attachmentCaptions: newImages.map( ( newImage ) => ( {
// Store the attachmentCaption id as a string for consistency
// with the type of the id in the images attribute.
id: toString( newImage.id ),
caption: newImage.caption,
} ) ),
} );

this.setAttributes( {
images: newImages.map( ( newImage ) => ( {
...pickRelevantMediaFiles( newImage, sizeSlug ),
Expand All @@ -232,6 +151,7 @@ class GalleryEdit extends Component {
} ) ),
columns: columns ? Math.min( newImages.length, columns ) : columns,
} );

insertBlocks( newBlocks, 0, clientId );
}

Expand Down Expand Up @@ -259,12 +179,6 @@ class GalleryEdit extends Component {
: __( 'Thumbnails are not cropped.' );
}

onFocusGalleryCaption() {
this.setState( {
selectedImage: null,
} );
}

setImageAttributes( index, attributes ) {
const {
attributes: { images },
Expand Down
2 changes: 1 addition & 1 deletion packages/block-library/src/gallery/shared.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import { get, pick } from 'lodash';

export function defaultColumnsNumber( attributes ) {
return Math.min( 3, attributes.images.length );
return Math.min( 3, attributes.ids.length );
}

export const pickRelevantMediaFiles = ( image, sizeSlug = 'large' ) => {
Expand Down