@jetbrains/ring-ui-built 6.0.30 → 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 (226) hide show
  1. package/components/_helpers/_rollupPluginBabelHelpers.js +7 -629
  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/style.css +1 -1
  191. package/components/tab-trap/tab-trap.js +122 -153
  192. package/components/table/cell.js +14 -26
  193. package/components/table/disable-hover-hoc.js +33 -51
  194. package/components/table/header-cell.js +64 -89
  195. package/components/table/header.js +104 -132
  196. package/components/table/multitable.js +107 -125
  197. package/components/table/row-with-focus-sensor.js +25 -69
  198. package/components/table/row.js +175 -216
  199. package/components/table/selection-adapter.js +1 -3
  200. package/components/table/selection-shortcuts-hoc.js +180 -181
  201. package/components/table/selection.js +156 -226
  202. package/components/table/smart-table.js +50 -88
  203. package/components/table/table.js +289 -358
  204. package/components/tabs/collapsible-more.js +46 -79
  205. package/components/tabs/collapsible-tab.js +31 -38
  206. package/components/tabs/collapsible-tabs.js +88 -153
  207. package/components/tabs/custom-item.js +4 -2
  208. package/components/tabs/dumb-tabs.js +74 -117
  209. package/components/tabs/smart-tabs.js +29 -69
  210. package/components/tabs/tab-link.js +1 -5
  211. package/components/tabs/tab.js +19 -31
  212. package/components/tabs/tabs.js +0 -31
  213. package/components/tag/tag.js +133 -173
  214. package/components/tags-input/tags-input.js +329 -427
  215. package/components/tags-list/tags-list.js +57 -78
  216. package/components/text/text.js +28 -39
  217. package/components/toggle/toggle.js +56 -70
  218. package/components/tooltip/tooltip.js +146 -190
  219. package/components/user-agreement/service.js +228 -371
  220. package/components/user-agreement/toolbox.eula.js +160 -1
  221. package/components/user-agreement/user-agreement.js +85 -120
  222. package/components/user-card/card.js +0 -29
  223. package/components/user-card/smart-user-card-tooltip.js +51 -111
  224. package/components/user-card/tooltip.js +47 -84
  225. package/components/user-card/user-card.js +0 -29
  226. package/package.json +1 -1
@@ -1,7 +1,4 @@
1
- import { _ as _defineProperty, a as _inherits, b as _createClass, d as _objectSpread2, c as _objectWithoutProperties, e as _extends, f as _classCallCheck, g as _callSuper } from '../_helpers/_rollupPluginBabelHelpers.js';
2
- import 'core-js/modules/es.array.map.js';
3
- import 'core-js/modules/es.array.reduce.js';
4
- import 'core-js/modules/es.object.to-string.js';
1
+ import { _ as _extends } from '../_helpers/_rollupPluginBabelHelpers.js';
5
2
  import React, { Component } from 'react';
6
3
  import PropTypes from 'prop-types';
7
4
  import { isAfter } from 'date-fns/isAfter';
@@ -16,17 +13,8 @@ import Years from './years.js';
16
13
  import Weekdays from './weekdays.js';
17
14
  import { dateType, parseTime } from './consts.js';
18
15
  import { m as modules_0c7b7d96 } from '../_helpers/date-picker.js';
19
- import 'core-js/modules/es.array.iterator.js';
20
- import 'core-js/modules/es.map.js';
21
- import 'core-js/modules/es.weak-map.js';
22
- import 'core-js/modules/web.dom-collections.iterator.js';
23
- import 'core-js/modules/es.array.concat.js';
24
- import 'core-js/modules/es.array.filter.js';
25
- import 'core-js/modules/es.regexp.exec.js';
26
- import 'core-js/modules/es.string.replace.js';
27
16
  import 'classnames';
28
17
  import '../_helpers/input.js';
29
- import 'core-js/modules/es.object.values.js';
30
18
  import '@jetbrains/icons/close-12px';
31
19
  import '../global/prop-types.js';
32
20
  import '../button/button.js';
@@ -35,17 +23,13 @@ import '../icon/icon.js';
35
23
  import 'util-deprecate';
36
24
  import '../icon/icon__constants.js';
37
25
  import '../_helpers/icon__svg.js';
38
- import 'core-js/modules/es.string.starts-with.js';
39
26
  import '../link/clickableLink.js';
