@elastic/eui 116.0.0 → 116.1.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 (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 +2 -2
  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
@@ -15,7 +15,6 @@ import React, { createContext, useState, useCallback, useMemo } from 'react';
15
15
  import classNames from 'classnames';
16
16
  import { keys, useEuiMemoizedStyles } from '../../../../services';
17
17
  import { EuiWrappingPopover } from '../../../popover';
18
- import { euiDataGridVariables } from '../../data_grid.styles';
19
18
  import { euiDataGridCellPopoverStyles } from './data_grid_cell_popover.styles';
20
19
  export var DataGridCellPopoverContext = /*#__PURE__*/createContext({
21
20
  popoverIsOpen: false,
@@ -120,14 +119,19 @@ export var useCellPopover = function useCellPopover() {
120
119
  };
121
120
  }, [popoverIsOpen, closeCellPopover, openCellPopover, cellLocation]);
122
121
  var styles = useEuiMemoizedStyles(euiDataGridCellPopoverStyles);
123
- var _useEuiMemoizedStyles = useEuiMemoizedStyles(euiDataGridVariables),
124
- levels = _useEuiMemoizedStyles.levels;
125
122
  var cellPopover = useMemo(function () {
126
123
  var _cellPopoverProps$pan, _cell$offsetWidth;
127
124
  if (!popoverIsOpen || !popoverAnchor) return null;
128
125
  var cell = popoverAnchor.closest('.euiDataGridRowCell');
129
126
 
130
- // Note that this popover is rendered once at the top grid level, rather than one popover per cell
127
+ // Note that this popover is rendered once at the top grid level, rather than one popover per cell.
128
+ //
129
+ // We intentionally do NOT pass `zIndex` here. Letting `EuiPopover` derive the
130
+ // panel's z-index from the anchor's stacking context (`getElementZIndex(button) + 2000`)
131
+ // keeps cell popovers above their host flyout — including when sibling/nested
132
+ // flyouts push the host's z-index above `levels.header`. See
133
+ // https://github.com/elastic/eui/issues/8801. Consumers that need a fixed
134
+ // value can still override via `setCellPopoverProps({ zIndex })`.
131
135
  return ___EmotionJSX(EuiWrappingPopover, _extends({
132
136
  isOpen: popoverIsOpen,
133
137
  display: "block",
@@ -136,8 +140,7 @@ export var useCellPopover = function useCellPopover() {
136
140
  ,
137
141
  panelPaddingSize: "s",
138
142
  anchorPosition: popoverAnchorPosition,
139
- repositionToCrossAxis: false,
140
- zIndex: levels.cellPopover
143
+ repositionToCrossAxis: false
141
144
  }, cellPopoverProps, {
142
145
  focusTrapProps: {
143
146
  onClickOutside: onClickOutside,
@@ -157,7 +160,7 @@ export var useCellPopover = function useCellPopover() {
157
160
  button: popoverAnchor,
158
161
  closePopover: closeCellPopover
159
162
  }), popoverContent);
160
- }, [styles, levels.cellPopover, popoverIsOpen, popoverAnchor, popoverContent, cellPopoverProps, closeCellPopover, onClickOutside, onKeyDown, popoverAnchorPosition]);
163
+ }, [styles, popoverIsOpen, popoverAnchor, popoverContent, cellPopoverProps, closeCellPopover, onClickOutside, onKeyDown, popoverAnchorPosition]);
161
164
  return useMemo(function () {
162
165
  return {
163
166
  cellPopoverContext: cellPopoverContext,
@@ -29,11 +29,12 @@ export var euiDataGridVariables = function euiDataGridVariables(euiThemeContext)
29
29
  m: euiFontSize(euiThemeContext, 's').fontSize
30
30
  },
31
31
  levels: {
32
- cellPopover: Number(euiTheme.levels.header),
33
- // Same z-index as EuiFlyout mask overlays - cell popovers should be under both modal and flyout overlays
34
- get stickyHeader() {
35
- return this.cellPopover - 1; // Needs to sit above the content + cell focus outlines/actions, but below actual popovers
36
- }
32
+ // Sits above content and cell focus outlines/actions, but below cell
33
+ // expansion popovers. Cell popovers no longer use a fixed z-index they
34
+ // derive theirs from their anchor's stacking context (see
35
+ // data_grid_cell_popover.tsx) so this only needs to clear the grid's
36
+ // own internal layers.
37
+ stickyHeader: Number(euiTheme.levels.header) - 1
37
38
  }
38
39
  };
39
40
  };
@@ -1,15 +1,9 @@
1
- import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
2
- import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
3
- import _createClass from "@babel/runtime/helpers/createClass";
4
- import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
5
- import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
6
- import _inherits from "@babel/runtime/helpers/inherits";
7
1
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
8
- var _excluded = ["children", "clickOutsideDisables", "disabled", "returnFocus", "noIsolation", "scrollLock", "gapMode"];
2
+ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
3
+ import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
4
+ var _excluded = ["children", "disabled", "clickOutsideDisables", "returnFocus", "noIsolation", "crossFrame", "scrollLock", "initialFocus", "gapMode", "closeOnMouseup", "onClickOutside"];
9
5
  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; }
10
6
  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; }
