@jetbrains/ring-ui-built 7.0.66 → 7.0.70

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 (231) hide show
  1. package/components/_helpers/anchor.js +12 -17
  2. package/components/_helpers/avatar-info.js +4 -5
  3. package/components/_helpers/button.classes.js +20 -21
  4. package/components/_helpers/caption.js +3 -3
  5. package/components/_helpers/card.js +26 -32
  6. package/components/_helpers/dialog-body-scroll-preventer.js +1 -2
  7. package/components/_helpers/icon-svg.js +9 -12
  8. package/components/_helpers/input.js +78 -86
  9. package/components/_helpers/loader-core.js +260 -0
  10. package/components/_helpers/query-assist-suggestions.js +0 -1
  11. package/components/_helpers/select-filter.js +19 -26
  12. package/components/_helpers/services-link.js +9 -12
  13. package/components/_helpers/sidebar.js +36 -44
  14. package/components/_helpers/tab-link.js +9 -11
  15. package/components/_helpers/theme.js +20 -24
  16. package/components/_helpers/title.js +12 -17
  17. package/components/alert/alert.js +41 -49
  18. package/components/alert/container.js +9 -12
  19. package/components/alert-service/alert-service.js +23 -32
  20. package/components/analytics/analytics-custom-plugin.js +12 -17
  21. package/components/analytics/analytics.js +1 -3
  22. package/components/auth/auth-core.js +128 -170
  23. package/components/auth/auth.js +3 -10
  24. package/components/auth/background-flow.js +5 -8
  25. package/components/auth/down-notification.js +9 -17
  26. package/components/auth/iframe-flow.js +13 -19
  27. package/components/auth/request-builder.js +4 -9
  28. package/components/auth/response-parser.js +9 -12
  29. package/components/auth/storage.js +12 -18
  30. package/components/auth/token-validator.js +19 -30
  31. package/components/auth/window-flow.js +22 -27
  32. package/components/auth-dialog/auth-dialog.js +40 -48
  33. package/components/auth-dialog-service/auth-dialog-service.js +10 -13
  34. package/components/avatar/avatar.figma.js +6 -6
  35. package/components/avatar/avatar.js +58 -59
  36. package/components/avatar/fallback-avatar.js +8 -11
  37. package/components/avatar-stack/avatar-stack.figma.js +10 -11
  38. package/components/avatar-stack/avatar-stack.js +25 -31
  39. package/components/banner/banner.js +0 -6
  40. package/components/breadcrumbs/breadcrumbs.figma.js +8 -6
  41. package/components/breadcrumbs/breadcrumbs.js +4 -5
  42. package/components/button/button.figma.js +15 -10
  43. package/components/button/button.js +59 -64
  44. package/components/button-group/button-group.js +11 -15
  45. package/components/button-group/caption.js +0 -1
  46. package/components/button-set/button-set.js +9 -12
  47. package/components/button-toolbar/button-toolbar.js +8 -11
  48. package/components/caret/caret.js +20 -28
  49. package/components/checkbox/checkbox-group.figma.js +8 -10
  50. package/components/checkbox/checkbox.figma.js +5 -5
  51. package/components/checkbox/checkbox.js +27 -35
  52. package/components/clipboard/clipboard-fallback.js +3 -3
  53. package/components/clipboard/clipboard.js +3 -16
  54. package/components/code/code.js +8 -14
  55. package/components/collapse/collapse-content.js +10 -15
  56. package/components/collapse/collapse-control.js +5 -7
  57. package/components/collapse/collapse.js +9 -11
  58. package/components/collapse/utils.js +1 -1
  59. package/components/confirm/confirm.js +17 -26
  60. package/components/confirm-service/confirm-service.js +30 -31
  61. package/components/content-layout/content-layout.js +21 -28
  62. package/components/content-layout/sidebar.js +0 -2
  63. package/components/contenteditable/contenteditable.js +23 -28
  64. package/components/control-help/control-help.js +8 -10
  65. package/components/control-label/control-label.js +12 -17
  66. package/components/data-list/data-list.js +57 -65
  67. package/components/data-list/data-list.mock.js +0 -4
  68. package/components/data-list/item.js +65 -72
  69. package/components/data-list/selection.js +11 -19
  70. package/components/data-list/title.js +0 -4
  71. package/components/date-picker/consts.js +3 -4
  72. package/components/date-picker/date-input.js +25 -33
  73. package/components/date-picker/date-picker.js +179 -193
  74. package/components/date-picker/date-popup.js +135 -127
  75. package/components/date-picker/day.d.ts +1 -1
  76. package/components/date-picker/day.js +24 -30
  77. package/components/date-picker/month-names.js +7 -12
  78. package/components/date-picker/month-slider.js +16 -22
  79. package/components/date-picker/month.js +3 -5
  80. package/components/date-picker/months.js +6 -6
  81. package/components/date-picker/weekdays.js +0 -1
  82. package/components/date-picker/years.js +20 -26
  83. package/components/dialog/dialog-body-scroll-preventer.js +0 -1
  84. package/components/dialog/dialog.js +73 -83
  85. package/components/dropdown/anchor.js +0 -4
  86. package/components/dropdown/dropdown.js +98 -114
  87. package/components/dropdown-menu/dropdown-menu.js +80 -79
  88. package/components/editable-heading/editable-heading.js +48 -54
  89. package/components/error-bubble/error-bubble.figma.js +4 -4
  90. package/components/error-bubble/error-bubble.js +9 -13
  91. package/components/error-message/error-message.js +1 -6
  92. package/components/footer/footer.js +11 -15
  93. package/components/global/compose-refs.js +1 -4
  94. package/components/global/compose.js +1 -4
  95. package/components/global/configuration.js +3 -3
  96. package/components/global/controls-height.js +0 -1
  97. package/components/global/create-stateful-context.js +10 -14
  98. package/components/global/data-tests.js +2 -10
  99. package/components/global/dom.js +6 -19
  100. package/components/global/focus-sensor-hoc.js +74 -87
  101. package/components/global/fuzzy-highlight.js +3 -8
  102. package/components/global/get-uid.js +1 -1
  103. package/components/global/inject-styles.js +5 -6
  104. package/components/global/listeners.js +2 -11
  105. package/components/global/memoize.js +0 -2
  106. package/components/global/normalize-indent.js +2 -6
  107. package/components/global/promise-with-timeout.js +4 -5
  108. package/components/global/react-dom-renderer.js +4 -9
  109. package/components/global/rerender-hoc.js +8 -11
  110. package/components/global/schedule-raf.js +1 -2
  111. package/components/global/theme.js +0 -5
  112. package/components/global/trivial-template-tag.js +1 -6
  113. package/components/global/url.js +2 -6
  114. package/components/global/use-event-callback.js +2 -3
  115. package/components/grid/col.js +7 -18
  116. package/components/grid/grid.js +9 -14
  117. package/components/grid/row.js +7 -11
  118. package/components/group/group.js +9 -12
  119. package/components/header/header-icon.js +8 -13
  120. package/components/header/header.js +16 -27
  121. package/components/header/links.js +7 -10
  122. package/components/header/logo.js +12 -16
  123. package/components/header/profile.js +73 -83
  124. package/components/header/services-link.js +0 -2
  125. package/components/header/services.js +32 -43
  126. package/components/header/smart-profile.js +44 -59
  127. package/components/header/smart-services.js +33 -45
  128. package/components/header/tray.js +8 -10
  129. package/components/heading/heading.js +27 -27
  130. package/components/http/http.js +120 -125
  131. package/components/http/http.mock.js +6 -10
  132. package/components/hub-source/hub-source-user.js +6 -13
  133. package/components/hub-source/hub-source-users-groups.js +8 -12
  134. package/components/hub-source/hub-source.js +8 -10
  135. package/components/i18n/i18n-context.js +4 -7
  136. package/components/i18n/i18n.js +5 -5
  137. package/components/icon/icon-svg.js +0 -4
  138. package/components/icon/icon.js +28 -32
  139. package/components/icon/index.js +0 -4
  140. package/components/input/input.figma.js +8 -8
  141. package/components/input/input.js +0 -4
  142. package/components/island/adaptive-island-hoc.js +19 -23
  143. package/components/island/content.js +70 -75
  144. package/components/island/header.js +21 -21
  145. package/components/island/island.js +11 -14
  146. package/components/link/clickable-link.js +30 -37
  147. package/components/link/link.js +27 -29
  148. package/components/list/list-custom.js +6 -11
  149. package/components/list/list-item.js +49 -56
  150. package/components/list/list-separator.js +0 -1
  151. package/components/list/list-title.js +0 -1
  152. package/components/list/list-users-groups-source.js +14 -22
  153. package/components/list/list.classes.js +8 -9
  154. package/components/list/list.js +387 -404
  155. package/components/loader/loader-core.js +2 -265
  156. package/components/loader/loader.d.ts +8 -0
  157. package/components/loader/loader.js +43 -29
  158. package/components/loader-inline/loader-inline.js +9 -12
  159. package/components/loader-screen/loader-screen.js +10 -14
  160. package/components/login-dialog/login-dialog.js +46 -54
  161. package/components/login-dialog/service.js +13 -15
  162. package/components/message/message.js +65 -79
  163. package/components/old-browsers-message/old-browsers-message-stop.js +0 -3
  164. package/components/old-browsers-message/old-browsers-message.js +1 -4
  165. package/components/old-browsers-message/white-list.js +5 -7
  166. package/components/pager/pager.js +73 -88
  167. package/components/panel/panel.js +9 -12
  168. package/components/permissions/permissions-cache.js +6 -8
  169. package/components/permissions/permissions.js +19 -21
  170. package/components/popup/popup.js +136 -145
  171. package/components/popup/popup.target.js +8 -10
  172. package/components/popup/position-css.js +19 -27
  173. package/components/popup/position.js +22 -28
  174. package/components/popup-menu/popup-menu.js +27 -37
  175. package/components/progress-bar/progress-bar.js +26 -32
  176. package/components/query-assist/query-assist-suggestions.js +0 -6
  177. package/components/query-assist/query-assist.js +432 -468
  178. package/components/radio/radio-item.js +30 -40
  179. package/components/radio/radio.js +6 -10
  180. package/components/scrollable-section/scrollable-section.js +7 -10
  181. package/components/select/select-filter.js +0 -6
  182. package/components/select/select-popup.js +155 -174
  183. package/components/select/select.js +464 -479
  184. package/components/shortcuts/core.js +40 -45
  185. package/components/shortcuts/shortcut-title.js +0 -1
  186. package/components/shortcuts/shortcuts-hoc.js +9 -15
  187. package/components/shortcuts/shortcuts.js +3 -5
  188. package/components/slider/slider.js +53 -66
  189. package/components/slider/slider.utils.js +1 -4
  190. package/components/storage/storage-local.js +2 -8
  191. package/components/storage/storage.js +0 -5
  192. package/components/style.css +1 -1
  193. package/components/tab-trap/tab-trap.js +21 -30
  194. package/components/table/cell.js +3 -4
  195. package/components/table/disable-hover-hoc.js +24 -28
  196. package/components/table/header-cell.js +30 -38
  197. package/components/table/header.js +20 -28
  198. package/components/table/multitable.js +81 -101
  199. package/components/table/row-with-focus-sensor.js +17 -28
  200. package/components/table/row.js +89 -99
  201. package/components/table/selection-adapter.js +0 -2
  202. package/components/table/selection-shortcuts-hoc.js +159 -161
  203. package/components/table/selection.js +23 -31
  204. package/components/table/simple-table.js +16 -22
  205. package/components/table/smart-table.js +19 -26
  206. package/components/table/table.js +137 -146
  207. package/components/tabs/collapsible-more.js +34 -47
  208. package/components/tabs/collapsible-tab.js +28 -33
  209. package/components/tabs/collapsible-tabs.js +16 -24
  210. package/components/tabs/custom-item.js +3 -6
  211. package/components/tabs/dumb-tabs.js +48 -64
  212. package/components/tabs/smart-tabs.js +14 -23
  213. package/components/tabs/tab-link.js +0 -2
  214. package/components/tabs/tab.js +0 -1
  215. package/components/tabs/tabs.js +0 -7
  216. package/components/tag/tag.js +30 -35
  217. package/components/tags-input/tags-input.js +192 -218
  218. package/components/tags-list/tags-list.js +26 -31
  219. package/components/text/text.js +16 -19
  220. package/components/toggle/toggle.js +19 -23
  221. package/components/tooltip/tooltip.js +110 -121
  222. package/components/upload/upload.js +19 -28
  223. package/components/user-agreement/service.js +247 -252
  224. package/components/user-agreement/toolbox.eula.js +160 -1
  225. package/components/user-agreement/user-agreement.js +23 -32
  226. package/components/user-card/card.js +0 -5
  227. package/components/user-card/smart-user-card-tooltip.js +41 -50
  228. package/components/user-card/tooltip.js +32 -38
  229. package/components/user-card/user-card.js +0 -5
  230. package/package.json +9 -3
  231. package/components/_helpers/_rollupPluginBabelHelpers.js +0 -72
