@zohodesk/components 1.2.50 → 1.2.51

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/README.md CHANGED
@@ -32,6 +32,9 @@ In this Package, we Provide Some Basic Components to Build Web App
32
32
  - TextBoxIcon
33
33
  - Tooltip
34
34
 
35
+ # 1.2.51
36
+
37
+ - **Popup** - Fixed issue: Error on unmount when target ref is not available.
35
38
 
36
39
  # 1.2.50
37
40
 
package/es/Popup/Popup.js CHANGED
@@ -95,6 +95,8 @@ const Popup = function (Component) {
95
95
  this.preventKeyboardScroll = this.preventKeyboardScroll.bind(this);
96
96
  this.addScrollBlockListeners = this.addScrollBlockListeners.bind(this);
97
97
  this.removeScrollBlockListeners = this.removeScrollBlockListeners.bind(this);
98
+ this.handleAddingScrollBlock = this.handleAddingScrollBlock.bind(this);
99
+ this.handleRemovingScrollBlock = this.handleRemovingScrollBlock.bind(this);
98
100
  this.handleIntersectionObserver = this.handleIntersectionObserver.bind(this);
99
101
  this.popupObserver = new ResizeObserver(this.handlePopupResize); //dropBoxSize
100
102
 
@@ -152,9 +154,7 @@ const Popup = function (Component) {
152
154
  dropElement
153
155
  } = this;
154
156
  const {
155
- needResizeHandling: propResizeHandling,
156
- isAbsolutePositioningNeeded,
157
- isOutsideScrollBlocked
157
+ needResizeHandling: propResizeHandling
158
158
  } = this.props;
159
159
 
160
160
  if (oldStateOpen !== isPopupReady) {
@@ -165,14 +165,10 @@ const Popup = function (Component) {
165
165
  this.popupObserver.disconnect();
166
166
  }
167
167
 
168
- if (isOutsideScrollBlocked && !isAbsolutePositioningNeeded) {
169
- if (isPopupReady) {
170
- addIntersectionObserver(this.placeHolderElement, this.handleIntersectionObserver);
171
- this.addScrollBlockListeners();
172
- } else {
173
- removeIntersectionObserver(this.placeHolderElement, this.handleIntersectionObserver);
174
- this.removeScrollBlockListeners();
175
- }
168
+ if (isPopupReady) {
169
+ this.handleAddingScrollBlock();
170
+ } else {
171
+ this.handleRemovingScrollBlock();
176
172
  }
177
173
  }
178
174
  }
@@ -189,8 +185,7 @@ const Popup = function (Component) {
189
185
 
190
186
  return res;
191
187
  }, popups);
192
- removeIntersectionObserver(this.placeHolderElement, this.handleIntersectionObserver);
193
- this.removeScrollBlockListeners();
188
+ this.handleRemovingScrollBlock();
194
189
  let noPopups = true;
195
190
 
196
191
  for (const i in popups) {
@@ -215,6 +210,30 @@ const Popup = function (Component) {
215
210
  }
216
211
  }
217
212
 
