@zohodesk/components 1.2.3 → 1.2.5

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 (205) hide show
  1. package/.cli/PropLessFiles.html +1 -1
  2. package/.cli/PropValidationExcludeFilesArray.js +10 -2
  3. package/.cli/propValidation_report.html +1 -1
  4. package/README.md +8 -0
  5. package/coverage/Button/Button.js.html +1 -1
  6. package/coverage/Button/css/Button.module.css.html +1 -1
  7. package/coverage/Button/css/cssJSLogic.js.html +1 -1
  8. package/coverage/Button/css/index.html +1 -1
  9. package/coverage/Button/index.html +1 -1
  10. package/coverage/Button/props/defaultProps.js.html +1 -1
  11. package/coverage/Button/props/index.html +1 -1
  12. package/coverage/Button/props/propTypes.js.html +1 -1
  13. package/coverage/Buttongroup/Buttongroup.js.html +1 -1
  14. package/coverage/Buttongroup/Buttongroup.module.css.html +1 -1
  15. package/coverage/Buttongroup/index.html +1 -1
  16. package/coverage/Buttongroup/props/defaultProps.js.html +1 -1
  17. package/coverage/Buttongroup/props/index.html +1 -1
  18. package/coverage/Buttongroup/props/propTypes.js.html +1 -1
  19. package/coverage/index.html +1 -1
  20. package/coverage/utils/dummyFunction.js.html +1 -1
  21. package/coverage/utils/index.html +1 -1
  22. package/es/index.js +2 -1
  23. package/es/v1/Accordion/Accordion.js +65 -0
  24. package/es/v1/Accordion/AccordionItem.js +57 -0
  25. package/es/v1/Accordion/index.js +2 -0
  26. package/es/v1/Animation/Animation.js +127 -0
  27. package/es/v1/AppContainer/AppContainer.js +134 -0
  28. package/es/v1/Avatar/Avatar.js +189 -0
  29. package/es/v1/AvatarTeam/AvatarTeam.js +70 -0
  30. package/es/v1/Button/Button.js +68 -0
  31. package/es/v1/Buttongroup/Buttongroup.js +31 -0
  32. package/es/v1/Card/Card.js +271 -0
  33. package/es/v1/CheckBox/CheckBox.js +155 -0
  34. package/es/v1/DateTime/CalendarView.js +218 -0
  35. package/es/v1/DateTime/DateTime.js +783 -0
  36. package/es/v1/DateTime/DateTimePopupFooter.js +47 -0
  37. package/es/v1/DateTime/DateTimePopupHeader.js +105 -0
  38. package/es/v1/DateTime/DateWidget.js +1098 -0
  39. package/es/v1/DateTime/DaysRow.js +31 -0
  40. package/es/v1/DateTime/Time.js +166 -0
  41. package/es/v1/DateTime/YearView.js +264 -0
  42. package/es/v1/DateTime/index.js +1 -0
  43. package/es/v1/DropBox/DropBox.js +91 -0
  44. package/es/v1/DropBox/DropBoxElement/DropBoxElement.js +132 -0
  45. package/es/v1/DropDown/DropDown.js +73 -0
  46. package/es/v1/DropDown/DropDownHeading.js +44 -0
  47. package/es/v1/DropDown/DropDownItem.js +76 -0
  48. package/es/v1/DropDown/DropDownSearch.js +63 -0
  49. package/es/v1/DropDown/DropDownSeparator.js +15 -0
  50. package/es/v1/Heading/Heading.js +32 -0
  51. package/es/v1/Label/Label.js +40 -0
  52. package/es/v1/Layout/Box.js +115 -0
  53. package/es/v1/Layout/Container.js +132 -0
  54. package/es/v1/Layout/index.js +2 -0
  55. package/es/v1/ListItem/ListContainer.js +102 -0
  56. package/es/v1/ListItem/ListItem.js +124 -0
  57. package/es/v1/ListItem/ListItemWithAvatar.js +145 -0
  58. package/es/v1/ListItem/ListItemWithCheckBox.js +104 -0
  59. package/es/v1/ListItem/ListItemWithIcon.js +127 -0
  60. package/es/v1/ListItem/ListItemWithRadio.js +105 -0
  61. package/es/v1/ListItem/index.js +6 -0
  62. package/es/v1/Modal/Modal.js +154 -0
  63. package/es/v1/MultiSelect/AdvancedGroupMultiSelect.js +1079 -0
  64. package/es/v1/MultiSelect/AdvancedMultiSelect.js +568 -0
  65. package/es/v1/MultiSelect/EmptyState.js +64 -0
  66. package/es/v1/MultiSelect/MobileHeader/MobileHeader.js +50 -0
  67. package/es/v1/MultiSelect/MultiSelect.js +1120 -0
  68. package/es/v1/MultiSelect/MultiSelectHeader.js +32 -0
  69. package/es/v1/MultiSelect/MultiSelectWithAvatar.js +216 -0
  70. package/es/v1/MultiSelect/SelectedOptions.js +82 -0
  71. package/es/v1/MultiSelect/Suggestions.js +142 -0
  72. package/es/v1/MultiSelect/index.js +4 -0
  73. package/es/v1/PopOver/PopOver.js +211 -0
  74. package/es/v1/Popup/Popup.js +645 -0
  75. package/es/v1/Radio/Radio.js +115 -0
  76. package/es/v1/Responsive/CustomResponsive.js +195 -0
  77. package/es/v1/Responsive/RefWrapper.js +39 -0
  78. package/es/v1/Responsive/ResizeComponent.js +197 -0
  79. package/es/v1/Responsive/ResizeObserver.js +140 -0
  80. package/es/v1/Responsive/Responsive.js +194 -0
  81. package/es/v1/Responsive/index.js +9 -0
  82. package/es/v1/ResponsiveDropBox/ResponsiveDropBox.js +58 -0
  83. package/es/v1/Ribbon/Ribbon.js +33 -0
  84. package/es/v1/RippleEffect/RippleEffect.js +24 -0
  85. package/es/v1/Select/GroupSelect.js +803 -0
  86. package/es/v1/Select/Select.js +969 -0
  87. package/es/v1/Select/SelectWithAvatar.js +344 -0
  88. package/es/v1/Select/SelectWithIcon.js +535 -0
  89. package/es/v1/Select/index.js +4 -0
  90. package/es/v1/Stencils/Stencils.js +26 -0
  91. package/es/v1/Switch/Switch.js +94 -0
  92. package/es/v1/Tab/Tab.js +108 -0
  93. package/es/v1/Tab/TabContent.js +30 -0
  94. package/es/v1/Tab/TabContentWrapper.js +29 -0
  95. package/es/v1/Tab/TabWrapper.js +57 -0
  96. package/es/v1/Tab/Tabs.js +612 -0
  97. package/es/v1/Tab/index.js +5 -0
  98. package/es/v1/Tag/Tag.js +134 -0
  99. package/es/v1/TextBox/TextBox.js +154 -0
  100. package/es/v1/TextBoxIcon/TextBoxIcon.js +158 -0
  101. package/es/v1/Textarea/Textarea.js +102 -0
  102. package/es/v1/Tooltip/Tooltip.js +518 -0
  103. package/es/v1/Typography/Typography.js +38 -0
  104. package/es/v1/Typography/css/Typography.module.css +376 -0
  105. package/es/v1/Typography/css/cssJSLogic.js +46 -0
  106. package/es/v1/Typography/css/letterSpacingMap.js +12 -0
  107. package/es/v1/Typography/props/defaultProps.js +8 -0
  108. package/es/v1/Typography/props/propTypes.js +24 -0
  109. package/es/v1/VelocityAnimation/VelocityAnimation/VelocityAnimation.js +69 -0
  110. package/es/v1/VelocityAnimation/VelocityAnimationGroup/VelocityAnimationGroup.js +100 -0
  111. package/es/v1/semantic/Button/Button.js +53 -0
  112. package/es/v1/semantic/index.js +1 -0
  113. package/lib/index.js +10 -1
  114. package/lib/v1/Accordion/Accordion.js +96 -0
  115. package/lib/v1/Accordion/AccordionItem.js +68 -0
  116. package/lib/v1/Accordion/index.js +23 -0
  117. package/lib/v1/Animation/Animation.js +143 -0
  118. package/lib/v1/AppContainer/AppContainer.js +204 -0
  119. package/lib/v1/Avatar/Avatar.js +246 -0
  120. package/lib/v1/AvatarTeam/AvatarTeam.js +81 -0
  121. package/lib/v1/Button/Button.js +82 -0
  122. package/lib/v1/Buttongroup/Buttongroup.js +44 -0
  123. package/lib/v1/Card/Card.js +365 -0
  124. package/lib/v1/CheckBox/CheckBox.js +166 -0
  125. package/lib/v1/DateTime/CalendarView.js +285 -0
  126. package/lib/v1/DateTime/DateTime.js +872 -0
  127. package/lib/v1/DateTime/DateTimePopupFooter.js +96 -0
  128. package/lib/v1/DateTime/DateTimePopupHeader.js +166 -0
  129. package/lib/v1/DateTime/DateWidget.js +1125 -0
  130. package/lib/v1/DateTime/DaysRow.js +80 -0
  131. package/lib/v1/DateTime/Time.js +254 -0
  132. package/lib/v1/DateTime/YearView.js +325 -0
  133. package/lib/v1/DateTime/index.js +15 -0
  134. package/lib/v1/DropBox/DropBox.js +119 -0
  135. package/lib/v1/DropBox/DropBoxElement/DropBoxElement.js +145 -0
  136. package/lib/v1/DropDown/DropDown.js +170 -0
  137. package/lib/v1/DropDown/DropDownHeading.js +93 -0
  138. package/lib/v1/DropDown/DropDownItem.js +127 -0
  139. package/lib/v1/DropDown/DropDownSearch.js +113 -0
  140. package/lib/v1/DropDown/DropDownSeparator.js +64 -0
  141. package/lib/v1/Heading/Heading.js +49 -0
  142. package/lib/v1/Label/Label.js +51 -0
  143. package/lib/v1/Layout/Box.js +128 -0
  144. package/lib/v1/Layout/Container.js +145 -0
  145. package/lib/v1/Layout/index.js +23 -0
  146. package/lib/v1/ListItem/ListContainer.js +120 -0
  147. package/lib/v1/ListItem/ListItem.js +138 -0
  148. package/lib/v1/ListItem/ListItemWithAvatar.js +162 -0
  149. package/lib/v1/ListItem/ListItemWithCheckBox.js +125 -0
  150. package/lib/v1/ListItem/ListItemWithIcon.js +143 -0
  151. package/lib/v1/ListItem/ListItemWithRadio.js +126 -0
  152. package/lib/v1/ListItem/index.js +55 -0
  153. package/lib/v1/Modal/Modal.js +212 -0
  154. package/lib/v1/MultiSelect/AdvancedGroupMultiSelect.js +1167 -0
  155. package/lib/v1/MultiSelect/AdvancedMultiSelect.js +634 -0
  156. package/lib/v1/MultiSelect/EmptyState.js +112 -0
  157. package/lib/v1/MultiSelect/MobileHeader/MobileHeader.js +62 -0
  158. package/lib/v1/MultiSelect/MultiSelect.js +1201 -0
  159. package/lib/v1/MultiSelect/MultiSelectHeader.js +78 -0
  160. package/lib/v1/MultiSelect/MultiSelectWithAvatar.js +270 -0
  161. package/lib/v1/MultiSelect/SelectedOptions.js +126 -0
  162. package/lib/v1/MultiSelect/Suggestions.js +195 -0
  163. package/lib/v1/MultiSelect/index.js +39 -0
  164. package/lib/v1/PopOver/PopOver.js +293 -0
  165. package/lib/v1/Popup/Popup.js +715 -0
  166. package/lib/v1/Radio/Radio.js +126 -0
  167. package/lib/v1/Responsive/CustomResponsive.js +242 -0
  168. package/lib/v1/Responsive/RefWrapper.js +57 -0
  169. package/lib/v1/Responsive/ResizeComponent.js +268 -0
  170. package/lib/v1/Responsive/ResizeObserver.js +168 -0
  171. package/lib/v1/Responsive/Responsive.js +274 -0
  172. package/lib/v1/Responsive/index.js +55 -0
  173. package/lib/v1/ResponsiveDropBox/ResponsiveDropBox.js +79 -0
  174. package/lib/v1/Ribbon/Ribbon.js +44 -0
  175. package/lib/v1/RippleEffect/RippleEffect.js +39 -0
  176. package/lib/v1/Select/GroupSelect.js +877 -0
  177. package/lib/v1/Select/Select.js +1013 -0
  178. package/lib/v1/Select/SelectWithAvatar.js +394 -0
  179. package/lib/v1/Select/SelectWithIcon.js +597 -0
  180. package/lib/v1/Select/index.js +39 -0
  181. package/lib/v1/Stencils/Stencils.js +43 -0
  182. package/lib/v1/Switch/Switch.js +108 -0
  183. package/lib/v1/Tab/Tab.js +132 -0
  184. package/lib/v1/Tab/TabContent.js +42 -0
  185. package/lib/v1/Tab/TabContentWrapper.js +42 -0
  186. package/lib/v1/Tab/TabWrapper.js +89 -0
  187. package/lib/v1/Tab/Tabs.js +680 -0
  188. package/lib/v1/Tab/index.js +47 -0
  189. package/lib/v1/Tag/Tag.js +154 -0
  190. package/lib/v1/TextBox/TextBox.js +168 -0
  191. package/lib/v1/TextBoxIcon/TextBoxIcon.js +196 -0
  192. package/lib/v1/Textarea/Textarea.js +118 -0
  193. package/lib/v1/Tooltip/Tooltip.js +586 -0
  194. package/lib/v1/Typography/Typography.js +56 -0
  195. package/lib/v1/Typography/css/Typography.module.css +376 -0
  196. package/lib/v1/Typography/css/cssJSLogic.js +41 -0
  197. package/lib/v1/Typography/css/letterSpacingMap.js +20 -0
  198. package/lib/v1/Typography/props/defaultProps.js +15 -0
  199. package/lib/v1/Typography/props/propTypes.js +35 -0
  200. package/lib/v1/VelocityAnimation/VelocityAnimation/VelocityAnimation.js +90 -0
  201. package/lib/v1/VelocityAnimation/VelocityAnimationGroup/VelocityAnimationGroup.js +126 -0
  202. package/lib/v1/semantic/Button/Button.js +63 -0
  203. package/lib/v1/semantic/index.js +15 -0
  204. package/package.json +4 -4
  205. package/result.json +1 -1
