From 49d79cf40a7786bee93af3594a95bb9ebfbc3094 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9rgio=20Est=C3=AAv=C3=A3o?= Date: Tue, 31 Mar 2020 22:44:34 +0100 Subject: [PATCH] Add pre to list of block wrappers (#21255) * 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 --- .../components/block-list/block-elements.js | 23 +++++++++++++++++ .../components/block-list/block-wrapper.js | 25 ++----------------- .../block-list/block-wrapper.native.js | 21 ++++------------ 3 files changed, 30 insertions(+), 39 deletions(-) create mode 100644 packages/block-editor/src/components/block-list/block-elements.js diff --git a/packages/block-editor/src/components/block-list/block-elements.js b/packages/block-editor/src/components/block-list/block-elements.js new file mode 100644 index 00000000000000..1d71649a1cc479 --- /dev/null +++ b/packages/block-editor/src/components/block-list/block-elements.js @@ -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; diff --git a/packages/block-editor/src/components/block-list/block-wrapper.js b/packages/block-editor/src/components/block-list/block-wrapper.js index cfcbfccb9a99f9..80a63a15df6ceb 100644 --- a/packages/block-editor/src/components/block-list/block-wrapper.js +++ b/packages/block-editor/src/components/block-list/block-wrapper.js @@ -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 ) => { @@ -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 ; } ); diff --git a/packages/block-editor/src/components/block-list/block-wrapper.native.js b/packages/block-editor/src/components/block-list/block-wrapper.native.js index 69cbf52723125a..c97dae59059f54 100644 --- a/packages/block-editor/src/components/block-list/block-wrapper.native.js +++ b/packages/block-editor/src/components/block-list/block-wrapper.native.js @@ -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 );