Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 19 additions & 11 deletions packages/edit-site/src/components/site-editor-routes/styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ import SidebarNavigationScreenGlobalStyles from '../sidebar-navigation-screen-gl
import SidebarGlobalStyles from '../sidebar-global-styles';

const { useLocation, useHistory } = unlock( routerPrivateApis );
const { StyleBookPreview } = unlock( editorPrivateApis );
const { StyleBookPreview, useGlobalStyles } = unlock( editorPrivateApis );

function StylesPreviewArea( { siteData } ) {
function StyleBookPreviewArea( { siteData } ) {
const { path, query } = useLocation();
const history = useHistory();
const isStylebook = query.preview === 'stylebook';
const { user: userConfig } = useGlobalStyles();
Comment thread
ramonjd marked this conversation as resolved.
Resolved

// Get section from URL query params
const section = query.section ?? '/';
Expand All @@ -31,14 +31,22 @@ function StylesPreviewArea( { siteData } ) {
);
};

if ( isStylebook ) {
return (
<StyleBookPreview
path={ section }
onPathChange={ onChangeSection }
settings={ siteData.editorSettings }
/>
);
return (
<StyleBookPreview
path={ section }
onPathChange={ onChangeSection }
settings={ siteData.editorSettings }
// Without userConfig the preview falls back to the static `settings` styles and unsaved global styles edits are not shown.
userConfig={ userConfig }
/>
);
}

function StylesPreviewArea( { siteData } ) {
const { query } = useLocation();

if ( query.preview === 'stylebook' ) {
return <StyleBookPreviewArea siteData={ siteData } />;
}

return <Editor />;
Expand Down
27 changes: 27 additions & 0 deletions test/e2e/specs/site-editor/style-book.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,33 @@ test.describe( 'Style Book', () => {
).toBeVisible();
} );

test( 'should reflect unsaved global styles edits', async ( { page } ) => {
const styleBookIframe = page.frameLocator(
'[name="style-book-canvas"]'
);
await expect(
styleBookIframe.getByRole( 'grid', { name: 'Examples of blocks' } )
).toBeVisible();

// Edit the user global styles without saving.
await page.evaluate( async () => {
const globalStylesId = await window.wp.data
.resolveSelect( 'core' )
.__experimentalGetCurrentGlobalStylesId();
window.wp.data
.dispatch( 'core' )
.editEntityRecord( 'root', 'globalStyles', globalStylesId, {
styles: { color: { background: '#ff0000' } },
} );
} );

// The Style Book should pick up the edit without a save or reload.
await expect( styleBookIframe.locator( 'body' ) ).toHaveCSS(
'background-color',
'rgb(255, 0, 0)'
);
} );

test( 'should allow opening the command menu from the header when open', async ( {
page,
} ) => {
Expand Down
Loading