Skip to content

Commit

Permalink
Add pre to list of block wrappers (#21255)
Browse files Browse the repository at this point in the history
* Add pre to list of block wrappers

* Share the elements definition between web and native.

* Make constant name all uppercase.

* Rename constant name to be all uppercase

* Rename elements constant to all uppercase
  • Loading branch information
SergioEstevao authored Mar 31, 2020
1 parent 00aa937 commit 3425305
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 39 deletions.
23 changes: 23 additions & 0 deletions packages/block-editor/src/components/block-list/block-elements.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const ELEMENTS = [
'p',
'div',
'h1',
'h2',
'h3',
'h4',
'h5',
'h6',
'ol',
'ul',
'li',
'figure',
'nav',
'pre',
'header',
'section',
'aside',
'footer',
'main',
];

export default ELEMENTS;
25 changes: 2 additions & 23 deletions packages/block-editor/src/components/block-list/block-wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { isInsideRootBlock } from '../../utils/dom';
import useMovingAnimation from './moving-animation';
import { Context, BlockNodes } from './root-container';
import { BlockContext } from './block';
import ELEMENTS from './block-elements';

const BlockComponent = forwardRef(
( { children, tagName = 'div', __unstableIsHtml, ...props }, wrapper ) => {
Expand Down Expand Up @@ -226,29 +227,7 @@ const BlockComponent = forwardRef(
}
);

const elements = [
'p',
'div',
'h1',
'h2',
'h3',
'h4',
'h5',
'h6',
'ol',
'ul',
'li',
'figure',
'nav',
'pre',
'header',
'section',
'aside',
'footer',
'main',
];

const ExtendedBlockComponent = elements.reduce( ( acc, element ) => {
const ExtendedBlockComponent = ELEMENTS.reduce( ( acc, element ) => {
acc[ element ] = forwardRef( ( props, ref ) => {
return <BlockComponent { ...props } ref={ ref } tagName={ element } />;
} );
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,9 @@
const elements = [
'p',
'div',
'h1',
'h2',
'h3',
'h4',
'h5',
'h6',
'ol',
'ul',
'li',
'figure',
'nav',
];
/**
* Internal dependencies
*/
import ELEMENTS from './block-elements';

const ExtendedBlockComponent = elements.reduce( ( acc, element ) => {
const ExtendedBlockComponent = ELEMENTS.reduce( ( acc, element ) => {
acc[ element ] = element;
return acc;
}, String );
Expand Down

0 comments on commit 3425305

Please sign in to comment.