@progress/kendo-dateinputs-common 0.2.0-dev.202301101148 → 0.2.0-dev.202301130811

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.
@@ -160,16 +160,18 @@ var DateObject = /** @class */ (function () {
160
160
  partiallyInvalidText += text[i];
161
161
  }
162
162
  else if (this.getInvalidDatePartValue(symbol)) {
163
+ var partsForSegment = this.getPartsForSegment(mask, i);
163
164
  if (symbol === "M") {
164
- if (mask.partMap[i].pattern.length > MONTH_PART_WITH_WORDS_THRESHOLD) {
165
+ var datePartText = (utils_2.parseToInt(this.getInvalidDatePartValue(symbol)) + JS_MONTH_OFFSET).toString();
166
+ if (partsForSegment.length > MONTH_PART_WITH_WORDS_THRESHOLD) {
165
167
  partiallyInvalidText += formattedDates[symbol][i];
166
168
  }
167
169
  else {
168
170
  if (this.getInvalidDatePartValue(symbol)) {
169
- var month = utils_2.parseToInt(this.getInvalidDatePartValue(symbol) + JS_MONTH_OFFSET).toString();
170
- var formattedMonth = utils_1.padZero(Math.abs(mask.partMap[i].pattern.length - month.length)) + month;
171
- partiallyInvalidText += formattedMonth;
172
- i += Math.max(0, formattedMonth.length - 1);
171
+ var formattedDatePart = utils_1.padZero(partsForSegment.length - datePartText.length) + datePartText;
172
+ partiallyInvalidText += formattedDatePart;
173
+ // add -1 as the first character in the segment is at index i
174
+ i += partsForSegment.length - 1;
173
175
  }
174
176
  else {
175
177
  partiallyInvalidText += formattedDates[symbol][i];
@@ -178,8 +180,11 @@ var DateObject = /** @class */ (function () {
178
180
  }
179
181
  else {
180
182
  if (this.getInvalidDatePartValue(symbol)) {
181
- partiallyInvalidText += this.getInvalidDatePartValue(symbol);
182
- i += Math.max(0, this.getInvalidDatePartValue(symbol).toString().length - 1);
183
+ var datePartText = this.getInvalidDatePartValue(symbol).toString();
184
+ var formattedDatePart = utils_1.padZero(partsForSegment.length - datePartText.length) + datePartText;
185
+ partiallyInvalidText += formattedDatePart;
186
+ // add -1 as the first character in the segment is at index i
187
+ i += partsForSegment.length - 1;
183
188
  }
184
189
  else {
185
190
  partiallyInvalidText += formattedDates[symbol][i];
@@ -290,16 +295,18 @@ var DateObject = /** @class */ (function () {
290
295
  }
291
296
  };
292
297
  DateObject.prototype.modifyPart = function (symbol, offset) {
298
+ if (!utils_2.isPresent(symbol) || !utils_2.isPresent(offset) || offset === 0) {
299
+ return;
300
+ }
293
301
  var newValue = kendo_date_math_1.cloneDate(this.value);
294
- var originalValue = kendo_date_math_1.cloneDate(this.value);
295
302
  var timeModified = false;
296
303
  var invalidDateFound;
297
- var currentInvalidDatePartValue = 0;
298
- if (!this.autoCorrectParts) {
299
- var isMonth = symbol === "M";
300
- var isDay = symbol === "d" || symbol === "E";
304
+ var isMonth = symbol === "M";
305
+ var isDay = symbol === "d" || symbol === "E";
306
+ var symbolExists = this.getExisting(symbol);
307
+ if (!this.autoCorrectParts && (isDay || isMonth)) {
301
308
  var invalidDateParts = this._partiallyInvalidDate.invalidDateParts || {};
302
- var invalidDatePart = invalidDateParts[symbol];
309
+ var invalidDatePartValue = this.getInvalidDatePartValue(symbol);
303
310
  var year = invalidDateParts.y.value || newValue.getFullYear();
304
311
  var month = invalidDateParts.M.value || newValue.getMonth();
305
312
  var day = invalidDateParts.d.value || invalidDateParts.E.value || newValue.getDate();
@@ -318,33 +325,61 @@ var DateObject = /** @class */ (function () {
318
325
  case 'E':
319
326
  day += offset;
320
327
  break;
321
- case 'h':
322
- case 'H':
323
- hour += offset;
324
- break;
325
- case 'm':
326
- minutes += offset;
327
- break;
328
- case 's':
329
- seconds += offset;
330
- break;
331
- case 'S':
332
- milliseconds += offset;
333
- break;
334
- // case 'a': newValue.setHours(newValue.getHours() + (12 * offset)); timeModified = true; break;
328
+ // case 'h':
329
+ // case 'H': hour += offset; break;
330
+ // case 'm': minutes += offset; break;
331
+ // case 's': seconds += offset; break;
332
+ // case 'S': milliseconds += offset; break;
335
333
  default: break;
336
334
  }
337
335
  if (symbol === "M") {
338
- if ((month < 0 || month > 11) && this.getExisting(symbol)) {
339
- // do not cycle months
340
- this.setExisting(symbol, false);
341
- return;
336
+ if ((month < 0 || month > 11)) {
337
+ if (symbolExists) {
338
+ this.setExisting(symbol, false);
339
+ this.resetInvalidDateSymbol(symbol);
340
+ return;
341
+ }
342
+ }
343
+ if (!symbolExists) {
344
+ if (month < 0) {
345
+ month = utils_2.clamp(11 + ((month % 11) + 1), 0, 11);
346
+ }
347
+ else {
348
+ var monthValue = utils_2.isPresent(invalidDatePartValue) ?
349
+ month :
350
+ ((offset - JS_MONTH_OFFSET) % 12);
351
+ month = utils_2.clamp(monthValue, 0, 11);
352
+ }
353
+ month = utils_2.clamp(month, 0, 11);
354
+ }
355
+ month = utils_2.clamp(month, 0, 11);
356
+ }
357
+ else if (symbol === "d") {
358
+ if (symbolExists) {
359
+ if (day <= 0 || day > 31) {
360
+ this.setExisting(symbol, false);
361
+ this.resetInvalidDateSymbol(symbol);
362
+ return;
363
+ }
364
+ }
365
+ else if (!symbolExists) {
366
+ if (utils_2.isPresent(invalidDatePartValue)) {
367
+ if (day <= 0 || day > 31) {
368
+ this.setExisting(symbol, false);
369
+ this.resetInvalidDateSymbol(symbol);
370
+ return;
371
+ }
372
+ }
373
+ if (offset < 0) {
374
+ var dayValue = utils_2.isPresent(invalidDatePartValue) ? day : 1 + (31 - Math.abs(offset % 31));
375
+ day = utils_2.clamp(dayValue, 1, 31);
376
+ }
377
+ else {
378
+ var dayValue = utils_2.isPresent(invalidDatePartValue) ? day : offset % 31;
379
+ day = utils_2.clamp(dayValue, 1, 31);
380
+ }
381
+ day = utils_2.clamp(day, 1, 31);
342
382
  }
343
- // const mask = this.dateFormatString(this.value, this.format);
344
- // const monthPart = mask.partMap.filter(x => x.type === "month");
345
- // if (monthPart && monthPart[0] && monthPart[0].pattern.length > MONTH_PART_WITH_WORDS_THRESHOLD) {
346
- month = (12 + month) % 12;
347
- // }
348
383
  }
349
384
  var dateCandidate = kendo_date_math_1.createDate(year, month, day, hour, minutes, seconds, milliseconds);
350
385
  var newValueCandidate = isMonth || isDay ?
@@ -441,92 +476,6 @@ var DateObject = /** @class */ (function () {
441
476
  this.setExisting(symbol, false);
442
477
  }
443
478
  }
444
- else {
445
- // this.modifyDateSymbol()
446
- switch (symbol) {
447
- case 'y':
448
- newValue.setFullYear(newValue.getFullYear() + offset);
449
- break;
450
- case 'M':
451
- newValue = kendo_date_math_1.addMonths(this.value, offset);
452
- break;
453
- case 'd':
454
- case 'E':
455
- newValue.setDate(newValue.getDate() + offset);
456
- break;
457
- case 'h':
458
- case 'H':
459
- newValue.setHours(newValue.getHours() + offset);
460
- timeModified = true;
461
- break;
462
- case 'm':
463
- newValue.setMinutes(newValue.getMinutes() + offset);
464
- timeModified = true;
465
- break;
466
- case 's':
467
- newValue.setSeconds(newValue.getSeconds() + offset);
468
- timeModified = true;
469
- break;
470
- case "S":
471
- newValue.setMilliseconds(newValue.getMilliseconds() + offset);
472
- break;
473
- case 'a':
474
- newValue.setHours(newValue.getHours() + (12 * offset));
475
- timeModified = true;
476
- break;
477
- default: break;
478
- }
479
- invalidDateFound = true;
480
- if (invalidDatePart && invalidDatePart.value) {
481
- currentInvalidDatePartValue = utils_2.parseToInt(invalidDatePart.value);
482
- }
483
- else {
484
- if (!utils_2.isPresent(invalidDatePart.value)) {
485
- newValue = kendo_date_math_1.cloneDate(originalValue);
486
- // this.modifyDateSymbol()
487
- switch (symbol) {
488
- case 'y':
489
- currentInvalidDatePartValue = originalValue.getFullYear();
490
- break;
491
- case 'M':
492
- currentInvalidDatePartValue = originalValue.getMonth();
493
- break;
494
- case 'd':
495
- case 'E':
496
- currentInvalidDatePartValue = originalValue.getDate();
497
- break;
498
- case 'h':
499
- case 'H':
500
- currentInvalidDatePartValue = originalValue.getHours();
501
- break;
502
- case 'm':
503
- currentInvalidDatePartValue = originalValue.getMinutes();
504
- break;
505
- case 's':
506
- currentInvalidDatePartValue = originalValue.getSeconds();
507
- break;
508
- case 'S':
509
- currentInvalidDatePartValue = originalValue.getMilliseconds();
510
- break;
511
- // case 'a': newValue.setHours(newValue.getHours() + (12 * offset)); timeModified = true; break;
512
- default: break;
513
- }
514
- }
515
- else {
516
- }
517
- }
518
- var invalidDatePartValue = Math.max(0, currentInvalidDatePartValue + offset);
519
- if (symbol !== "y") {
520
- invalidDatePartValue = utils_2.clamp(currentInvalidDatePartValue + offset, 0, 99);
521
- }
522
- this.setInvalidDatePart(symbol, {
523
- value: invalidDatePartValue,
524
- date: kendo_date_math_1.cloneDate(newValue),
525
- startDateOffset: (this.getInvalidDatePart(symbol).startDateOffset || 0) + offset,
526
- startDate: kendo_date_math_1.cloneDate(this.value)
527
- });
528
- this.setExisting(symbol, false);
529
- }
530
479
  }
531
480
  else {
532
481
  switch (symbol) {
@@ -791,6 +740,7 @@ var DateObject = /** @class */ (function () {
791
740
  // to "Thursday, February 1, 2022 3:04:05 AM"
792
741
  // as "EEEE, February..." is not parsable
793
742
  parsedDate = this.intl.parseDate(basePrefix + middle + baseSuffix, this.format, this.localeId);
743
+ datePartText = middle;
794
744
  }
795
745
  var isCurrentCharParsable = !isNaN(parseInt(currentChar, 10)) || (isInCaretMode && isDeleting && currentChar === "");
796
746
  if (!parsedDate && !isNaN(middleNumber) && isCurrentCharParsable) {
@@ -828,6 +778,26 @@ var DateObject = /** @class */ (function () {
828
778
  }
829
779
  this._value = parsedDate;
830
780
  this.setExisting(symbol, true);
781
+ if (isInCaretMode && switchToNext) {
782
+ if (symbol === "M") {
783
+ if (segmentLength <= MONTH_PART_WITH_WORDS_THRESHOLD) {
784
+ var datePartValue = utils_2.parseToInt(datePartText);
785
+ if (datePartValue >= 2) {
786
+ switchToNext = true;
787
+ }
788
+ else {
789
+ switchToNext = false;
790
+ }
791
+ }
792
+ }
793
+ else {
794
+ switchToNext = switchToNext ?
795
+ hasFixedFormat ?
796
+ datePartText.length === segmentLength :
797
+ datePartText.length > segmentLength :
798
+ switchToNext;
799
+ }
800
+ }
831
801
  return utils_2.extend(parseResult, { value: this.value, switchToNext: switchToNext });
832
802
  }
833
803
  }
@@ -1039,42 +1009,80 @@ var DateObject = /** @class */ (function () {
1039
1009
  var resultText = '';
1040
1010
  var resultFormat = '';
1041
1011
  var format = mask.symbols;
1042
- var _loop_1 = function (formatSymbolIndex) {
1043
- if (this_1.knownParts.indexOf(format[formatSymbolIndex]) === -1 || this_1.getExisting(format[formatSymbolIndex])) {
1044
- resultText = text[formatSymbolIndex] + resultText;
1012
+ var processTextSymbolsEnded = false;
1013
+ var ignoreFormatSymbolsCount = 0;
1014
+ var formattedDates = this.getFormattedInvalidDates(format);
1015
+ for (var formatSymbolIndex = format.length - 1; formatSymbolIndex >= 0; formatSymbolIndex--) {
1016
+ var partsForSegment = this.getPartsForSegment(mask, formatSymbolIndex);
1017
+ if (this.knownParts.indexOf(format[formatSymbolIndex]) === -1 || this.getExisting(format[formatSymbolIndex])) {
1018
+ if (this.autoCorrectParts) {
1019
+ resultText = text[formatSymbolIndex] + resultText;
1020
+ }
1021
+ else {
1022
+ if (text.length !== format.length) {
1023
+ if (processTextSymbolsEnded) {
1024
+ resultText = text[formatSymbolIndex] + resultText;
1025
+ }
1026
+ else if (ignoreFormatSymbolsCount > 0) {
1027
+ resultText = text[formatSymbolIndex] + resultText;
1028
+ ignoreFormatSymbolsCount--;
1029
+ if (ignoreFormatSymbolsCount <= 0) {
1030
+ processTextSymbolsEnded = true;
1031
+ }
1032
+ }
1033
+ else {
1034
+ resultText = (text[formatSymbolIndex + text.length - format.length] || "") + resultText;
1035
+ }
1036
+ }
1037
+ else {
1038
+ resultText = text[formatSymbolIndex] + resultText;
1039
+ }
1040
+ }
1045
1041
  resultFormat = format[formatSymbolIndex] + resultFormat;
1046
1042
  }
1047
1043
  else {
1048
1044
  var symbol = format[formatSymbolIndex];
1049
- while (formatSymbolIndex >= 0 && symbol === format[formatSymbolIndex]) {
1050
- formatSymbolIndex--;
1045
+ var formatSymbolIndexModifier = 0;
1046
+ if (this.autoCorrectParts || (!this.autoCorrectParts && !this.getInvalidDatePartValue(symbol))) {
1047
+ while (formatSymbolIndex >= 0 && symbol === format[formatSymbolIndex]) {
1048
+ formatSymbolIndex--;
1049
+ }
1050
+ formatSymbolIndex++;
1051
1051
  }
1052
- formatSymbolIndex++;
1053
- if (this_1.leadingZero && this_1.leadingZero[symbol]) {
1052
+ if (this.leadingZero && this.leadingZero[symbol]) {
1054
1053
  resultText = '0' + resultText;
1055
1054
  }
1056
1055
  else {
1057
- if (!this_1.autoCorrectParts && this_1.getInvalidDatePartValue(symbol)) {
1058
- // use mask.symbols instead of mask.partMap
1059
- var part_1 = mask.partMap[formatSymbolIndex];
1060
- var pattern = mask.partMap.filter(function (x) { return x.type === part_1.type && x.pattern === part_1.pattern; });
1061
- var segmentText = text.substr(formatSymbolIndex, pattern.length);
1062
- resultText = segmentText + resultText;
1056
+ if (!this.autoCorrectParts && this.getInvalidDatePartValue(symbol)) {
1057
+ var datePartText = this.getInvalidDatePartValue(symbol).toString();
1058
+ if (symbol === "M") {
1059
+ datePartText = (utils_2.parseToInt(this.getInvalidDatePartValue(symbol)) + JS_MONTH_OFFSET).toString();
1060
+ if (partsForSegment.length > MONTH_PART_WITH_WORDS_THRESHOLD) {
1061
+ resultText = formattedDates[symbol][formatSymbolIndex] + resultText;
1062
+ }
1063
+ else {
1064
+ datePartText = (utils_2.parseToInt(this.getInvalidDatePartValue(symbol)) + JS_MONTH_OFFSET).toString();
1065
+ resultText = datePartText + resultText;
1066
+ ignoreFormatSymbolsCount = datePartText.length - partsForSegment.length;
1067
+ }
1068
+ }
1069
+ else {
1070
+ resultText = datePartText + resultText;
1071
+ formatSymbolIndexModifier = datePartText.length - 1;
1072
+ ignoreFormatSymbolsCount = datePartText.length - partsForSegment.length;
1073
+ }
1063
1074
  }
1064
1075
  else {
1065
- resultText = this_1.dateFieldName(mask.partMap[formatSymbolIndex]) + resultText;
1076
+ resultText = this.dateFieldName(mask.partMap[formatSymbolIndex]) + resultText;
1066
1077
  }
1067
1078
  }
1068
1079
  while (resultFormat.length < resultText.length) {
1069
1080
  resultFormat = format[formatSymbolIndex] + resultFormat;
1070
1081
  }
1082
+ if (formatSymbolIndexModifier !== 0) {
1083
+ formatSymbolIndex = (formatSymbolIndex - formatSymbolIndexModifier) + (text.length - format.length);
1084
+ }
1071
1085
  }
1072
- out_formatSymbolIndex_1 = formatSymbolIndex;
1073
- };
1074
- var this_1 = this, out_formatSymbolIndex_1;
1075
- for (var formatSymbolIndex = format.length - 1; formatSymbolIndex >= 0; formatSymbolIndex--) {
1076
- _loop_1(formatSymbolIndex);
1077
- formatSymbolIndex = out_formatSymbolIndex_1;
1078
1086
  }
1079
1087
  return { text: resultText, format: resultFormat };
1080
1088
  };
@@ -1241,6 +1249,32 @@ var DateObject = /** @class */ (function () {
1241
1249
  DateObject.prototype.markDatePartsAsExisting = function () {
1242
1250
  this.modifyExisting(true);
1243
1251
  };
1252
+ /**
1253
+ * @hidden
1254
+ */
1255
+ DateObject.prototype.getPartsForSegment = function (mask, partIndex) {
1256
+ var segmentPart = mask.partMap[partIndex];
1257
+ var partsForSegment = [];
1258
+ for (var maskPartIndex = partIndex; maskPartIndex < mask.partMap.length; maskPartIndex++) {
1259
+ var part = mask.partMap[maskPartIndex];
1260
+ if (segmentPart.type === part.type && segmentPart.pattern === part.pattern) {
1261
+ partsForSegment.push(part);
1262
+ }
1263
+ else {
1264
+ break;
1265
+ }
1266
+ }
1267
+ for (var maskPartIndex = partIndex - 1; maskPartIndex >= 0; maskPartIndex--) {
1268
+ var part = mask.partMap[maskPartIndex];
1269
+ if (segmentPart.type === part.type && segmentPart.pattern === part.pattern) {
1270
+ partsForSegment.unshift(part);
1271
+ }
1272
+ else {
1273
+ break;
1274
+ }
1275
+ }
1276
+ return partsForSegment;
1277
+ };
1244
1278
  return DateObject;
1245
1279
  }());
1246
1280
  exports.DateObject = DateObject;
@@ -93,7 +93,7 @@ var DateInput = /** @class */ (function (_super) {
93
93
  dateValue = null;
94
94
  }
95
95
  this.element = element;
96
- this.element._kendoWidget = this;
96
+ // this.element._kendoWidget = this;
97
97
  this.options = utils_2.extend({}, defaultDateInputOptions, options);
98
98
  this.intl = this.options.intlService;
99
99
  this.formatPlaceholder = this.options.formatPlaceholder ? this.options.formatPlaceholder : 'formatPattern';
@@ -102,6 +102,7 @@ var DateInput = /** @class */ (function (_super) {
102
102
  this.setTextAndFormat();
103
103
  this.bindEvents();
104
104
  this.resetSegmentValue = true;
105
+ this.interactionMode = interaction_mode_1.DateInputInteractionMode.None;
105
106
  this.forceUpdate();
106
107
  };
107
108
  DateInput.prototype.destroy = function () {
@@ -157,8 +158,8 @@ var DateInput = /** @class */ (function (_super) {
157
158
  if (refresh === void 0) { refresh = false; }
158
159
  this.options = utils_2.extend(this.options, options);
159
160
  if (refresh) {
160
- this.destroy();
161
- this.init(this.element, options);
161
+ this.unbindEvents();
162
+ this.init(this.element, this.options);
162
163
  }
163
164
  };
164
165
  /**
@@ -371,14 +372,10 @@ var DateInput = /** @class */ (function (_super) {
371
372
  }
372
373
  else if (hasCaret) {
373
374
  if (this.options.format.length !== this.currentFormat.length) {
374
- if (hasDateValueChanged && utils_2.isPresent(this.dateObject.value)) {
375
- var elementValueLength = this.elementValue.length;
376
- this.forceUpdate();
377
- var selectionOffset = this.elementValue.length - elementValueLength;
378
- this.setSelection({
379
- start: currentSelection.start + selectionOffset,
380
- end: currentSelection.start + selectionOffset
381
- });
375
+ if (hasDateValueChanged && utils_2.isPresent(this.dateObject.getValue())) {
376
+ if (switchPart) {
377
+ this.switchDateSegment(1);
378
+ }
382
379
  }
383
380
  }
384
381
  else {
@@ -683,6 +680,14 @@ var DateInput = /** @class */ (function (_super) {
683
680
  if (start < 0) {
684
681
  start = 0;
685
682
  }
683
+ if (!this.options.autoCorrectParts && this.currentFormat.length !== this.currentText.length) {
684
+ if (this.currentFormat.length < this.currentText.length) {
685
+ end += this.currentText.length - this.currentFormat.length;
686
+ }
687
+ else {
688
+ end = Math.max(0, end - (this.currentFormat.length - this.currentText.length));
689
+ }
690
+ }
686
691
  return { start: start, end: end };
687
692
  };
688
693
  /**
@@ -706,24 +711,36 @@ var DateInput = /** @class */ (function (_super) {
706
711
  var selection = this.selection;
707
712
  if (this.isInCaretMode()) {
708
713
  var start = selection.start;
709
- var closestNonSeparatorSymbol = this.currentFormat[start];
710
- for (var i = start; i >= 0; i--) {
711
- closestNonSeparatorSymbol = this.currentFormat[i];
712
- if (closestNonSeparatorSymbol !== constants_1.Constants.formatSeparator) {
713
- start = i;
714
- break;
714
+ var currentSymbol = this.currentFormat[start - (this.elementValue.length - this.currentFormat.length)];
715
+ var symbol = "";
716
+ var symbolCandidate = "";
717
+ if (offset < 0) {
718
+ for (var i = 0; i < start + offset; i++) {
719
+ symbolCandidate = this.currentFormat[i];
720
+ if (symbolCandidate !== constants_1.Constants.formatSeparator &&
721
+ symbolCandidate !== currentSymbol) {
722
+ start = i;
723
+ symbol = symbolCandidate;
724
+ break;
725
+ }
715
726
  }
716
727
  }
717
- var symbol = void 0;
718
- for (var i = start; i < this.currentFormat.length; i++) {
719
- symbol = this.currentFormat[i];
720
- if (symbol !== constants_1.Constants.formatSeparator) {
721
- break;
728
+ else {
729
+ for (var i = start + offset; i < this.currentFormat.length; i++) {
730
+ symbolCandidate = this.currentFormat[i];
731
+ if (symbolCandidate !== constants_1.Constants.formatSeparator &&
732
+ symbolCandidate !== currentSymbol) {
733
+ start = i;
734
+ symbol = symbolCandidate;
735
+ break;
736
+ }
722
737
  }
723
738
  }
724
739
  if (symbol) {
725
740
  this.forceUpdate();
726
741
  this.setSelection(this.selectionBySymbol(symbol));
742
+ this.interactionMode = interaction_mode_1.DateInputInteractionMode.Selection;
743
+ return;
727
744
  }
728
745
  }
729
746
  var _a = this.selection, selectionStart = _a.start, selectionEnd = _a.end;