11
- function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
12
- function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
13
7
  /*
14
8
  * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
15
9
  * or more contributor license agreements. Licensed under the Elastic License
@@ -18,128 +12,115 @@ function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.
18
12
  * Side Public License, v 1.
19
13
  */
20
14
 
21
- import React, { Component } from 'react';
15
+ import React, { useState, useEffect, useCallback, useRef } from 'react';
22
16
  import { FocusOn } from 'react-focus-on';
23
17
  import { RemoveScrollBar } from 'react-remove-scroll-bar';
24
- import { findElementBySelectorOrRef } from '../../services';
18
+ import { findElementBySelectorOrRef, useUpdateEffect } from '../../services';
25
19
  import { usePropsWithComponentDefaults } from '../provider/component_defaults';
26
20
  import { jsx as ___EmotionJSX } from "@emotion/react";
27
- export var EuiFocusTrap = function EuiFocusTrap(props) {
28
- var propsWithDefaults = usePropsWithComponentDefaults('EuiFocusTrap', props);
29
- return ___EmotionJSX(EuiFocusTrapClass, propsWithDefaults);
30
- };
31
- var EuiFocusTrapClass = /*#__PURE__*/function (_Component) {
32
- function EuiFocusTrapClass() {
33
- var _this;
34
- _classCallCheck(this, EuiFocusTrapClass);
35
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
36
- args[_key] = arguments[_key];
21
+ export var EuiFocusTrap = function EuiFocusTrap(_props) {
22
+ var props = usePropsWithComponentDefaults('EuiFocusTrap', _props);
23
+ var children = props.children,
24
+ disabled = props.disabled,
25
+ _props$clickOutsideDi = props.clickOutsideDisables,
26
+ clickOutsideDisables = _props$clickOutsideDi === void 0 ? false : _props$clickOutsideDi,
27
+ _props$returnFocus = props.returnFocus,
28
+ returnFocus = _props$returnFocus === void 0 ? true : _props$returnFocus,
29
+ _props$noIsolation = props.noIsolation,
30
+ noIsolation = _props$noIsolation === void 0 ? true : _props$noIsolation,
31
+ _props$crossFrame = props.crossFrame,
32
+ crossFrame = _props$crossFrame === void 0 ? false : _props$crossFrame,
33
+ _props$scrollLock = props.scrollLock,
34
+ scrollLock = _props$scrollLock === void 0 ? false : _props$scrollLock,
35
+ initialFocus = props.initialFocus,
36
+ _props$gapMode = props.gapMode,
37
+ gapMode = _props$gapMode === void 0 ? 'padding' : _props$gapMode,
38
+ closeOnMouseup = props.closeOnMouseup,
39
+ onClickOutside = props.onClickOutside,
40
+ rest = _objectWithoutProperties(props, _excluded);
41
+ var _useState = useState(false),
42
+ _useState2 = _slicedToArray(_useState, 2),
43
+ hasBeenDisabledByClick = _useState2[0],
44
+ setHasBeenDisabledByClick = _useState2[1];
45
+ var isDisabled = disabled || hasBeenDisabledByClick;
46
+
47
+ // Programmatically sets focus on a nested DOM node; optional
48
+ var setInitialFocus = function setInitialFocus(initialFocus) {
49
+ if (!initialFocus) return;
50
+ var node = findElementBySelectorOrRef(initialFocus);
51
+ if (!node) return;
52
+ // `data-autofocus` is part of the 'react-focus-on' API
53
+ node.setAttribute('data-autofocus', 'true');
54
+ };
55
+
56
+ // Stabilize the onClickOutside callback
57
+ var onClickOutsideRef = useRef(onClickOutside);
58
+ onClickOutsideRef.current = onClickOutside;
59
+
60
+ // We use a ref to store the listener to prevent circular dependencies
61
+ // while still ensuring the listeners can properly be cleaned up
62
+ var mouseupListenerRef = useRef(null);
63
+ var removeMouseupListener = useCallback(function () {
64
+ if (mouseupListenerRef.current) {
65
+ document.removeEventListener('mouseup', mouseupListenerRef.current);
66
+ document.removeEventListener('touchend', mouseupListenerRef.current);
67
+ mouseupListenerRef.current = null;
37
68
  }
38
- _this = _callSuper(this, EuiFocusTrapClass, [].concat(args));
39
- _defineProperty(_this, "state", {
40
- hasBeenDisabledByClick: false
41
- });
42
- _defineProperty(_this, "lastInterceptedEvent", null);
43
- _defineProperty(_this, "preventFocusExit", false);
44
- // Programmatically sets focus on a nested DOM node; optional
45
- _defineProperty(_this, "setInitialFocus", function (initialFocus) {
46
- if (!initialFocus) return;
47
- var node = findElementBySelectorOrRef(initialFocus);
48
- if (!node) return;
49
- // `data-autofocus` is part of the 'react-focus-on' API
50
- node.setAttribute('data-autofocus', 'true');
51
- });
52
- _defineProperty(_this, "onMouseupOutside", function (e) {
53
- _this.removeMouseupListener();
69
+ }, []);
70
+ var addMouseupListener = useCallback(function () {
71
+ removeMouseupListener();
72
+ mouseupListenerRef.current = function (e) {
73
+ removeMouseupListener();
54
74
  // Timeout gives precedence to the consumer to initiate close if it has toggle behavior.
55
75
  // Otherwise this event may occur first and the consumer toggle will reopen the flyout.
56
76
  setTimeout(function () {
57
- var _this$props$onClickOu, _this$props;
58
- return (_this$props$onClickOu = (_this$props = _this.props).onClickOutside) === null || _this$props$onClickOu === void 0 ? void 0 : _this$props$onClickOu.call(_this$props, e);
77
+ var _onClickOutsideRef$cu;
78
+ return (_onClickOutsideRef$cu = onClickOutsideRef.current) === null || _onClickOutsideRef$cu === void 0 ? void 0 : _onClickOutsideRef$cu.call(onClickOutsideRef, e);
59
79
  });
60
- });
61
- _defineProperty(_this, "addMouseupListener", function () {
62
- document.addEventListener('mouseup', _this.onMouseupOutside);
63
- document.addEventListener('touchend', _this.onMouseupOutside);
64
- });
65
- _defineProperty(_this, "removeMouseupListener", function () {
66
- document.removeEventListener('mouseup', _this.onMouseupOutside);
67
- document.removeEventListener('touchend', _this.onMouseupOutside);
68
- });
69
- _defineProperty(_this, "handleOutsideClick", function (event) {
70
- var _this$props2 = _this.props,
71
- onClickOutside = _this$props2.onClickOutside,
72
- clickOutsideDisables = _this$props2.clickOutsideDisables,
73
- closeOnMouseup = _this$props2.closeOnMouseup;
74
- if (clickOutsideDisables) {
75
- _this.setState({
76
- hasBeenDisabledByClick: true
77
- });
78
- }
79
- if (onClickOutside) {
80
- closeOnMouseup ? _this.addMouseupListener() : onClickOutside(event);
81
- }
82
- });
83
- return _this;
84
- }
85
- _inherits(EuiFocusTrapClass, _Component);
86
- return _createClass(EuiFocusTrapClass, [{
87
- key: "componentDidMount",
88
- value: function componentDidMount() {
89
- this.setInitialFocus(this.props.initialFocus);
90
- }
91
- }, {
92
- key: "componentDidUpdate",
93
- value: function componentDidUpdate(prevProps) {
94
- if (prevProps.disabled === true && this.props.disabled === false) {
95
- this.setState({
96
- hasBeenDisabledByClick: false
97
- });
98
- }
80
+ };
81
+ document.addEventListener('mouseup', mouseupListenerRef.current);
82
+ document.addEventListener('touchend', mouseupListenerRef.current);
83
+ }, [removeMouseupListener]);
84
+ var handleOutsideClick = useCallback(function (event) {
85
+ if (clickOutsideDisables) {
86
+ setHasBeenDisabledByClick(true);
99
87
  }
100
- }, {
101
- key: "componentWillUnmount",
102
- value: function componentWillUnmount() {
103
- this.removeMouseupListener();
88
+ if (onClickOutside) {
89
+ closeOnMouseup ? addMouseupListener() : onClickOutside(event);
104
90
  }
105
- }, {
106
- key: "render",
107
- value: function render() {
108
- var _this$props3 = this.props,
109
- children = _this$props3.children,
110
- clickOutsideDisables = _this$props3.clickOutsideDisables,
111
- disabled = _this$props3.disabled,
112
- returnFocus = _this$props3.returnFocus,
113
- noIsolation = _this$props3.noIsolation,
114
- scrollLock = _this$props3.scrollLock,
115
- gapMode = _this$props3.gapMode,
116
- rest = _objectWithoutProperties(_this$props3, _excluded);
117
- var isDisabled = disabled || this.state.hasBeenDisabledByClick;
118
- var focusOnProps = _objectSpread(_objectSpread({
119
- returnFocus: returnFocus,
120
- noIsolation: noIsolation,
121
- enabled: !isDisabled
122
- }, rest), {}, {
123
- onClickOutside: this.handleOutsideClick,
124
- /**
125
- * `scrollLock` should always be unset on FocusOn, as it can prevent scrolling on
126
- * portals (i.e. popovers, comboboxes, dropdown menus, etc.) within modals & flyouts
127
- * @see https://github.com/theKashey/react-focus-on/issues/49
128
- */
129
- scrollLock: false
130
- });
131
- return ___EmotionJSX(FocusOn, focusOnProps, children, !isDisabled && scrollLock && ___EmotionJSX(RemoveScrollBar, {
132
- gapMode: gapMode
133
- }));
91
+ }, [clickOutsideDisables, closeOnMouseup, onClickOutside, addMouseupListener]);
92
+ useEffect(function () {
93
+ setInitialFocus(initialFocus);
94
+ // eslint-disable-next-line react-hooks/exhaustive-deps
95
+ }, []);
96
+ useUpdateEffect(function () {
97
+ if (!disabled) {
98
+ setHasBeenDisabledByClick(false);
134
99
  }
135
- }]);
136
- }(Component);
137
- _defineProperty(EuiFocusTrapClass, "defaultProps", {
138
- clickOutsideDisables: false,
139
- disabled: false,
140
- returnFocus: true,
141
- noIsolation: true,
142
- scrollLock: false,
143
- crossFrame: false,
144
- gapMode: 'padding' // EUI defaults to padding because Kibana's body/layout CSS ignores `margin`
145
- });
100
+ }, [disabled]);
101
+
102
+ // listener cleanup on unmount
103
+ useEffect(function () {
104
+ return function () {
105
+ return removeMouseupListener();
106
+ };
107
+ }, [removeMouseupListener]);
108
+ var focusOnProps = _objectSpread(_objectSpread({
109
+ returnFocus: returnFocus,
110
+ noIsolation: noIsolation,
111
+ initialFocus: initialFocus,
112
+ crossFrame: crossFrame,
113
+ enabled: !isDisabled
114
+ }, rest), {}, {
115
+ onClickOutside: handleOutsideClick,
116
+ /**
117
+ * `scrollLock` should always be unset on FocusOn, as it can prevent scrolling on
118
+ * portals (i.e. popovers, comboboxes, dropdown menus, etc.) within modals & flyouts
119
+ * @see https://github.com/theKashey/react-focus-on/issues/49
120
+ */
121
+ scrollLock: false
122
+ });
123
+ return ___EmotionJSX(FocusOn, focusOnProps, children, !isDisabled && scrollLock && ___EmotionJSX(RemoveScrollBar, {
124
+ gapMode: gapMode
125
+ }));
126
+ };
@@ -1,13 +1,6 @@
1
- import _createClass from "@babel/runtime/helpers/createClass";
2
- import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
3
- import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
4
- import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
5
- import _inherits from "@babel/runtime/helpers/inherits";
6
1
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
7
2
  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; }
8
3
  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; }
9
- function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
10
- function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
11
4
  /*
12
5
  * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
13
6
  * or more contributor license agreements. Licensed under the Elastic License
@@ -16,31 +9,29 @@ function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.
16
9
  * Side Public License, v 1.
17
10
  */
18
11
 
19
- import { useEffect } from 'react';
20
- import { EuiObserver } from '../observer';
21
- export var EuiMutationObserver = /*#__PURE__*/function (_EuiObserver) {
22
- function EuiMutationObserver() {
23
- var _this;
24
- _classCallCheck(this, EuiMutationObserver);
25
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
26
- args[_key] = arguments[_key];
27
- }
28
- _this = _callSuper(this, EuiMutationObserver, [].concat(args));
29
- _defineProperty(_this, "name", 'EuiMutationObserver');
30
- // the `onMutation` prop may change while the observer is bound, abstracting
31
- // it out into a separate function means the current `onMutation` value is used
32
- _defineProperty(_this, "onMutation", function (records, observer) {
33
- _this.props.onMutation(records, observer);
34
- });
35
- _defineProperty(_this, "beginObserve", function () {
36
- var childNode = _this.childNode;
37
- _this.observer = makeMutationObserver(childNode, _this.props.observerOptions, _this.onMutation);
38
- });
39
- return _this;
40
- }
41
- _inherits(EuiMutationObserver, _EuiObserver);
42
- return _createClass(EuiMutationObserver);
43
- }(EuiObserver);
12
+ import { useCallback, useEffect, useRef } from 'react';
13
+ import { useObserver } from '../use_observer';
14
+ export var EuiMutationObserver = function EuiMutationObserver(_ref) {
15
+ var children = _ref.children,
16
+ onMutation = _ref.onMutation,
17
+ observerOptions = _ref.observerOptions;
18
+ // Store onMutation and observerOptions in refs so the observer callback
19
+ // and setup always use the latest prop values without needing to
20
+ // re-subscribe (which would cause the ref callback to cycle)
21
+ var onMutationRef = useRef(onMutation);
22
+ onMutationRef.current = onMutation;
23
+ var observerOptionsRef = useRef(observerOptions);
24
+ observerOptionsRef.current = observerOptions;
25
+ var mutationCallback = useCallback(function (records, observer) {
26
+ onMutationRef.current(records, observer);
27
+ }, []);
28
+ var beginObserve = useCallback(function (node) {
29
+ return makeMutationObserver(node, observerOptionsRef.current, mutationCallback);
30
+ }, [mutationCallback]);
31
+ var updateChildNode = useObserver(beginObserve, 'EuiMutationObserver');
32
+ return children(updateChildNode);
33
+ };
34
+ EuiMutationObserver.displayName = 'EuiMutationObserver';
44
35
  var makeMutationObserver = function makeMutationObserver(node, _observerOptions, callback) {
45
36
  // The MutationObserver polyfill used in Kibana (for Jest) implements
46
37
  // an older spec in which specifying `attributeOldValue` or `attributeFilter`
@@ -1,12 +1,4 @@
1
1
  import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
- import _createClass from "@babel/runtime/helpers/createClass";
3
- import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
4
- import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
5
- import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
6
- import _inherits from "@babel/runtime/helpers/inherits";
7
- import _defineProperty from "@babel/runtime/helpers/defineProperty";
8
- function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
9
- function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
10
2
  /*
11
3
  * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
12
4
  * or more contributor license agreements. Licensed under the Elastic License
@@ -16,52 +8,44 @@ function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.
16
8
  */
17
9
 
18
10
  import { useCallback, useEffect, useRef, useState } from 'react';
19
- import { EuiObserver } from '../observer';
11
+ import { useObserver } from '../use_observer';
20
12
  export var hasResizeObserver = typeof window !== 'undefined' && typeof window.ResizeObserver !== 'undefined';
21
- export var EuiResizeObserver = /*#__PURE__*/function (_EuiObserver) {
22
- function EuiResizeObserver() {
23
- var _this;
24
- _classCallCheck(this, EuiResizeObserver);
25
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
26
- args[_key] = arguments[_key];
27
- }
28
- _this = _callSuper(this, EuiResizeObserver, [].concat(args));
29
- _defineProperty(_this, "name", 'EuiResizeObserver');
30
- _defineProperty(_this, "state", {
31
- height: 0,
32
- width: 0
33
- });
34
- _defineProperty(_this, "onResize", function (_ref) {
35
- var _ref2 = _slicedToArray(_ref, 1),
36
- entry = _ref2[0];
37
- var _entry$borderBoxSize$ = entry.borderBoxSize[0],
38
- width = _entry$borderBoxSize$.inlineSize,
39
- height = _entry$borderBoxSize$.blockSize;
13
+ export var EuiResizeObserver = function EuiResizeObserver(_ref) {
14
+ var children = _ref.children,
15
+ onResize = _ref.onResize;
16
+ var onResizeRef = useRef(onResize);
17
+ onResizeRef.current = onResize;
18
+ var sizeRef = useRef({
19
+ height: 0,
20
+ width: 0
21
+ });
22
+ var resizeCallback = useCallback(function (_ref2) {
23
+ var _ref3 = _slicedToArray(_ref2, 1),
24
+ entry = _ref3[0];
25
+ var _entry$borderBoxSize$ = entry.borderBoxSize[0],
26
+ width = _entry$borderBoxSize$.inlineSize,
27
+ height = _entry$borderBoxSize$.blockSize;
40
28
 
41
- // Check for actual resize event
42
- if (_this.state.height === height && _this.state.width === width) {
43
- return;
44
- }
45
- _this.props.onResize({
46
- height: height,
47
- width: width
48
- });
49
- _this.setState({
50
- height: height,
51
- width: width
52
- });
53
- });
54
- _defineProperty(_this, "beginObserve", function () {
55
- // The superclass checks that childNode is not null before invoking
56
- // beginObserve()
57
- var childNode = _this.childNode;
58
- _this.observer = makeResizeObserver(childNode, _this.onResize);
29
+ // Check for actual resize event
30
+ if (sizeRef.current.height === height && sizeRef.current.width === width) {
31
+ return;
32
+ }
33
+ sizeRef.current = {
34
+ height: height,
35
+ width: width
36
+ };
37
+ onResizeRef.current({
38
+ height: height,
39
+ width: width
59
40
  });
60
- return _this;
61
- }
62
- _inherits(EuiResizeObserver, _EuiObserver);
63
- return _createClass(EuiResizeObserver);
64
- }(EuiObserver);
41
+ }, []);
42
+ var beginObserve = useCallback(function (node) {
43
+ return makeResizeObserver(node, resizeCallback);
44
+ }, [resizeCallback]);
45
+ var updateChildNode = useObserver(beginObserve, 'EuiResizeObserver');
46
+ return children(updateChildNode);
47
+ };
48
+ EuiResizeObserver.displayName = 'EuiResizeObserver';
65
49
  var makeResizeObserver = function makeResizeObserver(node, callback) {
66
50
  var observer;
67
51
  if (hasResizeObserver) {
@@ -92,9 +76,9 @@ export var useResizeObserver = function useResizeObserver(container, dimension)
92
76
  }, [dimension]);
93
77
  useEffect(function () {
94
78
  if (container != null) {
95
- var observer = makeResizeObserver(container, function (_ref3) {
96
- var _ref4 = _slicedToArray(_ref3, 1),
97
- entry = _ref4[0];
79
+ var observer = makeResizeObserver(container, function (_ref4) {
80
+ var _ref5 = _slicedToArray(_ref4, 1),
81
+ entry = _ref5[0];
98
82
  var _entry$borderBoxSize$2 = entry.borderBoxSize[0],
99
83
  inlineSize = _entry$borderBoxSize$2.inlineSize,
100
84
  blockSize = _entry$borderBoxSize$2.blockSize;
@@ -0,0 +1,62 @@
1
+ /*
2
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3
+ * or more contributor license agreements. Licensed under the Elastic License
4
+ * 2.0 and the Server Side Public License, v 1; you may not use this file except
5
+ * in compliance with, at your election, the Elastic License 2.0 or the Server
6
+ * Side Public License, v 1.
7
+ */
8
+
9
+ import { useCallback, useEffect, useRef } from 'react';
10
+ /**
11
+ * A shared custom hook that provides a pattern for observing DOM nodes
12
+ * via browser observer APIs. Used by `EuiResizeObserver` and `EuiMutationObserver`.
13
+ *
14
+ * @param beginObserve - A callback that receives the target DOM element and should
15
+ * create and return the observer instance (e.g., `ResizeObserver`).
16
+ * @param componentName - Optional name used in error messages when no ref is
17
+ * attached on mount, mirroring the guard previously in `EuiObserver`.
18
+ */
19
+ export var useObserver = function useObserver(beginObserve) {
20
+ var componentName = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'useObserver';
21
+ var childNodeRef = useRef(null);
22
+ var observerRef = useRef(null);
23
+
24
+ // Store beginObserve in a ref so the ref callback doesn't cycle
25
+ var beginObserveRef = useRef(beginObserve);
26
+ beginObserveRef.current = beginObserve;
27
+
28
+ // Store componentName in a ref so the mount-only effect can access the
29
+ // latest value without needing it as a dependency.
30
+ var componentNameRef = useRef(componentName);
31
+ componentNameRef.current = componentName;
32
+
33
+ // Guard: throw if the ref callback was never called (no element attached),
34
+ // mirroring the check previously in EuiObserver.componentDidMount.
35
+ // Also cleans up the observer on unmount.
36
+ // Empty deps: run only on mount/unmount — componentName is only used for the
37
+ // error message and changing it must not disconnect/re-connect the observer.
38
+ useEffect(function () {
39
+ if (childNodeRef.current == null) {
40
+ throw new Error("".concat(componentNameRef.current, " did not receive a ref"));
41
+ }
42
+ return function () {
43
+ var _observerRef$current;
44
+ (_observerRef$current = observerRef.current) === null || _observerRef$current === void 0 || _observerRef$current.disconnect();
45
+ };
46
+ }, []);
47
+ var updateChildNode = useCallback(function (ref) {
48
+ if (childNodeRef.current === ref) return; // node hasn't changed
49
+
50
+ // if there's an existing observer disconnect it
51
+ if (observerRef.current != null) {
52
+ observerRef.current.disconnect();
53
+ observerRef.current = null;
54
+ }
55
+ childNodeRef.current = ref;
56
+ if (childNodeRef.current != null) {
57
+ var _beginObserveRef$curr;
58
+ observerRef.current = (_beginObserveRef$curr = beginObserveRef.current(childNodeRef.current)) !== null && _beginObserveRef$curr !== void 0 ? _beginObserveRef$curr : null;
59
+ }
60
+ }, []);
61
+ return updateChildNode;
62
+ };
@@ -1,7 +1,7 @@
1
1
  import _extends from "@babel/runtime/helpers/extends";
2
2
  import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
3
3
  import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
4
- var _excluded = ["children", "className", "anchorClassName", "anchorProps", "content", "title", "display", "repositionOnScroll", "disableScreenReaderOutput", "position", "offset", "id", "onMouseOut"];
4
+ var _excluded = ["children", "className", "anchorClassName", "anchorProps", "content", "title", "display", "repositionOnScroll", "disableScreenReaderOutput", "position", "offset", "id", "onMouseOut", "onBlur"];
5
5
  /*
6
6
  * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
7
7
  * or more contributor license agreements. Licensed under the Elastic License
@@ -66,6 +66,7 @@ export var EuiToolTip = /*#__PURE__*/forwardRef(function (_ref, ref) {
66
66
  offset = _ref.offset,
67
67
  idProp = _ref.id,
68
68
  onMouseOutProp = _ref.onMouseOut,
69
+ onBlurProp = _ref.onBlur,
69
70
  rest = _objectWithoutProperties(_ref, _excluded);
70
71
  var componentDefaultsContext = useContext(EuiComponentDefaultsContext);
71
72
  var _useState = useState(false),
@@ -212,7 +213,8 @@ export var EuiToolTip = /*#__PURE__*/forwardRef(function (_ref, ref) {
212
213
  var onBlur = useCallback(function () {
213
214
  setHasFocus(false);
214
215
  hideToolTip();
215
- }, [hideToolTip]);
216
+ onBlurProp === null || onBlurProp === void 0 || onBlurProp();
217
+ }, [hideToolTip, onBlurProp]);
216
218
  var onEscapeKey = useCallback(function (event) {
217
219
  if (event.key === keys.ESCAPE) {
218
220
  // when the tooltip is only visual, we don't want it to add an additional key stop