flatpickr-ce 4.10.0 → 4.12.0

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.
Files changed (154) hide show
  1. package/README.md +72 -1
  2. package/dist/esm/index.js +220 -113
  3. package/dist/esm/l10n/af.js +68 -0
  4. package/dist/esm/l10n/ar-dz.js +2 -1
  5. package/dist/esm/l10n/ar-sy.js +50 -0
  6. package/dist/esm/l10n/ar.js +1 -0
  7. package/dist/esm/l10n/az.js +1 -0
  8. package/dist/esm/l10n/br.js +1 -0
  9. package/dist/esm/l10n/da.js +1 -0
  10. package/dist/esm/l10n/de.js +1 -0
  11. package/dist/esm/l10n/default.js +1 -0
  12. package/dist/esm/l10n/es.js +1 -0
  13. package/dist/esm/l10n/eu.js +65 -0
  14. package/dist/esm/l10n/fi.js +1 -0
  15. package/dist/esm/l10n/fr.js +1 -0
  16. package/dist/esm/l10n/gl.js +1 -0
  17. package/dist/esm/l10n/gr.js +2 -1
  18. package/dist/esm/l10n/hy.js +1 -0
  19. package/dist/esm/l10n/index.js +11 -0
  20. package/dist/esm/l10n/ja.js +1 -0
  21. package/dist/esm/l10n/ko.js +1 -0
  22. package/dist/esm/l10n/pl.js +1 -0
  23. package/dist/esm/l10n/pt.js +1 -0
  24. package/dist/esm/l10n/sq.js +1 -0
  25. package/dist/esm/l10n/sv.js +1 -0
  26. package/dist/esm/l10n/tk.js +80 -0
  27. package/dist/esm/l10n/uk.js +1 -0
  28. package/dist/esm/l10n/zh.js +2 -0
  29. package/dist/esm/l10n/zh_tw.js +1 -0
  30. package/dist/esm/plugins/momentPlugin.js +2 -2
  31. package/dist/esm/plugins/rangePlugin.js +18 -3
  32. package/dist/esm/plugins/scrollPlugin.js +3 -3
  33. package/dist/esm/plugins/weekSelect/weekSelect.js +1 -0
  34. package/dist/esm/utils/dates.js +37 -19
  35. package/dist/flatpickr.css +15 -1
  36. package/dist/flatpickr.js +377 -146
  37. package/dist/flatpickr.min.css +2 -2
  38. package/dist/flatpickr.min.js +2 -2
  39. package/dist/l10n/af.d.ts +84 -0
  40. package/dist/l10n/af.js +81 -0
  41. package/dist/l10n/ar-dz.d.ts +6 -0
  42. package/dist/l10n/ar-dz.js +2 -1
  43. package/dist/l10n/ar-sy.d.ts +84 -0
  44. package/dist/l10n/ar-sy.js +63 -0
  45. package/dist/l10n/ar.d.ts +6 -0
  46. package/dist/l10n/ar.js +1 -0
  47. package/dist/l10n/at.d.ts +6 -0
  48. package/dist/l10n/az.d.ts +6 -0
  49. package/dist/l10n/az.js +1 -0
  50. package/dist/l10n/be.d.ts +6 -0
  51. package/dist/l10n/bg.d.ts +6 -0
  52. package/dist/l10n/bn.d.ts +6 -0
  53. package/dist/l10n/br.d.ts +6 -0
  54. package/dist/l10n/br.js +1 -0
  55. package/dist/l10n/bs.d.ts +6 -0
  56. package/dist/l10n/cat.d.ts +6 -0
  57. package/dist/l10n/ckb.d.ts +6 -0
  58. package/dist/l10n/cs.d.ts +6 -0
  59. package/dist/l10n/cy.d.ts +6 -0
  60. package/dist/l10n/da.d.ts +6 -0
  61. package/dist/l10n/da.js +1 -0
  62. package/dist/l10n/de.d.ts +6 -0
  63. package/dist/l10n/de.js +1 -0
  64. package/dist/l10n/default.js +1 -0
  65. package/dist/l10n/eo.d.ts +6 -0
  66. package/dist/l10n/es.d.ts +6 -0
  67. package/dist/l10n/es.js +1 -0
  68. package/dist/l10n/et.d.ts +6 -0
  69. package/dist/l10n/eu.d.ts +84 -0
  70. package/dist/l10n/eu.js +78 -0
  71. package/dist/l10n/fa.d.ts +6 -0
  72. package/dist/l10n/fi.d.ts +6 -0
  73. package/dist/l10n/fi.js +1 -0
  74. package/dist/l10n/fo.d.ts +6 -0
  75. package/dist/l10n/fr.d.ts +6 -0
  76. package/dist/l10n/fr.js +1 -0
  77. package/dist/l10n/ga.d.ts +6 -0
  78. package/dist/l10n/gl.d.ts +6 -0
  79. package/dist/l10n/gl.js +1 -0
  80. package/dist/l10n/gr.d.ts +6 -0
  81. package/dist/l10n/gr.js +2 -1
  82. package/dist/l10n/he.d.ts +6 -0
  83. package/dist/l10n/hi.d.ts +6 -0
  84. package/dist/l10n/hr.d.ts +6 -0
  85. package/dist/l10n/hu.d.ts +6 -0
  86. package/dist/l10n/hy.d.ts +6 -0
  87. package/dist/l10n/hy.js +1 -0
  88. package/dist/l10n/id.d.ts +6 -0
  89. package/dist/l10n/index.js +542 -197
  90. package/dist/l10n/is.d.ts +6 -0
  91. package/dist/l10n/it.d.ts +6 -0
  92. package/dist/l10n/ja.d.ts +6 -0
  93. package/dist/l10n/ja.js +1 -0
  94. package/dist/l10n/ka.d.ts +6 -0
  95. package/dist/l10n/km.d.ts +6 -0
  96. package/dist/l10n/ko.d.ts +6 -0
  97. package/dist/l10n/ko.js +1 -0
  98. package/dist/l10n/kz.d.ts +6 -0
  99. package/dist/l10n/lt.d.ts +6 -0
  100. package/dist/l10n/lv.d.ts +6 -0
  101. package/dist/l10n/mk.d.ts +6 -0
  102. package/dist/l10n/mn.d.ts +6 -0
  103. package/dist/l10n/ms.d.ts +6 -0
  104. package/dist/l10n/my.d.ts +6 -0
  105. package/dist/l10n/nl.d.ts +6 -0
  106. package/dist/l10n/nn.d.ts +6 -0
  107. package/dist/l10n/no.d.ts +6 -0
  108. package/dist/l10n/pa.d.ts +6 -0
  109. package/dist/l10n/pl.d.ts +6 -0
  110. package/dist/l10n/pl.js +1 -0
  111. package/dist/l10n/pt.d.ts +6 -0
  112. package/dist/l10n/pt.js +1 -0
  113. package/dist/l10n/ro.d.ts +6 -0
  114. package/dist/l10n/ru.d.ts +6 -0
  115. package/dist/l10n/si.d.ts +6 -0
  116. package/dist/l10n/sk.d.ts +6 -0
  117. package/dist/l10n/sl.d.ts +6 -0
  118. package/dist/l10n/sq.d.ts +6 -0
  119. package/dist/l10n/sq.js +1 -0
  120. package/dist/l10n/sr-cyr.d.ts +6 -0
  121. package/dist/l10n/sr.d.ts +6 -0
  122. package/dist/l10n/sv.d.ts +6 -0
  123. package/dist/l10n/sv.js +1 -0
  124. package/dist/l10n/tg.d.ts +6 -0
  125. package/dist/l10n/th.d.ts +6 -0
  126. package/dist/l10n/tk.d.ts +84 -0
  127. package/dist/l10n/tk.js +93 -0
  128. package/dist/l10n/tr.d.ts +6 -0
  129. package/dist/l10n/uk.d.ts +6 -0
  130. package/dist/l10n/uk.js +1 -0
  131. package/dist/l10n/uz.d.ts +6 -0
  132. package/dist/l10n/uz_latn.d.ts +6 -0
  133. package/dist/l10n/vn.d.ts +6 -0
  134. package/dist/l10n/zh.d.ts +6 -0
  135. package/dist/l10n/zh.js +2 -0
  136. package/dist/l10n/zh_tw.d.ts +6 -0
  137. package/dist/l10n/zh_tw.js +1 -0
  138. package/dist/plugins/minMaxTimePlugin.js +3 -1
  139. package/dist/plugins/momentPlugin.js +2 -2
  140. package/dist/plugins/rangePlugin.js +27 -3
  141. package/dist/plugins/scrollPlugin.js +3 -3
  142. package/dist/plugins/weekSelect/weekSelect.js +2 -0
  143. package/dist/themes/airbnb.css +15 -1
  144. package/dist/themes/confetti.css +14 -0
  145. package/dist/themes/dark.css +14 -0
  146. package/dist/themes/light.css +14 -0
  147. package/dist/themes/material_blue.css +14 -0
  148. package/dist/themes/material_green.css +14 -0
  149. package/dist/themes/material_orange.css +14 -0
  150. package/dist/themes/material_red.css +14 -0
  151. package/dist/types/instance.d.ts +1 -0
  152. package/dist/types/locale.d.ts +3 -1
  153. package/package.json +6 -1
  154. package/src/style/flatpickr.styl +24 -1
