@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
@@ -86,10 +86,6 @@ export var EuiComboBox = /*#__PURE__*/function (_Component) {
86
86
  });
87
87
  }
88
88
  });
89
- _defineProperty(_assertThisInitialized(_this), "autoSizeInputRefInstance", null);
90
- _defineProperty(_assertThisInitialized(_this), "autoSizeInputRefCallback", function (ref) {
91
- _this.autoSizeInputRefInstance = ref;
92
- });
93
89
  _defineProperty(_assertThisInitialized(_this), "searchInputRefInstance", null);
94
90
  _defineProperty(_assertThisInitialized(_this), "searchInputRefCallback", function (ref) {
95
91
  _this.searchInputRefInstance = ref;
@@ -562,15 +558,7 @@ export var EuiComboBox = /*#__PURE__*/function (_Component) {
562
558
  _createClass(EuiComboBox, [{
563
559
  key: "componentDidMount",
564
560
  value: function componentDidMount() {
565
- var _this2 = this;
566
561
  this._isMounted = true;
567
-
568
- // TODO: This will need to be called once the actual stylesheet loads.
569
- setTimeout(function () {
570
- if (_this2.autoSizeInputRefInstance) {
571
- _this2.autoSizeInputRefInstance.copyInputStyles();
572
- }
573
- }, 100);
574
562
  }
575
563
  }, {
576
564
  key: "componentDidUpdate",
@@ -603,7 +591,7 @@ export var EuiComboBox = /*#__PURE__*/function (_Component) {
603
591
  }, {
604
592
  key: "render",
605
593
  value: function render() {
606
- var _this3 = this;
594
+ var _this2 = this;
607
595
  var _this$props8 = this.props,
608
596
  dataTestSubj = _this$props8['data-test-subj'],
609
597
  async = _this$props8.async,
@@ -674,32 +662,32 @@ export var EuiComboBox = /*#__PURE__*/function (_Component) {
674
662
  default: "Choose from the following options"
675
663
  }, function (listboxAriaLabel) {
676
664
  return ___EmotionJSX(EuiComboBoxOptionsList, {
677
- zIndex: _this3.state.listZIndex,
678
- activeOptionIndex: _this3.state.activeOptionIndex,
679
- areAllOptionsSelected: _this3.areAllOptionsSelected(),
665
+ zIndex: _this2.state.listZIndex,
666
+ activeOptionIndex: _this2.state.activeOptionIndex,
667
+ areAllOptionsSelected: _this2.areAllOptionsSelected(),
680
668
  customOptionText: customOptionText,
681
669
  "data-test-subj": optionsListDataTestSubj,
682
670
  fullWidth: fullWidth,
683
671
  isCaseSensitive: isCaseSensitive,
684
672
  isLoading: isLoading,
685
- listRef: _this3.listRefCallback,
673
+ listRef: _this2.listRefCallback,
686
674
  matchingOptions: matchingOptions,
687
- onCloseList: _this3.closeList,
675
+ onCloseList: _this2.closeList,
688
676
  onCreateOption: onCreateOption,
689
- onOptionClick: _this3.onOptionClick,
690
- onOptionEnterKey: _this3.onOptionEnterKey,
691
- onScroll: _this3.onOptionListScroll,
692
- optionRef: _this3.optionRefCallback,
677
+ onOptionClick: _this2.onOptionClick,
678
+ onOptionEnterKey: _this2.onOptionEnterKey,
679
+ onScroll: _this2.onOptionListScroll,
680
+ optionRef: _this2.optionRefCallback,
693
681
  options: options,
694
682
  position: listPosition,
695
683
  singleSelection: singleSelection,
696
684
  renderOption: renderOption,
697
- rootId: _this3.rootId,
685
+ rootId: _this2.rootId,
698
686
  rowHeight: rowHeight,
699
687
  scrollToIndex: activeOptionIndex,
700
688
  searchValue: searchValue,
701
689
  selectedOptions: selectedOptions,
702
- updatePosition: _this3.updatePosition,
690
+ updatePosition: _this2.updatePosition,
703
691
  width: width,
704
692
  delimiter: delimiter,
705
693
  getSelectedOptionForSearchValue: getSelectedOptionForSearchValue,
@@ -723,7 +711,6 @@ export var EuiComboBox = /*#__PURE__*/function (_Component) {
723
711
  onBlur: this.onContainerBlur,
724
712
  ref: this.comboBoxRefCallback
725
713
  }), ___EmotionJSX(EuiComboBoxInput, {
726
- autoSizeInputRef: this.autoSizeInputRefCallback,
727
714
  compressed: compressed,
728
715
  focusedOptionId: this.hasActiveOption() ? this.rootId("_option-".concat(this.state.activeOptionIndex)) : undefined,
729
716
  fullWidth: fullWidth,
@@ -21,8 +21,7 @@ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Re
21
21
 
22
22
  import React, { Component } from 'react';
23
23
  import classNames from 'classnames';
24
- import AutosizeInput from 'react-input-autosize';
25
- import { keys } from '../../../services';
24
+ import { keys, CanvasTextUtils } from '../../../services';
26
25
  import { EuiScreenReaderOnly } from '../../accessibility';
27
26
  import { EuiFormControlLayout } from '../../form/form_control_layout';
28
27
  import { getFormControlClassNameForIconCount } from '../../form/form_control_layout/_num_icons';
@@ -39,8 +38,27 @@ export var EuiComboBoxInput = /*#__PURE__*/function (_Component) {
39
38
  }
40
39
  _this = _super.call.apply(_super, [this].concat(args));
41
40
  _defineProperty(_assertThisInitialized(_this), "state", {
41
+ inputWidth: 2,
42
42
  hasFocus: false
43
43
  });
44
+ _defineProperty(_assertThisInitialized(_this), "widthUtils", void 0);
45
+ _defineProperty(_assertThisInitialized(_this), "inputRefCallback", function (el) {
46
+ var _this$props$inputRef, _this$props;
47
+ _this.widthUtils = new CanvasTextUtils({
48
+ container: el
49
+ });
50
+ (_this$props$inputRef = (_this$props = _this.props).inputRef) === null || _this$props$inputRef === void 0 ? void 0 : _this$props$inputRef.call(_this$props, el);
51
+ });
52
+ _defineProperty(_assertThisInitialized(_this), "updateInputSize", function (inputValue) {
53
+ if (!_this.widthUtils) return;
54
+ _this.widthUtils.setTextToCheck(inputValue);
55
+ // Canvas has minute subpixel differences in rendering compared to DOM
56
+ // We'll buffer the input by ~2px just to ensure sufficient width
57
+ var inputWidth = Math.ceil(_this.widthUtils.textWidth) + 2;
58
+ _this.setState({
59
+ inputWidth: inputWidth
60
+ });
61
+ });
44
62
  _defineProperty(_assertThisInitialized(_this), "updatePosition", function () {
45
63
  // Wait a beat for the DOM to update, since we depend on DOM elements' bounds.
46
64
  requestAnimationFrame(function () {
@@ -62,13 +80,13 @@ export var EuiComboBoxInput = /*#__PURE__*/function (_Component) {
62
80
  });
63
81
  });
64
82
  _defineProperty(_assertThisInitialized(_this), "onKeyDown", function (event) {
65
- var _this$props = _this.props,
66
- searchValue = _this$props.searchValue,
67
- selectedOptions = _this$props.selectedOptions,
68
- onRemoveOption = _this$props.onRemoveOption,
69
- singleSelection = _this$props.singleSelection,
70
- isListOpen = _this$props.isListOpen,
71
- onOpenListClick = _this$props.onOpenListClick;
83
+ var _this$props2 = _this.props,
84
+ searchValue = _this$props2.searchValue,
85
+ selectedOptions = _this$props2.selectedOptions,
86
+ onRemoveOption = _this$props2.onRemoveOption,
87
+ singleSelection = _this$props2.singleSelection,
88
+ isListOpen = _this$props2.isListOpen,
89
+ onOpenListClick = _this$props2.onOpenListClick;
72
90
 
73
91
  // When backspacing from an empty input, delete the last pill option in the list
74
92
  var searchIsEmpty = !searchValue.length;
@@ -81,18 +99,10 @@ export var EuiComboBoxInput = /*#__PURE__*/function (_Component) {
81
99
  }
82
100
  });
83
101
  _defineProperty(_assertThisInitialized(_this), "inputOnChange", function (event) {
84
- var _this$props2 = _this.props,
85
- onChange = _this$props2.onChange,
86
- searchValue = _this$props2.searchValue;
87
- if (onChange) {
88
- onChange(event.target.value);
89
- }
90
- });
91
- _defineProperty(_assertThisInitialized(_this), "inputRefCallback", function (ref) {
92
- var autoSizeInputRef = _this.props.autoSizeInputRef;
93
- if (autoSizeInputRef) {
94
- autoSizeInputRef(ref);
95
- }
102
+ var _this$props$onChange, _this$props3;
103
+ var value = event.target.value;
104
+ _this.updateInputSize(value);
105
+ (_this$props$onChange = (_this$props3 = _this.props).onChange) === null || _this$props$onChange === void 0 ? void 0 : _this$props$onChange.call(_this$props3, value);
96
106
  });
97
107
  return _this;
98
108
  }
@@ -110,35 +120,34 @@ export var EuiComboBoxInput = /*#__PURE__*/function (_Component) {
110
120
  }, {
111
121
  key: "render",
112
122
  value: function render() {
113
- var _this$props3 = this.props,
114
- compressed = _this$props3.compressed,
115
- focusedOptionId = _this$props3.focusedOptionId,
116
- fullWidth = _this$props3.fullWidth,
117
- hasSelectedOptions = _this$props3.hasSelectedOptions,
118
- id = _this$props3.id,
119
- inputRef = _this$props3.inputRef,
120
- isDisabled = _this$props3.isDisabled,
121
- isListOpen = _this$props3.isListOpen,
122
- noIcon = _this$props3.noIcon,
123
- onClear = _this$props3.onClear,
124
- onClick = _this$props3.onClick,
125
- onCloseListClick = _this$props3.onCloseListClick,
126
- onOpenListClick = _this$props3.onOpenListClick,
127
- onRemoveOption = _this$props3.onRemoveOption,
128
- placeholder = _this$props3.placeholder,
129
- rootId = _this$props3.rootId,
130
- searchValue = _this$props3.searchValue,
131
- selectedOptions = _this$props3.selectedOptions,
132
- singleSelectionProp = _this$props3.singleSelection,
133
- toggleButtonRef = _this$props3.toggleButtonRef,
134
- value = _this$props3.value,
135
- prepend = _this$props3.prepend,
136
- append = _this$props3.append,
137
- isLoading = _this$props3.isLoading,
138
- isInvalid = _this$props3.isInvalid,
139
- autoFocus = _this$props3.autoFocus,
140
- ariaLabel = _this$props3['aria-label'],
141
- ariaLabelledby = _this$props3['aria-labelledby'];
123
+ var _this$props4 = this.props,
124
+ compressed = _this$props4.compressed,
125
+ focusedOptionId = _this$props4.focusedOptionId,
126
+ fullWidth = _this$props4.fullWidth,
127
+ hasSelectedOptions = _this$props4.hasSelectedOptions,
128
+ id = _this$props4.id,
129
+ isDisabled = _this$props4.isDisabled,
130
+ isListOpen = _this$props4.isListOpen,
131
+ noIcon = _this$props4.noIcon,
132
+ onClear = _this$props4.onClear,
133
+ onClick = _this$props4.onClick,
134
+ onCloseListClick = _this$props4.onCloseListClick,
135
+ onOpenListClick = _this$props4.onOpenListClick,
136
+ onRemoveOption = _this$props4.onRemoveOption,
137
+ placeholder = _this$props4.placeholder,
138
+ rootId = _this$props4.rootId,
139
+ searchValue = _this$props4.searchValue,
140
+ selectedOptions = _this$props4.selectedOptions,
141
+ singleSelectionProp = _this$props4.singleSelection,
142
+ toggleButtonRef = _this$props4.toggleButtonRef,
143
+ value = _this$props4.value,
144
+ prepend = _this$props4.prepend,
145
+ append = _this$props4.append,
146
+ isLoading = _this$props4.isLoading,
147
+ isInvalid = _this$props4.isInvalid,
148
+ autoFocus = _this$props4.autoFocus,
149
+ ariaLabel = _this$props4['aria-label'],
150
+ ariaLabelledby = _this$props4['aria-labelledby'];
142
151
  var singleSelection = Boolean(singleSelectionProp);
143
152
  var asPlainText = singleSelectionProp && _typeof(singleSelectionProp) === 'object' && singleSelectionProp.asPlainText || false;
144
153
  var pills = selectedOptions ? selectedOptions.map(function (option) {
@@ -230,7 +239,7 @@ export var EuiComboBoxInput = /*#__PURE__*/function (_Component) {
230
239
  "data-test-subj": "comboBoxInput",
231
240
  onClick: onClick,
232
241
  tabIndex: -1 // becomes onBlur event's relatedTarget, otherwise relatedTarget is null when clicking on this div
233
- }, !singleSelection || !searchValue ? pills : null, placeholderMessage, ___EmotionJSX(AutosizeInput, {
242
+ }, !singleSelection || !searchValue ? pills : null, placeholderMessage, ___EmotionJSX("input", {
234
243
  "aria-activedescendant": focusedOptionId,
235
244
  "aria-autocomplete": "list",
236
245
  "aria-controls": isListOpen ? rootId('listbox') : '',
@@ -242,7 +251,6 @@ export var EuiComboBoxInput = /*#__PURE__*/function (_Component) {
242
251
  "data-test-subj": "comboBoxSearchInput",
243
252
  disabled: isDisabled,
244
253
  id: id,
245
- inputRef: inputRef,
246
254
  onBlur: this.onBlur,
247
255
  onChange: this.inputOnChange,
248
256
  onFocus: this.onFocus,
@@ -250,7 +258,7 @@ export var EuiComboBoxInput = /*#__PURE__*/function (_Component) {
250
258
  ref: this.inputRefCallback,
251
259
  role: "combobox",
252
260
  style: {
253
- fontSize: 14
261
+ inlineSize: this.state.inputWidth
254
262
  },
255
263
  value: searchValue,
256
264
  autoFocus: autoFocus
@@ -7,4 +7,4 @@
7
7
  */
8
8
 
9
9
  export { EuiTextTruncate } from './text_truncate';
10
- export { CanvasTextUtils, TruncationUtils } from './utils';
10
+ export { TruncationUtils } from './utils';
@@ -1,12 +1,12 @@
1
1
  import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
2
  import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
3
+ import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
4
+ import _createClass from "@babel/runtime/helpers/createClass";
3
5
  import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized";
4
6
  import _get from "@babel/runtime/helpers/get";
5
7
  import _inherits from "@babel/runtime/helpers/inherits";
6
8
  import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
7
9
  import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
8
- import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
9
- import _createClass from "@babel/runtime/helpers/createClass";
10
10
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
11
11
  var _excluded = ["fullText", "ellipsis", "availableWidth"];
12
12
  function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
@@ -19,57 +19,7 @@ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Re
19
19
  * Side Public License, v 1.
20
20
  */
21
21
 
22
- /**
23
- * Under the hood, a temporary Canvas element is created for manipulating text
24
- * & determining text width.
25
- *
26
- * To accurately measure text, canvas rendering requires either a container to
27
- * compute/derive font styles from, or a static font string (useful for usage
28
- * outside the DOM). Particular care should be applied when fallback fonts are
29
- * used, as more fallback fonts can lead to less precision.
30
- *
31
- * Please note that while canvas is more significantly more performant than DOM
32
- * measurement, there are subpixel to single digit pixel differences between
33
- * DOM and canvas measurement due to the different rendering engines used.
34
- */
35
- export var CanvasTextUtils = /*#__PURE__*/function () {
36
- function CanvasTextUtils(_ref) {
37
- var _this = this;
38
- var font = _ref.font,
39
- container = _ref.container;
40
- _classCallCheck(this, CanvasTextUtils);
41
- _defineProperty(this, "context", void 0);
42
- _defineProperty(this, "currentText", '');
43
- _defineProperty(this, "computeFontFromElement", function (element) {
44
- var computedStyles = window.getComputedStyle(element);
45
- // TODO: font-stretch is not included even though it potentially should be
46
- // @see https://developer.mozilla.org/en-US/docs/Web/CSS/font#constituent_properties
47
- // It appears to be unsupported and/or breaks font computation in canvas
48
- return ['font-style', 'font-variant', 'font-weight', 'font-size', 'font-family'].map(function (prop) {
49
- return computedStyles.getPropertyValue(prop);
50
- }).join(' ').trim();
51
- });
52
- _defineProperty(this, "setTextToCheck", function (text) {
53
- _this.currentText = text;
54
- });
55
- this.context = document.createElement('canvas').getContext('2d');
56
-
57
- // Set the canvas font to ensure text width calculations are correct
58
- if (font) {
59
- this.context.font = font;
60
- } else if (container) {
61
- this.context.font = this.computeFontFromElement(container);
62
- }
63
- }
64
- _createClass(CanvasTextUtils, [{
65
- key: "textWidth",
66
- get: function get() {
67
- return this.context.measureText(this.currentText).width;
68
- }
69
- }]);
70
- return CanvasTextUtils;
71
- }();
72
-
22
+ import { CanvasTextUtils } from '../../services/canvas';
73
23
  /**
74
24
  * Utilities for truncating types at various positions, as well as
75
25
  * determining whether truncation is possible or even necessary.
@@ -77,22 +27,22 @@ export var CanvasTextUtils = /*#__PURE__*/function () {
77
27
  export var TruncationUtils = /*#__PURE__*/function (_CanvasTextUtils) {
78
28
  _inherits(TruncationUtils, _CanvasTextUtils);
79
29
  var _super = _createSuper(TruncationUtils);
80
- function TruncationUtils(_ref2) {
81
- var _this2;
82
- var fullText = _ref2.fullText,
83
- ellipsis = _ref2.ellipsis,
84
- _availableWidth = _ref2.availableWidth,
85
- rest = _objectWithoutProperties(_ref2, _excluded);
30
+ function TruncationUtils(_ref) {
31
+ var _this;
32
+ var fullText = _ref.fullText,
33
+ ellipsis = _ref.ellipsis,
34
+ _availableWidth = _ref.availableWidth,
35
+ rest = _objectWithoutProperties(_ref, _excluded);
86
36
  _classCallCheck(this, TruncationUtils);
87
- _this2 = _super.call(this, rest);
88
- _defineProperty(_assertThisInitialized(_this2), "fullText", void 0);
89
- _defineProperty(_assertThisInitialized(_this2), "ellipsis", void 0);
90
- _defineProperty(_assertThisInitialized(_this2), "availableWidth", void 0);
37
+ _this = _super.call(this, rest);
38
+ _defineProperty(_assertThisInitialized(_this), "fullText", void 0);
39
+ _defineProperty(_assertThisInitialized(_this), "ellipsis", void 0);
40
+ _defineProperty(_assertThisInitialized(_this), "availableWidth", void 0);
91
41
  /**
92
42
  * Performance utilities
93
43
  */
94
- _defineProperty(_assertThisInitialized(_this2), "debugPerformance", false);
95
- _defineProperty(_assertThisInitialized(_this2), "debugCounter", 0);
44
+ _defineProperty(_assertThisInitialized(_this), "debugPerformance", false);
45
+ _defineProperty(_assertThisInitialized(_this), "debugCounter", 0);
96
46
  /**
97
47
  * Internal utils for calculating a ratio based on the passed available width
98
48
  * vs the full text width.
@@ -100,21 +50,21 @@ export var TruncationUtils = /*#__PURE__*/function (_CanvasTextUtils) {
100
50
  * be slightly over the available width, which we can then remove from
101
51
  * character-by-character until the text just fits within the available width.
102
52
  */
103
- _defineProperty(_assertThisInitialized(_this2), "widthRatio", 0);
104
- _defineProperty(_assertThisInitialized(_this2), "setTextWidthRatio", function () {
105
- var text = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _this2.fullText;
53
+ _defineProperty(_assertThisInitialized(_this), "widthRatio", 0);
54
+ _defineProperty(_assertThisInitialized(_this), "setTextWidthRatio", function () {
55
+ var text = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _this.fullText;
106
56
  var textToOffset = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
107
57
  // Account for reduced available width due to (e.g.) truncation offset
108
- var availableWidth = _this2.availableWidth;
58
+ var availableWidth = _this.availableWidth;
109
59
  if (textToOffset) {
110
- _this2.setTextToCheck(textToOffset);
111
- availableWidth = availableWidth - _this2.textWidth;
60
+ _this.setTextToCheck(textToOffset);
61
+ availableWidth = availableWidth - _this.textWidth;
112
62
  }
113
- _this2.setTextToCheck(text);
114
- _this2.widthRatio = availableWidth / _this2.textWidth;
63
+ _this.setTextToCheck(text);
64
+ _this.widthRatio = availableWidth / _this.textWidth;
115
65
  });
116
- _defineProperty(_assertThisInitialized(_this2), "getTextFromRatio", function (text, type) {
117
- var characterRatio = Math.ceil(text.length * _this2.widthRatio);
66
+ _defineProperty(_assertThisInitialized(_this), "getTextFromRatio", function (text, type) {
67
+ var characterRatio = Math.ceil(text.length * _this.widthRatio);
118
68
  var index = type === 'start' ? text.length - characterRatio : characterRatio;
119
69
  var _splitText$at = splitText(text).at(index),
120
70
  _splitText$at2 = _slicedToArray(_splitText$at, 2),
@@ -125,24 +75,24 @@ export var TruncationUtils = /*#__PURE__*/function (_CanvasTextUtils) {
125
75
  /**
126
76
  * Early return checks
127
77
  */
128
- _defineProperty(_assertThisInitialized(_this2), "checkIfTruncationIsNeeded", function () {
129
- _this2.setTextToCheck(_this2.fullText);
130
- if (_this2.availableWidth >= _this2.textWidth) {
78
+ _defineProperty(_assertThisInitialized(_this), "checkIfTruncationIsNeeded", function () {
79
+ _this.setTextToCheck(_this.fullText);
80
+ if (_this.availableWidth >= _this.textWidth) {
131
81
  return false;
132
82
  }
133
83
  });
134
- _defineProperty(_assertThisInitialized(_this2), "checkSufficientEllipsisWidth", function (truncation) {
135
- var textToCheck = truncation === 'startEnd' ? "".concat(_this2.ellipsis, " ").concat(_this2.ellipsis) // startEnd needs a little more space
136
- : _this2.ellipsis;
137
- _this2.setTextToCheck(textToCheck);
138
- if (_this2.textWidth >= _this2.availableWidth * 0.9) {
84
+ _defineProperty(_assertThisInitialized(_this), "checkSufficientEllipsisWidth", function (truncation) {
85
+ var textToCheck = truncation === 'startEnd' ? "".concat(_this.ellipsis, " ").concat(_this.ellipsis) // startEnd needs a little more space
86
+ : _this.ellipsis;
87
+ _this.setTextToCheck(textToCheck);
88
+ if (_this.textWidth >= _this.availableWidth * 0.9) {
139
89
  console.error('The truncation ellipsis is larger than the available width. No text can be rendered.');
140
90
  return false;
141
91
  }
142
92
  });
143
- _defineProperty(_assertThisInitialized(_this2), "checkTruncationOffsetWidth", function (text) {
144
- _this2.setTextToCheck(text);
145
- if (_this2.textWidth > _this2.availableWidth) {
93
+ _defineProperty(_assertThisInitialized(_this), "checkTruncationOffsetWidth", function (text) {
94
+ _this.setTextToCheck(text);
95
+ if (_this.textWidth > _this.availableWidth) {
146
96
  console.error('The passed truncationOffset is too large for the available width. Truncating the offset instead.');
147
97
  return false;
148
98
  }
@@ -150,19 +100,19 @@ export var TruncationUtils = /*#__PURE__*/function (_CanvasTextUtils) {
150
100
  /**
151
101
  * Truncation types logic. This is where the magic happens
152
102
  */
153
- _defineProperty(_assertThisInitialized(_this2), "truncateStart", function (truncationOffset) {
154
- var truncatedText = _this2.fullText;
103
+ _defineProperty(_assertThisInitialized(_this), "truncateStart", function (truncationOffset) {
104
+ var truncatedText = _this.fullText;
155
105
  var leadingText = '';
156
106
  var combinedText = function combinedText() {
157
107
  return leadingText + truncatedText;
158
108
  };
159
109
  if (truncationOffset) {
160
- var _splitText$at3 = splitText(_this2.fullText).at(truncationOffset);
110
+ var _splitText$at3 = splitText(_this.fullText).at(truncationOffset);
161
111
  var _splitText$at4 = _slicedToArray(_splitText$at3, 2);
162
112
  leadingText = _splitText$at4[0];
163
113
  truncatedText = _splitText$at4[1];
164
- var widthCheck = leadingText + _this2.ellipsis;
165
- if (_this2.checkTruncationOffsetWidth(widthCheck) === false) {
114
+ var widthCheck = leadingText + _this.ellipsis;
115
+ if (_this.checkTruncationOffsetWidth(widthCheck) === false) {
166
116
  truncatedText = leadingText;
167
117
  leadingText = '';
168
118
  }
@@ -170,30 +120,30 @@ export var TruncationUtils = /*#__PURE__*/function (_CanvasTextUtils) {
170
120
 
171
121
  // Get text width ratio width accounting for any truncation offset text,
172
122
  // and guesstimate an initial truncated string
173
- _this2.setTextWidthRatio(truncatedText, leadingText);
174
- truncatedText = _this2.getTextFromRatio(truncatedText, 'start');
175
- leadingText += _this2.ellipsis;
176
- _this2.setTextToCheck(combinedText());
177
- while (_this2.textWidth > _this2.availableWidth) {
123
+ _this.setTextWidthRatio(truncatedText, leadingText);
124
+ truncatedText = _this.getTextFromRatio(truncatedText, 'start');
125
+ leadingText += _this.ellipsis;
126
+ _this.setTextToCheck(combinedText());
127
+ while (_this.textWidth > _this.availableWidth) {
178
128
  truncatedText = removeFirstCharacter(truncatedText);
179
- _this2.setTextToCheck(combinedText());
129
+ _this.setTextToCheck(combinedText());
180
130
  }
181
131
  return combinedText();
182
132
  });
183
- _defineProperty(_assertThisInitialized(_this2), "truncateEnd", function (truncationOffset) {
184
- var truncatedText = _this2.fullText;
133
+ _defineProperty(_assertThisInitialized(_this), "truncateEnd", function (truncationOffset) {
134
+ var truncatedText = _this.fullText;
185
135
  var trailingText = '';
186
136
  var combinedText = function combinedText() {
187
137
  return truncatedText + trailingText;
188
138
  };
189
139
  if (truncationOffset) {
190
- var index = _this2.fullText.length - truncationOffset;
191
- var _splitText$at5 = splitText(_this2.fullText).at(index);
140
+ var index = _this.fullText.length - truncationOffset;
141
+ var _splitText$at5 = splitText(_this.fullText).at(index);
192
142
  var _splitText$at6 = _slicedToArray(_splitText$at5, 2);
193
143
  truncatedText = _splitText$at6[0];
194
144
  trailingText = _splitText$at6[1];
195
- var widthCheck = _this2.ellipsis + trailingText;
196
- if (_this2.checkTruncationOffsetWidth(widthCheck) === false) {
145
+ var widthCheck = _this.ellipsis + trailingText;
146
+ if (_this.checkTruncationOffsetWidth(widthCheck) === false) {
197
147
  truncatedText = trailingText;
198
148
  trailingText = '';
199
149
  }
@@ -201,78 +151,78 @@ export var TruncationUtils = /*#__PURE__*/function (_CanvasTextUtils) {
201
151
 
202
152
  // Get text width ratio width accounting for any truncation offset text,
203
153
  // and guesstimate an initial truncated string
204
- _this2.setTextWidthRatio(truncatedText, trailingText);
205
- truncatedText = _this2.getTextFromRatio(truncatedText, 'end');
206
- trailingText = _this2.ellipsis + trailingText;
207
- _this2.setTextToCheck(combinedText());
208
- while (_this2.textWidth > _this2.availableWidth) {
154
+ _this.setTextWidthRatio(truncatedText, trailingText);
155
+ truncatedText = _this.getTextFromRatio(truncatedText, 'end');
156
+ trailingText = _this.ellipsis + trailingText;
157
+ _this.setTextToCheck(combinedText());
158
+ while (_this.textWidth > _this.availableWidth) {
209
159
  truncatedText = removeLastCharacter(truncatedText);
210
- _this2.setTextToCheck(combinedText());
160
+ _this.setTextToCheck(combinedText());
211
161
  }
212
162
  return combinedText();
213
163
  });
214
- _defineProperty(_assertThisInitialized(_this2), "truncateStartEndAtPosition", function (truncationPosition) {
164
+ _defineProperty(_assertThisInitialized(_this), "truncateStartEndAtPosition", function (truncationPosition) {
215
165
  // Split the text from the anchor position, using the width ratio
216
166
  // to get the starting and ending indices from the position
217
- _this2.setTextWidthRatio();
218
- var characterRatio = Math.floor(_this2.fullText.length * _this2.widthRatio / 2);
167
+ _this.setTextWidthRatio();
168
+ var characterRatio = Math.floor(_this.fullText.length * _this.widthRatio / 2);
219
169
  var truncateStart = truncationPosition - characterRatio;
220
170
  var truncateEnd = truncationPosition + characterRatio;
221
171
 
222
172
  // If either of the approximate start/end truncation indices go beyond the
223
173
  // bounds of the actual text, we can simply use end or start truncation instead
224
174
  if (truncateStart < 0) {
225
- return _this2.truncateEnd();
175
+ return _this.truncateEnd();
226
176
  }
227
- if (truncateEnd >= _this2.fullText.length) {
228
- return _this2.truncateStart();
177
+ if (truncateEnd >= _this.fullText.length) {
178
+ return _this.truncateStart();
229
179
  }
230
- var truncatedText = _this2.fullText.substring(truncateStart, truncateEnd);
180
+ var truncatedText = _this.fullText.substring(truncateStart, truncateEnd);
231
181
  var combinedText = function combinedText() {
232
- return _this2.ellipsis + truncatedText + _this2.ellipsis;
182
+ return _this.ellipsis + truncatedText + _this.ellipsis;
233
183
  };
234
- _this2.setTextToCheck(combinedText());
184
+ _this.setTextToCheck(combinedText());
235
185
  var alternating;
236
- while (_this2.textWidth > _this2.availableWidth) {
186
+ while (_this.textWidth > _this.availableWidth) {
237
187
  truncatedText = alternating ? removeLastCharacter(truncatedText) : removeFirstCharacter(truncatedText);
238
188
  alternating = !alternating;
239
- _this2.setTextToCheck(combinedText());
189
+ _this.setTextToCheck(combinedText());
240
190
  }
241
191
  return combinedText();
242
192
  });
243
- _defineProperty(_assertThisInitialized(_this2), "truncateStartEndAtMiddle", function () {
244
- var middlePosition = Math.floor(_this2.fullText.length / 2);
245
- return _this2.truncateStartEndAtPosition(middlePosition);
193
+ _defineProperty(_assertThisInitialized(_this), "truncateStartEndAtMiddle", function () {
194
+ var middlePosition = Math.floor(_this.fullText.length / 2);
195
+ return _this.truncateStartEndAtPosition(middlePosition);
246
196
  });
247
- _defineProperty(_assertThisInitialized(_this2), "truncateMiddle", function () {
248
- var middlePosition = Math.floor(_this2.fullText.length / 2);
249
- var _splitText$at7 = splitText(_this2.fullText).at(middlePosition),
197
+ _defineProperty(_assertThisInitialized(_this), "truncateMiddle", function () {
198
+ var middlePosition = Math.floor(_this.fullText.length / 2);
199
+ var _splitText$at7 = splitText(_this.fullText).at(middlePosition),
250
200
  _splitText$at8 = _slicedToArray(_splitText$at7, 2),
251
201
  firstHalf = _splitText$at8[0],
252
202
  secondHalf = _splitText$at8[1];
253
- _this2.setTextWidthRatio();
254
- firstHalf = _this2.getTextFromRatio(firstHalf, 'end');
255
- secondHalf = _this2.getTextFromRatio(secondHalf, 'start');
203
+ _this.setTextWidthRatio();
204
+ firstHalf = _this.getTextFromRatio(firstHalf, 'end');
205
+ secondHalf = _this.getTextFromRatio(secondHalf, 'start');
256
206
  var combinedText = function combinedText() {
257
- return firstHalf + _this2.ellipsis + secondHalf;
207
+ return firstHalf + _this.ellipsis + secondHalf;
258
208
  };
259
- _this2.setTextToCheck(combinedText());
209
+ _this.setTextToCheck(combinedText());
260
210
  var alternating;
261
- while (_this2.textWidth > _this2.availableWidth) {
211
+ while (_this.textWidth > _this.availableWidth) {
262
212
  alternating = !alternating;
263
213
  if (alternating) {
264
214
  firstHalf = removeLastCharacter(firstHalf);
265
215
  } else {
266
216
  secondHalf = removeFirstCharacter(secondHalf);
267
217
  }
268
- _this2.setTextToCheck(combinedText());
218
+ _this.setTextToCheck(combinedText());
269
219
  }
270
220
  return combinedText();
271
221
  });
272
- _this2.fullText = fullText;
273
- _this2.ellipsis = ellipsis;
274
- _this2.availableWidth = _availableWidth;
275
- return _this2;
222
+ _this.fullText = fullText;
223
+ _this.ellipsis = ellipsis;
224
+ _this.availableWidth = _availableWidth;
225
+ return _this;
276
226
  }
277
227
  _createClass(TruncationUtils, [{
278
228
  key: "textWidth",