@zohodesk/components 1.0.0-temp-241 → 1.0.0-temp-242

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (149) hide show
  1. package/README.md +48 -0
  2. package/assets/Appearance/dark/mode/Component_DarkMode.module.css +172 -168
  3. package/assets/Appearance/dark/mode/Component_v1_DarkMode.module.css +8 -8
  4. package/assets/Appearance/dark/themes/blue/blue_CTA_DarkModifyCategory.module.css +465 -465
  5. package/assets/Appearance/dark/themes/blue/blue_CTA_DarkTheme.module.css +31 -31
  6. package/assets/Appearance/dark/themes/blue/blue_ComponentTheme_DarkTheme.module.css +7 -4
  7. package/assets/Appearance/dark/themes/green/green_CTA_DarkModifyCategory.module.css +465 -465
  8. package/assets/Appearance/dark/themes/green/green_CTA_DarkTheme.module.css +31 -31
  9. package/assets/Appearance/dark/themes/green/green_ComponentTheme_DarkTheme.module.css +7 -4
  10. package/assets/Appearance/dark/themes/orange/orange_CTA_DarkModifyCategory.module.css +465 -465
  11. package/assets/Appearance/dark/themes/orange/orange_CTA_DarkTheme.module.css +31 -31
  12. package/assets/Appearance/dark/themes/orange/orange_ComponentTheme_DarkTheme.module.css +7 -4
  13. package/assets/Appearance/dark/themes/red/red_CTA_DarkModifyCategory.module.css +465 -465
  14. package/assets/Appearance/dark/themes/red/red_CTA_DarkTheme.module.css +31 -31
  15. package/assets/Appearance/dark/themes/red/red_ComponentTheme_DarkTheme.module.css +7 -4
  16. package/assets/Appearance/dark/themes/yellow/yellow_CTA_DarkModifyCategory.module.css +465 -465
  17. package/assets/Appearance/dark/themes/yellow/yellow_CTA_DarkTheme.module.css +31 -31
  18. package/assets/Appearance/dark/themes/yellow/yellow_ComponentTheme_DarkTheme.module.css +7 -4
  19. package/assets/Appearance/light/mode/Component_LightMode.module.css +169 -165
  20. package/assets/Appearance/light/mode/Component_v1_LightMode.module.css +8 -8
  21. package/assets/Appearance/light/themes/blue/blue_CTA_LightModifyCategory.module.css +465 -465
  22. package/assets/Appearance/light/themes/blue/blue_CTA_LightTheme.module.css +31 -31
  23. package/assets/Appearance/light/themes/blue/blue_ComponentTheme_LightTheme.module.css +7 -4
  24. package/assets/Appearance/light/themes/green/green_CTA_LightModifyCategory.module.css +465 -465
  25. package/assets/Appearance/light/themes/green/green_CTA_LightTheme.module.css +31 -31
  26. package/assets/Appearance/light/themes/green/green_ComponentTheme_LightTheme.module.css +7 -4
  27. package/assets/Appearance/light/themes/orange/orange_CTA_LightModifyCategory.module.css +465 -465
  28. package/assets/Appearance/light/themes/orange/orange_CTA_LightTheme.module.css +31 -31
  29. package/assets/Appearance/light/themes/orange/orange_ComponentTheme_LightTheme.module.css +7 -4
  30. package/assets/Appearance/light/themes/red/red_CTA_LightModifyCategory.module.css +465 -465
  31. package/assets/Appearance/light/themes/red/red_CTA_LightTheme.module.css +31 -31
  32. package/assets/Appearance/light/themes/red/red_ComponentTheme_LightTheme.module.css +7 -4
  33. package/assets/Appearance/light/themes/yellow/yellow_CTA_LightModifyCategory.module.css +465 -465
  34. package/assets/Appearance/light/themes/yellow/yellow_CTA_LightTheme.module.css +31 -31
  35. package/assets/Appearance/light/themes/yellow/yellow_ComponentTheme_LightTheme.module.css +7 -4
  36. package/assets/Appearance/pureDark/mode/Component_PureDarkMode.module.css +174 -170
  37. package/assets/Appearance/pureDark/mode/Component_v1_PureDarkMode.module.css +8 -8
  38. package/assets/Appearance/pureDark/themes/blue/blue_CTA_PureDarkModifyCategory.module.css +465 -465
  39. package/assets/Appearance/pureDark/themes/blue/blue_CTA_PureDarkTheme.module.css +31 -31
  40. package/assets/Appearance/pureDark/themes/blue/blue_ComponentTheme_PureDarkTheme.module.css +7 -4
  41. package/assets/Appearance/pureDark/themes/green/green_CTA_PureDarkModifyCategory.module.css +465 -465
  42. package/assets/Appearance/pureDark/themes/green/green_CTA_PureDarkTheme.module.css +31 -31
  43. package/assets/Appearance/pureDark/themes/green/green_ComponentTheme_PureDarkTheme.module.css +7 -4
  44. package/assets/Appearance/pureDark/themes/orange/orange_CTA_PureDarkModifyCategory.module.css +465 -465
  45. package/assets/Appearance/pureDark/themes/orange/orange_CTA_PureDarkTheme.module.css +31 -31
  46. package/assets/Appearance/pureDark/themes/orange/orange_ComponentTheme_PureDarkTheme.module.css +7 -4
  47. package/assets/Appearance/pureDark/themes/red/red_CTA_PureDarkModifyCategory.module.css +465 -465
  48. package/assets/Appearance/pureDark/themes/red/red_CTA_PureDarkTheme.module.css +31 -31
  49. package/assets/Appearance/pureDark/themes/red/red_ComponentTheme_PureDarkTheme.module.css +7 -4
  50. package/assets/Appearance/pureDark/themes/yellow/yellow_CTA_PureDarkModifyCategory.module.css +465 -465
  51. package/assets/Appearance/pureDark/themes/yellow/yellow_CTA_PureDarkTheme.module.css +31 -31
  52. package/assets/Appearance/pureDark/themes/yellow/yellow_ComponentTheme_PureDarkTheme.module.css +7 -4
  53. package/es/Button/__tests__/__snapshots__/Button.spec.js.snap +2 -2
  54. package/es/Button/css/Button.module.css +60 -6
  55. package/es/Button/css/cssJSLogic.js +2 -2
  56. package/es/Card/__tests__/Card.spec.js +48 -0
  57. package/es/Card/__tests__/CardContent.spec.js +61 -0
  58. package/es/Card/__tests__/CardHeader.spec.js +33 -0
  59. package/es/Card/__tests__/__snapshots__/Card.spec.js.snap +125 -0
  60. package/es/Card/__tests__/__snapshots__/CardContent.spec.js.snap +177 -0
  61. package/es/Card/__tests__/__snapshots__/CardHeader.spec.js.snap +51 -0
  62. package/es/ListItem/ListItem.js +10 -3
  63. package/es/ListItem/ListItemWithAvatar.js +15 -6
  64. package/es/ListItem/ListItemWithCheckBox.js +13 -6
  65. package/es/ListItem/ListItemWithIcon.js +14 -5
  66. package/es/ListItem/ListItemWithRadio.js +13 -6
  67. package/es/ListItem/__tests__/ListItem.spec.js +19 -0
  68. package/es/ListItem/__tests__/ListItemWithAvatar.spec.js +19 -0
  69. package/es/ListItem/__tests__/ListItemWithCheckBox.spec.js +19 -0
  70. package/es/ListItem/__tests__/ListItemWithIcon.spec.js +17 -0
  71. package/es/ListItem/__tests__/ListItemWithRadio.spec.js +19 -0
  72. package/es/ListItem/__tests__/__snapshots__/ListItem.spec.js.snap +78 -0
  73. package/es/ListItem/__tests__/__snapshots__/ListItemWithAvatar.spec.js.snap +140 -46
  74. package/es/ListItem/__tests__/__snapshots__/ListItemWithCheckBox.spec.js.snap +251 -49
  75. package/es/ListItem/__tests__/__snapshots__/ListItemWithIcon.spec.js.snap +144 -50
  76. package/es/ListItem/__tests__/__snapshots__/ListItemWithRadio.spec.js.snap +252 -52
  77. package/es/ListItem/props/propTypes.js +15 -5
  78. package/es/MultiSelect/MultiSelect.js +8 -1
  79. package/es/MultiSelect/Suggestions.js +2 -1
  80. package/es/MultiSelect/__tests__/__snapshots__/MultiSelectHeader.spec.js.snap +6 -6
  81. package/es/MultiSelect/props/propTypes.js +2 -3
  82. package/es/Popup/Popup.js +21 -1041
  83. package/es/Select/GroupSelect.js +4 -2
  84. package/es/Select/Select.js +7 -1
  85. package/es/Select/SelectWithAvatar.js +17 -4
  86. package/es/Select/SelectWithIcon.js +15 -5
  87. package/es/Select/props/defaultProps.js +2 -0
  88. package/es/Select/props/propTypes.js +5 -0
  89. package/es/Typography/__tests__/Typography.spec.js +225 -0
  90. package/es/Typography/__tests__/__snapshots__/Typography.spec.js.snap +1226 -0
  91. package/es/common/common.module.css +1 -1
  92. package/es/utils/Common.js +1 -1
  93. package/es/utils/dropDownUtils.js +13 -4
  94. package/es/v1/Popup/Popup.js +1 -1
  95. package/es/v1/Switch/__tests__/Switch.spec.js +41 -6
  96. package/es/v1/Switch/__tests__/__snapshots__/Switch.spec.js.snap +176 -5
  97. package/lib/Button/__tests__/__snapshots__/Button.spec.js.snap +2 -2
  98. package/lib/Button/css/Button.module.css +60 -6
  99. package/lib/Button/css/cssJSLogic.js +1 -1
  100. package/lib/Card/__tests__/Card.spec.js +54 -6
  101. package/lib/Card/__tests__/CardContent.spec.js +68 -0
  102. package/lib/Card/__tests__/CardHeader.spec.js +40 -0
  103. package/lib/Card/__tests__/__snapshots__/Card.spec.js.snap +125 -0
  104. package/lib/Card/__tests__/__snapshots__/CardContent.spec.js.snap +177 -0
  105. package/lib/Card/__tests__/__snapshots__/CardHeader.spec.js.snap +51 -0
  106. package/lib/ListItem/ListItem.js +10 -3
  107. package/lib/ListItem/ListItemWithAvatar.js +15 -6
  108. package/lib/ListItem/ListItemWithCheckBox.js +15 -6
  109. package/lib/ListItem/ListItemWithIcon.js +13 -5
  110. package/lib/ListItem/ListItemWithRadio.js +15 -6
  111. package/lib/ListItem/__tests__/ListItem.spec.js +23 -0
  112. package/lib/ListItem/__tests__/ListItemWithAvatar.spec.js +23 -0
  113. package/lib/ListItem/__tests__/ListItemWithCheckBox.spec.js +23 -0
  114. package/lib/ListItem/__tests__/ListItemWithIcon.spec.js +21 -0
  115. package/lib/ListItem/__tests__/ListItemWithRadio.spec.js +23 -0
  116. package/lib/ListItem/__tests__/__snapshots__/ListItem.spec.js.snap +78 -0
  117. package/lib/ListItem/__tests__/__snapshots__/ListItemWithAvatar.spec.js.snap +140 -46
  118. package/lib/ListItem/__tests__/__snapshots__/ListItemWithCheckBox.spec.js.snap +251 -49
  119. package/lib/ListItem/__tests__/__snapshots__/ListItemWithIcon.spec.js.snap +144 -50
  120. package/lib/ListItem/__tests__/__snapshots__/ListItemWithRadio.spec.js.snap +252 -52
  121. package/lib/ListItem/props/propTypes.js +15 -6
  122. package/lib/MultiSelect/MultiSelect.js +6 -2
  123. package/lib/MultiSelect/Suggestions.js +2 -1
  124. package/lib/MultiSelect/__tests__/__snapshots__/MultiSelectHeader.spec.js.snap +6 -6
  125. package/lib/MultiSelect/props/propTypes.js +3 -4
  126. package/lib/Popup/Popup.js +25 -1149
  127. package/lib/Select/GroupSelect.js +4 -3
  128. package/lib/Select/Select.js +7 -1
  129. package/lib/Select/SelectWithAvatar.js +17 -7
  130. package/lib/Select/SelectWithIcon.js +15 -5
  131. package/lib/Select/props/defaultProps.js +2 -1
  132. package/lib/Select/props/propTypes.js +5 -0
  133. package/lib/Typography/__tests__/Typography.spec.js +232 -0
  134. package/lib/Typography/__tests__/__snapshots__/Typography.spec.js.snap +1226 -0
  135. package/lib/common/common.module.css +1 -1
  136. package/lib/utils/Common.js +1 -1
  137. package/lib/utils/dropDownUtils.js +17 -4
  138. package/lib/v1/Popup/Popup.js +1 -1
  139. package/lib/v1/Switch/__tests__/Switch.spec.js +41 -6
  140. package/lib/v1/Switch/__tests__/__snapshots__/Switch.spec.js.snap +176 -5
  141. package/package.json +13 -13
  142. package/es/Popup/PositionMapping.js +0 -72
  143. package/es/Popup/Registry.js +0 -36
  144. package/es/Popup/intersectionObserver.js +0 -49
  145. package/es/Popup/viewPort.js +0 -373
  146. package/lib/Popup/PositionMapping.js +0 -81
  147. package/lib/Popup/Registry.js +0 -46
  148. package/lib/Popup/intersectionObserver.js +0 -72
  149. package/lib/Popup/viewPort.js +0 -367
