@zohodesk/components 1.0.0-temp-220.4 → 1.0.0-temp-220.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.
package/es/Popup/Popup.js CHANGED
@@ -38,52 +38,6 @@ const defaultState = {
38
38
  //{height: ‘’, width: ‘’,}
39
39
  isAbsolutePositioningNeeded: true
40
40
  };
41
- const SCROLL_BLOCK_EVENTS = Object.freeze([{
42
- name: 'wheel',
43
- handlerName: 'handleBlockScroll',
44
- options: {
45
- capture: true,
46
- passive: false
47
- }
48
- }, {
49
- name: 'touchmove',
50
- handlerName: 'handleBlockScroll',
51
- options: {
52
- capture: true,
53
- passive: false
54
- }
55
- }, {
56
- name: 'scroll',
57
- handlerName: 'handlePositionChange',
58
- options: {
59
- capture: true,
60
- passive: false
61
- }
62
- }, {
63
- name: 'keydown',
64
- handlerName: 'preventKeyboardScroll',
65
- options: {
66
- capture: true,
67
- passive: false
68
- }
69
- }]);
70
- const IFRAME_SCROLL_BLOCK_EVENTS = Object.freeze(SCROLL_BLOCK_EVENTS.filter(event => event.name !== 'keydown'));
71
- const CLICK_EVENTS = Object.freeze([{
72
- name: 'click',
73
- handlerName: 'documentClickHandler',
74
- options: {
75
- capture: false,
76
- passive: false
77
- }
78
- }, {
79
- name: 'click',
80
- handlerName: 'documentClickHandler1',
81
- options: {
82
- capture: true,
83
- passive: false
84
- }
85
- }]);
86
- const iframeSelector = '[data-scroll=true] iframe';
87
41
  /* eslint-disable react/no-deprecated */
88
42
 
89
43
  /* eslint-disable react/prop-types */
@@ -120,8 +74,9 @@ const Popup = function (Component) {
120
74
  isMobile: false
121
75
  };
122
76
  this.togglePopup = this.togglePopup.bind(this);
77
+ this.closePopups = this.closePopups.bind(this);
78
+ this.handleDocumentInteraction = this.handleDocumentInteraction.bind(this);
123
79
  this.documentClickHandler = this.documentClickHandler.bind(this);
124
- this.documentClickHandler1 = this.documentClickHandler1.bind(this);
125
80
  this.removeClose = this.removeClose.bind(this);
126
81
  this.documentKeyupHandler = this.documentKeyupHandler.bind(this);
127
82
  this.openPopupOnly = this.openPopupOnly.bind(this);
