-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Expand file tree
/
Copy pathindex.js
More file actions
66 lines (58 loc) · 1.52 KB
/
index.js
File metadata and controls
66 lines (58 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/**
* External dependencies
*/
import { connect } from 'react-redux';
import { get } from 'lodash';
/**
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { getDefaultBlockName } from '@wordpress/blocks';
/**
* Internal dependencies
*/
import './style.scss';
import BlockDropZone from '../block-drop-zone';
import { appendDefaultBlock, startTyping } from '../../store/actions';
import { getBlock, getBlockCount } from '../../store/selectors';
export function DefaultBlockAppender( { isVisible, onAppend, showPrompt } ) {
if ( ! isVisible ) {
return null;
}
return (
<div className="editor-default-block-appender">
<BlockDropZone />
<input
className="editor-default-block-appender__content"
type="text"
readOnly
onFocus={ onAppend }
onClick={ onAppend }
onKeyDown={ onAppend }
value={ showPrompt ? __( 'Write your story' ) : '' }
/>
</div>
);
}
export default connect(
( state, ownProps ) => {
const isEmpty = ! getBlockCount( state, ownProps.rootUID );
const lastBlock = getBlock( state, ownProps.lastBlockUID );
const isLastBlockDefault = get( lastBlock, 'name' ) === getDefaultBlockName();
return {
isVisible: isEmpty || ! isLastBlockDefault,
showPrompt: isEmpty,
};
},
( dispatch, ownProps ) => ( {
onAppend() {
const { layout, rootUID } = ownProps;
let attributes;
if ( layout ) {
attributes = { layout };
}
dispatch( appendDefaultBlock( attributes, rootUID ) );
dispatch( startTyping() );
},
} ),
)( DefaultBlockAppender );