@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.
Files changed (38) 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/popover/wrapping_popover.js +88 -45
  8. package/es/components/portal/portal.js +84 -38
  9. package/es/test/rtl/component_helpers.js +60 -1
  10. package/eui.d.ts +43 -8
  11. package/lib/components/datagrid/body/data_grid_body.js +11 -1
  12. package/lib/components/datagrid/body/data_grid_cell.js +31 -3
  13. package/lib/components/datagrid/data_grid.js +9 -1
  14. package/lib/components/datagrid/utils/row_heights.js +33 -4
  15. package/lib/components/popover/wrapping_popover.js +85 -44
  16. package/lib/components/portal/portal.js +87 -39
  17. package/lib/test/rtl/component_helpers.js +69 -3
  18. package/optimize/es/components/datagrid/body/data_grid_body.js +2 -0
  19. package/optimize/es/components/datagrid/body/data_grid_cell.js +13 -1
  20. package/optimize/es/components/datagrid/utils/row_heights.js +33 -4
  21. package/optimize/es/components/popover/wrapping_popover.js +79 -38
  22. package/optimize/es/components/portal/portal.js +66 -34
  23. package/optimize/es/test/rtl/component_helpers.js +60 -1
  24. package/optimize/lib/components/datagrid/body/data_grid_body.js +2 -0
  25. package/optimize/lib/components/datagrid/body/data_grid_cell.js +13 -1
  26. package/optimize/lib/components/datagrid/utils/row_heights.js +33 -4
  27. package/optimize/lib/components/popover/wrapping_popover.js +78 -38
  28. package/optimize/lib/components/portal/portal.js +65 -44
  29. package/optimize/lib/test/rtl/component_helpers.js +69 -3
  30. package/package.json +2 -2
  31. package/test-env/components/datagrid/body/data_grid_body.js +11 -1
  32. package/test-env/components/datagrid/body/data_grid_cell.js +31 -3
  33. package/test-env/components/datagrid/data_grid.js +9 -1
  34. package/test-env/components/datagrid/utils/row_heights.js +33 -4
  35. package/test-env/components/observer/resize_observer/resize_observer.js +43 -126
  36. package/test-env/components/popover/wrapping_popover.js +78 -38
  37. package/test-env/components/portal/portal.js +79 -45
  38. package/test-env/test/rtl/component_helpers.js +69 -3
package/eui.d.ts CHANGED
@@ -4368,7 +4368,7 @@ declare module '@elastic/eui/src/components/portal/portal' {
4368
4368
  * NOTE: We can't test this component because Enzyme doesn't support rendering
4369
4369
  * into portals.
4370
4370
  */
4371
- import { ReactNode } from 'react';
4371
+ import { Component, ReactNode } from 'react';
4372
4372
  interface InsertPositionsMap {
4373
4373
  after: InsertPosition;
4374
4374
  before: InsertPosition;
@@ -4386,7 +4386,14 @@ declare module '@elastic/eui/src/components/portal/portal' {
4386
4386
  };
4387
4387
  portalRef?: (ref: HTMLDivElement | null) => void;
4388
4388
  }
4389
- export const EuiPortal: React.FC<EuiPortalProps>;
4389
+ export class EuiPortal extends Component<EuiPortalProps> {
4390
+ portalNode: HTMLDivElement | null;
4391
+ constructor(props: EuiPortalProps);
4392
+ componentDidMount(): void;
4393
+ componentWillUnmount(): void;
4394
+ updatePortalRef(ref: HTMLDivElement | null): void;
4395
+ render(): import("react").ReactPortal | null;
4396
+ }
4390
4397
  export {};
4391
4398
 
4392
4399
  }
@@ -5058,7 +5065,7 @@ declare module '@elastic/eui/src/components/popover/popover_footer' {
5058
5065
 
5059
5066
  }
