-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds the gutenberg-off-canvas-navigation-editor experiment
- Loading branch information
1 parent
1386ec3
commit f8b5323
Showing
17 changed files
with
2,182 additions
and
0 deletions.
There are no files selected for viewing
5 changes: 5 additions & 0 deletions
5
packages/block-editor/src/components/off-canvas-editor/README.md
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,5 @@ | ||
# Experimental Off Canvas Editor | ||
|
||
The __ExperimentalOffCanvasEditor component is a modified ListView compoent. It provides an overview of the hierarchical structure of all blocks in the editor. The blocks are presented vertically one below the other. It enables editing of hierarchy and addition of elements in the block tree without selecting the block instance on the canvas. | ||
|
||
It is an experimental component which may end up completely merged into the ListView component via configuration props. |
89 changes: 89 additions & 0 deletions
89
packages/block-editor/src/components/off-canvas-editor/block-contents.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,89 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import classnames from 'classnames'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { useSelect } from '@wordpress/data'; | ||
import { forwardRef } from '@wordpress/element'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import ListViewBlockSelectButton from './block-select-button'; | ||
import BlockDraggable from '../block-draggable'; | ||
import { store as blockEditorStore } from '../../store'; | ||
|
||
const ListViewBlockContents = forwardRef( | ||
( | ||
{ | ||
onClick, | ||
onToggleExpanded, | ||
block, | ||
isSelected, | ||
position, | ||
siblingBlockCount, | ||
level, | ||
isExpanded, | ||
selectedClientIds, | ||
...props | ||
}, | ||
ref | ||
) => { | ||
const { clientId } = block; | ||
|
||
const { blockMovingClientId, selectedBlockInBlockEditor } = useSelect( | ||
( select ) => { | ||
const { hasBlockMovingClientId, getSelectedBlockClientId } = | ||
select( blockEditorStore ); | ||
return { | ||
blockMovingClientId: hasBlockMovingClientId(), | ||
selectedBlockInBlockEditor: getSelectedBlockClientId(), | ||
}; | ||
}, | ||
[ clientId ] | ||
); | ||
|
||
const isBlockMoveTarget = | ||
blockMovingClientId && selectedBlockInBlockEditor === clientId; | ||
|
||
const className = classnames( 'block-editor-list-view-block-contents', { | ||
'is-dropping-before': isBlockMoveTarget, | ||
} ); | ||
|
||
// Only include all selected blocks if the currently clicked on block | ||
// is one of the selected blocks. This ensures that if a user attempts | ||
// to drag a block that isn't part of the selection, they're still able | ||
// to drag it and rearrange its position. | ||
const draggableClientIds = selectedClientIds.includes( clientId ) | ||
? selectedClientIds | ||
: [ clientId ]; | ||
|
||
return ( | ||
<BlockDraggable clientIds={ draggableClientIds }> | ||
{ ( { draggable, onDragStart, onDragEnd } ) => ( | ||
<ListViewBlockSelectButton | ||
ref={ ref } | ||
className={ className } | ||
block={ block } | ||
onClick={ onClick } | ||
onToggleExpanded={ onToggleExpanded } | ||
isSelected={ isSelected } | ||
position={ position } | ||
siblingBlockCount={ siblingBlockCount } | ||
level={ level } | ||
draggable={ draggable } | ||
onDragStart={ onDragStart } | ||
onDragEnd={ onDragEnd } | ||
isExpanded={ isExpanded } | ||
{ ...props } | ||
/> | ||
) } | ||
</BlockDraggable> | ||
); | ||
} | ||
); | ||
|
||
export default ListViewBlockContents; |
113 changes: 113 additions & 0 deletions
113
packages/block-editor/src/components/off-canvas-editor/block-select-button.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,113 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import classnames from 'classnames'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { | ||
Button, | ||
__experimentalHStack as HStack, | ||
__experimentalTruncate as Truncate, | ||
} from '@wordpress/components'; | ||
import { forwardRef } from '@wordpress/element'; | ||
import { Icon, lock } from '@wordpress/icons'; | ||
import { SPACE, ENTER } from '@wordpress/keycodes'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import BlockIcon from '../block-icon'; | ||
import useBlockDisplayInformation from '../use-block-display-information'; | ||
import useBlockDisplayTitle from '../block-title/use-block-display-title'; | ||
import ListViewExpander from './expander'; | ||
import { useBlockLock } from '../block-lock'; | ||
|
||
function ListViewBlockSelectButton( | ||
{ | ||
className, | ||
block: { clientId }, | ||
onClick, | ||
onToggleExpanded, | ||
tabIndex, | ||
onFocus, | ||
onDragStart, | ||
onDragEnd, | ||
draggable, | ||
}, | ||
ref | ||
) { | ||
const blockInformation = useBlockDisplayInformation( clientId ); | ||
const blockTitle = useBlockDisplayTitle( { | ||
clientId, | ||
context: 'list-view', | ||
} ); | ||
const { isLocked } = useBlockLock( clientId ); | ||
|
||
// The `href` attribute triggers the browser's native HTML drag operations. | ||
// When the link is dragged, the element's outerHTML is set in DataTransfer object as text/html. | ||
// We need to clear any HTML drag data to prevent `pasteHandler` from firing | ||
// inside the `useOnBlockDrop` hook. | ||
const onDragStartHandler = ( event ) => { | ||
event.dataTransfer.clearData(); | ||
onDragStart?.( event ); | ||
}; | ||
|
||
function onKeyDownHandler( event ) { | ||
if ( event.keyCode === ENTER || event.keyCode === SPACE ) { | ||
onClick( event ); | ||
} | ||
} | ||
|
||
return ( | ||
<> | ||
<Button | ||
className={ classnames( | ||
'block-editor-list-view-block-select-button', | ||
className | ||
) } | ||
onClick={ onClick } | ||
onKeyDown={ onKeyDownHandler } | ||
ref={ ref } | ||
tabIndex={ tabIndex } | ||
onFocus={ onFocus } | ||
onDragStart={ onDragStartHandler } | ||
onDragEnd={ onDragEnd } | ||
draggable={ draggable } | ||
href={ `#block-${ clientId }` } | ||
aria-hidden={ true } | ||
> | ||
<ListViewExpander onClick={ onToggleExpanded } /> | ||
<BlockIcon icon={ blockInformation?.icon } showColors /> | ||
<HStack | ||
alignment="center" | ||
className="block-editor-list-view-block-select-button__label-wrapper" | ||
justify="flex-start" | ||
spacing={ 1 } | ||
> | ||
<span className="block-editor-list-view-block-select-button__title"> | ||
<Truncate ellipsizeMode="auto">{ blockTitle }</Truncate> | ||
</span> | ||
{ blockInformation?.anchor && ( | ||
<span className="block-editor-list-view-block-select-button__anchor-wrapper"> | ||
<Truncate | ||
className="block-editor-list-view-block-select-button__anchor" | ||
ellipsizeMode="auto" | ||
> | ||
{ blockInformation.anchor } | ||
</Truncate> | ||
</span> | ||
) } | ||
{ isLocked && ( | ||
<span className="block-editor-list-view-block-select-button__lock"> | ||
<Icon icon={ lock } /> | ||
</span> | ||
) } | ||
</HStack> | ||
</Button> | ||
</> | ||
); | ||
} | ||
|
||
export default forwardRef( ListViewBlockSelectButton ); |
Oops, something went wrong.