Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
onClick={(e, editor, next): CoreEditor | void => {
if (e.target) {
// @ts-ignore
const node = findNode(e.target as Element, editor)
if (!node) {
return editor
}
}
next()
}}
onChange={change => {
// eslint-disable-next-line max-depth
if (!targetDOMNode && closestBlock) {
targetDOMNode = findDOMNode(closestBlock)
}
}
}
// As the event is registered on the editor parent node
// ignore the event if it is coming from from the editor node itself
if (!targetDOMNode || targetDOMNode === this._editorNode) {
this.resetDropTarget()
return
}
if (event.dataTransfer) {
event.dataTransfer.dropEffect = 'move'
}
const targetNode = findNode(targetDOMNode, editor)
if (!targetNode) {
this.resetDropTarget()
return
}
const block =
targetNode.object === 'block'
? targetNode
: editor.value.document.getClosestBlock(targetNode.key)
// If no or same block reset and return
if (!block || block.key === node.key) {
this.resetDropTarget()
return
}
const blockDOMNode = findDOMNode(block)
const rect = blockDOMNode.getBoundingClientRect()
const position = event.clientY < rect.top + blockDOMNode.scrollHeight / 2 ? 'before' : 'after'
onDragStart(event, editor, next) {
const { value } = editor;
const { document } = value;
const node = findNode(event.target, editor);
if (node.type === blocks.image.type) {
const ancestors = document.getAncestors(node.key);
let imgContainer = ancestors.get(ancestors.size - 1);
if (imgContainer.type === type) {
editor.moveToRangeOfNode(imgContainer);
}
}
next();
},
},
onDrop(event: React.MouseEvent, editor: SlateEditor, next: (arg0: void) => void) {
const {target} = event
const node = findNode(target, editor)
if (editor.query('isVoid', node)) {
return editor
}
return next()
}
}
onDragStart(event, editor, next) {
const { value } = editor;
const { document } = value;
const node = findNode(event.target, editor);
if (node.type === blocks.image.type) {
const ancestors = document.getAncestors(node.key);
let imgContainer = ancestors.get(ancestors.size - 1);
if (imgContainer.type === type) {
editor.moveToRangeOfNode(imgContainer);
}
}
next();
},
},