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

Commit fedec94

Browse files
Merge pull request #21 from draft-js-plugins/counter
feat: add a few function to utils for count
2 parents 52bedb6 + 19ec241 commit fedec94

File tree

11 files changed

+13424
-3
lines changed

11 files changed

+13424
-3
lines changed

examples/counter/README.md

Lines changed: 2164 additions & 0 deletions
Large diffs are not rendered by default.

examples/counter/package-lock.json

Lines changed: 11113 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/counter/package.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"name": "@djsp/counter-example",
3+
"homepage": "https://github.com/draft-js-plugins/next#readme",
4+
"version": "0.1.5",
5+
"private": true,
6+
"license": "MIT",
7+
"dependencies": {
8+
"@djsp/utils": "^0.1.5",
9+
"@djsp/core": "^0.1.5",
10+
"react": "^16.2.0",
11+
"react-dom": "^16.2.0",
12+
"react-scripts": "^1.1.1"
13+
},
14+
"scripts": {
15+
"start": "react-scripts start",
16+
"build": "react-scripts build",
17+
"test": "react-scripts test --env=jsdom",
18+
"eject": "react-scripts eject"
19+
}
20+
}

examples/counter/public/index.html

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
6+
<meta name="theme-color" content="#000000">
7+
8+
<link rel="manifest" href="%PUBLIC_URL%/manifest.json">
9+
10+
<title>@djsp/suggestions</title>
11+
</head>
12+
13+
<body>
14+
<noscript>
15+
You need to enable JavaScript to run this app.
16+
</noscript>
17+
18+
<div id="root"></div>
19+
</body>
20+
</html>
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/core'
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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import React, { Component } from 'react'
2+
import ReactDOM from 'react-dom'
3+
4+
import { EditorState, ContentState } from 'draft-js'
5+
import { EditorContainer, Editor } from '@djsp/core'
6+
import WordCountPlugin from './WordCountPlugin'
7+
import './styles.css'
8+
9+
class App extends Component {
10+
state = {
11+
editorState: EditorState.createWithContent(
12+
ContentState.createFromText('Just type!')
13+
),
14+
}
15+
16+
onChange = editorState => this.setState({ editorState })
17+
18+
render() {
19+
return (
20+
<div>
21+
<EditorContainer
22+
editorState={this.state.editorState}
23+
onChange={this.onChange}>
24+
<WordCountPlugin />
25+
<Editor />
26+
</EditorContainer>
27+
</div>
28+
)
29+
}
30+
}
31+
32+
ReactDOM.render(<App />, document.getElementById('root'))

examples/counter/src/styles.css

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
body {
2+
font-family: sans-serif;
3+
font-size: 1.8em;
4+
padding: 1em;
5+
background: #12312e;
6+
}
7+
8+
.public-DraftEditor-content {
9+
padding: 2em;
10+
border-radius: 5px;
11+
color: #fff;
12+
border: #555;
13+
background: #244a46;
14+
}

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/package-lock.json

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/utils/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
"dist"
3737
],
3838
"dependencies": {
39-
"draft-js": "^0.10.5"
39+
"draft-js": "^0.10.5",
40+
"punycode": "^2.1.1"
4041
}
4142
}

0 commit comments

Comments
 (0)