1
1
import actions from 'actions' ;
2
2
import classNames from 'classnames' ;
3
3
import getOverlayPositionBasedOn from 'helpers/getOverlayPositionBasedOn' ;
4
- import useMedia from 'hooks/useMedia ' ;
4
+ import { isMobileSize , isTabletAndMobileSize } from 'helpers/getDeviceSize ' ;
5
5
import useOnClickOutside from 'hooks/useOnClickOutside' ;
6
6
import PropTypes from 'prop-types' ;
7
7
import React , { useCallback , useLayoutEffect , useMemo , useRef , useState } from 'react' ;
8
8
import { useDispatch , useSelector } from 'react-redux' ;
9
9
import { Swipeable } from 'react-swipeable' ;
10
10
import selectors from 'selectors' ;
11
11
import useArrowFocus from '../../hooks/useArrowFocus' ;
12
+ import getRootNode from 'helpers/getRootNode' ;
13
+ import DataElements from 'constants/dataElement' ;
12
14
import './FlyoutMenu.scss' ;
13
15
14
16
const MENUS = [
15
- 'menuOverlay' ,
17
+ DataElements . MENU_OVERLAY ,
16
18
'groupOverlay' ,
17
- 'viewControlsOverlay' ,
19
+ DataElements . VIEW_CONTROLS_OVERLAY ,
18
20
'searchOverlay' ,
19
21
'signatureOverlay' ,
20
- 'zoomOverlay' ,
22
+ DataElements . ZOOM_OVERLAY ,
21
23
'zoomOverlay1' ,
22
24
'zoomOverlay2' ,
23
25
'redactionOverlay' ,
24
26
'toolStylePopup' ,
25
- 'pageManipulationOverlay' ,
27
+ DataElements . PAGE_MANIPULATION_OVERLAY ,
26
28
'thumbnailsControlRotatePopup' ,
27
- 'thumbnailsControlInsertPopup' ,
28
29
'thumbnailsControlManipulatePopup' ,
29
30
'thumbnailsControlManipulatePopupSmall' ,
30
31
'tabMenu' ,
31
32
] ;
32
33
33
34
const TRIGGERS = [
34
- 'menuButton' ,
35
- 'viewControlsButton' ,
36
- 'zoomOverlayButton' ,
35
+ DataElements . MENU_OVERLAY_BUTTON ,
36
+ DataElements . VIEW_CONTROLS_OVERLAY_BUTTON ,
37
+ DataElements . ZOOM_OVERLAY_BUTTON ,
37
38
'zoomOverlayButton1' ,
38
39
'zoomOverlayButton2' ,
39
- 'pageManipulationOverlayButton' ,
40
+ DataElements . PAGE_MANIPULATION_OVERLAY_BUTTON ,
40
41
'thumbnailsControlRotatePopupTrigger' ,
41
- 'thumbnailsControlInsertPopupTrigger' ,
42
42
'thumbnailsControlManipulatePopupTrigger' ,
43
43
'thumbnailsControlManipulatePopupSmallTrigger' ,
44
44
'tabTrigger' ,
@@ -57,6 +57,8 @@ const propTypes = {
57
57
ariaLabel : PropTypes . string ,
58
58
} ;
59
59
60
+ const viewerHeight = window . isApryseWebViewerWebComponent ? getRootNode ( ) ?. host . clientHeight : window . innerHeight ;
61
+
60
62
function FlyoutMenu ( { menu, trigger, onClose, children, ariaLabel } ) {
61
63
const dispatch = useDispatch ( ) ;
62
64
@@ -66,7 +68,8 @@ function FlyoutMenu({ menu, trigger, onClose, children, ariaLabel }) {
66
68
const isOpen = useSelector ( ( state ) => selectors . isElementOpen ( state , menu ) ) ;
67
69
68
70
const isInDesktopOnlyMode = useSelector ( ( state ) => selectors . isInDesktopOnlyMode ( state ) ) ;
69
- const pageManipulationOverlayAlternativePosition = useSelector ( ( state ) => selectors . getPageManipulationOverlayAlternativePosition ( state ) ) ;
71
+ const pageManipulationOverlayAlternativePosition = useSelector ( ( state ) => selectors . getPageManipulationOverlayAlternativePosition ( state ) ,
72
+ ) ;
70
73
71
74
const closeMenu = useCallback ( ( ) => {
72
75
dispatch ( actions . closeElements ( [ menu ] ) ) ;
@@ -78,7 +81,7 @@ function FlyoutMenu({ menu, trigger, onClose, children, ariaLabel }) {
78
81
79
82
const onClickOutside = useCallback (
80
83
( e ) => {
81
- const menuButton = document . querySelector ( `[data-element="${ trigger } "]` ) ;
84
+ const menuButton = getRootNode ( ) . querySelector ( `[data-element="${ trigger } "]` ) ;
82
85
const clickedMenuButton = menuButton ?. contains ( e . target ) ;
83
86
if ( ! clickedMenuButton ) {
84
87
closeMenu ( ) ;
@@ -89,12 +92,12 @@ function FlyoutMenu({ menu, trigger, onClose, children, ariaLabel }) {
89
92
useOnClickOutside ( overlayRef , onClickOutside ) ;
90
93
91
94
const [ position , setPosition ] = useState ( ( ) => ( { left : 0 , right : 'auto' , top : 'auto' } ) ) ;
92
- const isMobile = useMedia ( [ '(max-width: 640px)' ] , [ true ] , false ) ;
93
- const isTabletOrMobile = useMedia ( [ '(max-width: 900px)' ] , [ true ] , false ) ;
95
+ const isMobile = isMobileSize ( ) ;
96
+ const isTabletAndMobile = isTabletAndMobileSize ( ) ;
94
97
95
98
const getAlternativePosition = ( ) => {
96
99
const alternativePosition = pageManipulationOverlayAlternativePosition ;
97
- const verticalGap = isMobile && isTabletOrMobile ? 14 : 6 ;
100
+ const verticalGap = isMobile && isTabletAndMobile ? 14 : 6 ;
98
101
const clickTop = alternativePosition . top ;
99
102
let top = clickTop + verticalGap ;
100
103
if ( clickTop > 100 ) {
@@ -103,8 +106,8 @@ function FlyoutMenu({ menu, trigger, onClose, children, ariaLabel }) {
103
106
* if the right-click click was not on the top of the page, we should check if the popup will fit on the
104
107
* the viewport and, if not, can adjust its position to "pass" the click position, otherwise the popup should always be below them
105
108
*/
106
- if ( clickTop + flyoutMenuHeight > window . innerHeight ) {
107
- const calculatedTop = window . innerHeight - flyoutMenuHeight - verticalGap ;
109
+ if ( clickTop + flyoutMenuHeight > viewerHeight ) {
110
+ const calculatedTop = viewerHeight - flyoutMenuHeight - verticalGap ;
108
111
top = calculatedTop > 0 ? calculatedTop : 0 ;
109
112
alternativePosition . top = top ;
110
113
}
@@ -122,11 +125,11 @@ function FlyoutMenu({ menu, trigger, onClose, children, ariaLabel }) {
122
125
const onResize = ( ) => {
123
126
let overlayAlternativePosition ;
124
127
125
- if ( trigger === 'pageManipulationOverlayButton' && pageManipulationOverlayAlternativePosition ) {
128
+ if ( trigger === DataElements . PAGE_MANIPULATION_OVERLAY_BUTTON && pageManipulationOverlayAlternativePosition ) {
126
129
overlayAlternativePosition = getAlternativePosition ( ) ;
127
130
} else {
128
- overlayAlternativePosition = getOverlayPositionBasedOn ( trigger , overlayRef , isMobile && isTabletOrMobile ) ;
129
- overlayAlternativePosition . maxHeight = window . innerHeight - overlayAlternativePosition . top ;
131
+ overlayAlternativePosition = getOverlayPositionBasedOn ( trigger , overlayRef , isMobile && isTabletAndMobile ) ;
132
+ overlayAlternativePosition . maxHeight = viewerHeight - overlayAlternativePosition . top ;
130
133
}
131
134
setPosition ( overlayAlternativePosition ) ;
132
135
} ;
@@ -135,7 +138,7 @@ function FlyoutMenu({ menu, trigger, onClose, children, ariaLabel }) {
135
138
window . addEventListener ( 'resize' , onResize ) ;
136
139
return ( ) => window . removeEventListener ( 'resize' , onResize ) ;
137
140
}
138
- } , [ allOtherMenus , dispatch , isOpen , isTabletOrMobile , trigger , isMobile ] ) ;
141
+ } , [ allOtherMenus , dispatch , isOpen , isTabletAndMobile , trigger , isMobile ] ) ;
139
142
140
143
if ( isDisabled ) {
141
144
return null ;
@@ -148,7 +151,14 @@ function FlyoutMenu({ menu, trigger, onClose, children, ariaLabel }) {
148
151
149
152
return (
150
153
< Swipeable onSwipedUp = { closeMenu } onSwipedDown = { closeMenu } preventDefaultTouchmoveEvent >
151
- < div className = { overlayClass } data-element = { menu } style = { ( ! isMobile || isInDesktopOnlyMode ) ? position : undefined } ref = { overlayRef } role = "listbox" aria-label = { ariaLabel } >
154
+ < div
155
+ className = { overlayClass }
156
+ data-element = { menu }
157
+ style = { ! isMobile || isInDesktopOnlyMode ? position : undefined }
158
+ ref = { overlayRef }
159
+ role = "listbox"
160
+ aria-label = { ariaLabel }
161
+ >
152
162
{ isMobile && ! isInDesktopOnlyMode && < div className = "swipe-indicator" /> }
153
163
{ children }
154
164
</ div >
0 commit comments