@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
@@ -1,22 +1,18 @@
1
- var _excluded = ["children", "clickOutsideDisables", "disabled", "returnFocus", "noIsolation", "scrollLock", "gapMode"];
2
1
  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); }
2
+ var _excluded = ["children", "disabled", "clickOutsideDisables", "returnFocus", "noIsolation", "crossFrame", "scrollLock", "initialFocus", "gapMode", "closeOnMouseup", "onClickOutside"];
3
3
  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; }
4
4
  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; }
5
- 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; }
6
- 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; }
7
- function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
8
- 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); } }
9
- function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
10
- function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
11
- 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); }
12
- function _assertThisInitialized(e) { if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return e; }
13
- function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
14
- function _getPrototypeOf(t) { return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, _getPrototypeOf(t); }
15
- 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); }
16
- function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); }
17
5
  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; }
18
6
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
19
7
  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); }
8
+ function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
9
+ 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."); }
10
+ 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; } }
11
+ 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; }
12
+ 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; } }
13
+ function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
14
+ 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; }
15
+ 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; }
20
16
  /*
21
17
  * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
22
18
  * or more contributor license agreements. Licensed under the Elastic License
@@ -25,183 +21,120 @@ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e
25
21
  * Side Public License, v 1.
26
22
  */
27
23
 
28
- import React, { Component } from 'react';
24
+ import React, { useState, useEffect, useCallback, useRef } from 'react';
29
25
  import PropTypes from "prop-types";
30
26
  import { FocusOn } from 'react-focus-on';
31
27
  import { RemoveScrollBar } from 'react-remove-scroll-bar';
32
- import { findElementBySelectorOrRef } from '../../services';
28
+ import { findElementBySelectorOrRef, useUpdateEffect } from '../../services';
33
29
  import { usePropsWithComponentDefaults } from '../provider/component_defaults';
34
30
  import { jsx as ___EmotionJSX } from "@emotion/react";