40
27
  import '../global/controls-height.js';
41
28
  import '../_helpers/button__classes.js';
42
29
  import '../global/get-uid.js';
43
- import 'core-js/modules/es.regexp.to-string.js';
44
30
  import '../i18n/i18n-context.js';
45
31
  import '../i18n/i18n.js';
46
- import 'core-js/modules/es.set.js';
47
32
  import '../global/composeRefs.js';
48
- import 'core-js/modules/web.dom-collections.for-each.js';
49
33
  import '../control-label/control-label.js';
50
34
  import 'date-fns/addMonths';
51
35
  import 'date-fns/getDay';
@@ -61,12 +45,8 @@ import 'date-fns/addDays';
61
45
  import 'date-fns/format';
62
46
  import 'date-fns/setDay';
63
47
  import './day.js';
64
- import 'core-js/modules/es.array.includes.js';
65
- import 'core-js/modules/es.string.includes.js';
66
48
  import 'date-fns/getDate';
67
49
  import 'date-fns/isToday';
68
- import 'core-js/modules/es.array.index-of.js';
69
- import 'core-js/modules/es.array.slice.js';
70
50
  import 'date-fns/add';
71
51
  import './month-names.js';
72
52
  import 'date-fns/isThisMonth';
@@ -80,409 +60,384 @@ import 'date-fns/isSameYear';
80
60
  import 'date-fns/isThisYear';
81
61
  import 'date-fns/setYear';
82
62
 
