@progress/kendo-dateinputs-common 0.2.0-dev.202301061353 → 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.
- package/CODEOWNERS +2 -0
- package/dist/cdn/js/kendo-dateinputs-common.js +1 -1
- package/dist/cdn/main.js +1 -1
- package/dist/es/common/dateobject.js +280 -161
- package/dist/es/common/utils.js +1 -1
- package/dist/es/dateinput/dateinput.js +115 -46
- package/dist/es/dateinput/utils.js +10 -14
- package/dist/es2015/common/dateobject.js +280 -161
- package/dist/es2015/common/utils.js +1 -1
- package/dist/es2015/dateinput/dateinput.js +114 -45
- package/dist/es2015/dateinput/utils.js +10 -14
- package/dist/npm/common/dateobject.d.ts +6 -1
- package/dist/npm/common/dateobject.js +279 -160
- package/dist/npm/common/utils.d.ts +1 -1
- package/dist/npm/common/utils.js +1 -1
- package/dist/npm/dateinput/dateinput.d.ts +13 -2
- package/dist/npm/dateinput/dateinput.js +114 -45
- package/dist/npm/dateinput/utils.js +10 -14
- package/dist/systemjs/kendo-dateinputs-common.js +1 -1
- package/global-setup.js +4 -0
- package/jest.config.js +9 -0
- package/package.json +4 -4
|
@@ -4,7 +4,7 @@ import { DateObject } from '../common/dateobject';
|
|
|
4
4
|
import { approximateStringMatching } from './utils';
|
|
5
5
|
import { KeyCode } from '../common/keycode';
|
|
6
6
|
import { Key } from '../common/key';
|
|
7
|
-
import { extend, isPresent, isDocumentAvailable, millisecondDigitsInFormat, millisecondStepFor,
|
|
7
|
+
import { extend, isPresent, isDocumentAvailable, millisecondDigitsInFormat, millisecondStepFor, isValidDate } from '../common/utils';
|
|
8
8
|
import { Observable } from '../common/observable';
|
|
9
9
|
import { DateInputInteractionMode } from './interaction-mode';
|
|
10
10
|
import { isEqual, cloneDate } from '@progress/kendo-date-math';
|
|
@@ -74,7 +74,7 @@ var DateInput = /** @class */ (function (_super) {
|
|
|
74
74
|
_this.currentText = '';
|
|
75
75
|
_this.currentFormat = '';
|
|
76
76
|
_this.interactionMode = DateInputInteractionMode.None;
|
|
77
|
-
_this.
|
|
77
|
+
_this.previousElementSelection = { start: 0, end: 0 };
|
|
78
78
|
_this.init(element, options);
|
|
79
79
|
return _this;
|
|
80
80
|
}
|
|
@@ -86,8 +86,8 @@ var DateInput = /** @class */ (function (_super) {
|
|
|
86
86
|
configurable: true
|
|
87
87
|
});
|
|
88
88
|
DateInput.prototype.init = function (element, options) {
|
|
89
|
-
var dateValue =
|
|
90
|
-
if (!
|
|
89
|
+
var dateValue = isValidDate(this.options.value) ? cloneDate(this.options.value) : new Date(options.formattedValue);
|
|
90
|
+
if (!isValidDate(dateValue)) {
|
|
91
91
|
dateValue = null;
|
|
92
92
|
}
|
|
93
93
|
this.element = element;
|
|
@@ -100,6 +100,7 @@ var DateInput = /** @class */ (function (_super) {
|
|
|
100
100
|
this.setTextAndFormat();
|
|
101
101
|
this.bindEvents();
|
|
102
102
|
this.resetSegmentValue = true;
|
|
103
|
+
this.interactionMode = DateInputInteractionMode.None;
|
|
103
104
|
this.forceUpdate();
|
|
104
105
|
};
|
|
105
106
|
DateInput.prototype.destroy = function () {
|
|
@@ -155,8 +156,8 @@ var DateInput = /** @class */ (function (_super) {
|
|
|
155
156
|
if (refresh === void 0) { refresh = false; }
|
|
156
157
|
this.options = extend(this.options, options);
|
|
157
158
|
if (refresh) {
|
|
158
|
-
this.
|
|
159
|
-
this.init(this.element, options);
|
|
159
|
+
this.unbindEvents();
|
|
160
|
+
this.init(this.element, this.options);
|
|
160
161
|
}
|
|
161
162
|
};
|
|
162
163
|
/**
|
|
@@ -272,33 +273,48 @@ var DateInput = /** @class */ (function (_super) {
|
|
|
272
273
|
var hasCaret = this.isInCaretMode();
|
|
273
274
|
if (hasCaret && this.keyDownEvent.key === Key.SPACE) {
|
|
274
275
|
// do not allow custom "holes" in the date segments
|
|
275
|
-
this.
|
|
276
|
+
this.restorePreviousInputEventState();
|
|
276
277
|
return;
|
|
277
278
|
}
|
|
278
279
|
var oldDateObjectValue = this.dateObject && this.dateObject.getValue();
|
|
279
280
|
var _a = this.dateObject.getTextAndFormat(), currentText = _a.text, currentFormat = _a.format;
|
|
280
281
|
this.currentFormat = currentFormat;
|
|
281
|
-
var text =
|
|
282
|
+
var text = "";
|
|
283
|
+
if (hasCaret) {
|
|
284
|
+
if (isBackspaceKey || isDeleteKey) {
|
|
285
|
+
text = this.previousElementValue;
|
|
286
|
+
}
|
|
287
|
+
else if (originalInteractionMode === DateInputInteractionMode.Caret) {
|
|
288
|
+
text = this.previousElementValue;
|
|
289
|
+
}
|
|
290
|
+
else {
|
|
291
|
+
text = currentText;
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
else {
|
|
295
|
+
text = currentText;
|
|
296
|
+
}
|
|
297
|
+
var newText = this.elementValue;
|
|
282
298
|
var diff = approximateStringMatching({
|
|
283
299
|
oldText: text,
|
|
284
|
-
newText:
|
|
300
|
+
newText: newText,
|
|
285
301
|
formatPattern: this.currentFormat,
|
|
286
302
|
selectionStart: this.selection.start,
|
|
287
303
|
isInCaretMode: hasCaret,
|
|
288
304
|
keyEvent: this.keyDownEvent
|
|
289
305
|
});
|
|
290
306
|
if (hasCaret && (!diff || diff.length === 0)) {
|
|
291
|
-
this.
|
|
307
|
+
this.restorePreviousInputEventState();
|
|
292
308
|
return;
|
|
293
309
|
}
|
|
294
310
|
else if (hasCaret && diff.length === 1) {
|
|
295
311
|
if (!diff[0] || !diff[0][0]) {
|
|
296
|
-
this.
|
|
312
|
+
this.restorePreviousInputEventState();
|
|
297
313
|
return;
|
|
298
314
|
}
|
|
299
315
|
else if (hasCaret && diff[0] &&
|
|
300
316
|
(diff[0][0] === Constants.formatSeparator || diff[0][1] === Constants.formatSeparator)) {
|
|
301
|
-
this.
|
|
317
|
+
this.restorePreviousInputEventState();
|
|
302
318
|
return;
|
|
303
319
|
}
|
|
304
320
|
}
|
|
@@ -313,7 +329,8 @@ var DateInput = /** @class */ (function (_super) {
|
|
|
313
329
|
resetSegmentValue: this.resetSegmentValue,
|
|
314
330
|
cycleSegmentValue: !this.isInCaretMode(),
|
|
315
331
|
rawTextValue: this.element.value,
|
|
316
|
-
isDeleting: isBackspaceKey || isDeleteKey
|
|
332
|
+
isDeleting: isBackspaceKey || isDeleteKey,
|
|
333
|
+
originalFormat: this.currentFormat
|
|
317
334
|
});
|
|
318
335
|
parsePartsResults.push(parsePartResult);
|
|
319
336
|
switchPart = parsePartResult.switchToNext;
|
|
@@ -351,6 +368,25 @@ var DateInput = /** @class */ (function (_super) {
|
|
|
351
368
|
}
|
|
352
369
|
}
|
|
353
370
|
}
|
|
371
|
+
else if (hasCaret) {
|
|
372
|
+
if (this.options.format.length !== this.currentFormat.length) {
|
|
373
|
+
if (hasDateValueChanged && isPresent(this.dateObject.getValue())) {
|
|
374
|
+
if (switchPart) {
|
|
375
|
+
this.switchDateSegment(1);
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
else {
|
|
380
|
+
if (hasDateValueChanged) {
|
|
381
|
+
if (lastParseResultHasNoValue) {
|
|
382
|
+
this.restorePreviousInputEventState();
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
else {
|
|
386
|
+
this.restorePreviousInputEventState();
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
}
|
|
354
390
|
}
|
|
355
391
|
if (!switchPart && hasCaret && !isBackspaceKey && !isDeleteKey && !resetPart && lastParseResultHasNoValue) {
|
|
356
392
|
if (hasDateValueChanged) {
|
|
@@ -367,10 +403,13 @@ var DateInput = /** @class */ (function (_super) {
|
|
|
367
403
|
this.setSelection(this.selectionBySymbol(symbolForSelection));
|
|
368
404
|
}
|
|
369
405
|
else {
|
|
370
|
-
this.
|
|
406
|
+
this.restorePreviousInputEventState();
|
|
371
407
|
}
|
|
372
408
|
}
|
|
373
409
|
}
|
|
410
|
+
else {
|
|
411
|
+
this.restorePreviousInputEventState();
|
|
412
|
+
}
|
|
374
413
|
}
|
|
375
414
|
else if (this.options.autoSwitchParts && (switchPart || navigationOnly)) {
|
|
376
415
|
if (!hasCaret) {
|
|
@@ -382,6 +421,12 @@ var DateInput = /** @class */ (function (_super) {
|
|
|
382
421
|
event: e
|
|
383
422
|
});
|
|
384
423
|
this.triggerInputEnd({ event: e });
|
|
424
|
+
if (hasCaret) {
|
|
425
|
+
// a format like "F" can dynamically change the resolved format pattern based on the value, e.g.
|
|
426
|
+
// "Tuesday, February 1, 2022 3:04:05 AM" becomes
|
|
427
|
+
// "Wednesday, February 2, 2022 3:04:05 AM" giving a diff of 2 ("Tuesday".length - "Wednesday".length)
|
|
428
|
+
this.setTextAndFormat();
|
|
429
|
+
}
|
|
385
430
|
};
|
|
386
431
|
/**
|
|
387
432
|
* @hidden
|
|
@@ -427,6 +472,8 @@ var DateInput = /** @class */ (function (_super) {
|
|
|
427
472
|
}
|
|
428
473
|
this.keyDownEvent = e;
|
|
429
474
|
this.previousElementValue = this.element.value;
|
|
475
|
+
var _a = this.selection, start = _a.start, end = _a.end;
|
|
476
|
+
this.previousElementSelection = { start: start, end: end };
|
|
430
477
|
var autoSwitchKeys = (this.options.autoSwitchKeys || [])
|
|
431
478
|
.map(function (x) { return x.toString().toLowerCase().trim(); });
|
|
432
479
|
if (autoSwitchKeys.indexOf(e.keyCode.toString()) >= 0 ||
|
|
@@ -436,7 +483,7 @@ var DateInput = /** @class */ (function (_super) {
|
|
|
436
483
|
autoSwitchKeys.indexOf(KeyCode.TAB) >= 0 ||
|
|
437
484
|
autoSwitchKeys.indexOf(KeyCode.TAB.toString()) >= 0;
|
|
438
485
|
if (isTabKey) {
|
|
439
|
-
var
|
|
486
|
+
var _b = this.selection, selectionStart = _b.start, selectionEnd = _b.end;
|
|
440
487
|
if (e.shiftKey && isTabKey) {
|
|
441
488
|
this.switchDateSegment(-1);
|
|
442
489
|
}
|
|
@@ -631,6 +678,14 @@ var DateInput = /** @class */ (function (_super) {
|
|
|
631
678
|
if (start < 0) {
|
|
632
679
|
start = 0;
|
|
633
680
|
}
|
|
681
|
+
if (!this.options.autoCorrectParts && this.currentFormat.length !== this.currentText.length) {
|
|
682
|
+
if (this.currentFormat.length < this.currentText.length) {
|
|
683
|
+
end += this.currentText.length - this.currentFormat.length;
|
|
684
|
+
}
|
|
685
|
+
else {
|
|
686
|
+
end = Math.max(0, end - (this.currentFormat.length - this.currentText.length));
|
|
687
|
+
}
|
|
688
|
+
}
|
|
634
689
|
return { start: start, end: end };
|
|
635
690
|
};
|
|
636
691
|
/**
|
|
@@ -654,24 +709,36 @@ var DateInput = /** @class */ (function (_super) {
|
|
|
654
709
|
var selection = this.selection;
|
|
655
710
|
if (this.isInCaretMode()) {
|
|
656
711
|
var start = selection.start;
|
|
657
|
-
var
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
712
|
+
var currentSymbol = this.currentFormat[start - (this.elementValue.length - this.currentFormat.length)];
|
|
713
|
+
var symbol = "";
|
|
714
|
+
var symbolCandidate = "";
|
|
715
|
+
if (offset < 0) {
|
|
716
|
+
for (var i = 0; i < start + offset; i++) {
|
|
717
|
+
symbolCandidate = this.currentFormat[i];
|
|
718
|
+
if (symbolCandidate !== Constants.formatSeparator &&
|
|
719
|
+
symbolCandidate !== currentSymbol) {
|
|
720
|
+
start = i;
|
|
721
|
+
symbol = symbolCandidate;
|
|
722
|
+
break;
|
|
723
|
+
}
|
|
663
724
|
}
|
|
664
725
|
}
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
726
|
+
else {
|
|
727
|
+
for (var i = start + offset; i < this.currentFormat.length; i++) {
|
|
728
|
+
symbolCandidate = this.currentFormat[i];
|
|
729
|
+
if (symbolCandidate !== Constants.formatSeparator &&
|
|
730
|
+
symbolCandidate !== currentSymbol) {
|
|
731
|
+
start = i;
|
|
732
|
+
symbol = symbolCandidate;
|
|
733
|
+
break;
|
|
734
|
+
}
|
|
670
735
|
}
|
|
671
736
|
}
|
|
672
737
|
if (symbol) {
|
|
673
738
|
this.forceUpdate();
|
|
674
739
|
this.setSelection(this.selectionBySymbol(symbol));
|
|
740
|
+
this.interactionMode = DateInputInteractionMode.Selection;
|
|
741
|
+
return;
|
|
675
742
|
}
|
|
676
743
|
}
|
|
677
744
|
var _a = this.selection, selectionStart = _a.start, selectionEnd = _a.end;
|
|
@@ -838,7 +905,6 @@ var DateInput = /** @class */ (function (_super) {
|
|
|
838
905
|
* @hidden
|
|
839
906
|
*/
|
|
840
907
|
DateInput.prototype.setElementValue = function (value) {
|
|
841
|
-
this.previousElementValue = this.element.value;
|
|
842
908
|
this.element.value = value;
|
|
843
909
|
};
|
|
844
910
|
/**
|
|
@@ -874,23 +940,25 @@ var DateInput = /** @class */ (function (_super) {
|
|
|
874
940
|
}
|
|
875
941
|
/* eslint-enable no-fallthrough */
|
|
876
942
|
};
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
}
|
|
889
|
-
else {
|
|
890
|
-
selectionOffset = -1;
|
|
891
|
-
}
|
|
943
|
+
/**
|
|
944
|
+
* @hidden
|
|
945
|
+
*/
|
|
946
|
+
DateInput.prototype.restorePreviousInputEventState = function () {
|
|
947
|
+
this.restorePreviousElementValue();
|
|
948
|
+
this.restorePreviousElementSelection();
|
|
949
|
+
};
|
|
950
|
+
/**
|
|
951
|
+
* @hidden
|
|
952
|
+
*/
|
|
953
|
+
DateInput.prototype.restorePreviousElementValue = function () {
|
|
892
954
|
this.setElementValue(this.previousElementValue || '');
|
|
893
|
-
|
|
955
|
+
};
|
|
956
|
+
/**
|
|
957
|
+
* @hidden
|
|
958
|
+
*/
|
|
959
|
+
DateInput.prototype.restorePreviousElementSelection = function () {
|
|
960
|
+
var _a = this.previousElementSelection, start = _a.start, end = _a.end;
|
|
961
|
+
this.setSelection({ start: start || 0, end: end || 0 });
|
|
894
962
|
};
|
|
895
963
|
DateInput.prototype.writeValue = function (value) {
|
|
896
964
|
this.verifyValue(value);
|
|
@@ -898,7 +966,7 @@ var DateInput = /** @class */ (function (_super) {
|
|
|
898
966
|
this.refreshElementValue();
|
|
899
967
|
};
|
|
900
968
|
DateInput.prototype.verifyValue = function (value) {
|
|
901
|
-
if (value && !
|
|
969
|
+
if (value && !isValidDate(value)) {
|
|
902
970
|
throw new Error("The 'value' should be a valid JavaScript Date instance.");
|
|
903
971
|
}
|
|
904
972
|
};
|
|
@@ -916,6 +984,7 @@ var DateInput = /** @class */ (function (_super) {
|
|
|
916
984
|
element.placeholder = this.options.placeholder;
|
|
917
985
|
}
|
|
918
986
|
var newElementValue = !showPlaceholder ? currentText : "";
|
|
987
|
+
this.previousElementValue = this.elementValue;
|
|
919
988
|
this.setElementValue(newElementValue);
|
|
920
989
|
if (this.isActive && !this.options.allowCaretMode && this.options.selectNearestSegmentOnFocus) {
|
|
921
990
|
this.selectNearestSegment(start);
|
|
@@ -999,10 +1068,10 @@ var DateInput = /** @class */ (function (_super) {
|
|
|
999
1068
|
intlService: this.intl,
|
|
1000
1069
|
formatPlaceholder: this.formatPlaceholder,
|
|
1001
1070
|
format: this.inputFormat,
|
|
1002
|
-
localeId: this.localeId,
|
|
1003
1071
|
cycleTime: this.options.cycleTime,
|
|
1004
1072
|
twoDigitYearMax: this.options.twoDigitYearMax,
|
|
1005
|
-
autoCorrectParts: this.options.autoCorrectParts
|
|
1073
|
+
autoCorrectParts: this.options.autoCorrectParts,
|
|
1074
|
+
value: this.options.value
|
|
1006
1075
|
}, options));
|
|
1007
1076
|
return dateObject;
|
|
1008
1077
|
};
|
|
@@ -53,27 +53,23 @@ export var approximateStringMatching = function (_a) {
|
|
|
53
53
|
Handle the typing over a literal as well.
|
|
54
54
|
*/
|
|
55
55
|
if ((isInCaretMode &&
|
|
56
|
-
newSegmentText.indexOf(oldSegmentText) === 0
|
|
56
|
+
(newSegmentText.indexOf(oldSegmentText) === 0 ||
|
|
57
|
+
formatPattern[selectionStart - 1] === Constants.formatSeparator)) ||
|
|
57
58
|
(!isInCaretMode &&
|
|
58
59
|
(newSegmentText.indexOf(oldSegmentText) === 0 ||
|
|
59
60
|
formatPattern[selectionStart - 1] === Constants.formatSeparator))) {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
var symbol = formatPattern[0];
|
|
66
|
-
for (var i = Math.max(0, oldSegmentText.length - 1); i < formatPattern.length; i++) {
|
|
67
|
-
if (formatPattern[i] !== Constants.formatSeparator) {
|
|
68
|
-
symbol = formatPattern[i];
|
|
69
|
-
break;
|
|
70
|
-
}
|
|
61
|
+
var symbol = formatPattern[0];
|
|
62
|
+
for (var i = Math.max(0, oldSegmentText.length - 1); i < formatPattern.length; i++) {
|
|
63
|
+
if (formatPattern[i] !== Constants.formatSeparator) {
|
|
64
|
+
symbol = formatPattern[i];
|
|
65
|
+
break;
|
|
71
66
|
}
|
|
72
|
-
return [[symbol, newSegmentText[selectionStart - 1]]];
|
|
73
67
|
}
|
|
68
|
+
return [[symbol, newSegmentText[selectionStart - 1]]];
|
|
74
69
|
}
|
|
75
70
|
/* Handle the entering of a space or a separator for navigating to the next item. */
|
|
76
|
-
if (newSegmentText[newSegmentText.length - 1] === ' ' ||
|
|
71
|
+
if ((!isInCaretMode && newSegmentText[newSegmentText.length - 1] === ' ') ||
|
|
72
|
+
(!isInCaretMode && newSegmentText[newSegmentText.length - 1] === oldTextSeparator)) {
|
|
77
73
|
return [[formatPattern[selectionStart - 1], Constants.formatSeparator]];
|
|
78
74
|
}
|
|
79
75
|
/* Handle typing over a correctly selected part. */
|