@descope/flow-components 2.0.548 → 2.0.549

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.cjs.js CHANGED
@@ -79160,8 +79160,9 @@ function requireIndex_cjs () {
79160
79160
  #blockNativeEvents() {
79161
79161
  ['blur', 'focus', 'focusin', 'focusout'].forEach((event) => {
79162
79162
  this.addEventListener(event, (e) => {
79163
- e.isTrusted && e.target === this && e.stopImmediatePropagation();
79164
- });
79163
+ if (e.isTrusted && e.target === this) {
79164
+ e.stopImmediatePropagation();
79165
+ } });
79165
79166
  });
79166
79167
  }
79167
79168
 
@@ -92990,6 +92991,7 @@ descope-boolean-field-internal {
92990
92991
  'PageUp',
92991
92992
  'PageDown',
92992
92993
  'Meta',
92994
+ 'Enter',
92993
92995
  ];
92994
92996
 
92995
92997
  const months = [
@@ -93020,7 +93022,7 @@ descope-boolean-field-internal {
93020
93022
  const counterConfig = {
93021
93023
  MONTH: { id: 'month', min: 1, max: 12, placeholder: 'MM', count: 5, shiftCount: 10 },
93022
93024
  DAY: { id: 'day', min: 1, max: 31, placeholder: 'DD', count: 5, shiftCount: 10 },
93023
- YEAR: { id: 'year', min: 0, max: 9999, placeholder: 'YYYY', count: 10, shiftCount: 100 },
93025
+ YEAR: { id: 'year', min: 1900, max: 2099, placeholder: 'YYYY', count: 10, shiftCount: 100 },
93024
93026
  };
93025
93027
 
93026
93028
  const BUTTON_LABEL_DONE = 'Done';
@@ -93032,7 +93034,7 @@ descope-boolean-field-internal {
93032
93034
  const isNumber = (val) => !Number.isNaN(Number(val));
93033
93035
 
93034
93036
  const getTimestampParts = (timestamp) => {
93035
- const date = new Date(timestamp);
93037
+ const date = newDate(timestamp);
93036
93038
  const year = date.getFullYear();
93037
93039
  const month = date.getMonth() + 1;
93038
93040
  const day = date.getDate();
@@ -93080,6 +93082,7 @@ descope-boolean-field-internal {
93080
93082
  shiftArrowDown: shiftKey && key === 'ArrowDown',
93081
93083
  shiftPageUp: shiftKey && key === 'PageUp',
93082
93084
  shiftPageDown: shiftKey && key === 'PageDown',
93085
+ enter: key === 'Enter',
93083
93086
  };
93084
93087
  };
93085
93088
 
@@ -94064,12 +94067,23 @@ descope-boolean-field-internal {
94064
94067
  // For examele, we have a DayCounter, MonthCounter and YearCounter, which can each separately navigate
94065
94068
  // between different ranges.
94066
94069
  class DateCounter {
94067
- constructor({ id, min, max, placeholder }) {
94070
+ #data = Object.freeze([]);
94071
+
94072
+ constructor({ id, min, max, placeholder }, onChange) {
94068
94073
  this.id = id;
94069
- this.data = [];
94070
94074
  this.min = min;
94071
94075
  this.max = max;
94072
94076
  this.placeholder = placeholder;
94077
+ this.onChange = onChange;
94078
+ }
94079
+
94080
+ get data() {
94081
+ return this.#data;
94082
+ }
94083
+
94084
+ set data(val) {
94085
+ this.#data = Object.freeze(val);
94086
+ this.onChange?.();
94073
94087
  }
94074
94088
 
94075
94089
  get #initialNumValue() {
@@ -94101,23 +94115,27 @@ descope-boolean-field-internal {
94101
94115
  }
94102
94116
 
94103
94117
  add(num) {
94104
- this.data.push(num);
94118
+ // use local var to avoid triggering onChange
94119
+ let data = this.data;
94120
+
94121
+ data = [...data, num];
94105
94122
 
94106
94123
  if (this.numberValue > this.max) {
94107
- this.data.length = 0;
94108
- this.data.push(num);
94109
- } else if (this.length < this.data.length) {
94110
- this.data.shift();
94124
+ data = [num];
94125
+ } else if (this.length < data.length) {
94126
+ data = data.slice(1, data.length);
94111
94127
  }
94112
94128
 
94129
+ this.data = data;
94130
+
94113
94131
  return num;
94114
94132
  }
94115
94133
 
94116
94134
  del() {
94117
94135
  if (!this.data.filter((d) => d !== '0').filter(Boolean).length) {
94118
- this.data.length = 0;
94136
+ this.data = [];
94119
94137
  } else {
94120
- this.data.pop();
94138
+ this.data = this.data.slice(0, this.data.length - 1);
94121
94139
  }
94122
94140
  }
94123
94141
 
@@ -94126,11 +94144,19 @@ descope-boolean-field-internal {
94126
94144
  }
94127
94145
 
94128
94146
  inc(gap) {
94129
- this.replaceValue(this.#initialNumValue + (gap || 1));
94147
+ this.replaceValue(
94148
+ this.#initialNumValue < this.max
94149
+ ? Math.max(this.#initialNumValue + (gap || 1), this.min)
94150
+ : this.min
94151
+ );
94130
94152
  }
94131
94153
 
94132
94154
  dec(gap) {
94133
- this.replaceValue(this.#initialNumValue - (gap || 1));
94155
+ this.replaceValue(
94156
+ this.#initialNumValue > this.min
94157
+ ? Math.min(this.#initialNumValue - (gap || 1), this.max)
94158
+ : this.max
94159
+ );
94134
94160
  }
94135
94161
 
94136
94162
  isInRange(val) {
@@ -94142,6 +94168,14 @@ descope-boolean-field-internal {
94142
94168
  this.data = val.toString().padStart(this.length, 0).split('');
94143
94169
  }
94144
94170
  }
94171
+
94172
+ setMin(val) {
94173
+ this.min = Number(val);
94174
+ }
94175
+
94176
+ setMax(val) {
94177
+ this.max = Number(val);
94178
+ }
94145
94179
  }
94146
94180
 
94147
94181
  const componentName$j = getComponentName$1('date-field');
@@ -94162,10 +94196,40 @@ descope-boolean-field-internal {
94162
94196
 
94163
94197
  selectedCounterIdx = 0;
94164
94198
 
94199
+ updateCountersDisplay() {
94200
+ this.inputElement.value = this.countersValue;
94201
+ }
94202
+
94203
+ updateValue() {
94204
+ if (this.isCountersOutOfRange) {
94205
+ this.updateTimestamp('');
94206
+ } else {
94207
+ const date = formats[this.format].getDate(this.inputElement.value);
94208
+ this.updateTimestamp(date.getTime());
94209
+ }
94210
+ }
94211
+
94212
+ onDateCounterChange = () => {
94213
+ this.updateCountersDisplay();
94214
+ this.updateValue();
94215
+ // update validity
94216
+ this.#dispatchInput();
94217
+ };
94218
+
94219
+ updateTimestamp(epochOrDate) {
94220
+ if (!epochOrDate) {
94221
+ this.timestamp = '';
94222
+ } else {
94223
+ this.timestamp = newDate(epochOrDate).getTime();
94224
+ }
94225
+ }
94226
+
94227
+ #yearDateCounter = new DateCounter(counterConfig.YEAR, this.onDateCounterChange.bind(this));
94228
+
94165
94229
  dateCounters = [
94166
- new DateCounter(counterConfig.MONTH),
94167
- new DateCounter(counterConfig.DAY),
94168
- new DateCounter(counterConfig.YEAR),
94230
+ new DateCounter(counterConfig.MONTH, this.onDateCounterChange.bind(this)),
94231
+ new DateCounter(counterConfig.DAY, this.onDateCounterChange.bind(this)),
94232
+ this.#yearDateCounter,
94169
94233
  ];
94170
94234
 
94171
94235
  static get observedAttributes() {
@@ -94217,11 +94281,10 @@ descope-boolean-field-internal {
94217
94281
 
94218
94282
  this.inputElement = this.shadowRoot.querySelector('descope-text-field');
94219
94283
  this.popoverToggleButton = this.inputElement.querySelector('.toggle-calendar');
94284
+ }
94220
94285
 
94221
- this.oninvalid = () => {
94222
- this.inputElement.setAttribute('invalid', 'true');
94223
- this.inputElement.focus();
94224
- };
94286
+ get validationTarget() {
94287
+ return this.inputElement;
94225
94288
  }
94226
94289
 
94227
94290
  get opened() {
@@ -94229,7 +94292,7 @@ descope-boolean-field-internal {
94229
94292
  }
94230
94293
 
94231
94294
  // returns the input's value as a timestamp
94232
- get inputValueTimestamp() {
94295
+ get displayValueEpoch() {
94233
94296
  const date = formats[this.format].getDate(this.inputElement.value);
94234
94297
 
94235
94298
  if (!isValidTimestamp(date?.getTime())) {
@@ -94281,37 +94344,32 @@ descope-boolean-field-internal {
94281
94344
  }
94282
94345
 
94283
94346
  set value(val) {
94284
- if (!val) return;
94285
-
94286
- const numVal = Number(val);
94287
- const isValTimestamp = !Number.isNaN(numVal);
94288
-
94289
- let date;
94290
- let timestamp;
94291
-
94292
- if (isValTimestamp) {
94293
- date = newDate(numVal);
94294
- timestamp = numVal;
94347
+ if (val) {
94348
+ this.updateTimestamp(val);
94349
+ this.updateDateCounters(newDate(val));
94295
94350
  } else {
94296
- date = newDate(val);
94297
- timestamp = date.getTime();
94351
+ this.updateTimestamp('');
94298
94352
  }
94353
+ }
94299
94354
 
94300
- if (!isValidTimestamp(timestamp) || timestamp === this.timestamp) {
94301
- return;
94302
- }
94355
+ get isCountersEmpty() {
94356
+ return this.dateCounters.every((dc) => dc.isEmpty);
94357
+ }
94303
94358
 
94304
- this.timestamp = timestamp;
94359
+ get isCountersOutOfRange() {
94360
+ return this.dateCounters.some((dc) => !dc.isInRange(dc.numberValue));
94361
+ }
94305
94362
 
94306
- this.updateInputDisplay();
94307
- this.updateDateCounters(date);
94363
+ reportValidity() {
94364
+ this.inputElement.reportValidity();
94365
+ }
94308
94366
 
94309
- // since baseElement is set to vaadin-popover, we need to manually dispatch an input event to trigger getValidity
94310
- this.dispatchEvent(new Event('input'));
94367
+ #dispatchInput() {
94368
+ this.inputElement.baseElement.dispatchEvent(new Event('input', { bubbles: true }));
94311
94369
  }
94312
94370
 
94313
94371
  updateInputDisplay() {
94314
- this.inputElement.value = formatTimestamp(newDate(this.value).getTime(), this.format);
94372
+ this.inputElement.value = formatTimestamp(newDate(this.countersValue).getTime(), this.format);
94315
94373
  }
94316
94374
 
94317
94375
  init() {
@@ -94319,6 +94377,7 @@ descope-boolean-field-internal {
94319
94377
 
94320
94378
  this.updateFormatPattern();
94321
94379
  this.initPopover();
94380
+ this.onDateCounterChange();
94322
94381
  this.initInputElement();
94323
94382
 
94324
94383
  setTimeout(() => {
@@ -94327,15 +94386,16 @@ descope-boolean-field-internal {
94327
94386
  }
94328
94387
 
94329
94388
  initInputElement() {
94389
+ this.inputElement.getValidity = this.getValidity.bind(this);
94390
+ this.inputElement.baseElement.checkValidity = this.checkValidity.bind(this);
94391
+
94330
94392
  this.popoverToggleButton.addEventListener('click', this.onPopoverToggle.bind(this));
94331
94393
 
94332
94394
  this.inputElement.addEventListener('focus', this.onFocus.bind(this));
94333
94395
  this.inputElement.addEventListener('blur', this.onBlur.bind(this));
94334
- this.inputElement.addEventListener('input', this.onInput.bind(this));
94335
94396
  this.inputElement.addEventListener('click', this.handleMouseCaretPositionChange.bind(this));
94336
- this.inputElement.addEventListener('keydown', this.handleKeyDownValueChange.bind(this));
94337
- this.inputElement.addEventListener('keydown', this.handleKeydownCaretPositionChange.bind(this));
94338
- this.inputElement.addEventListener('keydown', this.handleValueChange.bind(this));
94397
+ this.inputElement.addEventListener('keydown', this.handleNavKeys.bind(this));
94398
+ this.inputElement.addEventListener('keydown', this.handleDigitKeys.bind(this));
94339
94399
 
94340
94400
  forwardAttrs$1(this, this.inputElement, {
94341
94401
  includeAttrs: [
@@ -94349,8 +94409,14 @@ descope-boolean-field-internal {
94349
94409
  'full-width',
94350
94410
  'st-host-direction',
94351
94411
  'pattern',
94352
- 'invalid',
94353
94412
  'bordered',
94413
+ 'data-errormessage-value-missing',
94414
+ 'data-errormessage-pattern-mismatch',
94415
+ 'data-errormessage-range-underflow',
94416
+ 'data-errormessage-range-overflow',
94417
+ 'st-error-message-icon',
94418
+ 'st-error-message-icon-size',
94419
+ 'st-error-message-icon-padding',
94354
94420
  ],
94355
94421
  });
94356
94422
  }
@@ -94478,7 +94544,7 @@ descope-boolean-field-internal {
94478
94544
  this.getCounterById('month').replaceValue(calendarDate.getMonth() + 1);
94479
94545
  this.getCounterById('day').replaceValue(calendarDate.getDate());
94480
94546
 
94481
- this.dispatchEvent(new Event('input'));
94547
+ this.#dispatchInput();
94482
94548
  }
94483
94549
 
94484
94550
  this.closePopover();
@@ -94489,10 +94555,10 @@ descope-boolean-field-internal {
94489
94555
  isValidTimestamp(newDate(this.inputElement.value || '').getTime()) &&
94490
94556
  formats[this.format].validate(this.inputElement.value);
94491
94557
 
94492
- if (this.inputValueTimestamp || validInputVal) {
94558
+ if (this.displayValueEpoch || validInputVal) {
94493
94559
  this.calendar.setAttribute(
94494
94560
  'initial-value',
94495
- formatTimestamp(this.inputValueTimestamp || this.timestamp, NATIVE_FORMAT)
94561
+ formatTimestamp(this.displayValueEpoch || this.timestamp, NATIVE_FORMAT)
94496
94562
  );
94497
94563
  } else {
94498
94564
  this.calendar.clearValue();
@@ -94515,13 +94581,6 @@ descope-boolean-field-internal {
94515
94581
  });
94516
94582
  }
94517
94583
 
94518
- onInput(e) {
94519
- if (!e.target.value) {
94520
- this.calendar?.clear();
94521
- this.calendar?.renderCalendar();
94522
- }
94523
- }
94524
-
94525
94584
  onFocus() {
94526
94585
  if (this.isReadOnly) {
94527
94586
  return;
@@ -94533,16 +94592,13 @@ descope-boolean-field-internal {
94533
94592
  }
94534
94593
  }
94535
94594
 
94536
- clearInputValue() {
94537
- this.inputElement.value = '';
94538
- this.resetDateCounters();
94539
- }
94540
-
94541
94595
  onBlur() {
94542
- if (this.inputValueTimestamp) {
94543
- this.value = this.inputValueTimestamp;
94544
- } else if (!this.opened && this.countersValue === this.format) {
94545
- this.clearInputValue();
94596
+ if (this.opened) {
94597
+ return;
94598
+ }
94599
+
94600
+ if (this.inputElement.value === this.format) {
94601
+ this.inputElement.value = '';
94546
94602
  }
94547
94603
  }
94548
94604
 
@@ -94559,11 +94615,11 @@ descope-boolean-field-internal {
94559
94615
  this.setAttribute('pattern', formats[format].pattern);
94560
94616
  }
94561
94617
 
94562
- handleValueChange(e) {
94618
+ handleDigitKeys(e) {
94563
94619
  if (isNumber(e.key)) {
94564
94620
  e.preventDefault();
94565
94621
 
94566
- this.handleCountersValue(e.key);
94622
+ this.activeCounter.add(e.key);
94567
94623
 
94568
94624
  if (this.activeCounter.isFull) {
94569
94625
  this.selectNextCounter();
@@ -94583,11 +94639,6 @@ descope-boolean-field-internal {
94583
94639
  return [c1, c2, c3].indexOf(true);
94584
94640
  }
94585
94641
 
94586
- handleCountersValue(val) {
94587
- this.activeCounter.add(val);
94588
- this.inputElement.value = this.countersValue;
94589
- }
94590
-
94591
94642
  setSelectedCounterByCaretPosition(e) {
94592
94643
  this.selectedCounterIdx = this.getCounterIdx(e.target.selectionStart);
94593
94644
  }
@@ -94645,21 +94696,21 @@ descope-boolean-field-internal {
94645
94696
  });
94646
94697
  }
94647
94698
 
94648
- handleKeyDownValueChange(e) {
94699
+ handleNavKeys(e) {
94649
94700
  if (this.isReadOnly) {
94650
94701
  return;
94651
94702
  }
94652
94703
 
94653
94704
  const { key, shiftKey, metaKey } = e;
94654
94705
  const keys = getKeyMap(key, shiftKey, metaKey);
94655
- const allowedOperations = keys.refresh || keys.tab || keys.shiftTab;
94656
94706
 
94657
94707
  if (this.opened) {
94658
94708
  this.closePopover();
94659
94709
  }
94660
94710
 
94711
+ e.preventDefault();
94712
+
94661
94713
  if (isSupportedKey(key)) {
94662
- e.preventDefault();
94663
94714
  const counter = this.activeCounter;
94664
94715
 
94665
94716
  if (!counter) return;
@@ -94676,12 +94727,10 @@ descope-boolean-field-internal {
94676
94727
  else if (keys.pageDown) counter.dec(count);
94677
94728
  else if (keys.shiftPageUp) counter.inc(shiftCount);
94678
94729
  else if (keys.shiftPageDown) counter.dec(shiftCount);
94679
-
94680
- this.inputElement.value = this.countersValue;
94730
+ else if (keys.arrowRight) this.selectNextCounter();
94731
+ else if (keys.arrowLeft) this.selectPrevCounter();
94681
94732
 
94682
94733
  this.setInputSelectionRange();
94683
- } else if (!allowedOperations) {
94684
- e.preventDefault();
94685
94734
  }
94686
94735
  }
94687
94736
 
@@ -94696,25 +94745,6 @@ descope-boolean-field-internal {
94696
94745
  }
94697
94746
  }
94698
94747
 
94699
- handleKeydownCaretPositionChange(e) {
94700
- if (this.opened) {
94701
- return;
94702
- }
94703
-
94704
- const { key } = e;
94705
-
94706
- if (isSupportedKey(key)) {
94707
- e.preventDefault();
94708
-
94709
- const keys = getKeyMap(key, false);
94710
-
94711
- if (keys.arrowRight) this.selectNextCounter();
94712
- else if (keys.arrowLeft) this.selectPrevCounter();
94713
-
94714
- this.setInputSelectionRange();
94715
- }
94716
- }
94717
-
94718
94748
  handleMouseCaretPositionChange(e) {
94719
94749
  if (this.opened) {
94720
94750
  return;
@@ -94734,10 +94764,22 @@ descope-boolean-field-internal {
94734
94764
  });
94735
94765
  }
94736
94766
 
94767
+ setYearRange(val) {
94768
+ if (!val) return;
94769
+ const [min, max] = val.split?.('-');
94770
+ if (min && max) {
94771
+ this.#yearDateCounter.setMin(min);
94772
+ this.#yearDateCounter.setMax(max);
94773
+ }
94774
+ }
94775
+
94737
94776
  attributeChangedCallback(attrName, oldValue, newValue) {
94738
94777
  super.attributeChangedCallback?.(attrName, oldValue, newValue);
94739
94778
 
94740
94779
  if (oldValue !== newValue) {
94780
+ if (attrName === 'years-range') {
94781
+ this.setYearRange(newValue);
94782
+ }
94741
94783
  if (dateFieldAttrs.includes(attrName)) {
94742
94784
  if (newValue && attrName === 'format') {
94743
94785
  this.onFormatUpdate(newValue);
@@ -94756,16 +94798,20 @@ descope-boolean-field-internal {
94756
94798
  }
94757
94799
 
94758
94800
  getValidity() {
94759
- if (this.isRequired && !this.inputElement.value) {
94801
+ if (this.isRequired && this.isCountersEmpty) {
94760
94802
  return { valueMissing: true };
94761
94803
  }
94762
94804
 
94805
+ if (this.isCountersOutOfRange) {
94806
+ return { patternMismatch: true };
94807
+ }
94808
+
94763
94809
  return {};
94764
94810
  }
94765
94811
  }
94766
94812
 
94767
94813
  const textVars = TextFieldClass.cssVarList;
94768
- const { host: host$5, input, inputEleRTL, toggleButton, overlay, backdrop } = {
94814
+ const { host: host$5, input, inputEleRTL, toggleButton, overlay, backdrop} = {
94769
94815
  host: { selector: () => ':host' },
94770
94816
  input: { selector: () => 'descope-text-field' },
94771
94817
  inputEleRTL: { selector: () => ':host([st-host-direction="rtl"]) descope-text-field' },
@@ -94803,6 +94849,30 @@ descope-boolean-field-internal {
94803
94849
  overlayOutlineStyle: {
94804
94850
  property: () => DateFieldClass.cssVarList.overlayOutlineStyle,
94805
94851
  },
94852
+ errorMessageIcon: {
94853
+ selector: TextFieldClass.componentName,
94854
+ property: TextFieldClass.cssVarList.errorMessageIcon,
94855
+ },
94856
+ errorMessageIconSize: {
94857
+ selector: TextFieldClass.componentName,
94858
+ property: TextFieldClass.cssVarList.errorMessageIconSize,
94859
+ },
94860
+ errorMessageIconPadding: {
94861
+ selector: TextFieldClass.componentName,
94862
+ property: TextFieldClass.cssVarList.errorMessageIconPadding,
94863
+ },
94864
+ errorMessageIconRepeat: {
94865
+ selector: TextFieldClass.componentName,
94866
+ property: TextFieldClass.cssVarList.errorMessageIconRepeat,
94867
+ },
94868
+ errorMessageIconPosition: {
94869
+ selector: TextFieldClass.componentName,
94870
+ property: TextFieldClass.cssVarList.errorMessageIconPosition,
94871
+ },
94872
+ errorMessageFontSize: {
94873
+ selector: TextFieldClass.componentName,
94874
+ property: TextFieldClass.cssVarList.errorMessageFontSize,
94875
+ },
94806
94876
  },
94807
94877
  }),
94808
94878
  portalMixin({
@@ -94847,6 +94917,13 @@ descope-boolean-field-internal {
94847
94917
 
94848
94918
  [vars$g.rtlInputDirection]: 'ltr',
94849
94919
  [vars$g.rtlInputAlignment]: 'right',
94920
+
94921
+ [vars$g.errorMessageIcon]: refs$1.errorMessageIcon,
94922
+ [vars$g.errorMessageIconSize]: refs$1.errorMessageIconSize,
94923
+ [vars$g.errorMessageIconPadding]: refs$1.errorMessageIconPadding,
94924
+ [vars$g.errorMessageIconRepeat]: refs$1.errorMessageIconRepeat,
94925
+ [vars$g.errorMessageIconPosition]: refs$1.errorMessageIconPosition,
94926
+ [vars$g.errorMessageFontSize]: refs$1.errorMessageFontSize,
94850
94927
  };
94851
94928
 
94852
94929
  var dateField$1 = /*#__PURE__*/Object.freeze({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@descope/flow-components",
3
- "version": "2.0.548",
3
+ "version": "2.0.549",
4
4
  "description": "",
5
5
  "main": "dist/index.cjs.js",
6
6
  "module": "dist/index.esm.js",
@@ -112,7 +112,7 @@
112
112
  "webpack-dev-server": "5.2.1"
113
113
  },
114
114
  "dependencies": {
115
- "@descope/web-components-ui": "1.88.0"
115
+ "@descope/web-components-ui": "1.89.0"
116
116
  },
117
117
  "peerDependencies": {
118
118
  "react": ">= 18"