@jetbrains/ring-ui-built 6.0.31 → 6.0.32

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 (225) hide show
  1. package/components/_helpers/_rollupPluginBabelHelpers.js +1 -567
  2. package/components/_helpers/anchor.js +7 -6
  3. package/components/_helpers/button__classes.js +16 -14
  4. package/components/_helpers/caption.js +14 -20
  5. package/components/_helpers/card.js +95 -105
  6. package/components/_helpers/dialog__body-scroll-preventer.js +11 -19
  7. package/components/_helpers/icon__svg.js +22 -25
  8. package/components/_helpers/input.js +146 -177
  9. package/components/_helpers/query-assist__suggestions.js +74 -90
  10. package/components/_helpers/select__filter.js +48 -69
  11. package/components/_helpers/services-link.js +29 -37
  12. package/components/_helpers/sidebar.js +99 -107
  13. package/components/_helpers/tab-link.js +7 -7
  14. package/components/_helpers/theme.js +31 -40
  15. package/components/_helpers/title.js +57 -72
  16. package/components/alert/alert.js +150 -202
  17. package/components/alert/container.js +32 -41
  18. package/components/alert-service/alert-service.js +105 -170
  19. package/components/analytics/analytics.js +12 -22
  20. package/components/analytics/analytics__custom-plugin.js +54 -75
  21. package/components/auth/auth.js +4 -36
  22. package/components/auth/auth__core.js +746 -1471
  23. package/components/auth/background-flow.js +87 -127
  24. package/components/auth/down-notification.js +30 -73
  25. package/components/auth/iframe-flow.js +75 -133
  26. package/components/auth/request-builder.js +46 -82
  27. package/components/auth/response-parser.js +86 -116
  28. package/components/auth/storage.js +171 -334
  29. package/components/auth/token-validator.js +137 -242
  30. package/components/auth/window-flow.js +92 -134
  31. package/components/auth-dialog/auth-dialog.js +114 -172
  32. package/components/auth-dialog-service/auth-dialog-service.js +8 -31
  33. package/components/avatar/avatar-example-datauri.js +23 -1
  34. package/components/avatar/avatar.js +119 -152
  35. package/components/avatar/fallback-avatar.js +22 -38
  36. package/components/badge/badge.js +35 -45
  37. package/components/button/button.js +86 -107
  38. package/components/button-group/button-group.js +19 -33
  39. package/components/button-set/button-set.js +20 -32
  40. package/components/button-toolbar/button-toolbar.js +19 -31
  41. package/components/caret/caret.js +186 -220
  42. package/components/checkbox/checkbox.js +76 -101
  43. package/components/clipboard/clipboard-fallback.js +10 -10
  44. package/components/clipboard/clipboard.js +35 -132
  45. package/components/code/code.js +92 -166
  46. package/components/collapse/collapse-content.js +42 -64
  47. package/components/collapse/collapse-context.js +2 -2
  48. package/components/collapse/collapse-control.js +12 -14
  49. package/components/collapse/collapse.js +11 -17
  50. package/components/collapse/consts.js +4 -4
  51. package/components/collapse/utils.js +1 -3
  52. package/components/confirm/confirm.js +66 -104
  53. package/components/confirm-service/confirm-service.js +37 -59
  54. package/components/content-layout/content-layout.js +43 -64
  55. package/components/content-layout/sidebar.js +0 -1
  56. package/components/contenteditable/contenteditable.js +50 -59
  57. package/components/control-label/control-label.js +9 -9
  58. package/components/data-list/data-list.js +129 -182
  59. package/components/data-list/data-list.mock.js +2 -6
  60. package/components/data-list/item.js +143 -170
  61. package/components/data-list/selection.js +76 -136
  62. package/components/data-list/title.js +1 -12
  63. package/components/date-picker/consts.js +19 -26
  64. package/components/date-picker/date-input.js +113 -144
  65. package/components/date-picker/date-picker.js +227 -282
  66. package/components/date-picker/date-popup.js +350 -395
  67. package/components/date-picker/day.js +87 -116
  68. package/components/date-picker/month-names.js +43 -66
  69. package/components/date-picker/month-slider.js +51 -76
  70. package/components/date-picker/month.js +16 -25
  71. package/components/date-picker/months.js +43 -50
  72. package/components/date-picker/weekdays.js +12 -22
  73. package/components/date-picker/years.js +83 -110
  74. package/components/dialog/dialog.js +142 -190
  75. package/components/dialog/dialog__body-scroll-preventer.js +0 -4
  76. package/components/dropdown/anchor.js +0 -9
  77. package/components/dropdown/dropdown.js +182 -213
  78. package/components/dropdown-menu/dropdown-menu.js +71 -97
  79. package/components/editable-heading/editable-heading.js +75 -127
  80. package/components/error-bubble/error-bubble.js +31 -60
  81. package/components/error-message/error-message.js +39 -59
  82. package/components/footer/footer.js +27 -30
  83. package/components/global/compose.js +1 -10
  84. package/components/global/composeRefs.js +7 -12
  85. package/components/global/controls-height.js +2 -2
  86. package/components/global/create-stateful-context.js +15 -15
  87. package/components/global/data-tests.js +6 -14
  88. package/components/global/dom.js +47 -86
  89. package/components/global/focus-sensor-hoc.js +122 -132
  90. package/components/global/fuzzy-highlight.js +22 -36
  91. package/components/global/get-event-key.js +8 -8
  92. package/components/global/get-uid.js +4 -8
  93. package/components/global/inject-styles.js +10 -15
  94. package/components/global/listeners.js +27 -51
  95. package/components/global/memoize.js +6 -12
  96. package/components/global/normalize-indent.js +19 -50
  97. package/components/global/promise-with-timeout.js +6 -8
  98. package/components/global/prop-types.js +3 -5
  99. package/components/global/react-dom-renderer.js +28 -44
  100. package/components/global/react-render-adapter.js +1 -1
  101. package/components/global/rerender-hoc.js +12 -30
  102. package/components/global/schedule-raf.js +5 -6
  103. package/components/global/sniffer.js +1 -1
  104. package/components/global/theme.js +0 -22
  105. package/components/global/trivial-template-tag.js +3 -10
  106. package/components/global/typescript-utils.js +2 -6
  107. package/components/global/url.js +20 -26
  108. package/components/global/use-event-callback.js +6 -4
  109. package/components/grid/col.js +35 -52
  110. package/components/grid/grid.js +17 -31
  111. package/components/grid/row.js +35 -47
  112. package/components/group/group.js +17 -25
  113. package/components/header/header.js +33 -78
  114. package/components/header/logo.js +20 -36
  115. package/components/header/profile.js +166 -199
  116. package/components/header/services-link.js +0 -4
  117. package/components/header/services.js +73 -116
  118. package/components/header/smart-profile.js +111 -203
  119. package/components/header/smart-services.js +62 -113
  120. package/components/header/tray-icon.js +21 -37
  121. package/components/header/tray.js +21 -32
  122. package/components/heading/heading.js +24 -25
  123. package/components/http/http.d.ts +1 -3
  124. package/components/http/http.js +203 -353
  125. package/components/http/http.mock.js +49 -101
  126. package/components/hub-source/hub-source.js +83 -190
  127. package/components/hub-source/hub-source__user.js +11 -44
  128. package/components/hub-source/hub-source__users-groups.js +37 -65
  129. package/components/i18n/i18n-context.js +7 -10
  130. package/components/i18n/i18n.js +7 -10
  131. package/components/icon/icon.js +76 -93
  132. package/components/icon/icon__svg.js +0 -8
  133. package/components/icon/index.js +0 -8
  134. package/components/input/input.js +0 -13
  135. package/components/island/adaptive-island-hoc.js +30 -43
  136. package/components/island/content.js +115 -132
  137. package/components/island/header.js +57 -70
  138. package/components/island/island.js +28 -40
  139. package/components/island-legacy/content-legacy.js +17 -25
  140. package/components/island-legacy/header-legacy.js +19 -27
  141. package/components/island-legacy/island-legacy.js +17 -25
  142. package/components/link/clickableLink.js +44 -59
  143. package/components/link/link.js +57 -68
  144. package/components/list/consts.js +2 -2
  145. package/components/list/list.js +611 -698
  146. package/components/list/list__custom.js +44 -62
  147. package/components/list/list__hint.js +10 -19
  148. package/components/list/list__item.js +133 -174
  149. package/components/list/list__link.js +37 -50
  150. package/components/list/list__separator.js +14 -24
  151. package/components/list/list__title.js +22 -32
  152. package/components/list/list__users-groups-source.js +54 -126
  153. package/components/loader/loader.js +43 -74
  154. package/components/loader/loader__core.js +198 -263
  155. package/components/loader-inline/loader-inline.js +23 -35
  156. package/components/loader-screen/loader-screen.js +25 -46
  157. package/components/login-dialog/login-dialog.js +111 -158
  158. package/components/login-dialog/service.js +8 -34
  159. package/components/markdown/markdown.js +15 -23
  160. package/components/message/message.js +161 -203
  161. package/components/old-browsers-message/old-browsers-message.js +11 -18
  162. package/components/old-browsers-message/old-browsers-message__stop.js +0 -7
  163. package/components/old-browsers-message/white-list.js +8 -16
  164. package/components/pager/pager.js +212 -271
  165. package/components/panel/panel.js +17 -25
  166. package/components/permissions/permissions.js +127 -172
  167. package/components/permissions/permissions__cache.js +194 -224
  168. package/components/popup/popup.consts.js +1 -1
  169. package/components/popup/popup.js +284 -343
  170. package/components/popup/popup.target.js +9 -8
  171. package/components/popup/position.js +96 -106
  172. package/components/popup-menu/popup-menu.js +44 -80
  173. package/components/progress-bar/progress-bar.js +87 -104
  174. package/components/query-assist/query-assist.js +838 -916
  175. package/components/query-assist/query-assist__suggestions.js +1 -30
  176. package/components/radio/radio.js +19 -34
  177. package/components/radio/radio__item.js +52 -69
  178. package/components/select/select.js +852 -957
  179. package/components/select/select__filter.js +0 -30
  180. package/components/select/select__popup.js +373 -487
  181. package/components/shortcuts/core.js +166 -217
  182. package/components/shortcuts/shortcut-title.js +6 -11
  183. package/components/shortcuts/shortcuts-hoc.js +19 -45
  184. package/components/shortcuts/shortcuts.js +50 -75
  185. package/components/slider/slider.js +99 -122
  186. package/components/slider/slider.utils.js +14 -24
  187. package/components/storage/storage.js +4 -33
  188. package/components/storage/storage__fallback.js +149 -224
  189. package/components/storage/storage__local.js +90 -153
  190. package/components/tab-trap/tab-trap.js +122 -153
  191. package/components/table/cell.js +14 -26
  192. package/components/table/disable-hover-hoc.js +33 -51
  193. package/components/table/header-cell.js +64 -89
  194. package/components/table/header.js +104 -132
  195. package/components/table/multitable.js +107 -125
  196. package/components/table/row-with-focus-sensor.js +25 -69
  197. package/components/table/row.js +175 -216
  198. package/components/table/selection-adapter.js +1 -3
  199. package/components/table/selection-shortcuts-hoc.js +180 -181
  200. package/components/table/selection.js +156 -226
  201. package/components/table/smart-table.js +50 -88
  202. package/components/table/table.js +289 -358
  203. package/components/tabs/collapsible-more.js +46 -79
  204. package/components/tabs/collapsible-tab.js +31 -38
  205. package/components/tabs/collapsible-tabs.js +88 -153
  206. package/components/tabs/custom-item.js +4 -2
  207. package/components/tabs/dumb-tabs.js +74 -117
  208. package/components/tabs/smart-tabs.js +29 -69
  209. package/components/tabs/tab-link.js +1 -5
  210. package/components/tabs/tab.js +19 -31
  211. package/components/tabs/tabs.js +0 -31
  212. package/components/tag/tag.js +133 -173
  213. package/components/tags-input/tags-input.js +329 -427
  214. package/components/tags-list/tags-list.js +57 -78
  215. package/components/text/text.js +28 -39
  216. package/components/toggle/toggle.js +56 -70
  217. package/components/tooltip/tooltip.js +146 -190
  218. package/components/user-agreement/service.js +228 -371
  219. package/components/user-agreement/toolbox.eula.js +160 -1
  220. package/components/user-agreement/user-agreement.js +85 -120
  221. package/components/user-card/card.js +0 -29
  222. package/components/user-card/smart-user-card-tooltip.js +51 -111
  223. package/components/user-card/tooltip.js +47 -84
  224. package/components/user-card/user-card.js +0 -29
  225. package/package.json +1 -1