35
- export var EuiFocusTrap = function EuiFocusTrap(props) {
36
- var propsWithDefaults = usePropsWithComponentDefaults('EuiFocusTrap', props);
37
- return ___EmotionJSX(EuiFocusTrapClass, propsWithDefaults);
38
- };
39
- EuiFocusTrap.propTypes = {
40
- // For some reason, Storybook doesn't register these props if they're Pick<>'d
41
- className: PropTypes.string,
42
- css: PropTypes.any,
43
- style: PropTypes.any,
44
- /**
45
- * @default false
46
- */
47
- disabled: PropTypes.bool,
48
- /**
49
- * Whether `onClickOutside` should be called on mouseup instead of mousedown.
50
- * This flag can be used to prevent conflicts with outside toggle buttons by delaying the closing click callback.
51
- */
52
- closeOnMouseup: PropTypes.bool,
53
- /**
54
- * Clicking outside the trap area will disable the trap
55
- * @default false
56
- */
57
- clickOutsideDisables: PropTypes.bool,
58
- /**
59
- * Reference to element that will get focus when the trap is initiated
60
- */
61
- initialFocus: PropTypes.any,
62
- /**
63
- * if `scrollLock` is set to true, the body's scrollbar width will be preserved on lock
64
- * via the `gapMode` CSS property. Depending on your custom CSS, you may prefer to use
65
- * `margin` instead of `padding`.
66
- * @default padding
67
- */
68
- gapMode: PropTypes.oneOf(["padding", "margin"]),
69
- /**
70
- * Configures focus trapping between iframes.
71
- * By default, EuiFocusTrap allows focus to leave iframes and move to elements outside of it.
72
- * Set to `true` if you want focus to remain trapped within the iframe.
73
- * @default false
74
- */
75
- crossFrame: PropTypes.any,
76
- /**
77
- * @default false
78
- */
79
- scrollLock: PropTypes.any,
80
- /**
81
- * @default true
82
- */
83
- noIsolation: PropTypes.any,
84
- /**
85
- * @default true
86
- */
87
- returnFocus: PropTypes.any
88
- };
89
- var EuiFocusTrapClass = /*#__PURE__*/function (_Component) {
90
- function EuiFocusTrapClass() {
91
- var _this;
92
- _classCallCheck(this, EuiFocusTrapClass);
93
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
94
- args[_key] = arguments[_key];
31
+ export var EuiFocusTrap = function EuiFocusTrap(_props) {
32
+ var props = usePropsWithComponentDefaults('EuiFocusTrap', _props);
33
+ var children = props.children,
34
+ disabled = props.disabled,
35
+ _props$clickOutsideDi = props.clickOutsideDisables,
36
+ clickOutsideDisables = _props$clickOutsideDi === void 0 ? false : _props$clickOutsideDi,
37
+ _props$returnFocus = props.returnFocus,
38
+ returnFocus = _props$returnFocus === void 0 ? true : _props$returnFocus,
39
+ _props$noIsolation = props.noIsolation,
40
+ noIsolation = _props$noIsolation === void 0 ? true : _props$noIsolation,
41
+ _props$crossFrame = props.crossFrame,
42
+ crossFrame = _props$crossFrame === void 0 ? false : _props$crossFrame,
43
+ _props$scrollLock = props.scrollLock,
44
+ scrollLock = _props$scrollLock === void 0 ? false : _props$scrollLock,
45
+ initialFocus = props.initialFocus,
46
+ _props$gapMode = props.gapMode,
47
+ gapMode = _props$gapMode === void 0 ? 'padding' : _props$gapMode,
48
+ closeOnMouseup = props.closeOnMouseup,
49
+ onClickOutside = props.onClickOutside,
50
+ rest = _objectWithoutProperties(props, _excluded);
51
+ var _useState = useState(false),
52
+ _useState2 = _slicedToArray(_useState, 2),
53
+ hasBeenDisabledByClick = _useState2[0],
54
+ setHasBeenDisabledByClick = _useState2[1];
55
+ var isDisabled = disabled || hasBeenDisabledByClick;
56
+
57
+ // Programmatically sets focus on a nested DOM node; optional
58
+ var setInitialFocus = function setInitialFocus(initialFocus) {
59
+ if (!initialFocus) return;
60
+ var node = findElementBySelectorOrRef(initialFocus);
61
+ if (!node) return;
62
+ // `data-autofocus` is part of the 'react-focus-on' API
63
+ node.setAttribute('data-autofocus', 'true');
64
+ };
65
+
66
+ // Stabilize the onClickOutside callback
67
+ var onClickOutsideRef = useRef(onClickOutside);
68
+ onClickOutsideRef.current = onClickOutside;
69
+
70
+ // We use a ref to store the listener to prevent circular dependencies
71
+ // while still ensuring the listeners can properly be cleaned up
72
+ var mouseupListenerRef = useRef(null);
73
+ var removeMouseupListener = useCallback(function () {
74
+ if (mouseupListenerRef.current) {
75
+ document.removeEventListener('mouseup', mouseupListenerRef.current);
76
+ document.removeEventListener('touchend', mouseupListenerRef.current);
77
+ mouseupListenerRef.current = null;
95
78
  }
96
- _this = _callSuper(this, EuiFocusTrapClass, [].concat(args));
97
- _defineProperty(_this, "state", {
98
- hasBeenDisabledByClick: false
99
- });
100
- _defineProperty(_this, "lastInterceptedEvent", null);
101
- _defineProperty(_this, "preventFocusExit", false);
102
- // Programmatically sets focus on a nested DOM node; optional
103
- _defineProperty(_this, "setInitialFocus", function (initialFocus) {
104
- if (!initialFocus) return;
105
- var node = findElementBySelectorOrRef(initialFocus);
106
- if (!node) return;
107
- // `data-autofocus` is part of the 'react-focus-on' API
108
- node.setAttribute('data-autofocus', 'true');
109
- });
110
- _defineProperty(_this, "onMouseupOutside", function (e) {
111
- _this.removeMouseupListener();
79
+ }, []);
80
+ var addMouseupListener = useCallback(function () {
81
+ removeMouseupListener();
82
+ mouseupListenerRef.current = function (e) {
83
+ removeMouseupListener();
112
84
  // Timeout gives precedence to the consumer to initiate close if it has toggle behavior.
113
85
  // Otherwise this event may occur first and the consumer toggle will reopen the flyout.
114
86
  setTimeout(function () {
115
- var _this$props$onClickOu, _this$props;
116
- return (_this$props$onClickOu = (_this$props = _this.props).onClickOutside) === null || _this$props$onClickOu === void 0 ? void 0 : _this$props$onClickOu.call(_this$props, e);
87
+ var _onClickOutsideRef$cu;
88
+ return (_onClickOutsideRef$cu = onClickOutsideRef.current) === null || _onClickOutsideRef$cu === void 0 ? void 0 : _onClickOutsideRef$cu.call(onClickOutsideRef, e);
117
89
  });
118
- });
119
- _defineProperty(_this, "addMouseupListener", function () {
120
- document.addEventListener('mouseup', _this.onMouseupOutside);
121
- document.addEventListener('touchend', _this.onMouseupOutside);
122
- });
123
- _defineProperty(_this, "removeMouseupListener", function () {
124
- document.removeEventListener('mouseup', _this.onMouseupOutside);
125
- document.removeEventListener('touchend', _this.onMouseupOutside);
126
- });
127
- _defineProperty(_this, "handleOutsideClick", function (event) {
128
- var _this$props2 = _this.props,
129
- onClickOutside = _this$props2.onClickOutside,
130
- clickOutsideDisables = _this$props2.clickOutsideDisables,
131
- closeOnMouseup = _this$props2.closeOnMouseup;
132
- if (clickOutsideDisables) {
133
- _this.setState({
134
- hasBeenDisabledByClick: true
135
- });
136
- }
137
- if (onClickOutside) {
138
- closeOnMouseup ? _this.addMouseupListener() : onClickOutside(event);
139
- }
140
- });
141
- return _this;
142
- }
143
- _inherits(EuiFocusTrapClass, _Component);
144
- return _createClass(EuiFocusTrapClass, [{
145
- key: "componentDidMount",
146
- value: function componentDidMount() {
147
- this.setInitialFocus(this.props.initialFocus);
90
+ };
91
+ document.addEventListener('mouseup', mouseupListenerRef.current);
92
+ document.addEventListener('touchend', mouseupListenerRef.current);
93
+ }, [removeMouseupListener]);
94
+ var handleOutsideClick = useCallback(function (event) {
95
+ if (clickOutsideDisables) {
96
+ setHasBeenDisabledByClick(true);
148
97
  }
149
- }, {
150
- key: "componentDidUpdate",
151
- value: function componentDidUpdate(prevProps) {
152
- if (prevProps.disabled === true && this.props.disabled === false) {
153
- this.setState({
154
- hasBeenDisabledByClick: false
155
- });
156
- }
98
+ if (onClickOutside) {
99
+ closeOnMouseup ? addMouseupListener() : onClickOutside(event);
157
100
  }
158
- }, {
159
- key: "componentWillUnmount",
160
- value: function componentWillUnmount() {
161
- this.removeMouseupListener();
162
- }
163
- }, {
164
- key: "render",
165
- value: function render() {
166
- var _this$props3 = this.props,
167
- children = _this$props3.children,
168
- clickOutsideDisables = _this$props3.clickOutsideDisables,
169
- disabled = _this$props3.disabled,
170
- returnFocus = _this$props3.returnFocus,
171
- noIsolation = _this$props3.noIsolation,
172
- scrollLock = _this$props3.scrollLock,
173
- gapMode = _this$props3.gapMode,
174
- rest = _objectWithoutProperties(_this$props3, _excluded);
175
- var isDisabled = disabled || this.state.hasBeenDisabledByClick;
176
- var focusOnProps = _objectSpread(_objectSpread({
177
- returnFocus: returnFocus,
178
- noIsolation: noIsolation,
179
- enabled: !isDisabled
180
- }, rest), {}, {
181
- onClickOutside: this.handleOutsideClick,
182
- /**
183
- * `scrollLock` should always be unset on FocusOn, as it can prevent scrolling on
184
- * portals (i.e. popovers, comboboxes, dropdown menus, etc.) within modals & flyouts
185
- * @see https://github.com/theKashey/react-focus-on/issues/49
186
- */
187
- scrollLock: false
188
- });
189
- return ___EmotionJSX(FocusOn, focusOnProps, children, !isDisabled && scrollLock && ___EmotionJSX(RemoveScrollBar, {
190
- gapMode: gapMode
191
- }));
101
+ }, [clickOutsideDisables, closeOnMouseup, onClickOutside, addMouseupListener]);
102
+ useEffect(function () {
103
+ setInitialFocus(initialFocus);
104
+ // eslint-disable-next-line react-hooks/exhaustive-deps
105
+ }, []);
106
+ useUpdateEffect(function () {
107
+ if (!disabled) {
108
+ setHasBeenDisabledByClick(false);
192
109
  }
193
- }]);
194
- }(Component);
195
- _defineProperty(EuiFocusTrapClass, "defaultProps", {
196
- clickOutsideDisables: false,
197
- disabled: false,
198
- returnFocus: true,
199
- noIsolation: true,
200
- scrollLock: false,
201
- crossFrame: false,
202
- gapMode: 'padding' // EUI defaults to padding because Kibana's body/layout CSS ignores `margin`
203
- });
204
- EuiFocusTrapClass.propTypes = {
110
+ }, [disabled]);
111
+
112
+ // listener cleanup on unmount
113
+ useEffect(function () {
114
+ return function () {
115
+ return removeMouseupListener();
116
+ };
117
+ }, [removeMouseupListener]);
118
+ var focusOnProps = _objectSpread(_objectSpread({
119
+ returnFocus: returnFocus,
120
+ noIsolation: noIsolation,
121
+ initialFocus: initialFocus,
122
+ crossFrame: crossFrame,
123
+ enabled: !isDisabled
124
+ }, rest), {}, {
125
+ onClickOutside: handleOutsideClick,
126
+ /**
127
+ * `scrollLock` should always be unset on FocusOn, as it can prevent scrolling on
128
+ * portals (i.e. popovers, comboboxes, dropdown menus, etc.) within modals & flyouts
129
+ * @see https://github.com/theKashey/react-focus-on/issues/49
130
+ */
131
+ scrollLock: false
132
+ });
133
+ return ___EmotionJSX(FocusOn, focusOnProps, children, !isDisabled && scrollLock && ___EmotionJSX(RemoveScrollBar, {
134
+ gapMode: gapMode
135
+ }));
136
+ };
137
+ EuiFocusTrap.propTypes = {
205
138
  // For some reason, Storybook doesn't register these props if they're Pick<>'d
206
139
  className: PropTypes.string,
207
140
  css: PropTypes.any,
@@ -1,16 +1,6 @@
1
1
  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); }
2
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; }
3
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; }
4
- 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); } }
5
- function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
6
- function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
7
- function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
8
- 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); }
9
- function _assertThisInitialized(e) { if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return e; }
10
- function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
11
- function _getPrototypeOf(t) { return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, _getPrototypeOf(t); }
12
- 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); }
13
- function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); }
14
4
  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; }