package/dist/flatpickr.js CHANGED
@@ -1,4 +1,4 @@
1
- /* flatpickr v4.10.0, @license MIT */
1
+ /* flatpickr v4.12.0, @license MIT */
2
2
  (function (global, factory) {
3
3
  typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
4
4
  typeof define === 'function' && define.amd ? define(factory) :
@@ -197,6 +197,7 @@
197
197
  monthAriaLabel: "Month",
198
198
  hourAriaLabel: "Hour",
199
199
  minuteAriaLabel: "Minute",
200
+ secondAriaLabel: "Second",
200
201
  time_24hr: false,
201
202
  };
202
203
 
@@ -467,7 +468,8 @@
467
468
  var _b = _a.config, config = _b === void 0 ? defaults : _b, _c = _a.l10n, l10n = _c === void 0 ? english : _c, _d = _a.isMobile, isMobile = _d === void 0 ? false : _d;
468
469
  return function (dateObj, frmt, overrideLocale) {
469
470
  var locale = overrideLocale || l10n;
470
- if (config.formatDate !== undefined && !isMobile) {
471
+ // null, the default the docs list, leaves it unset like undefined (#2725)
472
+ if (config.formatDate && !isMobile) {
471
473
  return config.formatDate(dateObj, frmt, locale);
472
474
  }
473
475
  return frmt
@@ -583,7 +585,10 @@
583
585
  /**
584
586
  * The default time for a date on the given day. minDate and maxDate hold it
585
587
  * only on their own day, and only when set with a time: a date-only limit
586
- * leaves its whole day open, as for the time inputs (setHoursFromInputs)
588
+ * leaves its whole day open, as for the time inputs (setHoursFromInputs).
589
+ * minTime and maxTime hold it on every day, as they do the time inputs: an
590
+ * overnight window, minTime after maxTime, moves it to minTime only from the
591
+ * hours between the two
587
592
  */
588
593
  function getDefaultHours(config, date) {
589
594
  var hours = config.defaultHour;
@@ -594,27 +599,45 @@
594
599
  compareDates(date, limit) === 0 &&
595
600
  (limit.getHours() > 0 || limit.getMinutes() > 0 || limit.getSeconds() > 0);
596
601
  };
597
- if (holdsTime(config.minDate)) {
598
- var minHour = config.minDate.getHours();
599
- var minMinutes = config.minDate.getMinutes();
600
- var minSeconds = config.minDate.getSeconds();
601
- if (hours < minHour) {
602
- hours = minHour;
603
- }
604
- if (hours === minHour && minutes < minMinutes) {
605
- minutes = minMinutes;
606
- }
607
- if (hours === minHour && minutes === minMinutes && seconds < minSeconds)
608
- seconds = config.minDate.getSeconds();
609
- }
610
- if (holdsTime(config.maxDate)) {
611
- var maxHr = config.maxDate.getHours();
612
- var maxMinutes = config.maxDate.getMinutes();
613
- hours = Math.min(hours, maxHr);
614
- if (hours === maxHr)
615
- minutes = Math.min(maxMinutes, minutes);
616
- if (hours === maxHr && minutes === maxMinutes)
617
- seconds = Math.min(seconds, config.maxDate.getSeconds());
602
+ var holdAbove = function (limit) {
603
+ hours = Math.max(hours, limit.getHours());
604
+ if (hours === limit.getHours()) {
605
+ minutes = Math.max(minutes, limit.getMinutes());
606
+ if (minutes === limit.getMinutes())
607
+ seconds = Math.max(seconds, limit.getSeconds());
608
+ }
609
+ };
610
+ var holdBelow = function (limit) {
611
+ hours = Math.min(hours, limit.getHours());
612
+ if (hours === limit.getHours()) {
613
+ minutes = Math.min(minutes, limit.getMinutes());
614
+ if (minutes === limit.getMinutes())
615
+ seconds = Math.min(seconds, limit.getSeconds());
616
+ }
617
+ };
618
+ var secondsOf = function (time) {
619
+ return calculateSecondsSinceMidnight(time.getHours(), time.getMinutes(), time.getSeconds());
620
+ };
621
+ if (holdsTime(config.minDate))
622
+ holdAbove(config.minDate);
623
+ if (holdsTime(config.maxDate))
624
+ holdBelow(config.maxDate);
625
+ var minTime = config.minTime, maxTime = config.maxTime;
626
+ if (minTime !== undefined &&
627
+ maxTime !== undefined &&
628
+ secondsOf(minTime) > secondsOf(maxTime)) {
629
+ var time = calculateSecondsSinceMidnight(hours, minutes, seconds);
630
+ if (time > secondsOf(maxTime) && time < secondsOf(minTime)) {
631
+ hours = minTime.getHours();
632
+ minutes = minTime.getMinutes();
633
+ seconds = minTime.getSeconds();
634
+ }
635
+ }
636
+ else {
637
+ if (maxTime !== undefined)
638
+ holdBelow(maxTime);
639
+ if (minTime !== undefined)
640
+ holdAbove(minTime);
618
641
  }
619
642
  return { hours: hours, minutes: minutes, seconds: seconds };
620
643
  }
@@ -644,10 +667,14 @@
644
667
  var DEBOUNCED_CHANGE_MS = 300;
645
668
  // Instances created so far, which numbers their fields' ids
646
669
  var instanceCount = 0;
670
+ // weekdays and months each hold two lists that are used apart, so a custom
671
+ // locale that gives only one of them keeps the other from the base locale
672
+ function mergeLocale(base, custom) {
673
+ return __assign(__assign(__assign({}, base), custom), { weekdays: __assign(__assign({}, base.weekdays), custom === null || custom === void 0 ? void 0 : custom.weekdays), months: __assign(__assign({}, base.months), custom === null || custom === void 0 ? void 0 : custom.months) });
674
+ }
647
675
  function FlatpickrInstance(element, instanceConfig) {
648
676
  var self = {
649
677
  config: __assign(__assign({}, defaults), flatpickr.defaultConfig),
650
- l10n: english,
651
678
  };
652
679
  // The options the user gave, at creation and through set(), as opposed to
653
680
  // defaults
@@ -665,7 +692,10 @@
665
692
  // Listeners on the document and the window, bound only while the calendar
666
693
  // is open; kept apart from _handlers, which last until destroy()
667
694
  var openHandlers = [];
668
- self.parseDate = createDateParser({ config: self.config, l10n: self.l10n });
695
+ // Watches the calendar until it is laid out, while an element around it is
696
+ // hidden and its day grid has no width to measure (#2579). ResizeObserver
697
+ // is missing from TypeScript 4.1's DOM types
698
+ var layoutObserver;
669
699
  self._handlers = [];
670
700
  self.pluginElements = [];
671
701
  self.loadedPlugins = [];
@@ -674,6 +704,7 @@
674
704
  self._positionCalendar = positionCalendar;
675
705
  self._showValue = showValue;
676
706
  self._typedValue = typedValue;
707
+ self._startNewRange = startNewRange;
677
708
  self._getIncrement = getIncrement;
678
709
  self.changeMonth = changeMonth;
679
710
  self.changeYear = changeYear;
@@ -728,8 +759,10 @@
728
759
 
729
760
  However, most browsers are not Safari and positioning is expensive when used
730
761
  in scale. https://github.com/chmln/flatpickr/issues/1096
762
+
763
+ The page lays an inline calendar out: open() never positions it (#2787)
731
764
  */
732
- if (!self.isMobile && isSafari) {
765
+ if (!self.isMobile && !self.config.inline && isSafari) {
733
766
  positionCalendar();
734
767
  }
735
768
  triggerEvent("onReady");
@@ -744,30 +777,65 @@
744
777
  }
745
778
  function setCalendarWidth() {
746
779
  var config = self.config;
747
- if (config.weekNumbers === false && config.showMonths === 1) {
780
+ // the stylesheet's width fits one month without a week column; drop the
781
+ // widths written below, which set("showMonths", 1) would otherwise keep
782
+ // from more months (#2392). The week column is built once, and
783
+ // set("weekNumbers", false) doesn't remove it, so look at the DOM
784
+ if (self.weekWrapper === undefined && config.showMonths === 1) {
785
+ if (self.daysContainer !== undefined) {
786
+ self.daysContainer.style.removeProperty("width");
787
+ self.calendarContainer.style.removeProperty("width");
788
+ }
789
+ // nor measure it once it is laid out (#2579)
790
+ unobserveLayout();
748
791
  return;
749
792
  }
750
793
  else if (config.noCalendar !== true) {
751
- win.requestAnimationFrame(function () {
752
- if (self.calendarContainer !== undefined) {
753
- self.calendarContainer.style.visibility = "hidden";
754
- self.calendarContainer.style.display = "block";
755
- }
756
- if (self.daysContainer !== undefined) {
757
- var daysWidth = (self.days.offsetWidth + 1) * config.showMonths;
758
- self.daysContainer.style.width = daysWidth + "px";
759
- self.calendarContainer.style.width =
760
- daysWidth +
761
- (self.weekWrapper !== undefined
762
- ? self.weekWrapper.offsetWidth
763
- : 0) +
764
- "px";
765
- self.calendarContainer.style.removeProperty("visibility");
766
- self.calendarContainer.style.removeProperty("display");
767
- }
768
- });
794
+ win.requestAnimationFrame(measureCalendarWidth);
769
795
  }
770
796
  }
797
+ function measureCalendarWidth() {
798
+ if (self.calendarContainer !== undefined) {
799
+ self.calendarContainer.style.visibility = "hidden";
800
+ self.calendarContainer.style.display = "block";
801
+ }
802
+ if (self.daysContainer !== undefined) {
803
+ var gridWidth = self.days.offsetWidth;
804
+ // displaying the calendar doesn't lay it out while an element around
805
+ // it is hidden, e.g. a modal not shown yet: wait until it is
806
+ if (gridWidth === 0) {
807
+ observeLayout();
808
+ }
809
+ else {
810
+ var daysWidth = (gridWidth + 1) * self.config.showMonths;
811
+ self.daysContainer.style.width = daysWidth + "px";
812
+ self.calendarContainer.style.width =
813
+ daysWidth +
814
+ (self.weekWrapper !== undefined ? self.weekWrapper.offsetWidth : 0) +
815
+ "px";
816
+ unobserveLayout();
817
+ }
818
+ self.calendarContainer.style.removeProperty("visibility");
819
+ self.calendarContainer.style.removeProperty("display");
820
+ }
821
+ }
822
+ // The page lays an inline calendar out when it shows it, which only an
823
+ // observer tells of, called back after layout and before paint. open()
824
+ // measures a popup as it opens; the observer is left for one opened while
825
+ // an element around it is still hidden
826
+ function observeLayout() {
827
+ var Observer = win.ResizeObserver;
828
+ if (layoutObserver !== undefined || Observer === undefined)
829
+ return;
830
+ layoutObserver = new Observer(measureCalendarWidth);
831
+ layoutObserver.observe(self.calendarContainer);
832
+ }
833
+ function unobserveLayout() {
834
+ if (layoutObserver === undefined)
835
+ return;
836
+ layoutObserver.disconnect();
837
+ layoutObserver = undefined;
838
+ }
771
839
  /**
772
840
  * The day the time inputs' time goes on while no date is selected: today,
773
841
  * or the minDate or maxDate it falls outside of, as the calendar opens on.
@@ -809,14 +877,27 @@
809
877
  return hour % 12;
810
878
  }
811
879
  }
880
+ /**
881
+ * The number in a time input, or `shown`, the selected time's, instead of
882
+ * 0 when it holds none (#2498): emptied, or holding text the browser can't
883
+ * read as a number, such as "7:13" in Firefox or "7e" in any, which leaves
884
+ * an empty value. updateTime() selects the default time before reading,
885
+ * when nothing is selected
886
+ */
887
+ function readTimeInput(value, shown) {
888
+ var number = parseInt(value, 10);
889
+ return isNaN(number) && shown !== undefined ? shown : number || 0;
890
+ }
812
891
  /**
813
892
  * Syncs the selected date object time with user's time input
814
893
  */
815
894
  function setHoursFromInputs() {
816
895
  if (self.hourElement === undefined || self.minuteElement === undefined)
817
896
  return;
818
- var hours = (parseInt(self.hourElement.value.slice(-2), 10) || 0) % 24, minutes = (parseInt(self.minuteElement.value, 10) || 0) % 60, seconds = self.secondElement !== undefined
819
- ? (parseInt(self.secondElement.value, 10) || 0) % 60
897
+ var shown = self.latestSelectedDateObj;
898
+ var hours = readTimeInput(self.hourElement.value.slice(-2), shown && shown.getHours()) % 24, minutes = readTimeInput(self.minuteElement.value, shown && shown.getMinutes()) %
899
+ 60, seconds = self.secondElement !== undefined
900
+ ? readTimeInput(self.secondElement.value, shown && shown.getSeconds()) % 60
820
901
  : 0;
821
902
  if (self.amPM !== undefined) {
822
903
  hours = ampm2military(hours, self.amPM.textContent);
@@ -881,6 +962,14 @@
881
962
  setHours(date.getHours(), date.getMinutes(), date.getSeconds());
882
963
  }
883
964
  }
965
+ /**
966
+ * Puts the default time on the time inputs, the time a date picked while
967
+ * none is selected gets
968
+ */
969
+ function setDefaultHours() {
970
+ var _a = getDefaultHours(self.config, defaultTimeDate()), hours = _a.hours, minutes = _a.minutes, seconds = _a.seconds;
971
+ setHours(hours, minutes, seconds);
972
+ }
884
973
  /**
885
974
  * Sets the hours, minutes, and optionally seconds
886
975
  * of the latest selected date object and the
@@ -952,7 +1041,26 @@
952
1041
  };
953
1042
  if (!self.config.static)
954
1043
  listen(win, "resize", debounce(onResize, 50));
955
- listen(doc, win.ontouchstart !== undefined ? "touchstart" : "mousedown", documentClick);
1044
+ // A mouse press closes the calendar as it lands. On a touch screen, a
1045
+ // touch or pen press closes it on a tap, which ends in pointerup; one that
1046
+ // scrolls or zooms the page ends in pointercancel instead. touchstart
1047
+ // can't tell the two apart: it's left only where pointer events are missing.
1048
+ // The mouse is heard on pointerdown, not mousedown, which a tap also sends
1049
+ // after its pointerup.
1050
+ if (win.ontouchstart === undefined)
1051
+ listen(doc, "mousedown", documentClick);
1052
+ else if (win.PointerEvent === undefined)
1053
+ listen(doc, "touchstart", documentClick);
1054
+ else {
1055
+ listen(doc, "pointerdown", function (e) {
1056
+ if (e.pointerType === "mouse")
1057
+ documentClick(e);
1058
+ });
1059
+ listen(doc, "pointerup", function (e) {
1060
+ if (e.pointerType !== "mouse")
1061
+ documentClick(e);
1062
+ });
1063
+ }
956
1064
  listen(doc, "focus", documentClick, { capture: true });
957
1065
  }
958
1066
  function unbindOpenEvents() {
@@ -1030,6 +1138,14 @@
1030
1138
  return maxDate;
1031
1139
  return date;
1032
1140
  }
1141
+ /**
1142
+ * Whether the date's month is one of the months the calendar shows
1143
+ */
1144
+ function isMonthShown(date) {
1145
+ var firstMonth = self.currentYear * 12 + self.currentMonth;
1146
+ var month = date.getFullYear() * 12 + date.getMonth();
1147
+ return month >= firstMonth && month < firstMonth + self.config.showMonths;
1148
+ }
1033
1149
  /**
1034
1150
  * Set the calendar view to a particular date.
1035
1151
  * @param {Date} jumpDate the date to set the view to
@@ -1135,14 +1251,14 @@
1135
1251
  toggleClass(self.calendarContainer, "animate", self.config.animate === true);
1136
1252
  toggleClass(self.calendarContainer, "multiMonth", self.config.showMonths > 1);
1137
1253
  self.calendarContainer.appendChild(fragment);
1138
- var customAppend = self.config.appendTo !== undefined &&
1139
- self.config.appendTo.nodeType !== undefined;
1254
+ // null, the default the docs list, leaves it unset like undefined (#2725)
1255
+ var customAppend = !!self.config.appendTo && self.config.appendTo.nodeType !== undefined;
1140
1256
  if (self.config.inline || self.config.static) {
1141
1257
  self.calendarContainer.classList.add(self.config.inline ? "inline" : "static");
1142
1258
  if (self.config.inline) {
1143
1259
  if (!customAppend && self.element.parentNode)
1144
1260
  self.element.parentNode.insertBefore(self.calendarContainer, self._input.nextSibling);
1145
- else if (self.config.appendTo !== undefined)
1261
+ else if (self.config.appendTo)
1146
1262
  self.config.appendTo.appendChild(self.calendarContainer);
1147
1263
  }
1148
1264
  if (self.config.static) {
@@ -1157,9 +1273,7 @@
1157
1273
  }
1158
1274
  }
1159
1275
  if (!self.config.static && !self.config.inline)
1160
- (self.config.appendTo !== undefined
1161
- ? self.config.appendTo
1162
- : doc.body).appendChild(self.calendarContainer);
1276
+ (self.config.appendTo || doc.body).appendChild(self.calendarContainer);
1163
1277
  }
1164
1278
  function createDay(className, date, _dayNumber, i) {
1165
1279
  var dateIsEnabled = isEnabled(date, true), dayElement = createElement("span", className, date.getDate().toString());
@@ -1366,7 +1480,6 @@
1366
1480
  var month = createElement("option", "flatpickr-monthDropdown-month");
1367
1481
  month.value = new Date(self.currentYear, i).getMonth().toString();
1368
1482
  month.textContent = monthToStr(i, self.config.shorthandCurrentMonth, self.l10n);
1369
- month.tabIndex = -1;
1370
1483
  if (self.currentMonth === i) {
1371
1484
  month.selected = true;
1372
1485
  }
@@ -1389,7 +1502,6 @@
1389
1502
  var target = getEventTarget(e);
1390
1503
  var selectedMonth = parseInt(target.value, 10);
1391
1504
  self.changeMonth(selectedMonth - self.currentMonth);
1392
- triggerEvent("onMonthChange");
1393
1505
  });
1394
1506
  buildMonthSwitch();
1395
1507
  monthElement = self.monthsDropdownContainer;
@@ -1495,10 +1607,8 @@
1495
1607
  : defaults.minutes);
1496
1608
  self.hourElement.setAttribute("min", self.config.time_24hr ? "0" : "1");
1497
1609
  self.hourElement.setAttribute("max", self.config.time_24hr ? "23" : "12");
1498
- self.hourElement.setAttribute("maxlength", "2");
1499
1610
  self.minuteElement.setAttribute("min", "0");
1500
1611
  self.minuteElement.setAttribute("max", "59");
1501
- self.minuteElement.setAttribute("maxlength", "2");
1502
1612
  self.timeContainer.appendChild(hourInput);
1503
1613
  self.timeContainer.appendChild(separator);
1504
1614
  self.timeContainer.appendChild(minuteInput);
@@ -1508,6 +1618,7 @@
1508
1618
  self.timeContainer.classList.add("hasSeconds");
1509
1619
  var secondInput = createNumberInput("flatpickr-second", {
1510
1620
  id: idPrefix + "-second",
1621
+ "aria-label": self.l10n.secondAriaLabel,
1511
1622
  });
1512
1623
  self.secondElement = secondInput.getElementsByTagName("input")[0];
1513
1624
  self.secondElement.value = pad(self.latestSelectedDateObj
@@ -1515,7 +1626,6 @@
1515
1626
  : defaults.seconds);
1516
1627
  self.secondElement.setAttribute("min", "0");
1517
1628
  self.secondElement.setAttribute("max", "59");
1518
- self.secondElement.setAttribute("maxlength", "2");
1519
1629
  self.timeContainer.appendChild(createElement("span", "flatpickr-time-separator", ":"));
1520
1630
  self.timeContainer.appendChild(secondInput);
1521
1631
  }
@@ -1523,7 +1633,7 @@
1523
1633
  // add self.amPM if appropriate
1524
1634
  self.amPM = createElement("span", "flatpickr-am-pm", self.l10n.amPM[int((self.latestSelectedDateObj
1525
1635
  ? self.hourElement.value
1526
- : self.config.defaultHour) > 11)]);
1636
+ : defaults.hours) > 11)]);
1527
1637
  self.amPM.title = self.l10n.toggleTitle;
1528
1638
  self.amPM.tabIndex = -1;
1529
1639
  self.timeContainer.appendChild(self.amPM);
@@ -1573,8 +1683,15 @@
1573
1683
  if (firstDayOfWeek > 0 && firstDayOfWeek < weekdays.length) {
1574
1684
  weekdays = __spreadArrays(weekdays.splice(firstDayOfWeek, weekdays.length), weekdays.splice(0, firstDayOfWeek));
1575
1685
  }
1686
+ var _loop_1 = function (i) {
1687
+ var container = self.weekdayContainer.children[i];
1688
+ clearNode(container);
1689
+ weekdays.forEach(function (weekday) {
1690
+ return container.appendChild(createElement("span", "flatpickr-weekday", weekday));
1691
+ });
1692
+ };
1576
1693
  for (var i = self.config.showMonths; i--;) {
1577
- self.weekdayContainer.children[i].innerHTML = "\n <span class='flatpickr-weekday'>\n " + weekdays.join("</span><span class='flatpickr-weekday'>") + "\n </span>\n ";
1694
+ _loop_1(i);
1578
1695
  }
1579
1696
  }
1580
1697
  /* istanbul ignore next */
@@ -1620,16 +1737,26 @@
1620
1737
  self.currentYear = initialDate.getFullYear();
1621
1738
  self.currentMonth = initialDate.getMonth();
1622
1739
  }
1623
- if (self.config.enableTime === true) {
1624
- var _a = getDefaultHours(self.config, defaultTimeDate()), hours = _a.hours, minutes = _a.minutes, seconds = _a.seconds;
1625
- setHours(hours, minutes, seconds);
1626
- }
1740
+ if (self.config.enableTime === true)
1741
+ setDefaultHours();
1627
1742
  self.redraw();
1628
1743
  if (triggerChangeEvent)
1629
1744
  // triggerChangeEvent is true (default) or an Event
1630
1745
  triggerEvent("onChange");
1631
1746
  }
1632
1747
  function close() {
1748
+ // A calendar that closes showing none of its selected dates goes back to
1749
+ // latestSelectedDateObj (#2835); with none selected there is nowhere to go
1750
+ // back to, and one that isn't open, as an inline one, keeps its view. As
1751
+ // browsing does, the move is announced once the days are rebuilt, and
1752
+ // before onClose, which may move the view itself
1753
+ if (self.isOpen &&
1754
+ self.selectedDates.length > 0 &&
1755
+ !self.selectedDates.some(isMonthShown)) {
1756
+ var currentYear = self.currentYear, currentMonth = self.currentMonth;
1757
+ jumpToDate();
1758
+ triggerViewChange(currentYear, currentMonth);
1759
+ }
1633
1760
  self.isOpen = false;
1634
1761
  unbindOpenEvents();
1635
1762
  if (!self.isMobile) {
@@ -1650,6 +1777,7 @@
1650
1777
  }
1651
1778
  self._handlers = [];
1652
1779
  unbindOpenEvents();
1780
+ unobserveLayout();
1653
1781
  if (self.mobileInput) {
1654
1782
  if (self.mobileInput.parentNode)
1655
1783
  self.mobileInput.parentNode.removeChild(self.mobileInput);
@@ -1779,12 +1907,15 @@
1779
1907
  var _a;
1780
1908
  if (timeless === void 0) { timeless = true; }
1781
1909
  var dateToCheck = self.parseDate(date, undefined, timeless); // timeless
1910
+ // a time is compared only with a minDate or maxDate that has one: a
1911
+ // date-only limit leaves its whole day open, as the calendar and the time
1912
+ // inputs do (#2460)
1782
1913
  if ((self.config.minDate &&
1783
1914
  dateToCheck &&
1784
- compareDates(dateToCheck, self.config.minDate, timeless !== undefined ? timeless : !self.minDateHasTime) < 0) ||
1915
+ compareDates(dateToCheck, self.config.minDate, timeless || !self.minDateHasTime) < 0) ||
1785
1916
  (self.config.maxDate &&
1786
1917
  dateToCheck &&
1787
- compareDates(dateToCheck, self.config.maxDate, timeless !== undefined ? timeless : !self.maxDateHasTime) > 0))
1918
+ compareDates(dateToCheck, self.config.maxDate, timeless || !self.maxDateHasTime) > 0))
1788
1919
  return false;
1789
1920
  if (!self.config.enable && self.config.disable.length === 0)
1790
1921
  return true;
@@ -1838,7 +1969,7 @@
1838
1969
  * reads it from those
1839
1970
  */
1840
1971
  function typedValue() {
1841
- return self._input.value.trimEnd() === getDateStr()
1972
+ return self._input.value.replace(/\s+$/, "") === getDateStr()
1842
1973
  ? undefined
1843
1974
  : self._input.value;
1844
1975
  }
@@ -2055,7 +2186,7 @@
2055
2186
  maxRange = t;
2056
2187
  }
2057
2188
  }
2058
- var hoverableCells = Array.from(self.rContainer.querySelectorAll("*:nth-child(-n+" + self.config.showMonths + ") > ." + cellClass));
2189
+ var hoverableCells = Array.prototype.slice.call(self.rContainer.querySelectorAll("*:nth-child(-n+" + self.config.showMonths + ") > ." + cellClass));
2059
2190
  hoverableCells.forEach(function (dayElem) {
2060
2191
  var date = dayElem.dateObj;
2061
2192
  var timestamp = date.getTime();
@@ -2103,8 +2234,20 @@
2103
2234
  }
2104
2235
  }
2105
2236
  if (self.mobileInput !== undefined) {
2237
+ // focus() is what opens the picker on iOS, where showPicker() does
2238
+ // nothing for these inputs
2106
2239
  self.mobileInput.focus();
2107
- self.mobileInput.click();
2240
+ // click() doesn't open it in Firefox for Android (#2726). showPicker()
2241
+ // is missing before Chrome 99, Firefox 101 and Safari 16 (and from
2242
+ // TypeScript 4.1's DOM types) and throws where it can't open it, as
2243
+ // without a user gesture, in a cross-origin iframe or on a disabled
2244
+ // input: click() then, as before
2245
+ try {
2246
+ self.mobileInput.showPicker();
2247
+ }
2248
+ catch (_a) {
2249
+ self.mobileInput.click();
2250
+ }
2108
2251
  }
2109
2252
  triggerEvent("onOpen");
2110
2253
  return;
@@ -2118,6 +2261,10 @@
2118
2261
  bindOpenEvents();
2119
2262
  self.calendarContainer.classList.add("open");
2120
2263
  self._input.classList.add("active");
2264
+ // a popup created where it couldn't be laid out can be now: measure it
2265
+ // before it is placed by its width (#2579)
2266
+ if (layoutObserver !== undefined)
2267
+ measureCalendarWidth();
2121
2268
  triggerEvent("onOpen");
2122
2269
  positionCalendar(positionElement);
2123
2270
  }
