@jetbrains/ring-ui 5.0.155 → 5.0.157

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 (299) hide show
  1. package/components/checkbox/checkbox.css +1 -1
  2. package/components/global/variables_dark.css +2 -2
  3. package/components/radio/radio.css +1 -1
  4. package/dist/_helpers/_rollupPluginBabelHelpers.js +642 -1
  5. package/dist/_helpers/anchor.js +6 -7
  6. package/dist/_helpers/button__classes.js +16 -28
  7. package/dist/_helpers/card.js +107 -95
  8. package/dist/_helpers/dialog__body-scroll-preventer.js +20 -11
  9. package/dist/_helpers/footer.js +29 -34
  10. package/dist/_helpers/query-assist__suggestions.js +91 -74
  11. package/dist/_helpers/select__filter.js +71 -48
  12. package/dist/_helpers/services-link.js +41 -29
  13. package/dist/_helpers/sidebar.js +103 -99
  14. package/dist/_helpers/theme.js +42 -35
  15. package/dist/_helpers/title.js +71 -57
  16. package/dist/alert/alert.js +199 -158
  17. package/dist/alert/container.js +43 -32
  18. package/dist/alert-service/alert-service.js +172 -104
  19. package/dist/analytics/analytics.js +92 -68
  20. package/dist/analytics/analytics__custom-plugin.js +84 -60
  21. package/dist/analytics/analytics__fus-plugin.js +28 -15
  22. package/dist/analytics/analytics__ga-plugin.js +60 -43
  23. package/dist/analytics/analytics__plugin-utils.js +28 -22
  24. package/dist/auth/auth.js +36 -4
  25. package/dist/auth/auth__core.js +1458 -732
  26. package/dist/auth/background-flow.js +129 -87
  27. package/dist/auth/down-notification.js +75 -30
  28. package/dist/auth/iframe-flow.js +136 -75
  29. package/dist/auth/landing.js +90 -30
  30. package/dist/auth/request-builder.js +82 -46
  31. package/dist/auth/response-parser.js +119 -86
  32. package/dist/auth/storage.js +333 -171
  33. package/dist/auth/token-validator.js +244 -137
  34. package/dist/auth/window-flow.js +136 -92
  35. package/dist/auth-dialog/auth-dialog.js +176 -114
  36. package/dist/auth-dialog-service/auth-dialog-service.js +32 -7
  37. package/dist/auth-ng/auth-ng.js +70 -34
  38. package/dist/auth-ng/auth-ng.mock.js +6 -6
  39. package/dist/autofocus-ng/autofocus-ng.js +23 -8
  40. package/dist/avatar/avatar-example-datauri.js +1 -23
  41. package/dist/avatar/avatar.js +155 -119
  42. package/dist/avatar/fallback-avatar.js +41 -22
  43. package/dist/avatar-editor-ng/avatar-editor-ng.js +56 -23
  44. package/dist/avatar-editor-ng/avatar-editor-ng__template.js +1 -28
  45. package/dist/avatar-ng/avatar-ng.js +23 -1
  46. package/dist/badge/badge.js +43 -35
  47. package/dist/badge-ng/badge-ng.js +13 -1
  48. package/dist/breadcrumb-ng/breadcrumb-ng.js +15 -29
  49. package/dist/button/button.js +111 -87
  50. package/dist/button/button__classes.js +1 -0
  51. package/dist/button-group/button-group.js +35 -19
  52. package/dist/button-group/caption.js +22 -14
  53. package/dist/button-group-ng/button-group-ng.js +13 -7
  54. package/dist/button-ng/button-ng.js +154 -133
  55. package/dist/button-set/button-set.js +34 -20
  56. package/dist/button-set-ng/button-set-ng.js +2 -2
  57. package/dist/button-toolbar/button-toolbar.js +33 -19
  58. package/dist/button-toolbar-ng/button-toolbar-ng.js +5 -3
  59. package/dist/caret/caret.js +225 -188
  60. package/dist/checkbox/checkbox.js +104 -76
  61. package/dist/checkbox-ng/checkbox-ng.js +18 -27
  62. package/dist/clipboard/clipboard-fallback.js +10 -10
  63. package/dist/clipboard/clipboard.js +131 -34
  64. package/dist/code/code.js +168 -92
  65. package/dist/compiler-ng/compiler-ng.js +18 -15
  66. package/dist/confirm/confirm.js +108 -66
  67. package/dist/confirm-ng/confirm-ng.js +33 -4
  68. package/dist/confirm-service/confirm-service.js +66 -42
  69. package/dist/content-layout/content-layout.js +64 -43
  70. package/dist/content-layout/sidebar.js +1 -0
  71. package/dist/contenteditable/contenteditable.js +61 -50
  72. package/dist/control-label/control-label.js +11 -15
  73. package/dist/data-list/data-list.js +184 -128
  74. package/dist/data-list/data-list.mock.js +11 -2
  75. package/dist/data-list/item.js +174 -143
  76. package/dist/data-list/selection.js +139 -76
  77. package/dist/data-list/title.js +13 -1
  78. package/dist/data-list-ng/data-list-ng.js +31 -1
  79. package/dist/date-picker/consts.js +18 -15
  80. package/dist/date-picker/date-input.js +147 -115
  81. package/dist/date-picker/date-picker.js +285 -228
  82. package/dist/date-picker/date-popup.js +397 -356
  83. package/dist/date-picker/day.js +98 -84
  84. package/dist/date-picker/month-names.js +64 -43
  85. package/dist/date-picker/month-slider.js +74 -51
  86. package/dist/date-picker/month.js +21 -15
  87. package/dist/date-picker/months.js +48 -43
  88. package/dist/date-picker/weekdays.js +18 -12
  89. package/dist/date-picker/years.js +109 -84
  90. package/dist/dialog/dialog.js +189 -141
  91. package/dist/dialog/dialog__body-scroll-preventer.js +5 -0
  92. package/dist/dialog-ng/dialog-ng.js +401 -287
  93. package/dist/dialog-ng/dialog-ng__template.js +1 -70
  94. package/dist/docked-panel-ng/docked-panel-ng.js +33 -18
  95. package/dist/dropdown/anchor.js +10 -0
  96. package/dist/dropdown/dropdown.js +214 -182
  97. package/dist/dropdown-menu/dropdown-menu.js +102 -72
  98. package/dist/editable-heading/editable-heading.js +100 -58
  99. package/dist/error-bubble/error-bubble.js +64 -31
  100. package/dist/error-message/error-message.js +61 -38
  101. package/dist/error-message-ng/error-message-ng.js +11 -22
  102. package/dist/footer/footer.js +11 -1
  103. package/dist/footer-ng/footer-ng.js +64 -36
  104. package/dist/form-ng/form-ng.js +66 -56
  105. package/dist/global/angular-component-factory.js +76 -53
  106. package/dist/global/compose.js +10 -1
  107. package/dist/global/composeRefs.js +12 -7
  108. package/dist/global/controls-height.js +2 -2
  109. package/dist/global/create-stateful-context.js +19 -19
  110. package/dist/global/data-tests.js +15 -7
  111. package/dist/global/dom.js +95 -53
  112. package/dist/global/focus-sensor-hoc.js +134 -122
  113. package/dist/global/fuzzy-highlight.js +41 -27
  114. package/dist/global/get-event-key.js +8 -8
  115. package/dist/global/get-uid.js +8 -4
  116. package/dist/global/inject-styles.js +15 -10
  117. package/dist/global/linear-function.js +2 -2
  118. package/dist/global/listeners.js +53 -27
  119. package/dist/global/memoize.js +13 -6
  120. package/dist/global/normalize-indent.js +51 -19
  121. package/dist/global/promise-with-timeout.js +8 -6
  122. package/dist/global/prop-types.js +5 -3
  123. package/dist/global/react-dom-renderer.js +47 -28
  124. package/dist/global/react-render-adapter.js +19 -13
  125. package/dist/global/rerender-hoc.js +41 -16
  126. package/dist/global/ring-angular-component.js +20 -10
  127. package/dist/global/schedule-raf.js +6 -5
  128. package/dist/global/sniffer.js +1 -1
  129. package/dist/global/theme.js +24 -0
  130. package/dist/global/trivial-template-tag.js +10 -3
  131. package/dist/global/typescript-utils.js +6 -2
  132. package/dist/global/url.js +27 -21
  133. package/dist/global/use-event-callback.js +4 -6
  134. package/dist/grid/col.js +55 -35
  135. package/dist/grid/grid.js +36 -17
  136. package/dist/grid/row.js +48 -35
  137. package/dist/group/group.js +27 -17
  138. package/dist/group-ng/group-ng.js +2 -2
  139. package/dist/header/header.js +80 -33
  140. package/dist/header/logo.js +39 -20
  141. package/dist/header/profile.js +188 -150
  142. package/dist/header/services-link.js +9 -0
  143. package/dist/header/services.js +118 -73
  144. package/dist/header/smart-profile.js +207 -111
  145. package/dist/header/smart-services.js +115 -62
  146. package/dist/header/tray-icon.js +38 -21
  147. package/dist/header/tray.js +34 -21
  148. package/dist/heading/heading.js +25 -26
  149. package/dist/heading-ng/heading-ng.js +11 -1
  150. package/dist/http/http.js +368 -215
  151. package/dist/http/http.mock.js +104 -49
  152. package/dist/hub-source/hub-source.js +191 -83
  153. package/dist/hub-source/hub-source__user.js +45 -11
  154. package/dist/hub-source/hub-source__users-groups.js +67 -37
  155. package/dist/i18n/i18n-context.js +14 -10
  156. package/dist/i18n/i18n.js +11 -7
  157. package/dist/icon/icon.js +94 -76
  158. package/dist/icon/icon__svg.js +31 -24
  159. package/dist/icon/index.js +9 -0
  160. package/dist/icon-ng/icon-ng.js +27 -15
  161. package/dist/input/input.js +184 -145
  162. package/dist/input-ng/input-ng.js +96 -118
  163. package/dist/island/adaptive-island-hoc.js +45 -30
  164. package/dist/island/content.js +130 -115
  165. package/dist/island/header.js +69 -56
  166. package/dist/island/island.js +40 -28
  167. package/dist/island-legacy/content-legacy.js +27 -17
  168. package/dist/island-legacy/header-legacy.js +29 -19
  169. package/dist/island-legacy/island-legacy.js +27 -17
  170. package/dist/island-ng/island-content-ng.js +17 -26
  171. package/dist/island-ng/island-header-ng.js +9 -12
  172. package/dist/island-ng/island-ng-class-fixer.js +3 -0
  173. package/dist/island-ng/island-ng.js +6 -10
  174. package/dist/link/clickableLink.js +61 -44
  175. package/dist/link/link.js +85 -74
  176. package/dist/link-ng/link-ng.js +3 -5
  177. package/dist/list/consts.js +1 -1
  178. package/dist/list/list.js +696 -602
  179. package/dist/list/list__custom.js +61 -44
  180. package/dist/list/list__hint.js +21 -10
  181. package/dist/list/list__item.js +167 -129
  182. package/dist/list/list__link.js +54 -37
  183. package/dist/list/list__separator.js +24 -14
  184. package/dist/list/list__title.js +32 -22
  185. package/dist/list/list__users-groups-source.js +131 -54
  186. package/dist/loader/loader.js +78 -43
  187. package/dist/loader/loader__core.js +257 -189
  188. package/dist/loader-inline/loader-inline.js +37 -23
  189. package/dist/loader-inline-ng/loader-inline-ng.js +2 -2
  190. package/dist/loader-ng/loader-ng.js +46 -19
  191. package/dist/loader-screen/loader-screen.js +48 -25
  192. package/dist/loader-screen-ng/loader-screen-ng.js +46 -30
  193. package/dist/login-dialog/login-dialog.js +162 -111
  194. package/dist/login-dialog/service.js +35 -7
  195. package/dist/markdown/code.js +31 -9
  196. package/dist/markdown/heading.js +3 -5
  197. package/dist/markdown/link.js +13 -6
  198. package/dist/markdown/markdown.js +66 -33
  199. package/dist/message/message.js +157 -125
  200. package/dist/message-bundle-ng/message-bundle-ng.js +128 -44
  201. package/dist/old-browsers-message/old-browsers-message.js +19 -11
  202. package/dist/old-browsers-message/old-browsers-message__stop.js +8 -0
  203. package/dist/old-browsers-message/white-list.js +16 -9
  204. package/dist/pager/pager.js +275 -210
  205. package/dist/pager-ng/pager-ng.js +36 -1
  206. package/dist/panel/panel.js +27 -17
  207. package/dist/panel-ng/panel-ng.js +14 -1
  208. package/dist/permissions/permissions.js +173 -127
  209. package/dist/permissions/permissions__cache.js +225 -194
  210. package/dist/permissions-ng/permissions-ng.js +86 -35
  211. package/dist/place-under-ng/place-under-ng.js +68 -45
  212. package/dist/popup/popup.consts.js +1 -1
  213. package/dist/popup/popup.js +342 -280
  214. package/dist/popup/popup.target.js +8 -9
  215. package/dist/popup/position.js +153 -153
  216. package/dist/popup-menu/popup-menu.js +86 -44
  217. package/dist/progress-bar/progress-bar.js +97 -80
  218. package/dist/progress-bar-ng/progress-bar-ng.js +11 -1
  219. package/dist/promised-click-ng/promised-click-ng.js +92 -58
  220. package/dist/proxy-attrs/proxy-attrs.js +18 -9
  221. package/dist/query-assist/query-assist.js +903 -832
  222. package/dist/query-assist/query-assist__suggestions.js +33 -1
  223. package/dist/query-assist-ng/query-assist-ng.js +38 -1
  224. package/dist/radio/radio.js +36 -19
  225. package/dist/radio/radio__item.js +71 -52
  226. package/dist/radio-ng/radio-ng.js +14 -25
  227. package/dist/save-field-ng/save-field-ng.js +86 -52
  228. package/dist/save-field-ng/save-field-ng__template.js +1 -32
  229. package/dist/select/select.js +937 -835
  230. package/dist/select/select__filter.js +33 -0
  231. package/dist/select/select__popup.js +472 -359
  232. package/dist/select-ng/select-ng.js +125 -74
  233. package/dist/select-ng/select-ng__lazy.js +101 -50
  234. package/dist/select-ng/select-ng__options.js +107 -81
  235. package/dist/shortcuts/core.js +218 -166
  236. package/dist/shortcuts/shortcut-title.js +11 -6
  237. package/dist/shortcuts/shortcuts-hoc.js +47 -19
  238. package/dist/shortcuts/shortcuts.js +77 -50
  239. package/dist/shortcuts-hint-ng/shortcuts-hint-ng.js +104 -53
  240. package/dist/shortcuts-hint-ng/shortcuts-hint-ng__template.js +1 -48
  241. package/dist/shortcuts-ng/shortcuts-ng.js +86 -51
  242. package/dist/sidebar-ng/sidebar-ng.js +53 -22
  243. package/dist/sidebar-ng/sidebar-ng__button-template.js +1 -18
  244. package/dist/sidebar-ng/sidebar-ng__template.js +1 -10
  245. package/dist/storage/storage.js +35 -4
  246. package/dist/storage/storage__fallback.js +224 -149
  247. package/dist/storage/storage__local.js +156 -90
  248. package/dist/style.css +1 -1
  249. package/dist/tab-trap/tab-trap.js +157 -122
  250. package/dist/table/cell.js +28 -14
  251. package/dist/table/disable-hover-hoc.js +53 -33
  252. package/dist/table/header-cell.js +87 -64
  253. package/dist/table/header.js +126 -98
  254. package/dist/table/multitable.js +127 -107
  255. package/dist/table/row-with-focus-sensor.js +73 -25
  256. package/dist/table/row.js +208 -170
  257. package/dist/table/selection-adapter.js +3 -1
  258. package/dist/table/selection-shortcuts-hoc.js +184 -181
  259. package/dist/table/selection.js +228 -156
  260. package/dist/table/smart-table.js +93 -51
  261. package/dist/table/table.js +348 -281
  262. package/dist/table-legacy-ng/table-legacy-ng.js +117 -102
  263. package/dist/table-legacy-ng/table-legacy-ng__pager.js +42 -10
  264. package/dist/table-legacy-ng/table-legacy-ng__selection-navigate-actions.js +92 -69
  265. package/dist/table-legacy-ng/table-legacy-ng__selection.js +169 -119
  266. package/dist/table-legacy-ng/table-legacy-ng__toolbar.js +36 -21
  267. package/dist/table-ng/smart-table-ng.js +31 -1
  268. package/dist/table-ng/table-ng.js +31 -1
  269. package/dist/tabs/collapsible-more.js +87 -50
  270. package/dist/tabs/collapsible-tab.js +45 -38
  271. package/dist/tabs/collapsible-tabs.js +161 -94
  272. package/dist/tabs/custom-item.js +2 -4
  273. package/dist/tabs/dumb-tabs.js +122 -75
  274. package/dist/tabs/smart-tabs.js +75 -29
  275. package/dist/tabs/tab-link.js +29 -19
  276. package/dist/tabs/tab.js +33 -19
  277. package/dist/tabs/tabs.js +35 -0
  278. package/dist/tabs-ng/tabs-ng.js +38 -24
  279. package/dist/tabs-ng/tabs-ng__template.js +1 -38
  280. package/dist/tag/tag.js +170 -133
  281. package/dist/tags-input/tags-input.js +428 -327
  282. package/dist/tags-input-ng/tags-input-ng.js +37 -1
  283. package/dist/tags-list/tags-list.js +80 -56
  284. package/dist/template-ng/template-ng.js +50 -39
  285. package/dist/text/text.js +38 -28
  286. package/dist/title-ng/title-ng.js +28 -23
  287. package/dist/toggle/toggle.js +72 -56
  288. package/dist/toggle-ng/toggle-ng.js +14 -1
  289. package/dist/tooltip/tooltip.js +192 -146
  290. package/dist/tooltip-ng/tooltip-ng.js +51 -25
  291. package/dist/user-agreement/service.js +374 -227
  292. package/dist/user-agreement/toolbox.eula.js +1 -160
  293. package/dist/user-agreement/user-agreement.js +128 -86
  294. package/dist/user-card/card.js +32 -0
  295. package/dist/user-card/smart-user-card-tooltip.js +116 -51
  296. package/dist/user-card/tooltip.js +90 -48
  297. package/dist/user-card/user-card.js +32 -0
  298. package/dist/user-card-ng/user-card-ng.js +34 -2
  299. package/package.json +13 -13
