@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/index.esm.js CHANGED
@@ -5239,66 +5239,9 @@ loadingIndicatorStyles = `
5239
5239
 
5240
5240
  customElements.define(componentName$17, ButtonClass);
5241
5241
 
5242
- const SUPPORTED_FORMATS = ['MM/DD/YYYY', 'DD/MM/YYYY', 'YYYY/MM/DD'];
5243
-
5244
- const DEFAULT_FORMAT = SUPPORTED_FORMATS[0];
5245
-
5246
- const NATIVE_FORMAT = 'YYYY-MM-DD';
5247
-
5248
- const YEARS_RANGE = 100;
5249
-
5250
- const DIVIDER = '/';
5251
-
5252
- const COUNTER_SUPPORTED_KEYS = [
5253
- 'Backspace',
5254
- 'ArrowLeft',
5255
- 'ArrowRight',
5256
- 'ArrowDown',
5257
- 'ArrowUp',
5258
- 'PageUp',
5259
- 'PageDown',
5260
- 'Meta',
5261
- 'Enter',
5262
- ];
5263
-
5264
- const months = [
5265
- 'January',
5266
- 'February',
5267
- 'March',
5268
- 'April',
5269
- 'May',
5270
- 'June',
5271
- 'July',
5272
- 'August',
5273
- 'September',
5274
- 'October',
5275
- 'November',
5276
- 'December',
5277
- ];
5278
-
5279
- const weekdays = [
5280
- 'Sunday',
5281
- 'Monday',
5282
- 'Tuesday',
5283
- 'Wednesday',
5284
- 'Thursday',
5285
- 'Friday',
5286
- 'Saturday',
5287
- ];
5288
-
5289
- const counterConfig = {
5290
- MONTH: { id: 'month', min: 1, max: 12, placeholder: 'MM', count: 5, shiftCount: 10 },
5291
- DAY: { id: 'day', min: 1, max: 31, placeholder: 'DD', count: 5, shiftCount: 10 },
5292
- YEAR: { id: 'year', min: 1900, max: 2099, placeholder: 'YYYY', count: 10, shiftCount: 100 },
5293
- };
5294
-
5295
- const BUTTON_LABEL_DONE = 'Done';
5296
- const BUTTON_LABEL_CANCEL = 'Cancel';
5297
- const CALENDAR_LABEL_TODAY = 'Today';
5298
-
5299
5242
  const isValidTimestamp = (val) => !Number.isNaN(Number(val));
5300
5243
 
5301
- const isNumber = (val) => !Number.isNaN(Number(val));
5244
+ const isNumber = (val) => !!String(val || '').trim() && !Number.isNaN(Number(val));
5302
5245
 
5303
5246
  const getTimestampParts = (timestamp) => {
5304
5247
  const date = newDate(timestamp);
@@ -5331,28 +5274,6 @@ const newDate = (date) => {
5331
5274
  return new Date();
5332
5275
  };
5333
5276
 
5334
- const isSupportedKey = (key) => COUNTER_SUPPORTED_KEYS.includes(key);
5335
-
5336
- const getKeyMap = (key, shiftKey, metaKey) => {
5337
- return {
5338
- refresh: metaKey && key.toLowerCase() === 'r',
5339
- tab: key === 'Tab',
5340
- shiftTab: shiftKey && key === 'Tab',
5341
- backspace: key === 'Backspace',
5342
- arrowUp: !shiftKey && key === 'ArrowUp',
5343
- arrowDown: !shiftKey && key === 'ArrowDown',
5344
- arrowLeft: !shiftKey && key === 'ArrowLeft',
5345
- arrowRight: !shiftKey && key === 'ArrowRight',
5346
- pageUp: !shiftKey && key === 'PageUp',
5347
- pageDown: !shiftKey && key === 'PageDown',
5348
- shiftArrowUp: shiftKey && key === 'ArrowUp',
5349
- shiftArrowDown: shiftKey && key === 'ArrowDown',
5350
- shiftPageUp: shiftKey && key === 'PageUp',
5351
- shiftPageDown: shiftKey && key === 'PageDown',
5352
- enter: key === 'Enter',
5353
- };
5354
- };
5355
-
5356
5277
  const getCurrentTime = () => newDate().getTime();
5357
5278
  const getFullYear = (timestamp) => newDate(timestamp).getFullYear().toString();
5358
5279
  const getMonth = (timestamp) => (newDate(timestamp).getMonth() + 1).toString();
@@ -5382,6 +5303,51 @@ const arrowLeftIcon = `<svg width="24" height="24" viewBox="0 0 24 24" fill="non
5382
5303
  <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"/>
