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

Add initial quick inserter #22789

Merged
merged 19 commits into from
Jun 24, 2020
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
24 changes: 24 additions & 0 deletions docs/designers-developers/developers/data/data-core-edit-post.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,18 @@ _Returns_

- `boolean`: Is active.

<a name="isInserterOpened" href="#isInserterOpened">#</a> **isInserterOpened**

Returns true if the inserter is opened.

_Parameters_

- _state_ `Object`: Global application state.

_Returns_

- `boolean`: Whether the inserter is opened.

<a name="isMetaBoxLocationActive" href="#isMetaBoxLocationActive">#</a> **isMetaBoxLocationActive**

Returns true if there is an active meta box in the given location, or false
Expand Down Expand Up @@ -377,6 +389,18 @@ _Returns_

- `Object`: Action object.

<a name="setIsInserterOpened" href="#setIsInserterOpened">#</a> **setIsInserterOpened**

Returns an action object used to open/close the inserter.

_Parameters_

- _value_ `boolean`: A boolean representing whether the inserter should be opened or closed.

_Returns_

- `Object`: Action object.

<a name="showBlockTypes" href="#showBlockTypes">#</a> **showBlockTypes**

Returns an action object used in signalling that block types by the given
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ function BlockPopover( {
<Inserter
clientId={ clientId }
rootClientId={ rootClientId }
__experimentalIsQuick
/>
</div>
) }
Expand All @@ -206,9 +207,10 @@ function BlockPopover( {
{ showEmptyBlockSideInserter && (
<div className="block-editor-block-list__empty-block-inserter">
<Inserter
position="top right"
position="bottom right"
rootClientId={ rootClientId }
clientId={ clientId }
__experimentalIsQuick
/>
</div>
) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ export default function InsertionPoint( {
<Inserter
position="bottom center"
clientId={ inserterClientId }
__experimentalIsQuick
/>
</div>
</div>
Expand Down
59 changes: 59 additions & 0 deletions packages/block-editor/src/components/block-patterns-list/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/**
* WordPress dependencies
*/
import { useMemo } from '@wordpress/element';
import { parse } from '@wordpress/blocks';
import { ENTER, SPACE } from '@wordpress/keycodes';

/**
* Internal dependencies
*/
import BlockPreview from '../block-preview';

function BlockPattern( { pattern, onClick } ) {
const { content, viewportWidth } = pattern;
const blocks = useMemo( () => parse( content ), [ content ] );

return (
<div
className="block-editor-block-patterns-list__item"
role="button"
onClick={ () => onClick( pattern, blocks ) }
onKeyDown={ ( event ) => {
if ( ENTER === event.keyCode || SPACE === event.keyCode ) {
onClick( pattern, blocks );
}
} }
tabIndex={ 0 }
aria-label={ pattern.title }
>
<BlockPreview blocks={ blocks } viewportWidth={ viewportWidth } />
<div className="block-editor-block-patterns-list__item-title">
{ pattern.title }
</div>
</div>
);
}

function BlockPatternPlaceholder() {
return (
<div className="block-editor-block-patterns-list__item is-placeholder" />
);
}

function BlockPatternList( { blockPatterns, shownPatterns, onClickPattern } ) {
return blockPatterns.map( ( pattern ) => {
const isShown = shownPatterns.includes( pattern );
return isShown ? (
<BlockPattern
key={ pattern.name }
pattern={ pattern }
onClick={ onClickPattern }
/>
) : (
<BlockPatternPlaceholder key={ pattern.name } />
);
} );
}

export default BlockPatternList;
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
.block-editor-block-patterns-list__item {

border-radius: $radius-block-ui;
cursor: pointer;
margin-top: $grid-unit-20;
transition: all 0.05s ease-in-out;
position: relative;
border: $border-width solid transparent;

&:hover {
border: $border-width solid var(--wp-admin-theme-color);
}

&:focus {
box-shadow: inset 0 0 0 1px $white, 0 0 0 $border-width-focus var(--wp-admin-theme-color);

// Windows High Contrast mode will show this outline, but not the box-shadow.
outline: 2px solid transparent;
}

&.is-placeholder {
min-height: 100px;
}
}

.block-editor-block-patterns-list__item-title {
padding: $grid-unit-05;
font-size: 12px;
text-align: center;
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ function ButtonBlockAppender(
position="bottom center"
rootClientId={ rootClientId }
__experimentalSelectBlockOnInsert={ selectBlockOnInsert }
__experimentalIsQuick
renderToggle={ ( {
onToggle,
disabled,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,9 @@ export function DefaultBlockAppender( {
/>
<Inserter
rootClientId={ rootClientId }
position="top right"
position="bottom right"
isAppender
__experimentalIsQuick
/>
</div>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ exports[`DefaultBlockAppender should append a default block when input focused 1
value="Start writing or type / to choose a block"
/>
<WithSelect(WithDispatch(IfCondition(Inserter)))
__experimentalIsQuick={true}
isAppender={true}
position="top right"
position="bottom right"
/>
</div>
`;
Expand All @@ -48,8 +49,9 @@ exports[`DefaultBlockAppender should match snapshot 1`] = `
value="Start writing or type / to choose a block"
/>
<WithSelect(WithDispatch(IfCondition(Inserter)))
__experimentalIsQuick={true}
isAppender={true}
position="top right"
position="bottom right"
/>
</div>
`;
Expand All @@ -69,8 +71,9 @@ exports[`DefaultBlockAppender should optionally show without prompt 1`] = `
value=""
/>
<WithSelect(WithDispatch(IfCondition(Inserter)))
__experimentalIsQuick={true}
isAppender={true}
position="top right"
position="bottom right"
/>
</div>
`;
Original file line number Diff line number Diff line change
Expand Up @@ -7,65 +7,17 @@ import { fromPairs } from 'lodash';
* WordPress dependencies
*/
import { useMemo, useCallback } from '@wordpress/element';
import { parse } from '@wordpress/blocks';
import { ENTER, SPACE } from '@wordpress/keycodes';
import { __, _x } from '@wordpress/i18n';
import { useAsyncList } from '@wordpress/compose';

/**
* Internal dependencies
*/
import BlockPreview from '../block-preview';
import InserterPanel from './panel';
import { searchItems } from './search-items';
import InserterNoResults from './no-results';
import usePatternsState from './hooks/use-patterns-state';

function BlockPattern( { pattern, onClick } ) {
const { content, viewportWidth } = pattern;
const blocks = useMemo( () => parse( content ), [ content ] );

return (
<div
className="block-editor-inserter__patterns-item"
role="button"
onClick={ () => onClick( pattern, blocks ) }
onKeyDown={ ( event ) => {
if ( ENTER === event.keyCode || SPACE === event.keyCode ) {
onClick( pattern, blocks );
}
} }
tabIndex={ 0 }
aria-label={ pattern.title }
>
<BlockPreview blocks={ blocks } viewportWidth={ viewportWidth } />
<div className="block-editor-inserter__patterns-item-title">
{ pattern.title }
</div>
</div>
);
}

function BlockPatternPlaceholder() {
return (
<div className="block-editor-inserter__patterns-item is-placeholder" />
);
}

function BlockPatternList( { patterns, shownPatterns, onClickPattern } ) {
return patterns.map( ( pattern ) => {
const isShown = shownPatterns.includes( pattern );
return isShown ? (
<BlockPattern
key={ pattern.name }
pattern={ pattern }
onClick={ onClickPattern }
/>
) : (
<BlockPatternPlaceholder key={ pattern.name } />
);
} );
}
import BlockPatternList from '../block-patterns-list';

function BlockPatternsSearchResults( { filterValue, onInsert } ) {
const [ patterns, , onClick ] = usePatternsState( onInsert );
Expand All @@ -81,7 +33,7 @@ function BlockPatternsSearchResults( { filterValue, onInsert } ) {
<InserterPanel title={ __( 'Search Results' ) }>
<BlockPatternList
shownPatterns={ currentShownPatterns }
patterns={ filteredPatterns }
blockPatterns={ filteredPatterns }
onClickPattern={ onClick }
/>
</InserterPanel>
Expand Down Expand Up @@ -147,7 +99,7 @@ function BlockPatternsPerCategories( { onInsert } ) {
>
<BlockPatternList
shownPatterns={ currentShownPatterns }
patterns={ categoryPatterns }
blockPatterns={ categoryPatterns }
onClickPattern={ onClick }
/>
</InserterPanel>
Expand All @@ -159,7 +111,7 @@ function BlockPatternsPerCategories( { onInsert } ) {
<InserterPanel title={ _x( 'Uncategorized' ) }>
<BlockPatternList
shownPatterns={ currentShownPatterns }
patterns={ uncategorizedPatterns }
blockPatterns={ uncategorizedPatterns }
onClickPattern={ onClick }
/>
</InserterPanel>
Expand All @@ -168,7 +120,7 @@ function BlockPatternsPerCategories( { onInsert } ) {
);
}

function BlockPatterns( { onInsert, filterValue } ) {
function BlockPatternsTabs( { onInsert, filterValue } ) {
return filterValue ? (
<BlockPatternsSearchResults
onInsert={ onInsert }
Expand All @@ -179,4 +131,4 @@ function BlockPatterns( { onInsert, filterValue } ) {
);
}

export default BlockPatterns;
export default BlockPatternsTabs;
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { addQueryArgs } from '@wordpress/url';
import { controlsRepeat } from '@wordpress/icons';
import { useMemo, useEffect } from '@wordpress/element';
import { useSelect } from '@wordpress/data';
import { compose } from '@wordpress/compose';

/**
* Internal dependencies
Expand All @@ -29,7 +28,7 @@ const getBlockNamespace = ( item ) => item.name.split( '/' )[ 0 ];

const MAX_SUGGESTED_ITEMS = 6;

export function InserterBlockList( {
export function BlockTypesTab( {
rootClientId,
onInsert,
onHover,
Expand Down Expand Up @@ -244,4 +243,4 @@ export function InserterBlockList( {
);
}

export default compose( withSpokenMessages )( InserterBlockList );
export default withSpokenMessages( BlockTypesTab );
Loading