package/es/Popup/Popup.js CHANGED
@@ -1,1049 +1,29 @@
1
- /**** Libraries ****/
2
1
  import React from 'react';
3
- import hoistStatics from 'hoist-non-react-statics';
4
- import { PopupPropTypes, ContextTypes } from "./props/propTypes";
5
- /**** Methods ****/
6
-
7
- import { debounce, isDescendant, isTextSelected, cancelBubblingEffect, DUMMY_OBJECT } from "../utils/Common.js";
8
- import viewPort from "./viewPort";
9
- import { absolutePositionMapping, rtlAbsolutePositionMapping, rtlFixedPositionMapping } from "./PositionMapping.js";
10
- import ResizeObserver from '@zohodesk/virtualizer/lib/commons/ResizeObserver.js';
11
- import { addIntersectionObserver, removeIntersectionObserver } from "./intersectionObserver";
12
- import { positionMapping } from "../DropBox/DropBoxPositionMapping.js";
13
- import isMobilePopover from "../DropBox/utils/isMobilePopover.js";
14
- import selectn from 'selectn';
15
- import Registry from "./Registry.js";
16
-
17
- global.closeGroupPopups = function (groupName) {
18
- const groupPopups = Registry.popups[groupName] || [];
19
- groupPopups.forEach(popup => {
20
- popup.state.isPopupOpen && popup.setState({
21
- isPopupOpen: false,
22
- isPopupReady: false
23
- });
24
- });
25
- };
26
-
27
- const defaultState = {
28
- position: 'bottomCenter',
29
- height: '0px',
30
- positions: {},
31
- //{bottomCenter: true, bottomLeft: false, ...}
32
- positionsOffset: {},
33
- //{bottomCenter: {left: ‘’,top: ‘’ }, .....}
34
- targetOffset: {},
35
- //{height: ‘’, width: ‘’,}
36
- popupOffset: {},
37
- //{height: ‘’, width: ‘’,}
38
- isAbsolutePositioningNeeded: true
39
- };
40
- const SCROLL_BLOCK_EVENTS = Object.freeze([{
41
- name: 'wheel',
42
- handlerName: 'handleBlockScroll',
43
- options: {
44
- capture: true,
45
- passive: false
46
- }
47
- }, {
48
- name: 'touchmove',
49
- handlerName: 'handleBlockScroll',
50
- options: {
51
- capture: true,
52
- passive: false
53
- }
54
- }, {
55
- name: 'scroll',
56
- handlerName: 'handlePositionChange',
57
- options: {
58
- capture: true,
59
- passive: false
60
- }
61
- }, {
62
- name: 'keydown',
63
- handlerName: 'preventKeyboardScroll',
64
- options: {
65
- capture: true,
66
- passive: false
67
- }
68
- }]);
69
- const IFRAME_SCROLL_BLOCK_EVENTS = Object.freeze(SCROLL_BLOCK_EVENTS.filter(event => event.name !== 'keydown'));
70
- const CLICK_EVENTS = Object.freeze([{
71
- name: 'click',
72
- handlerName: 'documentClickHandler',
73
- options: {
74
- capture: false,
75
- passive: false
76
- }
77
- }, {
78
- name: 'click',
79
- handlerName: 'documentClickHandler1',
80
- options: {
81
- capture: true,
82
- passive: false
83
- }
84
- }]);
85
- /* eslint-disable react/no-deprecated */
86
-
87
- /* eslint-disable react/prop-types */
2
+ import DotkitPopup from '@zohodesk/dotkit/es/react/components/Popup/Popup';
3
+ import { getLibraryConfig } from "../Provider/Config.js";
88
4
 
