@jetbrains/ring-ui 5.0.126 → 5.0.128

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 (305) hide show
  1. package/components/alert/alert.js +2 -1
  2. package/components/alert/container.js +2 -1
  3. package/components/auth/auth__core.js +2 -1
  4. package/components/auth/request-builder.js +2 -1
  5. package/components/auth/response-parser.js +2 -1
  6. package/components/auth/token-validator.js +2 -1
  7. package/components/auth-dialog/auth-dialog.js +2 -1
  8. package/components/avatar/avatar.js +2 -1
  9. package/components/badge/badge.js +2 -1
  10. package/components/button/button.js +2 -1
  11. package/components/button-group/button-group.js +2 -1
  12. package/components/button-group/caption.js +2 -1
  13. package/components/button-set/button-set.js +2 -1
  14. package/components/button-toolbar/button-toolbar.js +2 -1
  15. package/components/caret/caret.js +2 -1
  16. package/components/checkbox/checkbox.js +2 -1
  17. package/components/code/code.js +2 -1
  18. package/components/confirm/confirm.js +2 -1
  19. package/components/content-layout/content-layout.js +2 -1
  20. package/components/content-layout/sidebar.js +2 -1
  21. package/components/data-list/data-list.js +2 -1
  22. package/components/data-list/item.js +2 -1
  23. package/components/date-picker/date-input.js +2 -1
  24. package/components/date-picker/date-picker.js +2 -1
  25. package/components/date-picker/date-popup.js +2 -1
  26. package/components/date-picker/day.js +2 -1
  27. package/components/date-picker/month-slider.js +2 -1
  28. package/components/date-picker/years.js +2 -1
  29. package/components/dialog/dialog.d.ts +4 -16
  30. package/components/dialog/dialog.js +6 -3
  31. package/components/dropdown/dropdown.js +2 -1
  32. package/components/editable-heading/editable-heading.css +2 -0
  33. package/components/error-bubble/error-bubble.js +2 -1
  34. package/components/error-message/error-message.js +2 -1
  35. package/components/footer/footer.js +1 -0
  36. package/components/global/react-dom-renderer.js +2 -1
  37. package/components/grid/col.js +2 -1
  38. package/components/grid/grid.js +2 -1
  39. package/components/grid/row.js +2 -1
  40. package/components/group/group.js +2 -1
  41. package/components/header/logo.js +2 -1
  42. package/components/header/profile.js +2 -1
  43. package/components/header/services-link.js +2 -1
  44. package/components/header/services.js +2 -1
  45. package/components/header/smart-profile.js +2 -1
  46. package/components/header/smart-services.js +2 -1
  47. package/components/header/tray-icon.js +2 -1
  48. package/components/header/tray.js +2 -1
  49. package/components/hub-source/hub-source.js +2 -1
  50. package/components/icon/icon.js +2 -1
  51. package/components/input/input.js +2 -1
  52. package/components/island/island.js +2 -1
  53. package/components/island-legacy/content-legacy.js +2 -1
  54. package/components/island-legacy/header-legacy.js +2 -1
  55. package/components/island-legacy/island-legacy.js +2 -1
  56. package/components/link/clickableLink.js +2 -1
  57. package/components/list/list.js +2 -1
  58. package/components/list/list__hint.js +2 -1
  59. package/components/list/list__users-groups-source.js +2 -1
  60. package/components/loader/loader.js +2 -1
  61. package/components/loader/loader__core.js +2 -1
  62. package/components/loader-screen/loader-screen.js +2 -1
  63. package/components/login-dialog/login-dialog.js +2 -1
  64. package/components/message/message.js +2 -1
  65. package/components/pager/pager.js +2 -1
  66. package/components/panel/panel.js +2 -1
  67. package/components/permissions/permissions.js +2 -1
  68. package/components/permissions/permissions__cache.js +2 -1
  69. package/components/popup/popup.js +2 -1
  70. package/components/popup-menu/popup-menu.js +2 -1
  71. package/components/progress-bar/progress-bar.js +2 -1
  72. package/components/query-assist/query-assist.js +4 -3
  73. package/components/radio/radio.js +2 -1
  74. package/components/radio/radio__item.js +2 -1
  75. package/components/select/select.js +3 -2
  76. package/components/select/select__filter.js +2 -1
  77. package/components/select/select__popup.js +4 -2
  78. package/components/shortcuts/shortcuts.js +2 -1
  79. package/components/storage/storage__fallback.js +2 -1
  80. package/components/tab-trap/tab-trap.js +2 -1
  81. package/components/table/cell.js +2 -1
  82. package/components/table/header-cell.js +2 -1
  83. package/components/table/header.js +2 -1
  84. package/components/table/multitable.js +2 -1
  85. package/components/table/row.js +3 -2
  86. package/components/table/table.js +4 -2
  87. package/components/tabs/smart-tabs.js +2 -1
  88. package/components/tabs/tab.js +2 -1
  89. package/components/tag/tag.js +2 -1
  90. package/components/tags-input/tags-input.d.ts +1 -1
  91. package/components/tags-input/tags-input.js +3 -2
  92. package/components/tags-list/tags-list.js +2 -1
  93. package/components/text/text.js +2 -1
  94. package/components/tooltip/tooltip.js +2 -1
  95. package/components/user-agreement/user-agreement.js +2 -1
  96. package/components/user-card/card.js +2 -1
  97. package/components/user-card/smart-user-card-tooltip.d.ts +1 -1
  98. package/components/user-card/smart-user-card-tooltip.js +2 -1
  99. package/components/user-card/tooltip.js +2 -1
  100. package/dist/_helpers/_rollupPluginBabelHelpers.js +1 -29
  101. package/dist/_helpers/anchor.js +1 -1
  102. package/dist/_helpers/card.js +44 -47
  103. package/dist/_helpers/footer.js +1 -0
  104. package/dist/_helpers/select__filter.js +10 -13
  105. package/dist/_helpers/services-link.js +10 -10
  106. package/dist/_helpers/sidebar.js +34 -37
  107. package/dist/_helpers/theme.js +1 -1
  108. package/dist/_helpers/title.js +12 -16
  109. package/dist/alert/alert.js +63 -66
  110. package/dist/alert/container.js +5 -5
  111. package/dist/alert-service/alert-service.js +5 -7
  112. package/dist/analytics/analytics.js +1 -2
  113. package/dist/analytics/analytics__custom-plugin.js +6 -8
  114. package/dist/auth/auth.js +1 -1
  115. package/dist/auth/auth__core.js +26 -26
  116. package/dist/auth/background-flow.js +4 -5
  117. package/dist/auth/iframe-flow.js +12 -12
  118. package/dist/auth/landing.js +1 -1
  119. package/dist/auth/request-builder.js +3 -5
  120. package/dist/auth/response-parser.js +5 -6
  121. package/dist/auth/storage.js +12 -12
  122. package/dist/auth/token-validator.js +13 -16
  123. package/dist/auth/window-flow.js +18 -19
  124. package/dist/auth-dialog/auth-dialog.js +54 -57
  125. package/dist/auth-dialog-service/auth-dialog-service.js +1 -1
  126. package/dist/auth-ng/auth-ng.js +1 -1
  127. package/dist/avatar/avatar.js +30 -33
  128. package/dist/avatar-ng/avatar-ng.js +1 -1
  129. package/dist/badge/badge.js +10 -10
  130. package/dist/badge-ng/badge-ng.js +1 -1
  131. package/dist/breadcrumb-ng/breadcrumb-ng.js +0 -1
  132. package/dist/button/button.js +24 -27
  133. package/dist/button-group/button-group.js +5 -5
  134. package/dist/button-group/caption.js +4 -4
  135. package/dist/button-ng/button-ng.js +68 -69
  136. package/dist/button-set/button-set.js +6 -6
  137. package/dist/button-toolbar/button-toolbar.js +6 -6
  138. package/dist/caret/caret.js +2 -4
  139. package/dist/checkbox/checkbox.js +27 -30
  140. package/dist/checkbox-ng/checkbox-ng.js +0 -1
  141. package/dist/code/code.js +17 -21
  142. package/dist/confirm/confirm.js +31 -34
  143. package/dist/confirm-ng/confirm-ng.js +1 -1
  144. package/dist/confirm-service/confirm-service.js +1 -1
  145. package/dist/content-layout/content-layout.js +17 -20
  146. package/dist/contenteditable/contenteditable.js +11 -11
  147. package/dist/data-list/data-list.js +49 -55
  148. package/dist/data-list/item.js +64 -67
  149. package/dist/data-list/selection.js +0 -1
  150. package/dist/data-list/title.js +1 -1
  151. package/dist/data-list-ng/data-list-ng.js +1 -1
  152. package/dist/date-picker/date-input.js +39 -42
  153. package/dist/date-picker/date-picker.js +162 -165
  154. package/dist/date-picker/date-popup.js +119 -119
  155. package/dist/date-picker/day.js +34 -38
  156. package/dist/date-picker/month-names.js +11 -14
  157. package/dist/date-picker/month-slider.js +24 -28
  158. package/dist/date-picker/month.js +1 -1
  159. package/dist/date-picker/months.js +1 -1
  160. package/dist/date-picker/years.js +9 -13
  161. package/dist/dialog/dialog.d.ts +4 -16
  162. package/dist/dialog/dialog.js +68 -65
  163. package/dist/dialog-ng/dialog-ng.js +21 -22
  164. package/dist/docked-panel-ng/docked-panel-ng.js +0 -1
  165. package/dist/dropdown/dropdown.js +101 -104
  166. package/dist/dropdown-menu/dropdown-menu.js +1 -1
  167. package/dist/editable-heading/editable-heading.js +1 -1
  168. package/dist/error-bubble/error-bubble.js +6 -6
  169. package/dist/error-message/error-message.js +10 -10
  170. package/dist/error-message-ng/error-message-ng.js +0 -1
  171. package/dist/footer-ng/footer-ng.js +19 -21
  172. package/dist/global/angular-component-factory.js +2 -3
  173. package/dist/global/dom.js +1 -5
  174. package/dist/global/focus-sensor-hoc.js +58 -61
  175. package/dist/global/listeners.js +1 -5
  176. package/dist/global/react-dom-renderer.js +8 -12
  177. package/dist/global/rerender-hoc.js +1 -5
  178. package/dist/global/ring-angular-component.js +1 -3
  179. package/dist/grid/col.js +13 -14
  180. package/dist/grid/grid.js +5 -5
  181. package/dist/grid/row.js +16 -17
  182. package/dist/group/group.js +5 -5
  183. package/dist/header/header.js +10 -10
  184. package/dist/header/logo.js +9 -9
  185. package/dist/header/profile.js +58 -58
  186. package/dist/header/services.js +19 -22
  187. package/dist/header/smart-profile.js +40 -43
  188. package/dist/header/smart-services.js +28 -31
  189. package/dist/header/tray-icon.js +6 -6
  190. package/dist/header/tray.js +5 -5
  191. package/dist/heading/heading.js +1 -1
  192. package/dist/heading-ng/heading-ng.js +1 -1
  193. package/dist/http/http.js +111 -107
  194. package/dist/http/http.mock.js +3 -4
  195. package/dist/hub-source/hub-source.js +7 -9
  196. package/dist/hub-source/hub-source__user.js +0 -1
  197. package/dist/hub-source/hub-source__users-groups.js +4 -5
  198. package/dist/icon/icon.js +18 -18
  199. package/dist/icon/icon__svg.js +1 -1
  200. package/dist/icon-ng/icon-ng.js +0 -1
  201. package/dist/input/input.js +35 -38
  202. package/dist/input-ng/input-ng.js +25 -26
  203. package/dist/island/adaptive-island-hoc.js +21 -25
  204. package/dist/island/content.js +62 -65
  205. package/dist/island/header.js +11 -11
  206. package/dist/island/island.js +8 -8
  207. package/dist/island-legacy/content-legacy.js +5 -5
  208. package/dist/island-legacy/header-legacy.js +5 -5
  209. package/dist/island-legacy/island-legacy.js +5 -5
  210. package/dist/link/clickableLink.js +27 -30
  211. package/dist/link/link.js +16 -16
  212. package/dist/list/list.js +389 -391
  213. package/dist/list/list__custom.js +6 -10
  214. package/dist/list/list__hint.js +3 -4
  215. package/dist/list/list__item.js +4 -7
  216. package/dist/list/list__link.js +1 -1
  217. package/dist/list/list__users-groups-source.js +3 -3
  218. package/dist/loader/loader.js +16 -19
  219. package/dist/loader/loader__core.js +62 -62
  220. package/dist/loader-inline/loader-inline.js +6 -6
  221. package/dist/loader-ng/loader-ng.js +3 -4
  222. package/dist/loader-screen/loader-screen.js +6 -6
  223. package/dist/loader-screen-ng/loader-screen-ng.js +0 -1
  224. package/dist/login-dialog/login-dialog.js +55 -58
  225. package/dist/login-dialog/service.js +1 -1
  226. package/dist/markdown/code.js +0 -1
  227. package/dist/markdown/markdown.js +1 -1
  228. package/dist/message/message.js +22 -25
  229. package/dist/old-browsers-message/white-list.js +2 -2
  230. package/dist/pager/pager.js +55 -58
  231. package/dist/pager-ng/pager-ng.js +1 -1
  232. package/dist/panel/panel.js +5 -5
  233. package/dist/panel-ng/panel-ng.js +0 -1
  234. package/dist/permissions/permissions.js +14 -16
  235. package/dist/permissions/permissions__cache.js +4 -6
  236. package/dist/permissions-ng/permissions-ng.js +1 -1
  237. package/dist/place-under-ng/place-under-ng.js +0 -1
  238. package/dist/popup/popup.js +118 -121
  239. package/dist/popup/popup.target.js +1 -1
  240. package/dist/popup/position.js +0 -1
  241. package/dist/popup-menu/popup-menu.js +19 -22
  242. package/dist/progress-bar/progress-bar.js +41 -44
  243. package/dist/progress-bar-ng/progress-bar-ng.js +1 -1
  244. package/dist/promised-click-ng/promised-click-ng.js +0 -1
  245. package/dist/query-assist/query-assist.js +507 -501
  246. package/dist/query-assist/query-assist__suggestions.js +1 -1
  247. package/dist/query-assist-ng/query-assist-ng.js +1 -1
  248. package/dist/radio/radio.js +10 -13
  249. package/dist/radio/radio__item.js +19 -22
  250. package/dist/select/select.js +351 -350
  251. package/dist/select/select__popup.js +148 -152
  252. package/dist/select-ng/select-ng.js +1 -1
  253. package/dist/select-ng/select-ng__lazy.js +4 -4
  254. package/dist/select-ng/select-ng__options.js +14 -15
  255. package/dist/shortcuts/core.js +35 -36
  256. package/dist/shortcuts/shortcuts-hoc.js +7 -11
  257. package/dist/shortcuts/shortcuts.js +10 -11
  258. package/dist/shortcuts-hint-ng/shortcuts-hint-ng.js +0 -1
  259. package/dist/shortcuts-ng/shortcuts-ng.js +0 -1
  260. package/dist/sidebar-ng/sidebar-ng.js +0 -1
  261. package/dist/storage/storage.js +1 -1
  262. package/dist/storage/storage__fallback.js +8 -10
  263. package/dist/storage/storage__local.js +2 -2
  264. package/dist/style.css +1 -1
  265. package/dist/tab-trap/tab-trap.js +84 -86
  266. package/dist/table/cell.js +6 -6
  267. package/dist/table/disable-hover-hoc.js +23 -25
  268. package/dist/table/header-cell.js +28 -31
  269. package/dist/table/header.js +58 -61
  270. package/dist/table/multitable.js +91 -95
  271. package/dist/table/row-with-focus-sensor.js +15 -18
  272. package/dist/table/row.js +51 -54
  273. package/dist/table/selection-shortcuts-hoc.js +145 -147
  274. package/dist/table/selection.js +7 -9
  275. package/dist/table/smart-table.js +21 -24
  276. package/dist/table/table.js +103 -109
  277. package/dist/table-legacy-ng/table-legacy-ng.js +1 -1
  278. package/dist/table-legacy-ng/table-legacy-ng__pager.js +1 -1
  279. package/dist/table-legacy-ng/table-legacy-ng__selection.js +1 -3
  280. package/dist/table-legacy-ng/table-legacy-ng__toolbar.js +0 -1
  281. package/dist/table-ng/smart-table-ng.js +1 -1
  282. package/dist/table-ng/table-ng.js +1 -1
  283. package/dist/tabs/collapsible-more.js +1 -1
  284. package/dist/tabs/collapsible-tab.js +1 -1
  285. package/dist/tabs/dumb-tabs.js +46 -49
  286. package/dist/tabs/smart-tabs.js +10 -10
  287. package/dist/tabs/tab.js +7 -8
  288. package/dist/tag/tag.js +42 -45
  289. package/dist/tags-input/tags-input.d.ts +1 -1
  290. package/dist/tags-input/tags-input.js +214 -213
  291. package/dist/tags-input-ng/tags-input-ng.js +1 -1
  292. package/dist/tags-list/tags-list.js +20 -20
  293. package/dist/template-ng/template-ng.js +25 -26
  294. package/dist/text/text.js +6 -6
  295. package/dist/toggle/toggle.js +19 -19
  296. package/dist/toggle-ng/toggle-ng.js +1 -1
  297. package/dist/tooltip/tooltip.js +86 -89
  298. package/dist/tooltip-ng/tooltip-ng.js +1 -1
  299. package/dist/user-agreement/service.js +207 -205
  300. package/dist/user-agreement/user-agreement.js +39 -42
  301. package/dist/user-card/smart-user-card-tooltip.d.ts +1 -1
  302. package/dist/user-card/smart-user-card-tooltip.js +32 -35
  303. package/dist/user-card/tooltip.js +26 -26
  304. package/dist/user-card-ng/user-card-ng.js +1 -1
  305. package/package.json +15 -15