@@ -0,0 +1,645 @@
1
+ function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
2
+
3
+ /**** Libraries ****/
4
+ import React from 'react';
5
+ import PropTypes from 'prop-types';
6
+ import hoistStatics from 'hoist-non-react-statics';
7
+ /**** Methods ****/
8
+
9
+ import { debounce, isDescendant, isTextSelected, cancelBubblingEffect } from '../../utils/Common.js';
10
+ import viewPort from './viewPort';
11
+ import { absolutePositionMapping, rtlAbsolutePositionMapping, rtlFixedPositionMapping } from '../../Popup/PositionMapping.json';
12
+ import ResizeObserver from '@zohodesk/virtualizer/lib/commons/ResizeObserver.js';
13
+ let lastOpenedGroup = [];
14
+ let popups = {};
15
+
16
+ global.closeGroupPopups = function (groupName) {
17
+ const groupPopups = popups[groupName] || [];
18
+ groupPopups.forEach(popup => {
19
+ popup.state.isPopupOpen && popup.setState({
20
+ isPopupOpen: false,
21
+ isPopupReady: false
22
+ });
23
+ });
24
+ };
25
+
26
+ const defaultState = {
27
+ position: 'bottomCenter',
28
+ height: '0px',
29
+ positions: {},
30
+ //{bottomCenter: true, bottomLeft: false, ...}
31
+ positionsOffset: {},
32
+ //{bottomCenter: {left: ‘’,top: ‘’ }, .....}
33
+ targetOffset: {},
34
+ //{height: ‘’, width: ‘’,}
35
+ popupOffset: {},
36
+ //{height: ‘’, width: ‘’,}
37
+ isAbsolutePositioningNeeded: true
38
+ };
39
+ /* eslint-disable react/no-deprecated */
40
+
41
+ /* eslint-disable react/prop-types */
42
+
43
+ const Popup = function (Component) {
44
+ let group = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'global';
45
+ let needResizeHandling = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
46
+ let {
47
+ isAbsolutePositioningNeeded: isAbsolutePopup = true,
48
+ isArrow: needPopupArrow = false,
49
+ customOrder: customPositionOrder = [],
50
+ scrollDebounceTime: popupScrollDebounceTime = 0,
51
+ closeOnScroll: closeOnScrollPopup = false
52
+ } = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
53
+
54
+ class Popup extends React.Component {
55
+ constructor(props) {
56
+ super(props);
57
+ this.state = {
58
+ isPopupOpen: props.isPopupOpen || false,
59
+ position: 'bottomCenter',
60
+ height: '0px',
61
+ isPopupReady: props.isPopupOpen || false,
62
+ positions: {},
63
+ //{bottomCenter: true, bottomLeft: false, ...}
64
+ positionsOffset: {},
65
+ //{bottomCenter: {left: ‘’,top: ‘’ }, .....}
66
+ targetOffset: {},
67
+ //{height: ‘’, width: ‘’,}
68
+ popupOffset: {},
69
+ //{height: ‘’, width: ‘’,}
70
+ isAbsolutePositioningNeeded: true
71
+ };
72
+ this.togglePopup = this.togglePopup.bind(this);
73
+ this.documentClickHandler = this.documentClickHandler.bind(this);
74
+ this.documentClickHandler1 = this.documentClickHandler1.bind(this);
75
+ this.removeClose = this.removeClose.bind(this);
76
+ this.documentKeyupHandler = this.documentKeyupHandler.bind(this);
77
+ this.openPopupOnly = this.openPopupOnly.bind(this);
78
+ this.closePopupOnly = this.closePopupOnly.bind(this);
79
+ this.getTargetRef = this.getTargetRef.bind(this);
80
+ this.getContainerRef = this.getContainerRef.bind(this);
81
+ this.handlePopupPosition = this.handlePopupPosition.bind(this);
82
+ this.handleResize = debounce(this.handleResize.bind(this), 300);
83
+ this.handlePopupResize = this.handlePopupResize.bind(this);
84
+ this.getIsAbsolutePopup = this.getIsAbsolutePopup.bind(this);
85
+ this.getNeedArrow = this.getNeedArrow.bind(this);
86
+ this.getCustomPositionOrder = this.getCustomPositionOrder.bind(this);
87
+ this.handleOpenPopupPositionChange = this.handleOpenPopupPositionChange.bind(this);
88
+ this.getScrollDebounceTime = this.getScrollDebounceTime.bind(this);
89
+ this.getCloseOnScrollPopup = this.getCloseOnScrollPopup.bind(this);
90
+ this.handleCloseLastOpenedGroup = this.handleCloseLastOpenedGroup.bind(this);
91
+ this.handleDocumentMouseDown = this.handleDocumentMouseDown.bind(this);
92
+ this.handleDocumentFocus = this.handleDocumentFocus.bind(this);
93
+ this.handleGetNeedPrevent = this.handleGetNeedPrevent.bind(this);
94
+ this.popupObserver = new ResizeObserver(this.handlePopupResize); //dropBoxSize
95
+
96
+ this.size = null;
97
+ this.isAbsolutePopup = isAbsolutePopup;
98
+ this.needPopupArrow = needPopupArrow;
99
+ this.customPositionOrder = customPositionOrder;
100
+ this.scrollDebounceTime = popupScrollDebounceTime;
101
+ this.closeOnScroll = closeOnScrollPopup;
102
+ const {
103
+ scrollDebounceTime
104
+ } = this.getScrollDebounceTime(this);
105
+ this.handleScroll = debounce(this.handleScroll.bind(this), scrollDebounceTime);
106
+ }
107
+
108
+ componentDidMount() {
109
+ const group = this.getGroup();
110
+ const groupPopups = popups[group] || [];
111
+ groupPopups.push(this);
112
+ popups[group] = groupPopups;
113
+
114
+ if (Object.keys(popups).length === 1 && groupPopups.length === 1) {
115
+ document.addEventListener('click', this.documentClickHandler, false);
116
+ document.addEventListener('keyup', this.documentKeyupHandler, false); // document.addEventListener('scroll', this.handleScroll, true);
117
+
118
+ window.addEventListener('resize', this.handleResize);
119
+ document.addEventListener('click', this.documentClickHandler1, true);
120
+ document.addEventListener('mousedown', this.handleDocumentMouseDown, true);
121
+ document.addEventListener('focus', this.handleDocumentFocus, true);
122
+ }
123
+ }
124
+
125
+ componentWillReceiveProps(nextProps) {
126
+ const {
127
+ isPopupOpen
128
+ } = this.state;
129
+
130
+ if (typeof nextProps.isPopupOpen !== 'undefined' && nextProps.isPopupOpen !== isPopupOpen) {
131
+ this.setState({
132
+ isPopupOpen: nextProps.isPopupOpen,
133
+ isPopupReady: nextProps.isPopupOpen
134
+ });
135
+ }
136
+ }
137
+
138
+ componentDidUpdate(prevProps, prevState) {
139
+ const {
140
+ isPopupReady
141
+ } = this.state;
142
+ const {
143
+ isPopupReady: oldStateOpen = false
144
+ } = prevState || {};
145
+ const {
146
+ dropElement
147
+ } = this;
148
+ const {
149
+ needResizeHandling: propResizeHandling
150
+ } = this.props;
151
+
152
+ if (oldStateOpen !== isPopupReady) {
153
+ if (isPopupReady && dropElement && (propResizeHandling !== undefined ? propResizeHandling : needResizeHandling)) {
154
+ this.popupObserver.replaceObservationElement(dropElement);
155
+ } else if (!isPopupReady) {
156
+ this.size = null;
157
+ this.popupObserver.disconnect();
158
+ }
159
+ }
160
+ }
161
+
162
+ componentWillUnmount() {
163
+ const group = this.getGroup();
164
+ popups = Object.keys(popups).reduce((res, groupName) => {
165
+ if (groupName === group) {
166
+ const groupPopups = popups[group];
167
+ const newGroupPopups = groupPopups.filter(popup => popup !== this);
168
+ newGroupPopups.length === 0 && lastOpenedGroup.indexOf(group) >= 0 && lastOpenedGroup.splice(lastOpenedGroup.indexOf(group), 1);
169
+ res[group] = newGroupPopups;
170
+ }
171
+
172
+ return res;
173
+ }, popups);
174
+ let noPopups = true;
175
+
176
+ for (const i in popups) {
177
+ if (popups[i].length >= 1) {
178
+ noPopups = false;
179
+ break;
180
+ }
181
+ }
182
+
183
+ if (this.popupObserver) {
184
+ this.popupObserver.disconnect();
185
+ }
186
+
187
+ if (noPopups) {
188
+ document.removeEventListener('click', this.documentClickHandler);
189
+ document.removeEventListener('keyup', this.documentKeyupHandler); // document.removeEventListener('scroll', this.handleScroll);
190
+
191
+ window.removeEventListener('resize', this.handleResize);
192
+ document.removeEventListener('click', this.documentClickHandler1, true);
193
+ document.removeEventListener('mousedown', this.handleDocumentMouseDown, true);
194
+ document.removeEventListener('focus', this.handleDocumentFocus, true);
195
+ }
196
+ }
197
+
198
+ getGroup() {
199
+ const {
200
+ popupGroup
201
+ } = this.props;
202
+ return popupGroup || group;
203
+ }
204
+
205
+ getNeedArrow(popup) {
206
+ const {
207
+ isArrow
208
+ } = popup.props;
209
+ const {
210
+ needPopupArrow
211
+ } = popup;
212
+ return isArrow !== undefined ? isArrow : needPopupArrow;
213
+ }
214
+
215
+ getScrollDebounceTime(popup) {
216
+ const {
217
+ scrollDebounceTime
218
+ } = popup.props;
219
+ const {
220
+ scrollDebounceTime: popupScrollDebounceTime
221
+ } = popup;
222
+ return scrollDebounceTime !== undefined ? scrollDebounceTime : popupScrollDebounceTime;
223
+ }
224
+
225
+ getCloseOnScrollPopup(popup) {
226
+ const {
227
+ closeOnScroll
228
+ } = popup.props;
229
+ const {
230
+ closeOnScroll: closeOnScrollPopup
231
+ } = popup;
232
+ return closeOnScroll !== undefined ? closeOnScroll : closeOnScrollPopup;
233
+ }
234
+
235
+ getIsAbsolutePopup(popup) {
236
+ const {
237
+ isAbsolutePositioningNeeded
238
+ } = popup.props;
239
+ const {
240
+ isAbsolutePopup
241
+ } = popup;
242
+ return isAbsolutePositioningNeeded !== undefined ? isAbsolutePositioningNeeded : isAbsolutePopup;
243
+ }
244
+
245
+ getCustomPositionOrder(popup) {
246
+ const {
247
+ customOrder = []
248
+ } = popup.props;
249
+ const {
250
+ customPositionOrder
251
+ } = popup;
252
+ return customOrder.length !== 0 ? customOrder : customPositionOrder;
253
+ }
254
+
255
+ togglePopup(e, defaultPosition) {
256
+ const group = this.getGroup();
257
+ this.removeClose(e);
258
+ const {
259
+ isPopupOpen
260
+ } = this.state;
261
+ const groupPopups = popups[group] || [];
262
+ lastOpenedGroup = !isPopupOpen && lastOpenedGroup.indexOf(group) === -1 ? [group, ...lastOpenedGroup] : lastOpenedGroup;
263
+ isPopupOpen && lastOpenedGroup.splice(0, 1);
264
+ groupPopups.forEach(popup => {
265
+ if (popup !== this && popup.state.isPopupOpen) {
266
+ popup.setState({
267
+ isPopupOpen: false,
268
+ isPopupReady: false
269
+ });
270
+ }
271
+ });
272
+
273
+ if (isPopupOpen) {
274
+ this.setState({
275
+ isPopupOpen: false,
276
+ isPopupReady: false
277
+ });
278
+ } else {
279
+ this.handlePopupPosition(defaultPosition);
280
+ }
281
+ }
282
+
283
+ openPopupOnly(e, defaultPosition) {
284
+ const group = this.getGroup();
285
+ this.removeClose(e);
286
+ lastOpenedGroup = lastOpenedGroup.indexOf(group) === -1 ? [group, ...lastOpenedGroup] : lastOpenedGroup;
287
+ this.handlePopupPosition(defaultPosition);
288
+ }
289
+
290
+ closePopupOnly(e) {
291
+ this.removeClose(e);
292
+ lastOpenedGroup.splice(0, 1);
293
+ const {
294
+ isPopupOpen
295
+ } = this.state;
296
+
297
+ if (isPopupOpen) {
298
+ this.setState({
299
+ isPopupOpen: false,
300
+ isPopupReady: false
301
+ });
302
+ }
303
+ }
304
+
305
+ handleCloseLastOpenedGroup() {
306
+ const groupPopups = lastOpenedGroup.length ? popups[lastOpenedGroup[0]] || [] : [];
307
+ lastOpenedGroup.splice(0, 1);
308
+ groupPopups.forEach(popup => {
309
+ popup.state.isPopupOpen && popup.setState({
310
+ isPopupOpen: false,
311
+ isPopupReady: false
312
+ });
313
+ });
314
+ }
315
+
316
+ handleDocumentMouseDown(e) {
317
+ const needPrevent = this.handleGetNeedPrevent(e);
318
+
319
+ if (needPrevent) {
320
+ this.removeClose(e);
321
+ }
322
+ }
323
+
324
+ handleDocumentFocus(e) {
325
+ const needPrevent = this.handleGetNeedPrevent(e);
326
+
327
+ if (needPrevent) {
328
+ this.removeClose(e);
329
+ }
330
+ }
331
+
332
+ handleGetNeedPrevent(e) {
333
+ let needPrevent = false;
334
+
335
+ if (lastOpenedGroup.length > 1) {
336
+ const {
337
+ target
338
+ } = e;
339
+ const groupPopups = lastOpenedGroup.length ? popups[lastOpenedGroup[0]] : [];
340
+ let openedPopup = null; // eslint-disable-next-line guard-for-in
341
+
342
+ for (const i in groupPopups) {
343
+ const {
344
+ isPopupOpen
345
+ } = groupPopups[i].state;
346
+
347
+ if (isPopupOpen) {
348
+ openedPopup = groupPopups[i];
349
+ break;
350
+ }
351
+ }
352
+
353
+ if (openedPopup) {
354
+ const {
355
+ dropElement,
356
+ placeHolderElement
357
+ } = openedPopup;
358
+ const isDropBoxChild = isDescendant(dropElement, target);
359
+ const isTargetChild = isDescendant(placeHolderElement, target); // const isPopupMassUpdateChild = isDescendant(
360
+ // massUpdateParent,
361
+ // dropElement
362
+ // );
363
+
364
+ if (!isDropBoxChild && !isTargetChild // && isPopupMassUpdateChild
365
+ ) {
366
+ needPrevent = true;
367
+ }
368
+ }
369
+ }
370
+
371
+ return needPrevent;
372
+ }
373
+
374
+ documentClickHandler1(e) {
375
+ const needPrevent = this.handleGetNeedPrevent(e);
376
+
377
+ if (needPrevent) {
378
+ this.removeClose(e);
379
+ this.handleCloseLastOpenedGroup();
380
+ }
381
+ }
382
+
383
+ documentClickHandler() {
384
+ try {
385
+ Object.keys(popups).forEach(groupName => {
386
+ const groupPopups = popups[groupName] || [];
387
+ groupPopups.forEach(popup => {
388
+ popup.state.isPopupOpen && (!popup.props.checkBeforeClose || popup.props.checkBeforeClose && popup.props.checkBeforeClose()) && !isTextSelected() && popup.setState({
389
+ isPopupOpen: false,
390
+ isPopupReady: false
391
+ });
392
+ });
393
+ });
394
+ lastOpenedGroup = [];
395
+ } catch (e) {// eslint-disable-next-line no-console
396
+ //console.error('popup component not unmounted properly', e);
397
+ }
398
+ }
399
+
400
+ documentKeyupHandler(e) {
401
+ try {
402
+ if (e.keyCode === 27) {
403
+ this.handleCloseLastOpenedGroup();
404
+ }
405
+ } catch (e) {// eslint-disable-next-line no-console
406
+ //console.log('error', e);
407
+ }
408
+ }
409
+
410
+ removeClose(e) {
411
+ // e && e.preventDefault && e.preventDefault();
412
+ cancelBubblingEffect(e);
413
+ }
414
+
415
+ handlePopupPosition() {
416
+ let defaultPosition = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'bottomCenter';
417
+ let isResizeHandling = arguments.length > 1 ? arguments[1] : undefined;
418
+ // isResizeHandling --->>> Window resize and dropBox resize
419
+ const {
420
+ direction
421
+ } = this.context || {};
422
+ const {
423
+ placeHolderElement,
424
+ dropElement
425
+ } = this;
426
+ const needArrow = this.getNeedArrow(this);
427
+ const isAbsolute = this.getIsAbsolutePopup(this);
428
+ const customOrder = this.getCustomPositionOrder(this);
429
+
430
+ if (direction === 'rtl') {
431
+ defaultPosition = isAbsolute ? rtlAbsolutePositionMapping[defaultPosition] : rtlFixedPositionMapping[defaultPosition];
432
+ } else {
433
+ defaultPosition = isAbsolute ? absolutePositionMapping[defaultPosition] : defaultPosition;
434
+ }
435
+
436
+ if (!placeHolderElement && !dropElement) {
437
+ this.setState({
438
+ isPopupOpen: true,
439
+ isPopupReady: true
440
+ });
441
+ return;
442
+ }
443
+
444
+ const setPosition = () => {
445
+ requestAnimationFrame(() => {
446
+ const {
447
+ placeHolderElement,
448
+ dropElement
449
+ } = this;
450
+ const {
451
+ position,
452
+ isPopupReady
453
+ } = this.state;
454
+ const scrollContainer = placeHolderElement.closest('[data-scroll=true]') || document.body;
455
+ const betterPosition = viewPort.betterView(dropElement, placeHolderElement, defaultPosition, scrollContainer, {
456
+ needArrow,
457
+ isAbsolute,
458
+ customOrder
459
+ });
460
+ const {
461
+ view,
462
+ views,
463
+ viewsOffset,
464
+ targetOffset,
465
+ popupOffset
466
+ } = betterPosition || {};
467
+
468
+ if (position !== view || !isPopupReady) {
469
+ this.setState({
470
+ isPopupReady: true,
471
+ position: view,
472
+ positions: views,
473
+ positionsOffset: viewsOffset,
474
+ targetOffset,
475
+ popupOffset,
476
+ isAbsolutePositioningNeeded: isAbsolute
477
+ });
478
+ }
479
+ });
480
+ };
481
+
482
+ if (isResizeHandling) {
483
+ setPosition();
484
+ } else {
485
+ this.defaultPosition = defaultPosition;
486
+ this.setState({
487
+ isPopupOpen: true,
488
+ isPopupReady: false
489
+ }, setPosition);
490
+ }
491
+ }
492
+
493
+ handleOpenPopupPositionChange() {
494
+ Object.keys(popups).forEach(groupName => {
495
+ const groupPopups = popups[groupName] || [];
496
+ groupPopups.forEach(popup => {
497
+ if (popup.state.isPopupOpen) {
498
+ const {
499
+ placeHolderElement,
500
+ dropElement,
501
+ defaultPosition
502
+ } = popup;
503
+ const {
504
+ position,
505
+ positionsOffset = {}
506
+ } = popup.state;
507
+
508
+ if (placeHolderElement && dropElement) {
509
+ const scrollContainer = placeHolderElement.closest('[data-scroll=true]') || document.body;
510
+ requestAnimationFrame(() => {
511
+ const needArrow = this.getNeedArrow(popup);
512
+ const isAbsolute = this.getIsAbsolutePopup(popup);
513
+ const customOrder = this.getCustomPositionOrder(popup);
514
+ const betterPosition = viewPort.betterView(dropElement, placeHolderElement, defaultPosition, scrollContainer, {
515
+ needArrow,
516
+ isAbsolute,
517
+ customOrder
518
+ });
519
+ const {
520
+ view,
521
+ views,
522
+ viewsOffset = {},
523
+ targetOffset,
524
+ popupOffset
525
+ } = betterPosition || {};
526
+ const {
527
+ left: oldLeft = '',
528
+ top: oldTop = ''
529
+ } = positionsOffset[position] || {};
530
+ const {
531
+ left = '',
532
+ top = ''
533
+ } = viewsOffset[view] || {};
534
+ const changeState = isAbsolute ? position !== view : oldLeft !== left || oldTop !== top; // let isInViewPort = viewPort.isInViewPort(
535
+ // placeHolderElement,
536
+ // scrollContainer
537
+ // );
538
+
539
+ if (changeState) {
540
+ popup.setState({
541
+ position: view,
542
+ positions: views,
543
+ positionsOffset: viewsOffset,
544
+ targetOffset,
545
+ popupOffset,
546
+ isAbsolutePositioningNeeded: isAbsolute
547
+ });
548
+ } // if (!isInViewPort && !isAbsolute) {
549
+ // popup.setState({ isPopupOpen: false, isPopupReady: false });
550
+ // } else if (view && changeState) {
551
+ // popup.setState({
552
+ // position: view,
553
+ // positions: views,
554
+ // positionsOffset: viewsOffset,
555
+ // targetOffset,
556
+ // popupOffset,
557
+ // isAbsolutePositioningNeeded: isAbsolute
558
+ // });
559
+ // }
560
+
561
+ });
562
+ }
563
+ }
564
+ });
565
+ });
566
+ }
567
+
568
+ handleResize() {
569
+ this.handleOpenPopupPositionChange();
570
+ }
571
+
572
+ handleScroll(e) {
573
+ // this.handleOpenPopupPositionChange();
574
+ const {
575
+ closeOnScroll
576
+ } = this.getCloseOnScrollPopup(this);
577
+ const {
578
+ isPopupReady
579
+ } = this.state;
580
+
581
+ if (isPopupReady) {
582
+ console.log('onscrollPopupREady');
583
+ }
584
+
585
+ if (isPopupReady && closeOnScroll) {
586
+ console.log(this, 'handle Scroll');
587
+ this.togglePopup(e);
588
+ }
589
+ }
590
+
591
+ handlePopupResize(popupSize) {
592
+ const {
593
+ height,
594
+ width
595
+ } = popupSize;
596
+ const {
597
+ height: oldHeight = 0,
598
+ width: oldWidth = 0
599
+ } = this.size || {};
600
+ const {
601
+ isPopupReady,
602
+ position
603
+ } = this.state;
604
+
605
+ if (isPopupReady && this.size && (oldHeight !== height || width !== oldWidth)) {
606
+ this.handlePopupPosition(position, true);
607
+ }
608
+
609
+ this.size = popupSize;
610
+ }
611
+
612
+ getTargetRef(el) {
613
+ this.placeHolderElement = el;
614
+ }
615
+
616
+ getContainerRef(el) {
617
+ this.dropElement = el;
618
+ }
619
+
620
+ render() {
621
+ const {
622
+ isPopupReady,
623
+ isPopupOpen
624
+ } = this.state;
625
+ const localState = isPopupReady ? this.state : {};
626
+ return /*#__PURE__*/React.createElement(Component, _extends({}, this.props, this.state, {
627
+ openPopupOnly: this.openPopupOnly,
628
+ closePopupOnly: this.closePopupOnly,
629
+ togglePopup: this.togglePopup,
630
+ removeClose: this.removeClose,
631
+ getTargetRef: this.getTargetRef,
632
+ getContainerRef: this.getContainerRef
633
+ }));
634
+ }
635
+
636
+ }
637
+
638
+ Popup.displayName = Component.displayName || Component.name || Popup.name;
639
+ Popup.contextTypes = {
640
+ direction: PropTypes.string
641
+ };
642
+ return hoistStatics(Popup, Component);
643
+ };
644
+
645
+ export default Popup;