From 8d81fa8fd47756a0aae2a331c84916035f11bf9d Mon Sep 17 00:00:00 2001 From: Andrew Serong <14988353+andrewserong@users.noreply.github.com> Date: Thu, 2 Mar 2023 16:43:15 +1100 Subject: [PATCH 01/12] Style Book: Try moving iframe to root of content area --- .../src/components/style-book/index.js | 137 +++++++++++++----- .../src/components/style-book/style.scss | 2 +- 2 files changed, 103 insertions(+), 36 deletions(-) diff --git a/packages/edit-site/src/components/style-book/index.js b/packages/edit-site/src/components/style-book/index.js index b9b6b63cfe4a9e..05e398ee502ec0 100644 --- a/packages/edit-site/src/components/style-book/index.js +++ b/packages/edit-site/src/components/style-book/index.js @@ -8,6 +8,7 @@ import classnames from 'classnames'; */ import { Button, + Disabled, TabPanel, createSlotFill, __experimentalUseSlotFills as useSlotFills, @@ -20,9 +21,13 @@ import { createBlock, } from '@wordpress/blocks'; import { - BlockPreview, + BlockList, privateApis as blockEditorPrivateApis, + store as blockEditorStore, + __unstableEditorStyles as EditorStyles, + __unstableIframe as Iframe, } from '@wordpress/block-editor'; +import { useSelect } from '@wordpress/data'; import { closeSmall } from '@wordpress/icons'; import { useResizeObserver, @@ -38,7 +43,9 @@ import { ESCAPE } from '@wordpress/keycodes'; */ import { unlock } from '../../private-apis'; -const { useGlobalStyle } = unlock( blockEditorPrivateApis ); +const { ExperimentalBlockEditorProvider, useGlobalStyle } = unlock( + blockEditorPrivateApis +); const SLOT_FILL_NAME = 'EditSiteStyleBook'; const { Slot: StyleBookSlot, Fill: StyleBookFill } = @@ -118,6 +125,15 @@ function StyleBook( { isSelected, onSelect, onClose } ) { [ examples ] ); + const originalSettings = useSelect( + ( select ) => select( blockEditorStore ).getSettings(), + [] + ); + const settings = useMemo( + () => ( { ...originalSettings, __unstableIsPreviewMode: true } ), + [ originalSettings ] + ); + function closeOnEscape( event ) { if ( event.keyCode === ESCAPE && ! event.defaultPrevented ) { event.preventDefault(); @@ -156,12 +172,51 @@ function StyleBook( { isSelected, onSelect, onClose } ) { tabs={ tabs } > { ( tab ) => ( - + ) } @@ -187,34 +242,46 @@ const Examples = memo( ( { examples, category, isSelected, onSelect } ) => ( ) ); -const Example = memo( ( { title, blocks, isSelected, onClick } ) => ( - -) ); + ); + /* eslint-enable jsx-a11y/no-static-element-interactions, jsx-a11y/click-events-have-key-events */ +} ); function useHasStyleBook() { const fills = useSlotFills( SLOT_FILL_NAME ); diff --git a/packages/edit-site/src/components/style-book/style.scss b/packages/edit-site/src/components/style-book/style.scss index fc88c399cac207..6ab68a99f9c5bf 100644 --- a/packages/edit-site/src/components/style-book/style.scss +++ b/packages/edit-site/src/components/style-book/style.scss @@ -26,7 +26,7 @@ bottom: 0; left: 0; overflow: auto; - padding: $grid-unit-40; + padding: 0; position: absolute; right: 0; top: $grid-unit-60; // Height of tabs. From 5e5b7c32b7eb6f95bae302aa330e417522d1d495 Mon Sep 17 00:00:00 2001 From: Andrew Serong <14988353+andrewserong@users.noreply.github.com> Date: Fri, 3 Mar 2023 12:08:45 +1100 Subject: [PATCH 02/12] Try to match styles inside the iframe to the existing text styles from Gutenberg --- .../src/components/style-book/index.js | 70 ++++++++++++++----- .../src/components/style-book/style.scss | 44 ------------ 2 files changed, 51 insertions(+), 63 deletions(-) diff --git a/packages/edit-site/src/components/style-book/index.js b/packages/edit-site/src/components/style-book/index.js index 05e398ee502ec0..c0dcf08d7ccc71 100644 --- a/packages/edit-site/src/components/style-book/index.js +++ b/packages/edit-site/src/components/style-book/index.js @@ -182,6 +182,11 @@ function StyleBook( { isSelected, onSelect, onClose } ) { `.is-root-container { display: flow-root; } body { position: relative; padding: 32px !important; } + .edit-site-style-book__examples { + max-width: 900px; + margin: 0 auto; + } + .edit-site-style-book__example { background: none; border-radius: 2px; @@ -201,16 +206,41 @@ function StyleBook( { isSelected, onSelect, onClose } ) { box-shadow: 0 0 0 1px var(--wp-admin-theme-color); } - .edit-site-style-book.is-wide .edit-site-style-book__example { + .edit-site-style-book__examples.is-wide .edit-site-style-book__example { flex-direction: row; } + + .edit-site-style-book__example-title { + font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif; + font-size: 11px; + font-weight: 500; + line-height: normal; + margin: 0; + text-align: left; + text-transform: uppercase; + } + + .edit-site-style-book__examples.is-wide .edit-site-style-book__example-title { + text-align: right; + width: 120px; + } + + .edit-site-style-book__example-preview { + width: 100%; + } ` } } - texIndex={ -1 } + tabIndex={ -1 } > 600, + } + ) } examples={ examples } category={ tab.name } isSelected={ isSelected } @@ -224,23 +254,25 @@ function StyleBook( { isSelected, onSelect, onClose } ) { ); } -const Examples = memo( ( { examples, category, isSelected, onSelect } ) => ( -
- { examples - .filter( ( example ) => example.category === category ) - .map( ( example ) => ( - { - onSelect( example.name ); - } } - /> - ) ) } -
-) ); +const Examples = memo( + ( { className, examples, category, isSelected, onSelect } ) => ( +
+ { examples + .filter( ( example ) => example.category === category ) + .map( ( example ) => ( + { + onSelect( example.name ); + } } + /> + ) ) } +
+ ) +); const Example = memo( ( { title, blocks, isSelected, onClick } ) => { const originalSettings = useSelect( diff --git a/packages/edit-site/src/components/style-book/style.scss b/packages/edit-site/src/components/style-book/style.scss index 6ab68a99f9c5bf..881b117a75ccb3 100644 --- a/packages/edit-site/src/components/style-book/style.scss +++ b/packages/edit-site/src/components/style-book/style.scss @@ -32,47 +32,3 @@ top: $grid-unit-60; // Height of tabs. } } - -.edit-site-style-book__examples { - max-width: 900px; - margin: 0 auto; -} - -.edit-site-style-book__example { - background: none; - border-radius: $radius-block-ui; - border: none; - color: inherit; - cursor: pointer; - display: flex; - flex-direction: column; - gap: $grid-unit-50; - margin-bottom: $grid-unit-50; - padding: $grid-unit-20; - width: 100%; - - &.is-selected { - box-shadow: 0 0 0 1px var(--wp-admin-theme-color); - } - - .edit-site-style-book.is-wide & { - flex-direction: row; - } -} - -.edit-site-style-book__example-title { - font-size: 11px; - font-weight: 500; - margin: 0; - text-align: left; - text-transform: uppercase; - - .edit-site-style-book.is-wide & { - text-align: right; - width: 120px; - } -} - -.edit-site-style-book__example-preview { - width: 100%; -} From bb07045acfde2d1bf79eeff511463c8d1cc9b973 Mon Sep 17 00:00:00 2001 From: Andrew Serong <14988353+andrewserong@users.noreply.github.com> Date: Fri, 3 Mar 2023 12:30:30 +1100 Subject: [PATCH 03/12] Restore margin rules to prevent vertical margins on previews from affecting the height of the preview --- packages/edit-site/src/components/style-book/index.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/packages/edit-site/src/components/style-book/index.js b/packages/edit-site/src/components/style-book/index.js index c0dcf08d7ccc71..e2005985bc863d 100644 --- a/packages/edit-site/src/components/style-book/index.js +++ b/packages/edit-site/src/components/style-book/index.js @@ -228,6 +228,13 @@ function StyleBook( { isSelected, onSelect, onClose } ) { .edit-site-style-book__example-preview { width: 100%; } + + .edit-site-style-book__example-preview .is-root-container > .wp-block:first-child { + margin-top: 0; + } + .edit-site-style-book__example-preview .is-root-container > .wp-block:last-child { + margin-bottom: 0; + } ` } From 8f370706ec9f148cae6e2e19c3e51da929ab69b3 Mon Sep 17 00:00:00 2001 From: Andrew Serong <14988353+andrewserong@users.noreply.github.com> Date: Fri, 3 Mar 2023 13:56:29 +1100 Subject: [PATCH 04/12] Fix svg filters, attempt to fix tabbing behaviour --- packages/edit-site/src/components/style-book/index.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/edit-site/src/components/style-book/index.js b/packages/edit-site/src/components/style-book/index.js index e2005985bc863d..990f75d2423af4 100644 --- a/packages/edit-site/src/components/style-book/index.js +++ b/packages/edit-site/src/components/style-book/index.js @@ -239,8 +239,10 @@ function StyleBook( { isSelected, onSelect, onClose } ) { } } - tabIndex={ -1 } + tabIndex={ 0 } > + { /* Filters need to be rendered before children to avoid Safari rendering issues. */ } + { settings.svgFilters } { title ) } onClick={ onClick } + tabIndex={ 0 } > { title } From fb5e7554494fbbd30023ae59a30010462ca68153 Mon Sep 17 00:00:00 2001 From: Andrew Serong <14988353+andrewserong@users.noreply.github.com> Date: Fri, 3 Mar 2023 14:38:37 +1100 Subject: [PATCH 05/12] Add Enter key handling, button role, update e2e tests --- .../src/components/style-book/index.js | 12 ++++- test/e2e/specs/site-editor/style-book.spec.js | 52 ++++++++++++------- 2 files changed, 45 insertions(+), 19 deletions(-) diff --git a/packages/edit-site/src/components/style-book/index.js b/packages/edit-site/src/components/style-book/index.js index 990f75d2423af4..ac4aaba938db79 100644 --- a/packages/edit-site/src/components/style-book/index.js +++ b/packages/edit-site/src/components/style-book/index.js @@ -36,7 +36,7 @@ import { useMergeRefs, } from '@wordpress/compose'; import { useMemo, memo } from '@wordpress/element'; -import { ESCAPE } from '@wordpress/keycodes'; +import { ENTER, ESCAPE } from '@wordpress/keycodes'; /** * Internal dependencies @@ -173,6 +173,7 @@ function StyleBook( { isSelected, onSelect, onClose } ) { > { ( tab ) => (