@@ -1,8 +1,3 @@
1
- import { _ as _defineProperty, a as _objectWithoutProperties } from '../_helpers/_rollupPluginBabelHelpers.js';
2
- import 'core-js/modules/es.symbol.description.js';
3
- import 'core-js/modules/es.regexp.exec.js';
4
- import 'core-js/modules/es.string.replace.js';
5
- import 'core-js/modules/web.dom-collections.iterator.js';
6
1
  import { jsx, jsxs } from 'react/jsx-runtime';
7
2
  import { Component } from 'react';
8
3
  import debounce from 'just-debounce-it';
@@ -32,12 +27,10 @@ import 'react-dom';
32
27
  import '../global/schedule-raf.js';
33
28
  import '../tab-trap/tab-trap.js';
34
29
  import '../popup/position.js';
35
- import 'core-js/modules/es.array.sort.js';
36
30
  import '../popup/popup.consts.js';
37
31
  import '../popup/popup.target.js';
38
32
  import '../popup/position-css.js';
39
33
  import '../list/list.js';
40
- import 'core-js/modules/es.string.trim.js';
41
34
  import 'react-virtualized/dist/es/List';
42
35
  import 'react-virtualized/dist/es/AutoSizer';
43
36
  import 'react-virtualized/dist/es/WindowScroller';
@@ -80,7 +73,6 @@ import '../_helpers/button.classes.js';
80
73
  import '../control-label/control-label.js';
81
74
  import '../i18n/i18n.js';
82
75
 
83
- const _excluded = ["suggestions"];
84
76
  const POPUP_COMPENSATION = PopupMenu.ListProps.Dimension.ITEM_PADDING + PopupMenu.PopupProps.Dimension.BORDER_WIDTH;
85
77
  const ngModelStateField = 'query';
86
78
  function noop() {}
