@elastic/eui 116.0.0 → 116.1.0-snapshot.1779110362015

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 (70) hide show
  1. package/es/components/accordion/accordion.js +95 -134
  2. package/es/components/basic_table/basic_table.js +6 -0
  3. package/es/components/basic_table/in_memory_table.js +6 -0
  4. package/es/components/color_picker/color_picker_swatch.js +4 -0
  5. package/es/components/context_menu/context_menu_panel.js +2 -2
  6. package/es/components/copy/copy.js +36 -13
  7. package/es/components/datagrid/body/cell/data_grid_cell_popover.js +10 -7
  8. package/es/components/datagrid/data_grid.styles.js +6 -5
  9. package/es/components/focus_trap/focus_trap.js +110 -177
  10. package/es/components/observer/mutation_observer/mutation_observer.js +32 -35
  11. package/es/components/observer/resize_observer/resize_observer.js +46 -60
  12. package/es/components/observer/use_observer.js +62 -0
  13. package/es/components/table/table_header_cell.js +4 -0
  14. package/es/components/tool_tip/icon_tip.js +4 -0
  15. package/es/components/tool_tip/tool_tip.js +8 -2
  16. package/eui.d.ts +26 -69
  17. package/lib/components/accordion/accordion.js +102 -139
  18. package/lib/components/basic_table/basic_table.js +6 -0
  19. package/lib/components/basic_table/in_memory_table.js +6 -0
  20. package/lib/components/color_picker/color_picker_swatch.js +4 -0
  21. package/lib/components/context_menu/context_menu_panel.js +2 -2
  22. package/lib/components/copy/copy.js +35 -12
  23. package/lib/components/datagrid/body/cell/data_grid_cell_popover.js +10 -7
  24. package/lib/components/datagrid/data_grid.styles.js +6 -5
  25. package/lib/components/focus_trap/focus_trap.js +117 -183
  26. package/lib/components/observer/mutation_observer/mutation_observer.js +32 -34
  27. package/lib/components/observer/resize_observer/resize_observer.js +48 -61
  28. package/lib/components/observer/use_observer.js +68 -0
  29. package/lib/components/table/table_header_cell.js +4 -0
  30. package/lib/components/tool_tip/icon_tip.js +4 -0
  31. package/lib/components/tool_tip/tool_tip.js +8 -2
  32. package/optimize/es/components/accordion/accordion.js +88 -126
  33. package/optimize/es/components/context_menu/context_menu_panel.js +2 -2
  34. package/optimize/es/components/copy/copy.js +36 -13
  35. package/optimize/es/components/datagrid/body/cell/data_grid_cell_popover.js +10 -7
  36. package/optimize/es/components/datagrid/data_grid.styles.js +6 -5
  37. package/optimize/es/components/focus_trap/focus_trap.js +103 -122
  38. package/optimize/es/components/observer/mutation_observer/mutation_observer.js +23 -32
  39. package/optimize/es/components/observer/resize_observer/resize_observer.js +38 -54
  40. package/optimize/es/components/observer/use_observer.js +62 -0
  41. package/optimize/es/components/tool_tip/tool_tip.js +4 -2
  42. package/optimize/lib/components/accordion/accordion.js +90 -127
  43. package/optimize/lib/components/context_menu/context_menu_panel.js +2 -2
  44. package/optimize/lib/components/copy/copy.js +35 -12
  45. package/optimize/lib/components/datagrid/body/cell/data_grid_cell_popover.js +10 -7
  46. package/optimize/lib/components/datagrid/data_grid.styles.js +6 -5
  47. package/optimize/lib/components/focus_trap/focus_trap.js +106 -124
  48. package/optimize/lib/components/observer/mutation_observer/mutation_observer.js +23 -32
  49. package/optimize/lib/components/observer/resize_observer/resize_observer.js +40 -54
  50. package/optimize/lib/components/observer/use_observer.js +68 -0
  51. package/optimize/lib/components/tool_tip/tool_tip.js +4 -2
  52. package/package.json +4 -3
  53. package/test-env/components/accordion/accordion.js +92 -129
  54. package/test-env/components/basic_table/basic_table.js +6 -0
  55. package/test-env/components/basic_table/in_memory_table.js +6 -0
  56. package/test-env/components/color_picker/color_picker_swatch.js +4 -0
  57. package/test-env/components/context_menu/context_menu_panel.js +2 -2
  58. package/test-env/components/copy/copy.js +35 -12
  59. package/test-env/components/datagrid/body/cell/data_grid_cell_popover.js +10 -7
  60. package/test-env/components/datagrid/data_grid.styles.js +6 -5
  61. package/test-env/components/observer/mutation_observer/mutation_observer.js +32 -32
  62. package/test-env/components/observer/use_observer.js +68 -0
  63. package/test-env/components/table/table_header_cell.js +4 -0
  64. package/test-env/components/tool_tip/icon_tip.js +4 -0
  65. package/test-env/components/tool_tip/tool_tip.js +8 -2
  66. package/es/components/observer/observer.js +0 -75
  67. package/lib/components/observer/observer.js +0 -79
  68. package/optimize/es/components/observer/observer.js +0 -69
  69. package/optimize/lib/components/observer/observer.js +0 -74
  70. package/test-env/components/observer/observer.js +0 -74
