Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bootstrap the sections exploded view #40314

Closed
wants to merge 18 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/block-editor/README.md
Expand Up @@ -173,6 +173,10 @@ _Related_

Undocumented declaration.

### BlockLockToolbar

Undocumented declaration.

### BlockMover

_Related_
Expand Down
13 changes: 3 additions & 10 deletions packages/block-editor/src/components/block-preview/README.md
Expand Up @@ -35,16 +35,9 @@ Width of the preview container in pixels. Controls at what size the blocks will

Padding for the preview container body.

### `__experimentalLive`
### `__experimentalScale`

- **Type** `Boolean`
- **Default:** `false`
- **Default:** `true`

Enables displaying previews without an iframe container.

### `__experimentalOnClick`

- **Type** `Function`
- **Default:** `undefined`

Use this callback in combination with `__experimentalLive`. The callback is attached to the preview container element.
Enables displaying previews without an iframe container.
11 changes: 9 additions & 2 deletions packages/block-editor/src/components/block-preview/auto.js
Expand Up @@ -23,6 +23,7 @@ function AutoBlockPreview( {
viewportWidth,
__experimentalPadding,
__experimentalMinHeight,
__experimentalScale = true,
} ) {
const [
containerResizeListener,
Expand Down Expand Up @@ -58,7 +59,10 @@ function AutoBlockPreview( {
// Initialize on render instead of module top level, to avoid circular dependency issues.
MemoizedBlockList = MemoizedBlockList || pure( BlockList );

const scale = containerWidth / viewportWidth;
const scale =
__experimentalScale === true
? containerWidth / viewportWidth
: __experimentalScale;

return (
<div className="block-editor-block-preview__container">
Expand Down Expand Up @@ -97,7 +101,10 @@ function AutoBlockPreview( {
tabIndex={ -1 }
style={ {
position: 'absolute',
width: viewportWidth,
width:
__experimentalScale === true
? viewportWidth
: 'calc( 100% / ' + __experimentalScale + ' )',
height: contentHeight,
pointerEvents: 'none',
// This is a catch-all max-height for patterns.
Expand Down
19 changes: 7 additions & 12 deletions packages/block-editor/src/components/block-preview/index.js
Expand Up @@ -18,7 +18,6 @@ import { memo, useMemo } from '@wordpress/element';
* Internal dependencies
*/
import BlockEditorProvider from '../provider';
import LiveBlockPreview from './live';
import AutoHeightBlockPreview from './auto';
import { store as blockEditorStore } from '../../store';
import { BlockListItems } from '../block-list';
Expand All @@ -27,8 +26,7 @@ export function BlockPreview( {
blocks,
__experimentalPadding = 0,
viewportWidth = 1200,
__experimentalLive = false,
__experimentalOnClick,
__experimentalScale = true,
__experimentalMinHeight,
} ) {
const originalSettings = useSelect(
Expand All @@ -46,15 +44,12 @@ export function BlockPreview( {
}
return (
<BlockEditorProvider value={ renderedBlocks } settings={ settings }>
{ __experimentalLive ? (
<LiveBlockPreview onClick={ __experimentalOnClick } />
) : (
<AutoHeightBlockPreview
viewportWidth={ viewportWidth }
__experimentalPadding={ __experimentalPadding }
__experimentalMinHeight={ __experimentalMinHeight }
/>
) }
<AutoHeightBlockPreview
viewportWidth={ viewportWidth }
__experimentalPadding={ __experimentalPadding }
__experimentalMinHeight={ __experimentalMinHeight }
__experimentalScale={ __experimentalScale }
/>
</BlockEditorProvider>
);
}
Expand Down
24 changes: 0 additions & 24 deletions packages/block-editor/src/components/block-preview/live.js

This file was deleted.

15 changes: 9 additions & 6 deletions packages/block-editor/src/components/block-tools/style.scss
Expand Up @@ -52,7 +52,8 @@
.block-editor-block-list__empty-block-inserter,
.block-editor-default-block-appender,
.block-editor-block-list__insertion-point-inserter,
.block-editor-block-list__block-popover-inserter {
.block-editor-block-list__block-popover-inserter,
.edit-site-block-list-exploded__inserter {
.block-editor-inserter__toggle.components-button.has-icon {
// Basic look
background: $gray-900;
Expand All @@ -70,11 +71,13 @@
}
}
}

.block-editor-block-list__insertion-point-inserter .block-editor-inserter__toggle.components-button.has-icon {
background: var(--wp-admin-theme-color);
&:hover {
background: $gray-900;
.edit-site-block-list-exploded__inserter,
.block-editor-block-list__insertion-point-inserter {
.block-editor-inserter__toggle.components-button.has-icon {
background: var(--wp-admin-theme-color);
&:hover {
background: $gray-900;
}
}
}

Expand Down
1 change: 1 addition & 0 deletions packages/block-editor/src/components/index.js
Expand Up @@ -108,6 +108,7 @@ export { default as BlockInspector } from './block-inspector';
export { default as BlockList } from './block-list';
export { useBlockProps } from './block-list/use-block-props';
export { LayoutStyle as __experimentalLayoutStyle } from './block-list/layout';
export { default as BlockLockToolbar } from './block-lock/toolbar';
export { default as BlockMover } from './block-mover';
export {
default as BlockPreview,
Expand Down
Expand Up @@ -65,9 +65,7 @@ export default function QuickInserter( {
setInserterIsOpened: settings.__experimentalSetIsInserterOpened,
prioritizePatterns:
settings.__experimentalPreferPatternsOnRoot &&
! rootClientId &&
index > 0 &&
( index < blockCount || blockCount === 0 ),
! rootClientId,
insertionIndex: index === -1 ? blockCount : index,
};
},
Expand Down
98 changes: 53 additions & 45 deletions packages/edit-site/src/components/block-editor/index.js
Expand Up @@ -40,6 +40,7 @@ import BlockInspectorButton from './block-inspector-button';
import EditTemplatePartMenuButton from '../edit-template-part-menu-button';
import BackButton from './back-button';
import ResizableEditor from './resizable-editor';
import BlockListExploded from '../block-list-exploded';

const LAYOUT = {
type: 'default',
Expand All @@ -48,7 +49,7 @@ const LAYOUT = {
};

export default function BlockEditor( { setIsInserterOpen } ) {
const { settings } = useSelect(
const { settings, editorMode } = useSelect(
( select ) => {
let storedSettings = select( editSiteStore ).getSettings(
setIsInserterOpen
Expand All @@ -74,6 +75,7 @@ export default function BlockEditor( { setIsInserterOpen } ) {

return {
settings: storedSettings,
editorMode: select( editSiteStore ).getEditorMode(),
};
},
[ setIsInserterOpen ]
Expand Down Expand Up @@ -158,52 +160,58 @@ export default function BlockEditor( { setIsInserterOpen } ) {
<SidebarInspectorFill>
<BlockInspector />
</SidebarInspectorFill>
<BlockTools
className={ classnames( 'edit-site-visual-editor', {
'is-focus-mode': isTemplatePart,
} ) }
__unstableContentRef={ contentRef }
onClick={ ( event ) => {
// Clear selected block when clicking on the gray background.
if ( event.target === event.currentTarget ) {
clearSelectedBlock();
}
} }
>
<BlockEditorKeyboardShortcuts.Register />
<BackButton />
<ResizableEditor
// Reinitialize the editor and reset the states when the template changes.
key={ templateId }
enableResizing={
isTemplatePart &&
// Disable resizing in mobile viewport.
! isMobileViewport
}
settings={ settings }
contentRef={ mergedRefs }
{ editorMode === 'exploded' && <BlockListExploded /> }

{ editorMode === 'visual' && (
<BlockTools
className={ classnames( 'edit-site-visual-editor', {
'is-focus-mode': isTemplatePart,
} ) }
__unstableContentRef={ contentRef }
onClick={ ( event ) => {
// Clear selected block when clicking on the gray background.
if ( event.target === event.currentTarget ) {
clearSelectedBlock();
}
} }
>
<BlockList
className="edit-site-block-editor__block-list wp-site-blocks"
__experimentalLayout={ LAYOUT }
renderAppender={ isTemplatePart ? false : undefined }
/>
</ResizableEditor>
<__unstableBlockSettingsMenuFirstItem>
{ ( { onClose } ) => (
<BlockInspectorButton onClick={ onClose } />
) }
</__unstableBlockSettingsMenuFirstItem>
<__unstableBlockToolbarLastItem>
<__unstableBlockNameContext.Consumer>
{ ( blockName ) =>
blockName === 'core/navigation' && (
<MaybeNavMenuSidebarToggle />
)
<BlockEditorKeyboardShortcuts.Register />
<BackButton />
<ResizableEditor
// Reinitialize the editor and reset the states when the template changes.
key={ templateId }
enableResizing={
isTemplatePart &&
// Disable resizing in mobile viewport.
! isMobileViewport
}
</__unstableBlockNameContext.Consumer>
</__unstableBlockToolbarLastItem>
</BlockTools>
settings={ settings }
contentRef={ mergedRefs }
>
<BlockList
className="edit-site-block-editor__block-list wp-site-blocks"
__experimentalLayout={ LAYOUT }
renderAppender={
isTemplatePart ? false : undefined
}
/>
</ResizableEditor>
<__unstableBlockSettingsMenuFirstItem>
{ ( { onClose } ) => (
<BlockInspectorButton onClick={ onClose } />
) }
</__unstableBlockSettingsMenuFirstItem>
<__unstableBlockToolbarLastItem>
<__unstableBlockNameContext.Consumer>
{ ( blockName ) =>
blockName === 'core/navigation' && (
<MaybeNavMenuSidebarToggle />
)
}
</__unstableBlockNameContext.Consumer>
</__unstableBlockToolbarLastItem>
</BlockTools>
) }
<ReusableBlocksMenuItems />
</BlockEditorProvider>
);
Expand Down
@@ -0,0 +1,4 @@
## BlockListExploded Component

This is an experimental component being built to implement the exploded view in the site editor.
The potential goal for this component is to be a component that can be used by any block editor, so it's important to keep its dependencies minimal. (block-editor dependencies). Eventually, it should be moved to the `@wordpress/block-editor` package.
37 changes: 37 additions & 0 deletions packages/edit-site/src/components/block-list-exploded/index.js
@@ -0,0 +1,37 @@
/**
* WordPress dependencies
*/
import { store as blockEditorStore, Inserter } from '@wordpress/block-editor';
import { useSelect } from '@wordpress/data';
import { pure } from '@wordpress/compose';

/**
* Internal dependencies
*/
import BlockListExplodedItem from './item';

const InserterBeforeBlock = pure( ( { clientId } ) => (
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't know we had this HoC. Should I prefer using this over React.memo?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be honest at this point, I don't know. What's certain is that we need to make a decision :P. This HoC was here before React introduced React.memo and if I'm not wrong also works for Class component contrary to React.memo which I think is only suited for function components.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, React.memo works only with functional components.

What's certain is that we need to make a decision

Got it. Use React.memo with function components use pure with Class components 😄

<div className="edit-site-block-list-exploded__inserter" key={ clientId }>
<Inserter clientId={ clientId } __experimentalIsQuick isPrimary />
</div>
) );

function BlockListExploded() {
const blockOrder = useSelect( ( select ) => {
return select( blockEditorStore ).getBlockOrder();
}, [] );

return (
<div className="edit-site-block-list-exploded">
{ blockOrder.map( ( clientId ) => (
<div key={ clientId }>
<InserterBeforeBlock clientId={ clientId } />
<BlockListExplodedItem clientId={ clientId } />
</div>
) ) }
<InserterBeforeBlock />
</div>
);
}

export default BlockListExploded;