Skip to content

Commit

Permalink
Revert "InnerBlocks: introduce prop to specify render callback for ea…
Browse files Browse the repository at this point in the history
…ch block. (#24232)" (#25196)

This reverts commit 48c4fb9.
  • Loading branch information
ZebulanStanphill authored Sep 9, 2020
1 parent 14edc2d commit 831a340
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 79 deletions.
5 changes: 0 additions & 5 deletions packages/block-editor/src/components/block-list/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ function BlockListBlock( {
toggleSelection,
index,
enableAnimation,
__experimentalRenderCallback: renderCallback,
} ) {
// In addition to withSelect, we should favor using useSelect in this
// component going forward to avoid leaking new props to the public API
Expand Down Expand Up @@ -241,10 +240,6 @@ function BlockListBlock( {
block = <Block.div { ...wrapperProps }>{ blockEdit }</Block.div>;
}

if ( renderCallback ) {
block = renderCallback( block );
}

return (
<BlockListBlockContext.Provider value={ memoizedValue }>
<BlockCrashBoundary onError={ onBlockError }>
Expand Down
4 changes: 0 additions & 4 deletions packages/block-editor/src/components/block-list/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ function BlockList(
className,
rootClientId,
renderAppender,
__experimentalItemCallback,
__experimentalTagName = 'div',
__experimentalAppenderTagName,
__experimentalPassedProps = {},
Expand Down Expand Up @@ -111,9 +110,6 @@ function BlockList(
isDropTarget &&
orientation === 'horizontal',
} ) }
__experimentalRenderCallback={
__experimentalItemCallback
}
/>
</AsyncModeProvider>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,6 @@ export class BlockList extends Component {
parentWidth,
marginVertical = styles.defaultBlock.marginTop,
marginHorizontal = styles.defaultBlock.marginLeft,
__experimentalItemCallback,
} = this.props;
return (
<BlockListItem
Expand All @@ -285,7 +284,6 @@ export class BlockList extends Component {
onCaretVerticalPositionChange={
this.onCaretVerticalPositionChange
}
__experimentalRenderCallback={ __experimentalItemCallback }
/>
);
}
Expand Down
8 changes: 1 addition & 7 deletions packages/block-editor/src/components/inner-blocks/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ function UncontrolledInnerBlocks( props ) {
const {
clientId,
allowedBlocks,
__experimentalItemCallback: itemCallback,
template,
templateLock,
forwardedRef,
Expand Down Expand Up @@ -94,7 +93,6 @@ function UncontrolledInnerBlocks( props ) {
{ ...props }
ref={ forwardedRef }
rootClientId={ clientId }
__experimentalItemCallback={ itemCallback }
className={ classes }
/>
);
Expand Down Expand Up @@ -159,11 +157,7 @@ ForwardedInnerBlocks.DefaultBlockAppender = DefaultBlockAppender;
ForwardedInnerBlocks.ButtonBlockAppender = ButtonBlockAppender;

ForwardedInnerBlocks.Content = withBlockContentContext(
( { BlockContent, __experimentalItemCallback } ) => (
<BlockContent
__experimentalItemCallback={ __experimentalItemCallback }
/>
)
( { BlockContent } ) => <BlockContent />
);

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ function UncontrolledInnerBlocks( props ) {
marginHorizontal,
horizontalAlignment,
filterInnerBlocks,
__experimentalItemCallback,
} = props;

const block = useSelect(
Expand Down Expand Up @@ -83,7 +82,6 @@ function UncontrolledInnerBlocks( props ) {
onAddBlock={ onAddBlock }
onDeleteBlock={ onDeleteBlock }
filterInnerBlocks={ filterInnerBlocks }
__experimentalItemCallback={ __experimentalItemCallback }
/>
);

Expand Down
21 changes: 6 additions & 15 deletions packages/block-editor/src/components/use-block-drop-zone/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/**
* External dependencies
*/
import { difference } from 'lodash';

/**
* WordPress dependencies
*/
Expand Down Expand Up @@ -44,6 +39,11 @@ export function getNearestBlockIndex( elements, position, orientation ) {
let candidateDistance;

elements.forEach( ( element, index ) => {
// Ensure the element is a block. It should have the `wp-block` class.
if ( ! element.classList.contains( 'wp-block' ) ) {
return;
}

const rect = element.getBoundingClientRect();
const [ distance, edge ] = getDistanceToNearestEdge(
position,
Expand Down Expand Up @@ -126,16 +126,7 @@ export default function useBlockDropZone( {

useEffect( () => {
if ( position ) {
// Get the root elements of blocks inside the element, ignoring
// InnerBlocks item wrappers and the children of the blocks.
const blockElements = difference(
Array.from( element.current.querySelectorAll( '.wp-block' ) ),
Array.from(
element.current.querySelectorAll(
':scope .wp-block .wp-block'
)
)
);
const blockElements = Array.from( element.current.children );

const targetIndex = getNearestBlockIndex(
blockElements,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,22 @@ describe( 'getNearestBlockIndex', () => {
expect( result ).toBeUndefined();
} );

it( 'returns `undefined` if the elements do not have the `wp-block` class', () => {
const nonBlockElements = [
{ classList: createMockClassList( 'some-other-class' ) },
];
const position = { x: 0, y: 0 };
const orientation = 'horizontal';

const result = getNearestBlockIndex(
nonBlockElements,
position,
orientation
);

expect( result ).toBeUndefined();
} );

describe( 'Vertical block lists', () => {
const orientation = 'vertical';

Expand Down
46 changes: 7 additions & 39 deletions packages/blocks/src/api/serializer.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,7 @@ import { isEmpty, reduce, isObject, castArray, startsWith } from 'lodash';
/**
* WordPress dependencies
*/
import {
Component,
RawHTML,
cloneElement,
renderToString,
} from '@wordpress/element';
import { Component, cloneElement, renderToString } from '@wordpress/element';
import { hasFilter, applyFilters } from '@wordpress/hooks';
import isShallowEqual from '@wordpress/is-shallow-equal';

Expand All @@ -26,16 +21,10 @@ import {
import { normalizeBlockType } from './utils';
import BlockContentProvider from '../block-content-provider';

/** @typedef {import('@wordpress/element').WPElement} WPElement */

/**
* @typedef {Object} WPBlockSerializationOptions Serialization Options.
*
* @property {boolean} isInnerBlocks
* Whether we are serializing inner blocks.
* @property {WPElement} [__experimentalRenderCallback]
* Callback to define HTML surrounding block, outside of the comment
* delimiters. Used by InnerBlocks API.
* @property {boolean} isInnerBlocks Whether we are serializing inner blocks.
*/

/**
Expand Down Expand Up @@ -318,41 +307,20 @@ export function getCommentDelimitedContent(
*
* @return {string} Serialized block.
*/
export function serializeBlock(
block,
{ isInnerBlocks = false, __experimentalRenderCallback: renderCallback } = {}
) {
export function serializeBlock( block, { isInnerBlocks = false } = {} ) {
const blockName = block.name;
const saveContent = getBlockContent( block );

// Serialized block content before wrapping it with an InnerBlocks item
// wrapper.
let unwrappedContent;

if (
blockName === getUnregisteredTypeHandlerName() ||
( ! isInnerBlocks && blockName === getFreeformContentHandlerName() )
) {
unwrappedContent = saveContent;
} else {
const blockType = getBlockType( blockName );
const saveAttributes = getCommentAttributes(
blockType,
block.attributes
);
unwrappedContent = getCommentDelimitedContent(
blockName,
saveAttributes,
saveContent
);
return saveContent;
}

if ( renderCallback ) {
return renderToString(
renderCallback( <RawHTML>{ unwrappedContent }</RawHTML> )
);
}
return unwrappedContent;
const blockType = getBlockType( blockName );
const saveAttributes = getCommentAttributes( blockType, block.attributes );
return getCommentDelimitedContent( blockName, saveAttributes, saveContent );
}

/**
Expand Down
7 changes: 2 additions & 5 deletions packages/blocks/src/block-content-provider/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,9 @@ const { Consumer, Provider } = createContext( () => {} );
* @return {WPComponent} Element with BlockContent injected via context.
*/
const BlockContentProvider = ( { children, innerBlocks } ) => {
const BlockContent = ( { __experimentalItemCallback } ) => {
const BlockContent = () => {
// Value is an array of blocks, so defer to block serializer
const html = serialize( innerBlocks, {
isInnerBlocks: true,
__experimentalRenderCallback: __experimentalItemCallback,
} );
const html = serialize( innerBlocks, { isInnerBlocks: true } );

// Use special-cased raw HTML tag to avoid default escaping
return <RawHTML>{ html }</RawHTML>;
Expand Down

0 comments on commit 831a340

Please sign in to comment.