Skip to content

Commit

Permalink
Bundle the block copy handler within the BlockCanvas component (#54207)
Browse files Browse the repository at this point in the history
  • Loading branch information
youknowriad authored Sep 6, 2023
1 parent dc8b7c8 commit 62b8de2
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 31 deletions.
10 changes: 9 additions & 1 deletion packages/block-editor/src/components/block-canvas/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/**
* WordPress dependencies
*/
import { useMergeRefs } from '@wordpress/compose';

/**
* Internal dependencies
*/
Expand All @@ -6,16 +11,19 @@ import EditorStyles from '../editor-styles';
import Iframe from '../iframe';
import WritingFlow from '../writing-flow';
import { useMouseMoveTypingReset } from '../observe-typing';
import { useClipboardHandler } from '../copy-handler';

export function ExperimentalBlockCanvas( {
shouldIframe = true,
height = '300px',
children = <BlockList />,
styles,
contentRef,
contentRef: contentRefProp,
iframeProps,
} ) {
const resetTypingRef = useMouseMoveTypingReset();
const copyHandler = useClipboardHandler();
const contentRef = useMergeRefs( [ copyHandler, contentRefProp ] );

if ( ! shouldIframe ) {
return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
BlockTools,
BlockSelectionClearer,
BlockInspector,
CopyHandler,
privateApis as blockEditorPrivateApis,
__unstableBlockSettingsMenuFirstItem,
} from '@wordpress/block-editor';
Expand Down Expand Up @@ -114,19 +113,17 @@ export default function SidebarBlockEditor( {
isFixedToolbarActive={ isFixedToolbarActive }
/>

<CopyHandler>
<BlockTools>
<BlockSelectionClearer>
<BlockCanvas
shouldIframe={ false }
styles={ settings.defaultEditorStyles }
height="100%"
>
<BlockList renderAppender={ BlockAppender } />
</BlockCanvas>
</BlockSelectionClearer>
</BlockTools>
</CopyHandler>
<BlockTools>
<BlockSelectionClearer>
<BlockCanvas
shouldIframe={ false }
styles={ settings.defaultEditorStyles }
height="100%"
>
<BlockList renderAppender={ BlockAppender } />
</BlockCanvas>
</BlockSelectionClearer>
</BlockTools>

{ createPortal(
// This is a temporary hack to prevent button component inside <BlockInspector>
Expand Down
2 changes: 0 additions & 2 deletions packages/edit-post/src/components/visual-editor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {
store as blockEditorStore,
__unstableUseBlockSelectionClearer as useBlockSelectionClearer,
__unstableUseTypewriter as useTypewriter,
__unstableUseClipboardHandler as useClipboardHandler,
__unstableUseTypingObserver as useTypingObserver,
__experimentalUseResizeCanvas as useResizeCanvas,
useSetting,
Expand Down Expand Up @@ -185,7 +184,6 @@ export default function VisualEditor( { styles } ) {
const ref = useRef();
const contentRef = useMergeRefs( [
ref,
useClipboardHandler(),
useTypewriter(),
useBlockSelectionClearer(),
] );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,9 @@ import { useRef } from '@wordpress/element';
import {
BlockList,
BlockTools,
__unstableUseClipboardHandler as useClipboardHandler,
store as blockEditorStore,
} from '@wordpress/block-editor';
import {
useMergeRefs,
useViewportMatch,
useResizeObserver,
} from '@wordpress/compose';
import { useViewportMatch, useResizeObserver } from '@wordpress/compose';
/**
* Internal dependencies
*/
Expand Down Expand Up @@ -76,8 +71,6 @@ export default function SiteEditorCanvas() {
! isMobileViewport;

const contentRef = useRef();
const mergedRefs = useMergeRefs( [ contentRef, useClipboardHandler() ] );

const isTemplateTypeNavigation = templateType === 'wp_navigation';

const isNavigationFocusMode = isTemplateTypeNavigation && isFocusMode;
Expand Down Expand Up @@ -127,7 +120,7 @@ export default function SiteEditorCanvas() {
<EditorCanvas
enableResizing={ enableResizing }
settings={ settings }
contentRef={ mergedRefs }
contentRef={ contentRef }
>
{ resizeObserver }
<BlockList
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ import {
useResourcePermissions,
} from '@wordpress/core-data';
import { useMemo } from '@wordpress/element';
import {
CopyHandler,
privateApis as blockEditorPrivateApis,
} from '@wordpress/block-editor';
import { privateApis as blockEditorPrivateApis } from '@wordpress/block-editor';
import { privateApis as editPatternsPrivateApis } from '@wordpress/patterns';
import { store as preferencesStore } from '@wordpress/preferences';

Expand Down Expand Up @@ -107,7 +104,7 @@ export default function WidgetAreasBlockEditorProvider( {
useSubRegistry={ false }
{ ...props }
>
<CopyHandler>{ children }</CopyHandler>
{ children }
<PatternsMenuItems rootClientId={ widgetAreaId } />
</ExperimentalBlockEditorProvider>
</SlotFillProvider>
Expand Down

1 comment on commit 62b8de2

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flaky tests detected in 62b8de2.
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/6096668802
📝 Reported issues:

Please sign in to comment.