From ffa22b8bace0b65d412d205cfd89b1b5d85834eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1vid=20Szab=C3=B3?= Date: Tue, 25 Aug 2020 15:24:40 +0200 Subject: [PATCH] Restore Site Title's Level toolbar and remove obsolete code (#24758) By mistake, we had two edit files. One at `/edit.js` and one at `/edit/index.js`. Looks like the Level toolbar functionality was added by this commit https://github.com/WordPress/gutenberg/commit/988ba5d9dd756f1306b9319a026174280006b857#diff-655f76535495d8ae1d82693b57a4ffba at`/edit/index.js` and later on `/edit.js` was created again by this commit https://github.com/WordPress/gutenberg/commit/0446ed1882c598ad6c34165f67cc1885c414eb40#diff-655f76535495d8ae1d82693b57a4ffba . After this commit, we lost the Level Toolbar which was residing in the `/edit/index.js`. Since we had an `edit` folder and an `edit.js` file, the import was confusing since we had no idea whether the file or the folder being resolved. This PR cleans up the mistake by removing the `/edit.js` and re-adding the Level toolbar. Co-authored-by: Bernie Reiter --- packages/block-library/CHANGELOG.md | 4 ++ packages/block-library/src/site-title/edit.js | 47 ------------------- .../src/site-title/edit/index.js | 33 ++++++++++--- 3 files changed, 31 insertions(+), 53 deletions(-) delete mode 100644 packages/block-library/src/site-title/edit.js diff --git a/packages/block-library/CHANGELOG.md b/packages/block-library/CHANGELOG.md index 8df5040d7a7fab..0160e0d59a3ab9 100644 --- a/packages/block-library/CHANGELOG.md +++ b/packages/block-library/CHANGELOG.md @@ -2,6 +2,10 @@ ## Unreleased +### New Features + +- Add heading level controls to Site Title block. + ## 2.12.0 (2020-01-13) ### Bug Fixes diff --git a/packages/block-library/src/site-title/edit.js b/packages/block-library/src/site-title/edit.js deleted file mode 100644 index d3553f75888bf0..00000000000000 --- a/packages/block-library/src/site-title/edit.js +++ /dev/null @@ -1,47 +0,0 @@ -/** - * External dependencies - */ -import classnames from 'classnames'; - -/** - * WordPress dependencies - */ -import { useEntityProp } from '@wordpress/core-data'; -import { __ } from '@wordpress/i18n'; -import { - RichText, - AlignmentToolbar, - BlockControls, - __experimentalBlock as Block, -} from '@wordpress/block-editor'; - -export default function SiteTitleEdit( { attributes, setAttributes } ) { - const { level, textAlign } = attributes; - const [ title, setTitle ] = useEntityProp( 'root', 'site', 'title' ); - const tagName = 0 === level ? 'p' : 'h' + level; - - return ( - <> - - { - setAttributes( { textAlign: nextAlign } ); - } } - /> - - - - - ); -} diff --git a/packages/block-library/src/site-title/edit/index.js b/packages/block-library/src/site-title/edit/index.js index a44629f7edf213..3079ced37d6a64 100644 --- a/packages/block-library/src/site-title/edit/index.js +++ b/packages/block-library/src/site-title/edit/index.js @@ -1,24 +1,40 @@ +/** + * External dependencies + */ +import classnames from 'classnames'; + /** * WordPress dependencies */ import { useEntityProp } from '@wordpress/core-data'; -import { BlockControls, RichText } from '@wordpress/block-editor'; import { __ } from '@wordpress/i18n'; +import { + RichText, + AlignmentToolbar, + BlockControls, + __experimentalBlock as Block, +} from '@wordpress/block-editor'; /** * Internal dependencies */ import LevelToolbar from './level-toolbar'; -export default function SiteTitleEdit( { - attributes: { level }, - setAttributes, -} ) { +export default function SiteTitleEdit( { attributes, setAttributes } ) { + const { level, textAlign } = attributes; const [ title, setTitle ] = useEntityProp( 'root', 'site', 'title' ); const tagName = level === 0 ? 'p' : `h${ level }`; + return ( <> + { + setAttributes( { textAlign: nextAlign } ); + } } + /> + @@ -26,12 +42,17 @@ export default function SiteTitleEdit( { } /> + );