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

Send contentInfo information when updating HTML. #23115

Merged
merged 12 commits into from
Jun 16, 2020
20 changes: 16 additions & 4 deletions packages/editor/src/components/provider/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import RNReactNativeGutenbergBridge, {
* WordPress dependencies
*/
import { Component } from '@wordpress/element';
import { count as wordCount } from '@wordpress/wordcount';
import {
parse,
serialize,
Expand Down Expand Up @@ -181,10 +182,20 @@ class NativeEditorProvider extends Component {
const hasChanges =
title !== this.post.title.raw || html !== this.post.content.raw;

// Variable to store the content structure metrics.
const contentInfo = {};
contentInfo.characterCount = wordCount(
html,
'characters_including_spaces'
);
contentInfo.wordCount = wordCount( html, 'words' );
contentInfo.paragraphCount = this.props.paragraphCount;
contentInfo.blockCount = this.props.blockCount;
RNReactNativeGutenbergBridge.provideToNative_Html(
html,
title,
hasChanges
hasChanges,
contentInfo
);

if ( hasChanges ) {
Expand Down Expand Up @@ -228,7 +239,7 @@ class NativeEditorProvider extends Component {
}

export default compose( [
withSelect( ( select, { rootClientId } ) => {
withSelect( ( select ) => {
const {
__unstableIsEditorReady: isEditorReady,
getEditorBlocks,
Expand All @@ -238,9 +249,9 @@ export default compose( [
const { getEditorMode } = select( 'core/edit-post' );

const {
getBlockCount,
getBlockIndex,
getSelectedBlockClientId,
getGlobalBlockCount,
} = select( 'core/block-editor' );

const selectedBlockClientId = getSelectedBlockClientId();
Expand All @@ -251,7 +262,8 @@ export default compose( [
title: getEditedPostAttribute( 'title' ),
getEditedPostContent,
selectedBlockIndex: getBlockIndex( selectedBlockClientId ),
blockCount: getBlockCount( rootClientId ),
blockCount: getGlobalBlockCount(),
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like getBlockCount is not needed anymore and we can remove it from the extraction list above, right?

paragraphCount: getGlobalBlockCount( 'core/paragraph' ),
};
} ),
withDispatch( ( dispatch ) => {
Expand Down