@@ -1,15 +1,4 @@
1
- import { _ as _defineProperty, a as _inherits, b as _createClass, f as _classCallCheck, g as _callSuper, h as _asyncToGenerator, i as _regeneratorRuntime } from '../_helpers/_rollupPluginBabelHelpers.js';
2
- import 'core-js/modules/es.array.concat.js';
3
- import 'core-js/modules/es.array.filter.js';
4
- import 'core-js/modules/es.array.index-of.js';
5
- import 'core-js/modules/es.array.iterator.js';
6
- import 'core-js/modules/es.array.map.js';
7
- import 'core-js/modules/es.map.js';
8
- import 'core-js/modules/es.object.assign.js';
9
- import 'core-js/modules/es.object.to-string.js';
10
- import 'core-js/modules/es.promise.js';
11
- import 'core-js/modules/web.dom-collections.iterator.js';
12
- import React, { Component, PureComponent } from 'react';
1
+ import React, { PureComponent, Component } from 'react';
13
2
  import PropTypes from 'prop-types';
14
3
  import classNames from 'classnames';
15
4
  import getEventKey from '../global/get-event-key.js';
@@ -22,20 +11,12 @@ import { S as Size, m as modules_88cfaf40 } from '../_helpers/input.js';
22
11
  import { ControlsHeightContext } from '../global/controls-height.js';
