Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update gallery block fixtures to match with gallery refactor to nested Image Blocks #28481

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
86 commits
Select commit Hold shift + click to select a range
9f148d9
Update Gallery to nested image blocks
Jan 13, 2021
7fa1397
Fix issue with images not loading on first selection from media gallery
Nov 4, 2020
4dbf48f
Remove the default columns setting as we don't have access to innerBl…
Nov 4, 2020
9d21319
Revert "Remove the default columns setting as we don't have access to…
Nov 4, 2020
fe7a91b
Add image count so we can work out default columns as innerBlocks not…
Nov 4, 2020
849f82b
Disable the innerBlocks dropzones so drag drop works same as existing…
Nov 5, 2020
4553dc2
Lint changes
Nov 5, 2020
500b988
Revert "Lint changes"
Nov 6, 2020
540bbbd
Revert "Disable the innerBlocks dropzones so drag drop works same as …
Nov 6, 2020
4a13c9d
Suggested solution for handling multiple file drop into gallery
Nov 6, 2020
bf5f8d9
Remove non image files from drag and drop and disable individual imag…
Jan 21, 2021
f896da9
Fix transform to individual images
Nov 8, 2020
bd06610
Fix transform from individual images
Nov 8, 2020
2dd4930
Revert drag and drop transform changes
Nov 9, 2020
57b7d98
Add gallery transform to image block to override the default gallery …
Nov 9, 2020
990cfb9
Move handling of file uploads to Gallery from media placeholder
Nov 16, 2020
689d7bc
split innerblocks mapping into separate effect to reduce chatter
Nov 17, 2020
c360f72
Add useMemo to currentImageOptions
Nov 17, 2020
9509366
reuse existing innerBlocks rather than recreating with every new imag…
Nov 17, 2020
570c702
Switch to useMemo for updating local image const instead of local com…
Nov 17, 2020
be26af8
Fix issue with image sizing not being available on initial load of co…
Nov 17, 2020
d152935
Memoise the useImageSizes hook
Nov 17, 2020
719b76b
Fix issue with media browser defaulting to edit gallery view
Nov 17, 2020
9fdde07
Fix missed incorrect use of addToGallery
Nov 17, 2020
e657247
Add some extra effects for getting the imageData as the getMedia call…
Nov 18, 2020
537f7da
Simplify the imageData by using a useSelect
Nov 19, 2020
c7de875
Another optimisation - only return a new imageData reference if all i…
Nov 19, 2020
b8fb9e5
Refactored Gallery: Add loading state to gallery image size options (…
aaronrobertshaw Nov 19, 2020
09b7f2b
Initial deprecations commit
Jan 13, 2021
3ee43f1
Fix issue with linkDestination not being applied in migration
Nov 19, 2020
1ae1ba2
Refactor gallery deprecations
aaronrobertshaw Nov 20, 2020
15909d5
Fix missing attributes from migration
aaronrobertshaw Nov 20, 2020
b4fbe2e
Update deprecation to set allowResize
aaronrobertshaw Nov 22, 2020
817a964
Fix issue with crop not working when certain plugins are loaded
Nov 22, 2020
8eed7f4
Fix SCSS lint errors
aaronrobertshaw Nov 22, 2020
b07fe67
Update the block example
Nov 23, 2020
0a325dc
Linting fixes
Nov 23, 2020
2c18948
Fix the e2e test and the accessibility issue with having aria group r…
Nov 23, 2020
37662ca
fix linting issues
Nov 23, 2020
aef6f98
Fix frontend omission of wp-block-image class
aaronrobertshaw Nov 24, 2020
24a9455
change deprecation to use imageCount as isEligible check as it seems …
Nov 25, 2020
e59ea15
Move back to a single deprecations file and reorder in array
Nov 26, 2020
fa8a159
Remove additional check in v5 isEligible
Nov 26, 2020
97849a9
Fix the v4 migration
Nov 26, 2020
5048707
Fix styles for Safari compatibility
aaronrobertshaw Nov 30, 2020
6abf4fe
Remove unnecessary gallery editor styles
aaronrobertshaw Nov 30, 2020
ee6628a
Fix typo in deprecations
aaronrobertshaw Nov 30, 2020
0035221
Restore styles to render deprecated gallery versions
Jan 21, 2021
41c5a27
Avoid applying flex styles to IE11
aaronrobertshaw Dec 1, 2020
5cf7a08
Add additional selector to prevent the hidden individual image drop z…
Dec 1, 2020
c748ce7
IE11 styling improvements
aaronrobertshaw Dec 2, 2020
cb153a1
Apply default style class to new images added to gallery
Dec 11, 2020
a38efbd
fix linting issues
Dec 11, 2020
06dd3d5
Move block props to the outer wrapper
Dec 13, 2020
77d887c
Revert "Move block props to the outer wrapper"
Dec 13, 2020
c2d229c
Revert "Revert "Move block props to the outer wrapper""
Dec 13, 2020
083fc42
Fetch media if isListItem is true
Jan 26, 2021
a392c2a
Change context from isListItem to isGrouped
Jan 26, 2021
8b06149
Remove wrapper div
Jan 21, 2021
260764d
remove extra wrapper around media placeholder and caption and use fle…
Jan 13, 2021
7cbea7a
Revert "remove extra wrapper around media placeholder and caption and…
Jan 13, 2021
55ff08b
Revert "Remove external div wrapper by moving InnerBlocks to a fragment"
Jan 21, 2021
d312f73
another update to image wrapper
Jan 13, 2021
c465a0d
put media uploader outside figure so structure matches front end
Dec 17, 2020
31dcd59
Replace div with View for the sake of native code
Dec 17, 2020
fa5f89b
Move setting of attributes to the child images
Jan 26, 2021
94b9ca2
Gallery Block Refactor: Account for null image ids in gallery migrati…
glendaviesnz Dec 22, 2020
7112959
Remove the gradient and put caption under image if is-rounded style a…
glendaviesnz Dec 24, 2020
11ce2f2
Remove outer div wrapper
Jan 21, 2021
a539edd
Keep image margins while dragging sibling
aaronrobertshaw Jan 14, 2021
34aa703
Fix e2e test expected markup to match new structure
Jan 18, 2021
a731edc
Gallery Block Refactor: Add handling of short code transforms (#28211)
glendaviesnz Jan 19, 2021
dbb1581
Removed unused prop
Jan 20, 2021
33bda1e
Account for undefined block and innerblocks in conversion to reusable…
glendaviesnz Jan 20, 2021
c6d2d0b
Add custom gutter sizes to refactored gallery (#28377)
aaronrobertshaw Jan 21, 2021
bea50ba
Adjust editor styles to match new dom structure
Jan 21, 2021
85428a7
Remove redundant styles that are duplicated in nested image blocks
Jan 21, 2021
a8c3dc6
Fix issue with Image block dragged out of Gallery still having inheri…
Jan 22, 2021
fab3d0e
When dragging an image block into a gallery make sure we don't wipe a…
Jan 25, 2021
5b466d6
fix issue with variable declaration order
Jan 25, 2021
31ce82f
Fix bug with custom link being overwritten by gallery linkTo changes
Jan 26, 2021
9c03251
Fix application of gutter size CSS var (#28759)
aaronrobertshaw Feb 5, 2021
d144d72
Fix mobile width for gallery images
aaronrobertshaw Feb 10, 2021
a0b9e7d
Add missing dependency to inner images selector
aaronrobertshaw Feb 10, 2021
58cf248
Fix all unit tests and block fixtures to match the refactored gallery…
Feb 10, 2021
6af96d3
Fix broken e2e test
Jan 26, 2021
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
56 changes: 17 additions & 39 deletions packages/block-editor/src/components/media-placeholder/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export function MediaPlaceholder( {
isAppender,
accept,
addToGallery,
isGallery = false,
multiple = false,
dropZoneUIOnly,
disableDropZone,
Expand Down Expand Up @@ -117,48 +118,25 @@ export function MediaPlaceholder( {
}
};

const onMediaLibrarySelection = ( files ) => {
if ( isGallery ) {
onSelect( files, true );
return;
}
onSelect( files );
};

const onFilesUpload = ( files ) => {
if ( isGallery ) {
// Because the Gallery hands the files over to Image component InnerBlocks just
// hand the handling of the files over to the Gallery
onSelect( files );
return;
}
onFilesPreUpload( files );
let setMedia;
if ( multiple ) {
if ( addToGallery ) {
// Since the setMedia function runs multiple times per upload group
// and is passed newMedia containing every item in its group each time, we must
// filter out whatever this upload group had previously returned to the
// gallery before adding and returning the image array with replacement newMedia
// values.

// Define an array to store urls from newMedia between subsequent function calls.
let lastMediaPassed = [];
setMedia = ( newMedia ) => {
// Remove any images this upload group is responsible for (lastMediaPassed).
// Their replacements are contained in newMedia.
const filteredMedia = ( value ?? [] ).filter( ( item ) => {
// If Item has id, only remove it if lastMediaPassed has an item with that id.
if ( item.id ) {
return ! lastMediaPassed.some(
// Be sure to convert to number for comparison.
( { id } ) => Number( id ) === Number( item.id )
);
}
// Compare transient images via .includes since gallery may append extra info onto the url.
return ! lastMediaPassed.some( ( { urlSlug } ) =>
item.url.includes( urlSlug )
);
} );
// Return the filtered media array along with newMedia.
onSelect( filteredMedia.concat( newMedia ) );
// Reset lastMediaPassed and set it with ids and urls from newMedia.
lastMediaPassed = newMedia.map( ( media ) => {
// Add everything up to '.fileType' to compare via .includes.
const cutOffIndex = media.url.lastIndexOf( '.' );
const urlSlug = media.url.slice( 0, cutOffIndex );
return { id: media.id, urlSlug };
} );
};
} else {
setMedia = onSelect;
}
setMedia = onSelect;
} else {
setMedia = ( [ media ] ) => onSelect( media );
}
Expand Down Expand Up @@ -306,7 +284,7 @@ export function MediaPlaceholder( {
addToGallery={ addToGallery }
gallery={ multiple && onlyAllowsImages() }
multiple={ multiple }
onSelect={ onSelect }
onSelect={ onMediaLibrarySelection }
allowedTypes={ allowedTypes }
value={
Array.isArray( value )
Expand Down
76 changes: 32 additions & 44 deletions packages/block-library/src/gallery/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,56 +3,19 @@
"name": "core/gallery",
"category": "media",
"attributes": {
"images": {
"imageUploads": {
"type": "array",
"default": [],
"source": "query",
"selector": ".blocks-gallery-item",
"query": {
"url": {
"type": "string",
"source": "attribute",
"selector": "img",
"attribute": "src"
},
"fullUrl": {
"type": "string",
"source": "attribute",
"selector": "img",
"attribute": "data-full-url"
},
"link": {
"type": "string",
"source": "attribute",
"selector": "img",
"attribute": "data-link"
},
"alt": {
"type": "string",
"source": "attribute",
"selector": "img",
"attribute": "alt",
"default": ""
},
"id": {
"type": "string",
"source": "attribute",
"selector": "img",
"attribute": "data-id"
},
"caption": {
"type": "string",
"source": "html",
"selector": ".blocks-gallery-item__caption"
}
"items": {
"type": "object"
}
},
"ids": {
"shortCodeTransforms": {
"type": "array",
"default": [],
"items": {
"type": "number"
},
"default": []
"type": "object"
}
},
"columns": {
"type": "number",
Expand All @@ -68,14 +31,39 @@
"type": "boolean",
"default": true
},
"linkTarget": {
"type": "string"
},
"linkTo": {
"type": "string"
},
"sizeSlug": {
"type": "string",
"default": "large"
},
"allowResize": {
"type": "boolean",
"default": false
},
"isGrouped": {
"type": "boolean",
"default": true
},
"imageCount": {
"type": "number",
"default": 0
},
"gutterSize": {
"type": "number"
}
},
"providesContext": {
"allowResize": "allowResize",
"isGrouped": "isGrouped",
"linkTo": "linkTo",
"linkTarget": "linkTarget",
"sizeSlug": "sizeSlug"
},
"supports": {
"anchor": true,
"align": true
Expand Down
4 changes: 2 additions & 2 deletions packages/block-library/src/gallery/constants.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export const LINK_DESTINATION_NONE = 'none';
export const LINK_DESTINATION_MEDIA = 'file';
export const LINK_DESTINATION_ATTACHMENT = 'post';
export const LINK_DESTINATION_MEDIA = 'media';
export const LINK_DESTINATION_ATTACHMENT = 'attachment';
Loading