import util from '@idraw/util' ; import { TypeElement , TypeElemDesc } from '@idraw/types' ; import iDraw from './../index' ; import { _tempData } from './../names' ; export function copyElements ( idraw ) { if ( idraw [ _tempData ] . get ( 'isFocus' ) !== true ) { return ; } const elems = util . data . deepClone ( idraw . getSelectedElements ( ) ) ; idraw [ _tempData ] . set ( 'clipboardElements' , elems ) ; } export function pasteElements ( idraw ) { if ( idraw [ _tempData ] . get ( 'isFocus' ) !== true ) { return ; } const elems = idraw [ _tempData ] . get ( 'clipboardElements' ) ; const moveRate = 0.1 ; elems . forEach ( ( elem ) => { elem . x += elem . w * moveRate ; elem . y += elem . w * moveRate ; idraw . addElement ( elem ) ; } ) ; idraw [ _tempData ] . set ( 'clipboardElements' , [ ] ) ; } export function cutElements ( idraw ) { if ( idraw [ _tempData ] . get ( 'isFocus' ) !== true ) { return ; } const elems = util . data . deepClone ( idraw . getSelectedElements ( ) ) ; elems . forEach ( ( elem ) => { idraw . deleteElement ( elem . uuid ) ; } ) ; idraw [ _tempData ] . set ( 'clipboardElements' , elems ) ; } export function deleteElements ( idraw ) { if ( idraw [ _tempData ] . get ( 'isFocus' ) !== true ) { return ; } const elems = util . data . deepClone ( idraw . getSelectedElements ( ) ) ; elems . forEach ( ( elem ) => { idraw . deleteElement ( elem . uuid ) ; } ) ; } const keyArrowMoveDistance = 4 ; export function keyArrowUp ( idraw ) { const elems = util . data . deepClone ( idraw . getSelectedElements ( ) ) ; if ( elems . length > 0 ) { elems . forEach ( ( elem ) => { elem . y -= keyArrowMoveDistance ; idraw . updateElement ( elem ) ; } ) ; } else { const { scrollTop } = idraw . getScreenTransform ( ) ; idraw . scrollTop ( scrollTop - keyArrowMoveDistance ) ; } } export function keyArrowDown ( idraw ) { const elems = util . data . deepClone ( idraw . getSelectedElements ( ) ) ; if ( elems . length > 0 ) { elems . forEach ( ( elem ) => { elem . y += keyArrowMoveDistance ; idraw . updateElement ( elem ) ; } ) ; } else { const { scrollTop } = idraw . getScreenTransform ( ) ; idraw . scrollTop ( scrollTop + keyArrowMoveDistance ) ; } } export function keyArrowLeft ( idraw ) { const elems = util . data . deepClone ( idraw . getSelectedElements ( ) ) ; if ( elems . length > 0 ) { elems . forEach ( ( elem ) => { elem . x -= keyArrowMoveDistance ; idraw . updateElement ( elem ) ; } ) ; } else { const { scrollLeft } = idraw . getScreenTransform ( ) ; idraw . scrollLeft ( scrollLeft - keyArrowMoveDistance ) ; } } export function keyArrowRight ( idraw ) { const elems = util . data . deepClone ( idraw . getSelectedElements ( ) ) ; if ( elems . length > 0 ) { elems . forEach ( ( elem ) => { elem . x += keyArrowMoveDistance ; idraw . updateElement ( elem ) ; } ) ; } else { const { scrollLeft } = idraw . getScreenTransform ( ) ; idraw . scrollLeft ( scrollLeft + keyArrowMoveDistance ) ; } } export function keyUndo ( idraw ) { idraw . undo ( ) ; }