import { MoveNodeOperation } from 'slate' ; import { cloneNode } from '../../utils' ; import { SyncValue } from '../../model' ; import { getParent , getChildren } from '../../path' ; const moveNode = ( doc , op ) : SyncValue => { const [ from , fromIndex ] = getParent ( doc , op . path ) ; const [ to , toIndex ] = getParent ( doc , op . newPath ) ; if ( from . text || to . text ) { throw new TypeError ( "Can't move node as child of a text node" ) ; } getChildren ( to ) . splice ( toIndex , 0 , ... getChildren ( from ) . splice ( fromIndex , 1 ) . map ( cloneNode ) ) ; return doc ; } ; export default moveNode ;