89
5
  const Popup = function (Component) {
90
6
  let group = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'global';
91
7
  let needResizeHandling = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
92
- let {
93
- isAbsolutePositioningNeeded: isAbsolutePopup = true,
94
- isArrow: needPopupArrow = false,
95
- customOrder: customPositionOrder = [],
96
- scrollDebounceTime: popupScrollDebounceTime = 0,
97
- closeOnScroll: closeOnScrollPopup = false,
98
- isOutsideScrollBlocked: isOutsideScrollBlock = false
99
- } = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
100
-
101
- class Popup extends React.Component {
102
- constructor(props) {
103
- super(props);
104
- this.state = {
105
- isPopupOpen: props.isPopupOpen || false,
106
- position: 'bottomCenter',
107
- height: '0px',
108
- isPopupReady: props.isPopupOpen || false,
109
- positions: {},
110
- //{bottomCenter: true, bottomLeft: false, ...}
111
- positionsOffset: {},
112
- //{bottomCenter: {left: ‘’,top: ‘’ }, .....}
113
- targetOffset: {},
114
- //{height: ‘’, width: ‘’,}
115
- popupOffset: {},
116
- //{height: ‘’, width: ‘’,}
117
- isAbsolutePositioningNeeded: true,
118
- isMobile: false
119
- };
120
- this.togglePopup = this.togglePopup.bind(this);
121
- this.documentClickHandler = this.documentClickHandler.bind(this);
122
- this.documentClickHandler1 = this.documentClickHandler1.bind(this);
123
- this.removeClose = this.removeClose.bind(this);
124
- this.documentKeyupHandler = this.documentKeyupHandler.bind(this);
125
- this.openPopupOnly = this.openPopupOnly.bind(this);
126
- this.closePopupOnly = this.closePopupOnly.bind(this);
127
- this.getTargetRef = this.getTargetRef.bind(this);
128
- this.getContainerRef = this.getContainerRef.bind(this);
129
- this.handlePopupPosition = this.handlePopupPosition.bind(this);
130
- this.handleResize = debounce(this.handleResize.bind(this), 300);
131
- this.handlePopupResize = this.handlePopupResize.bind(this);
132
- this.getIsAbsolutePopup = this.getIsAbsolutePopup.bind(this);
133
- this.getIsOutsideScrollBlocked = this.getIsOutsideScrollBlocked.bind(this);
134
- this.getNeedArrow = this.getNeedArrow.bind(this);
135
- this.getCustomPositionOrder = this.getCustomPositionOrder.bind(this);
136
- this.handleOpenPopupPositionChange = this.handleOpenPopupPositionChange.bind(this);
137
- this.getScrollDebounceTime = this.getScrollDebounceTime.bind(this);
138
- this.getCloseOnScrollPopup = this.getCloseOnScrollPopup.bind(this);
139
- this.handleCloseLastOpenedGroup = this.handleCloseLastOpenedGroup.bind(this);
140
- this.handleDocumentMouseDown = this.handleDocumentMouseDown.bind(this);
141
- this.handleDocumentFocus = this.handleDocumentFocus.bind(this);
142
- this.handleGetNeedPrevent = this.handleGetNeedPrevent.bind(this);
143
- this.handleBlockScroll = this.handleBlockScroll.bind(this);
144
- this.handlePositionChange = this.handlePositionChange.bind(this);
145
- this.preventKeyboardScroll = this.preventKeyboardScroll.bind(this);
146
- this.updateListeners = this.updateListeners.bind(this);
147
- this.addScrollBlockListeners = this.addScrollBlockListeners.bind(this);
148
- this.removeScrollBlockListeners = this.removeScrollBlockListeners.bind(this);
149
- this.addScrollToUpdateListeners = this.addScrollToUpdateListeners.bind(this);
150
- this.removeScrollToUpdateListeners = this.removeScrollToUpdateListeners.bind(this);
151
- this.handleAddingScrollBlock = this.handleAddingScrollBlock.bind(this);
152
- this.handleRemovingScrollBlock = this.handleRemovingScrollBlock.bind(this);
153
- this.handleIntersectionObserver = this.handleIntersectionObserver.bind(this);
154
- this.updateVisibilityOnIntersection = this.updateVisibilityOnIntersection.bind(this);
155
- this.handleAddingScrollToUpdatePosition = this.handleAddingScrollToUpdatePosition.bind(this);
156
- this.handleRemovingScrollToUpdatePosition = this.handleRemovingScrollToUpdatePosition.bind(this);
157
- this.setContainerDynamicPositioning = this.setContainerDynamicPositioning.bind(this);
158
- this.updatePopupState = this.updatePopupState.bind(this);
159
- this.handleScrollAndBlockEvents = this.handleScrollAndBlockEvents.bind(this);
160
- this.handleIframeEventListeners = this.handleIframeEventListeners.bind(this);
161
- this.handleDropElementStyleUpdate = this.handleDropElementStyleUpdate.bind(this);
162
- this.positionRef = /*#__PURE__*/React.createRef();
163
- this.rootElement = Registry.getRootElement();
164
- this.popupObserver = new ResizeObserver(this.handlePopupResize);
165
- this.cancelRaf = this.cancelRaf.bind(this);
166
- this.cancelPendingAnimationFrames = this.cancelPendingAnimationFrames.bind(this);
167
- this.setPositionRafId = null;
168
- this.resizePositionRafId = null; //dropBoxSize
169
-
170
- this.size = null;
171
- this.isTargetElementVisible = false;
172
- this.isAbsolutePopup = isAbsolutePopup;
173
- this.needPopupArrow = needPopupArrow;
174
- this.customPositionOrder = customPositionOrder;
175
- this.scrollDebounceTime = popupScrollDebounceTime;
176
- this.closeOnScroll = closeOnScrollPopup;
177
- this.isOutsideScrollBlock = isOutsideScrollBlock;
178
- const scrollDebounceTime = this.getScrollDebounceTime(this);
179
- this.updatePositionOnScroll = scrollDebounceTime > 0 ? debounce(this.updatePositionOnScroll.bind(this), scrollDebounceTime) : this.updatePositionOnScroll.bind(this); // this.handleScroll = debounce(this.handleScroll.bind(this), scrollDebounceTime);
180
- }
181
-
182
- componentDidMount() {
183
- const group = this.getGroup();
184
- const groupPopups = Registry.popups[group] || [];
185
- groupPopups.push(this);
186
- Registry.popups[group] = groupPopups;
187
-
188
- if (Object.keys(Registry.popups).length === 1 && groupPopups.length === 1 && Registry.listenerPopupRef === undefined) {
189
- Registry.listenerPopupRef = this;
190
- Registry.listenerPopupRef.updateListeners(true, CLICK_EVENTS, document);
191
- document.addEventListener('keyup', Registry.listenerPopupRef.documentKeyupHandler, false); // document.addEventListener('scroll', Registry.listenerPopupRef.handleScroll, true);
192
-
193
- window.addEventListener('resize', Registry.listenerPopupRef.handleResize);
194
- document.addEventListener('mousedown', Registry.listenerPopupRef.handleDocumentMouseDown, true);
195
- document.addEventListener('focus', Registry.listenerPopupRef.handleDocumentFocus, true);
196
- }
197
- }
198
-
199
- UNSAFE_componentWillReceiveProps(nextProps) {
200
- const {
201
- isPopupOpen
202
- } = this.state;
203
-
204
- if (typeof nextProps.isPopupOpen !== 'undefined' && nextProps.isPopupOpen !== isPopupOpen) {
205
- this.setState({
206
- isPopupOpen: nextProps.isPopupOpen,
207
- isPopupReady: nextProps.isPopupOpen
208
- });
209
- }
210
- }
211
-
212
- handleScrollAndBlockEvents(shouldAdd) {
213
- if (shouldAdd) {
214
- this.handleAddingScrollBlock();
215
- this.handleAddingScrollToUpdatePosition();
216
- } else {
217
- this.handleRemovingScrollBlock();
218
- this.handleRemovingScrollToUpdatePosition();
219
- }
220
- }
221
-
222
- handleIframeEventListeners(shouldAdd, eventList) {
223
- this.rootElement.querySelectorAll('iframe').forEach(frame => {
224
- const frameDocument = frame.contentDocument;
225
-
226
- if (frameDocument) {
227
- this.updateListeners(shouldAdd, eventList, frameDocument);
228
- }
229
- });
230
- }
231
-
232
- componentDidUpdate(prevProps, prevState) {
233
- const {
234
- isPopupReady,
235
- isMobile
236
- } = this.state;
237
- const {
238
- isPopupReady: oldStateOpen = false,
239
- isMobile: oldIsMobileState
240
- } = prevState || {};
241
- const {
242
- dropElement
243
- } = this;
244
- const {
245
- needResizeHandling: propResizeHandling
246
- } = this.props;
247
-
248
- if (oldStateOpen !== isPopupReady) {
249
- if (isPopupReady && dropElement && (propResizeHandling !== undefined ? propResizeHandling : needResizeHandling)) {
250
- this.popupObserver.replaceObservationElement(dropElement);
251
- } else if (!isPopupReady) {
252
- this.size = null;
253
- this.popupObserver.disconnect();
254
- }
255
- }
256
-
257
- if (oldStateOpen !== isPopupReady && !isMobile || oldIsMobileState !== isMobile) {
258
- const shouldAdd = isPopupReady && !isMobile;
259
- this.handleScrollAndBlockEvents(shouldAdd);
260
- this.handleIframeEventListeners(shouldAdd, CLICK_EVENTS);
261
- }
262
- }
263
-
264
- cancelRaf(refName) {
265
- const id = this[refName];
266
-
267
- if (id) {
268
- cancelAnimationFrame(id);
269
- this[refName] = null;
270
- }
271
- }
272
-
273
- cancelPendingAnimationFrames() {
274
- this.cancelRaf('setPositionRafId');
275
- this.cancelRaf('resizePositionRafId');
276
- }
277
-
278
- componentWillUnmount() {
279
- const group = this.getGroup();
280
- Registry.popups = Object.keys(Registry.popups).reduce((res, groupName) => {
281
- if (groupName === group) {
282
- const groupPopups = Registry.popups[group];
283
- const newGroupPopups = groupPopups.filter(popup => popup !== this);
284
- newGroupPopups.length === 0 && Registry.lastOpenedGroup.indexOf(group) >= 0 && Registry.lastOpenedGroup.splice(Registry.lastOpenedGroup.indexOf(group), 1);
285
- res[group] = newGroupPopups;
286
- }
287
-
288
- return res;
289
- }, Registry.popups);
290
- this.handleRemovingScrollBlock();
291
- this.handleRemovingScrollToUpdatePosition();
292
- this.handleIframeEventListeners(false, CLICK_EVENTS);
293
- let noPopups = true;
294
-
295
- for (const i in Registry.popups) {
296
- if (Registry.popups[i].length >= 1) {
297
- noPopups = false;
298
- break;
299
- }
300
- }
301
-
302
- if (this.popupObserver) {
303
- this.popupObserver.disconnect();
304
- }
305
-
306
- if (noPopups && Registry.listenerPopupRef !== undefined) {
307
- Registry.listenerPopupRef.updateListeners(false, CLICK_EVENTS, document);
308
- document.removeEventListener('keyup', Registry.listenerPopupRef.documentKeyupHandler); // document.removeEventListener('scroll', Registry.listenerPopupRef.handleScroll);
309
-
310
- window.removeEventListener('resize', Registry.listenerPopupRef.handleResize);
311
- document.removeEventListener('mousedown', Registry.listenerPopupRef.handleDocumentMouseDown, true);
312
- document.removeEventListener('focus', Registry.listenerPopupRef.handleDocumentFocus, true);
313
- Registry.listenerPopupRef = undefined;
314
- }
315
-
316
- this.cancelPendingAnimationFrames();
317
- }
318
-
319
- handleAddingScrollBlock() {
320
- const isAbsolutePositioningNeeded = this.getIsAbsolutePopup(this);
321
- const isOutsideScrollBlocked = this.getIsOutsideScrollBlocked(this);
322
-
323
- if (isOutsideScrollBlocked && !isAbsolutePositioningNeeded) {
324
- addIntersectionObserver(this.placeHolderElement, this.handleIntersectionObserver);
325
- this.addScrollBlockListeners();
326
- }
327
- }
328
-
329
- handleRemovingScrollBlock() {
330
- const isAbsolutePositioningNeeded = this.getIsAbsolutePopup(this);
331
- const isOutsideScrollBlocked = this.getIsOutsideScrollBlocked(this);
332
-
333
- if (isOutsideScrollBlocked && !isAbsolutePositioningNeeded) {
334
- removeIntersectionObserver(this.placeHolderElement, this.handleIntersectionObserver);
335
- this.removeScrollBlockListeners();
336
- }
337
- }
338
-
339
- handleAddingScrollToUpdatePosition() {
340
- const isAbsolutePositioningNeeded = this.getIsAbsolutePopup(this);
341
- const isOutsideScrollBlocked = this.getIsOutsideScrollBlocked(this);
342
-
343
- if (!isOutsideScrollBlocked && !isAbsolutePositioningNeeded) {
344
- addIntersectionObserver(this.placeHolderElement, this.updateVisibilityOnIntersection);
345
- const shouldAddScrollToUpdatePositionListeners = Registry.getOpenedScrollableFixedPopups().length === 1 && Registry.scrollableListenerPopupRef === undefined;
346
-
347
- if (shouldAddScrollToUpdatePositionListeners) {
348
- Registry.scrollableListenerPopupRef = this;
349
- Registry.scrollableListenerPopupRef.addScrollToUpdateListeners();
350
- }
351
- }
352
- }
353
-
354
- handleRemovingScrollToUpdatePosition() {
355
- const isAbsolutePositioningNeeded = this.getIsAbsolutePopup(this);
356
- const isOutsideScrollBlocked = this.getIsOutsideScrollBlocked(this);
357
-
358
- if (!isOutsideScrollBlocked && !isAbsolutePositioningNeeded) {
359
- removeIntersectionObserver(this.placeHolderElement, this.updateVisibilityOnIntersection);
360
- const shouldRemoveScrollToUpdatePositionListeners = Registry.getOpenedScrollableFixedPopups().length === 0 && Registry.scrollableListenerPopupRef !== undefined;
361
-
362
- if (shouldRemoveScrollToUpdatePositionListeners) {
363
- Registry.scrollableListenerPopupRef.removeScrollToUpdateListeners();
364
- Registry.scrollableListenerPopupRef = undefined;
365
- }
366
- }
367
- }
368
-
369
- handleDropElementStyleUpdate(_ref) {
370
- let {
371
- top = '',
372
- left = '',
373
- bottom = '',
374
- right = ''
375
- } = _ref;
376
- const {
377
- dropElement
378
- } = this;
379
- Object.assign(dropElement.style, {
380
- top: top ? `${top}px` : '',
381
- left: left ? `${left}px` : '',
382
- right: right ? `${right}px` : '',
383
- bottom: bottom ? `${bottom}px` : ''
384
- });
385
- }
386
-
387
- setContainerDynamicPositioning(betterPosition, needArrow) {
388
- const {
389
- dropElement
390
- } = this;
391
- const {
392
- isMobile
393
- } = this.state;
394
- const {
395
- view,
396
- viewsOffset
397
- } = betterPosition || DUMMY_OBJECT;
398
- const styleToApply = selectn(`${view}`, viewsOffset);
399
-
400
- if (isMobile) {
401
- this.handleDropElementStyleUpdate({
402
- top: '',
403
- left: '',
404
- right: '',
405
- bottom: ''
406
- });
407
- } else {
408
- this.handleDropElementStyleUpdate(styleToApply);
409
-
410
- if (this.positionRef.current !== view) {
411
- dropElement.setAttribute('data-position', `${view}`);
412
- dropElement.setAttribute('data-box-direction', selectn(`${view}.direction`, positionMapping));
413
-
414
- if (needArrow) {
415
- dropElement.setAttribute('data-arrow-position', selectn(`${view}.arrowPosition`, positionMapping));
416
- }
417
-
418
- this.positionRef.current = view;
419
- }
420
- }
421
- }
422
-
423
- updatePositionOnScroll(e) {
424
- const scrollablePopups = Registry.getOpenedScrollableFixedPopups(); // Check if the event target is outside all dropElements
425
-
426
- scrollablePopups.forEach(_ref2 => {
427
- let {
428
- placeHolderElement,
429
- defaultPosition,
430
- isTargetElementVisible,
431
- handlePopupPosition
432
- } = _ref2;
433
-
434
- if (e.target.contains(placeHolderElement) && isTargetElementVisible) {
435
- handlePopupPosition(defaultPosition, true);
436
- }
437
- });
438
- }
439
-
440
- updateListeners() {
441
- let add = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
442
- let eventList = arguments.length > 1 ? arguments[1] : undefined;
443
- let element = arguments.length > 2 ? arguments[2] : undefined;
444
- const method = add ? 'addEventListener' : 'removeEventListener';
445
- eventList.forEach(_ref3 => {
446
- let {
447
- name,
448
- handlerName,
449
- options
450
- } = _ref3;
451
- const handler = this[handlerName];
452
-
453
- if (handler) {
454
- element[method](name, handler, options);
455
- }
456
- });
457
- }
458
-
459
- addScrollBlockListeners() {
460
- // Only add scroll block listeners if at least one open popup needs outside scroll blocked
461
- const shouldAddScrollBlockListeners = Registry.getOpenedScrollBlockedFixedPopups().length === 1 && Registry.scrollBlockedListenerPopupRef === undefined;
462
-
463
- if (shouldAddScrollBlockListeners) {
464
- Registry.scrollBlockedListenerPopupRef = this; // Main document
465
-
466
- Registry.scrollBlockedListenerPopupRef.updateListeners(true, SCROLL_BLOCK_EVENTS, document); // Attach event listeners to all iframes within rootElement
467
-
468
- Registry.scrollBlockedListenerPopupRef.handleIframeEventListeners(true, IFRAME_SCROLL_BLOCK_EVENTS);
469
- }
470
- }
471
-
472
- removeScrollBlockListeners() {
473
- // Only remove scroll block listeners if at least one open popup needs outside scroll blocked
474
- const shouldRemoveScrollBlockListeners = Registry.getOpenedScrollBlockedFixedPopups().length === 0 && Registry.scrollBlockedListenerPopupRef !== undefined;
475
-
476
- if (shouldRemoveScrollBlockListeners) {
477
- Registry.scrollBlockedListenerPopupRef.updateListeners(false, SCROLL_BLOCK_EVENTS, document);
478
- Registry.scrollBlockedListenerPopupRef.handleIframeEventListeners(false, IFRAME_SCROLL_BLOCK_EVENTS);
479
- Registry.scrollBlockedListenerPopupRef = undefined;
480
- }
481
- }
482
-
483
- addScrollToUpdateListeners() {
484
- document.addEventListener('scroll', this.updatePositionOnScroll, {
485
- capture: true,
486
- passive: false
487
- });
488
- }
489
-
490
- removeScrollToUpdateListeners() {
491
- document.removeEventListener('scroll', this.updatePositionOnScroll, {
492
- capture: true,
493
- passive: false
494
- });
495
- }
496
-
497
- handleBlockScroll(event) {
498
- const scrollBlockedPopups = Registry.getOpenedScrollBlockedFixedPopups(); // Check if the event target is outside all dropElements
499
-
500
- const isOutsideAllDropElements = scrollBlockedPopups.every(_ref4 => {
501
- let {
502
- dropElement
503
- } = _ref4;
504
- return dropElement && dropElement !== event.target && !dropElement.contains(event.target);
505
- });
506
-
507
- if (isOutsideAllDropElements) {
508
- event.preventDefault();
509
- }
510
- }
511
-
512
- handlePositionChange(event) {
513
- const scrollBlockedPopups = Registry.getOpenedScrollBlockedFixedPopups();
514
- scrollBlockedPopups.forEach(_ref5 => {
515
- let {
516
- placeHolderElement,
517
- dropElement,
518
- handlePopupPosition,
519
- state
520
- } = _ref5;
521
-
522
- if (dropElement && dropElement !== event.target && !dropElement.contains(event.target) && placeHolderElement && placeHolderElement !== event.target && !placeHolderElement.contains(event.target) && event.target.contains(placeHolderElement)) {
523
- handlePopupPosition(state.position, true);
524
- }
525
- });
526
- }
527
-
528
- preventKeyboardScroll(event) {
529
- const keys = [32, 37, 38, 39, 40]; // Space, Arrow keys
530
-
531
- const scrollBlockedPopups = Registry.getOpenedScrollBlockedFixedPopups(); // Check if the event target is outside all dropElements
532
-
533
- const isOutsideAllDropElements = scrollBlockedPopups.every(_ref6 => {
534
- let {
535
- dropElement
536
- } = _ref6;
537
- return dropElement && dropElement !== event.target && !dropElement.contains(event.target) && keys.includes(event.keyCode);
538
- });
539
-
540
- if (isOutsideAllDropElements) {
541
- event.preventDefault();
542
- }
543
- }
544
-
545
- handleIntersectionObserver(entry) {
546
- if (entry.intersectionRatio === 0 && entry.isIntersecting === false) {
547
- this.closePopupOnly();
548
- }
549
- }
550
-
551
- updateVisibilityOnIntersection(entry) {
552
- const {
553
- dropElement
554
- } = this;
555
- if (!dropElement) return;
556
-
557
- if (entry.isIntersecting === true) {
558
- this.isTargetElementVisible = true;
559
- dropElement.setAttribute('data-visible', 'visible');
560
- } else if (entry.intersectionRatio === 0 && entry.isIntersecting === false) {
561
- this.isTargetElementVisible = false;
562
- dropElement.setAttribute('data-visible', 'hidden');
563
- }
564
- }
565
-
566
- getGroup() {
567
- const {
568
- popupGroup
569
- } = this.props;
570
- return popupGroup || group;
571
- }
572
-
573
- getNeedArrow(popup) {
574
- const {
575
- isArrow
576
- } = popup.props;
577
- const {
578
- needPopupArrow
579
- } = popup;
580
- return isArrow !== undefined ? isArrow : needPopupArrow;
581
- }
582
-
583
- getScrollDebounceTime(popup) {
584
- const {
585
- scrollDebounceTime
586
- } = popup.props;
587
- const {
588
- scrollDebounceTime: popupScrollDebounceTime
589
- } = popup;
590
- return scrollDebounceTime !== undefined ? scrollDebounceTime : popupScrollDebounceTime;
591
- }
592
-
593
- getCloseOnScrollPopup(popup) {
594
- const {
595
- closeOnScroll
596
- } = popup.props;
597
- const {
598
- closeOnScroll: closeOnScrollPopup
599
- } = popup;
600
- return closeOnScroll !== undefined ? closeOnScroll : closeOnScrollPopup;
601
- }
602
-
603
- getIsAbsolutePopup(popup) {
604
- const {
605
- isAbsolutePositioningNeeded
606
- } = popup.props;
607
- const {
608
- isAbsolutePopup
609
- } = popup;
610
- return isAbsolutePositioningNeeded !== undefined ? isAbsolutePositioningNeeded : isAbsolutePopup;
611
- }
612
-
613
- getIsOutsideScrollBlocked(popup) {
614
- const {
615
- isOutsideScrollBlocked
616
- } = popup.props;
617
- const {
618
- isOutsideScrollBlock
619
- } = popup;
620
- return isOutsideScrollBlocked !== undefined ? isOutsideScrollBlocked : isOutsideScrollBlock;
621
- }
622
-
623
- getCustomPositionOrder(popup) {
624
- const {
625
- customOrder = []
626
- } = popup.props;
627
- const {
628
- customPositionOrder
629
- } = popup;
630
- return customOrder.length !== 0 ? customOrder : customPositionOrder;
631
- }
632
-
633
- togglePopup(e, defaultPosition) {
634
- const group = this.getGroup();
635
- this.removeClose(e);
636
- const {
637
- isPopupOpen
638
- } = this.state;
639
- const groupPopups = Registry.popups[group] || [];
640
- Registry.lastOpenedGroup = !isPopupOpen && Registry.lastOpenedGroup.indexOf(group) === -1 ? [group, ...Registry.lastOpenedGroup] : Registry.lastOpenedGroup;
641
- isPopupOpen && Registry.lastOpenedGroup.splice(0, 1);
642
- groupPopups.forEach(popup => {
643
- if (popup !== this && popup.state.isPopupOpen) {
644
- popup.setState({
645
- isPopupOpen: false,
646
- isPopupReady: false
647
- });
648
- }
649
- });
650
-
651
- if (isPopupOpen) {
652
- this.setState({
653
- isPopupOpen: false,
654
- isPopupReady: false
655
- });
656
- } else {
657
- this.handlePopupPosition(defaultPosition);
658
- }
659
- }
660
-
661
- openPopupOnly(e, defaultPosition) {
662
- const group = this.getGroup();
663
- this.removeClose(e);
664
- Registry.lastOpenedGroup = Registry.lastOpenedGroup.indexOf(group) === -1 ? [group, ...Registry.lastOpenedGroup] : Registry.lastOpenedGroup;
665
- this.handlePopupPosition(defaultPosition);
666
- }
667
-
668
- closePopupOnly(e) {
669
- this.removeClose(e);
670
- const {
671
- isPopupOpen
672
- } = this.state;
673
-
674
- if (isPopupOpen) {
675
- Registry.lastOpenedGroup.splice(0, 1);
676
- this.setState({
677
- isPopupOpen: false,
678
- isPopupReady: false
679
- });
680
- }
681
- }
682
-
683
- handleCloseLastOpenedGroup() {
684
- const groupPopups = Registry.lastOpenedGroup.length ? Registry.popups[Registry.lastOpenedGroup[0]] || [] : [];
685
- Registry.lastOpenedGroup.splice(0, 1);
686
- groupPopups.forEach(popup => {
687
- popup.state.isPopupOpen && popup.setState({
688
- isPopupOpen: false,
689
- isPopupReady: false
690
- });
691
- });
692
- }
693
-
694
- handleDocumentMouseDown(e) {
695
- const needPrevent = this.handleGetNeedPrevent(e);
696
-
697
- if (needPrevent) {
698
- this.removeClose(e);
699
- }
700
- }
701
-
702
- handleDocumentFocus(e) {
703
- const needPrevent = this.handleGetNeedPrevent(e);
704
-
705
- if (needPrevent) {
706
- this.removeClose(e);
707
- }
708
- }
709
-
710
- handleGetNeedPrevent(e) {
711
- let needPrevent = false;
712
-
713
- if (Registry.lastOpenedGroup.length > 1) {
714
- const {
715
- target
716
- } = e;
717
- const groupPopups = Registry.lastOpenedGroup.length ? Registry.popups[Registry.lastOpenedGroup[0]] : [];
718
- let openedPopup = null; // eslint-disable-next-line guard-for-in
719
-
720
- for (const i in groupPopups) {
721
- const {
722
- isPopupOpen
723
- } = groupPopups[i].state;
724
-
725
- if (isPopupOpen) {
726
- openedPopup = groupPopups[i];
727
- break;
728
- }
729
- }
730
-
731
- if (openedPopup) {
732
- const {
733
- dropElement,
734
- placeHolderElement
735
- } = openedPopup;
736
- const isDropBoxChild = isDescendant(dropElement, target);
737
- const isTargetChild = isDescendant(placeHolderElement, target); // const isPopupMassUpdateChild = isDescendant(
738
- // massUpdateParent,
739
- // dropElement
740
- // );
741
-
742
- if (!isDropBoxChild && !isTargetChild // && isPopupMassUpdateChild
743
- ) {
744
- needPrevent = true;
745
- }
746
- }
747
- }
748
-
749
- return needPrevent;
750
- }
751
-
752
- documentClickHandler1(e) {
753
- const needPrevent = this.handleGetNeedPrevent(e);
754
-
755
- if (needPrevent) {
756
- this.removeClose(e);
757
- this.handleCloseLastOpenedGroup();
758
- }
759
- }
760
-
761
- documentClickHandler() {
762
- try {
763
- Object.keys(Registry.popups).forEach(groupName => {
764
- const groupPopups = Registry.popups[groupName] || [];
765
- groupPopups.forEach(popup => {
766
- popup.state.isPopupOpen && (!popup.props.checkBeforeClose || popup.props.checkBeforeClose && popup.props.checkBeforeClose()) && !isTextSelected() && popup.setState({
767
- isPopupOpen: false,
768
- isPopupReady: false
769
- });
770
- });
771
- });
772
- Registry.lastOpenedGroup = [];
773
- } catch (e) {// eslint-disable-next-line no-console
774
- //console.error('popup component not unmounted properly', e);
775
- }
776
- }
777
-
778
- documentKeyupHandler(e) {
779
- try {
780
- if (e.keyCode === 27) {
781
- this.handleCloseLastOpenedGroup();
782
- }
783
- } catch (e) {// eslint-disable-next-line no-console
784
- //console.log('error', e);
785
- }
786
- }
787
-
788
- removeClose(e) {
789
- // e && e.preventDefault && e.preventDefault();
790
- cancelBubblingEffect(e);
791
- }
792
-
793
- updatePopupState(view, views, viewsOffset, targetOffset, popupOffset, isAbsolute) {
794
- const isMobile = isMobilePopover(true);
795
- this.setState({
796
- isPopupReady: true,
797
- position: view,
798
- positions: views,
799
- positionsOffset: viewsOffset,
800
- targetOffset,
801
- popupOffset,
802
- isAbsolutePositioningNeeded: isAbsolute,
803
- isMobile: isMobile
804
- });
805
- }
806
-
807
- handlePopupPosition() {
808
- let defaultPosition = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'bottomCenter';
809
- let isUpdatePosition = arguments.length > 1 ? arguments[1] : undefined;
810
- // isUpdatePosition --->>> Window resize and dropBox resize and to update the position
811
- const {
812
- direction
813
- } = this.context || {};
814
- const {
815
- placeHolderElement,
816
- dropElement
817
- } = this;
818
- const needArrow = this.getNeedArrow(this);
819
- const isAbsolute = this.getIsAbsolutePopup(this);
820
- const customOrder = this.getCustomPositionOrder(this);
821
-
822
- if (direction === 'rtl') {
823
- defaultPosition = isAbsolute ? rtlAbsolutePositionMapping[defaultPosition] : rtlFixedPositionMapping[defaultPosition];
824
- } else {
825
- defaultPosition = isAbsolute ? absolutePositionMapping[defaultPosition] : defaultPosition;
826
- }
827
-
828
- if (!placeHolderElement && !dropElement) {
829
- const isMobile = isMobilePopover(true);
830
- this.setState({
831
- isPopupOpen: true,
832
- isPopupReady: true,
833
- isMobile: isMobile
834
- });
835
- return;
836
- }
837
-
838
- const setPosition = () => {
839
- this.cancelRaf('setPositionRafId');
840
- this.setPositionRafId = requestAnimationFrame(() => {
841
- const {
842
- placeHolderElement,
843
- dropElement
844
- } = this;
845
- const {
846
- position,
847
- isPopupReady
848
- } = this.state;
849
- const scrollContainer = placeHolderElement ? placeHolderElement.closest('[data-scroll=true]') || document.body : document.body;
850
- const betterPosition = viewPort.betterView(dropElement, placeHolderElement, defaultPosition, scrollContainer, {
851
- needArrow,
852
- isAbsolute,
853
- customOrder
854
- });
855
- const {
856
- view,
857
- views,
858
- viewsOffset,
859
- targetOffset,
860
- popupOffset
861
- } = betterPosition || DUMMY_OBJECT;
862
-
863
- if (!isAbsolute) {
864
- if (!isPopupReady) {
865
- this.updatePopupState(view, views, viewsOffset, targetOffset, popupOffset, isAbsolute);
866
- }
867
-
868
- if (!dropElement) {
869
- return;
870
- }
871
-
872
- this.setContainerDynamicPositioning(betterPosition, needArrow);
873
- } else {
874
- if (position !== view || !isPopupReady) {
875
- this.updatePopupState(view, views, viewsOffset, targetOffset, popupOffset, isAbsolute);
876
- }
877
- }
878
-
879
- this.setPositionRafId = null;
880
- });
881
- };
882
-
883
- if (isUpdatePosition) {
884
- setPosition();
885
- } else {
886
- this.defaultPosition = defaultPosition;
887
- this.setState({
888
- isPopupOpen: true,
889
- isPopupReady: false
890
- }, setPosition);
891
- }
892
- }
893
-
894
- handleOpenPopupPositionChange() {
895
- Object.keys(Registry.popups).forEach(groupName => {
896
- const groupPopups = Registry.popups[groupName] || [];
897
- groupPopups.forEach(popup => {
898
- if (popup.state.isPopupOpen) {
899
- const {
900
- placeHolderElement,
901
- dropElement,
902
- defaultPosition
903
- } = popup;
904
- const {
905
- position,
906
- positionsOffset = {}
907
- } = popup.state;
908
-
909
- if (placeHolderElement && dropElement) {
910
- const scrollContainer = placeHolderElement.closest('[data-scroll=true]') || document.body;
911
- this.cancelRaf('resizePositionRafId');
912
- this.resizePositionRafId = requestAnimationFrame(() => {
913
- const needArrow = this.getNeedArrow(popup);
914
- const isAbsolute = this.getIsAbsolutePopup(popup);
915
- const customOrder = this.getCustomPositionOrder(popup);
916
- const isMobile = isMobilePopover(true);
917
- const betterPosition = viewPort.betterView(dropElement, placeHolderElement, defaultPosition, scrollContainer, {
918
- needArrow,
919
- isAbsolute,
920
- customOrder
921
- });
922
- const {
923
- view,
924
- views,
925
- viewsOffset = {},
926
- targetOffset,
927
- popupOffset
928
- } = betterPosition || {};
929
- const {
930
- left: oldLeft = '',
931
- top: oldTop = '',
932
- bottom: oldBottom = '',
933
- right: oldRight = ''
934
- } = positionsOffset[position] || {};
935
- const {
936
- left = '',
937
- top = '',
938
- bottom = '',
939
- right = ''
940
- } = viewsOffset[view] || {};
941
- const changeState = isAbsolute ? position !== view : oldLeft !== left || oldTop !== top || oldBottom !== bottom || oldRight !== right; // let isInViewPort = viewPort.isInViewPort(
942
- // placeHolderElement,
943
- // scrollContainer
944
- // );
945
-
946
- if (changeState) {
947
- popup.setState({
948
- position: view,
949
- positions: views,
950
- positionsOffset: viewsOffset,
951
- targetOffset,
952
- popupOffset,
953
- isAbsolutePositioningNeeded: isAbsolute,
954
- isMobile: isMobile
955
- });
956
- } // if (!isInViewPort && !isAbsolute) {
957
- // popup.setState({ isPopupOpen: false, isPopupReady: false });
958
- // } else if (view && changeState) {
959
- // popup.setState({
960
- // position: view,
961
- // positions: views,
962
- // positionsOffset: viewsOffset,
963
- // targetOffset,
964
- // popupOffset,
965
- // isAbsolutePositioningNeeded: isAbsolute
966
- // });
967
- // }
968
-
969
-
970
- this.resizePositionRafId = null;
971
- });
972
- }
973
- }
974
- });
975
- });
976
- }
977
-
978
- handleResize() {
979
- this.handleOpenPopupPositionChange();
980
- } // handleScroll(e) {
981
- // // this.handleOpenPopupPositionChange();
982
- // const { closeOnScroll } = this.getCloseOnScrollPopup(this);
983
- // const { isPopupReady } = this.state;
984
- // if (isPopupReady) {
985
- // console.log('onscrollPopupREady');
986
- // }
987
- // if (isPopupReady && closeOnScroll) {
988
- // console.log(this, 'handle Scroll');
989
- // this.togglePopup(e);
990
- // }
991
- // }
992
-
993
-
994
- handlePopupResize(popupSize) {
995
- const {
996
- height,
997
- width
998
- } = popupSize;
999
- const {
1000
- height: oldHeight = 0,
1001
- width: oldWidth = 0
1002
- } = this.size || {};
1003
- const {
1004
- isPopupReady,
1005
- position
1006
- } = this.state;
1007
-
1008
- if (isPopupReady && this.size && (oldHeight !== height || width !== oldWidth)) {
1009
- this.handlePopupPosition(position, true);
1010
- }
1011
-
1012
- this.size = popupSize;
1013
- }
1014
-
1015
- getTargetRef(el) {
1016
- this.placeHolderElement = el;
1017
- }
1018
-
1019
- getContainerRef(el) {
1020
- this.dropElement = el;
1021
- }
1022
-
1023
- render() {
1024
- // const { isPopupReady, isPopupOpen } = this.state;
1025
- const {
1026
- isMobile,
1027
- ...restState
1028
- } = this.state; // const localState = isPopupReady ? this.state : {};
1029
-
1030
- return /*#__PURE__*/React.createElement(Component, { ...this.props,
1031
- ...restState,
1032
- openPopupOnly: this.openPopupOnly,
1033
- closePopupOnly: this.closePopupOnly,
1034
- togglePopup: this.togglePopup,
1035
- removeClose: this.removeClose,
1036
- getTargetRef: this.getTargetRef,
1037
- getContainerRef: this.getContainerRef
1038
- });
1039
- }
1040
-
1041
- }
1042
-
1043
- Popup.displayName = Component.displayName || Component.name || Popup.name;
1044
- Popup.contextTypes = ContextTypes;
1045
- Popup.propTypes = PopupPropTypes;
1046
- return hoistStatics(Popup, Component);
8
+ let options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
9
+ const {
10
+ isAbsolutePositioningNeeded = true,
11
+ isArrow = false,
12
+ customOrder = [],
13
+ scrollDebounceTime = 0,
14
+ closeOnScroll = false,
15
+ isOutsideScrollBlocked = false
16
+ } = options;
17
+ const getRootElement = getLibraryConfig('getRootElement');
18
+ const mobileWidth = getLibraryConfig('mobileWidth');
19
+ return DotkitPopup(Component, group, needResizeHandling, {
20
+ isAbsolutePositioningNeeded,
21
+ isArrow,
22
+ customOrder,
23
+ scrollDebounceTime,
24
+ closeOnScroll,
25
+ isOutsideScrollBlocked
26
+ }, getRootElement, mobileWidth);
1047
27
  };
1048
28
 
1049
29
  export default Popup;