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

Commit f13fd2e

Browse files
committed
add mergeBlockData into utils
1 parent 3130dfc commit f13fd2e

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
findWithRegex(regex: RegExp, contentBlock: ContentBlock, callback: () => void): void
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
@@ -279,3 +279,19 @@ export function findWithRegex(
279279
callback(start, start + matchArr[0].length)
280280
}
281281
}
282+
283+
export function mergeBlockData(
284+
editorState: EditorState,
285+
block: ContentBlock,
286+
data: { [id: string]: any }
287+
): EditorState {
288+
const content = editorState.getCurrentContent()
289+
const updatedBlock = block.mergeIn(['data'], data)
290+
const blockKey = block.getKey()
291+
const blockMap = content.getBlockMap().merge({ [blockKey]: updatedBlock })
292+
return EditorState.push(
293+
editorState,
294+
content.merge({ blockMap }),
295+
'change-block-data'
296+
)
297+
}

0 commit comments

Comments
 (0)