fix: mount filter controls in sidebar via InspectorControls
The FilterPanel was being mounted as a free-floating sibling of the block via an `editor.BlockEdit` HOC. In WordPress, a `PanelBody` only renders in the sidebar when wrapped in `<InspectorControls>`; without that wrapper, the panel renders wherever it lands in the React tree, which here was the editor canvas. Move the InspectorControls mount into the Edit component itself (the idiomatic place for an own block to expose sidebar controls), and drop the `editor.BlockEdit` filter from `src/index.js`. Add an Edit test that pins the contract: the filter panel must mount inside InspectorControls and never float outside it. Add a manual jest mock for @wordpress/block-editor so the Edit test can render in an environment without WordPress globals.
This commit is contained in:
+1
-28
@@ -14,7 +14,6 @@ import metadata from './block.json';
|
||||
import edit from './edit';
|
||||
import save from './save';
|
||||
import { PRESETS, DEFAULT_PRESET, isValidPresetSlug } from './presets';
|
||||
import { FilterPanel } from './inspector';
|
||||
import { transforms } from './transforms';
|
||||
|
||||
registerBlockType( metadata.name, {
|
||||
@@ -24,32 +23,6 @@ registerBlockType( metadata.name, {
|
||||
transforms,
|
||||
} );
|
||||
|
||||
/**
|
||||
* Add the filter panel to the Image block's inspector when the active
|
||||
* block is the Filtered Image block. We use the editor.BlockEdit filter
|
||||
* so we don't have to re-implement the entire MediaPlaceholder UX.
|
||||
*
|
||||
* @param {Function} BlockEdit
|
||||
* @return {Function}
|
||||
*/
|
||||
function withFilterPanel( BlockEdit ) {
|
||||
return ( props ) => {
|
||||
if ( props.name !== 'ksolo/image-filter' ) {
|
||||
return <BlockEdit { ...props } />;
|
||||
}
|
||||
return (
|
||||
<>
|
||||
<BlockEdit { ...props } />
|
||||
<FilterPanel
|
||||
attributes={ props.attributes }
|
||||
setAttributes={ props.setAttributes }
|
||||
/>
|
||||
</>
|
||||
);
|
||||
};
|
||||
}
|
||||
addFilter( 'editor.BlockEdit', 'solofilters-image-enhancements/with-filter-panel', withFilterPanel );
|
||||
|
||||
/**
|
||||
* Normalise the filter attribute on save. If the saved slug is unknown
|
||||
* (e.g. the post was edited by hand), fall back to DEFAULT_PRESET so the
|
||||
@@ -76,4 +49,4 @@ addFilter(
|
||||
|
||||
// Re-export PRESETS so the consuming downstream code (e.g. a future
|
||||
// design-tool integration) can grab them from this module.
|
||||
export { PRESETS };
|
||||
export { PRESETS };
|
||||
Reference in New Issue
Block a user