5060
5067
  declare module '@elastic/eui/src/components/popover/wrapping_popover' {
5061
- import { FunctionComponent } from 'react';
5068
+ import { Component } from 'react';
5062
5069
  import { Props as EuiPopoverProps } from '@elastic/eui/src/components/popover/popover';
5063
5070
  export interface EuiWrappingPopoverProps extends EuiPopoverProps {
5064
5071
  button: HTMLElement;
@@ -5068,7 +5075,15 @@ declare module '@elastic/eui/src/components/popover/wrapping_popover' {
5068
5075
  * then the button element is moved into the popover dom.
5069
5076
  * On unmount, the button is moved back to its original location.
5070
5077
  */
5071
- export const EuiWrappingPopover: FunctionComponent<EuiWrappingPopoverProps>;
5078
+ export class EuiWrappingPopover extends Component<EuiWrappingPopoverProps> {
5079
+ private portal;
5080
+ private anchor;
5081
+ componentDidMount(): void;
5082
+ componentWillUnmount(): void;
5083
+ setPortalRef: (node: HTMLElement | null) => void;
5084
+ setAnchorRef: (node: HTMLElement | null) => void;
5085
+ render(): JSX.Element;
5086
+ }
5072
5087
 
5073
5088
  }
5074
5089
  declare module '@elastic/eui/src/components/popover' {
@@ -9859,14 +9874,17 @@ declare module '@elastic/eui/src/components/datagrid/utils/sorting' {
9859
9874
  }
9860
9875
  declare module '@elastic/eui/src/components/datagrid/utils/row_heights' {
9861
9876
  import { CSSProperties, MutableRefObject } from 'react';
9862
- import { EuiDataGridStyleCellPaddings, EuiDataGridStyle, EuiDataGridRowHeightOption, EuiDataGridRowHeightsOptions, EuiDataGridColumn, ImperativeGridApi } from '@elastic/eui/src/components/datagrid/data_grid_types';
9877
+ import { GridOnItemsRenderedProps } from 'react-window';
9878
+ import { EuiDataGridColumn, EuiDataGridRowHeightOption, EuiDataGridRowHeightsOptions, EuiDataGridScrollAnchorRow, EuiDataGridStyle, EuiDataGridStyleCellPaddings, ImperativeGridApi } from '@elastic/eui/src/components/datagrid/data_grid_types';
9863
9879
  export const cellPaddingsMap: Record<EuiDataGridStyleCellPaddings, number>;
9864
9880
  export const AUTO_HEIGHT = "auto";
9865
9881
  export const DEFAULT_ROW_HEIGHT = 34;
9866
9882
  export class RowHeightUtils {
9867
9883
  private gridRef;
9884
+ private outerGridElementRef;
9885
+ private gridItemsRenderedRef;
9868
9886
  private rerenderGridBodyRef;
9869
- constructor(gridRef: MutableRefObject<ImperativeGridApi | null>, rerenderGridBodyRef: MutableRefObject<(() => void) | null>);
9887
+ constructor(gridRef: MutableRefObject<ImperativeGridApi | null>, outerGridElementRef: MutableRefObject<HTMLDivElement | null>, gridItemsRenderedRef: MutableRefObject<GridOnItemsRenderedProps | null>, rerenderGridBodyRef: MutableRefObject<(() => void) | null>);
9870
9888
  getRowHeightOption(rowIndex: number, rowHeightsOptions?: EuiDataGridRowHeightsOptions): EuiDataGridRowHeightOption | undefined;
9871
9889
  isRowHeightOverride(rowIndex: number, rowHeightsOptions?: EuiDataGridRowHeightsOptions): boolean;
9872
9890
  getCalculatedHeight(heightOption: EuiDataGridRowHeightOption, defaultHeight: number, rowIndex?: number, isRowHeightOverride?: boolean): number;
@@ -9893,13 +9911,16 @@ declare module '@elastic/eui/src/components/datagrid/utils/row_heights' {
9893
9911
  pruneHiddenColumnHeights(visibleColumns: EuiDataGridColumn[]): void;
9894
9912
  resetRow(visibleRowIndex: number): void;
9895
9913
  resetGrid(): void;
9914
+ compensateForLayoutShift(rowIndex: number, verticalLayoutShift: number, anchorRow: EuiDataGridScrollAnchorRow): void;
9896
9915
  }
9897
9916
  /**
9898
9917
  * Hook for instantiating RowHeightUtils, setting internal class vars,
9899
9918
  * and setting up various row-height-related side effects
9900
9919
  */
9901
- export const useRowHeightUtils: ({ gridRef, gridStyles, columns, rowHeightsOptions, }: {
9920
+ export const useRowHeightUtils: ({ gridRef, outerGridElementRef, gridItemsRenderedRef, gridStyles, columns, rowHeightsOptions, }: {
9902
9921
  gridRef: MutableRefObject<ImperativeGridApi | null>;
9922
+ outerGridElementRef: MutableRefObject<HTMLDivElement | null>;
9923
+ gridItemsRenderedRef: MutableRefObject<GridOnItemsRenderedProps | null>;
9903
9924
  gridStyles: EuiDataGridStyle;
9904
9925
  columns: EuiDataGridColumn[];
9905
9926
  rowHeightsOptions?: EuiDataGridRowHeightsOptions | undefined;
@@ -10796,6 +10817,7 @@ declare module '@elastic/eui/src/components/datagrid/data_grid_types' {
10796
10817
  width: number;
10797
10818
  }
10798
10819
  export type EuiDataGridOnColumnResizeHandler = (data: EuiDataGridOnColumnResizeData) => void;
10820
+ export type EuiDataGridScrollAnchorRow = 'start' | 'center' | undefined;
10799
10821
  export type EuiDataGridRowHeightOption = number | 'auto' | ExclusiveUnion<{
10800
10822
  lineCount: number;
10801
10823
  }, {
@@ -10822,6 +10844,13 @@ declare module '@elastic/eui/src/components/datagrid/data_grid_types' {
10822
10844
  * Can be used for, e.g. storing user `rowHeightsOptions` in a local storage object.
10823
10845
  */
10824
10846
  onChange?: (rowHeightsOptions: EuiDataGridRowHeightsOptions) => void;
10847
+ /**
10848
+ * Optional indicator of the row that should be used as an anchor for vertical layout shift compensation.
10849
+ * When set to 'start' or 'center', the topmost or middle visible row will try
10850
+ * to compensate for changes in their top offsets by adjusting the grid's scroll
10851
+ * position.
10852
+ */
10853
+ scrollAnchorRow?: EuiDataGridScrollAnchorRow;
10825
10854
  }
10826
10855
  export interface EuiDataGridRowManager {
10827
10856
  getRow(args: {
@@ -23627,13 +23656,19 @@ declare module 'mdast-util-to-hast/lib/all' {
23627
23656
  export = all;
23628
23657
  }
23629
23658
  declare module '@elastic/eui/src/test/rtl/component_helpers' {
23659
+ import '@testing-library/jest-dom';
23630
23660
  /**
23631
- * Ensure the EuiPopover being tested is open/closed before contiuning
23661
+ * Ensure the EuiPopover being tested is open/closed before continuing
23632
23662
  * Note: Because EuiPopover is portalled, we want to query `document`
23633
23663
  * instead of the `container` returned by RTL's render()
23634
23664
  */
23635
23665
  export const waitForEuiPopoverOpen: () => Promise<void>;
23636
23666
  export const waitForEuiPopoverClose: () => Promise<void>;
23667
+ /**
23668
+ * Ensure the EuiToolTip being tested is open and visible before continuing
23669
+ */
23670
+ export const waitForEuiToolTipVisible: () => Promise<void>;
23671
+ export const waitForEuiToolTipHidden: () => Promise<void>;
23637
23672
 
23638
23673
  }
23639
23674
  declare module '@elastic/eui/src/test/rtl/data_test_subj_queries' {
@@ -373,6 +373,8 @@ var EuiDataGridBody = function EuiDataGridBody(props) {
373
373
 
374
374
  var rowHeightUtils = (0, _row_heights.useRowHeightUtils)({
375
375
  gridRef: gridRef,
376
+ outerGridElementRef: outerGridRef,
377
+ gridItemsRenderedRef: gridItemsRendered,
376
378
  gridStyles: gridStyles,
377
379
  columns: columns,
378
380
  rowHeightsOptions: rowHeightsOptions
@@ -1057,7 +1059,15 @@ EuiDataGridBody.propTypes = {
1057
1059
  * Optional callback returning the current `rowHeightsOptions` when changes occur from user input (e.g. toolbar display controls).
1058
1060
  * Can be used for, e.g. storing user `rowHeightsOptions` in a local storage object.
1059
1061
  */
1060
- onChange: _propTypes.default.func
1062
+ onChange: _propTypes.default.func,
1063
+
1064
+ /**
1065
+ * Optional indicator of the row that should be used as an anchor for vertical layout shift compensation.
1066
+ * When set to 'start' or 'center', the topmost or middle visible row will try
1067
+ * to compensate for changes in their top offsets by adjusting the grid's scroll
1068
+ * position.
1069
+ */
1070
+ scrollAnchorRow: _propTypes.default.oneOf(["start", "center", undefined])
1061
1071
  }),
1062
1072
  isFullScreen: _propTypes.default.bool.isRequired,
1063
1073
  gridStyles: _propTypes.default.shape({
@@ -565,7 +565,15 @@ EuiDataGridCellContent.propTypes = {
565
565
  * Optional callback returning the current `rowHeightsOptions` when changes occur from user input (e.g. toolbar display controls).
566
566
  * Can be used for, e.g. storing user `rowHeightsOptions` in a local storage object.
567
567
  */
568
- onChange: _propTypes.default.func
568
+ onChange: _propTypes.default.func,
569
+
570
+ /**
571
+ * Optional indicator of the row that should be used as an anchor for vertical layout shift compensation.
572
+ * When set to 'start' or 'center', the topmost or middle visible row will try
573
+ * to compensate for changes in their top offsets by adjusting the grid's scroll
574
+ * position.
575
+ */
576
+ scrollAnchorRow: _propTypes.default.oneOf(["start", "center", undefined])
569
577
  }),
570
578
  rowHeightUtils: _propTypes.default.any,
571
579
  pagination: _propTypes.default.shape({
@@ -935,7 +943,7 @@ var EuiDataGridCell = /*#__PURE__*/function (_Component) {
935
943
  }, {
936
944
  key: "componentDidUpdate",
937
945
  value: function componentDidUpdate(prevProps) {
938
- var _this$props$rowHeight, _prevProps$rowHeights;
946
+ var _this$props$rowHeight, _prevProps$rowHeights, _this$props$rowHeight2, _this$props$style, _prevProps$style;
939
947
 
940
948
  this.recalculateAutoHeight();
941
949
 
@@ -943,6 +951,18 @@ var EuiDataGridCell = /*#__PURE__*/function (_Component) {
943
951
  this.recalculateLineHeight();
944
952
  }
945
953
 
954
+ if ((_this$props$rowHeight2 = this.props.rowHeightsOptions) !== null && _this$props$rowHeight2 !== void 0 && _this$props$rowHeight2.scrollAnchorRow && this.props.colIndex === 0 && // once per row
955
+ this.props.columnId === prevProps.columnId && // if this is still the same column
956
+ this.props.rowIndex === prevProps.rowIndex && // if this is still the same row
957
+ ((_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
958
+ ) {
959
+ var _prevProps$style2, _this$props$style2, _this$props$rowHeight3, _this$props$rowHeight4;
960
+
961
+ var previousTop = parseFloat((_prevProps$style2 = prevProps.style) === null || _prevProps$style2 === void 0 ? void 0 : _prevProps$style2.top);
962
+ var currentTop = parseFloat((_this$props$style2 = this.props.style) === null || _this$props$style2 === void 0 ? void 0 : _this$props$style2.top);
963
+ (_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);
964
+ }
965
+
946
966
  if (this.props.popoverContext.popoverIsOpen !== prevProps.popoverContext.popoverIsOpen || this.props.popoverContext.cellLocation !== prevProps.popoverContext.cellLocation || this.props.renderCellPopover !== prevProps.renderCellPopover) {
947
967
  this.handleCellPopover();
948
968
  }
@@ -1592,7 +1612,15 @@ EuiDataGridCell.propTypes = {
1592
1612
  * Optional callback returning the current `rowHeightsOptions` when changes occur from user input (e.g. toolbar display controls).
1593
1613
  * Can be used for, e.g. storing user `rowHeightsOptions` in a local storage object.
1594
1614
  */
1595
- onChange: _propTypes.default.func
1615
+ onChange: _propTypes.default.func,
1616
+
1617
+ /**
1618
+ * Optional indicator of the row that should be used as an anchor for vertical layout shift compensation.
1619
+ * When set to 'start' or 'center', the topmost or middle visible row will try
1620
+ * to compensate for changes in their top offsets by adjusting the grid's scroll
1621
+ * position.
1622
+ */
1623
+ scrollAnchorRow: _propTypes.default.oneOf(["start", "center", undefined])
1596
1624
  }),
1597
1625
  rowHeightUtils: _propTypes.default.any,
1598
1626
  rowManager: _propTypes.default.shape({
@@ -1282,7 +1282,15 @@ EuiDataGrid.propTypes = {
1282
1282
  * Optional callback returning the current `rowHeightsOptions` when changes occur from user input (e.g. toolbar display controls).
1283
1283
  * Can be used for, e.g. storing user `rowHeightsOptions` in a local storage object.
1284
1284
  */
1285
- onChange: _propTypes.default.func
1285
+ onChange: _propTypes.default.func,
1286
+
1287
+ /**
1288
+ * Optional indicator of the row that should be used as an anchor for vertical layout shift compensation.
1289
+ * When set to 'start' or 'center', the topmost or middle visible row will try
1290
+ * to compensate for changes in their top offsets by adjusting the grid's scroll
1291
+ * position.
1292
+ */
1293
+ scrollAnchorRow: _propTypes.default.oneOf(["start", "center", undefined])
1286
1294
  })
1287
1295
  };
1288
1296
  EuiDataGrid.displayName = 'EuiDataGrid';
@@ -7,10 +7,10 @@ exports.useRowHeightUtils = exports.useDefaultRowHeight = exports.cellPaddingsMa
7
7
 
8
8
  var _react = require("react");
9
9
 
10
- var _predicate = require("../../../services/predicate");
11
-
12
10
  var _services = require("../../../services");
13
11
 
12
+ var _predicate = require("../../../services/predicate");
13
+
14
14
  var _sorting = require("./sorting");
15
15
 
16
16
  function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
@@ -54,12 +54,14 @@ var DEFAULT_ROW_HEIGHT = 34;
54
54
  exports.DEFAULT_ROW_HEIGHT = DEFAULT_ROW_HEIGHT;
55
55
 
56
56
  var RowHeightUtils = /*#__PURE__*/function () {
57
- function RowHeightUtils(gridRef, rerenderGridBodyRef) {
57
+ function RowHeightUtils(gridRef, outerGridElementRef, gridItemsRenderedRef, rerenderGridBodyRef) {
58
58
  var _this = this;
59
59
 
60
60
  _classCallCheck(this, RowHeightUtils);
61
61
 
62
62
  this.gridRef = gridRef;
63
+ this.outerGridElementRef = outerGridElementRef;
64
+ this.gridItemsRenderedRef = gridItemsRenderedRef;
63
65
  this.rerenderGridBodyRef = rerenderGridBodyRef;
64
66
 
65
67
  _defineProperty(this, "styles", {
@@ -255,6 +257,31 @@ var RowHeightUtils = /*#__PURE__*/function () {
255
257
  (_this$gridRef$current = this.gridRef.current) === null || _this$gridRef$current === void 0 ? void 0 : _this$gridRef$current.resetAfterRowIndex(this.lastUpdatedRow);
256
258
  this.lastUpdatedRow = Infinity;
257
259
  }
260
+ }, {
261
+ key: "compensateForLayoutShift",
262
+ value: function compensateForLayoutShift(rowIndex, verticalLayoutShift, anchorRow) {
263
+ var grid = this.gridRef.current;
264
+ var outerGridElement = this.outerGridElementRef.current;
265
+ var renderedItems = this.gridItemsRenderedRef.current;
266
+
267
+ if (grid == null || outerGridElement == null || renderedItems == null || anchorRow == null || !Number.isFinite(verticalLayoutShift)) {
268
+ return;
269
+ } // skip if the start row is the anchor row but it hasn't shifted
270
+
271
+
272
+ if (anchorRow === 'start' && renderedItems.visibleRowStartIndex !== rowIndex) {
273
+ return;
274
+ } // skip if the center row is the anchor row but it hasn't shifted
275
+
276
+
277
+ if (anchorRow === 'center' && Math.floor((renderedItems.visibleRowStopIndex - renderedItems.visibleRowStartIndex) / 2) !== rowIndex) {
278
+ return;
279
+ }
280
+
281
+ grid.scrollTo({
282
+ scrollTop: outerGridElement.scrollTop + verticalLayoutShift
283
+ });
284
+ }
258
285
  }]);
259
286
 
260
287
  return RowHeightUtils;
@@ -269,13 +296,15 @@ exports.RowHeightUtils = RowHeightUtils;
269
296
 
270
297
  var useRowHeightUtils = function useRowHeightUtils(_ref2) {
271
298
  var gridRef = _ref2.gridRef,
299
+ outerGridElementRef = _ref2.outerGridElementRef,
300
+ gridItemsRenderedRef = _ref2.gridItemsRenderedRef,
272
301
  gridStyles = _ref2.gridStyles,
273
302
  columns = _ref2.columns,
274
303
  rowHeightsOptions = _ref2.rowHeightsOptions;
275
304
  var forceRenderRef = (0, _services.useLatest)((0, _services.useForceRender)());
276
305
 
277
306
  var _useState = (0, _react.useState)(function () {
278
- return new RowHeightUtils(gridRef, forceRenderRef);
307
+ return new RowHeightUtils(gridRef, outerGridElementRef, gridItemsRenderedRef, forceRenderRef);
279
308
  }),
280
309
  _useState2 = _slicedToArray(_useState, 1),
281
310
  rowHeightUtils = _useState2[0]; // Forces a rerender whenever the row heights change, as this can cause the
@@ -27,67 +27,108 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj &&
27
27
 
28
28
  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); }
29
29
 
30
- function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
30
+ 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; }
31
31
 
32
- 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."); }
32
+ 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; }
33
33
 
34
- 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); }
34
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
35
35
 
36
- 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; }
36
+ 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); } }
37
37
 
38
- 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; }
38
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
39
39
 
40
- function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
40
+ 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); }
41
41
 
42
- 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; }
42
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
43
43
 
44
- 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; }
44
+ 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); }; }
45
+
46
+ 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); }
47
+
48
+ function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
49
+
50
+ 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; } }
51
+
52
+ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
53
+
54
+ 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; }
45
55
 
46
56
  /**
47
57
  * Injects the EuiPopover next to the button via EuiPortal
48
58
  * then the button element is moved into the popover dom.
49
59
  * On unmount, the button is moved back to its original location.
50
60
  */
51
- var EuiWrappingPopover = function EuiWrappingPopover(_ref) {
52
- var button = _ref.button,
53
- rest = _objectWithoutProperties(_ref, _excluded);
54
-
55
- var _useState = (0, _react.useState)(null),
56
- _useState2 = _slicedToArray(_useState, 2),
57
- anchor = _useState2[0],
58
- setAnchor = _useState2[1];
59
-
60
- var _useState3 = (0, _react.useState)(null),
61
- _useState4 = _slicedToArray(_useState3, 2),
62
- portal = _useState4[0],
63
- setPortal = _useState4[1];
64
-
65
- (0, _react.useEffect)(function () {
66
- if (anchor) {
67
- // move the button into the popover DOM
68
- anchor.insertAdjacentElement('beforebegin', button);
61
+ var EuiWrappingPopover = /*#__PURE__*/function (_Component) {
62
+ _inherits(EuiWrappingPopover, _Component);
63
+
64
+ var _super = _createSuper(EuiWrappingPopover);
65
+
66
+ function EuiWrappingPopover() {
67
+ var _this;
68
+
69
+ _classCallCheck(this, EuiWrappingPopover);
70
+
71
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
72
+ args[_key] = arguments[_key];
69
73
  }
70
74
 
71
- return function () {
72
- if (portal) {
73
- // move the button back out of the popover DOM
74
- portal.insertAdjacentElement('beforebegin', button);
75
+ _this = _super.call.apply(_super, [this].concat(args));
76
+
77
+ _defineProperty(_assertThisInitialized(_this), "portal", null);
78
+
79
+ _defineProperty(_assertThisInitialized(_this), "anchor", null);
80
+
81
+ _defineProperty(_assertThisInitialized(_this), "setPortalRef", function (node) {
82
+ _this.portal = node;
83
+ });
84
+
85
+ _defineProperty(_assertThisInitialized(_this), "setAnchorRef", function (node) {
86
+ _this.anchor = node;
87
+ });
88
+
89
+ return _this;
90
+ }
91
+
92
+ _createClass(EuiWrappingPopover, [{
93
+ key: "componentDidMount",
94
+ value: function componentDidMount() {
95
+ if (this.anchor) {
96
+ this.anchor.insertAdjacentElement('beforebegin', this.props.button);
97
+ }
98
+ }
99
+ }, {
100
+ key: "componentWillUnmount",
101
+ value: function componentWillUnmount() {
102
+ if (this.props.button.parentNode) {
103
+ if (this.portal) {
104
+ this.portal.insertAdjacentElement('beforebegin', this.props.button);
105
+ }
75
106
  }
76
- };
77
- }, [anchor, button, portal]);
78
- return (0, _react2.jsx)(_portal.EuiPortal, {
79
- portalRef: setPortal,
80
- insert: {
81
- sibling: button,
82
- position: 'after'
83
107
  }
84
- }, (0, _react2.jsx)(_popover.EuiPopover, _extends({}, rest, {
85
- button: (0, _react2.jsx)("div", {
86
- ref: setAnchor,
87
- className: "euiWrappingPopover__anchor"
88
- })
89
- })));
90
- };
108
+ }, {
109
+ key: "render",
110
+ value: function render() {
111
+ var _this$props = this.props,
112
+ button = _this$props.button,
113
+ rest = _objectWithoutProperties(_this$props, _excluded);
114
+
115
+ return (0, _react2.jsx)(_portal.EuiPortal, {
116
+ portalRef: this.setPortalRef,
117
+ insert: {
118
+ sibling: this.props.button,
119
+ position: 'after'
120
+ }
121
+ }, (0, _react2.jsx)(_popover.EuiPopover, _extends({}, rest, {
122
+ button: (0, _react2.jsx)("div", {
123
+ ref: this.setAnchorRef,
124
+ className: "euiWrappingPopover__anchor"
125
+ })
126
+ })));
127
+ }
128
+ }]);
129
+
130
+ return EuiWrappingPopover;
131
+ }(_react.Component);
91
132
 
92
133
  exports.EuiWrappingPopover = EuiWrappingPopover;
93
134
  EuiWrappingPopover.propTypes = {
@@ -1,5 +1,7 @@
1
1
  "use strict";
2
2
 
3
+ 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); }
4
+
3
5
  Object.defineProperty(exports, "__esModule", {
4
6
  value: true
5
7
  });
@@ -7,23 +9,35 @@ exports.insertPositions = exports.INSERT_POSITIONS = exports.EuiPortal = void 0;
7
9
 
8
10
  var _react = require("react");
9
11
 
12
+ var _propTypes = _interopRequireDefault(require("prop-types"));
13
+
10
14
  var _reactDom = require("react-dom");
11
15
 
12
16
  var _common = require("../common");
13
17
 
14
- var _services = require("../../services");
18
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
19
+
20
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
21
+
22
+ 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); } }
23
+
24
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
15
25
 
