@elastic/eui 88.5.0 → 88.5.2

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 (107) hide show
  1. package/dist/eui_theme_dark.css +8 -21
  2. package/dist/eui_theme_dark.min.css +1 -1
  3. package/dist/eui_theme_light.css +8 -21
  4. package/dist/eui_theme_light.min.css +1 -1
  5. package/es/components/collapsible_nav_beta/collapsible_nav_beta.js +20 -6
  6. package/es/components/collapsible_nav_beta/collapsible_nav_beta.styles.js +4 -14
  7. package/es/components/collapsible_nav_beta/collapsible_nav_body_footer.js +57 -0
  8. package/es/components/collapsible_nav_beta/collapsible_nav_body_footer.styles.js +25 -0
  9. package/es/components/collapsible_nav_beta/collapsible_nav_group/collapsible_nav_group.js +156 -0
  10. package/es/components/collapsible_nav_beta/collapsible_nav_group/collapsible_nav_group.styles.js +19 -0
  11. package/es/components/collapsible_nav_beta/collapsible_nav_group/index.js +9 -0
  12. package/es/components/collapsible_nav_beta/collapsible_nav_item/collapsed/collapsed_nav_button.js +3 -7
  13. package/es/components/collapsible_nav_beta/collapsible_nav_item/collapsed/collapsed_nav_item.js +3 -7
  14. package/es/components/collapsible_nav_beta/collapsible_nav_item/collapsed/collapsed_nav_popover.js +4 -8
  15. package/es/components/collapsible_nav_beta/collapsible_nav_item/collapsible_nav_accordion.js +16 -63
  16. package/es/components/collapsible_nav_beta/collapsible_nav_item/collapsible_nav_accordion.styles.js +2 -10
  17. package/es/components/collapsible_nav_beta/collapsible_nav_item/collapsible_nav_item.js +122 -41
  18. package/es/components/collapsible_nav_beta/collapsible_nav_item/collapsible_nav_item.styles.js +13 -3
  19. package/es/components/combo_box/combo_box.js +12 -25
  20. package/es/components/combo_box/combo_box_input/combo_box_input.js +61 -54
  21. package/es/components/text_truncate/index.js +1 -1
  22. package/es/components/text_truncate/utils.js +88 -138
  23. package/es/services/canvas/canvas_text_utils.js +64 -0
  24. package/es/services/canvas/index.js +9 -0
  25. package/es/services/index.js +1 -0
  26. package/eui.d.ts +186 -105
  27. package/i18ntokens.json +8 -8
  28. package/lib/components/collapsible_nav_beta/collapsible_nav_beta.js +20 -6
  29. package/lib/components/collapsible_nav_beta/collapsible_nav_beta.styles.js +11 -19
  30. package/lib/components/collapsible_nav_beta/collapsible_nav_body_footer.js +67 -0
  31. package/lib/components/collapsible_nav_beta/collapsible_nav_body_footer.styles.js +33 -0
  32. package/lib/components/collapsible_nav_beta/collapsible_nav_group/collapsible_nav_group.js +166 -0
  33. package/lib/components/collapsible_nav_beta/collapsible_nav_group/collapsible_nav_group.styles.js +26 -0
  34. package/lib/components/collapsible_nav_beta/collapsible_nav_group/index.js +12 -0
  35. package/lib/components/collapsible_nav_beta/collapsible_nav_item/collapsed/collapsed_nav_button.js +3 -7
  36. package/lib/components/collapsible_nav_beta/collapsible_nav_item/collapsed/collapsed_nav_item.js +3 -7
  37. package/lib/components/collapsible_nav_beta/collapsible_nav_item/collapsed/collapsed_nav_popover.js +4 -8
  38. package/lib/components/collapsible_nav_beta/collapsible_nav_item/collapsible_nav_accordion.js +14 -61
  39. package/lib/components/collapsible_nav_beta/collapsible_nav_item/collapsible_nav_accordion.styles.js +1 -9
  40. package/lib/components/collapsible_nav_beta/collapsible_nav_item/collapsible_nav_item.js +122 -39
  41. package/lib/components/collapsible_nav_beta/collapsible_nav_item/collapsible_nav_item.styles.js +13 -4
  42. package/lib/components/combo_box/combo_box.js +12 -25
  43. package/lib/components/combo_box/combo_box_input/combo_box_input.js +60 -53
  44. package/lib/components/text_truncate/index.js +0 -6
  45. package/lib/components/text_truncate/utils.js +97 -148
  46. package/lib/services/canvas/canvas_text_utils.js +70 -0
  47. package/lib/services/canvas/index.js +12 -0
  48. package/lib/services/index.js +8 -0
  49. package/optimize/es/components/collapsible_nav_beta/collapsible_nav_beta.js +17 -3
  50. package/optimize/es/components/collapsible_nav_beta/collapsible_nav_beta.styles.js +4 -14
  51. package/optimize/es/components/collapsible_nav_beta/collapsible_nav_body_footer.js +56 -0
  52. package/optimize/es/components/collapsible_nav_beta/collapsible_nav_body_footer.styles.js +25 -0
  53. package/optimize/es/components/collapsible_nav_beta/collapsible_nav_group/collapsible_nav_group.js +48 -0
  54. package/optimize/es/components/collapsible_nav_beta/collapsible_nav_group/collapsible_nav_group.styles.js +19 -0
  55. package/optimize/es/components/collapsible_nav_beta/collapsible_nav_group/index.js +9 -0
  56. package/optimize/es/components/collapsible_nav_beta/collapsible_nav_item/collapsible_nav_accordion.js +7 -33
  57. package/optimize/es/components/collapsible_nav_beta/collapsible_nav_item/collapsible_nav_accordion.styles.js +2 -10
  58. package/optimize/es/components/collapsible_nav_beta/collapsible_nav_item/collapsible_nav_item.js +54 -21
  59. package/optimize/es/components/collapsible_nav_beta/collapsible_nav_item/collapsible_nav_item.styles.js +13 -3
  60. package/optimize/es/components/combo_box/combo_box.js +12 -25
  61. package/optimize/es/components/combo_box/combo_box_input/combo_box_input.js +61 -53
  62. package/optimize/es/components/text_truncate/index.js +1 -1
  63. package/optimize/es/components/text_truncate/utils.js +87 -137
  64. package/optimize/es/services/canvas/canvas_text_utils.js +60 -0
  65. package/optimize/es/services/canvas/index.js +9 -0
  66. package/optimize/es/services/index.js +1 -0
  67. package/optimize/lib/components/collapsible_nav_beta/collapsible_nav_beta.js +15 -1
  68. package/optimize/lib/components/collapsible_nav_beta/collapsible_nav_beta.styles.js +11 -19
  69. package/optimize/lib/components/collapsible_nav_beta/collapsible_nav_body_footer.js +66 -0
  70. package/optimize/lib/components/collapsible_nav_beta/collapsible_nav_body_footer.styles.js +33 -0
  71. package/optimize/lib/components/collapsible_nav_beta/collapsible_nav_group/collapsible_nav_group.js +58 -0
  72. package/optimize/lib/components/collapsible_nav_beta/collapsible_nav_group/collapsible_nav_group.styles.js +26 -0
  73. package/optimize/lib/components/collapsible_nav_beta/collapsible_nav_group/index.js +12 -0
  74. package/optimize/lib/components/collapsible_nav_beta/collapsible_nav_item/collapsible_nav_accordion.js +5 -31
  75. package/optimize/lib/components/collapsible_nav_beta/collapsible_nav_item/collapsible_nav_accordion.styles.js +1 -9
  76. package/optimize/lib/components/collapsible_nav_beta/collapsible_nav_item/collapsible_nav_item.js +54 -20
  77. package/optimize/lib/components/collapsible_nav_beta/collapsible_nav_item/collapsible_nav_item.styles.js +13 -4
  78. package/optimize/lib/components/combo_box/combo_box.js +12 -25
  79. package/optimize/lib/components/combo_box/combo_box_input/combo_box_input.js +60 -52
  80. package/optimize/lib/components/text_truncate/index.js +0 -6
  81. package/optimize/lib/components/text_truncate/utils.js +96 -147
  82. package/optimize/lib/services/canvas/canvas_text_utils.js +67 -0
  83. package/optimize/lib/services/canvas/index.js +12 -0
  84. package/optimize/lib/services/index.js +8 -0
  85. package/package.json +2 -5
  86. package/src/components/combo_box/_combo_box.scss +12 -19
  87. package/test-env/components/collapsible_nav_beta/collapsible_nav_beta.js +20 -6
  88. package/test-env/components/collapsible_nav_beta/collapsible_nav_beta.styles.js +11 -19
  89. package/test-env/components/collapsible_nav_beta/collapsible_nav_body_footer.js +66 -0
  90. package/test-env/components/collapsible_nav_beta/collapsible_nav_body_footer.styles.js +33 -0
  91. package/test-env/components/collapsible_nav_beta/collapsible_nav_group/collapsible_nav_group.js +165 -0
  92. package/test-env/components/collapsible_nav_beta/collapsible_nav_group/collapsible_nav_group.styles.js +26 -0
  93. package/test-env/components/collapsible_nav_beta/collapsible_nav_group/index.js +12 -0
  94. package/test-env/components/collapsible_nav_beta/collapsible_nav_item/collapsed/collapsed_nav_button.js +3 -7
  95. package/test-env/components/collapsible_nav_beta/collapsible_nav_item/collapsed/collapsed_nav_item.js +3 -7
  96. package/test-env/components/collapsible_nav_beta/collapsible_nav_item/collapsed/collapsed_nav_popover.js +4 -8
  97. package/test-env/components/collapsible_nav_beta/collapsible_nav_item/collapsible_nav_accordion.js +14 -61
  98. package/test-env/components/collapsible_nav_beta/collapsible_nav_item/collapsible_nav_accordion.styles.js +1 -9
  99. package/test-env/components/collapsible_nav_beta/collapsible_nav_item/collapsible_nav_item.js +122 -39
  100. package/test-env/components/collapsible_nav_beta/collapsible_nav_item/collapsible_nav_item.styles.js +13 -4
  101. package/test-env/components/combo_box/combo_box.js +12 -25
  102. package/test-env/components/combo_box/combo_box_input/combo_box_input.js +60 -53
  103. package/test-env/components/text_truncate/index.js +0 -6
  104. package/test-env/components/text_truncate/utils.js +96 -147
  105. package/test-env/services/canvas/canvas_text_utils.js +30 -0
  106. package/test-env/services/canvas/index.js +12 -0
  107. package/test-env/services/index.js +8 -0
