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

Block Editor: Group 'onRemove' callback with other public APIs #67551

Merged
merged 1 commit into from
Dec 4, 2024
Merged
Changes from all commits
Commits
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
19 changes: 6 additions & 13 deletions packages/block-editor/src/components/block-list/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,7 @@ import clsx from 'clsx';
/**
* WordPress dependencies
*/
import {
memo,
useCallback,
RawHTML,
useContext,
useMemo,
} from '@wordpress/element';
import { memo, RawHTML, useContext, useMemo } from '@wordpress/element';
import {
getBlockType,
getSaveContent,
Expand All @@ -28,7 +22,7 @@ import {
store as blocksStore,
} from '@wordpress/blocks';
import { withFilters } from '@wordpress/components';
import { withDispatch, useDispatch, useSelect } from '@wordpress/data';
import { withDispatch, useSelect } from '@wordpress/data';
import { compose } from '@wordpress/compose';
import { safeHTML } from '@wordpress/dom';

Expand Down Expand Up @@ -103,6 +97,7 @@ function BlockListBlock( {
wrapperProps,
setAttributes,
onReplace,
onRemove,
onInsertBlocksAfter,
onMerge,
toggleSelection,
Expand All @@ -113,11 +108,6 @@ function BlockListBlock( {
themeSupportsLayout,
...context
} = useContext( PrivateBlockContext );
const { removeBlock } = useDispatch( blockEditorStore );
const onRemove = useCallback(
() => removeBlock( clientId ),
[ clientId, removeBlock ]
);

const parentLayout = useLayout() || {};

Expand Down Expand Up @@ -537,6 +527,9 @@ const applyWithDispatch = withDispatch( ( dispatch, ownProps, registry ) => {
initialPosition
);
},
onRemove() {
removeBlock( ownProps.clientId );
},
toggleSelection( selectionEnabled ) {
toggleSelection( selectionEnabled );
},
Expand Down
Loading