-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor embed block to single block with block variations (#24090)
* add embed variations + blocks.json * remove core-embeds * minor refactorings * add block attributes * add deprecated + save files * remove settings file and change utils * index + edit draft * add responsive false to unknown embeds * add save function * get className from attributes * use `useSelect` and `useDispatch` hooks * remove common prop from attributes * minor changes * convert supports to scope in variations * Inline the handleIncomingPreview effect * add getEmbedInfoByProvider unit tests * add getEmbedInfoByProvider jsdoc * fix variable typo Co-authored-by: Miguel Fonseca <[email protected]> * small util refactorings * change utils * change findMoreSuitableBlock tests * use state variable for mergedAttributes * small changes * change responsive default attribute * change default value of responsive Co-authored-by: Miguel Fonseca <[email protected]> * change getEmbedInfoByProvider to just search variations * fix block test * add check for registered default embed block + tests * add support for old embed blocks * support deprecated transforms in parser * support deprecated transforms in parser * fix full-content tests * revert previewAttributes handling react lifecycle doesn't play well with the previous change - using megedAttributes as a local state var * fix e2e tests * fix unit tests * change all references to old core-embed block * add snapshots to e2e tests * enhance WP embed block matching with WP_EMBED_TYPE * remove snapshot with publish post * add responsive attribute to demo vimeo block * fix typo * add responsive attribute in old embed blocks in parser * try to limit BlockTypesList with prop * review feedback + tests * review feedback * indentation change to tabs * fix e2e snapshots after adding the `wp-block-embed-{provider}` class * minor refactor Co-authored-by: Miguel Fonseca <[email protected]>
- Loading branch information
1 parent
665a260
commit 0259002
Showing
36 changed files
with
1,236 additions
and
1,060 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
packages/block-editor/src/components/inserter/test/utils.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/** | ||
* Internal dependencies | ||
*/ | ||
import { | ||
moreItem, | ||
paragraphItem, | ||
someOtherItem, | ||
withVariationsItem, | ||
withSingleVariationItem, | ||
} from './fixtures'; | ||
import { includeVariationsInInserterItems } from '../utils'; | ||
|
||
describe( 'inserter utils', () => { | ||
describe( 'includeVariationsInInserterItems', () => { | ||
it( 'should return items if limit is equal to items length', () => { | ||
const items = [ moreItem, paragraphItem, someOtherItem ]; | ||
const res = includeVariationsInInserterItems( items, 3 ); | ||
expect( res ).toEqual( items ); | ||
} ); | ||
it( 'should slice items if items are more than provided limit', () => { | ||
const items = [ | ||
moreItem, | ||
paragraphItem, | ||
someOtherItem, | ||
withVariationsItem, | ||
]; | ||
const res = includeVariationsInInserterItems( items, 2 ); | ||
expect( res ).toEqual( [ moreItem, paragraphItem ] ); | ||
} ); | ||
it( 'should return proper result if no limit provided and block variations do NOT exist', () => { | ||
const items = [ moreItem, paragraphItem, someOtherItem ]; | ||
const res = includeVariationsInInserterItems( items ); | ||
expect( res ).toEqual( items ); | ||
} ); | ||
it( 'should return proper result if no limit provided and block variations exist', () => { | ||
const items = [ | ||
moreItem, | ||
paragraphItem, | ||
someOtherItem, | ||
withSingleVariationItem, | ||
]; | ||
const expected = [ | ||
...items, | ||
{ | ||
...withSingleVariationItem, | ||
id: 'core/embed-youtube', | ||
title: 'YouTube', | ||
description: 'youtube description', | ||
}, | ||
]; | ||
const res = includeVariationsInInserterItems( items ); | ||
expect( res ).toEqual( expected ); | ||
} ); | ||
} ); | ||
} ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
{ | ||
"name": "core/embed", | ||
"category": "embed", | ||
"attributes": { | ||
"url": { | ||
"type": "string" | ||
}, | ||
"caption": { | ||
"type": "string", | ||
"source": "html", | ||
"selector": "figcaption" | ||
}, | ||
"type": { | ||
"type": "string" | ||
}, | ||
"providerNameSlug": { | ||
"type": "string" | ||
}, | ||
"allowResponsive": { | ||
"type": "boolean", | ||
"default": true | ||
}, | ||
"responsive": { | ||
"type": "boolean", | ||
"default": false | ||
}, | ||
"previewable": { | ||
"type": "boolean", | ||
"default": true | ||
} | ||
}, | ||
"supports": { | ||
"align": true, | ||
"reusable": false, | ||
"html": false | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.