@@ -4,15 +4,15 @@ import { AllDimensionType, ApplyFocusEvent, FocusRenderEvent, Edition, Observabl
4
4
import ColumnService from '../data/columnService' ;
5
5
import SelectionStoreService from '../../store/selection/selection.store.service' ;
6
6
import { codesLetter } from '../../utils/keyCodes' ;
7
- import { SELECTION_BORDER_CLASS } from '../../utils/consts' ;
7
+ import { MOBILE_CLASS , SELECTION_BORDER_CLASS } from '../../utils/consts' ;
8
8
import { DataSourceState } from '../../store/dataSource/data.store' ;
9
9
import { isRangeSingleCell } from '../../store/selection/selection.helpers' ;
10
10
import { getCurrentCell , getElStyle } from './selection.utils' ;
11
11
import { isEditInput } from './editors/edit.utils' ;
12
12
import { KeyboardService } from './keyboard.service' ;
13
13
import { AutoFillService } from './autofill.service' ;
14
14
import { ClipboardService } from './clipboard.service' ;
15
- import { getFromEvent } from '../../utils/events' ;
15
+ import { getFromEvent , verifyTouchTarget } from '../../utils/events' ;
16
16
17
17
@Component ( {
18
18
tag : 'revogr-overlay-selection' ,
@@ -80,11 +80,20 @@ export class OverlaySelection {
80
80
* Custom editors register
81
81
*/
82
82
@Prop ( ) editors : Edition . Editors ;
83
- /** If true applys changes when cell closes if not Escape */
83
+ /**
84
+ * If true applys changes when cell closes if not Escape
85
+ */
84
86
@Prop ( ) applyChangesOnClose : boolean = false ;
85
- /** Additional data to pass to renderer */
87
+ /**
88
+ * Additional data to pass to renderer
89
+ */
86
90
@Prop ( ) additionalData : any ;
87
91
92
+ /**
93
+ * Is mobile view mode
94
+ */
95
+ @Prop ( ) isMobileDevice : boolean ;
96
+
88
97
// --------------------------------------------------------------------------
89
98
//
90
99
// Events
@@ -299,7 +308,11 @@ export class OverlaySelection {
299
308
300
309
private renderRange ( range : Selection . RangeArea ) {
301
310
const style = getElStyle ( range , this . dimensionRow . state , this . dimensionCol . state ) ;
302
- return [ < div class = { SELECTION_BORDER_CLASS } style = { style } /> ] ;
311
+ return [
312
+ < div class = { SELECTION_BORDER_CLASS } style = { style } >
313
+ { this . isMobileDevice && < div class = "range-handlers" > < span class = { MOBILE_CLASS } > </ span > < span class = { MOBILE_CLASS } > </ span > </ div > }
314
+ </ div >
315
+ ] ;
303
316
}
304
317
305
318
private renderEditCell ( ) {
@@ -389,6 +402,7 @@ export class OverlaySelection {
389
402
}
390
403
return (
391
404
< Host
405
+ class = { { mobile : this . isMobileDevice } }
392
406
// run edit on dblclick
393
407
onDblClick = { ( e : MouseEvent ) => {
394
408
// if dblclick prevented outside edit will not start
@@ -397,7 +411,7 @@ export class OverlaySelection {
397
411
}
398
412
} }
399
413
onMouseDown = { ( e : MouseEvent ) => this . onElementMouseDown ( e ) }
400
- onTouchStart = { ( e : TouchEvent ) => this . onElementMouseDown ( e ) } >
414
+ onTouchStart = { ( e : TouchEvent ) => this . onElementMouseDown ( e , true ) } >
401
415
{ els }
402
416
< slot name = "data" />
403
417
</ Host >
@@ -454,7 +468,7 @@ export class OverlaySelection {
454
468
return ! e . defaultPrevented ;
455
469
}
456
470
457
- protected onElementMouseDown ( e : MouseEvent | TouchEvent ) {
471
+ protected onElementMouseDown ( e : MouseEvent | TouchEvent , touch = false ) {
458
472
// Ignore focus if clicked input
459
473
if ( isEditInput ( e . target as HTMLElement | undefined ) ) {
460
474
return ;
@@ -463,14 +477,24 @@ export class OverlaySelection {
463
477
if ( e . defaultPrevented ) {
464
478
return ;
465
479
}
480
+ const x = getFromEvent ( e , 'clientX' ) ;
481
+ const y = getFromEvent ( e , 'clientY' ) ;
482
+ // skip touch
483
+ if ( x === null || y === null ) {
484
+ return ;
485
+ }
466
486
// Regular cell click
467
- const focusCell = getCurrentCell ( { x : getFromEvent ( e , 'clientX' ) , y : getFromEvent ( e , 'clientY' ) } , data ) ;
487
+ const focusCell = getCurrentCell ( { x, y } , data ) ;
468
488
this . selectionStoreService . focus ( focusCell , this . range && e . shiftKey ) ;
469
489
470
490
// Initiate autofill selection
471
491
if ( this . range ) {
472
492
this . autoFillService . selectionStart ( e . target as HTMLElement , data ) ;
473
- e . preventDefault ( ) ;
493
+ if ( ! touch ) {
494
+ e . preventDefault ( ) ;
495
+ } else if ( verifyTouchTarget ( ( e as TouchEvent ) . touches [ 0 ] , MOBILE_CLASS ) ) {
496
+ e . preventDefault ( ) ;
497
+ }
474
498
}
475
499
}
476
500
0 commit comments