@gechiui/block-editor
Version:
79 lines (73 loc) • 2.23 kB
JavaScript
import { createElement } from "@gechiui/element";
/**
* External dependencies
*/
import { TouchableWithoutFeedback, View } from 'react-native';
/**
* GeChiUI dependencies
*/
import { __ } from '@gechiui/i18n';
import { RichText } from '@gechiui/block-editor';
import { compose } from '@gechiui/compose';
import { decodeEntities } from '@gechiui/html-entities';
import { withSelect, withDispatch } from '@gechiui/data';
import { getDefaultBlockName } from '@gechiui/blocks';
/**
* Internal dependencies
*/
import BlockInsertionPoint from '../block-list/insertion-point';
import styles from './style.scss';
import { store as blockEditorStore } from '../../store';
export function DefaultBlockAppender(_ref) {
let {
isLocked,
isVisible,
onAppend,
placeholder,
containerStyle,
showSeparator
} = _ref;
if (isLocked || !isVisible) {
return null;
}
const value = typeof placeholder === 'string' ? decodeEntities(placeholder) : __('Start writing…');
return createElement(TouchableWithoutFeedback, {
onPress: onAppend
}, createElement(View, {
style: [styles.blockHolder, showSeparator && containerStyle],
pointerEvents: "box-only"
}, showSeparator ? createElement(BlockInsertionPoint, null) : createElement(RichText, {
placeholder: value,
onChange: () => {}
})));
}
export default compose(withSelect((select, ownProps) => {
const {
getBlockCount,
getBlockName,
isBlockValid,
getTemplateLock
} = select(blockEditorStore);
const isEmpty = !getBlockCount(ownProps.rootClientId);
const isLastBlockDefault = getBlockName(ownProps.lastBlockClientId) === getDefaultBlockName();
const isLastBlockValid = isBlockValid(ownProps.lastBlockClientId);
return {
isVisible: isEmpty || !isLastBlockDefault || !isLastBlockValid,
isLocked: !!getTemplateLock(ownProps.rootClientId)
};
}), withDispatch((dispatch, ownProps) => {
const {
insertDefaultBlock,
startTyping
} = dispatch(blockEditorStore);
return {
onAppend() {
const {
rootClientId
} = ownProps;
insertDefaultBlock(undefined, rootClientId);
startTyping();
}
};
}))(DefaultBlockAppender);
//# sourceMappingURL=index.native.js.map