5383
5304
  </svg>`;
5384
5305
 
5306
+ const SUPPORTED_FORMATS = ['MM/DD/YYYY', 'DD/MM/YYYY', 'YYYY/MM/DD'];
5307
+
5308
+ const DEFAULT_FORMAT = SUPPORTED_FORMATS[0];
5309
+
5310
+ const NATIVE_FORMAT = 'YYYY-MM-DD';
5311
+
5312
+ const YEARS_RANGE = 100;
5313
+
5314
+ const DIVIDER = '/';
5315
+
5316
+ const months = [
5317
+ 'January',
5318
+ 'February',
5319
+ 'March',
5320
+ 'April',
5321
+ 'May',
5322
+ 'June',
5323
+ 'July',
5324
+ 'August',
5325
+ 'September',
5326
+ 'October',
5327
+ 'November',
5328
+ 'December',
5329
+ ];
5330
+
5331
+ const weekdays = [
5332
+ 'Sunday',
5333
+ 'Monday',
5334
+ 'Tuesday',
5335
+ 'Wednesday',
5336
+ 'Thursday',
5337
+ 'Friday',
5338
+ 'Saturday',
5339
+ ];
5340
+
5341
+ const counterConfig = {
5342
+ MONTH: { id: 'month', min: 1, max: 12, placeholder: 'MM', count: 5, shiftCount: 10 },
5343
+ DAY: { id: 'day', min: 1, max: 31, placeholder: 'DD', count: 5, shiftCount: 10 },
5344
+ YEAR: { id: 'year', min: 1900, max: 2099, placeholder: 'YYYY', count: 10, shiftCount: 100 },
5345
+ };
5346
+
5347
+ const BUTTON_LABEL_DONE = 'Done';
5348
+ const BUTTON_LABEL_CANCEL = 'Cancel';
5349
+ const CALENDAR_LABEL_TODAY = 'Today';
5350
+
5385
5351
  const isValidAttrArr = (arr, count) =>
5386
5352
  Array.isArray(arr) && arr.length === count && arr.filter(Boolean).length === count;
5387
5353
 
@@ -6684,12 +6650,10 @@ class RawDateFieldClass extends BaseInputClass$a {
6684
6650
  }
6685
6651
  }
6686
6652
 
6687
- #yearDateCounter = new DateCounter(counterConfig.YEAR, this.onDateCounterChange.bind(this));
6688
-
6689
6653
  dateCounters = [
6690
6654
  new DateCounter(counterConfig.MONTH, this.onDateCounterChange.bind(this)),
6691
6655
  new DateCounter(counterConfig.DAY, this.onDateCounterChange.bind(this)),
6692
- this.#yearDateCounter,
6656
+ new DateCounter(counterConfig.YEAR, this.onDateCounterChange.bind(this)),
6693
6657
  ];
6694
6658
 
6695
6659
  static get observedAttributes() {
@@ -6804,6 +6768,9 @@ class RawDateFieldClass extends BaseInputClass$a {
6804
6768
  }
6805
6769
 
6806
6770
  get value() {
6771
+ if (this.isInvalidDate()) {
6772
+ return '';
6773
+ }
6807
6774
  return this.timestamp;
6808
6775
  }
6809
6776
 
@@ -6862,8 +6829,8 @@ class RawDateFieldClass extends BaseInputClass$a {
6862
6829
  this.inputElement.addEventListener('focus', this.onFocus.bind(this));
6863
6830
  this.inputElement.addEventListener('blur', this.onBlur.bind(this));
6864
6831
  this.inputElement.addEventListener('click', this.handleMouseCaretPositionChange.bind(this));
6865
- this.inputElement.addEventListener('keydown', this.handleNavKeys.bind(this));
6866
- this.inputElement.addEventListener('keydown', this.handleDigitKeys.bind(this));
6832
+ this.inputElement.addEventListener('keydown', this.handleArrowKeys.bind(this));
6833
+ this.inputElement.addEventListener('beforeinput', this.handleInput.bind(this));
6867
6834
 
6868
6835
  forwardAttrs$1(this, this.inputElement, {
6869
6836
  includeAttrs: [
@@ -6889,6 +6856,17 @@ class RawDateFieldClass extends BaseInputClass$a {
6889
6856
  });
6890
6857
  }
6891
6858
 
6859
+ handleInput(e) {
6860
+ e.preventDefault();
6861
+
6862
+ if (e.data && isNumber(e.data)) {
6863
+ this.parseDigits(e.data);
6864
+ this.updateCountersDisplay();
6865
+ } else if (e.inputType) {
6866
+ this.handleNavKeys(e);
6867
+ }
6868
+ }
6869
+
6892
6870
  initPopover() {
6893
6871
  this.baseElement.trigger = ['click'];
6894
6872
  this.baseElement.withBackdrop = true;
@@ -7057,6 +7035,8 @@ class RawDateFieldClass extends BaseInputClass$a {
7057
7035
 
7058
7036
  if (!this.inputElement.value) {
7059
7037
  this.inputElement.value = this.format;
7038
+ // If no value, on focus select the first part of the format placeholder
7039
+ this.selectedCounterIdx = 0;
7060
7040
  this.setInputSelectionRange();
7061
7041
  }
7062
7042
  }
@@ -7084,18 +7064,14 @@ class RawDateFieldClass extends BaseInputClass$a {
7084
7064
  this.setAttribute('pattern', formats[format].pattern);
7085
7065
  }
7086
7066
 
7087
- handleDigitKeys(e) {
7088
- if (isNumber(e.key)) {
7089
- e.preventDefault();
7090
-
7091
- this.activeCounter.add(e.key);
7092
-
7093
- if (this.activeCounter.isFull) {
7094
- this.selectNextCounter();
7095
- }
7067
+ parseDigits(value) {
7068
+ this.activeCounter.add(value);
7096
7069
 
7097
- this.setInputSelectionRange();
7070
+ if (this.activeCounter.isFull) {
7071
+ this.selectNextCounter();
7098
7072
  }
7073
+
7074
+ this.setInputSelectionRange();
7099
7075
  }
7100
7076
 
7101
7077
  getCounterIdx(caretPos) {
@@ -7165,52 +7141,47 @@ class RawDateFieldClass extends BaseInputClass$a {
7165
7141
  });
7166
7142
  }
7167
7143
 
7144
+ handleArrowKeys(e) {
7145
+ if (e.key === 'ArrowUp') {
7146
+ this.activeCounter.inc();
7147
+ } else if (e.key === 'ArrowDown') {
7148
+ this.activeCounter.dec();
7149
+ } else if (e.key === 'ArrowRight') {
7150
+ this.selectNextCounter();
7151
+ } else if (e.key === 'ArrowLeft') {
7152
+ this.selectPrevCounter();
7153
+ }
7154
+
7155
+ setTimeout(() => {
7156
+ this.setInputSelectionRange();
7157
+ });
7158
+ }
7159
+
7168
7160
  handleNavKeys(e) {
7169
7161
  if (this.isReadOnly) {
7170
7162
  return;
7171
7163
  }
7172
7164
 
7173
- const { key, shiftKey, metaKey } = e;
7174
- const keys = getKeyMap(key, shiftKey, metaKey);
7175
-
7176
7165
  if (this.opened) {
7177
7166
  this.closePopover();
7178
7167
  }
7179
7168
 
7180
- e.preventDefault();
7181
-
7182
- if (isSupportedKey(key)) {
7183
- const counter = this.activeCounter;
7184
-
7185
- if (!counter) return;
7169
+ if (!this.activeCounter) return;
7186
7170
 
7187
- const counterData = Object.values(counterConfig).find((config) => config.id === counter.id);
7188
- const { count, shiftCount } = counterData;
7189
-
7190
- if (keys.backspace) this.handleBackspace();
7191
- else if (keys.arrowUp) counter.inc();
7192
- else if (keys.arrowDown) counter.dec();
7193
- else if (keys.shiftArrowUp) counter.inc(count);
7194
- else if (keys.shiftArrowDown) counter.dec(count);
7195
- else if (keys.pageUp) counter.inc(count);
7196
- else if (keys.pageDown) counter.dec(count);
7197
- else if (keys.shiftPageUp) counter.inc(shiftCount);
7198
- else if (keys.shiftPageDown) counter.dec(shiftCount);
7199
- else if (keys.arrowRight) this.selectNextCounter();
7200
- else if (keys.arrowLeft) this.selectPrevCounter();
7201
-
7202
- this.setInputSelectionRange();
7171
+ if (e.inputType === 'deleteContentBackward') {
7172
+ this.handleBackspace();
7203
7173
  }
7174
+
7175
+ this.setInputSelectionRange();
7204
7176
  }
7205
7177
 
7206
7178
  handleBackspace() {
7207
- const counter = this.activeCounter;
7208
-
7209
- if (counter.isEmpty) {
7179
+ if (this.activeCounter.isEmpty) {
7180
+ this.activeCounter.clear();
7210
7181
  this.selectPrevCounter();
7211
7182
  this.setInputSelectionRange();
7212
7183
  } else {
7213
- counter.del();
7184
+ this.activeCounter.del();
7214
7185
  }
7215
7186
  }
7216
7187
 
@@ -7237,8 +7208,9 @@ class RawDateFieldClass extends BaseInputClass$a {
7237
7208
  if (!val) return;
7238
7209
  const [min, max] = val.split?.('-');
7239
7210
  if (min && max) {
7240
- this.#yearDateCounter.setMin(min);
7241
- this.#yearDateCounter.setMax(max);
7211
+ const counter = this.getCounterById('year');
7212
+ counter.setMin(min);
7213
+ counter.setMax(max);
7242
7214
  }
7243
7215
  }
7244
7216
 
@@ -7277,17 +7249,45 @@ class RawDateFieldClass extends BaseInputClass$a {
7277
7249
  }
7278
7250
  }
7279
7251
 
7252
+ // we want to validate the date supplied actually exists. For example: Feb 31 is not an actual date,
7253
+ // but in JS when create a `new Date('1999-02-31') we get March 2nd 1999.
7254
+ // To prevent this error from being submitted, we evaluate the
7255
+ // date parts against their generated Date value.
7256
+ isInvalidDate() {
7257
+ return Object.entries(this.getDateVals()).some(
7258
+ ([key, val]) => !val || this.getCounterById(key).numberValue !== val
7259
+ );
7260
+ }
7261
+
7280
7262
  getValidity() {
7281
7263
  if (this.isRequired && this.isCountersEmpty) {
7282
7264
  return { valueMissing: true };
7283
7265
  }
7284
7266
 
7285
- if (this.isCountersOutOfRange) {
7267
+ if (this.isCountersOutOfRange || this.isInvalidDate()) {
7286
7268
  return { patternMismatch: true };
7287
7269
  }
7288
7270
 
7289
7271
  return {};
7290
7272
  }
7273
+
7274
+ getDateVals() {
7275
+ const ret = {
7276
+ day: '',
7277
+ month: '',
7278
+ year: '',
7279
+ };
7280
+
7281
+ try {
7282
+ const date = newDate(this.timestamp);
7283
+
7284
+ ret.month = date.getMonth() + 1;
7285
+ ret.day = date.getDate();
7286
+ ret.year = date.getFullYear();
7287
+ } catch (e) {}
7288
+
7289
+ return ret;
7290
+ }
7291
7291
  }
7292
7292
 
7293
7293
  const textVars$4 = TextFieldClass.cssVarList;