Skip to content
This repository was archived by the owner on May 31, 2020. It is now read-only.

Conversation

@freedomlang
Copy link
Collaborator

@freedomlang freedomlang commented Oct 13, 2018

Resolve #23

@juliankrispel
Copy link
Member

import { getWordCount } from '@djsp/utils'
import { EditorContainer, Plugin, Editor } from '@djsp/core'

<EditorContainer>
  <Plugin>{({ editorState }) => getWordCount(editorState)}</Plugin>
  <Editor />
</EditorContainer>

@freedomlang freedomlang changed the title feat: add counter plugin feat: add a few function to utils for count Oct 28, 2018
Copy link
Member

@juliankrispel juliankrispel left a comment

Choose a reason for hiding this comment

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

Looks great! I'll help with getting it merged 👍 - if you could address some of the concerns that'd be fabbb!

onChange={this.onChange}>
<div>Char count: {getCharCount(this.state.editorState)}</div>
<div>Word count: {getWordCount(this.state.editorState)}</div>
<div>Line count: {getLineCount(this.state.editorState)}</div>
Copy link
Member

Choose a reason for hiding this comment

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

Make this a separate component WordCountPlugin.js

export default () => <Plugin>{({ editorState }) => <Fragment>
          <div>Char count: {getCharCount(this.state.editorState)}</div>
          <div>Word count: {getWordCount(this.state.editorState)}</div>
          <div>Line count: {getLineCount(this.state.editorState)}</div>
</Fragment>

And import it to index.js

@@ -1,4 +1,5 @@
import { AtomicBlockUtils, RichUtils, EditorState, Modifier } from 'draft-js';
import punycode from 'punycode';
Copy link
Member

Choose a reason for hiding this comment

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

How big is this dependency? Also, it needs to be added to external in the rollup config

Copy link
Member

Choose a reason for hiding this comment

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

why do we need this exactly?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This dependency used for handle unicode characters.

It's size is 142B(MINIFIED). Still need to added it into external?

@@ -1,8 +1,11 @@
'use strict';

Object.defineProperty(exports, '__esModule', { value: true });
Copy link
Member

Choose a reason for hiding this comment

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

dist folder should be ignored (let's check the .gitignore file

{
"name": "@djsp/utils",
"version": "0.0.3",
"version": "0.0.4",
Copy link
Member

Choose a reason for hiding this comment

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

this will update after a rebase

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ah, after git rebase master, the version updated to 0.1.5. Not sure if it is right

Modifier,
} from 'draft-js'
import type DraftEntityInstance from 'draft-js/lib/DraftEntityInstance'
// eslint-disable-next-line
Copy link
Member

Choose a reason for hiding this comment

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

shouldn't need to use the eslint comment here

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Eslint will throw error about deprecated-api. So i add eslint-disable-next-line node/no-deprecated-api in the next commit

return entity && entity.getType() === entityType
}

export function getCharCount(editorState: EditorState): number {
Copy link
Member

Choose a reason for hiding this comment

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

does this pass flow?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Currently, @djsp/utils can not pass flow. Looks like missing some files in flow-lib

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants