During a cut or copy event, sets fragment as the Slate document fragment to be copied.
functiononCopy(event, change, editor) {const { value } = changeconstfragment=// ... create a fragment from a set of nodes ...if (fragment) {cloneFragment(event, value, fragment)returntrue }}
Note that calling cloneFragment should be the last thing you do in your event handler. If you change the window selection after calling cloneFragment, the browser may copy the wrong content. If you need to perform an action after calling cloneFragment, wrap it in requestAnimationFrame:
findDOMNode
findDOMNode(node: Node) => DOMElement
Find the DOM node from a Slate Node. Modelled after React's built-in findDOMNode helper.
function onCut(event, change, editor) {
const { value } = change
const fragment = // ... create a fragment from a set of nodes ...
if (fragment) {
cloneFragment(event, value, fragment)
window.requestAnimationFrame(() => {
editor.change(change => change.delete())
})
return true
}
}
function componentDidUpdate() {
const { node } = this.props
const element = findDOMNode(node)
// Do something with the DOM `element`...
}
function onChange(change) {
const { value } = change
const range = findDOMRange(value.selection)
// Do something with the DOM `range`...
}
function onSomeNativeEvent(event) {
const node = findNode(event.target)
// Do something with `node`...
}
function onSomeNativeEvent() {
// You can find a range from a native DOM selection...
const nativeSelection = window.getSelection()
const range = findRange(nativeSelection, value)
// ...or from a native DOM range...
const nativeRange = nativeSelection.getRangeAt(0)
const range = findRange(nativeRange, value)
}
function onDrop(event, change, editor) {
const targetRange = getEventRange(event)
// Do something at the drop `targetRange`...
}
function onDrop(event, change, editor) {
const transfer = getEventTransfer(event)
const { type, node } = transfer
if (type == 'node') {
// Do something with `node`...
}
}
function onDragStart(event, change, editor) {
const { value } = change
const { startNode } = value
setEventTransfer(event, 'node', startNode)
}