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

Commit 926ab28

Browse files
freedomlangjuliankrispel
authored andcommitted
optimize counter-example and fix lint error
1 parent 555952e commit 926ab28

File tree

8 files changed

+42
-8
lines changed

8 files changed

+42
-8
lines changed
File renamed without changes.

examples/counter/package.json renamed to examples/couter-example/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
{
22
"name": "@djsp/counter-example",
3-
"homepage": "https://github.com/draft-js-plugins/next",
4-
"version": "0.0.1",
3+
"homepage": "https://github.com/draft-js-plugins/next#readme",
4+
"version": "0.1.5",
55
"private": true,
66
"license": "MIT",
77
"dependencies": {
8-
"@djsp/utils": "latest",
9-
"@djsp/editor": "latest",
8+
"@djsp/utils": "^0.1.5",
9+
"@djsp/editor": "^0.1.5",
1010
"react": "^16.2.0",
1111
"react-dom": "^16.2.0",
1212
"react-scripts": "^1.1.1"
File renamed without changes.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import React, { Fragment } from 'react'
2+
import { Plugin } from '@djsp/editor'
3+
import { getCharCount, getWordCount, getLineCount } from '@djsp/utils'
4+
5+
export default function WordCountPlugin() {
6+
return (
7+
<Plugin>
8+
{({ editorState }) => (
9+
<Fragment>
10+
<div>Char count: {getCharCount(editorState)}</div>
11+
<div>Word count: {getWordCount(editorState)}</div>
12+
<div>Line count: {getLineCount(editorState)}</div>
13+
</Fragment>
14+
)}
15+
</Plugin>
16+
)
17+
}

examples/counter/src/index.js renamed to examples/couter-example/src/index.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import ReactDOM from 'react-dom'
33

44
import { EditorState, ContentState } from 'draft-js'
55
import { EditorContainer, Editor } from '@djsp/editor'
6-
import { getCharCount, getWordCount, getLineCount } from '@djsp/utils'
6+
import WordCountPlugin from './WordCountPlugin'
77
import './styles.css'
88

99
class App extends Component {
@@ -21,9 +21,7 @@ class App extends Component {
2121
<EditorContainer
2222
editorState={this.state.editorState}
2323
onChange={this.onChange}>
24-
<div>Char count: {getCharCount(this.state.editorState)}</div>
25-
<div>Word count: {getWordCount(this.state.editorState)}</div>
26-
<div>Line count: {getLineCount(this.state.editorState)}</div>
24+
<WordCountPlugin />
2725
<Editor />
2826
</EditorContainer>
2927
</div>
File renamed without changes.

packages/utils/README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,24 @@ hasEntity(
125125
insertNewLine(editorState: EditorState): EditorState
126126
```
127127

128+
### getCharCount
129+
130+
```javascript
131+
getCharCount(editorState: EditorState): number
132+
```
133+
134+
### getLineCount
135+
136+
```javascript
137+
getLineCount(editorState: EditorState): number
138+
```
139+
140+
### getWordCount
141+
142+
```javascript
143+
getWordCount(editorState: EditorState): number
144+
```
145+
128146
## License
129147

130148
MIT © [juliankrispel](https://github.com/juliankrispel)

packages/utils/src/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
} from 'draft-js'
1515
import type DraftEntityInstance from 'draft-js/lib/DraftEntityInstance'
1616
import type { DraftDecorator } from 'draft-js/lib/DraftDecorator'
17+
// eslint-disable-next-line node/no-deprecated-api
1718
import punycode from 'punycode'
1819

1920
export function replaceWithAtomicBlock(

0 commit comments

Comments
 (0)