@@ -2148,8 +2295,10 @@
2148
2295
  self.selectedDates.indexOf(self.latestSelectedDateObj) === -1)
2149
2296
  self.latestSelectedDateObj =
2150
2297
  self.selectedDates[self.selectedDates.length - 1];
2151
- if (!self.selectedDates.length && type === "min")
2152
- setHoursFromDate(dateObj);
2298
+ // with none selected, the time inputs show the default time, which
2299
+ // the new limit may hold, as after clear() (#1869)
2300
+ if (!self.selectedDates.length)
2301
+ setDefaultHours();
2153
2302
  updateValue();
2154
2303
  }
2155
2304
  if (self.daysContainer) {
@@ -2168,6 +2317,7 @@
2168
2317
  };
2169
2318
  }
2170
2319
  function parseConfig() {
2320
+ var _a;
2171
2321
  var boolOpts = [
2172
2322
  "wrap",
2173
2323
  "weekNumbers",
@@ -2189,8 +2339,10 @@
2189
2339
  self.config.formatDate = userConfig.formatDate;
2190
2340
  Object.defineProperty(self.config, "enable", {
2191
2341
  get: function () { return self.config._enable; },
2342
+ // null, like undefined, the default the docs list, leaves every date
2343
+ // enabled, where [] would enable none (#2725)
2192
2344
  set: function (dates) {
2193
- self.config._enable = parseDateRules(dates);
2345
+ self.config._enable = dates ? parseDateRules(dates) : undefined;
2194
2346
  },
2195
2347
  });
2196
2348
  Object.defineProperty(self.config, "disable", {
@@ -2209,6 +2361,10 @@
2209
2361
  });
2210
2362
  var minMaxTimeSetter = function (type) { return function (val) {
2211
2363
  self.config[type === "min" ? "_minTime" : "_maxTime"] = self.parseDate(val, "H:i:S");
2364
+ // with none selected, the time inputs show the default time, which the
2365
+ // new limit may hold, as for minDate and maxDate (#2547)
2366
+ if (self.selectedDates && !self.selectedDates.length)
2367
+ setDefaultHours();
2212
2368
  }; };
2213
2369
  Object.defineProperty(self.config, "minTime", {
2214
2370
  get: function () { return self.config._minTime; },
@@ -2218,10 +2374,24 @@
2218
2374
  get: function () { return self.config._maxTime; },
2219
2375
  set: minMaxTimeSetter("max"),
2220
2376
  });
2377
+ // null, the default the docs list, is the built-in ", " like undefined
2378
+ // (#2725); the write below puts the one from setDefaults() through it too
2379
+ var conjunction = self.config.conjunction;
2380
+ Object.defineProperty(self.config, "conjunction", {
2381
+ get: function () { return conjunction; },
2382
+ set: function (value) {
2383
+ conjunction = value !== null && value !== void 0 ? value : defaults.conjunction;
2384
+ },
2385
+ });
2386
+ self.config.conjunction = conjunction;
2221
2387
  if (userConfig.mode === "time") {
2222
2388
  self.config.noCalendar = true;
2223
2389
  self.config.enableTime = true;
2224
2390
  }
2391
+ // The date options are parsed as they're assigned, below and from the
2392
+ // plugins, with the names of the instance's locale, which setupLocale()
2393
+ // would only set up afterwards (#2721)
2394
+ setupL10n((_a = userConfig.locale) !== null && _a !== void 0 ? _a : self.config.locale);
2225
2395
  Object.assign(self.config, defaultFormats(), userConfig);
2226
2396
  for (var i = 0; i < boolOpts.length; i++)
2227
2397
  // https://github.com/microsoft/TypeScript/issues/31663
@@ -2287,19 +2457,33 @@
2287
2457
  self.config.altFormat = formats.altFormat;
2288
2458
  }
2289
2459
  function getInputElem() {
2290
- return self.config.wrap
2291
- ? element.querySelector("[data-input]")
2292
- : element;
2460
+ if (!self.config.wrap)
2461
+ return element;
2462
+ // parseConfig() reads the input before setupInputs() does: without one,
2463
+ // init can't go on, and flatpickr() logs this rather than a TypeError
2464
+ var input = element.querySelector("[data-input]");
2465
+ if (!input)
2466
+ throw new Error('flatpickr: "wrap" needs an input with the data-input attribute inside the element');
2467
+ return input;
2293
2468
  }
2294
2469
  function setupLocale() {
2295
2470
  if (typeof self.config.locale !== "object" &&
2296
2471
  typeof flatpickr.l10ns[self.config.locale] === "undefined")
2297
2472
  self.config.errorHandler(new Error("flatpickr: invalid locale " + self.config.locale));
2298
- self.l10n = __assign(__assign({}, flatpickr.l10ns.default), (typeof self.config.locale === "object"
2299
- ? self.config.locale
2300
- : self.config.locale !== "default"
2301
- ? flatpickr.l10ns[self.config.locale]
2302
- : undefined));
2473
+ setupL10n(self.config.locale);
2474
+ if (userConfig.time_24hr === undefined &&
2475
+ flatpickr.defaultConfig.time_24hr === undefined) {
2476
+ self.config.time_24hr = self.l10n.time_24hr;
2477
+ }
2478
+ self.formatDate = createDateFormatter(self);
2479
+ }
2480
+ // The instance's locale, and the parser that reads its names
2481
+ function setupL10n(locale) {
2482
+ self.l10n = mergeLocale(flatpickr.l10ns.default, typeof locale === "object"
2483
+ ? locale
2484
+ : locale !== "default"
2485
+ ? flatpickr.l10ns[locale]
2486
+ : undefined);
2303
2487
  tokenRegex.D = "(" + self.l10n.weekdays.shorthand.join("|") + ")";
2304
2488
  tokenRegex.l = "(" + self.l10n.weekdays.longhand.join("|") + ")";
2305
2489
  tokenRegex.M = "(" + self.l10n.months.shorthand
@@ -2311,11 +2495,6 @@
2311
2495
  .sort(function (a, b) { return b.length - a.length; })
2312
2496
  .join("|") + ")";
2313
2497
  tokenRegex.K = "(" + self.l10n.amPM[0] + "|" + self.l10n.amPM[1] + ")";
2314
- if (userConfig.time_24hr === undefined &&
2315
- flatpickr.defaultConfig.time_24hr === undefined) {
2316
- self.config.time_24hr = self.l10n.time_24hr;
2317
- }
2318
- self.formatDate = createDateFormatter(self);
2319
2498
  self.parseDate = createDateParser({ config: self.config, l10n: self.l10n });
2320
2499
  }
2321
2500
  function positionCalendar(customPositionElement) {
@@ -2325,8 +2504,13 @@
2325
2504
  if (self.calendarContainer === undefined)
2326
2505
  return;
2327
2506
  triggerEvent("onPreCalendarPosition");
2328
- var positionElement = customPositionElement || self._positionElement;
2329
- var calendarHeight = Array.prototype.reduce.call(self.calendarContainer.children, (function (acc, child) { return acc + child.offsetHeight; }), 0), calendarWidth = self.calendarContainer.offsetWidth, configPos = self.config.position.split(" "), configPosVertical = configPos[0], configPosHorizontal = configPos.length > 1 ? configPos[1] : null, inputBounds = positionElement.getBoundingClientRect(), distanceFromBottom = win.innerHeight - inputBounds.bottom, isAutoVertical = configPosVertical !== "above" && configPosVertical !== "below", fitsBelow = distanceFromBottom >= calendarHeight, fitsAbove = inputBounds.top > calendarHeight,
2507
+ // a static calendar goes next to its wrapper, whichever element a popup
2508
+ // would be placed by; the page lays it out when it is also inline
2509
+ var wrapper = self.config.static && !self.config.inline
2510
+ ? self.calendarContainer.parentNode
2511
+ : undefined;
2512
+ var positionElement = wrapper || customPositionElement || self._positionElement;
2513
+ var calendarHeight = self.calendarContainer.offsetHeight, calendarWidth = self.calendarContainer.offsetWidth, configPos = self.config.position.split(" "), configPosVertical = configPos[0], configPosHorizontal = configPos.length > 1 ? configPos[1] : null, inputBounds = positionElement.getBoundingClientRect(), distanceFromBottom = win.innerHeight - inputBounds.bottom, isAutoVertical = configPosVertical !== "above" && configPosVertical !== "below", fitsBelow = distanceFromBottom >= calendarHeight, fitsAbove = inputBounds.top > calendarHeight,
2330
2514
  // the page can't always be scrolled to what sticks out of the viewport
2331
2515
  // (scroll-locked modals, touch screens), so a calendar that fits
2332
2516
  // neither above nor below goes on the roomier side, kept in the viewport
@@ -2337,7 +2521,14 @@
2337
2521
  !self.config.inline, showOnTop = keepInViewport
2338
2522
  ? inputBounds.top > distanceFromBottom
2339
2523
  : configPosVertical === "above" ||
2340
- (isAutoVertical && !fitsBelow && fitsAbove);
2524
+ (isAutoVertical &&
2525
+ !fitsBelow &&
2526
+ fitsAbove &&
2527
+ // a scroll container can't be scrolled to what it cuts off above
2528
+ // a static calendar, unlike what sticks out below, which it grows
2529
+ // to hold
2530
+ (wrapper === undefined ||
2531
+ inputBounds.top - getClipTop(wrapper) > calendarHeight));
2341
2532
  var anchoredTop = win.pageYOffset +
2342
2533
  inputBounds.top +
2343
2534
  (!showOnTop ? positionElement.offsetHeight + 2 : -calendarHeight - 2);
@@ -2369,6 +2560,8 @@
2369
2560
  var rightMost = left + calendarWidth > bodyWidth;
2370
2561
  var centerMost = rightMost && inputRight < calendarWidth;
2371
2562
  toggleClass(self.calendarContainer, "rightMost", rightMost);
2563
+ // the stylesheet places a static calendar against its wrapper, by the
2564
+ // arrow classes set above
2372
2565
  if (self.config.static)
2373
2566
  return;
2374
2567
  toggleClass(self.calendarContainer, "centerMost", centerMost);
@@ -2387,6 +2580,23 @@
2387
2580
  self.calendarContainer.style.left = left - origin.left + "px";
2388
2581
  self.calendarContainer.style.right = "auto";
2389
2582
  }
2583
+ // The top of what can be seen of a static calendar: the viewport's, or the
2584
+ // lowest inner top edge of the elements around it that clip their overflow
2585
+ function getClipTop(wrapper) {
2586
+ var _a;
2587
+ var clipTop = 0;
2588
+ for (var ancestor = wrapper; ancestor !== null;
2589
+ // shadow DOM lays an element out in the slot it is assigned to, and a
2590
+ // shadow root's children in its host
2591
+ ancestor =
2592
+ ancestor.assignedSlot ||
2593
+ ancestor.parentElement || ((_a = ancestor.parentNode) === null || _a === void 0 ? void 0 : _a.host) ||
2594
+ null) {
2595
+ if (win.getComputedStyle(ancestor).overflowY !== "visible")
2596
+ clipTop = Math.max(clipTop, ancestor.getBoundingClientRect().top + ancestor.clientTop);
2597
+ }
2598
+ return clipTop;
2599
+ }
2390
2600
  function getContainingBlockOrigin() {
2391
2601
  var containingBlock = self.calendarContainer.offsetParent;
2392
2602
  // offsetParent is null while the calendar is hidden, and stops at <body>
@@ -2433,6 +2643,15 @@
2433
2643
  self.close();
2434
2644
  }
2435
2645
  }
