mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-21 22:45:18 +02:00
Fix image drop in example (#919)
* Fix image drop in example Dropped images were being inserted at previous selection rather than drop target. * Fix linting errors
This commit is contained in:
committed by
Ian Storm Taylor
parent
ccb7a23ba3
commit
e81f4e24e9
@@ -161,7 +161,7 @@ class Images extends React.Component {
|
|||||||
const src = window.prompt('Enter the URL of the image:')
|
const src = window.prompt('Enter the URL of the image:')
|
||||||
if (!src) return
|
if (!src) return
|
||||||
let { state } = this.state
|
let { state } = this.state
|
||||||
state = this.insertImage(state, src)
|
state = this.insertImage(state, null, src)
|
||||||
this.onChange(state)
|
this.onChange(state)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -219,7 +219,7 @@ class Images extends React.Component {
|
|||||||
|
|
||||||
reader.addEventListener('load', () => {
|
reader.addEventListener('load', () => {
|
||||||
state = editor.getState()
|
state = editor.getState()
|
||||||
state = this.insertImage(state, reader.result)
|
state = this.insertImage(state, data.target, reader.result)
|
||||||
editor.onChange(state)
|
editor.onChange(state)
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -256,7 +256,7 @@ class Images extends React.Component {
|
|||||||
onPasteText = (e, data, state) => {
|
onPasteText = (e, data, state) => {
|
||||||
if (!isUrl(data.text)) return
|
if (!isUrl(data.text)) return
|
||||||
if (!isImage(data.text)) return
|
if (!isImage(data.text)) return
|
||||||
return this.insertImage(state, data.text)
|
return this.insertImage(state, data.target, data.text)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -267,9 +267,12 @@ class Images extends React.Component {
|
|||||||
* @return {State}
|
* @return {State}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
insertImage = (state, src) => {
|
insertImage = (state, target, src) => {
|
||||||
return state
|
const transform = state.transform()
|
||||||
.transform()
|
|
||||||
|
if (target) transform.select(target)
|
||||||
|
|
||||||
|
return transform
|
||||||
.insertBlock({
|
.insertBlock({
|
||||||
type: 'image',
|
type: 'image',
|
||||||
isVoid: true,
|
isVoid: true,
|
||||||
|
Reference in New Issue
Block a user