-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce ExperimentalBlockEditorProvider (#47319)
This commit introduces `ExperimentalBlockEditorProvider` that prevents mixing experimental editor settings and the public `BlockEditorProvider` component. The actual filtering is handled in a private `__experimentalUpdateSettings` selector in the block-editor store. Experimental settings may still be set via a PHP plugin – limiting this vector would require a separate PR. ## Rationale WordPress extenders cannot update the experimental block settings on their own. The `updateSettings()` actions of the `@wordpress/block-editor` store will filter out all the settings that are **not** a part of the public API. The only way to actually store them is via private action. `__experimentalUpdateSettings()`. To privatize a block editor setting, add it to the `privateSettings` list in [/packages/block-editor/src/store/actions.js](/packages/block-editor/src/store/actions.js): ```js const privateSettings = [ '__unstableInserterMediaCategories', // List a block editor setting here to make it private ]; ``` ## Mobile apps This commit updates a few `.native.js` files. Mobile apps choose to import the `.native.js` files over their `.js` counterparts whenever possible. At the same time, this PR introduced the expectation of having two extra named exports: `ExperimentalEditorProvider` and `ExperimentalBlockEditorProvider`. I updated the native files to export the regular Provider component under the experimental name. This works because the settings filtering is restricted to the web – it doesn't make sense in context of mobile apps anyway. Co-authored-by: ntsekouras <[email protected]>
- Loading branch information
1 parent
ff5beb5
commit 3e85c43
Showing
31 changed files
with
445 additions
and
140 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
98 changes: 98 additions & 0 deletions
98
packages/block-editor/src/components/provider/test/experimental-provider.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,98 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { render } from '@testing-library/react'; | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { useRegistry } from '@wordpress/data'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { BlockEditorProvider, ExperimentalBlockEditorProvider } from '../'; | ||
import { store as blockEditorStore } from '../../../store'; | ||
|
||
const HasEditorSetting = ( props ) => { | ||
const registry = useRegistry(); | ||
if ( props.setRegistry ) { | ||
props.setRegistry( registry ); | ||
} | ||
return <p>Test.</p>; | ||
}; | ||
|
||
describe( 'BlockEditorProvider', () => { | ||
let registry; | ||
const setRegistry = ( reg ) => { | ||
registry = reg; | ||
}; | ||
beforeEach( () => { | ||
registry = undefined; | ||
} ); | ||
it( 'should strip experimental settings', async () => { | ||
render( | ||
<BlockEditorProvider | ||
settings={ { | ||
__unstableInserterMediaCategories: true, | ||
} } | ||
> | ||
<HasEditorSetting setRegistry={ setRegistry } /> | ||
</BlockEditorProvider> | ||
); | ||
const settings = registry.select( blockEditorStore ).getSettings(); | ||
expect( settings ).not.toHaveProperty( | ||
'__unstableInserterMediaCategories' | ||
); | ||
} ); | ||
it( 'should preserve stable settings', async () => { | ||
render( | ||
<BlockEditorProvider | ||
settings={ { | ||
stableSetting: 'https://example.com', | ||
} } | ||
> | ||
<HasEditorSetting setRegistry={ setRegistry } /> | ||
</BlockEditorProvider> | ||
); | ||
const settings = registry.select( blockEditorStore ).getSettings(); | ||
expect( settings ).toHaveProperty( 'stableSetting' ); | ||
} ); | ||
} ); | ||
|
||
describe( 'ExperimentalBlockEditorProvider', () => { | ||
let registry; | ||
const setRegistry = ( reg ) => { | ||
registry = reg; | ||
}; | ||
beforeEach( () => { | ||
registry = undefined; | ||
} ); | ||
it( 'should preserve experimental settings', async () => { | ||
render( | ||
<ExperimentalBlockEditorProvider | ||
settings={ { | ||
__unstableInserterMediaCategories: true, | ||
} } | ||
> | ||
<HasEditorSetting setRegistry={ setRegistry } /> | ||
</ExperimentalBlockEditorProvider> | ||
); | ||
const settings = registry.select( blockEditorStore ).getSettings(); | ||
expect( settings ).toHaveProperty( | ||
'__unstableInserterMediaCategories' | ||
); | ||
} ); | ||
it( 'should preserve stable settings', async () => { | ||
render( | ||
<ExperimentalBlockEditorProvider | ||
settings={ { | ||
stableSetting: 'https://example.com', | ||
} } | ||
> | ||
<HasEditorSetting setRegistry={ setRegistry } /> | ||
</ExperimentalBlockEditorProvider> | ||
); | ||
const settings = registry.select( blockEditorStore ).getSettings(); | ||
expect( settings ).toHaveProperty( 'stableSetting' ); | ||
} ); | ||
} ); |
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.
3e85c43
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Flaky tests detected in 3e85c43.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.
🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/4018676421
📝 Reported issues:
specs/editor/various/multi-block-selection.test.js