2646
+ /**
2647
+ * Makes way for a day picked on a range that has both ends: a new range,
2648
+ * from no dates and at the default time, which the day takes from the time
2649
+ * inputs. rangePlugin makes the pick an edit of one end, which keeps the
2650
+ * time the time inputs show for it, unless the calendar is inline
2651
+ */
2652
+ function startNewRange() {
2653
+ self.clear(false, false);
2654
+ }
2436
2655
  function selectDate(e) {
2437
2656
  e.preventDefault();
2438
2657
  e.stopPropagation();
@@ -2450,12 +2669,9 @@
2450
2669
  if (t === undefined)
2451
2670
  return;
2452
2671
  var target = t;
2672
+ var prevTimes = getSelectedTimes();
2453
2673
  var selectedDate = (self.latestSelectedDateObj = new Date(target.dateObj.getTime()));
2454
- var firstMonth = self.currentYear * 12 + self.currentMonth;
2455
- var selectedMonth = selectedDate.getFullYear() * 12 + selectedDate.getMonth();
2456
- var shouldChangeMonth = (selectedMonth < firstMonth ||
2457
- selectedMonth > firstMonth + self.config.showMonths - 1) &&
2458
- self.config.mode !== "range";
2674
+ var shouldChangeMonth = !isMonthShown(selectedDate) && self.config.mode !== "range";
2459
2675
  self.selectedDateElem = target;
2460
2676
  if (self.config.mode === "single")
2461
2677
  self.selectedDates = [selectedDate];
@@ -2467,9 +2683,8 @@
2467
2683
  self.selectedDates.push(selectedDate);
2468
2684
  }
