import { MergeNodeOperation , Node } from 'slate' ; import { SyncValue } from '../../model' ; import { getParent , getChildren } from '../../path' ; import { toJS , cloneNode } from '../../utils' ; const mergeNode = ( doc , op ) : SyncValue => { const [ parent , index ] = getParent ( doc , op . path ) ; const prev = parent [ index - 1 ] || parent . children [ index - 1 ] ; const next = parent [ index ] || parent . children [ index ] ; if ( prev . text ) { prev . text . insertAt ( prev . text . length , ... toJS ( next . text ) . split ( '' ) ) ; } else { getChildren ( next ) . forEach ( ( n ) => getChildren ( prev ) . push ( cloneNode ( n ) ) ) ; } getChildren ( parent ) . deleteAt ( index , 1 ) ; return doc ; } ; export default mergeNode ;