@jetbrains/ring-ui 4.2.7 → 4.2.10

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 (318) hide show
  1. package/components/auth/auth__core.js +5 -0
  2. package/components/auth/token-validator.js +4 -1
  3. package/components/pager/pager.js +14 -14
  4. package/dist/_helpers/_rollupPluginBabelHelpers.js +34 -0
  5. package/dist/_helpers/anchor.js +33 -0
  6. package/dist/_helpers/badge.js +3 -0
  7. package/dist/_helpers/button-group.js +3 -0
  8. package/dist/_helpers/button-set.js +3 -0
  9. package/dist/_helpers/button-toolbar.js +3 -0
  10. package/dist/_helpers/button__classes.js +39 -0
  11. package/dist/_helpers/card.js +75 -0
  12. package/dist/_helpers/checkbox.js +3 -0
  13. package/dist/_helpers/date-picker.js +3 -0
  14. package/dist/_helpers/dialog__body-scroll-preventer.js +58 -0
  15. package/dist/_helpers/error-message.js +3 -0
  16. package/dist/_helpers/footer.js +121 -0
  17. package/dist/_helpers/grid.js +3 -0
  18. package/dist/_helpers/group.js +3 -0
  19. package/dist/_helpers/header.js +3 -0
  20. package/dist/_helpers/icon.js +3 -0
  21. package/dist/_helpers/inject-styles.js +22 -0
  22. package/dist/_helpers/input.js +3 -0
  23. package/dist/_helpers/island.js +3 -0
  24. package/dist/_helpers/link.js +3 -0
  25. package/dist/_helpers/list.js +3 -0
  26. package/dist/_helpers/loader-screen.js +3 -0
  27. package/dist/_helpers/panel.js +3 -0
  28. package/dist/_helpers/query-assist__suggestions.js +95 -0
  29. package/dist/_helpers/radio.js +3 -0
  30. package/dist/_helpers/select__filter.js +77 -0
  31. package/dist/_helpers/services-link.js +40 -0
  32. package/dist/_helpers/sidebar.js +126 -0
  33. package/dist/_helpers/table.js +3 -0
  34. package/dist/_helpers/tabs.js +3 -0
  35. package/dist/_helpers/title.js +100 -0
  36. package/dist/alert/alert.js +262 -0
  37. package/dist/alert/container.js +48 -0
  38. package/dist/alert-service/alert-service.js +173 -0
  39. package/dist/analytics/analytics.js +118 -0
  40. package/dist/analytics/analytics__custom-plugin.js +128 -0
  41. package/dist/analytics/analytics__fus-plugin.js +102 -0
  42. package/dist/analytics/analytics__ga-plugin.js +75 -0
  43. package/dist/analytics/analytics__plugin-utils.js +80 -0
  44. package/dist/analytics-ng/analytics-ng.js +95 -0
  45. package/dist/auth/auth.js +96 -0
  46. package/dist/auth/auth__core.js +1065 -0
  47. package/dist/auth/background-flow.js +123 -0
  48. package/dist/auth/down-notification.js +117 -0
  49. package/dist/auth/iframe-flow.js +153 -0
  50. package/dist/auth/landing-entry.js +5 -0
  51. package/dist/auth/landing.js +90 -0
  52. package/dist/auth/request-builder.js +76 -0
  53. package/dist/auth/response-parser.js +118 -0
  54. package/dist/auth/storage.js +283 -0
  55. package/dist/auth/token-validator.js +180 -0
  56. package/dist/auth/window-flow.js +134 -0
  57. package/dist/auth-dialog/auth-dialog.js +180 -0
  58. package/dist/auth-dialog-service/auth-dialog-service.js +71 -0
  59. package/dist/auth-ng/auth-ng.js +206 -0
  60. package/dist/auth-ng/auth-ng.mock.js +33 -0
  61. package/dist/autofocus-ng/autofocus-ng.js +51 -0
  62. package/dist/avatar/avatar-example-datauri.js +4 -0
  63. package/dist/avatar/avatar.js +163 -0
  64. package/dist/avatar/fallback-avatar.js +142 -0
  65. package/dist/avatar-editor-ng/avatar-editor-ng.js +167 -0
  66. package/dist/avatar-editor-ng/avatar-editor-ng__template.js +3 -0
  67. package/dist/avatar-ng/avatar-ng.js +21 -0
  68. package/dist/badge/badge.js +51 -0
  69. package/dist/badge-ng/badge-ng.js +18 -0
  70. package/dist/breadcrumb-ng/breadcrumb-ng.js +37 -0
  71. package/dist/button/button.js +125 -0
  72. package/dist/button/button__classes.js +5 -0
  73. package/dist/button-group/button-group.js +30 -0
  74. package/dist/button-group/caption.js +24 -0
  75. package/dist/button-group-ng/button-group-ng.js +39 -0
  76. package/dist/button-ng/button-ng.js +217 -0
  77. package/dist/button-set/button-set.js +26 -0
  78. package/dist/button-set-ng/button-set-ng.js +19 -0
  79. package/dist/button-toolbar/button-toolbar.js +29 -0
  80. package/dist/button-toolbar-ng/button-toolbar-ng.js +24 -0
  81. package/dist/caret/caret.js +266 -0
  82. package/dist/checkbox/checkbox.js +110 -0
  83. package/dist/checkbox-ng/checkbox-ng.js +38 -0
  84. package/dist/code/code.js +137 -0
  85. package/dist/compiler-ng/compiler-ng.js +53 -0
  86. package/dist/confirm/confirm.js +127 -0
  87. package/dist/confirm-ng/confirm-ng.js +69 -0
  88. package/dist/confirm-service/confirm-service.js +117 -0
  89. package/dist/content-layout/content-layout.js +66 -0
  90. package/dist/content-layout/sidebar.js +7 -0
  91. package/dist/contenteditable/contenteditable.js +78 -0
  92. package/dist/data-list/data-list.js +208 -0
  93. package/dist/data-list/data-list.mock.js +191 -0
  94. package/dist/data-list/item.js +229 -0
  95. package/dist/data-list/selection.js +102 -0
  96. package/dist/data-list/title.js +20 -0
  97. package/dist/data-list-ng/data-list-ng.js +62 -0
  98. package/dist/date-picker/consts.js +69 -0
  99. package/dist/date-picker/date-input.js +175 -0
  100. package/dist/date-picker/date-picker.js +367 -0
  101. package/dist/date-picker/date-popup.js +483 -0
  102. package/dist/date-picker/day.js +120 -0
  103. package/dist/date-picker/formats.js +3 -0
  104. package/dist/date-picker/month-names.js +100 -0
  105. package/dist/date-picker/month-slider.js +84 -0
  106. package/dist/date-picker/month.js +55 -0
  107. package/dist/date-picker/months.js +122 -0
  108. package/dist/date-picker/weekdays.js +32 -0
  109. package/dist/date-picker/years.js +110 -0
  110. package/dist/dialog/dialog.js +205 -0
  111. package/dist/dialog/dialog__body-scroll-preventer.js +3 -0
  112. package/dist/dialog-ng/dialog-ng.js +604 -0
  113. package/dist/dialog-ng/dialog-ng__template.js +3 -0
  114. package/dist/docked-panel-ng/docked-panel-ng.js +171 -0
  115. package/dist/dropdown/anchor.js +19 -0
  116. package/dist/dropdown/dropdown.js +236 -0
  117. package/dist/dropdown-menu/dropdown-menu.js +177 -0
  118. package/dist/error-bubble/error-bubble.js +59 -0
  119. package/dist/error-message/error-message.js +57 -0
  120. package/dist/error-message-ng/error-message-ng.js +35 -0
  121. package/dist/footer/footer.js +12 -0
  122. package/dist/footer-ng/footer-ng.js +64 -0
  123. package/dist/form-ng/form-ng.js +167 -0
  124. package/dist/global/angular-component-factory.js +84 -0
  125. package/dist/global/compose.js +9 -0
  126. package/dist/global/composeRefs.js +15 -0
  127. package/dist/global/conic-gradient.js +35 -0
  128. package/dist/global/create-stateful-context.js +55 -0
  129. package/dist/global/data-tests.js +24 -0
  130. package/dist/global/dom.js +125 -0
  131. package/dist/global/focus-sensor-hoc.js +146 -0
  132. package/dist/global/fuzzy-highlight.js +67 -0
  133. package/dist/global/get-event-key.js +111 -0
  134. package/dist/global/get-uid.js +15 -0
  135. package/dist/global/inject-styles.js +15 -0
  136. package/dist/global/linear-function.js +17 -0
  137. package/dist/global/listeners.js +44 -0
  138. package/dist/global/memoize.js +20 -0
  139. package/dist/global/normalize-indent.js +30 -0
  140. package/dist/global/promise-with-timeout.js +17 -0
  141. package/dist/global/radial-gradient-mask.js +38 -0
  142. package/dist/global/react-dom-renderer.js +46 -0
  143. package/dist/global/react-render-adapter.js +41 -0
  144. package/dist/global/rerender-hoc.js +55 -0
  145. package/dist/global/ring-angular-component.js +24 -0
  146. package/dist/global/schedule-raf.js +31 -0
  147. package/dist/global/sniffer.js +6 -0
  148. package/dist/global/supports-css.js +22 -0
  149. package/dist/global/theme.js +54 -0
  150. package/dist/global/trivial-template-tag.js +17 -0
  151. package/dist/global/url.js +165 -0
  152. package/dist/global/variables_dark.js +57 -0
  153. package/dist/grid/col.js +60 -0
  154. package/dist/grid/grid.js +33 -0
  155. package/dist/grid/row.js +64 -0
  156. package/dist/group/group.js +31 -0
  157. package/dist/group-ng/group-ng.js +11 -0
  158. package/dist/header/header.js +150 -0
  159. package/dist/header/logo.js +40 -0
  160. package/dist/header/profile.js +219 -0
  161. package/dist/header/services-link.js +12 -0
  162. package/dist/header/services.js +138 -0
  163. package/dist/header/smart-profile.js +233 -0
  164. package/dist/header/smart-services.js +163 -0
  165. package/dist/header/tray-icon.js +47 -0
  166. package/dist/header/tray.js +31 -0
  167. package/dist/heading/heading.js +73 -0
  168. package/dist/http/http.js +218 -0
  169. package/dist/http/http.mock.js +67 -0
  170. package/dist/hub-source/hub-source.js +130 -0
  171. package/dist/hub-source/hub-source__user.js +30 -0
  172. package/dist/hub-source/hub-source__users-groups.js +63 -0
  173. package/dist/icon/icon.js +105 -0
  174. package/dist/icon/icon__constants.js +33 -0
  175. package/dist/icon/icon__svg.js +83 -0
  176. package/dist/icon/index.js +12 -0
  177. package/dist/icon-ng/icon-ng.js +91 -0
  178. package/dist/input/input.js +230 -0
  179. package/dist/input-ng/input-ng.js +111 -0
  180. package/dist/island/adaptive-island-hoc.js +48 -0
  181. package/dist/island/content.js +160 -0
  182. package/dist/island/header.js +84 -0
  183. package/dist/island/island.js +51 -0
  184. package/dist/island-legacy/content-legacy.js +26 -0
  185. package/dist/island-legacy/header-legacy.js +28 -0
  186. package/dist/island-legacy/island-legacy.js +28 -0
  187. package/dist/island-ng/island-content-ng.js +42 -0
  188. package/dist/island-ng/island-header-ng.js +26 -0
  189. package/dist/island-ng/island-ng-class-fixer.js +11 -0
  190. package/dist/island-ng/island-ng.js +25 -0
  191. package/dist/link/clickableLink.js +64 -0
  192. package/dist/link/link.js +115 -0
  193. package/dist/link-ng/link-ng.js +22 -0
  194. package/dist/list/consts.js +26 -0
  195. package/dist/list/list.js +822 -0
  196. package/dist/list/list__custom.js +86 -0
  197. package/dist/list/list__hint.js +26 -0
  198. package/dist/list/list__item.js +206 -0
  199. package/dist/list/list__link.js +65 -0
  200. package/dist/list/list__separator.js +30 -0
  201. package/dist/list/list__title.js +39 -0
  202. package/dist/list/list__users-groups-source.js +130 -0
  203. package/dist/loader/loader.js +71 -0
  204. package/dist/loader/loader__core.js +273 -0
  205. package/dist/loader-inline/inject-styles.js +13 -0
  206. package/dist/loader-inline/loader-inline.js +58 -0
  207. package/dist/loader-inline-ng/loader-inline-ng.js +44 -0
  208. package/dist/loader-ng/loader-ng.js +44 -0
  209. package/dist/loader-screen/loader-screen.js +44 -0
  210. package/dist/loader-screen-ng/loader-screen-ng.js +95 -0
  211. package/dist/login-dialog/login-dialog.js +188 -0
  212. package/dist/login-dialog/service.js +72 -0
  213. package/dist/markdown/code.js +31 -0
  214. package/dist/markdown/heading.js +23 -0
  215. package/dist/markdown/link.js +31 -0
  216. package/dist/markdown/markdown.js +74 -0
  217. package/dist/message/message.js +235 -0
  218. package/dist/message-bundle-ng/message-bundle-ng.js +111 -0
  219. package/dist/old-browsers-message/old-browsers-message.js +101 -0
  220. package/dist/old-browsers-message/old-browsers-message__stop.js +5 -0
  221. package/dist/old-browsers-message/white-list.js +34 -0
  222. package/dist/pager/pager.js +365 -0
  223. package/dist/pager-ng/pager-ng.js +100 -0
  224. package/dist/panel/panel.js +31 -0
  225. package/dist/panel-ng/panel-ng.js +17 -0
  226. package/dist/permissions/permissions.js +200 -0
  227. package/dist/permissions/permissions__cache.js +272 -0
  228. package/dist/permissions-ng/permissions-ng.js +277 -0
  229. package/dist/place-under-ng/place-under-ng.js +158 -0
  230. package/dist/popup/popup.consts.js +41 -0
  231. package/dist/popup/popup.js +396 -0
  232. package/dist/popup/popup.target.js +26 -0
  233. package/dist/popup/position.js +280 -0
  234. package/dist/popup-menu/popup-menu.js +117 -0
  235. package/dist/progress-bar/progress-bar.js +114 -0
  236. package/dist/progress-bar-ng/progress-bar-ng.js +17 -0
  237. package/dist/promised-click-ng/promised-click-ng.js +128 -0
  238. package/dist/proxy-attrs/proxy-attrs.js +21 -0
  239. package/dist/query-assist/query-assist.js +1096 -0
  240. package/dist/query-assist/query-assist__suggestions.js +49 -0
  241. package/dist/query-assist-ng/query-assist-ng.js +86 -0
  242. package/dist/radio/radio.js +42 -0
  243. package/dist/radio/radio__item.js +78 -0
  244. package/dist/radio-ng/radio-ng.js +47 -0
  245. package/dist/save-field-ng/save-field-ng.js +337 -0
  246. package/dist/save-field-ng/save-field-ng__template.js +3 -0
  247. package/dist/select/select.js +1357 -0
  248. package/dist/select/select__filter.js +56 -0
  249. package/dist/select/select__popup.js +553 -0
  250. package/dist/select-ng/select-ng.js +637 -0
  251. package/dist/select-ng/select-ng__lazy.js +169 -0
  252. package/dist/select-ng/select-ng__options.js +145 -0
  253. package/dist/shortcuts/core.js +245 -0
  254. package/dist/shortcuts/shortcut-title.js +51 -0
  255. package/dist/shortcuts/shortcuts-hoc.js +42 -0
  256. package/dist/shortcuts/shortcuts.js +72 -0
  257. package/dist/shortcuts-hint-ng/shortcuts-hint-ng.js +123 -0
  258. package/dist/shortcuts-hint-ng/shortcuts-hint-ng__template.js +3 -0
  259. package/dist/shortcuts-ng/shortcuts-ng.js +262 -0
  260. package/dist/sidebar-ng/sidebar-ng.js +113 -0
  261. package/dist/sidebar-ng/sidebar-ng__button-template.js +3 -0
  262. package/dist/sidebar-ng/sidebar-ng__template.js +3 -0
  263. package/dist/storage/storage.js +59 -0
  264. package/dist/storage/storage__fallback.js +215 -0
  265. package/dist/storage/storage__local.js +154 -0
  266. package/dist/style.css +1 -0
  267. package/dist/tab-trap/tab-trap.js +177 -0
  268. package/dist/table/cell.js +26 -0
  269. package/dist/table/disable-hover-hoc.js +54 -0
  270. package/dist/table/header-cell.js +92 -0
  271. package/dist/table/header.js +193 -0
  272. package/dist/table/multitable.js +141 -0
  273. package/dist/table/row-with-focus-sensor.js +83 -0
  274. package/dist/table/row.js +278 -0
  275. package/dist/table/selection-adapter.js +16 -0
  276. package/dist/table/selection-shortcuts-hoc.js +215 -0
  277. package/dist/table/selection.js +223 -0
  278. package/dist/table/smart-table.js +125 -0
  279. package/dist/table/table.js +409 -0
  280. package/dist/table-legacy-ng/table-legacy-ng.js +468 -0
  281. package/dist/table-legacy-ng/table-legacy-ng__pager.js +120 -0
  282. package/dist/table-legacy-ng/table-legacy-ng__selection-navigate-actions.js +123 -0
  283. package/dist/table-legacy-ng/table-legacy-ng__selection.js +179 -0
  284. package/dist/table-legacy-ng/table-legacy-ng__toolbar.js +57 -0
  285. package/dist/table-ng/smart-table-ng.js +68 -0
  286. package/dist/table-ng/table-ng.js +67 -0
  287. package/dist/tabs/collapsible-more.js +198 -0
  288. package/dist/tabs/collapsible-tab.js +91 -0
  289. package/dist/tabs/collapsible-tabs.js +362 -0
  290. package/dist/tabs/custom-item.js +13 -0
  291. package/dist/tabs/dumb-tabs.js +164 -0
  292. package/dist/tabs/smart-tabs.js +106 -0
  293. package/dist/tabs/tab-link.js +42 -0
  294. package/dist/tabs/tab.js +33 -0
  295. package/dist/tabs/tabs.js +71 -0
  296. package/dist/tabs-ng/tabs-ng.js +194 -0
  297. package/dist/tabs-ng/tabs-ng__template.js +3 -0
  298. package/dist/tag/tag.js +197 -0
  299. package/dist/tags-input/tags-input.js +482 -0
  300. package/dist/tags-input-ng/tags-input-ng.js +93 -0
  301. package/dist/tags-list/tags-list.js +95 -0
  302. package/dist/template-ng/template-ng.js +71 -0
  303. package/dist/text/text.js +36 -0
  304. package/dist/theme-ng/theme-ng.js +45 -0
  305. package/dist/title-ng/title-ng.js +114 -0
  306. package/dist/toggle/toggle.js +78 -0
  307. package/dist/toggle-ng/toggle-ng.js +18 -0
  308. package/dist/tooltip/tooltip.js +209 -0
  309. package/dist/tooltip-ng/tooltip-ng.js +104 -0
  310. package/dist/user-agreement/service.js +412 -0
  311. package/dist/user-agreement/toolbox.eula.js +3 -0
  312. package/dist/user-agreement/user-agreement.js +169 -0
  313. package/dist/user-card/card.js +19 -0
  314. package/dist/user-card/smart-user-card-tooltip.js +114 -0
  315. package/dist/user-card/tooltip.js +95 -0
  316. package/dist/user-card/user-card.js +51 -0
  317. package/dist/user-card-ng/user-card-ng.js +62 -0
  318. package/package.json +2 -2
