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

Commit a553e48

Browse files
committed
feat(utils): add mergeEntityData method into utils
1 parent b70652b commit a553e48

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

packages/utils/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,12 @@ getLineCount(editorState: EditorState): number
143143
getWordCount(editorState: EditorState): number
144144
```
145145

146+
### mergeEntityData
147+
148+
```javascript
149+
mergeEntityData(editorState: EditorState, entityKey: string, data: Object): EditorState
150+
```
151+
146152
## License
147153

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

packages/utils/src/index.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,3 +266,15 @@ export function getWordCount(editorState: EditorState): number {
266266
const wordArray = cleanString.match(/\S+/g) // matches words according to whitespace
267267
return wordArray ? wordArray.length : 0
268268
}
269+
270+
export function mergeEntityData(
271+
editorState: EditorState,
272+
entityKey: string,
273+
data: Object
274+
): EditorState {
275+
const newContentState = editorState
276+
.getCurrentContent()
277+
.mergeEntityData(entityKey, data)
278+
279+
return EditorState.push(editorState, newContentState, 'apply-entity')
280+
}

0 commit comments

Comments
 (0)