@@ -1,4 +1,3 @@
1
- import { _ as _defineProperty } from '../_helpers/_rollupPluginBabelHelpers.js';
2
1
  import React, { Component } from 'react';
3
2
  import PropTypes from 'prop-types';
4
3
  import debounce from 'just-debounce-it';
@@ -21,6 +20,7 @@ import { ControlsHeightContext, ControlsHeight } from '../global/controls-height
21
20
  import { Size } from '../input/input.js';
22
21
  import { m as modules_88cfaf40 } from '../_helpers/input.js';
23
22
  import { Q as QueryAssistSuggestions, m as modules_da7ab055 } from '../_helpers/query-assist__suggestions.js';
23
+ import '../_helpers/_rollupPluginBabelHelpers.js';
24
24
  import 'react-dom/server';
25
25
  import '../popup/popup.js';
26
26
  import 'react-dom';
@@ -119,6 +119,110 @@ function cleanText(text) {
119
119
  + __icon__ \`string=\` Icon URI, Data URI is possible
120
120
  */
121
121
  class QueryAssist extends Component {
122
+ static propTypes = {
123
+ /**
124
+ * Open suggestions popup during the initial render
125
+ */
126
+ autoOpen: PropTypes.oneOf([true, false, 'force']),
127
+ /**
128
+ * Initial caret position
129
+ */
130
+ caret: PropTypes.number,
131
+ /**
132
+ * Show clickable "cross" icon on the right which clears the query
133
+ */
134
+ clear: PropTypes.bool,
135
+ /**
136
+ * Additional class for the component
137
+ */
138
+ className: PropTypes.string,
139
+ /**
140
+ * Additional class for the popup
141
+ */
142
+ popupClassName: PropTypes.string,
143
+ /**
144
+ * Additional class for the input
145
+ */
146
+ inputClassName: PropTypes.string,
147
+ /**
148
+ * Data source function
149
+ */
150
+ dataSource: PropTypes.func.isRequired,
151
+ /**
152
+ * Input debounce delay
153
+ */
154
+ delay: PropTypes.number,
155
+ /**
156
+ * Disable the component
157
+ */
158
+ disabled: PropTypes.bool,
159
+ /**
160
+ * Initial focus
161
+ */
162
+ focus: PropTypes.bool,
163
+ /**
164
+ * Hint under the suggestions list
165
+ */
166
+ hint: PropTypes.string,
167
+ /**
168
+ * Hint under the suggestions list visible when a suggestion is selected
169
+ */
170
+ hintOnSelection: PropTypes.string,
171
+ /**
172
+ * Show clickable "glass" icon on the right which applies the query
173
+ */
174
+ glass: PropTypes.bool,
175
+ /**
176
+ * Show loader when a data request is in process
177
+ */
178
+ loader: PropTypes.bool,
179
+ /**
180
+ * Field placeholder value
181
+ */
182
+ placeholder: PropTypes.string,
183
+ /**
184
+ * Called when the query is applied. An object with fields `caret`, `focus` and `query` is passed as an argument
185
+ */
186
+ onApply: PropTypes.func,
187
+ /**
188
+ * Called when the query is changed. An object with fields `caret` and `query` is passed as an argument
189
+ */
190
+ onChange: PropTypes.func,
191
+ /**
192
+ * Called when the query is cleared. Called without arguments
193
+ */
194
+ onClear: PropTypes.func,
195
+ /**
196
+ * Called when the suggestion is applied
197
+ */
198
+ onApplySuggestion: PropTypes.func,
199
+ /**
200
+ * Called when the focus status is changed. An object with fields `focus` is passed as an argument
201
+ */
202
+ onFocusChange: PropTypes.func,
203
+ /**
204
+ * Initial query
205
+ */
206
+ query: PropTypes.string,
207
+ useCustomItemRender: PropTypes.bool,
208
+ translations: PropTypes.object,
209
+ actions: PropTypes.array,
210
+ 'data-test': PropTypes.string,
211
+ huge: PropTypes.bool,
212
+ size: PropTypes.string
213
+ };
214
+ static defaultProps = {
215
+ onApply: noop,
216
+ onChange: noop,
217
+ onApplySuggestion: noop,
218
+ onClear: noop,
219
+ onFocusChange: noop,
220
+ size: Size.L,
221
+ translations: {
222
+ searchTitle: 'Search',
223
+ clearTitle: 'Clear search input'
224
+ }
225
+ };
122
226
  static getDerivedStateFromProps(_ref, _ref2) {
123
227
  let {
124
228
  query
@@ -135,400 +239,23 @@ class QueryAssist extends Component {
135
239
  }
136
240
  return nextState;
137
241
  }
138
- constructor(_props) {
139
- var _this;
140
- super(_props);
141
- _this = this;
142
- _defineProperty(this, "state", {
143
- dirty: !this.props.query,
144
- query: this.props.query,
145
- placeholderEnabled: !this.props.query,
146
- shortcuts: !!this.props.focus,
147
- suggestions: [],
148
- showPopup: false
149
- });
150
- _defineProperty(this, "immediateState", void 0);
151
- _defineProperty(this, "requestData", void 0);
152
- _defineProperty(this, "ngModelStateField", ngModelStateField);
153
- // An array of {query: string; caret: number}[]
154
- _defineProperty(this, "historyStack", []);
155
- _defineProperty(this, "mouseIsDownOnPopup", void 0);
156
- _defineProperty(this, "handleFocusChange", e => {
157
- // otherwise it's blur and false
158
- const focus = e.type === 'focus';
159
- this.immediateState.focus = focus;
160
- if (!focus) {
161
- this.blurInput();
162
- // Close popup on blur by keyboard (mostly shift+tab)
163
- if (!this.mouseIsDownOnPopup) {
164
- this.closePopup();
165
- }
166
- } else {
167
- this.setCaretPosition();
168
- }
169
- if (!this.mouseIsDownOnPopup) {
170
- this.props.onFocusChange({
171
- focus
172
- });
173
- }
174
- this.setState({
175
- shortcuts: focus
176
- });
177
- });
178
- _defineProperty(this, "node", void 0);
179
- _defineProperty(this, "nodeRef", node => {
180
- this.node = node;
181
- });
182
- _defineProperty(this, "setCaretPosition", function () {
183
- let params = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
184
- const queryLength = _this.immediateState.query != null ? _this.immediateState.query.length : 0;
185
- const newCaretPosition = _this.immediateState.caret < queryLength ? _this.immediateState.caret : queryLength;
186
- if (params.fromContentEditable) {
187
- _this.immediateState.selection = _this.immediateState.selection ? _this.immediateState.selection : _this.state.query && _this.state.query.length || null;
188
- }
189
- if (_this.immediateState.focus && !_this.props.disabled) {
190
- if (typeof _this.immediateState.selection === 'number' && Number.isInteger(_this.immediateState.selection) && _this.immediateState.selection > -1) {
191
- // Set to end of field value if newCaretPosition is inappropriate
192
- _this.caret?.setPosition(newCaretPosition >= 0 ? newCaretPosition : -1);
193
- _this.scrollInput();
194
- } else if (_this.immediateState.selection && typeof _this.immediateState.selection === 'object' && _this.immediateState.selection.startOffset !== undefined) {
195
- _this.caret?.setPosition(_this.immediateState.selection);
196
- } else if (_this.immediateState.selection === undefined || params.forceSetCaret) {
197
- _this.caret?.setPosition(-1);
198
- }
199
- }
200
- });
201
- _defineProperty(this, "togglePlaceholder", () => {
202
- const query = this.getQuery();
203
- const currentQueryIsEmpty = this.immediateState.query === '';
204
- const newQueryIsEmpty = query === '';
205
- if (newQueryIsEmpty !== currentQueryIsEmpty) {
206
- this.setState({
207
- placeholderEnabled: newQueryIsEmpty
208
- });
209
- }
210
- });
211
- _defineProperty(this, "isComposing", void 0);
212
- _defineProperty(this, "handleInput", e => {
213
- var _currentCaret$positio;
214
- this.togglePlaceholder();
215
- const currentCaret = this.caret?.getPosition();
216
- const props = {
217
- dirty: true,
218
- query: this.getQuery(),
219
- caret: typeof currentCaret === 'number' ? currentCaret : (_currentCaret$positio = currentCaret?.position) !== null && _currentCaret$positio !== void 0 ? _currentCaret$positio : 0,
220
- focus: true
221
- };
222
- if (this.immediateState.query === props.query && !this.isComposing) {
223
- this.handleCaretMove(e);
224
- return;
225
- }
226
- if (this.isComposing) {
227
- return;
228
- }
229
- this.immediateState = props;
230
- if (this.state.query) {
231
- var _this$state$styleRang;
232
- let i = 0;
233
- while (this.state.query[i] === this.immediateState.query[i] && i < this.state.query.length - 1) {
234
- i++;
235
- }
236
- const diff = this.immediateState.query.length - this.state.query.length;
237
- const originalIndex = this.immediateState.caret - diff;
238
- const ranges = [...((_this$state$styleRang = this.state.styleRanges) !== null && _this$state$styleRang !== void 0 ? _this$state$styleRang : [])];
239
- const range = ranges.find(r => originalIndex >= r.start && originalIndex <= r.start + r.length);
240
- if (range) {
241
- range.length += diff;
242
- }
243
- ranges.filter(r => r.start > originalIndex).forEach(r => {
244
- r.start += diff;
245
- });
246
- }
247
- this.props.onChange(props);
248
- if (this.props.autoOpen === 'force' || props.query.length > 0) {
249
- this.requestData?.();
250
- }
251
- });
252
- // It's necessary to prevent new element creation before any other hooks
253
- _defineProperty(this, "handleEnter", e => {
254
- if (e.key === 'Enter') {
255
- preventDefault(e);
256
- }
257
- });
258
- _defineProperty(this, "handleTab", e => {
259
- const list = this._popup && this._popup.list;
260
- const suggestion = list && (list.getSelected() || list.getFirst());
261
- if (suggestion && this.state.showPopup) {
262
- preventDefault(e);
263
- if (this.getQuery() !== this.immediateState.suggestionsQuery) {
264
- return false;
265
- }
266
- return this.handleComplete(suggestion, true);
267
- }
268
- if (this.state.loading) {
269
- preventDefault(e);
270
- return false;
271
- }
272
- return true;
273
- });
274
- _defineProperty(this, "setState", (state, resolve) => {
275
- super.setState(state, () => {
276
- this._pushHistory(state);
277
- resolve?.();
278
- });
279
- });
280
- _defineProperty(this, "undo", e => {
281
- const previous = this.historyStack.splice(0, 2)[1];
282
- if (!previous) {
283
- return;
284
- }
285
- this.setState({
286
- query: previous.query
287
- }, () => {
288
- this.caret?.setPosition(previous.caret);
289
- this.handleInput(e);
290
- });
291
- });
292
- _defineProperty(this, "handlePaste", e => {
293
- const INSERT_COMMAND = 'insertText';
294
- if (e.clipboardData && document.queryCommandSupported(INSERT_COMMAND)) {
295
- preventDefault(e);
296
- const text = cleanText(e.clipboardData.getData('text/plain'));
297
- document.execCommand(INSERT_COMMAND, false, text);
298
- this.handleInput(e);
299
- }
300
- });
301
- _defineProperty(this, "handleCaretMove", e => {
302
- var _currentCaret$positio2;
303
- if (this.isComposing) {
304
- return;
305
- }
306
- const currentCaret = this.caret?.getPosition();
307
- const caret = typeof currentCaret === 'number' ? currentCaret : (_currentCaret$positio2 = currentCaret?.position) !== null && _currentCaret$positio2 !== void 0 ? _currentCaret$positio2 : 0;
308
- const popupHidden = !this.state.showPopup && e.type === 'click';
309
- if (!this.props.disabled && (caret !== this.immediateState.caret || popupHidden)) {
310
- this.immediateState.caret = caret;
311
- this.scrollInput();
312
- if (this.immediateState.query.length > 0) {
313
- this.requestData?.();
314
- }
315
- }
316
- if (this.immediateState.query.length < 1) {
317
- this.setState({
318
- showPopup: false
319
- });
320
- }
321
- });
322
- _defineProperty(this, "handleStyleRangesResponse", _ref3 => {
323
- let {
324
- suggestions,
325
- ...restProps
326
- } = _ref3;
327
- return this.handleResponse(restProps);
328
- });
329
- _defineProperty(this, "handleResponse", function (_ref4) {
330
- let {
331
- query = '',
332
- caret = 0,
333
- styleRanges,
334
- suggestions = []
335
- } = _ref4;
336
- let afterCompletion = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
337
- return new Promise((resolve, reject) => {
338
- if (query === _this.getQuery() && (caret === _this.immediateState.caret || _this.immediateState.caret === undefined)) {
339
- // Do not setState on unmounted component
340
- if (!_this.node) {
341
- return;
342
- }
343
- const state = {
344
- dirty: _this.immediateState.dirty,
345
- loading: false,
346
- placeholderEnabled: !query,
347
- query,
348
- suggestions,
349
- showPopup: !!suggestions.length && !afterCompletion
350
- };
351
- _this.immediateState.suggestionsQuery = query;
352
- // Do not update deep equal styleRanges to simplify shouldComponentUpdate check
353
- if (!deepEqual(_this.state.styleRanges, styleRanges)) {
354
- state.styleRanges = styleRanges;
355
- }
356
- _this.immediateState.selection = _this.caret?.getPosition({
357
- avoidFocus: true
358
- });
359
- _this.setState(state, resolve);
360
- } else {
361
- reject(new Error('Current and response queries mismatch'));
362
- }
363
- });
364
- });
365
- _defineProperty(this, "handleApply", () => {
366
- this.closePopup();
367
- this.immediateState.dirty = false;
368
- // Only set dirty to false when query is saved already
369
- if (this.immediateState.query === this.state.query) {
370
- this.setState({
371
- dirty: false
372
- });
373
- }
374
- return this.props.onApply(this.immediateState);
375
- });
376
- _defineProperty(this, "handleComplete", (data, replace) => {
377
- var _suggestion$caret, _suggestion$caret2;
378
- if (!data || !data.data) {
379
- this.handleApply();
380
- return;
381
- }
382
- const query = this.getQuery();
383
- const currentCaret = this.immediateState.caret;
384
- const suggestion = data.data;
385
- const prefix = suggestion.prefix || '';
386
- const suffix = suggestion.suffix || '';
387
- const state = {
388
- caret: (_suggestion$caret = suggestion.caret) !== null && _suggestion$caret !== void 0 ? _suggestion$caret : 0,
389
- selection: (_suggestion$caret2 = suggestion.caret) !== null && _suggestion$caret2 !== void 0 ? _suggestion$caret2 : 0,
390
- query: query.substr(0, suggestion.completionStart) + prefix + suggestion.option + suffix
391
- };
392
- if (typeof replace === 'boolean' && replace) {
393
- var _suggestion$completio;
394
- state.query += this.immediateState.query.substr((_suggestion$completio = suggestion.completionEnd) !== null && _suggestion$completio !== void 0 ? _suggestion$completio : 0);
395
- } else {
396
- state.query += this.immediateState.query.substr(this.immediateState.caret);
397
- }
398
- this.props.onChange(state);
399
- this.props.onApplySuggestion(data.data, state);
400
- const focusState = {
401
- focus: true
402
- };
403
- this.props.onFocusChange(focusState);
404
- if (state.query !== this.immediateState.query) {
405
- this.setState({
406
- placeholderEnabled: !state.query,
407
- query: state.query
408
- });
409
- }
410
- this.immediateState = Object.assign(state, focusState);
411
- if (this.immediateState.caret !== currentCaret) {
412
- this.setCaretPosition();
413
- }
414
- this.closePopup();
415
- this.requestData?.(true);
416
- });
417
- _defineProperty(this, "requestStyleRanges", () => {
418
- const {
419
- query,
420
- caret
421
- } = this.immediateState;
422
- if (!query) {
423
- return Promise.reject(new Error('Query is empty'));
424
- }
425
- return this.sendRequest({
426
- query,
427
- caret,
428
- omitSuggestions: true
429
- }).then(this.handleStyleRangesResponse).catch(noop);
430
- });
431
- _defineProperty(this, "requestHandler", function () {
432
- let afterCompletion = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
433
- if (_this.props.disabled) {
434
- return Promise.reject(new Error('QueryAssist(@jetbrains/ring-ui): null exception'));
435
- }
436
- const {
437
- query,
438
- caret
439
- } = _this.immediateState;
440
- return _this.sendRequest({
441
- query,
442
- caret
443
- }).then(data => _this.handleResponse(data, afterCompletion)).catch(noop);
444
- });
445
- _defineProperty(this, "handleCtrlSpace", e => {
446
- preventDefault(e);
447
- if (!this.state.showPopup) {
448
- this.requestData?.();
449
- }
450
- });
451
- _defineProperty(this, "trackPopupMouseState", e => {
452
- this.mouseIsDownOnPopup = e.type === 'mousedown';
453
- });
454
- _defineProperty(this, "trackCompositionState", e => {
455
- this.isComposing = e.type !== 'compositionend';
456
- });
457
- _defineProperty(this, "closePopup", () => {
458
- if (this.node) {
459
- this.setState({
460
- showPopup: false
461
- });
462
- }
463
- });
464
- _defineProperty(this, "clearQuery", () => {
465
- const state = {
466
- dirty: false,
467
- caret: 0,
468
- query: '',
469
- focus: true
470
- };
471
- this.props.onChange(state);
472
- this.props.onClear();
473
- this.immediateState = state;
474
- this.setState({
475
- dirty: false,
476
- query: '',
477
- placeholderEnabled: true,
478
- loading: false
479
- });
480
- });
481
- _defineProperty(this, "input", void 0);
482
- _defineProperty(this, "caret", void 0);
483
- _defineProperty(this, "inputRef", node => {
484
- if (!node) {
485
- return;
486
- }
487
- this.input = node;
488
- this.caret = new Caret(this.input);
489
- });
490
- _defineProperty(this, "_popup", void 0);
491
- _defineProperty(this, "popupRef", node => {
492
- this._popup = node;
493
- });
494
- _defineProperty(this, "placeholder", void 0);
495
- _defineProperty(this, "placeholderRef", node => {
496
- this.placeholder = node;
497
- });
498
- _defineProperty(this, "glass", void 0);
499
- _defineProperty(this, "glassRef", node => {
500
- this.glass = node;
501
- });
502
- _defineProperty(this, "loader", void 0);
503
- _defineProperty(this, "loaderRef", node => {
504
- this.loader = node;
505
- });
506
- _defineProperty(this, "clear", void 0);
507
- _defineProperty(this, "clearRef", node => {
508
- this.clear = node;
509
- });
510
- _defineProperty(this, "shortcutsScope", getUID('ring-query-assist-'));
511
- _defineProperty(this, "shortcutsMap", {
512
- del: noop,
513
- enter: () => this.handleComplete(),
514
- 'command+enter': () => this.handleComplete(),
515
- 'ctrl+enter': () => this.handleComplete(),
516
- 'ctrl+space': this.handleCtrlSpace,
517
- tab: this.handleTab,
518
- 'meta+z': this.undo,
519
- right: noop,
520
- left: noop,
521
- space: noop,
522
- home: noop,
523
- end: noop
524
- });
525
- const _query = _props.query || '';
242
+ constructor(props) {
243
+ super(props);
244
+ const query = props.query || '';
526
245
  this.immediateState = {
527
- query: _query,
528
- caret: typeof _props.caret === 'number' && Number.isFinite(_props.caret) ? _props.caret : _query.length,
529
- focus: Boolean(_props.autoOpen || _props.focus)
246
+ query,
247
+ caret: typeof props.caret === 'number' && Number.isFinite(props.caret) ? props.caret : query.length,
248
+ focus: Boolean(props.autoOpen || props.focus)
530
249
  };
531
250
  }
251
+ state = {
252
+ dirty: !this.props.query,
253
+ query: this.props.query,
254
+ placeholderEnabled: !this.props.query,
255
+ shortcuts: !!this.props.focus,
256
+ suggestions: [],
257
+ showPopup: false
258
+ };
532
259
  componentDidMount() {
533
260
  const query = this.props.query || '';
534
261
  this.immediateState = {
@@ -570,11 +297,44 @@ class QueryAssist extends Component {
570
297
  }
571
298
  }
572
299
  }
573
- updateFocus(_ref5) {
300
+ static ngModelStateField = ngModelStateField;
301
+ immediateState;
302
+ requestData;
303
+ ngModelStateField = ngModelStateField;
304
+ // An array of {query: string; caret: number}[]
305
+ historyStack = [];
306
+ mouseIsDownOnPopup;
307
+ handleFocusChange = e => {
308
+ // otherwise it's blur and false
309
+ const focus = e.type === 'focus';
310
+ this.immediateState.focus = focus;
311
+ if (!focus) {
312
+ this.blurInput();
313
+ // Close popup on blur by keyboard (mostly shift+tab)
314
+ if (!this.mouseIsDownOnPopup) {
315
+ this.closePopup();
316
+ }
317
+ } else {
318
+ this.setCaretPosition();
319
+ }
320
+ if (!this.mouseIsDownOnPopup) {
321
+ this.props.onFocusChange({
322
+ focus
323
+ });
324
+ }
325
+ this.setState({
326
+ shortcuts: focus
327
+ });
328
+ };
329
+ node;
330
+ nodeRef = node => {
331
+ this.node = node;
332
+ };
333
+ updateFocus(_ref3) {
574
334
  let {
575
335
  focus,
576
336
  caret
577
- } = _ref5;
337
+ } = _ref3;
578
338
  const isCaretChanged = caret !== this.props.caret;
579
339
  const isFocusChanged = focus !== this.props.focus;
580
340
  if (isFocusChanged || isCaretChanged) {
@@ -582,6 +342,28 @@ class QueryAssist extends Component {
582
342
  this.setFocus(focusValue);
583
343
  }
584
344
  }
345
+ setCaretPosition = (() => {
346
+ var _this = this;
347
+ return function () {
348
+ let params = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
349
+ const queryLength = _this.immediateState.query != null ? _this.immediateState.query.length : 0;
350
+ const newCaretPosition = _this.immediateState.caret < queryLength ? _this.immediateState.caret : queryLength;
351
+ if (params.fromContentEditable) {
352
+ _this.immediateState.selection = _this.immediateState.selection ? _this.immediateState.selection : _this.state.query && _this.state.query.length || null;
353
+ }
354
+ if (_this.immediateState.focus && !_this.props.disabled) {
355
+ if (typeof _this.immediateState.selection === 'number' && Number.isInteger(_this.immediateState.selection) && _this.immediateState.selection > -1) {
356
+ // Set to end of field value if newCaretPosition is inappropriate
357
+ _this.caret?.setPosition(newCaretPosition >= 0 ? newCaretPosition : -1);
358
+ _this.scrollInput();
359
+ } else if (_this.immediateState.selection && typeof _this.immediateState.selection === 'object' && _this.immediateState.selection.startOffset !== undefined) {
360
+ _this.caret?.setPosition(_this.immediateState.selection);
361
+ } else if (_this.immediateState.selection === undefined || params.forceSetCaret) {
362
+ _this.caret?.setPosition(-1);
363
+ }
364
+ }
365
+ };
366
+ })();
585
367
  scrollInput() {
586
368
  const caretOffset = this.caret?.getOffset();
587
369
  if (this.input?.clientWidth !== this.input?.scrollWidth && caretOffset != null && this.input?.clientWidth != null && caretOffset > this.input.clientWidth) {
@@ -596,6 +378,85 @@ class QueryAssist extends Component {
596
378
  const renderLoader = this.props.loader !== false && this.state.loading;
597
379
  return this.props.glass || renderLoader;
598
380
  }
381
+ togglePlaceholder = () => {
382
+ const query = this.getQuery();
383
+ const currentQueryIsEmpty = this.immediateState.query === '';
384
+ const newQueryIsEmpty = query === '';
385
+ if (newQueryIsEmpty !== currentQueryIsEmpty) {
386
+ this.setState({
387
+ placeholderEnabled: newQueryIsEmpty
388
+ });
389
+ }
390
+ };
391
+ isComposing;
392
+ handleInput = e => {
393
+ var _currentCaret$positio;
394
+ this.togglePlaceholder();
395
+ const currentCaret = this.caret?.getPosition();
396
+ const props = {
397
+ dirty: true,
398
+ query: this.getQuery(),
399
+ caret: typeof currentCaret === 'number' ? currentCaret : (_currentCaret$positio = currentCaret?.position) !== null && _currentCaret$positio !== void 0 ? _currentCaret$positio : 0,
400
+ focus: true
401
+ };
402
+ if (this.immediateState.query === props.query && !this.isComposing) {
403
+ this.handleCaretMove(e);
404
+ return;
405
+ }
406
+ if (this.isComposing) {
407
+ return;
408
+ }
409
+ this.immediateState = props;
410
+ if (this.state.query) {
411
+ var _this$state$styleRang;
412
+ let i = 0;
413
+ while (this.state.query[i] === this.immediateState.query[i] && i < this.state.query.length - 1) {
414
+ i++;
415
+ }
416
+ const diff = this.immediateState.query.length - this.state.query.length;
417
+ const originalIndex = this.immediateState.caret - diff;
418
+ const ranges = [...((_this$state$styleRang = this.state.styleRanges) !== null && _this$state$styleRang !== void 0 ? _this$state$styleRang : [])];
419
+ const range = ranges.find(r => originalIndex >= r.start && originalIndex <= r.start + r.length);
420
+ if (range) {
421
+ range.length += diff;
422
+ }
423
+ ranges.filter(r => r.start > originalIndex).forEach(r => {
424
+ r.start += diff;
425
+ });
426
+ }
427
+ this.props.onChange(props);
428
+ if (this.props.autoOpen === 'force' || props.query.length > 0) {
429
+ this.requestData?.();
430
+ }
431
+ };
432
+ // It's necessary to prevent new element creation before any other hooks
433
+ handleEnter = e => {
434
+ if (e.key === 'Enter') {
435
+ preventDefault(e);
436
+ }
437
+ };
438
+ handleTab = e => {
439
+ const list = this._popup && this._popup.list;
440
+ const suggestion = list && (list.getSelected() || list.getFirst());
441
+ if (suggestion && this.state.showPopup) {
442
+ preventDefault(e);
443
+ if (this.getQuery() !== this.immediateState.suggestionsQuery) {
444
+ return false;
445
+ }
446
+ return this.handleComplete(suggestion, true);
447
+ }
448
+ if (this.state.loading) {
449
+ preventDefault(e);
450
+ return false;
451
+ }
452
+ return true;
453
+ };
454
+ setState = (state, resolve) => {
455
+ super.setState(state, () => {
456
+ this._pushHistory(state);
457
+ resolve?.();
458
+ });
459
+ };
599
460
  _pushHistory(state) {
600
461
  const queryIsSet = ('query' in state);
601
462
  const queryIsSame = this.historyStack[0]?.query === state.query;
@@ -609,6 +470,177 @@ class QueryAssist extends Component {
609
470
  });
610
471
  }
611
472
  }
473
+ undo = e => {
474
+ const previous = this.historyStack.splice(0, 2)[1];
475
+ if (!previous) {
476
+ return;
477
+ }
478
+ this.setState({
479
+ query: previous.query
480
+ }, () => {
481
+ this.caret?.setPosition(previous.caret);
482
+ this.handleInput(e);
483
+ });
484
+ };
485
+ handlePaste = e => {
486
+ const INSERT_COMMAND = 'insertText';
487
+ if (e.clipboardData && document.queryCommandSupported(INSERT_COMMAND)) {
488
+ preventDefault(e);
489
+ const text = cleanText(e.clipboardData.getData('text/plain'));
490
+ document.execCommand(INSERT_COMMAND, false, text);
491
+ this.handleInput(e);
492
+ }
493
+ };
494
+ handleCaretMove = e => {
495
+ var _currentCaret$positio2;
496
+ if (this.isComposing) {
497
+ return;
498
+ }
499
+ const currentCaret = this.caret?.getPosition();
500
+ const caret = typeof currentCaret === 'number' ? currentCaret : (_currentCaret$positio2 = currentCaret?.position) !== null && _currentCaret$positio2 !== void 0 ? _currentCaret$positio2 : 0;
501
+ const popupHidden = !this.state.showPopup && e.type === 'click';
502
+ if (!this.props.disabled && (caret !== this.immediateState.caret || popupHidden)) {
503
+ this.immediateState.caret = caret;
504
+ this.scrollInput();
505
+ if (this.immediateState.query.length > 0) {
506
+ this.requestData?.();
507
+ }
508
+ }
509
+ if (this.immediateState.query.length < 1) {
510
+ this.setState({
511
+ showPopup: false
512
+ });
513
+ }
514
+ };
515
+ handleStyleRangesResponse = _ref4 => {
516
+ let {
517
+ suggestions,
518
+ ...restProps
519
+ } = _ref4;
520
+ return this.handleResponse(restProps);
521
+ };
522
+ handleResponse = (() => {
523
+ var _this2 = this;
524
+ return function (_ref5) {
525
+ let {
526
+ query = '',
527
+ caret = 0,
528
+ styleRanges,
529
+ suggestions = []
530
+ } = _ref5;
531
+ let afterCompletion = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
532
+ return new Promise((resolve, reject) => {
533
+ if (query === _this2.getQuery() && (caret === _this2.immediateState.caret || _this2.immediateState.caret === undefined)) {
534
+ // Do not setState on unmounted component
535
+ if (!_this2.node) {
536
+ return;
537
+ }
538
+ const state = {
539
+ dirty: _this2.immediateState.dirty,
540
+ loading: false,
541
+ placeholderEnabled: !query,
542
+ query,
543
+ suggestions,
544
+ showPopup: !!suggestions.length && !afterCompletion
545
+ };
546
+ _this2.immediateState.suggestionsQuery = query;
547
+ // Do not update deep equal styleRanges to simplify shouldComponentUpdate check
548
+ if (!deepEqual(_this2.state.styleRanges, styleRanges)) {
549
+ state.styleRanges = styleRanges;
550
+ }
551
+ _this2.immediateState.selection = _this2.caret?.getPosition({
552
+ avoidFocus: true
553
+ });
554
+ _this2.setState(state, resolve);
555
+ } else {
556
+ reject(new Error('Current and response queries mismatch'));
557
+ }
558
+ });
559
+ };
560
+ })();
561
+ handleApply = () => {
562
+ this.closePopup();
563
+ this.immediateState.dirty = false;
564
+ // Only set dirty to false when query is saved already
565
+ if (this.immediateState.query === this.state.query) {
566
+ this.setState({
567
+ dirty: false
568
+ });
569
+ }
570
+ return this.props.onApply(this.immediateState);
571
+ };
572
+ handleComplete = (data, replace) => {
573
+ var _suggestion$caret, _suggestion$caret2;
574
+ if (!data || !data.data) {
575
+ this.handleApply();
576
+ return;
577
+ }
578
+ const query = this.getQuery();
579
+ const currentCaret = this.immediateState.caret;
580
+ const suggestion = data.data;
581
+ const prefix = suggestion.prefix || '';
582
+ const suffix = suggestion.suffix || '';
583
+ const state = {
584
+ caret: (_suggestion$caret = suggestion.caret) !== null && _suggestion$caret !== void 0 ? _suggestion$caret : 0,
585
+ selection: (_suggestion$caret2 = suggestion.caret) !== null && _suggestion$caret2 !== void 0 ? _suggestion$caret2 : 0,
586
+ query: query.substr(0, suggestion.completionStart) + prefix + suggestion.option + suffix
587
+ };
588
+ if (typeof replace === 'boolean' && replace) {
589
+ var _suggestion$completio;
590
+ state.query += this.immediateState.query.substr((_suggestion$completio = suggestion.completionEnd) !== null && _suggestion$completio !== void 0 ? _suggestion$completio : 0);
591
+ } else {
592
+ state.query += this.immediateState.query.substr(this.immediateState.caret);
593
+ }
594
+ this.props.onChange(state);
595
+ this.props.onApplySuggestion(data.data, state);
596
+ const focusState = {
597
+ focus: true
598
+ };
599
+ this.props.onFocusChange(focusState);
600
+ if (state.query !== this.immediateState.query) {
601
+ this.setState({
602
+ placeholderEnabled: !state.query,
603
+ query: state.query
604
+ });
605
+ }
606
+ this.immediateState = Object.assign(state, focusState);
607
+ if (this.immediateState.caret !== currentCaret) {
608
+ this.setCaretPosition();
609
+ }
610
+ this.closePopup();
611
+ this.requestData?.(true);
612
+ };
613
+ requestStyleRanges = () => {
614
+ const {
615
+ query,
616
+ caret
617
+ } = this.immediateState;
618
+ if (!query) {
619
+ return Promise.reject(new Error('Query is empty'));
620
+ }
621
+ return this.sendRequest({
622
+ query,
623
+ caret,
624
+ omitSuggestions: true
625
+ }).then(this.handleStyleRangesResponse).catch(noop);
626
+ };
627
+ requestHandler = (() => {
628
+ var _this3 = this;
629
+ return function () {
630
+ let afterCompletion = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
631
+ if (_this3.props.disabled) {
632
+ return Promise.reject(new Error('QueryAssist(@jetbrains/ring-ui): null exception'));
633
+ }
634
+ const {
635
+ query,
636
+ caret
637
+ } = _this3.immediateState;
638
+ return _this3.sendRequest({
639
+ query,
640
+ caret
641
+ }).then(data => _this3.handleResponse(data, afterCompletion)).catch(noop);
642
+ };
643
+ })();
612
644
  sendRequest(params) {
613
645
  const value = this.props.dataSource(params);
614
646
  const dataPromise = Promise.resolve(value);
@@ -658,6 +690,42 @@ class QueryAssist extends Component {
658
690
  const result = offset - POPUP_COMPENSATION;
659
691
  return result < minOffset ? minOffset : result;
660
692
  }
693
+ handleCtrlSpace = e => {
694
+ preventDefault(e);
695
+ if (!this.state.showPopup) {
696
+ this.requestData?.();
697
+ }
698
+ };
699
+ trackPopupMouseState = e => {
700
+ this.mouseIsDownOnPopup = e.type === 'mousedown';
701
+ };
702
+ trackCompositionState = e => {
703
+ this.isComposing = e.type !== 'compositionend';
704
+ };
705
+ closePopup = () => {
706
+ if (this.node) {
707
+ this.setState({
708
+ showPopup: false
709
+ });
710
+ }
711
+ };
712
+ clearQuery = () => {
713
+ const state = {
714
+ dirty: false,
715
+ caret: 0,
716
+ query: '',
717
+ focus: true
718
+ };
719
+ this.props.onChange(state);
720
+ this.props.onClear();
721
+ this.immediateState = state;
722
+ this.setState({
723
+ dirty: false,
724
+ query: '',
725
+ placeholderEnabled: true,
726
+ loading: false
727
+ });
728
+ };
661
729
  blurInput() {
662
730
  this.immediateState.selection = null;
663
731
  if (!this.props.focus) {
@@ -757,6 +825,50 @@ class QueryAssist extends Component {
757
825
  });
758
826
  }
759
827
  }
828
+ input;
829
+ caret;
830
+ inputRef = node => {
831
+ if (!node) {
832
+ return;
833
+ }
834
+ this.input = node;
835
+ this.caret = new Caret(this.input);
836
+ };
837
+ _popup;
838
+ popupRef = node => {
839
+ this._popup = node;
840
+ };
841
+ placeholder;
842
+ placeholderRef = node => {
843
+ this.placeholder = node;
844
+ };
845
+ glass;
846
+ glassRef = node => {
847
+ this.glass = node;
848
+ };
849
+ loader;
850
+ loaderRef = node => {
851
+ this.loader = node;
852
+ };
853
+ clear;
854
+ clearRef = node => {
855
+ this.clear = node;
856
+ };
857
+ shortcutsScope = getUID('ring-query-assist-');
858
+ shortcutsMap = {
859
+ del: noop,
860
+ enter: () => this.handleComplete(),
861
+ 'command+enter': () => this.handleComplete(),
862
+ 'ctrl+enter': () => this.handleComplete(),
863
+ 'ctrl+space': this.handleCtrlSpace,
864
+ tab: this.handleTab,
865
+ 'meta+z': this.undo,
866
+ right: noop,
867
+ left: noop,
868
+ space: noop,
869
+ home: noop,
870
+ end: noop
871
+ };
760
872
  renderActions() {
761
873
  const actions = [...(this.props.actions || [])];
762
874
  const renderClear = this.props.clear && !!this.state.query;
@@ -808,7 +920,7 @@ class QueryAssist extends Component {
808
920
  }, /*#__PURE__*/React.createElement("div", {
809
921
  "data-test": joinDataTestAttributes('ring-query-assist', dataTest),
810
922
  className: containerClasses,
811
- role: "search",
923
+ role: "presentation",
812
924
  ref: this.nodeRef
813
925
  }, this.state.shortcuts && /*#__PURE__*/React.createElement(Shortcuts, {
814
926
  map: this.shortcutsMap,
@@ -827,7 +939,6 @@ class QueryAssist extends Component {
827
939
  ref: this.loaderRef
828
940
  }, /*#__PURE__*/React.createElement(LoaderInline, null)), /*#__PURE__*/React.createElement(ContentEditable, {
829
941
  "aria-label": this.props.translations.searchTitle,
830
- role: "searchbox",
831
942
  className: inputClasses,
832
943
  "data-test": "ring-query-assist-input",
833
944
  inputRef: this.inputRef,
@@ -887,111 +998,6 @@ class QueryAssist extends Component {
887
998
  }))));
888
999
  }
889
1000
  }
890
- _defineProperty(QueryAssist, "propTypes", {
891
- /**
892
- * Open suggestions popup during the initial render
893
- */
894
- autoOpen: PropTypes.oneOf([true, false, 'force']),
895
- /**
896
- * Initial caret position
897
- */
898
- caret: PropTypes.number,
899
- /**
900
- * Show clickable "cross" icon on the right which clears the query
901
- */
902
- clear: PropTypes.bool,
903
- /**
904
- * Additional class for the component
905
- */
906
- className: PropTypes.string,
907
- /**
908
- * Additional class for the popup
909
- */
910
- popupClassName: PropTypes.string,
911
- /**
912
- * Additional class for the input
913
- */
914
- inputClassName: PropTypes.string,
915
- /**
916
- * Data source function
917
- */
918
- dataSource: PropTypes.func.isRequired,
919
- /**
920
- * Input debounce delay
921
- */
922
- delay: PropTypes.number,
923
- /**
924
- * Disable the component
925
- */
926
- disabled: PropTypes.bool,
927
- /**
928
- * Initial focus
929
- */
930
- focus: PropTypes.bool,
931
- /**
932
- * Hint under the suggestions list
933
- */
934
- hint: PropTypes.string,
935
- /**
936
- * Hint under the suggestions list visible when a suggestion is selected
937
- */
938
- hintOnSelection: PropTypes.string,
939
- /**
940
- * Show clickable "glass" icon on the right which applies the query
941
- */
942
- glass: PropTypes.bool,
943
- /**
944
- * Show loader when a data request is in process
945
- */
946
- loader: PropTypes.bool,
947
- /**
948
- * Field placeholder value
949
- */
950
- placeholder: PropTypes.string,
951
- /**
952
- * Called when the query is applied. An object with fields `caret`, `focus` and `query` is passed as an argument
953
- */
954
- onApply: PropTypes.func,
955
- /**
956
- * Called when the query is changed. An object with fields `caret` and `query` is passed as an argument
957
- */
958
- onChange: PropTypes.func,
959
- /**
960
- * Called when the query is cleared. Called without arguments
961
- */
962
- onClear: PropTypes.func,
963
- /**
964
- * Called when the suggestion is applied
965
- */
966
- onApplySuggestion: PropTypes.func,
967
- /**
968
- * Called when the focus status is changed. An object with fields `focus` is passed as an argument
969
- */
970
- onFocusChange: PropTypes.func,
971
- /**
972
- * Initial query
973
- */
974
- query: PropTypes.string,
975
- useCustomItemRender: PropTypes.bool,
976
- translations: PropTypes.object,
977
- actions: PropTypes.array,
978
- 'data-test': PropTypes.string,
979
- huge: PropTypes.bool,
980
- size: PropTypes.string
981
- });
982
- _defineProperty(QueryAssist, "defaultProps", {
983
- onApply: noop,
984
- onChange: noop,
985
- onApplySuggestion: noop,
986
- onClear: noop,
987
- onFocusChange: noop,
988
- size: Size.L,
989
- translations: {
990
- searchTitle: 'Search',
991
- clearTitle: 'Clear search input'
992
- }
993
- });
994
- _defineProperty(QueryAssist, "ngModelStateField", ngModelStateField);
995
1001
  const RerenderableQueryAssist = rerenderHOC(QueryAssist);
996
1002
 
997
1003
  export { RerenderableQueryAssist, QueryAssist as default };