-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Show workflows in inserter Add selector for getting inserter workflow items Stub out workflow items in inserter Avoid computing draggable blocks for non-draggable items Spread items to flatten them rather than creating a nested array Fix error thrown for non-draggable inserter block Show workflow component when selecting workflow Fix order of items returned from hook Pass root client id to workflows Remove unused property Make header and footer the active workflows Use proper area label Insert the template part block Use same classname as other modal Show existing template parts in modal Add non-area template part workflow Avoid showing empty sections Change inserter panel title Remove existing template parts from modal Iteration 2: Try an `insert` block API Add `insert` property to inserter items selector result Show `insert` component for inserter items that have one Refactor callbacks Use pattern name for created template part Iteration 3: Launch modal from inserted block Reorganise components and utils Revert "Iteration 3: Launch modal from inserted block" This reverts commit 3d04accc51fd04e169fd4567f76cb4a5b85bfa92. Refactor template part selection modal to be more generic More refactoring Fix close button Fix non-pluralized text Fix naming nitpick Refactor to use `inserterItem` API
- Loading branch information
Showing
20 changed files
with
535 additions
and
334 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
134 changes: 134 additions & 0 deletions
134
packages/block-editor/src/components/inserter-list-item/base.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import classnames from 'classnames'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { __experimentalTruncate as Truncate } from '@wordpress/components'; | ||
import { useMemo, useRef, memo } from '@wordpress/element'; | ||
import { | ||
createBlock, | ||
createBlocksFromInnerBlocksTemplate, | ||
} from '@wordpress/blocks'; | ||
import { ENTER, isAppleOS } from '@wordpress/keycodes'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import BlockIcon from '../block-icon'; | ||
import { InserterListboxItem } from '../inserter-listbox'; | ||
import InserterDraggableBlocks from '../inserter-draggable-blocks'; | ||
|
||
function InserterListItem( { | ||
className, | ||
isFirst, | ||
item, | ||
onSelect, | ||
onHover, | ||
isDraggable, | ||
...props | ||
} ) { | ||
const isDragging = useRef( false ); | ||
const itemIconStyle = item.icon | ||
? { | ||
backgroundColor: item.icon.background, | ||
color: item.icon.foreground, | ||
} | ||
: {}; | ||
const blocks = useMemo( () => { | ||
return [ | ||
createBlock( | ||
item.name, | ||
item.initialAttributes, | ||
createBlocksFromInnerBlocksTemplate( item.innerBlocks ) | ||
), | ||
]; | ||
}, [ item.name, item.initialAttributes, item.initialAttributes ] ); | ||
|
||
return ( | ||
<InserterDraggableBlocks | ||
isEnabled={ isDraggable && ! item.disabled } | ||
blocks={ blocks } | ||
icon={ item.icon } | ||
> | ||
{ ( { draggable, onDragStart, onDragEnd } ) => ( | ||
<div | ||
className="block-editor-block-types-list__list-item" | ||
draggable={ draggable } | ||
onDragStart={ ( event ) => { | ||
isDragging.current = true; | ||
if ( onDragStart ) { | ||
onHover( null ); | ||
onDragStart( event ); | ||
} | ||
} } | ||
onDragEnd={ ( event ) => { | ||
isDragging.current = false; | ||
if ( onDragEnd ) { | ||
onDragEnd( event ); | ||
} | ||
} } | ||
> | ||
<InserterListboxItem | ||
isFirst={ isFirst } | ||
className={ classnames( | ||
'block-editor-block-types-list__item', | ||
className | ||
) } | ||
disabled={ item.isDisabled } | ||
onClick={ ( event ) => { | ||
event.preventDefault(); | ||
onSelect( | ||
item, | ||
isAppleOS() ? event.metaKey : event.ctrlKey | ||
); | ||
onHover( null ); | ||
} } | ||
onKeyDown={ ( event ) => { | ||
const { keyCode } = event; | ||
if ( keyCode === ENTER ) { | ||
event.preventDefault(); | ||
onSelect( | ||
item, | ||
isAppleOS() ? event.metaKey : event.ctrlKey | ||
); | ||
onHover( null ); | ||
} | ||
} } | ||
onFocus={ () => { | ||
if ( isDragging.current ) { | ||
return; | ||
} | ||
onHover( item ); | ||
} } | ||
onMouseEnter={ () => { | ||
if ( isDragging.current ) { | ||
return; | ||
} | ||
onHover( item ); | ||
} } | ||
onMouseLeave={ () => onHover( null ) } | ||
onBlur={ () => onHover( null ) } | ||
{ ...props } | ||
> | ||
<span | ||
className="block-editor-block-types-list__item-icon" | ||
style={ itemIconStyle } | ||
> | ||
<BlockIcon icon={ item.icon } showColors /> | ||
</span> | ||
<span className="block-editor-block-types-list__item-title"> | ||
<Truncate numberOfLines={ 3 }> | ||
{ item.title } | ||
</Truncate> | ||
</span> | ||
</InserterListboxItem> | ||
</div> | ||
) } | ||
</InserterDraggableBlocks> | ||
); | ||
} | ||
|
||
export default memo( InserterListItem ); |
136 changes: 8 additions & 128 deletions
136
packages/block-editor/src/components/inserter-list-item/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,134 +1,14 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import classnames from 'classnames'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { useMemo, useRef, memo } from '@wordpress/element'; | ||
import { | ||
createBlock, | ||
createBlocksFromInnerBlocksTemplate, | ||
} from '@wordpress/blocks'; | ||
import { __experimentalTruncate as Truncate } from '@wordpress/components'; | ||
import { ENTER, isAppleOS } from '@wordpress/keycodes'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import BlockIcon from '../block-icon'; | ||
import { InserterListboxItem } from '../inserter-listbox'; | ||
import InserterDraggableBlocks from '../inserter-draggable-blocks'; | ||
import InserterListItemBase from './base'; | ||
|
||
function InserterListItem( { | ||
className, | ||
isFirst, | ||
item, | ||
onSelect, | ||
onHover, | ||
isDraggable, | ||
...props | ||
} ) { | ||
const isDragging = useRef( false ); | ||
const itemIconStyle = item.icon | ||
? { | ||
backgroundColor: item.icon.background, | ||
color: item.icon.foreground, | ||
} | ||
: {}; | ||
const blocks = useMemo( () => { | ||
return [ | ||
createBlock( | ||
item.name, | ||
item.initialAttributes, | ||
createBlocksFromInnerBlocksTemplate( item.innerBlocks ) | ||
), | ||
]; | ||
}, [ item.name, item.initialAttributes, item.initialAttributes ] ); | ||
export default function InserterListItem( props ) { | ||
const { inserterItem: InserterItem } = props.item; | ||
|
||
return ( | ||
<InserterDraggableBlocks | ||
isEnabled={ isDraggable && ! item.disabled } | ||
blocks={ blocks } | ||
icon={ item.icon } | ||
> | ||
{ ( { draggable, onDragStart, onDragEnd } ) => ( | ||
<div | ||
className="block-editor-block-types-list__list-item" | ||
draggable={ draggable } | ||
onDragStart={ ( event ) => { | ||
isDragging.current = true; | ||
if ( onDragStart ) { | ||
onHover( null ); | ||
onDragStart( event ); | ||
} | ||
} } | ||
onDragEnd={ ( event ) => { | ||
isDragging.current = false; | ||
if ( onDragEnd ) { | ||
onDragEnd( event ); | ||
} | ||
} } | ||
> | ||
<InserterListboxItem | ||
isFirst={ isFirst } | ||
className={ classnames( | ||
'block-editor-block-types-list__item', | ||
className | ||
) } | ||
disabled={ item.isDisabled } | ||
onClick={ ( event ) => { | ||
event.preventDefault(); | ||
onSelect( | ||
item, | ||
isAppleOS() ? event.metaKey : event.ctrlKey | ||
); | ||
onHover( null ); | ||
} } | ||
onKeyDown={ ( event ) => { | ||
const { keyCode } = event; | ||
if ( keyCode === ENTER ) { | ||
event.preventDefault(); | ||
onSelect( | ||
item, | ||
isAppleOS() ? event.metaKey : event.ctrlKey | ||
); | ||
onHover( null ); | ||
} | ||
} } | ||
onFocus={ () => { | ||
if ( isDragging.current ) { | ||
return; | ||
} | ||
onHover( item ); | ||
} } | ||
onMouseEnter={ () => { | ||
if ( isDragging.current ) { | ||
return; | ||
} | ||
onHover( item ); | ||
} } | ||
onMouseLeave={ () => onHover( null ) } | ||
onBlur={ () => onHover( null ) } | ||
{ ...props } | ||
> | ||
<span | ||
className="block-editor-block-types-list__item-icon" | ||
style={ itemIconStyle } | ||
> | ||
<BlockIcon icon={ item.icon } showColors /> | ||
</span> | ||
<span className="block-editor-block-types-list__item-title"> | ||
<Truncate numberOfLines={ 3 }> | ||
{ item.title } | ||
</Truncate> | ||
</span> | ||
</InserterListboxItem> | ||
</div> | ||
) } | ||
</InserterDraggableBlocks> | ||
); | ||
} | ||
if ( InserterItem ) { | ||
return <InserterItem { ...props } />; | ||
} | ||
|
||
export default memo( InserterListItem ); | ||
return <InserterListItemBase { ...props } />; | ||
} |
39 changes: 39 additions & 0 deletions
39
packages/block-editor/src/components/inserter-list-item/with-modal.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { Modal } from '@wordpress/components'; | ||
import { useState } from '@wordpress/element'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import InserterListItem from './base'; | ||
|
||
export default function InserterListItemWithModal( { | ||
modalProps, | ||
children, | ||
...props | ||
} ) { | ||
const [ isModalVisible, setIsModalVisible ] = useState( false ); | ||
|
||
return ( | ||
<> | ||
<InserterListItem | ||
{ ...props } | ||
onSelect={ () => setIsModalVisible( true ) } | ||
aria-haspopup="dialog" | ||
aria-expanded={ isModalVisible } | ||
/> | ||
{ isModalVisible && ( | ||
<Modal | ||
{ ...modalProps } | ||
onRequestClose={ () => { | ||
setIsModalVisible( false ); | ||
} } | ||
> | ||
{ children } | ||
</Modal> | ||
) } | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.