@jetbrains/ring-ui-built 7.0.113 → 7.0.115
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.
- package/components/date-picker/animate-date.js +1 -0
- package/components/date-picker/consts.d.ts +3 -2
- package/components/date-picker/consts.js +31 -6
- package/components/date-picker/date-picker.js +24 -12
- package/components/date-picker/date-popup.d.ts +1 -3
- package/components/date-picker/date-popup.js +38 -32
- package/components/date-picker/day.js +1 -0
- package/components/date-picker/scroll-arith.js +1 -0
- package/components/date-picker/use-scroll-behavior.js +1 -0
- package/components/date-picker/weekdays.js +1 -0
- package/components/date-picker/years.js +1 -0
- package/components/style.css +1 -1
- package/package.json +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type ReactNode } from 'react';
|
|
2
|
-
import type
|
|
2
|
+
import { type Locale } from 'date-fns';
|
|
3
3
|
declare const units: {
|
|
4
4
|
unit: number;
|
|
5
5
|
cellSize: number;
|
|
@@ -24,10 +24,11 @@ export declare const yearDuration: number;
|
|
|
24
24
|
export declare const yearScrollSpeed: number;
|
|
25
25
|
export declare const DOUBLE = 2;
|
|
26
26
|
export declare const HALF = 0.5;
|
|
27
|
-
export declare function parseTime(time: string): string | null;
|
|
27
|
+
export declare function parseTime(time: string | null | undefined): string | null;
|
|
28
28
|
export declare function shiftWeekArray<T>(arr: T[], startOfWeek: number): T[];
|
|
29
29
|
export declare function getWeekStartsOn(locale: Locale | undefined): number;
|
|
30
30
|
export declare function getDayNumInWeek(locale: Locale | undefined, day: number): number;
|
|
31
|
+
export declare function getDefaultScrollDate({ minDate, maxDate, parseDateInput, }: Pick<DatePopupBaseProps, 'minDate' | 'maxDate' | 'parseDateInput'>): Date;
|
|
31
32
|
export interface DateInputTranslations {
|
|
32
33
|
addFirstDate?: string;
|
|
33
34
|
addSecondDate?: string;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { add } from 'date-fns/add';
|
|
2
|
+
import { endOfDay } from 'date-fns';
|
|
2
3
|
import sniffr from '../global/sniffer.js';
|
|
3
4
|
import 'sniffr';
|
|
4
5
|
|
|
@@ -32,13 +33,14 @@ const yearScrollSpeed = yearDuration / (YEAR * units.cellSize);
|
|
|
32
33
|
const DOUBLE = 2;
|
|
33
34
|
const HALF = 0.5;
|
|
34
35
|
function parseTime(time) {
|
|
35
|
-
|
|
36
|
+
if (!time) return null;
|
|
36
37
|
if (/^([01][0-9]|2[0-3]):[0-5][0-9]$/.test(time)) {
|
|
37
|
-
|
|
38
|
-
} else if (/^([0-9]|2[0-3]):[0-5][0-9]$/.test(time)) {
|
|
39
|
-
result = `0${time}`;
|
|
38
|
+
return time;
|
|
40
39
|
}
|
|
41
|
-
|
|
40
|
+
if (/^([0-9]|2[0-3]):[0-5][0-9]$/.test(time)) {
|
|
41
|
+
return `0${time}`;
|
|
42
|
+
}
|
|
43
|
+
return null;
|
|
42
44
|
}
|
|
43
45
|
function shiftWeekArray(arr, startOfWeek) {
|
|
44
46
|
const shiftTimes = startOfWeek - 1;
|
|
@@ -52,6 +54,29 @@ function getDayNumInWeek(locale, day) {
|
|
|
52
54
|
const weekDays = shiftWeekArray(Object.values(weekdays), getWeekStartsOn(locale));
|
|
53
55
|
return weekDays.indexOf(day);
|
|
54
56
|
}
|
|
57
|
+
function getDefaultScrollDate({
|
|
58
|
+
minDate,
|
|
59
|
+
maxDate,
|
|
60
|
+
parseDateInput
|
|
61
|
+
}) {
|
|
62
|
+
const minDateParsed = parseDateInput(minDate);
|
|
63
|
+
const maxDateParsed = parseDateInput(maxDate);
|
|
64
|
+
const maxDateEndOfDayNum = maxDateParsed ? Number(endOfDay(maxDateParsed)) : null;
|
|
65
|
+
const now = Date.now();
|
|
66
|
+
if (minDateParsed != null && maxDateEndOfDayNum != null) {
|
|
67
|
+
if (minDateParsed.getTime() <= now && now <= maxDateEndOfDayNum) {
|
|
68
|
+
return new Date(now);
|
|
69
|
+
}
|
|
70
|
+
return minDateParsed;
|
|
71
|
+
}
|
|
72
|
+
if (minDateParsed != null && minDateParsed.getTime() > now) {
|
|
73
|
+
return minDateParsed;
|
|
74
|
+
}
|
|
75
|
+
if (maxDateParsed != null && maxDateEndOfDayNum != null && maxDateEndOfDayNum < now) {
|
|
76
|
+
return maxDateParsed;
|
|
77
|
+
}
|
|
78
|
+
return new Date(now);
|
|
79
|
+
}
|
|
55
80
|
/**
|
|
56
81
|
* Safari on iPhone doesn't allow setting scrollTop while a scroll is in progress.
|
|
57
82
|
* If you do, the browser will overwrite it during the next scroll event.
|
|
@@ -68,4 +93,4 @@ const calendarSyncOnYearScrollUpdateDelay = isSafariOnIPhone ? 130 : 100;
|
|
|
68
93
|
const dateAnimationDuration = 150;
|
|
69
94
|
const yearsAnimationDuration = 200;
|
|
70
95
|
|
|
71
|
-
export { DOUBLE, FIFTH_DAY, HALF, MIDDLE_DAY, WEEK, YEAR, calendarSyncOnYearScrollUpdateDelay, dateAnimationDuration, units as default, getDayNumInWeek, getWeekStartsOn, isSafariOnIPhone, parseTime, scrollerReRenderDelayIPhone, shiftWeekArray, weekdays, yearDuration, yearScrollSpeed, yearsAnimationDuration };
|
|
96
|
+
export { DOUBLE, FIFTH_DAY, HALF, MIDDLE_DAY, WEEK, YEAR, calendarSyncOnYearScrollUpdateDelay, dateAnimationDuration, units as default, getDayNumInWeek, getDefaultScrollDate, getWeekStartsOn, isSafariOnIPhone, parseTime, scrollerReRenderDelayIPhone, shiftWeekArray, weekdays, yearDuration, yearScrollSpeed, yearsAnimationDuration };
|
|
@@ -92,11 +92,11 @@ import './month-slider.js';
|
|
|
92
92
|
|
|
93
93
|
const PopupComponent = t0 => {
|
|
94
94
|
const $ = c(20);
|
|
95
|
-
if ($[0] !== "
|
|
95
|
+
if ($[0] !== "9234d8ca8b34a5b7faad566d500afe9eaca1e8773f78755a6a2c893b2294c421") {
|
|
96
96
|
for (let $i = 0; $i < 20; $i += 1) {
|
|
97
97
|
$[$i] = Symbol.for("react.memo_cache_sentinel");
|
|
98
98
|
}
|
|
99
|
-
$[0] = "
|
|
99
|
+
$[0] = "9234d8ca8b34a5b7faad566d500afe9eaca1e8773f78755a6a2c893b2294c421";
|
|
100
100
|
}
|
|
101
101
|
let className;
|
|
102
102
|
let datePopupProps;
|
|
@@ -260,8 +260,18 @@ class DatePicker extends PureComponent {
|
|
|
260
260
|
withTime,
|
|
261
261
|
applyTimeInput
|
|
262
262
|
} = this.props;
|
|
263
|
-
|
|
264
|
-
|
|
263
|
+
if (withTime && !(change instanceof Date) && change && 'date' in change && 'time' in change) {
|
|
264
|
+
const {
|
|
265
|
+
date,
|
|
266
|
+
time
|
|
267
|
+
} = change;
|
|
268
|
+
if (date) {
|
|
269
|
+
const dateWithTime = applyTimeInput(date, time);
|
|
270
|
+
onChange(dateWithTime);
|
|
271
|
+
}
|
|
272
|
+
} else {
|
|
273
|
+
onChange(change);
|
|
274
|
+
}
|
|
265
275
|
};
|
|
266
276
|
clear = () => {
|
|
267
277
|
let change = null;
|
|
@@ -282,16 +292,18 @@ class DatePicker extends PureComponent {
|
|
|
282
292
|
this.popup?._onCloseAttempt();
|
|
283
293
|
};
|
|
284
294
|
parse = memoize(date => {
|
|
285
|
-
|
|
286
|
-
parseDateInput
|
|
287
|
-
} = this.props;
|
|
295
|
+
let normalizedDate;
|
|
288
296
|
if (date instanceof Date) {
|
|
289
|
-
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
|
|
297
|
+
normalizedDate = date;
|
|
298
|
+
} else if (typeof date === 'number') {
|
|
299
|
+
normalizedDate = new Date(date);
|
|
300
|
+
} else {
|
|
301
|
+
const {
|
|
302
|
+
parseDateInput
|
|
303
|
+
} = this.props;
|
|
304
|
+
normalizedDate = parseDateInput(date);
|
|
293
305
|
}
|
|
294
|
-
return
|
|
306
|
+
return normalizedDate && isValid(normalizedDate) ? normalizedDate : null;
|
|
295
307
|
});
|
|
296
308
|
formatTime() {
|
|
297
309
|
const {
|
|
@@ -7,13 +7,11 @@ export default class DatePopup extends Component<DatePopupProps, DatePopupState>
|
|
|
7
7
|
onChange(): void;
|
|
8
8
|
};
|
|
9
9
|
constructor(props: DatePopupProps);
|
|
10
|
-
componentDidUpdate(
|
|
10
|
+
componentDidUpdate(_prevProps: DatePopupBaseProps, prevState: DatePopupState): void;
|
|
11
11
|
componentWillUnmount(): void;
|
|
12
12
|
private animationCleanup;
|
|
13
13
|
isInTimeMode: () => boolean;
|
|
14
14
|
componentRef: React.RefObject<HTMLDivElement | null>;
|
|
15
|
-
parse(text: string | null | undefined, type: 'time'): string;
|
|
16
|
-
parse(text: Date | number | string | null | undefined, type?: 'date' | 'from' | 'to'): Date;
|
|
17
15
|
select(changes: DatePickerChange): void;
|
|
18
16
|
confirm(name: Field): void;
|
|
19
17
|
isValidDate: (parsedText: Date) => boolean;
|
|
@@ -9,7 +9,7 @@ import DateInput from './date-input.js';
|
|
|
9
9
|
import Months from './months.js';
|
|
10
10
|
import Years from './years.js';
|
|
11
11
|
import Weekdays from './weekdays.js';
|
|
12
|
-
import { parseTime } from './consts.js';
|
|
12
|
+
import { getDefaultScrollDate, parseTime } from './consts.js';
|
|
13
13
|
import { animateDate } from './animate-date.js';
|
|
14
14
|
import MonthNames from './month-names.js';
|
|
15
15
|
import { s as styles } from '../_helpers/date-picker.js';
|
|
@@ -79,31 +79,33 @@ class DatePopup extends Component {
|
|
|
79
79
|
};
|
|
80
80
|
const {
|
|
81
81
|
range,
|
|
82
|
-
withTime
|
|
82
|
+
withTime,
|
|
83
|
+
parseDateInput
|
|
83
84
|
} = props;
|
|
84
85
|
if (!range) {
|
|
85
|
-
const parsedDate =
|
|
86
|
+
const parsedDate = parseDateInput(props.date);
|
|
86
87
|
const active = withTime && parsedDate && !props.time ? 'time' : 'date';
|
|
87
88
|
this.state = {
|
|
88
89
|
...defaultState,
|
|
89
90
|
active,
|
|
90
91
|
scrollDate: {
|
|
91
|
-
date: parsedDate,
|
|
92
|
+
date: parsedDate !== null && parsedDate !== void 0 ? parsedDate : getDefaultScrollDate(props),
|
|
92
93
|
source: 'other'
|
|
93
94
|
}
|
|
94
95
|
};
|
|
95
96
|
} else {
|
|
97
|
+
var _parseDateInput;
|
|
96
98
|
this.state = {
|
|
97
99
|
...defaultState,
|
|
98
100
|
active: props.from && !props.to ? 'to' : 'from',
|
|
99
101
|
scrollDate: {
|
|
100
|
-
date:
|
|
102
|
+
date: (_parseDateInput = parseDateInput(props.from)) !== null && _parseDateInput !== void 0 ? _parseDateInput : getDefaultScrollDate(props),
|
|
101
103
|
source: 'other'
|
|
102
104
|
}
|
|
103
105
|
};
|
|
104
106
|
}
|
|
105
107
|
}
|
|
106
|
-
componentDidUpdate(
|
|
108
|
+
componentDidUpdate(_prevProps, prevState) {
|
|
107
109
|
if (this.state.active !== prevState.active) {
|
|
108
110
|
if (this.state.text && prevState.active) {
|
|
109
111
|
this.confirm(prevState.active);
|
|
@@ -119,16 +121,11 @@ class DatePopup extends Component {
|
|
|
119
121
|
animationCleanup = null;
|
|
120
122
|
isInTimeMode = () => !this.props.range && this.props.withTime || false;
|
|
121
123
|
componentRef = /*#__PURE__*/React.createRef();
|
|
122
|
-
parse(text, type) {
|
|
123
|
-
if (type === 'time') {
|
|
124
|
-
return parseTime(String(text));
|
|
125
|
-
}
|
|
126
|
-
return this.props.parseDateInput(text);
|
|
127
|
-
}
|
|
128
124
|
select(changes) {
|
|
129
125
|
const {
|
|
130
126
|
range,
|
|
131
|
-
withTime
|
|
127
|
+
withTime,
|
|
128
|
+
parseDateInput
|
|
132
129
|
} = this.props;
|
|
133
130
|
const prevActive = this.state.active;
|
|
134
131
|
if (!range && !withTime) {
|
|
@@ -144,8 +141,8 @@ class DatePopup extends Component {
|
|
|
144
141
|
this.props.onChange(adjustedDate);
|
|
145
142
|
this.props.onComplete();
|
|
146
143
|
} else if (!range && withTime) {
|
|
147
|
-
const date =
|
|
148
|
-
const time =
|
|
144
|
+
const date = parseDateInput(this.props.date);
|
|
145
|
+
const time = parseTime(this.props.time);
|
|
149
146
|
const changeToSubmit = {
|
|
150
147
|
date: changes.date || date,
|
|
151
148
|
time: changes.time || time
|
|
@@ -167,8 +164,8 @@ class DatePopup extends Component {
|
|
|
167
164
|
...this.props,
|
|
168
165
|
...changes
|
|
169
166
|
};
|
|
170
|
-
from =
|
|
171
|
-
to =
|
|
167
|
+
from = parseDateInput(from);
|
|
168
|
+
to = parseDateInput(to);
|
|
172
169
|
// proceed to setting the end by default
|
|
173
170
|
let active = 'to';
|
|
174
171
|
let complete = false;
|
|
@@ -204,14 +201,17 @@ class DatePopup extends Component {
|
|
|
204
201
|
const text = this.state.text;
|
|
205
202
|
let result;
|
|
206
203
|
if (name === 'time') {
|
|
207
|
-
result =
|
|
208
|
-
const time =
|
|
204
|
+
result = parseTime(text);
|
|
205
|
+
const time = parseTime('time' in this.props ? this.props.time : '');
|
|
209
206
|
const emptyCase = this.state.active === 'time' ? '00:00' : null;
|
|
210
207
|
result = result || time || emptyCase;
|
|
211
208
|
} else {
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
209
|
+
const {
|
|
210
|
+
parseDateInput
|
|
211
|
+
} = this.props;
|
|
212
|
+
result = parseDateInput(text);
|
|
213
|
+
if (!result || !this.isValidDate(result)) {
|
|
214
|
+
result = parseDateInput(name in this.props ? this.props[name] : '');
|
|
215
215
|
}
|
|
216
216
|
}
|
|
217
217
|
this.select({
|
|
@@ -219,10 +219,15 @@ class DatePopup extends Component {
|
|
|
219
219
|
});
|
|
220
220
|
}
|
|
221
221
|
isValidDate = parsedText => {
|
|
222
|
-
const
|
|
223
|
-
|
|
222
|
+
const {
|
|
223
|
+
parseDateInput,
|
|
224
|
+
minDate,
|
|
225
|
+
maxDate
|
|
226
|
+
} = this.props;
|
|
227
|
+
const parsedMinDate = parseDateInput(minDate);
|
|
228
|
+
const parsedMaxDate = parseDateInput(maxDate);
|
|
224
229
|
if (parsedText) {
|
|
225
|
-
return !(
|
|
230
|
+
return !(parsedMinDate && isBefore(parsedText, parsedMinDate) || parsedMaxDate && isAfter(parsedText, parsedMaxDate));
|
|
226
231
|
}
|
|
227
232
|
return false;
|
|
228
233
|
};
|
|
@@ -234,8 +239,8 @@ class DatePopup extends Component {
|
|
|
234
239
|
}));
|
|
235
240
|
handleInput = (text, name) => {
|
|
236
241
|
if (name !== 'time') {
|
|
237
|
-
const parsed = this.
|
|
238
|
-
if (this.isValidDate(parsed)) {
|
|
242
|
+
const parsed = this.props.parseDateInput(text);
|
|
243
|
+
if (parsed && this.isValidDate(parsed)) {
|
|
239
244
|
this.animationCleanup?.();
|
|
240
245
|
const currentScrollDate = this.state.scrollDate?.date;
|
|
241
246
|
if (currentScrollDate != null) {
|
|
@@ -299,7 +304,8 @@ class DatePopup extends Component {
|
|
|
299
304
|
render() {
|
|
300
305
|
const {
|
|
301
306
|
range,
|
|
302
|
-
locale
|
|
307
|
+
locale,
|
|
308
|
+
parseDateInput
|
|
303
309
|
} = this.props;
|
|
304
310
|
const {
|
|
305
311
|
from,
|
|
@@ -308,17 +314,17 @@ class DatePopup extends Component {
|
|
|
308
314
|
time,
|
|
309
315
|
...restProps
|
|
310
316
|
} = this.props;
|
|
311
|
-
const parsedDate =
|
|
312
|
-
const parsedTo =
|
|
317
|
+
const parsedDate = parseDateInput(date);
|
|
318
|
+
const parsedTo = parseDateInput(to);
|
|
313
319
|
const names = range ? ['from', 'to'] : ['date'];
|
|
314
320
|
const dates = names.reduce((obj, key) => {
|
|
315
321
|
const value = this.props[key];
|
|
316
322
|
return {
|
|
317
323
|
...obj,
|
|
318
|
-
[key]:
|
|
324
|
+
[key]: parseDateInput(value)
|
|
319
325
|
};
|
|
320
326
|
}, {});
|
|
321
|
-
const activeDate = this.state.active !== 'time' ? this.state.hoverDate || (this.state.text ?
|
|
327
|
+
const activeDate = this.state.active !== 'time' ? this.state.hoverDate || (this.state.text ? parseDateInput(this.state.text) : null) : this.state.hoverDate || null;
|
|
322
328
|
const currentRange = range && dates.from && dates.to && [dates.from, dates.to] || null;
|
|
323
329
|
let activeRange = null;
|
|
324
330
|
if (range && activeDate) {
|
|
@@ -14,6 +14,7 @@ import { getDayNumInWeek, weekdays } from './consts.js';
|
|
|
14
14
|
import { s as styles } from '../_helpers/date-picker.js';
|
|
15
15
|
import { jsx } from 'react/jsx-runtime';
|
|
16
16
|
import 'date-fns/add';
|
|
17
|
+
import 'date-fns';
|
|
17
18
|
import '../global/sniffer.js';
|
|
18
19
|
import 'sniffr';
|
|
19
20
|
|
|
@@ -3,6 +3,7 @@ import { useState, useRef, useEffect, useLayoutEffect } from 'react';
|
|
|
3
3
|
import units, { isSafariOnIPhone, scrollerReRenderDelayIPhone } from './consts.js';
|
|
4
4
|
import useEventCallback from '../global/use-event-callback.js';
|
|
5
5
|
import 'date-fns/add';
|
|
6
|
+
import 'date-fns';
|
|
6
7
|
import '../global/sniffer.js';
|
|
7
8
|
import 'sniffr';
|
|
8
9
|
|
|
@@ -9,6 +9,7 @@ import { shiftWeekArray, getWeekStartsOn, weekdays } from './consts.js';
|
|
|
9
9
|
import { s as styles } from '../_helpers/date-picker.js';
|
|
10
10
|
import { jsx } from 'react/jsx-runtime';
|
|
11
11
|
import 'date-fns/add';
|
|
12
|
+
import 'date-fns';
|
|
12
13
|
import '../global/sniffer.js';
|
|
13
14
|
import 'sniffr';
|
|
14
15
|
|
|
@@ -17,6 +17,7 @@ import { useIntersectionObserver, useVisibility } from './use-intersection-obser
|
|
|
17
17
|
import { s as styles } from '../_helpers/date-picker.js';
|
|
18
18
|
import { jsx } from 'react/jsx-runtime';
|
|
19
19
|
import 'date-fns/add';
|
|
20
|
+
import 'date-fns';
|
|
20
21
|
import '../global/sniffer.js';
|
|
21
22
|
import 'sniffr';
|
|
22
23
|
import '../global/use-event-callback.js';
|