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

Commit 79cb83e

Browse files
committed
add mergeBlockData into utils
1 parent 6586bfe commit 79cb83e

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

packages/utils/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,12 @@ getWordCount(editorState: EditorState): number
149149
mergeEntityData(editorState: EditorState, entityKey: string, data: Object): EditorState
150150
```
151151

152+
### mergeBlockData
153+
154+
```javascript
155+
mergeBlockData(editorState: EditorState, block: ContentBlock, data: { [id: string]: any }): EditorState
156+
```
157+
152158
## License
153159

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

packages/utils/src/index.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,3 +278,19 @@ export function mergeEntityData(
278278

279279
return EditorState.push(editorState, newContentState, 'apply-entity')
280280
}
281+
282+
export function mergeBlockData(
283+
editorState: EditorState,
284+
block: ContentBlock,
285+
data: { [id: string]: any }
286+
): EditorState {
287+
const content = editorState.getCurrentContent()
288+
const updatedBlock = block.mergeIn(['data'], data)
289+
const blockKey = block.getKey()
290+
const blockMap = content.getBlockMap().merge({ [blockKey]: updatedBlock })
291+
return EditorState.push(
292+
editorState,
293+
content.merge({ blockMap }),
294+
'change-block-data'
295+
)
296+
}

0 commit comments

Comments
 (0)