@descope/web-components-ui 1.92.0 → 1.94.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 +127 -127
- package/dist/cjs/index.cjs.js.map +1 -1
- package/dist/index.esm.js +127 -127
- 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/package.json +1 -1
- package/src/components/descope-date-field/DateFieldClass.js +81 -49
- package/src/components/descope-date-field/consts.js +0 -12
- package/src/components/descope-date-field/helpers.js +1 -25
package/dist/cjs/index.cjs.js
CHANGED
@@ -15577,66 +15577,9 @@ var radioButton$1 = /*#__PURE__*/Object.freeze({
|
|
15577
15577
|
vars: vars$i
|
15578
15578
|
});
|
15579
15579
|
|
15580
|
-
const SUPPORTED_FORMATS = ['MM/DD/YYYY', 'DD/MM/YYYY', 'YYYY/MM/DD'];
|
15581
|
-
|
15582
|
-
const DEFAULT_FORMAT = SUPPORTED_FORMATS[0];
|
15583
|
-
|
15584
|
-
const NATIVE_FORMAT = 'YYYY-MM-DD';
|
15585
|
-
|
15586
|
-
const YEARS_RANGE = 100;
|
15587
|
-
|
15588
|
-
const DIVIDER = '/';
|
15589
|
-
|
15590
|
-
const COUNTER_SUPPORTED_KEYS = [
|
15591
|
-
'Backspace',
|
15592
|
-
'ArrowLeft',
|
15593
|
-
'ArrowRight',
|
15594
|
-
'ArrowDown',
|
15595
|
-
'ArrowUp',
|
15596
|
-
'PageUp',
|
15597
|
-
'PageDown',
|
15598
|
-
'Meta',
|
15599
|
-
'Enter',
|
15600
|
-
];
|
15601
|
-
|
15602
|
-
const months = [
|
15603
|
-
'January',
|
15604
|
-
'February',
|
15605
|
-
'March',
|
15606
|
-
'April',
|
15607
|
-
'May',
|
15608
|
-
'June',
|
15609
|
-
'July',
|
15610
|
-
'August',
|
15611
|
-
'September',
|
15612
|
-
'October',
|
15613
|
-
'November',
|
15614
|
-
'December',
|
15615
|
-
];
|
15616
|
-
|
15617
|
-
const weekdays = [
|
15618
|
-
'Sunday',
|
15619
|
-
'Monday',
|
15620
|
-
'Tuesday',
|
15621
|
-
'Wednesday',
|
15622
|
-
'Thursday',
|
15623
|
-
'Friday',
|
15624
|
-
'Saturday',
|
15625
|
-
];
|
15626
|
-
|
15627
|
-
const counterConfig = {
|
15628
|
-
MONTH: { id: 'month', min: 1, max: 12, placeholder: 'MM', count: 5, shiftCount: 10 },
|
15629
|
-
DAY: { id: 'day', min: 1, max: 31, placeholder: 'DD', count: 5, shiftCount: 10 },
|
15630
|
-
YEAR: { id: 'year', min: 1900, max: 2099, placeholder: 'YYYY', count: 10, shiftCount: 100 },
|
15631
|
-
};
|
15632
|
-
|
15633
|
-
const BUTTON_LABEL_DONE = 'Done';
|
15634
|
-
const BUTTON_LABEL_CANCEL = 'Cancel';
|
15635
|
-
const CALENDAR_LABEL_TODAY = 'Today';
|
15636
|
-
|
15637
15580
|
const isValidTimestamp = (val) => !Number.isNaN(Number(val));
|
15638
15581
|
|
15639
|
-
const isNumber = (val) => !Number.isNaN(Number(val));
|
15582
|
+
const isNumber = (val) => !!String(val || '').trim() && !Number.isNaN(Number(val));
|
15640
15583
|
|
15641
15584
|
const getTimestampParts = (timestamp) => {
|
15642
15585
|
const date = newDate(timestamp);
|
@@ -15669,28 +15612,6 @@ const newDate = (date) => {
|
|
15669
15612
|
return new Date();
|
15670
15613
|
};
|
15671
15614
|
|
15672
|
-
const isSupportedKey = (key) => COUNTER_SUPPORTED_KEYS.includes(key);
|
15673
|
-
|
15674
|
-
const getKeyMap = (key, shiftKey, metaKey) => {
|
15675
|
-
return {
|
15676
|
-
refresh: metaKey && key.toLowerCase() === 'r',
|
15677
|
-
tab: key === 'Tab',
|
15678
|
-
shiftTab: shiftKey && key === 'Tab',
|
15679
|
-
backspace: key === 'Backspace',
|
15680
|
-
arrowUp: !shiftKey && key === 'ArrowUp',
|
15681
|
-
arrowDown: !shiftKey && key === 'ArrowDown',
|
15682
|
-
arrowLeft: !shiftKey && key === 'ArrowLeft',
|
15683
|
-
arrowRight: !shiftKey && key === 'ArrowRight',
|
15684
|
-
pageUp: !shiftKey && key === 'PageUp',
|
15685
|
-
pageDown: !shiftKey && key === 'PageDown',
|
15686
|
-
shiftArrowUp: shiftKey && key === 'ArrowUp',
|
15687
|
-
shiftArrowDown: shiftKey && key === 'ArrowDown',
|
15688
|
-
shiftPageUp: shiftKey && key === 'PageUp',
|
15689
|
-
shiftPageDown: shiftKey && key === 'PageDown',
|
15690
|
-
enter: key === 'Enter',
|
15691
|
-
};
|
15692
|
-
};
|
15693
|
-
|
15694
15615
|
const getCurrentTime = () => newDate().getTime();
|
15695
15616
|
const getFullYear = (timestamp) => newDate(timestamp).getFullYear().toString();
|
15696
15617
|
const getMonth = (timestamp) => (newDate(timestamp).getMonth() + 1).toString();
|
@@ -15720,6 +15641,51 @@ const arrowLeftIcon = `<svg width="24" height="24" viewBox="0 0 24 24" fill="non
|
|
15720
15641
|
<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"/>
|
15721
15642
|
</svg>`;
|
15722
15643
|
|
15644
|
+
const SUPPORTED_FORMATS = ['MM/DD/YYYY', 'DD/MM/YYYY', 'YYYY/MM/DD'];
|
15645
|
+
|
15646
|
+
const DEFAULT_FORMAT = SUPPORTED_FORMATS[0];
|
15647
|
+
|
15648
|
+
const NATIVE_FORMAT = 'YYYY-MM-DD';
|
15649
|
+
|
15650
|
+
const YEARS_RANGE = 100;
|
15651
|
+
|
15652
|
+
const DIVIDER = '/';
|
15653
|
+
|
15654
|
+
const months = [
|
15655
|
+
'January',
|
15656
|
+
'February',
|
15657
|
+
'March',
|
15658
|
+
'April',
|
15659
|
+
'May',
|
15660
|
+
'June',
|
15661
|
+
'July',
|
15662
|
+
'August',
|
15663
|
+
'September',
|
15664
|
+
'October',
|
15665
|
+
'November',
|
15666
|
+
'December',
|
15667
|
+
];
|
15668
|
+
|
15669
|
+
const weekdays = [
|
15670
|
+
'Sunday',
|
15671
|
+
'Monday',
|
15672
|
+
'Tuesday',
|
15673
|
+
'Wednesday',
|
15674
|
+
'Thursday',
|
15675
|
+
'Friday',
|
15676
|
+
'Saturday',
|
15677
|
+
];
|
15678
|
+
|
15679
|
+
const counterConfig = {
|
15680
|
+
MONTH: { id: 'month', min: 1, max: 12, placeholder: 'MM', count: 5, shiftCount: 10 },
|
15681
|
+
DAY: { id: 'day', min: 1, max: 31, placeholder: 'DD', count: 5, shiftCount: 10 },
|
15682
|
+
YEAR: { id: 'year', min: 1900, max: 2099, placeholder: 'YYYY', count: 10, shiftCount: 100 },
|
15683
|
+
};
|
15684
|
+
|
15685
|
+
const BUTTON_LABEL_DONE = 'Done';
|
15686
|
+
const BUTTON_LABEL_CANCEL = 'Cancel';
|
15687
|
+
const CALENDAR_LABEL_TODAY = 'Today';
|
15688
|
+
|
15723
15689
|
const isValidAttrArr = (arr, count) =>
|
15724
15690
|
Array.isArray(arr) && arr.length === count && arr.filter(Boolean).length === count;
|
15725
15691
|
|
@@ -16829,12 +16795,10 @@ class RawDateFieldClass extends BaseInputClass$1 {
|
|
16829
16795
|
}
|
16830
16796
|
}
|
16831
16797
|
|
16832
|
-
#yearDateCounter = new DateCounter(counterConfig.YEAR, this.onDateCounterChange.bind(this));
|
16833
|
-
|
16834
16798
|
dateCounters = [
|
16835
16799
|
new DateCounter(counterConfig.MONTH, this.onDateCounterChange.bind(this)),
|
16836
16800
|
new DateCounter(counterConfig.DAY, this.onDateCounterChange.bind(this)),
|
16837
|
-
this
|
16801
|
+
new DateCounter(counterConfig.YEAR, this.onDateCounterChange.bind(this)),
|
16838
16802
|
];
|
16839
16803
|
|
16840
16804
|
static get observedAttributes() {
|
@@ -16949,6 +16913,9 @@ class RawDateFieldClass extends BaseInputClass$1 {
|
|
16949
16913
|
}
|
16950
16914
|
|
16951
16915
|
get value() {
|
16916
|
+
if (this.isInvalidDate()) {
|
16917
|
+
return '';
|
16918
|
+
}
|
16952
16919
|
return this.timestamp;
|
16953
16920
|
}
|
16954
16921
|
|
@@ -17007,8 +16974,8 @@ class RawDateFieldClass extends BaseInputClass$1 {
|
|
17007
16974
|
this.inputElement.addEventListener('focus', this.onFocus.bind(this));
|
17008
16975
|
this.inputElement.addEventListener('blur', this.onBlur.bind(this));
|
17009
16976
|
this.inputElement.addEventListener('click', this.handleMouseCaretPositionChange.bind(this));
|
17010
|
-
this.inputElement.addEventListener('keydown', this.
|
17011
|
-
this.inputElement.addEventListener('
|
16977
|
+
this.inputElement.addEventListener('keydown', this.handleArrowKeys.bind(this));
|
16978
|
+
this.inputElement.addEventListener('beforeinput', this.handleInput.bind(this));
|
17012
16979
|
|
17013
16980
|
forwardAttrs$1(this, this.inputElement, {
|
17014
16981
|
includeAttrs: [
|
@@ -17034,6 +17001,17 @@ class RawDateFieldClass extends BaseInputClass$1 {
|
|
17034
17001
|
});
|
17035
17002
|
}
|
17036
17003
|
|
17004
|
+
handleInput(e) {
|
17005
|
+
e.preventDefault();
|
17006
|
+
|
17007
|
+
if (e.data && isNumber(e.data)) {
|
17008
|
+
this.parseDigits(e.data);
|
17009
|
+
this.updateCountersDisplay();
|
17010
|
+
} else if (e.inputType) {
|
17011
|
+
this.handleNavKeys(e);
|
17012
|
+
}
|
17013
|
+
}
|
17014
|
+
|
17037
17015
|
initPopover() {
|
17038
17016
|
this.baseElement.trigger = ['click'];
|
17039
17017
|
this.baseElement.withBackdrop = true;
|
@@ -17202,6 +17180,8 @@ class RawDateFieldClass extends BaseInputClass$1 {
|
|
17202
17180
|
|
17203
17181
|
if (!this.inputElement.value) {
|
17204
17182
|
this.inputElement.value = this.format;
|
17183
|
+
// If no value, on focus select the first part of the format placeholder
|
17184
|
+
this.selectedCounterIdx = 0;
|
17205
17185
|
this.setInputSelectionRange();
|
17206
17186
|
}
|
17207
17187
|
}
|
@@ -17229,18 +17209,14 @@ class RawDateFieldClass extends BaseInputClass$1 {
|
|
17229
17209
|
this.setAttribute('pattern', formats[format].pattern);
|
17230
17210
|
}
|
17231
17211
|
|
17232
|
-
|
17233
|
-
|
17234
|
-
e.preventDefault();
|
17235
|
-
|
17236
|
-
this.activeCounter.add(e.key);
|
17237
|
-
|
17238
|
-
if (this.activeCounter.isFull) {
|
17239
|
-
this.selectNextCounter();
|
17240
|
-
}
|
17212
|
+
parseDigits(value) {
|
17213
|
+
this.activeCounter.add(value);
|
17241
17214
|
|
17242
|
-
|
17215
|
+
if (this.activeCounter.isFull) {
|
17216
|
+
this.selectNextCounter();
|
17243
17217
|
}
|
17218
|
+
|
17219
|
+
this.setInputSelectionRange();
|
17244
17220
|
}
|
17245
17221
|
|
17246
17222
|
getCounterIdx(caretPos) {
|
@@ -17310,52 +17286,47 @@ class RawDateFieldClass extends BaseInputClass$1 {
|
|
17310
17286
|
});
|
17311
17287
|
}
|
17312
17288
|
|
17289
|
+
handleArrowKeys(e) {
|
17290
|
+
if (e.key === 'ArrowUp') {
|
17291
|
+
this.activeCounter.inc();
|
17292
|
+
} else if (e.key === 'ArrowDown') {
|
17293
|
+
this.activeCounter.dec();
|
17294
|
+
} else if (e.key === 'ArrowRight') {
|
17295
|
+
this.selectNextCounter();
|
17296
|
+
} else if (e.key === 'ArrowLeft') {
|
17297
|
+
this.selectPrevCounter();
|
17298
|
+
}
|
17299
|
+
|
17300
|
+
setTimeout(() => {
|
17301
|
+
this.setInputSelectionRange();
|
17302
|
+
});
|
17303
|
+
}
|
17304
|
+
|
17313
17305
|
handleNavKeys(e) {
|
17314
17306
|
if (this.isReadOnly) {
|
17315
17307
|
return;
|
17316
17308
|
}
|
17317
17309
|
|
17318
|
-
const { key, shiftKey, metaKey } = e;
|
17319
|
-
const keys = getKeyMap(key, shiftKey, metaKey);
|
17320
|
-
|
17321
17310
|
if (this.opened) {
|
17322
17311
|
this.closePopover();
|
17323
17312
|
}
|
17324
17313
|
|
17325
|
-
|
17326
|
-
|
17327
|
-
if (isSupportedKey(key)) {
|
17328
|
-
const counter = this.activeCounter;
|
17329
|
-
|
17330
|
-
if (!counter) return;
|
17314
|
+
if (!this.activeCounter) return;
|
17331
17315
|
|
17332
|
-
|
17333
|
-
|
17334
|
-
|
17335
|
-
if (keys.backspace) this.handleBackspace();
|
17336
|
-
else if (keys.arrowUp) counter.inc();
|
17337
|
-
else if (keys.arrowDown) counter.dec();
|
17338
|
-
else if (keys.shiftArrowUp) counter.inc(count);
|
17339
|
-
else if (keys.shiftArrowDown) counter.dec(count);
|
17340
|
-
else if (keys.pageUp) counter.inc(count);
|
17341
|
-
else if (keys.pageDown) counter.dec(count);
|
17342
|
-
else if (keys.shiftPageUp) counter.inc(shiftCount);
|
17343
|
-
else if (keys.shiftPageDown) counter.dec(shiftCount);
|
17344
|
-
else if (keys.arrowRight) this.selectNextCounter();
|
17345
|
-
else if (keys.arrowLeft) this.selectPrevCounter();
|
17346
|
-
|
17347
|
-
this.setInputSelectionRange();
|
17316
|
+
if (e.inputType === 'deleteContentBackward') {
|
17317
|
+
this.handleBackspace();
|
17348
17318
|
}
|
17319
|
+
|
17320
|
+
this.setInputSelectionRange();
|
17349
17321
|
}
|
17350
17322
|
|
17351
17323
|
handleBackspace() {
|
17352
|
-
|
17353
|
-
|
17354
|
-
if (counter.isEmpty) {
|
17324
|
+
if (this.activeCounter.isEmpty) {
|
17325
|
+
this.activeCounter.clear();
|
17355
17326
|
this.selectPrevCounter();
|
17356
17327
|
this.setInputSelectionRange();
|
17357
17328
|
} else {
|
17358
|
-
|
17329
|
+
this.activeCounter.del();
|
17359
17330
|
}
|
17360
17331
|
}
|
17361
17332
|
|
@@ -17382,8 +17353,9 @@ class RawDateFieldClass extends BaseInputClass$1 {
|
|
17382
17353
|
if (!val) return;
|
17383
17354
|
const [min, max] = val.split?.('-');
|
17384
17355
|
if (min && max) {
|
17385
|
-
this
|
17386
|
-
|
17356
|
+
const counter = this.getCounterById('year');
|
17357
|
+
counter.setMin(min);
|
17358
|
+
counter.setMax(max);
|
17387
17359
|
}
|
17388
17360
|
}
|
17389
17361
|
|
@@ -17422,17 +17394,45 @@ class RawDateFieldClass extends BaseInputClass$1 {
|
|
17422
17394
|
}
|
17423
17395
|
}
|
17424
17396
|
|
17397
|
+
// we want to validate the date supplied actually exists. For example: Feb 31 is not an actual date,
|
17398
|
+
// but in JS when create a `new Date('1999-02-31') we get March 2nd 1999.
|
17399
|
+
// To prevent this error from being submitted, we evaluate the
|
17400
|
+
// date parts against their generated Date value.
|
17401
|
+
isInvalidDate() {
|
17402
|
+
return Object.entries(this.getDateVals()).some(
|
17403
|
+
([key, val]) => !val || this.getCounterById(key).numberValue !== val
|
17404
|
+
);
|
17405
|
+
}
|
17406
|
+
|
17425
17407
|
getValidity() {
|
17426
17408
|
if (this.isRequired && this.isCountersEmpty) {
|
17427
17409
|
return { valueMissing: true };
|
17428
17410
|
}
|
17429
17411
|
|
17430
|
-
if (this.isCountersOutOfRange) {
|
17412
|
+
if (this.isCountersOutOfRange || this.isInvalidDate()) {
|
17431
17413
|
return { patternMismatch: true };
|
17432
17414
|
}
|
17433
17415
|
|
17434
17416
|
return {};
|
17435
17417
|
}
|
17418
|
+
|
17419
|
+
getDateVals() {
|
17420
|
+
const ret = {
|
17421
|
+
day: '',
|
17422
|
+
month: '',
|
17423
|
+
year: '',
|
17424
|
+
};
|
17425
|
+
|
17426
|
+
try {
|
17427
|
+
const date = newDate(this.timestamp);
|
17428
|
+
|
17429
|
+
ret.month = date.getMonth() + 1;
|
17430
|
+
ret.day = date.getDate();
|
17431
|
+
ret.year = date.getFullYear();
|
17432
|
+
} catch (e) {}
|
17433
|
+
|
17434
|
+
return ret;
|
17435
|
+
}
|
17436
17436
|
}
|
17437
17437
|
|
17438
17438
|
const textVars = TextFieldClass.cssVarList;
|