@@ -7,6 +7,7 @@ exports.EuiCopy = void 0;
7
7
  var _react = _interopRequireWildcard(require("react"));
8
8
  var _propTypes = _interopRequireDefault(require("prop-types"));
9
9
  var _services = require("../../services");
10
+ var _accessibility = require("../accessibility");
10
11
  var _tool_tip = require("../tool_tip");
11
12
  var _react2 = require("@emotion/react");
12
13
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
@@ -38,21 +39,31 @@ var EuiCopy = exports.EuiCopy = /*#__PURE__*/function (_Component) {
38
39
  var _this;
39
40
  _classCallCheck(this, EuiCopy);
40
41
  _this = _callSuper(this, EuiCopy, [props]);
42
+ _defineProperty(_this, "tooltipRef", /*#__PURE__*/(0, _react.createRef)());
41
43
  _defineProperty(_this, "copy", function () {
42
44
  var isCopied = (0, _services.copyToClipboard)(_this.props.textToCopy);
43
45
  if (isCopied) {
44
46
  _this.setState({
45
- tooltipText: _this.props.afterMessage
47
+ tooltipText: _this.props.afterMessage,
48
+ isCopied: true
49
+ },
50
+ // `EuiToolTip` suppresses showing when content is empty, so `EuiCopy`
51
+ // imperatively shows the tooltip after the post-copy state update.
52
+ function () {
53
+ var _this$tooltipRef$curr;
54
+ (_this$tooltipRef$curr = _this.tooltipRef.current) === null || _this$tooltipRef$curr === void 0 || _this$tooltipRef$curr.showToolTip();
46
55
  });
47
56
  }
48
57
  });
49
58
  _defineProperty(_this, "resetTooltipText", function () {
50
59
  _this.setState({
51
- tooltipText: _this.props.beforeMessage
60
+ tooltipText: _this.props.beforeMessage,
61
+ isCopied: false
52
62
  });
53
63
  });
54
64
  _this.state = {
55
- tooltipText: _this.props.beforeMessage
65
+ tooltipText: _this.props.beforeMessage,
66
+ isCopied: false
56
67
  };
57
68
  return _this;
58
69
  }
@@ -60,17 +71,29 @@ var EuiCopy = exports.EuiCopy = /*#__PURE__*/function (_Component) {
60
71
  return _createClass(EuiCopy, [{
61
72
  key: "render",
62
73
  value: function render() {
74
+ var _this2 = this;
63
75
  var _this$props = this.props,
64
76
  children = _this$props.children,
65
- tooltipProps = _this$props.tooltipProps;
66
- return (
67
- // See `src/components/tool_tip/tool_tip.js` for explanation of below eslint-disable
68
- // eslint-disable-next-line jsx-a11y/mouse-events-have-key-events
69
- (0, _react2.jsx)(_tool_tip.EuiToolTip, _extends({
70
- content: this.state.tooltipText,
71
- onMouseOut: this.resetTooltipText
72
- }, tooltipProps), children(this.copy))
73
- );
77
+ tooltipProps = _this$props.tooltipProps,
78
+ afterMessage = _this$props.afterMessage;
79
+ var _this$state = this.state,
80
+ tooltipText = _this$state.tooltipText,
81
+ isCopied = _this$state.isCopied;
82
+ return (0, _react2.jsx)(_react.default.Fragment, null, (0, _react2.jsx)(_tool_tip.EuiToolTip, _extends({
83
+ ref: this.tooltipRef,
84
+ content: tooltipText,
85
+ onMouseOut: this.resetTooltipText
86
+ }, tooltipProps, {
87
+ onBlur: function onBlur() {
88
+ var _tooltipProps$onBlur;
89
+ tooltipProps === null || tooltipProps === void 0 || (_tooltipProps$onBlur = tooltipProps.onBlur) === null || _tooltipProps$onBlur === void 0 || _tooltipProps$onBlur.call(tooltipProps);
90
+ if (isCopied) _this2.resetTooltipText();
91
+ },
92
+ disableScreenReaderOutput: isCopied || !!(tooltipProps !== null && tooltipProps !== void 0 && tooltipProps.disableScreenReaderOutput)
93
+ }), children(this.copy)), (0, _react2.jsx)(_accessibility.EuiScreenReaderOnly, null, (0, _react2.jsx)("div", {
94
+ "aria-live": "assertive",
95
+ "aria-atomic": "true"
96
+ }, isCopied ? afterMessage : '')));
74
97
  }
75
98
  }]);
76
99
  }(_react.Component);
