@descope/flow-components 2.0.581 → 2.0.583

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
@@ -93151,6 +93151,104 @@ descope-boolean-field-internal {
93151
93151
  vars: vars$j
93152
93152
  });
93153
93153
 
93154
+ const SUPPORTED_FORMATS = ['MM/DD/YYYY', 'DD/MM/YYYY', 'YYYY/MM/DD'];
93155
+
93156
+ const DEFAULT_FORMAT = SUPPORTED_FORMATS[0];
93157
+
93158
+ const NATIVE_FORMAT = 'YYYY-MM-DD';
93159
+
93160
+ const YEARS_RANGE = 100;
93161
+
93162
+ const DIVIDER = '/';
93163
+
93164
+ const months = [
93165
+ 'January',
93166
+ 'February',
93167
+ 'March',
93168
+ 'April',
93169
+ 'May',
93170
+ 'June',
93171
+ 'July',
93172
+ 'August',
93173
+ 'September',
93174
+ 'October',
93175
+ 'November',
93176
+ 'December',
93177
+ ];
93178
+
93179
+ const weekdays = [
93180
+ 'Sunday',
93181
+ 'Monday',
93182
+ 'Tuesday',
93183
+ 'Wednesday',
93184
+ 'Thursday',
93185
+ 'Friday',
93186
+ 'Saturday',
93187
+ ];
93188
+
93189
+ const counterConfig = {
93190
+ MONTH: { id: 'month', min: 1, max: 12, placeholder: 'MM' },
93191
+ DAY: { id: 'day', min: 1, max: 31, placeholder: 'DD' },
93192
+ YEAR: { id: 'year', min: 0, max: 9999, placeholder: 'YYYY' },
93193
+ };
93194
+
93195
+ const valRange = {
93196
+ year: { min: 1900, max: 2099 },
93197
+ };
93198
+
93199
+ const BUTTON_LABEL_DONE = 'Done';
93200
+ const BUTTON_LABEL_CANCEL = 'Cancel';
93201
+ const CALENDAR_LABEL_TODAY = 'Today';
93202
+
93203
+ const MOBILE_DEVICE_INTERACTION_TIMEOUT_MS = 150;
93204
+
93205
+ const patterns = {
93206
+ MM: '(0?[1-9]|1[0-2])',
93207
+ DD: '(0?[1-9]|[12][0-9]|3[01])',
93208
+ YYYY: '([0-9]{4})',
93209
+ };
93210
+
93211
+ const createPattern = (format) => {
93212
+ const pattern = format
93213
+ .split(DIVIDER)
93214
+ .map((part) => patterns[part])
93215
+ .join('\\D');
93216
+
93217
+ return `^${pattern}$`;
93218
+ };
93219
+
93220
+ const createToValuesFn = (format) => {
93221
+ const order = format.split(DIVIDER);
93222
+ return (match) => {
93223
+ const values = {};
93224
+ order.forEach((part, index) => {
93225
+ values[part] = match[index + 1];
93226
+ });
93227
+ return [values.YYYY, values.MM, values.DD];
93228
+ };
93229
+ };
93230
+
93231
+ const createDate = (val, regexp, toValuesFn) => {
93232
+ const match = regexp.exec(val);
93233
+ if (!match) return null;
93234
+ const [year, month, day] = toValuesFn(match);
93235
+ return newDate([year, month, day].join(DIVIDER));
93236
+ };
93237
+
93238
+ const createFormat = (format) => {
93239
+ const pattern = createPattern(format);
93240
+ const toValuesFn = createToValuesFn(format);
93241
+ const regexp = new RegExp(pattern);
93242
+
93243
+ return {
93244
+ pattern,
93245
+ validate: (val) => regexp.test(val),
93246
+ getDate: (val) => createDate(val, regexp, toValuesFn),
93247
+ };
93248
+ };
93249
+
93250
+ const formats = Object.fromEntries(SUPPORTED_FORMATS.map((f) => [f, createFormat(f)]));
93251
+
93154
93252
  const isValidTimestamp = (val) => !Number.isNaN(Number(val));
93155
93253
 
93156
93254
  const isNumber = (val) => !!String(val || '').trim() && !Number.isNaN(Number(val));
