import Editor from "../editor" ; import StructureType from "../const/structure-type" ; import getSelection from "../selection/get-selection" ; import deleteSelection from "./delete-selection" ; import focusAt from "../selection/focus-at" ; const paste = ( editor , event ) => { event . preventDefault ( ) ; let copyInData = event . clipboardData ?. getData ( "text/plain" ) ; if ( ! copyInData ) return ; let rowData = copyInData . split ( "\n" ) ; if ( rowData . length === 0 ) return ; let selection = getSelection ( editor ) ; if ( ! selection . isCollapsed ) { deleteSelection ( editor , selection . range [ 0 ] , selection . range [ 1 ] ) ; selection = getSelection ( editor ) ; } let nowComponent = editor . storeManage . getBlockById ( selection . range [ 0 ] . id ) ; let start = selection . range [ 0 ] ; if ( nowComponent . type === StructureType . plainText ) { let operator = nowComponent . add ( start . offset , rowData . join ( "\n" ) ) ; focusAt ( editor , operator ?. [ 0 ] || start , operator ?. [ 1 ] ) ; return ; } rowData = rowData . filter ( ( each ) => each . trim ( ) . length !== 0 ) ; let operator = nowComponent . add ( start . offset , rowData [ 0 ] ) ; if ( rowData . length === 1 ) { return focusAt ( editor , operator ?. [ 0 ] || start , operator ?. [ 1 ] ) ; } let list = [ ] ; for ( let i = 1 ; i < rowData . length ; i ++ ) { list . push ( editor . componentFactory . buildParagraph ( rowData [ i ] ) ) ; } operator = nowComponent . split ( start . offset + rowData [ 0 ] . length , ... list ) ; focusAt ( editor , { id : list [ 0 ] . id , offset : rowData [ rowData . length - 1 ] . length , } ) ; return ; } ; export default paste ;