23
12
  import getUID from '../global/get-uid.js';
24
13
  import { ControlLabel } from '../control-label/control-label.js';
25
- import 'core-js/modules/es.array.find.js';
26
- import 'core-js/modules/es.array.reduce.js';
27
- import 'core-js/modules/es.array.slice.js';
28
- import 'core-js/modules/es.object.values.js';
29
- import 'core-js/modules/es.regexp.exec.js';
30
- import 'core-js/modules/es.string.replace.js';
31
- import 'core-js/modules/es.string.trim.js';
32
- import 'core-js/modules/web.dom-collections.for-each.js';
14
+ import '../_helpers/_rollupPluginBabelHelpers.js';
33
15
  import '@jetbrains/icons/chevron-down';
34
16
  import '@jetbrains/icons/close-12px';
35
17
  import 'deep-equal';
36
18
  import '../dropdown/dropdown.js';
37
19
  import '../global/data-tests.js';
38
- import 'core-js/modules/es.object.entries.js';
39
20
  import '../global/typescript-utils.js';
40
21
  import '../_helpers/anchor.js';
41
22
  import '@jetbrains/icons/chevron-10px';
@@ -43,40 +24,26 @@ import '../icon/icon.js';
43
24
  import 'util-deprecate';
44
25
  import '../icon/icon__constants.js';
45
26
  import '../_helpers/icon__svg.js';
46
- import 'core-js/modules/es.string.starts-with.js';
47
- import 'core-js/modules/es.weak-map.js';
48
27
  import '../button/button.js';
49
28
  import '../link/clickableLink.js';
50
29
  import '../_helpers/button__classes.js';
51
30
  import '../avatar/avatar.js';
52
31
  import '../global/url.js';
53
- import 'core-js/modules/es.string.match.js';
54
32
  import '../global/dom.js';
55
- import 'core-js/modules/es.set.js';
56
- import 'core-js/modules/es.string.split.js';
57
33
  import '../avatar/fallback-avatar.js';
58
- import 'core-js/modules/es.array.from.js';
59
- import 'core-js/modules/es.regexp.to-string.js';
60
34
  import '../popup/popup.js';
61
35
  import 'react-dom';
62
36
  import '../global/schedule-raf.js';
63
37
  import '../shortcuts/shortcuts.js';
64
38
  import '../shortcuts/core.js';
65
- import 'core-js/modules/es.array.find-index.js';
66
- import 'core-js/modules/es.array.includes.js';
67
- import 'core-js/modules/es.array.splice.js';
68
- import 'core-js/modules/es.string.includes.js';
69
39
  import 'combokeys';
70
40
  import '../global/sniffer.js';
71
41
  import 'sniffr';
72
42
  import '../tab-trap/tab-trap.js';
73
43
  import '../popup/position.js';
74
- import 'core-js/modules/es.array.sort.js';
75
44
  import '../popup/popup.consts.js';
76
45
  import '../popup/popup.target.js';
77
46
  import '../list/list.js';
78
- import 'core-js/modules/es.symbol.js';
79
- import 'core-js/modules/es.symbol.description.js';
80
47
  import 'react-virtualized/dist/es/List';
81
48
  import 'react-virtualized/dist/es/AutoSizer';
82
49
  import 'react-virtualized/dist/es/WindowScroller';
@@ -115,418 +82,353 @@ function noop() {}
115
82
  /**
116
83
  * @name Tags Input
117
84
  */
