@zohodesk/components 1.5.3 → 1.5.4-temp-1

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.
@@ -1,7 +1,5 @@
1
1
  "use strict";
2
2
 
3
- function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
4
-
5
3
  Object.defineProperty(exports, "__esModule", {
6
4
  value: true
7
5
  });
@@ -9,1163 +7,52 @@ exports["default"] = void 0;
9
7
 
10
8
  var _react = _interopRequireDefault(require("react"));
11
9
 
12
- var _hoistNonReactStatics = _interopRequireDefault(require("hoist-non-react-statics"));
13
-
14
- var _propTypes = require("./props/propTypes");
15
-
16
- var _Common = require("../utils/Common.js");
17
-
18
- var _viewPort = _interopRequireDefault(require("./viewPort"));
19
-
20
- var _PositionMapping = require("./PositionMapping.js");
10
+ var _Popup = _interopRequireDefault(require("@zohodesk/dotkit/es/react/components/Popup/Popup"));
21
11
 
22
- var _ResizeObserver = _interopRequireDefault(require("@zohodesk/virtualizer/lib/commons/ResizeObserver.js"));
12
+ var _Config = require("../Provider/Config.js");
23
13
 
24
- var _intersectionObserver = require("./intersectionObserver");
14
+ var _Common = require("./../utils/Common.js");
25
15
 
26
- var _DropBoxPositionMapping = require("../DropBox/DropBoxPositionMapping.js");
27
-
28
- var _isMobilePopover = _interopRequireDefault(require("../DropBox/utils/isMobilePopover.js"));
29
-
30
- var _selectn = _interopRequireDefault(require("selectn"));
31
-
32
- var _Registry = _interopRequireDefault(require("./Registry.js"));
33
-
34
- var _excluded = ["isMobile"];
16
+ var _Registry = _interopRequireDefault(require("@zohodesk/dotkit/es/react/components/Popup/Registry.js"));
35
17
 
36
18
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
37
19
 
38
- 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); }
39
-
40
- function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
41
-
42
- function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
43
-
44
- function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
45
-
46
- function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
47
-
48
- function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
49
-
50
- function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
51
-
52
- function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
53
-
54
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
55
-
56
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
57
-
58
- function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
59
-
60
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
61
-
62
- function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
63
-
64
- function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
65
-
66
- function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
67
-
68
- function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
69
-
70
- function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
71
-
72
- function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
73
-
74
- function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
75
-
76
- global.closeGroupPopups = function (groupName) {
77
- var groupPopups = _Registry["default"].popups[groupName] || [];
78
- groupPopups.forEach(function (popup) {
79
- popup.state.isPopupOpen && popup.setState({
80
- isPopupOpen: false,
81
- isPopupReady: false
82
- });
83
- });
84
- };
85
-
86
- var defaultState = {
87
- position: 'bottomCenter',
88
- height: '0px',
89
- positions: {},
90
- //{bottomCenter: true, bottomLeft: false, ...}
91
- positionsOffset: {},
92
- //{bottomCenter: {left: ‘’,top: ‘’ }, .....}
93
- targetOffset: {},
94
- //{height: ‘’, width: ‘’,}
95
- popupOffset: {},
96
- //{height: ‘’, width: ‘’,}
97
- isAbsolutePositioningNeeded: true
98
- };
99
- var SCROLL_BLOCK_EVENTS = Object.freeze([{
100
- name: 'wheel',
101
- handlerName: 'handleBlockScroll',
102
- options: {
103
- capture: true,
104
- passive: false
105
- }
106
- }, {
107
- name: 'touchmove',
108
- handlerName: 'handleBlockScroll',
109
- options: {
110
- capture: true,
111
- passive: false
112
- }
113
- }, {
114
- name: 'scroll',
115
- handlerName: 'handlePositionChange',
116
- options: {
117
- capture: true,
118
- passive: false
119
- }
120
- }, {
121
- name: 'keydown',
122
- handlerName: 'preventKeyboardScroll',
123
- options: {
124
- capture: true,
125
- passive: false
126
- }
127
- }]);
128
- var IFRAME_SCROLL_BLOCK_EVENTS = Object.freeze(SCROLL_BLOCK_EVENTS.filter(function (event) {
129
- return event.name !== 'keydown';
130
- }));
131
- var CLICK_EVENTS = Object.freeze([{
132
- name: 'click',
133
- handlerName: 'documentClickHandler',
134
- options: {
135
- capture: false,
136
- passive: false
137
- }
138
- }, {
139
- name: 'click',
140
- handlerName: 'documentClickHandler1',
141
- options: {
142
- capture: true,
143
- passive: false
144
- }
145
- }]);
146
- /* eslint-disable react/no-deprecated */
147
-
148
- /* eslint-disable react/prop-types */
20
+ global.closeGroupPopups = _Registry["default"].closeAllPopupsInGroup;
149
21
 