@@ -9,7 +9,6 @@ var _react = _interopRequireWildcard(require("react"));
9
9
  var _classnames = _interopRequireDefault(require("classnames"));
10
10
  var _services = require("../../../../services");
11
11
  var _popover = require("../../../popover");
12
- var _data_grid = require("../../data_grid.styles");
13
12
  var _data_grid_cell_popover = require("./data_grid_cell_popover.styles");
14
13
  var _text = require("../../../text");
15
14
  var _code = require("../../../code");
@@ -138,14 +137,19 @@ var useCellPopover = exports.useCellPopover = function useCellPopover() {
138
137
  };
139
138
  }, [popoverIsOpen, closeCellPopover, openCellPopover, cellLocation]);
140
139
  var styles = (0, _services.useEuiMemoizedStyles)(_data_grid_cell_popover.euiDataGridCellPopoverStyles);
141
- var _useEuiMemoizedStyles = (0, _services.useEuiMemoizedStyles)(_data_grid.euiDataGridVariables),
142
- levels = _useEuiMemoizedStyles.levels;
143
140
  var cellPopover = (0, _react.useMemo)(function () {
144
141
  var _cellPopoverProps$pan, _cell$offsetWidth;
145
142
  if (!popoverIsOpen || !popoverAnchor) return null;
146
143
  var cell = popoverAnchor.closest('.euiDataGridRowCell');
147
144
 
148
- // Note that this popover is rendered once at the top grid level, rather than one popover per cell
145
+ // Note that this popover is rendered once at the top grid level, rather than one popover per cell.
146
+ //
147
+ // We intentionally do NOT pass `zIndex` here. Letting `EuiPopover` derive the
148
+ // panel's z-index from the anchor's stacking context (`getElementZIndex(button) + 2000`)
149
+ // keeps cell popovers above their host flyout — including when sibling/nested
150
+ // flyouts push the host's z-index above `levels.header`. See
151
+ // https://github.com/elastic/eui/issues/8801. Consumers that need a fixed
152
+ // value can still override via `setCellPopoverProps({ zIndex })`.
149
153
  return (0, _react2.jsx)(_popover.EuiWrappingPopover, _extends({
150
154
  isOpen: popoverIsOpen,
151
155
  display: "block",
@@ -154,8 +158,7 @@ var useCellPopover = exports.useCellPopover = function useCellPopover() {
154
158
  ,
155
159
  panelPaddingSize: "s",
156
160
  anchorPosition: popoverAnchorPosition,
157
- repositionToCrossAxis: false,
158
- zIndex: levels.cellPopover
161
+ repositionToCrossAxis: false
159
162
  }, cellPopoverProps, {
160
163
  focusTrapProps: {
161
164
  onClickOutside: onClickOutside,
@@ -175,7 +178,7 @@ var useCellPopover = exports.useCellPopover = function useCellPopover() {
175
178
  button: popoverAnchor,
176
179
  closePopover: closeCellPopover
177
180
  }), popoverContent);
178
- }, [styles, levels.cellPopover, popoverIsOpen, popoverAnchor, popoverContent, cellPopoverProps, closeCellPopover, onClickOutside, onKeyDown, popoverAnchorPosition]);
181
+ }, [styles, popoverIsOpen, popoverAnchor, popoverContent, cellPopoverProps, closeCellPopover, onClickOutside, onKeyDown, popoverAnchorPosition]);
179
182
  return (0, _react.useMemo)(function () {
180
183
  return {
181
184
  cellPopoverContext: cellPopoverContext,
@@ -35,11 +35,12 @@ var euiDataGridVariables = exports.euiDataGridVariables = function euiDataGridVa
35
35
  m: (0, _global_styling.euiFontSize)(euiThemeContext, 's').fontSize
36
36
  },
37
37
  levels: {
38
- cellPopover: Number(euiTheme.levels.header),
39
- // Same z-index as EuiFlyout mask overlays - cell popovers should be under both modal and flyout overlays
40
- get stickyHeader() {
41
- return this.cellPopover - 1; // Needs to sit above the content + cell focus outlines/actions, but below actual popovers
42
- }
38
+ // Sits above content and cell focus outlines/actions, but below cell
39
+ // expansion popovers. Cell popovers no longer use a fixed z-index they
40
+ // derive theirs from their anchor's stacking context (see
41
+ // data_grid_cell_popover.tsx) so this only needs to clear the grid's
42
+ // own internal layers.
43
+ stickyHeader: Number(euiTheme.levels.header) - 1
43
44
  }
44
45
  };
45
46
  };
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
 
3
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
3
4
  Object.defineProperty(exports, "__esModule", {
4
5
  value: true
5
6
  });
@@ -11,204 +12,137 @@ var _reactRemoveScrollBar = require("react-remove-scroll-bar");
11
12
  var _services = require("../../services");
12
13
  var _component_defaults = require("../provider/component_defaults");
13
14
  var _react2 = require("@emotion/react");
14
- var _excluded = ["children", "clickOutsideDisables", "disabled", "returnFocus", "noIsolation", "scrollLock", "gapMode"];
15
+ var _excluded = ["children", "disabled", "clickOutsideDisables", "returnFocus", "noIsolation", "crossFrame", "scrollLock", "initialFocus", "gapMode", "closeOnMouseup", "onClickOutside"];
16
+ /*
17
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
18
+ * or more contributor license agreements. Licensed under the Elastic License
19
+ * 2.0 and the Server Side Public License, v 1; you may not use this file except
20
+ * in compliance with, at your election, the Elastic License 2.0 or the Server
21
+ * Side Public License, v 1.
22
+ */
15
23
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
16
24
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
17
25
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
18
- function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
19
26
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
20
27
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
21
- function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], t.indexOf(o) >= 0 || {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
22
- function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (e.indexOf(n) >= 0) continue; t[n] = r[n]; } return t; }
23
- function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
24
- function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
25
- function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
26
- function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
27
- function _possibleConstructorReturn(t, e) { if (e && ("object" == _typeof(e) || "function" == typeof e)) return e; if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined"); return _assertThisInitialized(t); }
28
- function _assertThisInitialized(e) { if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return e; }
29
- function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
30
- function _getPrototypeOf(t) { return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, _getPrototypeOf(t); }
31
- function _inherits(t, e) { if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function"); t.prototype = Object.create(e && e.prototype, { constructor: { value: t, writable: !0, configurable: !0 } }), Object.defineProperty(t, "prototype", { writable: !1 }), e && _setPrototypeOf(t, e); }
32
- function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); }
33
28
  function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