@@ -0,0 +1,1096 @@
1
+ import { _ as _defineProperty } from '../_helpers/_rollupPluginBabelHelpers.js';
2
+ import 'core-js/modules/es.string.replace.js';
3
+ import 'core-js/modules/web.dom-collections.iterator.js';
4
+ import React, { Component } from 'react';
5
+ import PropTypes from 'prop-types';
6
+ import debounce from 'just-debounce-it';
7
+ import classNames from 'classnames';
8
+ import deepEqual from 'deep-equal';
9
+ import searchIcon from '@jetbrains/icons/search';
10
+ import closeIcon from '@jetbrains/icons/close';
11
+ import getUID from '../global/get-uid.js';
12
+ import joinDataTestAttributes from '../global/data-tests.js';
13
+ import { preventDefault, getRect } from '../global/dom.js';
14
+ import Caret from '../caret/caret.js';
15
+ import ContentEditable from '../contenteditable/contenteditable.js';
16
+ import PopupMenu from '../popup-menu/popup-menu.js';
17
+ import LoaderInline from '../loader-inline/loader-inline.js';
18
+ import Shortcuts from '../shortcuts/shortcuts.js';
19
+ import rerenderHOC from '../global/rerender-hoc.js';
20
+ import Theme from '../global/theme.js';
21
+ import Button from '../button/button.js';
22
+ import { Q as QueryAssistSuggestions, m as modules_da7ab055 } from '../_helpers/query-assist__suggestions.js';
23
+ import 'react-dom/server';
24
+ import '../popup/popup.js';
25
+ import 'react-dom';
26
+ import '../global/schedule-raf.js';
27
+ import '../tab-trap/tab-trap.js';
28
+ import '../popup/position.js';
29
+ import '../popup/popup.consts.js';
30
+ import '../popup/popup.target.js';
31
+ import '../shortcuts/core.js';
32
+ import 'combokeys';
33
+ import '../global/sniffer.js';
34
+ import 'sniffr';
35
+ import '../list/list.js';
36
+ import 'react-virtualized/dist/es/List';
37
+ import 'react-virtualized/dist/es/AutoSizer';
38
+ import 'react-virtualized/dist/es/WindowScroller';
39
+ import 'react-virtualized/dist/es/CellMeasurer';
40
+ import 'util-deprecate';
41
+ import 'memoize-one';
42
+ import '../global/memoize.js';
43
+ import '../global/create-stateful-context.js';
44
+ import '../list/list__link.js';
45
+ import '../link/link.js';
46
+ import 'focus-visible';
47
+ import '../link/clickableLink.js';
48
+ import '../_helpers/link.js';
49
+ import '../_helpers/list.js';
50
+ import '../list/list__item.js';
51
+ import '../avatar/avatar.js';
52
+ import '../global/url.js';
53
+ import '../avatar/fallback-avatar.js';
54
+ import '../checkbox/checkbox.js';
55
+ import '@jetbrains/icons/checkmark';
56
+ import '@jetbrains/icons/remove-10px';
57
+ import '../icon/icon.js';
58
+ import '../icon/icon__constants.js';
59
+ import '../_helpers/icon.js';
60
+ import '../icon/icon__svg.js';
61
+ import '../_helpers/checkbox.js';
62
+ import '../list/list__custom.js';
63
+ import '../global/get-event-key.js';
64
+ import '../list/list__title.js';
65
+ import '../list/list__separator.js';
66
+ import '../list/list__hint.js';
67
+ import '../list/consts.js';
68
+ import '../_helpers/inject-styles.js';
69
+ import '../global/conic-gradient.js';
70
+ import 'conic-gradient';
71
+ import '../global/supports-css.js';
72
+ import '../global/inject-styles.js';
73
+ import '../global/radial-gradient-mask.js';
74
+ import '../global/react-render-adapter.js';
75
+ import '../global/composeRefs.js';
76
+ import '@jetbrains/icons/chevron-10px';
77
+ import '../_helpers/button__classes.js';
78
+
79
+ const POPUP_COMPENSATION = PopupMenu.ListProps.Dimension.ITEM_PADDING + PopupMenu.PopupProps.Dimension.BORDER_WIDTH;
80
+ const ngModelStateField = 'query';
81
+
82
+ function noop() {}
83
+
84
+ function cleanText(text) {
85
+ return text.replace(/([\n\r])+/g, ' ');
86
+ }
87
+ /**
88
+ * @name Query Assist
89
+ */
90
+
91
+ /**
92
+ * ## Data source function
93
+
94
+ Component class calls a data source function when user input happens and passes an object with fields \`caret\`, \`focus\` and \`query\` as the only argument.
95
+ The function must return an object with the fields described below. The object can be optionally wrapped in a Promise.
96
+
97
+ ### Return object fields
98
+
99
+ \`caret\` and \`query\` should just return server values provided to data source function.
100
+ These fields allow the Query Assist component to recognise and drop earlier responses from the server.
101
+
102
+ + __caret__ (\`string=0\`) Caret from request
103
+ + __query__ (\`string=''\`) Query from request
104
+ + __styleRanges__ (\`Array<suggestion>=\`) Array of \`styleRange\` objects, used to highlight the request in the input field
105
+ + __suggestions__ (\`Array<styleRange>\`) Array of \`suggestion\` objects to show.
106
+
107
+ ### **styleRange** object fields
108
+
109
+ start \`number\` Range start (in characters)
110
+ length \`number\` Range length (in characters)
111
+ style \`string\` Style of the range. Possible values: \`text\`, \`field_value\`, \`field_name\`, \`operator\`
112
+
113
+ ### **suggestion** object fields
114
+
115
+ + __prefix__ \`string=\` Suggestion option prefix
116
+ + __option__ \`string\` Suggestion option
117
+ + __suffix__ \`string=\` Suggestion option suffix
118
+ + __description__ \`string=\` Suggestion option description. Is not visible when a group is set
119
+ + __matchingStart__ \`number\` (required when matchingEnd is set) Start of the highlighted part of an option in the suggestions list (in characters)
120
+ + __matchingEnd__ \`number\` (required when matchingEnd is set) End of the highlighted part of an option in the suggestions list (in characters)
121
+ + __caret__ \`number\` Caret position after option completion (in characters)
122
+ + __completionStart__ \`number\` Where to start insertion (or replacement, when completing with the \`Tab\` key) of the completion option (in characters)
123
+ + __completionEnd__ \`number\` Where to end insertion of the completion option (in characters)
124
+ + __group__ \`string=\` Group title. Options with the same title are grouped under it
125
+ + __icon__ \`string=\` Icon URI, Data URI is possible
126
+ */
127
+
128
+
129
+ class QueryAssist extends Component {
130
+ constructor() {
131
+ var _this;
132
+
133
+ super(...arguments);
134
+ _this = this;
135
+
136
+ _defineProperty(this, "state", {
137
+ dirty: !this.props.query,
138
+ query: this.props.query,
139
+ placeholderEnabled: !this.props.query,
140
+ shortcuts: !!this.props.focus,
141
+ suggestions: [],
142
+ showPopup: false
143
+ });
144
+
145
+ _defineProperty(this, "ngModelStateField", ngModelStateField);
146
+
147
+ _defineProperty(this, "historyStack", []);
148
+
149
+ _defineProperty(this, "handleFocusChange", e => {
150
+ // otherwise it's blur and false
151
+ const focus = e.type === 'focus';
152
+ this.immediateState.focus = focus;
153
+
154
+ if (!focus) {
155
+ this.blurInput(); // Close popup on blur by keyboard (mostly shift+tab)
156
+
157
+ if (!this.mouseIsDownOnPopup) {
158
+ this.closePopup();
159
+ }
160
+ } else {
161
+ this.setCaretPosition();
162
+ }
163
+
164
+ if (!this.mouseIsDownOnPopup) {
165
+ this.props.onFocusChange({
166
+ focus
167
+ });
168
+ }
169
+
170
+ this.setState({
171
+ shortcuts: !!focus
172
+ });
173
+ });
174
+
175
+ _defineProperty(this, "nodeRef", node => {
176
+ this.node = node;
177
+ });
178
+
179
+ _defineProperty(this, "setCaretPosition", function () {
180
+ let params = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
181
+ const queryLength = _this.immediateState.query != null && _this.immediateState.query.length;
182
+ const newCaretPosition = _this.immediateState.caret < queryLength ? _this.immediateState.caret : queryLength;
183
+
184
+ if (params.fromContentEditable) {
185
+ _this.immediateState.selection = _this.immediateState.selection ? _this.immediateState.selection : _this.state.query && _this.state.query.length;
186
+ }
187
+
188
+ if (_this.immediateState.focus && !_this.props.disabled) {
189
+ if (Number.isInteger(_this.immediateState.selection) && _this.immediateState.selection > -1) {
190
+ // Set to end of field value if newCaretPosition is inappropriate
191
+ _this.caret.setPosition(newCaretPosition >= 0 ? newCaretPosition : -1);
192
+
193
+ _this.scrollInput();
194
+ } else if (_this.immediateState.selection && _this.immediateState.selection.startOffset !== undefined) {
195
+ _this.caret.setPosition(_this.immediateState.selection);
196
+ } else if (!_this.immediateState.selection || params.forceSetCaret) {
197
+ _this.caret.setPosition(-1);
198
+ }
199
+ }
200
+ });
201
+
202
+ _defineProperty(this, "togglePlaceholder", () => {
203
+ const query = this.getQuery();
204
+ const currentQueryIsEmpty = this.immediateState.query === '';
205
+ const newQueryIsEmpty = query === '';
206
+
207
+ if (newQueryIsEmpty !== currentQueryIsEmpty) {
208
+ this.setState({
209
+ placeholderEnabled: newQueryIsEmpty
210
+ });
211
+ }
212
+ });
213
+
214
+ _defineProperty(this, "handleInput", e => {
215
+ this.togglePlaceholder();
216
+ const currentCaret = this.caret.getPosition();
217
+ const props = {
218
+ dirty: true,
219
+ query: this.getQuery(),
220
+ caret: Number.isInteger(currentCaret) ? currentCaret : currentCaret.position,
221
+ focus: true
222
+ };
223
+
224
+ if (this.immediateState.query === props.query && !this.isComposing) {
225
+ this.handleCaretMove(e);
226
+ return;
227
+ }
228
+
229
+ if (this.isComposing) {
230
+ return;
231
+ }
232
+
233
+ this.immediateState = props;
234
+ this.props.onChange(props);
235
+
236
+ if (props.query.length > 0) {
237
+ this.requestData();
238
+ }
239
+ });
240
+
241
+ _defineProperty(this, "handleEnter", e => {
242
+ if (e.key === 'Enter') {
243
+ preventDefault(e);
244
+ }
245
+ });
246
+
247
+ _defineProperty(this, "handleTab", e => {
248
+ const list = this._popup && this._popup.list;
249
+ const suggestion = list && (list.getSelected() || list.getFirst());
250
+
251
+ if (suggestion && this.state.showPopup) {
252
+ preventDefault(e);
253
+
254
+ if (this.getQuery() !== this.immediateState.suggestionsQuery) {
255
+ return false;
256
+ }
257
+
258
+ return this.handleComplete(suggestion, true);
259
+ }
260
+
261
+ if (this.state.loading) {
262
+ preventDefault(e);
263
+ return false;
264
+ }
265
+
266
+ return true;
267
+ });
268
+
269
+ _defineProperty(this, "setState", (state, resolve) => {
270
+ super.setState(state, () => {
271
+ this._pushHistory(state);
272
+
273
+ resolve === null || resolve === void 0 ? void 0 : resolve();
274
+ });
275
+ });
276
+
277
+ _defineProperty(this, "undo", e => {
278
+ // eslint-disable-next-line no-unused-vars
279
+ const [current, previous] = this.historyStack.splice(0, 2);
280
+
281
+ if (!previous) {
282
+ return;
283
+ }
284
+
285
+ this.setState({
286
+ query: previous.query
287
+ }, () => {
288
+ this.caret.setPosition(previous.caret);
289
+ this.handleInput(e);
290
+ });
291
+ });
292
+
293
+ _defineProperty(this, "handlePaste", e => {
294
+ const INSERT_COMMAND = 'insertText';
295
+
296
+ if (e.clipboardData && document.queryCommandSupported(INSERT_COMMAND)) {
297
+ preventDefault(e);
298
+ const text = cleanText(e.clipboardData.getData('text/plain'));
299
+ document.execCommand(INSERT_COMMAND, false, text);
300
+ this.handleInput(e);
301
+ }
302
+ });
303
+
304
+ _defineProperty(this, "handleCaretMove", e => {
305
+ if (this.isComposing) {
306
+ return;
307
+ }
308
+
309
+ const currentCaret = this.caret.getPosition();
310
+ const caret = Number.isInteger(currentCaret) ? currentCaret : currentCaret.position;
311
+ const popupHidden = !this.state.showPopup && e.type === 'click';
312
+
313
+ if (!this.props.disabled && (caret !== this.immediateState.caret || popupHidden)) {
314
+ this.immediateState.caret = caret;
315
+ this.scrollInput();
316
+
317
+ if (this.immediateState.query.length > 0) {
318
+ this.requestData();
319
+ }
320
+ }
321
+
322
+ if (this.immediateState.query.length < 1) {
323
+ this.setState({
324
+ showPopup: false
325
+ });
326
+ }
327
+ });
328
+
329
+ _defineProperty(this, "handleStyleRangesResponse", _ref => {
330
+ let {
331
+ suggestions,
332
+ ...restProps
333
+ } = _ref;
334
+ return this.handleResponse(restProps);
335
+ });
336
+
337
+ _defineProperty(this, "handleResponse", function (_ref2) {
338
+ let {
339
+ query = '',
340
+ caret = 0,
341
+ styleRanges,
342
+ suggestions = []
343
+ } = _ref2;
344
+ let afterCompletion = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
345
+ return new Promise((resolve, reject) => {
346
+ if (query === _this.getQuery() && (caret === _this.immediateState.caret || _this.immediateState.caret === undefined)) {
347
+ // Do not setState on unmounted component
348
+ if (!_this.node) {
349
+ return;
350
+ }
351
+
352
+ const state = {
353
+ dirty: _this.immediateState.dirty,
354
+ loading: false,
355
+ placeholderEnabled: !query,
356
+ query,
357
+ suggestions,
358
+ showPopup: !!suggestions.length && !afterCompletion
359
+ };
360
+ _this.immediateState.suggestionsQuery = query; // Do not update deep equal styleRanges to simplify shouldComponentUpdate check
361
+
362
+ if (!deepEqual(_this.state.styleRanges, styleRanges)) {
363
+ state.styleRanges = styleRanges;
364
+ }
365
+
366
+ _this.immediateState.selection = _this.caret.getPosition({
367
+ avoidFocus: true
368
+ });
369
+
370
+ _this.setState(state, resolve);
371
+ } else {
372
+ reject(new Error('Current and response queries mismatch'));
373
+ }
374
+ });
375
+ });
376
+
377
+ _defineProperty(this, "handleApply", () => {
378
+ this.closePopup();
379
+ this.immediateState.dirty = false; // Only set dirty to false when query is saved already
380
+
381
+ if (this.immediateState.query === this.state.query) {
382
+ this.setState({
383
+ dirty: false
384
+ });
385
+ }
386
+
387
+ return this.props.onApply(this.immediateState);
388
+ });
389
+
390
+ _defineProperty(this, "handleComplete", (data, replace) => {
391
+ if (!data || !data.data) {
392
+ this.handleApply();
393
+ return;
394
+ }
395
+
396
+ const query = this.getQuery();
397
+ const currentCaret = this.immediateState.caret;
398
+ const suggestion = data.data;
399
+ const prefix = suggestion.prefix || '';
400
+ const suffix = suggestion.suffix || '';
401
+ const state = {
402
+ caret: suggestion.caret,
403
+ selection: suggestion.caret,
404
+ query: query.substr(0, suggestion.completionStart) + prefix + suggestion.option + suffix
405
+ };
406
+
407
+ if (typeof replace === 'boolean' && replace) {
408
+ state.query += this.immediateState.query.substr(suggestion.completionEnd);
409
+ } else {
410
+ state.query += this.immediateState.query.substr(this.immediateState.caret);
411
+ }
412
+
413
+ this.props.onChange(state);
414
+ this.props.onApplySuggestion(data.data, state);
415
+ const focusState = {
416
+ focus: true
417
+ };
418
+ this.props.onFocusChange(focusState);
419
+
420
+ if (state.query !== this.immediateState.query) {
421
+ this.setState({
422
+ placeholderEnabled: !state.query,
423
+ query: state.query
424
+ });
425
+ }
426
+
427
+ this.immediateState = Object.assign(state, focusState);
428
+
429
+ if (this.immediateState.caret !== currentCaret) {
430
+ this.setCaretPosition();
431
+ }
432
+
433
+ this.closePopup();
434
+ this.requestData(true);
435
+ });
436
+
437
+ _defineProperty(this, "requestStyleRanges", () => {
438
+ const {
439
+ query,
440
+ caret
441
+ } = this.immediateState;
442
+
443
+ if (!query) {
444
+ return Promise.reject(new Error('Query is empty'));
445
+ }
446
+
447
+ return this.sendRequest({
448
+ query,
449
+ caret,
450
+ omitSuggestions: true
451
+ }).then(this.handleStyleRangesResponse).catch(noop);
452
+ });
453
+
454
+ _defineProperty(this, "requestHandler", function () {
455
+ let afterCompletion = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
456
+
457
+ if (_this.props.disabled) {
458
+ return Promise.reject(new Error('QueryAssist(@jetbrains/ring-ui): null exception'));
459
+ }
460
+
461
+ const {
462
+ query,
463
+ caret
464
+ } = _this.immediateState;
465
+ return _this.sendRequest({
466
+ query,
467
+ caret
468
+ }).then(data => _this.handleResponse(data, afterCompletion)).catch(noop);
469
+ });
470
+
471
+ _defineProperty(this, "handleCtrlSpace", e => {
472
+ preventDefault(e);
473
+
474
+ if (!this.state.showPopup) {
475
+ this.requestData();
476
+ }
477
+ });
478
+
479
+ _defineProperty(this, "trackPopupMouseState", e => {
480
+ this.mouseIsDownOnPopup = e.type === 'mousedown';
481
+ });
482
+
483
+ _defineProperty(this, "trackCompositionState", e => {
484
+ this.isComposing = e.type !== 'compositionend';
485
+ });
486
+
487
+ _defineProperty(this, "closePopup", () => {
488
+ if (this.node) {
489
+ this.setState({
490
+ showPopup: false
491
+ });
492
+ }
493
+ });
494
+
495
+ _defineProperty(this, "clearQuery", () => {
496
+ const state = {
497
+ dirty: false,
498
+ caret: 0,
499
+ query: '',
500
+ focus: true
501
+ };
502
+ this.props.onChange(state);
503
+ this.props.onClear();
504
+ this.immediateState = state;
505
+ this.setState({
506
+ dirty: false,
507
+ query: '',
508
+ placeholderEnabled: true,
509
+ loading: false
510
+ });
511
+ });
512
+
513
+ _defineProperty(this, "inputRef", node => {
514
+ if (!node) {
515
+ return;
516
+ }
517
+
518
+ this.input = node;
519
+ this.caret = new Caret(this.input);
520
+ });
521
+
522
+ _defineProperty(this, "popupRef", node => {
523
+ this._popup = node;
524
+ });
525
+
526
+ _defineProperty(this, "placeholderRef", node => {
527
+ this.placeholder = node;
528
+ });
529
+
530
+ _defineProperty(this, "glassRef", node => {
531
+ this.glass = node;
532
+ });
533
+
534
+ _defineProperty(this, "loaderRef", node => {
535
+ this.loader = node;
536
+ });
537
+
538
+ _defineProperty(this, "clearRef", node => {
539
+ this.clear = node;
540
+ });
541
+
542
+ _defineProperty(this, "shortcutsScope", getUID('ring-query-assist-'));
543
+
544
+ _defineProperty(this, "shortcutsMap", {
545
+ del: noop,
546
+ enter: this.handleComplete,
547
+ 'command+enter': this.handleComplete,
548
+ 'ctrl+enter': this.handleComplete,
549
+ 'ctrl+space': this.handleCtrlSpace,
550
+ tab: this.handleTab,
551
+ 'meta+z': this.undo,
552
+ right: noop,
553
+ left: noop,
554
+ space: noop,
555
+ home: noop,
556
+ end: noop
557
+ });
558
+ }
559
+
560
+ static getDerivedStateFromProps(_ref3, _ref4) {
561
+ let {
562
+ query
563
+ } = _ref3;
564
+ let {
565
+ prevQuery
566
+ } = _ref4;
567
+ const nextState = {
568
+ prevQuery: query
569
+ };
570
+
571
+ if (typeof query === 'string' && query !== prevQuery) {
572
+ nextState.query = query;
573
+ nextState.placeholderEnabled = !query;
574
+ }
575
+
576
+ return nextState;
577
+ }
578
+
579
+ componentDidMount() {
580
+ const query = this.props.query || '';
581
+ this.immediateState = {
582
+ query,
583
+ caret: Number.isFinite(this.props.caret) ? this.props.caret : query.length,
584
+ focus: Boolean(this.props.autoOpen || this.props.focus)
585
+ };
586
+ this.setupRequestHandler(this.props.delay);
587
+
588
+ if (this.props.autoOpen && query.length > 0) {
589
+ this.requestHandler().catch(noop);
590
+ } else {
591
+ this.requestStyleRanges().catch(noop);
592
+ }
593
+
594
+ this.setCaretPosition();
595
+
596
+ this._pushHistory(this.state);
597
+ }
598
+
599
+ shouldComponentUpdate(props, state) {
600
+ return state.query !== this.state.query || state.dirty !== this.state.dirty || state.loading !== this.state.loading || state.showPopup !== this.state.showPopup || state.suggestions !== this.state.suggestions || state.styleRanges !== this.state.styleRanges || state.placeholderEnabled !== this.state.placeholderEnabled || props.placeholder !== this.props.placeholder || props.disabled !== this.props.disabled || props.clear !== this.props.clear || props.focus !== this.props.focus || props.actions !== this.props.actions || props.loader !== this.props.loader || props.glass !== this.props.glass;
601
+ }
602
+
603
+ componentDidUpdate(prevProps) {
604
+ const {
605
+ caret,
606
+ delay,
607
+ query
608
+ } = this.props;
609
+ const queryChanged = query !== prevProps.query;
610
+ this.updateFocus(prevProps);
611
+ this.setupRequestHandler(delay);
612
+ const shouldSetCaret = typeof caret === 'number' && caret !== prevProps.caret;
613
+
614
+ if (shouldSetCaret) {
615
+ this.immediateState.caret = caret;
616
+ }
617
+
618
+ if (typeof query === 'string' && queryChanged && query !== this.immediateState.query) {
619
+ this.immediateState.query = query;
620
+
621
+ if (query && prevProps.autoOpen && query.length > 0) {
622
+ this.requestData();
623
+ } else if (query) {
624
+ this.requestStyleRanges();
625
+ }
626
+ }
627
+ }
628
+
629
+ updateFocus(_ref5) {
630
+ let {
631
+ focus,
632
+ caret
633
+ } = _ref5;
634
+ const isCaretChanged = caret !== this.props.caret;
635
+ const isFocusChanged = focus !== this.props.focus;
636
+
637
+ if (isFocusChanged || isCaretChanged) {
638
+ const focusValue = isFocusChanged ? this.props.focus : true;
639
+ this.setFocus(focusValue);
640
+ }
641
+ }
642
+
643
+ scrollInput() {
644
+ const caretOffset = this.caret.getOffset();
645
+
646
+ if (this.input.clientWidth !== this.input.scrollWidth && caretOffset > this.input.clientWidth) {
647
+ this.input.scrollLeft += caretOffset;
648
+ }
649
+ }
650
+
651
+ getQuery() {
652
+ return this.input.textContent.replace(/\s/g, ' ');
653
+ }
654
+
655
+ isRenderingGlassOrLoader() {
656
+ const renderLoader = this.props.loader !== false && this.state.loading;
657
+ return this.props.glass || renderLoader;
658
+ }
659
+
660
+ _pushHistory(state) {
661
+ var _this$historyStack$;
662
+
663
+ const queryIsSet = ('query' in state);
664
+ const queryIsSame = ((_this$historyStack$ = this.historyStack[0]) === null || _this$historyStack$ === void 0 ? void 0 : _this$historyStack$.query) === state.query;
665
+
666
+ if (queryIsSet && !queryIsSame) {
667
+ var _this$caret$getPositi, _this$caret;
668
+
669
+ this.historyStack.unshift({
670
+ query: state.query,
671
+ caret: (_this$caret$getPositi = (_this$caret = this.caret) === null || _this$caret === void 0 ? void 0 : _this$caret.getPosition({
672
+ avoidFocus: true
673
+ })) !== null && _this$caret$getPositi !== void 0 ? _this$caret$getPositi : -1
674
+ });
675
+ }
676
+ }
677
+
678
+ sendRequest(params) {
679
+ const value = this.props.dataSource(params);
680
+ const dataPromise = Promise.resolve(value);
681
+ const CLOSE_POPUP_TIMEOUT = 500; // Close popup after timeout between long requests
682
+
683
+ const timeout = window.setTimeout(() => {
684
+ if (this.node) {
685
+ this.setState({
686
+ loading: true
687
+ });
688
+ }
689
+
690
+ if (params.query === this.immediateState.query) {
691
+ this.closePopup();
692
+ }
693
+ }, CLOSE_POPUP_TIMEOUT);
694
+ dataPromise.then(() => window.clearTimeout(timeout)).catch(() => {
695
+ window.clearTimeout(timeout);
696
+ this.setState({
697
+ loading: false
698
+ });
699
+ });
700
+ return dataPromise;
701
+ }
702
+
703
+ getPopupOffset(suggestions) {
704
+ const ICON_SPACING = 12;
705
+ const minOffset = this.isRenderingGlassOrLoader() ? ICON_SPACING : 0;
706
+
707
+ if (!this.input) {
708
+ return minOffset;
709
+ } // First suggestion should be enough?
710
+
711
+
712
+ const suggestion = suggestions && suggestions[0]; // Check if suggestion begins not from the end
713
+
714
+ const completionStart = suggestion && suggestion.completionStart !== suggestion.completionEnd && suggestion.completionStart;
715
+ const inputChildren = this.input.firstChild && this.input.firstChild.children;
716
+ const completionStartNode = inputChildren && Number.isInteger(completionStart) && inputChildren[Math.min(completionStart, inputChildren.length - 1)];
717
+ let offset = completionStartNode && getRect(completionStartNode).right - getRect(this.input).left;
718
+
719
+ if (!offset) {
720
+ const caret = this.caret.getOffset(); // Do not compensate caret in the beginning of field
721
+
722
+ if (caret === 0) {
723
+ return minOffset;
724
+ } else {
725
+ offset = caret;
726
+ }
727
+ }
728
+
729
+ const result = offset - POPUP_COMPENSATION;
730
+ return result < minOffset ? minOffset : result;
731
+ }
732
+
733
+ blurInput() {
734
+ this.immediateState.selection = {};
735
+
736
+ if (!this.props.focus) {
737
+ this.caret.target.blur();
738
+ }
739
+ }
740
+ /**
741
+ * Optionally setup data request delay. For each component create a separate
742
+ * instance of the delayed function. This may help reduce the load on the server
743
+ * when the user quickly inputs data.
744
+ */
745
+
746
+
747
+ setupRequestHandler(delay) {
748
+ const needDelay = typeof delay === 'number';
749
+ const hasDelay = this.requestData !== this.requestHandler;
750
+
751
+ if (!this.requestData || hasDelay !== needDelay) {
752
+ if (needDelay) {
753
+ this.requestData = debounce(this.requestHandler, delay);
754
+ } else {
755
+ this.requestData = this.requestHandler;
756
+ }
757
+ }
758
+ }
759
+
760
+ _renderSuggestion(suggestion) {
761
+ const {
762
+ ITEM
763
+ } = PopupMenu.ListProps.Type;
764
+ const {
765
+ description,
766
+ icon,
767
+ group
768
+ } = suggestion;
769
+ const key = QueryAssistSuggestions.createKey(suggestion);
770
+ const label = QueryAssistSuggestions.renderLabel(suggestion);
771
+ return {
772
+ key,
773
+ icon,
774
+ label,
775
+ description,
776
+ group,
777
+ rgItemType: ITEM,
778
+ data: suggestion
779
+ };
780
+ }
781
+
782
+ renderSuggestions() {
783
+ const {
784
+ suggestions
785
+ } = this.state;
786
+
787
+ if (!suggestions || !suggestions.length) {
788
+ return [];
789
+ }
790
+
791
+ return QueryAssistSuggestions.renderList(suggestions, this._renderSuggestion);
792
+ }
793
+
794
+ renderQuery() {
795
+ const {
796
+ dirty,
797
+ styleRanges,
798
+ query
799
+ } = this.state;
800
+ const classes = [];
801
+ const LETTER_CLASS = 'letter';
802
+ const LETTER_DEFAULT_CLASS = modules_da7ab055.letterDefault;
803
+
804
+ if (styleRanges && styleRanges.length) {
805
+ styleRanges.forEach((item, index) => {
806
+ if (dirty && index === styleRanges.length - 1 && item.style === 'text') {
807
+ return;
808
+ }
809
+
810
+ const styleName = "".concat(LETTER_CLASS, "-").concat(item.style.replace('_', '-'));
811
+
812
+ for (let i = item.start; i < item.start + item.length; i++) {
813
+ classes[i] = modules_da7ab055[styleName];
814
+ }
815
+ });
816
+ }
817
+
818
+ return Array.from(query).map((letter, index, letters) => {
819
+ const className = classNames(modules_da7ab055.letter, classes[index] || LETTER_DEFAULT_CLASS);
820
+ const dataTest = letters.length - 1 === index ? 'ring-query-assist-last-letter' : null; // \u00a0 === &nbsp;
821
+
822
+ return /*#__PURE__*/React.createElement("span", {
823
+ // eslint-disable-next-line react/no-array-index-key
824
+ key: index + letter,
825
+ className: className,
826
+ "data-test": dataTest
827
+ }, letter === ' ' ? '\u00a0' : letter);
828
+ });
829
+ }
830
+
831
+ setFocus(focus) {
832
+ this.setState({
833
+ shortcuts: !!focus
834
+ });
835
+ const isComponentFocused = Boolean(this.immediateState.focus);
836
+
837
+ if (focus === false && isComponentFocused) {
838
+ this.immediateState.focus = focus;
839
+ this.blurInput();
840
+ } else if (focus === true && !isComponentFocused) {
841
+ this.immediateState.focus = focus;
842
+ this.setCaretPosition({
843
+ forceSetCaret: true
844
+ });
845
+ }
846
+ }
847
+
848
+ renderActions() {
849
+ const actions = [].concat(this.props.actions || []);
850
+ const renderClear = this.props.clear && !!this.state.query;
851
+
852
+ if (renderClear) {
853
+ actions.push( /*#__PURE__*/React.createElement(Button, {
854
+ icon: closeIcon,
855
+ key: 'clearAction',
856
+ className: modules_da7ab055.icon,
857
+ iconClassName: modules_da7ab055.iconInner,
858
+ title: this.props.translations.clearTitle,
859
+ ref: this.clearRef,
860
+ onClick: this.clearQuery,
861
+ "data-test": "query-assist-clear-icon"
862
+ }));
863
+ }
864
+
865
+ return actions;
866
+ }
867
+
868
+ render() {
869
+ const {
870
+ theme,
871
+ glass,
872
+ 'data-test': dataTest,
873
+ className,
874
+ useCustomItemRender
875
+ } = this.props;
876
+ const renderPlaceholder = !!this.props.placeholder && this.state.placeholderEnabled;
877
+ const renderLoader = this.props.loader !== false && this.state.loading;
878
+ const renderGlass = glass && !renderLoader;
879
+ const renderUnderline = theme === Theme.DARK;
880
+ const actions = this.renderActions();
881
+ const inputClasses = classNames({
882
+ ["".concat(modules_da7ab055.input, " ring-js-shortcuts")]: true,
883
+ [modules_da7ab055.inputGap]: actions.length || this.isRenderingGlassOrLoader() && !glass,
884
+ [modules_da7ab055.inputGap2]: actions.length === 2,
885
+ // TODO: replace with flex-box layout
886
+ [modules_da7ab055.inputLeftGap]: this.isRenderingGlassOrLoader() && glass,
887
+ [modules_da7ab055.inputDisabled]: this.props.disabled
888
+ });
889
+ return /*#__PURE__*/React.createElement("div", {
890
+ "data-test": joinDataTestAttributes('ring-query-assist', dataTest),
891
+ className: classNames(className, modules_da7ab055.queryAssist, modules_da7ab055[theme]),
892
+ role: "presentation",
893
+ ref: this.nodeRef
894
+ }, this.state.shortcuts && /*#__PURE__*/React.createElement(Shortcuts, {
895
+ map: this.shortcutsMap,
896
+ scope: this.shortcutsScope
897
+ }), renderGlass && /*#__PURE__*/React.createElement(Button, {
898
+ icon: searchIcon,
899
+ className: modules_da7ab055.icon,
900
+ iconClassName: modules_da7ab055.iconInner,
901
+ title: this.props.translations.searchTitle,
902
+ ref: this.glassRef,
903
+ onClick: this.handleApply,
904
+ "data-test": "query-assist-search-icon"
905
+ }), renderLoader && /*#__PURE__*/React.createElement("div", {
906
+ className: classNames(modules_da7ab055.icon, modules_da7ab055.loader, {
907
+ [modules_da7ab055.loaderOnTheRight]: !glass
908
+ }),
909
+ ref: this.loaderRef
910
+ }, /*#__PURE__*/React.createElement(LoaderInline, {
911
+ theme: theme
912
+ })), /*#__PURE__*/React.createElement(ContentEditable, {
913
+ "aria-label": this.props.translations.searchTitle,
914
+ className: inputClasses,
915
+ "data-test": "ring-query-assist-input",
916
+ inputRef: this.inputRef,
917
+ disabled: this.props.disabled,
918
+ onComponentUpdate: () => this.setCaretPosition({
919
+ fromContentEditable: true
920
+ }),
921
+ onBlur: this.handleFocusChange,
922
+ onClick: this.handleCaretMove,
923
+ onCompositionStart: this.trackCompositionState,
924
+ onCompositionEnd: this.trackCompositionState,
925
+ onFocus: this.handleFocusChange,
926
+ onInput: this.handleInput // To support IE use the same method
927
+ ,
928
+ onKeyUp: this.handleInput // to handle input and key up
929
+ ,
930
+ onKeyDown: this.handleEnter,
931
+ onPaste: this.handlePaste,
932
+ spellCheck: "false"
933
+ }, this.state.query && /*#__PURE__*/React.createElement("span", null, this.renderQuery())), renderPlaceholder && /*#__PURE__*/React.createElement("button", {
934
+ type: "button",
935
+ className: classNames(modules_da7ab055.placeholder, {
936
+ [modules_da7ab055.placeholderSpaced]: glass
937
+ }),
938
+ ref: this.placeholderRef,
939
+ onClick: this.handleCaretMove,
940
+ "data-test": "query-assist-placeholder"
941
+ }, this.props.placeholder), renderUnderline && /*#__PURE__*/React.createElement("div", {
942
+ className: modules_da7ab055.focusUnderline
943
+ }), actions && /*#__PURE__*/React.createElement("div", {
944
+ "data-test": "ring-query-assist-actions",
945
+ className: modules_da7ab055.actions
946
+ }, actions), /*#__PURE__*/React.createElement(PopupMenu, {
947
+ hidden: !this.state.showPopup,
948
+ onCloseAttempt: this.closePopup,
949
+ ref: this.popupRef,
950
+ anchorElement: this.node,
951
+ keepMounted: true,
952
+ attached: true,
953
+ className: classNames(modules_da7ab055[theme], this.props.popupClassName),
954
+ directions: [PopupMenu.PopupProps.Directions.BOTTOM_RIGHT],
955
+ data: useCustomItemRender ? this.state.suggestions : this.renderSuggestions(),
956
+ "data-test": "ring-query-assist-popup",
957
+ hint: this.props.hint,
958
+ hintOnSelection: this.props.hintOnSelection,
959
+ left: this.getPopupOffset(this.state.suggestions),
960
+ maxHeight: PopupMenu.PopupProps.MaxHeight.SCREEN,
961
+ onMouseDown: this.trackPopupMouseState,
962
+ onMouseUp: this.trackPopupMouseState,
963
+ onSelect: this.handleComplete
964
+ }));
965
+ }
966
+
967
+ }
968
+
969
+ _defineProperty(QueryAssist, "propTypes", {
970
+ theme: PropTypes.string,
971
+
972
+ /**
973
+ * Open suggestions popup during the initial render
974
+ */
975
+ autoOpen: PropTypes.bool,
976
+
977
+ /**
978
+ * Initial caret position
979
+ */
980
+ caret: PropTypes.number,
981
+
982
+ /**
983
+ * Show clickable "cross" icon on the right which clears the query
984
+ */
985
+ clear: PropTypes.bool,
986
+
987
+ /**
988
+ * Additional class for the component
989
+ */
990
+ className: PropTypes.string,
991
+
992
+ /**
993
+ * Additional class for the popup
994
+ */
995
+ popupClassName: PropTypes.string,
996
+
997
+ /**
998
+ * Data source function
999
+ */
1000
+ dataSource: PropTypes.func.isRequired,
1001
+
1002
+ /**
1003
+ * Input debounce delay
1004
+ */
1005
+ delay: PropTypes.number,
1006
+
1007
+ /**
1008
+ * Disable the component
1009
+ */
1010
+ disabled: PropTypes.bool,
1011
+
1012
+ /**
1013
+ * Initial focus
1014
+ */
1015
+ focus: PropTypes.bool,
1016
+
1017
+ /**
1018
+ * Hint under the suggestions list
1019
+ */
1020
+ hint: PropTypes.string,
1021
+
1022
+ /**
1023
+ * Hint under the suggestions list visible when a suggestion is selected
1024
+ */
1025
+ hintOnSelection: PropTypes.string,
1026
+
1027
+ /**
1028
+ * Show clickable "glass" icon on the right which applies the query
1029
+ */
1030
+ glass: PropTypes.bool,
1031
+
1032
+ /**
1033
+ * Show loader when a data request is in process
1034
+ */
1035
+ loader: PropTypes.bool,
1036
+
1037
+ /**
1038
+ * Field placeholder value
1039
+ */
1040
+ placeholder: PropTypes.string,
1041
+
1042
+ /**
1043
+ * Called when the query is applied. An object with fields `caret`, `focus` and `query` is passed as an argument
1044
+ */
1045
+ onApply: PropTypes.func,
1046
+
1047
+ /**
1048
+ * Called when the query is changed. An object with fields `caret` and `query` is passed as an argument
1049
+ */
1050
+ onChange: PropTypes.func,
1051
+
1052
+ /**
1053
+ * Called when the query is cleared. Called without arguments
1054
+ */
1055
+ onClear: PropTypes.func,
1056
+
1057
+ /**
1058
+ * Called when the suggestion is applied
1059
+ */
1060
+ onApplySuggestion: PropTypes.func,
1061
+
1062
+ /**
1063
+ * Called when the focus status is changed. An object with fields `focus` is passed as an argument
1064
+ */
1065
+ onFocusChange: PropTypes.func,
1066
+
1067
+ /**
1068
+ * Initial query
1069
+ */
1070
+ query: PropTypes.string,
1071
+ useCustomItemRender: PropTypes.bool,
1072
+ translations: PropTypes.object,
1073
+ actions: PropTypes.array,
1074
+ 'data-test': PropTypes.string
1075
+ });
1076
+
1077
+ _defineProperty(QueryAssist, "defaultProps", {
1078
+ theme: Theme.LIGHT,
1079
+ onApply: noop,
1080
+ onChange: noop,
1081
+ onApplySuggestion: noop,
1082
+ onClear: noop,
1083
+ onFocusChange: noop,
1084
+ translations: {
1085
+ searchTitle: 'Search',
1086
+ clearTitle: 'Clear search input'
1087
+ }
1088
+ });
1089
+
1090
+ _defineProperty(QueryAssist, "ngModelStateField", ngModelStateField);
1091
+
1092
+ _defineProperty(QueryAssist, "Theme", Theme);
1093
+
1094
+ const RerenderableQueryAssist = rerenderHOC(QueryAssist);
1095
+
1096
+ export { RerenderableQueryAssist, QueryAssist as default };