83
- var _excluded = ["from", "to", "date", "time"];
84
- var scrollExpDelay = 10;
85
- var DatePopup = /*#__PURE__*/function (_Component) {
86
- function DatePopup(props) {
87
- var _this;
88
- _classCallCheck(this, DatePopup);
89
- _this = _callSuper(this, DatePopup, [props]);
90
- _defineProperty(_this, "_scrollDate", void 0);
91
- _defineProperty(_this, "_scrollTS", void 0);
92
- _defineProperty(_this, "isInTimeMode", function () {
93
- return !_this.props.range && _this.props.withTime || false;
94
- });
95
- _defineProperty(_this, "componentRef", /*#__PURE__*/React.createRef());
96
- _defineProperty(_this, "handleWheel", function (e) {
97
- if (e.cancelable) {
98
- e.preventDefault();
99
- }
100
- });
101
- _defineProperty(_this, "isValidDate", function (parsedText) {
102
- var minDate = _this.parse(_this.props.minDate, 'date');
103
- var maxDate = _this.parse(_this.props.maxDate, 'date');
104
- if (parsedText) {
105
- return !(minDate && isBefore(parsedText, minDate) || maxDate && isAfter(parsedText, maxDate));
106
- }
107
- return false;
108
- });
109
- _defineProperty(_this, "scheduleScroll", function () {
110
- var current = _this.state.scrollDate && _this.parse(_this.state.scrollDate, 'date') || _this.parse(_this.props[_this.state.active], 'date') || new Date();
111
- var goal = _this._scrollDate;
112
- if (!current || !goal || DatePopup.sameDay(goal, current)) {
113
- _this._scrollDate = null;
114
- _this._scrollTS = null;
115
- return;
116
- }
117
- if (_this._scrollTS) {
118
- var diff = goal - Number(current);
119
- var dt = Date.now() - _this._scrollTS;
120
- var next = goal - diff * Math.pow(Math.E, -dt / scrollExpDelay);
121
- _this.setState({
122
- scrollDate: next
123
- });
124
- }
125
- _this._scrollTS = Date.now();
126
- window.requestAnimationFrame(_this.scheduleScroll);
127
- });
128
- _defineProperty(_this, "scrollTo", function (scrollDate) {
129
- _this._scrollDate = scrollDate;
130
- if (!_this._scrollTS) {
131
- _this.scheduleScroll();
132
- }
133
- });
134
- _defineProperty(_this, "hoverHandler", function (hoverDate) {
135
- return _this.setState({
136
- hoverDate
137
- });
138
- });
139
- _defineProperty(_this, "handleActivate", memoize(function (name) {
140
- return function () {
141
- return _this.setState({
142
- active: name
143
- });
144
- };
145
- }));
146
- _defineProperty(_this, "handleInput", function (text, name) {
147
- if (name !== 'time') {
148
- var parsed = _this.parse(text, name);
149
- if (_this.isValidDate(parsed)) {
150
- _this.scrollTo(Number(parsed));
151
- }
152
- }
153
- _this.setState({
154
- text,
155
- hoverDate: null
156
- });
157
- });
158
- _defineProperty(_this, "handleConfirm", memoize(function (name) {
159
- return function () {
160
- return _this.confirm(name);
161
- };
162
- }));
163
- _defineProperty(_this, "selectHandler", function (date) {
164
- if (_this.isInTimeMode()) {
165
- _this.setState({
166
- active: 'time'
167
- }, function () {
168
- return _this.select({
169
- date
170
- });
171
- });
172
- } else {
173
- _this.select({
174
- [_this.state.active]: date
175
- });
176
- }
177
- });
178
- _defineProperty(_this, "handleScroll", function (scrollDate) {
179
- return _this.setState({
180
- scrollDate
181
- });
182
- });
183
- _defineProperty(_this, "onClear", function (e) {
184
- var _this$props$onClear, _this$props, _this$componentRef$cu;
185
- var changes;
186
- if (_this.props.range) {
187
- changes = {
188
- from: null,
189
- to: null
190
- };
191
- } else {
192
- changes = {
193
- date: null
194
- };
195
- }
196
- _this.select(changes);
197
- (_this$props$onClear = (_this$props = _this.props).onClear) === null || _this$props$onClear === void 0 || _this$props$onClear.call(_this$props, e);
198
- (_this$componentRef$cu = _this.componentRef.current) === null || _this$componentRef$cu === void 0 || (_this$componentRef$cu = _this$componentRef$cu.querySelector('input')) === null || _this$componentRef$cu === void 0 || _this$componentRef$cu.focus();
199
- });
200
- var defaultState = {
63
+ const scrollExpDelay = 10;
64
+ class DatePopup extends Component {
65
+ static sameDay(next, prev) {
66
+ if (next && prev) {
67
+ return isSameDay(next, prev);
68
+ }
69
+ return next === prev;
70
+ }
71
+ static propTypes = {
72
+ className: PropTypes.string,
73
+ date: dateType,
74
+ range: PropTypes.bool,
75
+ withTime: PropTypes.bool,
76
+ time: PropTypes.string,
77
+ from: dateType,
78
+ to: dateType,
79
+ renderAfterCalendar: PropTypes.func,
80
+ displayFormat: PropTypes.func,
81
+ parseDateInput: PropTypes.func,
82
+ onChange: PropTypes.func,
83
+ onComplete: PropTypes.func,
84
+ onClear: PropTypes.func,
85
+ minDate: dateType,
86
+ maxDate: dateType,
87
+ fromPlaceholder: PropTypes.string,
88
+ toPlaceholder: PropTypes.string,
89
+ timePlaceholder: PropTypes.string,
90
+ locale: PropTypes.object
91
+ };
92
+ static defaultProps = {
93
+ onChange() {}
94
+ };
95
+ constructor(props) {
96
+ super(props);
97
+ const defaultState = {
201
98
  text: null,
202
99
  hoverDate: null,
203
100
  scrollDate: null
204
101
  };
205
- var range = props.range,
206
- withTime = props.withTime;
102
+ const {
103
+ range,
104
+ withTime
105
+ } = props;
207
106
  if (!range) {
208
- var parsedDate = _this.parse(props.date, 'date');
209
- var active = withTime && parsedDate && !props.time ? 'time' : 'date';
210
- _this.state = _objectSpread2(_objectSpread2({}, defaultState), {}, {
107
+ const parsedDate = this.parse(props.date, 'date');
108
+ const active = withTime && parsedDate && !props.time ? 'time' : 'date';
109
+ this.state = {
110
+ ...defaultState,
211
111
  active
212
- });
112
+ };
213
113
  } else if (props.from && !props.to) {
214
- _this.state = _objectSpread2(_objectSpread2({}, defaultState), {}, {
114
+ this.state = {
115
+ ...defaultState,
215
116
  active: 'to'
216
- });
117
+ };
217
118
  } else {
218
- _this.state = _objectSpread2(_objectSpread2({}, defaultState), {}, {
119
+ this.state = {
120
+ ...defaultState,
219
121
  active: 'from'
220
- });
122
+ };
221
123
  }
222
- return _this;
223
124
  }
224
- _inherits(DatePopup, _Component);
225
- return _createClass(DatePopup, [{
226
- key: "componentDidMount",
227
- value: function componentDidMount() {
228
- if (this.componentRef.current) {
229
- this.componentRef.current.addEventListener('wheel', this.handleWheel);
230
- }
125
+ componentDidMount() {
126
+ if (this.componentRef.current) {
127
+ this.componentRef.current.addEventListener('wheel', this.handleWheel);
231
128
  }
232
- }, {
233
- key: "componentDidUpdate",
234
- value: function componentDidUpdate(prevProps, prevState) {
235
- if (this.state.active !== prevState.active) {
236
- if (this.state.text && prevState.active) {
237
- this.confirm(prevState.active);
238
- }
239
- this.setState({
240
- text: null
241
- });
129
+ }
130
+ componentDidUpdate(prevProps, prevState) {
131
+ if (this.state.active !== prevState.active) {
132
+ if (this.state.text && prevState.active) {
133
+ this.confirm(prevState.active);
242
134
  }
135
+ this.setState({
136
+ text: null
137
+ });
243
138
  }
244
- }, {
245
- key: "componentWillUnmount",
246
- value: function componentWillUnmount() {
247
- if (this.componentRef.current) {
248
- this.componentRef.current.removeEventListener('wheel', this.handleWheel);
249
- }
139
+ }
140
+ componentWillUnmount() {
141
+ if (this.componentRef.current) {
142
+ this.componentRef.current.removeEventListener('wheel', this.handleWheel);
250
143
  }
251
- }, {
252
- key: "parse",
253
- value: function parse(text, type) {
254
- if (type === 'time') {
255
- return parseTime(String(text));
256
- }
257
- return this.props.parseDateInput(text);
144
+ }
145
+ _scrollDate;
146
+ _scrollTS;
147
+ isInTimeMode = () => !this.props.range && this.props.withTime || false;
148
+ componentRef = /*#__PURE__*/React.createRef();
149
+ handleWheel = e => {
150
+ if (e.cancelable) {
151
+ e.preventDefault();
152
+ }
153
+ };
154
+ parse(text, type) {
155
+ if (type === 'time') {
156
+ return parseTime(String(text));
258
157
  }
259
- }, {
260
- key: "select",
261
- value: function select(changes) {
262
- var _this$props2 = this.props,
263
- range = _this$props2.range,
264
- withTime = _this$props2.withTime;
265
- var prevActive = this.state.active;
266
- if (!range && !withTime) {
267
- this.setState({
268
- text: null,
269
- scrollDate: null
270
- });
271
- var adjustedDate = changes.date && set(new Date(), {
272
- year: changes.date.getFullYear(),
273
- month: changes.date.getMonth(),
274
- date: changes.date.getDate()
275
- });
276
- this.props.onChange(adjustedDate);
158
+ return this.props.parseDateInput(text);
159
+ }
160
+ select(changes) {
161
+ const {
162
+ range,
163
+ withTime
164
+ } = this.props;
165
+ const prevActive = this.state.active;
166
+ if (!range && !withTime) {
167
+ this.setState({
168
+ text: null,
169
+ scrollDate: null
170
+ });
171
+ const adjustedDate = changes.date && set(new Date(), {
172
+ year: changes.date.getFullYear(),
173
+ month: changes.date.getMonth(),
174
+ date: changes.date.getDate()
175
+ });
176
+ this.props.onChange(adjustedDate);
177
+ this.props.onComplete();
178
+ } else if (!range && withTime) {
179
+ const date = this.parse(this.props.date, 'date');
180
+ const time = this.parse(this.props.time, 'time');
181
+ const changeToSubmit = {
182
+ date: changes.date || date,
183
+ time: changes.time || time
184
+ };
185
+ this.setState({
186
+ active: changes.date ? 'time' : 'date',
187
+ text: null,
188
+ scrollDate: null
189
+ });
190
+ this.props.onChange(changeToSubmit);
191
+ if (!changes.date && prevActive === 'time' && changeToSubmit.date && changeToSubmit.time) {
277
192
  this.props.onComplete();
278
- } else if (!range && withTime) {
279
- var date = this.parse(this.props.date, 'date');
280
- var time = this.parse(this.props.time, 'time');
281
- var changeToSubmit = {
282
- date: changes.date || date,
283
- time: changes.time || time
284
- };
285
- this.setState({
286
- active: changes.date ? 'time' : 'date',
287
- text: null,
288
- scrollDate: null
289
- });
290
- this.props.onChange(changeToSubmit);
291
- if (!changes.date && prevActive === 'time' && changeToSubmit.date && changeToSubmit.time) {
292
- this.props.onComplete();
293
- }
294
- } else {
295
- var _this$props$changes = _objectSpread2(_objectSpread2({}, this.props), changes),
296
- from = _this$props$changes.from,
297
- to = _this$props$changes.to;
298
- from = this.parse(from, 'from');
299
- to = this.parse(to, 'to');
300
- // proceed to setting the end by default
301
- var active = 'to';
302
- var complete = false;
303
- // end is before beginning
304
- if (from && to && isAfter(startOfDay(from), startOfDay(to))) {
305
- // ignore the old end when beginning is changed
306
- if (changes.from) {
307
- to = null;
308
- // treat range as reverse when end is changed
309
- } else if (changes.to) {
310
- to = from;
311
- from = changes.to;
312
- }
193
+ }
194
+ } else {
195
+ let {
196
+ from,
197
+ to
198
+ } = {
199
+ ...this.props,
200
+ ...changes
201
+ };
202
+ from = this.parse(from, 'from');
203
+ to = this.parse(to, 'to');
204
+ // proceed to setting the end by default
205
+ let active = 'to';
206
+ let complete = false;
207
+ // end is before beginning
208
+ if (from && to && isAfter(startOfDay(from), startOfDay(to))) {
209
+ // ignore the old end when beginning is changed
210
+ if (changes.from) {
211
+ to = null;
212
+ // treat range as reverse when end is changed
313
213
  } else if (changes.to) {
314
- active = 'from';
315
- complete = !!from;
316
- }
317
- this.setState({
318
- active,
319
- hoverDate: null,
320
- text: null
321
- });
322
- this.props.onChange({
323
- from,
324
- to
325
- });
326
- if (complete) {
327
- this.props.onComplete();
214
+ to = from;
215
+ from = changes.to;
328
216
  }
217
+ } else if (changes.to) {
218
+ active = 'from';
219
+ complete = !!from;
220
+ }
221
+ this.setState({
222
+ active,
223
+ hoverDate: null,
224
+ text: null
225
+ });
226
+ this.props.onChange({
227
+ from,
228
+ to
229
+ });
230
+ if (complete) {
231
+ this.props.onComplete();
329
232
  }
330
233
  }
331
- }, {
332
- key: "confirm",
333
- value: function confirm(name) {
334
- var text = this.state.text;
335
- var result;
336
- if (name === 'time') {
337
- result = this.parse(text, name);
338
- var time = this.parse('time' in this.props ? this.props.time : '', 'time');
339
- var emptyCase = this.state.active === 'time' ? '00:00' : null;
340
- result = result || time || emptyCase;
341
- } else {
342
- result = this.parse(text, name);
343
- if (!this.isValidDate(result)) {
344
- result = this.parse(name in this.props ? this.props[name] : '', name);
345
- }
234
+ }
235
+ confirm(name) {
236
+ const text = this.state.text;
237
+ let result;
238
+ if (name === 'time') {
239
+ result = this.parse(text, name);
240
+ const time = this.parse('time' in this.props ? this.props.time : '', 'time');
241
+ const emptyCase = this.state.active === 'time' ? '00:00' : null;
242
+ result = result || time || emptyCase;
243
+ } else {
244
+ result = this.parse(text, name);
245
+ if (!this.isValidDate(result)) {
246
+ result = this.parse(name in this.props ? this.props[name] : '', name);
346
247
  }
347
- this.select({
348
- [name]: result
248
+ }
249
+ this.select({
250
+ [name]: result
251
+ });
252
+ }
253
+ isValidDate = parsedText => {
254
+ const minDate = this.parse(this.props.minDate, 'date');
255
+ const maxDate = this.parse(this.props.maxDate, 'date');
256
+ if (parsedText) {
257
+ return !(minDate && isBefore(parsedText, minDate) || maxDate && isAfter(parsedText, maxDate));
258
+ }
259
+ return false;
260
+ };
261
+ scheduleScroll = () => {
262
+ const current = this.state.scrollDate && this.parse(this.state.scrollDate, 'date') || this.parse(this.props[this.state.active], 'date') || new Date();
263
+ const goal = this._scrollDate;
264
+ if (!current || !goal || DatePopup.sameDay(goal, current)) {
265
+ this._scrollDate = null;
266
+ this._scrollTS = null;
267
+ return;
268
+ }
269
+ if (this._scrollTS) {
270
+ const diff = goal - Number(current);
271
+ const dt = Date.now() - this._scrollTS;
272
+ const next = goal - diff * Math.E ** (-dt / scrollExpDelay);
273
+ this.setState({
274
+ scrollDate: next
349
275
  });
350
276
  }
351
- }, {
352
- key: "render",
353
- value: function render() {
354
- var _this2 = this;
355
- var _this$props3 = this.props,
356
- range = _this$props3.range,
357
- withTime = _this$props3.withTime,
358
- locale = _this$props3.locale;
359
- var _this$props4 = this.props;
360
- _this$props4.from;
361
- _this$props4.to;
362
- _this$props4.date;
363
- var time = _this$props4.time,
364
- restProps = _objectWithoutProperties(_this$props4, _excluded);
365
- var parsedDate = this.parse(this.props.date, 'date');
366
- var parsedTo = this.parse(this.props.to, 'to');
367
- var names = range ? ['from', 'to'] : ['date'];
368
- var dates = names.reduce(function (obj, key) {
369
- var value = _this2.props[key];
370
- return _objectSpread2(_objectSpread2({}, obj), {}, {
371
- [key]: _this2.parse(value, key)
372
- });
373
- }, {});
374
- var activeDate = this.state.active !== 'time' ? this.state.hoverDate || (this.state.text != null ? this.parse(this.state.text, 'date') : null) : this.state.hoverDate || null;
375
- var currentRange = range && dates.from && dates.to && [dates.from, dates.to] || null;
376
- var activeRange = null;
377
- if (range && activeDate) {
378
- switch (this.state.active) {
379
- case 'from':
380
- if (dates.to && isAfter(startOfDay(activeDate), startOfDay(dates.to))) {
381
- activeRange = [activeDate, dates.to];
382
- }
383
- break;
384
- case 'to':
385
- if (!dates.from) {
386
- break;
387
- }
388
- if (isBefore(startOfDay(activeDate), startOfDay(dates.from))) {
389
- activeRange = [activeDate, dates.from];
390
- } else {
391
- activeRange = [dates.from, activeDate];
392
- }
393
- break;
394
- }
277
+ this._scrollTS = Date.now();
278
+ window.requestAnimationFrame(this.scheduleScroll);
279
+ };
280
+ scrollTo = scrollDate => {
281
+ this._scrollDate = scrollDate;
282
+ if (!this._scrollTS) {
283
+ this.scheduleScroll();
284
+ }
285
+ };
286
+ hoverHandler = hoverDate => this.setState({
287
+ hoverDate
288
+ });
289
+ handleActivate = memoize(name => () => this.setState({
290
+ active: name
291
+ }));
292
+ handleInput = (text, name) => {
293
+ if (name !== 'time') {
294
+ const parsed = this.parse(text, name);
295
+ if (this.isValidDate(parsed)) {
296
+ this.scrollTo(Number(parsed));
395
297
  }
396
- var scrollDate = withTime && !range ? this.state.scrollDate || dates.date || new Date() : this.state.scrollDate || dates[this.state.active] || new Date();
397
- var calendarProps = _objectSpread2(_objectSpread2(_objectSpread2({}, restProps), dates), {}, {
398
- scrollDate,
399
- activeDate,
400
- currentRange,
401
- activeRange,
402
- onScroll: this.handleScroll,
403
- onScrollChange: this.scrollTo
298
+ }
299
+ this.setState({
300
+ text,
301
+ hoverDate: null
302
+ });
303
+ };
304
+ handleConfirm = memoize(name => () => this.confirm(name));
305
+ selectHandler = date => {
306
+ if (this.isInTimeMode()) {
307
+ this.setState({
308
+ active: 'time'
309
+ }, () => this.select({
310
+ date
311
+ }));
312
+ } else {
313
+ this.select({
314
+ [this.state.active]: date
404
315
  });
405
- var clearable = Boolean(this.props.onClear);
406
- return /*#__PURE__*/React.createElement("div", {
407
- className: modules_0c7b7d96.datePopup,
408
- "data-test": "ring-date-popup",
409
- ref: this.componentRef
410
- }, /*#__PURE__*/React.createElement("div", {
411
- className: modules_0c7b7d96.filterWrapper
412
- }, names.map(function (name) {
413
- var onClear;
414
- if (clearable && name !== 'from' && !_this2.isInTimeMode()) {
415
- onClear = _this2.onClear.bind(_this2);
416
- }
417
- return /*#__PURE__*/React.createElement(DateInput, _extends({}, _this2.props, _this2.state, {
418
- divider: name === 'from' && (dates[name] != null || parsedTo != null),
419
- name: name,
420
- key: name,
421
- date: dates[name],
422
- active: _this2.state.active === name,
423
- onActivate: _this2.handleActivate(name),
424
- onInput: _this2.handleInput,
425
- onConfirm: _this2.handleConfirm(name),
426
- onClear: onClear,
427
- locale: locale
428
- }));
429
- }), this.isInTimeMode() ? /*#__PURE__*/React.createElement(DateInput, _extends({}, this.props, {
430
- text: this.state.text,
431
- divider: !!parsedDate,
432
- hoverDate: null,
433
- name: 'time',
434
- key: 'time',
435
- date: null,
436
- time: time,
437
- active: this.state.active === 'time',
438
- onActivate: this.handleActivate('time'),
439
- onInput: this.handleInput,
440
- onConfirm: this.handleConfirm('time'),
441
- onClear: clearable && this.onClear || undefined,
442
- locale: locale
443
- })) : ''), /*#__PURE__*/React.createElement(Weekdays, {
444
- locale: locale
445
- }), /*#__PURE__*/React.createElement("div", {
446
- className: modules_0c7b7d96.calendar
447
- }, /*#__PURE__*/React.createElement(Months, _extends({}, calendarProps, {
448
- onHover: this.hoverHandler,
449
- onSelect: this.selectHandler,
450
- locale: locale
451
- })), /*#__PURE__*/React.createElement(Years, calendarProps)), this.props.renderAfterCalendar && this.props.renderAfterCalendar(this.state));
452
316
  }
453
- }], [{
454
- key: "sameDay",
455
- value: function sameDay(next, prev) {
456
- if (next && prev) {
457
- return isSameDay(next, prev);
317
+ };
318
+ handleScroll = scrollDate => this.setState({
319
+ scrollDate
320
+ });
321
+ onClear = e => {
322
+ let changes;
323
+ if (this.props.range) {
324
+ changes = {
325
+ from: null,
326
+ to: null
327
+ };
328
+ } else {
329
+ changes = {
330
+ date: null
331
+ };
332
+ }
333
+ this.select(changes);
334
+ this.props.onClear?.(e);
335
+ this.componentRef.current?.querySelector('input')?.focus();
336
+ };
337
+ render() {
338
+ const {
339
+ range,
340
+ withTime,
341
+ locale
342
+ } = this.props;
343
+ const {
344
+ from,
345
+ to,
346
+ date,
347
+ time,
348
+ ...restProps
349
+ } = this.props;
350
+ const parsedDate = this.parse(this.props.date, 'date');
351
+ const parsedTo = this.parse(this.props.to, 'to');
352
+ const names = range ? ['from', 'to'] : ['date'];
353
+ const dates = names.reduce((obj, key) => {
354
+ const value = this.props[key];
355
+ return {
356
+ ...obj,
357
+ [key]: this.parse(value, key)
358
+ };
359
+ }, {});
360
+ const activeDate = this.state.active !== 'time' ? this.state.hoverDate || (this.state.text != null ? this.parse(this.state.text, 'date') : null) : this.state.hoverDate || null;
361
+ const currentRange = range && dates.from && dates.to && [dates.from, dates.to] || null;
362
+ let activeRange = null;
363
+ if (range && activeDate) {
364
+ switch (this.state.active) {
365
+ case 'from':
366
+ if (dates.to && isAfter(startOfDay(activeDate), startOfDay(dates.to))) {
367
+ activeRange = [activeDate, dates.to];
368
+ }
369
+ break;
370
+ case 'to':
371
+ if (!dates.from) {
372
+ break;
373
+ }
374
+ if (isBefore(startOfDay(activeDate), startOfDay(dates.from))) {
375
+ activeRange = [activeDate, dates.from];
376
+ } else {
377
+ activeRange = [dates.from, activeDate];
378
+ }
379
+ break;
458
380
  }
459
- return next === prev;
460
381
  }
461
- }]);
462
- }(Component);
463
- _defineProperty(DatePopup, "propTypes", {
464
- className: PropTypes.string,
465
- date: dateType,
466
- range: PropTypes.bool,
467
- withTime: PropTypes.bool,
468
- time: PropTypes.string,
469
- from: dateType,
470
- to: dateType,
471
- renderAfterCalendar: PropTypes.func,
472
- displayFormat: PropTypes.func,
473
- parseDateInput: PropTypes.func,
474
- onChange: PropTypes.func,
475
- onComplete: PropTypes.func,
476
- onClear: PropTypes.func,
477
- minDate: dateType,
478
- maxDate: dateType,
479
- fromPlaceholder: PropTypes.string,
480
- toPlaceholder: PropTypes.string,
481
- timePlaceholder: PropTypes.string,
482
- locale: PropTypes.object
483
- });
484
- _defineProperty(DatePopup, "defaultProps", {
485
- onChange() {}
486
- });
382
+ const scrollDate = withTime && !range ? this.state.scrollDate || dates.date || new Date() : this.state.scrollDate || dates[this.state.active] || new Date();
383
+ const calendarProps = {
384
+ ...restProps,
385
+ ...dates,
386
+ scrollDate,
387
+ activeDate,
388
+ currentRange,
389
+ activeRange,
390
+ onScroll: this.handleScroll,
391
+ onScrollChange: this.scrollTo
392
+ };
393
+ const clearable = Boolean(this.props.onClear);
394
+ return /*#__PURE__*/React.createElement("div", {
395
+ className: modules_0c7b7d96.datePopup,
396
+ "data-test": "ring-date-popup",
397
+ ref: this.componentRef
398
+ }, /*#__PURE__*/React.createElement("div", {
399
+ className: modules_0c7b7d96.filterWrapper
400
+ }, names.map(name => {
401
+ let onClear;
402
+ if (clearable && name !== 'from' && !this.isInTimeMode()) {
403
+ onClear = this.onClear.bind(this);
404
+ }
405
+ return /*#__PURE__*/React.createElement(DateInput, _extends({}, this.props, this.state, {
406
+ divider: name === 'from' && (dates[name] != null || parsedTo != null),
407
+ name: name,
408
+ key: name,
409
+ date: dates[name],
410
+ active: this.state.active === name,
411
+ onActivate: this.handleActivate(name),
412
+ onInput: this.handleInput,
413
+ onConfirm: this.handleConfirm(name),
414
+ onClear: onClear,
415
+ locale: locale
416
+ }));
417
+ }), this.isInTimeMode() ? /*#__PURE__*/React.createElement(DateInput, _extends({}, this.props, {
418
+ text: this.state.text,
419
+ divider: !!parsedDate,
420
+ hoverDate: null,
421
+ name: 'time',
422
+ key: 'time',
423
+ date: null,
424
+ time: time,
425
+ active: this.state.active === 'time',
426
+ onActivate: this.handleActivate('time'),
427
+ onInput: this.handleInput,
428
+ onConfirm: this.handleConfirm('time'),
429
+ onClear: clearable && this.onClear || undefined,
430
+ locale: locale
431
+ })) : ''), /*#__PURE__*/React.createElement(Weekdays, {
432
+ locale: locale
433
+ }), /*#__PURE__*/React.createElement("div", {
434
+ className: modules_0c7b7d96.calendar
435
+ }, /*#__PURE__*/React.createElement(Months, _extends({}, calendarProps, {
436
+ onHover: this.hoverHandler,
437
+ onSelect: this.selectHandler,
438
+ locale: locale
439
+ })), /*#__PURE__*/React.createElement(Years, calendarProps)), this.props.renderAfterCalendar && this.props.renderAfterCalendar(this.state));
440
+ }
441
+ }
487
442
 
488
443
  export { DatePopup as default };