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

Masonry block use inner core/image blocks #2117

Merged
merged 63 commits into from
Dec 7, 2021
Merged
Show file tree
Hide file tree
Changes from 59 commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
d708c33
try some major mods
AnthonyLedesma Oct 14, 2021
64410c9
more gallery refactors
AnthonyLedesma Oct 19, 2021
9c59c30
Merge branch 'master' into try/masonry-grid
AnthonyLedesma Oct 21, 2021
3a854a9
tweak a few styles
AnthonyLedesma Oct 21, 2021
77ddbd5
Merge branch 'master' into try/masonry-grid
AnthonyLedesma Oct 25, 2021
591872e
tweak block styles
AnthonyLedesma Oct 26, 2021
c4fc6f8
not sure why this broke
AnthonyLedesma Oct 26, 2021
b55d4d9
Merge branch 'master' into try/masonry-grid
AnthonyLedesma Oct 26, 2021
71dcd7b
apply lint fixes
AnthonyLedesma Oct 28, 2021
e3c174d
working on save.js
AnthonyLedesma Oct 29, 2021
62f26a2
fix save styles
AnthonyLedesma Oct 29, 2021
eca907c
fix editor and front-end styles
AnthonyLedesma Oct 29, 2021
544c772
enhance caption style
AnthonyLedesma Nov 2, 2021
c6d2d8e
allow gutter in masonry
AnthonyLedesma Nov 2, 2021
180d0e7
revert package updates
AnthonyLedesma Nov 2, 2021
411a104
Merge branch 'master' into try/masonry-grid
AnthonyLedesma Nov 2, 2021
23ddacf
update deprecated attribute array
AnthonyLedesma Nov 2, 2021
ab45ee3
add gutter styles
AnthonyLedesma Nov 3, 2021
ef5bc9a
merge master
olafleur-godaddy Nov 4, 2021
e59a113
Remove linting errors
olafleur-godaddy Nov 4, 2021
cff39b0
fix gutter application
AnthonyLedesma Nov 9, 2021
c62e0be
fix captions on front-end
AnthonyLedesma Nov 10, 2021
31ca2cb
Merge branch 'master' into try/masonry-grid
AnthonyLedesma Nov 10, 2021
b2dc6b1
Merge branch 'master' into try/masonry-grid
AnthonyLedesma Nov 11, 2021
a2b7c66
preserve blockProps
AnthonyLedesma Nov 11, 2021
fcf5e5e
fix lightbox controls and script
AnthonyLedesma Nov 11, 2021
917681b
fix captions from library
AnthonyLedesma Nov 11, 2021
748f709
masonry fixes
AnthonyLedesma Nov 15, 2021
f264006
Merge branch 'master' into try/masonry-grid
olafleur-godaddy Nov 16, 2021
9083fb6
Merge branch 'master' into try/masonry-grid
AnthonyLedesma Nov 16, 2021
d516e12
fix deprecation from master
AnthonyLedesma Nov 17, 2021
a430d2a
backward compat to 5.5
AnthonyLedesma Nov 17, 2021
29363c2
fix deprecations
AnthonyLedesma Nov 18, 2021
dc8de42
fix save.spec and radius
AnthonyLedesma Nov 19, 2021
75621bb
fix image media details fetch errors
AnthonyLedesma Nov 19, 2021
f536895
fix transforms
AnthonyLedesma Nov 22, 2021
a22b5cc
fix transforms to other galleries
AnthonyLedesma Nov 23, 2021
e22c1b9
Merge branch 'master' into try/masonry-grid
AnthonyLedesma Nov 23, 2021
90c4026
lint fixes
AnthonyLedesma Nov 23, 2021
235c956
add cypress tests
AnthonyLedesma Nov 23, 2021
57f999b
revert block-editor update
AnthonyLedesma Nov 23, 2021
e295cf8
keep block-editor updates
AnthonyLedesma Nov 23, 2021
88ec240
remove proptypes assertions & fix gutter custom defaults
AnthonyLedesma Nov 23, 2021
9a0ef3d
update form snapshot
AnthonyLedesma Nov 23, 2021
83e67c1
Merge branch 'master' into try/masonry-grid
olafleur-godaddy Nov 25, 2021
8b1e200
re-add media-filter controls to masonry gallery
AnthonyLedesma Nov 29, 2021
b007b4f
remove shortcode transform logic and fix image filter controls
AnthonyLedesma Nov 30, 2021
ab8f0b8
Merge branch 'master' into try/masonry-grid
olafleur-godaddy Nov 30, 2021
1078991
fix image-filter class application
AnthonyLedesma Nov 30, 2021
dd64129
even more changes to media-filter
AnthonyLedesma Nov 30, 2021
86f1aba
ensure that blocks deprecate when they used old style media-filtes
AnthonyLedesma Nov 30, 2021
e934661
correct offset deprecation for media-filters
AnthonyLedesma Nov 30, 2021
3f30109
fixes to media-filters logic
AnthonyLedesma Dec 1, 2021
7210899
revert 86f1aba4841328b53a84ea4feb5a9455701aa3af
AnthonyLedesma Dec 1, 2021
f409afb
jest test image-filter class application
AnthonyLedesma Dec 1, 2021
00fda8b
add media-filter snapshots
AnthonyLedesma Dec 1, 2021
9a5d867
properly migrate old attributes when deprecating
AnthonyLedesma Dec 1, 2021
60017b6
allow class application to image and gallery blocks
AnthonyLedesma Dec 1, 2021
9c60ffc
Merge branch 'master' into try/masonry-grid
olafleur-godaddy Dec 2, 2021
c3f6d56
add comment about duplicate styles
AnthonyLedesma Dec 7, 2021
b13a3cd
fix stacked jest test
AnthonyLedesma Dec 7, 2021
df4597a
formatting fixes to address feedback
AnthonyLedesma Dec 7, 2021
06c235d
more formatting for feedback
AnthonyLedesma Dec 7, 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
8 changes: 0 additions & 8 deletions .babelrc