34
29
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
35
- function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } /*
36
- * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
37
- * or more contributor license agreements. Licensed under the Elastic License
38
- * 2.0 and the Server Side Public License, v 1; you may not use this file except
39
- * in compliance with, at your election, the Elastic License 2.0 or the Server
40
- * Side Public License, v 1.
41
- */
42
- var EuiFocusTrap = exports.EuiFocusTrap = function EuiFocusTrap(props) {
43
- var propsWithDefaults = (0, _component_defaults.usePropsWithComponentDefaults)('EuiFocusTrap', props);
44
- return (0, _react2.jsx)(EuiFocusTrapClass, propsWithDefaults);
45
- };
46
- EuiFocusTrap.propTypes = {
47
- // For some reason, Storybook doesn't register these props if they're Pick<>'d
48
- className: _propTypes.default.string,
49
- css: _propTypes.default.any,
50
- style: _propTypes.default.any,
51
- /**
52
- * @default false
53
- */
54
- disabled: _propTypes.default.bool,
55
- /**
56
- * Whether `onClickOutside` should be called on mouseup instead of mousedown.
57
- * This flag can be used to prevent conflicts with outside toggle buttons by delaying the closing click callback.
58
- */
59
- closeOnMouseup: _propTypes.default.bool,
60
- /**
61
- * Clicking outside the trap area will disable the trap
62
- * @default false
63
- */
64
- clickOutsideDisables: _propTypes.default.bool,
65
- /**
66
- * Reference to element that will get focus when the trap is initiated
67
- */
68
- initialFocus: _propTypes.default.any,
69
- /**
70
- * if `scrollLock` is set to true, the body's scrollbar width will be preserved on lock
71
- * via the `gapMode` CSS property. Depending on your custom CSS, you may prefer to use
72
- * `margin` instead of `padding`.
73
- * @default padding
74
- */
75
- gapMode: _propTypes.default.oneOf(["padding", "margin"]),
76
- /**
77
- * Configures focus trapping between iframes.
78
- * By default, EuiFocusTrap allows focus to leave iframes and move to elements outside of it.
79
- * Set to `true` if you want focus to remain trapped within the iframe.
80
- * @default false
81
- */
82
- crossFrame: _propTypes.default.any,
83
- /**
84
- * @default false
85
- */
86
- scrollLock: _propTypes.default.any,
87
- /**
88
- * @default true
89
- */
90
- noIsolation: _propTypes.default.any,
91
- /**
92
- * @default true
93
- */
94
- returnFocus: _propTypes.default.any
95
- };
96
- var EuiFocusTrapClass = /*#__PURE__*/function (_Component) {
97
- function EuiFocusTrapClass() {
98
- var _this;
99
- _classCallCheck(this, EuiFocusTrapClass);
100
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
101
- args[_key] = arguments[_key];
30
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
31
+ function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
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."); }
33
+ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
34
+ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
35
+ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
36
+ function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
37
+ function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], t.indexOf(o) >= 0 || {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
38
+ function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (e.indexOf(n) >= 0) continue; t[n] = r[n]; } return t; }
39
+ var EuiFocusTrap = exports.EuiFocusTrap = function EuiFocusTrap(_props) {
40
+ var props = (0, _component_defaults.usePropsWithComponentDefaults)('EuiFocusTrap', _props);
41
+ var children = props.children,
42
+ disabled = props.disabled,
43
+ _props$clickOutsideDi = props.clickOutsideDisables,
44
+ clickOutsideDisables = _props$clickOutsideDi === void 0 ? false : _props$clickOutsideDi,
45
+ _props$returnFocus = props.returnFocus,
46
+ returnFocus = _props$returnFocus === void 0 ? true : _props$returnFocus,
47
+ _props$noIsolation = props.noIsolation,
48
+ noIsolation = _props$noIsolation === void 0 ? true : _props$noIsolation,
49
+ _props$crossFrame = props.crossFrame,
50
+ crossFrame = _props$crossFrame === void 0 ? false : _props$crossFrame,
51
+ _props$scrollLock = props.scrollLock,
52
+ scrollLock = _props$scrollLock === void 0 ? false : _props$scrollLock,
53
+ initialFocus = props.initialFocus,
54
+ _props$gapMode = props.gapMode,
55
+ gapMode = _props$gapMode === void 0 ? 'padding' : _props$gapMode,
56
+ closeOnMouseup = props.closeOnMouseup,
57
+ onClickOutside = props.onClickOutside,
58
+ rest = _objectWithoutProperties(props, _excluded);
59
+ var _useState = (0, _react.useState)(false),
60
+ _useState2 = _slicedToArray(_useState, 2),
61
+ hasBeenDisabledByClick = _useState2[0],
62
+ setHasBeenDisabledByClick = _useState2[1];
63
+ var isDisabled = disabled || hasBeenDisabledByClick;
64
+
65
+ // Programmatically sets focus on a nested DOM node; optional
66
+ var setInitialFocus = function setInitialFocus(initialFocus) {
67
+ if (!initialFocus) return;
68
+ var node = (0, _services.findElementBySelectorOrRef)(initialFocus);
69
+ if (!node) return;
70
+ // `data-autofocus` is part of the 'react-focus-on' API
71
+ node.setAttribute('data-autofocus', 'true');
72
+ };
73
+
74
+ // Stabilize the onClickOutside callback
75
+ var onClickOutsideRef = (0, _react.useRef)(onClickOutside);
76
+ onClickOutsideRef.current = onClickOutside;
77
+
78
+ // We use a ref to store the listener to prevent circular dependencies
79
+ // while still ensuring the listeners can properly be cleaned up
80
+ var mouseupListenerRef = (0, _react.useRef)(null);
81
+ var removeMouseupListener = (0, _react.useCallback)(function () {
82
+ if (mouseupListenerRef.current) {
83
+ document.removeEventListener('mouseup', mouseupListenerRef.current);
84
+ document.removeEventListener('touchend', mouseupListenerRef.current);
85
+ mouseupListenerRef.current = null;
102
86
  }
103
- _this = _callSuper(this, EuiFocusTrapClass, [].concat(args));
104
- _defineProperty(_this, "state", {
105
- hasBeenDisabledByClick: false
106
- });
107
- _defineProperty(_this, "lastInterceptedEvent", null);
108
- _defineProperty(_this, "preventFocusExit", false);
109
- // Programmatically sets focus on a nested DOM node; optional
110
- _defineProperty(_this, "setInitialFocus", function (initialFocus) {
111
- if (!initialFocus) return;
112
- var node = (0, _services.findElementBySelectorOrRef)(initialFocus);
113
- if (!node) return;
114
- // `data-autofocus` is part of the 'react-focus-on' API
115
- node.setAttribute('data-autofocus', 'true');
116
- });
117
- _defineProperty(_this, "onMouseupOutside", function (e) {
118
- _this.removeMouseupListener();
87
+ }, []);
88
+ var addMouseupListener = (0, _react.useCallback)(function () {
89
+ removeMouseupListener();
90
+ mouseupListenerRef.current = function (e) {
91
+ removeMouseupListener();
119
92
  // Timeout gives precedence to the consumer to initiate close if it has toggle behavior.
120
93
  // Otherwise this event may occur first and the consumer toggle will reopen the flyout.
121
94
  setTimeout(function () {
122
- var _this$props$onClickOu, _this$props;
123
- return (_this$props$onClickOu = (_this$props = _this.props).onClickOutside) === null || _this$props$onClickOu === void 0 ? void 0 : _this$props$onClickOu.call(_this$props, e);
95
+ var _onClickOutsideRef$cu;
96
+ return (_onClickOutsideRef$cu = onClickOutsideRef.current) === null || _onClickOutsideRef$cu === void 0 ? void 0 : _onClickOutsideRef$cu.call(onClickOutsideRef, e);
124
97
  });
125
- });
126
- _defineProperty(_this, "addMouseupListener", function () {
127
- document.addEventListener('mouseup', _this.onMouseupOutside);
128
- document.addEventListener('touchend', _this.onMouseupOutside);
129
- });
130
- _defineProperty(_this, "removeMouseupListener", function () {
131
- document.removeEventListener('mouseup', _this.onMouseupOutside);
132
- document.removeEventListener('touchend', _this.onMouseupOutside);
133
- });
134
- _defineProperty(_this, "handleOutsideClick", function (event) {
135
- var _this$props2 = _this.props,
136
- onClickOutside = _this$props2.onClickOutside,
137
- clickOutsideDisables = _this$props2.clickOutsideDisables,
138
- closeOnMouseup = _this$props2.closeOnMouseup;
139
- if (clickOutsideDisables) {
140
- _this.setState({
141
- hasBeenDisabledByClick: true
142
- });
143
- }
144
- if (onClickOutside) {
145
- closeOnMouseup ? _this.addMouseupListener() : onClickOutside(event);
146
- }
147
- });
148
- return _this;
149
- }
150
- _inherits(EuiFocusTrapClass, _Component);
151
- return _createClass(EuiFocusTrapClass, [{
152
- key: "componentDidMount",
153
- value: function componentDidMount() {
154
- this.setInitialFocus(this.props.initialFocus);
98
+ };
99
+ document.addEventListener('mouseup', mouseupListenerRef.current);
100
+ document.addEventListener('touchend', mouseupListenerRef.current);
101
+ }, [removeMouseupListener]);
102
+ var handleOutsideClick = (0, _react.useCallback)(function (event) {
103
+ if (clickOutsideDisables) {
104
+ setHasBeenDisabledByClick(true);
155
105
  }
156
- }, {
157
- key: "componentDidUpdate",
158
- value: function componentDidUpdate(prevProps) {
159
- if (prevProps.disabled === true && this.props.disabled === false) {
160
- this.setState({
161
- hasBeenDisabledByClick: false
162
- });
163
- }
106
+ if (onClickOutside) {
107
+ closeOnMouseup ? addMouseupListener() : onClickOutside(event);
164
108
  }
165
- }, {
166
- key: "componentWillUnmount",
167
- value: function componentWillUnmount() {
168
- this.removeMouseupListener();
169
- }
170
- }, {
171
- key: "render",
172
- value: function render() {
173
- var _this$props3 = this.props,
174
- children = _this$props3.children,
175
- clickOutsideDisables = _this$props3.clickOutsideDisables,
176
- disabled = _this$props3.disabled,
177
- returnFocus = _this$props3.returnFocus,
178
- noIsolation = _this$props3.noIsolation,
179
- scrollLock = _this$props3.scrollLock,
180
- gapMode = _this$props3.gapMode,
181
- rest = _objectWithoutProperties(_this$props3, _excluded);
182
- var isDisabled = disabled || this.state.hasBeenDisabledByClick;
183
- var focusOnProps = _objectSpread(_objectSpread({
184
- returnFocus: returnFocus,
185
- noIsolation: noIsolation,
186
- enabled: !isDisabled
187
- }, rest), {}, {
188
- onClickOutside: this.handleOutsideClick,
189
- /**
190
- * `scrollLock` should always be unset on FocusOn, as it can prevent scrolling on
191
- * portals (i.e. popovers, comboboxes, dropdown menus, etc.) within modals & flyouts
192
- * @see https://github.com/theKashey/react-focus-on/issues/49
193
- */
194
- scrollLock: false
195
- });
196
- return (0, _react2.jsx)(_reactFocusOn.FocusOn, focusOnProps, children, !isDisabled && scrollLock && (0, _react2.jsx)(_reactRemoveScrollBar.RemoveScrollBar, {
197
- gapMode: gapMode
198
- }));
109
+ }, [clickOutsideDisables, closeOnMouseup, onClickOutside, addMouseupListener]);
110
+ (0, _react.useEffect)(function () {
111
+ setInitialFocus(initialFocus);
112
+ // eslint-disable-next-line react-hooks/exhaustive-deps
113
+ }, []);
114
+ (0, _services.useUpdateEffect)(function () {
115
+ if (!disabled) {
116
+ setHasBeenDisabledByClick(false);
199
117
  }
200
- }]);
201
- }(_react.Component);
202
- _defineProperty(EuiFocusTrapClass, "defaultProps", {
203
- clickOutsideDisables: false,
204
- disabled: false,
205
- returnFocus: true,
206
- noIsolation: true,
207
- scrollLock: false,
208
- crossFrame: false,
209
- gapMode: 'padding' // EUI defaults to padding because Kibana's body/layout CSS ignores `margin`
210
- });
211
- EuiFocusTrapClass.propTypes = {
118
+ }, [disabled]);
119
+
120
+ // listener cleanup on unmount
121
+ (0, _react.useEffect)(function () {
122
+ return function () {
123
+ return removeMouseupListener();
124
+ };
125
+ }, [removeMouseupListener]);
126
+ var focusOnProps = _objectSpread(_objectSpread({
127
+ returnFocus: returnFocus,
128
+ noIsolation: noIsolation,
129
+ initialFocus: initialFocus,
130
+ crossFrame: crossFrame,
131
+ enabled: !isDisabled
132
+ }, rest), {}, {
133
+ onClickOutside: handleOutsideClick,
134
+ /**
135
+ * `scrollLock` should always be unset on FocusOn, as it can prevent scrolling on
136
+ * portals (i.e. popovers, comboboxes, dropdown menus, etc.) within modals & flyouts
137
+ * @see https://github.com/theKashey/react-focus-on/issues/49
138
+ */
139
+ scrollLock: false
140
+ });
141
+ return (0, _react2.jsx)(_reactFocusOn.FocusOn, focusOnProps, children, !isDisabled && scrollLock && (0, _react2.jsx)(_reactRemoveScrollBar.RemoveScrollBar, {
142
+ gapMode: gapMode
143
+ }));
144
+ };
145
+ EuiFocusTrap.propTypes = {
212
146
  // For some reason, Storybook doesn't register these props if they're Pick<>'d
213
147
  className: _propTypes.default.string,
214
148
  css: _propTypes.default.any,
@@ -5,20 +5,12 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.useMutationObserver = exports.EuiMutationObserver = void 0;
7
7
  var _react = require("react");
8
- var _observer = require("../observer");
8
+ var _propTypes = _interopRequireDefault(require("prop-types"));
9
+ var _use_observer = require("../use_observer");
10
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
9
11
  function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
10
12
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
11
13
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
12
- function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
13
- function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
14
- function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
15
- function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
16
- function _possibleConstructorReturn(t, e) { if (e && ("object" == _typeof(e) || "function" == typeof e)) return e; if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined"); return _assertThisInitialized(t); }
17
- function _assertThisInitialized(e) { if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return e; }
18
- function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
19
- function _getPrototypeOf(t) { return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, _getPrototypeOf(t); }
20
- function _inherits(t, e) { if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function"); t.prototype = Object.create(e && e.prototype, { constructor: { value: t, writable: !0, configurable: !0 } }), Object.defineProperty(t, "prototype", { writable: !1 }), e && _setPrototypeOf(t, e); }
21
- function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); }
22
14
  function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
23
15
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
24
16
  function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } /*
@@ -28,29 +20,35 @@ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e
28
20
  * in compliance with, at your election, the Elastic License 2.0 or the Server
29
21
  * Side Public License, v 1.
30
22
  */
31
- var EuiMutationObserver = exports.EuiMutationObserver = /*#__PURE__*/function (_EuiObserver) {
32
- function EuiMutationObserver() {
33
- var _this;
34
- _classCallCheck(this, EuiMutationObserver);
35
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
36
- args[_key] = arguments[_key];
37
- }
38
- _this = _callSuper(this, EuiMutationObserver, [].concat(args));
39
- _defineProperty(_this, "name", 'EuiMutationObserver');
40
- // the `onMutation` prop may change while the observer is bound, abstracting
41
- // it out into a separate function means the current `onMutation` value is used
42
- _defineProperty(_this, "onMutation", function (records, observer) {
43
- _this.props.onMutation(records, observer);
44
- });
45
- _defineProperty(_this, "beginObserve", function () {
46
- var childNode = _this.childNode;
47
- _this.observer = makeMutationObserver(childNode, _this.props.observerOptions, _this.onMutation);
48
- });
49
- return _this;
50
- }
51
- _inherits(EuiMutationObserver, _EuiObserver);
52
- return _createClass(EuiMutationObserver);
53
- }(_observer.EuiObserver);
23
+ var EuiMutationObserver = exports.EuiMutationObserver = function EuiMutationObserver(_ref) {
24
+ var children = _ref.children,
25
+ onMutation = _ref.onMutation,
26
+ observerOptions = _ref.observerOptions;
27
+ // Store onMutation and observerOptions in refs so the observer callback
28
+ // and setup always use the latest prop values without needing to
29
+ // re-subscribe (which would cause the ref callback to cycle)
30
+ var onMutationRef = (0, _react.useRef)(onMutation);
31
+ onMutationRef.current = onMutation;
32
+ var observerOptionsRef = (0, _react.useRef)(observerOptions);
33
+ observerOptionsRef.current = observerOptions;
34
+ var mutationCallback = (0, _react.useCallback)(function (records, observer) {
35
+ onMutationRef.current(records, observer);
36
+ }, []);
37
+ var beginObserve = (0, _react.useCallback)(function (node) {
38
+ return makeMutationObserver(node, observerOptionsRef.current, mutationCallback);
39
+ }, [mutationCallback]);
40
+ var updateChildNode = (0, _use_observer.useObserver)(beginObserve, 'EuiMutationObserver');
41
+ return children(updateChildNode);
42
+ };
43
+ EuiMutationObserver.propTypes = {
44
+ /**
45
+ * ReactNode to render as this component's content
46
+ */
47
+ children: _propTypes.default.func.isRequired,
48
+ onMutation: _propTypes.default.any.isRequired,
49
+ observerOptions: _propTypes.default.any
50
+ };
51
+ EuiMutationObserver.displayName = 'EuiMutationObserver';
54
52
  var makeMutationObserver = function makeMutationObserver(node, _observerOptions, callback) {
55
53
  // The MutationObserver polyfill used in Kibana (for Jest) implements
56
54
  // an older spec in which specifying `attributeOldValue` or `attributeFilter`