-
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.
Remove BlockEditorProvider from BlockList and add native version of E…
…ditorProvider to Editor. Plus support InsertionPoint and BlockListAppender
- Loading branch information
Showing
3 changed files
with
109 additions
and
0 deletions.
There are no files selected for viewing
54 changes: 54 additions & 0 deletions
54
packages/block-editor/src/components/block-list-appender/index.native.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,54 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { last } from 'lodash'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { withSelect } from '@wordpress/data'; | ||
import { getDefaultBlockName } from '@wordpress/blocks'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import DefaultBlockAppender from '../default-block-appender'; | ||
import styles from './style.scss'; | ||
|
||
function BlockListAppender( { | ||
blockClientIds, | ||
rootClientId, | ||
canInsertDefaultBlock, | ||
isLocked, | ||
} ) { | ||
if ( isLocked ) { | ||
return null; | ||
} | ||
|
||
if ( canInsertDefaultBlock ) { | ||
return ( | ||
<DefaultBlockAppender | ||
rootClientId={ rootClientId } | ||
lastBlockClientId={ last( blockClientIds ) } | ||
containerStyle={ styles.blockListAppender } | ||
placeholder={ blockClientIds.length > 0 ? '' : null } | ||
/> | ||
); | ||
} | ||
|
||
return null; | ||
} | ||
|
||
export default withSelect( ( select, { rootClientId } ) => { | ||
const { | ||
getBlockOrder, | ||
canInsertBlockType, | ||
getTemplateLock, | ||
} = select( 'core/block-editor' ); | ||
|
||
return { | ||
isLocked: !! getTemplateLock( rootClientId ), | ||
blockClientIds: getBlockOrder( rootClientId ), | ||
canInsertDefaultBlock: canInsertBlockType( getDefaultBlockName(), rootClientId ), | ||
}; | ||
} )( BlockListAppender ); |
9 changes: 9 additions & 0 deletions
9
packages/block-editor/src/components/block-list-appender/style.native.scss
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,9 @@ | ||
|
||
.blockListAppender { | ||
background-color: $white; | ||
padding-left: 16; | ||
padding-right: 16; | ||
padding-top: 12; | ||
padding-bottom: 0; // will be flushed into inline toolbar height | ||
border-color: transparent; | ||
} |
46 changes: 46 additions & 0 deletions
46
packages/block-editor/src/components/block-list/insertion-point.native.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,46 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { Text, View } from 'react-native'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { __ } from '@wordpress/i18n'; | ||
import { withSelect } from '@wordpress/data'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import styles from './style.scss'; | ||
|
||
const BlockInsertionPoint = ( { showInsertionPoint } ) => { | ||
if ( ! showInsertionPoint ) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<View style={ styles.containerStyleAddHere } > | ||
<View style={ styles.lineStyleAddHere }></View> | ||
<Text style={ styles.labelStyleAddHere } >{ __( 'ADD BLOCK HERE' ) }</Text> | ||
<View style={ styles.lineStyleAddHere }></View> | ||
</View> | ||
); | ||
}; | ||
|
||
export default withSelect( ( select, { clientId, rootClientId } ) => { | ||
const { | ||
getBlockIndex, | ||
getBlockInsertionPoint, | ||
isBlockInsertionPointVisible, | ||
} = select( 'core/block-editor' ); | ||
const blockIndex = getBlockIndex( clientId, rootClientId ); | ||
const insertionPoint = getBlockInsertionPoint(); | ||
const showInsertionPoint = ( | ||
isBlockInsertionPointVisible() && | ||
insertionPoint.index === blockIndex && | ||
insertionPoint.rootClientId === rootClientId | ||
); | ||
|
||
return { showInsertionPoint }; | ||
} )( BlockInsertionPoint ); |