@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
@@ -11,9 +11,9 @@ import _defineProperty from "@babel/runtime/helpers/defineProperty";
11
11
  * in compliance with, at your election, the Elastic License 2.0 or the Server
12
12
  * Side Public License, v 1.
13
13
  */
14
- import { useEffect, useState, useMemo, useCallback, useContext } from 'react';
15
- import { isObject, isNumber } from '../../../services/predicate';
14
+ import { useCallback, useContext, useEffect, useMemo, useState } from 'react';
16
15
  import { useForceRender, useLatest } from '../../../services';
16
+ import { isNumber, isObject } from '../../../services/predicate';
17
17
  import { DataGridSortingContext } from './sorting'; // TODO: Once JS variables are available, use them here instead of hard-coded maps
18
18
 
19
19
  export var cellPaddingsMap = {
@@ -24,12 +24,14 @@ export var cellPaddingsMap = {
24
24
  export var AUTO_HEIGHT = 'auto';
25
25
  export var DEFAULT_ROW_HEIGHT = 34;
26
26
  export var RowHeightUtils = /*#__PURE__*/function () {
27
- function RowHeightUtils(gridRef, rerenderGridBodyRef) {
27
+ function RowHeightUtils(gridRef, outerGridElementRef, gridItemsRenderedRef, rerenderGridBodyRef) {
28
28
  var _this = this;
29
29
 
30
30
  _classCallCheck(this, RowHeightUtils);
31
31
 
32
32
  this.gridRef = gridRef;
33
+ this.outerGridElementRef = outerGridElementRef;
34
+ this.gridItemsRenderedRef = gridItemsRenderedRef;
33
35
  this.rerenderGridBodyRef = rerenderGridBodyRef;
34
36
 
35
37
  _defineProperty(this, "styles", {
@@ -225,6 +227,31 @@ export var RowHeightUtils = /*#__PURE__*/function () {
225
227
  (_this$gridRef$current = this.gridRef.current) === null || _this$gridRef$current === void 0 ? void 0 : _this$gridRef$current.resetAfterRowIndex(this.lastUpdatedRow);
226
228
  this.lastUpdatedRow = Infinity;
227
229
  }
230
+ }, {
231
+ key: "compensateForLayoutShift",
232
+ value: function compensateForLayoutShift(rowIndex, verticalLayoutShift, anchorRow) {
233
+ var grid = this.gridRef.current;
234
+ var outerGridElement = this.outerGridElementRef.current;
235
+ var renderedItems = this.gridItemsRenderedRef.current;
236
+
237
+ if (grid == null || outerGridElement == null || renderedItems == null || anchorRow == null || !Number.isFinite(verticalLayoutShift)) {
238
+ return;
239
+ } // skip if the start row is the anchor row but it hasn't shifted
240
+
241
+
242
+ if (anchorRow === 'start' && renderedItems.visibleRowStartIndex !== rowIndex) {
243
+ return;
244
+ } // skip if the center row is the anchor row but it hasn't shifted
245
+
246
+
247
+ if (anchorRow === 'center' && Math.floor((renderedItems.visibleRowStopIndex - renderedItems.visibleRowStartIndex) / 2) !== rowIndex) {
248
+ return;
249
+ }
250
+
251
+ grid.scrollTo({
252
+ scrollTop: outerGridElement.scrollTop + verticalLayoutShift
253
+ });
254
+ }
228
255
  }]);
229
256
 
230
257
  return RowHeightUtils;
@@ -236,13 +263,15 @@ export var RowHeightUtils = /*#__PURE__*/function () {
236
263
 
237
264
  export var useRowHeightUtils = function useRowHeightUtils(_ref2) {
238
265
  var gridRef = _ref2.gridRef,
266
+ outerGridElementRef = _ref2.outerGridElementRef,
267
+ gridItemsRenderedRef = _ref2.gridItemsRenderedRef,
239
268
  gridStyles = _ref2.gridStyles,
240
269
  columns = _ref2.columns,
241
270
  rowHeightsOptions = _ref2.rowHeightsOptions;
242
271
  var forceRenderRef = useLatest(useForceRender());
243
272
 
244
273
  var _useState = useState(function () {
245
- return new RowHeightUtils(gridRef, forceRenderRef);
274
+ return new RowHeightUtils(gridRef, outerGridElementRef, gridItemsRenderedRef, forceRenderRef);
246
275
  }),
247
276
  _useState2 = _slicedToArray(_useState, 1),
248
277
  rowHeightUtils = _useState2[0]; // Forces a rerender whenever the row heights change, as this can cause the
@@ -14,7 +14,8 @@ import React, { useContext } from 'react';
14
14
  import classNames from 'classnames';
15
15
  import { useEuiTheme } from '../../services';
16
16
  import { euiDescriptionListDescriptionStyles } from './description_list_description.styles';
17
- import { EuiDescriptionListContext } from './description_list_context';
17
+ import { EuiDescriptionListContext } from './description_list_context'; // Export required for correct inference by HOCs
18
+
18
19
  import { jsx as ___EmotionJSX } from "@emotion/react";
19
20
  export var EuiDescriptionListDescription = function EuiDescriptionListDescription(_ref) {
20
21
  var children = _ref.children,
@@ -14,7 +14,8 @@ import React, { useContext } from 'react';
14
14
  import classNames from 'classnames';
15
15
  import { useEuiTheme } from '../../services';
16
16
  import { euiDescriptionListTitleStyles } from './description_list_title.styles';
17
- import { EuiDescriptionListContext } from './description_list_context';
17
+ import { EuiDescriptionListContext } from './description_list_context'; // Export required for correct inference by HOCs
18
+
18
19
  import { jsx as ___EmotionJSX } from "@emotion/react";
19
20
  export var EuiDescriptionListTitle = function EuiDescriptionListTitle(_ref) {
20
21
  var children = _ref.children,
@@ -1,8 +1,18 @@
1
1
  import _extends from "@babel/runtime/helpers/extends";
2
- import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
3
2
  import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
3
+ import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
4
+ import _createClass from "@babel/runtime/helpers/createClass";
5
+ import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized";
6
+ import _inherits from "@babel/runtime/helpers/inherits";
7
+ import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
8
+ import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
9
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
4
10
  var _excluded = ["button"];
5
11
 
12
+ 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); }; }
13
+
14
+ 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; } }
15
+
6
16
  /*
7
17
  * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
8
18
  * or more contributor license agreements. Licensed under the Elastic License
@@ -10,7 +20,7 @@ var _excluded = ["button"];
10
20
  * in compliance with, at your election, the Elastic License 2.0 or the Server
11
21
  * Side Public License, v 1.
12
22
  */
13
- import React, { useState, useEffect } from 'react';
23
+ import React, { Component } from 'react';
14
24
  import { EuiPopover } from './popover';
15
25
  import { EuiPortal } from '../portal';
16
26
  import { jsx as ___EmotionJSX } from "@emotion/react";
@@ -20,43 +30,74 @@ import { jsx as ___EmotionJSX } from "@emotion/react";
20
30
  * then the button element is moved into the popover dom.
21
31
  * On unmount, the button is moved back to its original location.
22
32
  */
23
- export var EuiWrappingPopover = function EuiWrappingPopover(_ref) {
24
- var button = _ref.button,
25
- rest = _objectWithoutProperties(_ref, _excluded);
26
-
27
- var _useState = useState(null),
28
- _useState2 = _slicedToArray(_useState, 2),
29
- anchor = _useState2[0],
30
- setAnchor = _useState2[1];
31
-
32
- var _useState3 = useState(null),
33
- _useState4 = _slicedToArray(_useState3, 2),
34
- portal = _useState4[0],
35
- setPortal = _useState4[1];
36
-
37
- useEffect(function () {
38
- if (anchor) {
39
- // move the button into the popover DOM
40
- anchor.insertAdjacentElement('beforebegin', button);
33
+ export var EuiWrappingPopover = /*#__PURE__*/function (_Component) {
34
+ _inherits(EuiWrappingPopover, _Component);
35
+
36
+ var _super = _createSuper(EuiWrappingPopover);
37
+
38
+ function EuiWrappingPopover() {
39
+ var _this;
40
+
41
+ _classCallCheck(this, EuiWrappingPopover);
42
+
43
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
44
+ args[_key] = arguments[_key];
41
45
  }
42
46
 
43
- return function () {
44
- if (portal) {
45
- // move the button back out of the popover DOM
46
- portal.insertAdjacentElement('beforebegin', button);
47
+ _this = _super.call.apply(_super, [this].concat(args));
48
+
49
+ _defineProperty(_assertThisInitialized(_this), "portal", null);
50
+
51
+ _defineProperty(_assertThisInitialized(_this), "anchor", null);
52
+
53
+ _defineProperty(_assertThisInitialized(_this), "setPortalRef", function (node) {
54
+ _this.portal = node;
55
+ });
56
+
57
+ _defineProperty(_assertThisInitialized(_this), "setAnchorRef", function (node) {
58
+ _this.anchor = node;
59
+ });
60
+
61
+ return _this;
62
+ }
63
+
64
+ _createClass(EuiWrappingPopover, [{
65
+ key: "componentDidMount",
66
+ value: function componentDidMount() {
67
+ if (this.anchor) {
68
+ this.anchor.insertAdjacentElement('beforebegin', this.props.button);
69
+ }
70
+ }
71
+ }, {
72
+ key: "componentWillUnmount",
73
+ value: function componentWillUnmount() {
74
+ if (this.props.button.parentNode) {
75
+ if (this.portal) {
76
+ this.portal.insertAdjacentElement('beforebegin', this.props.button);
77
+ }
47
78
  }
48
- };
49
- }, [anchor, button, portal]);
50
- return ___EmotionJSX(EuiPortal, {
51
- portalRef: setPortal,
52
- insert: {
53
- sibling: button,
54
- position: 'after'
55
79
  }
56
- }, ___EmotionJSX(EuiPopover, _extends({}, rest, {
57
- button: ___EmotionJSX("div", {
58
- ref: setAnchor,
59
- className: "euiWrappingPopover__anchor"
60
- })
61
- })));
62
- };
80
+ }, {
81
+ key: "render",
82
+ value: function render() {
83
+ var _this$props = this.props,
84
+ button = _this$props.button,
85
+ rest = _objectWithoutProperties(_this$props, _excluded);
86
+
87
+ return ___EmotionJSX(EuiPortal, {
88
+ portalRef: this.setPortalRef,
89
+ insert: {
90
+ sibling: this.props.button,
91
+ position: 'after'
92
+ }
93
+ }, ___EmotionJSX(EuiPopover, _extends({}, rest, {
94
+ button: ___EmotionJSX("div", {
95
+ ref: this.setAnchorRef,
96
+ className: "euiWrappingPopover__anchor"
97
+ })
98
+ })));
99
+ }
100
+ }]);
101
+
102
+ return EuiWrappingPopover;
103
+ }(Component);
@@ -1,4 +1,14 @@
1
- import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
1
+ import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
2
+ import _createClass from "@babel/runtime/helpers/createClass";
3
+ import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized";
4
+ import _inherits from "@babel/runtime/helpers/inherits";
5
+ import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
6
+ import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
7
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
8
+
9
+ 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); }; }
10
+
11
+ 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; } }
2
12
 
