@elastic/eui 62.1.0 → 62.2.2

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.
Files changed (62) hide show
  1. package/dist/eui_charts_theme.js +330 -330
  2. package/dist/eui_charts_theme.js.map +1 -1
  3. package/es/components/datagrid/body/data_grid_body.js +11 -1
  4. package/es/components/datagrid/body/data_grid_cell.js +31 -3
  5. package/es/components/datagrid/data_grid.js +9 -1
  6. package/es/components/datagrid/utils/row_heights.js +33 -4
  7. package/es/components/description_list/description_list_description.js +2 -1
  8. package/es/components/description_list/description_list_title.js +2 -1
  9. package/es/components/popover/wrapping_popover.js +88 -45
  10. package/es/components/portal/portal.js +84 -38
  11. package/es/services/breakpoint/{currentEuiBreakpoint.js → current_breakpoint.js} +2 -12
  12. package/es/services/breakpoint/current_breakpoint_hook.js +20 -0
  13. package/es/services/breakpoint/index.js +2 -1
  14. package/es/services/breakpoint/useIsWithinBreakpoints.js +1 -1
  15. package/es/test/rtl/component_helpers.js +60 -1
  16. package/eui.d.ts +50 -150
  17. package/lib/components/datagrid/body/data_grid_body.js +11 -1
  18. package/lib/components/datagrid/body/data_grid_cell.js +31 -3
  19. package/lib/components/datagrid/data_grid.js +9 -1
  20. package/lib/components/datagrid/utils/row_heights.js +33 -4
  21. package/lib/components/popover/wrapping_popover.js +85 -44
  22. package/lib/components/portal/portal.js +87 -39
  23. package/lib/services/breakpoint/{currentEuiBreakpoint.js → current_breakpoint.js} +5 -16
  24. package/lib/services/breakpoint/current_breakpoint_hook.js +31 -0
  25. package/lib/services/breakpoint/index.js +17 -4
  26. package/lib/services/breakpoint/useIsWithinBreakpoints.js +2 -2
  27. package/lib/test/rtl/component_helpers.js +69 -3
  28. package/optimize/es/components/datagrid/body/data_grid_body.js +2 -0
  29. package/optimize/es/components/datagrid/body/data_grid_cell.js +13 -1
  30. package/optimize/es/components/datagrid/utils/row_heights.js +33 -4
  31. package/optimize/es/components/description_list/description_list_description.js +2 -1
  32. package/optimize/es/components/description_list/description_list_title.js +2 -1
  33. package/optimize/es/components/popover/wrapping_popover.js +79 -38
  34. package/optimize/es/components/portal/portal.js +66 -34
  35. package/optimize/es/services/breakpoint/{currentEuiBreakpoint.js → current_breakpoint.js} +2 -11
  36. package/optimize/es/services/breakpoint/current_breakpoint_hook.js +20 -0
  37. package/optimize/es/services/breakpoint/index.js +2 -1
  38. package/optimize/es/services/breakpoint/useIsWithinBreakpoints.js +1 -1
  39. package/optimize/es/test/rtl/component_helpers.js +60 -1
  40. package/optimize/lib/components/datagrid/body/data_grid_body.js +2 -0
  41. package/optimize/lib/components/datagrid/body/data_grid_cell.js +13 -1
  42. package/optimize/lib/components/datagrid/utils/row_heights.js +33 -4
  43. package/optimize/lib/components/popover/wrapping_popover.js +78 -38
  44. package/optimize/lib/components/portal/portal.js +65 -44
  45. package/optimize/lib/services/breakpoint/{currentEuiBreakpoint.js → current_breakpoint.js} +5 -18
  46. package/optimize/lib/services/breakpoint/current_breakpoint_hook.js +31 -0
  47. package/optimize/lib/services/breakpoint/index.js +17 -4
  48. package/optimize/lib/services/breakpoint/useIsWithinBreakpoints.js +2 -2
  49. package/optimize/lib/test/rtl/component_helpers.js +69 -3
  50. package/package.json +2 -2
  51. package/test-env/components/datagrid/body/data_grid_body.js +11 -1
  52. package/test-env/components/datagrid/body/data_grid_cell.js +31 -3
  53. package/test-env/components/datagrid/data_grid.js +9 -1
  54. package/test-env/components/datagrid/utils/row_heights.js +33 -4
  55. package/test-env/components/observer/resize_observer/resize_observer.js +43 -126
  56. package/test-env/components/popover/wrapping_popover.js +78 -38
  57. package/test-env/components/portal/portal.js +79 -45
  58. package/test-env/services/breakpoint/current_breakpoint.js +68 -0
  59. package/test-env/services/breakpoint/{currentEuiBreakpoint.js → current_breakpoint_hook.js} +3 -7
  60. package/test-env/services/breakpoint/index.js +17 -4
  61. package/test-env/services/breakpoint/useIsWithinBreakpoints.js +2 -2
  62. package/test-env/test/rtl/component_helpers.js +69 -3
