@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/cjs/index.cjs.js
CHANGED
@@ -15756,6 +15756,104 @@ var radioButton$1 = /*#__PURE__*/Object.freeze({
|
|
15756
15756
|
vars: vars$j
|
15757
15757
|
});
|
15758
15758
|
|
15759
|
+
const SUPPORTED_FORMATS = ['MM/DD/YYYY', 'DD/MM/YYYY', 'YYYY/MM/DD'];
|
15760
|
+
|
15761
|
+
const DEFAULT_FORMAT = SUPPORTED_FORMATS[0];
|
15762
|
+
|
15763
|
+
const NATIVE_FORMAT = 'YYYY-MM-DD';
|
15764
|
+
|
15765
|
+
const YEARS_RANGE = 100;
|
15766
|
+
|
15767
|
+
const DIVIDER = '/';
|
15768
|
+
|
15769
|
+
const months = [
|
15770
|
+
'January',
|
15771
|
+
'February',
|
15772
|
+
'March',
|
15773
|
+
'April',
|
15774
|
+
'May',
|
15775
|
+
'June',
|
15776
|
+
'July',
|
15777
|
+
'August',
|
15778
|
+
'September',
|
15779
|
+
'October',
|
15780
|
+
'November',
|
15781
|
+
'December',
|
15782
|
+
];
|
15783
|
+
|
15784
|
+
const weekdays = [
|
15785
|
+
'Sunday',
|
15786
|
+
'Monday',
|
15787
|
+
'Tuesday',
|
15788
|
+
'Wednesday',
|
15789
|
+
'Thursday',
|
15790
|
+
'Friday',
|
15791
|
+
'Saturday',
|
15792
|
+
];
|
15793
|
+
|
15794
|
+
const counterConfig = {
|
15795
|
+
MONTH: { id: 'month', min: 1, max: 12, placeholder: 'MM' },
|
15796
|
+
DAY: { id: 'day', min: 1, max: 31, placeholder: 'DD' },
|
15797
|
+
YEAR: { id: 'year', min: 0, max: 9999, placeholder: 'YYYY' },
|
15798
|
+
};
|
15799
|
+
|
15800
|
+
const valRange = {
|
15801
|
+
year: { min: 1900, max: 2099 },
|
15802
|
+
};
|
15803
|
+
|
15804
|
+
const BUTTON_LABEL_DONE = 'Done';
|
15805
|
+
const BUTTON_LABEL_CANCEL = 'Cancel';
|
15806
|
+
const CALENDAR_LABEL_TODAY = 'Today';
|
15807
|
+
|
15808
|
+
const MOBILE_DEVICE_INTERACTION_TIMEOUT_MS = 150;
|
15809
|
+
|
15810
|
+
const patterns = {
|
15811
|
+
MM: '(0?[1-9]|1[0-2])',
|
15812
|
+
DD: '(0?[1-9]|[12][0-9]|3[01])',
|
15813
|
+
YYYY: '([0-9]{4})',
|
15814
|
+
};
|
15815
|
+
|
15816
|
+
const createPattern = (format) => {
|
15817
|
+
const pattern = format
|
15818
|
+
.split(DIVIDER)
|
15819
|
+
.map((part) => patterns[part])
|
15820
|
+
.join('\\D');
|
15821
|
+
|
15822
|
+
return `^${pattern}$`;
|
15823
|
+
};
|
15824
|
+
|
15825
|
+
const createToValuesFn = (format) => {
|
15826
|
+
const order = format.split(DIVIDER);
|
15827
|
+
return (match) => {
|
15828
|
+
const values = {};
|
15829
|
+
order.forEach((part, index) => {
|
15830
|
+
values[part] = match[index + 1];
|
15831
|
+
});
|
15832
|
+
return [values.YYYY, values.MM, values.DD];
|
15833
|
+
};
|
15834
|
+
};
|
15835
|
+
|
15836
|
+
const createDate = (val, regexp, toValuesFn) => {
|
15837
|
+
const match = regexp.exec(val);
|
15838
|
+
if (!match) return null;
|
15839
|
+
const [year, month, day] = toValuesFn(match);
|
15840
|
+
return newDate([year, month, day].join(DIVIDER));
|
15841
|
+
};
|
15842
|
+
|
15843
|
+
const createFormat = (format) => {
|
15844
|
+
const pattern = createPattern(format);
|
15845
|
+
const toValuesFn = createToValuesFn(format);
|
15846
|
+
const regexp = new RegExp(pattern);
|
15847
|
+
|
15848
|
+
return {
|
15849
|
+
pattern,
|
15850
|
+
validate: (val) => regexp.test(val),
|
15851
|
+
getDate: (val) => createDate(val, regexp, toValuesFn),
|
15852
|
+
};
|
15853
|
+
};
|
15854
|
+
|
15855
|
+
const formats = Object.fromEntries(SUPPORTED_FORMATS.map((f) => [f, createFormat(f)]));
|
15856
|
+
|
15759
15857
|
const isValidTimestamp = (val) => !Number.isNaN(Number(val));
|
15760
15858
|
|
15761
15859
|
const isNumber = (val) => !!String(val || '').trim() && !Number.isNaN(Number(val));
|
@@ -15805,6 +15903,12 @@ const overrideConstructedStylesheet = (ele) => {
|
|
15805
15903
|
ele?.shadowRoot?.adoptedStyleSheets?.push(cs);
|
15806
15904
|
};
|
15807
15905
|
|
15906
|
+
const parseDateString = (val, format) => {
|
15907
|
+
const trimmed = val.trim?.();
|
15908
|
+
if (!trimmed) return null;
|
15909
|
+
return formats[format].getDate(trimmed);
|
15910
|
+
};
|
15911
|
+
|
15808
15912
|
const calendarIcon = `
|
15809
15913
|
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
|
15810
15914
|
<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"/>
|
@@ -15820,55 +15924,6 @@ const arrowLeftIcon = `<svg width="24" height="24" viewBox="0 0 24 24" fill="non
|
|
15820
15924
|
<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"/>
|
15821
15925
|
</svg>`;
|
15822
15926
|
|
15823
|
-
const SUPPORTED_FORMATS = ['MM/DD/YYYY', 'DD/MM/YYYY', 'YYYY/MM/DD'];
|
15824
|
-
|
15825
|
-
const DEFAULT_FORMAT = SUPPORTED_FORMATS[0];
|
15826
|
-
|
15827
|
-
const NATIVE_FORMAT = 'YYYY-MM-DD';
|
15828
|
-
|
15829
|
-
const YEARS_RANGE = 100;
|
15830
|
-
|
15831
|
-
const DIVIDER = '/';
|
15832
|
-
|
15833
|
-
const months = [
|
15834
|
-
'January',
|
15835
|
-
'February',
|
15836
|
-
'March',
|
15837
|
-
'April',
|
15838
|
-
'May',
|
15839
|
-
'June',
|
15840
|
-
'July',
|
15841
|
-
'August',
|
15842
|
-
'September',
|
15843
|
-
'October',
|
15844
|
-
'November',
|
15845
|
-
'December',
|
15846
|
-
];
|
15847
|
-
|
15848
|
-
const weekdays = [
|
15849
|
-
'Sunday',
|
15850
|
-
'Monday',
|
15851
|
-
'Tuesday',
|
15852
|
-
'Wednesday',
|
15853
|
-
'Thursday',
|
15854
|
-
'Friday',
|
15855
|
-
'Saturday',
|
15856
|
-
];
|
15857
|
-
|
15858
|
-
const counterConfig = {
|
15859
|
-
MONTH: { id: 'month', min: 1, max: 12, placeholder: 'MM' },
|
15860
|
-
DAY: { id: 'day', min: 1, max: 31, placeholder: 'DD' },
|
15861
|
-
YEAR: { id: 'year', min: 0, max: 9999, placeholder: 'YYYY' },
|
15862
|
-
};
|
15863
|
-
|
15864
|
-
const valRange = {
|
15865
|
-
year: { min: 1900, max: 2099 },
|
15866
|
-
};
|
15867
|
-
|
15868
|
-
const BUTTON_LABEL_DONE = 'Done';
|
15869
|
-
const BUTTON_LABEL_CANCEL = 'Cancel';
|
15870
|
-
const CALENDAR_LABEL_TODAY = 'Today';
|
15871
|
-
|
15872
15927
|
const isValidAttrArr = (arr, count) =>
|
15873
15928
|
Array.isArray(arr) && arr.length === count && arr.filter(Boolean).length === count;
|
15874
15929
|
|
@@ -16770,53 +16825,6 @@ var calendar$1 = /*#__PURE__*/Object.freeze({
|
|
16770
16825
|
vars: vars$i
|
16771
16826
|
});
|
16772
16827
|
|
16773
|
-
const patterns = {
|
16774
|
-
MM: '(0?[1-9]|1[0-2])',
|
16775
|
-
DD: '(0?[1-9]|[12][0-9]|3[01])',
|
16776
|
-
YYYY: '([0-9]{4})',
|
16777
|
-
};
|
16778
|
-
|
16779
|
-
const createPattern = (format) => {
|
16780
|
-
const pattern = format
|
16781
|
-
.split(DIVIDER)
|
16782
|
-
.map((part) => patterns[part])
|
16783
|
-
.join('\\D');
|
16784
|
-
|
16785
|
-
return `^${pattern}$`;
|
16786
|
-
};
|
16787
|
-
|
16788
|
-
const createToValuesFn = (format) => {
|
16789
|
-
const order = format.split(DIVIDER);
|
16790
|
-
return (match) => {
|
16791
|
-
const values = {};
|
16792
|
-
order.forEach((part, index) => {
|
16793
|
-
values[part] = match[index + 1];
|
16794
|
-
});
|
16795
|
-
return [values.YYYY, values.MM, values.DD];
|
16796
|
-
};
|
16797
|
-
};
|
16798
|
-
|
16799
|
-
const createDate = (val, regexp, toValuesFn) => {
|
16800
|
-
const match = regexp.exec(val);
|
16801
|
-
if (!match) return null;
|
16802
|
-
const [year, month, day] = toValuesFn(match);
|
16803
|
-
return newDate([year, month, day].join(DIVIDER));
|
16804
|
-
};
|
16805
|
-
|
16806
|
-
const createFormat = (format) => {
|
16807
|
-
const pattern = createPattern(format);
|
16808
|
-
const toValuesFn = createToValuesFn(format);
|
16809
|
-
const regexp = new RegExp(pattern);
|
16810
|
-
|
16811
|
-
return {
|
16812
|
-
pattern,
|
16813
|
-
validate: (val) => regexp.test(val),
|
16814
|
-
getDate: (val) => createDate(val, regexp, toValuesFn),
|
16815
|
-
};
|
16816
|
-
};
|
16817
|
-
|
16818
|
-
const formats = Object.fromEntries(SUPPORTED_FORMATS.map((f) => [f, createFormat(f)]));
|
16819
|
-
|
16820
16828
|
// DateCounterClass allows us to add several counters to the input, and use them seperately.
|
16821
16829
|
// For examele, we have a DayCounter, MonthCounter and YearCounter, which can each separately navigate
|
16822
16830
|
// between different ranges.
|
@@ -16953,8 +16961,6 @@ class RawDateFieldClass extends BaseInputClass$1 {
|
|
16953
16961
|
|
16954
16962
|
selectedCounterIdx = 0;
|
16955
16963
|
|
16956
|
-
#focused = false;
|
16957
|
-
|
16958
16964
|
updateCountersDisplay() {
|
16959
16965
|
this.inputElement.value = this.countersValue;
|
16960
16966
|
}
|
@@ -17128,6 +17134,11 @@ class RawDateFieldClass extends BaseInputClass$1 {
|
|
17128
17134
|
return this.getAttribute('disable-calendar') === 'true';
|
17129
17135
|
}
|
17130
17136
|
|
17137
|
+
get isSelectAll() {
|
17138
|
+
const inputEle = this.inputElement.baseElement.inputElement;
|
17139
|
+
return inputEle.value.length === inputEle.selectionStart + inputEle.selectionEnd;
|
17140
|
+
}
|
17141
|
+
|
17131
17142
|
reportValidity() {
|
17132
17143
|
this.inputElement.reportValidity();
|
17133
17144
|
}
|
@@ -17162,24 +17173,10 @@ class RawDateFieldClass extends BaseInputClass$1 {
|
|
17162
17173
|
this.inputElement.addEventListener('focus', this.onFocus.bind(this));
|
17163
17174
|
this.inputElement.addEventListener('blur', this.onBlur.bind(this));
|
17164
17175
|
this.inputElement.addEventListener('click', this.handleMouseCaretPositionChange.bind(this));
|
17165
|
-
this.inputElement.addEventListener('keydown', this.
|
17176
|
+
this.inputElement.addEventListener('keydown', this.handleKeyboard.bind(this));
|
17166
17177
|
this.inputElement.addEventListener('beforeinput', this.handleInput.bind(this));
|
17167
|
-
|
17168
|
-
|
17169
|
-
// Since we can't seem to block touch events (`touch-action: none` or preventing default on `touchstart`
|
17170
|
-
// or `touchend`, we listen to `pointerdown` and in case it's of type `touch` we execute
|
17171
|
-
// the component's logic for range selection.
|
17172
|
-
this.inputElement.addEventListener('pointerdown', (e) => {
|
17173
|
-
if (e.pointerType === 'touch') {
|
17174
|
-
e.preventDefault();
|
17175
|
-
if (!this.#focused) {
|
17176
|
-
this.inputElement.focus();
|
17177
|
-
}
|
17178
|
-
setTimeout(() => {
|
17179
|
-
this.handleMouseCaretPositionChange(e);
|
17180
|
-
}, 250);
|
17181
|
-
}
|
17182
|
-
});
|
17178
|
+
this.inputElement.addEventListener('pointerdown', this.onPointerDown.bind(this));
|
17179
|
+
this.inputElement.addEventListener('paste', this.onPaste.bind(this));
|
17183
17180
|
|
17184
17181
|
forwardAttrs$1(this, this.inputElement, {
|
17185
17182
|
includeAttrs: [
|
@@ -17208,6 +17205,8 @@ class RawDateFieldClass extends BaseInputClass$1 {
|
|
17208
17205
|
handleInput(e) {
|
17209
17206
|
e.preventDefault();
|
17210
17207
|
|
17208
|
+
this.handleSelectAll();
|
17209
|
+
|
17211
17210
|
if (e.data && isNumber(e.data)) {
|
17212
17211
|
this.parseDigits(e.data);
|
17213
17212
|
this.updateCountersDisplay();
|
@@ -17228,6 +17227,12 @@ class RawDateFieldClass extends BaseInputClass$1 {
|
|
17228
17227
|
});
|
17229
17228
|
}
|
17230
17229
|
|
17230
|
+
handleSelectAll() {
|
17231
|
+
if (this.isSelectAll) {
|
17232
|
+
this.selectFirstCounter();
|
17233
|
+
}
|
17234
|
+
}
|
17235
|
+
|
17231
17236
|
#popoverPosStylesheet;
|
17232
17237
|
|
17233
17238
|
#popoverRenderer(root) {
|
@@ -17377,16 +17382,19 @@ class RawDateFieldClass extends BaseInputClass$1 {
|
|
17377
17382
|
});
|
17378
17383
|
}
|
17379
17384
|
|
17385
|
+
// In mobile devices, there are cases were `pointerdown` is triggered
|
17386
|
+
// instead of `click`.
|
17387
|
+
onPointerDown(e) {
|
17388
|
+
setTimeout(() => this.handleMouseCaretPositionChange(e), MOBILE_DEVICE_INTERACTION_TIMEOUT_MS);
|
17389
|
+
}
|
17390
|
+
|
17380
17391
|
onFocus() {
|
17381
|
-
if (this.isReadOnly
|
17392
|
+
if (this.isReadOnly) {
|
17382
17393
|
return;
|
17383
17394
|
}
|
17384
17395
|
|
17385
|
-
// We
|
17386
|
-
|
17387
|
-
this.#focused = true;
|
17388
|
-
|
17389
|
-
this.resetDisplay();
|
17396
|
+
// We need to wait for focus to end before we set selection
|
17397
|
+
setTimeout(() => this.resetDisplay());
|
17390
17398
|
}
|
17391
17399
|
|
17392
17400
|
resetDisplay() {
|
@@ -17394,18 +17402,13 @@ class RawDateFieldClass extends BaseInputClass$1 {
|
|
17394
17402
|
this.inputElement.value = this.format;
|
17395
17403
|
}
|
17396
17404
|
|
17397
|
-
// On focus select the first
|
17398
|
-
this.
|
17399
|
-
|
17400
|
-
|
17401
|
-
// set selection on first counter
|
17402
|
-
this.inputElement.setSelectionRange(0, this.sortedCounters[0].length);
|
17403
|
-
});
|
17405
|
+
// On focus select the first counter
|
17406
|
+
this.selectFirstCounter();
|
17407
|
+
// set selection on first counter
|
17408
|
+
this.inputElement.setSelectionRange(0, this.sortedCounters[0].length);
|
17404
17409
|
}
|
17405
17410
|
|
17406
17411
|
onBlur() {
|
17407
|
-
this.#focused = false;
|
17408
|
-
|
17409
17412
|
if (this.opened) {
|
17410
17413
|
return;
|
17411
17414
|
}
|
@@ -17435,6 +17438,8 @@ class RawDateFieldClass extends BaseInputClass$1 {
|
|
17435
17438
|
this.selectNextCounter();
|
17436
17439
|
}
|
17437
17440
|
|
17441
|
+
// We wait for the digit to be parsed, and only then set the selection.
|
17442
|
+
// Failing to do so results in unexpected "jump" of the screen in mobile devices.
|
17438
17443
|
this.setInputSelectionRange();
|
17439
17444
|
}
|
17440
17445
|
|
@@ -17450,10 +17455,18 @@ class RawDateFieldClass extends BaseInputClass$1 {
|
|
17450
17455
|
|
17451
17456
|
setSelectedCounterByCaretPosition(e) {
|
17452
17457
|
this.selectedCounterIdx = this.getCounterIdx(
|
17453
|
-
|
17458
|
+
// if triggered by touch event, target might not include `selectionStart`
|
17459
|
+
// in that case we fall back to the inputElement's `selectionStart` value.
|
17460
|
+
// Therefore, it is recommended to run this function with setTimeout,
|
17461
|
+
// at least for mobile events.
|
17462
|
+
e.target?.selectionStart || this.inputElement.selectionStart
|
17454
17463
|
);
|
17455
17464
|
}
|
17456
17465
|
|
17466
|
+
selectFirstCounter() {
|
17467
|
+
this.selectedCounterIdx = 0;
|
17468
|
+
}
|
17469
|
+
|
17457
17470
|
selectNextCounter() {
|
17458
17471
|
if (this.selectedCounterIdx < this.dateCounters.length) {
|
17459
17472
|
this.selectedCounterIdx = Math.min(this.selectedCounterIdx + 1, 2);
|
@@ -17476,14 +17489,18 @@ class RawDateFieldClass extends BaseInputClass$1 {
|
|
17476
17489
|
return;
|
17477
17490
|
}
|
17478
17491
|
|
17479
|
-
|
17480
|
-
|
17481
|
-
|
17492
|
+
// We wait for before setting the selection, otherwise there's an
|
17493
|
+
// unexpected "jump" of the screen in mobile devices.
|
17494
|
+
setTimeout(() => {
|
17495
|
+
const caretStart = this.sortedCounters
|
17496
|
+
.slice(0, this.selectedCounterIdx)
|
17497
|
+
.reduce((acc, counter) => acc + counter.length, this.selectedCounterIdx);
|
17482
17498
|
|
17483
|
-
|
17484
|
-
|
17485
|
-
|
17486
|
-
|
17499
|
+
this.inputElement.setSelectionRange(
|
17500
|
+
caretStart,
|
17501
|
+
caretStart + this.sortedCounters[this.selectedCounterIdx].length
|
17502
|
+
);
|
17503
|
+
});
|
17487
17504
|
}
|
17488
17505
|
|
17489
17506
|
resetDateCounters() {
|
@@ -17507,7 +17524,17 @@ class RawDateFieldClass extends BaseInputClass$1 {
|
|
17507
17524
|
});
|
17508
17525
|
}
|
17509
17526
|
|
17510
|
-
|
17527
|
+
handleKeyboard(e) {
|
17528
|
+
if (e.metaKey || e.ctrlKey) {
|
17529
|
+
if (e.key.toLowerCase() === 'x') {
|
17530
|
+
this.onCut(e);
|
17531
|
+
}
|
17532
|
+
|
17533
|
+
return;
|
17534
|
+
}
|
17535
|
+
|
17536
|
+
this.handleSelectAll();
|
17537
|
+
|
17511
17538
|
if (e.key === 'ArrowUp') {
|
17512
17539
|
this.activeCounter.inc();
|
17513
17540
|
} else if (e.key === 'ArrowDown') {
|
@@ -17518,9 +17545,7 @@ class RawDateFieldClass extends BaseInputClass$1 {
|
|
17518
17545
|
this.selectPrevCounter();
|
17519
17546
|
}
|
17520
17547
|
|
17521
|
-
|
17522
|
-
this.setInputSelectionRange();
|
17523
|
-
});
|
17548
|
+
this.setInputSelectionRange();
|
17524
17549
|
}
|
17525
17550
|
|
17526
17551
|
handleNavKeys(e) {
|
@@ -17542,27 +17567,37 @@ class RawDateFieldClass extends BaseInputClass$1 {
|
|
17542
17567
|
}
|
17543
17568
|
|
17544
17569
|
handleBackspace() {
|
17545
|
-
if (this.
|
17546
|
-
this.
|
17570
|
+
if (this.isSelectAll) {
|
17571
|
+
this.resetToInitialState();
|
17572
|
+
return;
|
17573
|
+
}
|
17574
|
+
|
17575
|
+
const counter = this.activeCounter;
|
17576
|
+
|
17577
|
+
if (counter.isEmpty) {
|
17547
17578
|
this.selectPrevCounter();
|
17548
17579
|
this.setInputSelectionRange();
|
17549
17580
|
} else {
|
17550
|
-
|
17581
|
+
counter.set('');
|
17551
17582
|
}
|
17583
|
+
|
17584
|
+
// To support keyboards like SwiftKey, we need to re-render the counters display and selection,
|
17585
|
+
// otherwise we get an unexpected behavior, where the format is deleted.
|
17586
|
+
setTimeout(() => {
|
17587
|
+
this.updateCountersDisplay();
|
17588
|
+
this.setInputSelectionRange();
|
17589
|
+
});
|
17552
17590
|
}
|
17553
17591
|
|
17554
17592
|
handleMouseCaretPositionChange(e) {
|
17555
17593
|
if (this.opened) {
|
17556
17594
|
return;
|
17557
17595
|
}
|
17596
|
+
|
17558
17597
|
e.preventDefault();
|
17559
|
-
this.setSelectedCounterByCaretPosition(e);
|
17560
17598
|
|
17561
|
-
|
17562
|
-
|
17563
|
-
setTimeout(() => {
|
17564
|
-
this.setInputSelectionRange();
|
17565
|
-
});
|
17599
|
+
this.setSelectedCounterByCaretPosition(e);
|
17600
|
+
this.setInputSelectionRange();
|
17566
17601
|
}
|
17567
17602
|
|
17568
17603
|
onInitialValueChange(val) {
|
@@ -17654,6 +17689,62 @@ class RawDateFieldClass extends BaseInputClass$1 {
|
|
17654
17689
|
|
17655
17690
|
return ret;
|
17656
17691
|
}
|
17692
|
+
|
17693
|
+
resetToInitialState() {
|
17694
|
+
this.resetDateCounters();
|
17695
|
+
this.selectFirstCounter();
|
17696
|
+
this.resetDisplay();
|
17697
|
+
}
|
17698
|
+
|
17699
|
+
onCut(e) {
|
17700
|
+
e.preventDefault();
|
17701
|
+
|
17702
|
+
if (this.isSelectAll) {
|
17703
|
+
this.#copyToClipboard(this.countersValue);
|
17704
|
+
this.resetToInitialState();
|
17705
|
+
} else {
|
17706
|
+
this.#copyToClipboard(this.activeCounter.stringValue);
|
17707
|
+
this.activeCounter.set('');
|
17708
|
+
}
|
17709
|
+
|
17710
|
+
this.setInputSelectionRange();
|
17711
|
+
}
|
17712
|
+
|
17713
|
+
#copyToClipboard(value) {
|
17714
|
+
try {
|
17715
|
+
navigator.clipboard.writeText(value);
|
17716
|
+
} catch (err) {
|
17717
|
+
console.error('Failed to copy date value:', err);
|
17718
|
+
}
|
17719
|
+
}
|
17720
|
+
|
17721
|
+
onPaste(e) {
|
17722
|
+
e.preventDefault();
|
17723
|
+
|
17724
|
+
const clipboardData = e.clipboardData || window.clipboardData;
|
17725
|
+
const pastedData = clipboardData.getData('Text');
|
17726
|
+
|
17727
|
+
// try paste entire date if valid
|
17728
|
+
const validDate = parseDateString(pastedData, this.format);
|
17729
|
+
|
17730
|
+
if (validDate) {
|
17731
|
+
this.value = validDate.getTime();
|
17732
|
+
this.onDateCounterChange();
|
17733
|
+
|
17734
|
+
// select all
|
17735
|
+
setTimeout(() => this.inputElement.setSelectionRange(0, this.inputElement.value.length));
|
17736
|
+
} else {
|
17737
|
+
const value = Number(pastedData);
|
17738
|
+
|
17739
|
+
// try paste in counter if possible
|
17740
|
+
if (value && this.activeCounter.min <= value && this.activeCounter.max >= value) {
|
17741
|
+
// use String to get rid of any zero padding
|
17742
|
+
this.activeCounter.set(String(value));
|
17743
|
+
|
17744
|
+
setTimeout(() => this.setInputSelectionRange());
|
17745
|
+
}
|
17746
|
+
}
|
17747
|
+
}
|
17657
17748
|
}
|
17658
17749
|
|
17659
17750
|
const textVars$1 = TextFieldClass.cssVarList;
|