2469
2685
  else if (self.config.mode === "range") {
2470
- if (self.selectedDates.length === 2) {
2471
- self.clear(false, false);
2472
- }
2686
+ if (self.selectedDates.length === 2)
2687
+ self._startNewRange();
2473
2688
  self.latestSelectedDateObj = selectedDate;
2474
2689
  self.selectedDates.push(selectedDate);
2475
2690
  // unless selecting same date twice, sort ascendingly
@@ -2490,17 +2705,12 @@
2490
2705
  updateNavigationCurrentMonth();
2491
2706
  buildDays();
2492
2707
  updateValue();
2493
- // maintain focus
2494
- if (!shouldChangeMonth &&
2495
- self.config.mode !== "range" &&
2496
- self.config.showMonths === 1)
2497
- focusOnDayElem(target);
2498
- else if (self.selectedDateElem !== undefined &&
2499
- self.hourElement === undefined) {
2500
- self.selectedDateElem && self.selectedDateElem.focus();
2501
- }
2708
+ // maintain focus: buildDays() has replaced the day picked, so its new
2709
+ // cell is looked up by date (#2791)
2502
2710
  if (self.hourElement !== undefined)
2503
- self.hourElement !== undefined && self.hourElement.focus();
2711
+ self.hourElement.focus();
2712
+ else
2713
+ focusOnDay(getVisibleDay(selectedDate), 0);
2504
2714
  if (self.config.closeOnSelect) {
2505
2715
  var single = self.config.mode === "single" && !self.config.enableTime;
2506
2716
  var range = self.config.mode === "range" &&
@@ -2510,7 +2720,11 @@
2510
2720
  focusAndClose();
2511
2721
  }
2512
2722
  }