@@ -93200,6 +93298,12 @@ descope-boolean-field-internal {
93200
93298
  ele?.shadowRoot?.adoptedStyleSheets?.push(cs);
93201
93299
  };
93202
93300
 
93301
+ const parseDateString = (val, format) => {
93302
+ const trimmed = val.trim?.();
93303
+ if (!trimmed) return null;
93304
+ return formats[format].getDate(trimmed);
93305
+ };
93306
+
93203
93307
  const calendarIcon = `
93204
93308
  <svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
93205
93309
  <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"/>
@@ -93215,57 +93319,6 @@ descope-boolean-field-internal {
93215
93319
  <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"/>
93216
93320
  </svg>`;
93217
93321
 
93218
- const SUPPORTED_FORMATS = ['MM/DD/YYYY', 'DD/MM/YYYY', 'YYYY/MM/DD'];
93219
-
93220
- const DEFAULT_FORMAT = SUPPORTED_FORMATS[0];
93221
-
93222
- const NATIVE_FORMAT = 'YYYY-MM-DD';
93223
-
93224
- const YEARS_RANGE = 100;
93225
-
93226
- const DIVIDER = '/';
93227
-
93228
- const months = [
93229
- 'January',
93230
- 'February',
93231
- 'March',
93232
- 'April',
93233
- 'May',
93234
- 'June',
93235
- 'July',
93236
- 'August',
93237
- 'September',
93238
- 'October',
93239
- 'November',
93240
- 'December',
93241
- ];
93242
-
93243
- const weekdays = [
93244
- 'Sunday',
93245
- 'Monday',
93246
- 'Tuesday',
93247
- 'Wednesday',
93248
- 'Thursday',
93249
- 'Friday',
93250
- 'Saturday',
93251
- ];
93252
-
93253
- const counterConfig = {
93254
- MONTH: { id: 'month', min: 1, max: 12, placeholder: 'MM' },
93255
- DAY: { id: 'day', min: 1, max: 31, placeholder: 'DD' },
93256
- YEAR: { id: 'year', min: 0, max: 9999, placeholder: 'YYYY' },
93257
- };
93258
-
93259
- const valRange = {
93260
- year: { min: 1900, max: 2099 },
93261
- };
93262
-
93263
- const BUTTON_LABEL_DONE = 'Done';
93264
- const BUTTON_LABEL_CANCEL = 'Cancel';
93265
- const CALENDAR_LABEL_TODAY = 'Today';
93266
-
93267
- const MOBILE_DEVICE_INTERACTION_TIMEOUT_MS = 150;
93268
-
93269
93322
  const isValidAttrArr = (arr, count) =>
93270
93323
  Array.isArray(arr) && arr.length === count && arr.filter(Boolean).length === count;
93271
93324
 
@@ -94167,53 +94220,6 @@ descope-boolean-field-internal {
94167
94220
  vars: vars$i
94168
94221
  });
94169
94222
 
94170
- const patterns = {
94171
- MM: '(0?[1-9]|1[0-2])',
94172
- DD: '(0?[1-9]|[12][0-9]|3[01])',
94173
- YYYY: '([0-9]{4})',
94174
- };
94175
-
94176
- const createPattern = (format) => {
94177
- const pattern = format
94178
- .split(DIVIDER)
94179
- .map((part) => patterns[part])
94180
- .join('\\D');
94181
-
94182
- return `^${pattern}$`;
94183
- };
94184
-
94185
- const createToValuesFn = (format) => {
94186
- const order = format.split(DIVIDER);
94187
- return (match) => {
94188
- const values = {};
94189
- order.forEach((part, index) => {
94190
- values[part] = match[index + 1];
94191
- });
94192
- return [values.YYYY, values.MM, values.DD];
94193
- };
94194
- };
94195
-
94196
- const createDate = (val, regexp, toValuesFn) => {
94197
- const match = regexp.exec(val);
94198
- if (!match) return null;
94199
- const [year, month, day] = toValuesFn(match);
94200
- return newDate([year, month, day].join(DIVIDER));
94201
- };
94202
-
94203
- const createFormat = (format) => {
94204
- const pattern = createPattern(format);
94205
- const toValuesFn = createToValuesFn(format);
94206
- const regexp = new RegExp(pattern);
94207
-
94208
- return {
94209
- pattern,
94210
- validate: (val) => regexp.test(val),
94211
- getDate: (val) => createDate(val, regexp, toValuesFn),
94212
- };
94213
- };
94214
-
94215
- const formats = Object.fromEntries(SUPPORTED_FORMATS.map((f) => [f, createFormat(f)]));
94216
-
94217
94223
  // DateCounterClass allows us to add several counters to the input, and use them seperately.
