1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-30 10:29:48 +02:00

add isVoid property to nodes

This commit is contained in:
Ian Storm Taylor
2016-06-30 11:13:56 -07:00
parent aba40a2aaf
commit 1069fee13a
38 changed files with 329 additions and 94 deletions

View File

@@ -34,40 +34,25 @@ class Images extends React.Component {
}
const { anchorBlock, selection } = state
let transform = state.transform()
if (anchorBlock.text == '') {
state = state
.transform()
.setBlock('image', { src })
.apply()
if (anchorBlock.text != '') {
if (selection.isAtEndOf(anchorBlock)) {
transform = transform.splitBlock()
} else if (selection.isAtStartOf(anchorBlock)) {
transform = transform.splitBlock().moveToStartOfPreviousBlock()
} else {
transform = transform.splitBlock().splitBlock().moveToStartOfPreviousBlock()
}
}
else if (selection.isAtEndOf(anchorBlock)) {
state = state
.transform()
.splitBlock()
.setBlock('image', { src })
.apply()
}
else if (selection.isAtStartOf(anchorBlock)) {
state = state
.transform()
.splitBlock()
.moveToStartOfPreviousBlock()
.setBlock('image', { src })
.apply()
}
else {
state = state
.transform()
.splitBlock()
.splitBlock()
.moveToStartOfPreviousBlock()
.setBlock('image', { src })
.apply()
}
state = transform
.setBlock({
type: 'image',
isVoid: true,
data: { src }
})
.apply()
this.setState({ state })
}

View File

@@ -17,8 +17,8 @@
{
"kind": "block",
"type": "image",
"isVoid": true,
"data": {
"isVoid": true,
"src": "https://img.washingtonpost.com/wp-apps/imrs.php?src=https://img.washingtonpost.com/news/speaking-of-science/wp-content/uploads/sites/36/2015/10/as12-49-7278-1024x1024.jpg&w=1484"
},
"nodes": [