This file was deleted.

8 changes: 8 additions & 0 deletions babel.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"presets": [
"@wordpress/babel-preset-default"
],
"plugins": [
"@babel/plugin-proposal-class-properties"
]
}
AnthonyLedesma marked this conversation as resolved.
Show resolved Hide resolved
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
"@wordpress/api-fetch": "^5.2.4",
"@wordpress/base-styles": "^4.0.2",
"@wordpress/blob": "^3.2.1",
"@wordpress/block-editor": "^7.0.4",
"@wordpress/block-editor": "8.0.1",
"@wordpress/block-library": "^6.0.2",
"@wordpress/blocks": "^11.1.2",
"@wordpress/components": "^19.0.0",
Expand All @@ -108,7 +108,9 @@
"@wordpress/jest-preset-default": "^7.1.2",
"@wordpress/jest-puppeteer-axe": "^3.1.0",
"@wordpress/keycodes": "^3.2.3",
"@wordpress/notices": "^3.2.5",
"@wordpress/plugins": "^4.0.4",
"@wordpress/primitives": "^3.0.3",
"@wordpress/rich-text": "^5.0.4",
"@wordpress/scripts": "^19.0.0",
"@wordpress/server-side-render": "^3.0.4",
Expand Down
6 changes: 5 additions & 1 deletion src/blocks/form/test/__snapshots__/save.spec.js.snap
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`coblocks/form should render with form details 1`] = `"<!-- wp:coblocks/form {\\"subject\\":\\"Form subject\\",\\"to\\":\\"Form to text\\"} /-->"`;
exports[`coblocks/form should render with form details 1`] = `
"<!-- wp:coblocks/form {\\"subject\\":\\"Form subject\\",\\"to\\":\\"Form to text\\"} -->
<div class=\\"wp-block-coblocks-form\\"></div>
<!-- /wp:coblocks/form -->"
`;
20 changes: 12 additions & 8 deletions src/blocks/gallery-carousel/test/transforms.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ describe( 'coblocks/gallery-carousel transforms', () => {
{ index: 0, url: 'https://s.w.org/images/core/5.3/Windbuchencom.jpg' },
{ index: 1, url: 'https://s.w.org/images/core/5.3/Glacial_lakes,_Bhutan.jpg' },
] };

const innerBlocks = [
createBlock( 'core/image', attributes.images[0], [] ),
createBlock( 'core/image', attributes.images[1], [] )
];

