downshift 6.1.2 → 6.1.3

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.
@@ -63,12 +63,14 @@ function scrollIntoView(node, menuNode) {
63
63
  /**
64
64
  * @param {HTMLElement} parent the parent node
65
65
  * @param {HTMLElement} child the child node
66
+ * @param {Window} environment The window context where downshift renders.
66
67
  * @return {Boolean} whether the parent is the child or the child is in the parent
67
68
  */
68
69
 
69
70
 
70
- function isOrContainsNode(parent, child) {
71
- return parent === child || child instanceof Node && parent.contains && parent.contains(child);
71
+ function isOrContainsNode(parent, child, environment) {
72
+ var result = parent === child || child instanceof environment.Node && parent.contains && parent.contains(child);
73
+ return result;
72
74
  }
73
75
  /**
74
76
  * Simple debounce implementation. Will call the given
@@ -416,20 +418,20 @@ function getNextNonDisabledIndex(moveAmount, baseIndex, itemCount, getItemNodeFr
416
418
  *
417
419
  * @param {EventTarget} target Target to check.
418
420
  * @param {HTMLElement[]} downshiftElements The elements that form downshift (list, toggle button etc).
419
- * @param {Document} document The document.
421
+ * @param {Window} environment The window context where downshift renders.
420
422
  * @param {boolean} checkActiveElement Whether to also check activeElement.
421
423
  *
422
424
  * @returns {boolean} Whether or not the target is within downshift elements.
423
425
  */
424
426
 
425
427
 
426
- function targetWithinDownshift(target, downshiftElements, document, checkActiveElement) {
428
+ function targetWithinDownshift(target, downshiftElements, environment, checkActiveElement) {
427
429
  if (checkActiveElement === void 0) {
428
430
  checkActiveElement = true;
429
431
  }
430
432
 
431
433
  return downshiftElements.some(function (contextNode) {
432
- return contextNode && (isOrContainsNode(contextNode, target) || checkActiveElement && isOrContainsNode(contextNode, document.activeElement));
434
+ return contextNode && (isOrContainsNode(contextNode, target, environment) || checkActiveElement && isOrContainsNode(contextNode, environment.document.activeElement, environment));
433
435
  });
434
436
  } // eslint-disable-next-line import/no-mutable-exports
435
437
 
@@ -1438,7 +1440,7 @@ var Downshift = /*#__PURE__*/function () {
1438
1440
  _this7.isMouseDown = false; // if the target element or the activeElement is within a downshift node
1439
1441
  // then we don't want to reset downshift
1440
1442
 
1441
- var contextWithinDownshift = targetWithinDownshift(event.target, [_this7._rootNode, _this7._menuNode], _this7.props.environment.document);
1443
+ var contextWithinDownshift = targetWithinDownshift(event.target, [_this7._rootNode, _this7._menuNode], _this7.props.environment);
1442
1444
 
1443
1445
  if (!contextWithinDownshift && _this7.getState().isOpen) {
1444
1446
  _this7.reset({
@@ -1464,7 +1466,7 @@ var Downshift = /*#__PURE__*/function () {
1464
1466
  };
1465
1467
 
1466
1468
  var onTouchEnd = function onTouchEnd(event) {
1467
- var contextWithinDownshift = targetWithinDownshift(event.target, [_this7._rootNode, _this7._menuNode], _this7.props.environment.document, false);
1469
+ var contextWithinDownshift = targetWithinDownshift(event.target, [_this7._rootNode, _this7._menuNode], _this7.props.environment, false);
1468
1470
 
1469
1471
  if (!_this7.isTouchMove && !contextWithinDownshift && _this7.getState().isOpen) {
1470
1472
  _this7.reset({
@@ -2017,7 +2019,7 @@ function useMouseAndTouchTracker(isOpen, downshiftElementRefs, environment, hand
2017
2019
 
2018
2020
  if (isOpen && !targetWithinDownshift(event.target, downshiftElementRefs.map(function (ref) {
2019
2021
  return ref.current;
2020
- }), environment.document)) {
2022
+ }), environment)) {
2021
2023
  handleBlur();
2022
2024
  }
2023
2025
  };
@@ -2033,7 +2035,7 @@ function useMouseAndTouchTracker(isOpen, downshiftElementRefs, environment, hand
2033
2035
  var onTouchEnd = function onTouchEnd(event) {
2034
2036
  if (isOpen && !mouseAndTouchTrackersRef.current.isTouchMove && !targetWithinDownshift(event.target, downshiftElementRefs.map(function (ref) {
2035
2037
  return ref.current;
2036
- }), environment.document, false)) {
2038
+ }), environment, false)) {
2037
2039
  handleBlur();
2038
2040
  }
2039
2041
  };
@@ -50,12 +50,14 @@ function scrollIntoView(node, menuNode) {
50
50
  /**
51
51
  * @param {HTMLElement} parent the parent node
52
52
  * @param {HTMLElement} child the child node
53
+ * @param {Window} environment The window context where downshift renders.
53
54
  * @return {Boolean} whether the parent is the child or the child is in the parent
54
55
  */
55
56
 
56
57
 
57
- function isOrContainsNode(parent, child) {
58
- return parent === child || child instanceof Node && parent.contains && parent.contains(child);
58
+ function isOrContainsNode(parent, child, environment) {
59
+ var result = parent === child || child instanceof environment.Node && parent.contains && parent.contains(child);
60
+ return result;
59
61
  }
60
62
  /**
61
63
  * Simple debounce implementation. Will call the given
@@ -403,20 +405,20 @@ function getNextNonDisabledIndex(moveAmount, baseIndex, itemCount, getItemNodeFr
403
405
  *
404
406
  * @param {EventTarget} target Target to check.
405
407
  * @param {HTMLElement[]} downshiftElements The elements that form downshift (list, toggle button etc).
406
- * @param {Document} document The document.
408
+ * @param {Window} environment The window context where downshift renders.
407
409
  * @param {boolean} checkActiveElement Whether to also check activeElement.
408
410
  *
409
411
  * @returns {boolean} Whether or not the target is within downshift elements.
410
412
  */
411
413
 
412
414
 
413
- function targetWithinDownshift(target, downshiftElements, document, checkActiveElement) {
415
+ function targetWithinDownshift(target, downshiftElements, environment, checkActiveElement) {
414
416
  if (checkActiveElement === void 0) {
415
417
  checkActiveElement = true;
416
418
  }
417
419
 
418
420
  return downshiftElements.some(function (contextNode) {
419
- return contextNode && (isOrContainsNode(contextNode, target) || checkActiveElement && isOrContainsNode(contextNode, document.activeElement));
421
+ return contextNode && (isOrContainsNode(contextNode, target, environment) || checkActiveElement && isOrContainsNode(contextNode, environment.document.activeElement, environment));
420
422
  });
421
423
  } // eslint-disable-next-line import/no-mutable-exports
422
424
 
@@ -1425,7 +1427,7 @@ var Downshift = /*#__PURE__*/function () {
1425
1427
  _this7.isMouseDown = false; // if the target element or the activeElement is within a downshift node
1426
1428
  // then we don't want to reset downshift
1427
1429
 
1428
- var contextWithinDownshift = targetWithinDownshift(event.target, [_this7._rootNode, _this7._menuNode], _this7.props.environment.document);
1430
+ var contextWithinDownshift = targetWithinDownshift(event.target, [_this7._rootNode, _this7._menuNode], _this7.props.environment);
1429
1431
 
1430
1432
  if (!contextWithinDownshift && _this7.getState().isOpen) {
1431
1433
  _this7.reset({
@@ -1451,7 +1453,7 @@ var Downshift = /*#__PURE__*/function () {
1451
1453
  };
1452
1454
 
1453
1455
  var onTouchEnd = function onTouchEnd(event) {
1454
- var contextWithinDownshift = targetWithinDownshift(event.target, [_this7._rootNode, _this7._menuNode], _this7.props.environment.document, false);
1456
+ var contextWithinDownshift = targetWithinDownshift(event.target, [_this7._rootNode, _this7._menuNode], _this7.props.environment, false);
1455
1457
 
1456
1458
  if (!_this7.isTouchMove && !contextWithinDownshift && _this7.getState().isOpen) {
1457
1459
  _this7.reset({
@@ -2004,7 +2006,7 @@ function useMouseAndTouchTracker(isOpen, downshiftElementRefs, environment, hand
2004
2006
 
2005
2007
  if (isOpen && !targetWithinDownshift(event.target, downshiftElementRefs.map(function (ref) {
2006
2008
  return ref.current;
2007
- }), environment.document)) {
2009
+ }), environment)) {
2008
2010
  handleBlur();
2009
2011
  }
2010
2012
  };
@@ -2020,7 +2022,7 @@ function useMouseAndTouchTracker(isOpen, downshiftElementRefs, environment, hand
2020
2022
  var onTouchEnd = function onTouchEnd(event) {
2021
2023
  if (isOpen && !mouseAndTouchTrackersRef.current.isTouchMove && !targetWithinDownshift(event.target, downshiftElementRefs.map(function (ref) {
2022
2024
  return ref.current;
2023
- }), environment.document, false)) {
2025
+ }), environment, false)) {
2024
2026
  handleBlur();
2025
2027
  }
2026
2028
  };
@@ -63,12 +63,14 @@ function scrollIntoView(node, menuNode) {
63
63
  /**
64
64
  * @param {HTMLElement} parent the parent node
65
65
  * @param {HTMLElement} child the child node
66
+ * @param {Window} environment The window context where downshift renders.
66
67
  * @return {Boolean} whether the parent is the child or the child is in the parent
67
68
  */
68
69
 
69
70
 
70
- function isOrContainsNode(parent, child) {
71
- return parent === child || child instanceof Node && parent.contains && parent.contains(child);
71
+ function isOrContainsNode(parent, child, environment) {
72
+ var result = parent === child || child instanceof environment.Node && parent.contains && parent.contains(child);
73
+ return result;
72
74
  }
73
75
  /**
74
76
  * Simple debounce implementation. Will call the given
@@ -416,20 +418,20 @@ function getNextNonDisabledIndex(moveAmount, baseIndex, itemCount, getItemNodeFr
416
418
  *
417
419
  * @param {EventTarget} target Target to check.
418
420
  * @param {HTMLElement[]} downshiftElements The elements that form downshift (list, toggle button etc).
419
- * @param {Document} document The document.
421
+ * @param {Window} environment The window context where downshift renders.
420
422
  * @param {boolean} checkActiveElement Whether to also check activeElement.
421
423
  *
422
424
  * @returns {boolean} Whether or not the target is within downshift elements.
423
425
  */
424
426
 
425
427
 
426
- function targetWithinDownshift(target, downshiftElements, document, checkActiveElement) {
428
+ function targetWithinDownshift(target, downshiftElements, environment, checkActiveElement) {
427
429
  if (checkActiveElement === void 0) {
428
430
  checkActiveElement = true;
429
431
  }
430
432
 
431
433
  return downshiftElements.some(function (contextNode) {
432
- return contextNode && (isOrContainsNode(contextNode, target) || checkActiveElement && isOrContainsNode(contextNode, document.activeElement));
434
+ return contextNode && (isOrContainsNode(contextNode, target, environment) || checkActiveElement && isOrContainsNode(contextNode, environment.document.activeElement, environment));
433
435
  });
434
436
  } // eslint-disable-next-line import/no-mutable-exports
435
437
 
@@ -1946,7 +1948,7 @@ function useMouseAndTouchTracker(isOpen, downshiftElementRefs, environment, hand
1946
1948
 
1947
1949
  if (isOpen && !targetWithinDownshift(event.target, downshiftElementRefs.map(function (ref) {
1948
1950
  return ref.current;
1949
- }), environment.document)) {
1951
+ }), environment)) {
1950
1952
  handleBlur();
1951
1953
  }
1952
1954
  };
@@ -1962,7 +1964,7 @@ function useMouseAndTouchTracker(isOpen, downshiftElementRefs, environment, hand
1962
1964
  var onTouchEnd = function onTouchEnd(event) {
1963
1965
  if (isOpen && !mouseAndTouchTrackersRef.current.isTouchMove && !targetWithinDownshift(event.target, downshiftElementRefs.map(function (ref) {
1964
1966
  return ref.current;
1965
- }), environment.document, false)) {
1967
+ }), environment, false)) {
1966
1968
  handleBlur();
1967
1969
  }
1968
1970
  };
@@ -1513,12 +1513,14 @@
1513
1513
  /**
1514
1514
  * @param {HTMLElement} parent the parent node
1515
1515
  * @param {HTMLElement} child the child node
1516
+ * @param {Window} environment The window context where downshift renders.
1516
1517
  * @return {Boolean} whether the parent is the child or the child is in the parent
1517
1518
  */
1518
1519
 
1519
1520
 
1520
- function isOrContainsNode(parent, child) {
1521
- return parent === child || child instanceof Node && parent.contains && parent.contains(child);
1521
+ function isOrContainsNode(parent, child, environment) {
1522
+ var result = parent === child || child instanceof environment.Node && parent.contains && parent.contains(child);
1523
+ return result;
1522
1524
  }
1523
1525
  /**
1524
1526
  * Simple debounce implementation. Will call the given
@@ -1866,20 +1868,20 @@
1866
1868
  *
1867
1869
  * @param {EventTarget} target Target to check.
1868
1870
  * @param {HTMLElement[]} downshiftElements The elements that form downshift (list, toggle button etc).
1869
- * @param {Document} document The document.
1871
+ * @param {Window} environment The window context where downshift renders.
1870
1872
  * @param {boolean} checkActiveElement Whether to also check activeElement.
1871
1873
  *
1872
1874
  * @returns {boolean} Whether or not the target is within downshift elements.
1873
1875
  */
1874
1876
 
1875
1877
 
1876
- function targetWithinDownshift(target, downshiftElements, document, checkActiveElement) {
1878
+ function targetWithinDownshift(target, downshiftElements, environment, checkActiveElement) {
1877
1879
  if (checkActiveElement === void 0) {
1878
1880
  checkActiveElement = true;
1879
1881
  }
1880
1882
 
1881
1883
  return downshiftElements.some(function (contextNode) {
1882
- return contextNode && (isOrContainsNode(contextNode, target) || checkActiveElement && isOrContainsNode(contextNode, document.activeElement));
1884
+ return contextNode && (isOrContainsNode(contextNode, target, environment) || checkActiveElement && isOrContainsNode(contextNode, environment.document.activeElement, environment));
1883
1885
  });
1884
1886
  } // eslint-disable-next-line import/no-mutable-exports
1885
1887
 
@@ -2882,7 +2884,7 @@
2882
2884
  _this7.isMouseDown = false; // if the target element or the activeElement is within a downshift node
2883
2885
  // then we don't want to reset downshift
2884
2886
 
2885
- var contextWithinDownshift = targetWithinDownshift(event.target, [_this7._rootNode, _this7._menuNode], _this7.props.environment.document);
2887
+ var contextWithinDownshift = targetWithinDownshift(event.target, [_this7._rootNode, _this7._menuNode], _this7.props.environment);
2886
2888
 
2887
2889
  if (!contextWithinDownshift && _this7.getState().isOpen) {
2888
2890
  _this7.reset({
@@ -2908,7 +2910,7 @@
2908
2910
  };
2909
2911
 
2910
2912
  var onTouchEnd = function onTouchEnd(event) {
2911
- var contextWithinDownshift = targetWithinDownshift(event.target, [_this7._rootNode, _this7._menuNode], _this7.props.environment.document, false);
2913
+ var contextWithinDownshift = targetWithinDownshift(event.target, [_this7._rootNode, _this7._menuNode], _this7.props.environment, false);
2912
2914
 
2913
2915
  if (!_this7.isTouchMove && !contextWithinDownshift && _this7.getState().isOpen) {
2914
2916
  _this7.reset({
@@ -3457,7 +3459,7 @@
3457
3459
 
3458
3460
  if (isOpen && !targetWithinDownshift(event.target, downshiftElementRefs.map(function (ref) {
3459
3461
  return ref.current;
3460
- }), environment.document)) {
3462
+ }), environment)) {
3461
3463
  handleBlur();
3462
3464
  }
3463
3465
  };
@@ -3473,7 +3475,7 @@
3473
3475
  var onTouchEnd = function onTouchEnd(event) {
3474
3476
  if (isOpen && !mouseAndTouchTrackersRef.current.isTouchMove && !targetWithinDownshift(event.target, downshiftElementRefs.map(function (ref) {
3475
3477
  return ref.current;
3476
- }), environment.document, false)) {
3478
+ }), environment, false)) {
3477
3479
  handleBlur();
3478
3480
  }
3479
3481
  };