@progress/kendo-dateinputs-common 0.4.2-dev.202501141100 → 0.4.2-develop.2
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 +15 -9
- package/dist/es/common/observable.js +1 -0
- package/dist/es/common/utils.js +4 -2
- package/dist/es/dateinput/dateinput.js +12 -10
- package/dist/es2015/common/dateobject.js +56 -50
- package/dist/es2015/common/observable.js +2 -1
- package/dist/es2015/common/utils.js +2 -1
- package/dist/es2015/dateinput/dateinput.js +11 -9
- package/dist/npm/common/constants.js +1 -0
- package/dist/npm/common/dateobject.d.ts +3 -2
- package/dist/npm/common/dateobject.js +117 -110
- package/dist/npm/common/key.js +1 -0
- package/dist/npm/common/keycode.js +1 -0
- package/dist/npm/common/mask.js +1 -0
- package/dist/npm/common/observable.js +5 -3
- package/dist/npm/common/utils.d.ts +1 -1
- package/dist/npm/common/utils.js +42 -23
- package/dist/npm/dateinput/dateinput.d.ts +7 -7
- package/dist/npm/dateinput/dateinput.js +43 -40
- package/dist/npm/dateinput/interaction-mode.js +2 -1
- package/dist/npm/dateinput/utils.js +11 -5
- package/dist/npm/main.js +2 -1
- package/dist/systemjs/kendo-dateinputs-common.js +1 -1
- package/package.json +40 -47
- package/CODEOWNERS +0 -2
- package/NOTICE.txt +0 -614
- package/bin/release-master +0 -20
- package/global-setup.js +0 -4
- package/jest.config.js +0 -9
- package/tools/release-master +0 -20
|
@@ -13,6 +13,31 @@ const MONTH_SYMBOL = "M";
|
|
|
13
13
|
// JS months start from 0 (January) instead of 1 (January)
|
|
14
14
|
const JS_MONTH_OFFSET = 1;
|
|
15
15
|
export class DateObject {
|
|
16
|
+
set value(value) {
|
|
17
|
+
if (value && !(value instanceof Date)) {
|
|
18
|
+
// throw new Error("The 'value' should be a valid JavaScript Date instance.");
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
this._value = value;
|
|
22
|
+
this.resetInvalidDate();
|
|
23
|
+
}
|
|
24
|
+
get value() {
|
|
25
|
+
return this._value;
|
|
26
|
+
}
|
|
27
|
+
get localeId() {
|
|
28
|
+
let localeId = Constants.defaultLocaleId;
|
|
29
|
+
const cldrKeys = Object.keys(this.intl.cldr);
|
|
30
|
+
for (let i = 0; i < cldrKeys.length; i++) {
|
|
31
|
+
const key = cldrKeys[i];
|
|
32
|
+
const value = this.intl.cldr[key];
|
|
33
|
+
if (value.name && value.calendar && value.numbers &&
|
|
34
|
+
value.name !== Constants.defaultLocaleId) {
|
|
35
|
+
localeId = value.name;
|
|
36
|
+
break;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return localeId;
|
|
40
|
+
}
|
|
16
41
|
constructor({ intlService, formatPlaceholder, format, cycleTime = false, twoDigitYearMax = Constants.twoDigitYearMax, value = null, autoCorrectParts = true, toggleDayPeriod = false }) {
|
|
17
42
|
this.year = true;
|
|
18
43
|
this.month = true;
|
|
@@ -75,31 +100,6 @@ export class DateObject {
|
|
|
75
100
|
this._value = cloneDate(value);
|
|
76
101
|
}
|
|
77
102
|
}
|
|
78
|
-
set value(value) {
|
|
79
|
-
if (value && !(value instanceof Date)) {
|
|
80
|
-
// throw new Error("The 'value' should be a valid JavaScript Date instance.");
|
|
81
|
-
return;
|
|
82
|
-
}
|
|
83
|
-
this._value = value;
|
|
84
|
-
this.resetInvalidDate();
|
|
85
|
-
}
|
|
86
|
-
get value() {
|
|
87
|
-
return this._value;
|
|
88
|
-
}
|
|
89
|
-
get localeId() {
|
|
90
|
-
let localeId = Constants.defaultLocaleId;
|
|
91
|
-
const cldrKeys = Object.keys(this.intl.cldr);
|
|
92
|
-
for (let i = 0; i < cldrKeys.length; i++) {
|
|
93
|
-
const key = cldrKeys[i];
|
|
94
|
-
const value = this.intl.cldr[key];
|
|
95
|
-
if (value.name && value.calendar && value.numbers &&
|
|
96
|
-
value.name !== Constants.defaultLocaleId) {
|
|
97
|
-
localeId = value.name;
|
|
98
|
-
break;
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
return localeId;
|
|
102
|
-
}
|
|
103
103
|
/**
|
|
104
104
|
* @hidden
|
|
105
105
|
*/
|
|
@@ -228,7 +228,7 @@ export class DateObject {
|
|
|
228
228
|
*/
|
|
229
229
|
getFormattedInvalidDates(customFormat = "") {
|
|
230
230
|
const format = customFormat || this.format;
|
|
231
|
-
|
|
231
|
+
const formattedDatesForSymbol = {
|
|
232
232
|
'E': '',
|
|
233
233
|
'H': '',
|
|
234
234
|
'M': '',
|
|
@@ -337,10 +337,10 @@ export class DateObject {
|
|
|
337
337
|
let year = invalidDateParts.y.value || newValue.getFullYear();
|
|
338
338
|
let month = invalidDateParts.M.value || newValue.getMonth();
|
|
339
339
|
let day = invalidDateParts.d.value || invalidDateParts.E.value || newValue.getDate();
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
340
|
+
const hour = invalidDateParts.h.value || invalidDateParts.H.value || newValue.getHours();
|
|
341
|
+
const minutes = invalidDateParts.m.value || newValue.getMinutes();
|
|
342
|
+
const seconds = invalidDateParts.s.value || newValue.getSeconds();
|
|
343
|
+
const milliseconds = invalidDateParts.S.value || newValue.getMilliseconds();
|
|
344
344
|
switch (symbol) {
|
|
345
345
|
case 'y':
|
|
346
346
|
year += offset;
|
|
@@ -505,6 +505,7 @@ export class DateObject {
|
|
|
505
505
|
}
|
|
506
506
|
}
|
|
507
507
|
else {
|
|
508
|
+
const hours = newValue.getHours();
|
|
508
509
|
switch (symbol) {
|
|
509
510
|
case 'y':
|
|
510
511
|
newValue.setFullYear(newValue.getFullYear() + offset);
|
|
@@ -533,7 +534,6 @@ export class DateObject {
|
|
|
533
534
|
newValue.setMilliseconds(newValue.getMilliseconds() + offset);
|
|
534
535
|
break;
|
|
535
536
|
case 'a':
|
|
536
|
-
let hours = newValue.getHours();
|
|
537
537
|
if (this.toggleDayPeriod) {
|
|
538
538
|
newValue.setHours(hours >= 12 ? hours - 12 : hours + 12);
|
|
539
539
|
}
|
|
@@ -604,10 +604,10 @@ export class DateObject {
|
|
|
604
604
|
}
|
|
605
605
|
i += datePart.pattern.length - 1;
|
|
606
606
|
}
|
|
607
|
-
|
|
607
|
+
const shouldResetPart = isInCaretMode && symbol === "M" && dateParts.partMap
|
|
608
608
|
.filter(x => x.type === "month")
|
|
609
609
|
.some(x => x.pattern.length > MONTH_PART_WITH_WORDS_THRESHOLD);
|
|
610
|
-
|
|
610
|
+
const parseResult = {
|
|
611
611
|
value: null,
|
|
612
612
|
switchToNext: false,
|
|
613
613
|
resetPart: shouldResetPart,
|
|
@@ -655,7 +655,7 @@ export class DateObject {
|
|
|
655
655
|
const datePartStartIndex = (hasFixedFormat ? convertedBaseFormat : originalFormat).indexOf(symbol);
|
|
656
656
|
const datePartEndIndex = (hasFixedFormat ? convertedBaseFormat : originalFormat).lastIndexOf(symbol);
|
|
657
657
|
const segmentLength = datePartEndIndex - datePartStartIndex + 1;
|
|
658
|
-
|
|
658
|
+
const formatToTextLengthDiff = originalFormat.length - rawInputValue.length;
|
|
659
659
|
if (isInCaretMode || (!isInCaretMode && !this.autoCorrectParts)) {
|
|
660
660
|
for (let i = 0; i < baseDate.length; i++) {
|
|
661
661
|
if (baseFormat[i] === symbol) {
|
|
@@ -749,7 +749,7 @@ export class DateObject {
|
|
|
749
749
|
}
|
|
750
750
|
}
|
|
751
751
|
let parsedDate = null;
|
|
752
|
-
|
|
752
|
+
const month = this.matchMonth(currentChar);
|
|
753
753
|
const dayPeriod = this.matchDayPeriod(currentChar, symbol);
|
|
754
754
|
const isZeroCurrentChar = currentChar === '0';
|
|
755
755
|
const leadingZero = this.leadingZero || {};
|
|
@@ -757,7 +757,7 @@ export class DateObject {
|
|
|
757
757
|
if (datePartText === "0") {
|
|
758
758
|
datePartText = current;
|
|
759
759
|
}
|
|
760
|
-
|
|
760
|
+
const valueNumber = parseToInt(resetSegmentValue ?
|
|
761
761
|
currentChar :
|
|
762
762
|
(isInCaretMode ? datePartText : current) + currentChar);
|
|
763
763
|
if (valueNumber === 0 && !this.isAbbrMonth(dateParts.partMap, symbol)) {
|
|
@@ -794,9 +794,19 @@ export class DateObject {
|
|
|
794
794
|
// middle = padZero(segmentLength - middle.length) + middle;
|
|
795
795
|
middle = padZero(patternLength - middle.length) + middle;
|
|
796
796
|
}
|
|
797
|
-
|
|
797
|
+
const middleNumber = parseInt(middle, 10);
|
|
798
798
|
const candidateDateString = prefix + middle + suffix;
|
|
799
799
|
parsedDate = this.intl.parseDate(candidateDateString, this.format, this.localeId);
|
|
800
|
+
// if the format does not include year/month/day, e.g. hh:mm:ss
|
|
801
|
+
// then the exact date cannot be inferred as there is no data for it
|
|
802
|
+
// thus the today's date is used, but revert to the original date
|
|
803
|
+
// to keep other parts of the date unchanged
|
|
804
|
+
if (parsedDate && this.value &&
|
|
805
|
+
dateParts.partMap.every(x => x.type !== "year" && x.type !== "month" && x.type != "day")) {
|
|
806
|
+
parsedDate.setFullYear(this.value.getFullYear());
|
|
807
|
+
parsedDate.setMonth(this.value.getMonth());
|
|
808
|
+
parsedDate.setDate(this.value.getDate());
|
|
809
|
+
}
|
|
800
810
|
let autoCorrectedPrefixAndSuffix = false;
|
|
801
811
|
if (isInCaretMode && !isValidDate(parsedDate)) {
|
|
802
812
|
// if part of the date is not available, e.g. "d"
|
|
@@ -946,15 +956,15 @@ export class DateObject {
|
|
|
946
956
|
const isDay = symbol === "d";
|
|
947
957
|
let newValue = cloneDate(this._value);
|
|
948
958
|
const invalidDateParts = this._partiallyInvalidDate.invalidDateParts || {};
|
|
949
|
-
|
|
959
|
+
const year = invalidDateParts.y.value || newValue.getFullYear();
|
|
950
960
|
/* tslint:disable:no-shadowed-variable */
|
|
951
|
-
|
|
961
|
+
const month = isMonth ? datePartValue : invalidDateParts.M.value || newValue.getMonth();
|
|
952
962
|
/* tslint:enable:no-shadowed-variable */
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
963
|
+
const day = isDay ? datePartValue : invalidDateParts.d.value || invalidDateParts.E.value || newValue.getDate();
|
|
964
|
+
const hour = invalidDateParts.h.value || invalidDateParts.H.value || newValue.getHours();
|
|
965
|
+
const minutes = invalidDateParts.m.value || newValue.getMinutes();
|
|
966
|
+
const seconds = invalidDateParts.s.value || newValue.getSeconds();
|
|
967
|
+
const milliseconds = invalidDateParts.S.value || newValue.getMilliseconds();
|
|
958
968
|
const dateCandidate = createDate(year, month, day, hour, minutes, seconds, milliseconds);
|
|
959
969
|
const dateCandidateExists = areDatePartsEqualTo(dateCandidate, year, month, day, hour, minutes, seconds, milliseconds);
|
|
960
970
|
const newValueCandidate = isMonth || isDay ?
|
|
@@ -1257,7 +1267,7 @@ export class DateObject {
|
|
|
1257
1267
|
// Important: right to left.
|
|
1258
1268
|
let resultText = '';
|
|
1259
1269
|
let resultFormat = '';
|
|
1260
|
-
|
|
1270
|
+
const format = mask.symbols;
|
|
1261
1271
|
let processTextSymbolsEnded = false;
|
|
1262
1272
|
let ignoreFormatSymbolsCount = 0;
|
|
1263
1273
|
const formattedDates = this.getFormattedInvalidDates(format);
|
|
@@ -1550,11 +1560,7 @@ export class DateObject {
|
|
|
1550
1560
|
const peekedDate = this.intl.parseDate(peekedDateString, this.format, this.localeId);
|
|
1551
1561
|
const leadingZeroOffset = (this.leadingZero || {})[symbol] || 0;
|
|
1552
1562
|
const patternSatisfied = (leadingZeroOffset + unpadZero(middle).length) >= patternLength;
|
|
1553
|
-
|
|
1554
|
-
if (symbol === "M") {
|
|
1555
|
-
}
|
|
1556
|
-
else if (symbol === "d") {
|
|
1557
|
-
}
|
|
1563
|
+
const parsedPeekedValue = parseToInt(peekedValue);
|
|
1558
1564
|
const switchToNext = peekedDate === null ||
|
|
1559
1565
|
(leadingZero[symbol] ?
|
|
1560
1566
|
patternValue.length <= middle.length :
|
|
@@ -7,12 +7,13 @@ export class Observable {
|
|
|
7
7
|
this.options = extend({}, defaultOptions, options);
|
|
8
8
|
}
|
|
9
9
|
destroy() {
|
|
10
|
+
this.options = {};
|
|
10
11
|
}
|
|
11
12
|
/**
|
|
12
13
|
* @hidden
|
|
13
14
|
*/
|
|
14
15
|
trigger(eventName, args = {}) {
|
|
15
|
-
|
|
16
|
+
const eventData = {
|
|
16
17
|
defaultPrevented: false,
|
|
17
18
|
preventDefault: () => {
|
|
18
19
|
eventData.defaultPrevented = true;
|
|
@@ -46,7 +46,7 @@ export const deepExtend = (target, ...sources) => {
|
|
|
46
46
|
const source = sources.shift();
|
|
47
47
|
if (isObject(target) && isObject(source)) {
|
|
48
48
|
for (const key in source) {
|
|
49
|
-
if (!
|
|
49
|
+
if (!Object.prototype.hasOwnProperty.call(source, key) ||
|
|
50
50
|
key === "__proto__" ||
|
|
51
51
|
key === "constructor" ||
|
|
52
52
|
key === "prototype") {
|
|
@@ -71,6 +71,7 @@ export const deepExtend = (target, ...sources) => {
|
|
|
71
71
|
/**
|
|
72
72
|
* @hidden
|
|
73
73
|
*/
|
|
74
|
+
// eslint-disable-next-line
|
|
74
75
|
export const noop = () => { };
|
|
75
76
|
/**
|
|
76
77
|
* @hidden
|
|
@@ -66,6 +66,9 @@ const defaultDateInputOptions = {
|
|
|
66
66
|
toggleDayPeriod: false
|
|
67
67
|
};
|
|
68
68
|
export class DateInput extends Observable {
|
|
69
|
+
get value() {
|
|
70
|
+
return this.dateObject && this.dateObject.getValue();
|
|
71
|
+
}
|
|
69
72
|
constructor(element, options) {
|
|
70
73
|
super(options);
|
|
71
74
|
this.dateObject = null;
|
|
@@ -77,9 +80,6 @@ export class DateInput extends Observable {
|
|
|
77
80
|
this.previousElementSelection = { start: 0, end: 0 };
|
|
78
81
|
this.init(element, options);
|
|
79
82
|
}
|
|
80
|
-
get value() {
|
|
81
|
-
return this.dateObject && this.dateObject.getValue();
|
|
82
|
-
}
|
|
83
83
|
init(element, options) {
|
|
84
84
|
let dateValue = isValidDate(this.options.value) ? cloneDate(this.options.value) : new Date(options.formattedValue);
|
|
85
85
|
if (!isValidDate(dateValue)) {
|
|
@@ -87,7 +87,7 @@ export class DateInput extends Observable {
|
|
|
87
87
|
}
|
|
88
88
|
this.element = element;
|
|
89
89
|
// this.element._kendoWidget = this;
|
|
90
|
-
this.options = extend({}, defaultDateInputOptions, options, { steps: Object.assign({}, defaultDateInputOptions.steps, options.steps) });
|
|
90
|
+
this.options = extend({}, defaultDateInputOptions, options, { steps: Object.assign(Object.assign({}, defaultDateInputOptions.steps), options.steps) });
|
|
91
91
|
this.intl = this.options.intlService;
|
|
92
92
|
this.dateObject = this.createDateObject();
|
|
93
93
|
this.dateObject.setValue(dateValue);
|
|
@@ -147,7 +147,7 @@ export class DateInput extends Observable {
|
|
|
147
147
|
this.element.removeEventListener(MOUSE_WHEEL, this.onElementMouseWheel);
|
|
148
148
|
}
|
|
149
149
|
setOptions(options, refresh = false) {
|
|
150
|
-
this.options = extend({}, this.options, options, { steps: Object.assign({}, defaultDateInputOptions.steps, options.steps) });
|
|
150
|
+
this.options = extend({}, this.options, options, { steps: Object.assign(Object.assign({}, defaultDateInputOptions.steps), options.steps) });
|
|
151
151
|
this.setDateObjectOptions();
|
|
152
152
|
if (refresh) {
|
|
153
153
|
this.unbindEvents();
|
|
@@ -302,7 +302,7 @@ export class DateInput extends Observable {
|
|
|
302
302
|
oldText = currentText;
|
|
303
303
|
}
|
|
304
304
|
const newText = this.elementValue;
|
|
305
|
-
|
|
305
|
+
const diff = approximateStringMatching({
|
|
306
306
|
oldText: oldText,
|
|
307
307
|
newText: newText,
|
|
308
308
|
formatPattern: this.currentFormat,
|
|
@@ -368,7 +368,7 @@ export class DateInput extends Observable {
|
|
|
368
368
|
const currentSelection = this.selection;
|
|
369
369
|
if (hasCaret) {
|
|
370
370
|
const diffChar = diff && diff.length > 0 ? diff[0][0] : null;
|
|
371
|
-
|
|
371
|
+
const hasLeadingZero = this.dateObject.getLeadingZero()[diffChar];
|
|
372
372
|
if (diff.length && diff[0][0] !== Constants.formatSeparator) {
|
|
373
373
|
if (switchPart) {
|
|
374
374
|
this.forceUpdateWithSelection();
|
|
@@ -789,7 +789,7 @@ export class DateInput extends Observable {
|
|
|
789
789
|
}
|
|
790
790
|
}
|
|
791
791
|
this.interactionMode = DateInputInteractionMode.None;
|
|
792
|
-
|
|
792
|
+
const { start: selectionStart, end: selectionEnd } = this.selection;
|
|
793
793
|
if (selectionStart < selectionEnd &&
|
|
794
794
|
this.currentFormat[selectionStart] !== this.currentFormat[selectionEnd - 1]) {
|
|
795
795
|
this.setSelection(this.selectionByIndex(offset > 0 ? selectionStart : selectionEnd - 1));
|
|
@@ -1146,7 +1146,9 @@ export class DateInput extends Observable {
|
|
|
1146
1146
|
* @hidden
|
|
1147
1147
|
*/
|
|
1148
1148
|
autoFill() {
|
|
1149
|
-
|
|
1149
|
+
const dateObject = this.dateObject;
|
|
1150
|
+
const currentDate = new Date();
|
|
1151
|
+
let day, month, year, hours, minutes, seconds;
|
|
1150
1152
|
if (dateObject.date || dateObject.month || dateObject.year || dateObject.hours || dateObject.minutes || dateObject.seconds) {
|
|
1151
1153
|
year = dateObject.year ? dateObject.value.getFullYear() : currentDate.getFullYear(),
|
|
1152
1154
|
month = dateObject.month ? dateObject.value.getMonth() : currentDate.getMonth(),
|
|
@@ -17,8 +17,9 @@ export declare class DateObject {
|
|
|
17
17
|
private knownParts;
|
|
18
18
|
private symbols;
|
|
19
19
|
private _value;
|
|
20
|
-
value: Date;
|
|
21
|
-
|
|
20
|
+
set value(value: Date);
|
|
21
|
+
get value(): Date;
|
|
22
|
+
private get localeId();
|
|
22
23
|
private cycleTime;
|
|
23
24
|
private dayPeriods;
|
|
24
25
|
private twoDigitYearMax;
|