@@ -343,6 +343,8 @@ export var EuiDataGridBody = function EuiDataGridBody(props) {
343
343
 
344
344
  var rowHeightUtils = useRowHeightUtils({
345
345
  gridRef: gridRef,
346
+ outerGridElementRef: outerGridRef,
347
+ gridItemsRenderedRef: gridItemsRendered,
346
348
  gridStyles: gridStyles,
347
349
  columns: columns,
348
350
  rowHeightsOptions: rowHeightsOptions
@@ -1025,7 +1027,15 @@ EuiDataGridBody.propTypes = {
1025
1027
  * Optional callback returning the current `rowHeightsOptions` when changes occur from user input (e.g. toolbar display controls).
1026
1028
  * Can be used for, e.g. storing user `rowHeightsOptions` in a local storage object.
1027
1029
  */
1028
- onChange: PropTypes.func
1030
+ onChange: PropTypes.func,
1031
+
1032
+ /**
1033
+ * Optional indicator of the row that should be used as an anchor for vertical layout shift compensation.
1034
+ * When set to 'start' or 'center', the topmost or middle visible row will try
1035
+ * to compensate for changes in their top offsets by adjusting the grid's scroll
1036
+ * position.
1037
+ */
1038
+ scrollAnchorRow: PropTypes.oneOf(["start", "center", undefined])
1029
1039
  }),
1030
1040
  isFullScreen: PropTypes.bool.isRequired,
1031
1041
  gridStyles: PropTypes.shape({
@@ -544,7 +544,15 @@ EuiDataGridCellContent.propTypes = {
544
544
  * Optional callback returning the current `rowHeightsOptions` when changes occur from user input (e.g. toolbar display controls).
545
545
  * Can be used for, e.g. storing user `rowHeightsOptions` in a local storage object.
546
546
  */
547
- onChange: PropTypes.func
547
+ onChange: PropTypes.func,
548
+
549
+ /**
550
+ * Optional indicator of the row that should be used as an anchor for vertical layout shift compensation.
551
+ * When set to 'start' or 'center', the topmost or middle visible row will try
552
+ * to compensate for changes in their top offsets by adjusting the grid's scroll
553
+ * position.
554
+ */
555
+ scrollAnchorRow: PropTypes.oneOf(["start", "center", undefined])
548
556
  }),
549
557
  rowHeightUtils: PropTypes.any,
550
558
  pagination: PropTypes.shape({
@@ -915,7 +923,7 @@ export var EuiDataGridCell = /*#__PURE__*/function (_Component) {
915
923
  }, {
916
924
  key: "componentDidUpdate",
917
925
  value: function componentDidUpdate(prevProps) {
918
- var _this$props$rowHeight, _prevProps$rowHeights;
926
+ var _this$props$rowHeight, _prevProps$rowHeights, _this$props$rowHeight2, _this$props$style, _prevProps$style;
919
927
 
920
928
  this.recalculateAutoHeight();
921
929
 
@@ -923,6 +931,18 @@ export var EuiDataGridCell = /*#__PURE__*/function (_Component) {
923
931
  this.recalculateLineHeight();
924
932
  }
925
933
 
934
+ if ((_this$props$rowHeight2 = this.props.rowHeightsOptions) !== null && _this$props$rowHeight2 !== void 0 && _this$props$rowHeight2.scrollAnchorRow && this.props.colIndex === 0 && // once per row
935
+ this.props.columnId === prevProps.columnId && // if this is still the same column
936
+ this.props.rowIndex === prevProps.rowIndex && // if this is still the same row
937
+ ((_this$props$style = this.props.style) === null || _this$props$style === void 0 ? void 0 : _this$props$style.top) !== ((_prevProps$style = prevProps.style) === null || _prevProps$style === void 0 ? void 0 : _prevProps$style.top) // if the top position has changed
938
+ ) {
939
+ var _prevProps$style2, _this$props$style2, _this$props$rowHeight3, _this$props$rowHeight4;
940
+
941
+ var previousTop = parseFloat((_prevProps$style2 = prevProps.style) === null || _prevProps$style2 === void 0 ? void 0 : _prevProps$style2.top);
942
+ var currentTop = parseFloat((_this$props$style2 = this.props.style) === null || _this$props$style2 === void 0 ? void 0 : _this$props$style2.top);
943
+ (_this$props$rowHeight3 = this.props.rowHeightUtils) === null || _this$props$rowHeight3 === void 0 ? void 0 : _this$props$rowHeight3.compensateForLayoutShift(this.props.rowIndex, currentTop - previousTop, (_this$props$rowHeight4 = this.props.rowHeightsOptions) === null || _this$props$rowHeight4 === void 0 ? void 0 : _this$props$rowHeight4.scrollAnchorRow);
944
+ }
945
+
926
946
  if (this.props.popoverContext.popoverIsOpen !== prevProps.popoverContext.popoverIsOpen || this.props.popoverContext.cellLocation !== prevProps.popoverContext.cellLocation || this.props.renderCellPopover !== prevProps.renderCellPopover) {
927
947
  this.handleCellPopover();
928
948
  }
@@ -1572,7 +1592,15 @@ EuiDataGridCell.propTypes = {
1572
1592
  * Optional callback returning the current `rowHeightsOptions` when changes occur from user input (e.g. toolbar display controls).
1573
1593
  * Can be used for, e.g. storing user `rowHeightsOptions` in a local storage object.
1574
1594
  */
1575
- onChange: PropTypes.func
1595
+ onChange: PropTypes.func,
1596
+
1597
+ /**
1598
+ * Optional indicator of the row that should be used as an anchor for vertical layout shift compensation.
1599
+ * When set to 'start' or 'center', the topmost or middle visible row will try
1600
+ * to compensate for changes in their top offsets by adjusting the grid's scroll
1601
+ * position.
1602
+ */
1603
+ scrollAnchorRow: PropTypes.oneOf(["start", "center", undefined])
1576
1604
  }),
1577
1605
  rowHeightUtils: PropTypes.any,
1578
1606
  rowManager: PropTypes.shape({
@@ -1253,7 +1253,15 @@ EuiDataGrid.propTypes = {
1253
1253
  * Optional callback returning the current `rowHeightsOptions` when changes occur from user input (e.g. toolbar display controls).
1254
1254
  * Can be used for, e.g. storing user `rowHeightsOptions` in a local storage object.
1255
1255
  */
1256
- onChange: PropTypes.func
1256
+ onChange: PropTypes.func,
1257
+
1258
+ /**
1259
+ * Optional indicator of the row that should be used as an anchor for vertical layout shift compensation.
1260
+ * When set to 'start' or 'center', the topmost or middle visible row will try
1261
+ * to compensate for changes in their top offsets by adjusting the grid's scroll
1262
+ * position.
1263
+ */
1264
+ scrollAnchorRow: PropTypes.oneOf(["start", "center", undefined])
1257
1265
  })
1258
1266
  };
1259
1267
  EuiDataGrid.displayName = 'EuiDataGrid';
@@ -33,9 +33,9 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
33
33
  * in compliance with, at your election, the Elastic License 2.0 or the Server
34
34
  * Side Public License, v 1.
35
35
  */
36
- import { useEffect, useState, useMemo, useCallback, useContext } from 'react';
37
- import { isObject, isNumber } from '../../../services/predicate';
36
+ import { useCallback, useContext, useEffect, useMemo, useState } from 'react';
38
37
  import { useForceRender, useLatest } from '../../../services';
38
+ import { isNumber, isObject } from '../../../services/predicate';
39
39
  import { DataGridSortingContext } from './sorting'; // TODO: Once JS variables are available, use them here instead of hard-coded maps
40
40
 
41
41
  export var cellPaddingsMap = {
@@ -46,12 +46,14 @@ export var cellPaddingsMap = {
46
46
  export var AUTO_HEIGHT = 'auto';
47
47
  export var DEFAULT_ROW_HEIGHT = 34;
48
48
  export var RowHeightUtils = /*#__PURE__*/function () {
49
- function RowHeightUtils(gridRef, rerenderGridBodyRef) {
49
+ function RowHeightUtils(gridRef, outerGridElementRef, gridItemsRenderedRef, rerenderGridBodyRef) {
50
50
  var _this = this;
51
51
 
52
52
  _classCallCheck(this, RowHeightUtils);
53
53
 
54
54
  this.gridRef = gridRef;
55
+ this.outerGridElementRef = outerGridElementRef;
56
+ this.gridItemsRenderedRef = gridItemsRenderedRef;
55
57
  this.rerenderGridBodyRef = rerenderGridBodyRef;
56
58
 
57
59
  _defineProperty(this, "styles", {
@@ -247,6 +249,31 @@ export var RowHeightUtils = /*#__PURE__*/function () {
247
249
  (_this$gridRef$current = this.gridRef.current) === null || _this$gridRef$current === void 0 ? void 0 : _this$gridRef$current.resetAfterRowIndex(this.lastUpdatedRow);
248
250
  this.lastUpdatedRow = Infinity;
249
251
  }
252
+ }, {
253
+ key: "compensateForLayoutShift",
254
+ value: function compensateForLayoutShift(rowIndex, verticalLayoutShift, anchorRow) {
255
+ var grid = this.gridRef.current;
256
+ var outerGridElement = this.outerGridElementRef.current;
257
+ var renderedItems = this.gridItemsRenderedRef.current;
258
+
259
+ if (grid == null || outerGridElement == null || renderedItems == null || anchorRow == null || !Number.isFinite(verticalLayoutShift)) {
260
+ return;
261
+ } // skip if the start row is the anchor row but it hasn't shifted
262
+
263
+
264
+ if (anchorRow === 'start' && renderedItems.visibleRowStartIndex !== rowIndex) {
265
+ return;
266
+ } // skip if the center row is the anchor row but it hasn't shifted
267
+
268
+
269
+ if (anchorRow === 'center' && Math.floor((renderedItems.visibleRowStopIndex - renderedItems.visibleRowStartIndex) / 2) !== rowIndex) {
270
+ return;
271
+ }
272
+
273
+ grid.scrollTo({
274
+ scrollTop: outerGridElement.scrollTop + verticalLayoutShift
275
+ });
276
+ }
250
277
  }]);
251
278
 
252
279
  return RowHeightUtils;
@@ -258,13 +285,15 @@ export var RowHeightUtils = /*#__PURE__*/function () {
258
285
 
259
286
  export var useRowHeightUtils = function useRowHeightUtils(_ref2) {
260
287
  var gridRef = _ref2.gridRef,
288
+ outerGridElementRef = _ref2.outerGridElementRef,
289
+ gridItemsRenderedRef = _ref2.gridItemsRenderedRef,
261
290
  gridStyles = _ref2.gridStyles,
262
291
  columns = _ref2.columns,
263
292
  rowHeightsOptions = _ref2.rowHeightsOptions;
264
293
  var forceRenderRef = useLatest(useForceRender());
265
294
 
266
295
  var _useState = useState(function () {
267
- return new RowHeightUtils(gridRef, forceRenderRef);
296
+ return new RowHeightUtils(gridRef, outerGridElementRef, gridItemsRenderedRef, forceRenderRef);
268
297
  }),
269
298
  _useState2 = _slicedToArray(_useState, 1),
270
299
  rowHeightUtils = _useState2[0]; // Forces a rerender whenever the row heights change, as this can cause the
@@ -30,7 +30,8 @@ import PropTypes from "prop-types";
30
30
  import classNames from 'classnames';
31
31
  import { useEuiTheme } from '../../services';
32
32
  import { euiDescriptionListDescriptionStyles } from './description_list_description.styles';
33
- import { EuiDescriptionListContext } from './description_list_context';
33
+ import { EuiDescriptionListContext } from './description_list_context'; // Export required for correct inference by HOCs
34
+
34
35
  import { jsx as ___EmotionJSX } from "@emotion/react";
35
36
  export var EuiDescriptionListDescription = function EuiDescriptionListDescription(_ref) {
36
37
  var children = _ref.children,
@@ -30,7 +30,8 @@ import PropTypes from "prop-types";
30
30
  import classNames from 'classnames';
31
31
  import { useEuiTheme } from '../../services';
32
32
  import { euiDescriptionListTitleStyles } from './description_list_title.styles';
33
- import { EuiDescriptionListContext } from './description_list_context';
33
+ import { EuiDescriptionListContext } from './description_list_context'; // Export required for correct inference by HOCs
34
+
34
35
  import { jsx as ___EmotionJSX } from "@emotion/react";
35
36
  export var EuiDescriptionListTitle = function EuiDescriptionListTitle(_ref) {
36
37
  var children = _ref.children,
@@ -1,22 +1,34 @@
1
+ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
2
+
1
3
  var _excluded = ["button"];
2
4
 
3
5
  function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
4
6
 
5
- function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
7
+ function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
6
8
 
7
- function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
9
+ function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
8
10
 
9
- function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
11
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
10
12
 
11
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
13
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
12
14
 
13
- function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
15
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
14
16
 
15
- function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
17
+ function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
16
18
 
17
- function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
19
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
18
20
 
19
- function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
21
+ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
22
+
23
+ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
24
+
25
+ function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
26
+
27
+ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
28
+
29
+ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
30
+
31
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
20
32
 
21
33
  /*
22
34
  * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
@@ -25,7 +37,7 @@ function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) r
25
37
  * in compliance with, at your election, the Elastic License 2.0 or the Server
26
38
  * Side Public License, v 1.
27
39
  */
28
- import React, { useState, useEffect } from 'react';
40
+ import React, { Component } from 'react';
29
41
  import PropTypes from "prop-types";
30
42
  import { EuiPopover } from './popover';
31
43
  import { EuiPortal } from '../portal';
@@ -36,46 +48,77 @@ import { jsx as ___EmotionJSX } from "@emotion/react";
36
48
  * then the button element is moved into the popover dom.
37
49
  * On unmount, the button is moved back to its original location.
38
50
  */
39
- export var EuiWrappingPopover = function EuiWrappingPopover(_ref) {
40
- var button = _ref.button,
41
- rest = _objectWithoutProperties(_ref, _excluded);
42
-
43
- var _useState = useState(null),
44
- _useState2 = _slicedToArray(_useState, 2),
45
- anchor = _useState2[0],
46
- setAnchor = _useState2[1];
47
-
48
- var _useState3 = useState(null),
49
- _useState4 = _slicedToArray(_useState3, 2),
50
- portal = _useState4[0],
51
- setPortal = _useState4[1];
52
-
53
- useEffect(function () {
54
- if (anchor) {
55
- // move the button into the popover DOM
56
- anchor.insertAdjacentElement('beforebegin', button);
51
+ export var EuiWrappingPopover = /*#__PURE__*/function (_Component) {
52
+ _inherits(EuiWrappingPopover, _Component);
53
+
54
+ var _super = _createSuper(EuiWrappingPopover);
55
+
56
+ function EuiWrappingPopover() {
57
+ var _this;
58
+
59
+ _classCallCheck(this, EuiWrappingPopover);
60
+
61
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
62
+ args[_key] = arguments[_key];
57
63
  }
58
64
 
59
- return function () {
60
- if (portal) {
61
- // move the button back out of the popover DOM
62
- portal.insertAdjacentElement('beforebegin', button);
65
+ _this = _super.call.apply(_super, [this].concat(args));
66
+
67
+ _defineProperty(_assertThisInitialized(_this), "portal", null);
68
+
69
+ _defineProperty(_assertThisInitialized(_this), "anchor", null);
70
+
71
+ _defineProperty(_assertThisInitialized(_this), "setPortalRef", function (node) {
72
+ _this.portal = node;
73
+ });
74
+
75
+ _defineProperty(_assertThisInitialized(_this), "setAnchorRef", function (node) {
76
+ _this.anchor = node;
77
+ });
78
+
79
+ return _this;
80
+ }
81
+
82
+ _createClass(EuiWrappingPopover, [{
83
+ key: "componentDidMount",
84
+ value: function componentDidMount() {
85
+ if (this.anchor) {
86
+ this.anchor.insertAdjacentElement('beforebegin', this.props.button);
87
+ }
88
+ }
89
+ }, {
90
+ key: "componentWillUnmount",
91
+ value: function componentWillUnmount() {
92
+ if (this.props.button.parentNode) {
93
+ if (this.portal) {
94
+ this.portal.insertAdjacentElement('beforebegin', this.props.button);
95
+ }
63
96
  }
64
- };
65
- }, [anchor, button, portal]);
66
- return ___EmotionJSX(EuiPortal, {
67
- portalRef: setPortal,
68
- insert: {
69
- sibling: button,
70
- position: 'after'
71
97
  }
72
- }, ___EmotionJSX(EuiPopover, _extends({}, rest, {
73
- button: ___EmotionJSX("div", {
74
- ref: setAnchor,
75
- className: "euiWrappingPopover__anchor"
76
- })
77
- })));
78
- };
98
+ }, {
99
+ key: "render",
100
+ value: function render() {
101
+ var _this$props = this.props,
102
+ button = _this$props.button,
103
+ rest = _objectWithoutProperties(_this$props, _excluded);
104
+
105
+ return ___EmotionJSX(EuiPortal, {
106
+ portalRef: this.setPortalRef,
107
+ insert: {
108
+ sibling: this.props.button,
109
+ position: 'after'
110
+ }
111
+ }, ___EmotionJSX(EuiPopover, _extends({}, rest, {
112
+ button: ___EmotionJSX("div", {
113
+ ref: this.setAnchorRef,
114
+ className: "euiWrappingPopover__anchor"
115
+ })
116
+ })));
117
+ }
118
+ }]);
119
+
120
+ return EuiWrappingPopover;
121
+ }(Component);
79
122
  EuiWrappingPopover.propTypes = {
80
123
  button: PropTypes.any.isRequired
81
124
  };
@@ -1,14 +1,26 @@
1
- function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
1
+ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
2
2
 
3
- function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
3
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
4
4
 
5
- function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
5
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
6
6
 
7
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
7
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
8
8
 
9
- function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
9
+ function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
10
10
 
11
- function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
11
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
12
+
13
+ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
14
+
15
+ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
16
+
17
+ function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
18
+
19
+ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
20
+
21
+ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
22
+
23
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
12
24
 
13
25
  /*
14
26
  * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
@@ -22,54 +34,88 @@ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
22
34
  * NOTE: We can't test this component because Enzyme doesn't support rendering
23
35
  * into portals.
24
36
  */
25
- import { useState, useEffect } from 'react';
37
+ import { Component } from 'react';
38
+ import PropTypes from "prop-types";
26
39
  import { createPortal } from 'react-dom';
27
40
  import { keysOf } from '../common';
28
- import { useUpdateEffect } from '../../services';
29
41
  export var insertPositions = {
30
42
  after: 'afterend',
31
43
  before: 'beforebegin'
32
44
  };
33
45
  export var INSERT_POSITIONS = keysOf(insertPositions);
34
- export var EuiPortal = function EuiPortal(_ref) {
35
- var insert = _ref.insert,
36
- portalRef = _ref.portalRef,
37
- children = _ref.children;
46
+ export var EuiPortal = /*#__PURE__*/function (_Component) {
47
+ _inherits(EuiPortal, _Component);
48
+
49
+ var _super = _createSuper(EuiPortal);
50
+
51
+ function EuiPortal(props) {
52
+ var _this;
53
+
54
+ _classCallCheck(this, EuiPortal);
38
55
 
39
- var _useState = useState(null),
40
- _useState2 = _slicedToArray(_useState, 2),
41
- portalNode = _useState2[0],
42
- setPortalNode = _useState2[1]; // pull `sibling` and `position` out of insert in case their wrapping object is recreated every render
56
+ _this = _super.call(this, props);
43
57
 
58
+ _defineProperty(_assertThisInitialized(_this), "portalNode", null);
44
59
 
45
- var _ref2 = insert || {},
46
- sibling = _ref2.sibling,
47
- position = _ref2.position;
60
+ if (typeof window === 'undefined') return _possibleConstructorReturn(_this); // Prevent SSR errors
48
61
 
49
- useEffect(function () {
50
- var portalNode = document.createElement('div');
51
- portalNode.dataset.euiportal = 'true';
52
- setPortalNode(portalNode);
62
+ var insert = _this.props.insert;
63
+ _this.portalNode = document.createElement('div');
64
+ _this.portalNode.dataset.euiportal = 'true';
53
65
 
54
- if (sibling == null || position == null) {
66
+ if (insert == null) {
55
67
  // no insertion defined, append to body
56
- document.body.appendChild(portalNode);
68
+ document.body.appendChild(_this.portalNode);
57
69
  } else {
58
70
  // inserting before or after an element
59
- sibling.insertAdjacentElement(insertPositions[position], portalNode);
71
+ var sibling = insert.sibling,
72
+ position = insert.position;
73
+ sibling.insertAdjacentElement(insertPositions[position], _this.portalNode);
60
74
  }
61
75
 
62
- return function () {
63
- if (portalNode && portalNode.parentNode) {
64
- portalNode.parentNode.removeChild(portalNode);
76
+ return _this;
77
+ }
78
+
79
+ _createClass(EuiPortal, [{
80
+ key: "componentDidMount",
81
+ value: function componentDidMount() {
82
+ this.updatePortalRef(this.portalNode);
83
+ }
84
+ }, {
85
+ key: "componentWillUnmount",
86
+ value: function componentWillUnmount() {
87
+ var _this$portalNode;
88
+
89
+ if ((_this$portalNode = this.portalNode) !== null && _this$portalNode !== void 0 && _this$portalNode.parentNode) {
90
+ this.portalNode.parentNode.removeChild(this.portalNode);
65
91
  }
66
- };
67
- }, [sibling, position]);
68
- useUpdateEffect(function () {
69
- portalRef === null || portalRef === void 0 ? void 0 : portalRef(portalNode);
70
- return function () {
71
- portalRef === null || portalRef === void 0 ? void 0 : portalRef(null);
72
- };
73
- }, [portalNode, portalRef]);
74
- return portalNode == null ? null : /*#__PURE__*/createPortal(children, portalNode);
92
+
93
+ this.updatePortalRef(null);
94
+ }
95
+ }, {
96
+ key: "updatePortalRef",
97
+ value: function updatePortalRef(ref) {
98
+ if (this.props.portalRef) {
99
+ this.props.portalRef(ref);
100
+ }
101
+ }
102
+ }, {
103
+ key: "render",
104
+ value: function render() {
105
+ return this.portalNode ? /*#__PURE__*/createPortal(this.props.children, this.portalNode) : null;
106
+ }
107
+ }]);
108
+
109
+ return EuiPortal;
110
+ }(Component);
111
+ EuiPortal.propTypes = {
112
+ /**
113
+ * ReactNode to render as this component's content
114
+ */
115
+ children: PropTypes.node.isRequired,
116
+ insert: PropTypes.shape({
117
+ sibling: PropTypes.any.isRequired,
118
+ position: PropTypes.oneOf(["before", "after"]).isRequired
119
+ }),
120
+ portalRef: PropTypes.func
75
121
  };
@@ -1,5 +1,3 @@
1
- function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
2
-
3
1
  function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
4
2
 
5
3
  function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
@@ -19,7 +17,7 @@ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
19
17
  * in compliance with, at your election, the Elastic License 2.0 or the Server
20
18
  * Side Public License, v 1.
21
19
  */
22
- import React, { createContext, useContext, useState, useEffect } from 'react';
20
+ import React, { createContext, useState, useEffect } from 'react';
23
21
  import { useEuiTheme } from '../theme';
24
22
  import { throttle } from '../throttle';
25
23
  import { getBreakpoint } from './breakpoint';
@@ -36,7 +34,7 @@ export var CurrentEuiBreakpointProvider = function CurrentEuiBreakpointProvider(
36
34
  var _useEuiTheme = useEuiTheme(),
37
35
  breakpoints = _useEuiTheme.euiTheme.breakpoint;
38
36
 
39
- var _useState = useState((typeof window === "undefined" ? "undefined" : _typeof(window)) !== undefined ? getBreakpoint(window.innerWidth, breakpoints) : undefined),
37
+ var _useState = useState(typeof window !== 'undefined' ? getBreakpoint(window.innerWidth, breakpoints) : undefined),
40
38
  _useState2 = _slicedToArray(_useState, 2),
41
39
  currentBreakpoint = _useState2[0],
42
40
  setCurrentBreakpoint = _useState2[1];
@@ -53,12 +51,4 @@ export var CurrentEuiBreakpointProvider = function CurrentEuiBreakpointProvider(
53
51
  return ___EmotionJSX(CurrentEuiBreakpointContext.Provider, {
54
52
  value: currentBreakpoint
55
53
  }, children);
56
- };
57
- /**
58
- * Hook util / syntactical sugar
59
- */
60
-
61
- export var useCurrentEuiBreakpoint = function useCurrentEuiBreakpoint() {
62
- var currentBreakpoint = useContext(CurrentEuiBreakpointContext);
63
- return currentBreakpoint;
64
54
  };
@@ -0,0 +1,20 @@
1
+ /*
2
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3
+ * or more contributor license agreements. Licensed under the Elastic License
4
+ * 2.0 and the Server Side Public License, v 1; you may not use this file except
5
+ * in compliance with, at your election, the Elastic License 2.0 or the Server
6
+ * Side Public License, v 1.
7
+ */
8
+ import { useContext } from 'react';
9
+ import { CurrentEuiBreakpointContext } from './current_breakpoint';
10
+ /**
11
+ * Hook util / syntactical sugar for useContext()
12
+ *
13
+ * This hook is in its own separate file to make mocking it
14
+ * as a testenv easy for Jest unit tests
15
+ */
16
+
17
+ export var useCurrentEuiBreakpoint = function useCurrentEuiBreakpoint() {
18
+ var currentBreakpoint = useContext(CurrentEuiBreakpointContext);
19
+ return currentBreakpoint;
20
+ };
@@ -6,5 +6,6 @@
6
6
  * Side Public License, v 1.
7
7
  */
8
8
  export * from './breakpoint';
9
- export * from './currentEuiBreakpoint';
9
+ export * from './current_breakpoint';
10
+ export * from './current_breakpoint_hook';
10
11
  export * from './useIsWithinBreakpoints';
@@ -5,7 +5,7 @@
5
5
  * in compliance with, at your election, the Elastic License 2.0 or the Server
6
6
  * Side Public License, v 1.
7
7
  */
8
- import { useCurrentEuiBreakpoint } from './currentEuiBreakpoint';
8
+ import { useCurrentEuiBreakpoint } from './current_breakpoint_hook';
9
9
  /**
10
10
  * Given the current window.innerWidth and an array of breakpoint keys,
11
11
  * this hook stores state and returns true or false if the window.innerWidth