3
13
  /*
4
14
  * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
@@ -12,54 +22,76 @@ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
12
22
  * NOTE: We can't test this component because Enzyme doesn't support rendering
13
23
  * into portals.
14
24
  */
15
- import { useState, useEffect } from 'react';
25
+ import { Component } from 'react';
16
26
  import { createPortal } from 'react-dom';
17
27
  import { keysOf } from '../common';
18
- import { useUpdateEffect } from '../../services';
19
28
  export var insertPositions = {
20
29
  after: 'afterend',
21
30
  before: 'beforebegin'
22
31
  };
23
32
  export var INSERT_POSITIONS = keysOf(insertPositions);
24
- export var EuiPortal = function EuiPortal(_ref) {
25
- var insert = _ref.insert,
26
- portalRef = _ref.portalRef,
27
- children = _ref.children;
33
+ export var EuiPortal = /*#__PURE__*/function (_Component) {
34
+ _inherits(EuiPortal, _Component);
35
+
36
+ var _super = _createSuper(EuiPortal);
37
+
38
+ function EuiPortal(props) {
39
+ var _this;
28
40
 
29
- var _useState = useState(null),
30
- _useState2 = _slicedToArray(_useState, 2),
31
- portalNode = _useState2[0],
32
- setPortalNode = _useState2[1]; // pull `sibling` and `position` out of insert in case their wrapping object is recreated every render
41
+ _classCallCheck(this, EuiPortal);
33
42
 
43
+ _this = _super.call(this, props);
34
44
 
35
- var _ref2 = insert || {},
36
- sibling = _ref2.sibling,
37
- position = _ref2.position;
45
+ _defineProperty(_assertThisInitialized(_this), "portalNode", null);
38
46
 
39
- useEffect(function () {
40
- var portalNode = document.createElement('div');
41
- portalNode.dataset.euiportal = 'true';
42
- setPortalNode(portalNode);
47
+ if (typeof window === 'undefined') return _possibleConstructorReturn(_this); // Prevent SSR errors
43
48
 
44
- if (sibling == null || position == null) {
49
+ var insert = _this.props.insert;
50
+ _this.portalNode = document.createElement('div');
51
+ _this.portalNode.dataset.euiportal = 'true';
52
+
53
+ if (insert == null) {
45
54
  // no insertion defined, append to body
46
- document.body.appendChild(portalNode);
55
+ document.body.appendChild(_this.portalNode);
47
56
  } else {
48
57
  // inserting before or after an element
49
- sibling.insertAdjacentElement(insertPositions[position], portalNode);
58
+ var sibling = insert.sibling,
59
+ position = insert.position;
60
+ sibling.insertAdjacentElement(insertPositions[position], _this.portalNode);
61
+ }
62
+
63
+ return _this;
64
+ }
65
+
66
+ _createClass(EuiPortal, [{
67
+ key: "componentDidMount",
68
+ value: function componentDidMount() {
69
+ this.updatePortalRef(this.portalNode);
50
70
  }
71
+ }, {
72
+ key: "componentWillUnmount",
73
+ value: function componentWillUnmount() {
74
+ var _this$portalNode;
75
+
76
+ if ((_this$portalNode = this.portalNode) !== null && _this$portalNode !== void 0 && _this$portalNode.parentNode) {
77
+ this.portalNode.parentNode.removeChild(this.portalNode);
78
+ }
51
79
 
52
- return function () {
53
- if (portalNode && portalNode.parentNode) {
54
- portalNode.parentNode.removeChild(portalNode);
80
+ this.updatePortalRef(null);
81
+ }
82
+ }, {
83
+ key: "updatePortalRef",
84
+ value: function updatePortalRef(ref) {
85
+ if (this.props.portalRef) {
86
+ this.props.portalRef(ref);
55
87
  }
56
- };
57
- }, [sibling, position]);
58
- useUpdateEffect(function () {
59
- portalRef === null || portalRef === void 0 ? void 0 : portalRef(portalNode);
60
- return function () {
61
- portalRef === null || portalRef === void 0 ? void 0 : portalRef(null);
62
- };
63
- }, [portalNode, portalRef]);
64
- return portalNode == null ? null : /*#__PURE__*/createPortal(children, portalNode);
65
- };
88
+ }
89
+ }, {
90
+ key: "render",
91
+ value: function render() {
92
+ return this.portalNode ? /*#__PURE__*/createPortal(this.props.children, this.portalNode) : null;
93
+ }
94
+ }]);
95
+
96
+ return EuiPortal;
97
+ }(Component);
@@ -1,4 +1,3 @@
1
- import _typeof from "@babel/runtime/helpers/typeof";
2
1
  import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
3
2
 
4
3
  /*
@@ -8,7 +7,7 @@ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
8
7
  * in compliance with, at your election, the Elastic License 2.0 or the Server
9
8
  * Side Public License, v 1.
10
9
  */
11
- import React, { createContext, useContext, useState, useEffect } from 'react';
10
+ import React, { createContext, useState, useEffect } from 'react';
12
11
  import { useEuiTheme } from '../theme';
13
12
  import { throttle } from '../throttle';
14
13
  import { getBreakpoint } from './breakpoint';
@@ -25,7 +24,7 @@ export var CurrentEuiBreakpointProvider = function CurrentEuiBreakpointProvider(
25
24
  var _useEuiTheme = useEuiTheme(),
26
25
  breakpoints = _useEuiTheme.euiTheme.breakpoint;
27
26
 
28
- var _useState = useState((typeof window === "undefined" ? "undefined" : _typeof(window)) !== undefined ? getBreakpoint(window.innerWidth, breakpoints) : undefined),
27
+ var _useState = useState(typeof window !== 'undefined' ? getBreakpoint(window.innerWidth, breakpoints) : undefined),
29
28
  _useState2 = _slicedToArray(_useState, 2),
30
29
  currentBreakpoint = _useState2[0],
31
30
  setCurrentBreakpoint = _useState2[1];
@@ -42,12 +41,4 @@ export var CurrentEuiBreakpointProvider = function CurrentEuiBreakpointProvider(
42
41
  return ___EmotionJSX(CurrentEuiBreakpointContext.Provider, {
43
42
  value: currentBreakpoint
44
43
  }, children);
45
- };
46
- /**
47
- * Hook util / syntactical sugar
48
- */
49
-
50
- export var useCurrentEuiBreakpoint = function useCurrentEuiBreakpoint() {
51
- var currentBreakpoint = useContext(CurrentEuiBreakpointContext);
52
- return currentBreakpoint;
53
44
  };
@@ -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
@@ -8,9 +8,10 @@ import _regeneratorRuntime from "@babel/runtime/regenerator";
8
8
  * in compliance with, at your election, the Elastic License 2.0 or the Server
9
9
  * Side Public License, v 1.
10
10
  */
11
+ import '@testing-library/jest-dom';
11
12
  import { waitFor } from '@testing-library/react';
12
13
  /**
13
- * Ensure the EuiPopover being tested is open/closed before contiuning
14
+ * Ensure the EuiPopover being tested is open/closed before continuing
14
15
  * Note: Because EuiPopover is portalled, we want to query `document`
15
16
  * instead of the `container` returned by RTL's render()
16
17
  */
@@ -68,4 +69,62 @@ export var waitForEuiPopoverClose = /*#__PURE__*/function () {
68
69
  return function waitForEuiPopoverClose() {
69
70
  return _ref2.apply(this, arguments);
70
71
  };
72
+ }();
73
+ /**
74
+ * Ensure the EuiToolTip being tested is open and visible before continuing
75
+ */
76
+
77
+ export var waitForEuiToolTipVisible = /*#__PURE__*/function () {
78
+ var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3() {
79
+ return _regeneratorRuntime.wrap(function _callee3$(_context3) {
80
+ while (1) {
81
+ switch (_context3.prev = _context3.next) {
82
+ case 0:
83
+ _context3.next = 2;
84
+ return waitFor(function () {
85
+ var tooltip = document.querySelector('.euiToolTipPopover');
86
+ expect(tooltip).toBeVisible();
87
+ });
88
+
89
+ case 2:
90
+ return _context3.abrupt("return", _context3.sent);
91
+
92
+ case 3:
93
+ case "end":
94
+ return _context3.stop();
95
+ }
96
+ }
97
+ }, _callee3);
98
+ }));
99
+
100
+ return function waitForEuiToolTipVisible() {
101
+ return _ref3.apply(this, arguments);
102
+ };
103
+ }();
104
+ export var waitForEuiToolTipHidden = /*#__PURE__*/function () {
105
+ var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4() {
106
+ return _regeneratorRuntime.wrap(function _callee4$(_context4) {
107
+ while (1) {
108
+ switch (_context4.prev = _context4.next) {
109
+ case 0:
110
+ _context4.next = 2;
111
+ return waitFor(function () {
112
+ var tooltip = document.querySelector('.euiToolTipPopover');
113
+ expect(tooltip).toBeNull();
114
+ });
115
+
116
+ case 2:
117
+ return _context4.abrupt("return", _context4.sent);
118
+
119
+ case 3:
120
+ case "end":
121
+ return _context4.stop();
122
+ }
123
+ }
124
+ }, _callee4);
125
+ }));
126
+
127
+ return function waitForEuiToolTipHidden() {
128
+ return _ref4.apply(this, arguments);
129
+ };
71
130
  }();