150
22
  var Popup = function Popup(Component) {
151
23
  var group = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'global';
152
24
  var needResizeHandling = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
153
-
154
- var _ref = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {},
155
- _ref$isAbsolutePositi = _ref.isAbsolutePositioningNeeded,
156
- isAbsolutePopup = _ref$isAbsolutePositi === void 0 ? true : _ref$isAbsolutePositi,
157
- _ref$isArrow = _ref.isArrow,
158
- needPopupArrow = _ref$isArrow === void 0 ? false : _ref$isArrow,
159
- _ref$customOrder = _ref.customOrder,
160
- customPositionOrder = _ref$customOrder === void 0 ? [] : _ref$customOrder,
161
- _ref$scrollDebounceTi = _ref.scrollDebounceTime,
162
- popupScrollDebounceTime = _ref$scrollDebounceTi === void 0 ? 0 : _ref$scrollDebounceTi,
163
- _ref$closeOnScroll = _ref.closeOnScroll,
164
- closeOnScrollPopup = _ref$closeOnScroll === void 0 ? false : _ref$closeOnScroll,
165
- _ref$isOutsideScrollB = _ref.isOutsideScrollBlocked,
166
- isOutsideScrollBlock = _ref$isOutsideScrollB === void 0 ? false : _ref$isOutsideScrollB;
167
-
168
- var Popup = /*#__PURE__*/function (_React$Component) {
169
- _inherits(Popup, _React$Component);
170
-
171
- var _super = _createSuper(Popup);
172
-
173
- function Popup(props) {
174
- var _this;
175
-
176
- _classCallCheck(this, Popup);
177
-
178
- _this = _super.call(this, props);
179
- _this.state = {
180
- isPopupOpen: props.isPopupOpen || false,
181
- position: 'bottomCenter',
182
- height: '0px',
183
- isPopupReady: props.isPopupOpen || false,
184
- positions: {},
185
- //{bottomCenter: true, bottomLeft: false, ...}
186
- positionsOffset: {},
187
- //{bottomCenter: {left: ‘’,top: ‘’ }, .....}
188
- targetOffset: {},
189
- //{height: ‘’, width: ‘’,}
190
- popupOffset: {},
191
- //{height: ‘’, width: ‘’,}
192
- isAbsolutePositioningNeeded: true,
193
- isMobile: false
194
- };
195
- _this.togglePopup = _this.togglePopup.bind(_assertThisInitialized(_this));
196
- _this.documentClickHandler = _this.documentClickHandler.bind(_assertThisInitialized(_this));
197
- _this.documentClickHandler1 = _this.documentClickHandler1.bind(_assertThisInitialized(_this));
198
- _this.removeClose = _this.removeClose.bind(_assertThisInitialized(_this));
199
- _this.documentKeyupHandler = _this.documentKeyupHandler.bind(_assertThisInitialized(_this));
200
- _this.openPopupOnly = _this.openPopupOnly.bind(_assertThisInitialized(_this));
201
- _this.closePopupOnly = _this.closePopupOnly.bind(_assertThisInitialized(_this));
202
- _this.getTargetRef = _this.getTargetRef.bind(_assertThisInitialized(_this));
203
- _this.getContainerRef = _this.getContainerRef.bind(_assertThisInitialized(_this));
204
- _this.handlePopupPosition = _this.handlePopupPosition.bind(_assertThisInitialized(_this));
205
- _this.handleResize = (0, _Common.debounce)(_this.handleResize.bind(_assertThisInitialized(_this)), 300);
206
- _this.handlePopupResize = _this.handlePopupResize.bind(_assertThisInitialized(_this));
207
- _this.getIsAbsolutePopup = _this.getIsAbsolutePopup.bind(_assertThisInitialized(_this));
208
- _this.getIsOutsideScrollBlocked = _this.getIsOutsideScrollBlocked.bind(_assertThisInitialized(_this));
209
- _this.getNeedArrow = _this.getNeedArrow.bind(_assertThisInitialized(_this));
210
- _this.getCustomPositionOrder = _this.getCustomPositionOrder.bind(_assertThisInitialized(_this));
211
- _this.handleOpenPopupPositionChange = _this.handleOpenPopupPositionChange.bind(_assertThisInitialized(_this));
212
- _this.getScrollDebounceTime = _this.getScrollDebounceTime.bind(_assertThisInitialized(_this));
213
- _this.getCloseOnScrollPopup = _this.getCloseOnScrollPopup.bind(_assertThisInitialized(_this));
214
- _this.handleCloseLastOpenedGroup = _this.handleCloseLastOpenedGroup.bind(_assertThisInitialized(_this));
215
- _this.handleDocumentMouseDown = _this.handleDocumentMouseDown.bind(_assertThisInitialized(_this));
216
- _this.handleDocumentFocus = _this.handleDocumentFocus.bind(_assertThisInitialized(_this));
217
- _this.handleGetNeedPrevent = _this.handleGetNeedPrevent.bind(_assertThisInitialized(_this));
218
- _this.handleBlockScroll = _this.handleBlockScroll.bind(_assertThisInitialized(_this));
219
- _this.handlePositionChange = _this.handlePositionChange.bind(_assertThisInitialized(_this));
220
- _this.preventKeyboardScroll = _this.preventKeyboardScroll.bind(_assertThisInitialized(_this));
221
- _this.updateListeners = _this.updateListeners.bind(_assertThisInitialized(_this));
222
- _this.addScrollBlockListeners = _this.addScrollBlockListeners.bind(_assertThisInitialized(_this));
223
- _this.removeScrollBlockListeners = _this.removeScrollBlockListeners.bind(_assertThisInitialized(_this));
224
- _this.addScrollToUpdateListeners = _this.addScrollToUpdateListeners.bind(_assertThisInitialized(_this));
225
- _this.removeScrollToUpdateListeners = _this.removeScrollToUpdateListeners.bind(_assertThisInitialized(_this));
226
- _this.handleAddingScrollBlock = _this.handleAddingScrollBlock.bind(_assertThisInitialized(_this));
227
- _this.handleRemovingScrollBlock = _this.handleRemovingScrollBlock.bind(_assertThisInitialized(_this));
228
- _this.handleIntersectionObserver = _this.handleIntersectionObserver.bind(_assertThisInitialized(_this));
229
- _this.updateVisibilityOnIntersection = _this.updateVisibilityOnIntersection.bind(_assertThisInitialized(_this));
230
- _this.handleAddingScrollToUpdatePosition = _this.handleAddingScrollToUpdatePosition.bind(_assertThisInitialized(_this));
231
- _this.handleRemovingScrollToUpdatePosition = _this.handleRemovingScrollToUpdatePosition.bind(_assertThisInitialized(_this));
232
- _this.setContainerDynamicPositioning = _this.setContainerDynamicPositioning.bind(_assertThisInitialized(_this));
233
- _this.updatePopupState = _this.updatePopupState.bind(_assertThisInitialized(_this));
234
- _this.handleScrollAndBlockEvents = _this.handleScrollAndBlockEvents.bind(_assertThisInitialized(_this));
235
- _this.handleIframeEventListeners = _this.handleIframeEventListeners.bind(_assertThisInitialized(_this));
236
- _this.handleDropElementStyleUpdate = _this.handleDropElementStyleUpdate.bind(_assertThisInitialized(_this));
237
- _this.setPosition = _this.setPosition.bind(_assertThisInitialized(_this));
238
- _this.positionRef = /*#__PURE__*/_react["default"].createRef();
239
- _this.rootElement = _Registry["default"].getRootElement();
240
- _this.popupObserver = new _ResizeObserver["default"](_this.handlePopupResize);
241
- _this.cancelRaf = _this.cancelRaf.bind(_assertThisInitialized(_this));
242
- _this.cancelPendingAnimationFrames = _this.cancelPendingAnimationFrames.bind(_assertThisInitialized(_this));
243
- _this.setPositionRafId = null;
244
- _this.resizePositionRafId = null; //dropBoxSize
245
-
246
- _this.size = null;
247
- _this.isTargetElementVisible = false;
248
- _this.isAbsolutePopup = isAbsolutePopup;
249
- _this.needPopupArrow = needPopupArrow;
250
- _this.customPositionOrder = customPositionOrder;
251
- _this.scrollDebounceTime = popupScrollDebounceTime;
252
- _this.closeOnScroll = closeOnScrollPopup;
253
- _this.isOutsideScrollBlock = isOutsideScrollBlock;
254
-
255
- var scrollDebounceTime = _this.getScrollDebounceTime(_assertThisInitialized(_this));
256
-
257
- _this.updatePositionOnScroll = scrollDebounceTime > 0 ? (0, _Common.debounce)(_this.updatePositionOnScroll.bind(_assertThisInitialized(_this)), scrollDebounceTime) : _this.updatePositionOnScroll.bind(_assertThisInitialized(_this)); // this.handleScroll = debounce(this.handleScroll.bind(this), scrollDebounceTime);
258
-
259
- return _this;
260
- }
261
-
262
- _createClass(Popup, [{
263
- key: "componentDidMount",
264
- value: function componentDidMount() {
265
- var group = this.getGroup();
266
- var groupPopups = _Registry["default"].popups[group] || [];
267
- groupPopups.push(this);
268
- _Registry["default"].popups[group] = groupPopups;
269
-
270
- if (Object.keys(_Registry["default"].popups).length === 1 && groupPopups.length === 1 && _Registry["default"].listenerPopupRef === undefined) {
271
- _Registry["default"].listenerPopupRef = this;
272
-
273
- _Registry["default"].listenerPopupRef.updateListeners(true, CLICK_EVENTS, document);
274
-
275
- document.addEventListener('keyup', _Registry["default"].listenerPopupRef.documentKeyupHandler, false); // document.addEventListener('scroll', Registry.listenerPopupRef.handleScroll, true);
276
-
277
- window.addEventListener('resize', _Registry["default"].listenerPopupRef.handleResize);
278
- document.addEventListener('mousedown', _Registry["default"].listenerPopupRef.handleDocumentMouseDown, true);
279
- document.addEventListener('focus', _Registry["default"].listenerPopupRef.handleDocumentFocus, true);
280
- }
281
- }
282
- }, {
283
- key: "UNSAFE_componentWillReceiveProps",
284
- value: function UNSAFE_componentWillReceiveProps(nextProps) {
285
- var isPopupOpen = this.state.isPopupOpen;
286
-
287
- if (typeof nextProps.isPopupOpen !== 'undefined' && nextProps.isPopupOpen !== isPopupOpen) {
288
- this.setState({
289
- isPopupOpen: nextProps.isPopupOpen,
290
- isPopupReady: nextProps.isPopupOpen
291
- });
292
- }
293
- }
294
- }, {
295
- key: "handleScrollAndBlockEvents",
296
- value: function handleScrollAndBlockEvents(shouldAdd) {
297
- if (shouldAdd) {
298
- this.handleAddingScrollBlock();
299
- this.handleAddingScrollToUpdatePosition();
300
- } else {
301
- this.handleRemovingScrollBlock();
302
- this.handleRemovingScrollToUpdatePosition();
303
- }
304
- }
305
- }, {
306
- key: "handleIframeEventListeners",
307
- value: function handleIframeEventListeners(shouldAdd, eventList) {
308
- var _this2 = this;
309
-
310
- this.rootElement.querySelectorAll('iframe').forEach(function (frame) {
311
- var frameDocument = frame.contentDocument;
312
-
313
- if (frameDocument) {
314
- _this2.updateListeners(shouldAdd, eventList, frameDocument);
315
- }
316
- });
317
- }
318
- }, {
319
- key: "componentDidUpdate",
320
- value: function componentDidUpdate(prevProps, prevState) {
321
- var _this$state = this.state,
322
- isPopupReady = _this$state.isPopupReady,
323
- isMobile = _this$state.isMobile;
324
-
325
- var _ref2 = prevState || {},
326
- _ref2$isPopupReady = _ref2.isPopupReady,
327
- oldStateOpen = _ref2$isPopupReady === void 0 ? false : _ref2$isPopupReady,
328
- oldIsMobileState = _ref2.isMobile;
329
-
330
- var dropElement = this.dropElement;
331
- var propResizeHandling = this.props.needResizeHandling;
332
-
333
- if (oldStateOpen !== isPopupReady) {
334
- if (isPopupReady && dropElement && (propResizeHandling !== undefined ? propResizeHandling : needResizeHandling)) {
335
- this.popupObserver.replaceObservationElement(dropElement);
336
- } else if (!isPopupReady) {
337
- this.size = null;
338
- this.popupObserver.disconnect();
339
- }
340
- }
341
-
342
- if (oldStateOpen !== isPopupReady && !isMobile || oldIsMobileState !== isMobile) {
343
- var shouldAdd = isPopupReady && !isMobile;
344
- this.handleScrollAndBlockEvents(shouldAdd);
345
- this.handleIframeEventListeners(shouldAdd, CLICK_EVENTS);
346
- }
347
- }
348
- }, {
349
- key: "cancelRaf",
350
- value: function cancelRaf(refName) {
351
- var id = this[refName];
352
-
353
- if (id) {
354
- cancelAnimationFrame(id);
355
- this[refName] = null;
356
- }
357
- }
358
- }, {
359
- key: "cancelPendingAnimationFrames",
360
- value: function cancelPendingAnimationFrames() {
361
- this.cancelRaf('setPositionRafId');
362
- this.cancelRaf('resizePositionRafId');
363
- }
364
- }, {
365
- key: "componentWillUnmount",
366
- value: function componentWillUnmount() {
367
- var _this3 = this;
368
-
369
- var group = this.getGroup();
370
- _Registry["default"].popups = Object.keys(_Registry["default"].popups).reduce(function (res, groupName) {
371
- if (groupName === group) {
372
- var groupPopups = _Registry["default"].popups[group];
373
- var newGroupPopups = groupPopups.filter(function (popup) {
374
- return popup !== _this3;
375
- });
376
- newGroupPopups.length === 0 && _Registry["default"].lastOpenedGroup.indexOf(group) >= 0 && _Registry["default"].lastOpenedGroup.splice(_Registry["default"].lastOpenedGroup.indexOf(group), 1);
377
- res[group] = newGroupPopups;
378
- }
379
-
380
- return res;
381
- }, _Registry["default"].popups);
382
- this.handleRemovingScrollBlock();
383
- this.handleRemovingScrollToUpdatePosition();
384
- this.handleIframeEventListeners(false, CLICK_EVENTS);
385
- var noPopups = true;
386
-
387
- for (var i in _Registry["default"].popups) {
388
- if (_Registry["default"].popups[i].length >= 1) {
389
- noPopups = false;
390
- break;
391
- }
392
- }
393
-
394
- if (this.popupObserver) {
395
- this.popupObserver.disconnect();
396
- }
397
-
398
- if (noPopups && _Registry["default"].listenerPopupRef !== undefined) {
399
- _Registry["default"].listenerPopupRef.updateListeners(false, CLICK_EVENTS, document);
400
-
401
- document.removeEventListener('keyup', _Registry["default"].listenerPopupRef.documentKeyupHandler); // document.removeEventListener('scroll', Registry.listenerPopupRef.handleScroll);
402
-
403
- window.removeEventListener('resize', _Registry["default"].listenerPopupRef.handleResize);
404
- document.removeEventListener('mousedown', _Registry["default"].listenerPopupRef.handleDocumentMouseDown, true);
405
- document.removeEventListener('focus', _Registry["default"].listenerPopupRef.handleDocumentFocus, true);
406
- _Registry["default"].listenerPopupRef = undefined;
407
- }
408
-
409
- this.cancelPendingAnimationFrames();
410
- }
411
- }, {
412
- key: "handleAddingScrollBlock",
413
- value: function handleAddingScrollBlock() {
414
- var isAbsolutePositioningNeeded = this.getIsAbsolutePopup(this);
415
- var isOutsideScrollBlocked = this.getIsOutsideScrollBlocked(this);
416
-
417
- if (isOutsideScrollBlocked && !isAbsolutePositioningNeeded) {
418
- (0, _intersectionObserver.addIntersectionObserver)(this.placeHolderElement, this.handleIntersectionObserver);
419
- this.addScrollBlockListeners();
420
- }
421
- }
422
- }, {
423
- key: "handleRemovingScrollBlock",
424
- value: function handleRemovingScrollBlock() {
425
- var isAbsolutePositioningNeeded = this.getIsAbsolutePopup(this);
426
- var isOutsideScrollBlocked = this.getIsOutsideScrollBlocked(this);
427
-
428
- if (isOutsideScrollBlocked && !isAbsolutePositioningNeeded) {
429
- (0, _intersectionObserver.removeIntersectionObserver)(this.placeHolderElement, this.handleIntersectionObserver);
430
- this.removeScrollBlockListeners();
431
- }
432
- }
433
- }, {
434
- key: "handleAddingScrollToUpdatePosition",
435
- value: function handleAddingScrollToUpdatePosition() {
436
- var isAbsolutePositioningNeeded = this.getIsAbsolutePopup(this);
437
- var isOutsideScrollBlocked = this.getIsOutsideScrollBlocked(this);
438
-
439
- if (!isOutsideScrollBlocked && !isAbsolutePositioningNeeded) {
440
- (0, _intersectionObserver.addIntersectionObserver)(this.placeHolderElement, this.updateVisibilityOnIntersection);
441
- var shouldAddScrollToUpdatePositionListeners = _Registry["default"].getOpenedScrollableFixedPopups().length === 1 && _Registry["default"].scrollableListenerPopupRef === undefined;
442
-
443
- if (shouldAddScrollToUpdatePositionListeners) {
444
- _Registry["default"].scrollableListenerPopupRef = this;
445
-
446
- _Registry["default"].scrollableListenerPopupRef.addScrollToUpdateListeners();
447
- }
448
- }
449
- }
450
- }, {
451
- key: "handleRemovingScrollToUpdatePosition",
452
- value: function handleRemovingScrollToUpdatePosition() {
453
- var isAbsolutePositioningNeeded = this.getIsAbsolutePopup(this);
454
- var isOutsideScrollBlocked = this.getIsOutsideScrollBlocked(this);
455
-
456
- if (!isOutsideScrollBlocked && !isAbsolutePositioningNeeded) {
457
- (0, _intersectionObserver.removeIntersectionObserver)(this.placeHolderElement, this.updateVisibilityOnIntersection);
458
- var shouldRemoveScrollToUpdatePositionListeners = _Registry["default"].getOpenedScrollableFixedPopups().length === 0 && _Registry["default"].scrollableListenerPopupRef !== undefined;
459
-
460
- if (shouldRemoveScrollToUpdatePositionListeners) {
461
- _Registry["default"].scrollableListenerPopupRef.removeScrollToUpdateListeners();
462
-
463
- _Registry["default"].scrollableListenerPopupRef = undefined;
464
- }
465
- }
466
- }
467
- }, {
468
- key: "handleDropElementStyleUpdate",
469
- value: function handleDropElementStyleUpdate(_ref3) {
470
- var _ref3$top = _ref3.top,
471
- top = _ref3$top === void 0 ? '' : _ref3$top,
472
- _ref3$left = _ref3.left,
473
- left = _ref3$left === void 0 ? '' : _ref3$left,
474
- _ref3$bottom = _ref3.bottom,
475
- bottom = _ref3$bottom === void 0 ? '' : _ref3$bottom,
476
- _ref3$right = _ref3.right,
477
- right = _ref3$right === void 0 ? '' : _ref3$right;
478
- var dropElement = this.dropElement;
479
- Object.assign(dropElement.style, {
480
- top: top ? "".concat(top, "px") : '',
481
- left: left ? "".concat(left, "px") : '',
482
- right: right ? "".concat(right, "px") : '',
483
- bottom: bottom ? "".concat(bottom, "px") : ''
484
- });
485
- }
486
- }, {
487
- key: "setContainerDynamicPositioning",
488
- value: function setContainerDynamicPositioning(betterPosition, needArrow) {
489
- var dropElement = this.dropElement;
490
- var isMobile = this.state.isMobile;
491
-
492
- if (dropElement) {
493
- var _ref4 = betterPosition || _Common.DUMMY_OBJECT,
494
- view = _ref4.view,
495
- viewsOffset = _ref4.viewsOffset;
496
-
497
- var styleToApply = (0, _selectn["default"])("".concat(view), viewsOffset);
498
-
499
- if (isMobile) {
500
- this.handleDropElementStyleUpdate({
501
- top: '',
502
- left: '',
503
- right: '',
504
- bottom: ''
505
- });
506
- } else {
507
- this.handleDropElementStyleUpdate(styleToApply);
508
-
509
- if (this.positionRef.current !== view) {
510
- dropElement.setAttribute('data-position', "".concat(view));
511
- dropElement.setAttribute('data-box-direction', (0, _selectn["default"])("".concat(view, ".direction"), _DropBoxPositionMapping.positionMapping));
512
-
513
- if (needArrow) {
514
- dropElement.setAttribute('data-arrow-position', (0, _selectn["default"])("".concat(view, ".arrowPosition"), _DropBoxPositionMapping.positionMapping));
515
- }
516
-
517
- this.positionRef.current = view;
518
- }
519
- }
520
- }
521
- }
522
- }, {
523
- key: "updatePositionOnScroll",
524
- value: function updatePositionOnScroll(e) {
525
- var scrollablePopups = _Registry["default"].getOpenedScrollableFixedPopups(); // Check if the event target is outside all dropElements
526
-
527
-
528
- scrollablePopups.forEach(function (_ref5) {
529
- var placeHolderElement = _ref5.placeHolderElement,
530
- defaultPosition = _ref5.defaultPosition,
531
- isTargetElementVisible = _ref5.isTargetElementVisible,
532
- handlePopupPosition = _ref5.handlePopupPosition;
533
-
534
- if (e.target.contains(placeHolderElement) && isTargetElementVisible) {
535
- handlePopupPosition(defaultPosition, true);
536
- }
537
- });
538
- }
539
- }, {
540
- key: "updateListeners",
541
- value: function updateListeners() {
542
- var _this4 = this;
543
-
544
- var add = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
545
- var eventList = arguments.length > 1 ? arguments[1] : undefined;
546
- var element = arguments.length > 2 ? arguments[2] : undefined;
547
- var method = add ? 'addEventListener' : 'removeEventListener';
548
- eventList.forEach(function (_ref6) {
549
- var name = _ref6.name,
550
- handlerName = _ref6.handlerName,
551
- options = _ref6.options;
552
- var handler = _this4[handlerName];
553
-
554
- if (handler) {
555
- element[method](name, handler, options);
556
- }
557
- });
558
- }
559
- }, {
560
- key: "addScrollBlockListeners",
561
- value: function addScrollBlockListeners() {
562
- // Only add scroll block listeners if at least one open popup needs outside scroll blocked
563
- var shouldAddScrollBlockListeners = _Registry["default"].getOpenedScrollBlockedFixedPopups().length === 1 && _Registry["default"].scrollBlockedListenerPopupRef === undefined;
564
-
565
- if (shouldAddScrollBlockListeners) {
566
- _Registry["default"].scrollBlockedListenerPopupRef = this; // Main document
567
-
568
- _Registry["default"].scrollBlockedListenerPopupRef.updateListeners(true, SCROLL_BLOCK_EVENTS, document); // Attach event listeners to all iframes within rootElement
569
-
570
-
571
- _Registry["default"].scrollBlockedListenerPopupRef.handleIframeEventListeners(true, IFRAME_SCROLL_BLOCK_EVENTS);
572
- }
573
- }
574
- }, {
575
- key: "removeScrollBlockListeners",
576
- value: function removeScrollBlockListeners() {
577
- // Only remove scroll block listeners if at least one open popup needs outside scroll blocked
578
- var shouldRemoveScrollBlockListeners = _Registry["default"].getOpenedScrollBlockedFixedPopups().length === 0 && _Registry["default"].scrollBlockedListenerPopupRef !== undefined;
579
-
580
- if (shouldRemoveScrollBlockListeners) {
581
- _Registry["default"].scrollBlockedListenerPopupRef.updateListeners(false, SCROLL_BLOCK_EVENTS, document);
582
-
583
- _Registry["default"].scrollBlockedListenerPopupRef.handleIframeEventListeners(false, IFRAME_SCROLL_BLOCK_EVENTS);
584
-
585
- _Registry["default"].scrollBlockedListenerPopupRef = undefined;
586
- }
587
- }
588
- }, {
589
- key: "addScrollToUpdateListeners",
590
- value: function addScrollToUpdateListeners() {
591
- document.addEventListener('scroll', this.updatePositionOnScroll, {
592
- capture: true,
593
- passive: false
594
- });
595
- }
596
- }, {
597
- key: "removeScrollToUpdateListeners",
598
- value: function removeScrollToUpdateListeners() {
599
- document.removeEventListener('scroll', this.updatePositionOnScroll, {
600
- capture: true,
601
- passive: false
602
- });
603
- }
604
- }, {
605
- key: "handleBlockScroll",
606
- value: function handleBlockScroll(event) {
607
- var scrollBlockedPopups = _Registry["default"].getOpenedScrollBlockedFixedPopups(); // Check if the event target is outside all dropElements
608
-
609
-
610
- var isOutsideAllDropElements = scrollBlockedPopups.every(function (_ref7) {
611
- var dropElement = _ref7.dropElement;
612
- return dropElement && dropElement !== event.target && !dropElement.contains(event.target);
613
- });
614
-
615
- if (isOutsideAllDropElements) {
616
- event.preventDefault();
617
- }
618
- }
619
- }, {
620
- key: "handlePositionChange",
621
- value: function handlePositionChange(event) {
622
- var scrollBlockedPopups = _Registry["default"].getOpenedScrollBlockedFixedPopups();
623
-
624
- scrollBlockedPopups.forEach(function (_ref8) {
625
- var placeHolderElement = _ref8.placeHolderElement,
626
- dropElement = _ref8.dropElement,
627
- handlePopupPosition = _ref8.handlePopupPosition,
628
- state = _ref8.state;
629
-
630
- if (dropElement && dropElement !== event.target && !dropElement.contains(event.target) && placeHolderElement && placeHolderElement !== event.target && !placeHolderElement.contains(event.target) && event.target.contains(placeHolderElement)) {
631
- handlePopupPosition(state.position, true);
632
- }
633
- });
634
- }
635
- }, {
636
- key: "preventKeyboardScroll",
637
- value: function preventKeyboardScroll(event) {
638
- var keys = [32, 37, 38, 39, 40]; // Space, Arrow keys
639
-
640
- var scrollBlockedPopups = _Registry["default"].getOpenedScrollBlockedFixedPopups(); // Check if the event target is outside all dropElements
641
-
642
-
643
- var isOutsideAllDropElements = scrollBlockedPopups.every(function (_ref9) {
644
- var dropElement = _ref9.dropElement;
645
- return dropElement && dropElement !== event.target && !dropElement.contains(event.target) && keys.includes(event.keyCode);
646
- });
647
-
648
- if (isOutsideAllDropElements) {
649
- event.preventDefault();
650
- }
651
- }
652
- }, {
653
- key: "handleIntersectionObserver",
654
- value: function handleIntersectionObserver(entry) {
655
- if (entry.intersectionRatio === 0 && entry.isIntersecting === false) {
656
- this.closePopupOnly();
657
- }
658
- }
659
- }, {
660
- key: "updateVisibilityOnIntersection",
661
- value: function updateVisibilityOnIntersection(entry) {
662
- var dropElement = this.dropElement;
663
- if (!dropElement) return;
664
-
665
- if (entry.isIntersecting === true) {
666
- this.isTargetElementVisible = true;
667
- dropElement.setAttribute('data-visible', 'visible');
668
- } else if (entry.intersectionRatio === 0 && entry.isIntersecting === false) {
669
- this.isTargetElementVisible = false;
670
- dropElement.setAttribute('data-visible', 'hidden');
671
- }
672
- }
673
- }, {
674
- key: "getGroup",
675
- value: function getGroup() {
676
- var popupGroup = this.props.popupGroup;
677
- return popupGroup || group;
678
- }
679
- }, {
680
- key: "getNeedArrow",
681
- value: function getNeedArrow(popup) {
682
- var isArrow = popup.props.isArrow;
683
- var needPopupArrow = popup.needPopupArrow;
684
- return isArrow !== undefined ? isArrow : needPopupArrow;
685
- }
686
- }, {
687
- key: "getScrollDebounceTime",
688
- value: function getScrollDebounceTime(popup) {
689
- var scrollDebounceTime = popup.props.scrollDebounceTime;
690
- var popupScrollDebounceTime = popup.scrollDebounceTime;
691
- return scrollDebounceTime !== undefined ? scrollDebounceTime : popupScrollDebounceTime;
692
- }
693
- }, {
694
- key: "getCloseOnScrollPopup",
695
- value: function getCloseOnScrollPopup(popup) {
696
- var closeOnScroll = popup.props.closeOnScroll;
697
- var closeOnScrollPopup = popup.closeOnScroll;
698
- return closeOnScroll !== undefined ? closeOnScroll : closeOnScrollPopup;
699
- }
700
- }, {
701
- key: "getIsAbsolutePopup",
702
- value: function getIsAbsolutePopup(popup) {
703
- var isAbsolutePositioningNeeded = popup.props.isAbsolutePositioningNeeded;
704
- var isAbsolutePopup = popup.isAbsolutePopup;
705
- return isAbsolutePositioningNeeded !== undefined ? isAbsolutePositioningNeeded : isAbsolutePopup;
706
- }
707
- }, {
708
- key: "getIsOutsideScrollBlocked",
709
- value: function getIsOutsideScrollBlocked(popup) {
710
- var isOutsideScrollBlocked = popup.props.isOutsideScrollBlocked;
711
- var isOutsideScrollBlock = popup.isOutsideScrollBlock;
712
- return isOutsideScrollBlocked !== undefined ? isOutsideScrollBlocked : isOutsideScrollBlock;
713
- }
714
- }, {
715
- key: "getCustomPositionOrder",
716
- value: function getCustomPositionOrder(popup) {
717
- var _popup$props$customOr = popup.props.customOrder,
718
- customOrder = _popup$props$customOr === void 0 ? [] : _popup$props$customOr;
719
- var customPositionOrder = popup.customPositionOrder;
720
- return customOrder.length !== 0 ? customOrder : customPositionOrder;
721
- }
722
- }, {
723
- key: "togglePopup",
724
- value: function togglePopup(e, defaultPosition) {
725
- var _this5 = this;
726
-
727
- var group = this.getGroup();
728
- this.removeClose(e);
729
- var isPopupOpen = this.state.isPopupOpen;
730
- var groupPopups = _Registry["default"].popups[group] || [];
731
- _Registry["default"].lastOpenedGroup = !isPopupOpen && _Registry["default"].lastOpenedGroup.indexOf(group) === -1 ? [group].concat(_toConsumableArray(_Registry["default"].lastOpenedGroup)) : _Registry["default"].lastOpenedGroup;
732
- isPopupOpen && _Registry["default"].lastOpenedGroup.splice(0, 1);
733
- groupPopups.forEach(function (popup) {
734
- if (popup !== _this5 && popup.state.isPopupOpen) {
735
- popup.setState({
736
- isPopupOpen: false,
737
- isPopupReady: false
738
- });
739
- }
740
- });
741
-
742
- if (isPopupOpen) {
743
- this.setState({
744
- isPopupOpen: false,
745
- isPopupReady: false
746
- });
747
- } else {
748
- this.handlePopupPosition(defaultPosition);
749
- }
750
- }
751
- }, {
752
- key: "openPopupOnly",
753
- value: function openPopupOnly(e, defaultPosition) {
754
- var group = this.getGroup();
755
- this.removeClose(e);
756
- _Registry["default"].lastOpenedGroup = _Registry["default"].lastOpenedGroup.indexOf(group) === -1 ? [group].concat(_toConsumableArray(_Registry["default"].lastOpenedGroup)) : _Registry["default"].lastOpenedGroup;
757
- this.handlePopupPosition(defaultPosition);
758
- }
759
- }, {
760
- key: "closePopupOnly",
761
- value: function closePopupOnly(e) {
762
- this.removeClose(e);
763
- var isPopupOpen = this.state.isPopupOpen;
764
-
765
- if (isPopupOpen) {
766
- _Registry["default"].lastOpenedGroup.splice(0, 1);
767
-
768
- this.setState({
769
- isPopupOpen: false,
770
- isPopupReady: false
771
- });
772
- }
773
- }
774
- }, {
775
- key: "handleCloseLastOpenedGroup",
776
- value: function handleCloseLastOpenedGroup() {
777
- var groupPopups = _Registry["default"].lastOpenedGroup.length ? _Registry["default"].popups[_Registry["default"].lastOpenedGroup[0]] || [] : [];
778
-
779
- _Registry["default"].lastOpenedGroup.splice(0, 1);
780
-
781
- groupPopups.forEach(function (popup) {
782
- popup.state.isPopupOpen && popup.setState({
783
- isPopupOpen: false,
784
- isPopupReady: false
785
- });
786
- });
787
- }
788
- }, {
789
- key: "handleDocumentMouseDown",
790
- value: function handleDocumentMouseDown(e) {
791
- var needPrevent = this.handleGetNeedPrevent(e);
792
-
793
- if (needPrevent) {
794
- this.removeClose(e);
795
- }
796
- }
797
- }, {
798
- key: "handleDocumentFocus",
799
- value: function handleDocumentFocus(e) {
800
- var needPrevent = this.handleGetNeedPrevent(e);
801
-
802
- if (needPrevent) {
803
- this.removeClose(e);
804
- }
805
- }
806
- }, {
807
- key: "handleGetNeedPrevent",
808
- value: function handleGetNeedPrevent(e) {
809
- var needPrevent = false;
810
-
811
- if (_Registry["default"].lastOpenedGroup.length > 1) {
812
- var target = e.target;
813
- var groupPopups = _Registry["default"].lastOpenedGroup.length ? _Registry["default"].popups[_Registry["default"].lastOpenedGroup[0]] : [];
814
- var openedPopup = null; // eslint-disable-next-line guard-for-in
815
-
816
- for (var i in groupPopups) {
817
- var isPopupOpen = groupPopups[i].state.isPopupOpen;
818
-
819
- if (isPopupOpen) {
820
- openedPopup = groupPopups[i];
821
- break;
822
- }
823
- }
824
-
825
- if (openedPopup) {
826
- var _openedPopup = openedPopup,
827
- dropElement = _openedPopup.dropElement,
828
- placeHolderElement = _openedPopup.placeHolderElement;
829
- var isDropBoxChild = (0, _Common.isDescendant)(dropElement, target);
830
- var isTargetChild = (0, _Common.isDescendant)(placeHolderElement, target); // const isPopupMassUpdateChild = isDescendant(
831
- // massUpdateParent,
832
- // dropElement
833
- // );
834
-
835
- if (!isDropBoxChild && !isTargetChild // && isPopupMassUpdateChild
836
- ) {
837
- needPrevent = true;
838
- }
839
- }
840
- }
841
-
842
- return needPrevent;
843
- }
844
- }, {
845
- key: "documentClickHandler1",
846
- value: function documentClickHandler1(e) {
847
- var needPrevent = this.handleGetNeedPrevent(e);
848
-
849
- if (needPrevent) {
850
- this.removeClose(e);
851
- this.handleCloseLastOpenedGroup();
852
- }
853
- }
854
- }, {
855
- key: "documentClickHandler",
856
- value: function documentClickHandler() {
857
- try {
858
- Object.keys(_Registry["default"].popups).forEach(function (groupName) {
859
- var groupPopups = _Registry["default"].popups[groupName] || [];
860
- groupPopups.forEach(function (popup) {
861
- popup.state.isPopupOpen && (!popup.props.checkBeforeClose || popup.props.checkBeforeClose && popup.props.checkBeforeClose()) && !(0, _Common.isTextSelected)() && popup.setState({
862
- isPopupOpen: false,
863
- isPopupReady: false
864
- });
865
- });
866
- });
867
- _Registry["default"].lastOpenedGroup = [];
868
- } catch (e) {// eslint-disable-next-line no-console
869
- //console.error('popup component not unmounted properly', e);
870
- }
871
- }
872
- }, {
873
- key: "documentKeyupHandler",
874
- value: function documentKeyupHandler(e) {
875
- try {
876
- if (e.keyCode === 27) {
877
- this.handleCloseLastOpenedGroup();
878
- }
879
- } catch (e) {// eslint-disable-next-line no-console
880
- //console.log('error', e);
881
- }
882
- }
883
- }, {
884
- key: "removeClose",
885
- value: function removeClose(e) {
886
- // e && e.preventDefault && e.preventDefault();
887
- (0, _Common.cancelBubblingEffect)(e);
888
- }
889
- }, {
890
- key: "updatePopupState",
891
- value: function updatePopupState(view, views, viewsOffset, targetOffset, popupOffset, isAbsolute) {
892
- var isMobile = (0, _isMobilePopover["default"])(true);
893
- this.setState({
894
- isPopupReady: true,
895
- position: view,
896
- positions: views,
897
- positionsOffset: viewsOffset,
898
- targetOffset: targetOffset,
899
- popupOffset: popupOffset,
900
- isAbsolutePositioningNeeded: isAbsolute,
901
- isMobile: isMobile
902
- });
903
- }
904
- }, {
905
- key: "setPosition",
906
- value: function setPosition() {
907
- var _this6 = this;
908
-
909
- this.cancelRaf('setPositionRafId');
910
- var needArrow = this.getNeedArrow(this);
911
- var isAbsolute = this.getIsAbsolutePopup(this);
912
- var customOrder = this.getCustomPositionOrder(this);
913
- this.setPositionRafId = requestAnimationFrame(function () {
914
- var placeHolderElement = _this6.placeHolderElement,
915
- dropElement = _this6.dropElement,
916
- defaultPosition = _this6.defaultPosition;
917
- var _this6$state = _this6.state,
918
- position = _this6$state.position,
919
- isPopupReady = _this6$state.isPopupReady;
920
- var scrollContainer = placeHolderElement ? placeHolderElement.closest('[data-scroll=true]') || document.body : document.body;
921
-
922
- var betterPosition = _viewPort["default"].betterView(dropElement, placeHolderElement, defaultPosition, scrollContainer, {
923
- needArrow: needArrow,
924
- isAbsolute: isAbsolute,
925
- customOrder: customOrder
926
- });
927
-
928
- var _ref10 = betterPosition || _Common.DUMMY_OBJECT,
929
- view = _ref10.view,
930
- views = _ref10.views,
931
- viewsOffset = _ref10.viewsOffset,
932
- targetOffset = _ref10.targetOffset,
933
- popupOffset = _ref10.popupOffset;
934
-
935
- if (!isAbsolute) {
936
- if (!isPopupReady) {
937
- _this6.updatePopupState(view, views, viewsOffset, targetOffset, popupOffset, isAbsolute);
938
- }
939
-
940
- _this6.setContainerDynamicPositioning(betterPosition, needArrow);
941
- } else {
942
- if (position !== view || !isPopupReady) {
943
- _this6.updatePopupState(view, views, viewsOffset, targetOffset, popupOffset, isAbsolute);
944
- }
945
- }
946
-
947
- _this6.setPositionRafId = null;
948
- });
949
- }
950
- }, {
951
- key: "handlePopupPosition",
952
- value: function handlePopupPosition() {
953
- var defaultPosition = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'bottomCenter';
954
- var isUpdatePosition = arguments.length > 1 ? arguments[1] : undefined;
955
-
956
- // isUpdatePosition --->>> Window resize and dropBox resize and to update the position
957
- var _ref11 = this.context || {},
958
- direction = _ref11.direction;
959
-
960
- var placeHolderElement = this.placeHolderElement,
961
- dropElement = this.dropElement;
962
- var isAbsolute = this.getIsAbsolutePopup(this);
963
-
964
- if (direction === 'rtl') {
965
- defaultPosition = isAbsolute ? _PositionMapping.rtlAbsolutePositionMapping[defaultPosition] : _PositionMapping.rtlFixedPositionMapping[defaultPosition];
966
- } else {
967
- defaultPosition = isAbsolute ? _PositionMapping.absolutePositionMapping[defaultPosition] : defaultPosition;
968
- }
969
-
970
- this.defaultPosition = defaultPosition;
971
-
972
- if (!placeHolderElement && !dropElement) {
973
- var isMobile = (0, _isMobilePopover["default"])(true);
974
- this.setState({
975
- isPopupOpen: true,
976
- isPopupReady: true,
977
- isMobile: isMobile
978
- });
979
- return;
980
- }
981
-
982
- if (isUpdatePosition) {
983
- this.setPosition();
984
- } else {
985
- this.setState({
986
- isPopupOpen: true,
987
- isPopupReady: false
988
- }, this.setPosition);
989
- }
990
- }
991
- }, {
992
- key: "handleOpenPopupPositionChange",
993
- value: function handleOpenPopupPositionChange() {
994
- var _this7 = this;
995
-
996
- Object.keys(_Registry["default"].popups).forEach(function (groupName) {
997
- var groupPopups = _Registry["default"].popups[groupName] || [];
998
- groupPopups.forEach(function (popup) {
999
- if (popup.state.isPopupOpen) {
1000
- var placeHolderElement = popup.placeHolderElement,
1001
- dropElement = popup.dropElement,
1002
- defaultPosition = popup.defaultPosition;
1003
- var _popup$state = popup.state,
1004
- position = _popup$state.position,
1005
- _popup$state$position = _popup$state.positionsOffset,
1006
- positionsOffset = _popup$state$position === void 0 ? {} : _popup$state$position;
1007
-
1008
- if (placeHolderElement && dropElement) {
1009
- var scrollContainer = placeHolderElement.closest('[data-scroll=true]') || document.body;
1010
-
1011
- _this7.cancelRaf('resizePositionRafId');
1012
-
1013
- _this7.resizePositionRafId = requestAnimationFrame(function () {
1014
- var needArrow = _this7.getNeedArrow(popup);
1015
-
1016
- var isAbsolute = _this7.getIsAbsolutePopup(popup);
1017
-
1018
- var customOrder = _this7.getCustomPositionOrder(popup);
1019
-
1020
- var isMobile = (0, _isMobilePopover["default"])(true);
1021
-
1022
- var betterPosition = _viewPort["default"].betterView(dropElement, placeHolderElement, defaultPosition, scrollContainer, {
1023
- needArrow: needArrow,
1024
- isAbsolute: isAbsolute,
1025
- customOrder: customOrder
1026
- });
1027
-
1028
- var _ref12 = betterPosition || {},
1029
- view = _ref12.view,
1030
- views = _ref12.views,
1031
- _ref12$viewsOffset = _ref12.viewsOffset,
1032
- viewsOffset = _ref12$viewsOffset === void 0 ? {} : _ref12$viewsOffset,
1033
- targetOffset = _ref12.targetOffset,
1034
- popupOffset = _ref12.popupOffset;
1035
-
1036
- var _ref13 = positionsOffset[position] || {},
1037
- _ref13$left = _ref13.left,
1038
- oldLeft = _ref13$left === void 0 ? '' : _ref13$left,
1039
- _ref13$top = _ref13.top,
1040
- oldTop = _ref13$top === void 0 ? '' : _ref13$top,
1041
- _ref13$bottom = _ref13.bottom,
1042
- oldBottom = _ref13$bottom === void 0 ? '' : _ref13$bottom,
1043
- _ref13$right = _ref13.right,
1044
- oldRight = _ref13$right === void 0 ? '' : _ref13$right;
1045
-
1046
- var _ref14 = viewsOffset[view] || {},
1047
- _ref14$left = _ref14.left,
1048
- left = _ref14$left === void 0 ? '' : _ref14$left,
1049
- _ref14$top = _ref14.top,
1050
- top = _ref14$top === void 0 ? '' : _ref14$top,
1051
- _ref14$bottom = _ref14.bottom,
1052
- bottom = _ref14$bottom === void 0 ? '' : _ref14$bottom,
1053
- _ref14$right = _ref14.right,
1054
- right = _ref14$right === void 0 ? '' : _ref14$right;
1055
-
1056
- var changeState = isAbsolute ? position !== view : oldLeft !== left || oldTop !== top || oldBottom !== bottom || oldRight !== right; // let isInViewPort = viewPort.isInViewPort(
1057
- // placeHolderElement,
1058
- // scrollContainer
1059
- // );
1060
-
1061
- if (changeState) {
1062
- popup.setState({
1063
- position: view,
1064
- positions: views,
1065
- positionsOffset: viewsOffset,
1066
- targetOffset: targetOffset,
1067
- popupOffset: popupOffset,
1068
- isAbsolutePositioningNeeded: isAbsolute,
1069
- isMobile: isMobile
1070
- });
1071
- } // if (!isInViewPort && !isAbsolute) {
1072
- // popup.setState({ isPopupOpen: false, isPopupReady: false });
1073
- // } else if (view && changeState) {
1074
- // popup.setState({
1075
- // position: view,
1076
- // positions: views,
1077
- // positionsOffset: viewsOffset,
1078
- // targetOffset,
1079
- // popupOffset,
1080
- // isAbsolutePositioningNeeded: isAbsolute
1081
- // });
1082
- // }
1083
-
1084
-
1085
- _this7.resizePositionRafId = null;
1086
- });
1087
- }
1088
- }
1089
- });
1090
- });
1091
- }
1092
- }, {
1093
- key: "handleResize",
1094
- value: function handleResize() {
1095
- this.handleOpenPopupPositionChange();
1096
- } // handleScroll(e) {
1097
- // // this.handleOpenPopupPositionChange();
1098
- // const { closeOnScroll } = this.getCloseOnScrollPopup(this);
1099
- // const { isPopupReady } = this.state;
1100
- // if (isPopupReady) {
1101
- // console.log('onscrollPopupREady');
1102
- // }
1103
- // if (isPopupReady && closeOnScroll) {
1104
- // console.log(this, 'handle Scroll');
1105
- // this.togglePopup(e);
1106
- // }
1107
- // }
1108
-
1109
- }, {
1110
- key: "handlePopupResize",
1111
- value: function handlePopupResize(popupSize) {
1112
- var height = popupSize.height,
1113
- width = popupSize.width;
1114
-
1115
- var _ref15 = this.size || {},
1116
- _ref15$height = _ref15.height,
1117
- oldHeight = _ref15$height === void 0 ? 0 : _ref15$height,
1118
- _ref15$width = _ref15.width,
1119
- oldWidth = _ref15$width === void 0 ? 0 : _ref15$width;
1120
-
1121
- var _this$state2 = this.state,
1122
- isPopupReady = _this$state2.isPopupReady,
1123
- position = _this$state2.position;
1124
-
1125
- if (isPopupReady && this.size && (oldHeight !== height || width !== oldWidth)) {
1126
- this.handlePopupPosition(position, true);
1127
- }
1128
-
1129
- this.size = popupSize;
1130
- }
1131
- }, {
1132
- key: "getTargetRef",
1133
- value: function getTargetRef(el) {
1134
- this.placeHolderElement = el;
1135
- }
1136
- }, {
1137
- key: "getContainerRef",
1138
- value: function getContainerRef(el) {
1139
- this.dropElement = el;
1140
- }
1141
- }, {
1142
- key: "render",
1143
- value: function render() {
1144
- // const { isPopupReady, isPopupOpen } = this.state;
1145
- var _this$state3 = this.state,
1146
- isMobile = _this$state3.isMobile,
1147
- restState = _objectWithoutProperties(_this$state3, _excluded); // const localState = isPopupReady ? this.state : {};
1148
-
1149
-
1150
- return /*#__PURE__*/_react["default"].createElement(Component, _extends({}, this.props, restState, {
1151
- openPopupOnly: this.openPopupOnly,
1152
- closePopupOnly: this.closePopupOnly,
1153
- togglePopup: this.togglePopup,
1154
- recomputePosition: this.setPosition,
1155
- removeClose: this.removeClose,
1156
- getTargetRef: this.getTargetRef,
1157
- getContainerRef: this.getContainerRef
1158
- }));
1159
- }
1160
- }]);
1161
-
1162
- return Popup;
1163
- }(_react["default"].Component);
1164
-
1165
- Popup.displayName = Component.displayName || Component.name || Popup.name;
1166
- Popup.contextTypes = _propTypes.ContextTypes;
1167
- Popup.propTypes = _propTypes.PopupPropTypes;
1168
- return (0, _hoistNonReactStatics["default"])(Popup, Component);
25
+ var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : _Common.DUMMY_OBJECT;
26
+ var _options$isAbsolutePo = options.isAbsolutePositioningNeeded,
27
+ isAbsolutePositioningNeeded = _options$isAbsolutePo === void 0 ? true : _options$isAbsolutePo,
28
+ _options$isArrow = options.isArrow,
29
+ isArrow = _options$isArrow === void 0 ? false : _options$isArrow,
30
+ _options$customOrder = options.customOrder,
31
+ customOrder = _options$customOrder === void 0 ? _Common.DUMMY_ARRAY : _options$customOrder,
32
+ _options$scrollDeboun = options.scrollDebounceTime,
33
+ scrollDebounceTime = _options$scrollDeboun === void 0 ? 0 : _options$scrollDeboun,
34
+ _options$closeOnScrol = options.closeOnScroll,
35
+ closeOnScroll = _options$closeOnScrol === void 0 ? false : _options$closeOnScrol,
36
+ _options$isOutsideScr = options.isOutsideScrollBlocked,
37
+ isOutsideScrollBlocked = _options$isOutsideScr === void 0 ? false : _options$isOutsideScr;
38
+ var getRootElement = (0, _Config.getLibraryConfig)('getRootElement');
39
+ var mobileWidth = (0, _Config.getLibraryConfig)('mobileWidth');
40
+ var middleware = {
41
+ useAbsolutePositioning: isAbsolutePositioningNeeded,
42
+ positionOrder: customOrder,
43
+ isArrow: isArrow,
44
+ scrollDebounceTime: scrollDebounceTime,
45
+ closeOnScroll: closeOnScroll,
46
+ isOutsideScrollBlocked: isOutsideScrollBlocked,
47
+ enableResizeHandling: needResizeHandling
48
+ };
49
+ var popupConfig = {
50
+ group: group,
51
+ mobileWidth: mobileWidth,
52
+ rootElementCallback: getRootElement,
53
+ middleware: middleware
54
+ };
55
+ return (0, _Popup["default"])(Component, popupConfig);
1169
56
  };
1170
57
 
1171
58
  var _default = Popup;