@@ -145,7 +100,6 @@ const Popup = function (Component) {
145
100
  this.handleBlockScroll = this.handleBlockScroll.bind(this);
146
101
  this.handlePositionChange = this.handlePositionChange.bind(this);
147
102
  this.preventKeyboardScroll = this.preventKeyboardScroll.bind(this);
148
- this.updateListeners = this.updateListeners.bind(this);
149
103
  this.addScrollBlockListeners = this.addScrollBlockListeners.bind(this);
150
104
  this.removeScrollBlockListeners = this.removeScrollBlockListeners.bind(this);
151
105
  this.handleAddingScrollBlock = this.handleAddingScrollBlock.bind(this);
@@ -158,7 +112,6 @@ const Popup = function (Component) {
158
112
  this.setContainerDynamicPositioning = this.setContainerDynamicPositioning.bind(this);
159
113
  this.updatePopupState = this.updatePopupState.bind(this);
160
114
  this.handleScrollAndBlockEvents = this.handleScrollAndBlockEvents.bind(this);
161
- this.handleIframeClickEvents = this.handleIframeClickEvents.bind(this);
162
115
  this.handleDropElementStyleUpdate = this.handleDropElementStyleUpdate.bind(this);
163
116
  this.positionRef = /*#__PURE__*/React.createRef();
164
117
  this.popupObserver = new ResizeObserver(this.handlePopupResize); //dropBoxSize
@@ -181,11 +134,11 @@ const Popup = function (Component) {
181
134
  popups[group] = groupPopups;
182
135
 
183
136
  if (Object.keys(popups).length === 1 && groupPopups.length === 1) {
137
+ document.addEventListener('click', this.handleDocumentInteraction, true);
184
138
  document.addEventListener('click', this.documentClickHandler, false);
185
139
  document.addEventListener('keyup', this.documentKeyupHandler, false); // document.addEventListener('scroll', this.handleScroll, true);
186
140
 
187
141
  window.addEventListener('resize', this.handleResize);
188
- document.addEventListener('click', this.documentClickHandler1, true);
189
142
  document.addEventListener('mousedown', this.handleDocumentMouseDown, true);
190
143
  document.addEventListener('focus', this.handleDocumentFocus, true);
191
144
  }
@@ -214,21 +167,6 @@ const Popup = function (Component) {
214
167
  }
215
168
  }
216
169
 
217
- handleIframeClickEvents(isPopupReady, isMobile) {
218
- const toggleListeners = add => {
219
- this.updateListeners(add, CLICK_EVENTS, document);
220
- document.querySelectorAll(iframeSelector).forEach(frame => {
221
- const frameDocument = frame.contentDocument;
222
-
223
- if (frameDocument) {
224
- this.updateListeners(add, CLICK_EVENTS, frameDocument);
225
- }
226
- });
227
- };
228
-
229
- toggleListeners(isPopupReady && !isMobile);
230
- }
231
-
232
170
  componentDidUpdate(prevProps, prevState) {
233
171
  const {
234
172
  isPopupReady,
@@ -256,7 +194,6 @@ const Popup = function (Component) {
256
194
 
257
195
  if (oldStateOpen !== isPopupReady && !isMobile || oldIsMobileState !== isMobile) {
258
196
  this.handleScrollAndBlockEvents(isPopupReady, isMobile);
259
- this.handleIframeClickEvents(isPopupReady, isMobile);
260
197
  }
261
198
  }
262
199
 
@@ -288,11 +225,11 @@ const Popup = function (Component) {
288
225
  }
289
226
 
290
227
  if (noPopups) {
291
- document.removeEventListener('click', this.documentClickHandler);
228
+ document.removeEventListener('click', this.handleDocumentInteraction, true);
229
+ document.removeEventListener('click', this.documentClickHandler, false);
292
230
  document.removeEventListener('keyup', this.documentKeyupHandler); // document.removeEventListener('scroll', this.handleScroll);
293
231
 
294
232
  window.removeEventListener('resize', this.handleResize);
295
- document.removeEventListener('click', this.documentClickHandler1, true);
296
233
  document.removeEventListener('mousedown', this.handleDocumentMouseDown, true);
297
234
  document.removeEventListener('focus', this.handleDocumentFocus, true);
298
235
  }
@@ -410,51 +347,41 @@ const Popup = function (Component) {
410
347
  }
411
348
  }
412
349
 
413
- updateListeners() {
414
- let add = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
415
- let eventList = arguments.length > 1 ? arguments[1] : undefined;
416
- let element = arguments.length > 2 ? arguments[2] : undefined;
417
- const method = add ? 'addEventListener' : 'removeEventListener';
418
-
419
- const applyListeners = target => {
420
- eventList.forEach(_ref2 => {
421
- let {
422
- name,
423
- handlerName,
424
- options
425
- } = _ref2;
426
- const handler = this[handlerName];
427
-
428
- if (handler) {
429
- target[method](name, handler, options);
430
- }
431
- });
432
- };
433
-
434
- applyListeners(element);
435
- }
436
-
437
350
  addScrollBlockListeners() {
438
- // Main document
439
- this.updateListeners(true, SCROLL_BLOCK_EVENTS, document); // Attach event listeners to all iframes within elements that have the attribute data-scroll=true
440
-
441
- document.querySelectorAll(iframeSelector).forEach(frame => {
442
- const frameDocument = frame.contentDocument;
443
-
444
- if (frameDocument) {
445
- this.updateListeners(true, IFRAME_SCROLL_BLOCK_EVENTS, frameDocument);
446
- }
351
+ document.addEventListener('wheel', this.handleBlockScroll, {
352
+ capture: true,
353
+ passive: false
354
+ });
355
+ document.addEventListener('touchmove', this.handleBlockScroll, {
356
+ capture: true,
357
+ passive: false
358
+ });
359
+ document.addEventListener('scroll', this.handlePositionChange, {
360
+ capture: true,
361
+ passive: false
362
+ });
363
+ document.addEventListener('keydown', this.preventKeyboardScroll, {
364
+ capture: true,
365
+ passive: false
447
366
  });
448
367
  }
449
368
 
450
369
  removeScrollBlockListeners() {
451
- this.updateListeners(false, SCROLL_BLOCK_EVENTS, document);
452
- document.querySelectorAll(iframeSelector).forEach(frame => {
453
- const frameDocument = frame.contentDocument;
454
-
455
- if (frameDocument) {
456
- this.updateListeners(false, IFRAME_SCROLL_BLOCK_EVENTS, frameDocument);
457
- }
370
+ document.removeEventListener('wheel', this.handleBlockScroll, {
371
+ capture: true,
372
+ passive: false
373
+ });
374
+ document.removeEventListener('touchmove', this.handleBlockScroll, {
375
+ capture: true,
376
+ passive: false
377
+ });
378
+ document.removeEventListener('scroll', this.handlePositionChange, {
379
+ capture: true,
380
+ passive: false
381
+ });
382
+ document.removeEventListener('keydown', this.preventKeyboardScroll, {
383
+ capture: true,
384
+ passive: false
458
385
  });
459
386
  }
460
387
 
@@ -691,29 +618,62 @@ const Popup = function (Component) {
691
618
  return needPrevent;
692
619
  }
693
620
 
694
- documentClickHandler1(e) {
695
- const needPrevent = this.handleGetNeedPrevent(e);
621
+ closePopups(e) {
622
+ let checkTarget = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
696
623
 
697
- if (needPrevent) {
698
- this.removeClose(e);
699
- this.handleCloseLastOpenedGroup();
700
- }
701
- }
702
-
703
- documentClickHandler() {
704
624
  try {
705
625
  Object.keys(popups).forEach(groupName => {
706
- const groupPopups = popups[groupName] || [];
707
- groupPopups.forEach(popup => {
708
- popup.state.isPopupOpen && (!popup.props.checkBeforeClose || popup.props.checkBeforeClose && popup.props.checkBeforeClose()) && !isTextSelected() && popup.setState({
709
- isPopupOpen: false,
710
- isPopupReady: false
711
- });
626
+ const openGroupPopups = (popups[groupName] || []).filter(popup => popup.state.isPopupOpen);
627
+ openGroupPopups.forEach(popup => {
628
+ const {
629
+ dropElement,
630
+ placeHolderElement
631
+ } = popup;
632
+ const {
633
+ target
634
+ } = e || {};
635
+ const canClosePopup = !popup.props.checkBeforeClose || popup.props.checkBeforeClose && popup.props.checkBeforeClose() && !isTextSelected();
636
+ const isOutsideClick = checkTarget && placeHolderElement && dropElement && placeHolderElement !== target && !placeHolderElement.contains(target) && dropElement !== target && !dropElement.contains(target);
637
+
638
+ if (canClosePopup && (!checkTarget || isOutsideClick)) {
639
+ popup.setState({
640
+ isPopupOpen: false,
641
+ isPopupReady: false
642
+ });
643
+ }
712
644
  });
713
645
  });
714
- lastOpenedGroup = [];
715
- } catch (e) {// eslint-disable-next-line no-console
716
- //console.error('popup component not unmounted properly', e);
646
+
647
+ if (!checkTarget) {
648
+ lastOpenedGroup = [];
649
+ }
650
+ } catch (error) {// eslint-disable-next-line no-console
651
+ //console.error('popup component not unmounted properly', error);
652
+ }
653
+ }
654
+
655
+ documentClickHandler(e) {
656
+ // Handles document click events to close all popups.
657
+ // This function closes all popups without checking if the click occurred outside the popup.
658
+ this.closePopups(e, false);
659
+ }
660
+
661
+ handleDocumentInteraction(e) {
662
+ // Handles interactions with the document to determine whether to close the popup.
663
+ // This function is specifically designed to close the popup when clicking outside of it.
664
+ // Check if the click event should prevent popup closure.
665
+ const needPrevent = this.handleGetNeedPrevent(e);
666
+
667
+ if (needPrevent) {
668
+ // If the click event should prevent popup closure:
669
+ // - Stop the event propagation.
670
+ // - Close the last opened group of popups.
671
+ this.removeClose(e);
672
+ this.handleCloseLastOpenedGroup();
673
+ } else {
674
+ // If the click event does not need to prevent popup closure:
675
+ // - Close all popups, but only if the click occurred outside the popup elements.
676
+ this.closePopups(e, true);
717
677
  }
718
678
  }
719
679
 
@@ -97,54 +97,6 @@ var defaultState = {
97
97
  //{height: ‘’, width: ‘’,}
98
98
  isAbsolutePositioningNeeded: true
99
99
  };
100
- var SCROLL_BLOCK_EVENTS = Object.freeze([{
101
- name: 'wheel',
102
- handlerName: 'handleBlockScroll',
103
- options: {
104
- capture: true,
105
- passive: false
106
- }
107
- }, {
108
- name: 'touchmove',
109
- handlerName: 'handleBlockScroll',
110
- options: {
111
- capture: true,
112
- passive: false
113
- }
114
- }, {
115
- name: 'scroll',
116
- handlerName: 'handlePositionChange',
117
- options: {
118
- capture: true,
119
- passive: false
120
- }
121
- }, {
122
- name: 'keydown',
123
- handlerName: 'preventKeyboardScroll',
124
- options: {
125
- capture: true,
126
- passive: false
127
- }
128
- }]);
129
- var IFRAME_SCROLL_BLOCK_EVENTS = Object.freeze(SCROLL_BLOCK_EVENTS.filter(function (event) {
130
- return event.name !== 'keydown';
131
- }));
132
- var CLICK_EVENTS = Object.freeze([{
133
- name: 'click',
134
- handlerName: 'documentClickHandler',
135
- options: {
136
- capture: false,
137
- passive: false
138
- }
139
- }, {
140
- name: 'click',
141
- handlerName: 'documentClickHandler1',
142
- options: {
143
- capture: true,
144
- passive: false
145
- }
146
- }]);
147
- var iframeSelector = '[data-scroll=true] iframe';
148
100
  /* eslint-disable react/no-deprecated */
149
101
 
150
102
  /* eslint-disable react/prop-types */
@@ -195,8 +147,9 @@ var Popup = function Popup(Component) {
195
147
  isMobile: false
196
148
  };
197
149
  _this.togglePopup = _this.togglePopup.bind(_assertThisInitialized(_this));
150
+ _this.closePopups = _this.closePopups.bind(_assertThisInitialized(_this));
151
+ _this.handleDocumentInteraction = _this.handleDocumentInteraction.bind(_assertThisInitialized(_this));
198
152
  _this.documentClickHandler = _this.documentClickHandler.bind(_assertThisInitialized(_this));
199
- _this.documentClickHandler1 = _this.documentClickHandler1.bind(_assertThisInitialized(_this));
200
153
  _this.removeClose = _this.removeClose.bind(_assertThisInitialized(_this));
201
154
  _this.documentKeyupHandler = _this.documentKeyupHandler.bind(_assertThisInitialized(_this));
202
155
  _this.openPopupOnly = _this.openPopupOnly.bind(_assertThisInitialized(_this));
@@ -220,7 +173,6 @@ var Popup = function Popup(Component) {
220
173
  _this.handleBlockScroll = _this.handleBlockScroll.bind(_assertThisInitialized(_this));
221
174
  _this.handlePositionChange = _this.handlePositionChange.bind(_assertThisInitialized(_this));
222
175
  _this.preventKeyboardScroll = _this.preventKeyboardScroll.bind(_assertThisInitialized(_this));
223
- _this.updateListeners = _this.updateListeners.bind(_assertThisInitialized(_this));
224
176
  _this.addScrollBlockListeners = _this.addScrollBlockListeners.bind(_assertThisInitialized(_this));
225
177
  _this.removeScrollBlockListeners = _this.removeScrollBlockListeners.bind(_assertThisInitialized(_this));
226
178
  _this.handleAddingScrollBlock = _this.handleAddingScrollBlock.bind(_assertThisInitialized(_this));
@@ -233,7 +185,6 @@ var Popup = function Popup(Component) {
233
185
  _this.setContainerDynamicPositioning = _this.setContainerDynamicPositioning.bind(_assertThisInitialized(_this));
234
186
  _this.updatePopupState = _this.updatePopupState.bind(_assertThisInitialized(_this));
235
187
  _this.handleScrollAndBlockEvents = _this.handleScrollAndBlockEvents.bind(_assertThisInitialized(_this));
236
- _this.handleIframeClickEvents = _this.handleIframeClickEvents.bind(_assertThisInitialized(_this));
237
188
  _this.handleDropElementStyleUpdate = _this.handleDropElementStyleUpdate.bind(_assertThisInitialized(_this));
238
189
  _this.positionRef = /*#__PURE__*/_react["default"].createRef();
239
190
  _this.popupObserver = new _ResizeObserver["default"](_this.handlePopupResize); //dropBoxSize
@@ -260,11 +211,11 @@ var Popup = function Popup(Component) {
260
211
  popups[group] = groupPopups;
261
212
 
262
213
  if (Object.keys(popups).length === 1 && groupPopups.length === 1) {
214
+ document.addEventListener('click', this.handleDocumentInteraction, true);
263
215
  document.addEventListener('click', this.documentClickHandler, false);
264
216
  document.addEventListener('keyup', this.documentKeyupHandler, false); // document.addEventListener('scroll', this.handleScroll, true);
265
217
 
266
218
  window.addEventListener('resize', this.handleResize);
267
- document.addEventListener('click', this.documentClickHandler1, true);
268
219
  document.addEventListener('mousedown', this.handleDocumentMouseDown, true);
269
220
  document.addEventListener('focus', this.handleDocumentFocus, true);
270
221
  }
@@ -292,25 +243,6 @@ var Popup = function Popup(Component) {
292
243
  this.handleRemovingScrollToUpdatePosition();
293
244
  }
294
245
  }
295
- }, {
296
- key: "handleIframeClickEvents",
297
- value: function handleIframeClickEvents(isPopupReady, isMobile) {
298
- var _this2 = this;
299
-
300
- var toggleListeners = function toggleListeners(add) {
301
- _this2.updateListeners(add, CLICK_EVENTS, document);
302
-
303
- document.querySelectorAll(iframeSelector).forEach(function (frame) {
304
- var frameDocument = frame.contentDocument;
305
-
306
- if (frameDocument) {
307
- _this2.updateListeners(add, CLICK_EVENTS, frameDocument);
308
- }
309
- });
310
- };
311
-
312
- toggleListeners(isPopupReady && !isMobile);
313
- }
314
246
  }, {
315
247
  key: "componentDidUpdate",
316
248
  value: function componentDidUpdate(prevProps, prevState) {
@@ -337,20 +269,19 @@ var Popup = function Popup(Component) {
337
269
 
338
270
  if (oldStateOpen !== isPopupReady && !isMobile || oldIsMobileState !== isMobile) {
339
271
  this.handleScrollAndBlockEvents(isPopupReady, isMobile);
340
- this.handleIframeClickEvents(isPopupReady, isMobile);
341
272
  }
342
273
  }
343
274
  }, {
344
275
  key: "componentWillUnmount",
345
276
  value: function componentWillUnmount() {
346
- var _this3 = this;
277
+ var _this2 = this;
347
278
 
348
279
  var group = this.getGroup();
349
280
  popups = Object.keys(popups).reduce(function (res, groupName) {
350
281
  if (groupName === group) {
351
282
  var groupPopups = popups[group];
352
283
  var newGroupPopups = groupPopups.filter(function (popup) {
353
- return popup !== _this3;
284
+ return popup !== _this2;
354
285
  });
355
286
  newGroupPopups.length === 0 && lastOpenedGroup.indexOf(group) >= 0 && lastOpenedGroup.splice(lastOpenedGroup.indexOf(group), 1);
356
287
  res[group] = newGroupPopups;
@@ -374,11 +305,11 @@ var Popup = function Popup(Component) {
374
305
  }
375
306
 
376
307
  if (noPopups) {
377
- document.removeEventListener('click', this.documentClickHandler);
308
+ document.removeEventListener('click', this.handleDocumentInteraction, true);
309
+ document.removeEventListener('click', this.documentClickHandler, false);
378
310
  document.removeEventListener('keyup', this.documentKeyupHandler); // document.removeEventListener('scroll', this.handleScroll);
379
311
 
380
312
  window.removeEventListener('resize', this.handleResize);
381
- document.removeEventListener('click', this.documentClickHandler1, true);
382
313
  document.removeEventListener('mousedown', this.handleDocumentMouseDown, true);
383
314
  document.removeEventListener('focus', this.handleDocumentFocus, true);
384
315
  }
@@ -497,59 +428,44 @@ var Popup = function Popup(Component) {
497
428
  this.handlePopupPosition(defaultPosition, true);
498
429
  }
499
430
  }
500
- }, {
501
- key: "updateListeners",
502
- value: function updateListeners() {
503
- var _this4 = this;
504
-
505
- var add = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
506
- var eventList = arguments.length > 1 ? arguments[1] : undefined;
507
- var element = arguments.length > 2 ? arguments[2] : undefined;
508
- var method = add ? 'addEventListener' : 'removeEventListener';
509
-
510
- var applyListeners = function applyListeners(target) {
511
- eventList.forEach(function (_ref5) {
512
- var name = _ref5.name,
513
- handlerName = _ref5.handlerName,
514
- options = _ref5.options;
515
- var handler = _this4[handlerName];
516
-
517
- if (handler) {
518
- target[method](name, handler, options);
519
- }
520
- });
521
- };
522
-
523
- applyListeners(element);
524
- }
525
431
  }, {
526
432
  key: "addScrollBlockListeners",
527
433
  value: function addScrollBlockListeners() {
528
- var _this5 = this;
529
-
530
- // Main document
531
- this.updateListeners(true, SCROLL_BLOCK_EVENTS, document); // Attach event listeners to all iframes within elements that have the attribute data-scroll=true
532
-
533
- document.querySelectorAll(iframeSelector).forEach(function (frame) {
534
- var frameDocument = frame.contentDocument;
535
-
536
- if (frameDocument) {
537
- _this5.updateListeners(true, IFRAME_SCROLL_BLOCK_EVENTS, frameDocument);
538
- }
434
+ document.addEventListener('wheel', this.handleBlockScroll, {
435
+ capture: true,
436
+ passive: false
437
+ });
438
+ document.addEventListener('touchmove', this.handleBlockScroll, {
439
+ capture: true,
440
+ passive: false
441
+ });
442
+ document.addEventListener('scroll', this.handlePositionChange, {
443
+ capture: true,
444
+ passive: false
445
+ });
446
+ document.addEventListener('keydown', this.preventKeyboardScroll, {
447
+ capture: true,
448
+ passive: false
539
449
  });
540
450
  }
541
451
  }, {
542
452
  key: "removeScrollBlockListeners",
543
453
  value: function removeScrollBlockListeners() {
544
- var _this6 = this;
545
-
546
- this.updateListeners(false, SCROLL_BLOCK_EVENTS, document);
547
- document.querySelectorAll(iframeSelector).forEach(function (frame) {
548
- var frameDocument = frame.contentDocument;
549
-
550
- if (frameDocument) {
551
- _this6.updateListeners(false, IFRAME_SCROLL_BLOCK_EVENTS, frameDocument);
552
- }
454
+ document.removeEventListener('wheel', this.handleBlockScroll, {
455
+ capture: true,
456
+ passive: false
457
+ });
458
+ document.removeEventListener('touchmove', this.handleBlockScroll, {
459
+ capture: true,
460
+ passive: false
461
+ });
462
+ document.removeEventListener('scroll', this.handlePositionChange, {
463
+ capture: true,
464
+ passive: false
465
+ });
466
+ document.removeEventListener('keydown', this.preventKeyboardScroll, {
467
+ capture: true,
468
+ passive: false
553
469
  });
554
470
  }
555
471
  }, {
@@ -657,7 +573,7 @@ var Popup = function Popup(Component) {
657
573
  }, {
658
574
  key: "togglePopup",
659
575
  value: function togglePopup(e, defaultPosition) {
660
- var _this7 = this;
576
+ var _this3 = this;
661
577
 
662
578
  var group = this.getGroup();
663
579
  this.removeClose(e);
@@ -666,7 +582,7 @@ var Popup = function Popup(Component) {
666
582
  lastOpenedGroup = !isPopupOpen && lastOpenedGroup.indexOf(group) === -1 ? [group].concat(_toConsumableArray(lastOpenedGroup)) : lastOpenedGroup;
667
583
  isPopupOpen && lastOpenedGroup.splice(0, 1);
668
584
  groupPopups.forEach(function (popup) {
669
- if (popup !== _this7 && popup.state.isPopupOpen) {
585
+ if (popup !== _this3 && popup.state.isPopupOpen) {
670
586
  popup.setState({
671
587
  isPopupOpen: false,
672
588
  isPopupReady: false
@@ -774,31 +690,66 @@ var Popup = function Popup(Component) {
774
690
  return needPrevent;
775
691
  }
776
692
  }, {
777
- key: "documentClickHandler1",
778
- value: function documentClickHandler1(e) {
779
- var needPrevent = this.handleGetNeedPrevent(e);
693
+ key: "closePopups",
694
+ value: function closePopups(e) {
695
+ var checkTarget = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
780
696
 
781
- if (needPrevent) {
782
- this.removeClose(e);
783
- this.handleCloseLastOpenedGroup();
784
- }
785
- }
786
- }, {
787
- key: "documentClickHandler",
788
- value: function documentClickHandler() {
789
697
  try {
790
698
  Object.keys(popups).forEach(function (groupName) {
791
- var groupPopups = popups[groupName] || [];
792
- groupPopups.forEach(function (popup) {
793
- popup.state.isPopupOpen && (!popup.props.checkBeforeClose || popup.props.checkBeforeClose && popup.props.checkBeforeClose()) && !(0, _Common.isTextSelected)() && popup.setState({
794
- isPopupOpen: false,
795
- isPopupReady: false
796
- });
699
+ var openGroupPopups = (popups[groupName] || []).filter(function (popup) {
700
+ return popup.state.isPopupOpen;
701
+ });
702
+ openGroupPopups.forEach(function (popup) {
703
+ var dropElement = popup.dropElement,
704
+ placeHolderElement = popup.placeHolderElement;
705
+
706
+ var _ref5 = e || {},
707
+ target = _ref5.target;
708
+
709
+ var canClosePopup = !popup.props.checkBeforeClose || popup.props.checkBeforeClose && popup.props.checkBeforeClose() && !(0, _Common.isTextSelected)();
710
+ var isOutsideClick = checkTarget && placeHolderElement && dropElement && placeHolderElement !== target && !placeHolderElement.contains(target) && dropElement !== target && !dropElement.contains(target);
711
+
712
+ if (canClosePopup && (!checkTarget || isOutsideClick)) {
713
+ popup.setState({
714
+ isPopupOpen: false,
715
+ isPopupReady: false
716
+ });
717
+ }
797
718
  });
798
719
  });
799
- lastOpenedGroup = [];
800
- } catch (e) {// eslint-disable-next-line no-console
801
- //console.error('popup component not unmounted properly', e);
720
+
721
+ if (!checkTarget) {
722
+ lastOpenedGroup = [];
723
+ }
724
+ } catch (error) {// eslint-disable-next-line no-console
725
+ //console.error('popup component not unmounted properly', error);
726
+ }
727
+ }
728
+ }, {
729
+ key: "documentClickHandler",
730
+ value: function documentClickHandler(e) {
731
+ // Handles document click events to close all popups.
732
+ // This function closes all popups without checking if the click occurred outside the popup.
733
+ this.closePopups(e, false);
734
+ }
735
+ }, {
736
+ key: "handleDocumentInteraction",
737
+ value: function handleDocumentInteraction(e) {
738
+ // Handles interactions with the document to determine whether to close the popup.
739
+ // This function is specifically designed to close the popup when clicking outside of it.
740
+ // Check if the click event should prevent popup closure.
741
+ var needPrevent = this.handleGetNeedPrevent(e);
742
+
743
+ if (needPrevent) {
744
+ // If the click event should prevent popup closure:
745
+ // - Stop the event propagation.
746
+ // - Close the last opened group of popups.
747
+ this.removeClose(e);
748
+ this.handleCloseLastOpenedGroup();
749
+ } else {
750
+ // If the click event does not need to prevent popup closure:
751
+ // - Close all popups, but only if the click occurred outside the popup elements.
752
+ this.closePopups(e, true);
802
753
  }
803
754
  }
804
755
  }, {
@@ -836,7 +787,7 @@ var Popup = function Popup(Component) {
836
787
  }, {
837
788
  key: "handlePopupPosition",
838
789
  value: function handlePopupPosition() {
839
- var _this8 = this;
790
+ var _this4 = this;
840
791
 
841
792
  var defaultPosition = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'bottomCenter';
842
793
  var isUpdatePosition = arguments.length > 1 ? arguments[1] : undefined;
@@ -869,11 +820,11 @@ var Popup = function Popup(Component) {
869
820
 
870
821
  var setPosition = function setPosition() {
871
822
  requestAnimationFrame(function () {
872
- var placeHolderElement = _this8.placeHolderElement,
873
- dropElement = _this8.dropElement;
874
- var _this8$state = _this8.state,
875
- position = _this8$state.position,
876
- isPopupReady = _this8$state.isPopupReady;
823
+ var placeHolderElement = _this4.placeHolderElement,
824
+ dropElement = _this4.dropElement;
825
+ var _this4$state = _this4.state,
826
+ position = _this4$state.position,
827
+ isPopupReady = _this4$state.isPopupReady;
877
828
  var scrollContainer = placeHolderElement.closest('[data-scroll=true]') || document.body;
878
829
 
879
830
  var betterPosition = _viewPort["default"].betterView(dropElement, placeHolderElement, defaultPosition, scrollContainer, {
@@ -891,17 +842,17 @@ var Popup = function Popup(Component) {
891
842
 
892
843
  if (!isAbsolute) {
893
844
  if (!isPopupReady) {
894
- _this8.updatePopupState(view, views, viewsOffset, targetOffset, popupOffset, isAbsolute);
845
+ _this4.updatePopupState(view, views, viewsOffset, targetOffset, popupOffset, isAbsolute);
895
846
  }
896
847
 
897
848
  if (!dropElement) {
898
849
  return;
899
850
  }
900
851
 
901
- _this8.setContainerDynamicPositioning(betterPosition, needArrow);
852
+ _this4.setContainerDynamicPositioning(betterPosition, needArrow);
902
853
  } else {
903
854
  if (position !== view || !isPopupReady) {
904
- _this8.updatePopupState(view, views, viewsOffset, targetOffset, popupOffset, isAbsolute);
855
+ _this4.updatePopupState(view, views, viewsOffset, targetOffset, popupOffset, isAbsolute);
905
856
  }
906
857
  }
907
858
  });
@@ -920,7 +871,7 @@ var Popup = function Popup(Component) {
920
871
  }, {
921
872
  key: "handleOpenPopupPositionChange",
922
873
  value: function handleOpenPopupPositionChange() {
923
- var _this9 = this;
874
+ var _this5 = this;
924
875
 
925
876
  Object.keys(popups).forEach(function (groupName) {
926
877
  var groupPopups = popups[groupName] || [];
@@ -937,11 +888,11 @@ var Popup = function Popup(Component) {
937
888
  if (placeHolderElement && dropElement) {
938
889
  var scrollContainer = placeHolderElement.closest('[data-scroll=true]') || document.body;
939
890
  requestAnimationFrame(function () {
940
- var needArrow = _this9.getNeedArrow(popup);
891
+ var needArrow = _this5.getNeedArrow(popup);
941
892
 
942
- var isAbsolute = _this9.getIsAbsolutePopup(popup);
893
+ var isAbsolute = _this5.getIsAbsolutePopup(popup);
943
894
 
944
- var customOrder = _this9.getCustomPositionOrder(popup);
895
+ var customOrder = _this5.getCustomPositionOrder(popup);
945
896
 
946
897
  var isMobile = (0, _isMobilePopover["default"])(true);
947
898
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zohodesk/components",
3
- "version": "1.0.0-temp-220.4",
3
+ "version": "1.0.0-temp-220.5",
4
4
  "main": "es/index.js",
5
5
  "module": "es/index.js",
6
6
  "private": false,
@@ -71,7 +71,7 @@
71
71
  "@zohodesk/a11y": "2.3.4",
72
72
  "@zohodesk/docstool": "1.0.0-alpha-2",
73
73
  "@zohodesk/hooks": "2.0.5",
74
- "@zohodesk/icons": "1.0.72",
74
+ "@zohodesk/icons": "1.0.74",
75
75
  "@zohodesk/svg": "1.1.22",
76
76
  "@zohodesk/utils": "1.3.14",
77
77
  "@zohodesk/variables": "1.0.0",
@@ -86,7 +86,7 @@
86
86
  "selectn": "1.1.2"
87
87
  },
88
88
  "peerDependencies": {
89
- "@zohodesk/icons": "1.0.72",
89
+ "@zohodesk/icons": "1.0.74",
90
90
  "@zohodesk/variables": "1.0.0",
91
91
  "@zohodesk/svg": "1.1.22",
92
92
  "@zohodesk/virtualizer": "1.0.3",