Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Word Count #1624

Closed
2 changes: 2 additions & 0 deletions editor/sidebar/post-settings/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import PostTaxonomies from '../post-taxonomies';
import FeaturedImage from '../featured-image';
import DiscussionPanel from '../discussion-panel';
import LastRevision from '../last-revision';
import WordCount from '../word-count';

const PostSettings = ( { toggleSidebar } ) => {
return (
Expand All @@ -37,6 +38,7 @@ const PostSettings = ( { toggleSidebar } ) => {
</div>
</PanelHeader>
<PostStatus />
<WordCount />
<LastRevision />
<PostTaxonomies />
<FeaturedImage />
Expand Down
27 changes: 27 additions & 0 deletions editor/sidebar/word-count/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* External dependencies
*/
import { connect } from 'react-redux';

/**
* WordPress dependencies
*/
import { __ } from 'i18n';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note with #2172, these need to be updated to prefix the dependencies with @wordpress/. You will need to perform a rebase against the latest version of master and apply your changes:

git fetch origin
git rebase origin/master

import PanelBody from 'components/panel/body';
import { getBlocks } from '../../selectors';
import { serialize } from 'blocks';

function WordCount( { content } ) {
const wordCount = wp.utils.WordCounter.prototype.count( content );
return (
<PanelBody><strong>{ __( 'Word Count' ) }: </strong>{ wordCount }</PanelBody>
);
}

export default connect(
( state ) => {
return {
content: serialize( getBlocks( state ) ),
};
}
)( WordCount );
13 changes: 10 additions & 3 deletions lib/client-assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,16 @@ function gutenberg_editor_scripts_and_styles( $hook ) {
wp_enqueue_script(
'wp-editor',
gutenberg_url( 'editor/build/index.js' ),
array( 'wp-api', 'wp-date', 'wp-i18n', 'wp-blocks', 'wp-element', 'wp-components', 'wp-utils' ),
array(
'wp-api',
'wp-date',
'wp-i18n',
'wp-blocks',
'wp-element',
'wp-components',
'wp-utils',
'word-count',
),
filemtime( gutenberg_dir_path() . 'editor/build/index.js' ),
true // enqueue in the footer.
);
Expand All @@ -438,8 +447,6 @@ function gutenberg_editor_scripts_and_styles( $hook ) {
// `wp-utils` doesn't clobbber `word-count`. See WordPress/gutenberg#1569.
$word_count_script = wp_scripts()->query( 'word-count' );
array_push( $word_count_script->deps, 'wp-utils' );
// Now load the `word-count` script from core.
wp_enqueue_script( 'word-count' );

$post_id = null;
if ( isset( $_GET['post_id'] ) && (int) $_GET['post_id'] > 0 ) {
Expand Down