15
5
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
16
6
  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); }
@@ -22,31 +12,38 @@ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e
22
12
  * Side Public License, v 1.
23
13
  */
24
14
 
25
- import { useEffect } from 'react';
26
- import { EuiObserver } from '../observer';
27
- export var EuiMutationObserver = /*#__PURE__*/function (_EuiObserver) {
28
- function EuiMutationObserver() {
29
- var _this;
30
- _classCallCheck(this, EuiMutationObserver);
31
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
32
- args[_key] = arguments[_key];
33
- }
34
- _this = _callSuper(this, EuiMutationObserver, [].concat(args));
35
- _defineProperty(_this, "name", 'EuiMutationObserver');
36
- // the `onMutation` prop may change while the observer is bound, abstracting
37
- // it out into a separate function means the current `onMutation` value is used
38
- _defineProperty(_this, "onMutation", function (records, observer) {
39
- _this.props.onMutation(records, observer);
40
- });
41
- _defineProperty(_this, "beginObserve", function () {
42
- var childNode = _this.childNode;
43
- _this.observer = makeMutationObserver(childNode, _this.props.observerOptions, _this.onMutation);
44
- });
45
- return _this;
46
- }
47
- _inherits(EuiMutationObserver, _EuiObserver);
48
- return _createClass(EuiMutationObserver);
49
- }(EuiObserver);
15
+ import { useCallback, useEffect, useRef } from 'react';
16
+ import PropTypes from "prop-types";
17
+ import { useObserver } from '../use_observer';
18
+ export var EuiMutationObserver = function EuiMutationObserver(_ref) {
19
+ var children = _ref.children,
20
+ onMutation = _ref.onMutation,
21
+ observerOptions = _ref.observerOptions;
22
+ // Store onMutation and observerOptions in refs so the observer callback
23
+ // and setup always use the latest prop values without needing to
24
+ // re-subscribe (which would cause the ref callback to cycle)
25
+ var onMutationRef = useRef(onMutation);
26
+ onMutationRef.current = onMutation;
27
+ var observerOptionsRef = useRef(observerOptions);
28
+ observerOptionsRef.current = observerOptions;
29
+ var mutationCallback = useCallback(function (records, observer) {
30
+ onMutationRef.current(records, observer);
31
+ }, []);
32
+ var beginObserve = useCallback(function (node) {
33
+ return makeMutationObserver(node, observerOptionsRef.current, mutationCallback);
34
+ }, [mutationCallback]);
35
+ var updateChildNode = useObserver(beginObserve, 'EuiMutationObserver');
36
+ return children(updateChildNode);
37
+ };
38
+ EuiMutationObserver.propTypes = {
39
+ /**
40
+ * ReactNode to render as this component's content
41
+ */
42
+ children: PropTypes.func.isRequired,
43
+ onMutation: PropTypes.any.isRequired,
44
+ observerOptions: PropTypes.any
45
+ };
46
+ EuiMutationObserver.displayName = 'EuiMutationObserver';
50
47
  var makeMutationObserver = function makeMutationObserver(node, _observerOptions, callback) {
51
48
  // The MutationObserver polyfill used in Kibana (for Jest) implements
52
49
  // an older spec in which specifying `attributeOldValue` or `attributeFilter`
@@ -1,23 +1,9 @@
1
- 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); }
2
1
  function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
