mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-01 04:50:27 +02:00
add always ending in paragraph to image example
This commit is contained in:
@@ -87,6 +87,7 @@ class Images extends React.Component {
|
||||
state={this.state.state}
|
||||
renderNode={this.renderNode}
|
||||
onChange={this.onChange}
|
||||
onDocumentChange={this.onDocumentChange}
|
||||
onPaste={this.onPaste}
|
||||
/>
|
||||
</div>
|
||||
@@ -114,6 +115,34 @@ class Images extends React.Component {
|
||||
this.setState({ state })
|
||||
}
|
||||
|
||||
/**
|
||||
* On document change, if the last block is an image, add another paragraph.
|
||||
*
|
||||
* @param {Document} document
|
||||
* @param {State} state
|
||||
*/
|
||||
|
||||
onDocumentChange = (document, state) => {
|
||||
const blocks = document.getBlocks()
|
||||
const last = blocks.last()
|
||||
if (last.type != 'image') return
|
||||
|
||||
const normalized = state
|
||||
.transform()
|
||||
.collapseToEndOf(last)
|
||||
.splitBlock()
|
||||
.setBlock({
|
||||
type: 'paragraph',
|
||||
isVoid: false,
|
||||
data: {}
|
||||
})
|
||||
.apply({
|
||||
snapshot: false
|
||||
})
|
||||
|
||||
this.onChange(normalized)
|
||||
}
|
||||
|
||||
/**
|
||||
* On clicking the image button, prompt for an image and insert it.
|
||||
*
|
||||
|
Reference in New Issue
Block a user