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