@@ -1,5 +1,20 @@
1
- import { _ as _extends } from '../_helpers/_rollupPluginBabelHelpers.js';
2
- import React, { Component, Fragment } from 'react';
1
+ import { c as _defineProperty, j as _inherits, k as _createSuper, b as _classCallCheck, d as _typeof, m as _assertThisInitialized, a as _objectSpread2, h as _objectWithoutProperties, q as _toPropertyKey, _ as _createClass, i as _extends } from '../_helpers/_rollupPluginBabelHelpers.js';
2
+ import 'core-js/modules/es.array.index-of.js';
3
+ import 'core-js/modules/es.array.reduce.js';
4
+ import 'core-js/modules/es.object.to-string.js';
5
+ import 'core-js/modules/es.string.trim.js';
6
+ import 'core-js/modules/es.array.filter.js';
7
+ import 'core-js/modules/es.regexp.exec.js';
8
+ import 'core-js/modules/es.array.find.js';
9
+ import 'core-js/modules/es.array.concat.js';
10
+ import 'core-js/modules/es.string.replace.js';
11
+ import 'core-js/modules/es.array.map.js';
12
+ import 'core-js/modules/web.dom-collections.for-each.js';
13
+ import 'core-js/modules/es.array.slice.js';
14
+ import 'core-js/modules/es.object.keys.js';
15
+ import 'core-js/modules/es.object.assign.js';
16
+ import 'core-js/modules/es.object.values.js';
17
+ import React, { Fragment, Component } from 'react';
3
18
  import classNames from 'classnames';
4
19
  import PropTypes from 'prop-types';
5
20
  import chevronDownIcon from '@jetbrains/icons/chevron-down';
@@ -20,31 +35,51 @@ import fuzzyHighlight from '../global/fuzzy-highlight.js';
20
35
  import memoize from '../global/memoize.js';
21
36
  import { I18nContext } from '../i18n/i18n-context.js';
22
37
  import { isArray } from '../global/typescript-utils.js';
23
- import { ControlsHeightContext, ControlsHeight } from '../global/controls-height.js';
38
+ import { ControlsHeight, ControlsHeightContext } from '../global/controls-height.js';
24
39
  import { m as modules_88cfaf40 } from '../_helpers/input.js';
25
40
  import SelectPopup from './select__popup.js';
26
41
  import { A as Anchor } from '../_helpers/anchor.js';
42
+ import 'core-js/modules/es.object.entries.js';
27
43
  import '@jetbrains/icons/chevron-10px';
28
44
  import '../icon/icon.js';
29
45
  import 'util-deprecate';
30
46
  import '../icon/icon__constants.js';
31
47
  import '../_helpers/icon.js';
32
48
  import '../icon/icon__svg.js';
49
+ import 'core-js/modules/es.string.starts-with.js';
50
+ import 'core-js/modules/es.array.iterator.js';
51
+ import 'core-js/modules/es.map.js';
52
+ import 'core-js/modules/es.string.iterator.js';
53
+ import 'core-js/modules/web.dom-collections.iterator.js';
54
+ import 'core-js/modules/es.weak-map.js';
33
55
  import '../link/clickableLink.js';
34
56
  import '../_helpers/button__classes.js';
35
57
  import '../global/url.js';
58
+ import 'core-js/modules/es.string.match.js';
36
59
  import '../global/dom.js';
60
+ import 'core-js/modules/es.string.split.js';
61
+ import 'core-js/modules/es.set.js';
37
62
  import '../avatar/fallback-avatar.js';
63
+ import 'core-js/modules/es.number.constructor.js';
64
+ import 'core-js/modules/es.array.from.js';
65
+ import 'core-js/modules/es.regexp.to-string.js';
38
66
  import 'react-dom';
39
67
  import '../global/schedule-raf.js';
40
68
  import '../tab-trap/tab-trap.js';
41
69
  import '../popup/position.js';
70
+ import 'core-js/modules/es.array.includes.js';
71
+ import 'core-js/modules/es.string.includes.js';
72
+ import 'core-js/modules/es.array.sort.js';
42
73
  import '../popup/popup.consts.js';
43
74
  import '../popup/popup.target.js';
44
75
  import '../shortcuts/core.js';
76
+ import 'core-js/modules/es.array.splice.js';
77
+ import 'core-js/modules/es.array.find-index.js';
45
78
  import 'combokeys';
46
79
  import '../global/sniffer.js';
47
80
  import 'sniffr';
81
+ import 'core-js/modules/es.symbol.js';
82
+ import 'core-js/modules/es.symbol.description.js';
48
83
  import 'react-virtualized/dist/es/List';
49
84
  import 'react-virtualized/dist/es/AutoSizer';
50
85
  import 'react-virtualized/dist/es/WindowScroller';
@@ -98,12 +133,16 @@ var Type;
98
133
  Type["INLINE"] = "INLINE";
99
134
  Type["INPUT_WITHOUT_CONTROLS"] = "INPUT_WITHOUT_CONTROLS";
100
135
  })(Type || (Type = {}));
