import { getUISelection , getUIValue } from '../../document' ; import { createDataTransfer } from '../dataTransfer/DataTransfer' ; import { EditableInputType } from '../edit/isEditable' ; import { hasOwnSelection } from './selection' ; export function copySelection ( target ) { const data = hasOwnSelection ( target ) ? { 'text/plain' : readSelectedValueFromInput ( target ) } : { 'text/plain' : String ( target . ownerDocument . getSelection ( ) ) } ; const dt = createDataTransfer ( ) ; for ( const type in data ) { if ( data [ type ] ) { dt . setData ( type , data [ type ] ) ; } } return dt ; } function readSelectedValueFromInput ( target ) { const sel = getUISelection ( target ) ; const val = getUIValue ( target ) ; return val . substring ( sel . startOffset , sel . endOffset ) ; }