@descope/web-components-ui 1.103.0 → 1.105.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
@@ -5499,6 +5499,8 @@ const BUTTON_LABEL_DONE = 'Done';
5499
5499
  const BUTTON_LABEL_CANCEL = 'Cancel';
5500
5500
  const CALENDAR_LABEL_TODAY = 'Today';
5501
5501
 
5502
+ const MOBILE_DEVICE_INTERACTION_TIMEOUT_MS = 150;
5503
+
5502
5504
  const isValidAttrArr = (arr, count) =>
5503
5505
  Array.isArray(arr) && arr.length === count && arr.filter(Boolean).length === count;
5504
5506
 
@@ -6776,8 +6778,6 @@ class RawDateFieldClass extends BaseInputClass$a {
6776
6778
 
6777
6779
  selectedCounterIdx = 0;
6778
6780
 
6779
- #focused = false;
6780
-
6781
6781
  updateCountersDisplay() {
6782
6782
  this.inputElement.value = this.countersValue;
6783
6783
  }
@@ -6987,22 +6987,7 @@ class RawDateFieldClass extends BaseInputClass$a {
6987
6987
  this.inputElement.addEventListener('click', this.handleMouseCaretPositionChange.bind(this));
6988
6988
  this.inputElement.addEventListener('keydown', this.handleArrowKeys.bind(this));
6989
6989
  this.inputElement.addEventListener('beforeinput', this.handleInput.bind(this));
6990
-
6991
- // We want to handle touch events the same way we handle `click` events.
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
- });
6990
+ this.inputElement.addEventListener('pointerdown', this.onPointerDown.bind(this));
7006
6991
 