@@ -354,6 +354,8 @@ var EuiDataGridBody = function EuiDataGridBody(props) {
354
354
 
355
355
  var rowHeightUtils = (0, _row_heights.useRowHeightUtils)({
356
356
  gridRef: gridRef,
357
+ outerGridElementRef: outerGridRef,
358
+ gridItemsRenderedRef: gridItemsRendered,
357
359
  gridStyles: gridStyles,
358
360
  columns: columns,
359
361
  rowHeightsOptions: rowHeightsOptions
@@ -413,7 +413,7 @@ var EuiDataGridCell = /*#__PURE__*/function (_Component) {
413
413
  }, {
414
414
  key: "componentDidUpdate",
415
415
  value: function componentDidUpdate(prevProps) {
416
- var _this$props$rowHeight, _prevProps$rowHeights;
416
+ var _this$props$rowHeight, _prevProps$rowHeights, _this$props$rowHeight2, _this$props$style, _prevProps$style;
417
417
 
418
418
  this.recalculateAutoHeight();
419
419
 
@@ -421,6 +421,18 @@ var EuiDataGridCell = /*#__PURE__*/function (_Component) {
421
421
  this.recalculateLineHeight();
422
422
  }
423
423
 
424
+ if ((_this$props$rowHeight2 = this.props.rowHeightsOptions) !== null && _this$props$rowHeight2 !== void 0 && _this$props$rowHeight2.scrollAnchorRow && this.props.colIndex === 0 && // once per row
425
+ this.props.columnId === prevProps.columnId && // if this is still the same column
426
+ this.props.rowIndex === prevProps.rowIndex && // if this is still the same row
427
+ ((_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
428
+ ) {
429
+ var _prevProps$style2, _this$props$style2, _this$props$rowHeight3, _this$props$rowHeight4;
430
+
431
+ var previousTop = parseFloat((_prevProps$style2 = prevProps.style) === null || _prevProps$style2 === void 0 ? void 0 : _prevProps$style2.top);
432
+ var currentTop = parseFloat((_this$props$style2 = this.props.style) === null || _this$props$style2 === void 0 ? void 0 : _this$props$style2.top);
433
+ (_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);
434
+ }
435
+
424
436
  if (this.props.popoverContext.popoverIsOpen !== prevProps.popoverContext.popoverIsOpen || this.props.popoverContext.cellLocation !== prevProps.popoverContext.cellLocation || this.props.renderCellPopover !== prevProps.renderCellPopover) {
425
437
  this.handleCellPopover();
426
438
  }
@@ -19,10 +19,10 @@ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/de
19
19
 
20
20
  var _react = require("react");
21
21
 
22
- var _predicate = require("../../../services/predicate");
23
-
24
22
  var _services = require("../../../services");
25
23
 
24
+ var _predicate = require("../../../services/predicate");
25
+
26
26
  var _sorting = require("./sorting");
27
27
 
28
28
  /*
@@ -45,11 +45,13 @@ var DEFAULT_ROW_HEIGHT = 34;
45
45
  exports.DEFAULT_ROW_HEIGHT = DEFAULT_ROW_HEIGHT;
46
46
 
47
47
  var RowHeightUtils = /*#__PURE__*/function () {
48
- function RowHeightUtils(gridRef, rerenderGridBodyRef) {
48
+ function RowHeightUtils(gridRef, outerGridElementRef, gridItemsRenderedRef, rerenderGridBodyRef) {
49
49
  var _this = this;
50
50
 
51
51
  (0, _classCallCheck2.default)(this, RowHeightUtils);
52
52
  this.gridRef = gridRef;
53
+ this.outerGridElementRef = outerGridElementRef;
54
+ this.gridItemsRenderedRef = gridItemsRenderedRef;
53
55
  this.rerenderGridBodyRef = rerenderGridBodyRef;
54
56
  (0, _defineProperty2.default)(this, "styles", {
55
57
  paddingTop: 0,
@@ -240,6 +242,31 @@ var RowHeightUtils = /*#__PURE__*/function () {
240
242
  (_this$gridRef$current = this.gridRef.current) === null || _this$gridRef$current === void 0 ? void 0 : _this$gridRef$current.resetAfterRowIndex(this.lastUpdatedRow);
241
243
  this.lastUpdatedRow = Infinity;
242
244
  }
245
+ }, {
246
+ key: "compensateForLayoutShift",
247
+ value: function compensateForLayoutShift(rowIndex, verticalLayoutShift, anchorRow) {
248
+ var grid = this.gridRef.current;
249
+ var outerGridElement = this.outerGridElementRef.current;
250
+ var renderedItems = this.gridItemsRenderedRef.current;
251
+
252
+ if (grid == null || outerGridElement == null || renderedItems == null || anchorRow == null || !Number.isFinite(verticalLayoutShift)) {
253
+ return;
254
+ } // skip if the start row is the anchor row but it hasn't shifted
255
+
256
+
257
+ if (anchorRow === 'start' && renderedItems.visibleRowStartIndex !== rowIndex) {
258
+ return;
259
+ } // skip if the center row is the anchor row but it hasn't shifted
260
+
261
+
262
+ if (anchorRow === 'center' && Math.floor((renderedItems.visibleRowStopIndex - renderedItems.visibleRowStartIndex) / 2) !== rowIndex) {
263
+ return;
264
+ }
265
+
266
+ grid.scrollTo({
267
+ scrollTop: outerGridElement.scrollTop + verticalLayoutShift
268
+ });
269
+ }
243
270
  }]);
244
271
  return RowHeightUtils;
245
272
  }();
@@ -253,13 +280,15 @@ exports.RowHeightUtils = RowHeightUtils;
253
280
 
254
281
  var useRowHeightUtils = function useRowHeightUtils(_ref2) {
255
282
  var gridRef = _ref2.gridRef,
283
+ outerGridElementRef = _ref2.outerGridElementRef,
284
+ gridItemsRenderedRef = _ref2.gridItemsRenderedRef,
256
285
  gridStyles = _ref2.gridStyles,
257
286
  columns = _ref2.columns,
258
287
  rowHeightsOptions = _ref2.rowHeightsOptions;
259
288
  var forceRenderRef = (0, _services.useLatest)((0, _services.useForceRender)());
260
289
 
261
290
  var _useState = (0, _react.useState)(function () {
262
- return new RowHeightUtils(gridRef, forceRenderRef);
291
+ return new RowHeightUtils(gridRef, outerGridElementRef, gridItemsRenderedRef, forceRenderRef);
263
292
  }),
264
293
  _useState2 = (0, _slicedToArray2.default)(_useState, 1),
265
294
  rowHeightUtils = _useState2[0]; // Forces a rerender whenever the row heights change, as this can cause the