@zohodesk/components 1.0.0-temp-220 → 1.0.0-temp-220.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.
package/es/Popup/Popup.js CHANGED
@@ -74,7 +74,9 @@ const Popup = function (Component) {
74
74
  isMobile: false
75
75
  };
76
76
  this.togglePopup = this.togglePopup.bind(this);
77
+ this.closePopups = this.closePopups.bind(this);
77
78
  this.handleDocumentInteraction = this.handleDocumentInteraction.bind(this);
79
+ this.documentClickHandler = this.documentClickHandler.bind(this);
78
80
  this.removeClose = this.removeClose.bind(this);
79
81
  this.documentKeyupHandler = this.documentKeyupHandler.bind(this);
80
82
  this.openPopupOnly = this.openPopupOnly.bind(this);
@@ -133,6 +135,7 @@ const Popup = function (Component) {
133
135
 
134
136
  if (Object.keys(popups).length === 1 && groupPopups.length === 1) {
135
137
  document.addEventListener('click', this.handleDocumentInteraction, true);
138
+ document.addEventListener('click', this.documentClickHandler, false);
136
139
  document.addEventListener('keyup', this.documentKeyupHandler, false); // document.addEventListener('scroll', this.handleScroll, true);
137
140
 
138
141
  window.addEventListener('resize', this.handleResize);
@@ -223,6 +226,7 @@ const Popup = function (Component) {
223
226
 
224
227
  if (noPopups) {
225
228
  document.removeEventListener('click', this.handleDocumentInteraction, true);
229
+ document.removeEventListener('click', this.documentClickHandler, false);
226
230
  document.removeEventListener('keyup', this.documentKeyupHandler); // document.removeEventListener('scroll', this.handleScroll);
227
231
 
228
232
  window.removeEventListener('resize', this.handleResize);
@@ -614,29 +618,59 @@ const Popup = function (Component) {
614
618
  return needPrevent;
615
619
  }
616
620
 
621
+ closePopups(e) {
622
+ let checkTarget = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
623
+
624
+ try {
625
+ Object.keys(popups).forEach(groupName => {
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
+ }
644
+ });
645
+ });
646
+ lastOpenedGroup = [];
647
+ } catch (error) {// eslint-disable-next-line no-console
648
+ //console.error('popup component not unmounted properly', error);
649
+ }
650
+ }
651
+
652
+ documentClickHandler(e) {
653
+ // Handles document click events to close all popups.
654
+ // This function closes all popups without checking if the click occurred outside the popup.
655
+ this.closePopups(e, false);
656
+ }
657
+
617
658
  handleDocumentInteraction(e) {
659
+ // Handles interactions with the document to determine whether to close the popup.
660
+ // This function is specifically designed to close the popup when clicking outside of it.
661
+ // Check if the click event should prevent popup closure.
618
662
  const needPrevent = this.handleGetNeedPrevent(e);
619
663
 
620
664
  if (needPrevent) {
665
+ // If the click event should prevent popup closure:
666
+ // - Stop the event propagation.
667
+ // - Close the last opened group of popups.
621
668
  this.removeClose(e);
622
669
  this.handleCloseLastOpenedGroup();
623
670
  } else {
624
- try {
625
- Object.keys(popups).forEach(groupName => {
626
- const groupPopups = popups[groupName] || [];
627
- groupPopups.forEach(popup => {
628
- if (popup.placeHolderElement && popup.dropElement && popup.placeHolderElement !== e.target && !popup.placeHolderElement.contains(e.target) && popup.dropElement !== e.target && !popup.dropElement.contains(e.target)) {
629
- popup.state.isPopupOpen && (!popup.props.checkBeforeClose || popup.props.checkBeforeClose && popup.props.checkBeforeClose()) && !isTextSelected() && popup.setState({
630
- isPopupOpen: false,
631
- isPopupReady: false
632
- });
633
- }
634
- });
635
- });
636
- lastOpenedGroup = [];
637
- } catch (error) {// eslint-disable-next-line no-console
638
- //console.error('popup component not unmounted properly', error);
639
- }
671
+ // If the click event does not need to prevent popup closure:
672
+ // - Close all popups, but only if the click occurred outside the popup elements.
673
+ this.closePopups(e, true);
640
674
  }
641
675
  }
642
676
 
@@ -147,7 +147,9 @@ var Popup = function Popup(Component) {
147
147
  isMobile: false
148
148
  };
149
149
  _this.togglePopup = _this.togglePopup.bind(_assertThisInitialized(_this));
150
+ _this.closePopups = _this.closePopups.bind(_assertThisInitialized(_this));
150
151
  _this.handleDocumentInteraction = _this.handleDocumentInteraction.bind(_assertThisInitialized(_this));
152
+ _this.documentClickHandler = _this.documentClickHandler.bind(_assertThisInitialized(_this));
151
153
  _this.removeClose = _this.removeClose.bind(_assertThisInitialized(_this));
152
154
  _this.documentKeyupHandler = _this.documentKeyupHandler.bind(_assertThisInitialized(_this));
153
155
  _this.openPopupOnly = _this.openPopupOnly.bind(_assertThisInitialized(_this));
@@ -210,6 +212,7 @@ var Popup = function Popup(Component) {
210
212
 
211
213
  if (Object.keys(popups).length === 1 && groupPopups.length === 1) {
212
214
  document.addEventListener('click', this.handleDocumentInteraction, true);
215
+ document.addEventListener('click', this.documentClickHandler, false);
213
216
  document.addEventListener('keyup', this.documentKeyupHandler, false); // document.addEventListener('scroll', this.handleScroll, true);
214
217
 
215
218
  window.addEventListener('resize', this.handleResize);
@@ -303,6 +306,7 @@ var Popup = function Popup(Component) {
303
306
 
304
307
  if (noPopups) {
305
308
  document.removeEventListener('click', this.handleDocumentInteraction, true);
309
+ document.removeEventListener('click', this.documentClickHandler, false);
306
310
  document.removeEventListener('keyup', this.documentKeyupHandler); // document.removeEventListener('scroll', this.handleScroll);
307
311
 
308
312
  window.removeEventListener('resize', this.handleResize);
@@ -685,31 +689,64 @@ var Popup = function Popup(Component) {
685
689
 
686
690
  return needPrevent;
687
691
  }
692
+ }, {
693
+ key: "closePopups",
694
+ value: function closePopups(e) {
695
+ var checkTarget = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
696
+
697
+ try {
698
+ Object.keys(popups).forEach(function (groupName) {
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
+ }
718
+ });
719
+ });
720
+ lastOpenedGroup = [];
721
+ } catch (error) {// eslint-disable-next-line no-console
722
+ //console.error('popup component not unmounted properly', error);
723
+ }
724
+ }
725
+ }, {
726
+ key: "documentClickHandler",
727
+ value: function documentClickHandler(e) {
728
+ // Handles document click events to close all popups.
729
+ // This function closes all popups without checking if the click occurred outside the popup.
730
+ this.closePopups(e, false);
731
+ }
688
732
  }, {
689
733
  key: "handleDocumentInteraction",
690
734
  value: function handleDocumentInteraction(e) {
735
+ // Handles interactions with the document to determine whether to close the popup.
736
+ // This function is specifically designed to close the popup when clicking outside of it.
737
+ // Check if the click event should prevent popup closure.
691
738
  var needPrevent = this.handleGetNeedPrevent(e);
692
739
 
693
740
  if (needPrevent) {
741
+ // If the click event should prevent popup closure:
742
+ // - Stop the event propagation.
743
+ // - Close the last opened group of popups.
694
744
  this.removeClose(e);
695
745
  this.handleCloseLastOpenedGroup();
696
746
  } else {
697
- try {
698
- Object.keys(popups).forEach(function (groupName) {
699
- var groupPopups = popups[groupName] || [];
700
- groupPopups.forEach(function (popup) {
701
- if (popup.placeHolderElement && popup.dropElement && popup.placeHolderElement !== e.target && !popup.placeHolderElement.contains(e.target) && popup.dropElement !== e.target && !popup.dropElement.contains(e.target)) {
702
- popup.state.isPopupOpen && (!popup.props.checkBeforeClose || popup.props.checkBeforeClose && popup.props.checkBeforeClose()) && !(0, _Common.isTextSelected)() && popup.setState({
703
- isPopupOpen: false,
704
- isPopupReady: false
705
- });
706
- }
707
- });
708
- });
709
- lastOpenedGroup = [];
710
- } catch (error) {// eslint-disable-next-line no-console
711
- //console.error('popup component not unmounted properly', error);
712
- }
747
+ // If the click event does not need to prevent popup closure:
748
+ // - Close all popups, but only if the click occurred outside the popup elements.
749
+ this.closePopups(e, true);
713
750
  }
714
751
  }
715
752
  }, {
@@ -753,8 +790,8 @@ var Popup = function Popup(Component) {
753
790
  var isUpdatePosition = arguments.length > 1 ? arguments[1] : undefined;
754
791
 
755
792
  // isUpdatePosition --->>> Window resize and dropBox resize and to update the position
756
- var _ref5 = this.context || {},
757
- direction = _ref5.direction;
793
+ var _ref6 = this.context || {},
794
+ direction = _ref6.direction;
758
795
 
759
796
  var placeHolderElement = this.placeHolderElement,
760
797
  dropElement = this.dropElement;
@@ -793,12 +830,12 @@ var Popup = function Popup(Component) {
793
830
  customOrder: customOrder
794
831
  });
795
832
 
796
- var _ref6 = betterPosition || _Common.DUMMY_OBJECT,
797
- view = _ref6.view,
798
- views = _ref6.views,
799
- viewsOffset = _ref6.viewsOffset,
800
- targetOffset = _ref6.targetOffset,
801
- popupOffset = _ref6.popupOffset;
833
+ var _ref7 = betterPosition || _Common.DUMMY_OBJECT,
834
+ view = _ref7.view,
835
+ views = _ref7.views,
836
+ viewsOffset = _ref7.viewsOffset,
837
+ targetOffset = _ref7.targetOffset,
838
+ popupOffset = _ref7.popupOffset;
802
839
 
803
840
  if (!isAbsolute) {
804
841
  if (!isPopupReady) {
@@ -862,33 +899,33 @@ var Popup = function Popup(Component) {
862
899
  customOrder: customOrder
863
900
  });
864
901
 
865
- var _ref7 = betterPosition || {},
866
- view = _ref7.view,
867
- views = _ref7.views,
868
- _ref7$viewsOffset = _ref7.viewsOffset,
869
- viewsOffset = _ref7$viewsOffset === void 0 ? {} : _ref7$viewsOffset,
870
- targetOffset = _ref7.targetOffset,
871
- popupOffset = _ref7.popupOffset;
872
-
873
- var _ref8 = positionsOffset[position] || {},
874
- _ref8$left = _ref8.left,
875
- oldLeft = _ref8$left === void 0 ? '' : _ref8$left,
876
- _ref8$top = _ref8.top,
877
- oldTop = _ref8$top === void 0 ? '' : _ref8$top,
878
- _ref8$bottom = _ref8.bottom,
879
- oldBottom = _ref8$bottom === void 0 ? '' : _ref8$bottom,
880
- _ref8$right = _ref8.right,
881
- oldRight = _ref8$right === void 0 ? '' : _ref8$right;
882
-
883
- var _ref9 = viewsOffset[view] || {},
902
+ var _ref8 = betterPosition || {},
903
+ view = _ref8.view,
904
+ views = _ref8.views,
905
+ _ref8$viewsOffset = _ref8.viewsOffset,
906
+ viewsOffset = _ref8$viewsOffset === void 0 ? {} : _ref8$viewsOffset,
907
+ targetOffset = _ref8.targetOffset,
908
+ popupOffset = _ref8.popupOffset;
909
+
910
+ var _ref9 = positionsOffset[position] || {},
884
911
  _ref9$left = _ref9.left,
885
- left = _ref9$left === void 0 ? '' : _ref9$left,
912
+ oldLeft = _ref9$left === void 0 ? '' : _ref9$left,
886
913
  _ref9$top = _ref9.top,
887
- top = _ref9$top === void 0 ? '' : _ref9$top,
914
+ oldTop = _ref9$top === void 0 ? '' : _ref9$top,
888
915
  _ref9$bottom = _ref9.bottom,
889
- bottom = _ref9$bottom === void 0 ? '' : _ref9$bottom,
916
+ oldBottom = _ref9$bottom === void 0 ? '' : _ref9$bottom,
890
917
  _ref9$right = _ref9.right,
891
- right = _ref9$right === void 0 ? '' : _ref9$right;
918
+ oldRight = _ref9$right === void 0 ? '' : _ref9$right;
919
+
920
+ var _ref10 = viewsOffset[view] || {},
921
+ _ref10$left = _ref10.left,
922
+ left = _ref10$left === void 0 ? '' : _ref10$left,
923
+ _ref10$top = _ref10.top,
924
+ top = _ref10$top === void 0 ? '' : _ref10$top,
925
+ _ref10$bottom = _ref10.bottom,
926
+ bottom = _ref10$bottom === void 0 ? '' : _ref10$bottom,
927
+ _ref10$right = _ref10.right,
928
+ right = _ref10$right === void 0 ? '' : _ref10$right;
892
929
 
893
930
  var changeState = isAbsolute ? position !== view : oldLeft !== left || oldTop !== top || oldBottom !== bottom || oldRight !== right; // let isInViewPort = viewPort.isInViewPort(
894
931
  // placeHolderElement,
@@ -947,11 +984,11 @@ var Popup = function Popup(Component) {
947
984
  var height = popupSize.height,
948
985
  width = popupSize.width;
949
986
 
950
- var _ref10 = this.size || {},
951
- _ref10$height = _ref10.height,
952
- oldHeight = _ref10$height === void 0 ? 0 : _ref10$height,
953
- _ref10$width = _ref10.width,
954
- oldWidth = _ref10$width === void 0 ? 0 : _ref10$width;
987
+ var _ref11 = this.size || {},
988
+ _ref11$height = _ref11.height,
989
+ oldHeight = _ref11$height === void 0 ? 0 : _ref11$height,
990
+ _ref11$width = _ref11.width,
991
+ oldWidth = _ref11$width === void 0 ? 0 : _ref11$width;
955
992
 
956
993
  var _this$state2 = this.state,
957
994
  isPopupReady = _this$state2.isPopupReady,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zohodesk/components",
3
- "version": "1.0.0-temp-220",
3
+ "version": "1.0.0-temp-220.1",
4
4
  "main": "es/index.js",
5
5
  "module": "es/index.js",
6
6
  "private": false,