101
- const ICONS_OFFSET = 5;
102
- const ICON_WIDTH = 20;
103
- const getStyle = memoize(iconsLength => ({
104
- paddingRight: ICONS_OFFSET + iconsLength * ICON_WIDTH
105
- }));
106
- const isInputMode = type => type === Type.INPUT || type === Type.INPUT_WITHOUT_CONTROLS;
136
+ var ICONS_OFFSET = 5;
137
+ var ICON_WIDTH = 20;
138
+ var getStyle = memoize(function (iconsLength) {
139
+ return {
140
+ paddingRight: ICONS_OFFSET + iconsLength * ICON_WIDTH
141
+ };
142
+ });
143
+ var _isInputMode = function isInputMode(type) {
144
+ return type === Type.INPUT || type === Type.INPUT_WITHOUT_CONTROLS;
145
+ };
107
146
  function getLowerCaseLabel(item) {
108
147
  if (List.isItemType(List.ListProps.Type.SEPARATOR, item) || List.isItemType(List.ListProps.Type.HINT, item) || typeof item.label !== 'string') {
109
148
  return null;
@@ -111,66 +150,77 @@ function getLowerCaseLabel(item) {
111
150
  return item.label.toLowerCase();
112
151
  }
113
152
  function doesLabelMatch(itemToCheck, fn) {
114
- const lowerCaseLabel = getLowerCaseLabel(itemToCheck);
153
+ var lowerCaseLabel = getLowerCaseLabel(itemToCheck);
115
154
  if (lowerCaseLabel == null) {
116
155
  return true;
117
156
  }
118
157
  return fn(lowerCaseLabel);
119
158
  }
120
- function getFilterFn(filter) {
121
- if (typeof filter === 'object') {
159
+ function _getFilterFn(filter) {
160
+ if (_typeof(filter) === 'object') {
122
161
  if (filter.fn) {
123
162
  return filter.fn;
124
163
  }
125
164
  if (filter.fuzzy) {
126
- return (itemToCheck, checkString) => doesLabelMatch(itemToCheck, lowerCaseLabel => fuzzyHighlight(checkString, lowerCaseLabel).matched);
165
+ return function (itemToCheck, checkString) {
166
+ return doesLabelMatch(itemToCheck, function (lowerCaseLabel) {
167
+ return fuzzyHighlight(checkString, lowerCaseLabel).matched;
168
+ });
169
+ };
127
170
  }
128
171
  }
129
- return (itemToCheck, checkString) => doesLabelMatch(itemToCheck, lowerCaseLabel => lowerCaseLabel.indexOf(checkString) >= 0);
172
+ return function (itemToCheck, checkString) {
173
+ return doesLabelMatch(itemToCheck, function (lowerCaseLabel) {
174
+ return lowerCaseLabel.indexOf(checkString) >= 0;
175
+ });
176
+ };
130
177
  }
131
178
  function buildMultipleMap(selected) {
132
- return selected.reduce((acc, item) => {
179
+ return selected.reduce(function (acc, item) {
133
180
  acc[item.key] = true;
134
181
  return acc;
135
182
  }, {});
136
183
  }
137
- function getListItems(props, state, rawFilterString) {
138
- let data = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : props.data;
139
- let filterString = rawFilterString.trim();
140
- if (isInputMode(props.type) && !props.allowAny && state.selected && !Array.isArray(state.selected) && filterString === state.selected.label) {
184
+ function _getListItems(props, state, rawFilterString) {
185
+ var data = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : props.data;
186
+ var filterString = rawFilterString.trim();
187
+ if (_isInputMode(props.type) && !props.allowAny && state.selected && !Array.isArray(state.selected) && filterString === state.selected.label) {
141
188
  filterString = ''; // ignore multiple if it is exactly the selected item
142
189
  }
143
190
 
144
- const lowerCaseString = filterString.toLowerCase();
145
- const filteredData = [];
146
- let exactMatch = false;
147
- const check = getFilterFn(props.filter);
148
- for (let i = 0; i < data.length; i++) {
149
- const item = {
150
- ...data[i]
151
- };
191
+ var lowerCaseString = filterString.toLowerCase();
192
+ var filteredData = [];
193
+ var exactMatch = false;
194
+ var check = _getFilterFn(props.filter);
195
+ var _loop = function _loop() {
196
+ var item = _objectSpread2({}, data[i]);
152
197
  if (check(item, lowerCaseString, data)) {
198
+ var _state$multipleMap2;
153
199
  exactMatch = item.label === filterString;
154
- if (props.multiple && !(typeof props.multiple === 'object' && props.multiple.removeSelectedItems)) {
155
- item.checkbox = !!state.multipleMap?.[item.key];
200
+ if (props.multiple && !(_typeof(props.multiple) === 'object' && props.multiple.removeSelectedItems)) {
201
+ var _state$multipleMap;
202
+ item.checkbox = !!((_state$multipleMap = state.multipleMap) !== null && _state$multipleMap !== void 0 && _state$multipleMap[item.key]);
156
203
  }
157
- if (props.multiple && typeof props.multiple === 'object' && props.multiple.limit && Array.isArray(state.selected)) {
158
- item.disabled = props.multiple.limit === state.selected.length && !state.selected.find(selectedItem => selectedItem.key === item.key);
204
+ if (props.multiple && _typeof(props.multiple) === 'object' && props.multiple.limit && Array.isArray(state.selected)) {
205
+ item.disabled = props.multiple.limit === state.selected.length && !state.selected.find(function (selectedItem) {
206
+ return selectedItem.key === item.key;
207
+ });
159
208
  }
160
209
  // Ignore item if it's multiple and is already selected
161
- if (!(props.multiple && typeof props.multiple === 'object' && props.multiple.removeSelectedItems && state.multipleMap?.[item.key])) {
210
+ if (!(props.multiple && _typeof(props.multiple) === 'object' && props.multiple.removeSelectedItems && (_state$multipleMap2 = state.multipleMap) !== null && _state$multipleMap2 !== void 0 && _state$multipleMap2[item.key])) {
162
211
  filteredData.push(item);
163
212
  }
164
213
  }
214
+ };
215
+ for (var i = 0; i < data.length; i++) {
216
+ _loop();
165
217
  }
166
- let addButton = null;
167
- const {
168
- add
169
- } = props;
218
+ var addButton = null;
219
+ var add = props.add;
170
220
  if (add && filterString && !exactMatch || add && add.alwaysVisible) {
171
221
  if (!(add.regexp && !add.regexp.test(filterString)) && !(add.minlength && filterString.length < +add.minlength) || add.alwaysVisible) {
172
222
  var _add$delayed;
173
- let label;
223
+ var label;
174
224
  if (add.label) {
175
225
  label = typeof add.label === 'function' ? add.label(filterString) : add.label;
176
226
  } else {
@@ -178,23 +228,23 @@ function getListItems(props, state, rawFilterString) {
178
228
  }
179
229
  addButton = {
180
230
  prefix: add.prefix,
181
- label,
231
+ label: label,
182
232
  delayed: (_add$delayed = add.delayed) !== null && _add$delayed !== void 0 ? _add$delayed : true
183
233
  };
184
234
  }
185
235
  }
186
236
  return {
187
- filteredData,
188
- addButton
237
+ filteredData: filteredData,
238
+ addButton: addButton
189
239
  };
190
240
  }
191
241
  function getSelectedIndex(selected, data) {
192
- const firstSelected = Array.isArray(selected) ? selected[0] : selected;
242
+ var firstSelected = Array.isArray(selected) ? selected[0] : selected;
193
243
  if (firstSelected == null) {
194
244
  return null;
195
245
  }
196
- for (let i = 0; i < data.length; i++) {
197
- const item = data[i];
246
+ for (var i = 0; i < data.length; i++) {
247
+ var item = data[i];
198
248
  if (item.key === undefined) {
199
249
  continue;
200
250
  }
@@ -204,26 +254,28 @@ function getSelectedIndex(selected, data) {
204
254
  }
205
255
  return null;
206
256
  }
207
- const getItemLabel = _ref => {
208
- let {
209
- selectedLabel,
210
- label
211
- } = _ref;
257
+ var getItemLabel = function getItemLabel(_ref) {
258
+ var selectedLabel = _ref.selectedLabel,
259
+ label = _ref.label;
212
260
  if (selectedLabel != null) {
213
261
  return selectedLabel;
214
262
  }
215
263
  return typeof label === 'string' ? label : '';
216
264
  };
217
- const getValueForFilter = (selected, type, filterValue) => selected && !isArray(selected) && isInputMode(type) ? getItemLabel(selected) : filterValue;
265
+ var _getValueForFilter = function getValueForFilter(selected, type, filterValue) {
266
+ return selected && !isArray(selected) && _isInputMode(type) ? getItemLabel(selected) : filterValue;
267
+ };
218
268
  function isSameSelected(prevSelected, selected) {
219
269
  if (!prevSelected || !selected || prevSelected.length !== selected.length) {
220
270
  return false;
221
271
  }
222
- const keysMap = selected.reduce((result, item) => {
272
+ var keysMap = selected.reduce(function (result, item) {
223
273
  result[item.key] = true;
224
274
  return result;
225
275
  }, {});
226
- return prevSelected.every(it => keysMap[it.key]);
276
+ return prevSelected.every(function (it) {
277
+ return keysMap[it.key];
278
+ });
227
279
  }
228
280
  /**
229
281
  * @name Select
@@ -233,503 +285,181 @@ function isSameSelected(prevSelected, selected) {
233
285
  /**
234
286
  * Displays a select.
235
287
  */
236
- class Select extends Component {
237
- static defaultProps = {
238
- data: [],
239
- filter: false,
240
- multiple: false,
241
- clear: false,
242
- loading: false,
243
- disabled: false,
244
- type: Type.BUTTON,
245
- size: Size.M,
246
- targetElement: null,
247
- hideSelected: false,
248
- allowAny: false,
249
- hideArrow: false,
250
- showPopup: false,
251
- maxHeight: 600,
252
- directions: [Popup.PopupProps.Directions.BOTTOM_RIGHT, Popup.PopupProps.Directions.BOTTOM_LEFT, Popup.PopupProps.Directions.TOP_LEFT, Popup.PopupProps.Directions.TOP_RIGHT],
253
- selected: null,
254
- label: null,
255
- selectedLabel: null,
256
- inputPlaceholder: '',
257
- hint: null,
258
- shortcutsEnabled: false,
259
- onBeforeOpen: noop,
260
- onLoadMore: noop,
261
- onOpen: noop,
262
- onClose: noop,
263
- onFilter: noop,
264
- onFocus: noop,
265
- onBlur: noop,
266
- onKeyDown: noop,
267
- onSelect: noop,
268
- onDeselect: noop,
269
- onOutsideClick: noop,
270
- onChange: noop,
271
- onAdd: noop,
272
- onDone: noop,
273
- onReset: noop,
274
- tags: null,
275
- ringPopupTarget: null,
276
- dir: 'ltr'
277
- };
278
- static getDerivedStateFromProps(nextProps, prevState) {
279
- const {
280
- multiple,
281
- data,
282
- type
283
- } = nextProps;
284
- const {
285
- prevSelected,
286
- prevData,
287
- prevMultiple,
288
- filterValue
289
- } = prevState;
290
- const nextState = {
291
- prevData: data,
292
- prevSelected: nextProps.selected,
293
- prevMultiple: multiple
294
- };
295
- if ('data' in nextProps && data !== prevData) {
296
- const {
297
- filteredData,
298
- addButton
299
- } = getListItems(nextProps, prevState, filterValue, data);
300
- Object.assign(nextState, {
301
- shownData: filteredData,
302
- addButton
303
- });
304
- if (prevState.selected) {
305
- Object.assign(nextState, {
306
- selectedIndex: getSelectedIndex(prevState.selected, data),
307
- filterValue: getValueForFilter(prevState.selected, type, filterValue)
308
- });
309
- }
310
- }
311
- if ('selected' in nextProps && nextProps.selected !== prevSelected) {
312
- const selected = nextProps.selected || (multiple ? [] : null);
313
- const selectedIndex = getSelectedIndex(selected, data || prevData);
314
- Object.assign(nextState, {
315
- selected,
316
- filterValue: getValueForFilter(selected, type, filterValue)
317
- });
318
- if (!Array.isArray(prevSelected) || !Array.isArray(selected) || !isSameSelected(prevSelected, selected)) {
319
- Object.assign(nextState, {
320
- selectedIndex
321
- });
322
- }
323
- }
324
- if (prevMultiple !== multiple && !deepEqual(prevMultiple, multiple)) {
325
- nextState.selected = multiple ? [] : null;
326
- }
327
- if (multiple && !nextState.selected) {
328
- nextState.selected = prevState.selected;
329
- }
330
- const {
331
- selected
332
- } = {
333
- ...prevState,
334
- ...nextState
335
- };
336
- if (selected && Array.isArray(selected)) {
337
- nextState.multipleMap = buildMultipleMap(selected);
338
- const {
339
- filteredData,
340
- addButton
341
- } = getListItems(nextProps, nextState, filterValue, data);
342
- Object.assign(nextState, {
343
- shownData: filteredData,
344
- addButton
345
- });
288
+ var Select = /*#__PURE__*/function (_Component) {
289
+ _inherits(Select, _Component);
290
+ var _super = _createSuper(Select);
291
+ function Select() {
292
+ var _this;
293
+ _classCallCheck(this, Select);
294
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
295
+ args[_key] = arguments[_key];
346
296
  }
347
- return nextState;
348
- }
349
- state = {
350
- data: [],
351
- shownData: [],
352
- selected: this.props.multiple ? [] : null,
353
- selectedIndex: null,
354
- filterValue: this.props.filter && typeof this.props.filter === 'object' && this.props.filter.value || '',
355
- shortcutsEnabled: false,
356
- popupShortcuts: false,
357
- showPopup: this.props.showPopup,
358
- prevData: this.props.data,
359
- prevSelected: null,
360
- prevMultiple: this.props.multiple,
361
- multipleMap: {},
362
- addButton: null
363
- };
364
- componentDidUpdate(prevProps, prevState) {
365
- const {
366
- showPopup,
367
- selected
368
- } = this.state;
369
- const {
370
- onClose,
371
- onOpen,
372
- onChange,
373
- multiple
374
- } = this.props;
375
- if (prevState.showPopup && !showPopup) {
376
- onClose(selected);
377
- } else if (!prevState.showPopup && showPopup) {
378
- onOpen();
379
- }
380
- if (multiple !== prevProps.multiple && !deepEqual(multiple, prevProps.multiple)) {
381
- onChange(selected);
382
- }
383
- }
384
- static contextType = ControlsHeightContext;
385
- static Type = Type;
386
- static Size = Size;
387
- id = getUID('select-');
388
- shortcutsScope = this.id;
389
- listId = `${this.id}:list`;
390
- _focusHandler = e => {
391
- this.props.onFocus(e);
392
- this.setState({
393
- shortcutsEnabled: true,
394
- focused: true
297
+ _this = _super.call.apply(_super, [this].concat(args));
298
+ _defineProperty(_assertThisInitialized(_this), "state", {
299
+ data: [],
300
+ shownData: [],
301
+ selected: _this.props.multiple ? [] : null,
302
+ selectedIndex: null,
303
+ filterValue: _this.props.filter && _typeof(_this.props.filter) === 'object' && _this.props.filter.value || '',
304
+ shortcutsEnabled: false,
305
+ popupShortcuts: false,
306
+ showPopup: _this.props.showPopup,
307
+ prevData: _this.props.data,
308
+ prevSelected: null,
309
+ prevMultiple: _this.props.multiple,
310
+ multipleMap: {},
311
+ addButton: null
395
312
  });
396
- };
397
- _blurHandler = () => {
398
- this.props.onBlur();
399
- if (this._popup && this._popup.isVisible() && !this._popup.isClickingPopup) {
400
- window.setTimeout(() => {
401
- this.setState({
402
- showPopup: false
403
- });
404
- });
405
- }
406
- if (!this._popup?.isClickingPopup) {
407
- this.setState({
408
- shortcutsEnabled: false,
409
- focused: false
313
+ _defineProperty(_assertThisInitialized(_this), "id", getUID('select-'));
314
+ _defineProperty(_assertThisInitialized(_this), "shortcutsScope", _this.id);
315
+ _defineProperty(_assertThisInitialized(_this), "listId", "".concat(_this.id, ":list"));
316
+ _defineProperty(_assertThisInitialized(_this), "_focusHandler", function (e) {
317
+ _this.props.onFocus(e);
318
+ _this.setState({
319
+ shortcutsEnabled: true,
320
+ focused: true
410
321
  });
411
- }
412
- };
413
- node;
414
- nodeRef = el => {
415
- this.node = el;
416
- };
417
- _popup = null;
418
- onEmptyPopupEnter = () => {
419
- if (this.state.addButton) {
420
- this.addHandler();
421
- }
422
- };
423
- _onEnter = () => {
424
- if (this.state.addButton && this.state.shownData.length === 0) {
425
- this.addHandler();
426
- }
427
- this.props.onDone();
428
- if (!this._popup?.isVisible() && this.props.allowAny) {
429
- return true;
430
- }
431
- return undefined;
432
- };
433
- _onEsc = event => {
434
- if (!this._popup?.isVisible()) {
435
- return true;
436
- } else if (this.props.multiple || !this.props.getInitial) {
437
- return false;
438
- }
439
- const selected = {
440
- key: Math.random(),
441
- label: this.props.getInitial()
442
- };
443
- this.setState({
444
- selected,
445
- filterValue: this.getValueForFilter(selected)
446
- }, () => {
447
- this.props.onChange(selected, event);
448
- this.props.onReset();
449
322
  });
450
- return undefined;
451
- };
452
- _inputShortcutHandler = () => {
453
- if (this.state.focused && this._popup && !this._popup.isVisible()) {
454
- this._clickHandler();
455
- }
456
- };
457
- getValueForFilter(selected) {
458
- return getValueForFilter(selected, this.props.type, this.state.filterValue);
459
- }
460
- _getSelectedIndex(selected, data) {
461
- return getSelectedIndex(selected, data);
462
- }
463
- popupRef = el => {
464
- this._popup = el;
465
- };
466
- _getResetOption() {
467
- const isOptionsSelected = Array.isArray(this.state.selected) && this.state.selected.length;
468
- const reset = this.props.tags && typeof this.props.tags === 'object' ? this.props.tags.reset : null;
469
- if (!isOptionsSelected || !reset) {
470
- return null;
471
- }
472
- const resetHandler = (item, event) => {
473
- this.clear(event);
474
- this.clearFilter();
475
- this.props.onFilter('');
476
- this.setState(prevState => ({
477
- shownData: prevState.shownData.slice(reset.separator ? 2 : 1),
478
- multipleMap: {}
479
- }));
480
- this._redrawPopup();
481
- };
482
- return {
483
- isResetItem: true,
484
- separator: reset.separator,
485
- key: reset.label,
486
- rgItemType: List.ListProps.Type.CUSTOM,
487
- template: /*#__PURE__*/React.createElement(Button, {
488
- text: true,
489
- className: modules_9d0de074.button,
490
- "data-test": "ring-select-reset-tags-button",
491
- height: ControlsHeight.S
492
- }, reset.label),
493
- glyph: reset.glyph,
494
- onClick: resetHandler
495
- };
496
- }
497
- _prependResetOption(shownData) {
498
- const resetOption = this._getResetOption();
499
- if (resetOption) {
500
- const resetItems = [resetOption];
501
- if (resetOption.separator) {
502
- resetItems.push({
503
- rgItemType: List.ListProps.Type.SEPARATOR
323
+ _defineProperty(_assertThisInitialized(_this), "_blurHandler", function () {
324
+ var _this$_popup;
325
+ _this.props.onBlur();
326
+ if (_this._popup && _this._popup.isVisible() && !_this._popup.isClickingPopup) {
327
+ window.setTimeout(function () {
328
+ _this.setState({
329
+ showPopup: false
330
+ });
504
331
  });
505
332
  }
506
- return resetItems.concat(shownData);
507
- }
508
- return shownData;
509
- }
510
- _renderPopup() {
511
- const anchorElement = this.props.targetElement || this.node;
512
- const {
513
- showPopup,
514
- shownData
515
- } = this.state;
516
- const _shownData = this._prependResetOption(shownData);
517
- return /*#__PURE__*/React.createElement(I18nContext.Consumer, null, _ref2 => {
518
- let {
519
- translate
520
- } = _ref2;
521
- let message;
522
- if (this.props.loading) {
523
- var _this$props$loadingMe;
524
- message = (_this$props$loadingMe = this.props.loadingMessage) !== null && _this$props$loadingMe !== void 0 ? _this$props$loadingMe : translate('loading');
525
- } else if (!shownData.length) {
526
- var _this$props$notFoundM;
527
- message = (_this$props$notFoundM = this.props.notFoundMessage) !== null && _this$props$notFoundM !== void 0 ? _this$props$notFoundM : translate('noOptionsFound');
333
+ if (!((_this$_popup = _this._popup) !== null && _this$_popup !== void 0 && _this$_popup.isClickingPopup)) {
334
+ _this.setState({
335
+ shortcutsEnabled: false,
336
+ focused: false
337
+ });
528
338
  }
529
- return /*#__PURE__*/React.createElement(SelectPopup, {
530
- data: _shownData,
531
- message: message,
532
- toolbar: showPopup && this.getToolbar(),
533
- topbar: this.getTopbar(),
534
- loading: this.props.loading,
535
- activeIndex: this.state.selectedIndex,
536
- hidden: !showPopup,
537
- ref: this.popupRef,
538
- maxHeight: this.props.maxHeight,
539
- minWidth: this.props.minWidth,
540
- directions: this.props.directions,
541
- className: this.props.popupClassName,
542
- style: this.props.popupStyle,
543
- top: this.props.top,
544
- left: this.props.left,
545
- filter: this.isInputMode() ? false : this.props.filter // disable popup filter in INPUT mode
546
- ,
547
- multiple: this.props.multiple,
548
- filterValue: this.state.filterValue,
549
- anchorElement: anchorElement,
550
- onCloseAttempt: this._onCloseAttempt,
551
- onOutsideClick: this.props.onOutsideClick,
552
- onSelect: this._listSelectHandler,
553
- onSelectAll: this._listSelectAllHandler,
554
- onFilter: this._filterChangeHandler,
555
- onClear: this.clearFilter,
556
- onLoadMore: this.props.onLoadMore,
557
- isInputMode: this.isInputMode(),
558
- selected: this.state.selected,
559
- tags: this.props.tags,
560
- compact: this.props.compact,
561
- renderOptimization: this.props.renderOptimization,
562
- ringPopupTarget: this.props.ringPopupTarget,
563
- disableMoveOverflow: this.props.disableMoveOverflow,
564
- disableScrollToActive: this.props.disableScrollToActive,
565
- dir: this.props.dir,
566
- onEmptyPopupEnter: this.onEmptyPopupEnter,
567
- listId: this.listId
568
- });
569
339
  });
570
- }
571
- _showPopup() {
572
- if (!this.node) {
573
- return;
574
- }
575
- const shownData = this.getListItems(this.filterValue());
576
- this.setState({
577
- showPopup: true,
578
- shownData
340
+ _defineProperty(_assertThisInitialized(_this), "node", void 0);
341
+ _defineProperty(_assertThisInitialized(_this), "nodeRef", function (el) {
342
+ _this.node = el;
579
343
  });
580
- }
581
- _hidePopup(tryFocusAnchor) {
582
- if (this.node && this.state.showPopup) {
583
- this.setState(prevState => ({
584
- showPopup: false,
585
- filterValue: this.props.allowAny ? prevState.filterValue : ''
586
- }));
587
- if (tryFocusAnchor) {
588
- const focusableSelectExists = this.node && this.node.querySelector('[data-test~=ring-select__focus]');
589
- const restoreFocusNode = this.props.targetElement || focusableSelectExists;
590
- if (restoreFocusNode) {
591
- restoreFocusNode.focus();
592
- }
344
+ _defineProperty(_assertThisInitialized(_this), "_popup", null);
345
+ _defineProperty(_assertThisInitialized(_this), "onEmptyPopupEnter", function () {
346
+ if (_this.state.addButton) {
347
+ _this.addHandler();
593
348
  }
594
- }
595
- }
596
- addHandler = () => {
597
- const value = this.filterValue();
598
- this._hidePopup();
599
- this.props.onAdd(value);
600
- };
601
- getToolbar() {
602
- const {
603
- hint,
604
- renderBottomToolbar
605
- } = this.props;
606
- const {
607
- prefix,
608
- label,
609
- delayed
610
- } = this.state.addButton || {};
611
- const isToolbarHasElements = this.state.addButton || hint || renderBottomToolbar;
612
- if (!isToolbarHasElements) {
613
- return null;
614
- }
615
- return /*#__PURE__*/React.createElement("div", {
616
- className: classNames({
617
- [modules_9d0de074.toolbar]: Boolean(this.state.addButton || renderBottomToolbar)
618
- }),
619
- "data-test": "ring-select-toolbar"
620
- }, renderBottomToolbar && renderBottomToolbar(), this.state.addButton && /*#__PURE__*/React.createElement(Button, {
621
- text: true,
622
- delayed: delayed,
623
- className: classNames(modules_9d0de074.button, modules_9d0de074.buttonSpaced),
624
- onClick: this.addHandler,
625
- "data-test": "ring-select-toolbar-button"
626
- }, prefix ? `${prefix} ${label}` : label), hint && /*#__PURE__*/React.createElement(List.ListHint, {
627
- label: hint,
628
- "data-test": "ring-select-toolbar-hint"
629
- }));
630
- }
631
- getTopbar() {
632
- return this.props.renderTopToolbar?.();
633
- }
634
- getLowerCaseLabel = getLowerCaseLabel;
635
- doesLabelMatch = doesLabelMatch;
636
- getFilterFn() {
637
- return getFilterFn(this.props.filter);
638
- }
639
- getListItems(rawFilterString, data) {
640
- const {
641
- filteredData,
642
- addButton
643
- } = getListItems(this.props, this.state, rawFilterString, data);
644
- this.setState({
645
- addButton
646
349
  });
647
- return filteredData;
648
- }
649
- filterValue(setValue) {
650
- if (typeof setValue === 'string' || typeof setValue === 'number') {
651
- this.setState({
652
- filterValue: setValue
653
- });
350
+ _defineProperty(_assertThisInitialized(_this), "_onEnter", function () {
351
+ var _this$_popup2;
352
+ if (_this.state.addButton && _this.state.shownData.length === 0) {
353
+ _this.addHandler();
354
+ }
355
+ _this.props.onDone();
356
+ if (!((_this$_popup2 = _this._popup) !== null && _this$_popup2 !== void 0 && _this$_popup2.isVisible()) && _this.props.allowAny) {
357
+ return true;
358
+ }
654
359
  return undefined;
655
- } else {
656
- return this.state.filterValue;
657
- }
658
- }
659
- isInputMode() {
660
- return isInputMode(this.props.type);
661
- }
662
- _clickHandler = () => {
663
- if (!this.props.disabled) {
664
- if (this.state.showPopup) {
665
- this._hidePopup();
666
- } else {
667
- this.props.onBeforeOpen();
668
- this._showPopup();
360
+ });
361
+ _defineProperty(_assertThisInitialized(_this), "_onEsc", function (event) {
362
+ var _this$_popup3;
363
+ if (!((_this$_popup3 = _this._popup) !== null && _this$_popup3 !== void 0 && _this$_popup3.isVisible())) {
364
+ return true;
365
+ } else if (_this.props.multiple || !_this.props.getInitial) {
366
+ return false;
669
367
  }
670
- }
671
- };
672
- _openPopupIfClosed = () => {
673
- if (this.props.disabled || this.state.showPopup) {
674
- return;
675
- }
676
- this.props.onBeforeOpen();
677
- this._showPopup();
678
- };
679
- _filterChangeHandler = e => {
680
- this._setFilter(e.currentTarget.value, e);
681
- };
682
- _setFilter = (value, event) => {
683
- if (this.isInputMode() && !this.state.focused) {
684
- return;
685
- }
686
- if (value === this.state.filterValue) {
687
- return;
688
- }
689
- const filterValue = value.replace(/^\s+/g, '');
690
- this.props.onFilter(filterValue);
691
- if (this.props.allowAny) {
692
- const fakeSelected = {
368
+ var selected = {
693
369
  key: Math.random(),
694
- label: filterValue
370
+ label: _this.props.getInitial()
695
371
  };
696
- this.setState({
697
- selected: filterValue === '' ? null : fakeSelected,
698
- selectedIndex: null
699
- }, () => {
700
- this.props.onSelect(fakeSelected, event);
701
- this.props.onChange(fakeSelected, event);
372
+ _this.setState({
373
+ selected: selected,
374
+ filterValue: _this.getValueForFilter(selected)
375
+ }, function () {
376
+ _this.props.onChange(selected, event);
377
+ _this.props.onReset();
702
378
  });
703
- }
704
- !this._popup?.isVisible() && this.props.onBeforeOpen();
705
- this.setState({
706
- filterValue
707
- }, () => {
708
- this._showPopup();
379
+ return undefined;
709
380
  });
710
- };
711
- _rebuildMultipleMap(selected) {
712
- if (Array.isArray(selected)) {
713
- this.setState({
714
- multipleMap: buildMultipleMap(selected)
381
+ _defineProperty(_assertThisInitialized(_this), "_inputShortcutHandler", function () {
382
+ if (_this.state.focused && _this._popup && !_this._popup.isVisible()) {
383
+ _this._clickHandler();
384
+ }
385
+ });
386
+ _defineProperty(_assertThisInitialized(_this), "popupRef", function (el) {
387
+ _this._popup = el;
388
+ });
389
+ _defineProperty(_assertThisInitialized(_this), "addHandler", function () {
390
+ var value = _this.filterValue();
391
+ _this._hidePopup();
392
+ _this.props.onAdd(value);
393
+ });
394
+ _defineProperty(_assertThisInitialized(_this), "getLowerCaseLabel", getLowerCaseLabel);
395
+ _defineProperty(_assertThisInitialized(_this), "doesLabelMatch", doesLabelMatch);
396
+ _defineProperty(_assertThisInitialized(_this), "_clickHandler", function () {
397
+ if (!_this.props.disabled) {
398
+ if (_this.state.showPopup) {
399
+ _this._hidePopup();
400
+ } else {
401
+ _this.props.onBeforeOpen();
402
+ _this._showPopup();
403
+ }
404
+ }
405
+ });
406
+ _defineProperty(_assertThisInitialized(_this), "_openPopupIfClosed", function () {
407
+ if (_this.props.disabled || _this.state.showPopup) {
408
+ return;
409
+ }
410
+ _this.props.onBeforeOpen();
411
+ _this._showPopup();
412
+ });
413
+ _defineProperty(_assertThisInitialized(_this), "_filterChangeHandler", function (e) {
414
+ _this._setFilter(e.currentTarget.value, e);
415
+ });
416
+ _defineProperty(_assertThisInitialized(_this), "_setFilter", function (value, event) {
417
+ var _this$_popup4;
418
+ if (_this.isInputMode() && !_this.state.focused) {
419
+ return;
420
+ }
421
+ if (value === _this.state.filterValue) {
422
+ return;
423
+ }
424
+ var filterValue = value.replace(/^\s+/g, '');
425
+ _this.props.onFilter(filterValue);
426
+ if (_this.props.allowAny) {
427
+ var fakeSelected = {
428
+ key: Math.random(),
429
+ label: filterValue
430
+ };
431
+ _this.setState({
432
+ selected: filterValue === '' ? null : fakeSelected,
433
+ selectedIndex: null
434
+ }, function () {
435
+ _this.props.onSelect(fakeSelected, event);
436
+ _this.props.onChange(fakeSelected, event);
437
+ });
438
+ }
439
+ !((_this$_popup4 = _this._popup) !== null && _this$_popup4 !== void 0 && _this$_popup4.isVisible()) && _this.props.onBeforeOpen();
440
+ _this.setState({
441
+ filterValue: filterValue
442
+ }, function () {
443
+ _this._showPopup();
715
444
  });
716
- }
717
- }
718
- _redrawPopup = () => {
719
- if (this.props.multiple) {
720
- setTimeout(() => {
721
- this.isInputMode() && this.clearFilter();
722
- this._showPopup();
723
- }, 0);
724
- }
725
- };
726
- _listSelectHandler = (() => {
727
- var _this = this;
728
- return function (selected, event) {
729
- let opts = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
730
- const isItem = item => List.isItemType(List.ListProps.Type.ITEM, item);
731
- const isCustomItem = item => List.isItemType(List.ListProps.Type.CUSTOM, item);
732
- const isSelectItemEvent = event && (event.type === 'select' || event.type === 'keydown');
445
+ });
446
+ _defineProperty(_assertThisInitialized(_this), "_redrawPopup", function () {
447
+ if (_this.props.multiple) {
448
+ setTimeout(function () {
449
+ _this.isInputMode() && _this.clearFilter();
450
+ _this._showPopup();
451
+ }, 0);
452
+ }
453
+ });
454
+ _defineProperty(_assertThisInitialized(_this), "_listSelectHandler", function (selected, event) {
455
+ var opts = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
456
+ var isItem = function isItem(item) {
457
+ return List.isItemType(List.ListProps.Type.ITEM, item);
458
+ };
459
+ var isCustomItem = function isCustomItem(item) {
460
+ return List.isItemType(List.ListProps.Type.CUSTOM, item);
461
+ };
462
+ var isSelectItemEvent = event && (event.type === 'select' || event.type === 'keydown');
733
463
  if (isSelectItemEvent) {
734
464
  event.preventDefault();
735
465
  }
@@ -739,376 +469,748 @@ class Select extends Component {
739
469
  if (!_this.props.multiple) {
740
470
  _this._hidePopup(isSelectItemEvent);
741
471
  _this.setState({
742
- selected,
472
+ selected: selected,
743
473
  selectedIndex: _this._getSelectedIndex(selected, _this.props.data)
744
- }, () => {
745
- const newFilterValue = _this.isInputMode() && !_this.props.hideSelected ? getItemLabel(selected) : '';
474
+ }, function () {
475
+ var newFilterValue = _this.isInputMode() && !_this.props.hideSelected ? getItemLabel(selected) : '';
746
476
  _this.filterValue(newFilterValue);
747
477
  _this.props.onFilter(newFilterValue);
748
478
  _this.props.onSelect(selected, event);
749
479
  _this.props.onChange(selected, event);
750
480
  });
751
481
  } else {
752
- const {
753
- tryKeepOpen
754
- } = opts;
482
+ var tryKeepOpen = opts.tryKeepOpen;
755
483
  if (!tryKeepOpen) {
756
484
  _this._hidePopup(isSelectItemEvent);
757
485
  }
758
486
  if (selected.key == null) {
759
487
  throw new Error('Multiple selection requires each item to have the "key" property');
760
488
  }
761
- _this.setState(prevState => {
762
- const currentSelection = prevState.selected;
763
- let nextSelection;
489
+ _this.setState(function (prevState) {
490
+ var currentSelection = prevState.selected;
491
+ var nextSelection;
764
492
  if (!prevState.multipleMap[selected.key]) {
765
493
  nextSelection = currentSelection.concat(selected);
766
494
  _this.props.onSelect && _this.props.onSelect(selected, event);
767
495
  } else {
768
- nextSelection = currentSelection.filter(item => item.key !== selected.key);
496
+ nextSelection = currentSelection.filter(function (item) {
497
+ return item.key !== selected.key;
498
+ });
769
499
  _this.props.onDeselect && _this.props.onDeselect(selected);
770
500
  }
771
501
  _this.props.onChange(nextSelection, event);
772
- const nextState = {
502
+ var nextState = {
773
503
  selected: nextSelection,
774
504
  selectedIndex: _this._getSelectedIndex(selected, _this.props.data)
775
505
  };
776
- if (typeof _this.props.multiple === 'object' && _this.props.multiple.limit && nextSelection.length === _this.props.multiple.limit) {
777
- nextState.shownData = prevState.shownData.map(item => nextSelection.find(selectedItem => selectedItem.key === item.key) ? item : {
778
- ...item,
779
- disabled: true
506
+ if (_typeof(_this.props.multiple) === 'object' && _this.props.multiple.limit && nextSelection.length === _this.props.multiple.limit) {
507
+ nextState.shownData = prevState.shownData.map(function (item) {
508
+ return nextSelection.find(function (selectedItem) {
509
+ return selectedItem.key === item.key;
510
+ }) ? item : _objectSpread2(_objectSpread2({}, item), {}, {
511
+ disabled: true
512
+ });
780
513
  });
781
514
  }
782
515
  if (!prevState.multipleMap[selected.key]) {
783
- nextState.multipleMap = {
784
- ...prevState.multipleMap,
785
- [selected.key]: true
786
- };
516
+ nextState.multipleMap = _objectSpread2(_objectSpread2({}, prevState.multipleMap), {}, _defineProperty({}, selected.key, true));
787
517
  } else {
788
- const {
789
- [selected.key]: _,
790
- ...restMultipleMap
791
- } = prevState.multipleMap;
518
+ var _prevState$multipleMa = prevState.multipleMap,
519
+ _selected$key = selected.key;
520
+ _prevState$multipleMa[_selected$key];
521
+ var restMultipleMap = _objectWithoutProperties(_prevState$multipleMa, [_selected$key].map(_toPropertyKey));
792
522
  nextState.multipleMap = restMultipleMap;
793
523
  }
794
- return {
795
- ...prevState,
796
- ...nextState
797
- };
798
- }, () => {
524
+ return _objectSpread2(_objectSpread2({}, prevState), nextState);
525
+ }, function () {
799
526
  if (tryKeepOpen) {
800
527
  _this._redrawPopup();
801
528
  }
802
529
  });
803
530
  }
804
- };
805
- })();
806
- _listSelectAllHandler = (() => {
807
- var _this2 = this;
808
- return function () {
809
- let isSelectAll = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
810
- const isItem = item => List.isItemType(List.ListProps.Type.ITEM, item);
811
- const isCustomItem = item => List.isItemType(List.ListProps.Type.CUSTOM, item);
812
- _this2.setState(prevState => {
813
- const currentSelection = prevState.selected;
814
- let nextSelection;
531
+ });
532
+ _defineProperty(_assertThisInitialized(_this), "_listSelectAllHandler", function () {
533
+ var isSelectAll = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
534
+ var isItem = function isItem(item) {
535
+ return List.isItemType(List.ListProps.Type.ITEM, item);
536
+ };
537
+ var isCustomItem = function isCustomItem(item) {
538
+ return List.isItemType(List.ListProps.Type.CUSTOM, item);
539
+ };
540
+ _this.setState(function (prevState) {
541
+ var currentSelection = prevState.selected;
542
+ var nextSelection;
815
543
  if (isSelectAll) {
816
- nextSelection = _this2.props.data.filter(item => (isItem(item) || isCustomItem(item)) && !item.disabled);
817
- nextSelection.filter(item => !_this2.props.selected.find(selectedItem => item.key === selectedItem.key)).forEach(item => {
818
- _this2.props.onSelect && _this2.props.onSelect(item);
544
+ nextSelection = _this.props.data.filter(function (item) {
545
+ return (isItem(item) || isCustomItem(item)) && !item.disabled;
546
+ });
547
+ nextSelection.filter(function (item) {
548
+ return !_this.props.selected.find(function (selectedItem) {
549
+ return item.key === selectedItem.key;
550
+ });
551
+ }).forEach(function (item) {
552
+ _this.props.onSelect && _this.props.onSelect(item);
819
553
  });
820
554
  } else {
821
555
  nextSelection = [];
822
- currentSelection.forEach(item => {
823
- _this2.props.onDeselect && _this2.props.onDeselect(item);
556
+ currentSelection.forEach(function (item) {
557
+ _this.props.onDeselect && _this.props.onDeselect(item);
824
558
  });
825
559
  }
826
- _this2.props.onChange(nextSelection, event);
560
+ _this.props.onChange(nextSelection, event);
827
561
  return {
828
562
  filterValue: '',
829
563
  selected: nextSelection,
830
- selectedIndex: isSelectAll ? _this2._getSelectedIndex(nextSelection, _this2.props.data) : null,
831
- shownData: prevState.shownData.map(item => ({
832
- ...item,
833
- checkbox: isSelectAll
834
- })),
835
- multipleMap: isSelectAll ? buildMultipleMap(_this2.props.data.filter(item => !item.disabled)) : {}
564
+ selectedIndex: isSelectAll ? _this._getSelectedIndex(nextSelection, _this.props.data) : null,
565
+ shownData: prevState.shownData.map(function (item) {
566
+ return _objectSpread2(_objectSpread2({}, item), {}, {
567
+ checkbox: isSelectAll
568
+ });
569
+ }),
570
+ multipleMap: isSelectAll ? buildMultipleMap(_this.props.data.filter(function (item) {
571
+ return !item.disabled;
572
+ })) : {}
836
573
  };
837
- }, _this2._redrawPopup);
838
- };
839
- })();
840
- _onCloseAttempt = (event, isEsc) => {
841
- if (this.isInputMode()) {
842
- if (!this.props.allowAny) {
843
- if (this.props.hideSelected || !this.state.selected || this.props.multiple) {
844
- this.clearFilter();
845
- } else if (this.state.selected && !Array.isArray(this.state.selected)) {
846
- this.filterValue(getItemLabel(this.state.selected));
574
+ }, _this._redrawPopup);
575
+ });
576
+ _defineProperty(_assertThisInitialized(_this), "_onCloseAttempt", function (event, isEsc) {
577
+ if (_this.isInputMode()) {
578
+ if (!_this.props.allowAny) {
579
+ if (_this.props.hideSelected || !_this.state.selected || _this.props.multiple) {
580
+ _this.clearFilter();
581
+ } else if (_this.state.selected && !Array.isArray(_this.state.selected)) {
582
+ _this.filterValue(getItemLabel(_this.state.selected));
583
+ }
584
+ }
585
+ }
586
+ var isTagRemoved = _this.props.tags && event && event.target && event.target instanceof Element && event.target.matches('[data-test="ring-tag-remove"]');
587
+ if (!isTagRemoved) {
588
+ _this._hidePopup(isEsc);
589
+ }
590
+ });
591
+ _defineProperty(_assertThisInitialized(_this), "clearFilter", function (e) {
592
+ _this._setFilter('', e);
593
+ });
594
+ _defineProperty(_assertThisInitialized(_this), "clear", function (event) {
595
+ if (event) {
596
+ event.stopPropagation();
597
+ }
598
+ var empty = _this.props.multiple ? [] : null;
599
+ _this.setState({
600
+ selected: empty,
601
+ selectedIndex: null,
602
+ filterValue: ''
603
+ }, function () {
604
+ if (_this.props.onChange) {
605
+ _this.props.onChange(empty, event);
847
606
  }
607
+ });
608
+ return false;
609
+ });
610
+ _defineProperty(_assertThisInitialized(_this), "filter", void 0);
611
+ _defineProperty(_assertThisInitialized(_this), "filterRef", function (el) {
612
+ _this.filter = el;
613
+ });
614
+ return _this;
615
+ }
616
+ _createClass(Select, [{
617
+ key: "componentDidUpdate",
618
+ value: function componentDidUpdate(prevProps, prevState) {
619
+ var _this$state = this.state,
620
+ showPopup = _this$state.showPopup,
621
+ selected = _this$state.selected;
622
+ var _this$props = this.props,
623
+ onClose = _this$props.onClose,
624
+ onOpen = _this$props.onOpen,
625
+ onChange = _this$props.onChange,
626
+ multiple = _this$props.multiple;
627
+ if (prevState.showPopup && !showPopup) {
628
+ onClose(selected);
629
+ } else if (!prevState.showPopup && showPopup) {
630
+ onOpen();
631
+ }
632
+ if (multiple !== prevProps.multiple && !deepEqual(multiple, prevProps.multiple)) {
633
+ onChange(selected);
848
634
  }
849
635
  }
850
- const isTagRemoved = this.props.tags && event && event.target && event.target instanceof Element && event.target.matches('[data-test="ring-tag-remove"]');
851
- if (!isTagRemoved) {
852
- this._hidePopup(isEsc);
636
+ }, {
637
+ key: "getValueForFilter",
638
+ value: function getValueForFilter(selected) {
639
+ return _getValueForFilter(selected, this.props.type, this.state.filterValue);
853
640
  }
854
- };
855
- clearFilter = e => {
856
- this._setFilter('', e);
857
- };
858
- clear = event => {
859
- if (event) {
860
- event.stopPropagation();
641
+ }, {
642
+ key: "_getSelectedIndex",
643
+ value: function _getSelectedIndex(selected, data) {
644
+ return getSelectedIndex(selected, data);
861
645
  }
862
- const empty = this.props.multiple ? [] : null;
863
- this.setState({
864
- selected: empty,
865
- selectedIndex: null,
866
- filterValue: ''
867
- }, () => {
868
- if (this.props.onChange) {
869
- this.props.onChange(empty, event);
646
+ }, {
647
+ key: "_getResetOption",
648
+ value: function _getResetOption() {
649
+ var _this2 = this;
650
+ var isOptionsSelected = Array.isArray(this.state.selected) && this.state.selected.length;
651
+ var reset = this.props.tags && _typeof(this.props.tags) === 'object' ? this.props.tags.reset : null;
652
+ if (!isOptionsSelected || !reset) {
653
+ return null;
870
654
  }
871
- });
872
- return false;
873
- };
874
- _selectionIsEmpty() {
875
- return Array.isArray(this.state.selected) && !this.state.selected.length || !this.state.selected;
876
- }
877
- _getLabel() {
878
- var _ref3, _this$props$label;
879
- return (_ref3 = (_this$props$label = this.props.label) !== null && _this$props$label !== void 0 ? _this$props$label : this.props.selectedLabel) !== null && _ref3 !== void 0 ? _ref3 : 'Select an option';
880
- }
881
- _getPlaceholder() {
882
- if (this._selectionIsEmpty()) {
883
- var _this$props$label2;
884
- return (_this$props$label2 = this.props.label) !== null && _this$props$label2 !== void 0 ? _this$props$label2 : 'Select an option';
655
+ var resetHandler = function resetHandler(item, event) {
656
+ _this2.clear(event);
657
+ _this2.clearFilter();
658
+ _this2.props.onFilter('');
659
+ _this2.setState(function (prevState) {
660
+ return {
661
+ shownData: prevState.shownData.slice(reset.separator ? 2 : 1),
662
+ multipleMap: {}
663
+ };
664
+ });
665
+ _this2._redrawPopup();
666
+ };
667
+ return {
668
+ isResetItem: true,
669
+ separator: reset.separator,
670
+ key: reset.label,
671
+ rgItemType: List.ListProps.Type.CUSTOM,
672
+ template: /*#__PURE__*/React.createElement(Button, {
673
+ text: true,
674
+ className: modules_9d0de074.button,
675
+ "data-test": "ring-select-reset-tags-button",
676
+ height: ControlsHeight.S
677
+ }, reset.label),
678
+ glyph: reset.glyph,
679
+ onClick: resetHandler
680
+ };
885
681
  }
886
- return this._getSelectedString();
887
- }
888
- _getSelectedString() {
889
- if (Array.isArray(this.state.selected)) {
890
- const labels = [];
891
- for (let i = 0; i < this.state.selected.length; i++) {
892
- labels.push(getItemLabel(this.state.selected[i]));
682
+ }, {
683
+ key: "_prependResetOption",
684
+ value: function _prependResetOption(shownData) {
685
+ var resetOption = this._getResetOption();
686
+ if (resetOption) {
687
+ var resetItems = [resetOption];
688
+ if (resetOption.separator) {
689
+ resetItems.push({
690
+ rgItemType: List.ListProps.Type.SEPARATOR
691
+ });
692
+ }
693
+ return resetItems.concat(shownData);
893
694
  }
894
- return labels.filter(Boolean).join(', ');
895
- } else {
896
- return this.state.selected != null ? getItemLabel(this.state.selected) : null;
695
+ return shownData;
897
696
  }
898
- }
899
- _getIcons() {
900
- const {
901
- selected
902
- } = this.state;
903
- const {
904
- disabled,
905
- clear,
906
- hideArrow
907
- } = this.props;
908
- const icons = [];
909
- const height = this.props.height || this.context;
910
- if (!Array.isArray(selected) && selected?.icon) {
911
- icons.push( /*#__PURE__*/React.createElement("button", {
912
- title: "Toggle options popup",
913
- type: "button",
914
- className: modules_9d0de074.selectedIcon,
915
- key: "selected",
916
- disabled: this.props.disabled,
917
- onClick: this._clickHandler,
918
- style: {
919
- backgroundImage: `url(${selected.icon})`
697
+ }, {
698
+ key: "_renderPopup",
699
+ value: function _renderPopup() {
700
+ var _this3 = this;
701
+ var anchorElement = this.props.targetElement || this.node;
702
+ var _this$state2 = this.state,
703
+ showPopup = _this$state2.showPopup,
704
+ shownData = _this$state2.shownData;
705
+ var _shownData = this._prependResetOption(shownData);
706
+ return /*#__PURE__*/React.createElement(I18nContext.Consumer, null, function (_ref2) {
707
+ var translate = _ref2.translate;
708
+ var message;
709
+ if (_this3.props.loading) {
710
+ var _this3$props$loadingM;
711
+ message = (_this3$props$loadingM = _this3.props.loadingMessage) !== null && _this3$props$loadingM !== void 0 ? _this3$props$loadingM : translate('loading');
712
+ } else if (!shownData.length) {
713
+ var _this3$props$notFound;
714
+ message = (_this3$props$notFound = _this3.props.notFoundMessage) !== null && _this3$props$notFound !== void 0 ? _this3$props$notFound : translate('noOptionsFound');
920
715
  }
921
- }));
716
+ return /*#__PURE__*/React.createElement(SelectPopup, {
717
+ data: _shownData,
718
+ message: message,
719
+ toolbar: showPopup && _this3.getToolbar(),
720
+ topbar: _this3.getTopbar(),
721
+ loading: _this3.props.loading,
722
+ activeIndex: _this3.state.selectedIndex,
723
+ hidden: !showPopup,
724
+ ref: _this3.popupRef,
725
+ maxHeight: _this3.props.maxHeight,
726
+ minWidth: _this3.props.minWidth,
727
+ directions: _this3.props.directions,
728
+ className: _this3.props.popupClassName,
729
+ style: _this3.props.popupStyle,
730
+ top: _this3.props.top,
731
+ left: _this3.props.left,
732
+ filter: _this3.isInputMode() ? false : _this3.props.filter // disable popup filter in INPUT mode
733
+ ,
734
+ multiple: _this3.props.multiple,
735
+ filterValue: _this3.state.filterValue,
736
+ anchorElement: anchorElement,
737
+ onCloseAttempt: _this3._onCloseAttempt,
738
+ onOutsideClick: _this3.props.onOutsideClick,
739
+ onSelect: _this3._listSelectHandler,
740
+ onSelectAll: _this3._listSelectAllHandler,
741
+ onFilter: _this3._filterChangeHandler,
742
+ onClear: _this3.clearFilter,
743
+ onLoadMore: _this3.props.onLoadMore,
744
+ isInputMode: _this3.isInputMode(),
745
+ selected: _this3.state.selected,
746
+ tags: _this3.props.tags,
747
+ compact: _this3.props.compact,
748
+ renderOptimization: _this3.props.renderOptimization,
749
+ ringPopupTarget: _this3.props.ringPopupTarget,
750
+ disableMoveOverflow: _this3.props.disableMoveOverflow,
751
+ disableScrollToActive: _this3.props.disableScrollToActive,
752
+ dir: _this3.props.dir,
753
+ onEmptyPopupEnter: _this3.onEmptyPopupEnter,
754
+ listId: _this3.listId
755
+ });
756
+ });
922
757
  }
923
- if (clear && !disabled && !this._selectionIsEmpty()) {
924
- icons.push( /*#__PURE__*/React.createElement(Button, {
925
- title: "Clear selection",
926
- "data-test": "ring-clear-select",
927
- className: modules_9d0de074.clearIcon,
928
- key: "close",
929
- disabled: this.props.disabled,
930
- onClick: this.clear,
931
- height: height,
932
- icon: closeIcon
933
- }));
758
+ }, {
759
+ key: "_showPopup",
760
+ value: function _showPopup() {
761
+ if (!this.node) {
762
+ return;
763
+ }
764
+ var shownData = this.getListItems(this.filterValue());
765
+ this.setState({
766
+ showPopup: true,
767
+ shownData: shownData
768
+ });
769
+ }
770
+ }, {
771
+ key: "_hidePopup",
772
+ value: function _hidePopup(tryFocusAnchor) {
773
+ var _this4 = this;
774
+ if (this.node && this.state.showPopup) {
775
+ this.setState(function (prevState) {
776
+ return {
777
+ showPopup: false,
778
+ filterValue: _this4.props.allowAny ? prevState.filterValue : ''
779
+ };
780
+ });
781
+ if (tryFocusAnchor) {
782
+ var focusableSelectExists = this.node && this.node.querySelector('[data-test~=ring-select__focus]');
783
+ var restoreFocusNode = this.props.targetElement || focusableSelectExists;
784
+ if (restoreFocusNode) {
785
+ restoreFocusNode.focus();
786
+ }
787
+ }
788
+ }
934
789
  }
935
- if (!hideArrow) {
936
- icons.push( /*#__PURE__*/React.createElement(Button, {
937
- title: "Toggle options popup",
938
- className: modules_9d0de074.chevron,
939
- iconClassName: modules_9d0de074.chevronIcon,
940
- icon: chevronDownIcon,
941
- key: "hide",
942
- disabled: this.props.disabled,
943
- height: height,
944
- onClick: this._clickHandler
790
+ }, {
791
+ key: "getToolbar",
792
+ value: function getToolbar() {
793
+ var _this$props2 = this.props,
794
+ hint = _this$props2.hint,
795
+ renderBottomToolbar = _this$props2.renderBottomToolbar;
796
+ var _ref3 = this.state.addButton || {},
797
+ prefix = _ref3.prefix,
798
+ label = _ref3.label,
799
+ delayed = _ref3.delayed;
800
+ var isToolbarHasElements = this.state.addButton || hint || renderBottomToolbar;
801
+ if (!isToolbarHasElements) {
802
+ return null;
803
+ }
804
+ return /*#__PURE__*/React.createElement("div", {
805
+ className: classNames(_defineProperty({}, modules_9d0de074.toolbar, Boolean(this.state.addButton || renderBottomToolbar))),
806
+ "data-test": "ring-select-toolbar"
807
+ }, renderBottomToolbar && renderBottomToolbar(), this.state.addButton && /*#__PURE__*/React.createElement(Button, {
808
+ text: true,
809
+ delayed: delayed,
810
+ className: classNames(modules_9d0de074.button, modules_9d0de074.buttonSpaced),
811
+ onClick: this.addHandler,
812
+ "data-test": "ring-select-toolbar-button"
813
+ }, prefix ? "".concat(prefix, " ").concat(label) : label), hint && /*#__PURE__*/React.createElement(List.ListHint, {
814
+ label: hint,
815
+ "data-test": "ring-select-toolbar-hint"
945
816
  }));
946
817
  }
947
- return icons;
948
- }
949
- _getAvatar() {
950
- return !Array.isArray(this.state.selected) && (this.state.selected?.avatar || this.state.selected?.showGeneratedAvatar) && /*#__PURE__*/React.createElement(Avatar, {
951
- className: modules_9d0de074.avatar,
952
- url: this.state.selected.avatar,
953
- username: this.state.selected.username,
954
- size: Size$1.Size20
955
- });
956
- }
957
- filter;
958
- filterRef = el => {
959
- this.filter = el;
960
- };
961
- getShortcutsMap() {
962
- return {
963
- enter: this._onEnter,
964
- esc: this._onEsc,
965
- up: this._inputShortcutHandler,
966
- down: this._inputShortcutHandler,
967
- right: noop,
968
- left: noop,
969
- 'shift+up': noop,
970
- 'shift+down': noop,
971
- space: noop
972
- };
973
- }
974
- renderSelect(activeItemId) {
975
- var _this$props$label3, _this$props$label4, _this$props$buttonCla;
976
- const dataTest = this.props['data-test'];
977
- const {
978
- selectedLabel
979
- } = this.props;
980
- const {
981
- shortcutsEnabled
982
- } = this.state;
983
- const classes = classNames(modules_9d0de074.select, 'ring-js-shortcuts', this.props.className, modules_9d0de074[`height${this.props.height || this.context}`], {
984
- [modules_9d0de074[`size${this.props.size}`]]: this.props.type !== Type.INLINE,
985
- [modules_9d0de074.disabled]: this.props.disabled
986
- });
987
- const icons = this._getIcons();
988
- const style = getStyle(icons.length);
989
- const iconsNode = /*#__PURE__*/React.createElement("div", {
990
- className: modules_9d0de074.icons
991
- }, icons);
992
- const ariaProps = this.state.showPopup ? {
993
- 'aria-owns': this.listId,
994
- 'aria-activedescendant': activeItemId,
995
- 'aria-label': (_this$props$label3 = this.props.label) !== null && _this$props$label3 !== void 0 ? _this$props$label3 : undefined
996
- } : {
997
- 'aria-label': (_this$props$label4 = this.props.label) !== null && _this$props$label4 !== void 0 ? _this$props$label4 : undefined
998
- };
999
- switch (this.props.type) {
1000
- case Type.INPUT_WITHOUT_CONTROLS:
1001
- case Type.INPUT:
1002
- return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
1003
- ref: this.nodeRef,
1004
- className: classNames(classes, modules_9d0de074.inputMode),
1005
- "data-test": joinDataTestAttributes('ring-select', dataTest)
1006
- }, shortcutsEnabled && /*#__PURE__*/React.createElement(Shortcuts, {
1007
- map: this.getShortcutsMap(),
1008
- scope: this.shortcutsScope
1009
- }), /*#__PURE__*/React.createElement(Input, _extends({}, ariaProps, {
1010
- height: this.props.height,
1011
- autoComplete: "off",
1012
- id: this.props.id,
1013
- onClick: this._clickHandler,
1014
- inputRef: this.filterRef,
1015
- disabled: this.props.disabled,
1016
- value: this.state.filterValue,
1017
- borderless: this.props.type === Type.INPUT_WITHOUT_CONTROLS,
1018
- style: style,
1019
- size: Size.FULL,
1020
- onChange: this._filterChangeHandler,
1021
- onFocus: this._focusHandler,
1022
- onBlur: this._blurHandler
1023
- // Input with error style without description
1024
- ,
1025
- error: this.props.error != null ? '' : null,
1026
- label: this.props.type === Type.INPUT ? this._getLabel() : null,
1027
- placeholder: this.props.inputPlaceholder,
1028
- onKeyDown: this.props.onKeyDown,
1029
- "data-test": "ring-select__focus",
1030
- enableShortcuts: shortcutsEnabled ? Object.keys({
1031
- ...this.getShortcutsMap(),
1032
- ...this._popup?.list?.shortcutsMap
1033
- }) : undefined,
1034
- afterInput: this.props.type === Type.INPUT && iconsNode
1035
- })), this._renderPopup()), this.props.error && /*#__PURE__*/React.createElement("div", {
1036
- className: classNames(modules_88cfaf40.errorText, modules_88cfaf40[`size${this.props.size}`])
1037
- }, this.props.error));
1038
- case Type.BUTTON:
1039
- return /*#__PURE__*/React.createElement("div", {
1040
- ref: this.nodeRef,
1041
- className: classNames(classes, modules_9d0de074.buttonMode),
1042
- "data-test": joinDataTestAttributes('ring-select', dataTest)
1043
- }, selectedLabel && /*#__PURE__*/React.createElement(ControlLabel, {
1044
- type: this.props.labelType,
818
+ }, {
819
+ key: "getTopbar",
820
+ value: function getTopbar() {
821
+ var _this$props$renderTop, _this$props3;
822
+ return (_this$props$renderTop = (_this$props3 = this.props).renderTopToolbar) === null || _this$props$renderTop === void 0 ? void 0 : _this$props$renderTop.call(_this$props3);
823
+ }
824
+ }, {
825
+ key: "getFilterFn",
826
+ value: function getFilterFn() {
827
+ return _getFilterFn(this.props.filter);
828
+ }
829
+ }, {
830
+ key: "getListItems",
831
+ value: function getListItems(rawFilterString, data) {
832
+ var _getListItems2 = _getListItems(this.props, this.state, rawFilterString, data),
833
+ filteredData = _getListItems2.filteredData,
834
+ addButton = _getListItems2.addButton;
835
+ this.setState({
836
+ addButton: addButton
837
+ });
838
+ return filteredData;
839
+ }
840
+ }, {
841
+ key: "filterValue",
842
+ value: function filterValue(setValue) {
843
+ if (typeof setValue === 'string' || typeof setValue === 'number') {
844
+ this.setState({
845
+ filterValue: setValue
846
+ });
847
+ return undefined;
848
+ } else {
849
+ return this.state.filterValue;
850
+ }
851
+ }
852
+ }, {
853
+ key: "isInputMode",
854
+ value: function isInputMode() {
855
+ return _isInputMode(this.props.type);
856
+ }
857
+ }, {
858
+ key: "_rebuildMultipleMap",
859
+ value: function _rebuildMultipleMap(selected) {
860
+ if (Array.isArray(selected)) {
861
+ this.setState({
862
+ multipleMap: buildMultipleMap(selected)
863
+ });
864
+ }
865
+ }
866
+ }, {
867
+ key: "_selectionIsEmpty",
868
+ value: function _selectionIsEmpty() {
869
+ return Array.isArray(this.state.selected) && !this.state.selected.length || !this.state.selected;
870
+ }
871
+ }, {
872
+ key: "_getLabel",
873
+ value: function _getLabel() {
874
+ var _ref4, _this$props$label;
875
+ return (_ref4 = (_this$props$label = this.props.label) !== null && _this$props$label !== void 0 ? _this$props$label : this.props.selectedLabel) !== null && _ref4 !== void 0 ? _ref4 : 'Select an option';
876
+ }
877
+ }, {
878
+ key: "_getPlaceholder",
879
+ value: function _getPlaceholder() {
880
+ if (this._selectionIsEmpty()) {
881
+ var _this$props$label2;
882
+ return (_this$props$label2 = this.props.label) !== null && _this$props$label2 !== void 0 ? _this$props$label2 : 'Select an option';
883
+ }
884
+ return this._getSelectedString();
885
+ }
886
+ }, {
887
+ key: "_getSelectedString",
888
+ value: function _getSelectedString() {
889
+ if (Array.isArray(this.state.selected)) {
890
+ var labels = [];
891
+ for (var i = 0; i < this.state.selected.length; i++) {
892
+ labels.push(getItemLabel(this.state.selected[i]));
893
+ }
894
+ return labels.filter(Boolean).join(', ');
895
+ } else {
896
+ return this.state.selected != null ? getItemLabel(this.state.selected) : null;
897
+ }
898
+ }
899
+ }, {
900
+ key: "_getIcons",
901
+ value: function _getIcons() {
902
+ var selected = this.state.selected;
903
+ var _this$props4 = this.props,
904
+ disabled = _this$props4.disabled,
905
+ clear = _this$props4.clear,
906
+ hideArrow = _this$props4.hideArrow;
907
+ var icons = [];
908
+ var height = this.props.height || this.context;
909
+ if (!Array.isArray(selected) && selected !== null && selected !== void 0 && selected.icon) {
910
+ icons.push( /*#__PURE__*/React.createElement("button", {
911
+ title: "Toggle options popup",
912
+ type: "button",
913
+ className: modules_9d0de074.selectedIcon,
914
+ key: "selected",
1045
915
  disabled: this.props.disabled,
1046
- htmlFor: this.props.id
1047
- }, selectedLabel), shortcutsEnabled && /*#__PURE__*/React.createElement(Shortcuts, {
1048
- map: this.getShortcutsMap(),
1049
- scope: this.shortcutsScope
1050
- }), /*#__PURE__*/React.createElement("div", {
1051
- className: modules_9d0de074.buttonContainer
1052
- }, /*#__PURE__*/React.createElement(Button, _extends({}, ariaProps, {
1053
- height: this.props.height,
1054
- id: this.props.id,
1055
916
  onClick: this._clickHandler,
1056
- className: classNames(this.props.buttonClassName, modules_9d0de074.buttonValue, {
1057
- [modules_9d0de074.buttonValueOpen]: this.state.showPopup,
1058
- [modules_9d0de074.buttonValueEmpty]: this._selectionIsEmpty()
1059
- }),
917
+ style: {
918
+ backgroundImage: "url(".concat(selected.icon, ")")
919
+ }
920
+ }));
921
+ }
922
+ if (clear && !disabled && !this._selectionIsEmpty()) {
923
+ icons.push( /*#__PURE__*/React.createElement(Button, {
924
+ title: "Clear selection",
925
+ "data-test": "ring-clear-select",
926
+ className: modules_9d0de074.clearIcon,
927
+ key: "close",
1060
928
  disabled: this.props.disabled,
1061
- style: style,
1062
- "data-test": "ring-select__button ring-select__focus"
1063
- }), this._getAvatar(), this._getPlaceholder()), iconsNode), this._renderPopup());
1064
- case Type.INLINE:
1065
- return /*#__PURE__*/React.createElement("div", {
1066
- className: classes,
1067
- ref: this.nodeRef,
1068
- "data-test": joinDataTestAttributes('ring-select', dataTest)
1069
- }, shortcutsEnabled && /*#__PURE__*/React.createElement(Shortcuts, {
1070
- map: this.getShortcutsMap(),
1071
- scope: this.shortcutsScope
1072
- }), /*#__PURE__*/React.createElement(Anchor, _extends({}, ariaProps, {
1073
- className: (_this$props$buttonCla = this.props.buttonClassName) !== null && _this$props$buttonCla !== void 0 ? _this$props$buttonCla : undefined,
1074
- id: this.props.id,
1075
- onClick: this._clickHandler,
1076
- "data-test": "ring-select__focus",
929
+ onClick: this.clear,
930
+ height: height,
931
+ icon: closeIcon
932
+ }));
933
+ }
934
+ if (!hideArrow) {
935
+ icons.push( /*#__PURE__*/React.createElement(Button, {
936
+ title: "Toggle options popup",
937
+ className: modules_9d0de074.chevron,
938
+ iconClassName: modules_9d0de074.chevronIcon,
939
+ icon: chevronDownIcon,
940
+ key: "hide",
1077
941
  disabled: this.props.disabled,
1078
- active: this.state.showPopup
1079
- }), this._getPlaceholder()), this._renderPopup());
1080
- default:
1081
- if (this.props.customAnchor) {
1082
- return /*#__PURE__*/React.createElement(Fragment, null, shortcutsEnabled && /*#__PURE__*/React.createElement(Shortcuts, {
942
+ height: height,
943
+ onClick: this._clickHandler
944
+ }));
945
+ }
946
+ return icons;
947
+ }
948
+ }, {
949
+ key: "_getAvatar",
950
+ value: function _getAvatar() {
951
+ var _this$state$selected, _this$state$selected2;
952
+ return !Array.isArray(this.state.selected) && (((_this$state$selected = this.state.selected) === null || _this$state$selected === void 0 ? void 0 : _this$state$selected.avatar) || ((_this$state$selected2 = this.state.selected) === null || _this$state$selected2 === void 0 ? void 0 : _this$state$selected2.showGeneratedAvatar)) && /*#__PURE__*/React.createElement(Avatar, {
953
+ className: modules_9d0de074.avatar,
954
+ url: this.state.selected.avatar,
955
+ username: this.state.selected.username,
956
+ size: Size$1.Size20
957
+ });
958
+ }
959
+ }, {
960
+ key: "getShortcutsMap",
961
+ value: function getShortcutsMap() {
962
+ return {
963
+ enter: this._onEnter,
964
+ esc: this._onEsc,
965
+ up: this._inputShortcutHandler,
966
+ down: this._inputShortcutHandler,
967
+ right: noop,
968
+ left: noop,
969
+ 'shift+up': noop,
970
+ 'shift+down': noop,
971
+ space: noop
972
+ };
973
+ }
974
+ }, {
975
+ key: "renderSelect",
976
+ value: function renderSelect(activeItemId) {
977
+ var _classNames2, _this$props$label3, _this$props$label4, _this$_popup5, _this$_popup5$list, _classNames3, _this$props$buttonCla;
978
+ var dataTest = this.props['data-test'];
979
+ var selectedLabel = this.props.selectedLabel;
980
+ var shortcutsEnabled = this.state.shortcutsEnabled;
981
+ var classes = classNames(modules_9d0de074.select, 'ring-js-shortcuts', this.props.className, modules_9d0de074["height".concat(this.props.height || this.context)], (_classNames2 = {}, _defineProperty(_classNames2, modules_9d0de074["size".concat(this.props.size)], this.props.type !== Type.INLINE), _defineProperty(_classNames2, modules_9d0de074.disabled, this.props.disabled), _classNames2));
982
+ var icons = this._getIcons();
983
+ var style = getStyle(icons.length);
984
+ var iconsNode = /*#__PURE__*/React.createElement("div", {
985
+ className: modules_9d0de074.icons
986
+ }, icons);
987
+ var ariaProps = this.state.showPopup ? {
988
+ 'aria-owns': this.listId,
989
+ 'aria-activedescendant': activeItemId,
990
+ 'aria-label': (_this$props$label3 = this.props.label) !== null && _this$props$label3 !== void 0 ? _this$props$label3 : undefined
991
+ } : {
992
+ 'aria-label': (_this$props$label4 = this.props.label) !== null && _this$props$label4 !== void 0 ? _this$props$label4 : undefined
993
+ };
994
+ switch (this.props.type) {
995
+ case Type.INPUT_WITHOUT_CONTROLS:
996
+ case Type.INPUT:
997
+ return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
998
+ ref: this.nodeRef,
999
+ className: classNames(classes, modules_9d0de074.inputMode),
1000
+ "data-test": joinDataTestAttributes('ring-select', dataTest)
1001
+ }, shortcutsEnabled && /*#__PURE__*/React.createElement(Shortcuts, {
1002
+ map: this.getShortcutsMap(),
1003
+ scope: this.shortcutsScope
1004
+ }), /*#__PURE__*/React.createElement(Input, _extends({}, ariaProps, {
1005
+ height: this.props.height,
1006
+ autoComplete: "off",
1007
+ id: this.props.id,
1008
+ onClick: this._clickHandler,
1009
+ inputRef: this.filterRef,
1010
+ disabled: this.props.disabled,
1011
+ value: this.state.filterValue,
1012
+ borderless: this.props.type === Type.INPUT_WITHOUT_CONTROLS,
1013
+ style: style,
1014
+ size: Size.FULL,
1015
+ onChange: this._filterChangeHandler,
1016
+ onFocus: this._focusHandler,
1017
+ onBlur: this._blurHandler
1018
+ // Input with error style without description
1019
+ ,
1020
+ error: this.props.error != null ? '' : null,
1021
+ label: this.props.type === Type.INPUT ? this._getLabel() : null,
1022
+ placeholder: this.props.inputPlaceholder,
1023
+ onKeyDown: this.props.onKeyDown,
1024
+ "data-test": "ring-select__focus",
1025
+ enableShortcuts: shortcutsEnabled ? Object.keys(_objectSpread2(_objectSpread2({}, this.getShortcutsMap()), (_this$_popup5 = this._popup) === null || _this$_popup5 === void 0 ? void 0 : (_this$_popup5$list = _this$_popup5.list) === null || _this$_popup5$list === void 0 ? void 0 : _this$_popup5$list.shortcutsMap)) : undefined,
1026
+ afterInput: this.props.type === Type.INPUT && iconsNode
1027
+ })), this._renderPopup()), this.props.error && /*#__PURE__*/React.createElement("div", {
1028
+ className: classNames(modules_88cfaf40.errorText, modules_88cfaf40["size".concat(this.props.size)])
1029
+ }, this.props.error));
1030
+ case Type.BUTTON:
1031
+ return /*#__PURE__*/React.createElement("div", {
1032
+ ref: this.nodeRef,
1033
+ className: classNames(classes, modules_9d0de074.buttonMode),
1034
+ "data-test": joinDataTestAttributes('ring-select', dataTest)
1035
+ }, selectedLabel && /*#__PURE__*/React.createElement(ControlLabel, {
1036
+ type: this.props.labelType,
1037
+ disabled: this.props.disabled,
1038
+ htmlFor: this.props.id
1039
+ }, selectedLabel), shortcutsEnabled && /*#__PURE__*/React.createElement(Shortcuts, {
1040
+ map: this.getShortcutsMap(),
1041
+ scope: this.shortcutsScope
1042
+ }), /*#__PURE__*/React.createElement("div", {
1043
+ className: modules_9d0de074.buttonContainer
1044
+ }, /*#__PURE__*/React.createElement(Button, _extends({}, ariaProps, {
1045
+ height: this.props.height,
1046
+ id: this.props.id,
1047
+ onClick: this._clickHandler,
1048
+ className: classNames(this.props.buttonClassName, modules_9d0de074.buttonValue, (_classNames3 = {}, _defineProperty(_classNames3, modules_9d0de074.buttonValueOpen, this.state.showPopup), _defineProperty(_classNames3, modules_9d0de074.buttonValueEmpty, this._selectionIsEmpty()), _classNames3)),
1049
+ disabled: this.props.disabled,
1050
+ style: style,
1051
+ "data-test": "ring-select__button ring-select__focus"
1052
+ }), this._getAvatar(), this._getPlaceholder()), iconsNode), this._renderPopup());
1053
+ case Type.INLINE:
1054
+ return /*#__PURE__*/React.createElement("div", {
1055
+ className: classes,
1056
+ ref: this.nodeRef,
1057
+ "data-test": joinDataTestAttributes('ring-select', dataTest)
1058
+ }, shortcutsEnabled && /*#__PURE__*/React.createElement(Shortcuts, {
1083
1059
  map: this.getShortcutsMap(),
1084
1060
  scope: this.shortcutsScope
1085
- }), this.props.customAnchor({
1086
- wrapperProps: {
1087
- ref: this.nodeRef,
1088
- 'data-test': joinDataTestAttributes('ring-select', dataTest)
1089
- },
1090
- buttonProps: {
1091
- ...ariaProps,
1092
- id: this.props.id,
1093
- onClick: this._clickHandler,
1094
- disabled: this.props.disabled,
1095
- children: this._getPlaceholder(),
1096
- 'data-test': 'ring-select_focus'
1097
- },
1098
- popup: this._renderPopup()
1099
- }));
1061
+ }), /*#__PURE__*/React.createElement(Anchor, _extends({}, ariaProps, {
1062
+ className: (_this$props$buttonCla = this.props.buttonClassName) !== null && _this$props$buttonCla !== void 0 ? _this$props$buttonCla : undefined,
1063
+ id: this.props.id,
1064
+ onClick: this._clickHandler,
1065
+ "data-test": "ring-select__focus",
1066
+ disabled: this.props.disabled,
1067
+ active: this.state.showPopup
1068
+ }), this._getPlaceholder()), this._renderPopup());
1069
+ default:
1070
+ if (this.props.customAnchor) {
1071
+ return /*#__PURE__*/React.createElement(Fragment, null, shortcutsEnabled && /*#__PURE__*/React.createElement(Shortcuts, {
1072
+ map: this.getShortcutsMap(),
1073
+ scope: this.shortcutsScope
1074
+ }), this.props.customAnchor({
1075
+ wrapperProps: {
1076
+ ref: this.nodeRef,
1077
+ 'data-test': joinDataTestAttributes('ring-select', dataTest)
1078
+ },
1079
+ buttonProps: _objectSpread2(_objectSpread2({}, ariaProps), {}, {
1080
+ id: this.props.id,
1081
+ onClick: this._clickHandler,
1082
+ disabled: this.props.disabled,
1083
+ children: this._getPlaceholder(),
1084
+ 'data-test': 'ring-select_focus'
1085
+ }),
1086
+ popup: this._renderPopup()
1087
+ }));
1088
+ }
1089
+ return /*#__PURE__*/React.createElement("span", {
1090
+ id: this.props.id,
1091
+ ref: this.nodeRef,
1092
+ "data-test": "ring-select"
1093
+ }, this._renderPopup());
1094
+ }
1095
+ }
1096
+ }, {
1097
+ key: "render",
1098
+ value: function render() {
1099
+ var _this5 = this;
1100
+ return /*#__PURE__*/React.createElement(ActiveItemContext.Provider, null, /*#__PURE__*/React.createElement(ActiveItemContext.ValueContext.Consumer, null, function (activeItemId) {
1101
+ return _this5.renderSelect(activeItemId);
1102
+ }));
1103
+ }
1104
+ }], [{
1105
+ key: "getDerivedStateFromProps",
1106
+ value: function getDerivedStateFromProps(nextProps, prevState) {
1107
+ var multiple = nextProps.multiple,
1108
+ data = nextProps.data,
1109
+ type = nextProps.type;
1110
+ var prevSelected = prevState.prevSelected,
1111
+ prevData = prevState.prevData,
1112
+ prevMultiple = prevState.prevMultiple,
1113
+ filterValue = prevState.filterValue;
1114
+ var nextState = {
1115
+ prevData: data,
1116
+ prevSelected: nextProps.selected,
1117
+ prevMultiple: multiple
1118
+ };
1119
+ if ('data' in nextProps && data !== prevData) {
1120
+ var _getListItems3 = _getListItems(nextProps, prevState, filterValue, data),
1121
+ filteredData = _getListItems3.filteredData,
1122
+ addButton = _getListItems3.addButton;
1123
+ Object.assign(nextState, {
1124
+ shownData: filteredData,
1125
+ addButton: addButton
1126
+ });
1127
+ if (prevState.selected) {
1128
+ Object.assign(nextState, {
1129
+ selectedIndex: getSelectedIndex(prevState.selected, data),
1130
+ filterValue: _getValueForFilter(prevState.selected, type, filterValue)
1131
+ });
1132
+ }
1133
+ }
1134
+ if ('selected' in nextProps && nextProps.selected !== prevSelected) {
1135
+ var _selected = nextProps.selected || (multiple ? [] : null);
1136
+ var selectedIndex = getSelectedIndex(_selected, data || prevData);
1137
+ Object.assign(nextState, {
1138
+ selected: _selected,
1139
+ filterValue: _getValueForFilter(_selected, type, filterValue)
1140
+ });
1141
+ if (!Array.isArray(prevSelected) || !Array.isArray(_selected) || !isSameSelected(prevSelected, _selected)) {
1142
+ Object.assign(nextState, {
1143
+ selectedIndex: selectedIndex
1144
+ });
1100
1145
  }
1101
- return /*#__PURE__*/React.createElement("span", {
1102
- id: this.props.id,
1103
- ref: this.nodeRef,
1104
- "data-test": "ring-select"
1105
- }, this._renderPopup());
1146
+ }
1147
+ if (prevMultiple !== multiple && !deepEqual(prevMultiple, multiple)) {
1148
+ nextState.selected = multiple ? [] : null;
1149
+ }
1150
+ if (multiple && !nextState.selected) {
1151
+ nextState.selected = prevState.selected;
1152
+ }
1153
+ var _prevState$nextState = _objectSpread2(_objectSpread2({}, prevState), nextState),
1154
+ selected = _prevState$nextState.selected;
1155
+ if (selected && Array.isArray(selected)) {
1156
+ nextState.multipleMap = buildMultipleMap(selected);
1157
+ var _getListItems4 = _getListItems(nextProps, nextState, filterValue, data),
1158
+ _filteredData = _getListItems4.filteredData,
1159
+ _addButton = _getListItems4.addButton;
1160
+ Object.assign(nextState, {
1161
+ shownData: _filteredData,
1162
+ addButton: _addButton
1163
+ });
1164
+ }
1165
+ return nextState;
1106
1166
  }
1107
- }
1108
- render() {
1109
- return /*#__PURE__*/React.createElement(ActiveItemContext.Provider, null, /*#__PURE__*/React.createElement(ActiveItemContext.ValueContext.Consumer, null, activeItemId => this.renderSelect(activeItemId)));
1110
- }
1111
- }
1167
+ }]);
1168
+ return Select;
1169
+ }(Component);
1170
+ _defineProperty(Select, "defaultProps", {
1171
+ data: [],
1172
+ filter: false,
1173
+ multiple: false,
1174
+ clear: false,
1175
+ loading: false,
1176
+ disabled: false,
1177
+ type: Type.BUTTON,
1178
+ size: Size.M,
1179
+ targetElement: null,
1180
+ hideSelected: false,
1181
+ allowAny: false,
1182
+ hideArrow: false,
1183
+ showPopup: false,
1184
+ maxHeight: 600,
1185
+ directions: [Popup.PopupProps.Directions.BOTTOM_RIGHT, Popup.PopupProps.Directions.BOTTOM_LEFT, Popup.PopupProps.Directions.TOP_LEFT, Popup.PopupProps.Directions.TOP_RIGHT],
1186
+ selected: null,
1187
+ label: null,
1188
+ selectedLabel: null,
1189
+ inputPlaceholder: '',
1190
+ hint: null,
1191
+ shortcutsEnabled: false,
1192
+ onBeforeOpen: noop,
1193
+ onLoadMore: noop,
1194
+ onOpen: noop,
1195
+ onClose: noop,
1196
+ onFilter: noop,
1197
+ onFocus: noop,
1198
+ onBlur: noop,
1199
+ onKeyDown: noop,
1200
+ onSelect: noop,
1201
+ onDeselect: noop,
1202
+ onOutsideClick: noop,
1203
+ onChange: noop,
1204
+ onAdd: noop,
1205
+ onDone: noop,
1206
+ onReset: noop,
1207
+ tags: null,
1208
+ ringPopupTarget: null,
1209
+ dir: 'ltr'
1210
+ });
1211
+ _defineProperty(Select, "contextType", ControlsHeightContext);
1212
+ _defineProperty(Select, "Type", Type);
1213
+ _defineProperty(Select, "Size", Size);
1112
1214
  Select.propTypes = {
1113
1215
  className: PropTypes.string,
1114
1216
  buttonClassName: PropTypes.string,
@@ -1168,6 +1270,6 @@ Select.propTypes = {
1168
1270
  dir: PropTypes.oneOf(['ltr', 'rtl']),
1169
1271
  'data-test': PropTypes.string
1170
1272
  };
1171
- const RerenderableSelect = rerenderHOC(Select);
1273
+ var RerenderableSelect = rerenderHOC(Select);
1172
1274
 
1173
1275
  export { RerenderableSelect, Type, Select as default };