1
- import { OutsidePlacement , PositionCoOrds } from '../models' ;
1
+ import { OutsidePlacement , PositionMeta } from '../models' ;
2
2
import { Bus } from '../utils' ;
3
3
import { ToppyPosition } from './position' ;
4
4
@@ -28,7 +28,7 @@ export class RelativePosition extends ToppyPosition {
28
28
if ( this . config . autoUpdate ) this . listenDrag ( tid ) ;
29
29
}
30
30
31
- getPositions ( hostElement : HTMLElement ) : PositionCoOrds {
31
+ getPositions ( hostElement : HTMLElement ) : Pick < PositionMeta , any > {
32
32
const s = this . getCoords ( this . config . src ) ;
33
33
const h = this . getCoords ( hostElement ) ;
34
34
@@ -45,11 +45,11 @@ export class RelativePosition extends ToppyPosition {
45
45
if ( typeof this . config . width === 'number' ) {
46
46
h . width = this . config . width ;
47
47
}
48
- const props = this . calculatePos ( this . config . placement , s , h ) ;
49
- return { ...this . round ( props ) , width : this . config . width , height : this . config . height } ;
48
+ const { pos , props } = this . calculatePos ( this . config . placement , s , h ) ;
49
+ return { ...this . round ( props ) , width : this . config . width , height : this . config . height , extra : pos } ;
50
50
}
51
51
52
- private getCoords ( elem : HTMLElement ) : PositionCoOrds {
52
+ private getCoords ( elem : HTMLElement ) : PositionMeta {
53
53
const box : any = elem . getBoundingClientRect ( ) ;
54
54
55
55
return {
@@ -104,16 +104,14 @@ export class RelativePosition extends ToppyPosition {
104
104
return this . calc ( pos , s , h ) ;
105
105
}
106
106
107
- private calculatePos ( pos , s , h , c = true ) : object {
107
+ private calculatePos ( pos , s , h , c = true ) : { [ x : string ] : any } {
108
108
const props = this . getProps ( pos , s , h ) ;
109
- if ( ! c ) {
110
- return props ;
111
- }
112
- if ( this . config . autoUpdate && this . isOverflowed ( { ...props , width : h . width , height : h . height } ) ) {
109
+
110
+ if ( c && this . config . autoUpdate && this . isOverflowed ( { ...props , width : h . width , height : h . height } ) ) {
113
111
return this . calculatePos ( this . nextPosition ( pos ) , s , h , false ) ;
114
112
}
115
113
116
- return props ;
114
+ return { pos , props } ;
117
115
}
118
116
119
117
private isOverflowed ( props : { [ x : string ] : any } ) : boolean {
0 commit comments