@descope/web-components-ui 1.104.0 → 1.106.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/dist/cjs/index.cjs.js +242 -151
- package/dist/cjs/index.cjs.js.map +1 -1
- package/dist/index.esm.js +242 -151
- package/dist/index.esm.js.map +1 -1
- package/dist/umd/DescopeDev.js +1 -1
- package/dist/umd/DescopeDev.js.map +1 -1
- package/dist/umd/descope-date-field-descope-calendar-index-js.js +1 -1
- package/dist/umd/descope-date-field-descope-calendar-index-js.js.map +1 -1
- package/dist/umd/descope-date-field-index-js.js +1 -1
- package/dist/umd/descope-date-field-index-js.js.map +1 -1
- package/dist/umd/index.js +1 -1
- package/dist/umd/index.js.map +1 -1
- package/package.json +9 -9
- package/src/components/descope-date-field/DateFieldClass.js +147 -56
- package/src/components/descope-date-field/consts.js +2 -0
- package/src/components/descope-date-field/helpers.js +8 -0
package/dist/index.esm.js
CHANGED
@@ -5386,6 +5386,104 @@ loadingIndicatorStyles = `
|
|
5386
5386
|
|
5387
5387
|
customElements.define(componentName$18, ButtonClass);
|
5388
5388
|
|
5389
|
+
const SUPPORTED_FORMATS = ['MM/DD/YYYY', 'DD/MM/YYYY', 'YYYY/MM/DD'];
|
5390
|
+
|
5391
|
+
const DEFAULT_FORMAT = SUPPORTED_FORMATS[0];
|
5392
|
+
|
5393
|
+
const NATIVE_FORMAT = 'YYYY-MM-DD';
|
5394
|
+
|
5395
|
+
const YEARS_RANGE = 100;
|
5396
|
+
|
5397
|
+
const DIVIDER = '/';
|
5398
|
+
|
5399
|
+
const months = [
|
5400
|
+
'January',
|
5401
|
+
'February',
|
5402
|
+
'March',
|
5403
|
+
'April',
|
5404
|
+
'May',
|
5405
|
+
'June',
|
5406
|
+
'July',
|
5407
|
+
'August',
|
5408
|
+
'September',
|
5409
|
+
'October',
|
5410
|
+
'November',
|
5411
|
+
'December',
|
5412
|
+
];
|
5413
|
+
|
5414
|
+
const weekdays = [
|
5415
|
+
'Sunday',
|
5416
|
+
'Monday',
|
5417
|
+
'Tuesday',
|
5418
|
+
'Wednesday',
|
5419
|
+
'Thursday',
|
5420
|
+
'Friday',
|
5421
|
+
'Saturday',
|
5422
|
+
];
|
5423
|
+
|
5424
|
+
const counterConfig = {
|
5425
|
+
MONTH: { id: 'month', min: 1, max: 12, placeholder: 'MM' },
|
5426
|
+
DAY: { id: 'day', min: 1, max: 31, placeholder: 'DD' },
|
5427
|
+
YEAR: { id: 'year', min: 0, max: 9999, placeholder: 'YYYY' },
|
5428
|
+
};
|
5429
|
+
|
5430
|
+
const valRange = {
|
5431
|
+
year: { min: 1900, max: 2099 },
|
5432
|
+
};
|
5433
|
+
|
5434
|
+
const BUTTON_LABEL_DONE = 'Done';
|
5435
|
+
const BUTTON_LABEL_CANCEL = 'Cancel';
|
5436
|
+
const CALENDAR_LABEL_TODAY = 'Today';
|
5437
|
+
|
5438
|
+
const MOBILE_DEVICE_INTERACTION_TIMEOUT_MS = 150;
|
5439
|
+
|
5440
|
+
const patterns = {
|
5441
|
+
MM: '(0?[1-9]|1[0-2])',
|
5442
|
+
DD: '(0?[1-9]|[12][0-9]|3[01])',
|
5443
|
+
YYYY: '([0-9]{4})',
|
5444
|
+
};
|
5445
|
+
|
5446
|
+
const createPattern = (format) => {
|
5447
|
+
const pattern = format
|
5448
|
+
.split(DIVIDER)
|
5449
|
+
.map((part) => patterns[part])
|
5450
|
+
.join('\\D');
|
5451
|
+
|
5452
|
+
return `^${pattern}$`;
|
5453
|
+
};
|
5454
|
+
|
5455
|
+
const createToValuesFn = (format) => {
|
5456
|
+
const order = format.split(DIVIDER);
|
5457
|
+
return (match) => {
|
5458
|
+
const values = {};
|
5459
|
+
order.forEach((part, index) => {
|
5460
|
+
values[part] = match[index + 1];
|
5461
|
+
});
|
5462
|
+
return [values.YYYY, values.MM, values.DD];
|
5463
|
+
};
|
5464
|
+
};
|
5465
|
+
|
5466
|
+
const createDate = (val, regexp, toValuesFn) => {
|
5467
|
+
const match = regexp.exec(val);
|
5468
|
+
if (!match) return null;
|
5469
|
+
const [year, month, day] = toValuesFn(match);
|
5470
|
+
return newDate([year, month, day].join(DIVIDER));
|
5471
|
+
};
|
5472
|
+
|
5473
|
+
const createFormat = (format) => {
|
5474
|
+
const pattern = createPattern(format);
|
5475
|
+
const toValuesFn = createToValuesFn(format);
|
5476
|
+
const regexp = new RegExp(pattern);
|
5477
|
+
|
5478
|
+
return {
|
5479
|
+
pattern,
|
5480
|
+
validate: (val) => regexp.test(val),
|
5481
|
+
getDate: (val) => createDate(val, regexp, toValuesFn),
|
5482
|
+
};
|
5483
|
+
};
|
5484
|
+
|
5485
|
+
const formats = Object.fromEntries(SUPPORTED_FORMATS.map((f) => [f, createFormat(f)]));
|
5486
|
+
|
5389
5487
|
const isValidTimestamp = (val) => !Number.isNaN(Number(val));
|
5390
5488
|
|
5391
5489
|
const isNumber = (val) => !!String(val || '').trim() && !Number.isNaN(Number(val));
|
@@ -5435,6 +5533,12 @@ const overrideConstructedStylesheet = (ele) => {
|
|
5435
5533
|
ele?.shadowRoot?.adoptedStyleSheets?.push(cs);
|
5436
5534
|
};
|
5437
5535
|
|
5536
|
+
const parseDateString = (val, format) => {
|
5537
|
+
const trimmed = val.trim?.();
|
5538
|
+
if (!trimmed) return null;
|
5539
|
+
return formats[format].getDate(trimmed);
|
5540
|
+
};
|
5541
|
+
|
5438
5542
|
const calendarIcon = `
|
5439
5543
|
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
|
5440
5544
|
<path fill-rule="evenodd" clip-rule="evenodd" d="M9 5H15V4.50468C15 4.21404 15.226 4 15.5047 4H16.4953C16.786 4 17 4.22595 17 4.50468V5H18.7568C19.3028 5 19.75 5.44725 19.75 5.99896V7.00104C19.75 7.55734 19.3053 8 18.7568 8H5.24317C4.69717 8 4.25 7.55275 4.25 7.00104V5.99896C4.25 5.44266 4.69466 5 5.24317 5H7V4.50468C7 4.21404 7.22596 4 7.50468 4H8.49532C8.78596 4 9 4.22595 9 4.50468V5ZM5.50468 9H6.49532C6.78596 9 7 9.22596 7 9.50468V10.4953C7 10.786 6.77404 11 6.49532 11H5.50468C5.21404 11 5 10.774 5 10.4953V9.50468C5 9.21404 5.22595 9 5.50468 9ZM8.50468 9H9.49532C9.78596 9 10 9.22596 10 9.50468V10.4953C10 10.786 9.77404 11 9.49532 11H8.50468C8.21404 11 8 10.774 8 10.4953V9.50468C8 9.21404 8.22596 9 8.50468 9ZM11.5047 9H12.4953C12.786 9 13 9.22596 13 9.50468V10.4953C13 10.786 12.774 11 12.4953 11H11.5047C11.214 11 11 10.774 11 10.4953V9.50468C11 9.21404 11.226 9 11.5047 9ZM5.50468 12H6.49532C6.78596 12 7 12.226 7 12.5047V13.4953C7 13.786 6.77404 14 6.49532 14H5.50468C5.21404 14 5 13.774 5 13.4953V12.5047C5 12.214 5.22595 12 5.50468 12ZM8.50468 12H9.49532C9.78596 12 10 12.226 10 12.5047V13.4953C10 13.786 9.77404 14 9.49532 14H8.50468C8.21404 14 8 13.774 8 13.4953V12.5047C8 12.214 8.22596 12 8.50468 12ZM11.5047 12H12.4953C12.786 12 13 12.226 13 12.5047V13.4953C13 13.786 12.774 14 12.4953 14H11.5047C11.214 14 11 13.774 11 13.4953V12.5047C11 12.214 11.226 12 11.5047 12ZM5.50468 15H6.49532C6.78596 15 7 15.226 7 15.5047V16.4953C7 16.786 6.77404 17 6.49532 17H5.50468C5.21404 17 5 16.774 5 16.4953V15.5047C5 15.214 5.22595 15 5.50468 15ZM8.50468 15H9.49532C9.78596 15 10 15.226 10 15.5047V16.4953C10 16.786 9.77404 17 9.49532 17H8.50468C8.21404 17 8 16.774 8 16.4953V15.5047C8 15.214 8.22596 15 8.50468 15ZM11.5047 15H12.4953C12.786 15 13 15.226 13 15.5047V16.4953C13 16.786 12.774 17 12.4953 17H11.5047C11.214 17 11 16.774 11 16.4953V15.5047C11 15.214 11.226 15 11.5047 15ZM14.5047 9H15.4953C15.786 9 16 9.22596 16 9.50468V10.4953C16 10.786 15.774 11 15.4953 11H14.5047C14.214 11 14 10.774 14 10.4953V9.50468C14 9.21404 14.226 9 14.5047 9ZM14.5047 12H15.4953C15.786 12 16 12.226 16 12.5047V13.4953C16 13.786 15.774 14 15.4953 14H14.5047C14.214 14 14 13.774 14 13.4953V12.5047C14 12.214 14.226 12 14.5047 12ZM14.5047 15H15.4953C15.786 15 16 15.226 16 15.5047V16.4953C16 16.786 15.774 17 15.4953 17H14.5047C14.214 17 14 16.774 14 16.4953V15.5047C14 15.214 14.226 15 14.5047 15ZM17.5047 15H18.4953C18.786 15 19 15.226 19 15.5047V16.4953C19 16.786 18.774 17 18.4953 17H17.5047C17.214 17 17 16.774 17 16.4953V15.5047C17 15.214 17.226 15 17.5047 15ZM5.50468 18H6.49532C6.78596 18 7 18.226 7 18.5047V19.4953C7 19.786 6.77404 20 6.49532 20H5.50468C5.21404 20 5 19.774 5 19.4953V18.5047C5 18.214 5.22595 18 5.50468 18ZM8.50468 18H9.49532C9.78596 18 10 18.226 10 18.5047V19.4953C10 19.786 9.77404 20 9.49532 20H8.50468C8.21404 20 8 19.774 8 19.4953V18.5047C8 18.214 8.22596 18 8.50468 18ZM11.5047 18H12.4953C12.786 18 13 18.226 13 18.5047V19.4953C13 19.786 12.774 20 12.4953 20H11.5047C11.214 20 11 19.774 11 19.4953V18.5047C11 18.214 11.226 18 11.5047 18ZM14.5047 18H15.4953C15.786 18 16 18.226 16 18.5047V19.4953C16 19.786 15.774 20 15.4953 20H14.5047C14.214 20 14 19.774 14 19.4953V18.5047C14 18.214 14.226 18 14.5047 18ZM17.5047 18H18.4953C18.786 18 19 18.226 19 18.5047V19.4953C19 19.786 18.774 20 18.4953 20H17.5047C17.214 20 17 19.774 17 19.4953V18.5047C17 18.214 17.226 18 17.5047 18ZM17.5047 12H18.4953C18.786 12 19 12.226 19 12.5047V13.4953C19 13.786 18.774 14 18.4953 14H17.5047C17.214 14 17 13.774 17 13.4953V12.5047C17 12.214 17.226 12 17.5047 12ZM17.5047 9H18.4953C18.786 9 19 9.22596 19 9.50468V10.4953C19 10.786 18.774 11 18.4953 11H17.5047C17.214 11 17 10.774 17 10.4953V9.50468C17 9.21404 17.226 9 17.5047 9Z" fill="#808080"/>
|
@@ -5450,55 +5554,6 @@ const arrowLeftIcon = `<svg width="24" height="24" viewBox="0 0 24 24" fill="non
|
|
5450
5554
|
<path d="M14.7272 17.2193C15.1209 17.6584 15.0841 18.3334 14.6451 18.7272C14.206 19.1209 13.5309 19.0841 13.1372 18.6451C13.1372 18.6451 7.99776 13.0457 7.63399 12.64C7.27023 12.2343 7.27023 11.7608 7.63399 11.3552L13.1372 5.35492C13.5309 4.91587 14.206 4.87912 14.6451 5.27283C15.0841 5.66655 15.1209 6.34164 14.7272 6.78069L9.86322 12L14.7272 17.2193Z" fill="#808080"/>
|
5451
5555
|
</svg>`;
|
5452
5556
|
|
5453
|
-
const SUPPORTED_FORMATS = ['MM/DD/YYYY', 'DD/MM/YYYY', 'YYYY/MM/DD'];
|
5454
|
-
|
5455
|
-
const DEFAULT_FORMAT = SUPPORTED_FORMATS[0];
|
5456
|
-
|
5457
|
-
const NATIVE_FORMAT = 'YYYY-MM-DD';
|
5458
|
-
|
5459
|
-
const YEARS_RANGE = 100;
|
5460
|
-
|
5461
|
-
const DIVIDER = '/';
|
5462
|
-
|
5463
|
-
const months = [
|
5464
|
-
'January',
|
5465
|
-
'February',
|
5466
|
-
'March',
|
5467
|
-
'April',
|
5468
|
-
'May',
|
5469
|
-
'June',
|
5470
|
-
'July',
|
5471
|
-
'August',
|
5472
|
-
'September',
|
5473
|
-
'October',
|
5474
|
-
'November',
|
5475
|
-
'December',
|
5476
|
-
];
|
5477
|
-
|
5478
|
-
const weekdays = [
|
5479
|
-
'Sunday',
|
5480
|
-
'Monday',
|
5481
|
-
'Tuesday',
|
5482
|
-
'Wednesday',
|
5483
|
-
'Thursday',
|
5484
|
-
'Friday',
|
5485
|
-
'Saturday',
|
5486
|
-
];
|
5487
|
-
|
5488
|
-
const counterConfig = {
|
5489
|
-
MONTH: { id: 'month', min: 1, max: 12, placeholder: 'MM' },
|
5490
|
-
DAY: { id: 'day', min: 1, max: 31, placeholder: 'DD' },
|
5491
|
-
YEAR: { id: 'year', min: 0, max: 9999, placeholder: 'YYYY' },
|
5492
|
-
};
|
5493
|
-
|
5494
|
-
const valRange = {
|
5495
|
-
year: { min: 1900, max: 2099 },
|
5496
|
-
};
|
5497
|
-
|
5498
|
-
const BUTTON_LABEL_DONE = 'Done';
|
5499
|
-
const BUTTON_LABEL_CANCEL = 'Cancel';
|
5500
|
-
const CALENDAR_LABEL_TODAY = 'Today';
|
5501
|
-
|
5502
5557
|
const isValidAttrArr = (arr, count) =>
|
5503
5558
|
Array.isArray(arr) && arr.length === count && arr.filter(Boolean).length === count;
|
5504
5559
|
|
@@ -6593,53 +6648,6 @@ const TextFieldClass = compose$1(
|
|
6593
6648
|
|
6594
6649
|
customElements.define(componentName$16, TextFieldClass);
|
6595
6650
|
|
6596
|
-
const patterns = {
|
6597
|
-
MM: '(0?[1-9]|1[0-2])',
|
6598
|
-
DD: '(0?[1-9]|[12][0-9]|3[01])',
|
6599
|
-
YYYY: '([0-9]{4})',
|
6600
|
-
};
|
6601
|
-
|
6602
|
-
const createPattern = (format) => {
|
6603
|
-
const pattern = format
|
6604
|
-
.split(DIVIDER)
|
6605
|
-
.map((part) => patterns[part])
|
6606
|
-
.join('\\D');
|
6607
|
-
|
6608
|
-
return `^${pattern}$`;
|
6609
|
-
};
|
6610
|
-
|
6611
|
-
const createToValuesFn = (format) => {
|
6612
|
-
const order = format.split(DIVIDER);
|
6613
|
-
return (match) => {
|
6614
|
-
const values = {};
|
6615
|
-
order.forEach((part, index) => {
|
6616
|
-
values[part] = match[index + 1];
|
6617
|
-
});
|
6618
|
-
return [values.YYYY, values.MM, values.DD];
|
6619
|
-
};
|
6620
|
-
};
|
6621
|
-
|
6622
|
-
const createDate = (val, regexp, toValuesFn) => {
|
6623
|
-
const match = regexp.exec(val);
|
6624
|
-
if (!match) return null;
|
6625
|
-
const [year, month, day] = toValuesFn(match);
|
6626
|
-
return newDate([year, month, day].join(DIVIDER));
|
6627
|
-
};
|
6628
|
-
|
6629
|
-
const createFormat = (format) => {
|
6630
|
-
const pattern = createPattern(format);
|
6631
|
-
const toValuesFn = createToValuesFn(format);
|
6632
|
-
const regexp = new RegExp(pattern);
|
6633
|
-
|
6634
|
-
return {
|
6635
|
-
pattern,
|
6636
|
-
validate: (val) => regexp.test(val),
|
6637
|
-
getDate: (val) => createDate(val, regexp, toValuesFn),
|
6638
|
-
};
|
6639
|
-
};
|
6640
|
-
|
6641
|
-
const formats = Object.fromEntries(SUPPORTED_FORMATS.map((f) => [f, createFormat(f)]));
|
6642
|
-
|
6643
6651
|
// DateCounterClass allows us to add several counters to the input, and use them seperately.
|
6644
6652
|
// For examele, we have a DayCounter, MonthCounter and YearCounter, which can each separately navigate
|
6645
6653
|
// between different ranges.
|
@@ -6776,8 +6784,6 @@ class RawDateFieldClass extends BaseInputClass$a {
|
|
6776
6784
|
|
6777
6785
|
selectedCounterIdx = 0;
|
6778
6786
|
|
6779
|
-
#focused = false;
|
6780
|
-
|
6781
6787
|
updateCountersDisplay() {
|
6782
6788
|
this.inputElement.value = this.countersValue;
|
6783
6789
|
}
|
@@ -6951,6 +6957,11 @@ class RawDateFieldClass extends BaseInputClass$a {
|
|
6951
6957
|
return this.getAttribute('disable-calendar') === 'true';
|
6952
6958
|
}
|
6953
6959
|
|
6960
|
+
get isSelectAll() {
|
6961
|
+
const inputEle = this.inputElement.baseElement.inputElement;
|
6962
|
+
return inputEle.value.length === inputEle.selectionStart + inputEle.selectionEnd;
|
6963
|
+
}
|
6964
|
+
|
6954
6965
|
reportValidity() {
|
6955
6966
|
this.inputElement.reportValidity();
|
6956
6967
|
}
|
@@ -6985,24 +6996,10 @@ class RawDateFieldClass extends BaseInputClass$a {
|
|
6985
6996
|
this.inputElement.addEventListener('focus', this.onFocus.bind(this));
|
6986
6997
|
this.inputElement.addEventListener('blur', this.onBlur.bind(this));
|
6987
6998
|
this.inputElement.addEventListener('click', this.handleMouseCaretPositionChange.bind(this));
|
6988
|
-
this.inputElement.addEventListener('keydown', this.
|
6999
|
+
this.inputElement.addEventListener('keydown', this.handleKeyboard.bind(this));
|
6989
7000
|
this.inputElement.addEventListener('beforeinput', this.handleInput.bind(this));
|
6990
|
-
|
6991
|
-
|
6992
|
-
// Since we can't seem to block touch events (`touch-action: none` or preventing default on `touchstart`
|
6993
|
-
// or `touchend`, we listen to `pointerdown` and in case it's of type `touch` we execute
|
6994
|
-
// the component's logic for range selection.
|
6995
|
-
this.inputElement.addEventListener('pointerdown', (e) => {
|
6996
|
-
if (e.pointerType === 'touch') {
|
6997
|
-
e.preventDefault();
|
6998
|
-
if (!this.#focused) {
|
6999
|
-
this.inputElement.focus();
|
7000
|
-
}
|
7001
|
-
setTimeout(() => {
|
7002
|
-
this.handleMouseCaretPositionChange(e);
|
7003
|
-
}, 250);
|
7004
|
-
}
|
7005
|
-
});
|
7001
|
+
this.inputElement.addEventListener('pointerdown', this.onPointerDown.bind(this));
|
7002
|
+
this.inputElement.addEventListener('paste', this.onPaste.bind(this));
|
7006
7003
|
|
7007
7004
|
forwardAttrs$1(this, this.inputElement, {
|
7008
7005
|
includeAttrs: [
|
@@ -7031,6 +7028,8 @@ class RawDateFieldClass extends BaseInputClass$a {
|
|
7031
7028
|
handleInput(e) {
|
7032
7029
|
e.preventDefault();
|
7033
7030
|
|
7031
|
+
this.handleSelectAll();
|
7032
|
+
|
7034
7033
|
if (e.data && isNumber(e.data)) {
|
7035
7034
|
this.parseDigits(e.data);
|
7036
7035
|
this.updateCountersDisplay();
|
@@ -7051,6 +7050,12 @@ class RawDateFieldClass extends BaseInputClass$a {
|
|
7051
7050
|
});
|
7052
7051
|
}
|
7053
7052
|
|
7053
|
+
handleSelectAll() {
|
7054
|
+
if (this.isSelectAll) {
|
7055
|
+
this.selectFirstCounter();
|
7056
|
+
}
|
7057
|
+
}
|
7058
|
+
|
7054
7059
|
#popoverPosStylesheet;
|
7055
7060
|
|
7056
7061
|
#popoverRenderer(root) {
|
@@ -7200,16 +7205,19 @@ class RawDateFieldClass extends BaseInputClass$a {
|
|
7200
7205
|
});
|
7201
7206
|
}
|
7202
7207
|
|
7208
|
+
// In mobile devices, there are cases were `pointerdown` is triggered
|
7209
|
+
// instead of `click`.
|
7210
|
+
onPointerDown(e) {
|
7211
|
+
setTimeout(() => this.handleMouseCaretPositionChange(e), MOBILE_DEVICE_INTERACTION_TIMEOUT_MS);
|
7212
|
+
}
|
7213
|
+
|
7203
7214
|
onFocus() {
|
7204
|
-
if (this.isReadOnly
|
7215
|
+
if (this.isReadOnly) {
|
7205
7216
|
return;
|
7206
7217
|
}
|
7207
7218
|
|
7208
|
-
// We
|
7209
|
-
|
7210
|
-
this.#focused = true;
|
7211
|
-
|
7212
|
-
this.resetDisplay();
|
7219
|
+
// We need to wait for focus to end before we set selection
|
7220
|
+
setTimeout(() => this.resetDisplay());
|
7213
7221
|
}
|
7214
7222
|
|
7215
7223
|
resetDisplay() {
|
@@ -7217,18 +7225,13 @@ class RawDateFieldClass extends BaseInputClass$a {
|
|
7217
7225
|
this.inputElement.value = this.format;
|
7218
7226
|
}
|
7219
7227
|
|
7220
|
-
// On focus select the first
|
7221
|
-
this.
|
7222
|
-
|
7223
|
-
|
7224
|
-
// set selection on first counter
|
7225
|
-
this.inputElement.setSelectionRange(0, this.sortedCounters[0].length);
|
7226
|
-
});
|
7228
|
+
// On focus select the first counter
|
7229
|
+
this.selectFirstCounter();
|
7230
|
+
// set selection on first counter
|
7231
|
+
this.inputElement.setSelectionRange(0, this.sortedCounters[0].length);
|
7227
7232
|
}
|
7228
7233
|
|
7229
7234
|
onBlur() {
|
7230
|
-
this.#focused = false;
|
7231
|
-
|
7232
7235
|
if (this.opened) {
|
7233
7236
|
return;
|
7234
7237
|
}
|
@@ -7258,6 +7261,8 @@ class RawDateFieldClass extends BaseInputClass$a {
|
|
7258
7261
|
this.selectNextCounter();
|
7259
7262
|
}
|
7260
7263
|
|
7264
|
+
// We wait for the digit to be parsed, and only then set the selection.
|
7265
|
+
// Failing to do so results in unexpected "jump" of the screen in mobile devices.
|
7261
7266
|
this.setInputSelectionRange();
|
7262
7267
|
}
|
7263
7268
|
|
@@ -7273,10 +7278,18 @@ class RawDateFieldClass extends BaseInputClass$a {
|
|
7273
7278
|
|
7274
7279
|
setSelectedCounterByCaretPosition(e) {
|
7275
7280
|
this.selectedCounterIdx = this.getCounterIdx(
|
7276
|
-
|
7281
|
+
// if triggered by touch event, target might not include `selectionStart`
|
7282
|
+
// in that case we fall back to the inputElement's `selectionStart` value.
|
7283
|
+
// Therefore, it is recommended to run this function with setTimeout,
|
7284
|
+
// at least for mobile events.
|
7285
|
+
e.target?.selectionStart || this.inputElement.selectionStart
|
7277
7286
|
);
|
7278
7287
|
}
|
7279
7288
|
|
7289
|
+
selectFirstCounter() {
|
7290
|
+
this.selectedCounterIdx = 0;
|
7291
|
+
}
|
7292
|
+
|
7280
7293
|
selectNextCounter() {
|
7281
7294
|
if (this.selectedCounterIdx < this.dateCounters.length) {
|
7282
7295
|
this.selectedCounterIdx = Math.min(this.selectedCounterIdx + 1, 2);
|
@@ -7299,14 +7312,18 @@ class RawDateFieldClass extends BaseInputClass$a {
|
|
7299
7312
|
return;
|
7300
7313
|
}
|
7301
7314
|
|
7302
|
-
|
7303
|
-
|
7304
|
-
|
7315
|
+
// We wait for before setting the selection, otherwise there's an
|
7316
|
+
// unexpected "jump" of the screen in mobile devices.
|
7317
|
+
setTimeout(() => {
|
7318
|
+
const caretStart = this.sortedCounters
|
7319
|
+
.slice(0, this.selectedCounterIdx)
|
7320
|
+
.reduce((acc, counter) => acc + counter.length, this.selectedCounterIdx);
|
7305
7321
|
|
7306
|
-
|
7307
|
-
|
7308
|
-
|
7309
|
-
|
7322
|
+
this.inputElement.setSelectionRange(
|
7323
|
+
caretStart,
|
7324
|
+
caretStart + this.sortedCounters[this.selectedCounterIdx].length
|
7325
|
+
);
|
7326
|
+
});
|
7310
7327
|
}
|
7311
7328
|
|
7312
7329
|
resetDateCounters() {
|
@@ -7330,7 +7347,17 @@ class RawDateFieldClass extends BaseInputClass$a {
|
|
7330
7347
|
});
|
7331
7348
|
}
|
7332
7349
|
|
7333
|
-
|
7350
|
+
handleKeyboard(e) {
|
7351
|
+
if (e.metaKey || e.ctrlKey) {
|
7352
|
+
if (e.key.toLowerCase() === 'x') {
|
7353
|
+
this.onCut(e);
|
7354
|
+
}
|
7355
|
+
|
7356
|
+
return;
|
7357
|
+
}
|
7358
|
+
|
7359
|
+
this.handleSelectAll();
|
7360
|
+
|
7334
7361
|
if (e.key === 'ArrowUp') {
|
7335
7362
|
this.activeCounter.inc();
|
7336
7363
|
} else if (e.key === 'ArrowDown') {
|
@@ -7341,9 +7368,7 @@ class RawDateFieldClass extends BaseInputClass$a {
|
|
7341
7368
|
this.selectPrevCounter();
|
7342
7369
|
}
|
7343
7370
|
|
7344
|
-
|
7345
|
-
this.setInputSelectionRange();
|
7346
|
-
});
|
7371
|
+
this.setInputSelectionRange();
|
7347
7372
|
}
|
7348
7373
|
|
7349
7374
|
handleNavKeys(e) {
|
@@ -7365,27 +7390,37 @@ class RawDateFieldClass extends BaseInputClass$a {
|
|
7365
7390
|
}
|
7366
7391
|
|
7367
7392
|
handleBackspace() {
|
7368
|
-
if (this.
|
7369
|
-
this.
|
7393
|
+
if (this.isSelectAll) {
|
7394
|
+
this.resetToInitialState();
|
7395
|
+
return;
|
7396
|
+
}
|
7397
|
+
|
7398
|
+
const counter = this.activeCounter;
|
7399
|
+
|
7400
|
+
if (counter.isEmpty) {
|
7370
7401
|
this.selectPrevCounter();
|
7371
7402
|
this.setInputSelectionRange();
|
7372
7403
|
} else {
|
7373
|
-
|
7404
|
+
counter.set('');
|
7374
7405
|
}
|
7406
|
+
|
7407
|
+
// To support keyboards like SwiftKey, we need to re-render the counters display and selection,
|
7408
|
+
// otherwise we get an unexpected behavior, where the format is deleted.
|
7409
|
+
setTimeout(() => {
|
7410
|
+
this.updateCountersDisplay();
|
7411
|
+
this.setInputSelectionRange();
|
7412
|
+
});
|
7375
7413
|
}
|
7376
7414
|
|
7377
7415
|
handleMouseCaretPositionChange(e) {
|
7378
7416
|
if (this.opened) {
|
7379
7417
|
return;
|
7380
7418
|
}
|
7419
|
+
|
7381
7420
|
e.preventDefault();
|
7382
|
-
this.setSelectedCounterByCaretPosition(e);
|
7383
7421
|
|
7384
|
-
|
7385
|
-
|
7386
|
-
setTimeout(() => {
|
7387
|
-
this.setInputSelectionRange();
|
7388
|
-
});
|
7422
|
+
this.setSelectedCounterByCaretPosition(e);
|
7423
|
+
this.setInputSelectionRange();
|
7389
7424
|
}
|
7390
7425
|
|
7391
7426
|
onInitialValueChange(val) {
|
@@ -7477,6 +7512,62 @@ class RawDateFieldClass extends BaseInputClass$a {
|
|
7477
7512
|
|
7478
7513
|
return ret;
|
7479
7514
|
}
|
7515
|
+
|
7516
|
+
resetToInitialState() {
|
7517
|
+
this.resetDateCounters();
|
7518
|
+
this.selectFirstCounter();
|
7519
|
+
this.resetDisplay();
|
7520
|
+
}
|
7521
|
+
|
7522
|
+
onCut(e) {
|
7523
|
+
e.preventDefault();
|
7524
|
+
|
7525
|
+
if (this.isSelectAll) {
|
7526
|
+
this.#copyToClipboard(this.countersValue);
|
7527
|
+
this.resetToInitialState();
|
7528
|
+
} else {
|
7529
|
+
this.#copyToClipboard(this.activeCounter.stringValue);
|
7530
|
+
this.activeCounter.set('');
|
7531
|
+
}
|
7532
|
+
|
7533
|
+
this.setInputSelectionRange();
|
7534
|
+
}
|
7535
|
+
|
7536
|
+
#copyToClipboard(value) {
|
7537
|
+
try {
|
7538
|
+
navigator.clipboard.writeText(value);
|
7539
|
+
} catch (err) {
|
7540
|
+
console.error('Failed to copy date value:', err);
|
7541
|
+
}
|
7542
|
+
}
|
7543
|
+
|
7544
|
+
onPaste(e) {
|
7545
|
+
e.preventDefault();
|
7546
|
+
|
7547
|
+
const clipboardData = e.clipboardData || window.clipboardData;
|
7548
|
+
const pastedData = clipboardData.getData('Text');
|
7549
|
+
|
7550
|
+
// try paste entire date if valid
|
7551
|
+
const validDate = parseDateString(pastedData, this.format);
|
7552
|
+
|
7553
|
+
if (validDate) {
|
7554
|
+
this.value = validDate.getTime();
|
7555
|
+
this.onDateCounterChange();
|
7556
|
+
|
7557
|
+
// select all
|
7558
|
+
setTimeout(() => this.inputElement.setSelectionRange(0, this.inputElement.value.length));
|
7559
|
+
} else {
|
7560
|
+
const value = Number(pastedData);
|
7561
|
+
|
7562
|
+
// try paste in counter if possible
|
7563
|
+
if (value && this.activeCounter.min <= value && this.activeCounter.max >= value) {
|
7564
|
+
// use String to get rid of any zero padding
|
7565
|
+
this.activeCounter.set(String(value));
|
7566
|
+
|
7567
|
+
setTimeout(() => this.setInputSelectionRange());
|
7568
|
+
}
|
7569
|
+
}
|
7570
|
+
}
|
7480
7571
|
}
|
7481
7572
|
|
7482
7573
|
const textVars$5 = TextFieldClass.cssVarList;
|