94218
94224
  // For examele, we have a DayCounter, MonthCounter and YearCounter, which can each separately navigate
94219
94225
  // between different ranges.
@@ -94523,6 +94529,11 @@ descope-boolean-field-internal {
94523
94529
  return this.getAttribute('disable-calendar') === 'true';
94524
94530
  }
94525
94531
 
94532
+ get isSelectAll() {
94533
+ const inputEle = this.inputElement.baseElement.inputElement;
94534
+ return inputEle.value.length === inputEle.selectionStart + inputEle.selectionEnd;
94535
+ }
94536
+
94526
94537
  reportValidity() {
94527
94538
  this.inputElement.reportValidity();
94528
94539
  }
@@ -94557,9 +94568,10 @@ descope-boolean-field-internal {
94557
94568
  this.inputElement.addEventListener('focus', this.onFocus.bind(this));
94558
94569
  this.inputElement.addEventListener('blur', this.onBlur.bind(this));
94559
94570
  this.inputElement.addEventListener('click', this.handleMouseCaretPositionChange.bind(this));
94560
- this.inputElement.addEventListener('keydown', this.handleArrowKeys.bind(this));
94571
+ this.inputElement.addEventListener('keydown', this.handleKeyboard.bind(this));
94561
94572
  this.inputElement.addEventListener('beforeinput', this.handleInput.bind(this));
94562
94573
  this.inputElement.addEventListener('pointerdown', this.onPointerDown.bind(this));
94574
+ this.inputElement.addEventListener('paste', this.onPaste.bind(this));
94563
94575
 
94564
94576
  forwardAttrs$1(this, this.inputElement, {
94565
94577
  includeAttrs: [
@@ -94588,6 +94600,8 @@ descope-boolean-field-internal {
94588
94600
  handleInput(e) {
94589
94601
  e.preventDefault();
94590
94602
 
94603
+ this.handleSelectAll();
94604
+
94591
94605
  if (e.data && isNumber(e.data)) {
94592
94606
  this.parseDigits(e.data);
94593
94607
  this.updateCountersDisplay();
@@ -94608,6 +94622,12 @@ descope-boolean-field-internal {
94608
94622
  });
94609
94623
  }
94610
94624
 
94625
+ handleSelectAll() {
94626
+ if (this.isSelectAll) {
94627
+ this.selectFirstCounter();
94628
+ }
94629
+ }
94630
+
94611
94631
  #popoverPosStylesheet;
94612
94632
 
94613
94633
  #popoverRenderer(root) {
@@ -94778,7 +94798,8 @@ descope-boolean-field-internal {
94778
94798
  }
94779
94799
 
94780
94800
  // On focus select the first counter
94781
- this.selectedCounterIdx = 0;
94801
+ this.selectFirstCounter();
94802
+ // set selection on first counter
94782
94803
  this.inputElement.setSelectionRange(0, this.sortedCounters[0].length);
94783
94804
  }
94784
94805
 
@@ -94837,6 +94858,10 @@ descope-boolean-field-internal {
94837
94858
  );
94838
94859
  }
94839
94860
 
94861
+ selectFirstCounter() {
94862
+ this.selectedCounterIdx = 0;
94863
+ }
94864
+
94840
94865
  selectNextCounter() {
94841
94866
  if (this.selectedCounterIdx < this.dateCounters.length) {
94842
94867
  this.selectedCounterIdx = Math.min(this.selectedCounterIdx + 1, 2);
@@ -94894,7 +94919,17 @@ descope-boolean-field-internal {
94894
94919
  });
94895
94920
  }
94896
94921
 
94897
- handleArrowKeys(e) {
94922
+ handleKeyboard(e) {
94923
+ if (e.metaKey || e.ctrlKey) {
94924
+ if (e.key.toLowerCase() === 'x') {
94925
+ this.onCut(e);
94926
+ }
94927
+
94928
+ return;
94929
+ }
94930
+
94931
+ this.handleSelectAll();
94932
+
94898
94933
  if (e.key === 'ArrowUp') {
94899
94934
  this.activeCounter.inc();
94900
94935
  } else if (e.key === 'ArrowDown') {
@@ -94927,6 +94962,11 @@ descope-boolean-field-internal {
94927
94962
  }
94928
94963
 
94929
94964
  handleBackspace() {
94965
+ if (this.isSelectAll) {
94966
+ this.resetToInitialState();
94967
+ return;
94968
+ }
94969
+
94930
94970
  const counter = this.activeCounter;
94931
94971
 
94932
94972
  if (counter.isEmpty) {
@@ -95044,6 +95084,62 @@ descope-boolean-field-internal {
95044
95084
 
95045
95085
  return ret;
95046
95086
  }
95087
+
95088
+ resetToInitialState() {
95089
+ this.resetDateCounters();
95090
+ this.selectFirstCounter();
95091
+ this.resetDisplay();
95092
+ }
95093
+
95094
+ onCut(e) {
95095
+ e.preventDefault();
95096
+
95097
+ if (this.isSelectAll) {
95098
+ this.#copyToClipboard(this.countersValue);
95099
+ this.resetToInitialState();
95100
+ } else {
95101
+ this.#copyToClipboard(this.activeCounter.stringValue);
95102
+ this.activeCounter.set('');
95103
+ }
95104
+
95105
+ this.setInputSelectionRange();
95106
+ }
95107
+
95108
+ #copyToClipboard(value) {
95109
+ try {
95110
+ navigator.clipboard.writeText(value);
95111
+ } catch (err) {
95112
+ console.error('Failed to copy date value:', err);
95113
+ }
95114
+ }
95115
+
95116
+ onPaste(e) {
95117
+ e.preventDefault();
95118
+
95119
+ const clipboardData = e.clipboardData || window.clipboardData;
95120
+ const pastedData = clipboardData.getData('Text');
95121
+
95122
+ // try paste entire date if valid
95123
+ const validDate = parseDateString(pastedData, this.format);
95124
+
95125
+ if (validDate) {
95126
+ this.value = validDate.getTime();
95127
+ this.onDateCounterChange();
95128
+
95129
+ // select all
95130
+ setTimeout(() => this.inputElement.setSelectionRange(0, this.inputElement.value.length));
95131
+ } else {
95132
+ const value = Number(pastedData);
95133
+
95134
+ // try paste in counter if possible
95135
+ if (value && this.activeCounter.min <= value && this.activeCounter.max >= value) {
95136
+ // use String to get rid of any zero padding
95137
+ this.activeCounter.set(String(value));
95138
+
95139
+ setTimeout(() => this.setInputSelectionRange());
95140
+ }
95141
+ }
95142
+ }
95047
95143
  }
95048
95144
 
95049
95145
  const textVars$1 = TextFieldClass.cssVarList;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@descope/flow-components",
3
- "version": "2.0.581",
3
+ "version": "2.0.583",
4
4
  "description": "",
5
5
  "main": "dist/index.cjs.js",
6
6
  "module": "dist/index.esm.js",
@@ -78,7 +78,7 @@
78
78
  "eslint-plugin-jest-dom": "5.5.0",
79
79
  "eslint-plugin-jest-formatting": "3.1.0",
80
80
  "eslint-plugin-jsx-a11y": "^6.6.1",
81
- "eslint-plugin-n": "17.19.0",
81
+ "eslint-plugin-n": "17.20.0",
82
82
  "eslint-plugin-no-only-tests": "3.3.0",
83
83
  "eslint-plugin-prefer-arrow": "1.2.3",
84
84
  "eslint-plugin-prettier": "5.4.1",
@@ -112,7 +112,7 @@
112
112
  "webpack-dev-server": "5.2.1"
113
113
  },
114
114
  "dependencies": {
115
- "@descope/web-components-ui": "1.105.0"
115
+ "@descope/web-components-ui": "1.106.0"
116
116
  },
117
117
  "peerDependencies": {
118
118
  "react": ">= 18"