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: merge RootContainer with BlockList #27531

Merged
merged 2 commits into from
Dec 6, 2020
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { getScrollContainer } from '@wordpress/dom';
import BlockSelectionButton from './block-selection-button';
import BlockContextualToolbar from './block-contextual-toolbar';
import Inserter from '../inserter';
import { BlockNodes } from './root-container';
import { BlockNodes } from './';
import { getBlockDOMNode } from '../../utils/dom';

function selector( select ) {
Expand Down
50 changes: 25 additions & 25 deletions packages/block-editor/src/components/block-list/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,45 +7,47 @@ import classnames from 'classnames';
* WordPress dependencies
*/
import { AsyncModeProvider, useSelect } from '@wordpress/data';
import { useRef, forwardRef } from '@wordpress/element';
import { useRef, createContext, useState } from '@wordpress/element';

/**
* Internal dependencies
*/
import BlockListBlock from './block';
import BlockListAppender from '../block-list-appender';
import RootContainer from './root-container';
import useBlockDropZone from '../use-block-drop-zone';
import useInsertionPoint from './insertion-point';
import BlockPopover from './block-popover';

/**
* If the block count exceeds the threshold, we disable the reordering animation
* to avoid laginess.
*/
const BLOCK_ANIMATION_THRESHOLD = 200;

function BlockList(
{ className, placeholder, rootClientId, renderAppender },
ref
) {
const Container = rootClientId ? 'div' : RootContainer;
Copy link
Member Author

@ellatrix ellatrix Dec 6, 2020

Choose a reason for hiding this comment

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

rootClientId will always be falsy since InnerBlocks doesn't use this component anymore.

Copy link
Contributor

Choose a reason for hiding this comment

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

When did InnerBlocks stop using this component?

const fallbackRef = useRef();
const wrapperRef = ref || fallbackRef;
export const BlockNodes = createContext();
export const SetBlockNodes = createContext();

export default function BlockList( { className } ) {
const ref = useRef();
const [ blockNodes, setBlockNodes ] = useState( {} );
const insertionPoint = useInsertionPoint( ref );

return (
<Container
ref={ wrapperRef }
className={ classnames(
'block-editor-block-list__layout',
className
) }
>
<BlockListItems
placeholder={ placeholder }
rootClientId={ rootClientId }
renderAppender={ renderAppender }
wrapperRef={ wrapperRef }
/>
</Container>
<BlockNodes.Provider value={ blockNodes }>
{ insertionPoint }
<BlockPopover />
<div
ref={ ref }
className={ classnames(
'block-editor-block-list__layout is-root-container',
className
) }
>
<SetBlockNodes.Provider value={ setBlockNodes }>
<BlockListItems wrapperRef={ ref } />
</SetBlockNodes.Provider>
</div>
</BlockNodes.Provider>
);
}

Expand Down Expand Up @@ -161,5 +163,3 @@ export function BlockListItems( props ) {
</AsyncModeProvider>
);
}

export default forwardRef( BlockList );
40 changes: 0 additions & 40 deletions packages/block-editor/src/components/block-list/root-container.js

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { __unstableGetBlockProps as getBlockProps } from '@wordpress/blocks';
* Internal dependencies
*/
import useMovingAnimation from '../../use-moving-animation';
import { SetBlockNodes } from '../root-container';
import { SetBlockNodes } from '../';
import { BlockListBlockContext } from '../block';
import { useFocusFirstElement } from './use-focus-first-element';
import { useIsHovered } from './use-is-hovered';
Expand Down