diff --git a/editor/sidebar/post-settings/index.js b/editor/sidebar/post-settings/index.js index 7d939a44e42179..cf9ee483a3f7a9 100644 --- a/editor/sidebar/post-settings/index.js +++ b/editor/sidebar/post-settings/index.js @@ -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 ( @@ -37,6 +38,7 @@ const PostSettings = ( { toggleSidebar } ) => { + diff --git a/editor/sidebar/word-count/index.js b/editor/sidebar/word-count/index.js new file mode 100644 index 00000000000000..594ceb61e78d2a --- /dev/null +++ b/editor/sidebar/word-count/index.js @@ -0,0 +1,27 @@ +/** + * External dependencies + */ +import { connect } from 'react-redux'; + +/** + * WordPress dependencies + */ +import { __ } from 'i18n'; +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 ( + { __( 'Word Count' ) }: { wordCount } + ); +} + +export default connect( + ( state ) => { + return { + content: serialize( getBlocks( state ) ), + }; + } +)( WordCount ); diff --git a/lib/client-assets.php b/lib/client-assets.php index 4adc798b7abbdd..da7e3b3eb62c47 100644 --- a/lib/client-assets.php +++ b/lib/client-assets.php @@ -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. ); @@ -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 ) {