beforeAll( () => {
// Register all gallery blocks.
Expand All @@ -38,7 +43,7 @@ describe( 'coblocks/gallery-carousel transforms', () => {
} );

it( 'should transform from coblocks/gallery-masonry block', () => {
const galleryMasonry = createBlock( 'coblocks/gallery-masonry', attributes );
const galleryMasonry = createBlock( 'coblocks/gallery-masonry', {}, innerBlocks );
const transformed = switchToBlockType( galleryMasonry, name );

expect( transformed[ 0 ].isValid ).toBe( true );
Expand Down Expand Up @@ -93,7 +98,7 @@ describe( 'coblocks/gallery-carousel transforms', () => {
} );

it( 'should transform from core/image block only if match', () => {
expect( transforms.from[ 1 ].isMatch( [ { id: 1234, url: 'someUrl' }, { id: "1234", url: 'someUrl' } ] ) ).toHaveLength( 1 );
expect( transforms.from[ 2 ].isMatch( [ { id: 1234, url: 'someUrl' }, { id: "1234", url: 'someUrl' } ] ) ).toHaveLength( 1 );
} );

it( 'should transform to coblocks/gallery-stacked block', () => {
Expand All @@ -109,13 +114,12 @@ describe( 'coblocks/gallery-carousel transforms', () => {

it( 'should transform to coblocks/gallery-masonry block', () => {
const block = createBlock( name, attributes );
const transformed = switchToBlockType( block, 'coblocks/gallery-masonry' );
const transformed = switchToBlockType( block, 'coblocks/gallery-masonry' )[ 0 ];

expect( transformed[ 0 ].isValid ).toBe( true );
for ( let i = 0; i < attributes.images.length; i++ ) {
expect( transformed[ 0 ].attributes.images[ i ].index ).toBe( attributes.images[ i ].index );
expect( transformed[ 0 ].attributes.images[ i ].url ).toBe( attributes.images[ i ].url );
}
expect( transformed.isValid ).toBe( true );
transformed.innerBlocks.forEach( ( image, index ) => {
expect( image.attributes.url ).toBe( attributes.images[ index ].url );
} );
} );

it( 'should transform to coblocks/gallery-offset block', () => {
Expand Down
33 changes: 25 additions & 8 deletions src/blocks/gallery-carousel/transforms.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import pick from 'lodash/pick';
/**
* Internal dependencies
*/
import metadata from './block.json';
import { GalleryTransforms } from '../../components/block-gallery/shared';
import metadata from './block.json';

/**
* WordPress dependencies
Expand All @@ -18,10 +18,8 @@ import { createBlock } from '@wordpress/blocks';
const transforms = {
from: [
{
type: 'block',
blocks: [
'coblocks/gallery-collage',
'coblocks/gallery-masonry',
'coblocks/gallery-stacked',
'coblocks/gallery-offset',
'core/gallery',
Expand All @@ -32,36 +30,55 @@ const transforms = {
gridSize: 'lrg',
} )
),
type: 'block',
},
{
blocks: [ 'coblocks/gallery-masonry' ],
transform: ( attributes, innerBlocks ) => {
const validImages = innerBlocks.map( ( block, index ) => {
const imageBlockAttributes = block.attributes;
return {
alt: imageBlockAttributes?.alt,
caption: imageBlockAttributes?.caption,
id: imageBlockAttributes?.id,
index,
url: imageBlockAttributes?.url,
};
} );
return createBlock( metadata.name, { images: validImages }, [] );
},
type: 'block',
isMultiBlock: true,
},
{
blocks: [ 'core/image' ],
isMatch: ( content ) => filter( content, ( { id, url } ) => Number.isInteger( id ) && url ),
isMultiBlock: true,
transform: ( content ) =>
createBlock( metadata.name, {
images: content.map( ( attributes, index ) => ( { ...pick( attributes, [ 'id', 'url', 'alt', 'caption' ] ), index } ) ),
ids: content.map( ( { id } ) => id ),
captions: !! filter( content, ( { caption } ) => !! caption ),
ids: content.map( ( { id } ) => id ),
images: content.map( ( attributes, index ) => ( { ...pick( attributes, [ 'id', 'url', 'alt', 'caption' ] ), index } ) ),
} ),
type: 'block',

},
{
type: 'prefix',
prefix: ':carousel',
transform( content ) {
return createBlock( metadata.name, {
content,
} );
},
type: 'prefix',
},
],
to: [
{
type: 'block',
blocks: [ 'core/gallery' ],
transform: ( attributes ) => createBlock( 'core/gallery', {
...GalleryTransforms( attributes ),
} ),
type: 'block',
},
],
};
Expand Down
Loading