@@ -7,7 +7,6 @@ exports.EuiComboBoxInput = void 0;
7
7
  var _react = _interopRequireWildcard(require("react"));
8
8
  var _propTypes = _interopRequireDefault(require("prop-types"));
9
9
  var _classnames = _interopRequireDefault(require("classnames"));
10
- var _reactInputAutosize = _interopRequireDefault(require("react-input-autosize"));
11
10
  var _services = require("../../../services");
12
11
  var _accessibility = require("../../accessibility");
13
12
  var _form_control_layout = require("../../form/form_control_layout");
@@ -52,8 +51,27 @@ var EuiComboBoxInput = /*#__PURE__*/function (_Component) {
52
51
  }
53
52
  _this = _super.call.apply(_super, [this].concat(args));
54
53
  _defineProperty(_assertThisInitialized(_this), "state", {
54
+ inputWidth: 2,
55
55
  hasFocus: false
56
56
  });
57
+ _defineProperty(_assertThisInitialized(_this), "widthUtils", void 0);
58
+ _defineProperty(_assertThisInitialized(_this), "inputRefCallback", function (el) {
59
+ var _this$props$inputRef, _this$props;
60
+ _this.widthUtils = new _services.CanvasTextUtils({
61
+ container: el
62
+ });
63
+ (_this$props$inputRef = (_this$props = _this.props).inputRef) === null || _this$props$inputRef === void 0 ? void 0 : _this$props$inputRef.call(_this$props, el);
64
+ });
65
+ _defineProperty(_assertThisInitialized(_this), "updateInputSize", function (inputValue) {
66
+ if (!_this.widthUtils) return;
67
+ _this.widthUtils.setTextToCheck(inputValue);
68
+ // Canvas has minute subpixel differences in rendering compared to DOM
69
+ // We'll buffer the input by ~2px just to ensure sufficient width
70
+ var inputWidth = Math.ceil(_this.widthUtils.textWidth) + 2;
71
+ _this.setState({
72
+ inputWidth: inputWidth
73
+ });
74
+ });
57
75
  _defineProperty(_assertThisInitialized(_this), "updatePosition", function () {
58
76
  // Wait a beat for the DOM to update, since we depend on DOM elements' bounds.
59
77
  requestAnimationFrame(function () {
@@ -75,13 +93,13 @@ var EuiComboBoxInput = /*#__PURE__*/function (_Component) {
75
93
  });
76
94
  });
77
95
  _defineProperty(_assertThisInitialized(_this), "onKeyDown", function (event) {
78
- var _this$props = _this.props,
79
- searchValue = _this$props.searchValue,
80
- selectedOptions = _this$props.selectedOptions,
81
- onRemoveOption = _this$props.onRemoveOption,
82
- singleSelection = _this$props.singleSelection,
83
- isListOpen = _this$props.isListOpen,
84
- onOpenListClick = _this$props.onOpenListClick;
96
+ var _this$props2 = _this.props,
97
+ searchValue = _this$props2.searchValue,
98
+ selectedOptions = _this$props2.selectedOptions,
99
+ onRemoveOption = _this$props2.onRemoveOption,
100
+ singleSelection = _this$props2.singleSelection,
101
+ isListOpen = _this$props2.isListOpen,
102
+ onOpenListClick = _this$props2.onOpenListClick;
85
103
 
86
104
  // When backspacing from an empty input, delete the last pill option in the list
87
105
  var searchIsEmpty = !searchValue.length;
@@ -94,18 +112,10 @@ var EuiComboBoxInput = /*#__PURE__*/function (_Component) {
94
112
  }
95
113
  });
96
114
  _defineProperty(_assertThisInitialized(_this), "inputOnChange", function (event) {
97
- var _this$props2 = _this.props,
98
- onChange = _this$props2.onChange,
99
- searchValue = _this$props2.searchValue;
100
- if (onChange) {
101
- onChange(event.target.value);
102
- }
103
- });
104
- _defineProperty(_assertThisInitialized(_this), "inputRefCallback", function (ref) {
105
- var autoSizeInputRef = _this.props.autoSizeInputRef;
106
- if (autoSizeInputRef) {
107
- autoSizeInputRef(ref);
108
- }
115
+ var _this$props$onChange, _this$props3;
116
+ var value = event.target.value;
117
+ _this.updateInputSize(value);
118
+ (_this$props$onChange = (_this$props3 = _this.props).onChange) === null || _this$props$onChange === void 0 ? void 0 : _this$props$onChange.call(_this$props3, value);
109
119
  });
110
120
  return _this;
111
121
  }
