-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Block API: Allow more than 1 block stylesheets #32510
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
Merged
Merged
Changes from 18 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
0b3f55b
working POC with the comments-form block.
aristath 403715c
add gutenberg_enqueue_block_style function
aristath 3d86def
now works for the editor too!
aristath 47c6163
function was renamed
aristath 115417e
$register arg is not necessary
aristath dc71737
Change hook to enqueue_block_assets
aristath ac830fc
Use array_shift
aristath 46f29f5
Add RTL styles
aristath d2049ab
Update lib/blocks.php
aristath 24ae1ea
Rename function to wp_enqueue_block_style
aristath 05d08c8
Wrap function in a function_exists check
aristath 5dcf487
WIP tests
aristath 0adfc74
tests now run properly
aristath 0582145
await for selector instead of snapshot
aristath a790220
Add support for file paths
aristath 6bc1604
CS fix
aristath a646016
Spacing fix
aristath baac268
Add comment to explain _why_ we're expecting errors.
aristath 032a7f9
make the handle unique when using a path
aristath 7b3e854
Add test for stylesheet loaded via path instead of handle
aristath File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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
44 changes: 44 additions & 0 deletions
44
packages/e2e-tests/plugins/iframed-multiple-stylesheets.php
This file contains hidden or 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,44 @@ | ||
| <?php | ||
| /** | ||
| * Plugin Name: Gutenberg Test Iframed Multiple Stylesheets | ||
| * Plugin URI: https://github.com/WordPress/gutenberg | ||
| * Author: Gutenberg Team | ||
| * | ||
| * @package gutenberg-test-iframed-multiple-stylesheets | ||
| */ | ||
|
|
||
| add_action( | ||
| 'setup_theme', | ||
| function() { | ||
| add_theme_support( 'block-templates' ); | ||
| } | ||
| ); | ||
|
|
||
| add_action( | ||
| 'init', | ||
| function() { | ||
| wp_register_script( | ||
| 'iframed-multiple-stylesheets-editor-script', | ||
| plugin_dir_url( __FILE__ ) . 'iframed-multiple-stylesheets/editor.js', | ||
| array( | ||
| 'wp-blocks', | ||
| 'wp-block-editor', | ||
| 'wp-element', | ||
| ), | ||
| filemtime( plugin_dir_path( __FILE__ ) . 'iframed-multiple-stylesheets/editor.js' ) | ||
| ); | ||
| wp_register_style( | ||
| 'iframed-multiple-stylesheets-style', | ||
| plugin_dir_url( __FILE__ ) . 'iframed-multiple-stylesheets/style.css', | ||
| array(), | ||
| filemtime( plugin_dir_path( __FILE__ ) . 'iframed-multiple-stylesheets/style.css' ) | ||
| ); | ||
| wp_register_style( | ||
| 'iframed-multiple-stylesheets-style2', | ||
| plugin_dir_url( __FILE__ ) . 'iframed-multiple-stylesheets/style2.css', | ||
| array(), | ||
| filemtime( plugin_dir_path( __FILE__ ) . 'iframed-multiple-stylesheets/style2.css' ) | ||
| ); | ||
| register_block_type_from_metadata( __DIR__ . '/iframed-multiple-stylesheets' ); | ||
| } | ||
| ); |
15 changes: 15 additions & 0 deletions
15
packages/e2e-tests/plugins/iframed-multiple-stylesheets/block.json
This file contains hidden or 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,15 @@ | ||
| { | ||
| "apiVersion": 2, | ||
| "name": "test/iframed-multiple-stylesheets", | ||
| "title": "Iframed Multiple Stylesheets", | ||
| "category": "text", | ||
| "icon": "smiley", | ||
| "description": "", | ||
| "supports": { | ||
| "html": false | ||
| }, | ||
| "textdomain": "iframed-multiple-stylesheets", | ||
| "editorScript": "iframed-multiple-stylesheets-editor-script", | ||
| "editorStyle": "file:./editor.css", | ||
| "style": [ "iframed-multiple-stylesheets-style", "iframed-multiple-stylesheets-style2" ] | ||
aristath marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
6 changes: 6 additions & 0 deletions
6
packages/e2e-tests/plugins/iframed-multiple-stylesheets/editor.css
This file contains hidden or 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,6 @@ | ||
| /** | ||
| * The following styles get applied inside the editor only. | ||
| */ | ||
| .wp-block-test-iframed-inline-styles { | ||
| border: 1px dotted #f00; | ||
| } |
15 changes: 15 additions & 0 deletions
15
packages/e2e-tests/plugins/iframed-multiple-stylesheets/editor.js
This file contains hidden or 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,15 @@ | ||
| ( ( { wp: { element, blocks, blockEditor } } ) => { | ||
| const { createElement: el } = element; | ||
| const { registerBlockType } = blocks; | ||
| const { useBlockProps } = blockEditor; | ||
|
|
||
| registerBlockType( 'test/iframed-multiple-stylesheets', { | ||
| apiVersion: 2, | ||
| edit: function Edit() { | ||
| return el( 'div', useBlockProps(), 'Edit' ); | ||
| }, | ||
| save: function Save() { | ||
| return el( 'div', useBlockProps.save(), 'Save' ); | ||
| }, | ||
| } ); | ||
| } )( window ); |
7 changes: 7 additions & 0 deletions
7
packages/e2e-tests/plugins/iframed-multiple-stylesheets/style.css
This file contains hidden or 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,7 @@ | ||
| /** | ||
| * The following styles get applied both on the front of your site and in the | ||
| * editor. | ||
| */ | ||
| .wp-block-test-iframed-multiple-stylesheets { | ||
| border-style: dashed; | ||
| } |
7 changes: 7 additions & 0 deletions
7
packages/e2e-tests/plugins/iframed-multiple-stylesheets/style2.css
This file contains hidden or 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,7 @@ | ||
| /** | ||
| * The following styles get applied both on the front of your site and in the | ||
| * editor. | ||
| */ | ||
| .wp-block-test-iframed-multiple-stylesheets { | ||
| border-color: #f00 !important; | ||
| } |
66 changes: 66 additions & 0 deletions
66
packages/e2e-tests/specs/editor/plugins/iframed-multiple-block-stylesheets.test.js
This file contains hidden or 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,66 @@ | ||
| /** | ||
| * WordPress dependencies | ||
| */ | ||
| import { | ||
| activatePlugin, | ||
| createNewPost, | ||
| deactivatePlugin, | ||
| insertBlock, | ||
| openDocumentSettingsSidebar, | ||
| clickButton, | ||
| canvas, | ||
| } from '@wordpress/e2e-test-utils'; | ||
|
|
||
| async function getComputedStyle( context, property ) { | ||
| await context.waitForSelector( | ||
| '.wp-block-test-iframed-multiple-stylesheets' | ||
| ); | ||
| return await context.evaluate( ( prop ) => { | ||
| const container = document.querySelector( | ||
| '.wp-block-test-iframed-multiple-stylesheets' | ||
| ); | ||
| return window.getComputedStyle( container )[ prop ]; | ||
| }, property ); | ||
| } | ||
|
|
||
| describe( 'iframed multiple block stylesheets', () => { | ||
| beforeEach( async () => { | ||
| await activatePlugin( 'gutenberg-test-iframed-multiple-stylesheets' ); | ||
| await createNewPost( { postType: 'page' } ); | ||
| } ); | ||
|
|
||
| afterEach( async () => { | ||
| await deactivatePlugin( 'gutenberg-test-iframed-multiple-stylesheets' ); | ||
| } ); | ||
|
|
||
| it( 'should load multiple block stylesheets in iframe', async () => { | ||
| await insertBlock( 'Iframed Multiple Stylesheets' ); | ||
|
|
||
| await page.waitForSelector( | ||
| '.wp-block-test-iframed-multiple-stylesheets' | ||
| ); | ||
| await openDocumentSettingsSidebar(); | ||
| await clickButton( 'Page' ); | ||
| await clickButton( 'Template' ); | ||
| await clickButton( 'New' ); | ||
| await page.keyboard.press( 'Tab' ); | ||
| await page.keyboard.press( 'Tab' ); | ||
| await page.keyboard.type( 'Iframed Test' ); | ||
| await clickButton( 'Create' ); | ||
| await page.waitForSelector( 'iframe[name="editor-canvas"]' ); | ||
|
|
||
| // Style loaded from the main stylesheet. | ||
| expect( await getComputedStyle( canvas(), 'border-style' ) ).toBe( | ||
| 'dashed' | ||
| ); | ||
|
|
||
| // Style loaded from the additional stylesheet. | ||
| expect( await getComputedStyle( canvas(), 'border-color' ) ).toBe( | ||
| 'rgb(255, 0, 0)' | ||
| ); | ||
|
|
||
| // Skip errors related to block-styles enqueing and the use of add_editor_style. | ||
| // The issue is tracked on https://github.com/WordPress/gutenberg/issues/33212. | ||
| expect( console ).toHaveErrored(); | ||
aristath marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } ); | ||
| } ); | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.