@artemy-tech/datepicker 0.6.1 → 0.7.0
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/README.md +61 -130
- package/dist/{DateRangePicker-C8_RSTkZ.d.cts → DateRangePicker-DMprhiDL.d.cts} +7 -2
- package/dist/{DateRangePicker-C8_RSTkZ.d.ts → DateRangePicker-DMprhiDL.d.ts} +7 -2
- package/dist/{chunk-I3ID2PSC.js → chunk-66Q5CMWV.js} +204 -80
- package/dist/chunk-66Q5CMWV.js.map +1 -0
- package/dist/index.cjs +201 -78
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +1 -1
- package/dist/rhf.cjs +201 -78
- package/dist/rhf.cjs.map +1 -1
- package/dist/rhf.d.cts +2 -1
- package/dist/rhf.d.ts +2 -1
- package/dist/rhf.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-I3ID2PSC.js.map +0 -1
package/dist/rhf.cjs
CHANGED
|
@@ -118,34 +118,137 @@ function Spinner() {
|
|
|
118
118
|
|
|
119
119
|
// src/utils/date-mask.ts
|
|
120
120
|
var import_date_fns = require("date-fns");
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
121
|
+
|
|
122
|
+
// src/utils/format-schema.ts
|
|
123
|
+
var DATE_TOKENS = ["yyyy", "dd", "MM"];
|
|
124
|
+
var TIME_TOKENS = ["HH", "mm", "ss"];
|
|
125
|
+
var ALL_TOKENS = [...DATE_TOKENS, ...TIME_TOKENS];
|
|
126
|
+
var TOKEN_LENGTH = {
|
|
127
|
+
yyyy: 4,
|
|
128
|
+
dd: 2,
|
|
129
|
+
MM: 2,
|
|
130
|
+
HH: 2,
|
|
131
|
+
mm: 2,
|
|
132
|
+
ss: 2
|
|
133
|
+
};
|
|
134
|
+
var RU_TOKEN_PLACEHOLDER = {
|
|
135
|
+
yyyy: "\u0433\u0433\u0433\u0433",
|
|
136
|
+
dd: "\u0434\u0434",
|
|
137
|
+
MM: "\u043C\u043C",
|
|
138
|
+
HH: "\u0447\u0447",
|
|
139
|
+
mm: "\u043C\u043C",
|
|
140
|
+
ss: "\u0441\u0441"
|
|
141
|
+
};
|
|
142
|
+
var EN_TOKEN_PLACEHOLDER = {
|
|
143
|
+
yyyy: "yyyy",
|
|
144
|
+
dd: "dd",
|
|
145
|
+
MM: "mm",
|
|
146
|
+
HH: "hh",
|
|
147
|
+
mm: "mm",
|
|
148
|
+
ss: "ss"
|
|
149
|
+
};
|
|
150
|
+
function tokenize(format4, allowTime) {
|
|
151
|
+
const parts = [];
|
|
152
|
+
let i = 0;
|
|
153
|
+
while (i < format4.length) {
|
|
154
|
+
let matched = null;
|
|
155
|
+
for (const token of ALL_TOKENS) {
|
|
156
|
+
if (format4.startsWith(token, i)) {
|
|
157
|
+
matched = token;
|
|
158
|
+
break;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
if (matched) {
|
|
162
|
+
if (!allowTime && TIME_TOKENS.includes(matched)) {
|
|
163
|
+
throw new Error(
|
|
164
|
+
`dateFormat must not contain time tokens (got "${matched}"). Use the "showTime" prop instead.`
|
|
165
|
+
);
|
|
166
|
+
}
|
|
167
|
+
parts.push({ kind: "token", token: matched });
|
|
168
|
+
i += matched.length;
|
|
169
|
+
continue;
|
|
170
|
+
}
|
|
171
|
+
parts.push({ kind: "sep", char: format4[i] });
|
|
172
|
+
i++;
|
|
173
|
+
}
|
|
174
|
+
return parts;
|
|
175
|
+
}
|
|
176
|
+
function validateDateParts(parts) {
|
|
177
|
+
var _a, _b;
|
|
178
|
+
const counts = {};
|
|
179
|
+
for (const p of parts) {
|
|
180
|
+
if (p.kind === "token") counts[p.token] = ((_a = counts[p.token]) != null ? _a : 0) + 1;
|
|
181
|
+
}
|
|
182
|
+
for (const token of DATE_TOKENS) {
|
|
183
|
+
if (counts[token] !== 1) {
|
|
184
|
+
throw new Error(
|
|
185
|
+
`dateFormat must contain "${token}" exactly once. Supported tokens: dd, MM, yyyy. Got: ${(_b = counts[token]) != null ? _b : 0}`
|
|
186
|
+
);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
126
189
|
}
|
|
127
|
-
function
|
|
128
|
-
|
|
190
|
+
function buildSchemaFromParts(parts, isRu) {
|
|
191
|
+
const placeholderMap = isRu ? RU_TOKEN_PLACEHOLDER : EN_TOKEN_PLACEHOLDER;
|
|
192
|
+
const separators = [];
|
|
193
|
+
let digitCount = 0;
|
|
194
|
+
let format4 = "";
|
|
195
|
+
let placeholder = "";
|
|
196
|
+
let pendingSep = "";
|
|
197
|
+
for (const part of parts) {
|
|
198
|
+
if (part.kind === "sep") {
|
|
199
|
+
pendingSep += part.char;
|
|
200
|
+
format4 += part.char;
|
|
201
|
+
placeholder += part.char;
|
|
202
|
+
continue;
|
|
203
|
+
}
|
|
204
|
+
if (pendingSep) {
|
|
205
|
+
separators.push({ afterDigit: digitCount, chars: pendingSep });
|
|
206
|
+
pendingSep = "";
|
|
207
|
+
}
|
|
208
|
+
digitCount += TOKEN_LENGTH[part.token];
|
|
209
|
+
format4 += part.token;
|
|
210
|
+
placeholder += placeholderMap[part.token];
|
|
211
|
+
}
|
|
212
|
+
return { format: format4, digitCount, separators, placeholder };
|
|
129
213
|
}
|
|
130
|
-
function
|
|
131
|
-
if (!
|
|
132
|
-
return
|
|
214
|
+
function isRuLocale(locale) {
|
|
215
|
+
if (!locale) return true;
|
|
216
|
+
return locale.code === "ru";
|
|
133
217
|
}
|
|
134
|
-
function
|
|
135
|
-
|
|
136
|
-
|
|
218
|
+
function buildFormatSchema(dateFormat, timeFormat, locale) {
|
|
219
|
+
const dateParts = tokenize(dateFormat, false);
|
|
220
|
+
validateDateParts(dateParts);
|
|
221
|
+
const parts = [...dateParts];
|
|
222
|
+
if (timeFormat) {
|
|
223
|
+
parts.push({ kind: "sep", char: " " });
|
|
224
|
+
parts.push(...tokenize(timeFormat, true));
|
|
225
|
+
}
|
|
226
|
+
return buildSchemaFromParts(parts, isRuLocale(locale));
|
|
137
227
|
}
|
|
138
|
-
function
|
|
139
|
-
const d = digits.slice(0,
|
|
228
|
+
function applySchemaMask(digits, schema) {
|
|
229
|
+
const d = digits.slice(0, schema.digitCount);
|
|
140
230
|
let result = "";
|
|
231
|
+
let sepIdx = 0;
|
|
141
232
|
for (let i = 0; i < d.length; i++) {
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
233
|
+
while (sepIdx < schema.separators.length && schema.separators[sepIdx].afterDigit === i) {
|
|
234
|
+
result += schema.separators[sepIdx].chars;
|
|
235
|
+
sepIdx++;
|
|
236
|
+
}
|
|
145
237
|
result += d[i];
|
|
146
238
|
}
|
|
147
239
|
return result;
|
|
148
240
|
}
|
|
241
|
+
|
|
242
|
+
// src/utils/date-mask.ts
|
|
243
|
+
var DEFAULT_DATE_FORMAT = "dd.MM.yyyy";
|
|
244
|
+
function resolveTimeFormat(showTime) {
|
|
245
|
+
if (!showTime) return null;
|
|
246
|
+
if (showTime === true) return "HH:mm:ss";
|
|
247
|
+
return showTime.format;
|
|
248
|
+
}
|
|
249
|
+
function applyMask(digits, schema) {
|
|
250
|
+
return applySchemaMask(digits, schema);
|
|
251
|
+
}
|
|
149
252
|
function getCursorPos(masked, digitCount) {
|
|
150
253
|
if (digitCount === 0) return 0;
|
|
151
254
|
let count = 0;
|
|
@@ -160,11 +263,11 @@ function getCursorPos(masked, digitCount) {
|
|
|
160
263
|
function toDateOnly(date) {
|
|
161
264
|
return new Date(date.getFullYear(), date.getMonth(), date.getDate(), 12, 0, 0);
|
|
162
265
|
}
|
|
163
|
-
function parseDateTime(masked,
|
|
164
|
-
if (masked.replace(/\D/g, "").length !==
|
|
165
|
-
const date = (0, import_date_fns.parse)(masked,
|
|
166
|
-
if (!(0, import_date_fns.isValid)(date) || (0, import_date_fns.format)(date,
|
|
167
|
-
return
|
|
266
|
+
function parseDateTime(masked, schema) {
|
|
267
|
+
if (masked.replace(/\D/g, "").length !== schema.digitCount) return void 0;
|
|
268
|
+
const date = (0, import_date_fns.parse)(masked, schema.format, /* @__PURE__ */ new Date());
|
|
269
|
+
if (!(0, import_date_fns.isValid)(date) || (0, import_date_fns.format)(date, schema.format) !== masked) return void 0;
|
|
270
|
+
return schema.digitCount === 8 ? toDateOnly(date) : date;
|
|
168
271
|
}
|
|
169
272
|
|
|
170
273
|
// src/components/DatePicker/DatePicker.tsx
|
|
@@ -187,12 +290,18 @@ function DatePicker({
|
|
|
187
290
|
iconPosition = "end",
|
|
188
291
|
className,
|
|
189
292
|
renderInput,
|
|
190
|
-
customTrigger
|
|
293
|
+
customTrigger,
|
|
294
|
+
locale = import_locale.ru,
|
|
295
|
+
dateFormat: dateFormatProp = DEFAULT_DATE_FORMAT
|
|
191
296
|
}) {
|
|
192
297
|
const timeFormat = resolveTimeFormat(showTime);
|
|
193
|
-
const
|
|
194
|
-
|
|
195
|
-
|
|
298
|
+
const schema = (0, import_react3.useMemo)(
|
|
299
|
+
() => buildFormatSchema(dateFormatProp, timeFormat, locale),
|
|
300
|
+
[dateFormatProp, timeFormat, locale]
|
|
301
|
+
);
|
|
302
|
+
const dateFormat = schema.format;
|
|
303
|
+
const maxDigits = schema.digitCount;
|
|
304
|
+
const defaultPlaceholder = placeholder != null ? placeholder : schema.placeholder;
|
|
196
305
|
const showSeconds = timeFormat === "HH:mm:ss";
|
|
197
306
|
const fromDay = fromDate ? (0, import_date_fns2.startOfDay)(fromDate) : void 0;
|
|
198
307
|
const toDay = toDate ? (0, import_date_fns2.startOfDay)(toDate) : void 0;
|
|
@@ -256,7 +365,7 @@ function DatePicker({
|
|
|
256
365
|
if (!isControlled) setInternalDate(void 0);
|
|
257
366
|
onChange == null ? void 0 : onChange(void 0);
|
|
258
367
|
} else if (digits.length === maxDigits) {
|
|
259
|
-
const date = parseDateTime(masked,
|
|
368
|
+
const date = parseDateTime(masked, schema);
|
|
260
369
|
lastEmittedRef.current = date;
|
|
261
370
|
if (date) lastValidRef.current = masked;
|
|
262
371
|
setInputInvalid(!date);
|
|
@@ -280,7 +389,7 @@ function DatePicker({
|
|
|
280
389
|
const cursorPos = (_a = input.selectionStart) != null ? _a : 0;
|
|
281
390
|
const raw = input.value;
|
|
282
391
|
const digits = raw.replace(/\D/g, "").slice(0, maxDigits);
|
|
283
|
-
const masked = applyMask(digits,
|
|
392
|
+
const masked = applyMask(digits, schema);
|
|
284
393
|
const digitsBeforeCursor = raw.slice(0, cursorPos).replace(/\D/g, "").length;
|
|
285
394
|
const newCursorPos = getCursorPos(masked, digitsBeforeCursor);
|
|
286
395
|
setInputValue(masked);
|
|
@@ -298,10 +407,14 @@ function DatePicker({
|
|
|
298
407
|
e.preventDefault();
|
|
299
408
|
return;
|
|
300
409
|
}
|
|
301
|
-
|
|
410
|
+
const separatorChars = /* @__PURE__ */ new Set();
|
|
411
|
+
schema.separators.forEach((s) => {
|
|
412
|
+
for (const ch of s.chars) separatorChars.add(ch);
|
|
413
|
+
});
|
|
414
|
+
if (e.key === "Backspace" && pos > 0 && separatorChars.has(input.value[pos - 1])) {
|
|
302
415
|
e.preventDefault();
|
|
303
416
|
const val = input.value;
|
|
304
|
-
const masked = applyMask((val.slice(0, pos - 2) + val.slice(pos)).replace(/\D/g, ""),
|
|
417
|
+
const masked = applyMask((val.slice(0, pos - 2) + val.slice(pos)).replace(/\D/g, ""), schema);
|
|
305
418
|
setInputValue(masked);
|
|
306
419
|
commit(masked);
|
|
307
420
|
requestAnimationFrame(() => input.setSelectionRange(pos - 2, pos - 2));
|
|
@@ -309,7 +422,7 @@ function DatePicker({
|
|
|
309
422
|
}
|
|
310
423
|
function handlePaste(e) {
|
|
311
424
|
e.preventDefault();
|
|
312
|
-
const masked = applyMask(e.clipboardData.getData("text").replace(/\D/g, ""),
|
|
425
|
+
const masked = applyMask(e.clipboardData.getData("text").replace(/\D/g, ""), schema);
|
|
313
426
|
setInputValue(masked);
|
|
314
427
|
commit(masked);
|
|
315
428
|
requestAnimationFrame(() => {
|
|
@@ -423,7 +536,7 @@ function DatePicker({
|
|
|
423
536
|
endMonth: toDay,
|
|
424
537
|
disabled: disabledDays.length ? disabledDays : void 0,
|
|
425
538
|
navLayout: "around",
|
|
426
|
-
locale
|
|
539
|
+
locale
|
|
427
540
|
}
|
|
428
541
|
) }),
|
|
429
542
|
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "datepicker__time-separator" }),
|
|
@@ -457,7 +570,7 @@ function DatePicker({
|
|
|
457
570
|
endMonth: toDay,
|
|
458
571
|
disabled: disabledDays.length ? disabledDays : void 0,
|
|
459
572
|
navLayout: "around",
|
|
460
|
-
locale
|
|
573
|
+
locale
|
|
461
574
|
}
|
|
462
575
|
)
|
|
463
576
|
}
|
|
@@ -495,22 +608,16 @@ var import_locale2 = require("date-fns/locale");
|
|
|
495
608
|
|
|
496
609
|
// src/utils/range-mask.ts
|
|
497
610
|
var import_date_fns3 = require("date-fns");
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
const d = digits.slice(0, 8);
|
|
501
|
-
let result = "";
|
|
502
|
-
for (let i = 0; i < d.length; i++) {
|
|
503
|
-
if (i === 2 || i === 4) result += ".";
|
|
504
|
-
result += d[i];
|
|
505
|
-
}
|
|
506
|
-
return result;
|
|
611
|
+
function applyDateMask(digits, schema) {
|
|
612
|
+
return applySchemaMask(digits, schema);
|
|
507
613
|
}
|
|
508
|
-
function applyRangeMask(digits) {
|
|
509
|
-
const
|
|
510
|
-
const
|
|
511
|
-
const
|
|
614
|
+
function applyRangeMask(digits, schema) {
|
|
615
|
+
const total = schema.digitCount * 2;
|
|
616
|
+
const all = digits.slice(0, total);
|
|
617
|
+
const fromMasked = applyDateMask(all.slice(0, schema.digitCount), schema);
|
|
618
|
+
const toDigits = all.slice(schema.digitCount);
|
|
512
619
|
if (toDigits.length === 0) return fromMasked;
|
|
513
|
-
return `${fromMasked} \u2014 ${applyDateMask(toDigits)}`;
|
|
620
|
+
return `${fromMasked} \u2014 ${applyDateMask(toDigits, schema)}`;
|
|
514
621
|
}
|
|
515
622
|
function getRangeCursorPos(masked, digitCount) {
|
|
516
623
|
if (digitCount === 0) return 0;
|
|
@@ -526,17 +633,17 @@ function getRangeCursorPos(masked, digitCount) {
|
|
|
526
633
|
function toDateOnly2(date) {
|
|
527
634
|
return new Date(date.getFullYear(), date.getMonth(), date.getDate(), 12, 0, 0);
|
|
528
635
|
}
|
|
529
|
-
function parseDate(masked) {
|
|
530
|
-
if (masked.replace(/\D/g, "").length !==
|
|
531
|
-
const date = (0, import_date_fns3.parse)(masked,
|
|
532
|
-
if (!(0, import_date_fns3.isValid)(date) || (0, import_date_fns3.format)(date,
|
|
636
|
+
function parseDate(masked, schema) {
|
|
637
|
+
if (masked.replace(/\D/g, "").length !== schema.digitCount) return void 0;
|
|
638
|
+
const date = (0, import_date_fns3.parse)(masked, schema.format, /* @__PURE__ */ new Date());
|
|
639
|
+
if (!(0, import_date_fns3.isValid)(date) || (0, import_date_fns3.format)(date, schema.format) !== masked) return void 0;
|
|
533
640
|
return toDateOnly2(date);
|
|
534
641
|
}
|
|
535
|
-
function formatRange(from, to) {
|
|
642
|
+
function formatRange(from, to, schema) {
|
|
536
643
|
if (!from) return "";
|
|
537
|
-
const fromStr = (0, import_date_fns3.format)(from,
|
|
644
|
+
const fromStr = (0, import_date_fns3.format)(from, schema.format);
|
|
538
645
|
if (!to) return fromStr;
|
|
539
|
-
return `${fromStr} \u2014 ${(0, import_date_fns3.format)(to,
|
|
646
|
+
return `${fromStr} \u2014 ${(0, import_date_fns3.format)(to, schema.format)}`;
|
|
540
647
|
}
|
|
541
648
|
function resolveShowSeconds(showTime) {
|
|
542
649
|
if (!showTime) return false;
|
|
@@ -561,8 +668,16 @@ function DateRangePicker({
|
|
|
561
668
|
showTime,
|
|
562
669
|
icon,
|
|
563
670
|
iconPosition = "end",
|
|
564
|
-
className
|
|
671
|
+
className,
|
|
672
|
+
locale = import_locale2.ru,
|
|
673
|
+
dateFormat: dateFormatProp = DEFAULT_DATE_FORMAT
|
|
565
674
|
}) {
|
|
675
|
+
const schema = (0, import_react4.useMemo)(
|
|
676
|
+
() => buildFormatSchema(dateFormatProp, null, locale),
|
|
677
|
+
[dateFormatProp, locale]
|
|
678
|
+
);
|
|
679
|
+
const maxDigits = schema.digitCount;
|
|
680
|
+
const totalDigits = maxDigits * 2;
|
|
566
681
|
const resolvedIcon = loading ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Spinner, {}) : icon === false ? null : icon != null ? icon : /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(CalendarIcon, {});
|
|
567
682
|
const isControlled = value !== void 0;
|
|
568
683
|
const showSeconds = resolveShowSeconds(showTime);
|
|
@@ -580,7 +695,7 @@ function DateRangePicker({
|
|
|
580
695
|
);
|
|
581
696
|
const [inputValue, setInputValue] = (0, import_react4.useState)(() => {
|
|
582
697
|
const initial = value != null ? value : defaultValue;
|
|
583
|
-
return formatRange(initial == null ? void 0 : initial.from, initial == null ? void 0 : initial.to);
|
|
698
|
+
return formatRange(initial == null ? void 0 : initial.from, initial == null ? void 0 : initial.to, schema);
|
|
584
699
|
});
|
|
585
700
|
const [inputInvalid, setInputInvalid] = (0, import_react4.useState)(false);
|
|
586
701
|
const [open, setOpen] = (0, import_react4.useState)(false);
|
|
@@ -624,7 +739,7 @@ function DateRangePicker({
|
|
|
624
739
|
const lastToTime = (_f = (_e = lastEmittedToRef.current) == null ? void 0 : _e.getTime()) != null ? _f : null;
|
|
625
740
|
if (fromTime === lastFromTime && toTime === lastToTime) return;
|
|
626
741
|
if (!wasControlledRef.current && value === void 0) return;
|
|
627
|
-
setInputValue(formatRange(newFrom, newTo));
|
|
742
|
+
setInputValue(formatRange(newFrom, newTo, schema));
|
|
628
743
|
setInputInvalid(false);
|
|
629
744
|
if (!isControlled) {
|
|
630
745
|
setInternalFrom(newFrom);
|
|
@@ -652,7 +767,7 @@ function DateRangePicker({
|
|
|
652
767
|
setInternalFrom(from);
|
|
653
768
|
setInternalTo(void 0);
|
|
654
769
|
}
|
|
655
|
-
setInputValue(formatRange(from, void 0));
|
|
770
|
+
setInputValue(formatRange(from, void 0, schema));
|
|
656
771
|
setInputInvalid(false);
|
|
657
772
|
lastEmittedFromRef.current = from;
|
|
658
773
|
lastEmittedToRef.current = void 0;
|
|
@@ -675,7 +790,7 @@ function DateRangePicker({
|
|
|
675
790
|
setInternalFrom(from);
|
|
676
791
|
setInternalTo(to);
|
|
677
792
|
}
|
|
678
|
-
setInputValue(formatRange(from, to));
|
|
793
|
+
setInputValue(formatRange(from, to, schema));
|
|
679
794
|
setInputInvalid(false);
|
|
680
795
|
lastEmittedFromRef.current = from;
|
|
681
796
|
lastEmittedToRef.current = to;
|
|
@@ -720,18 +835,18 @@ function DateRangePicker({
|
|
|
720
835
|
const input = e.target;
|
|
721
836
|
const cursorPos = (_a = input.selectionStart) != null ? _a : 0;
|
|
722
837
|
const raw = input.value;
|
|
723
|
-
const digits = raw.replace(/\D/g, "").slice(0,
|
|
724
|
-
const masked = applyRangeMask(digits);
|
|
838
|
+
const digits = raw.replace(/\D/g, "").slice(0, totalDigits);
|
|
839
|
+
const masked = applyRangeMask(digits, schema);
|
|
725
840
|
const digitsBeforeCursor = raw.slice(0, cursorPos).replace(/\D/g, "").length;
|
|
726
841
|
setInputValue(masked);
|
|
727
842
|
setAnchorDate(void 0);
|
|
728
843
|
setHoveredDate(void 0);
|
|
729
|
-
const fromDigits = digits.slice(0,
|
|
730
|
-
const toDigits = digits.slice(
|
|
731
|
-
const parsedFrom = fromDigits.length ===
|
|
732
|
-
const parsedTo = toDigits.length ===
|
|
733
|
-
const fromComplete = fromDigits.length ===
|
|
734
|
-
const toComplete = toDigits.length ===
|
|
844
|
+
const fromDigits = digits.slice(0, maxDigits);
|
|
845
|
+
const toDigits = digits.slice(maxDigits);
|
|
846
|
+
const parsedFrom = fromDigits.length === maxDigits ? parseDate(applyDateMask(fromDigits, schema), schema) : void 0;
|
|
847
|
+
const parsedTo = toDigits.length === maxDigits ? parseDate(applyDateMask(toDigits, schema), schema) : void 0;
|
|
848
|
+
const fromComplete = fromDigits.length === maxDigits;
|
|
849
|
+
const toComplete = toDigits.length === maxDigits;
|
|
735
850
|
setInputInvalid(fromComplete && !parsedFrom || toComplete && !parsedTo);
|
|
736
851
|
if (!isControlled) {
|
|
737
852
|
setInternalFrom(parsedFrom);
|
|
@@ -760,13 +875,18 @@ function DateRangePicker({
|
|
|
760
875
|
e.preventDefault();
|
|
761
876
|
return;
|
|
762
877
|
}
|
|
763
|
-
|
|
878
|
+
const separatorChars = /* @__PURE__ */ new Set([" ", "\u2014"]);
|
|
879
|
+
schema.separators.forEach((s) => {
|
|
880
|
+
for (const ch of s.chars) separatorChars.add(ch);
|
|
881
|
+
});
|
|
882
|
+
if (e.key === "Backspace" && pos > 0 && separatorChars.has(input.value[pos - 1])) {
|
|
764
883
|
e.preventDefault();
|
|
765
884
|
const val = input.value;
|
|
766
885
|
const charsToSkip = (_c = (_b = val.slice(0, pos).match(/[\s—]+$/)) == null ? void 0 : _b[0].length) != null ? _c : 1;
|
|
767
886
|
const newPos = pos - charsToSkip;
|
|
768
887
|
const masked = applyRangeMask(
|
|
769
|
-
(val.slice(0, newPos - 1) + val.slice(newPos)).replace(/\D/g, "")
|
|
888
|
+
(val.slice(0, newPos - 1) + val.slice(newPos)).replace(/\D/g, ""),
|
|
889
|
+
schema
|
|
770
890
|
);
|
|
771
891
|
setInputValue(masked);
|
|
772
892
|
requestAnimationFrame(
|
|
@@ -777,15 +897,18 @@ function DateRangePicker({
|
|
|
777
897
|
function handlePaste(e) {
|
|
778
898
|
e.preventDefault();
|
|
779
899
|
const text = e.clipboardData.getData("text");
|
|
780
|
-
const digits = text.replace(/\D/g, "").slice(0,
|
|
781
|
-
const masked = applyRangeMask(digits);
|
|
900
|
+
const digits = text.replace(/\D/g, "").slice(0, totalDigits);
|
|
901
|
+
const masked = applyRangeMask(digits, schema);
|
|
782
902
|
setInputValue(masked);
|
|
783
903
|
setAnchorDate(void 0);
|
|
784
904
|
setHoveredDate(void 0);
|
|
785
|
-
const parsedFrom = digits.length >=
|
|
786
|
-
const parsedTo = digits.length >=
|
|
905
|
+
const parsedFrom = digits.length >= maxDigits ? parseDate(applyDateMask(digits.slice(0, maxDigits), schema), schema) : void 0;
|
|
906
|
+
const parsedTo = digits.length >= totalDigits ? parseDate(
|
|
907
|
+
applyDateMask(digits.slice(maxDigits, totalDigits), schema),
|
|
908
|
+
schema
|
|
909
|
+
) : void 0;
|
|
787
910
|
setInputInvalid(
|
|
788
|
-
digits.length >=
|
|
911
|
+
digits.length >= maxDigits && !parsedFrom || digits.length >= totalDigits && !parsedTo
|
|
789
912
|
);
|
|
790
913
|
if (!isControlled) {
|
|
791
914
|
setInternalFrom(parsedFrom);
|
|
@@ -803,7 +926,7 @@ function DateRangePicker({
|
|
|
803
926
|
}
|
|
804
927
|
);
|
|
805
928
|
}
|
|
806
|
-
const placeholder = label && !focused && !filled ? void 0 :
|
|
929
|
+
const placeholder = label && !focused && !filled ? void 0 : `${schema.placeholder} \u2014 ${schema.placeholder}`;
|
|
807
930
|
const interactive = !disabled && !loading;
|
|
808
931
|
return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(
|
|
809
932
|
"div",
|
|
@@ -889,7 +1012,7 @@ function DateRangePicker({
|
|
|
889
1012
|
endMonth: toDay,
|
|
890
1013
|
disabled: disabledDays.length ? disabledDays : void 0,
|
|
891
1014
|
numberOfMonths: 2,
|
|
892
|
-
locale
|
|
1015
|
+
locale
|
|
893
1016
|
}
|
|
894
1017
|
) }) }),
|
|
895
1018
|
/* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "datepicker__time-row", children: [
|
|
@@ -941,7 +1064,7 @@ function DateRangePicker({
|
|
|
941
1064
|
startMonth: fromConstraint,
|
|
942
1065
|
endMonth: toConstraint,
|
|
943
1066
|
numberOfMonths: 2,
|
|
944
|
-
locale
|
|
1067
|
+
locale
|
|
945
1068
|
}
|
|
946
1069
|
)
|
|
947
1070
|
}
|