2513
- triggerChange();
2723
+ // announce only a change: a selected day picked again, or an end of a
2724
+ // range picked again with rangePlugin keeping the other, leaves the
2725
+ // dates as they were (#2700)
2726
+ if (getSelectedTimes() !== prevTimes)
2727
+ triggerChange();
2514
2728
  }
2515
2729
  var CALLBACKS = {
2516
2730
  locale: [setupLocale, updateWeekdays, rebuildTime],
@@ -2535,22 +2749,27 @@
2535
2749
  ],
2536
2750
  };
2537
2751
  function set(option, value) {
2538
- if (option !== null && typeof option === "object") {
2539
- Object.assign(self.config, option);
2540
- Object.assign(userConfig, option);
2541
- for (var key in option) {
2542
- if (CALLBACKS[key] !== undefined)
2543
- CALLBACKS[key].forEach(function (x) { return x(); });
2544
- }
2545
- }
2546
- else {
2547
- self.config[option] = value;
2548
- userConfig[option] = value;
2549
- if (CALLBACKS[option] !== undefined)
2550
- CALLBACKS[option].forEach(function (x) { return x(); });
2551
- else if (HOOKS.indexOf(option) > -1)
2552
- self.config[option] = arrayify(value);
2553
- }
2752
+ var _a;
2753
+ var options = option !== null && typeof option === "object"
2754
+ ? option
2755
+ : (_a = {}, _a[option] = value, _a);
2756
+ // own keys only, as Object.assign took them
2757
+ var keys = Object.keys(options);
2758
+ keys.forEach(function (key) {
2759
+ userConfig[key] = options[key];
2760
+ // triggerEvent() runs a hook from a list, whichever form it's given in
2761
+ // (#2578)
2762
+ self.config[key] =
2763
+ HOOKS.indexOf(key) > -1
2764
+ ? arrayify(options[key])
2765
+ : options[key];
2766
+ });
2767
+ // once every option is in: a callback may read another one given with it
2768
+ keys.forEach(function (key) {
2769
+ var callbacks = CALLBACKS[key];
2770
+ if (callbacks !== undefined)
2771
+ callbacks.forEach(function (x) { return x(); });
2772
+ });
2554
2773
  self.redraw();
2555
2774
  updateValue(true);
2556
2775
  }