118
- var POPUP_VERTICAL_SHIFT = 2;
119
- var TagsInput = /*#__PURE__*/function (_PureComponent) {
120
- function TagsInput(props) {
121
- var _this;
122
- _classCallCheck(this, TagsInput);
123
- _this = _callSuper(this, TagsInput, [props]);
124
- _defineProperty(_this, "state", {
125
- tags: [],
126
- prevTags: null,
127
- suggestions: [],
128
- loading: true,
129
- focused: false,
130
- query: '',
131
- activeIndex: 0
132
- });
133
- _defineProperty(_this, "ngModelStateField", void 0);
134
- _defineProperty(_this, "id", _this.props.id || getUID('ring-tags-list-'));
135
- _defineProperty(_this, "node", void 0);
136
- _defineProperty(_this, "nodeRef", function (node) {
137
- _this.node = node;
138
- });
139
- _defineProperty(_this, "input", void 0);
140
- _defineProperty(_this, "caret", void 0);
141
- _defineProperty(_this, "focusInput", function () {
142
- var _this$getInputNode;
143
- (_this$getInputNode = _this.getInputNode()) === null || _this$getInputNode === void 0 || _this$getInputNode.focus();
144
- });
145
- _defineProperty(_this, "focus", function () {
146
- _this.focusInput();
147
- });
148
- _defineProperty(_this, "addTag", function (tag) {
149
- var _this$select, _this$select2;
150
- if (tag == null) {
151
- return;
152
- }
153
- var isUniqueTag = _this.state.tags.filter(function (item) {
154
- return tag.key === item.key;
155
- }).length === 0;
156
- (_this$select = _this.select) === null || _this$select === void 0 || _this$select.clear();
157
- (_this$select2 = _this.select) === null || _this$select2 === void 0 || _this$select2.filterValue('');
158
- if (isUniqueTag) {
159
- _this.setState(function (prevState) {
160
- return {
161
- tags: prevState.tags.concat([tag])
162
- };
163
- });
164
- _this.props.onAddTag({
165
- tag
166
- });
167
- _this.setActiveIndex();
168
- }
169
- });
170
- _defineProperty(_this, "clickHandler", function (event) {
171
- var _this$select3;
172
- if (event.target !== _this.node && event.target.parentElement !== _this.node) {
173
- return;
85
+ const POPUP_VERTICAL_SHIFT = 2;
86
+ class TagsInput extends PureComponent {
87
+ static propTypes = {
88
+ className: PropTypes.string,
89
+ tags: PropTypes.array,
90
+ /**
91
+ * Datasource should return array(or promise) of suggestions.
92
+ * Each suggestion should contain key and label fields.
93
+ * DataSource should handle caching and response racing (when later request
94
+ * responded earlier) by himself.
95
+ */
96
+ dataSource: PropTypes.func,
97
+ onAddTag: PropTypes.func,
98
+ onRemoveTag: PropTypes.func,
99
+ customTagComponent: PropTypes.instanceOf(Component),
100
+ maxPopupHeight: PropTypes.number,
101
+ minPopupWidth: PropTypes.number,
102
+ placeholder: PropTypes.string,
103
+ canNotBeEmpty: PropTypes.bool,
104
+ disabled: PropTypes.bool,
105
+ autoOpen: PropTypes.bool,
106
+ renderOptimization: PropTypes.bool,
107
+ filter: PropTypes.oneOfType([PropTypes.bool, PropTypes.shape({
108
+ fn: PropTypes.func
109
+ })]),
110
+ size: PropTypes.string,
111
+ height: PropTypes.string,
112
+ label: PropTypes.node,
113
+ loadingMessage: PropTypes.string,
114
+ notFoundMessage: PropTypes.string,
115
+ hint: PropTypes.node,
116
+ allowAddNewTags: PropTypes.bool
117
+ };
118
+ static defaultProps = {
119
+ dataSource: noop,
120
+ onAddTag: noop,
121
+ onRemoveTag: noop,
122
+ customTagComponent: null,
123
+ maxPopupHeight: 500,
124
+ minPopupWidth: 360,
125
+ canNotBeEmpty: false,
126
+ disabled: false,
127
+ autoOpen: false,
128
+ renderOptimization: true,
129
+ allowAddNewTags: false,
130
+ filter: {
131
+ fn: () => true
132
+ },
133
+ placeholder: 'Select an option',
134
+ size: Size.M
135
+ };
136
+ constructor(props) {
137
+ super(props);
138
+ this.ngModelStateField = TagsInput.ngModelStateField;
139
+ }
140
+ state = {
141
+ tags: [],
142
+ prevTags: null,
143
+ suggestions: [],
144
+ loading: true,
145
+ focused: false,
146
+ query: '',
147
+ activeIndex: 0
148
+ };
149
+ static getDerivedStateFromProps(_ref, _ref2) {
150
+ let {
151
+ tags
152
+ } = _ref;
153
+ let {
154
+ prevTags
155
+ } = _ref2;
156
+ const nextState = {
157
+ prevTags: tags
158
+ };
159
+ if (tags != null && tags !== prevTags) {
160
+ Object.assign(nextState, {
161
+ tags,
162
+ activeIndex: tags.length
163
+ });
164
+ }
165
+ return nextState;
166
+ }
167
+ componentDidMount() {
168
+ if (this.props.autoOpen && !this.props.disabled) {
169
+ this.focusInput();
170
+ this.loadSuggestions();
171
+ this.select?._showPopup();
172
+ }
173
+ }
174
+ static ngModelStateField = 'tags';
175
+ ngModelStateField;
176
+ static contextType = ControlsHeightContext;
177
+ id = this.props.id || getUID('ring-tags-list-');
178
+ node;
179
+ nodeRef = node => {
180
+ this.node = node;
181
+ };
182
+ input;
183
+ caret;
184
+ getInputNode() {
185
+ if (!this.input) {
186
+ this.input = this.select?.filter;
187
+ if (this.input) {
188
+ this.caret = new Caret(this.input);
174
189
  }
175
- (_this$select3 = _this.select) === null || _this$select3 === void 0 || _this$select3._clickHandler();
190
+ }
191
+ return this.input;
192
+ }
193
+ setActiveIndex(activeIndex) {
194
+ this.setState({
195
+ activeIndex
176
196
  });
177
- _defineProperty(_this, "filterExistingTags", function (suggestions) {
178
- var tagsMap = new Map(_this.state.tags.map(function (tag) {
179
- return [tag.key, tag];
197
+ }
198
+ focusInput = () => {
199
+ this.getInputNode()?.focus();
200
+ };
201
+ focus = () => {
202
+ this.focusInput();
203
+ };
204
+ addTag = tag => {
205
+ if (tag == null) {
206
+ return;
207
+ }
208
+ const isUniqueTag = this.state.tags.filter(item => tag.key === item.key).length === 0;
209
+ this.select?.clear();
210
+ this.select?.filterValue('');
211
+ if (isUniqueTag) {
212
+ this.setState(prevState => ({
213
+ tags: prevState.tags.concat([tag])
180
214
  }));
181
- return suggestions.filter(function (suggestion) {
182
- return !tagsMap.has(suggestion.key);
215
+ this.props.onAddTag({
216
+ tag
183
217
  });
184
- });
185
- _defineProperty(_this, "loadSuggestions", function () {
186
- var query = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
218
+ this.setActiveIndex();
219
+ }
220
+ };
221
+ onRemoveTag(tagToRemove) {
222
+ return Promise.resolve(this.props.onRemoveTag({
223
+ tag: tagToRemove
224
+ })).then(() => {
225
+ const tags = this.state.tags.filter(tag => tag !== tagToRemove);
226
+ if (this.node) {
227
+ this.setState({
228
+ tags
229
+ });
230
+ this.focusInput();
231
+ }
232
+ return tags;
233
+ }, this.focusInput);
234
+ }
235
+ clickHandler = event => {
236
+ if (event.target !== this.node && event.target.parentElement !== this.node) {
237
+ return;
238
+ }
239
+ this.select?._clickHandler();
240
+ };
241
+ filterExistingTags = suggestions => {
242
+ const tagsMap = new Map(this.state.tags.map(tag => [tag.key, tag]));
243
+ return suggestions.filter(suggestion => !tagsMap.has(suggestion.key));
244
+ };
245
+ loadSuggestions = (() => {
246
+ var _this = this;
247
+ return function () {
248
+ let query = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
187
249
  return _this.setState({
188
250
  loading: true,
189
251
  query
190
- }, /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
191
- var suggestionsResult, allSuggestions, suggestions;
192
- return _regeneratorRuntime().wrap(function _callee$(_context) {
193
- while (1) switch (_context.prev = _context.next) {
194
- case 0:
195
- _context.prev = 0;
196
- suggestionsResult = _this.props.dataSource({
197
- query
198
- });
199
- if (!Array.isArray(suggestionsResult)) {
200
- _context.next = 6;
201
- break;
202
- }
203
- _context.t0 = suggestionsResult;
204
- _context.next = 9;
205
- break;
206
- case 6:
207
- _context.next = 8;
208
- return suggestionsResult;
209
- case 8:
210
- _context.t0 = _context.sent;
211
- case 9:
212
- allSuggestions = _context.t0;
213
- suggestions = _this.filterExistingTags(allSuggestions);
214
- if (_this.node && query === _this.state.query) {
215
- _this.setState({
216
- suggestions,
217
- loading: false
218
- });
219
- }
220
- _context.next = 17;
221
- break;
222
- case 14:
223
- _context.prev = 14;
224
- _context.t1 = _context["catch"](0);
225
- _this.setState({
226
- loading: false
227
- });
228
- case 17:
229
- case "end":
230
- return _context.stop();
231
- }
232
- }, _callee, null, [[0, 14]]);
233
- })));
234
- });
235
- _defineProperty(_this, "_focusHandler", function () {
236
- _this.setActiveIndex(null);
237
- _this.setState({
238
- focused: true
239
- });
240
- });
241
- _defineProperty(_this, "_blurHandler", function () {
242
- _this.setState({
243
- focused: false
244
- });
245
- });
246
- _defineProperty(_this, "selectTag", function (moveForward) {
247
- var activeIndex = typeof _this.state.activeIndex === 'number' ? _this.state.activeIndex : _this.state.tags.length + 1;
248
- var newActiveIndex = activeIndex + (moveForward ? 1 : -1);
249
- if (newActiveIndex >= _this.state.tags.length) {
250
- newActiveIndex = _this.state.tags.length - 1;
251
- } else if (newActiveIndex < 0) {
252
- newActiveIndex = 0;
253
- }
254
- if (_this.state.activeIndex !== newActiveIndex) {
255
- _this.setActiveIndex(newActiveIndex);
256
- }
257
- });
258
- _defineProperty(_this, "handleKeyDown", function (event) {
259
- var _this$select4;
260
- var key = getEventKey(event);
261
- var isInputFocused = function isInputFocused() {
262
- var _this$getInputNode$ta, _this$getInputNode2;
263
- return event.target instanceof Element && event.target.matches((_this$getInputNode$ta = (_this$getInputNode2 = _this.getInputNode()) === null || _this$getInputNode2 === void 0 ? void 0 : _this$getInputNode2.tagName) !== null && _this$getInputNode$ta !== void 0 ? _this$getInputNode$ta : '');
264
- };
265
- if (key === ' ' && _this.props.allowAddNewTags) {
266
- var _this$getInputNode3;
267
- event.stopPropagation();
268
- var value = (_this$getInputNode3 = _this.getInputNode()) === null || _this$getInputNode3 === void 0 ? void 0 : _this$getInputNode3.value;
269
- if (value != null && value !== '') {
270
- _this.handleTagCreation(value);
271
- }
272
- return true;
273
- }
274
- if ((_this$select4 = _this.select) !== null && _this$select4 !== void 0 && (_this$select4 = _this$select4._popup) !== null && _this$select4 !== void 0 && _this$select4.isVisible()) {
275
- return true;
276
- }
277
- if (key === 'ArrowLeft') {
278
- if (_this.getInputNode() && _this.caret != null && Number(_this.caret.getPosition()) > 0) {
279
- return true;
280
- }
281
- _this.selectTag();
282
- return false;
283
- }
284
- if (key === 'ArrowRight' && !isInputFocused()) {
285
- if (_this.state.activeIndex === _this.state.tags.length - 1) {
286
- if (!_this.props.disabled) {
287
- var _this$getInputNode4;
288
- (_this$getInputNode4 = _this.getInputNode()) === null || _this$getInputNode4 === void 0 || _this$getInputNode4.focus();
289
- _this.setActiveIndex();
252
+ }, async () => {
253
+ try {
254
+ const suggestionsResult = _this.props.dataSource({
255
+ query
256
+ });
257
+ const allSuggestions = Array.isArray(suggestionsResult) ? suggestionsResult : await suggestionsResult;
258
+ const suggestions = _this.filterExistingTags(allSuggestions);
259
+ if (_this.node && query === _this.state.query) {
260
+ _this.setState({
261
+ suggestions,
262
+ loading: false
263
+ });
290
264
  }
291
- } else {
292
- _this.selectTag(true);
293
- }
294
- return false;
295
- }
296
- if (!_this.props.disabled) {
297
- var _this$getInputNode5;
298
- if (key === 'Backspace' && !((_this$getInputNode5 = _this.getInputNode()) !== null && _this$getInputNode5 !== void 0 && _this$getInputNode5.value)) {
299
- var _this$select5;
300
- event.preventDefault();
301
- var tagsLength = _this.state.tags.length;
302
- (_this$select5 = _this.select) === null || _this$select5 === void 0 || _this$select5._hidePopup(true); // otherwise confirmation may be overlapped by popup
303
- _this.onRemoveTag(_this.state.tags[tagsLength - 1]);
304
- return false;
305
- }
306
- if ((key === 'Delete' || key === 'Backspace') && _this.state.activeIndex != null && _this.state.tags[_this.state.activeIndex]) {
307
- _this.onRemoveTag(_this.state.tags[_this.state.activeIndex]).then(function () {
308
- return _this.selectTag(true);
265
+ } catch (e) {
266
+ _this.setState({
267
+ loading: false
309
268
  });
310
- return false;
311
269
  }
312
- }
313
- return true;
314
- });
315
- _defineProperty(_this, "handleClick", memoize(function (tag) {
316
- return function () {
317
- _this.setActiveIndex(_this.state.tags.indexOf(tag));
318
- };
319
- }));
320
- _defineProperty(_this, "handleRemove", memoize(function (tag) {
321
- return function () {
322
- return _this.onRemoveTag(tag);
323
- };
324
- }));
325
- _defineProperty(_this, "handleTagCreation", function (label) {
326
- _this.addTag({
327
- key: label,
328
- label
329
270
  });
271
+ };
272
+ })();
273
+ _focusHandler = () => {
274
+ this.setActiveIndex(null);
275
+ this.setState({
276
+ focused: true
330
277
  });
331
- _defineProperty(_this, "select", void 0);
332
- _defineProperty(_this, "selectRef", function (el) {
333
- _this.select = el;
278
+ };
279
+ _blurHandler = () => {
280
+ this.setState({
281
+ focused: false
334
282
  });
335
- _this.ngModelStateField = TagsInput.ngModelStateField;
336
- return _this;
337
- }
338
- _inherits(TagsInput, _PureComponent);
339
- return _createClass(TagsInput, [{
340
- key: "componentDidMount",
341
- value: function componentDidMount() {
342
- if (this.props.autoOpen && !this.props.disabled) {
343
- var _this$select6;
344
- this.focusInput();
345
- this.loadSuggestions();
346
- (_this$select6 = this.select) === null || _this$select6 === void 0 || _this$select6._showPopup();
347
- }
283
+ };
284
+ selectTag = moveForward => {
285
+ const activeIndex = typeof this.state.activeIndex === 'number' ? this.state.activeIndex : this.state.tags.length + 1;
286
+ let newActiveIndex = activeIndex + (moveForward ? 1 : -1);
287
+ if (newActiveIndex >= this.state.tags.length) {
288
+ newActiveIndex = this.state.tags.length - 1;
289
+ } else if (newActiveIndex < 0) {
290
+ newActiveIndex = 0;
348
291
  }
349
- }, {
350
- key: "getInputNode",
351
- value: function getInputNode() {
352
- if (!this.input) {
353
- var _this$select7;
354
- this.input = (_this$select7 = this.select) === null || _this$select7 === void 0 ? void 0 : _this$select7.filter;
355
- if (this.input) {
356
- this.caret = new Caret(this.input);
357
- }
358
- }
359
- return this.input;
292
+ if (this.state.activeIndex !== newActiveIndex) {
293
+ this.setActiveIndex(newActiveIndex);
360
294
  }
361
- }, {
362
- key: "setActiveIndex",
363
- value: function setActiveIndex(activeIndex) {
364
- this.setState({
365
- activeIndex
366
- });
295
+ };
296
+ handleKeyDown = event => {
297
+ const key = getEventKey(event);
298
+ const isInputFocused = () => {
299
+ var _this$getInputNode$ta;
300
+ return event.target instanceof Element && event.target.matches((_this$getInputNode$ta = this.getInputNode()?.tagName) !== null && _this$getInputNode$ta !== void 0 ? _this$getInputNode$ta : '');
301
+ };
302
+ if (key === ' ' && this.props.allowAddNewTags) {
303
+ event.stopPropagation();
304
+ const value = this.getInputNode()?.value;
305
+ if (value != null && value !== '') {
306
+ this.handleTagCreation(value);
307
+ }
308
+ return true;
367
309
  }
368
- }, {
369
- key: "onRemoveTag",
370
- value: function onRemoveTag(tagToRemove) {
371
- var _this2 = this;
372
- return Promise.resolve(this.props.onRemoveTag({
373
- tag: tagToRemove
374
- })).then(function () {
375
- var tags = _this2.state.tags.filter(function (tag) {
376
- return tag !== tagToRemove;
377
- });
378
- if (_this2.node) {
379
- _this2.setState({
380
- tags
381
- });
382
- _this2.focusInput();
383
- }
384
- return tags;
385
- }, this.focusInput);
310
+ if (this.select?._popup?.isVisible()) {
311
+ return true;
386
312
  }
387
- }, {
388
- key: "render",
389
- value: function render() {
390
- var _this$state = this.state,
391
- focused = _this$state.focused,
392
- tags = _this$state.tags,
393
- activeIndex = _this$state.activeIndex;
394
- var _this$props = this.props,
395
- disabled = _this$props.disabled,
396
- canNotBeEmpty = _this$props.canNotBeEmpty,
397
- allowAddNewTags = _this$props.allowAddNewTags,
398
- filter = _this$props.filter,
399
- size = _this$props.size,
400
- labelType = _this$props.labelType,
401
- _this$props$height = _this$props.height,
402
- height = _this$props$height === void 0 ? this.context : _this$props$height,
403
- label = _this$props.label;
404
- var classes = classNames(modules_5aa8aaf3.tagsInput, [modules_88cfaf40["size".concat(size)]], [modules_88cfaf40["height".concat(height)]], {
405
- [modules_5aa8aaf3.tagsInputDisabled]: disabled,
406
- [modules_5aa8aaf3.tagsInputFocused]: focused
407
- }, this.props.className);
408
- return /*#__PURE__*/React.createElement("div", {
409
- // it transfers focus to input
410
- role: "presentation",
411
- className: classes,
412
- onKeyDown: this.handleKeyDown,
413
- onClick: this.clickHandler,
414
- ref: this.nodeRef
415
- }, label && /*#__PURE__*/React.createElement(ControlLabel, {
416
- htmlFor: this.id,
417
- disabled: disabled,
418
- type: labelType
419
- }, label), /*#__PURE__*/React.createElement(TagsList, {
420
- tags: tags,
421
- activeIndex: activeIndex,
422
- disabled: disabled,
423
- canNotBeEmpty: canNotBeEmpty,
424
- handleRemove: this.handleRemove,
425
- className: modules_5aa8aaf3.tagsList,
426
- tagClassName: modules_5aa8aaf3.tag,
427
- handleClick: this.handleClick,
428
- customTagComponent: this.props.customTagComponent
429
- }, /*#__PURE__*/React.createElement(Select, {
430
- id: this.id,
431
- ref: this.selectRef,
432
- size: Select.Size.AUTO,
433
- type: Select.Type.INPUT_WITHOUT_CONTROLS,
434
- inputPlaceholder: this.props.placeholder,
435
- data: this.state.suggestions,
436
- className: classNames(modules_5aa8aaf3.tagsSelect),
437
- onSelect: this.addTag,
438
- onFocus: this._focusHandler,
439
- onBlur: this._blurHandler,
440
- renderOptimization: this.props.renderOptimization,
441
- add: allowAddNewTags ? {
442
- prefix: 'Add new tag'
443
- } : undefined,
444
- onAdd: allowAddNewTags ? this.handleTagCreation : undefined,
445
- filter: filter,
446
- maxHeight: this.props.maxPopupHeight,
447
- minWidth: this.props.minPopupWidth,
448
- top: POPUP_VERTICAL_SHIFT,
449
- loading: this.state.loading,
450
- onFilter: this.loadSuggestions,
451
- onBeforeOpen: this.loadSuggestions,
452
- onKeyDown: this.handleKeyDown,
453
- disabled: this.props.disabled,
454
- loadingMessage: this.props.loadingMessage,
455
- notFoundMessage: this.props.notFoundMessage,
456
- hint: this.props.hint
457
- })));
313
+ if (key === 'ArrowLeft') {
314
+ if (this.getInputNode() && this.caret != null && Number(this.caret.getPosition()) > 0) {
315
+ return true;
316
+ }
317
+ this.selectTag();
318
+ return false;
458
319
  }
459
- }], [{
460
- key: "getDerivedStateFromProps",
461
- value: function getDerivedStateFromProps(_ref2, _ref3) {
462
- var tags = _ref2.tags;
463
- var prevTags = _ref3.prevTags;
464
- var nextState = {
465
- prevTags: tags
466
- };
467
- if (tags != null && tags !== prevTags) {
468
- Object.assign(nextState, {
469
- tags,
470
- activeIndex: tags.length
471
- });
320
+ if (key === 'ArrowRight' && !isInputFocused()) {
321
+ if (this.state.activeIndex === this.state.tags.length - 1) {
322
+ if (!this.props.disabled) {
323
+ this.getInputNode()?.focus();
324
+ this.setActiveIndex();
325
+ }
326
+ } else {
327
+ this.selectTag(true);
472
328
  }
473
- return nextState;
329
+ return false;
474
330
  }
475
- }]);
476
- }(PureComponent);
477
- _defineProperty(TagsInput, "propTypes", {
478
- className: PropTypes.string,
479
- tags: PropTypes.array,
480
- /**
481
- * Datasource should return array(or promise) of suggestions.
482
- * Each suggestion should contain key and label fields.
483
- * DataSource should handle caching and response racing (when later request
484
- * responded earlier) by himself.
485
- */
486
- dataSource: PropTypes.func,
487
- onAddTag: PropTypes.func,
488
- onRemoveTag: PropTypes.func,
489
- customTagComponent: PropTypes.instanceOf(Component),
490
- maxPopupHeight: PropTypes.number,
491
- minPopupWidth: PropTypes.number,
492
- placeholder: PropTypes.string,
493
- canNotBeEmpty: PropTypes.bool,
494
- disabled: PropTypes.bool,
495
- autoOpen: PropTypes.bool,
496
- renderOptimization: PropTypes.bool,
497
- filter: PropTypes.oneOfType([PropTypes.bool, PropTypes.shape({
498
- fn: PropTypes.func
499
- })]),
500
- size: PropTypes.string,
501
- height: PropTypes.string,
502
- label: PropTypes.node,
503
- loadingMessage: PropTypes.string,
504
- notFoundMessage: PropTypes.string,
505
- hint: PropTypes.node,
506
- allowAddNewTags: PropTypes.bool
507
- });
508
- _defineProperty(TagsInput, "defaultProps", {
509
- dataSource: noop,
510
- onAddTag: noop,
511
- onRemoveTag: noop,
512
- customTagComponent: null,
513
- maxPopupHeight: 500,
514
- minPopupWidth: 360,
515
- canNotBeEmpty: false,
516
- disabled: false,
517
- autoOpen: false,
518
- renderOptimization: true,
519
- allowAddNewTags: false,
520
- filter: {
521
- fn: function fn() {
522
- return true;
331
+ if (!this.props.disabled) {
332
+ if (key === 'Backspace' && !this.getInputNode()?.value) {
333
+ event.preventDefault();
334
+ const tagsLength = this.state.tags.length;
335
+ this.select?._hidePopup(true); // otherwise confirmation may be overlapped by popup
336
+ this.onRemoveTag(this.state.tags[tagsLength - 1]);
337
+ return false;
338
+ }
339
+ if ((key === 'Delete' || key === 'Backspace') && this.state.activeIndex != null && this.state.tags[this.state.activeIndex]) {
340
+ this.onRemoveTag(this.state.tags[this.state.activeIndex]).then(() => this.selectTag(true));
341
+ return false;
342
+ }
523
343
  }
524
- },
525
- placeholder: 'Select an option',
526
- size: Size.M
527
- });
528
- _defineProperty(TagsInput, "ngModelStateField", 'tags');
529
- _defineProperty(TagsInput, "contextType", ControlsHeightContext);
530
- var RerenderableTagsInput = rerenderHOC(TagsInput);
344
+ return true;
345
+ };
346
+ handleClick = memoize(tag => () => {
347
+ this.setActiveIndex(this.state.tags.indexOf(tag));
348
+ });
349
+ handleRemove = memoize(tag => () => this.onRemoveTag(tag));
350
+ handleTagCreation = label => {
351
+ this.addTag({
352
+ key: label,
353
+ label
354
+ });
355
+ };
356
+ select;
357
+ selectRef = el => {
358
+ this.select = el;
359
+ };
360
+ render() {
361
+ const {
362
+ focused,
363
+ tags,
364
+ activeIndex
365
+ } = this.state;
366
+ const {
367
+ disabled,
368
+ canNotBeEmpty,
369
+ allowAddNewTags,
370
+ filter,
371
+ size,
372
+ labelType,
373
+ height = this.context,
374
+ label
375
+ } = this.props;
376
+ const classes = classNames(modules_5aa8aaf3.tagsInput, [modules_88cfaf40[`size${size}`]], [modules_88cfaf40[`height${height}`]], {
377
+ [modules_5aa8aaf3.tagsInputDisabled]: disabled,
378
+ [modules_5aa8aaf3.tagsInputFocused]: focused
379
+ }, this.props.className);
380
+ return /*#__PURE__*/React.createElement("div", {
381
+ // it transfers focus to input
382
+ role: "presentation",
383
+ className: classes,
384
+ onKeyDown: this.handleKeyDown,
385
+ onClick: this.clickHandler,
386
+ ref: this.nodeRef
387
+ }, label && /*#__PURE__*/React.createElement(ControlLabel, {
388
+ htmlFor: this.id,
389
+ disabled: disabled,
390
+ type: labelType
391
+ }, label), /*#__PURE__*/React.createElement(TagsList, {
392
+ tags: tags,
393
+ activeIndex: activeIndex,
394
+ disabled: disabled,
395
+ canNotBeEmpty: canNotBeEmpty,
396
+ handleRemove: this.handleRemove,
397
+ className: modules_5aa8aaf3.tagsList,
398
+ tagClassName: modules_5aa8aaf3.tag,
399
+ handleClick: this.handleClick,
400
+ customTagComponent: this.props.customTagComponent
401
+ }, /*#__PURE__*/React.createElement(Select, {
402
+ id: this.id,
403
+ ref: this.selectRef,
404
+ size: Select.Size.AUTO,
405
+ type: Select.Type.INPUT_WITHOUT_CONTROLS,
406
+ inputPlaceholder: this.props.placeholder,
407
+ data: this.state.suggestions,
408
+ className: classNames(modules_5aa8aaf3.tagsSelect),
409
+ onSelect: this.addTag,
410
+ onFocus: this._focusHandler,
411
+ onBlur: this._blurHandler,
412
+ renderOptimization: this.props.renderOptimization,
413
+ add: allowAddNewTags ? {
414
+ prefix: 'Add new tag'
415
+ } : undefined,
416
+ onAdd: allowAddNewTags ? this.handleTagCreation : undefined,
417
+ filter: filter,
418
+ maxHeight: this.props.maxPopupHeight,
419
+ minWidth: this.props.minPopupWidth,
420
+ top: POPUP_VERTICAL_SHIFT,
421
+ loading: this.state.loading,
422
+ onFilter: this.loadSuggestions,
423
+ onBeforeOpen: this.loadSuggestions,
424
+ onKeyDown: this.handleKeyDown,
425
+ disabled: this.props.disabled,
426
+ loadingMessage: this.props.loadingMessage,
427
+ notFoundMessage: this.props.notFoundMessage,
428
+ hint: this.props.hint
429
+ })));
430
+ }
431
+ }
432
+ const RerenderableTagsInput = rerenderHOC(TagsInput);
531
433
 
532
434
  export { RerenderableTagsInput, TagsInput as default };