@progress/kendo-dateinputs-common 0.2.0-dev.202301161405 → 0.2.0-dev.202301171717
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/cdn/js/kendo-dateinputs-common.js +1 -1
- package/dist/cdn/main.js +1 -1
- package/dist/es/common/dateobject.js +203 -66
- package/dist/es/dateinput/dateinput.js +58 -7
- package/dist/es2015/common/dateobject.js +204 -67
- package/dist/es2015/dateinput/dateinput.js +59 -8
- package/dist/npm/common/dateobject.d.ts +4 -0
- package/dist/npm/common/dateobject.js +203 -66
- package/dist/npm/dateinput/dateinput.d.ts +1 -0
- package/dist/npm/dateinput/dateinput.js +58 -7
- package/dist/systemjs/kendo-dateinputs-common.js +1 -1
- package/package.json +1 -1
|
@@ -547,6 +547,14 @@ var DateObject = /** @class */ (function () {
|
|
|
547
547
|
literal: ""
|
|
548
548
|
};
|
|
549
549
|
});
|
|
550
|
+
var flatDateParts = dateParts.partMap
|
|
551
|
+
.map(function (x) {
|
|
552
|
+
return {
|
|
553
|
+
type: x.type,
|
|
554
|
+
pattern: x.pattern,
|
|
555
|
+
text: ""
|
|
556
|
+
};
|
|
557
|
+
});
|
|
550
558
|
for (var i = 0; i < datePartsLiterals.length; i++) {
|
|
551
559
|
var datePart = datePartsLiterals[i];
|
|
552
560
|
for (var j = 0; j < datePart.pattern.length; j++) {
|
|
@@ -556,13 +564,23 @@ var DateObject = /** @class */ (function () {
|
|
|
556
564
|
}
|
|
557
565
|
i += datePart.pattern.length - 1;
|
|
558
566
|
}
|
|
567
|
+
for (var i = 0; i < flatDateParts.length; i++) {
|
|
568
|
+
var datePart = flatDateParts[i];
|
|
569
|
+
for (var j = 0; j < datePart.pattern.length; j++) {
|
|
570
|
+
if (flatDateParts[i + j]) {
|
|
571
|
+
flatDateParts[i + j].text = datePart.pattern[j];
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
i += datePart.pattern.length - 1;
|
|
575
|
+
}
|
|
559
576
|
var shouldResetPart = isInCaretMode && symbol === "M" && dateParts.partMap
|
|
560
577
|
.filter(function (x) { return x.type === "month"; })
|
|
561
578
|
.some(function (x) { return x.pattern.length > MONTH_PART_WITH_WORDS_THRESHOLD; });
|
|
562
579
|
var parseResult = {
|
|
563
580
|
value: null,
|
|
564
581
|
switchPart: false,
|
|
565
|
-
resetPart: shouldResetPart
|
|
582
|
+
resetPart: shouldResetPart,
|
|
583
|
+
hasInvalidDatePart: false
|
|
566
584
|
};
|
|
567
585
|
if (!currentChar) {
|
|
568
586
|
if (isInCaretMode) {
|
|
@@ -596,13 +614,19 @@ var DateObject = /** @class */ (function () {
|
|
|
596
614
|
var basePrefix = '';
|
|
597
615
|
var baseSuffix = '';
|
|
598
616
|
var suffix = '';
|
|
599
|
-
var
|
|
600
|
-
var
|
|
601
|
-
|
|
617
|
+
var convertedBaseFormat = "";
|
|
618
|
+
for (var i = 0; i < flatDateParts.length; i++) {
|
|
619
|
+
convertedBaseFormat += flatDateParts[i].text;
|
|
620
|
+
}
|
|
602
621
|
var hasFixedFormat = (this.format === baseFormat) ||
|
|
622
|
+
(this.format === convertedBaseFormat) ||
|
|
603
623
|
(this.format === originalFormat) ||
|
|
604
624
|
(this.format.length === originalFormat.length);
|
|
625
|
+
var datePartStartIndex = (hasFixedFormat ? convertedBaseFormat : originalFormat).indexOf(symbol);
|
|
626
|
+
var datePartEndIndex = (hasFixedFormat ? convertedBaseFormat : originalFormat).lastIndexOf(symbol);
|
|
627
|
+
var segmentLength = datePartEndIndex - datePartStartIndex + 1;
|
|
605
628
|
var processedSegmentCharsCount = 0;
|
|
629
|
+
var formatToTextLengthDiff = originalFormat.length - rawInputValue.length;
|
|
606
630
|
if (isInCaretMode || (!isInCaretMode && !this.autoCorrectParts)) {
|
|
607
631
|
for (var i = 0; i < baseDate.length; i++) {
|
|
608
632
|
if (baseFormat[i] === symbol) {
|
|
@@ -615,6 +639,11 @@ var DateObject = /** @class */ (function () {
|
|
|
615
639
|
}
|
|
616
640
|
processedSegmentCharsCount++;
|
|
617
641
|
}
|
|
642
|
+
else if (formatToTextLengthDiff > 0) {
|
|
643
|
+
if (datePartText.length + formatToTextLengthDiff < segmentLength) {
|
|
644
|
+
datePartText += rawInputValue[i] || "";
|
|
645
|
+
}
|
|
646
|
+
}
|
|
618
647
|
else {
|
|
619
648
|
datePartText += rawInputValue[i] || "";
|
|
620
649
|
}
|
|
@@ -629,13 +658,13 @@ var DateObject = /** @class */ (function () {
|
|
|
629
658
|
baseSuffix += baseDate[i];
|
|
630
659
|
}
|
|
631
660
|
}
|
|
632
|
-
if (hasFixedFormat
|
|
633
|
-
if (
|
|
661
|
+
if (hasFixedFormat) {
|
|
662
|
+
if (convertedBaseFormat.length < rawInputValue.length) {
|
|
634
663
|
datePartText += currentChar;
|
|
635
664
|
}
|
|
636
665
|
else if (!isDeleting && originalFormat.length > rawInputValue.length) {
|
|
637
666
|
var lengthDiff = originalFormat.length - rawInputValue.length;
|
|
638
|
-
var trimmedDatePartText = datePartText.
|
|
667
|
+
var trimmedDatePartText = datePartText.substr(0, datePartText.length - lengthDiff);
|
|
639
668
|
if (trimmedDatePartText && trimmedDatePartText.length > 0) {
|
|
640
669
|
datePartText = trimmedDatePartText;
|
|
641
670
|
}
|
|
@@ -644,7 +673,7 @@ var DateObject = /** @class */ (function () {
|
|
|
644
673
|
return utils_2.extend(parseResult, { value: null, switchToNext: false });
|
|
645
674
|
}
|
|
646
675
|
}
|
|
647
|
-
|
|
676
|
+
if (!hasFixedFormat || (hasFixedFormat && !this.autoCorrectParts)) {
|
|
648
677
|
processedSegmentCharsCount = 0;
|
|
649
678
|
current = "";
|
|
650
679
|
datePartText = "";
|
|
@@ -662,6 +691,11 @@ var DateObject = /** @class */ (function () {
|
|
|
662
691
|
}
|
|
663
692
|
processedSegmentCharsCount++;
|
|
664
693
|
}
|
|
694
|
+
else if (formatToTextLengthDiff > 0) {
|
|
695
|
+
if (datePartText.length + formatToTextLengthDiff < segmentLength) {
|
|
696
|
+
datePartText += rawInputValue[i] || "";
|
|
697
|
+
}
|
|
698
|
+
}
|
|
665
699
|
else {
|
|
666
700
|
datePartText += rawInputValue[i] || "";
|
|
667
701
|
}
|
|
@@ -671,24 +705,12 @@ var DateObject = /** @class */ (function () {
|
|
|
671
705
|
prefix += rawInputValue[i] || "";
|
|
672
706
|
}
|
|
673
707
|
else {
|
|
674
|
-
suffix += rawInputValue[i] || "";
|
|
708
|
+
suffix += rawInputValue[i - formatToTextLengthDiff] || "";
|
|
675
709
|
}
|
|
676
710
|
}
|
|
677
711
|
if (originalFormat.length < rawInputValue.length) {
|
|
678
712
|
datePartText += currentChar;
|
|
679
713
|
}
|
|
680
|
-
else if (!isDeleting && originalFormat.length > rawInputValue.length) {
|
|
681
|
-
var lengthDiff = originalFormat.length - rawInputValue.length;
|
|
682
|
-
var trimmedDatePartText = datePartText.substring(0, datePartText.length - lengthDiff);
|
|
683
|
-
if (trimmedDatePartText && trimmedDatePartText.length > 0) {
|
|
684
|
-
var originalDatePartText = datePartText;
|
|
685
|
-
datePartText = trimmedDatePartText;
|
|
686
|
-
if (prefix + datePartText + suffix !== rawInputValue) {
|
|
687
|
-
// move trimmed characters to the suffix
|
|
688
|
-
suffix = originalDatePartText.substring(datePartText.length) + suffix;
|
|
689
|
-
}
|
|
690
|
-
}
|
|
691
|
-
}
|
|
692
714
|
}
|
|
693
715
|
}
|
|
694
716
|
if (!isInCaretMode) {
|
|
@@ -722,8 +744,13 @@ var DateObject = /** @class */ (function () {
|
|
|
722
744
|
var dayPeriod = this.matchDayPeriod(currentChar, symbol);
|
|
723
745
|
var isZeroCurrentChar = currentChar === '0';
|
|
724
746
|
var leadingZero = this.leadingZero || {};
|
|
725
|
-
if (isZeroCurrentChar
|
|
726
|
-
|
|
747
|
+
if (isZeroCurrentChar) {
|
|
748
|
+
if (datePartText === "0") {
|
|
749
|
+
datePartText = current;
|
|
750
|
+
}
|
|
751
|
+
var valueNumber = utils_2.parseToInt(resetSegmentValue ?
|
|
752
|
+
currentChar :
|
|
753
|
+
(isInCaretMode ? datePartText : current) + currentChar);
|
|
727
754
|
if (valueNumber === 0 && !this.isAbbrMonth(dateParts.partMap, symbol)) {
|
|
728
755
|
this.incrementLeadingZero(symbol);
|
|
729
756
|
}
|
|
@@ -751,23 +778,15 @@ var DateObject = /** @class */ (function () {
|
|
|
751
778
|
isInCaretMode ?
|
|
752
779
|
datePartText :
|
|
753
780
|
(current.substring(i) + currentChar);
|
|
754
|
-
if (!this.autoCorrectParts) {
|
|
755
|
-
tryParse = false;
|
|
756
|
-
if (!isInCaretMode) {
|
|
757
|
-
// try to make an exact match as there will be only 1 attempt
|
|
758
|
-
middle = utils_1.unpadZero(middle);
|
|
759
|
-
middle = utils_1.padZero(segmentLength - middle.length) + middle;
|
|
760
|
-
}
|
|
761
|
-
}
|
|
762
|
-
if (isInCaretMode) {
|
|
763
|
-
// try to make an exact match as there will be only 1 attempt
|
|
781
|
+
if (isInCaretMode || !this.autoCorrectParts) {
|
|
764
782
|
tryParse = false;
|
|
765
783
|
middle = utils_1.unpadZero(middle);
|
|
784
|
+
middle = utils_1.padZero(segmentLength - middle.length) + middle;
|
|
766
785
|
}
|
|
767
786
|
var middleNumber = parseInt(middle, 10);
|
|
768
787
|
var candidateDateString = prefix + middle + suffix;
|
|
769
788
|
parsedDate = this.intl.parseDate(candidateDateString, this.format, this.localeId);
|
|
770
|
-
if (isInCaretMode && !
|
|
789
|
+
if (isInCaretMode && !utils_2.isValidDate(parsedDate)) {
|
|
771
790
|
// if part of the date is not available, e.g. "d"
|
|
772
791
|
// but an expanded format like "F" is used
|
|
773
792
|
// the element value can be "EEEE, February 1, 2022 3:04:05 AM"
|
|
@@ -777,7 +796,6 @@ var DateObject = /** @class */ (function () {
|
|
|
777
796
|
// as "EEEE, February..." is not parsable
|
|
778
797
|
if (this.autoCorrectParts) {
|
|
779
798
|
parsedDate = this.intl.parseDate(basePrefix + middle + baseSuffix, this.format, this.localeId);
|
|
780
|
-
datePartText = middle;
|
|
781
799
|
}
|
|
782
800
|
}
|
|
783
801
|
var isCurrentCharParsable = !isNaN(parseInt(currentChar, 10)) || (isInCaretMode && isDeleting && currentChar === "");
|
|
@@ -838,14 +856,12 @@ var DateObject = /** @class */ (function () {
|
|
|
838
856
|
}
|
|
839
857
|
if (isInCaretMode && switchToNext) {
|
|
840
858
|
if (symbol === "M") {
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
switchToNext = false;
|
|
848
|
-
}
|
|
859
|
+
var datePartValue = utils_2.parseToInt(datePartText);
|
|
860
|
+
if (datePartValue >= 2 || datePartText.length >= 2) {
|
|
861
|
+
switchToNext = true;
|
|
862
|
+
}
|
|
863
|
+
else {
|
|
864
|
+
switchToNext = false;
|
|
849
865
|
}
|
|
850
866
|
}
|
|
851
867
|
else {
|
|
@@ -878,9 +894,6 @@ var DateObject = /** @class */ (function () {
|
|
|
878
894
|
this.leadingZero = !this.isAbbrMonth(dateParts.partMap, symbol) ? (_b = {}, _b[symbol] = true, _b) : null;
|
|
879
895
|
this.setExisting(symbol, false);
|
|
880
896
|
}
|
|
881
|
-
if (isInCaretMode && datePartText.length > segmentLength) {
|
|
882
|
-
return utils_2.extend(parseResult, { value: null, switchToNext: false });
|
|
883
|
-
}
|
|
884
897
|
if (!this.autoCorrectParts) {
|
|
885
898
|
var datePartValue = void 0;
|
|
886
899
|
var textToParse = isInCaretMode ? datePartText : middle;
|
|
@@ -891,20 +904,146 @@ var DateObject = /** @class */ (function () {
|
|
|
891
904
|
return utils_2.extend(parseResult, { value: null, switchToNext: false });
|
|
892
905
|
}
|
|
893
906
|
datePartValue = symbol === "M" ?
|
|
894
|
-
|
|
907
|
+
parsedValue - JS_MONTH_OFFSET :
|
|
895
908
|
parsedValue;
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
this.
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
909
|
+
var isMonth = symbol === "M";
|
|
910
|
+
var isDay = symbol === "d";
|
|
911
|
+
var newValue = kendo_date_math_1.cloneDate(this._value);
|
|
912
|
+
var invalidDateParts = this._partiallyInvalidDate.invalidDateParts || {};
|
|
913
|
+
var year = invalidDateParts.y.value || newValue.getFullYear();
|
|
914
|
+
/* tslint:disable:no-shadowed-variable */
|
|
915
|
+
var month_1 = isMonth ? datePartValue : invalidDateParts.M.value || newValue.getMonth();
|
|
916
|
+
/* tslint:enable:no-shadowed-variable */
|
|
917
|
+
var day = isDay ? datePartValue : invalidDateParts.d.value || invalidDateParts.E.value || newValue.getDate();
|
|
918
|
+
var hour = invalidDateParts.h.value || invalidDateParts.H.value || newValue.getHours();
|
|
919
|
+
var minutes = invalidDateParts.m.value || newValue.getMinutes();
|
|
920
|
+
var seconds = invalidDateParts.s.value || newValue.getSeconds();
|
|
921
|
+
var milliseconds = invalidDateParts.S.value || newValue.getMilliseconds();
|
|
922
|
+
var dateCandidate = kendo_date_math_1.createDate(year, month_1, day, hour, minutes, seconds, milliseconds);
|
|
923
|
+
var dateCandidateExists = utils_2.areDatePartsEqualTo(dateCandidate, year, month_1, day, hour, minutes, seconds, milliseconds);
|
|
924
|
+
var newValueCandidate = isMonth || isDay ?
|
|
925
|
+
this.modifyDateSymbolWithValue(newValue, symbol, isMonth ? month_1 : day) :
|
|
926
|
+
null;
|
|
927
|
+
var invalidDateFound = false;
|
|
928
|
+
if (isMonth && newValueCandidate) {
|
|
929
|
+
if (newValueCandidate.getMonth() === month_1) {
|
|
930
|
+
if (this.getExisting("d")) {
|
|
931
|
+
if (dateCandidateExists) {
|
|
932
|
+
newValue = kendo_date_math_1.cloneDate(dateCandidate);
|
|
933
|
+
this.resetInvalidDateSymbol(symbol);
|
|
934
|
+
}
|
|
935
|
+
else {
|
|
936
|
+
invalidDateFound = true;
|
|
937
|
+
this.setInvalidDatePart(symbol, {
|
|
938
|
+
value: month_1,
|
|
939
|
+
date: kendo_date_math_1.cloneDate(newValueCandidate),
|
|
940
|
+
// startDateOffset: offset,
|
|
941
|
+
startDate: kendo_date_math_1.cloneDate(this.value)
|
|
942
|
+
});
|
|
943
|
+
this.setExisting(symbol, false);
|
|
944
|
+
}
|
|
945
|
+
}
|
|
946
|
+
else if (dateCandidateExists) {
|
|
947
|
+
this.resetInvalidDateSymbol(symbol);
|
|
948
|
+
newValue = kendo_date_math_1.cloneDate(dateCandidate);
|
|
949
|
+
if (this.getExisting("M") && this.getExisting("y")) {
|
|
950
|
+
// changing from 28/Feb to 29/Feb to 29/March
|
|
951
|
+
this.setExisting("d", true);
|
|
952
|
+
this.resetInvalidDateSymbol("d");
|
|
953
|
+
}
|
|
954
|
+
}
|
|
955
|
+
else {
|
|
956
|
+
this.resetInvalidDateSymbol(symbol);
|
|
957
|
+
newValue = kendo_date_math_1.cloneDate(newValueCandidate);
|
|
958
|
+
}
|
|
959
|
+
}
|
|
960
|
+
else {
|
|
961
|
+
invalidDateFound = true;
|
|
962
|
+
this.setInvalidDatePart(symbol, {
|
|
963
|
+
value: month_1,
|
|
964
|
+
date: kendo_date_math_1.cloneDate(newValueCandidate),
|
|
965
|
+
// startDateOffset: offset,
|
|
966
|
+
startDate: kendo_date_math_1.cloneDate(this.value)
|
|
967
|
+
});
|
|
968
|
+
this.setExisting(symbol, false);
|
|
969
|
+
}
|
|
970
|
+
}
|
|
971
|
+
else if (isDay && newValueCandidate) {
|
|
972
|
+
if (newValueCandidate.getDate() === day) {
|
|
973
|
+
if (this.getExisting("M")) {
|
|
974
|
+
if (dateCandidateExists) {
|
|
975
|
+
newValue = kendo_date_math_1.cloneDate(dateCandidate);
|
|
976
|
+
this.resetInvalidDateSymbol(symbol);
|
|
977
|
+
}
|
|
978
|
+
else {
|
|
979
|
+
invalidDateFound = true;
|
|
980
|
+
this.setInvalidDatePart(symbol, {
|
|
981
|
+
value: day,
|
|
982
|
+
date: kendo_date_math_1.cloneDate(newValueCandidate),
|
|
983
|
+
// startDateOffset: offset,
|
|
984
|
+
startDate: kendo_date_math_1.cloneDate(this.value)
|
|
985
|
+
});
|
|
986
|
+
this.setExisting(symbol, false);
|
|
987
|
+
}
|
|
988
|
+
}
|
|
989
|
+
else if (dateCandidateExists) {
|
|
990
|
+
newValue = kendo_date_math_1.cloneDate(dateCandidate);
|
|
991
|
+
this.resetInvalidDateSymbol(symbol);
|
|
992
|
+
if (this.getExisting("d") && this.getExisting("y")) {
|
|
993
|
+
// changing from 31/Jan to 31/Feb to 28/Feb
|
|
994
|
+
this.setExisting("M", true);
|
|
995
|
+
this.resetInvalidDateSymbol("M");
|
|
996
|
+
}
|
|
997
|
+
}
|
|
998
|
+
else {
|
|
999
|
+
this.resetInvalidDateSymbol(symbol);
|
|
1000
|
+
newValue = kendo_date_math_1.cloneDate(newValueCandidate);
|
|
1001
|
+
}
|
|
1002
|
+
}
|
|
1003
|
+
else {
|
|
1004
|
+
invalidDateFound = true;
|
|
1005
|
+
this.setInvalidDatePart(symbol, {
|
|
1006
|
+
value: day,
|
|
1007
|
+
date: kendo_date_math_1.cloneDate(this.value),
|
|
1008
|
+
// startDateOffset: offset,
|
|
1009
|
+
startDate: kendo_date_math_1.cloneDate(this.value)
|
|
1010
|
+
});
|
|
1011
|
+
this.setExisting(symbol, false);
|
|
1012
|
+
}
|
|
1013
|
+
}
|
|
1014
|
+
if (!invalidDateFound) {
|
|
1015
|
+
this.setExisting(symbol, true);
|
|
1016
|
+
if (isInCaretMode && !utils_2.isValidDate(parsedDate)) {
|
|
1017
|
+
var valueCandidate = this.intl.parseDate(basePrefix + middle + baseSuffix, this.format, this.localeId);
|
|
1018
|
+
if (utils_2.isValidDate(valueCandidate)) {
|
|
1019
|
+
this._value = valueCandidate;
|
|
1020
|
+
}
|
|
1021
|
+
}
|
|
1022
|
+
else {
|
|
1023
|
+
this._value = newValue;
|
|
1024
|
+
}
|
|
1025
|
+
if (this.getValue()) {
|
|
1026
|
+
this.resetInvalidDate();
|
|
1027
|
+
}
|
|
1028
|
+
}
|
|
1029
|
+
var switchToNext = false;
|
|
1030
|
+
if (symbol === "M") {
|
|
1031
|
+
if (parsedValue >= 2 || textToParse.length >= 2) {
|
|
1032
|
+
switchToNext = true;
|
|
1033
|
+
}
|
|
1034
|
+
else {
|
|
1035
|
+
switchToNext = false;
|
|
1036
|
+
}
|
|
1037
|
+
}
|
|
1038
|
+
else {
|
|
1039
|
+
switchToNext = hasFixedFormat ?
|
|
1040
|
+
textToParse.length === segmentLength :
|
|
1041
|
+
textToParse.length > segmentLength;
|
|
1042
|
+
}
|
|
904
1043
|
return utils_2.extend(parseResult, {
|
|
905
1044
|
value: null,
|
|
906
|
-
switchToNext:
|
|
907
|
-
hasInvalidDatePart:
|
|
1045
|
+
switchToNext: switchToNext,
|
|
1046
|
+
hasInvalidDatePart: invalidDateFound
|
|
908
1047
|
});
|
|
909
1048
|
}
|
|
910
1049
|
}
|
|
@@ -927,6 +1066,12 @@ var DateObject = /** @class */ (function () {
|
|
|
927
1066
|
DateObject.prototype.setLeadingZero = function (leadingZero) {
|
|
928
1067
|
this.leadingZero = leadingZero;
|
|
929
1068
|
};
|
|
1069
|
+
/**
|
|
1070
|
+
* @hidden
|
|
1071
|
+
*/
|
|
1072
|
+
DateObject.prototype.getLeadingZero = function () {
|
|
1073
|
+
return this.leadingZero || {};
|
|
1074
|
+
};
|
|
930
1075
|
/**
|
|
931
1076
|
* @hidden
|
|
932
1077
|
*/
|
|
@@ -1010,7 +1155,6 @@ var DateObject = /** @class */ (function () {
|
|
|
1010
1155
|
var dateFormatParts = this.intl.splitDateFormat(this.format, this.localeId);
|
|
1011
1156
|
for (var i = 0; i < dateFormatParts.length; i++) {
|
|
1012
1157
|
if (dateFormatParts[i].type === 'month' && dateFormatParts[i].names) {
|
|
1013
|
-
// return this.intl.dateFormatNames(dateFormatParts[i].names);
|
|
1014
1158
|
return this.intl.dateFormatNames(locale, dateFormatParts[i].names);
|
|
1015
1159
|
}
|
|
1016
1160
|
}
|
|
@@ -1222,15 +1366,8 @@ var DateObject = /** @class */ (function () {
|
|
|
1222
1366
|
};
|
|
1223
1367
|
DateObject.prototype.setInvalidDatePart = function (symbol, _a) {
|
|
1224
1368
|
var _b = _a.value, value = _b === void 0 ? null : _b, _c = _a.date, date = _c === void 0 ? null : _c, _d = _a.startDateOffset, startDateOffset = _d === void 0 ? 0 : _d, _e = _a.startDate, startDate = _e === void 0 ? null : _e;
|
|
1225
|
-
var clampedValue = value;
|
|
1226
|
-
if (symbol === "d") {
|
|
1227
|
-
clampedValue = utils_2.clamp(utils_2.isPresent(value) ? value : 1, 1, 31);
|
|
1228
|
-
}
|
|
1229
|
-
else if (symbol === "M") {
|
|
1230
|
-
clampedValue = utils_2.clamp(utils_2.isPresent(value) ? value : 0, 0, 11);
|
|
1231
|
-
}
|
|
1232
1369
|
if (this._partiallyInvalidDate.invalidDateParts[symbol]) {
|
|
1233
|
-
this._partiallyInvalidDate.invalidDateParts[symbol].value =
|
|
1370
|
+
this._partiallyInvalidDate.invalidDateParts[symbol].value = value;
|
|
1234
1371
|
this._partiallyInvalidDate.invalidDateParts[symbol].date = date;
|
|
1235
1372
|
this._partiallyInvalidDate.invalidDateParts[symbol].startDateOffset = startDateOffset;
|
|
1236
1373
|
this._partiallyInvalidDate.startDate = startDate;
|
|
@@ -33,6 +33,7 @@ var CHANGE = "change";
|
|
|
33
33
|
var defaultDateInputOptions = {
|
|
34
34
|
format: "d",
|
|
35
35
|
allowNulls: false,
|
|
36
|
+
hasPlaceholder: false,
|
|
36
37
|
placeholder: null,
|
|
37
38
|
cycleTime: true,
|
|
38
39
|
locale: null,
|
|
@@ -305,6 +306,24 @@ var DateInput = /** @class */ (function (_super) {
|
|
|
305
306
|
isInCaretMode: hasCaret,
|
|
306
307
|
keyEvent: this.keyDownEvent
|
|
307
308
|
});
|
|
309
|
+
var currentFormatChar = this.formatStateOnKeyDown.format[this.formatStateOnKeyDown.selectionStart] || "";
|
|
310
|
+
if (this.options.allowCaretMode && hasCaret && this.currentFormat.length !== this.elementValue.length) {
|
|
311
|
+
if (currentFormatChar &&
|
|
312
|
+
currentFormatChar.length > 0 &&
|
|
313
|
+
currentFormatChar !== constants_1.Constants.formatSeparator) {
|
|
314
|
+
if (!diff || diff.length === 0) {
|
|
315
|
+
diff = [];
|
|
316
|
+
diff[0][0] = currentFormatChar;
|
|
317
|
+
diff[0][1] = e.data || "";
|
|
318
|
+
}
|
|
319
|
+
else if (diff[0] && diff[0][0] !== constants_1.Constants.formatSeparator) {
|
|
320
|
+
if (diff[0][0] !== currentFormatChar) {
|
|
321
|
+
diff[0][0] = currentFormatChar;
|
|
322
|
+
diff[0][1] = e.data || "";
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
}
|
|
308
327
|
if (hasCaret && (!diff || diff.length === 0)) {
|
|
309
328
|
this.restorePreviousInputEventState();
|
|
310
329
|
return;
|
|
@@ -377,10 +396,30 @@ var DateInput = /** @class */ (function (_super) {
|
|
|
377
396
|
if (switchPart) {
|
|
378
397
|
this.switchDateSegment(1);
|
|
379
398
|
}
|
|
399
|
+
else {
|
|
400
|
+
if (this.options.format.length !== this.currentFormat.length &&
|
|
401
|
+
currentFormatChar && currentFormatChar !== "y") {
|
|
402
|
+
var elementValueLength = this.elementValue.length;
|
|
403
|
+
this.forceUpdate();
|
|
404
|
+
var selectionOffset = this.elementValue.length - elementValueLength;
|
|
405
|
+
this.setSelection({
|
|
406
|
+
start: currentSelection.start + selectionOffset,
|
|
407
|
+
end: currentSelection.start + selectionOffset
|
|
408
|
+
});
|
|
409
|
+
}
|
|
410
|
+
}
|
|
380
411
|
}
|
|
381
412
|
else {
|
|
382
|
-
if (lastParseResultHasNoValue
|
|
383
|
-
this.
|
|
413
|
+
if (lastParseResultHasNoValue) {
|
|
414
|
+
var hasLeadingZero = this.dateObject.getLeadingZero()[currentFormatChar];
|
|
415
|
+
if (switchPart) {
|
|
416
|
+
this.switchDateSegment(1);
|
|
417
|
+
}
|
|
418
|
+
else if (e.data === "0" && hasLeadingZero) {
|
|
419
|
+
}
|
|
420
|
+
else {
|
|
421
|
+
this.restorePreviousInputEventState();
|
|
422
|
+
}
|
|
384
423
|
}
|
|
385
424
|
}
|
|
386
425
|
}
|
|
@@ -405,7 +444,10 @@ var DateInput = /** @class */ (function (_super) {
|
|
|
405
444
|
}
|
|
406
445
|
}
|
|
407
446
|
else {
|
|
408
|
-
|
|
447
|
+
var hasLeadingZero = this.dateObject.getLeadingZero()[currentFormatChar];
|
|
448
|
+
if (e.data === "0" && hasLeadingZero) {
|
|
449
|
+
}
|
|
450
|
+
else if (!hasInvalidDatePart) {
|
|
409
451
|
this.restorePreviousInputEventState();
|
|
410
452
|
}
|
|
411
453
|
}
|
|
@@ -469,9 +511,14 @@ var DateInput = /** @class */ (function (_super) {
|
|
|
469
511
|
if (this.triggerKeyDown({ event: e })) {
|
|
470
512
|
return;
|
|
471
513
|
}
|
|
514
|
+
var _a = this.selection, start = _a.start, end = _a.end;
|
|
472
515
|
this.keyDownEvent = e;
|
|
473
516
|
this.previousElementValue = this.element.value;
|
|
474
|
-
|
|
517
|
+
this.formatStateOnKeyDown = {
|
|
518
|
+
format: this.currentFormat,
|
|
519
|
+
selectionStart: start,
|
|
520
|
+
selectionEnd: end
|
|
521
|
+
};
|
|
475
522
|
this.previousElementSelection = { start: start, end: end };
|
|
476
523
|
var autoSwitchKeys = (this.options.autoSwitchKeys || [])
|
|
477
524
|
.map(function (x) { return x.toString().toLowerCase().trim(); });
|
|
@@ -741,11 +788,13 @@ var DateInput = /** @class */ (function (_super) {
|
|
|
741
788
|
return;
|
|
742
789
|
}
|
|
743
790
|
}
|
|
791
|
+
this.interactionMode = interaction_mode_1.DateInputInteractionMode.None;
|
|
744
792
|
var _a = this.selection, selectionStart = _a.start, selectionEnd = _a.end;
|
|
745
793
|
if (selectionStart < selectionEnd &&
|
|
746
794
|
this.currentFormat[selectionStart] !== this.currentFormat[selectionEnd - 1]) {
|
|
747
795
|
this.setSelection(this.selectionByIndex(offset > 0 ? selectionStart : selectionEnd - 1));
|
|
748
796
|
this.resetSegmentValue = true;
|
|
797
|
+
this.interactionMode = interaction_mode_1.DateInputInteractionMode.None;
|
|
749
798
|
return;
|
|
750
799
|
}
|
|
751
800
|
var previousFormatSymbol = this.currentFormat[selectionStart];
|
|
@@ -776,6 +825,7 @@ var DateInput = /** @class */ (function (_super) {
|
|
|
776
825
|
this.setSelection({ start: a, end: b });
|
|
777
826
|
this.resetSegmentValue = true;
|
|
778
827
|
}
|
|
828
|
+
this.interactionMode = interaction_mode_1.DateInputInteractionMode.None;
|
|
779
829
|
};
|
|
780
830
|
DateInput.prototype.modifyDateSegmentValue = function (offset, symbol, event) {
|
|
781
831
|
if (symbol === void 0) { symbol = ""; }
|
|
@@ -977,13 +1027,14 @@ var DateInput = /** @class */ (function (_super) {
|
|
|
977
1027
|
var _a = this.dateObject.getTextAndFormat(format), currentText = _a.text, currentFormat = _a.format;
|
|
978
1028
|
this.currentFormat = currentFormat;
|
|
979
1029
|
this.currentText = currentText;
|
|
1030
|
+
var hasPlaceholder = this.options.hasPlaceholder || utils_2.isPresent(this.options.placeholder);
|
|
980
1031
|
var showPlaceholder = !this.isActive &&
|
|
981
|
-
|
|
1032
|
+
hasPlaceholder &&
|
|
982
1033
|
!this.dateObject.hasValue();
|
|
983
|
-
if (utils_2.isPresent(this.options.placeholder)) {
|
|
1034
|
+
if (hasPlaceholder && utils_2.isPresent(this.options.placeholder)) {
|
|
984
1035
|
element.placeholder = this.options.placeholder;
|
|
985
1036
|
}
|
|
986
|
-
var newElementValue =
|
|
1037
|
+
var newElementValue = showPlaceholder ? "" : currentText;
|
|
987
1038
|
this.previousElementValue = this.elementValue;
|
|
988
1039
|
this.setElementValue(newElementValue);
|
|
989
1040
|
if (this.isActive && !this.options.allowCaretMode && this.options.selectNearestSegmentOnFocus) {
|