@@ -2686,11 +2905,6 @@
2686
2905
  }
2687
2906
  function setupInputs() {
2688
2907
  self.input = getInputElem();
2689
- /* istanbul ignore next */
2690
- if (!self.input) {
2691
- self.config.errorHandler(new Error("Invalid input element specified"));
2692
- return;
2693
- }
2694
2908
  // hack: store previous type to restore it after destroy()
2695
2909
  self.input._type = self.input.type;
2696
2910
  self.input.type = "text";
@@ -2704,6 +2918,12 @@
2704
2918
  self.altInput.disabled = self.input.disabled;
2705
2919
  self.altInput.required = self.input.required;
2706
2920
  self.altInput.tabIndex = self.input.tabIndex;
2921
+ // The attribute as written: the autocomplete property reads "" for a
2922
+ // value browsers don't know, such as the "nope" pages write where
2923
+ // Chrome ignores "off" (#2577)
2924
+ var autocomplete = self.input.getAttribute("autocomplete");
2925
+ if (autocomplete !== null)
2926
+ self.altInput.setAttribute("autocomplete", autocomplete);
2707
2927
  self.altInput.type = "text";
2708
2928
  self.input.setAttribute("type", "hidden");
2709
2929
  if (!self.config.static && self.input.parentNode)
@@ -2741,34 +2961,45 @@
2741
2961
  setMobileLimit("min");
2742
2962
  setMobileLimit("max");
2743
2963
  }
