@progress/kendo-dateinputs-common 0.2.0-dev.202301131210 → 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.
@@ -29,6 +29,7 @@ const CHANGE = "change";
29
29
  const defaultDateInputOptions = {
30
30
  format: "d",
31
31
  allowNulls: false,
32
+ hasPlaceholder: false,
32
33
  placeholder: null,
33
34
  cycleTime: true,
34
35
  locale: null,
@@ -286,7 +287,7 @@ export class DateInput extends Observable {
286
287
  text = currentText;
287
288
  }
288
289
  const newText = this.elementValue;
289
- const diff = approximateStringMatching({
290
+ let diff = approximateStringMatching({
290
291
  oldText: text,
291
292
  newText: newText,
292
293
  formatPattern: this.currentFormat,
@@ -294,6 +295,24 @@ export class DateInput extends Observable {
294
295
  isInCaretMode: hasCaret,
295
296
  keyEvent: this.keyDownEvent
296
297
  });
298
+ const currentFormatChar = this.formatStateOnKeyDown.format[this.formatStateOnKeyDown.selectionStart] || "";
299
+ if (this.options.allowCaretMode && hasCaret && this.currentFormat.length !== this.elementValue.length) {
300
+ if (currentFormatChar &&
301
+ currentFormatChar.length > 0 &&
302
+ currentFormatChar !== Constants.formatSeparator) {
303
+ if (!diff || diff.length === 0) {
304
+ diff = [];
305
+ diff[0][0] = currentFormatChar;
306
+ diff[0][1] = e.data || "";
307
+ }
308
+ else if (diff[0] && diff[0][0] !== Constants.formatSeparator) {
309
+ if (diff[0][0] !== currentFormatChar) {
310
+ diff[0][0] = currentFormatChar;
311
+ diff[0][1] = e.data || "";
312
+ }
313
+ }
314
+ }
315
+ }
297
316
  if (hasCaret && (!diff || diff.length === 0)) {
298
317
  this.restorePreviousInputEventState();
299
318
  return;
@@ -335,6 +354,7 @@ export class DateInput extends Observable {
335
354
  const lastParseResultHasNoValue = lastParseResult && !lastParseResult.value;
336
355
  const parsingFailedOnDelete = (hasCaret && (isBackspaceKey || isDeleteKey) && lastParseResultHasNoValue);
337
356
  const resetPart = lastParseResult ? lastParseResult.resetPart : false;
357
+ const hasInvalidDatePart = lastParseResult ? lastParseResult.hasInvalidDatePart : false;
338
358
  const hasDateValueChanged = !isEqual(oldDateObjectValue, this.dateObject.value);
339
359
  let symbolForSelection;
340
360
  const currentSelection = this.selection;
@@ -360,14 +380,35 @@ export class DateInput extends Observable {
360
380
  }
361
381
  }
362
382
  else if (hasCaret) {
363
- if (hasDateValueChanged && isPresent(this.dateObject.getValue())) {
383
+ if ((hasDateValueChanged && isPresent(this.dateObject.getValue()) ||
384
+ (!hasDateValueChanged && switchPart && isPresent(this.dateObject.getValue())))) {
364
385
  if (switchPart) {
365
386
  this.switchDateSegment(1);
366
387
  }
388
+ else {
389
+ if (this.options.format.length !== this.currentFormat.length &&
390
+ currentFormatChar && currentFormatChar !== "y") {
391
+ const elementValueLength = this.elementValue.length;
392
+ this.forceUpdate();
393
+ const selectionOffset = this.elementValue.length - elementValueLength;
394
+ this.setSelection({
395
+ start: currentSelection.start + selectionOffset,
396
+ end: currentSelection.start + selectionOffset
397
+ });
398
+ }
399
+ }
367
400
  }
368
401
  else {
369
402
  if (lastParseResultHasNoValue) {
370
- this.restorePreviousInputEventState();
403
+ let hasLeadingZero = this.dateObject.getLeadingZero()[currentFormatChar];
404
+ if (switchPart) {
405
+ this.switchDateSegment(1);
406
+ }
407
+ else if (e.data === "0" && hasLeadingZero) {
408
+ }
409
+ else {
410
+ this.restorePreviousInputEventState();
411
+ }
371
412
  }
372
413
  }
373
414
  }
@@ -379,20 +420,25 @@ export class DateInput extends Observable {
379
420
  }
380
421
  else {
381
422
  // the input is not complete, not parsable or not updatable
382
- if (hasCaret && originalInteractionMode !== DateInputInteractionMode.Caret && hasDateValueChanged) {
423
+ if (originalInteractionMode !== DateInputInteractionMode.Caret && hasDateValueChanged) {
383
424
  }
384
- else if (hasCaret && originalInteractionMode !== DateInputInteractionMode.Caret) {
425
+ else if (originalInteractionMode !== DateInputInteractionMode.Caret) {
385
426
  symbolForSelection = this.currentFormat[currentSelection.start];
386
427
  this.forceUpdate();
387
428
  this.setSelection(this.selectionBySymbol(symbolForSelection));
388
429
  }
389
- else {
430
+ else if (!hasInvalidDatePart) {
390
431
  this.restorePreviousInputEventState();
391
432
  }
392
433
  }
393
434
  }
394
435
  else {
395
- this.restorePreviousInputEventState();
436
+ let hasLeadingZero = this.dateObject.getLeadingZero()[currentFormatChar];
437
+ if (e.data === "0" && hasLeadingZero) {
438
+ }
439
+ else if (!hasInvalidDatePart) {
440
+ this.restorePreviousInputEventState();
441
+ }
396
442
  }
397
443
  }
398
444
  else if (this.options.autoSwitchParts && (switchPart || navigationOnly)) {
@@ -454,9 +500,14 @@ export class DateInput extends Observable {
454
500
  if (this.triggerKeyDown({ event: e })) {
455
501
  return;
456
502
  }
503
+ const { start, end } = this.selection;
457
504
  this.keyDownEvent = e;
458
505
  this.previousElementValue = this.element.value;
459
- const { start, end } = this.selection;
506
+ this.formatStateOnKeyDown = {
507
+ format: this.currentFormat,
508
+ selectionStart: start,
509
+ selectionEnd: end
510
+ };
460
511
  this.previousElementSelection = { start, end };
461
512
  const autoSwitchKeys = (this.options.autoSwitchKeys || [])
462
513
  .map(x => x.toString().toLowerCase().trim());
@@ -710,11 +761,13 @@ export class DateInput extends Observable {
710
761
  return;
711
762
  }
712
763
  }
764
+ this.interactionMode = DateInputInteractionMode.None;
713
765
  let { start: selectionStart, end: selectionEnd } = this.selection;
714
766
  if (selectionStart < selectionEnd &&
715
767
  this.currentFormat[selectionStart] !== this.currentFormat[selectionEnd - 1]) {
716
768
  this.setSelection(this.selectionByIndex(offset > 0 ? selectionStart : selectionEnd - 1));
717
769
  this.resetSegmentValue = true;
770
+ this.interactionMode = DateInputInteractionMode.None;
718
771
  return;
719
772
  }
720
773
  const previousFormatSymbol = this.currentFormat[selectionStart];
@@ -745,6 +798,7 @@ export class DateInput extends Observable {
745
798
  this.setSelection({ start: a, end: b });
746
799
  this.resetSegmentValue = true;
747
800
  }
801
+ this.interactionMode = DateInputInteractionMode.None;
748
802
  }
749
803
  modifyDateSegmentValue(offset, symbol = "", event = {}) {
750
804
  if (!this.dateObject) {
@@ -933,13 +987,14 @@ export class DateInput extends Observable {
933
987
  const { text: currentText, format: currentFormat } = this.dateObject.getTextAndFormat(format);
934
988
  this.currentFormat = currentFormat;
935
989
  this.currentText = currentText;
990
+ const hasPlaceholder = this.options.hasPlaceholder || isPresent(this.options.placeholder);
936
991
  const showPlaceholder = !this.isActive &&
937
- isPresent(this.options.placeholder) &&
992
+ hasPlaceholder &&
938
993
  !this.dateObject.hasValue();
939
- if (isPresent(this.options.placeholder)) {
994
+ if (hasPlaceholder && isPresent(this.options.placeholder)) {
940
995
  element.placeholder = this.options.placeholder;
941
996
  }
942
- const newElementValue = !showPlaceholder ? currentText : "";
997
+ const newElementValue = showPlaceholder ? "" : currentText;
943
998
  this.previousElementValue = this.elementValue;
944
999
  this.setElementValue(newElementValue);
945
1000
  if (this.isActive && !this.options.allowCaretMode && this.options.selectNearestSegmentOnFocus) {
@@ -81,6 +81,10 @@ export declare class DateObject {
81
81
  */
82
82
  resetLeadingZero(): boolean;
83
83
  setLeadingZero(leadingZero: any): void;
84
+ /**
85
+ * @hidden
86
+ */
87
+ getLeadingZero(): any;
84
88
  /**
85
89
  * @hidden
86
90
  */
@@ -158,6 +162,10 @@ export declare class DateObject {
158
162
  startDateOffset?: number;
159
163
  startDate?: any;
160
164
  }): void;
165
+ /**
166
+ * @hidden
167
+ */
168
+ hasInvalidDatePart(): boolean;
161
169
  /**
162
170
  * @hidden
163
171
  */