16
- function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
26
+ 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); }
17
27
 
18
- 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."); }
28
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
19
29
 
20
- 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); }
30
+ 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); }; }
21
31
 
22
- 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; }
32
+ 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); }
23
33
 
24
- 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; }
34
+ function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
25
35
 
26
- function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
36
+ 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; } }
37
+
38
+ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
39
+
40
+ 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; }
27
41
 
28
42
  var insertPositions = {
29
43
  after: 'afterend',
@@ -33,47 +47,81 @@ exports.insertPositions = insertPositions;
33
47
  var INSERT_POSITIONS = (0, _common.keysOf)(insertPositions);
34
48
  exports.INSERT_POSITIONS = INSERT_POSITIONS;
35
49
 
36
- var EuiPortal = function EuiPortal(_ref) {
37
- var insert = _ref.insert,
38
- portalRef = _ref.portalRef,
39
- children = _ref.children;
50
+ var EuiPortal = /*#__PURE__*/function (_Component) {
51
+ _inherits(EuiPortal, _Component);
52
+
53
+ var _super = _createSuper(EuiPortal);
54
+
55
+ function EuiPortal(props) {
56
+ var _this;
40
57
 
41
- var _useState = (0, _react.useState)(null),
42
- _useState2 = _slicedToArray(_useState, 2),
43
- portalNode = _useState2[0],
44
- setPortalNode = _useState2[1]; // pull `sibling` and `position` out of insert in case their wrapping object is recreated every render
58
+ _classCallCheck(this, EuiPortal);
45
59
 
60
+ _this = _super.call(this, props);
46
61
 
47
- var _ref2 = insert || {},
48
- sibling = _ref2.sibling,
49
- position = _ref2.position;
62
+ _defineProperty(_assertThisInitialized(_this), "portalNode", null);
50
63
 
51
- (0, _react.useEffect)(function () {
52
- var portalNode = document.createElement('div');
53
- portalNode.dataset.euiportal = 'true';
54
- setPortalNode(portalNode);
64
+ if (typeof window === 'undefined') return _possibleConstructorReturn(_this); // Prevent SSR errors
55
65
 
56
- if (sibling == null || position == null) {
66
+ var insert = _this.props.insert;
67
+ _this.portalNode = document.createElement('div');
68
+ _this.portalNode.dataset.euiportal = 'true';
69
+
70
+ if (insert == null) {
57
71
  // no insertion defined, append to body
58
- document.body.appendChild(portalNode);
72
+ document.body.appendChild(_this.portalNode);
59
73
  } else {
60
74
  // inserting before or after an element
61
- sibling.insertAdjacentElement(insertPositions[position], portalNode);
75
+ var sibling = insert.sibling,
76
+ position = insert.position;
77
+ sibling.insertAdjacentElement(insertPositions[position], _this.portalNode);
62
78
  }
63
79
 
64
- return function () {
65
- if (portalNode && portalNode.parentNode) {
66
- portalNode.parentNode.removeChild(portalNode);
80
+ return _this;
81
+ }
82
+
83
+ _createClass(EuiPortal, [{
84
+ key: "componentDidMount",
85
+ value: function componentDidMount() {
86
+ this.updatePortalRef(this.portalNode);
87
+ }
88
+ }, {
89
+ key: "componentWillUnmount",
90
+ value: function componentWillUnmount() {
91
+ var _this$portalNode;
92
+
93
+ if ((_this$portalNode = this.portalNode) !== null && _this$portalNode !== void 0 && _this$portalNode.parentNode) {
94
+ this.portalNode.parentNode.removeChild(this.portalNode);
67
95
  }
68
- };
69
- }, [sibling, position]);
70
- (0, _services.useUpdateEffect)(function () {
71
- portalRef === null || portalRef === void 0 ? void 0 : portalRef(portalNode);
72
- return function () {
73
- portalRef === null || portalRef === void 0 ? void 0 : portalRef(null);
74
- };
75
- }, [portalNode, portalRef]);
76
- return portalNode == null ? null : /*#__PURE__*/(0, _reactDom.createPortal)(children, portalNode);
77
- };
78
96
 
79
- exports.EuiPortal = EuiPortal;
97
+ this.updatePortalRef(null);
98
+ }
99
+ }, {
100
+ key: "updatePortalRef",
101
+ value: function updatePortalRef(ref) {
102
+ if (this.props.portalRef) {
103
+ this.props.portalRef(ref);
104
+ }
105
+ }
106
+ }, {
107
+ key: "render",
108
+ value: function render() {
109
+ return this.portalNode ? /*#__PURE__*/(0, _reactDom.createPortal)(this.props.children, this.portalNode) : null;
110
+ }
111
+ }]);
112
+
113
+ return EuiPortal;
114
+ }(_react.Component);
115
+
116
+ exports.EuiPortal = EuiPortal;
117
+ EuiPortal.propTypes = {
118
+ /**
119
+ * ReactNode to render as this component's content
120
+ */
121
+ children: _propTypes.default.node.isRequired,
122
+ insert: _propTypes.default.shape({
123
+ sibling: _propTypes.default.any.isRequired,
124
+ position: _propTypes.default.oneOf(["before", "after"]).isRequired
125
+ }),
126
+ portalRef: _propTypes.default.func
127
+ };