Skip to content

Commit

Permalink
Remove BlockEditorProvider from BlockList and add native version of E…
Browse files Browse the repository at this point in the history
…ditorProvider to Editor. Plus support InsertionPoint and BlockListAppender
  • Loading branch information
Tug committed Aug 8, 2019
1 parent b685fb1 commit ea77a0b
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 0 deletions.
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 );
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;
}
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 );

0 comments on commit ea77a0b

Please sign in to comment.