@elastic/eui 62.1.0 → 62.2.0
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/dist/eui_charts_theme.js +330 -330
- package/dist/eui_charts_theme.js.map +1 -1
- package/es/components/datagrid/body/data_grid_body.js +11 -1
- package/es/components/datagrid/body/data_grid_cell.js +31 -3
- package/es/components/datagrid/data_grid.js +9 -1
- package/es/components/datagrid/utils/row_heights.js +33 -4
- package/es/components/popover/wrapping_popover.js +88 -45
- package/es/components/portal/portal.js +84 -38
- package/es/test/rtl/component_helpers.js +60 -1
- package/eui.d.ts +43 -8
- package/lib/components/datagrid/body/data_grid_body.js +11 -1
- package/lib/components/datagrid/body/data_grid_cell.js +31 -3
- package/lib/components/datagrid/data_grid.js +9 -1
- package/lib/components/datagrid/utils/row_heights.js +33 -4
- package/lib/components/popover/wrapping_popover.js +85 -44
- package/lib/components/portal/portal.js +87 -39
- package/lib/test/rtl/component_helpers.js +69 -3
- package/optimize/es/components/datagrid/body/data_grid_body.js +2 -0
- package/optimize/es/components/datagrid/body/data_grid_cell.js +13 -1
- package/optimize/es/components/datagrid/utils/row_heights.js +33 -4
- package/optimize/es/components/popover/wrapping_popover.js +79 -38
- package/optimize/es/components/portal/portal.js +66 -34
- package/optimize/es/test/rtl/component_helpers.js +60 -1
- package/optimize/lib/components/datagrid/body/data_grid_body.js +2 -0
- package/optimize/lib/components/datagrid/body/data_grid_cell.js +13 -1
- package/optimize/lib/components/datagrid/utils/row_heights.js +33 -4
- package/optimize/lib/components/popover/wrapping_popover.js +78 -38
- package/optimize/lib/components/portal/portal.js +65 -44
- package/optimize/lib/test/rtl/component_helpers.js +69 -3
- package/package.json +2 -2
- package/test-env/components/datagrid/body/data_grid_body.js +11 -1
- package/test-env/components/datagrid/body/data_grid_cell.js +31 -3
- package/test-env/components/datagrid/data_grid.js +9 -1
- package/test-env/components/datagrid/utils/row_heights.js +33 -4
- package/test-env/components/observer/resize_observer/resize_observer.js +43 -126
- package/test-env/components/popover/wrapping_popover.js +78 -38
- package/test-env/components/portal/portal.js +79 -45
- package/test-env/test/rtl/component_helpers.js +69 -3
|
@@ -3,7 +3,9 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.waitForEuiPopoverOpen = exports.waitForEuiPopoverClose = void 0;
|
|
6
|
+
exports.waitForEuiToolTipVisible = exports.waitForEuiToolTipHidden = exports.waitForEuiPopoverOpen = exports.waitForEuiPopoverClose = void 0;
|
|
7
|
+
|
|
8
|
+
require("@testing-library/jest-dom");
|
|
7
9
|
|
|
8
10
|
var _react = require("@testing-library/react");
|
|
9
11
|
|
|
@@ -12,7 +14,7 @@ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try
|
|
|
12
14
|
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
13
15
|
|
|
14
16
|
/**
|
|
15
|
-
* Ensure the EuiPopover being tested is open/closed before
|
|
17
|
+
* Ensure the EuiPopover being tested is open/closed before continuing
|
|
16
18
|
* Note: Because EuiPopover is portalled, we want to query `document`
|
|
17
19
|
* instead of the `container` returned by RTL's render()
|
|
18
20
|
*/
|
|
@@ -73,5 +75,69 @@ var waitForEuiPopoverClose = /*#__PURE__*/function () {
|
|
|
73
75
|
return _ref2.apply(this, arguments);
|
|
74
76
|
};
|
|
75
77
|
}();
|
|
78
|
+
/**
|
|
79
|
+
* Ensure the EuiToolTip being tested is open and visible before continuing
|
|
80
|
+
*/
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
exports.waitForEuiPopoverClose = waitForEuiPopoverClose;
|
|
84
|
+
|
|
85
|
+
var waitForEuiToolTipVisible = /*#__PURE__*/function () {
|
|
86
|
+
var _ref3 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee3() {
|
|
87
|
+
return regeneratorRuntime.wrap(function _callee3$(_context3) {
|
|
88
|
+
while (1) {
|
|
89
|
+
switch (_context3.prev = _context3.next) {
|
|
90
|
+
case 0:
|
|
91
|
+
_context3.next = 2;
|
|
92
|
+
return (0, _react.waitFor)(function () {
|
|
93
|
+
var tooltip = document.querySelector('.euiToolTipPopover');
|
|
94
|
+
expect(tooltip).toBeVisible();
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
case 2:
|
|
98
|
+
return _context3.abrupt("return", _context3.sent);
|
|
99
|
+
|
|
100
|
+
case 3:
|
|
101
|
+
case "end":
|
|
102
|
+
return _context3.stop();
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}, _callee3);
|
|
106
|
+
}));
|
|
107
|
+
|
|
108
|
+
return function waitForEuiToolTipVisible() {
|
|
109
|
+
return _ref3.apply(this, arguments);
|
|
110
|
+
};
|
|
111
|
+
}();
|
|
112
|
+
|
|
113
|
+
exports.waitForEuiToolTipVisible = waitForEuiToolTipVisible;
|
|
114
|
+
|
|
115
|
+
var waitForEuiToolTipHidden = /*#__PURE__*/function () {
|
|
116
|
+
var _ref4 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee4() {
|
|
117
|
+
return regeneratorRuntime.wrap(function _callee4$(_context4) {
|
|
118
|
+
while (1) {
|
|
119
|
+
switch (_context4.prev = _context4.next) {
|
|
120
|
+
case 0:
|
|
121
|
+
_context4.next = 2;
|
|
122
|
+
return (0, _react.waitFor)(function () {
|
|
123
|
+
var tooltip = document.querySelector('.euiToolTipPopover');
|
|
124
|
+
expect(tooltip).toBeNull();
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
case 2:
|
|
128
|
+
return _context4.abrupt("return", _context4.sent);
|
|
129
|
+
|
|
130
|
+
case 3:
|
|
131
|
+
case "end":
|
|
132
|
+
return _context4.stop();
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}, _callee4);
|
|
136
|
+
}));
|
|
137
|
+
|
|
138
|
+
return function waitForEuiToolTipHidden() {
|
|
139
|
+
return _ref4.apply(this, arguments);
|
|
140
|
+
};
|
|
141
|
+
}();
|
|
76
142
|
|
|
77
|
-
exports.
|
|
143
|
+
exports.waitForEuiToolTipHidden = waitForEuiToolTipHidden;
|
|
@@ -320,6 +320,8 @@ export var EuiDataGridBody = function EuiDataGridBody(props) {
|
|
|
320
320
|
|
|
321
321
|
var rowHeightUtils = useRowHeightUtils({
|
|
322
322
|
gridRef: gridRef,
|
|
323
|
+
outerGridElementRef: outerGridRef,
|
|
324
|
+
gridItemsRenderedRef: gridItemsRendered,
|
|
323
325
|
gridStyles: gridStyles,
|
|
324
326
|
columns: columns,
|
|
325
327
|
rowHeightsOptions: rowHeightsOptions
|
|
@@ -408,7 +408,7 @@ export var EuiDataGridCell = /*#__PURE__*/function (_Component) {
|
|
|
408
408
|
}, {
|
|
409
409
|
key: "componentDidUpdate",
|
|
410
410
|
value: function componentDidUpdate(prevProps) {
|
|
411
|
-
var _this$props$rowHeight, _prevProps$rowHeights;
|
|
411
|
+
var _this$props$rowHeight, _prevProps$rowHeights, _this$props$rowHeight2, _this$props$style, _prevProps$style;
|
|
412
412
|
|
|
413
413
|
this.recalculateAutoHeight();
|
|
414
414
|
|
|
@@ -416,6 +416,18 @@ export var EuiDataGridCell = /*#__PURE__*/function (_Component) {
|
|
|
416
416
|
this.recalculateLineHeight();
|
|
417
417
|
}
|
|
418
418
|
|
|
419
|
+
if ((_this$props$rowHeight2 = this.props.rowHeightsOptions) !== null && _this$props$rowHeight2 !== void 0 && _this$props$rowHeight2.scrollAnchorRow && this.props.colIndex === 0 && // once per row
|
|
420
|
+
this.props.columnId === prevProps.columnId && // if this is still the same column
|
|
421
|
+
this.props.rowIndex === prevProps.rowIndex && // if this is still the same row
|
|
422
|
+
((_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
|
|
423
|
+
) {
|
|
424
|
+
var _prevProps$style2, _this$props$style2, _this$props$rowHeight3, _this$props$rowHeight4;
|
|
425
|
+
|
|
426
|
+
var previousTop = parseFloat((_prevProps$style2 = prevProps.style) === null || _prevProps$style2 === void 0 ? void 0 : _prevProps$style2.top);
|
|
427
|
+
var currentTop = parseFloat((_this$props$style2 = this.props.style) === null || _this$props$style2 === void 0 ? void 0 : _this$props$style2.top);
|
|
428
|
+
(_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);
|
|
429
|
+
}
|
|
430
|
+
|
|
419
431
|
if (this.props.popoverContext.popoverIsOpen !== prevProps.popoverContext.popoverIsOpen || this.props.popoverContext.cellLocation !== prevProps.popoverContext.cellLocation || this.props.renderCellPopover !== prevProps.renderCellPopover) {
|
|
420
432
|
this.handleCellPopover();
|
|
421
433
|
}
|
|
@@ -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 {
|
|
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
|
|
@@ -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, {
|
|
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
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
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
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
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
|
-
},
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
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
|
|
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 {
|
|
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
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
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
|
-
|
|
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
|
-
|
|
36
|
-
sibling = _ref2.sibling,
|
|
37
|
-
position = _ref2.position;
|
|
45
|
+
_defineProperty(_assertThisInitialized(_this), "portalNode", null);
|
|
38
46
|
|
|
39
|
-
|
|
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
|
-
|
|
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.
|
|
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
|
-
|
|
53
|
-
|
|
54
|
-
|
|
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
|
-
},
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
return
|
|
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);
|
|
@@ -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
|
|
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
|