@zohodesk/components 1.0.0-temp-220.4 → 1.0.0-temp-220.6

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
@@ -12,6 +12,7 @@ import { addIntersectionObserver, removeIntersectionObserver } from "./intersect
12
12
  import { positionMapping } from "../DropBox/DropBoxPositionMapping.js";
13
13
  import isMobilePopover from "../DropBox/utils/isMobilePopover.js";
14
14
  import selectn from 'selectn';
15
+ import { getLibraryConfig } from "../Provider/Config.js";
15
16
  let lastOpenedGroup = [];
16
17
  let popups = {};
17
18
 
@@ -83,7 +84,6 @@ const CLICK_EVENTS = Object.freeze([{
83
84
  passive: false
84
85
  }
85
86
  }]);
86
- const iframeSelector = '[data-scroll=true] iframe';
87
87
  /* eslint-disable react/no-deprecated */
88
88
 
89
89
  /* eslint-disable react/prop-types */
@@ -160,7 +160,9 @@ const Popup = function (Component) {
160
160
  this.handleScrollAndBlockEvents = this.handleScrollAndBlockEvents.bind(this);
161
161
  this.handleIframeClickEvents = this.handleIframeClickEvents.bind(this);
162
162
  this.handleDropElementStyleUpdate = this.handleDropElementStyleUpdate.bind(this);
163
+ this.getParentContainerElement = this.getParentContainerElement.bind(this);
163
164
  this.positionRef = /*#__PURE__*/React.createRef();
165
+ this.parentContainerElement = this.getParentContainerElement();
164
166
  this.popupObserver = new ResizeObserver(this.handlePopupResize); //dropBoxSize
165
167
 
166
168
  this.size = null;
@@ -181,11 +183,10 @@ const Popup = function (Component) {
181
183
  popups[group] = groupPopups;
182
184
 
183
185
  if (Object.keys(popups).length === 1 && groupPopups.length === 1) {
184
- document.addEventListener('click', this.documentClickHandler, false);
186
+ this.updateListeners(true, CLICK_EVENTS, document);
185
187
  document.addEventListener('keyup', this.documentKeyupHandler, false); // document.addEventListener('scroll', this.handleScroll, true);
186
188
 
187
189
  window.addEventListener('resize', this.handleResize);
188
- document.addEventListener('click', this.documentClickHandler1, true);
189
190
  document.addEventListener('mousedown', this.handleDocumentMouseDown, true);
190
191
  document.addEventListener('focus', this.handleDocumentFocus, true);
191
192
  }
@@ -204,8 +205,22 @@ const Popup = function (Component) {
204
205
  }
205
206
  }
206
207
 
207
- handleScrollAndBlockEvents(isPopupReady, isMobile) {
208
- if (isPopupReady && !isMobile) {
208
+ getParentContainerElement() {
209
+ const getParentContainer = getLibraryConfig('getParentContainer');
210
+
211
+ if (getParentContainer && typeof getParentContainer === 'function') {
212
+ const parent = getParentContainer();
213
+
214
+ if (parent) {
215
+ return parent;
216
+ }
217
+ }
218
+
219
+ return document;
220
+ }
221
+
222
+ handleScrollAndBlockEvents(shouldAdd) {
223
+ if (shouldAdd) {
209
224
  this.handleAddingScrollBlock();
210
225
  this.handleAddingScrollToUpdatePosition();
211
226
  } else {
@@ -214,19 +229,14 @@ const Popup = function (Component) {
214
229
  }
215
230
  }
216
231
 
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
- };
232
+ handleIframeClickEvents(shouldAdd) {
233
+ this.parentContainerElement.querySelectorAll('iframe').forEach(frame => {
234
+ const frameDocument = frame.contentDocument;
228
235
 
229
- toggleListeners(isPopupReady && !isMobile);
236
+ if (frameDocument) {
237
+ this.updateListeners(shouldAdd, CLICK_EVENTS, frameDocument);
238
+ }
239
+ });
230
240
  }
231
241
 
232
242
  componentDidUpdate(prevProps, prevState) {
@@ -255,8 +265,8 @@ const Popup = function (Component) {
255
265
  }
256
266
 
257
267
  if (oldStateOpen !== isPopupReady && !isMobile || oldIsMobileState !== isMobile) {
258
- this.handleScrollAndBlockEvents(isPopupReady, isMobile);
259
- this.handleIframeClickEvents(isPopupReady, isMobile);
268
+ this.handleScrollAndBlockEvents(isPopupReady && !isMobile);
269
+ this.handleIframeClickEvents(isPopupReady && !isMobile);
260
270
  }
261
271
  }
262
272
 
@@ -274,6 +284,7 @@ const Popup = function (Component) {
274
284
  }, popups);
275
285
  this.handleRemovingScrollBlock();
276
286
  this.handleRemovingScrollToUpdatePosition();
287
+ this.handleIframeClickEvents(false);
277
288
  let noPopups = true;
278
289
 
279
290
  for (const i in popups) {
@@ -288,11 +299,10 @@ const Popup = function (Component) {
288
299
  }
289
300
 
290
301
  if (noPopups) {
291
- document.removeEventListener('click', this.documentClickHandler);
302
+ this.updateListeners(false, CLICK_EVENTS, document);
292
303
  document.removeEventListener('keyup', this.documentKeyupHandler); // document.removeEventListener('scroll', this.handleScroll);
293
304
 
294
305
  window.removeEventListener('resize', this.handleResize);
295
- document.removeEventListener('click', this.documentClickHandler1, true);
296
306
  document.removeEventListener('mousedown', this.handleDocumentMouseDown, true);
297
307
  document.removeEventListener('focus', this.handleDocumentFocus, true);
298
308
  }
@@ -415,30 +425,25 @@ const Popup = function (Component) {
415
425
  let eventList = arguments.length > 1 ? arguments[1] : undefined;
416
426
  let element = arguments.length > 2 ? arguments[2] : undefined;
417
427
  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);
428
+ eventList.forEach(_ref2 => {
429
+ let {
430
+ name,
431
+ handlerName,
432
+ options
433
+ } = _ref2;
434
+ const handler = this[handlerName];
435
+
436
+ if (handler) {
437
+ element[method](name, handler, options);
438
+ }
439
+ });
435
440
  }
436
441
 
437
442
  addScrollBlockListeners() {
438
443
  // 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
444
+ this.updateListeners(true, SCROLL_BLOCK_EVENTS, document); // Attach event listeners to all iframes within parentContainerElement
440
445
 
441
- document.querySelectorAll(iframeSelector).forEach(frame => {
446
+ this.parentContainerElement.querySelectorAll('iframe').forEach(frame => {
442
447
  const frameDocument = frame.contentDocument;
443
448
 
444
449
  if (frameDocument) {
@@ -449,7 +454,7 @@ const Popup = function (Component) {
449
454
 
450
455
  removeScrollBlockListeners() {
451
456
  this.updateListeners(false, SCROLL_BLOCK_EVENTS, document);
452
- document.querySelectorAll(iframeSelector).forEach(frame => {
457
+ this.parentContainerElement.querySelectorAll('iframe').forEach(frame => {
453
458
  const frameDocument = frame.contentDocument;
454
459
 
455
460
  if (frameDocument) {
@@ -8,7 +8,8 @@ let id = {
8
8
  direction: 'ltr',
9
9
  tooltipDebounce: 175,
10
10
  getTooltipContainer: () => {},
11
- autoComplete: false
11
+ autoComplete: false,
12
+ getParentContainer: () => {}
12
13
  };
13
14
  export function getLibraryConfig(key) {
14
15
  return id[key];
@@ -29,6 +29,8 @@ var _isMobilePopover = _interopRequireDefault(require("../DropBox/utils/isMobile
29
29
 
30
30
  var _selectn = _interopRequireDefault(require("selectn"));
31
31
 
32
+ var _Config = require("../Provider/Config.js");
33
+
32
34
  var _excluded = ["isMobile"];
33
35
 
34
36
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
@@ -144,7 +146,6 @@ var CLICK_EVENTS = Object.freeze([{
144
146
  passive: false
145
147
  }
146
148
  }]);
147
- var iframeSelector = '[data-scroll=true] iframe';
148
149
  /* eslint-disable react/no-deprecated */
149
150
 
150
151
  /* eslint-disable react/prop-types */
@@ -235,7 +236,9 @@ var Popup = function Popup(Component) {
235
236
  _this.handleScrollAndBlockEvents = _this.handleScrollAndBlockEvents.bind(_assertThisInitialized(_this));
236
237
  _this.handleIframeClickEvents = _this.handleIframeClickEvents.bind(_assertThisInitialized(_this));
237
238
  _this.handleDropElementStyleUpdate = _this.handleDropElementStyleUpdate.bind(_assertThisInitialized(_this));
239
+ _this.getParentContainerElement = _this.getParentContainerElement.bind(_assertThisInitialized(_this));
238
240
  _this.positionRef = /*#__PURE__*/_react["default"].createRef();
241
+ _this.parentContainerElement = _this.getParentContainerElement();
239
242
  _this.popupObserver = new _ResizeObserver["default"](_this.handlePopupResize); //dropBoxSize
240
243
 
241
244
  _this.size = null;
@@ -260,11 +263,10 @@ var Popup = function Popup(Component) {
260
263
  popups[group] = groupPopups;
261
264
 
262
265
  if (Object.keys(popups).length === 1 && groupPopups.length === 1) {
263
- document.addEventListener('click', this.documentClickHandler, false);
266
+ this.updateListeners(true, CLICK_EVENTS, document);
264
267
  document.addEventListener('keyup', this.documentKeyupHandler, false); // document.addEventListener('scroll', this.handleScroll, true);
265
268
 
266
269
  window.addEventListener('resize', this.handleResize);
267
- document.addEventListener('click', this.documentClickHandler1, true);
268
270
  document.addEventListener('mousedown', this.handleDocumentMouseDown, true);
269
271
  document.addEventListener('focus', this.handleDocumentFocus, true);
270
272
  }
@@ -281,10 +283,25 @@ var Popup = function Popup(Component) {
281
283
  });
282
284
  }
283
285
  }
286
+ }, {
287
+ key: "getParentContainerElement",
288
+ value: function getParentContainerElement() {
289
+ var getParentContainer = (0, _Config.getLibraryConfig)('getParentContainer');
290
+
291
+ if (getParentContainer && typeof getParentContainer === 'function') {
292
+ var parent = getParentContainer();
293
+
294
+ if (parent) {
295
+ return parent;
296
+ }
297
+ }
298
+
299
+ return document;
300
+ }
284
301
  }, {
285
302
  key: "handleScrollAndBlockEvents",
286
- value: function handleScrollAndBlockEvents(isPopupReady, isMobile) {
287
- if (isPopupReady && !isMobile) {
303
+ value: function handleScrollAndBlockEvents(shouldAdd) {
304
+ if (shouldAdd) {
288
305
  this.handleAddingScrollBlock();
289
306
  this.handleAddingScrollToUpdatePosition();
290
307
  } else {
@@ -294,22 +311,16 @@ var Popup = function Popup(Component) {
294
311
  }
295
312
  }, {
296
313
  key: "handleIframeClickEvents",
297
- value: function handleIframeClickEvents(isPopupReady, isMobile) {
314
+ value: function handleIframeClickEvents(shouldAdd) {
298
315
  var _this2 = this;
299
316
 
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
- };
317
+ this.parentContainerElement.querySelectorAll('iframe').forEach(function (frame) {
318
+ var frameDocument = frame.contentDocument;
311
319
 
312
- toggleListeners(isPopupReady && !isMobile);
320
+ if (frameDocument) {
321
+ _this2.updateListeners(shouldAdd, CLICK_EVENTS, frameDocument);
322
+ }
323
+ });
313
324
  }
314
325
  }, {
315
326
  key: "componentDidUpdate",
@@ -336,8 +347,8 @@ var Popup = function Popup(Component) {
336
347
  }
337
348
 
338
349
  if (oldStateOpen !== isPopupReady && !isMobile || oldIsMobileState !== isMobile) {
339
- this.handleScrollAndBlockEvents(isPopupReady, isMobile);
340
- this.handleIframeClickEvents(isPopupReady, isMobile);
350
+ this.handleScrollAndBlockEvents(isPopupReady && !isMobile);
351
+ this.handleIframeClickEvents(isPopupReady && !isMobile);
341
352
  }
342
353
  }
343
354
  }, {
@@ -360,6 +371,7 @@ var Popup = function Popup(Component) {
360
371
  }, popups);
361
372
  this.handleRemovingScrollBlock();
362
373
  this.handleRemovingScrollToUpdatePosition();
374
+ this.handleIframeClickEvents(false);
363
375
  var noPopups = true;
364
376
 
365
377
  for (var i in popups) {
@@ -374,11 +386,10 @@ var Popup = function Popup(Component) {
374
386
  }
375
387
 
376
388
  if (noPopups) {
377
- document.removeEventListener('click', this.documentClickHandler);
389
+ this.updateListeners(false, CLICK_EVENTS, document);
378
390
  document.removeEventListener('keyup', this.documentKeyupHandler); // document.removeEventListener('scroll', this.handleScroll);
379
391
 
380
392
  window.removeEventListener('resize', this.handleResize);
381
- document.removeEventListener('click', this.documentClickHandler1, true);
382
393
  document.removeEventListener('mousedown', this.handleDocumentMouseDown, true);
383
394
  document.removeEventListener('focus', this.handleDocumentFocus, true);
384
395
  }
@@ -506,21 +517,16 @@ var Popup = function Popup(Component) {
506
517
  var eventList = arguments.length > 1 ? arguments[1] : undefined;
507
518
  var element = arguments.length > 2 ? arguments[2] : undefined;
508
519
  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);
520
+ eventList.forEach(function (_ref5) {
521
+ var name = _ref5.name,
522
+ handlerName = _ref5.handlerName,
523
+ options = _ref5.options;
524
+ var handler = _this4[handlerName];
525
+
526
+ if (handler) {
527
+ element[method](name, handler, options);
528
+ }
529
+ });
524
530
  }
525
531
  }, {
526
532
  key: "addScrollBlockListeners",
@@ -528,9 +534,9 @@ var Popup = function Popup(Component) {
528
534
  var _this5 = this;
529
535
 
530
536
  // 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
537
+ this.updateListeners(true, SCROLL_BLOCK_EVENTS, document); // Attach event listeners to all iframes within parentContainerElement
532
538
 
533
- document.querySelectorAll(iframeSelector).forEach(function (frame) {
539
+ this.parentContainerElement.querySelectorAll('iframe').forEach(function (frame) {
534
540
  var frameDocument = frame.contentDocument;
535
541
 
536
542
  if (frameDocument) {
@@ -544,7 +550,7 @@ var Popup = function Popup(Component) {
544
550
  var _this6 = this;
545
551
 
546
552
  this.updateListeners(false, SCROLL_BLOCK_EVENTS, document);
547
- document.querySelectorAll(iframeSelector).forEach(function (frame) {
553
+ this.parentContainerElement.querySelectorAll('iframe').forEach(function (frame) {
548
554
  var frameDocument = frame.contentDocument;
549
555
 
550
556
  if (frameDocument) {
@@ -15,7 +15,8 @@ var id = {
15
15
  direction: 'ltr',
16
16
  tooltipDebounce: 175,
17
17
  getTooltipContainer: function getTooltipContainer() {},
18
- autoComplete: false
18
+ autoComplete: false,
19
+ getParentContainer: function getParentContainer() {}
19
20
  };
20
21
 
21
22
  function getLibraryConfig(key) {
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.6",
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.75",
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.75",
90
90
  "@zohodesk/variables": "1.0.0",
91
91
  "@zohodesk/svg": "1.1.22",
92
92
  "@zohodesk/virtualizer": "1.0.3",