2744
- // minDate or maxDate as the native input's min or max, in the input's format
2745
- // (#2860). min is where the input's step counts from, so it's put on a whole
2746
- // minute with a step of whole minutes, 60 s by default, and on a whole second
2747
- // with a step of seconds (#2908). The native picker offers only those: min
2748
- // is raised to the next one, as flatpickr drops a value before minDate, and
2749
- // max is cut to the one before. A date input holds no time, and raising min
2750
- // there could move it a day on
2964
+ // minDate or maxDate as the native input's min or max (#2860). The native
2965
+ // picker offers only the times on the input's step: min is raised to the
2966
+ // next one, as flatpickr drops a value before minDate, and max is cut to the
2967
+ // one before. A date input holds no time, and raising min there could move
2968
+ // it a day on. A maxDate without a time leaves its whole day open, as
2969
+ // flatpickr does (#2460): max is cut from the day's last moment
2751
2970
  function setMobileLimit(type) {
2752
2971
  var mobileInput = self.mobileInput;
2753
2972
  var limit = self.config[type + "Date"];
2754
2973
  if (limit === undefined)
2755
2974
  return mobileInput.removeAttribute(type);
2756
- var date = new Date(limit.getTime());
2757
- var unit = Number(mobileInput.step || 60) % 60 === 0 ? 60 : 1;
2758
2975
  var round = type === "min" && mobileInput.type !== "date" ? Math.ceil : Math.floor;
2759
- var seconds = date.getSeconds() + date.getMilliseconds() / 1000;
2760
- date.setSeconds(round(seconds / unit) * unit, 0);
2761
- mobileInput[type] = self.formatDate(date, self.mobileFormatStr);
2976
+ var date = new Date(limit.getTime());
2977
+ if (type === "max" && !self.maxDateHasTime)
2978
+ date.setHours(23, 59, 59, 999);
2979
+ mobileInput[type] = formatMobileDate(date, round);
2980
+ }
2981
+ // A date in the native input's format, put on its step: on a whole minute
2982
+ // with a step of whole minutes, 60 s by default, and on a whole second with
2983
+ // a step of seconds (#2908). min is where the step counts from, and a value
2984
+ // off it is a step mismatch that keeps the form from submitting (#2393)
2985
+ function formatMobileDate(date, round) {
2986
+ if (round === void 0) { round = Math.floor; }
2987
+ var step = self.mobileInput.step;
2988
+ var unit = Number(step || 60) % 60 === 0 ? 60 : 1;
2989
+ var onStep = new Date(date.getTime());
2990
+ var seconds = onStep.getSeconds() + onStep.getMilliseconds() / 1000;
2991
+ onStep.setSeconds(round(seconds / unit) * unit, 0);
2992
+ return self.formatDate(onStep, self.mobileFormatStr);
2762
2993
  }
2763
2994
  function setupMobile() {
2764
2995
  self.mobileInput = createElement("input", self.input.className + " flatpickr-mobile");
2765
- self.mobileInput.tabIndex = 1;
2996
+ self.mobileInput.tabIndex = self.input.tabIndex;
2766
2997
  setMobileInputType();
2767
2998
  self.mobileInput.disabled = self.input.disabled;
2768
2999
  self.mobileInput.required = self.input.required;
2769
3000
  self.mobileInput.placeholder = self.input.placeholder;
2770
3001
  if (self.selectedDates.length > 0) {
2771
- self.mobileInput.defaultValue = self.mobileInput.value = self.formatDate(self.selectedDates[0], self.mobileFormatStr);
3002
+ self.mobileInput.defaultValue = self.mobileInput.value = formatMobileDate(self.selectedDates[0]);
2772
3003
  }
2773
3004
  self.input.type = "hidden";
2774
3005
  if (self.altInput !== undefined)
@@ -2870,7 +3101,7 @@
2870
3101
  if (triggerChange === void 0) { triggerChange = true; }
2871
3102
  if (self.mobileInput !== undefined && self.mobileFormatStr) {
2872
3103
  var mobileValue = self.latestSelectedDateObj !== undefined
2873
- ? self.formatDate(self.latestSelectedDateObj, self.mobileFormatStr)
3104
+ ? formatMobileDate(self.latestSelectedDateObj)
2874
3105
  : "";
2875
3106
  var currentDate = self.parseDate(self.mobileInput.value, self.mobileFormatStr);
2876
3107
  // Browsers leave out zero seconds ("15:05", not "15:05:00"). Writing an
@@ -3016,7 +3247,7 @@
3016
3247
  default: __assign({}, english),
3017
3248
  };
3018
3249
  flatpickr.localize = function (l10n) {
3019
- flatpickr.l10ns.default = __assign(__assign({}, flatpickr.l10ns.default), l10n);
3250
+ flatpickr.l10ns.default = mergeLocale(flatpickr.l10ns.default, l10n);
3020
3251
  };
3021
3252
  flatpickr.setDefaults = function (config) {
3022
3253
  flatpickr.defaultConfig = __assign(__assign({}, flatpickr.defaultConfig), config);