Skip to content

Commit 5c09774

Browse files
picker refactor
1 parent c473fbe commit 5c09774

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

docs/reference/deprecated.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ Gutenberg's deprecation policy is intended to support backwards-compatibility fo
2222
- `getMetaBoxes` selector (`core/edit-post`) has been removed. Use `getActiveMetaBoxLocations` selector (`core/edit-post`) instead.
2323
- `getMetaBox` selector (`core/edit-post`) has been removed. Use `isMetaBoxLocationActive` selector (`core/edit-post`) instead.
2424
- Attribute type coercion has been removed. Omit the source to preserve type via serialized comment demarcation.
25+
- `mediaDetails` in object passed to `onFileChange` callback of `wp.editor.mediaUpload`. Please use `media_details` property instead.
2526

2627
## 4.1.0
2728

packages/block-library/src/gallery/edit.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,10 @@ export function defaultColumnsNumber( attributes ) {
4444
return Math.min( 3, attributes.images.length );
4545
}
4646

47-
export const RELEVANT_MEDIA_FIELDS = [ 'alt', 'caption', 'id', 'link', 'url' ];
47+
const RELEVANT_MEDIA_FIELDS = [ 'alt', 'caption', 'id', 'link', 'url' ];
48+
export const pickRelevantMediaFiles = ( image ) => {
49+
return pick( image, RELEVANT_MEDIA_FIELDS );
50+
};
4851

4952
class GalleryEdit extends Component {
5053
constructor() {
@@ -89,7 +92,7 @@ class GalleryEdit extends Component {
8992

9093
onSelectImages( images ) {
9194
this.props.setAttributes( {
92-
images: images.map( ( image ) => pick( image, RELEVANT_MEDIA_FIELDS ) ),
95+
images: images.map( ( image ) => pickRelevantMediaFiles( image ) ),
9396
} );
9497
}
9598

@@ -137,7 +140,7 @@ class GalleryEdit extends Component {
137140
allowedTypes: ALLOWED_MEDIA_TYPES,
138141
filesList: files,
139142
onFileChange: ( images ) => {
140-
const imagesNormalized = images.map( ( image ) => pick( image, RELEVANT_MEDIA_FIELDS ) );
143+
const imagesNormalized = images.map( ( image ) => pickRelevantMediaFiles( image ) );
141144
setAttributes( {
142145
images: currentImages.concat( imagesNormalized ),
143146
} );

packages/block-library/src/gallery/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* External dependencies
33
*/
4-
import { filter, every, pick } from 'lodash';
4+
import { filter, every } from 'lodash';
55

66
/**
77
* WordPress dependencies
@@ -14,7 +14,7 @@ import { createBlobURL } from '@wordpress/blob';
1414
/**
1515
* Internal dependencies
1616
*/
17-
import { default as edit, defaultColumnsNumber, RELEVANT_MEDIA_FIELDS } from './edit';
17+
import { default as edit, defaultColumnsNumber, pickRelevantMediaFiles } from './edit';
1818

1919
const blockAttributes = {
2020
images: {
@@ -135,7 +135,7 @@ export const settings = {
135135
mediaUpload( {
136136
filesList: files,
137137
onFileChange: ( images ) => onChange( block.clientId, {
138-
images: images.map( ( image ) => pick( image, RELEVANT_MEDIA_FIELDS ) ),
138+
images: images.map( ( image ) => pickRelevantMediaFiles( image ) ),
139139
} ),
140140
allowedTypes: [ 'image' ],
141141
} );

0 commit comments

Comments
 (0)