7007
6992
  forwardAttrs$1(this, this.inputElement, {
7008
6993
  includeAttrs: [
@@ -7200,16 +7185,19 @@ class RawDateFieldClass extends BaseInputClass$a {
7200
7185
  });
7201
7186
  }
7202
7187
 
7188
+ // In mobile devices, there are cases were `pointerdown` is triggered
7189
+ // instead of `click`.
7190
+ onPointerDown(e) {
7191
+ setTimeout(() => this.handleMouseCaretPositionChange(e), MOBILE_DEVICE_INTERACTION_TIMEOUT_MS);
7192
+ }
7193
+
7203
7194
  onFocus() {
7204
- if (this.isReadOnly || this.#focused) {
7195
+ if (this.isReadOnly) {
7205
7196
  return;
7206
7197
  }
7207
7198
 
7208
- // We use this flag to support mobile logic, which calls `focus` on touch event, we want to make sure
7209
- // focus executes it logic only when needed.
7210
- this.#focused = true;
7211
-
7212
- this.resetDisplay();
7199
+ // We need to wait for focus to end before we set selection
7200
+ setTimeout(() => this.resetDisplay());
7213
7201
  }
7214
7202
 
7215
7203
  resetDisplay() {
@@ -7217,18 +7205,12 @@ class RawDateFieldClass extends BaseInputClass$a {
7217
7205
  this.inputElement.value = this.format;
7218
7206
  }
7219
7207
 
7220
- // On focus select the first part of the format placeholder
7208
+ // On focus select the first counter
7221
7209
  this.selectedCounterIdx = 0;
7222
-
7223
- setTimeout(() => {
7224
- // set selection on first counter
7225
- this.inputElement.setSelectionRange(0, this.sortedCounters[0].length);
7226
- });
7210
+ this.inputElement.setSelectionRange(0, this.sortedCounters[0].length);
7227
7211
  }
7228
7212
 
7229
7213
  onBlur() {
7230
- this.#focused = false;
7231
-
7232
7214
  if (this.opened) {
7233
7215
  return;
7234
7216
  }
@@ -7258,6 +7240,8 @@ class RawDateFieldClass extends BaseInputClass$a {
7258
7240
  this.selectNextCounter();
7259
7241
  }
7260
7242
 
7243
+ // We wait for the digit to be parsed, and only then set the selection.
7244
+ // Failing to do so results in unexpected "jump" of the screen in mobile devices.
7261
7245
  this.setInputSelectionRange();
7262
7246
  }
7263
7247
 
@@ -7273,7 +7257,11 @@ class RawDateFieldClass extends BaseInputClass$a {
7273
7257
 
7274
7258
  setSelectedCounterByCaretPosition(e) {
7275
7259
  this.selectedCounterIdx = this.getCounterIdx(
7276
- e.target.selectionStart || this.inputElement.selectionStart
7260
+ // if triggered by touch event, target might not include `selectionStart`
7261
+ // in that case we fall back to the inputElement's `selectionStart` value.
7262
+ // Therefore, it is recommended to run this function with setTimeout,
7263
+ // at least for mobile events.
7264
+ e.target?.selectionStart || this.inputElement.selectionStart
7277
7265
  );
7278
7266
  }
7279
7267
 
@@ -7299,14 +7287,18 @@ class RawDateFieldClass extends BaseInputClass$a {
7299
7287
  return;
7300
7288
  }
7301
7289
 
7302
- const caretStart = this.sortedCounters
7303
- .slice(0, this.selectedCounterIdx)
7304
- .reduce((acc, counter) => acc + counter.length, this.selectedCounterIdx);
7290
+ // We wait for before setting the selection, otherwise there's an
7291
+ // unexpected "jump" of the screen in mobile devices.
7292
+ setTimeout(() => {
7293
+ const caretStart = this.sortedCounters
7294
+ .slice(0, this.selectedCounterIdx)
7295
+ .reduce((acc, counter) => acc + counter.length, this.selectedCounterIdx);
7305
7296
 
7306
- this.inputElement.setSelectionRange(
7307
- caretStart,
7308
- caretStart + this.sortedCounters[this.selectedCounterIdx].length
7309
- );
7297
+ this.inputElement.setSelectionRange(
7298
+ caretStart,
7299
+ caretStart + this.sortedCounters[this.selectedCounterIdx].length
7300
+ );
7301
+ });
7310
7302
  }
7311
7303
 
7312
7304
  resetDateCounters() {
@@ -7341,9 +7333,7 @@ class RawDateFieldClass extends BaseInputClass$a {
7341
7333
  this.selectPrevCounter();
7342
7334
  }
7343
7335
 
7344
- setTimeout(() => {
7345
- this.setInputSelectionRange();
7346
- });
7336
+ this.setInputSelectionRange();
7347
7337
  }
7348
7338
 
7349
7339
  handleNavKeys(e) {
@@ -7365,27 +7355,32 @@ class RawDateFieldClass extends BaseInputClass$a {
7365
7355
  }
7366
7356
 
7367
7357
  handleBackspace() {
7368
- if (this.activeCounter.isEmpty) {
7369
- this.activeCounter.clear();
7358
+ const counter = this.activeCounter;
7359
+
7360
+ if (counter.isEmpty) {
7370
7361
  this.selectPrevCounter();
7371
7362
  this.setInputSelectionRange();
7372
7363
  } else {
7373
- this.activeCounter.del();
7364
+ counter.set('');
7374
7365
  }
7366
+
7367
+ // To support keyboards like SwiftKey, we need to re-render the counters display and selection,
7368
+ // otherwise we get an unexpected behavior, where the format is deleted.
7369
+ setTimeout(() => {
7370
+ this.updateCountersDisplay();
7371
+ this.setInputSelectionRange();
7372
+ });
7375
7373
  }
7376
7374
 
7377
7375
  handleMouseCaretPositionChange(e) {
7378
7376
  if (this.opened) {
7379
7377
  return;
7380
7378
  }
7379
+
7381
7380
  e.preventDefault();
7382
- this.setSelectedCounterByCaretPosition(e);
7383
7381
 
7384
- // On keydown - in desktop mode - selection is sometimes not set, and instead there is a cursor.
7385
- // We need to wait until we can set selection range.
7386
- setTimeout(() => {
7387
- this.setInputSelectionRange();
7388
- });
7382
+ this.setSelectedCounterByCaretPosition(e);
7383
+ this.setInputSelectionRange();
7389
7384
  }
7390
7385
 
7391
7386
  onInitialValueChange(val) {
@@ -19026,6 +19021,13 @@ const colors$2 = genColors({
19026
19021
  highlight: '#fef1f1',
19027
19022
  contrast: '#ffffff',
19028
19023
  },
19024
+ warning: {
19025
+ main: '#c45512',
19026
+ dark: '#a24309',
19027
+ light: '#ff985a',
19028
+ highlight: '#fdf0e5',
19029
+ contrast: '#ffffff',
19030
+ },
19029
19031
  });
19030
19032
 
19031
19033
  const fonts$1 = {
@@ -19203,6 +19205,13 @@ const colors$1 = genColors$1({
19203
19205
  highlight: '#fef1f1',
19204
19206
  contrast: '#ffffff',
19205
19207
  },
19208
+ warning: {
19209
+ main: '#c45512',
19210
+ dark: '#a24309',
19211
+ light: '#ff985a',
19212
+ highlight: '#fdf0e5',
19213
+ contrast: '#ffffff',
19214
+ },
19206
19215
  });
19207
19216
 
19208
19217
  const fonts = {
@@ -20220,9 +20229,21 @@ const text$1 = {
20220
20229
  error: {
20221
20230
  [vars$O.textColor]: globalRefs$A.colors.error.main,
20222
20231
  },
20232
+ 'error-dark': {
20233
+ [vars$O.textColor]: globalRefs$A.colors.error.dark,
20234
+ },
20223
20235
  success: {
20224
20236
  [vars$O.textColor]: globalRefs$A.colors.success.main,
20225
20237
  },
20238
+ 'success-dark': {
20239
+ [vars$O.textColor]: globalRefs$A.colors.success.dark,
20240
+ },
20241
+ warning: {
20242
+ [vars$O.textColor]: globalRefs$A.colors.warning.main,
20243
+ },
20244
+ 'warning-dark': {
20245
+ [vars$O.textColor]: globalRefs$A.colors.warning.dark,
20246
+ },
20226
20247
  },
20227
20248
 
20228
20249
  textAlign: {
@@ -24332,6 +24353,13 @@ const colors = {
24332
24353
  highlight: '#4a0603',
24333
24354
  contrast: '#000000',
24334
24355
  },
24356
+ warning: {
24357
+ main: '#EF7A33',
24358
+ dark: '#FF985A',
24359
+ light: '#FF6304',
24360
+ highlight: '#C45512',
24361
+ contrast: '#000000',
24362
+ },
24335
24363
  };
24336
24364
 
24337
24365
  const darkTheme = merge({}, defaultTheme, {