3
2
  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."); }
4
3
  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; } }
5
4
  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; }
6
5
  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; } }
7
6
  function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
8
- 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); } }
9
- function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
10
- function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
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 _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); }
13
- function _assertThisInitialized(e) { if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return e; }
14
- function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
15
- function _getPrototypeOf(t) { return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, _getPrototypeOf(t); }
16
- 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); }
17
- function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); }
18
- 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; }
19
- function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
20
- 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); }
21
7
  /*
22
8
  * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
23
9
  * or more contributor license agreements. Licensed under the Elastic License
@@ -27,52 +13,52 @@ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e
27
13
  */
28
14
 
29
15
  import { useCallback, useEffect, useRef, useState } from 'react';
30
- import { EuiObserver } from '../observer';
16
+ import PropTypes from "prop-types";
17
+ import { useObserver } from '../use_observer';
31
18
  export var hasResizeObserver = typeof window !== 'undefined' && typeof window.ResizeObserver !== 'undefined';
32
- export var EuiResizeObserver = /*#__PURE__*/function (_EuiObserver) {
33
- function EuiResizeObserver() {
34
- var _this;
35
- _classCallCheck(this, EuiResizeObserver);
36
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
37
- args[_key] = arguments[_key];
38
- }
39
- _this = _callSuper(this, EuiResizeObserver, [].concat(args));
40
- _defineProperty(_this, "name", 'EuiResizeObserver');
41
- _defineProperty(_this, "state", {
42
- height: 0,
43
- width: 0
44
- });
45
- _defineProperty(_this, "onResize", function (_ref) {
46
- var _ref2 = _slicedToArray(_ref, 1),
47
- entry = _ref2[0];
48
- var _entry$borderBoxSize$ = entry.borderBoxSize[0],
49
- width = _entry$borderBoxSize$.inlineSize,
50
- height = _entry$borderBoxSize$.blockSize;
19
+ export var EuiResizeObserver = function EuiResizeObserver(_ref) {
20
+ var children = _ref.children,
21
+ onResize = _ref.onResize;
22
+ var onResizeRef = useRef(onResize);
23
+ onResizeRef.current = onResize;
24
+ var sizeRef = useRef({
25
+ height: 0,
26
+ width: 0
27
+ });
28
+ var resizeCallback = useCallback(function (_ref2) {
29
+ var _ref3 = _slicedToArray(_ref2, 1),
30
+ entry = _ref3[0];
31
+ var _entry$borderBoxSize$ = entry.borderBoxSize[0],
32
+ width = _entry$borderBoxSize$.inlineSize,
33
+ height = _entry$borderBoxSize$.blockSize;
51
34
 
52
- // Check for actual resize event
53
- if (_this.state.height === height && _this.state.width === width) {
54
- return;
55
- }
56
- _this.props.onResize({
57
- height: height,
58
- width: width
59
- });
60
- _this.setState({
61
- height: height,
62
- width: width
63
- });
64
- });
65
- _defineProperty(_this, "beginObserve", function () {
66
- // The superclass checks that childNode is not null before invoking
67
- // beginObserve()
68
- var childNode = _this.childNode;
69
- _this.observer = makeResizeObserver(childNode, _this.onResize);
35
+ // Check for actual resize event
36
+ if (sizeRef.current.height === height && sizeRef.current.width === width) {
37
+ return;
38
+ }
39
+ sizeRef.current = {
40
+ height: height,
41
+ width: width
42
+ };
43
+ onResizeRef.current({
44
+ height: height,
45
+ width: width
70
46
  });
71
- return _this;
72
- }
73
- _inherits(EuiResizeObserver, _EuiObserver);
74
- return _createClass(EuiResizeObserver);
75
- }(EuiObserver);
47
+ }, []);
48
+ var beginObserve = useCallback(function (node) {
49
+ return makeResizeObserver(node, resizeCallback);
50
+ }, [resizeCallback]);
51
+ var updateChildNode = useObserver(beginObserve, 'EuiResizeObserver');
52
+ return children(updateChildNode);
53
+ };
54
+ EuiResizeObserver.propTypes = {
55
+ /**
56
+ * ReactNode to render as this component's content
57
+ */
58
+ children: PropTypes.func.isRequired,
59
+ onResize: PropTypes.func.isRequired
60
+ };
61
+ EuiResizeObserver.displayName = 'EuiResizeObserver';
76
62
  var makeResizeObserver = function makeResizeObserver(node, callback) {
77
63
  var observer;
78
64
  if (hasResizeObserver) {
@@ -103,9 +89,9 @@ export var useResizeObserver = function useResizeObserver(container, dimension)
103
89
  }, [dimension]);
104
90
  useEffect(function () {
105
91
  if (container != null) {
106
- var observer = makeResizeObserver(container, function (_ref3) {
107
- var _ref4 = _slicedToArray(_ref3, 1),
108
- entry = _ref4[0];
92
+ var observer = makeResizeObserver(container, function (_ref4) {
93
+ var _ref5 = _slicedToArray(_ref4, 1),
94
+ entry = _ref5[0];
109
95
  var _entry$borderBoxSize$2 = entry.borderBoxSize[0],
110
96
  inlineSize = _entry$borderBoxSize$2.inlineSize,
111
97
  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
+ };
@@ -237,6 +237,10 @@ EuiTableHeaderCell.propTypes = {
237
237
  * hidden.
238
238
  */
239
239
  onMouseOut: PropTypes.func,
240
+ /**
241
+ * If supplied, called when the trigger loses focus.
242
+ */
243
+ onBlur: PropTypes.func,
240
244
  /**
241
245
  * Offset in pixels from the anchor. Defaults to 16.
242
246
  */
@@ -93,6 +93,10 @@ EuiIconTip.propTypes = {
93
93
  * hidden.
94
94
  */
95
95
  onMouseOut: PropTypes.func,
96
+ /**
97
+ * If supplied, called when the trigger loses focus.
98
+ */
99
+ onBlur: PropTypes.func,
96
100
  /**
97
101
  * Offset in pixels from the anchor. Defaults to 16.
98
102
  */