mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-11 17:53:59 +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}
|
state={this.state.state}
|
||||||
renderNode={this.renderNode}
|
renderNode={this.renderNode}
|
||||||
onChange={this.onChange}
|
onChange={this.onChange}
|
||||||
|
onDocumentChange={this.onDocumentChange}
|
||||||
onPaste={this.onPaste}
|
onPaste={this.onPaste}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
@@ -114,6 +115,34 @@ class Images extends React.Component {
|
|||||||
this.setState({ state })
|
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.
|
* On clicking the image button, prompt for an image and insert it.
|
||||||
*
|
*
|
||||||
|
Reference in New Issue
Block a user