@@ -127,13 +119,19 @@ function cleanText(text) {
127
119
  + __icon__ \`string=\` Icon URI, Data URI is possible
128
120
  */
129
121
  class QueryAssist extends Component {
130
- static getDerivedStateFromProps(_ref, _ref2) {
131
- let {
132
- query
133
- } = _ref;
134
- let {
135
- prevQuery
136
- } = _ref2;
122
+ static defaultProps = {
123
+ onApply: noop,
124
+ onChange: noop,
125
+ onApplySuggestion: noop,
126
+ onClear: noop,
127
+ onFocusChange: noop,
128
+ size: Size.L
129
+ };
130
+ static getDerivedStateFromProps({
131
+ query
132
+ }, {
133
+ prevQuery
134
+ }) {
137
135
  const nextState = {
138
136
  prevQuery: query
139
137
  };
@@ -143,417 +141,23 @@ class QueryAssist extends Component {
143
141
  }
144
142
  return nextState;
145
143
  }
146
- constructor(_props) {
147
- var _this;
148
- super(_props);
149
- _this = this;
150
- _defineProperty(this, "state", {
151
- dirty: !this.props.query,
152
- query: this.props.query,
153
- placeholderEnabled: !this.props.query,
154
- shortcuts: !!this.props.focus,
155
- suggestions: [],
156
- showPopup: false
157
- });
158
- _defineProperty(this, "immediateState", void 0);
159
- _defineProperty(this, "requestData", void 0);
160
- _defineProperty(this, "ngModelStateField", ngModelStateField);
161
- // An array of {query: string; caret: number}[]
162
- _defineProperty(this, "historyStack", []);
163
- _defineProperty(this, "mouseIsDownOnPopup", void 0);
164
- _defineProperty(this, "handleFocusChange", e => {
165
- // otherwise it's blur and false
166
- const focus = e.type === 'focus';
167
- this.immediateState.focus = focus;
168
- if (!focus) {
169
- this.blurInput();
170
- // Close popup on blur by keyboard (mostly shift+tab)
171
- if (!this.mouseIsDownOnPopup) {
172
- this.closePopup();
173
- }
174
- } else {
175
- this.setCaretPosition();
176
- }
177
- if (!this.mouseIsDownOnPopup) {
178
- this.props.onFocusChange({
179
- focus
180
- });
181
- }
182
- if (this.state.shortcuts !== focus) {
183
- this.setState({
184
- shortcuts: focus
185
- });
186
- }
187
- });
188
- _defineProperty(this, "node", void 0);
189
- _defineProperty(this, "nodeRef", node => {
190
- this.node = node;
191
- });
192
- // eslint-disable-next-line complexity
193
- _defineProperty(this, "setCaretPosition", function () {
194
- let params = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
195
- const queryLength = _this.immediateState.query ? _this.immediateState.query.length : 0;
196
- const newCaretPosition = _this.immediateState.caret < queryLength ? _this.immediateState.caret : queryLength;
197
- if (params.fromContentEditable) {
198
- _this.immediateState.selection = _this.immediateState.selection ? _this.immediateState.selection : _this.state.query && _this.state.query.length || null;
199
- }
200
- if (_this.immediateState.focus && !_this.props.disabled) {
201
- if (typeof _this.immediateState.selection === 'number' && Number.isInteger(_this.immediateState.selection) && _this.immediateState.selection > -1) {
202
- var _this$caret;
203
- // Set to end of field value if newCaretPosition is inappropriate
204
- (_this$caret = _this.caret) === null || _this$caret === void 0 || _this$caret.setPosition(newCaretPosition >= 0 ? newCaretPosition : -1);
205
- _this.scrollInput();
206
- } else if (_this.immediateState.selection && typeof _this.immediateState.selection === 'object' && _this.immediateState.selection.startOffset !== undefined) {
207
- var _this$caret2;
208
- (_this$caret2 = _this.caret) === null || _this$caret2 === void 0 || _this$caret2.setPosition(_this.immediateState.selection);
209
- } else if (_this.immediateState.selection === undefined || params.forceSetCaret) {
210
- var _this$caret3;
211
- (_this$caret3 = _this.caret) === null || _this$caret3 === void 0 || _this$caret3.setPosition(-1);
212
- }
213
- }
214
- });
215
- _defineProperty(this, "togglePlaceholder", () => {
216
- const query = this.getQuery();
217
- const currentQueryIsEmpty = this.immediateState.query === '';
218
- const newQueryIsEmpty = query === '';
219
- if (newQueryIsEmpty !== currentQueryIsEmpty) {
220
- this.setState({
221
- placeholderEnabled: newQueryIsEmpty
222
- });
223
- }
224
- });
225
- _defineProperty(this, "isComposing", void 0);
226
- _defineProperty(this, "handleInput", e => {
227
- var _this$caret4, _currentCaret$positio;
228
- this.togglePlaceholder();
229
- const currentCaret = (_this$caret4 = this.caret) === null || _this$caret4 === void 0 ? void 0 : _this$caret4.getPosition();
230
- const props = {
231
- dirty: true,
232
- query: this.getQuery(),
233
- caret: typeof currentCaret === 'number' ? currentCaret : (_currentCaret$positio = currentCaret === null || currentCaret === void 0 ? void 0 : currentCaret.position) !== null && _currentCaret$positio !== void 0 ? _currentCaret$positio : 0,
234
- focus: true
235
- };
236
- if (this.immediateState.query === props.query && !this.isComposing) {
237
- this.handleCaretMove(e);
238
- return;
239
- }
240
- if (this.isComposing) {
241
- return;
242
- }
243
- this.immediateState = props;
244
- if (this.state.query) {
245
- var _this$state$styleRang;
246
- let i = 0;
247
- while (this.state.query[i] === this.immediateState.query[i] && i < this.state.query.length - 1) {
248
- i++;
249
- }
250
- const diff = this.immediateState.query.length - this.state.query.length;
251
- const originalIndex = this.immediateState.caret - diff;
252
- const ranges = [...((_this$state$styleRang = this.state.styleRanges) !== null && _this$state$styleRang !== void 0 ? _this$state$styleRang : [])];
253
- const range = ranges.find(r => originalIndex >= r.start && originalIndex <= r.start + r.length);
254
- if (range) {
255
- range.length += diff;
256
- }
257
- ranges.filter(r => r.start > originalIndex).forEach(r => {
258
- r.start += diff;
259
- });
260
- }
261
- this.props.onChange(props);
262
- if (this.props.autoOpen === 'force' || props.query.length > 0) {
263
- var _this$requestData;
264
- (_this$requestData = this.requestData) === null || _this$requestData === void 0 || _this$requestData.call(this);
265
- }
266
- });
267
- // It's necessary to prevent new element creation before any other hooks
268
- _defineProperty(this, "handleEnter", e => {
269
- if (e.key === 'Enter') {
270
- preventDefault(e);
271
- }
272
- });
273
- _defineProperty(this, "handleTab", e => {
274
- const list = this._popup && this._popup.list;
275
- const suggestion = list && (list.getSelected() || list.getFirst());
276
- if (suggestion && this.state.showPopup) {
277
- preventDefault(e);
278
- if (this.getQuery() !== this.immediateState.suggestionsQuery) {
279
- return false;
280
- }
281
- return this.handleComplete(suggestion, true);
282
- }
283
- if (this.state.loading) {
284
- preventDefault(e);
285
- return false;
286
- }
287
- return true;
288
- });
289
- _defineProperty(this, "setState", (state, resolve) => {
290
- super.setState(state, () => {
291
- this._pushHistory(state);
292
- resolve === null || resolve === void 0 || resolve();
293
- });
294
- });
295
- _defineProperty(this, "undo", e => {
296
- const previous = this.historyStack.splice(0, 2)[1];
297
- if (!previous) {
298
- return;
299
- }
300
- this.setState({
301
- query: previous.query
302
- }, () => {
303
- var _this$caret5;
304
- (_this$caret5 = this.caret) === null || _this$caret5 === void 0 || _this$caret5.setPosition(previous.caret);
305
- this.handleInput(e);
306
- });
307
- });
308
- _defineProperty(this, "handlePaste", e => {
309
- const INSERT_COMMAND = 'insertText';
310
- if (e.clipboardData && document.queryCommandSupported(INSERT_COMMAND)) {
311
- preventDefault(e);
312
- const text = cleanText(e.clipboardData.getData('text/plain'));
313
- document.execCommand(INSERT_COMMAND, false, text);
314
- this.handleInput(e);
315
- }
316
- });
317
- _defineProperty(this, "handleCaretMove", e => {
318
- var _this$caret6, _currentCaret$positio2;
319
- if (this.isComposing) {
320
- return;
321
- }
322
- const currentCaret = (_this$caret6 = this.caret) === null || _this$caret6 === void 0 ? void 0 : _this$caret6.getPosition();
323
- const caret = typeof currentCaret === 'number' ? currentCaret : (_currentCaret$positio2 = currentCaret === null || currentCaret === void 0 ? void 0 : currentCaret.position) !== null && _currentCaret$positio2 !== void 0 ? _currentCaret$positio2 : 0;
324
- const popupHidden = !this.state.showPopup && e.type === 'click';
325
- if (!this.props.disabled && (caret !== this.immediateState.caret || popupHidden)) {
326
- this.immediateState.prevCaret = this.immediateState.caret;
327
- this.immediateState.caret = caret;
328
- this.scrollInput();
329
- if (this.immediateState.query.length > 0) {
330
- var _this$requestData2;
331
- (_this$requestData2 = this.requestData) === null || _this$requestData2 === void 0 || _this$requestData2.call(this);
332
- }
333
- }
334
- if (this.props.autoOpen !== 'force' && this.immediateState.query.length < 1) {
335
- this.setState({
336
- showPopup: false
337
- });
338
- }
339
- });
340
- _defineProperty(this, "handleStyleRangesResponse", _ref3 => {
341
- let {
342
- suggestions
343
- } = _ref3,
344
- restProps = _objectWithoutProperties(_ref3, _excluded);
345
- return this.handleResponse(restProps);
346
- });
347
- _defineProperty(this, "handleResponse", function (_ref4) {
348
- let {
349
- query = '',
350
- caret = 0,
351
- styleRanges,
352
- suggestions = []
353
- } = _ref4;
354
- let afterCompletion = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
355
- return new Promise((resolve, reject) => {
356
- if (query === _this.getQuery() && (caret === _this.immediateState.caret || _this.immediateState.caret === undefined)) {
357
- var _this$caret7;
358
- // Do not setState on unmounted component
359
- if (!_this.node) {
360
- return;
361
- }
362
- const state = {
363
- dirty: _this.immediateState.dirty,
364
- loading: false,
365
- placeholderEnabled: !query,
366
- query,
367
- suggestions,
368
- showPopup: !!suggestions.length && (_this.props.autoOpen === 'force' || !afterCompletion)
369
- };
370
- _this.immediateState.suggestionsQuery = query;
371
- // Do not update deep equal styleRanges to simplify shouldComponentUpdate check
372
- if (!dequal(_this.state.styleRanges, styleRanges)) {
373
- state.styleRanges = styleRanges;
374
- }
375
- _this.immediateState.selection = (_this$caret7 = _this.caret) === null || _this$caret7 === void 0 ? void 0 : _this$caret7.getPosition({
376
- avoidFocus: true
377
- });
378
- _this.setState(state, resolve);
379
- } else {
380
- reject(new Error('Current and response queries mismatch'));
381
- }
382
- });
383
- });
384
- _defineProperty(this, "handleApply", () => {
385
- this.closePopup();
386
- this.immediateState.dirty = false;
387
- // Only set dirty to false when query is saved already
388
- if (this.immediateState.query === this.state.query) {
389
- this.setState({
390
- dirty: false
391
- });
392
- }
393
- return this.props.onApply(this.immediateState);
394
- });
395
- _defineProperty(this, "handleComplete", (data, replace) => {
396
- var _suggestion$caret, _suggestion$caret2, _this$requestData3;
397
- if (!data || !data.data) {
398
- this.handleApply();
399
- return;
400
- }
401
- const query = this.getQuery();
402
- const currentCaret = this.immediateState.caret;
403
- const suggestion = data.data;
404
- const prefix = suggestion.prefix || '';
405
- const suffix = suggestion.suffix || '';
406
- const state = {
407
- prevCaret: currentCaret,
408
- caret: (_suggestion$caret = suggestion.caret) !== null && _suggestion$caret !== void 0 ? _suggestion$caret : 0,
409
- selection: (_suggestion$caret2 = suggestion.caret) !== null && _suggestion$caret2 !== void 0 ? _suggestion$caret2 : 0,
410
- query: query.substr(0, suggestion.completionStart) + prefix + suggestion.option + suffix
411
- };
412
- if (typeof replace === 'boolean' && replace) {
413
- var _suggestion$completio;
414
- state.query += this.immediateState.query.substr((_suggestion$completio = suggestion.completionEnd) !== null && _suggestion$completio !== void 0 ? _suggestion$completio : 0);
415
- } else {
416
- state.query += this.immediateState.query.substr(this.immediateState.caret);
417
- }
418
- this.props.onChange(state);
419
- this.props.onApplySuggestion(data.data, state);
420
- const focusState = {
421
- focus: true
422
- };
423
- this.props.onFocusChange(focusState);
424
- if (state.query !== this.immediateState.query) {
425
- this.setState({
426
- placeholderEnabled: !state.query,
427
- query: state.query
428
- });
429
- }
430
- this.immediateState = Object.assign(state, focusState);
431
- if (this.immediateState.caret !== currentCaret) {
432
- this.setCaretPosition();
433
- }
434
- this.closePopup();
435
- (_this$requestData3 = this.requestData) === null || _this$requestData3 === void 0 || _this$requestData3.call(this, true);
436
- });
437
- _defineProperty(this, "requestStyleRanges", () => {
438
- const {
439
- query,
440
- caret
441
- } = this.immediateState;
442
- if (!query) {
443
- return Promise.reject(new Error('Query is empty'));
444
- }
445
- return this.sendRequest({
446
- query,
447
- caret,
448
- omitSuggestions: true
449
- }).then(this.handleStyleRangesResponse).catch(noop);
450
- });
451
- _defineProperty(this, "requestHandler", function () {
452
- let afterCompletion = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
453
- if (_this.props.disabled) {
454
- return Promise.reject(new Error('QueryAssist(@jetbrains/ring-ui): null exception'));
455
- }
456
- const {
457
- query,
458
- caret
459
- } = _this.immediateState;
460
- return _this.sendRequest({
461
- query,
462
- caret
463
- }).then(data => _this.handleResponse(data, afterCompletion)).catch(noop);
464
- });
465
- _defineProperty(this, "handleCtrlSpace", e => {
466
- preventDefault(e);
467
- if (!this.state.showPopup) {
468
- var _this$requestData4;
469
- (_this$requestData4 = this.requestData) === null || _this$requestData4 === void 0 || _this$requestData4.call(this);
470
- }
471
- });
472
- _defineProperty(this, "trackPopupMouseState", e => {
473
- this.mouseIsDownOnPopup = e.type === 'mousedown';
474
- });
475
- _defineProperty(this, "trackCompositionState", e => {
476
- this.isComposing = e.type !== 'compositionend';
477
- });
478
- _defineProperty(this, "closePopup", () => {
479
- if (this.node) {
480
- this.setState({
481
- showPopup: false
482
- });
483
- }
484
- });
485
- _defineProperty(this, "clearQuery", () => {
486
- const state = {
487
- dirty: false,
488
- caret: 0,
489
- query: '',
490
- focus: true
491
- };
492
- this.props.onChange(state);
493
- this.props.onClear();
494
- this.immediateState = state;
495
- this.setState({
496
- dirty: false,
497
- query: '',
498
- placeholderEnabled: true,
499
- loading: false
500
- });
501
- });
502
- _defineProperty(this, "input", void 0);
503
- _defineProperty(this, "caret", void 0);
504
- _defineProperty(this, "inputRef", node => {
505
- if (!node) {
506
- return;
507
- }
508
- this.input = node;
509
- this.caret = new Caret(this.input);
510
- });
511
- _defineProperty(this, "_popup", void 0);
512
- _defineProperty(this, "popupRef", node => {
513
- this._popup = node;
514
- });
515
- _defineProperty(this, "placeholder", void 0);
516
- _defineProperty(this, "placeholderRef", node => {
517
- this.placeholder = node;
518
- });
519
- _defineProperty(this, "glass", void 0);
520
- _defineProperty(this, "glassRef", node => {
521
- this.glass = node;
522
- });
523
- _defineProperty(this, "loader", void 0);
524
- _defineProperty(this, "loaderRef", node => {
525
- this.loader = node;
526
- });
527
- _defineProperty(this, "clear", void 0);
528
- _defineProperty(this, "clearRef", node => {
529
- this.clear = node;
530
- });
531
- _defineProperty(this, "shortcutsScope", getUID('ring-query-assist-'));
532
- _defineProperty(this, "shortcutsMap", {
533
- del: noop,
534
- enter: () => this.handleComplete(),
535
- 'command+enter': () => this.handleComplete(),
536
- 'ctrl+enter': () => this.handleComplete(),
537
- 'ctrl+space': this.handleCtrlSpace,
538
- tab: this.handleTab,
539
- 'meta+z': this.undo,
540
- right: noop,
541
- left: noop,
542
- space: noop,
543
- home: noop,
544
- end: noop
545
- });
546
- _defineProperty(this, "listShortcutsMap", {
547
- home: noop,
548
- end: noop
549
- });
550
- const _query = _props.query || '';
144
+ constructor(props) {
145
+ super(props);
146
+ const query = props.query || '';
551
147
  this.immediateState = {
552
- query: _query,
553
- caret: typeof _props.caret === 'number' && Number.isFinite(_props.caret) ? _props.caret : _query.length,
554
- focus: Boolean(_props.autoOpen || _props.focus)
148
+ query,
149
+ caret: typeof props.caret === 'number' && Number.isFinite(props.caret) ? props.caret : query.length,
150
+ focus: Boolean(props.autoOpen || props.focus)
555
151
  };
556
152
  }
153
+ state = {
154
+ dirty: !this.props.query,
155
+ query: this.props.query,
156
+ placeholderEnabled: !this.props.query,
157
+ shortcuts: !!this.props.focus,
158
+ suggestions: [],
159
+ showPopup: false
160
+ };
557
161
  componentDidMount() {
558
162
  const query = this.props.query || '';
559
163
  this.immediateState = {
@@ -590,18 +194,51 @@ class QueryAssist extends Component {
590
194
  if (typeof query === 'string' && queryChanged && query !== this.immediateState.query) {
591
195
  this.immediateState.query = query;
592
196
  if (query && (this.props.autoOpen === 'force' || prevProps.autoOpen && query.length > 0)) {
593
- var _this$requestData5;
594
- (_this$requestData5 = this.requestData) === null || _this$requestData5 === void 0 || _this$requestData5.call(this);
197
+ this.requestData?.();
595
198
  } else if (query) {
596
199
  this.requestStyleRanges();
597
200
  }
598
201
  }
599
202
  }
600
- updateFocus(_ref5) {
601
- let {
602
- focus,
603
- caret
604
- } = _ref5;
203
+ static ngModelStateField = ngModelStateField;
204
+ immediateState;
205
+ requestData;
206
+ ngModelStateField = ngModelStateField;
207
+ // An array of {query: string; caret: number}[]
208
+ historyStack = [];
209
+ mouseIsDownOnPopup;
210
+ handleFocusChange = e => {
211
+ // otherwise it's blur and false
212
+ const focus = e.type === 'focus';
213
+ this.immediateState.focus = focus;
214
+ if (!focus) {
215
+ this.blurInput();
216
+ // Close popup on blur by keyboard (mostly shift+tab)
217
+ if (!this.mouseIsDownOnPopup) {
218
+ this.closePopup();
219
+ }
220
+ } else {
221
+ this.setCaretPosition();
222
+ }
223
+ if (!this.mouseIsDownOnPopup) {
224
+ this.props.onFocusChange({
225
+ focus
226
+ });
227
+ }
228
+ if (this.state.shortcuts !== focus) {
229
+ this.setState({
230
+ shortcuts: focus
231
+ });
232
+ }
233
+ };
234
+ node;
235
+ nodeRef = node => {
236
+ this.node = node;
237
+ };
238
+ updateFocus({
239
+ focus,
240
+ caret
241
+ }) {
605
242
  const isCaretChanged = caret !== this.props.caret;
606
243
  const isFocusChanged = focus !== this.props.focus;
607
244
  if (isFocusChanged || isCaretChanged) {
@@ -609,35 +246,290 @@ class QueryAssist extends Component {
609
246
  this.setFocus(focusValue);
610
247
  }
611
248
  }
249
+ // eslint-disable-next-line complexity
250
+ setCaretPosition = (params = {}) => {
251
+ const queryLength = this.immediateState.query ? this.immediateState.query.length : 0;
252
+ const newCaretPosition = this.immediateState.caret < queryLength ? this.immediateState.caret : queryLength;
253
+ if (params.fromContentEditable) {
254
+ this.immediateState.selection = this.immediateState.selection ? this.immediateState.selection : this.state.query && this.state.query.length || null;
255
+ }
256
+ if (this.immediateState.focus && !this.props.disabled) {
257
+ if (typeof this.immediateState.selection === 'number' && Number.isInteger(this.immediateState.selection) && this.immediateState.selection > -1) {
258
+ // Set to end of field value if newCaretPosition is inappropriate
259
+ this.caret?.setPosition(newCaretPosition >= 0 ? newCaretPosition : -1);
260
+ this.scrollInput();
261
+ } else if (this.immediateState.selection && typeof this.immediateState.selection === 'object' && this.immediateState.selection.startOffset !== undefined) {
262
+ this.caret?.setPosition(this.immediateState.selection);
263
+ } else if (this.immediateState.selection === undefined || params.forceSetCaret) {
264
+ this.caret?.setPosition(-1);
265
+ }
266
+ }
267
+ };
612
268
  scrollInput() {
613
- var _this$caret8, _this$input, _this$input2, _this$input3, _this$input4;
614
- const caretOffset = (_this$caret8 = this.caret) === null || _this$caret8 === void 0 ? void 0 : _this$caret8.getOffset();
615
- if (((_this$input = this.input) === null || _this$input === void 0 ? void 0 : _this$input.clientWidth) !== ((_this$input2 = this.input) === null || _this$input2 === void 0 ? void 0 : _this$input2.scrollWidth) && caretOffset && (_this$input3 = this.input) !== null && _this$input3 !== void 0 && _this$input3.clientWidth && caretOffset > ((_this$input4 = this.input) === null || _this$input4 === void 0 ? void 0 : _this$input4.clientWidth)) {
269
+ const caretOffset = this.caret?.getOffset();
270
+ if (this.input?.clientWidth !== this.input?.scrollWidth && caretOffset && this.input?.clientWidth !== undefined && caretOffset > this.input?.clientWidth) {
616
271
  this.input.scrollLeft += caretOffset;
617
272
  }
618
273
  }
619
274
  getQuery() {
620
- var _this$input$textConte, _this$input5;
621
- return (_this$input$textConte = (_this$input5 = this.input) === null || _this$input5 === void 0 || (_this$input5 = _this$input5.textContent) === null || _this$input5 === void 0 ? void 0 : _this$input5.replace(/\s/g, ' ')) !== null && _this$input$textConte !== void 0 ? _this$input$textConte : '';
275
+ var _this$input$textConte;
276
+ return (_this$input$textConte = this.input?.textContent?.replace(/\s/g, ' ')) !== null && _this$input$textConte !== void 0 ? _this$input$textConte : '';
622
277
  }
623
278
  isRenderingGlassOrLoader() {
624
279
  const renderLoader = this.props.loader !== false && this.state.loading;
625
280
  return this.props.glass || renderLoader;
626
281
  }
282
+ togglePlaceholder = () => {
283
+ const query = this.getQuery();
284
+ const currentQueryIsEmpty = this.immediateState.query === '';
285
+ const newQueryIsEmpty = query === '';
286
+ if (newQueryIsEmpty !== currentQueryIsEmpty) {
287
+ this.setState({
288
+ placeholderEnabled: newQueryIsEmpty
289
+ });
290
+ }
291
+ };
292
+ isComposing;
293
+ handleInput = e => {
294
+ var _currentCaret$positio;
295
+ this.togglePlaceholder();
296
+ const currentCaret = this.caret?.getPosition();
297
+ const props = {
298
+ dirty: true,
299
+ query: this.getQuery(),
300
+ caret: typeof currentCaret === 'number' ? currentCaret : (_currentCaret$positio = currentCaret?.position) !== null && _currentCaret$positio !== void 0 ? _currentCaret$positio : 0,
301
+ focus: true
302
+ };
303
+ if (this.immediateState.query === props.query && !this.isComposing) {
304
+ this.handleCaretMove(e);
305
+ return;
306
+ }
307
+ if (this.isComposing) {
308
+ return;
309
+ }
310
+ this.immediateState = props;
311
+ if (this.state.query) {
312
+ var _this$state$styleRang;
313
+ let i = 0;
314
+ while (this.state.query[i] === this.immediateState.query[i] && i < this.state.query.length - 1) {
315
+ i++;
316
+ }
317
+ const diff = this.immediateState.query.length - this.state.query.length;
318
+ const originalIndex = this.immediateState.caret - diff;
319
+ const ranges = [...((_this$state$styleRang = this.state.styleRanges) !== null && _this$state$styleRang !== void 0 ? _this$state$styleRang : [])];
320
+ const range = ranges.find(r => originalIndex >= r.start && originalIndex <= r.start + r.length);
321
+ if (range) {
322
+ range.length += diff;
323
+ }
324
+ ranges.filter(r => r.start > originalIndex).forEach(r => {
325
+ r.start += diff;
326
+ });
327
+ }
328
+ this.props.onChange(props);
329
+ if (this.props.autoOpen === 'force' || props.query.length > 0) {
330
+ this.requestData?.();
331
+ }
332
+ };
333
+ // It's necessary to prevent new element creation before any other hooks
334
+ handleEnter = e => {
335
+ if (e.key === 'Enter') {
336
+ preventDefault(e);
337
+ }
338
+ };
339
+ handleTab = e => {
340
+ const list = this._popup && this._popup.list;
341
+ const suggestion = list && (list.getSelected() || list.getFirst());
342
+ if (suggestion && this.state.showPopup) {
343
+ preventDefault(e);
344
+ if (this.getQuery() !== this.immediateState.suggestionsQuery) {
345
+ return false;
346
+ }
347
+ return this.handleComplete(suggestion, true);
348
+ }
349
+ if (this.state.loading) {
350
+ preventDefault(e);
351
+ return false;
352
+ }
353
+ return true;
354
+ };
355
+ setState = (state, resolve) => {
356
+ super.setState(state, () => {
357
+ this._pushHistory(state);
358
+ resolve?.();
359
+ });
360
+ };
627
361
  _pushHistory(state) {
628
- var _this$historyStack$;
629
362
  const queryIsSet = 'query' in state;
630
- const queryIsSame = ((_this$historyStack$ = this.historyStack[0]) === null || _this$historyStack$ === void 0 ? void 0 : _this$historyStack$.query) === state.query;
363
+ const queryIsSame = this.historyStack[0]?.query === state.query;
631
364
  if (queryIsSet && !queryIsSame) {
632
- var _this$caret$getPositi, _this$caret9;
365
+ var _this$caret$getPositi;
633
366
  this.historyStack.unshift({
634
367
  query: state.query,
635
- caret: (_this$caret$getPositi = (_this$caret9 = this.caret) === null || _this$caret9 === void 0 ? void 0 : _this$caret9.getPosition({
368
+ caret: (_this$caret$getPositi = this.caret?.getPosition({
636
369
  avoidFocus: true
637
370
  })) !== null && _this$caret$getPositi !== void 0 ? _this$caret$getPositi : -1
638
371
  });
639
372
  }
640
373
  }
374
+ undo = e => {
375
+ const previous = this.historyStack.splice(0, 2)[1];
376
+ if (!previous) {
377
+ return;
378
+ }
379
+ this.setState({
380
+ query: previous.query
381
+ }, () => {
382
+ this.caret?.setPosition(previous.caret);
383
+ this.handleInput(e);
384
+ });
385
+ };
386
+ handlePaste = e => {
387
+ const INSERT_COMMAND = 'insertText';
388
+ if (e.clipboardData && document.queryCommandSupported(INSERT_COMMAND)) {
389
+ preventDefault(e);
390
+ const text = cleanText(e.clipboardData.getData('text/plain'));
391
+ document.execCommand(INSERT_COMMAND, false, text);
392
+ this.handleInput(e);
393
+ }
394
+ };
395
+ handleCaretMove = e => {
396
+ var _currentCaret$positio2;
397
+ if (this.isComposing) {
398
+ return;
399
+ }
400
+ const currentCaret = this.caret?.getPosition();
401
+ const caret = typeof currentCaret === 'number' ? currentCaret : (_currentCaret$positio2 = currentCaret?.position) !== null && _currentCaret$positio2 !== void 0 ? _currentCaret$positio2 : 0;
402
+ const popupHidden = !this.state.showPopup && e.type === 'click';
403
+ if (!this.props.disabled && (caret !== this.immediateState.caret || popupHidden)) {
404
+ this.immediateState.prevCaret = this.immediateState.caret;
405
+ this.immediateState.caret = caret;
406
+ this.scrollInput();
407
+ if (this.immediateState.query.length > 0) {
408
+ this.requestData?.();
409
+ }
410
+ }
411
+ if (this.props.autoOpen !== 'force' && this.immediateState.query.length < 1) {
412
+ this.setState({
413
+ showPopup: false
414
+ });
415
+ }
416
+ };
417
+ handleStyleRangesResponse = ({
418
+ suggestions,
419
+ ...restProps
420
+ }) => this.handleResponse(restProps);
421
+ handleResponse = ({
422
+ query = '',
423
+ caret = 0,
424
+ styleRanges,
425
+ suggestions = []
426
+ }, afterCompletion = false) => new Promise((resolve, reject) => {
427
+ if (query === this.getQuery() && (caret === this.immediateState.caret || this.immediateState.caret === undefined)) {
428
+ // Do not setState on unmounted component
429
+ if (!this.node) {
430
+ return;
431
+ }
432
+ const state = {
433
+ dirty: this.immediateState.dirty,
434
+ loading: false,
435
+ placeholderEnabled: !query,
436
+ query,
437
+ suggestions,
438
+ showPopup: !!suggestions.length && (this.props.autoOpen === 'force' || !afterCompletion)
439
+ };
440
+ this.immediateState.suggestionsQuery = query;
441
+ // Do not update deep equal styleRanges to simplify shouldComponentUpdate check
442
+ if (!dequal(this.state.styleRanges, styleRanges)) {
443
+ state.styleRanges = styleRanges;
444
+ }
445
+ this.immediateState.selection = this.caret?.getPosition({
446
+ avoidFocus: true
447
+ });
448
+ this.setState(state, resolve);
449
+ } else {
450
+ reject(new Error('Current and response queries mismatch'));
451
+ }
452
+ });
453
+ handleApply = () => {
454
+ this.closePopup();
455
+ this.immediateState.dirty = false;
456
+ // Only set dirty to false when query is saved already
457
+ if (this.immediateState.query === this.state.query) {
458
+ this.setState({
459
+ dirty: false
460
+ });
461
+ }
462
+ return this.props.onApply(this.immediateState);
463
+ };
464
+ handleComplete = (data, replace) => {
465
+ var _suggestion$caret, _suggestion$caret2;
466
+ if (!data || !data.data) {
467
+ this.handleApply();
468
+ return;
469
+ }
470
+ const query = this.getQuery();
471
+ const currentCaret = this.immediateState.caret;
472
+ const suggestion = data.data;
473
+ const prefix = suggestion.prefix || '';
474
+ const suffix = suggestion.suffix || '';
475
+ const state = {
476
+ prevCaret: currentCaret,
477
+ caret: (_suggestion$caret = suggestion.caret) !== null && _suggestion$caret !== void 0 ? _suggestion$caret : 0,
478
+ selection: (_suggestion$caret2 = suggestion.caret) !== null && _suggestion$caret2 !== void 0 ? _suggestion$caret2 : 0,
479
+ query: query.substr(0, suggestion.completionStart) + prefix + suggestion.option + suffix
480
+ };
481
+ if (typeof replace === 'boolean' && replace) {
482
+ var _suggestion$completio;
483
+ state.query += this.immediateState.query.substr((_suggestion$completio = suggestion.completionEnd) !== null && _suggestion$completio !== void 0 ? _suggestion$completio : 0);
484
+ } else {
485
+ state.query += this.immediateState.query.substr(this.immediateState.caret);
486
+ }
487
+ this.props.onChange(state);
488
+ this.props.onApplySuggestion(data.data, state);
489
+ const focusState = {
490
+ focus: true
491
+ };
492
+ this.props.onFocusChange(focusState);
493
+ if (state.query !== this.immediateState.query) {
494
+ this.setState({
495
+ placeholderEnabled: !state.query,
496
+ query: state.query
497
+ });
498
+ }
499
+ this.immediateState = Object.assign(state, focusState);
500
+ if (this.immediateState.caret !== currentCaret) {
501
+ this.setCaretPosition();
502
+ }
503
+ this.closePopup();
504
+ this.requestData?.(true);
505
+ };
506
+ requestStyleRanges = () => {
507
+ const {
508
+ query,
509
+ caret
510
+ } = this.immediateState;
511
+ if (!query) {
512
+ return Promise.reject(new Error('Query is empty'));
513
+ }
514
+ return this.sendRequest({
515
+ query,
516
+ caret,
517
+ omitSuggestions: true
518
+ }).then(this.handleStyleRangesResponse).catch(noop);
519
+ };
520
+ requestHandler = (afterCompletion = false) => {
521
+ if (this.props.disabled) {
522
+ return Promise.reject(new Error('QueryAssist(@jetbrains/ring-ui): null exception'));
523
+ }
524
+ const {
525
+ query,
526
+ caret
527
+ } = this.immediateState;
528
+ return this.sendRequest({
529
+ query,
530
+ caret
531
+ }).then(data => this.handleResponse(data, afterCompletion)).catch(noop);
532
+ };
641
533
  sendRequest(params) {
642
534
  const value = this.props.dataSource(params);
643
535
  const dataPromise = Promise.resolve(value);
@@ -675,8 +567,8 @@ class QueryAssist extends Component {
675
567
  const completionStartNode = inputChildren && typeof completionStart === 'number' && inputChildren[Math.min(completionStart, inputChildren.length - 1)];
676
568
  let offset = completionStartNode && getRect(completionStartNode).right - getRect(this.input).left;
677
569
  if (!offset) {
678
- var _this$caret$getOffset, _this$caret0;
679
- const caret = (_this$caret$getOffset = (_this$caret0 = this.caret) === null || _this$caret0 === void 0 ? void 0 : _this$caret0.getOffset()) !== null && _this$caret$getOffset !== void 0 ? _this$caret$getOffset : 0;
570
+ var _this$caret$getOffset;
571
+ const caret = (_this$caret$getOffset = this.caret?.getOffset()) !== null && _this$caret$getOffset !== void 0 ? _this$caret$getOffset : 0;
680
572
  // Do not compensate caret in the beginning of field
681
573
  if (caret === 0) {
682
574
  return minOffset;
@@ -686,11 +578,46 @@ class QueryAssist extends Component {
686
578
  const result = offset - POPUP_COMPENSATION;
687
579
  return result < minOffset ? minOffset : result;
688
580
  }
581
+ handleCtrlSpace = e => {
582
+ preventDefault(e);
583
+ if (!this.state.showPopup) {
584
+ this.requestData?.();
585
+ }
586
+ };
587
+ trackPopupMouseState = e => {
588
+ this.mouseIsDownOnPopup = e.type === 'mousedown';
589
+ };
590
+ trackCompositionState = e => {
591
+ this.isComposing = e.type !== 'compositionend';
592
+ };
593
+ closePopup = () => {
594
+ if (this.node) {
595
+ this.setState({
596
+ showPopup: false
597
+ });
598
+ }
599
+ };
600
+ clearQuery = () => {
601
+ const state = {
602
+ dirty: false,
603
+ caret: 0,
604
+ query: '',
605
+ focus: true
606
+ };
607
+ this.props.onChange(state);
608
+ this.props.onClear();
609
+ this.immediateState = state;
610
+ this.setState({
611
+ dirty: false,
612
+ query: '',
613
+ placeholderEnabled: true,
614
+ loading: false
615
+ });
616
+ };
689
617
  blurInput() {
690
618
  this.immediateState.selection = null;
691
619
  if (!this.props.focus) {
692
- var _this$caret1;
693
- (_this$caret1 = this.caret) === null || _this$caret1 === void 0 || _this$caret1.target.blur();
620
+ this.caret?.target.blur();
694
621
  }
695
622
  }
696
623
  /**
@@ -753,7 +680,7 @@ class QueryAssist extends Component {
753
680
  if (dirty && index === styleRanges.length - 1 && item.style === 'text') {
754
681
  return;
755
682
  }
756
- const styleName = "".concat(LETTER_CLASS, "-").concat(item.style.replace('_', '-'));
683
+ const styleName = `${LETTER_CLASS}-${item.style.replace('_', '-')}`;
757
684
  for (let i = item.start; i < item.start + item.length; i++) {
758
685
  classes[i] = styles[styleName];
759
686
  }
@@ -785,20 +712,67 @@ class QueryAssist extends Component {
785
712
  });
786
713
  }
787
714
  }
715
+ input;
716
+ caret;
717
+ inputRef = node => {
718
+ if (!node) {
719
+ return;
720
+ }
721
+ this.input = node;
722
+ this.caret = new Caret(this.input);
723
+ };
724
+ _popup;
725
+ popupRef = node => {
726
+ this._popup = node;
727
+ };
728
+ placeholder;
729
+ placeholderRef = node => {
730
+ this.placeholder = node;
731
+ };
732
+ glass;
733
+ glassRef = node => {
734
+ this.glass = node;
735
+ };
736
+ loader;
737
+ loaderRef = node => {
738
+ this.loader = node;
739
+ };
740
+ clear;
741
+ clearRef = node => {
742
+ this.clear = node;
743
+ };
744
+ shortcutsScope = getUID('ring-query-assist-');
745
+ shortcutsMap = {
746
+ del: noop,
747
+ enter: () => this.handleComplete(),
748
+ 'command+enter': () => this.handleComplete(),
749
+ 'ctrl+enter': () => this.handleComplete(),
750
+ 'ctrl+space': this.handleCtrlSpace,
751
+ tab: this.handleTab,
752
+ 'meta+z': this.undo,
753
+ right: noop,
754
+ left: noop,
755
+ space: noop,
756
+ home: noop,
757
+ end: noop
758
+ };
759
+ listShortcutsMap = {
760
+ home: noop,
761
+ end: noop
762
+ };
788
763
  renderActions() {
789
764
  const actions = [...(this.props.actions || [])];
790
765
  const renderClear = this.props.clear && !!this.state.query;
791
766
  if (renderClear) {
792
767
  actions.push(jsx(I18nContext.Consumer, {
793
- children: _ref6 => {
794
- var _this$props$translati, _this$props$translati2;
795
- let {
796
- translate
797
- } = _ref6;
768
+ children: ({
769
+ translate
770
+ }) => {
771
+ var _this$props$translati;
798
772
  return jsx(Button, {
799
773
  icon: closeIcon,
800
774
  className: styles.clear,
801
- title: (_this$props$translati = (_this$props$translati2 = this.props.translations) === null || _this$props$translati2 === void 0 ? void 0 : _this$props$translati2.clearTitle) !== null && _this$props$translati !== void 0 ? _this$props$translati : translate('clearTitle'),
775
+ title: (_this$props$translati = this.props.translations?.clearTitle) !== null && _this$props$translati !== void 0 ? _this$props$translati : translate('clearTitle'),
802
776
  ref: this.clearRef,
803
777
  onClick: this.clearQuery,
804
778
  "data-test": 'query-assist-clear-icon'
@@ -822,14 +796,14 @@ class QueryAssist extends Component {
822
796
  const renderLoader = this.props.loader !== false && this.state.loading;
823
797
  const renderGlass = glass && !renderLoader;
824
798
  const actions = this.renderActions();
825
- const containerClasses = classNames(className, inputStyles["size".concat(huge ? Size.FULL : size)], {
799
+ const containerClasses = classNames(className, inputStyles[`size${huge ? Size.FULL : size}`], {
826
800
  [styles.queryAssist]: true,
827
801
  [styles.withIcon]: renderGlass && !huge || renderLoader,
828
802
  [styles.huge]: huge,
829
803
  [styles.queryAssistDisabled]: this.props.disabled
830
804
  });
831
805
  const inputClasses = classNames(this.props.inputClassName, {
832
- ["".concat(styles.input, " ring-js-shortcuts")]: true,
806
+ [`${styles.input} ring-js-shortcuts`]: true,
833
807
  [styles.inputGap]: actions.length || this.isRenderingGlassOrLoader() && !glass,
834
808
  [styles.inputGap2]: actions.length === 2,
835
809
  // TODO: replace with flex-box layout
@@ -843,11 +817,10 @@ class QueryAssist extends Component {
843
817
  return jsx(ControlsHeightContext.Provider, {
844
818
  value: ControlsHeight.M,
845
819
  children: jsx(I18nContext.Consumer, {
846
- children: _ref7 => {
820
+ children: ({
821
+ translate
822
+ }) => {
847
823
  var _translations$searchT, _translations$searchT2, _translations$searchT3;
848
- let {
849
- translate
850
- } = _ref7;
851
824
  return jsxs("div", {
852
825
  "data-test": joinDataTestAttributes('ring-query-assist', dataTest),
853
826
  className: containerClasses,
@@ -859,7 +832,7 @@ class QueryAssist extends Component {
859
832
  }), renderGlass && !huge && jsx(Icon, {
860
833
  glyph: searchIcon,
861
834
  className: styles.icon,
862
- title: (_translations$searchT = translations === null || translations === void 0 ? void 0 : translations.searchTitle) !== null && _translations$searchT !== void 0 ? _translations$searchT : translate('searchTitle'),
835
+ title: (_translations$searchT = translations?.searchTitle) !== null && _translations$searchT !== void 0 ? _translations$searchT : translate('searchTitle'),
863
836
  ref: this.glassRef,
864
837
  "data-test": 'query-assist-search-icon'
865
838
  }), renderLoader && jsx("div", {
@@ -870,7 +843,7 @@ class QueryAssist extends Component {
870
843
  ref: this.loaderRef,
871
844
  children: jsx(LoaderInline, {})
872
845
  }), jsx(ContentEditable, {
873
- "aria-label": (_translations$searchT2 = translations === null || translations === void 0 ? void 0 : translations.searchTitle) !== null && _translations$searchT2 !== void 0 ? _translations$searchT2 : translate('searchTitle'),
846
+ "aria-label": (_translations$searchT2 = translations?.searchTitle) !== null && _translations$searchT2 !== void 0 ? _translations$searchT2 : translate('searchTitle'),
874
847
  className: inputClasses,
875
848
  "data-test": 'ring-query-assist-input',
876
849
  inputRef: this.inputRef,
@@ -929,7 +902,7 @@ class QueryAssist extends Component {
929
902
  children: jsx(Icon, {
930
903
  glyph: searchIcon,
931
904
  className: styles.rightSearchIcon,
932
- title: (_translations$searchT3 = translations === null || translations === void 0 ? void 0 : translations.searchTitle) !== null && _translations$searchT3 !== void 0 ? _translations$searchT3 : translate('searchTitle'),
905
+ title: (_translations$searchT3 = translations?.searchTitle) !== null && _translations$searchT3 !== void 0 ? _translations$searchT3 : translate('searchTitle'),
933
906
  onClick: this.handleApply,
934
907
  ref: this.glassRef,
935
908
  "data-test": 'query-assist-search-icon'
@@ -941,15 +914,6 @@ class QueryAssist extends Component {
941
914
  });
942
915
  }
943
916
  }
944
- _defineProperty(QueryAssist, "defaultProps", {
945
- onApply: noop,
946
- onChange: noop,
947
- onApplySuggestion: noop,
948
- onClear: noop,
949
- onFocusChange: noop,
950
- size: Size.L
951
- });
952
- _defineProperty(QueryAssist, "ngModelStateField", ngModelStateField);
953
917
  const RerenderableQueryAssist = rerenderHOC(QueryAssist);
954
918
 
955
919
  export { RerenderableQueryAssist, QueryAssist as default };