213
+ handleAddingScrollBlock() {
214
+ const {
215
+ isAbsolutePositioningNeeded,
216
+ isOutsideScrollBlocked
217
+ } = this.props;
218
+
219
+ if (isOutsideScrollBlocked && !isAbsolutePositioningNeeded) {
220
+ addIntersectionObserver(this.placeHolderElement, this.handleIntersectionObserver);
221
+ this.addScrollBlockListeners();
222
+ }
223
+ }
224
+
225
+ handleRemovingScrollBlock() {
226
+ const {
227
+ isAbsolutePositioningNeeded,
228
+ isOutsideScrollBlocked
229
+ } = this.props;
230
+
231
+ if (isOutsideScrollBlocked && !isAbsolutePositioningNeeded) {
232
+ removeIntersectionObserver(this.placeHolderElement, this.handleIntersectionObserver);
233
+ this.removeScrollBlockListeners();
234
+ }
235
+ }
236
+
218
237
  addScrollBlockListeners() {
219
238
  document.addEventListener('wheel', this.handleBlockScroll, {
220
239
  capture: true,
@@ -2,38 +2,48 @@ let observerCallbacks = null;
2
2
  let intersectionObserver = null;
3
3
 
4
4
  function handleObserverCallbacks(entries) {
5
- entries.map((entry, i) => {
5
+ entries.forEach(entry => {
6
6
  let oldCallbacks = observerCallbacks.get(entry.target);
7
- oldCallbacks.length && oldCallbacks.forEach(callback => {
8
- callback && callback(entry);
9
- });
7
+
8
+ if (Array.isArray(oldCallbacks) && oldCallbacks.length) {
9
+ oldCallbacks.forEach(callback => {
10
+ callback && callback(entry);
11
+ });
12
+ }
10
13
  });
11
14
  }
12
15
 
13
16
  export function addIntersectionObserver(element, callback, options) {
14
- if (intersectionObserver === null && observerCallbacks === null) {
15
- intersectionObserver = new IntersectionObserver(entries => {
16
- handleObserverCallbacks(entries);
17
- }, options);
18
- observerCallbacks = new Map();
19
- }
17
+ if (!!element && typeof callback == 'function') {
18
+ if (intersectionObserver === null && observerCallbacks === null) {
19
+ intersectionObserver = new IntersectionObserver(entries => {
20
+ handleObserverCallbacks(entries);
21
+ }, options);
22
+ observerCallbacks = new Map();
23
+ }
20
24
 
21
- intersectionObserver.observe(element);
22
- let oldCallbacks = observerCallbacks.get(element) || [];
23
- observerCallbacks.set(element, [...oldCallbacks, callback]);
25
+ intersectionObserver.observe(element);
26
+ let oldCallbacks = observerCallbacks.get(element) || [];
27
+ observerCallbacks.set(element, [...oldCallbacks, callback]);
28
+ }
24
29
  }
25
30
  export function removeIntersectionObserver(element, callback) {
26
- let oldCallbacks = observerCallbacks ? observerCallbacks.get(element) : [];
27
- oldCallbacks = oldCallbacks.filter(handler => handler !== callback);
31
+ if (!!element && typeof callback == 'function') {
32
+ let oldCallbacks = observerCallbacks ? observerCallbacks.get(element) : null;
28
33
 
29
- if (intersectionObserver && oldCallbacks.length === 0) {
30
- observerCallbacks.delete(element);
31
- intersectionObserver.unobserve(element);
32
- }
34
+ if (Array.isArray(oldCallbacks)) {
35
+ let callbacks = oldCallbacks.filter(handler => handler !== callback);
36
+
37
+ if (intersectionObserver && callbacks.length === 0) {
38
+ observerCallbacks.delete(element);
39
+ intersectionObserver.unobserve(element);
40
+ }
41
+ }
33
42
 
34
- if (intersectionObserver && observerCallbacks && observerCallbacks.size === 0) {
35
- intersectionObserver.disconnect();
36
- intersectionObserver = null;
37
- observerCallbacks = null;
43
+ if (intersectionObserver && observerCallbacks && observerCallbacks.size === 0) {
44
+ intersectionObserver.disconnect();
45
+ intersectionObserver = null;
46
+ observerCallbacks = null;
47
+ }
38
48
  }
39
49
  }
@@ -158,6 +158,8 @@ var Popup = function Popup(Component) {
158
158
  _this.preventKeyboardScroll = _this.preventKeyboardScroll.bind(_assertThisInitialized(_this));
159
159
  _this.addScrollBlockListeners = _this.addScrollBlockListeners.bind(_assertThisInitialized(_this));
160
160
  _this.removeScrollBlockListeners = _this.removeScrollBlockListeners.bind(_assertThisInitialized(_this));
161
+ _this.handleAddingScrollBlock = _this.handleAddingScrollBlock.bind(_assertThisInitialized(_this));
162
+ _this.handleRemovingScrollBlock = _this.handleRemovingScrollBlock.bind(_assertThisInitialized(_this));
161
163
  _this.handleIntersectionObserver = _this.handleIntersectionObserver.bind(_assertThisInitialized(_this));
162
164
  _this.popupObserver = new _ResizeObserver["default"](_this.handlePopupResize); //dropBoxSize
163
165
 
@@ -216,10 +218,7 @@ var Popup = function Popup(Component) {
216
218
  oldStateOpen = _ref2$isPopupReady === void 0 ? false : _ref2$isPopupReady;
217
219
 
218
220
  var dropElement = this.dropElement;
219
- var _this$props = this.props,
220
- propResizeHandling = _this$props.needResizeHandling,
221
- isAbsolutePositioningNeeded = _this$props.isAbsolutePositioningNeeded,
222
- isOutsideScrollBlocked = _this$props.isOutsideScrollBlocked;
221
+ var propResizeHandling = this.props.needResizeHandling;
223
222
 
224
223
  if (oldStateOpen !== isPopupReady) {
225
224
  if (isPopupReady && dropElement && (propResizeHandling !== undefined ? propResizeHandling : needResizeHandling)) {
@@ -229,14 +228,10 @@ var Popup = function Popup(Component) {
229
228
  this.popupObserver.disconnect();
230
229
  }
231
230
 
232
- if (isOutsideScrollBlocked && !isAbsolutePositioningNeeded) {
233
- if (isPopupReady) {
234
- (0, _intersectionObserver.addIntersectionObserver)(this.placeHolderElement, this.handleIntersectionObserver);
235
- this.addScrollBlockListeners();
236
- } else {
237
- (0, _intersectionObserver.removeIntersectionObserver)(this.placeHolderElement, this.handleIntersectionObserver);
238
- this.removeScrollBlockListeners();
239
- }
231
+ if (isPopupReady) {
232
+ this.handleAddingScrollBlock();
233
+ } else {
234
+ this.handleRemovingScrollBlock();
240
235
  }
241
236
  }
242
237
  }
@@ -258,8 +253,7 @@ var Popup = function Popup(Component) {
258
253
 
259
254
  return res;
260
255
  }, popups);
261
- (0, _intersectionObserver.removeIntersectionObserver)(this.placeHolderElement, this.handleIntersectionObserver);
262
- this.removeScrollBlockListeners();
256
+ this.handleRemovingScrollBlock();
263
257
  var noPopups = true;
264
258
 
265
259
  for (var i in popups) {
@@ -283,6 +277,30 @@ var Popup = function Popup(Component) {
283
277
  document.removeEventListener('focus', this.handleDocumentFocus, true);
284
278
  }
285
279
  }
280
+ }, {
281
+ key: "handleAddingScrollBlock",
282
+ value: function handleAddingScrollBlock() {
283
+ var _this$props = this.props,
284
+ isAbsolutePositioningNeeded = _this$props.isAbsolutePositioningNeeded,
285
+ isOutsideScrollBlocked = _this$props.isOutsideScrollBlocked;
286
+
287
+ if (isOutsideScrollBlocked && !isAbsolutePositioningNeeded) {
288
+ (0, _intersectionObserver.addIntersectionObserver)(this.placeHolderElement, this.handleIntersectionObserver);
289
+ this.addScrollBlockListeners();
290
+ }
291
+ }
292
+ }, {
293
+ key: "handleRemovingScrollBlock",
294
+ value: function handleRemovingScrollBlock() {
295
+ var _this$props2 = this.props,
296
+ isAbsolutePositioningNeeded = _this$props2.isAbsolutePositioningNeeded,
297
+ isOutsideScrollBlocked = _this$props2.isOutsideScrollBlocked;
298
+
299
+ if (isOutsideScrollBlocked && !isAbsolutePositioningNeeded) {
300
+ (0, _intersectionObserver.removeIntersectionObserver)(this.placeHolderElement, this.handleIntersectionObserver);
301
+ this.removeScrollBlockListeners();
302
+ }
303
+ }
286
304
  }, {
287
305
  key: "addScrollBlockListeners",
288
306
  value: function addScrollBlockListeners() {
@@ -22,41 +22,51 @@ var observerCallbacks = null;
22
22
  var intersectionObserver = null;
23
23
 
24
24
  function handleObserverCallbacks(entries) {
25
- entries.map(function (entry, i) {
25
+ entries.forEach(function (entry) {
26
26
  var oldCallbacks = observerCallbacks.get(entry.target);
27
- oldCallbacks.length && oldCallbacks.forEach(function (callback) {
28
- callback && callback(entry);
29
- });
27
+
28
+ if (Array.isArray(oldCallbacks) && oldCallbacks.length) {
29
+ oldCallbacks.forEach(function (callback) {
30
+ callback && callback(entry);
31
+ });
32
+ }
30
33
  });
31
34
  }
32
35
 
33
36
  function addIntersectionObserver(element, callback, options) {
34
- if (intersectionObserver === null && observerCallbacks === null) {
35
- intersectionObserver = new IntersectionObserver(function (entries) {
36
- handleObserverCallbacks(entries);
37
- }, options);
38
- observerCallbacks = new Map();
39
- }
37
+ if (!!element && typeof callback == 'function') {
38
+ if (intersectionObserver === null && observerCallbacks === null) {
39
+ intersectionObserver = new IntersectionObserver(function (entries) {
40
+ handleObserverCallbacks(entries);
41
+ }, options);
42
+ observerCallbacks = new Map();
43
+ }
40
44
 
41
- intersectionObserver.observe(element);
42
- var oldCallbacks = observerCallbacks.get(element) || [];
43
- observerCallbacks.set(element, [].concat(_toConsumableArray(oldCallbacks), [callback]));
45
+ intersectionObserver.observe(element);
46
+ var oldCallbacks = observerCallbacks.get(element) || [];
47
+ observerCallbacks.set(element, [].concat(_toConsumableArray(oldCallbacks), [callback]));
48
+ }
44
49
  }
45
50
 
46
51
  function removeIntersectionObserver(element, callback) {
47
- var oldCallbacks = observerCallbacks ? observerCallbacks.get(element) : [];
48
- oldCallbacks = oldCallbacks.filter(function (handler) {
49
- return handler !== callback;
50
- });
52
+ if (!!element && typeof callback == 'function') {
53
+ var oldCallbacks = observerCallbacks ? observerCallbacks.get(element) : null;
51
54
 
52
- if (intersectionObserver && oldCallbacks.length === 0) {
53
- observerCallbacks["delete"](element);
54
- intersectionObserver.unobserve(element);
55
- }
55
+ if (Array.isArray(oldCallbacks)) {
56
+ var callbacks = oldCallbacks.filter(function (handler) {
57
+ return handler !== callback;
58
+ });
59
+
60
+ if (intersectionObserver && callbacks.length === 0) {
61
+ observerCallbacks["delete"](element);
62
+ intersectionObserver.unobserve(element);
63
+ }
64
+ }
56
65
 
57
- if (intersectionObserver && observerCallbacks && observerCallbacks.size === 0) {
58
- intersectionObserver.disconnect();
59
- intersectionObserver = null;
60
- observerCallbacks = null;
66
+ if (intersectionObserver && observerCallbacks && observerCallbacks.size === 0) {
67
+ intersectionObserver.disconnect();
68
+ intersectionObserver = null;
69
+ observerCallbacks = null;
70
+ }
61
71
  }
62
72
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zohodesk/components",
3
- "version": "1.2.50",
3
+ "version": "1.2.51",
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.2.6",
72
72
  "@zohodesk/docstool": "1.0.0-alpha-2",
73
73
  "@zohodesk/hooks": "2.0.5",
74
- "@zohodesk/icons": "1.0.66",
74
+ "@zohodesk/icons": "1.0.67",
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.66",
89
+ "@zohodesk/icons": "1.0.67",
90
90
  "@zohodesk/variables": "1.0.0",
91
91
  "@zohodesk/svg": "1.1.22",
92
92
  "@zohodesk/virtualizer": "1.0.3",