@@ -123,35 +133,34 @@ var EuiComboBoxInput = /*#__PURE__*/function (_Component) {
123
133
  }, {
124
134
  key: "render",
125
135
  value: function render() {
126
- var _this$props3 = this.props,
127
- compressed = _this$props3.compressed,
128
- focusedOptionId = _this$props3.focusedOptionId,
129
- fullWidth = _this$props3.fullWidth,
130
- hasSelectedOptions = _this$props3.hasSelectedOptions,
131
- id = _this$props3.id,
132
- inputRef = _this$props3.inputRef,
133
- isDisabled = _this$props3.isDisabled,
134
- isListOpen = _this$props3.isListOpen,
135
- noIcon = _this$props3.noIcon,
136
- onClear = _this$props3.onClear,
137
- onClick = _this$props3.onClick,
138
- onCloseListClick = _this$props3.onCloseListClick,
139
- onOpenListClick = _this$props3.onOpenListClick,
140
- onRemoveOption = _this$props3.onRemoveOption,
141
- placeholder = _this$props3.placeholder,
142
- rootId = _this$props3.rootId,
143
- searchValue = _this$props3.searchValue,
144
- selectedOptions = _this$props3.selectedOptions,
145
- singleSelectionProp = _this$props3.singleSelection,
146
- toggleButtonRef = _this$props3.toggleButtonRef,
147
- value = _this$props3.value,
148
- prepend = _this$props3.prepend,
149
- append = _this$props3.append,
150
- isLoading = _this$props3.isLoading,
151
- isInvalid = _this$props3.isInvalid,
152
- autoFocus = _this$props3.autoFocus,
153
- ariaLabel = _this$props3['aria-label'],
154
- ariaLabelledby = _this$props3['aria-labelledby'];
136
+ var _this$props4 = this.props,
137
+ compressed = _this$props4.compressed,
138
+ focusedOptionId = _this$props4.focusedOptionId,
139
+ fullWidth = _this$props4.fullWidth,
140
+ hasSelectedOptions = _this$props4.hasSelectedOptions,
141
+ id = _this$props4.id,
142
+ isDisabled = _this$props4.isDisabled,
143
+ isListOpen = _this$props4.isListOpen,
144
+ noIcon = _this$props4.noIcon,
145
+ onClear = _this$props4.onClear,
146
+ onClick = _this$props4.onClick,
147
+ onCloseListClick = _this$props4.onCloseListClick,
148
+ onOpenListClick = _this$props4.onOpenListClick,
149
+ onRemoveOption = _this$props4.onRemoveOption,
150
+ placeholder = _this$props4.placeholder,
151
+ rootId = _this$props4.rootId,
152
+ searchValue = _this$props4.searchValue,
153
+ selectedOptions = _this$props4.selectedOptions,
154
+ singleSelectionProp = _this$props4.singleSelection,
155
+ toggleButtonRef = _this$props4.toggleButtonRef,
156
+ value = _this$props4.value,
157
+ prepend = _this$props4.prepend,
158
+ append = _this$props4.append,
159
+ isLoading = _this$props4.isLoading,
160
+ isInvalid = _this$props4.isInvalid,
161
+ autoFocus = _this$props4.autoFocus,
162
+ ariaLabel = _this$props4['aria-label'],
163
+ ariaLabelledby = _this$props4['aria-labelledby'];
155
164
  var singleSelection = Boolean(singleSelectionProp);
156
165
  var asPlainText = singleSelectionProp && _typeof(singleSelectionProp) === 'object' && singleSelectionProp.asPlainText || false;
157
166
  var pills = selectedOptions ? selectedOptions.map(function (option) {
@@ -243,7 +252,7 @@ var EuiComboBoxInput = /*#__PURE__*/function (_Component) {
243
252
  "data-test-subj": "comboBoxInput",
244
253
  onClick: onClick,
245
254
  tabIndex: -1 // becomes onBlur event's relatedTarget, otherwise relatedTarget is null when clicking on this div
246
- }, !singleSelection || !searchValue ? pills : null, placeholderMessage, (0, _react2.jsx)(_reactInputAutosize.default, {
255
+ }, !singleSelection || !searchValue ? pills : null, placeholderMessage, (0, _react2.jsx)("input", {
247
256
  "aria-activedescendant": focusedOptionId,
248
257
  "aria-autocomplete": "list",
249
258
  "aria-controls": isListOpen ? rootId('listbox') : '',
@@ -255,7 +264,6 @@ var EuiComboBoxInput = /*#__PURE__*/function (_Component) {
255
264
  "data-test-subj": "comboBoxSearchInput",
256
265
  disabled: isDisabled,
257
266
  id: id,
258
- inputRef: inputRef,
259
267
  onBlur: this.onBlur,
260
268
  onChange: this.inputOnChange,
261
269
  onFocus: this.onFocus,
@@ -263,7 +271,7 @@ var EuiComboBoxInput = /*#__PURE__*/function (_Component) {
263
271
  ref: this.inputRefCallback,
264
272
  role: "combobox",
265
273
  style: {
266
- fontSize: 14
274
+ inlineSize: this.state.inputWidth
267
275
  },
268
276
  value: searchValue,
269
277
  autoFocus: autoFocus
@@ -274,7 +282,6 @@ var EuiComboBoxInput = /*#__PURE__*/function (_Component) {
274
282
  }(_react.Component);
275
283
  exports.EuiComboBoxInput = EuiComboBoxInput;
276
284
  EuiComboBoxInput.propTypes = {
277
- autoSizeInputRef: _propTypes.default.any,
278
285
  compressed: _propTypes.default.bool.isRequired,
279
286
  focusedOptionId: _propTypes.default.string,
280
287
  fullWidth: _propTypes.default.bool,
@@ -3,12 +3,6 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- Object.defineProperty(exports, "CanvasTextUtils", {
7
- enumerable: true,
8
- get: function get() {
9
- return _utils.CanvasTextUtils;
10
- }
11
- });
12
6
  Object.defineProperty(exports, "EuiTextTruncate", {
13
7
  enumerable: true,
14
8
  get: function get() {
@@ -3,7 +3,8 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.TruncationUtils = exports.CanvasTextUtils = void 0;
6
+ exports.TruncationUtils = void 0;
7
+ var _canvas = require("../../services/canvas");
7
8
  var _excluded = ["fullText", "ellipsis", "availableWidth"];
8
9
  function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
9
10
  function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
@@ -14,6 +15,9 @@ function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefine
14
15
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
15
16
  function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
16
17
  function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
18
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
19
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
20
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
17
21
  function _get() { if (typeof Reflect !== "undefined" && Reflect.get) { _get = Reflect.get.bind(); } else { _get = function _get(target, property, receiver) { var base = _superPropBase(target, property); if (!base) return; var desc = Object.getOwnPropertyDescriptor(base, property); if (desc.get) { return desc.get.call(arguments.length < 3 ? target : receiver); } return desc.value; }; } return _get.apply(this, arguments); }
18
22
  function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; }
19
23
  function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
@@ -23,93 +27,38 @@ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) ===
23
27
  function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
24
28
  function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
25
29
  function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
26
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
27
- function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
28
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
29
30
  function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
30
31
  function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
31
- function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
32
- /*
33
- * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
34
- * or more contributor license agreements. Licensed under the Elastic License
35
- * 2.0 and the Server Side Public License, v 1; you may not use this file except
36
- * in compliance with, at your election, the Elastic License 2.0 or the Server
37
- * Side Public License, v 1.
38
- */
39
- /**
40
- * Under the hood, a temporary Canvas element is created for manipulating text
41
- * & determining text width.
42
- *
43
- * To accurately measure text, canvas rendering requires either a container to
44
- * compute/derive font styles from, or a static font string (useful for usage
45
- * outside the DOM). Particular care should be applied when fallback fonts are
46
- * used, as more fallback fonts can lead to less precision.
47
- *
48
- * Please note that while canvas is more significantly more performant than DOM
49
- * measurement, there are subpixel to single digit pixel differences between
50
- * DOM and canvas measurement due to the different rendering engines used.
51
- */
52
- var CanvasTextUtils = /*#__PURE__*/function () {
53
- function CanvasTextUtils(_ref) {
54
- var _this = this;
55
- var font = _ref.font,
56
- container = _ref.container;
57
- _classCallCheck(this, CanvasTextUtils);
58
- _defineProperty(this, "context", void 0);
59
- _defineProperty(this, "currentText", '');
60
- _defineProperty(this, "computeFontFromElement", function (element) {
61
- var computedStyles = window.getComputedStyle(element);
62
- // TODO: font-stretch is not included even though it potentially should be
63
- // @see https://developer.mozilla.org/en-US/docs/Web/CSS/font#constituent_properties
64
- // It appears to be unsupported and/or breaks font computation in canvas
65
- return ['font-style', 'font-variant', 'font-weight', 'font-size', 'font-family'].map(function (prop) {
66
- return computedStyles.getPropertyValue(prop);
67
- }).join(' ').trim();
68
- });
69
- _defineProperty(this, "setTextToCheck", function (text) {
70
- _this.currentText = text;
71
- });
72
- this.context = document.createElement('canvas').getContext('2d');
73
-
74
- // Set the canvas font to ensure text width calculations are correct
75
- if (font) {
76
- this.context.font = font;
77
- } else if (container) {
78
- this.context.font = this.computeFontFromElement(container);
79
- }
80
- }
81
- _createClass(CanvasTextUtils, [{
82
- key: "textWidth",
83
- get: function get() {
84
- return this.context.measureText(this.currentText).width;
85
- }
86
- }]);
87
- return CanvasTextUtils;
88
- }();
32
+ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } /*
33
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
34
+ * or more contributor license agreements. Licensed under the Elastic License
35
+ * 2.0 and the Server Side Public License, v 1; you may not use this file except
36
+ * in compliance with, at your election, the Elastic License 2.0 or the Server
37
+ * Side Public License, v 1.
38
+ */
89
39
  /**
90
40
  * Utilities for truncating types at various positions, as well as
91
41
  * determining whether truncation is possible or even necessary.
92
42
  */
93
- exports.CanvasTextUtils = CanvasTextUtils;
94
43
  var TruncationUtils = /*#__PURE__*/function (_CanvasTextUtils) {
95
44
  _inherits(TruncationUtils, _CanvasTextUtils);
96
45
  var _super = _createSuper(TruncationUtils);
97
- function TruncationUtils(_ref2) {
98
- var _this2;
99
- var fullText = _ref2.fullText,
100
- ellipsis = _ref2.ellipsis,
101
- _availableWidth = _ref2.availableWidth,
102
- rest = _objectWithoutProperties(_ref2, _excluded);
46
+ function TruncationUtils(_ref) {
47
+ var _this;
48
+ var fullText = _ref.fullText,
49
+ ellipsis = _ref.ellipsis,
50
+ _availableWidth = _ref.availableWidth,
51
+ rest = _objectWithoutProperties(_ref, _excluded);
103
52
  _classCallCheck(this, TruncationUtils);
104
- _this2 = _super.call(this, rest);
105
- _defineProperty(_assertThisInitialized(_this2), "fullText", void 0);
106
- _defineProperty(_assertThisInitialized(_this2), "ellipsis", void 0);
107
- _defineProperty(_assertThisInitialized(_this2), "availableWidth", void 0);
53
+ _this = _super.call(this, rest);
54
+ _defineProperty(_assertThisInitialized(_this), "fullText", void 0);
55
+ _defineProperty(_assertThisInitialized(_this), "ellipsis", void 0);
56
+ _defineProperty(_assertThisInitialized(_this), "availableWidth", void 0);
108
57
  /**
109
58
  * Performance utilities
110
59
  */
111
- _defineProperty(_assertThisInitialized(_this2), "debugPerformance", false);
112
- _defineProperty(_assertThisInitialized(_this2), "debugCounter", 0);
60
+ _defineProperty(_assertThisInitialized(_this), "debugPerformance", false);
61
+ _defineProperty(_assertThisInitialized(_this), "debugCounter", 0);
113
62
  /**
114
63
  * Internal utils for calculating a ratio based on the passed available width
115
64
  * vs the full text width.
@@ -117,21 +66,21 @@ var TruncationUtils = /*#__PURE__*/function (_CanvasTextUtils) {
117
66
  * be slightly over the available width, which we can then remove from
118
67
  * character-by-character until the text just fits within the available width.
119
68
  */
120
- _defineProperty(_assertThisInitialized(_this2), "widthRatio", 0);
121
- _defineProperty(_assertThisInitialized(_this2), "setTextWidthRatio", function () {
122
- var text = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _this2.fullText;
69
+ _defineProperty(_assertThisInitialized(_this), "widthRatio", 0);
70
+ _defineProperty(_assertThisInitialized(_this), "setTextWidthRatio", function () {
71
+ var text = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _this.fullText;
123
72
  var textToOffset = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
124
73
  // Account for reduced available width due to (e.g.) truncation offset
125
- var availableWidth = _this2.availableWidth;
74
+ var availableWidth = _this.availableWidth;
126
75
  if (textToOffset) {
127
- _this2.setTextToCheck(textToOffset);
128
- availableWidth = availableWidth - _this2.textWidth;
76
+ _this.setTextToCheck(textToOffset);
77
+ availableWidth = availableWidth - _this.textWidth;
129
78
  }
130
- _this2.setTextToCheck(text);
131
- _this2.widthRatio = availableWidth / _this2.textWidth;
79
+ _this.setTextToCheck(text);
80
+ _this.widthRatio = availableWidth / _this.textWidth;
132
81
  });
133
- _defineProperty(_assertThisInitialized(_this2), "getTextFromRatio", function (text, type) {
134
- var characterRatio = Math.ceil(text.length * _this2.widthRatio);
82
+ _defineProperty(_assertThisInitialized(_this), "getTextFromRatio", function (text, type) {
83
+ var characterRatio = Math.ceil(text.length * _this.widthRatio);
135
84
  var index = type === 'start' ? text.length - characterRatio : characterRatio;
136
85
  var _splitText$at = splitText(text).at(index),
137
86
  _splitText$at2 = _slicedToArray(_splitText$at, 2),
@@ -142,24 +91,24 @@ var TruncationUtils = /*#__PURE__*/function (_CanvasTextUtils) {
142
91
  /**
143
92
  * Early return checks
144
93
  */
145
- _defineProperty(_assertThisInitialized(_this2), "checkIfTruncationIsNeeded", function () {
146
- _this2.setTextToCheck(_this2.fullText);
147
- if (_this2.availableWidth >= _this2.textWidth) {
94
+ _defineProperty(_assertThisInitialized(_this), "checkIfTruncationIsNeeded", function () {
95
+ _this.setTextToCheck(_this.fullText);
96
+ if (_this.availableWidth >= _this.textWidth) {
148
97
  return false;
149
98
  }
150
99
  });
151
- _defineProperty(_assertThisInitialized(_this2), "checkSufficientEllipsisWidth", function (truncation) {
152
- var textToCheck = truncation === 'startEnd' ? "".concat(_this2.ellipsis, " ").concat(_this2.ellipsis) // startEnd needs a little more space
153
- : _this2.ellipsis;
154
- _this2.setTextToCheck(textToCheck);
155
- if (_this2.textWidth >= _this2.availableWidth * 0.9) {
100
+ _defineProperty(_assertThisInitialized(_this), "checkSufficientEllipsisWidth", function (truncation) {
101
+ var textToCheck = truncation === 'startEnd' ? "".concat(_this.ellipsis, " ").concat(_this.ellipsis) // startEnd needs a little more space
102
+ : _this.ellipsis;
103
+ _this.setTextToCheck(textToCheck);
104
+ if (_this.textWidth >= _this.availableWidth * 0.9) {
156
105
  console.error('The truncation ellipsis is larger than the available width. No text can be rendered.');
157
106
  return false;
158
107
  }
159
108
  });
160
- _defineProperty(_assertThisInitialized(_this2), "checkTruncationOffsetWidth", function (text) {
161
- _this2.setTextToCheck(text);
162
- if (_this2.textWidth > _this2.availableWidth) {
109
+ _defineProperty(_assertThisInitialized(_this), "checkTruncationOffsetWidth", function (text) {
110
+ _this.setTextToCheck(text);
111
+ if (_this.textWidth > _this.availableWidth) {
163
112
  console.error('The passed truncationOffset is too large for the available width. Truncating the offset instead.');
164
113
  return false;
165
114
  }
@@ -167,19 +116,19 @@ var TruncationUtils = /*#__PURE__*/function (_CanvasTextUtils) {
167
116
  /**
168
117
  * Truncation types logic. This is where the magic happens
169
118
  */
170
- _defineProperty(_assertThisInitialized(_this2), "truncateStart", function (truncationOffset) {
171
- var truncatedText = _this2.fullText;
119
+ _defineProperty(_assertThisInitialized(_this), "truncateStart", function (truncationOffset) {
120
+ var truncatedText = _this.fullText;
172
121
  var leadingText = '';
173
122
  var combinedText = function combinedText() {
174
123
  return leadingText + truncatedText;
175
124
  };
176
125
  if (truncationOffset) {
177
- var _splitText$at3 = splitText(_this2.fullText).at(truncationOffset);
126
+ var _splitText$at3 = splitText(_this.fullText).at(truncationOffset);
178
127
  var _splitText$at4 = _slicedToArray(_splitText$at3, 2);
179
128
  leadingText = _splitText$at4[0];
180
129
  truncatedText = _splitText$at4[1];
181
- var widthCheck = leadingText + _this2.ellipsis;
182
- if (_this2.checkTruncationOffsetWidth(widthCheck) === false) {
130
+ var widthCheck = leadingText + _this.ellipsis;
131
+ if (_this.checkTruncationOffsetWidth(widthCheck) === false) {
183
132
  truncatedText = leadingText;
184
133
  leadingText = '';
185
134
  }
@@ -187,30 +136,30 @@ var TruncationUtils = /*#__PURE__*/function (_CanvasTextUtils) {
187
136
 
188
137
  // Get text width ratio width accounting for any truncation offset text,
189
138
  // and guesstimate an initial truncated string
190
- _this2.setTextWidthRatio(truncatedText, leadingText);
191
- truncatedText = _this2.getTextFromRatio(truncatedText, 'start');
192
- leadingText += _this2.ellipsis;
193
- _this2.setTextToCheck(combinedText());
194
- while (_this2.textWidth > _this2.availableWidth) {
139
+ _this.setTextWidthRatio(truncatedText, leadingText);
140
+ truncatedText = _this.getTextFromRatio(truncatedText, 'start');
141
+ leadingText += _this.ellipsis;
142
+ _this.setTextToCheck(combinedText());
143
+ while (_this.textWidth > _this.availableWidth) {
195
144
  truncatedText = removeFirstCharacter(truncatedText);
196
- _this2.setTextToCheck(combinedText());
145
+ _this.setTextToCheck(combinedText());
197
146
  }
198
147
  return combinedText();
199
148
  });
200
- _defineProperty(_assertThisInitialized(_this2), "truncateEnd", function (truncationOffset) {
201
- var truncatedText = _this2.fullText;
149
+ _defineProperty(_assertThisInitialized(_this), "truncateEnd", function (truncationOffset) {
150
+ var truncatedText = _this.fullText;
202
151
  var trailingText = '';
203
152
  var combinedText = function combinedText() {
204
153
  return truncatedText + trailingText;
205
154
  };
206
155
  if (truncationOffset) {
207
- var index = _this2.fullText.length - truncationOffset;
208
- var _splitText$at5 = splitText(_this2.fullText).at(index);
156
+ var index = _this.fullText.length - truncationOffset;
157
+ var _splitText$at5 = splitText(_this.fullText).at(index);
209
158
  var _splitText$at6 = _slicedToArray(_splitText$at5, 2);
210
159
  truncatedText = _splitText$at6[0];
211
160
  trailingText = _splitText$at6[1];
212
- var widthCheck = _this2.ellipsis + trailingText;
213
- if (_this2.checkTruncationOffsetWidth(widthCheck) === false) {
161
+ var widthCheck = _this.ellipsis + trailingText;
162
+ if (_this.checkTruncationOffsetWidth(widthCheck) === false) {
214
163
  truncatedText = trailingText;
215
164
  trailingText = '';
216
165
  }
@@ -218,78 +167,78 @@ var TruncationUtils = /*#__PURE__*/function (_CanvasTextUtils) {
218
167
 
219
168
  // Get text width ratio width accounting for any truncation offset text,
220
169
  // and guesstimate an initial truncated string
221
- _this2.setTextWidthRatio(truncatedText, trailingText);
222
- truncatedText = _this2.getTextFromRatio(truncatedText, 'end');
223
- trailingText = _this2.ellipsis + trailingText;
224
- _this2.setTextToCheck(combinedText());
225
- while (_this2.textWidth > _this2.availableWidth) {
170
+ _this.setTextWidthRatio(truncatedText, trailingText);
171
+ truncatedText = _this.getTextFromRatio(truncatedText, 'end');
172
+ trailingText = _this.ellipsis + trailingText;
173
+ _this.setTextToCheck(combinedText());
174
+ while (_this.textWidth > _this.availableWidth) {
226
175
  truncatedText = removeLastCharacter(truncatedText);
227
- _this2.setTextToCheck(combinedText());
176
+ _this.setTextToCheck(combinedText());
228
177
  }
229
178
  return combinedText();
230
179
  });
231
- _defineProperty(_assertThisInitialized(_this2), "truncateStartEndAtPosition", function (truncationPosition) {
180
+ _defineProperty(_assertThisInitialized(_this), "truncateStartEndAtPosition", function (truncationPosition) {
232
181
  // Split the text from the anchor position, using the width ratio
233
182
  // to get the starting and ending indices from the position
234
- _this2.setTextWidthRatio();
235
- var characterRatio = Math.floor(_this2.fullText.length * _this2.widthRatio / 2);
183
+ _this.setTextWidthRatio();
184
+ var characterRatio = Math.floor(_this.fullText.length * _this.widthRatio / 2);
236
185
  var truncateStart = truncationPosition - characterRatio;
237
186
  var truncateEnd = truncationPosition + characterRatio;
238
187
 
239
188
  // If either of the approximate start/end truncation indices go beyond the
240
189
  // bounds of the actual text, we can simply use end or start truncation instead
241
190
  if (truncateStart < 0) {
242
- return _this2.truncateEnd();
191
+ return _this.truncateEnd();
243
192
  }
244
- if (truncateEnd >= _this2.fullText.length) {
245
- return _this2.truncateStart();
193
+ if (truncateEnd >= _this.fullText.length) {
194
+ return _this.truncateStart();
246
195
  }
247
- var truncatedText = _this2.fullText.substring(truncateStart, truncateEnd);
196
+ var truncatedText = _this.fullText.substring(truncateStart, truncateEnd);
248
197
  var combinedText = function combinedText() {
249
- return _this2.ellipsis + truncatedText + _this2.ellipsis;
198
+ return _this.ellipsis + truncatedText + _this.ellipsis;
250
199
  };
251
- _this2.setTextToCheck(combinedText());
200
+ _this.setTextToCheck(combinedText());
252
201
  var alternating;
253
- while (_this2.textWidth > _this2.availableWidth) {
202
+ while (_this.textWidth > _this.availableWidth) {
254
203
  truncatedText = alternating ? removeLastCharacter(truncatedText) : removeFirstCharacter(truncatedText);
255
204
  alternating = !alternating;
256
- _this2.setTextToCheck(combinedText());
205
+ _this.setTextToCheck(combinedText());
257
206
  }
258
207
  return combinedText();
259
208
  });
260
- _defineProperty(_assertThisInitialized(_this2), "truncateStartEndAtMiddle", function () {
261
- var middlePosition = Math.floor(_this2.fullText.length / 2);
262
- return _this2.truncateStartEndAtPosition(middlePosition);
209
+ _defineProperty(_assertThisInitialized(_this), "truncateStartEndAtMiddle", function () {
210
+ var middlePosition = Math.floor(_this.fullText.length / 2);
211
+ return _this.truncateStartEndAtPosition(middlePosition);
263
212
  });
264
- _defineProperty(_assertThisInitialized(_this2), "truncateMiddle", function () {
265
- var middlePosition = Math.floor(_this2.fullText.length / 2);
266
- var _splitText$at7 = splitText(_this2.fullText).at(middlePosition),
213
+ _defineProperty(_assertThisInitialized(_this), "truncateMiddle", function () {
214
+ var middlePosition = Math.floor(_this.fullText.length / 2);
215
+ var _splitText$at7 = splitText(_this.fullText).at(middlePosition),
267
216
  _splitText$at8 = _slicedToArray(_splitText$at7, 2),
268
217
  firstHalf = _splitText$at8[0],
269
218
  secondHalf = _splitText$at8[1];
270
- _this2.setTextWidthRatio();
271
- firstHalf = _this2.getTextFromRatio(firstHalf, 'end');
272
- secondHalf = _this2.getTextFromRatio(secondHalf, 'start');
219
+ _this.setTextWidthRatio();
220
+ firstHalf = _this.getTextFromRatio(firstHalf, 'end');
221
+ secondHalf = _this.getTextFromRatio(secondHalf, 'start');
273
222
  var combinedText = function combinedText() {
274
- return firstHalf + _this2.ellipsis + secondHalf;
223
+ return firstHalf + _this.ellipsis + secondHalf;
275
224
  };
276
- _this2.setTextToCheck(combinedText());
225
+ _this.setTextToCheck(combinedText());
277
226
  var alternating;
278
- while (_this2.textWidth > _this2.availableWidth) {
227
+ while (_this.textWidth > _this.availableWidth) {
279
228
  alternating = !alternating;
280
229
  if (alternating) {
281
230
  firstHalf = removeLastCharacter(firstHalf);
282
231
  } else {
283
232
  secondHalf = removeFirstCharacter(secondHalf);
284
233
  }
285
- _this2.setTextToCheck(combinedText());
234
+ _this.setTextToCheck(combinedText());
286
235
  }
287
236
  return combinedText();
288
237
  });
289
- _this2.fullText = fullText;
290
- _this2.ellipsis = ellipsis;
291
- _this2.availableWidth = _availableWidth;
292
- return _this2;
238
+ _this.fullText = fullText;
239
+ _this.ellipsis = ellipsis;
240
+ _this.availableWidth = _availableWidth;
241
+ return _this;
293
242
  }
294
243
  _createClass(TruncationUtils, [{
295
244
  key: "textWidth",
@@ -301,7 +250,7 @@ var TruncationUtils = /*#__PURE__*/function (_CanvasTextUtils) {
301
250
  }
302
251
  }]);
303
252
  return TruncationUtils;
304
- }(CanvasTextUtils);
253
+ }(_canvas.CanvasTextUtils);
305
254
  /**
306
255
  * DRY character/substring utils
307
256
  */